@openai/codex-security 0.9.1 → 0.10.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 (444) hide show
  1. package/README.md +37 -788
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +3 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  14. package/_bundled_plugin/references/access-advisory.md +1 -1
  15. package/_bundled_plugin/references/artifact-storage.md +1 -1
  16. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  17. package/_bundled_plugin/references/core-scan.md +5 -42
  18. package/_bundled_plugin/references/final-report.md +1 -1
  19. package/_bundled_plugin/references/focused-investigator.md +13 -0
  20. package/_bundled_plugin/references/scan-prologue.md +2 -2
  21. package/_bundled_plugin/references/scan-runtime.md +4 -2
  22. package/_bundled_plugin/references/security-guidance.md +14 -1
  23. package/_bundled_plugin/references/threat-model.md +1 -0
  24. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  25. package/_bundled_plugin/scripts/deep_scan_workbench.py +30 -12
  26. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  27. package/_bundled_plugin/scripts/finalize_scan_contract.py +47 -9
  28. package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
  29. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +2 -0
  30. package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
  31. package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
  32. package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
  33. package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
  34. package/_bundled_plugin/scripts/workbench/storage.py +25 -5
  35. package/_bundled_plugin/scripts/workbench_cli.py +24 -2
  36. package/_bundled_plugin/scripts/workbench_constants.py +2 -0
  37. package/_bundled_plugin/scripts/workbench_db.py +257 -268
  38. package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
  39. package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
  40. package/_bundled_plugin/scripts/workbench_progress.py +159 -3
  41. package/_bundled_plugin/scripts/workbench_publication.py +2 -3
  42. package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
  43. package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
  44. package/_bundled_plugin/scripts/workbench_scan_history.py +291 -134
  45. package/_bundled_plugin/scripts/workbench_scan_start.py +208 -11
  46. package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
  47. package/_bundled_plugin/scripts/workbench_schema.py +220 -14
  48. package/_bundled_plugin/scripts/workbench_setup.py +1 -1
  49. package/_bundled_plugin/scripts/workbench_source_scopes.py +8 -0
  50. package/_bundled_plugin/scripts/workbench_target.py +486 -85
  51. package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
  52. package/_bundled_plugin/shared/workbench-history-repairs.json +64 -14
  53. package/_bundled_plugin/shared/workbench-migrations.json +66 -0
  54. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +4 -2
  55. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +2 -2
  56. package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
  57. package/_bundled_plugin/skills/publish-findings/SKILL.md +26 -160
  58. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  59. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
  60. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
  61. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  62. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  63. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  64. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  65. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  66. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  67. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  68. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  69. package/bin/codex-security.mjs +2 -2
  70. package/dist/api.d.ts +7 -1
  71. package/dist/api.d.ts.map +1 -1
  72. package/dist/api.js +459 -157
  73. package/dist/api.js.map +1 -1
  74. package/dist/armorcode-findings.d.ts +9 -0
  75. package/dist/armorcode-findings.d.ts.map +1 -0
  76. package/dist/armorcode-findings.js +145 -0
  77. package/dist/armorcode-findings.js.map +1 -0
  78. package/dist/artifact-export.d.ts +2 -0
  79. package/dist/artifact-export.d.ts.map +1 -1
  80. package/dist/artifact-export.js +29 -13
  81. package/dist/artifact-export.js.map +1 -1
  82. package/dist/auth.d.ts +6 -2
  83. package/dist/auth.d.ts.map +1 -1
  84. package/dist/auth.js +33 -12
  85. package/dist/auth.js.map +1 -1
  86. package/dist/batch-cost.d.ts +18 -0
  87. package/dist/batch-cost.d.ts.map +1 -0
  88. package/dist/batch-cost.js +41 -0
  89. package/dist/batch-cost.js.map +1 -0
  90. package/dist/blackduck-findings.d.ts +1 -1
  91. package/dist/blackduck-findings.d.ts.map +1 -1
  92. package/dist/blackduck-findings.js +5 -18
  93. package/dist/blackduck-findings.js.map +1 -1
  94. package/dist/bundled-plugin.d.ts +4 -0
  95. package/dist/bundled-plugin.d.ts.map +1 -0
  96. package/dist/bundled-plugin.js +23 -0
  97. package/dist/bundled-plugin.js.map +1 -0
  98. package/dist/classify-scan-severity.d.ts +1 -1
  99. package/dist/classify-scan-severity.d.ts.map +1 -1
  100. package/dist/classify-scan-severity.js +11 -3
  101. package/dist/classify-scan-severity.js.map +1 -1
  102. package/dist/classify-severity-diagnostics.d.ts +10 -0
  103. package/dist/classify-severity-diagnostics.d.ts.map +1 -0
  104. package/dist/classify-severity-diagnostics.js +57 -0
  105. package/dist/classify-severity-diagnostics.js.map +1 -0
  106. package/dist/classify-severity-records.d.ts +4 -0
  107. package/dist/classify-severity-records.d.ts.map +1 -1
  108. package/dist/classify-severity-records.js +35 -8
  109. package/dist/classify-severity-records.js.map +1 -1
  110. package/dist/classify-severity.d.ts.map +1 -1
  111. package/dist/classify-severity.js +9 -6
  112. package/dist/classify-severity.js.map +1 -1
  113. package/dist/cli-argument.d.ts +4 -0
  114. package/dist/cli-argument.d.ts.map +1 -0
  115. package/dist/cli-argument.js +17 -0
  116. package/dist/cli-argument.js.map +1 -0
  117. package/dist/cli-help.d.ts +1 -1
  118. package/dist/cli-help.d.ts.map +1 -1
  119. package/dist/cli-help.js +71 -29
  120. package/dist/cli-help.js.map +1 -1
  121. package/dist/cli-hook.d.ts +3 -0
  122. package/dist/cli-hook.d.ts.map +1 -0
  123. package/dist/cli-hook.js +87 -0
  124. package/dist/cli-hook.js.map +1 -0
  125. package/dist/cli-integrations.d.ts +13 -0
  126. package/dist/cli-integrations.d.ts.map +1 -0
  127. package/dist/cli-integrations.js +333 -0
  128. package/dist/cli-integrations.js.map +1 -0
  129. package/dist/cli-mcp.d.ts +15 -0
  130. package/dist/cli-mcp.d.ts.map +1 -0
  131. package/dist/cli-mcp.js +178 -0
  132. package/dist/cli-mcp.js.map +1 -0
  133. package/dist/cli-token-view.d.ts +10 -0
  134. package/dist/cli-token-view.d.ts.map +1 -0
  135. package/dist/cli-token-view.js +41 -0
  136. package/dist/cli-token-view.js.map +1 -0
  137. package/dist/cli.d.ts +8 -3
  138. package/dist/cli.d.ts.map +1 -1
  139. package/dist/cli.js +1860 -903
  140. package/dist/cli.js.map +1 -1
  141. package/dist/cloud-publish.d.ts.map +1 -1
  142. package/dist/cloud-publish.js +33 -31
  143. package/dist/cloud-publish.js.map +1 -1
  144. package/dist/codex-sdk-environment.d.ts +6 -0
  145. package/dist/codex-sdk-environment.d.ts.map +1 -1
  146. package/dist/codex-sdk-environment.js +19 -0
  147. package/dist/codex-sdk-environment.js.map +1 -1
  148. package/dist/command-words.d.ts +3 -0
  149. package/dist/command-words.d.ts.map +1 -0
  150. package/dist/command-words.js +46 -0
  151. package/dist/command-words.js.map +1 -0
  152. package/dist/component-plan.d.ts.map +1 -1
  153. package/dist/component-plan.js +3 -3
  154. package/dist/component-plan.js.map +1 -1
  155. package/dist/component-scan.d.ts +3 -1
  156. package/dist/component-scan.d.ts.map +1 -1
  157. package/dist/component-scan.js +40 -7
  158. package/dist/component-scan.js.map +1 -1
  159. package/dist/config.d.ts +1 -1
  160. package/dist/config.d.ts.map +1 -1
  161. package/dist/config.js +30 -1
  162. package/dist/config.js.map +1 -1
  163. package/dist/continuum-aws.d.ts +6 -0
  164. package/dist/continuum-aws.d.ts.map +1 -0
  165. package/dist/continuum-aws.js +202 -0
  166. package/dist/continuum-aws.js.map +1 -0
  167. package/dist/continuum-collector.d.ts +44 -0
  168. package/dist/continuum-collector.d.ts.map +1 -0
  169. package/dist/continuum-collector.js +266 -0
  170. package/dist/continuum-collector.js.map +1 -0
  171. package/dist/continuum-findings.d.ts +31 -2
  172. package/dist/continuum-findings.d.ts.map +1 -1
  173. package/dist/continuum-findings.js +497 -59
  174. package/dist/continuum-findings.js.map +1 -1
  175. package/dist/contract.d.ts +1 -0
  176. package/dist/contract.d.ts.map +1 -1
  177. package/dist/contract.js +3 -0
  178. package/dist/contract.js.map +1 -1
  179. package/dist/cost.d.ts.map +1 -1
  180. package/dist/cost.js +1 -45
  181. package/dist/cost.js.map +1 -1
  182. package/dist/crowdstrike-findings.d.ts +7 -0
  183. package/dist/crowdstrike-findings.d.ts.map +1 -0
  184. package/dist/crowdstrike-findings.js +210 -0
  185. package/dist/crowdstrike-findings.js.map +1 -0
  186. package/dist/custom-validation-prompt.d.ts +1 -1
  187. package/dist/custom-validation-prompt.d.ts.map +1 -1
  188. package/dist/custom-validation-prompt.js +29 -19
  189. package/dist/custom-validation-prompt.js.map +1 -1
  190. package/dist/deduplication/local.d.ts +3 -1
  191. package/dist/deduplication/local.d.ts.map +1 -1
  192. package/dist/deduplication/local.js +8 -1
  193. package/dist/deduplication/local.js.map +1 -1
  194. package/dist/deduplication/refusal.d.ts.map +1 -1
  195. package/dist/deduplication/refusal.js +2 -1
  196. package/dist/deduplication/refusal.js.map +1 -1
  197. package/dist/deduplication/scan.d.ts +2 -0
  198. package/dist/deduplication/scan.d.ts.map +1 -1
  199. package/dist/deduplication/scan.js +24 -7
  200. package/dist/deduplication/scan.js.map +1 -1
  201. package/dist/deep-scan.d.ts.map +1 -1
  202. package/dist/deep-scan.js +16 -15
  203. package/dist/deep-scan.js.map +1 -1
  204. package/dist/endor-findings.d.ts +2 -2
  205. package/dist/endor-findings.d.ts.map +1 -1
  206. package/dist/endor-findings.js +6 -23
  207. package/dist/endor-findings.js.map +1 -1
  208. package/dist/errors.d.ts +3 -1
  209. package/dist/errors.d.ts.map +1 -1
  210. package/dist/errors.js +7 -3
  211. package/dist/errors.js.map +1 -1
  212. package/dist/executable-path.d.ts +3 -0
  213. package/dist/executable-path.d.ts.map +1 -1
  214. package/dist/executable-path.js +26 -0
  215. package/dist/executable-path.js.map +1 -1
  216. package/dist/external-findings-import.d.ts.map +1 -1
  217. package/dist/external-findings-import.js +12 -1
  218. package/dist/external-findings-import.js.map +1 -1
  219. package/dist/external-findings-local.d.ts +66 -4
  220. package/dist/external-findings-local.d.ts.map +1 -1
  221. package/dist/external-findings-local.js +258 -59
  222. package/dist/external-findings-local.js.map +1 -1
  223. package/dist/external-findings-publish.d.ts +6 -1
  224. package/dist/external-findings-publish.d.ts.map +1 -1
  225. package/dist/external-findings-publish.js +330 -1633
  226. package/dist/external-findings-publish.js.map +1 -1
  227. package/dist/external-findings-read.d.ts +11 -2
  228. package/dist/external-findings-read.d.ts.map +1 -1
  229. package/dist/external-findings-read.js +56 -53
  230. package/dist/external-findings-read.js.map +1 -1
  231. package/dist/external-findings.d.ts +1 -1
  232. package/dist/external-findings.d.ts.map +1 -1
  233. package/dist/external-findings.js +12 -1
  234. package/dist/external-findings.js.map +1 -1
  235. package/dist/external-import-contract.d.ts +6 -11
  236. package/dist/external-import-contract.d.ts.map +1 -1
  237. package/dist/external-import-contract.js +35 -177
  238. package/dist/external-import-contract.js.map +1 -1
  239. package/dist/external-import-models.d.ts +1 -1
  240. package/dist/external-import-models.d.ts.map +1 -1
  241. package/dist/external-import-models.js.map +1 -1
  242. package/dist/finding-prompt.d.ts.map +1 -1
  243. package/dist/finding-prompt.js +2 -2
  244. package/dist/finding-prompt.js.map +1 -1
  245. package/dist/github-dependabot-findings.d.ts.map +1 -1
  246. package/dist/github-dependabot-findings.js +3 -4
  247. package/dist/github-dependabot-findings.js.map +1 -1
  248. package/dist/github-findings.d.ts.map +1 -1
  249. package/dist/github-findings.js +19 -287
  250. package/dist/github-findings.js.map +1 -1
  251. package/dist/host-protocol.d.ts +6 -0
  252. package/dist/host-protocol.d.ts.map +1 -1
  253. package/dist/host-protocol.js +11 -1
  254. package/dist/host-protocol.js.map +1 -1
  255. package/dist/host-records-protocol.d.ts +2 -0
  256. package/dist/host-records-protocol.d.ts.map +1 -1
  257. package/dist/host-records-protocol.js +4 -0
  258. package/dist/host-records-protocol.js.map +1 -1
  259. package/dist/hosted-remediation.d.ts +1 -0
  260. package/dist/hosted-remediation.d.ts.map +1 -1
  261. package/dist/hosted-remediation.js +23 -3
  262. package/dist/hosted-remediation.js.map +1 -1
  263. package/dist/index.d.ts +5 -3
  264. package/dist/index.d.ts.map +1 -1
  265. package/dist/index.js +3 -1
  266. package/dist/index.js.map +1 -1
  267. package/dist/inspector-findings.d.ts.map +1 -1
  268. package/dist/inspector-findings.js +19 -35
  269. package/dist/inspector-findings.js.map +1 -1
  270. package/dist/knowledge-base.d.ts +1 -1
  271. package/dist/knowledge-base.d.ts.map +1 -1
  272. package/dist/knowledge-base.js +34 -27
  273. package/dist/knowledge-base.js.map +1 -1
  274. package/dist/linear.d.ts +11 -0
  275. package/dist/linear.d.ts.map +1 -1
  276. package/dist/linear.js.map +1 -1
  277. package/dist/local-git-metadata.d.ts +5 -2
  278. package/dist/local-git-metadata.d.ts.map +1 -1
  279. package/dist/local-git-metadata.js +8 -4
  280. package/dist/local-git-metadata.js.map +1 -1
  281. package/dist/multiscan.d.ts +4 -0
  282. package/dist/multiscan.d.ts.map +1 -1
  283. package/dist/multiscan.js +83 -39
  284. package/dist/multiscan.js.map +1 -1
  285. package/dist/opengrep-findings.d.ts +4 -2
  286. package/dist/opengrep-findings.d.ts.map +1 -1
  287. package/dist/opengrep-findings.js +39 -22
  288. package/dist/opengrep-findings.js.map +1 -1
  289. package/dist/private-finding-import.d.ts +8 -13
  290. package/dist/private-finding-import.d.ts.map +1 -1
  291. package/dist/private-finding-import.js +69 -129
  292. package/dist/private-finding-import.js.map +1 -1
  293. package/dist/project-config-schema.d.ts +2 -0
  294. package/dist/project-config-schema.d.ts.map +1 -1
  295. package/dist/project-config-schema.js +1 -0
  296. package/dist/project-config-schema.js.map +1 -1
  297. package/dist/project-config.d.ts +1 -0
  298. package/dist/project-config.d.ts.map +1 -1
  299. package/dist/project-config.js +56 -13
  300. package/dist/project-config.js.map +1 -1
  301. package/dist/prompt-files.d.ts +7 -2
  302. package/dist/prompt-files.d.ts.map +1 -1
  303. package/dist/prompt-files.js +42 -20
  304. package/dist/prompt-files.js.map +1 -1
  305. package/dist/provider-profile.d.ts.map +1 -1
  306. package/dist/provider-profile.js +4 -9
  307. package/dist/provider-profile.js.map +1 -1
  308. package/dist/publication.d.ts +1 -1
  309. package/dist/publication.d.ts.map +1 -1
  310. package/dist/publication.js.map +1 -1
  311. package/dist/record.d.ts +1 -5
  312. package/dist/record.d.ts.map +1 -1
  313. package/dist/record.js +3 -51
  314. package/dist/record.js.map +1 -1
  315. package/dist/remediation.d.ts.map +1 -1
  316. package/dist/remediation.js +3 -1
  317. package/dist/remediation.js.map +1 -1
  318. package/dist/runtime.d.ts +35 -7
  319. package/dist/runtime.d.ts.map +1 -1
  320. package/dist/runtime.js +782 -153
  321. package/dist/runtime.js.map +1 -1
  322. package/dist/saved-scan-bootstrap.d.ts +6 -1
  323. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  324. package/dist/saved-scan-bootstrap.js +267 -115
  325. package/dist/saved-scan-bootstrap.js.map +1 -1
  326. package/dist/scan-archive-path.d.ts +2 -0
  327. package/dist/scan-archive-path.d.ts.map +1 -0
  328. package/dist/scan-archive-path.js +5 -0
  329. package/dist/scan-archive-path.js.map +1 -0
  330. package/dist/scan-comparison.d.ts +20 -2
  331. package/dist/scan-comparison.d.ts.map +1 -1
  332. package/dist/scan-comparison.js +26 -5
  333. package/dist/scan-comparison.js.map +1 -1
  334. package/dist/scan-dashboard.d.ts +1 -0
  335. package/dist/scan-dashboard.d.ts.map +1 -1
  336. package/dist/scan-dashboard.js +18 -2
  337. package/dist/scan-dashboard.js.map +1 -1
  338. package/dist/scan-executor.d.ts.map +1 -1
  339. package/dist/scan-executor.js +4 -2
  340. package/dist/scan-executor.js.map +1 -1
  341. package/dist/scan-history-renderer.d.ts +1 -0
  342. package/dist/scan-history-renderer.d.ts.map +1 -1
  343. package/dist/scan-history-renderer.js +25 -9
  344. package/dist/scan-history-renderer.js.map +1 -1
  345. package/dist/scan-logs.d.ts.map +1 -1
  346. package/dist/scan-logs.js +28 -4
  347. package/dist/scan-logs.js.map +1 -1
  348. package/dist/scan-settings.d.ts +1 -0
  349. package/dist/scan-settings.d.ts.map +1 -1
  350. package/dist/scan-settings.js +1 -0
  351. package/dist/scan-settings.js.map +1 -1
  352. package/dist/scanner-import.d.ts +5 -11
  353. package/dist/scanner-import.d.ts.map +1 -1
  354. package/dist/scanner-import.js +16 -89
  355. package/dist/scanner-import.js.map +1 -1
  356. package/dist/security-policy.d.ts.map +1 -1
  357. package/dist/security-policy.js +26 -6
  358. package/dist/security-policy.js.map +1 -1
  359. package/dist/semgrep-findings.d.ts.map +1 -1
  360. package/dist/semgrep-findings.js +14 -48
  361. package/dist/semgrep-findings.js.map +1 -1
  362. package/dist/semgrep-platform-findings.d.ts +20 -70
  363. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  364. package/dist/semgrep-platform-findings.js +116 -333
  365. package/dist/semgrep-platform-findings.js.map +1 -1
  366. package/dist/severity-review.d.ts.map +1 -1
  367. package/dist/severity-review.js +1 -0
  368. package/dist/severity-review.js.map +1 -1
  369. package/dist/snyk-findings.d.ts +2 -0
  370. package/dist/snyk-findings.d.ts.map +1 -1
  371. package/dist/snyk-findings.js +5 -8
  372. package/dist/snyk-findings.js.map +1 -1
  373. package/dist/snyk-rest-findings.d.ts +3 -20
  374. package/dist/snyk-rest-findings.d.ts.map +1 -1
  375. package/dist/snyk-rest-findings.js +45 -217
  376. package/dist/snyk-rest-findings.js.map +1 -1
  377. package/dist/sonar-findings.d.ts +1 -1
  378. package/dist/sonar-findings.d.ts.map +1 -1
  379. package/dist/sonar-findings.js +2 -4
  380. package/dist/sonar-findings.js.map +1 -1
  381. package/dist/sonar-import.d.ts +3 -0
  382. package/dist/sonar-import.d.ts.map +1 -1
  383. package/dist/sonar-import.js +28 -30
  384. package/dist/sonar-import.js.map +1 -1
  385. package/dist/stored-finding-projection.d.ts +6 -0
  386. package/dist/stored-finding-projection.d.ts.map +1 -0
  387. package/dist/stored-finding-projection.js +129 -0
  388. package/dist/stored-finding-projection.js.map +1 -0
  389. package/dist/stored-findings-publication.d.ts +23 -0
  390. package/dist/stored-findings-publication.d.ts.map +1 -0
  391. package/dist/stored-findings-publication.js +169 -0
  392. package/dist/stored-findings-publication.js.map +1 -0
  393. package/dist/targets.d.ts +8 -1
  394. package/dist/targets.d.ts.map +1 -1
  395. package/dist/targets.js +103 -23
  396. package/dist/targets.js.map +1 -1
  397. package/dist/tenable-findings.d.ts +1 -4
  398. package/dist/tenable-findings.d.ts.map +1 -1
  399. package/dist/tenable-findings.js.map +1 -1
  400. package/dist/trivy-findings.d.ts.map +1 -1
  401. package/dist/trivy-findings.js +0 -11
  402. package/dist/trivy-findings.js.map +1 -1
  403. package/dist/trusted-executable.d.ts +7 -0
  404. package/dist/trusted-executable.d.ts.map +1 -1
  405. package/dist/trusted-executable.js +148 -37
  406. package/dist/trusted-executable.js.map +1 -1
  407. package/dist/value.js +3 -1
  408. package/dist/value.js.map +1 -1
  409. package/dist/veracode-findings.d.ts +1 -3
  410. package/dist/veracode-findings.d.ts.map +1 -1
  411. package/dist/veracode-findings.js +13 -38
  412. package/dist/veracode-findings.js.map +1 -1
  413. package/dist/version.d.ts +3 -1
  414. package/dist/version.d.ts.map +1 -1
  415. package/dist/version.js +184 -32
  416. package/dist/version.js.map +1 -1
  417. package/dist/wiz-findings.d.ts +2 -2
  418. package/dist/wiz-findings.d.ts.map +1 -1
  419. package/dist/wiz-findings.js +14 -92
  420. package/dist/wiz-findings.js.map +1 -1
  421. package/docs/classify-severity-records.md +30 -0
  422. package/docs/cli.md +537 -124
  423. package/docs/findings-service.md +22 -9
  424. package/docs/hosted-remediation.md +13 -4
  425. package/docs/sdk.md +918 -0
  426. package/package.json +15 -6
  427. package/schemas/external-findings.schema.json +2 -1
  428. package/schemas/project-config.schema.json +5 -0
  429. package/dist/hosted-scanner-v1.d.ts +0 -6
  430. package/dist/hosted-scanner-v1.d.ts.map +0 -1
  431. package/dist/hosted-scanner-v1.js +0 -60
  432. package/dist/hosted-scanner-v1.js.map +0 -1
  433. package/dist/reader-selection.d.ts +0 -15
  434. package/dist/reader-selection.d.ts.map +0 -1
  435. package/dist/reader-selection.js +0 -89
  436. package/dist/reader-selection.js.map +0 -1
  437. package/dist/semgrep-platform-v1.d.ts +0 -6
  438. package/dist/semgrep-platform-v1.d.ts.map +0 -1
  439. package/dist/semgrep-platform-v1.js +0 -83
  440. package/dist/semgrep-platform-v1.js.map +0 -1
  441. package/dist/snyk-rest-v1.d.ts +0 -28
  442. package/dist/snyk-rest-v1.d.ts.map +0 -1
  443. package/dist/snyk-rest-v1.js +0 -132
  444. package/dist/snyk-rest-v1.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"sonar-findings.js","sourceRoot":"","sources":["../src/sonar-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,qBAAqB,EAErB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,IAAI,GACL,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAE3E,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACxE,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;IAC9B,MAAM,EAAE,WAAW;IACnB,YAAY,EAAE,WAAW;IACzB,OAAO,EAAE,WAAW;IACpB,MAAM,EAAE,WAAW,CAAC,QAAQ,EAAE;IAC9B,WAAW,EAAE,WAAW,CAAC,QAAQ,EAAE;IACnC,aAAa,EAAE,WAAW,CAAC,QAAQ,EAAE;IACrC,WAAW,EAAE,CAAC;SACX,MAAM,EAAE;SACR,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,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gBAC3B,UAAU,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE;gBAC/B,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAClE,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;gBACxB,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;aAC/D;YACD,WAAW,EAAE,eAAe,CAAC;gBAC3B,GAAG,OAAO;gBACV,KAAK;gBACL,UAAU,EAAE,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC;gBAChE,GAAG,CAAC,UAAU,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;aACxC,CAAC;SACH,EACD,MAAM,CACP,CAAC;IACJ,CAAC,EACD,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC,EAC5D,MAAM,EACN,EAAE,MAAM,EAAE,OAAO,EAAE,CAC6B,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,mBAA2B,EAC3B,MAAM,GAAyB,OAAO;IAEtC,OAAO,sBAAsB,CAC3B,MAAM,eAAe,CAAC,IAAI,CAAC,EAC3B,mBAAmB,EACnB,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n cloudRepositoryUrlKey,\n type ExternalImportTarget,\n repositoryUrlKey,\n validateExternalEvidence,\n} from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport type { Provider, Severity } from \"./external-import-models.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n text,\n} from \"./scanner-import.js\";\nimport { declaredScannerRepositoryUrl } from \"./scanner-repository-url.js\";\n\nconst sonarFormat = \"sonar-issues/v1\";\nconst captureText = z.string().refine((value) => Boolean(value.trim()));\nconst captureSchema = z.object({\n format: z.literal(sonarFormat),\n server: captureText,\n organization: captureText,\n project: captureText,\n branch: captureText.optional(),\n pullRequest: captureText.optional(),\n repositoryUrl: captureText.optional(),\n projectBase: z\n .string()\n .refine((path) => path === \"\" || relativePath(path) === path)\n .optional(),\n pages: z.array(z.unknown()).min(1),\n queryPageCounts: z.array(z.int().positive()).min(1).optional(),\n});\nexport type SonarCapture = z.infer<typeof captureSchema>;\n\nexport function parseSonarCapture(value: unknown): SonarCapture {\n const capture = captureSchema.parse(value);\n if (capture.branch && capture.pullRequest)\n throw new Error(\n \"A Sonar capture must select a branch or a pull request, not both.\",\n );\n const url = URL.parse(capture.server);\n if (\n !url ||\n ![\"https:\", \"http:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n )\n throw new Error(\n \"Expected an HTTP(S) Sonar server URL without credentials, query or fragment.\",\n );\n capture.server = url.href.replace(/\\/$/u, \"\");\n if (capture.repositoryUrl)\n declaredScannerRepositoryUrl(capture.repositoryUrl, \"Sonar\", \"local\");\n return capture;\n}\n\ntype NativeRecord = Record<string, unknown>;\n\nconst issueScopeFields = [\n \"organization\",\n \"project\",\n \"branch\",\n \"pullRequest\",\n] as const;\nconst scopeFields = [\"server\", ...issueScopeFields] as const;\ntype SonarScope = Partial<Record<(typeof scopeFields)[number], string>>;\n\nfunction mergeSonarScope(\n scope: SonarScope,\n data: NativeRecord,\n fields: readonly (keyof SonarScope)[] = scopeFields,\n) {\n for (const field of fields) {\n const value = text(data[field]);\n if (value === null) continue;\n if (scope[field] !== undefined && scope[field] !== value)\n throw new Error(`The Sonar export contains conflicting ${field} values.`);\n scope[field] = value;\n }\n if (scope.branch && scope.pullRequest)\n throw new Error(\"The Sonar export mixes branch and pull request results.\");\n}\n\nfunction requireConsistentSonarRef(\n scope: SonarScope,\n hasUnscopedIssue: boolean,\n) {\n if (hasUnscopedIssue && (scope.branch || scope.pullRequest))\n throw new Error(\n \"The Sonar export mixes issues with a named ref and issues without a ref.\",\n );\n}\n\n/** Normalized Sonar reports and their individual issues retain the source repository. */\nexport function sonarRepositoryUrls(\n provider: Provider,\n findings: ExternalFindings[\"findings\"],\n report: ExternalFindings[\"report\"],\n target: ExternalImportTarget,\n): Set<string> {\n const urls = new Set<string>();\n function add(data: NativeRecord | undefined, scope: SonarScope) {\n if (data?.[\"format\"] !== sonarFormat) return;\n if (provider !== \"sonar\")\n throw new Error(\"Retained Sonar evidence requires the sonar provider.\");\n mergeSonarScope(scope, data);\n urls.add(\n declaredScannerRepositoryUrl(data[\"repositoryUrl\"], \"Sonar\", target),\n );\n }\n const reportScope: SonarScope = {};\n add(report, reportScope);\n const scope = { ...reportScope };\n let hasUnscopedIssue = false;\n for (const { evidence, source_finding_id } of findings) {\n const data = evidence.source_data;\n const rowScope = { ...reportScope };\n add(data ?? undefined, rowScope);\n if (data?.[\"format\"] === sonarFormat && data[\"issue\"] !== undefined) {\n const issue = record(data[\"issue\"], \"Retained Sonar issue\");\n mergeSonarScope(rowScope, issue, issueScopeFields);\n if (\n requiredText(issue[\"key\"], \"Retained Sonar issue key\") !==\n source_finding_id\n )\n throw new Error(\n \"The normalized finding ID does not match the retained Sonar issue key.\",\n );\n }\n mergeSonarScope(scope, rowScope);\n if (!rowScope.branch && !rowScope.pullRequest) hasUnscopedIssue = true;\n }\n requireConsistentSonarRef(scope, hasUnscopedIssue);\n if (\n scope.branch &&\n findings.some(\n ({ evidence }) =>\n (report?.[\"format\"] === sonarFormat ||\n evidence.source_data?.[\"format\"] === sonarFormat) &&\n evidence.branch != null &&\n evidence.branch !== scope.branch,\n )\n )\n throw new Error(\n \"The finding branch does not match the retained Sonar branch.\",\n );\n return urls;\n}\n\nconst pagingSchema = z.object({\n pageIndex: z.int().positive(),\n pageSize: z.int().positive(),\n total: z.int().nonnegative(),\n});\n\nfunction indexByKey(value: unknown, label: string) {\n const index = new Map<string, NativeRecord>();\n for (const item of array(value ?? [], label)) {\n const row = record(item, label);\n const key = requiredText(row[\"key\"], `${label} key`);\n index.set(key, row);\n }\n return index;\n}\n\nexport function mergeSonarIssueScope(scope: SonarScope, issue: NativeRecord) {\n mergeSonarScope(scope, issue, issueScopeFields);\n}\n\nfunction readPage(value: unknown) {\n const page = record(value, \"Sonar issue search page\");\n return {\n paging: pagingSchema.parse(page[\"paging\"]),\n issues: array(page[\"issues\"], \"Sonar issues\").map((issue) =>\n record(issue, \"Sonar issue\"),\n ),\n components: indexByKey(page[\"components\"], \"Sonar component\"),\n rules: indexByKey(page[\"rules\"], \"Sonar rule\"),\n };\n}\n\nfunction completeQueryPages(values: unknown[]) {\n const pages = values\n .map(readPage)\n .sort((a, b) => a.paging.pageIndex - b.paging.pageIndex);\n const first = pages[0]?.paging;\n if (\n !first ||\n pages.length !== Math.max(1, Math.ceil(first.total / first.pageSize)) ||\n pages.some(\n ({ paging, issues }, i) =>\n paging.pageIndex !== i + 1 ||\n paging.total !== first.total ||\n paging.pageSize !== first.pageSize ||\n issues.length !==\n Math.min(first.pageSize, first.total - i * first.pageSize),\n )\n )\n throw new Error(\n \"Supply every Sonar issue search page exactly once, with consistent paging and issue counts.\",\n );\n return pages;\n}\n\nexport function completeSonarPages(\n values: unknown[],\n queryPageCounts?: number[],\n) {\n const counts = queryPageCounts ?? [values.length];\n if (counts.reduce((sum, count) => sum + count, 0) !== values.length)\n throw new Error(\"Sonar query page counts do not match the captured pages.\");\n let offset = 0;\n const pages = counts.flatMap((count) => {\n const query = values.slice(offset, offset + count);\n offset += count;\n return completeQueryPages(query);\n });\n const ids = new Set<string>();\n for (const { issues } of pages) {\n for (const issue of issues) {\n const id = text(issue[\"key\"]);\n if (id && ids.has(id))\n throw new Error(\n \"Sonar issue search pages overlap. Collect the selection again.\",\n );\n if (id) ids.add(id);\n }\n }\n return pages;\n}\n\nconst severityLevels: Readonly<Record<string, Severity>> = {\n BLOCKER: \"critical\",\n HIGH: \"high\",\n MEDIUM: \"medium\",\n LOW: \"low\",\n INFO: \"informational\",\n CRITICAL: \"high\",\n MAJOR: \"medium\",\n MINOR: \"low\",\n};\n\nfunction securitySeverity(issue: NativeRecord): Severity {\n const impacts = array(issue[\"impacts\"] ?? [], \"Sonar issue impacts\");\n const security = impacts.find(\n (impact) => isRecord(impact) && impact[\"softwareQuality\"] === \"SECURITY\",\n );\n if (\n !isRecord(security) &&\n (impacts.length || issue[\"type\"] !== \"VULNERABILITY\")\n )\n throw new Error(\n \"Sonar issue has no security impact or legacy vulnerability type.\",\n );\n const value = isRecord(security) ? security[\"severity\"] : issue[\"severity\"];\n return typeof value === \"string\" && Object.hasOwn(severityLevels, value)\n ? severityLevels[value]!\n : \"unknown\";\n}\n\nfunction relatedComponents(\n issue: NativeRecord,\n primary: string,\n components: Map<string, NativeRecord>,\n) {\n const keys = new Set([primary]);\n for (const value of array(issue[\"flows\"] ?? [], \"Sonar issue flows\")) {\n const flow = record(value, \"Sonar flow\");\n for (const entry of array(flow[\"locations\"], \"Sonar flow locations\")) {\n const location = record(entry, \"Sonar flow location\");\n const key = text(location[\"component\"]);\n if (key) keys.add(key);\n }\n }\n return Array.from(keys).flatMap((key) => components.get(key) ?? []);\n}\n\nfunction issueLink(\n server: string,\n project: string,\n id: string,\n branch?: string,\n pullRequest?: string,\n) {\n const link = new URL(\"project/issues\", server + \"/\");\n link.searchParams.set(\"id\", project);\n if (branch) link.searchParams.set(\"branch\", branch);\n if (pullRequest) link.searchParams.set(\"pullRequest\", pullRequest);\n link.searchParams.set(\"open\", id);\n link.searchParams.set(\"issues\", id);\n return link.href;\n}\n\nexport function normalizeSonarFindings(\n input: unknown,\n sourceRepositoryUrl: string,\n target: ExternalImportTarget = \"cloud\",\n) {\n const capture =\n isRecord(input) && \"format\" in input ? parseSonarCapture(input) : undefined;\n const repository = declaredScannerRepositoryUrl(\n capture?.repositoryUrl ?? sourceRepositoryUrl,\n \"Sonar\",\n target,\n );\n if (capture?.repositoryUrl && sourceRepositoryUrl) {\n const key = target === \"cloud\" ? cloudRepositoryUrlKey : repositoryUrlKey;\n if (\n key(repository) !==\n key(declaredScannerRepositoryUrl(sourceRepositoryUrl, \"Sonar\", target))\n )\n throw new Error(\n \"The Sonar capture repository does not match the declared source repository.\",\n );\n }\n const pages = completeSonarPages(\n capture?.pages ?? (Array.isArray(input) ? input : [input]),\n capture?.queryPageCounts,\n );\n const rows = pages.flatMap((page) =>\n page.issues.map((issue) => ({ issue, page })),\n );\n const scope: SonarScope = {};\n if (capture) mergeSonarScope(scope, capture);\n const hasUnscopedIssue = rows.some(\n ({ issue }) => !text(issue[\"branch\"]) && !text(issue[\"pullRequest\"]),\n );\n for (const { issue } of rows) {\n requiredText(issue[\"project\"], \"Sonar issue project\");\n mergeSonarIssueScope(scope, issue);\n }\n requireConsistentSonarRef(\n scope,\n !capture?.branch && !capture?.pullRequest && hasUnscopedIssue,\n );\n const context = {\n format: sonarFormat,\n ...(capture?.projectBase !== undefined && {\n projectBase: capture.projectBase,\n }),\n ...scope,\n repositoryUrl: repository,\n };\n return normalizeRecords(\n rows,\n ({ issue, page }, id) => {\n const component = requiredText(\n issue[\"component\"],\n \"Sonar issue component\",\n );\n const componentPath = relativePath(\n page.components.get(component)?.[\"path\"],\n );\n const base = capture?.projectBase;\n const path =\n componentPath && base !== undefined\n ? base\n ? `${base}/${componentPath}`\n : componentPath\n : null;\n const range =\n issue[\"textRange\"] == null\n ? null\n : record(issue[\"textRange\"], \"Sonar issue textRange\");\n const line = range?.[\"startLine\"] ?? issue[\"line\"] ?? null;\n const rule = requiredText(issue[\"rule\"], \"Sonar issue rule\");\n const descriptor = page.rules.get(rule);\n const name = text(descriptor?.[\"name\"]);\n const updated = text(issue[\"updateDate\"]);\n const severity = securitySeverity(issue);\n return validateExternalEvidence(\n {\n title: name ?? rule,\n severity,\n description: text(issue[\"message\"]),\n url: capture\n ? issueLink(\n capture.server,\n capture.project,\n id,\n scope.branch,\n scope.pullRequest,\n )\n : null,\n locations: path ? [{ path, line }] : [],\n branch: scope.branch ?? null,\n source_updated_at: updated\n ? Math.floor(Date.parse(updated) / 1000)\n : null,\n details: {\n kind: \"sast\",\n scanner_origin: \"SonarQube\",\n repository: { url: repository },\n source_status: text(issue[\"issueStatus\"]) ?? text(issue[\"status\"]),\n rule: { id: rule, name },\n code: { end_line: path ? (range?.[\"endLine\"] ?? null) : null },\n },\n source_data: structuredClone({\n ...context,\n issue,\n components: relatedComponents(issue, component, page.components),\n ...(descriptor && { rule: descriptor }),\n }),\n },\n target,\n );\n },\n ({ issue }) => requiredText(issue[\"key\"], \"Sonar issue key\"),\n target,\n { report: context },\n ) as ExternalFindings & { report: typeof context };\n}\n\nexport async function readSonarFindings(\n path: string,\n sourceRepositoryUrl: string,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeSonarFindings(\n await readScannerJson(path),\n sourceRepositoryUrl,\n target,\n );\n}\n"]}
1
+ {"version":3,"file":"sonar-findings.js","sourceRoot":"","sources":["../src/sonar-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,qBAAqB,EAErB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,IAAI,GACL,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAE3E,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,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,MAAM,EAAE,OAAO,EAAE,CAC6B,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,sBAAsB,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n cloudRepositoryUrlKey,\n type ExternalImportTarget,\n repositoryUrlKey,\n validateExternalEvidence,\n} from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport type { Provider, Severity } from \"./external-import-models.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n normalizeRecords,\n scannerJsonReader,\n record,\n relativePath,\n requiredText,\n text,\n} from \"./scanner-import.js\";\nimport { declaredScannerRepositoryUrl } from \"./scanner-repository-url.js\";\n\nconst sonarFormat = \"sonar-issues/v1\";\nconst captureText = z.string().refine((value) => Boolean(value.trim()));\nconst captureSchema = z.object({\n format: z.literal(sonarFormat),\n server: captureText,\n organization: captureText,\n project: captureText,\n branch: captureText.optional(),\n pullRequest: captureText.optional(),\n repositoryUrl: captureText.optional(),\n projectBase: z\n .string()\n .refine((path) => path === \"\" || relativePath(path) === path)\n .optional(),\n pages: z.array(z.unknown()).min(1),\n queryPageCounts: z.array(z.int().positive()).min(1).optional(),\n});\nexport type SonarCapture = z.infer<typeof captureSchema>;\n\nexport function parseSonarCapture(value: unknown): SonarCapture {\n const capture = captureSchema.parse(value);\n if (capture.branch && capture.pullRequest)\n throw new Error(\n \"A Sonar capture must select a branch or a pull request, not both.\",\n );\n const url = URL.parse(capture.server);\n if (\n !url ||\n ![\"https:\", \"http:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n )\n throw new Error(\n \"Expected an HTTP(S) Sonar server URL without credentials, query or fragment.\",\n );\n capture.server = url.href.replace(/\\/$/u, \"\");\n if (capture.repositoryUrl)\n declaredScannerRepositoryUrl(capture.repositoryUrl, \"Sonar\", \"local\");\n return capture;\n}\n\ntype NativeRecord = Record<string, unknown>;\n\nconst issueScopeFields = [\n \"organization\",\n \"project\",\n \"branch\",\n \"pullRequest\",\n] as const;\nconst scopeFields = [\"server\", ...issueScopeFields] as const;\ntype SonarScope = Partial<Record<(typeof scopeFields)[number], string>>;\n\nfunction mergeSonarScope(\n scope: SonarScope,\n data: NativeRecord,\n fields: readonly (keyof SonarScope)[] = scopeFields,\n) {\n for (const field of fields) {\n const value = text(data[field]);\n if (value === null) continue;\n if (scope[field] !== undefined && scope[field] !== value)\n throw new Error(`The Sonar export contains conflicting ${field} values.`);\n scope[field] = value;\n }\n if (scope.branch && scope.pullRequest)\n throw new Error(\"The Sonar export mixes branch and pull request results.\");\n}\n\nfunction requireConsistentSonarRef(\n scope: SonarScope,\n hasUnscopedIssue: boolean,\n) {\n if (hasUnscopedIssue && (scope.branch || scope.pullRequest))\n throw new Error(\n \"The Sonar export mixes issues with a named ref and issues without a ref.\",\n );\n}\n\n/** Normalized Sonar reports and their individual issues retain the source repository. */\nexport function sonarRepositoryUrls(\n provider: Provider,\n findings: ExternalFindings[\"findings\"],\n report: ExternalFindings[\"report\"],\n target: ExternalImportTarget,\n): Set<string> {\n const urls = new Set<string>();\n function add(data: NativeRecord | undefined, scope: SonarScope) {\n if (data?.[\"format\"] !== sonarFormat) return;\n if (provider !== \"sonar\")\n throw new Error(\"Retained Sonar evidence requires the sonar provider.\");\n mergeSonarScope(scope, data);\n urls.add(\n declaredScannerRepositoryUrl(data[\"repositoryUrl\"], \"Sonar\", target),\n );\n }\n const reportScope: SonarScope = {};\n add(report, reportScope);\n const scope = { ...reportScope };\n let hasUnscopedIssue = false;\n for (const { evidence, source_finding_id } of findings) {\n const data = evidence.source_data;\n const rowScope = { ...reportScope };\n add(data ?? undefined, rowScope);\n if (data?.[\"format\"] === sonarFormat && data[\"issue\"] !== undefined) {\n const issue = record(data[\"issue\"], \"Retained Sonar issue\");\n mergeSonarScope(rowScope, issue, issueScopeFields);\n if (\n requiredText(issue[\"key\"], \"Retained Sonar issue key\") !==\n source_finding_id\n )\n throw new Error(\n \"The normalized finding ID does not match the retained Sonar issue key.\",\n );\n }\n mergeSonarScope(scope, rowScope);\n if (!rowScope.branch && !rowScope.pullRequest) hasUnscopedIssue = true;\n }\n requireConsistentSonarRef(scope, hasUnscopedIssue);\n if (\n scope.branch &&\n findings.some(\n ({ evidence }) =>\n (report?.[\"format\"] === sonarFormat ||\n evidence.source_data?.[\"format\"] === sonarFormat) &&\n evidence.branch != null &&\n evidence.branch !== scope.branch,\n )\n )\n throw new Error(\n \"The finding branch does not match the retained Sonar branch.\",\n );\n return urls;\n}\n\nconst pagingSchema = z.object({\n pageIndex: z.int().positive(),\n pageSize: z.int().positive(),\n total: z.int().nonnegative(),\n});\n\nfunction indexByKey(value: unknown, label: string) {\n const index = new Map<string, NativeRecord>();\n for (const item of array(value ?? [], label)) {\n const row = record(item, label);\n const key = requiredText(row[\"key\"], `${label} key`);\n index.set(key, row);\n }\n return index;\n}\n\nexport function mergeSonarIssueScope(scope: SonarScope, issue: NativeRecord) {\n mergeSonarScope(scope, issue, issueScopeFields);\n}\n\nfunction readPage(value: unknown) {\n const page = record(value, \"Sonar issue search page\");\n return {\n paging: pagingSchema.parse(page[\"paging\"]),\n issues: array(page[\"issues\"], \"Sonar issues\").map((issue) =>\n record(issue, \"Sonar issue\"),\n ),\n components: indexByKey(page[\"components\"], \"Sonar component\"),\n rules: indexByKey(page[\"rules\"], \"Sonar rule\"),\n };\n}\n\nfunction completeQueryPages(values: unknown[]) {\n const pages = values\n .map(readPage)\n .sort((a, b) => a.paging.pageIndex - b.paging.pageIndex);\n const first = pages[0]?.paging;\n if (\n !first ||\n pages.length !== Math.max(1, Math.ceil(first.total / first.pageSize)) ||\n pages.some(\n ({ paging, issues }, i) =>\n paging.pageIndex !== i + 1 ||\n paging.total !== first.total ||\n paging.pageSize !== first.pageSize ||\n issues.length !==\n Math.min(first.pageSize, first.total - i * first.pageSize),\n )\n )\n throw new Error(\n \"Supply every Sonar issue search page exactly once, with consistent paging and issue counts.\",\n );\n return pages;\n}\n\nexport function completeSonarPages(\n values: unknown[],\n queryPageCounts?: number[],\n) {\n const counts = queryPageCounts ?? [values.length];\n if (counts.reduce((sum, count) => sum + count, 0) !== values.length)\n throw new Error(\"Sonar query page counts do not match the captured pages.\");\n let offset = 0;\n const pages = counts.flatMap((count) => {\n const query = values.slice(offset, offset + count);\n offset += count;\n return completeQueryPages(query);\n });\n const ids = new Set<string>();\n for (const { issues } of pages) {\n for (const issue of issues) {\n const id = text(issue[\"key\"]);\n if (id && ids.has(id))\n throw new Error(\n \"Sonar issue search pages overlap. Collect the selection again.\",\n );\n if (id) ids.add(id);\n }\n }\n return pages;\n}\n\nconst severityLevels: Readonly<Record<string, Severity>> = {\n BLOCKER: \"critical\",\n HIGH: \"high\",\n MEDIUM: \"medium\",\n LOW: \"low\",\n INFO: \"informational\",\n CRITICAL: \"high\",\n MAJOR: \"medium\",\n MINOR: \"low\",\n};\n\nfunction securitySeverity(issue: NativeRecord): Severity {\n const impacts = array(issue[\"impacts\"] ?? [], \"Sonar issue impacts\");\n const security = impacts.find(\n (impact) => isRecord(impact) && impact[\"softwareQuality\"] === \"SECURITY\",\n );\n if (\n !isRecord(security) &&\n (impacts.length || issue[\"type\"] !== \"VULNERABILITY\")\n )\n throw new Error(\n \"Sonar issue has no security impact or legacy vulnerability type.\",\n );\n const value = isRecord(security) ? security[\"severity\"] : issue[\"severity\"];\n return typeof value === \"string\" && Object.hasOwn(severityLevels, value)\n ? severityLevels[value]!\n : \"unknown\";\n}\n\nfunction relatedComponents(\n issue: NativeRecord,\n primary: string,\n components: Map<string, NativeRecord>,\n) {\n const keys = new Set([primary]);\n for (const value of array(issue[\"flows\"] ?? [], \"Sonar issue flows\")) {\n const flow = record(value, \"Sonar flow\");\n for (const entry of array(flow[\"locations\"], \"Sonar flow locations\")) {\n const location = record(entry, \"Sonar flow location\");\n const key = text(location[\"component\"]);\n if (key) keys.add(key);\n }\n }\n return Array.from(keys).flatMap((key) => components.get(key) ?? []);\n}\n\nfunction issueLink(\n server: string,\n project: string,\n id: string,\n branch?: string,\n pullRequest?: string,\n) {\n const link = new URL(\"project/issues\", server + \"/\");\n link.searchParams.set(\"id\", project);\n if (branch) link.searchParams.set(\"branch\", branch);\n if (pullRequest) link.searchParams.set(\"pullRequest\", pullRequest);\n link.searchParams.set(\"open\", id);\n link.searchParams.set(\"issues\", id);\n return link.href;\n}\n\nexport function normalizeSonarFindings(\n input: unknown,\n sourceRepositoryUrl: string,\n target: ExternalImportTarget = \"cloud\",\n) {\n const capture =\n isRecord(input) && \"format\" in input ? parseSonarCapture(input) : undefined;\n const repository = declaredScannerRepositoryUrl(\n capture?.repositoryUrl ?? sourceRepositoryUrl,\n \"Sonar\",\n target,\n );\n if (capture?.repositoryUrl && sourceRepositoryUrl) {\n const key = target === \"cloud\" ? cloudRepositoryUrlKey : repositoryUrlKey;\n if (\n key(repository) !==\n key(declaredScannerRepositoryUrl(sourceRepositoryUrl, \"Sonar\", target))\n )\n throw new Error(\n \"The Sonar capture repository does not match the declared source repository.\",\n );\n }\n const pages = completeSonarPages(\n capture?.pages ?? (Array.isArray(input) ? input : [input]),\n capture?.queryPageCounts,\n );\n const rows = pages.flatMap((page) =>\n page.issues.map((issue) => ({ issue, page })),\n );\n const scope: SonarScope = {};\n if (capture) mergeSonarScope(scope, capture);\n const hasUnscopedIssue = rows.some(\n ({ issue }) => !text(issue[\"branch\"]) && !text(issue[\"pullRequest\"]),\n );\n for (const { issue } of rows) {\n requiredText(issue[\"project\"], \"Sonar issue project\");\n mergeSonarIssueScope(scope, issue);\n }\n requireConsistentSonarRef(\n scope,\n !capture?.branch && !capture?.pullRequest && hasUnscopedIssue,\n );\n const context = {\n format: sonarFormat,\n ...(capture?.projectBase !== undefined && {\n projectBase: capture.projectBase,\n }),\n ...scope,\n repositoryUrl: repository,\n };\n return normalizeRecords(\n rows,\n ({ issue, page }, id) => {\n const component = requiredText(\n issue[\"component\"],\n \"Sonar issue component\",\n );\n const componentPath = relativePath(\n page.components.get(component)?.[\"path\"],\n );\n const base = capture?.projectBase;\n const path =\n componentPath && base !== undefined\n ? base\n ? `${base}/${componentPath}`\n : componentPath\n : null;\n const range =\n issue[\"textRange\"] == null\n ? null\n : record(issue[\"textRange\"], \"Sonar issue textRange\");\n const line = range?.[\"startLine\"] ?? issue[\"line\"] ?? null;\n const rule = requiredText(issue[\"rule\"], \"Sonar issue rule\");\n const descriptor = page.rules.get(rule);\n const name = text(descriptor?.[\"name\"]);\n const updated = text(issue[\"updateDate\"]);\n const severity = securitySeverity(issue);\n return validateExternalEvidence(\n {\n title: name ?? rule,\n severity,\n description: text(issue[\"message\"]),\n url: capture\n ? issueLink(\n capture.server,\n capture.project,\n id,\n scope.branch,\n scope.pullRequest,\n )\n : null,\n locations: path ? [{ path, line }] : [],\n branch: scope.branch ?? null,\n source_updated_at: updated\n ? Math.floor(Date.parse(updated) / 1000)\n : null,\n details: {\n kind: \"sast\",\n scanner_origin: \"SonarQube\",\n repository: { url: repository },\n source_status: text(issue[\"issueStatus\"]) ?? text(issue[\"status\"]),\n rule: { id: rule, name },\n code: { end_line: path ? (range?.[\"endLine\"] ?? null) : null },\n },\n source_data: structuredClone({\n ...context,\n issue,\n components: relatedComponents(issue, component, page.components),\n ...(descriptor && { rule: descriptor }),\n }),\n },\n target,\n );\n },\n ({ issue }) => requiredText(issue[\"key\"], \"Sonar issue key\"),\n target,\n { report: context },\n ) as ExternalFindings & { report: typeof context };\n}\n\nexport const readSonarFindings = scannerJsonReader(normalizeSonarFindings);\n"]}
@@ -52,6 +52,7 @@ export declare function prepareSonarImport(options: SonarImportOptions, dependen
52
52
  source_finding_id: string | null;
53
53
  reason: string;
54
54
  }[];
55
+ importId: string | undefined;
55
56
  };
56
57
  cloudError: string | undefined;
57
58
  cloud: undefined;
@@ -77,6 +78,7 @@ export declare function prepareSonarImport(options: SonarImportOptions, dependen
77
78
  source_finding_id: string | null;
78
79
  reason: string;
79
80
  }[];
81
+ importId: string | undefined;
80
82
  };
81
83
  cloud: import("./external-findings-publish.js").ExternalPublicationResult;
82
84
  cloudError: undefined;
@@ -102,6 +104,7 @@ export declare function prepareSonarImport(options: SonarImportOptions, dependen
102
104
  source_finding_id: string | null;
103
105
  reason: string;
104
106
  }[];
107
+ importId: string | undefined;
105
108
  };
106
109
  cloudError: string;
107
110
  cloud: import("./external-findings-publish.js").ExternalPublicationResult | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"sonar-import.d.ts","sourceRoot":"","sources":["../src/sonar-import.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAQ1D,OAAO,EAKL,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAEhC,MAAM,gCAAgC,CAAC;AAqBxC,UAAU,kBAAkB;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;CACd;AA8ED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,+BAA+B,GAAG;IAC9C,OAAO,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACpC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+QF"}
1
+ {"version":3,"file":"sonar-import.d.ts","sourceRoot":"","sources":["../src/sonar-import.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EAML,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAChC,MAAM,gCAAgC,CAAC;AAyBxC,UAAU,kBAAkB;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;CACd;AAkDD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,+BAA+B,GAAG;IAC9C,OAAO,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACpC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+SF"}
@@ -1,39 +1,21 @@
1
1
  import { hash } from "node:crypto";
2
- import { lstat, open, readlink, realpath, stat } from "node:fs/promises";
2
+ import { lstat, open, readFile, readlink, realpath, stat, } from "node:fs/promises";
3
3
  import { basename, dirname, join } from "node:path";
4
4
  import { resolveConfigPath } from "./config-path.js";
5
5
  import { collectSonarIssues } from "./sonar-collector.js";
6
6
  import { normalizeSonarFindings, parseSonarCapture } from "./sonar-findings.js";
7
7
  import { configuredFetchRemotes, prepareLocalImport, } from "./external-findings-local.js";
8
+ import { prepareStoredFindingsPublication } from "./stored-findings-publication.js";
8
9
  import { commandGitProtectionRoots } from "./local-git-metadata.js";
9
- import { ExternalPublicationError, externalPublicationStateDirectory, prepareNormalizedExternalPublication, writeAtomicJson, } from "./external-findings-publish.js";
10
+ import { cloudReviewDigest, ExternalPublicationError, externalPublicationStateDirectory, prepareNormalizedPublication, writeAtomicJson, } from "./external-findings-publish.js";
10
11
  import { readScannerJson, stableId } from "./scanner-import.js";
11
12
  import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
12
13
  import { canonicalConfigPath, codexSecurityStateDirectory, preparePersistentOutputRoot, requirePrivateDirectory, requireSecureOutputAncestry, requireOutputOutsideRepositories, workbenchEnvironment, } from "./runtime.js";
13
- import { gitMarkerRoot, normalizeRepository } from "./targets.js";
14
+ import { gitMarkerRoot, normalizeRepository, nullIfMissingFile, } from "./targets.js";
14
15
  import { errorMessage } from "./errors.js";
15
16
  import { canonicalJson } from "./record.js";
16
17
  import { repositoryUrlKey, validateExternalReport, } from "./external-import-contract.js";
17
18
  import { notify } from "./value.js";
18
- function cloudReviewDigest(preview, checkout) {
19
- return hash("sha256", canonicalJson({
20
- checkout,
21
- api: preview.cloudApiUrl,
22
- account: preview.accountId,
23
- repository: preview.destination.id,
24
- connector: preview.destination.repo_connector_id,
25
- url: preview.destination.url,
26
- reset: preview.destination.reset_marker,
27
- source: preview.source,
28
- privateImport: preview.privateImport,
29
- items: preview.requests.flatMap((request) => request.items.map((item) => [
30
- item.source_finding_id,
31
- item.expected_version,
32
- request.repository.environment_id,
33
- item.evidence,
34
- ])),
35
- }));
36
- }
37
19
  async function readCapture(input) {
38
20
  if (!(await stat(input)).isFile())
39
21
  return { path: input, raw: await readScannerJson(input) };
@@ -198,8 +180,13 @@ export async function prepareSonarImport(options, dependencies) {
198
180
  ]);
199
181
  const source = { provider: "sonar", sourceKey };
200
182
  const local = await prepareLocalImport(findings, { repository, ...source, sourceRepositoryUrl }, { environment, signal }, [{ url: repositoryUrl }], [], fetchRemotes);
183
+ // Record the selection before submitting so a lost response can be replayed
184
+ // with the workbench checkpoint for these exact finding versions.
185
+ const selectionPath = `${localCapture}.import`;
186
+ const storedPublication = async (importId, ifCurrent = false) => (await prepareStoredFindingsPublication({ repository, importId, ifCurrent }, { repository: repositoryUrl }, dependencies)).groups[0];
201
187
  let cloud;
202
188
  let cloudError;
189
+ const reviewedCapturePath = (preview) => join(root, `${evidenceDigest}.${checkout}.${cloudReviewDigest(preview, repository)}.json`);
203
190
  if (options.to === "cloud" && local.preview.read > 0) {
204
191
  const reviewedCheckout = retained?.[2] === checkout && Boolean(retained?.[3]);
205
192
  const reviewError = "Cloud publication requires the reviewed capture for this checkout, account, repository and environment. Run import sonar with this capture and --to cloud --dry-run, then pass the returned capture path with --to cloud --yes.";
@@ -211,9 +198,13 @@ export async function prepareSonarImport(options, dependencies) {
211
198
  const bindingError = "This checkout has no matching Git remote. Verify the Sonar project's repository and pass --source-repository-url to preview Cloud publication.";
212
199
  if (!confirmedRepository && !reviewedCheckout)
213
200
  throw new Error(bindingError);
214
- const prepared = await prepareNormalizedExternalPublication(normalizeSonarFindings(report, options.sourceRepositoryUrl ?? "", "cloud"), { repository: repositoryUrl, ...source }, dependencies);
215
- const review = cloudReviewDigest(prepared.preview, repository);
216
- const reviewedCapture = join(root, `${evidenceDigest}.${checkout}.${review}.json`);
201
+ const savedId = await readFile(selectionPath, "utf8").catch(nullIfMissingFile);
202
+ const previous = savedId === null
203
+ ? undefined
204
+ : await storedPublication(JSON.parse(savedId), true);
205
+ const prepared = previous ??
206
+ (await prepareNormalizedPublication(normalizeSonarFindings(report, options.sourceRepositoryUrl ?? "", "cloud"), { repository: repositoryUrl, ...source }, dependencies, "preview"));
207
+ const reviewedCapture = reviewedCapturePath(prepared.preview);
217
208
  if (input !== reviewedCapture) {
218
209
  if (!confirmedRepository)
219
210
  throw new Error(bindingError);
@@ -222,7 +213,7 @@ export async function prepareSonarImport(options, dependencies) {
222
213
  await writeAtomicJson(reviewedCapture, report);
223
214
  }
224
215
  capture = reviewedCapture;
225
- cloud = prepared;
216
+ cloud = prepared.preview;
226
217
  }
227
218
  catch (error) {
228
219
  signal?.throwIfAborted();
@@ -243,18 +234,25 @@ export async function prepareSonarImport(options, dependencies) {
243
234
  return {
244
235
  info,
245
236
  local: local.preview,
246
- cloud: cloud?.preview,
237
+ cloud,
247
238
  cloudError,
248
239
  async import() {
249
240
  signal?.throwIfAborted();
250
- const { counts, ready, excluded } = await local.import();
251
- const saved = { ...info, local: { counts, ready, excluded } };
241
+ const { counts, ready, excluded, importId } = await local.import();
242
+ const saved = { ...info, local: { counts, ready, excluded, importId } };
252
243
  if (!cloud)
253
244
  return { ...saved, cloudError, cloud: undefined };
254
245
  try {
246
+ if (!importId)
247
+ throw new Error("No stored Sonar import to publish.");
248
+ const publication = await storedPublication(importId);
249
+ if (!publication ||
250
+ reviewedCapturePath(publication.preview) !== capture)
251
+ throw new Error("The stored findings or Cloud destination have changed. Preview the Sonar capture again with --to cloud --dry-run.");
252
+ await writeAtomicJson(selectionPath, importId);
255
253
  return {
256
254
  ...saved,
257
- cloud: await cloud.publish(),
255
+ cloud: await publication.publish(publication.reviewId),
258
256
  cloudError: undefined,
259
257
  };
260
258
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sonar-import.js","sourceRoot":"","sources":["../src/sonar-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO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KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC;gBAC9D,IAAI,CAAC,KAAK;oBAAE,OAAO,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;gBAC9D,IAAI,CAAC;oBACH,OAAO;wBACL,GAAG,KAAK;wBACR,KAAK,EAAE,MAAM,KAAK,CAAC,OAAO,EAAE;wBAC5B,UAAU,EAAE,SAAS;qBACtB,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO;wBACL,GAAG,KAAK;wBACR,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC;wBAC/B,KAAK,EACH,KAAK,YAAY,wBAAwB;4BACvC,CAAC,CAAC,KAAK,CAAC,MAAM;4BACd,CAAC,CAAC,SAAS;qBAChB,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAClD,CAAC;AACH,CAAC","sourcesContent":["import { hash } from \"node:crypto\";\nimport { lstat, open, readlink, realpath, stat } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { resolveConfigPath } from \"./config-path.js\";\nimport { collectSonarIssues } from \"./sonar-collector.js\";\nimport { normalizeSonarFindings, parseSonarCapture } from \"./sonar-findings.js\";\nimport {\n configuredFetchRemotes,\n type ConfiguredFetchRemote,\n prepareLocalImport,\n} from \"./external-findings-local.js\";\nimport { commandGitProtectionRoots } from \"./local-git-metadata.js\";\nimport {\n ExternalPublicationError,\n externalPublicationStateDirectory,\n prepareNormalizedExternalPublication,\n writeAtomicJson,\n type ExternalPublicationDependencies,\n type ExternalPublicationPreview,\n type PreparedExternalPublication,\n} from \"./external-findings-publish.js\";\nimport { readScannerJson, stableId } from \"./scanner-import.js\";\nimport { declaredScannerRepositoryUrl } from \"./scanner-repository-url.js\";\nimport {\n canonicalConfigPath,\n codexSecurityStateDirectory,\n preparePersistentOutputRoot,\n requirePrivateDirectory,\n requireSecureOutputAncestry,\n requireOutputOutsideRepositories,\n workbenchEnvironment,\n} from \"./runtime.js\";\nimport { gitMarkerRoot, normalizeRepository } from \"./targets.js\";\nimport { errorMessage } from \"./errors.js\";\nimport { canonicalJson } from \"./record.js\";\nimport {\n repositoryUrlKey,\n validateExternalReport,\n} from \"./external-import-contract.js\";\nimport { notify } from \"./value.js\";\n\ninterface SonarImportOptions {\n cwd: string;\n capture?: string | undefined;\n project?: string | undefined;\n branch?: string | undefined;\n pullRequest?: string | undefined;\n issueKeys: string[];\n sourceRepositoryUrl?: string | undefined;\n to: \"local\" | \"cloud\";\n dryRun: boolean;\n yes: boolean;\n}\n\nfunction cloudReviewDigest(\n preview: ExternalPublicationPreview,\n checkout: string,\n) {\n return hash(\n \"sha256\",\n canonicalJson({\n checkout,\n api: preview.cloudApiUrl,\n account: preview.accountId,\n repository: preview.destination.id,\n connector: preview.destination.repo_connector_id,\n url: preview.destination.url,\n reset: preview.destination.reset_marker,\n source: preview.source,\n privateImport: preview.privateImport,\n items: preview.requests.flatMap((request) =>\n request.items.map((item) => [\n item.source_finding_id,\n item.expected_version,\n request.repository.environment_id,\n item.evidence,\n ]),\n ),\n }),\n );\n}\n\nasync function readCapture(input: string) {\n if (!(await stat(input)).isFile())\n return { path: input, raw: await readScannerJson(input) };\n if (process.platform === \"linux\") {\n const file = await open(input, \"r\");\n try {\n // Use the same open file for its bytes and its retained evidence name.\n // An unlinked descriptor is still readable, even if its name is reused.\n const name = await readlink(`/proc/self/fd/${file.fd}`).catch(\n async (error: unknown) => {\n const opened = await file.stat({ bigint: true });\n if (opened.nlink === 0n)\n throw new Error(\n `Could not verify the unlinked Sonar capture's name: ${errorMessage(error)}. Select a named JSON file and retry.`,\n { cause: error },\n );\n const path = await realpath(input);\n const named = await stat(path, { bigint: true });\n if (named.ino !== opened.ino || named.dev !== opened.dev)\n throw new Error(\n \"The selected Sonar capture changed while being opened. Preview it again.\",\n { cause: error },\n );\n return path;\n },\n );\n let path = name;\n const deletedSuffix = \" (deleted)\";\n if (name.endsWith(deletedSuffix)) {\n // The suffix can also be literal. Only ascribe the former name to\n // this descriptor when the displayed name does not identify it.\n const opened = await file.stat({ bigint: true });\n const named =\n opened.nlink > 0n\n ? await stat(name, { bigint: true }).catch(() => undefined)\n : undefined;\n if (named?.ino !== opened.ino || named.dev !== opened.dev)\n path = name.slice(0, -deletedSuffix.length);\n }\n return { path, raw: await readScannerJson(file) };\n } finally {\n await file.close();\n }\n }\n const path = await realpath(input);\n return { path, raw: await readScannerJson(path) };\n}\n\nexport async function prepareSonarImport(\n options: SonarImportOptions,\n dependencies: ExternalPublicationDependencies & {\n collect?: typeof collectSonarIssues;\n onCapture?: (path: string) => void;\n },\n) {\n const { signal, environment = process.env } = dependencies;\n signal?.throwIfAborted();\n if (\n options.capture &&\n (options.project ||\n options.branch ||\n options.pullRequest ||\n options.issueKeys.length)\n )\n throw new Error(\n \"A saved capture already identifies the selected Sonar project, ref and issues. Omit the live selection options.\",\n );\n const repository =\n (await gitMarkerRoot(options.cwd, signal, \"nearest\")) ??\n (await normalizeRepository(options.cwd, signal));\n const selectedPath =\n options.capture && resolveConfigPath(options.cwd, options.capture);\n // Resolve directory aliases while keeping the evidence and approval digests\n // in the filename selected by the caller.\n const input =\n selectedPath &&\n join(await realpath(dirname(selectedPath)), basename(selectedPath));\n const captureData = input ? await readCapture(input) : undefined;\n const raw = captureData\n ? captureData.raw\n : await (dependencies.collect ?? collectSonarIssues)({\n cwd: options.cwd,\n project: options.project,\n sourceRepositoryUrl: options.sourceRepositoryUrl,\n branch: options.branch,\n pullRequest: options.pullRequest,\n issueKeys: options.issueKeys.length ? options.issueKeys : undefined,\n environment,\n signal,\n });\n let report = parseSonarCapture(raw);\n validateExternalReport(report);\n const configuredState = codexSecurityStateDirectory(environment);\n const protectedRoots = [\n repository,\n ...(await commandGitProtectionRoots(options.cwd, environment, signal)),\n ];\n requireOutputOutsideRepositories(protectedRoots, configuredState, \"runtime\");\n const state = await canonicalConfigPath(configuredState);\n const destination = await canonicalConfigPath(\n join(state, \"imports\", \"sonar\"),\n );\n requireOutputOutsideRepositories(protectedRoots, state, \"runtime\");\n requireOutputOutsideRepositories(protectedRoots, destination, \"runtime\");\n await requireSecureOutputAncestry(destination);\n const root = await preparePersistentOutputRoot(state, \"imports\", \"sonar\");\n await requirePrivateDirectory(\n await lstat(root),\n root,\n \"Sonar capture directory\",\n );\n const retainedName = (path: string | undefined) =>\n path && dirname(path) === root\n ? /^([a-f0-9]{64})(?:\\.([a-f0-9]{64})(?:\\.([a-f0-9]{64}))?)?\\.json$/u.exec(\n basename(path),\n )\n : undefined;\n const retained = retainedName(input);\n const target = retainedName(captureData?.path);\n if (retained || target) {\n const digest = hash(\"sha256\", JSON.stringify(raw));\n if (\n (retained && retained[1] !== digest) ||\n (target && target[1] !== digest)\n )\n throw new Error(\n \"The saved Sonar capture has changed. Preview a fresh copy of the Sonar evidence.\",\n );\n }\n if (!report.repositoryUrl && options.sourceRepositoryUrl) {\n report = parseSonarCapture({\n ...report,\n repositoryUrl: declaredScannerRepositoryUrl(\n options.sourceRepositoryUrl,\n \"Sonar\",\n \"local\",\n ),\n });\n }\n const evidenceDigest = hash(\"sha256\", JSON.stringify(report));\n async function recoverLiveSelection(error: unknown): Promise<never> {\n if (!input) {\n // Keep the collected bytes replayable without marking them reviewed.\n const recovery = join(root, `${evidenceDigest}.json`);\n try {\n await writeAtomicJson(recovery, report);\n } catch (recoveryError) {\n throw new Error(\n `${errorMessage(error)}. Could not save the Sonar capture: ${errorMessage(recoveryError)}`,\n { cause: error },\n );\n }\n notify(() => dependencies.onCapture?.(recovery));\n }\n throw error;\n }\n let checkout = hash(\"sha256\", repository);\n let sourceRepositoryUrl = options.sourceRepositoryUrl;\n let fetchRemotes: ConfiguredFetchRemote[] | undefined;\n // A portable report can name a repository. Only a reviewed capture can\n // restore the operator's mapping to this checkout's effective fetch URLs.\n const mappedUrl =\n sourceRepositoryUrl ??\n (retained?.[1] === evidenceDigest && retained[2] && retained[2] !== checkout\n ? report.repositoryUrl\n : undefined);\n if (mappedUrl) {\n fetchRemotes = await configuredFetchRemotes(\n repository,\n \"sonar\",\n protectedRoots,\n workbenchEnvironment(environment),\n signal,\n ).catch(recoverLiveSelection);\n const mapped = hash(\n \"sha256\",\n canonicalJson([repository, repositoryUrlKey(mappedUrl), fetchRemotes]),\n );\n if (sourceRepositoryUrl || mapped === retained?.[2]) {\n sourceRepositoryUrl = mappedUrl;\n checkout = mapped;\n }\n }\n const localCapture = join(root, `${evidenceDigest}.${checkout}.json`);\n if (\n options.to === \"local\" &&\n options.yes &&\n !options.dryRun &&\n input &&\n (retained?.[1] !== evidenceDigest || retained[2] !== checkout)\n ) {\n throw new Error(\n \"This Sonar capture has not been reviewed for this checkout. Run import sonar with this capture and --dry-run here, then confirm the returned capture.\",\n );\n }\n let capture =\n options.to === \"cloud\" &&\n input &&\n retained?.[1] === evidenceDigest &&\n retained?.[2] === checkout\n ? input\n : localCapture;\n if (capture !== input)\n await writeAtomicJson(capture, report).catch(recoverLiveSelection);\n try {\n const repositoryUrl = report.repositoryUrl ?? options.sourceRepositoryUrl;\n if (!repositoryUrl) {\n throw new Error(\n \"Sonar did not supply a repository binding. Verify the project's repository and rerun with the saved capture and --source-repository-url.\",\n );\n }\n const findings = normalizeSonarFindings(\n report,\n options.sourceRepositoryUrl ?? \"\",\n \"local\",\n );\n const { branch, pullRequest } = findings.report;\n const sourceKey = stableId(\"sonar\", [\n report.server,\n report.organization,\n report.project,\n branch ?? null,\n pullRequest ?? null,\n ]);\n const source = { provider: \"sonar\", sourceKey } as const;\n const local = await prepareLocalImport(\n findings,\n { repository, ...source, sourceRepositoryUrl },\n { environment, signal },\n [{ url: repositoryUrl }],\n [],\n fetchRemotes,\n );\n let cloud: PreparedExternalPublication | undefined;\n let cloudError: string | undefined;\n if (options.to === \"cloud\" && local.preview.read > 0) {\n const reviewedCheckout =\n retained?.[2] === checkout && Boolean(retained?.[3]);\n const reviewError =\n \"Cloud publication requires the reviewed capture for this checkout, account, repository and environment. Run import sonar with this capture and --to cloud --dry-run, then pass the returned capture path with --to cloud --yes.\";\n if (options.yes && !options.dryRun && !reviewedCheckout)\n throw new Error(reviewError);\n try {\n requireOutputOutsideRepositories(\n protectedRoots,\n await canonicalConfigPath(\n externalPublicationStateDirectory(environment),\n ),\n \"runtime\",\n );\n const confirmedRepository =\n local.matchesRepositoryRemote || sourceRepositoryUrl;\n const bindingError =\n \"This checkout has no matching Git remote. Verify the Sonar project's repository and pass --source-repository-url to preview Cloud publication.\";\n if (!confirmedRepository && !reviewedCheckout)\n throw new Error(bindingError);\n const prepared = await prepareNormalizedExternalPublication(\n normalizeSonarFindings(\n report,\n options.sourceRepositoryUrl ?? \"\",\n \"cloud\",\n ),\n { repository: repositoryUrl, ...source },\n dependencies,\n );\n const review = cloudReviewDigest(prepared.preview, repository);\n const reviewedCapture = join(\n root,\n `${evidenceDigest}.${checkout}.${review}.json`,\n );\n if (input !== reviewedCapture) {\n if (!confirmedRepository) throw new Error(bindingError);\n if (options.yes && !options.dryRun) throw new Error(reviewError);\n await writeAtomicJson(reviewedCapture, report);\n }\n capture = reviewedCapture;\n cloud = prepared;\n } catch (error) {\n signal?.throwIfAborted();\n cloudError = errorMessage(error);\n }\n }\n const info = {\n capture,\n repository,\n repositoryUrl,\n sourceKey,\n server: report.server,\n organization: report.organization,\n project: report.project,\n branch,\n pullRequest,\n };\n return {\n info,\n local: local.preview,\n cloud: cloud?.preview,\n cloudError,\n async import() {\n signal?.throwIfAborted();\n const { counts, ready, excluded } = await local.import();\n const saved = { ...info, local: { counts, ready, excluded } };\n if (!cloud) return { ...saved, cloudError, cloud: undefined };\n try {\n return {\n ...saved,\n cloud: await cloud.publish(),\n cloudError: undefined,\n };\n } catch (error) {\n return {\n ...saved,\n cloudError: errorMessage(error),\n cloud:\n error instanceof ExternalPublicationError\n ? error.result\n : undefined,\n };\n }\n },\n };\n } finally {\n notify(() => dependencies.onCapture?.(capture));\n }\n}\n"]}
1
+ {"version":3,"file":"sonar-import.js","sourceRoot":"","sources":["../src/sonar-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,IAAI,GACL,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EACL,sBAAsB,EAEtB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AACpF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,iCAAiC,EACjC,4BAA4B,EAC5B,eAAe,GAGhB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,2BAA2B,EAC3B,uBAAuB,EACvB,2BAA2B,EAC3B,gCAAgC,EAChC,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,aA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,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO;wBACL,GAAG,KAAK;wBACR,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC;wBAC/B,KAAK,EACH,KAAK,YAAY,wBAAwB;4BACvC,CAAC,CAAC,KAAK,CAAC,MAAM;4BACd,CAAC,CAAC,SAAS;qBAChB,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAClD,CAAC;AACH,CAAC","sourcesContent":["import { hash } from \"node:crypto\";\nimport {\n lstat,\n open,\n readFile,\n readlink,\n realpath,\n stat,\n} from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { resolveConfigPath } from \"./config-path.js\";\nimport { collectSonarIssues } from \"./sonar-collector.js\";\nimport { normalizeSonarFindings, parseSonarCapture } from \"./sonar-findings.js\";\nimport {\n configuredFetchRemotes,\n type ConfiguredFetchRemote,\n prepareLocalImport,\n} from \"./external-findings-local.js\";\nimport { prepareStoredFindingsPublication } from \"./stored-findings-publication.js\";\nimport { commandGitProtectionRoots } from \"./local-git-metadata.js\";\nimport {\n cloudReviewDigest,\n ExternalPublicationError,\n externalPublicationStateDirectory,\n prepareNormalizedPublication,\n writeAtomicJson,\n type ExternalPublicationDependencies,\n type ExternalPublicationPreview,\n} from \"./external-findings-publish.js\";\nimport { readScannerJson, stableId } from \"./scanner-import.js\";\nimport { declaredScannerRepositoryUrl } from \"./scanner-repository-url.js\";\nimport {\n canonicalConfigPath,\n codexSecurityStateDirectory,\n preparePersistentOutputRoot,\n requirePrivateDirectory,\n requireSecureOutputAncestry,\n requireOutputOutsideRepositories,\n workbenchEnvironment,\n} from \"./runtime.js\";\nimport {\n gitMarkerRoot,\n normalizeRepository,\n nullIfMissingFile,\n} from \"./targets.js\";\nimport { errorMessage } from \"./errors.js\";\nimport { canonicalJson } from \"./record.js\";\nimport {\n repositoryUrlKey,\n validateExternalReport,\n} from \"./external-import-contract.js\";\nimport { notify } from \"./value.js\";\n\ninterface SonarImportOptions {\n cwd: string;\n capture?: string | undefined;\n project?: string | undefined;\n branch?: string | undefined;\n pullRequest?: string | undefined;\n issueKeys: string[];\n sourceRepositoryUrl?: string | undefined;\n to: \"local\" | \"cloud\";\n dryRun: boolean;\n yes: boolean;\n}\n\nasync function readCapture(input: string) {\n if (!(await stat(input)).isFile())\n return { path: input, raw: await readScannerJson(input) };\n if (process.platform === \"linux\") {\n const file = await open(input, \"r\");\n try {\n // Use the same open file for its bytes and its retained evidence name.\n // An unlinked descriptor is still readable, even if its name is reused.\n const name = await readlink(`/proc/self/fd/${file.fd}`).catch(\n async (error: unknown) => {\n const opened = await file.stat({ bigint: true });\n if (opened.nlink === 0n)\n throw new Error(\n `Could not verify the unlinked Sonar capture's name: ${errorMessage(error)}. Select a named JSON file and retry.`,\n { cause: error },\n );\n const path = await realpath(input);\n const named = await stat(path, { bigint: true });\n if (named.ino !== opened.ino || named.dev !== opened.dev)\n throw new Error(\n \"The selected Sonar capture changed while being opened. Preview it again.\",\n { cause: error },\n );\n return path;\n },\n );\n let path = name;\n const deletedSuffix = \" (deleted)\";\n if (name.endsWith(deletedSuffix)) {\n // The suffix can also be literal. Only ascribe the former name to\n // this descriptor when the displayed name does not identify it.\n const opened = await file.stat({ bigint: true });\n const named =\n opened.nlink > 0n\n ? await stat(name, { bigint: true }).catch(() => undefined)\n : undefined;\n if (named?.ino !== opened.ino || named.dev !== opened.dev)\n path = name.slice(0, -deletedSuffix.length);\n }\n return { path, raw: await readScannerJson(file) };\n } finally {\n await file.close();\n }\n }\n const path = await realpath(input);\n return { path, raw: await readScannerJson(path) };\n}\n\nexport async function prepareSonarImport(\n options: SonarImportOptions,\n dependencies: ExternalPublicationDependencies & {\n collect?: typeof collectSonarIssues;\n onCapture?: (path: string) => void;\n },\n) {\n const { signal, environment = process.env } = dependencies;\n signal?.throwIfAborted();\n if (\n options.capture &&\n (options.project ||\n options.branch ||\n options.pullRequest ||\n options.issueKeys.length)\n )\n throw new Error(\n \"A saved capture already identifies the selected Sonar project, ref and issues. Omit the live selection options.\",\n );\n const repository =\n (await gitMarkerRoot(options.cwd, signal, \"nearest\")) ??\n (await normalizeRepository(options.cwd, signal));\n const selectedPath =\n options.capture && resolveConfigPath(options.cwd, options.capture);\n // Resolve directory aliases while keeping the evidence and approval digests\n // in the filename selected by the caller.\n const input =\n selectedPath &&\n join(await realpath(dirname(selectedPath)), basename(selectedPath));\n const captureData = input ? await readCapture(input) : undefined;\n const raw = captureData\n ? captureData.raw\n : await (dependencies.collect ?? collectSonarIssues)({\n cwd: options.cwd,\n project: options.project,\n sourceRepositoryUrl: options.sourceRepositoryUrl,\n branch: options.branch,\n pullRequest: options.pullRequest,\n issueKeys: options.issueKeys.length ? options.issueKeys : undefined,\n environment,\n signal,\n });\n let report = parseSonarCapture(raw);\n validateExternalReport(report);\n const configuredState = codexSecurityStateDirectory(environment);\n const protectedRoots = [\n repository,\n ...(await commandGitProtectionRoots(options.cwd, environment, signal)),\n ];\n requireOutputOutsideRepositories(protectedRoots, configuredState, \"runtime\");\n const state = await canonicalConfigPath(configuredState);\n const destination = await canonicalConfigPath(\n join(state, \"imports\", \"sonar\"),\n );\n requireOutputOutsideRepositories(protectedRoots, state, \"runtime\");\n requireOutputOutsideRepositories(protectedRoots, destination, \"runtime\");\n await requireSecureOutputAncestry(destination);\n const root = await preparePersistentOutputRoot(state, \"imports\", \"sonar\");\n await requirePrivateDirectory(\n await lstat(root),\n root,\n \"Sonar capture directory\",\n );\n const retainedName = (path: string | undefined) =>\n path && dirname(path) === root\n ? /^([a-f0-9]{64})(?:\\.([a-f0-9]{64})(?:\\.([a-f0-9]{64}))?)?\\.json$/u.exec(\n basename(path),\n )\n : undefined;\n const retained = retainedName(input);\n const target = retainedName(captureData?.path);\n if (retained || target) {\n const digest = hash(\"sha256\", JSON.stringify(raw));\n if (\n (retained && retained[1] !== digest) ||\n (target && target[1] !== digest)\n )\n throw new Error(\n \"The saved Sonar capture has changed. Preview a fresh copy of the Sonar evidence.\",\n );\n }\n if (!report.repositoryUrl && options.sourceRepositoryUrl) {\n report = parseSonarCapture({\n ...report,\n repositoryUrl: declaredScannerRepositoryUrl(\n options.sourceRepositoryUrl,\n \"Sonar\",\n \"local\",\n ),\n });\n }\n const evidenceDigest = hash(\"sha256\", JSON.stringify(report));\n async function recoverLiveSelection(error: unknown): Promise<never> {\n if (!input) {\n // Keep the collected bytes replayable without marking them reviewed.\n const recovery = join(root, `${evidenceDigest}.json`);\n try {\n await writeAtomicJson(recovery, report);\n } catch (recoveryError) {\n throw new Error(\n `${errorMessage(error)}. Could not save the Sonar capture: ${errorMessage(recoveryError)}`,\n { cause: error },\n );\n }\n notify(() => dependencies.onCapture?.(recovery));\n }\n throw error;\n }\n let checkout = hash(\"sha256\", repository);\n let sourceRepositoryUrl = options.sourceRepositoryUrl;\n let fetchRemotes: ConfiguredFetchRemote[] | undefined;\n // A portable report can name a repository. Only a reviewed capture can\n // restore the operator's mapping to this checkout's effective fetch URLs.\n const mappedUrl =\n sourceRepositoryUrl ??\n (retained?.[1] === evidenceDigest && retained[2] && retained[2] !== checkout\n ? report.repositoryUrl\n : undefined);\n if (mappedUrl) {\n fetchRemotes = await configuredFetchRemotes(\n repository,\n \"sonar\",\n protectedRoots,\n workbenchEnvironment(environment),\n signal,\n ).catch(recoverLiveSelection);\n const mapped = hash(\n \"sha256\",\n canonicalJson([repository, repositoryUrlKey(mappedUrl), fetchRemotes]),\n );\n if (sourceRepositoryUrl || mapped === retained?.[2]) {\n sourceRepositoryUrl = mappedUrl;\n checkout = mapped;\n }\n }\n const localCapture = join(root, `${evidenceDigest}.${checkout}.json`);\n if (\n options.to === \"local\" &&\n options.yes &&\n !options.dryRun &&\n input &&\n (retained?.[1] !== evidenceDigest || retained[2] !== checkout)\n ) {\n throw new Error(\n \"This Sonar capture has not been reviewed for this checkout. Run import sonar with this capture and --dry-run here, then confirm the returned capture.\",\n );\n }\n let capture =\n options.to === \"cloud\" &&\n input &&\n retained?.[1] === evidenceDigest &&\n retained?.[2] === checkout\n ? input\n : localCapture;\n if (capture !== input)\n await writeAtomicJson(capture, report).catch(recoverLiveSelection);\n try {\n const repositoryUrl = report.repositoryUrl ?? options.sourceRepositoryUrl;\n if (!repositoryUrl) {\n throw new Error(\n \"Sonar did not supply a repository binding. Verify the project's repository and rerun with the saved capture and --source-repository-url.\",\n );\n }\n const findings = normalizeSonarFindings(\n report,\n options.sourceRepositoryUrl ?? \"\",\n \"local\",\n );\n const { branch, pullRequest } = findings.report;\n const sourceKey = stableId(\"sonar\", [\n report.server,\n report.organization,\n report.project,\n branch ?? null,\n pullRequest ?? null,\n ]);\n const source = { provider: \"sonar\", sourceKey } as const;\n const local = await prepareLocalImport(\n findings,\n { repository, ...source, sourceRepositoryUrl },\n { environment, signal },\n [{ url: repositoryUrl }],\n [],\n fetchRemotes,\n );\n // Record the selection before submitting so a lost response can be replayed\n // with the workbench checkpoint for these exact finding versions.\n const selectionPath = `${localCapture}.import`;\n const storedPublication = async (importId: string, ifCurrent = false) =>\n (\n await prepareStoredFindingsPublication(\n { repository, importId, ifCurrent },\n { repository: repositoryUrl },\n dependencies,\n )\n ).groups[0];\n let cloud: ExternalPublicationPreview | undefined;\n let cloudError: string | undefined;\n const reviewedCapturePath = (preview: ExternalPublicationPreview) =>\n join(\n root,\n `${evidenceDigest}.${checkout}.${cloudReviewDigest(preview, repository)}.json`,\n );\n if (options.to === \"cloud\" && local.preview.read > 0) {\n const reviewedCheckout =\n retained?.[2] === checkout && Boolean(retained?.[3]);\n const reviewError =\n \"Cloud publication requires the reviewed capture for this checkout, account, repository and environment. Run import sonar with this capture and --to cloud --dry-run, then pass the returned capture path with --to cloud --yes.\";\n if (options.yes && !options.dryRun && !reviewedCheckout)\n throw new Error(reviewError);\n try {\n requireOutputOutsideRepositories(\n protectedRoots,\n await canonicalConfigPath(\n externalPublicationStateDirectory(environment),\n ),\n \"runtime\",\n );\n const confirmedRepository =\n local.matchesRepositoryRemote || sourceRepositoryUrl;\n const bindingError =\n \"This checkout has no matching Git remote. Verify the Sonar project's repository and pass --source-repository-url to preview Cloud publication.\";\n if (!confirmedRepository && !reviewedCheckout)\n throw new Error(bindingError);\n const savedId = await readFile(selectionPath, \"utf8\").catch(\n nullIfMissingFile,\n );\n const previous =\n savedId === null\n ? undefined\n : await storedPublication(JSON.parse(savedId), true);\n const prepared =\n previous ??\n (await prepareNormalizedPublication(\n normalizeSonarFindings(\n report,\n options.sourceRepositoryUrl ?? \"\",\n \"cloud\",\n ),\n { repository: repositoryUrl, ...source },\n dependencies,\n \"preview\",\n ));\n const reviewedCapture = reviewedCapturePath(prepared.preview);\n if (input !== reviewedCapture) {\n if (!confirmedRepository) throw new Error(bindingError);\n if (options.yes && !options.dryRun) throw new Error(reviewError);\n await writeAtomicJson(reviewedCapture, report);\n }\n capture = reviewedCapture;\n cloud = prepared.preview;\n } catch (error) {\n signal?.throwIfAborted();\n cloudError = errorMessage(error);\n }\n }\n const info = {\n capture,\n repository,\n repositoryUrl,\n sourceKey,\n server: report.server,\n organization: report.organization,\n project: report.project,\n branch,\n pullRequest,\n };\n return {\n info,\n local: local.preview,\n cloud,\n cloudError,\n async import() {\n signal?.throwIfAborted();\n const { counts, ready, excluded, importId } = await local.import();\n const saved = { ...info, local: { counts, ready, excluded, importId } };\n if (!cloud) return { ...saved, cloudError, cloud: undefined };\n try {\n if (!importId) throw new Error(\"No stored Sonar import to publish.\");\n const publication = await storedPublication(importId);\n if (\n !publication ||\n reviewedCapturePath(publication.preview) !== capture\n )\n throw new Error(\n \"The stored findings or Cloud destination have changed. Preview the Sonar capture again with --to cloud --dry-run.\",\n );\n await writeAtomicJson(selectionPath, importId);\n return {\n ...saved,\n cloud: await publication.publish(publication.reviewId),\n cloudError: undefined,\n };\n } catch (error) {\n return {\n ...saved,\n cloudError: errorMessage(error),\n cloud:\n error instanceof ExternalPublicationError\n ? error.result\n : undefined,\n };\n }\n },\n };\n } finally {\n notify(() => dependencies.onCapture?.(capture));\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { StoredExternalFinding } from "./external-findings-local.js";
2
+ import type { ExternalFindings, ExternalSourceRepository } from "./external-findings.js";
3
+ type StoredRow = Pick<StoredExternalFinding, "provider" | "sourceFindingId" | "evidence">;
4
+ export declare function projectStoredFinding(row: StoredRow, sourceRepositories: readonly ExternalSourceRepository[], inspectorMap?: ReadonlyMap<string, string>): ExternalFindings;
5
+ export {};
6
+ //# sourceMappingURL=stored-finding-projection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stored-finding-projection.d.ts","sourceRoot":"","sources":["../src/stored-finding-projection.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAEV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAQhC,KAAK,SAAS,GAAG,IAAI,CACnB,qBAAqB,EACrB,UAAU,GAAG,iBAAiB,GAAG,UAAU,CAC5C,CAAC;AAqIF,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,SAAS,EACd,kBAAkB,EAAE,SAAS,wBAAwB,EAAE,EACvD,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,gBAAgB,CAelB"}
@@ -0,0 +1,129 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { normalizeBlackDuckFindings } from "./blackduck-findings.js";
3
+ import { continuumIssueFormat, normalizeContinuumFindings, } from "./continuum-findings.js";
4
+ import { normalizeEndorFindings } from "./endor-findings.js";
5
+ import { validateExternalEvidence, } from "./external-import-contract.js";
6
+ import { normalizeInspectorFindings } from "./inspector-findings.js";
7
+ import { projectStoredOpenGrepFinding } from "./opengrep-findings.js";
8
+ import { isRecord } from "./record.js";
9
+ import { array, normalizeRecords, record } from "./scanner-import.js";
10
+ import { storedSemgrepCloudEvidence } from "./semgrep-platform-findings.js";
11
+ import { normalizeTrivyFindings } from "./trivy-findings.js";
12
+ /** Reconstruct only report envelopes for which a native row retains its inputs. */
13
+ function* nativeReaders(row, inspectorMap) {
14
+ const data = row.evidence.source_data;
15
+ if (!data)
16
+ return;
17
+ if (row.provider === "endor" && data["uuid"] === row.sourceFindingId)
18
+ yield (target) => normalizeEndorFindings(data, target);
19
+ if (row.provider === "trivy" &&
20
+ isRecord(data["report"]) &&
21
+ isRecord(data["result"]) &&
22
+ typeof data["scanRoot"] === "string") {
23
+ const root = data["scanRoot"];
24
+ const input = {
25
+ ...data["report"],
26
+ Results: [
27
+ {
28
+ ...data["result"],
29
+ Vulnerabilities: [data["vulnerability"]],
30
+ Packages: data["package"] ? [data["package"]] : [],
31
+ },
32
+ ],
33
+ };
34
+ yield (target) => normalizeTrivyFindings(input, target, root);
35
+ }
36
+ const url = data["sourceRepositoryUrl"];
37
+ if (typeof url !== "string")
38
+ return;
39
+ if (row.provider === "inspector" && isRecord(data["finding"]))
40
+ yield (target) => normalizeInspectorFindings({ findings: [data["finding"]] }, url, target, inspectorMap);
41
+ if (row.provider === "continuum" && isRecord(data["finding"])) {
42
+ // The list and detail APIs can return the same raw record with different SAST projections.
43
+ const detail = {
44
+ finding: data["finding"],
45
+ patches: data["patches"] ?? [],
46
+ evidenceArtifacts: data["evidence_artifacts"] ?? [],
47
+ validationIssue: data["validation_issue"],
48
+ };
49
+ yield (target) => normalizeContinuumFindings(detail, url, target);
50
+ yield (target) => normalizeContinuumFindings({ items: [data["finding"]] }, url, target);
51
+ }
52
+ const issue = data["issue"];
53
+ if (row.provider === "continuum" &&
54
+ data["format"] === continuumIssueFormat &&
55
+ isRecord(issue))
56
+ yield (target) => {
57
+ const artifacts = array(data["evidence_artifacts"] ?? [], "Continuum issue evidence artifacts");
58
+ const patches = array(data["patches"] ?? [], "Continuum patches").map((patch) => ({
59
+ artifactId: record(patch, "Continuum patch")["artifactId"],
60
+ artifactType: "PATCH",
61
+ body: { patch },
62
+ }));
63
+ return normalizeContinuumFindings({
64
+ format: continuumIssueFormat,
65
+ environmentId: data["environmentId"],
66
+ issues: [
67
+ {
68
+ issue: { ...issue, artifacts: [...artifacts, ...patches] },
69
+ findings: data["findings"],
70
+ },
71
+ ],
72
+ }, url, target);
73
+ };
74
+ if (row.provider === "blackduck" &&
75
+ typeof data["projectVersionUrl"] === "string") {
76
+ const input = {
77
+ totalCount: 1,
78
+ items: [data["row"]],
79
+ _meta: {
80
+ href: data["projectVersionUrl"] + "/vulnerable-bom-components",
81
+ links: [],
82
+ },
83
+ };
84
+ yield (target) => normalizeBlackDuckFindings(input, url, target);
85
+ }
86
+ }
87
+ function cloudEvidence(row, finding, sourceRepositories, inspectorMap) {
88
+ try {
89
+ return validateExternalEvidence(row.evidence, "cloud");
90
+ }
91
+ catch (error) {
92
+ if (row.provider === "semgrep") {
93
+ const projected = storedSemgrepCloudEvidence(finding, sourceRepositories);
94
+ if (projected)
95
+ return validateExternalEvidence(projected, "cloud");
96
+ }
97
+ // Enriched typed fields can exceed Cloud limits while the complete native
98
+ // record fits. Verify the local reader reproduced this reviewed row before
99
+ // allowing its Cloud reader to choose different optional fields.
100
+ for (const read of nativeReaders(row, inspectorMap)) {
101
+ let local;
102
+ try {
103
+ local = read("local");
104
+ }
105
+ catch {
106
+ continue;
107
+ }
108
+ if (!isDeepStrictEqual(local.findings[0], finding))
109
+ continue;
110
+ const cloud = read("cloud");
111
+ if (cloud.findings.length)
112
+ return cloud.findings[0].evidence;
113
+ }
114
+ throw error;
115
+ }
116
+ }
117
+ export function projectStoredFinding(row, sourceRepositories, inspectorMap) {
118
+ const finding = {
119
+ source_finding_id: row.sourceFindingId,
120
+ evidence: row.evidence,
121
+ };
122
+ if (row.provider === "semgrep") {
123
+ const traces = projectStoredOpenGrepFinding(finding);
124
+ if (traces)
125
+ return traces;
126
+ }
127
+ return normalizeRecords([row], () => cloudEvidence(row, finding, sourceRepositories, inspectorMap), () => row.sourceFindingId, "cloud");
128
+ }
129
+ //# sourceMappingURL=stored-finding-projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stored-finding-projection.js","sourceRoot":"","sources":["../src/stored-finding-projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EACL,wBAAwB,GAEzB,MAAM,+BAA+B,CAAC;AAOvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAQ7D,mFAAmF;AACnF,QAAQ,CAAC,CAAC,aAAa,CACrB,GAAc,EACd,YAA0C;IAE1C,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC;IACtC,IAAI,CAAC,IAAI;QAAE,OAAO;IAClB,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,eAAe;QAClE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACzD,IACE,GAAG,CAAC,QAAQ,KAAK,OAAO;QACxB,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxB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AK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;gBAAE,SAAS;YAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM;gBAAE,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAC,QAAQ,CAAC;QAChE,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,GAAc,EACd,kBAAuD,EACvD,YAA0C;IAE1C,MAAM,OAAO,GAAG;QACd,iBAAiB,EAAE,GAAG,CAAC,eAAe;QACtC,QAAQ,EAAE,GAAG,CAAC,QAAQ;KACvB,CAAC;IACF,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,4BAA4B,CAAC,OAAO,CAAC,CAAC;QACrD,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;IAC5B,CAAC;IACD,OAAO,gBAAgB,CACrB,CAAC,GAAG,CAAC,EACL,GAAG,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,kBAAkB,EAAE,YAAY,CAAC,EACnE,GAAG,EAAE,CAAC,GAAG,CAAC,eAAe,EACzB,OAAO,CACR,CAAC;AACJ,CAAC","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport { normalizeBlackDuckFindings } from \"./blackduck-findings.js\";\nimport {\n continuumIssueFormat,\n normalizeContinuumFindings,\n} from \"./continuum-findings.js\";\nimport { normalizeEndorFindings } from \"./endor-findings.js\";\nimport {\n validateExternalEvidence,\n type ExternalImportTarget,\n} from \"./external-import-contract.js\";\nimport type { StoredExternalFinding } from \"./external-findings-local.js\";\nimport type {\n ExternalFinding,\n ExternalFindings,\n ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport { normalizeInspectorFindings } from \"./inspector-findings.js\";\nimport { projectStoredOpenGrepFinding } from \"./opengrep-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport { array, normalizeRecords, record } from \"./scanner-import.js\";\nimport { storedSemgrepCloudEvidence } from \"./semgrep-platform-findings.js\";\nimport { normalizeTrivyFindings } from \"./trivy-findings.js\";\n\ntype StoredRow = Pick<\n StoredExternalFinding,\n \"provider\" | \"sourceFindingId\" | \"evidence\"\n>;\ntype Reader = (target: ExternalImportTarget) => ExternalFindings;\n\n/** Reconstruct only report envelopes for which a native row retains its inputs. */\nfunction* nativeReaders(\n row: StoredRow,\n inspectorMap?: ReadonlyMap<string, string>,\n): Generator<Reader> {\n const data = row.evidence.source_data;\n if (!data) return;\n if (row.provider === \"endor\" && data[\"uuid\"] === row.sourceFindingId)\n yield (target) => normalizeEndorFindings(data, target);\n if (\n row.provider === \"trivy\" &&\n isRecord(data[\"report\"]) &&\n isRecord(data[\"result\"]) &&\n typeof data[\"scanRoot\"] === \"string\"\n ) {\n const root = data[\"scanRoot\"];\n const input = {\n ...data[\"report\"],\n Results: [\n {\n ...data[\"result\"],\n Vulnerabilities: [data[\"vulnerability\"]],\n Packages: data[\"package\"] ? [data[\"package\"]] : [],\n },\n ],\n };\n yield (target) => normalizeTrivyFindings(input, target, root);\n }\n const url = data[\"sourceRepositoryUrl\"];\n if (typeof url !== \"string\") return;\n if (row.provider === \"inspector\" && isRecord(data[\"finding\"]))\n yield (target) =>\n normalizeInspectorFindings(\n { findings: [data[\"finding\"]] },\n url,\n target,\n inspectorMap,\n );\n if (row.provider === \"continuum\" && isRecord(data[\"finding\"])) {\n // The list and detail APIs can return the same raw record with different SAST projections.\n const detail = {\n finding: data[\"finding\"],\n patches: data[\"patches\"] ?? [],\n evidenceArtifacts: data[\"evidence_artifacts\"] ?? [],\n validationIssue: data[\"validation_issue\"],\n };\n yield (target) => normalizeContinuumFindings(detail, url, target);\n yield (target) =>\n normalizeContinuumFindings({ items: [data[\"finding\"]] }, url, target);\n }\n const issue = data[\"issue\"];\n if (\n row.provider === \"continuum\" &&\n data[\"format\"] === continuumIssueFormat &&\n isRecord(issue)\n )\n yield (target) => {\n const artifacts = array(\n data[\"evidence_artifacts\"] ?? [],\n \"Continuum issue evidence artifacts\",\n );\n const patches = array(data[\"patches\"] ?? [], \"Continuum patches\").map(\n (patch) => ({\n artifactId: record(patch, \"Continuum patch\")[\"artifactId\"],\n artifactType: \"PATCH\",\n body: { patch },\n }),\n );\n return normalizeContinuumFindings(\n {\n format: continuumIssueFormat,\n environmentId: data[\"environmentId\"],\n issues: [\n {\n issue: { ...issue, artifacts: [...artifacts, ...patches] },\n findings: data[\"findings\"],\n },\n ],\n },\n url,\n target,\n );\n };\n if (\n row.provider === \"blackduck\" &&\n typeof data[\"projectVersionUrl\"] === \"string\"\n ) {\n const input = {\n totalCount: 1,\n items: [data[\"row\"]],\n _meta: {\n href: data[\"projectVersionUrl\"] + \"/vulnerable-bom-components\",\n links: [],\n },\n };\n yield (target) => normalizeBlackDuckFindings(input, url, target);\n }\n}\n\nfunction cloudEvidence(\n row: StoredRow,\n finding: ExternalFinding,\n sourceRepositories: readonly ExternalSourceRepository[],\n inspectorMap?: ReadonlyMap<string, string>,\n) {\n try {\n return validateExternalEvidence(row.evidence, \"cloud\");\n } catch (error) {\n if (row.provider === \"semgrep\") {\n const projected = storedSemgrepCloudEvidence(finding, sourceRepositories);\n if (projected) return validateExternalEvidence(projected, \"cloud\");\n }\n // Enriched typed fields can exceed Cloud limits while the complete native\n // record fits. Verify the local reader reproduced this reviewed row before\n // allowing its Cloud reader to choose different optional fields.\n for (const read of nativeReaders(row, inspectorMap)) {\n let local: ExternalFindings;\n try {\n local = read(\"local\");\n } catch {\n continue;\n }\n if (!isDeepStrictEqual(local.findings[0], finding)) continue;\n const cloud = read(\"cloud\");\n if (cloud.findings.length) return cloud.findings[0]!.evidence;\n }\n throw error;\n }\n}\n\nexport function projectStoredFinding(\n row: StoredRow,\n sourceRepositories: readonly ExternalSourceRepository[],\n inspectorMap?: ReadonlyMap<string, string>,\n): ExternalFindings {\n const finding = {\n source_finding_id: row.sourceFindingId,\n evidence: row.evidence,\n };\n if (row.provider === \"semgrep\") {\n const traces = projectStoredOpenGrepFinding(finding);\n if (traces) return traces;\n }\n return normalizeRecords(\n [row],\n () => cloudEvidence(row, finding, sourceRepositories, inspectorMap),\n () => row.sourceFindingId,\n \"cloud\",\n );\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import { type LocalExternalFindingSelection, type LocalExternalImportDependencies, type StoredExternalFinding } from "./external-findings-local.js";
2
+ import { type ExternalPublicationDependencies, type ExternalPublicationPreview, type ExternalPublicationResult } from "./external-findings-publish.js";
3
+ type Dependencies = ExternalPublicationDependencies & LocalExternalImportDependencies;
4
+ type Reference = Pick<StoredExternalFinding, "id" | "version" | "provider" | "sourceKey" | "sourceFindingId">;
5
+ export interface StoredFindingsPublicationGroup {
6
+ /** Prepare this selection again to resume the same reviewed source in another process. */
7
+ selection: LocalExternalFindingSelection;
8
+ preview: ExternalPublicationPreview;
9
+ reviewId: string;
10
+ publish(reviewId: string): Promise<ExternalPublicationResult>;
11
+ }
12
+ export interface StoredFindingsPublication {
13
+ groups: StoredFindingsPublicationGroup[];
14
+ excluded: (Reference & {
15
+ reason: string;
16
+ })[];
17
+ }
18
+ /** Preview each source once. Each group's approval can be resumed independently. */
19
+ export declare function prepareStoredFindingsPublication(selection: LocalExternalFindingSelection, options: {
20
+ repository: string;
21
+ }, dependencies?: Dependencies): Promise<StoredFindingsPublication>;
22
+ export {};
23
+ //# sourceMappingURL=stored-findings-publication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stored-findings-publication.d.ts","sourceRoot":"","sources":["../src/stored-findings-publication.ts"],"names":[],"mappings":"AAIA,OAAO,EAIL,KAAK,6BAA6B,EAElC,KAAK,+BAA+B,EACpC,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAIL,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAE/B,MAAM,gCAAgC,CAAC;AASxC,KAAK,YAAY,GAAG,+BAA+B,GACjD,+BAA+B,CAAC;AAClC,KAAK,SAAS,GAAG,IAAI,CACnB,qBAAqB,EACrB,IAAI,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,iBAAiB,CAChE,CAAC;AAGF,MAAM,WAAW,8BAA8B;IAC7C,0FAA0F;IAC1F,SAAS,EAAE,6BAA6B,CAAC;IACzC,OAAO,EAAE,0BAA0B,CAAC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAC/D;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,8BAA8B,EAAE,CAAC;IACzC,QAAQ,EAAE,CAAC,SAAS,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC;CAC9C;AAuJD,oFAAoF;AACpF,wBAAsB,gCAAgC,CACpD,SAAS,EAAE,6BAA6B,EACxC,OAAO,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,EAC/B,YAAY,GAAE,YAAiB,GAC9B,OAAO,CAAC,yBAAyB,CAAC,CAwFpC"}