@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openai/codex-security",
3
- "version": "0.9.1",
3
+ "version": "0.10.1",
4
4
  "description": "TypeScript SDK and CLI for Codex Security",
5
5
  "license": "Apache-2.0",
6
6
  "author": "OpenAI",
@@ -17,6 +17,11 @@
17
17
  },
18
18
  "main": "./dist/index.js",
19
19
  "types": "./dist/index.d.ts",
20
+ "imports": {
21
+ "#classify-severity-records-logs": {
22
+ "codex-security-records-logs-v1": "./dist/classify-severity-diagnostics.js"
23
+ }
24
+ },
20
25
  "exports": {
21
26
  "./server": {
22
27
  "types": "./dist/server/api.d.ts",
@@ -43,6 +48,7 @@
43
48
  "LICENSE",
44
49
  "README.md",
45
50
  "docs/cli.md",
51
+ "docs/sdk.md",
46
52
  "docs/findings-service.md",
47
53
  "docs/dedupe-records.md",
48
54
  "docs/classify-severity-records.md",
@@ -54,6 +60,7 @@
54
60
  "publishConfig": {
55
61
  "access": "public",
56
62
  "executableFiles": [
63
+ "_bundled_plugin/scripts/dispatch_inventory_tool",
57
64
  "_bundled_plugin/scripts/launch_codex_security_mcp"
58
65
  ]
59
66
  },
@@ -62,10 +69,11 @@
62
69
  "@inquirer/confirm": "6.3.5",
63
70
  "@inquirer/input": "5.1.9",
64
71
  "@inquirer/search": "4.3.6",
65
- "@linear/sdk": "100.0.0",
72
+ "@linear/sdk": "101.1.0",
66
73
  "@octokit/core": "7.0.8",
67
- "@openai/codex": "0.167.0",
68
- "@openai/codex-sdk": "0.167.0",
74
+ "@openai/codex": "0.167.1",
75
+ "@openai/codex-sdk": "0.167.1",
76
+ "add-mcp": "2.6.1",
69
77
  "ajv": "8.20.0",
70
78
  "fflate": "0.8.3",
71
79
  "incur": "0.7.1",
@@ -74,10 +82,11 @@
74
82
  "pdfjs-dist": "6.5.438",
75
83
  "react": "19.3.1",
76
84
  "saxes": "6.0.0",
77
- "semver": "7.8.5",
85
+ "semver": "7.8.6",
78
86
  "smol-toml": "1.9.1",
79
87
  "string-width": "8.3.0",
80
88
  "strip-ansi": "7.2.0",
89
+ "tokenx": "1.6.0",
81
90
  "yaml": "2.9.1",
82
91
  "yauzl": "3.4.0",
83
92
  "zod": "4.6.7"
@@ -98,7 +107,7 @@
98
107
  "prettier": "3.9.10",
99
108
  "typescript": "7.0.2"
100
109
  },
101
- "gitHead": "fe1089ab514599931ff0ce77a82dc8c4a99201ea",
110
+ "gitHead": "9293f253bb979fd470d91e7ba1117362c0b304a3",
102
111
  "scripts": {
103
112
  "audit:prod": "pnpm audit --prod --audit-level high",
104
113
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
@@ -390,7 +390,8 @@
390
390
  "sonar",
391
391
  "continuum",
392
392
  "checkmarx",
393
- "trivy"
393
+ "trivy",
394
+ "armorcode"
394
395
  ],
395
396
  "title": "Provider",
396
397
  "type": "string"
@@ -91,6 +91,11 @@
91
91
  }
92
92
  ]
93
93
  },
94
+ "exclude_paths": {
95
+ "description": "Literal files or directories relative to the selected repository. Exclusions take precedence over inclusions.",
96
+ "type": "array",
97
+ "items": { "type": "string", "minLength": 1 }
98
+ },
94
99
  "knowledge_base": {
95
100
  "description": "Context files or directories, relative to this file. An empty list selects no additional context.",
96
101
  "type": "array",
@@ -1,6 +0,0 @@
1
- export declare function legacyDecimalInteger(token: string): string | undefined;
2
- /** A legacy export needs a type witness when JSON.parse cannot preserve a decimal. */
3
- export declare function isLegacyWitness(token: string): boolean;
4
- /** Original hosted exports saved imprecise JSON numbers as text plus a sparse type witness. */
5
- export declare function restoreLegacyHostedNumbers(document: Record<string, unknown>): Record<string, unknown>;
6
- //# sourceMappingURL=hosted-scanner-v1.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hosted-scanner-v1.d.ts","sourceRoot":"","sources":["../src/hosted-scanner-v1.ts"],"names":[],"mappings":"AASA,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUtE;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAWtD;AAyBD,+FAA+F;AAC/F,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMzB"}
@@ -1,60 +0,0 @@
1
- import { canonicalNumber } from "./external-import-contract.js";
2
- import { hostedNumberToken, parseHostedScannerJson, } from "./hosted-scanner-http.js";
3
- import { isRecord } from "./record.js";
4
- const jsonNumber = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/iu;
5
- export function legacyDecimalInteger(token) {
6
- if (!jsonNumber.test(token))
7
- return;
8
- const value = Number(token);
9
- // Rule out unbounded exponents cheaply. Rounded boundary values still need an exact check.
10
- if (!Number.isInteger(value) || value < 1 || value > 2 ** 63)
11
- return;
12
- const id = canonicalNumber(token);
13
- return /^[1-9]\d{0,18}$/u.test(id) &&
14
- (id.length < 19 || id <= "9223372036854775807")
15
- ? id
16
- : undefined;
17
- }
18
- /** A legacy export needs a type witness when JSON.parse cannot preserve a decimal. */
19
- export function isLegacyWitness(token) {
20
- if (!jsonNumber.test(token))
21
- return false;
22
- const value = Number(token);
23
- if (!Number.isFinite(value) ||
24
- (Number.isInteger(value) && !Number.isSafeInteger(value)))
25
- return true;
26
- // Distinguish zero from underflow without converting an unbounded exponent.
27
- if (value === 0)
28
- return /[1-9]/u.test(token.split(/e/iu, 1)[0]);
29
- return canonicalNumber(token) !== String(value);
30
- }
31
- function restoreField(value, witness) {
32
- if (typeof witness === "string") {
33
- if (value !== witness || !isLegacyWitness(witness))
34
- throw new Error("Invalid exact scanner number.");
35
- return parseHostedScannerJson(witness);
36
- }
37
- if (!isRecord(witness) ||
38
- hostedNumberToken(witness) !== undefined ||
39
- (!Array.isArray(value) &&
40
- (!isRecord(value) || hostedNumberToken(value) !== undefined)))
41
- throw new Error("Invalid scanner numeric fields.");
42
- const restored = Array.isArray(value) ? [...value] : { ...value };
43
- const fields = restored;
44
- for (const [key, child] of Object.entries(witness)) {
45
- if (!Object.hasOwn(restored, key))
46
- throw new Error("Invalid scanner numeric field.");
47
- fields[key] = restoreField(fields[key], child);
48
- }
49
- return restored;
50
- }
51
- /** Original hosted exports saved imprecise JSON numbers as text plus a sparse type witness. */
52
- export function restoreLegacyHostedNumbers(document) {
53
- const fields = document["numericFields"];
54
- if (fields === undefined)
55
- return document;
56
- if (!isRecord(fields) || Object.hasOwn(fields, "numericFields"))
57
- throw new Error("Invalid scanner numeric fields.");
58
- return restoreField(document, fields);
59
- }
60
- //# sourceMappingURL=hosted-scanner-v1.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hosted-scanner-v1.js","sourceRoot":"","sources":["../src/hosted-scanner-v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,UAAU,GAAG,8CAA8C,CAAC;AAElE,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO;IACpC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,2FAA2F;IAC3F,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,EAAE;QAAE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,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACpB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,CAAC;QAE/D,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC;IAClE,MAAM,MAAM,GAAG,QAAmC,CAAC;IACnD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,0BAA0B,CACxC,QAAiC;IAEjC,MAAM,MAAM,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;IACzC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC1C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,OAAO,YAAY,CAAC,QAAQ,EAAE,MAAM,CAA4B,CAAC;AACnE,CAAC","sourcesContent":["import { canonicalNumber } from \"./external-import-contract.js\";\nimport {\n hostedNumberToken,\n parseHostedScannerJson,\n} from \"./hosted-scanner-http.js\";\nimport { isRecord } from \"./record.js\";\n\nconst jsonNumber = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:e[+-]?\\d+)?$/iu;\n\nexport function legacyDecimalInteger(token: string): string | undefined {\n if (!jsonNumber.test(token)) return;\n const value = Number(token);\n // Rule out unbounded exponents cheaply. Rounded boundary values still need an exact check.\n if (!Number.isInteger(value) || value < 1 || value > 2 ** 63) return;\n const id = canonicalNumber(token);\n return /^[1-9]\\d{0,18}$/u.test(id) &&\n (id.length < 19 || id <= \"9223372036854775807\")\n ? id\n : undefined;\n}\n\n/** A legacy export needs a type witness when JSON.parse cannot preserve a decimal. */\nexport function isLegacyWitness(token: string): boolean {\n if (!jsonNumber.test(token)) return false;\n const value = Number(token);\n if (\n !Number.isFinite(value) ||\n (Number.isInteger(value) && !Number.isSafeInteger(value))\n )\n return true;\n // Distinguish zero from underflow without converting an unbounded exponent.\n if (value === 0) return /[1-9]/u.test(token.split(/e/iu, 1)[0]!);\n return canonicalNumber(token) !== String(value);\n}\n\nfunction restoreField(value: unknown, witness: unknown): unknown {\n if (typeof witness === \"string\") {\n if (value !== witness || !isLegacyWitness(witness))\n throw new Error(\"Invalid exact scanner number.\");\n return parseHostedScannerJson(witness);\n }\n if (\n !isRecord(witness) ||\n hostedNumberToken(witness) !== undefined ||\n (!Array.isArray(value) &&\n (!isRecord(value) || hostedNumberToken(value) !== undefined))\n )\n throw new Error(\"Invalid scanner numeric fields.\");\n const restored = Array.isArray(value) ? [...value] : { ...value };\n const fields = restored as Record<string, unknown>;\n for (const [key, child] of Object.entries(witness)) {\n if (!Object.hasOwn(restored, key))\n throw new Error(\"Invalid scanner numeric field.\");\n fields[key] = restoreField(fields[key], child);\n }\n return restored;\n}\n\n/** Original hosted exports saved imprecise JSON numbers as text plus a sparse type witness. */\nexport function restoreLegacyHostedNumbers(\n document: Record<string, unknown>,\n): Record<string, unknown> {\n const fields = document[\"numericFields\"];\n if (fields === undefined) return document;\n if (!isRecord(fields) || Object.hasOwn(fields, \"numericFields\"))\n throw new Error(\"Invalid scanner numeric fields.\");\n return restoreField(document, fields) as Record<string, unknown>;\n}\n"]}
@@ -1,15 +0,0 @@
1
- import type { ExternalFindings } from "./external-findings.js";
2
- export declare function markPreviousCloudProjection(findings: ExternalFindings): void;
3
- export declare function hasPreviousCloudProjection(findings: ExternalFindings): boolean;
4
- export interface LegacyReaderSelection {
5
- sourceFindingIds: string[];
6
- snapshot?: ExternalFindings;
7
- unprovenIdPrefixes?: string[];
8
- uncertainFindingIds?: string[];
9
- unprovenOccurrenceCount?: number;
10
- knownFindings?: ExternalFindings["findings"];
11
- }
12
- export declare function rememberPreviousSelection(result: ExternalFindings, prior: LegacyReaderSelection): void;
13
- /** Only unchanged SDK output can identify an older, differently serialized selection. */
14
- export declare function previousReaderSelection(input: ExternalFindings, current: ExternalFindings, native?: ExternalFindings | null): LegacyReaderSelection | undefined;
15
- //# sourceMappingURL=reader-selection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reader-selection.d.ts","sourceRoot":"","sources":["../src/reader-selection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM/D,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAE5E;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAET;AAED,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC9C;AAoCD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,qBAAqB,GAC3B,IAAI,CAaN;AAED,yFAAyF;AACzF,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,gBAAgB,GAAG,IAAI,GAC/B,qBAAqB,GAAG,SAAS,CA6CnC"}
@@ -1,89 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { isDeepStrictEqual } from "node:util";
3
- import { isBoxedPrimitive, isProxy } from "node:util/types";
4
- import { canonicalJson, cloneWithoutGetters } from "./record.js";
5
- const changedCloudProjections = new WeakSet();
6
- // Readers mark selections whose original Cloud request can have different evidence.
7
- export function markPreviousCloudProjection(findings) {
8
- changedCloudProjections.add(findings);
9
- }
10
- export function hasPreviousCloudProjection(findings) {
11
- return changedCloudProjections.has(findings);
12
- }
13
- const previousSelections = new WeakMap();
14
- // The registry digest is process-local. Frame both ordered lists separately so a
15
- // local import never needs one JSON string containing all its findings.
16
- function exportedSelectionDigest(result, preserveScalar) {
17
- const { findings, excluded, ...metadata } = result;
18
- const digest = createHash("sha256");
19
- digest.update(canonicalJson(metadata, undefined, preserveScalar));
20
- for (const rows of [excluded, findings]) {
21
- digest.update("[");
22
- for (let index = 0; index < rows.length; index++) {
23
- // Keep the array index supplied to toJSON. An omitted entry in an array
24
- // is JSON null, just like an explicit null or a hole.
25
- const entry = canonicalJson({ [index]: rows[index] }, undefined, preserveScalar);
26
- digest.update(entry === "{}" ? `{"${index}":null}` : entry);
27
- }
28
- digest.update("]");
29
- }
30
- return digest.digest("hex");
31
- }
32
- export function rememberPreviousSelection(result, prior) {
33
- // Stop-only hints do not require hashing unbounded local evidence.
34
- const exported = prior.snapshot || prior.knownFindings
35
- ? exportedSelectionDigest(result, isBoxedPrimitive)
36
- : undefined;
37
- const selection = {
38
- exported,
39
- native: exported ? cloneWithoutGetters(result) : undefined,
40
- previous: prior,
41
- };
42
- previousSelections.set(result, selection);
43
- previousSelections.set(result.findings, selection);
44
- }
45
- /** Only unchanged SDK output can identify an older, differently serialized selection. */
46
- export function previousReaderSelection(input, current, native) {
47
- const selection = previousSelections.get(input) ??
48
- (!isProxy(input) &&
49
- previousSelections.get(Object.getOwnPropertyDescriptor(input, "findings")?.value));
50
- if (!selection)
51
- return undefined;
52
- const observed = native === undefined ? cloneWithoutGetters(input) : native;
53
- if (selection.native && observed && selection.exported) {
54
- // Callers can attach a report after normalizing rows. Historical validation
55
- // and the saved approval still bind the independently captured report.
56
- const attachedReport = !Object.hasOwn(selection.native, "report") &&
57
- !Object.hasOwn(selection.previous.snapshot ?? {}, "report") &&
58
- observed.report !== undefined;
59
- const rows = (value) => {
60
- if (!attachedReport)
61
- return value;
62
- const { report: _report, ...readerOutput } = value;
63
- return readerOutput;
64
- };
65
- if (isDeepStrictEqual(selection.native, rows(observed)) &&
66
- exportedSelectionDigest(rows(current)) === selection.exported) {
67
- const prior = selection.previous;
68
- return attachedReport && prior.snapshot
69
- ? { ...prior, snapshot: { ...prior.snapshot, report: observed.report } }
70
- : prior;
71
- }
72
- }
73
- // Without a verified snapshot these IDs can only stop a retry. Preserve
74
- // the caller's order when they rearranged the same known occurrences.
75
- let sourceFindingIds = selection.previous.sourceFindingIds;
76
- if (current.findings.length === sourceFindingIds.length) {
77
- const members = new Set(sourceFindingIds);
78
- const ordered = current.findings.map((row) => row.source_finding_id);
79
- if (ordered.every((id) => members.has(id)))
80
- sourceFindingIds = ordered;
81
- }
82
- return {
83
- sourceFindingIds,
84
- unprovenIdPrefixes: selection.previous.unprovenIdPrefixes,
85
- uncertainFindingIds: selection.previous.uncertainFindingIds,
86
- unprovenOccurrenceCount: selection.previous.unprovenOccurrenceCount,
87
- };
88
- }
89
- //# sourceMappingURL=reader-selection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reader-selection.js","sourceRoot":"","sources":["../src/reader-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,E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CAAC;QAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACrE,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAAE,gBAAgB,GAAG,OAAO,CAAC;IACzE,CAAC;IACD,OAAO;QACL,gBAAgB;QAChB,kBAAkB,EAAE,SAAS,CAAC,QAAQ,CAAC,kBAAkB;QACzD,mBAAmB,EAAE,SAAS,CAAC,QAAQ,CAAC,mBAAmB;QAC3D,uBAAuB,EAAE,SAAS,CAAC,QAAQ,CAAC,uBAAuB;KACpE,CAAC;AACJ,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { isBoxedPrimitive, isProxy } from \"node:util/types\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport { canonicalJson, cloneWithoutGetters } from \"./record.js\";\n\nconst changedCloudProjections = new WeakSet<ExternalFindings>();\n\n// Readers mark selections whose original Cloud request can have different evidence.\nexport function markPreviousCloudProjection(findings: ExternalFindings): void {\n changedCloudProjections.add(findings);\n}\n\nexport function hasPreviousCloudProjection(\n findings: ExternalFindings,\n): boolean {\n return changedCloudProjections.has(findings);\n}\n\nexport interface LegacyReaderSelection {\n sourceFindingIds: string[];\n snapshot?: ExternalFindings;\n unprovenIdPrefixes?: string[];\n uncertainFindingIds?: string[];\n unprovenOccurrenceCount?: number;\n knownFindings?: ExternalFindings[\"findings\"];\n}\nconst previousSelections = new WeakMap<\n object,\n {\n exported?: string;\n native?: ExternalFindings;\n previous: LegacyReaderSelection;\n }\n>();\n\n// The registry digest is process-local. Frame both ordered lists separately so a\n// local import never needs one JSON string containing all its findings.\nfunction exportedSelectionDigest(\n result: ExternalFindings,\n preserveScalar?: (value: object) => boolean,\n): string {\n const { findings, excluded, ...metadata } = result;\n const digest = createHash(\"sha256\");\n digest.update(canonicalJson(metadata, undefined, preserveScalar));\n for (const rows of [excluded, findings]) {\n digest.update(\"[\");\n for (let index = 0; index < rows.length; index++) {\n // Keep the array index supplied to toJSON. An omitted entry in an array\n // is JSON null, just like an explicit null or a hole.\n const entry = canonicalJson(\n { [index]: rows[index] },\n undefined,\n preserveScalar,\n );\n digest.update(entry === \"{}\" ? `{\"${index}\":null}` : entry);\n }\n digest.update(\"]\");\n }\n return digest.digest(\"hex\");\n}\n\nexport function rememberPreviousSelection(\n result: ExternalFindings,\n prior: LegacyReaderSelection,\n): void {\n // Stop-only hints do not require hashing unbounded local evidence.\n const exported =\n prior.snapshot || prior.knownFindings\n ? exportedSelectionDigest(result, isBoxedPrimitive)\n : undefined;\n const selection = {\n exported,\n native: exported ? cloneWithoutGetters(result) : undefined,\n previous: prior,\n };\n previousSelections.set(result, selection);\n previousSelections.set(result.findings, selection);\n}\n\n/** Only unchanged SDK output can identify an older, differently serialized selection. */\nexport function previousReaderSelection(\n input: ExternalFindings,\n current: ExternalFindings,\n native?: ExternalFindings | null,\n): LegacyReaderSelection | undefined {\n const selection =\n previousSelections.get(input) ??\n (!isProxy(input) &&\n previousSelections.get(\n Object.getOwnPropertyDescriptor(input, \"findings\")?.value,\n ));\n if (!selection) return undefined;\n const observed = native === undefined ? cloneWithoutGetters(input) : native;\n if (selection.native && observed && selection.exported) {\n // Callers can attach a report after normalizing rows. Historical validation\n // and the saved approval still bind the independently captured report.\n const attachedReport =\n !Object.hasOwn(selection.native, \"report\") &&\n !Object.hasOwn(selection.previous.snapshot ?? {}, \"report\") &&\n observed.report !== undefined;\n const rows = (value: ExternalFindings) => {\n if (!attachedReport) return value;\n const { report: _report, ...readerOutput } = value;\n return readerOutput;\n };\n if (\n isDeepStrictEqual(selection.native, rows(observed)) &&\n exportedSelectionDigest(rows(current)) === selection.exported\n ) {\n const prior = selection.previous;\n return attachedReport && prior.snapshot\n ? { ...prior, snapshot: { ...prior.snapshot, report: observed.report } }\n : prior;\n }\n }\n // Without a verified snapshot these IDs can only stop a retry. Preserve\n // the caller's order when they rearranged the same known occurrences.\n let sourceFindingIds = selection.previous.sourceFindingIds;\n if (current.findings.length === sourceFindingIds.length) {\n const members = new Set(sourceFindingIds);\n const ordered = current.findings.map((row) => row.source_finding_id);\n if (ordered.every((id) => members.has(id))) sourceFindingIds = ordered;\n }\n return {\n sourceFindingIds,\n unprovenIdPrefixes: selection.previous.unprovenIdPrefixes,\n uncertainFindingIds: selection.previous.uncertainFindingIds,\n unprovenOccurrenceCount: selection.previous.unprovenOccurrenceCount,\n };\n}\n"]}
@@ -1,6 +0,0 @@
1
- import { type SemgrepRepositoryReference, semgrepRepositoryUrlKey } from "./semgrep-platform-findings.js";
2
- /** Early v1 exports also admitted positive integral decimal spellings stored as text. */
3
- export declare function semgrepV1Id(value: unknown): string;
4
- /** Translate a saved object-row export into lossless per-finding JSON for the current reader. */
5
- export declare function upgradeSemgrepPlatformReport(input: Record<string, unknown>, declaredUrl?: string, repositoryKey?: typeof semgrepRepositoryUrlKey, references?: SemgrepRepositoryReference): Record<string, unknown>;
6
- //# sourceMappingURL=semgrep-platform-v1.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"semgrep-platform-v1.d.ts","sourceRoot":"","sources":["../src/semgrep-platform-v1.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,KAAK,0BAA0B,EAE/B,uBAAuB,EACxB,MAAM,gCAAgC,CAAC;AAExC,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASlD;AAUD,iGAAiG;AACjG,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,WAAW,CAAC,EAAE,MAAM,EACpB,aAAa,iCAA0B,EACvC,UAAU,GAAE,0BAA+B,GAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyFzB"}
@@ -1,83 +0,0 @@
1
- import { hostedNumberToken } from "./hosted-scanner-http.js";
2
- import { hostedRepositoryUrl } from "./hosted-scanner-http.js";
3
- import { legacyDecimalInteger, restoreLegacyHostedNumbers, } from "./hosted-scanner-v1.js";
4
- import { array, record, requiredText, text } from "./scanner-import.js";
5
- import { legacyProjectAliases, semgrepNativeProjectUrl, semgrepProjectUrlEvidence, semgrepPlatformId, semgrepRepositoryUrlKey, } from "./semgrep-platform-findings.js";
6
- /** Early v1 exports also admitted positive integral decimal spellings stored as text. */
7
- export function semgrepV1Id(value) {
8
- if (typeof value === "number" && Number.isSafeInteger(value))
9
- return semgrepPlatformId(String(value));
10
- const token = hostedNumberToken(value);
11
- if (token !== undefined && !/^[1-9][0-9]*$/u.test(token))
12
- return semgrepPlatformId(legacyDecimalInteger(token));
13
- return semgrepPlatformId(typeof value === "string" ? legacyDecimalInteger(value) : value);
14
- }
15
- function isLossyNumber(value) {
16
- return (typeof value === "number" &&
17
- (!Number.isFinite(value) ||
18
- (Number.isInteger(value) && !Number.isSafeInteger(value))));
19
- }
20
- /** Translate a saved object-row export into lossless per-finding JSON for the current reader. */
21
- export function upgradeSemgrepPlatformReport(input, declaredUrl, repositoryKey = semgrepRepositoryUrlKey, references = []) {
22
- const report = restoreLegacyHostedNumbers(input);
23
- const project = record(report["project"], "Semgrep project");
24
- const name = requiredText(project["name"], "Semgrep project name");
25
- const mapping = report["sourceRepositoryUrl"] ?? declaredUrl;
26
- const bound = mapping === undefined
27
- ? undefined
28
- : hostedRepositoryUrl(mapping, "Semgrep source repository");
29
- const native = semgrepNativeProjectUrl(project["url"], references);
30
- const url = hostedRepositoryUrl(native ?? bound, "Semgrep project repository");
31
- for (const other of [bound, declaredUrl]) {
32
- if (other !== undefined &&
33
- repositoryKey(hostedRepositoryUrl(other, "Semgrep repository")) !==
34
- repositoryKey(url))
35
- throw new Error("Semgrep project does not match the declared source repository URL.");
36
- }
37
- // For a resolved native URL, retain only the mapping saved in the report.
38
- const urlEvidence = semgrepProjectUrlEvidence(project["url"], native, native === undefined || report["sourceRepositoryUrl"] != null
39
- ? bound
40
- : undefined);
41
- const entries = array(report["findings"], "Semgrep findings");
42
- let aliases = report["repositoryAliases"];
43
- if (aliases === undefined) {
44
- const derived = legacyProjectAliases(name, url, references, urlEvidence.sourceRepositoryUrl);
45
- const observed = new Set();
46
- for (const entry of entries) {
47
- const row = record(entry, "Semgrep finding");
48
- const repo = record(row["repository"] ?? {}, "Semgrep finding repository");
49
- const label = text(repo["name"]);
50
- if (!label)
51
- continue;
52
- // Without the later alias list, each row must independently identify the project.
53
- if (repo["id"] == null &&
54
- (repo["url"] == null || repo["url"] === "") &&
55
- !derived.has(label))
56
- throw new Error("Semgrep finding repository does not match the selected project.");
57
- observed.add(label);
58
- }
59
- aliases = Array.from(observed);
60
- }
61
- return {
62
- format: "semgrep-platform-findings/v2",
63
- deployment: report["deployment"],
64
- project: { id: semgrepV1Id(project["id"]), name, url },
65
- ...urlEvidence,
66
- product: report["product"],
67
- ref: report["ref"],
68
- findingCount: report["findingCount"],
69
- repositoryAliases: aliases,
70
- findings: entries.map((entry) => {
71
- const row = record(entry, "Semgrep finding");
72
- const repository = record(row["repository"] ?? {}, "Semgrep finding repository");
73
- if ([row["id"], repository["id"]].some(isLossyNumber))
74
- throw new Error("Expected an exact, positive Semgrep Platform ID.");
75
- return JSON.stringify(row, (_key, value) => {
76
- if (isLossyNumber(value))
77
- throw new Error("Cannot retain an unsafe Semgrep finding number. Read the original Semgrep export to preserve its JSON numbers.");
78
- return value;
79
- });
80
- }),
81
- };
82
- }
83
- //# sourceMappingURL=semgrep-platform-v1.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"semgrep-platform-v1.js","sourceRoot":"","sources":["../src/semgrep-platform-v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACL,oBA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AG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC9B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;YAC7C,MAAM,UAAU,GAAG,MAAM,CACvB,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,EACvB,4BAA4B,CAC7B,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;gBACnD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACtE,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,KAAc,EAAE,EAAE;gBAClD,IAAI,aAAa,CAAC,KAAK,CAAC;oBACtB,MAAM,IAAI,KAAK,CACb,gHAAgH,CACjH,CAAC;gBACJ,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;KACH,CAAC;AACJ,CAAC","sourcesContent":["import { hostedNumberToken } from \"./hosted-scanner-http.js\";\nimport { hostedRepositoryUrl } from \"./hosted-scanner-http.js\";\nimport {\n legacyDecimalInteger,\n restoreLegacyHostedNumbers,\n} from \"./hosted-scanner-v1.js\";\nimport { array, record, requiredText, text } from \"./scanner-import.js\";\nimport {\n legacyProjectAliases,\n semgrepNativeProjectUrl,\n semgrepProjectUrlEvidence,\n type SemgrepRepositoryReference,\n semgrepPlatformId,\n semgrepRepositoryUrlKey,\n} from \"./semgrep-platform-findings.js\";\n\n/** Early v1 exports also admitted positive integral decimal spellings stored as text. */\nexport function semgrepV1Id(value: unknown): string {\n if (typeof value === \"number\" && Number.isSafeInteger(value))\n return semgrepPlatformId(String(value));\n const token = hostedNumberToken(value);\n if (token !== undefined && !/^[1-9][0-9]*$/u.test(token))\n return semgrepPlatformId(legacyDecimalInteger(token));\n return semgrepPlatformId(\n typeof value === \"string\" ? legacyDecimalInteger(value) : value,\n );\n}\n\nfunction isLossyNumber(value: unknown): boolean {\n return (\n typeof value === \"number\" &&\n (!Number.isFinite(value) ||\n (Number.isInteger(value) && !Number.isSafeInteger(value)))\n );\n}\n\n/** Translate a saved object-row export into lossless per-finding JSON for the current reader. */\nexport function upgradeSemgrepPlatformReport(\n input: Record<string, unknown>,\n declaredUrl?: string,\n repositoryKey = semgrepRepositoryUrlKey,\n references: SemgrepRepositoryReference = [],\n): Record<string, unknown> {\n const report = restoreLegacyHostedNumbers(input);\n const project = record(report[\"project\"], \"Semgrep project\");\n const name = requiredText(project[\"name\"], \"Semgrep project name\");\n const mapping = report[\"sourceRepositoryUrl\"] ?? declaredUrl;\n const bound =\n mapping === undefined\n ? undefined\n : hostedRepositoryUrl(mapping, \"Semgrep source repository\");\n const native = semgrepNativeProjectUrl(project[\"url\"], references);\n const url = hostedRepositoryUrl(\n native ?? bound,\n \"Semgrep project repository\",\n );\n for (const other of [bound, declaredUrl]) {\n if (\n other !== undefined &&\n repositoryKey(hostedRepositoryUrl(other, \"Semgrep repository\")) !==\n repositoryKey(url)\n )\n throw new Error(\n \"Semgrep project does not match the declared source repository URL.\",\n );\n }\n // For a resolved native URL, retain only the mapping saved in the report.\n const urlEvidence = semgrepProjectUrlEvidence(\n project[\"url\"],\n native,\n native === undefined || report[\"sourceRepositoryUrl\"] != null\n ? bound\n : undefined,\n );\n const entries = array(report[\"findings\"], \"Semgrep findings\");\n let aliases = report[\"repositoryAliases\"];\n if (aliases === undefined) {\n const derived = legacyProjectAliases(\n name,\n url,\n references,\n urlEvidence.sourceRepositoryUrl,\n );\n const observed = new Set<string>();\n for (const entry of entries) {\n const row = record(entry, \"Semgrep finding\");\n const repo = record(\n row[\"repository\"] ?? {},\n \"Semgrep finding repository\",\n );\n const label = text(repo[\"name\"]);\n if (!label) continue;\n // Without the later alias list, each row must independently identify the project.\n if (\n repo[\"id\"] == null &&\n (repo[\"url\"] == null || repo[\"url\"] === \"\") &&\n !derived.has(label)\n )\n throw new Error(\n \"Semgrep finding repository does not match the selected project.\",\n );\n observed.add(label);\n }\n aliases = Array.from(observed);\n }\n return {\n format: \"semgrep-platform-findings/v2\",\n deployment: report[\"deployment\"],\n project: { id: semgrepV1Id(project[\"id\"]), name, url },\n ...urlEvidence,\n product: report[\"product\"],\n ref: report[\"ref\"],\n findingCount: report[\"findingCount\"],\n repositoryAliases: aliases,\n findings: entries.map((entry) => {\n const row = record(entry, \"Semgrep finding\");\n const repository = record(\n row[\"repository\"] ?? {},\n \"Semgrep finding repository\",\n );\n if ([row[\"id\"], repository[\"id\"]].some(isLossyNumber))\n throw new Error(\"Expected an exact, positive Semgrep Platform ID.\");\n return JSON.stringify(row, (_key, value: unknown) => {\n if (isLossyNumber(value))\n throw new Error(\n \"Cannot retain an unsafe Semgrep finding number. Read the original Semgrep export to preserve its JSON numbers.\",\n );\n return value;\n });\n }),\n };\n}\n"]}
@@ -1,28 +0,0 @@
1
- type Resource = Record<string, unknown>;
2
- export declare const SNYK_REST_ISSUES_V1 = "snyk-rest-issues/v1";
3
- export declare const SNYK_REST_ISSUES_FORMAT = "snyk-rest-issues/v2";
4
- export declare function isSnykRestFormat(value: unknown): boolean;
5
- /** Only v1 can carry native JSON numbers outside the lossless evidence strings. */
6
- export declare function parseSnykReport(text: string): unknown;
7
- /** Recover the exact v1 wire representation whether numbers were native or witnessed strings. */
8
- export declare function encodeSnykV1File(document: Resource): Resource;
9
- /** Read v1 exports, retained source records, and empty-report project contexts. */
10
- export declare function readSnykRestDocument(document: Resource, context?: Resource): Resource;
11
- /** Retain v1's evidence representation so replaying an existing import stays unchanged. */
12
- export declare function originalSnykEvidence(document: Resource, source: Resource): {
13
- context: {
14
- format: string;
15
- project: unknown;
16
- target: unknown;
17
- numericFields?: Resource | undefined;
18
- };
19
- rows: {
20
- format: string;
21
- project: unknown;
22
- target: unknown;
23
- numericFields?: Resource | undefined;
24
- issue: unknown;
25
- }[];
26
- } | undefined;
27
- export {};
28
- //# sourceMappingURL=snyk-rest-v1.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snyk-rest-v1.d.ts","sourceRoot":"","sources":["../src/snyk-rest-v1.ts"],"names":[],"mappings":"AAWA,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACxC,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AACzD,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAC7D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAExD;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKrD;AA0BD,iGAAiG;AACjG,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAM7D;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,QAAQ,GACjB,QAAQ,CA2CV;AAQD,2FAA2F;AAC3F,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ;;;;;;;;;;;;;;cAiCxE"}
@@ -1,132 +0,0 @@
1
- import { hostedNumberToken, parseHostedScannerJson, } from "./hosted-scanner-http.js";
2
- import { isLegacyWitness, restoreLegacyHostedNumbers, } from "./hosted-scanner-v1.js";
3
- import { canonicalJson, isRecord } from "./record.js";
4
- import { array, record } from "./scanner-import.js";
5
- export const SNYK_REST_ISSUES_V1 = "snyk-rest-issues/v1";
6
- export const SNYK_REST_ISSUES_FORMAT = "snyk-rest-issues/v2";
7
- export function isSnykRestFormat(value) {
8
- return value === SNYK_REST_ISSUES_FORMAT || value === SNYK_REST_ISSUES_V1;
9
- }
10
- /** Only v1 can carry native JSON numbers outside the lossless evidence strings. */
11
- export function parseSnykReport(text) {
12
- const document = JSON.parse(text);
13
- return isRecord(document) && document["format"] === SNYK_REST_ISSUES_V1
14
- ? parseHostedScannerJson(text)
15
- : document;
16
- }
17
- function encodeNumbers(data) {
18
- const fields = Object.create(null);
19
- const values = data;
20
- for (const [key, value] of Object.entries(values)) {
21
- const token = hostedNumberToken(value);
22
- if (token !== undefined) {
23
- if (isLegacyWitness(token)) {
24
- values[key] = token;
25
- fields[key] = token;
26
- }
27
- else {
28
- values[key] = Number(token);
29
- }
30
- }
31
- else if (value !== null && typeof value === "object") {
32
- // restoreLegacyHostedNumbers shares branches that had no sidecar.
33
- // Keep the captured input reusable for another repository projection.
34
- const child = Array.isArray(value) ? [...value] : { ...value };
35
- values[key] = child;
36
- const nested = encodeNumbers(child);
37
- if (nested)
38
- fields[key] = nested;
39
- }
40
- }
41
- return Object.keys(fields).length ? fields : undefined;
42
- }
43
- /** Recover the exact v1 wire representation whether numbers were native or witnessed strings. */
44
- export function encodeSnykV1File(document) {
45
- const source = { ...restoreLegacyHostedNumbers(document) };
46
- delete source["numericFields"];
47
- const fields = encodeNumbers(source);
48
- if (fields)
49
- source["numericFields"] = fields;
50
- return source;
51
- }
52
- /** Read v1 exports, retained source records, and empty-report project contexts. */
53
- export function readSnykRestDocument(document, context) {
54
- if (document["format"] !== SNYK_REST_ISSUES_V1)
55
- return document;
56
- const fields = document["numericFields"];
57
- if (context && isRecord(fields)) {
58
- // A projected row may keep witnesses for assets that now come from its report.
59
- const inline = { ...fields };
60
- for (const field of ["project", "target"]) {
61
- const json = context[field + "Json"];
62
- if (document[field] !== undefined ||
63
- !(field in fields) ||
64
- typeof json !== "string")
65
- continue;
66
- const asset = encodeSnykV1File({ [field]: parseHostedScannerJson(json) });
67
- if (canonicalJson(fields[field]) !==
68
- canonicalJson(at(asset, "numericFields", field)))
69
- throw new Error("Invalid scanner numeric fields for the retained Snyk asset.");
70
- delete inline[field];
71
- document = { ...document, numericFields: inline };
72
- }
73
- }
74
- const exact = restoreLegacyHostedNumbers(document);
75
- return {
76
- ...exact,
77
- format: SNYK_REST_ISSUES_FORMAT,
78
- projectJson: JSON.stringify(exact["project"]),
79
- targetJson: JSON.stringify(exact["target"]),
80
- issueJson: JSON.stringify(exact["issue"]),
81
- ...(exact["pages"] !== undefined && {
82
- pages: array(exact["pages"], "Snyk issue pages").map((entry) => {
83
- const page = record(entry, "Snyk saved page");
84
- return {
85
- startingAfter: page["startingAfter"],
86
- responseJson: JSON.stringify(page["response"]),
87
- };
88
- }),
89
- }),
90
- };
91
- }
92
- function at(value, ...path) {
93
- for (const segment of path)
94
- value = isRecord(value) ? value[segment] : undefined;
95
- return value;
96
- }
97
- /** Retain v1's evidence representation so replaying an existing import stays unchanged. */
98
- export function originalSnykEvidence(document, source) {
99
- if (document["format"] !== SNYK_REST_ISSUES_V1)
100
- return;
101
- const { projectJson: _project, targetJson: _target, ...scope } = source;
102
- const fields = document["numericFields"];
103
- const assetFields = {};
104
- for (const key of ["project", "target"]) {
105
- const field = at(fields, key);
106
- if (field !== undefined)
107
- assetFields[key] = field;
108
- }
109
- const context = {
110
- ...scope,
111
- format: SNYK_REST_ISSUES_V1,
112
- project: document["project"],
113
- target: document["target"],
114
- ...(Object.keys(assetFields).length > 0 && { numericFields: assetFields }),
115
- };
116
- const rows = array(document["pages"], "Snyk issue pages").flatMap((value, i) => {
117
- const page = record(value, "Snyk saved page");
118
- const response = record(page["response"], "Snyk issue page");
119
- return array(response["data"], "Snyk issue page data").map((issue, j) => {
120
- const field = at(fields, "pages", i, "response", "data", j);
121
- return {
122
- ...context,
123
- issue,
124
- ...(field !== undefined && {
125
- numericFields: { ...assetFields, issue: field },
126
- }),
127
- };
128
- });
129
- });
130
- return { context, rows };
131
- }
132
- //# sourceMappingURL=snyk-rest-v1.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snyk-rest-v1.js","sourceRoot":"","sources":["../src/snyk-rest-v1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,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W,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC;KAC3E,CAAC;IACF,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,OAAO,CAC/D,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QACX,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,sBAAsB,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YACtE,MAAM,KAAK,GAAG,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAC5D,OAAO;gBACL,GAAG,OAAO;gBACV,KAAK;gBACL,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI;oBACzB,aAAa,EAAE,EAAE,GAAG,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE;iBAChD,CAAC;aACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CACF,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import {\n hostedNumberToken,\n parseHostedScannerJson,\n} from \"./hosted-scanner-http.js\";\nimport {\n isLegacyWitness,\n restoreLegacyHostedNumbers,\n} from \"./hosted-scanner-v1.js\";\nimport { canonicalJson, isRecord } from \"./record.js\";\nimport { array, record } from \"./scanner-import.js\";\n\ntype Resource = Record<string, unknown>;\nexport const SNYK_REST_ISSUES_V1 = \"snyk-rest-issues/v1\";\nexport const SNYK_REST_ISSUES_FORMAT = \"snyk-rest-issues/v2\";\nexport function isSnykRestFormat(value: unknown): boolean {\n return value === SNYK_REST_ISSUES_FORMAT || value === SNYK_REST_ISSUES_V1;\n}\n\n/** Only v1 can carry native JSON numbers outside the lossless evidence strings. */\nexport function parseSnykReport(text: string): unknown {\n const document: unknown = JSON.parse(text);\n return isRecord(document) && document[\"format\"] === SNYK_REST_ISSUES_V1\n ? parseHostedScannerJson(text)\n : document;\n}\n\nfunction encodeNumbers(data: object): Resource | undefined {\n const fields: Resource = Object.create(null);\n const values = data as Resource;\n for (const [key, value] of Object.entries(values)) {\n const token = hostedNumberToken(value);\n if (token !== undefined) {\n if (isLegacyWitness(token)) {\n values[key] = token;\n fields[key] = token;\n } else {\n values[key] = Number(token);\n }\n } else if (value !== null && typeof value === \"object\") {\n // restoreLegacyHostedNumbers shares branches that had no sidecar.\n // Keep the captured input reusable for another repository projection.\n const child = Array.isArray(value) ? [...value] : { ...value };\n values[key] = child;\n const nested = encodeNumbers(child);\n if (nested) fields[key] = nested;\n }\n }\n return Object.keys(fields).length ? fields : undefined;\n}\n\n/** Recover the exact v1 wire representation whether numbers were native or witnessed strings. */\nexport function encodeSnykV1File(document: Resource): Resource {\n const source = { ...restoreLegacyHostedNumbers(document) };\n delete source[\"numericFields\"];\n const fields = encodeNumbers(source);\n if (fields) source[\"numericFields\"] = fields;\n return source;\n}\n\n/** Read v1 exports, retained source records, and empty-report project contexts. */\nexport function readSnykRestDocument(\n document: Resource,\n context?: Resource,\n): Resource {\n if (document[\"format\"] !== SNYK_REST_ISSUES_V1) return document;\n const fields = document[\"numericFields\"];\n if (context && isRecord(fields)) {\n // A projected row may keep witnesses for assets that now come from its report.\n const inline = { ...fields };\n for (const field of [\"project\", \"target\"]) {\n const json = context[field + \"Json\"];\n if (\n document[field] !== undefined ||\n !(field in fields) ||\n typeof json !== \"string\"\n )\n continue;\n const asset = encodeSnykV1File({ [field]: parseHostedScannerJson(json) });\n if (\n canonicalJson(fields[field]) !==\n canonicalJson(at(asset, \"numericFields\", field))\n )\n throw new Error(\n \"Invalid scanner numeric fields for the retained Snyk asset.\",\n );\n delete inline[field];\n document = { ...document, numericFields: inline };\n }\n }\n const exact = restoreLegacyHostedNumbers(document);\n return {\n ...exact,\n format: SNYK_REST_ISSUES_FORMAT,\n projectJson: JSON.stringify(exact[\"project\"]),\n targetJson: JSON.stringify(exact[\"target\"]),\n issueJson: JSON.stringify(exact[\"issue\"]),\n ...(exact[\"pages\"] !== undefined && {\n pages: array(exact[\"pages\"], \"Snyk issue pages\").map((entry) => {\n const page = record(entry, \"Snyk saved page\");\n return {\n startingAfter: page[\"startingAfter\"],\n responseJson: JSON.stringify(page[\"response\"]),\n };\n }),\n }),\n };\n}\n\nfunction at(value: unknown, ...path: (string | number)[]): unknown {\n for (const segment of path)\n value = isRecord(value) ? value[segment] : undefined;\n return value;\n}\n\n/** Retain v1's evidence representation so replaying an existing import stays unchanged. */\nexport function originalSnykEvidence(document: Resource, source: Resource) {\n if (document[\"format\"] !== SNYK_REST_ISSUES_V1) return;\n const { projectJson: _project, targetJson: _target, ...scope } = source;\n const fields = document[\"numericFields\"];\n const assetFields: Resource = {};\n for (const key of [\"project\", \"target\"]) {\n const field = at(fields, key);\n if (field !== undefined) assetFields[key] = field;\n }\n const context = {\n ...scope,\n format: SNYK_REST_ISSUES_V1,\n project: document[\"project\"],\n target: document[\"target\"],\n ...(Object.keys(assetFields).length > 0 && { numericFields: assetFields }),\n };\n const rows = array(document[\"pages\"], \"Snyk issue pages\").flatMap(\n (value, i) => {\n const page = record(value, \"Snyk saved page\");\n const response = record(page[\"response\"], \"Snyk issue page\");\n return array(response[\"data\"], \"Snyk issue page data\").map((issue, j) => {\n const field = at(fields, \"pages\", i, \"response\", \"data\", j);\n return {\n ...context,\n issue,\n ...(field !== undefined && {\n numericFields: { ...assetFields, issue: field },\n }),\n };\n });\n },\n );\n return { context, rows };\n}\n"]}