@openai/codex-security 0.8.1 → 0.8.3

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 (396) hide show
  1. package/README.md +45 -57
  2. package/_bundled_plugin/.app.json +4 -0
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
  7. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  14. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  15. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
  16. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  17. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  18. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  19. package/_bundled_plugin/references/artifact-storage.md +1 -1
  20. package/_bundled_plugin/references/core-scan.md +14 -5
  21. package/_bundled_plugin/references/default-severity-rubric.md +28 -0
  22. package/_bundled_plugin/references/finding-detail-fields.md +1 -0
  23. package/_bundled_plugin/references/threat-model.md +1 -0
  24. package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
  26. package/_bundled_plugin/scripts/finding_preview.py +5 -29
  27. package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
  28. package/_bundled_plugin/scripts/report_projection.py +87 -136
  29. package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
  30. package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
  31. package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
  32. package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
  33. package/_bundled_plugin/scripts/workbench_cli.py +102 -13
  34. package/_bundled_plugin/scripts/workbench_constants.py +9 -0
  35. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
  36. package/_bundled_plugin/scripts/workbench_db.py +187 -363
  37. package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
  38. package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
  39. package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
  40. package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
  41. package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
  42. package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
  43. package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
  44. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  45. package/_bundled_plugin/scripts/workbench_setup.py +239 -0
  46. package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
  47. package/_bundled_plugin/scripts/workbench_target.py +120 -35
  48. package/_bundled_plugin/scripts/workbench_validation.py +1 -9
  49. package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
  50. package/_bundled_plugin/shared/workbench-migrations.json +19 -0
  51. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
  52. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
  53. package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
  54. package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
  55. package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
  56. package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
  57. package/_bundled_plugin/skills/publish-findings/SKILL.md +68 -35
  58. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
  59. package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
  60. package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
  61. package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
  62. package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
  63. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
  64. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
  65. package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
  66. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
  67. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
  68. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
  69. package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
  70. package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
  71. package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
  72. package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
  73. package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
  74. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
  75. package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
  76. package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
  77. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
  78. package/dist/api.d.ts +6 -1
  79. package/dist/api.d.ts.map +1 -1
  80. package/dist/api.js +414 -163
  81. package/dist/api.js.map +1 -1
  82. package/dist/auth.js +7 -2
  83. package/dist/auth.js.map +1 -1
  84. package/dist/blackduck-findings.d.ts +8 -0
  85. package/dist/blackduck-findings.d.ts.map +1 -0
  86. package/dist/blackduck-findings.js +305 -0
  87. package/dist/blackduck-findings.js.map +1 -0
  88. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  89. package/dist/bulk-scan-discovery.js +51 -36
  90. package/dist/bulk-scan-discovery.js.map +1 -1
  91. package/dist/classify-severity-records.d.ts +5 -0
  92. package/dist/classify-severity-records.d.ts.map +1 -1
  93. package/dist/classify-severity-records.js +6 -8
  94. package/dist/classify-severity-records.js.map +1 -1
  95. package/dist/classify-severity.d.ts +4 -1
  96. package/dist/classify-severity.d.ts.map +1 -1
  97. package/dist/classify-severity.js +28 -9
  98. package/dist/classify-severity.js.map +1 -1
  99. package/dist/cli.d.ts +3 -0
  100. package/dist/cli.d.ts.map +1 -1
  101. package/dist/cli.js +635 -266
  102. package/dist/cli.js.map +1 -1
  103. package/dist/codex-prompt.d.ts +2 -0
  104. package/dist/codex-prompt.d.ts.map +1 -1
  105. package/dist/codex-prompt.js +6 -0
  106. package/dist/codex-prompt.js.map +1 -1
  107. package/dist/component-scan.d.ts.map +1 -1
  108. package/dist/component-scan.js +6 -5
  109. package/dist/component-scan.js.map +1 -1
  110. package/dist/config.d.ts +2 -1
  111. package/dist/config.d.ts.map +1 -1
  112. package/dist/config.js +162 -40
  113. package/dist/config.js.map +1 -1
  114. package/dist/continuum-findings.d.ts +7 -0
  115. package/dist/continuum-findings.d.ts.map +1 -0
  116. package/dist/continuum-findings.js +157 -0
  117. package/dist/continuum-findings.js.map +1 -0
  118. package/dist/contract-values.d.ts +28 -0
  119. package/dist/contract-values.d.ts.map +1 -0
  120. package/dist/contract-values.js +75 -0
  121. package/dist/contract-values.js.map +1 -0
  122. package/dist/contract.d.ts +2 -20
  123. package/dist/contract.d.ts.map +1 -1
  124. package/dist/contract.js +58 -669
  125. package/dist/contract.js.map +1 -1
  126. package/dist/cost-model.d.ts.map +1 -1
  127. package/dist/cost-model.js +1 -4
  128. package/dist/cost-model.js.map +1 -1
  129. package/dist/cost.d.ts +19 -1
  130. package/dist/cost.d.ts.map +1 -1
  131. package/dist/cost.js +2120 -39
  132. package/dist/cost.js.map +1 -1
  133. package/dist/custom-validation-prompt.d.ts +1 -1
  134. package/dist/custom-validation-prompt.d.ts.map +1 -1
  135. package/dist/custom-validation-prompt.js +5 -0
  136. package/dist/custom-validation-prompt.js.map +1 -1
  137. package/dist/custom-validation.d.ts +2 -0
  138. package/dist/custom-validation.d.ts.map +1 -1
  139. package/dist/custom-validation.js +6 -2
  140. package/dist/custom-validation.js.map +1 -1
  141. package/dist/deduplication/deduplication-prompts.d.ts +4 -4
  142. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  143. package/dist/deduplication/deduplication-prompts.js +2 -2
  144. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  145. package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
  146. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  147. package/dist/deduplication/deduplication-reviewer.js +12 -5
  148. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  149. package/dist/deduplication/deduplication.js.map +1 -1
  150. package/dist/deduplication/finding-schema.d.ts +19 -1
  151. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  152. package/dist/deduplication/finding-schema.js +25 -0
  153. package/dist/deduplication/finding-schema.js.map +1 -1
  154. package/dist/deduplication/local.d.ts.map +1 -1
  155. package/dist/deduplication/local.js +3 -8
  156. package/dist/deduplication/local.js.map +1 -1
  157. package/dist/deduplication/records.d.ts +11 -3
  158. package/dist/deduplication/records.d.ts.map +1 -1
  159. package/dist/deduplication/records.js +48 -16
  160. package/dist/deduplication/records.js.map +1 -1
  161. package/dist/deep-scan.d.ts +11 -0
  162. package/dist/deep-scan.d.ts.map +1 -1
  163. package/dist/deep-scan.js +235 -4
  164. package/dist/deep-scan.js.map +1 -1
  165. package/dist/default-severity-rubric.d.ts +1 -2
  166. package/dist/default-severity-rubric.d.ts.map +1 -1
  167. package/dist/default-severity-rubric.js +2 -66
  168. package/dist/default-severity-rubric.js.map +1 -1
  169. package/dist/endor-findings.d.ts.map +1 -1
  170. package/dist/endor-findings.js +44 -89
  171. package/dist/endor-findings.js.map +1 -1
  172. package/dist/errors.js +1 -1
  173. package/dist/errors.js.map +1 -1
  174. package/dist/external-findings-import.d.ts.map +1 -1
  175. package/dist/external-findings-import.js +11 -15
  176. package/dist/external-findings-import.js.map +1 -1
  177. package/dist/external-findings-local.d.ts +12 -1
  178. package/dist/external-findings-local.d.ts.map +1 -1
  179. package/dist/external-findings-local.js +411 -184
  180. package/dist/external-findings-local.js.map +1 -1
  181. package/dist/external-findings-publish.d.ts +15 -1
  182. package/dist/external-findings-publish.d.ts.map +1 -1
  183. package/dist/external-findings-publish.js +1238 -226
  184. package/dist/external-findings-publish.js.map +1 -1
  185. package/dist/external-findings-read.d.ts +10 -0
  186. package/dist/external-findings-read.d.ts.map +1 -1
  187. package/dist/external-findings-read.js +71 -51
  188. package/dist/external-findings-read.js.map +1 -1
  189. package/dist/external-findings.d.ts +13 -0
  190. package/dist/external-findings.d.ts.map +1 -1
  191. package/dist/external-findings.js +124 -1
  192. package/dist/external-findings.js.map +1 -1
  193. package/dist/external-import-contract.d.ts +29 -1
  194. package/dist/external-import-contract.d.ts.map +1 -1
  195. package/dist/external-import-contract.js +314 -44
  196. package/dist/external-import-contract.js.map +1 -1
  197. package/dist/external-import-models.d.ts +1 -1
  198. package/dist/external-import-models.d.ts.map +1 -1
  199. package/dist/external-import-models.js.map +1 -1
  200. package/dist/finding-normalization.d.ts +1 -1
  201. package/dist/finding-normalization.d.ts.map +1 -1
  202. package/dist/finding-normalization.js +46 -11
  203. package/dist/finding-normalization.js.map +1 -1
  204. package/dist/finding-retrieval.d.ts +3 -3
  205. package/dist/finding-retrieval.d.ts.map +1 -1
  206. package/dist/finding-retrieval.js.map +1 -1
  207. package/dist/finding-workflow.d.ts +6 -1
  208. package/dist/finding-workflow.d.ts.map +1 -1
  209. package/dist/finding-workflow.js +2 -2
  210. package/dist/finding-workflow.js.map +1 -1
  211. package/dist/git-remote.d.ts +4 -0
  212. package/dist/git-remote.d.ts.map +1 -1
  213. package/dist/git-remote.js +20 -0
  214. package/dist/git-remote.js.map +1 -1
  215. package/dist/github-advisories.d.ts +3 -12
  216. package/dist/github-advisories.d.ts.map +1 -1
  217. package/dist/github-advisories.js +9 -29
  218. package/dist/github-advisories.js.map +1 -1
  219. package/dist/github-dependabot-findings.d.ts.map +1 -1
  220. package/dist/github-dependabot-findings.js +7 -16
  221. package/dist/github-dependabot-findings.js.map +1 -1
  222. package/dist/github-findings.d.ts.map +1 -1
  223. package/dist/github-findings.js +344 -56
  224. package/dist/github-findings.js.map +1 -1
  225. package/dist/github.d.ts +17 -7
  226. package/dist/github.d.ts.map +1 -1
  227. package/dist/github.js +43 -30
  228. package/dist/github.js.map +1 -1
  229. package/dist/host-protocol.d.ts +7 -2
  230. package/dist/host-protocol.d.ts.map +1 -1
  231. package/dist/host-protocol.js +27 -3
  232. package/dist/host-protocol.js.map +1 -1
  233. package/dist/host-records-protocol.d.ts +10 -11
  234. package/dist/host-records-protocol.d.ts.map +1 -1
  235. package/dist/host-records-protocol.js +69 -9
  236. package/dist/host-records-protocol.js.map +1 -1
  237. package/dist/hosted-scan.d.ts +15 -0
  238. package/dist/hosted-scan.d.ts.map +1 -1
  239. package/dist/hosted-scan.js +55 -33
  240. package/dist/hosted-scan.js.map +1 -1
  241. package/dist/index.d.ts +8 -0
  242. package/dist/index.d.ts.map +1 -1
  243. package/dist/index.js +7 -0
  244. package/dist/index.js.map +1 -1
  245. package/dist/inspector-findings.d.ts +9 -0
  246. package/dist/inspector-findings.d.ts.map +1 -0
  247. package/dist/inspector-findings.js +512 -0
  248. package/dist/inspector-findings.js.map +1 -0
  249. package/dist/knowledge-base.js +18 -5
  250. package/dist/knowledge-base.js.map +1 -1
  251. package/dist/local-git-metadata.d.ts +5 -0
  252. package/dist/local-git-metadata.d.ts.map +1 -0
  253. package/dist/local-git-metadata.js +131 -0
  254. package/dist/local-git-metadata.js.map +1 -0
  255. package/dist/multiscan.d.ts.map +1 -1
  256. package/dist/multiscan.js +22 -12
  257. package/dist/multiscan.js.map +1 -1
  258. package/dist/opengrep-findings.d.ts.map +1 -1
  259. package/dist/opengrep-findings.js +34 -20
  260. package/dist/opengrep-findings.js.map +1 -1
  261. package/dist/patch-tui.d.ts +1 -1
  262. package/dist/patch-tui.d.ts.map +1 -1
  263. package/dist/patch-tui.js +94 -36
  264. package/dist/patch-tui.js.map +1 -1
  265. package/dist/private-finding-import.d.ts +246 -0
  266. package/dist/private-finding-import.d.ts.map +1 -0
  267. package/dist/private-finding-import.js +387 -0
  268. package/dist/private-finding-import.js.map +1 -0
  269. package/dist/project-config.d.ts.map +1 -1
  270. package/dist/project-config.js +2 -2
  271. package/dist/project-config.js.map +1 -1
  272. package/dist/provider-profile.d.ts +10 -2
  273. package/dist/provider-profile.d.ts.map +1 -1
  274. package/dist/provider-profile.js +72 -10
  275. package/dist/provider-profile.js.map +1 -1
  276. package/dist/publication.js +7 -1
  277. package/dist/publication.js.map +1 -1
  278. package/dist/reader-selection.d.ts +13 -0
  279. package/dist/reader-selection.d.ts.map +1 -0
  280. package/dist/reader-selection.js +81 -0
  281. package/dist/reader-selection.js.map +1 -0
  282. package/dist/record.d.ts +6 -1
  283. package/dist/record.d.ts.map +1 -1
  284. package/dist/record.js +53 -2
  285. package/dist/record.js.map +1 -1
  286. package/dist/remediation.d.ts +5 -0
  287. package/dist/remediation.d.ts.map +1 -1
  288. package/dist/remediation.js +30 -0
  289. package/dist/remediation.js.map +1 -1
  290. package/dist/result.d.ts +2 -0
  291. package/dist/result.d.ts.map +1 -1
  292. package/dist/result.js +3 -1
  293. package/dist/result.js.map +1 -1
  294. package/dist/runtime.d.ts +5 -3
  295. package/dist/runtime.d.ts.map +1 -1
  296. package/dist/runtime.js +110 -57
  297. package/dist/runtime.js.map +1 -1
  298. package/dist/scan-activity.js +40 -17
  299. package/dist/scan-activity.js.map +1 -1
  300. package/dist/scan-comparison.d.ts +1 -1
  301. package/dist/scan-comparison.d.ts.map +1 -1
  302. package/dist/scan-comparison.js +11 -13
  303. package/dist/scan-comparison.js.map +1 -1
  304. package/dist/scan-dashboard.d.ts +1 -0
  305. package/dist/scan-dashboard.d.ts.map +1 -1
  306. package/dist/scan-dashboard.js +37 -48
  307. package/dist/scan-dashboard.js.map +1 -1
  308. package/dist/scan-executor.d.ts +2 -0
  309. package/dist/scan-executor.d.ts.map +1 -1
  310. package/dist/scan-executor.js.map +1 -1
  311. package/dist/scan-history-renderer.d.ts.map +1 -1
  312. package/dist/scan-history-renderer.js +22 -9
  313. package/dist/scan-history-renderer.js.map +1 -1
  314. package/dist/scan-logs.d.ts.map +1 -1
  315. package/dist/scan-logs.js +5 -5
  316. package/dist/scan-logs.js.map +1 -1
  317. package/dist/scanner-import.d.ts +48 -3
  318. package/dist/scanner-import.d.ts.map +1 -1
  319. package/dist/scanner-import.js +214 -39
  320. package/dist/scanner-import.js.map +1 -1
  321. package/dist/scanner-repository-url.d.ts +14 -0
  322. package/dist/scanner-repository-url.d.ts.map +1 -0
  323. package/dist/scanner-repository-url.js +67 -0
  324. package/dist/scanner-repository-url.js.map +1 -0
  325. package/dist/semgrep-findings.d.ts.map +1 -1
  326. package/dist/semgrep-findings.js +50 -88
  327. package/dist/semgrep-findings.js.map +1 -1
  328. package/dist/semgrep-platform-findings.d.ts +12 -0
  329. package/dist/semgrep-platform-findings.d.ts.map +1 -0
  330. package/dist/semgrep-platform-findings.js +198 -0
  331. package/dist/semgrep-platform-findings.js.map +1 -0
  332. package/dist/severity-rubric.d.ts +20 -0
  333. package/dist/severity-rubric.d.ts.map +1 -0
  334. package/dist/severity-rubric.js +73 -0
  335. package/dist/severity-rubric.js.map +1 -0
  336. package/dist/severity-store.js +15 -5
  337. package/dist/severity-store.js.map +1 -1
  338. package/dist/snyk-findings.d.ts.map +1 -1
  339. package/dist/snyk-findings.js +97 -106
  340. package/dist/snyk-findings.js.map +1 -1
  341. package/dist/sonar-collector.d.ts +16 -0
  342. package/dist/sonar-collector.d.ts.map +1 -0
  343. package/dist/sonar-collector.js +383 -0
  344. package/dist/sonar-collector.js.map +1 -0
  345. package/dist/sonar-findings.d.ts +49 -0
  346. package/dist/sonar-findings.d.ts.map +1 -0
  347. package/dist/sonar-findings.js +288 -0
  348. package/dist/sonar-findings.js.map +1 -0
  349. package/dist/sonar-import.d.ts +111 -0
  350. package/dist/sonar-import.d.ts.map +1 -0
  351. package/dist/sonar-import.js +279 -0
  352. package/dist/sonar-import.js.map +1 -0
  353. package/dist/suggest-owners.d.ts.map +1 -1
  354. package/dist/suggest-owners.js +2 -1
  355. package/dist/suggest-owners.js.map +1 -1
  356. package/dist/targets.d.ts +3 -0
  357. package/dist/targets.d.ts.map +1 -1
  358. package/dist/targets.js +18 -12
  359. package/dist/targets.js.map +1 -1
  360. package/dist/terminal-columns.d.ts +4 -0
  361. package/dist/terminal-columns.d.ts.map +1 -0
  362. package/dist/terminal-columns.js +19 -0
  363. package/dist/terminal-columns.js.map +1 -0
  364. package/dist/validation-records.d.ts +0 -3
  365. package/dist/validation-records.d.ts.map +1 -1
  366. package/dist/validation-records.js +0 -16
  367. package/dist/validation-records.js.map +1 -1
  368. package/dist/veracode-findings.d.ts +7 -0
  369. package/dist/veracode-findings.d.ts.map +1 -0
  370. package/dist/veracode-findings.js +371 -0
  371. package/dist/veracode-findings.js.map +1 -0
  372. package/dist/windows-path.d.ts.map +1 -1
  373. package/dist/windows-path.js +1 -0
  374. package/dist/windows-path.js.map +1 -1
  375. package/dist/wiz-csv.d.ts +2 -2
  376. package/dist/wiz-csv.d.ts.map +1 -1
  377. package/dist/wiz-csv.js +1 -3
  378. package/dist/wiz-csv.js.map +1 -1
  379. package/dist/wiz-findings.d.ts +10 -2
  380. package/dist/wiz-findings.d.ts.map +1 -1
  381. package/dist/wiz-findings.js +88 -49
  382. package/dist/wiz-findings.js.map +1 -1
  383. package/docs/classify-severity-records.md +1 -1
  384. package/docs/cli.md +320 -481
  385. package/docs/dedupe-records.md +27 -4
  386. package/docs/findings-service.md +21 -8
  387. package/docs/hosted-scans.md +16 -1
  388. package/package.json +9 -10
  389. package/schemas/external-findings.schema.json +12 -1
  390. package/schemas/hosted-scan-v2.fixture.json +16 -1
  391. package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
  392. package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
  393. package/dist/deduplication/records-protocol.d.ts +0 -4
  394. package/dist/deduplication/records-protocol.d.ts.map +0 -1
  395. package/dist/deduplication/records-protocol.js +0 -35
  396. package/dist/deduplication/records-protocol.js.map +0 -1
@@ -0,0 +1,246 @@
1
+ import { z } from "zod";
2
+ import { CodexSecurityError } from "./errors.js";
3
+ import type { ExternalFinding, ExternalFindings } from "./external-findings.js";
4
+ import type { ImportSource } from "./external-import-models.js";
5
+ declare const privateFormat: z.ZodEnum<{
6
+ "endor.findings_json.v1": "endor.findings_json.v1";
7
+ "security.findings.v1": "security.findings.v1";
8
+ "wiz.vulnerability_json.v1": "wiz.vulnerability_json.v1";
9
+ }>;
10
+ export type PrivateImportFormat = z.infer<typeof privateFormat>;
11
+ declare const contextSchema: z.ZodObject<{
12
+ object: z.ZodLiteral<"security.finding_import_context">;
13
+ context_version: z.ZodString;
14
+ can_upload: z.ZodBoolean;
15
+ can_create_import_jobs: z.ZodBoolean;
16
+ can_read: z.ZodBoolean;
17
+ formats: z.ZodArray<z.ZodString>;
18
+ limits: z.ZodObject<{
19
+ max_direct_file_bytes: z.ZodInt;
20
+ max_record_bytes: z.ZodInt;
21
+ }, z.core.$strip>;
22
+ }, z.core.$strip>;
23
+ declare const jobSchema: z.ZodObject<{
24
+ object: z.ZodLiteral<"security.finding_import_job">;
25
+ id: z.ZodString;
26
+ request_id: z.ZodUUID;
27
+ source: z.ZodObject<{
28
+ provider: z.ZodString;
29
+ source_key: z.ZodString;
30
+ }, z.core.$strip>;
31
+ input: z.ZodObject<{
32
+ type: z.ZodLiteral<"file">;
33
+ file_id: z.ZodString;
34
+ format: z.ZodEnum<{
35
+ "endor.findings_json.v1": "endor.findings_json.v1";
36
+ "security.findings.v1": "security.findings.v1";
37
+ "wiz.vulnerability_json.v1": "wiz.vulnerability_json.v1";
38
+ }>;
39
+ }, z.core.$strip>;
40
+ default_targets: z.ZodArray<z.ZodObject<{
41
+ type: z.ZodLiteral<"repository">;
42
+ repo_id: z.ZodString;
43
+ repo_connector_id: z.ZodString;
44
+ }, z.core.$strip>>;
45
+ status: z.ZodEnum<{
46
+ cancelled: "cancelled";
47
+ cancelling: "cancelling";
48
+ completed: "completed";
49
+ failed: "failed";
50
+ in_progress: "in_progress";
51
+ queued: "queued";
52
+ }>;
53
+ counts: z.ZodObject<{
54
+ total: z.ZodNullable<z.ZodInt>;
55
+ discovered: z.ZodInt;
56
+ created: z.ZodInt;
57
+ updated: z.ZodInt;
58
+ unchanged: z.ZodInt;
59
+ error: z.ZodInt;
60
+ unprocessed: z.ZodInt;
61
+ }, z.core.$strip>;
62
+ poll_after_seconds: z.ZodNullable<z.ZodInt>;
63
+ error: z.ZodNullable<z.ZodObject<{
64
+ message: z.ZodString;
65
+ }, z.core.$strip>>;
66
+ }, z.core.$strip>;
67
+ export type PrivateImportContext = z.infer<typeof contextSchema>;
68
+ export type PrivateImportJob = z.infer<typeof jobSchema>;
69
+ export declare function privateReport(findings: ExternalFinding[], limits: PrivateImportContext["limits"]): {
70
+ format: PrivateImportFormat;
71
+ bytes: string;
72
+ digest: string;
73
+ };
74
+ export declare function selectPrivateReport(selection: ExternalFindings, provider: string, path: string | undefined, context: PrivateImportContext, saved: string | undefined): Promise<ReturnType<typeof privateReport>>;
75
+ export declare function unsuccessfulJob(job: PrivateImportJob | undefined): boolean;
76
+ export declare function readPrivateCheckpoint(serialized: string, expected: {
77
+ format: PrivateImportFormat;
78
+ apiBaseUrl: string;
79
+ accountId: string;
80
+ contextVersion: string;
81
+ sha256: string;
82
+ source: ImportSource;
83
+ repository: {
84
+ id: string;
85
+ repo_connector_id: string;
86
+ };
87
+ }): {
88
+ format: "endor.findings_json.v1" | "security.findings.v1" | "wiz.vulnerability_json.v1";
89
+ apiBaseUrl: string;
90
+ accountId: string;
91
+ contextVersion: string;
92
+ sha256: string;
93
+ source: {
94
+ provider: string;
95
+ source_key: string;
96
+ };
97
+ repository: {
98
+ id: string;
99
+ repo_connector_id: string;
100
+ };
101
+ uploadRequestId: string;
102
+ jobRequestId: string;
103
+ fileId?: string | undefined;
104
+ jobId?: string | undefined;
105
+ receipt?: {
106
+ object: "security.finding_import_job";
107
+ id: string;
108
+ request_id: string;
109
+ source: {
110
+ provider: string;
111
+ source_key: string;
112
+ };
113
+ input: {
114
+ type: "file";
115
+ file_id: string;
116
+ format: "endor.findings_json.v1" | "security.findings.v1" | "wiz.vulnerability_json.v1";
117
+ };
118
+ default_targets: {
119
+ type: "repository";
120
+ repo_id: string;
121
+ repo_connector_id: string;
122
+ }[];
123
+ status: "cancelled" | "cancelling" | "completed" | "failed" | "in_progress" | "queued";
124
+ counts: {
125
+ total: number | null;
126
+ discovered: number;
127
+ created: number;
128
+ updated: number;
129
+ unchanged: number;
130
+ error: number;
131
+ unprocessed: number;
132
+ };
133
+ poll_after_seconds: number | null;
134
+ error: {
135
+ message: string;
136
+ } | null;
137
+ } | undefined;
138
+ previousReceipt?: {
139
+ object: "security.finding_import_job";
140
+ id: string;
141
+ request_id: string;
142
+ source: {
143
+ provider: string;
144
+ source_key: string;
145
+ };
146
+ input: {
147
+ type: "file";
148
+ file_id: string;
149
+ format: "endor.findings_json.v1" | "security.findings.v1" | "wiz.vulnerability_json.v1";
150
+ };
151
+ default_targets: {
152
+ type: "repository";
153
+ repo_id: string;
154
+ repo_connector_id: string;
155
+ }[];
156
+ status: "cancelled" | "cancelling" | "completed" | "failed" | "in_progress" | "queued";
157
+ counts: {
158
+ total: number | null;
159
+ discovered: number;
160
+ created: number;
161
+ updated: number;
162
+ unchanged: number;
163
+ error: number;
164
+ unprocessed: number;
165
+ };
166
+ poll_after_seconds: number | null;
167
+ error: {
168
+ message: string;
169
+ } | null;
170
+ } | undefined;
171
+ } | undefined;
172
+ export declare class PrivateImportRequestError extends CodexSecurityError {
173
+ readonly status: number;
174
+ readonly code: string | undefined;
175
+ constructor(status: number, code: string | undefined, message: string);
176
+ }
177
+ export declare function privateImportClient(base: string, credentials: {
178
+ access_token: string;
179
+ account_id: string;
180
+ }, fetch: (url: string, options: RequestInit) => Promise<Response>, signal?: AbortSignal): {
181
+ context(): Promise<{
182
+ object: "security.finding_import_context";
183
+ context_version: string;
184
+ can_upload: boolean;
185
+ can_create_import_jobs: boolean;
186
+ can_read: boolean;
187
+ formats: string[];
188
+ limits: {
189
+ max_direct_file_bytes: number;
190
+ max_record_bytes: number;
191
+ };
192
+ }>;
193
+ upload(input: {
194
+ requestId: string;
195
+ contextVersion: string;
196
+ bytes: string;
197
+ digest: string;
198
+ recovering: boolean;
199
+ }): Promise<string>;
200
+ job(input: {
201
+ requestId: string;
202
+ contextVersion: string;
203
+ fileId: string;
204
+ format: PrivateImportFormat;
205
+ source: ImportSource;
206
+ repository: {
207
+ id: string;
208
+ repo_connector_id: string;
209
+ };
210
+ jobId?: string;
211
+ }, accepted: (id: string) => Promise<void>): Promise<{
212
+ object: "security.finding_import_job";
213
+ id: string;
214
+ request_id: string;
215
+ source: {
216
+ provider: string;
217
+ source_key: string;
218
+ };
219
+ input: {
220
+ type: "file";
221
+ file_id: string;
222
+ format: "endor.findings_json.v1" | "security.findings.v1" | "wiz.vulnerability_json.v1";
223
+ };
224
+ default_targets: {
225
+ type: "repository";
226
+ repo_id: string;
227
+ repo_connector_id: string;
228
+ }[];
229
+ status: "cancelled" | "cancelling" | "completed" | "failed" | "in_progress" | "queued";
230
+ counts: {
231
+ total: number | null;
232
+ discovered: number;
233
+ created: number;
234
+ updated: number;
235
+ unchanged: number;
236
+ error: number;
237
+ unprocessed: number;
238
+ };
239
+ poll_after_seconds: number | null;
240
+ error: {
241
+ message: string;
242
+ } | null;
243
+ }>;
244
+ };
245
+ export {};
246
+ //# sourceMappingURL=private-finding-import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-finding-import.d.ts","sourceRoot":"","sources":["../src/private-finding-import.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,387 @@
1
+ import { hash } from "node:crypto";
2
+ import { constants } from "node:fs";
3
+ import { open } from "node:fs/promises";
4
+ import { setTimeout as delay } from "node:timers/promises";
5
+ import { z } from "zod";
6
+ import { CodexSecurityError } from "./errors.js";
7
+ import { canonicalJson, isRecord } from "./record.js";
8
+ const structuredFormat = "security.findings.v1";
9
+ const privateFormat = z.enum([
10
+ structuredFormat,
11
+ "endor.findings_json.v1",
12
+ "wiz.vulnerability_json.v1",
13
+ ]);
14
+ const fileId = z.string().regex(/^aifile_[0-9a-f]{32}$/u);
15
+ const contextSchema = z.object({
16
+ object: z.literal("security.finding_import_context"),
17
+ context_version: z.string().min(1),
18
+ can_upload: z.boolean(),
19
+ can_create_import_jobs: z.boolean(),
20
+ can_read: z.boolean(),
21
+ formats: z.array(z.string()),
22
+ limits: z.object({
23
+ max_direct_file_bytes: z.int().positive(),
24
+ max_record_bytes: z.int().positive(),
25
+ }),
26
+ });
27
+ const fileSchema = z.object({
28
+ id: fileId,
29
+ object: z.literal("security.finding_import_file"),
30
+ purpose: z.literal("report"),
31
+ sha256: z.string(),
32
+ bytes: z.int().positive(),
33
+ });
34
+ const jobSchema = z.object({
35
+ object: z.literal("security.finding_import_job"),
36
+ id: z.string().regex(/^import_[0-9a-f]{32}$/u),
37
+ request_id: z.uuid(),
38
+ source: z.object({ provider: z.string(), source_key: z.string() }),
39
+ input: z.object({
40
+ type: z.literal("file"),
41
+ file_id: fileId,
42
+ format: privateFormat,
43
+ }),
44
+ default_targets: z.array(z.object({
45
+ type: z.literal("repository"),
46
+ repo_id: z.string(),
47
+ repo_connector_id: z.string(),
48
+ })),
49
+ status: z.enum([
50
+ "queued",
51
+ "in_progress",
52
+ "cancelling",
53
+ "completed",
54
+ "failed",
55
+ "cancelled",
56
+ ]),
57
+ counts: z.object({
58
+ total: z.int().nonnegative().nullable(),
59
+ discovered: z.int().nonnegative(),
60
+ created: z.int().nonnegative(),
61
+ updated: z.int().nonnegative(),
62
+ unchanged: z.int().nonnegative(),
63
+ error: z.int().nonnegative(),
64
+ unprocessed: z.int().nonnegative(),
65
+ }),
66
+ poll_after_seconds: z.int().positive().nullable(),
67
+ error: z.object({ message: z.string() }).nullable(),
68
+ });
69
+ export function privateReport(findings, limits) {
70
+ if (findings.length > 10_000)
71
+ throw new CodexSecurityError("A structured report accepts up to 10,000 findings. Split this selection.");
72
+ const records = findings.map(({ source_finding_id, evidence }) => {
73
+ if (source_finding_id !== source_finding_id.trim())
74
+ throw new CodexSecurityError("A private source finding ID cannot have leading or trailing whitespace.");
75
+ const record = {
76
+ source_finding_id,
77
+ evidence: {
78
+ ...evidence,
79
+ severity: evidence.severity === "unknown" ? null : evidence.severity,
80
+ locations: evidence.locations?.map(({ path, line }, index) => ({
81
+ path,
82
+ start_line: line,
83
+ ...(index === 0 && evidence.details?.code?.end_line != null
84
+ ? { end_line: evidence.details.code.end_line }
85
+ : {}),
86
+ })),
87
+ },
88
+ };
89
+ if (Buffer.byteLength(canonicalJson(record)) > limits.max_record_bytes)
90
+ throw new CodexSecurityError(`Finding ${JSON.stringify(source_finding_id)} exceeds the private import record limit.`);
91
+ return record;
92
+ });
93
+ const bytes = canonicalJson({ format: structuredFormat, findings: records });
94
+ if (Buffer.byteLength(bytes) > limits.max_direct_file_bytes)
95
+ throw new CodexSecurityError("The selected report exceeds the Cloud direct-upload limit. Split this selection.");
96
+ return {
97
+ format: structuredFormat,
98
+ bytes,
99
+ digest: hash("sha256", bytes),
100
+ };
101
+ }
102
+ const endorExport = z.strictObject({
103
+ list: z.strictObject({
104
+ objects: z.array(z.unknown()),
105
+ response: z
106
+ .strictObject({
107
+ next_page_id: z.literal(["", null]).optional(),
108
+ next_page_token: z.literal(["", "0", 0, null]).optional(),
109
+ total_size: z.union([z.string(), z.number()]).optional(),
110
+ })
111
+ .optional(),
112
+ }),
113
+ });
114
+ const wizExport = z.strictObject({
115
+ vulnerabilityFindings: z.strictObject({
116
+ nodes: z.array(z.unknown()),
117
+ pageInfo: z
118
+ .strictObject({
119
+ hasNextPage: z.literal(false).optional(),
120
+ hasPreviousPage: z.literal(false).optional(),
121
+ startCursor: z.string().nullable().optional(),
122
+ endCursor: z.string().nullable().optional(),
123
+ })
124
+ .optional(),
125
+ }),
126
+ });
127
+ // Only complete, known envelopes can be sent byte for byte. Unreviewed sibling
128
+ // collections, metadata or partial pages keep the normalized projection.
129
+ function nativeRecords(payload, provider) {
130
+ if (provider === "wiz" && Array.isArray(payload))
131
+ return payload;
132
+ if (!isRecord(payload))
133
+ return;
134
+ if (provider === "endor") {
135
+ if (isRecord(payload["spec"]))
136
+ return [payload];
137
+ return endorExport.safeParse(payload).data?.list.objects;
138
+ }
139
+ if (typeof payload["id"] === "string")
140
+ return [payload];
141
+ const data = Object.keys(payload).length === 1 && "data" in payload
142
+ ? payload["data"]
143
+ : payload;
144
+ return wizExport.safeParse(data).data?.vulnerabilityFindings.nodes;
145
+ }
146
+ export async function selectPrivateReport(selection, provider, path, context, saved) {
147
+ const checkpoint = saved === undefined ? undefined : checkpointSchema.parse(JSON.parse(saved));
148
+ const originalFormat = checkpoint?.contextVersion === context.context_version
149
+ ? checkpoint.format
150
+ : undefined;
151
+ const format = provider === "endor"
152
+ ? "endor.findings_json.v1"
153
+ : provider === "wiz"
154
+ ? "wiz.vulnerability_json.v1"
155
+ : undefined;
156
+ if (format &&
157
+ path &&
158
+ selection.excluded.length === 0 &&
159
+ selection.read <= 10_000 &&
160
+ selection.findings.length === selection.read &&
161
+ (originalFormat
162
+ ? originalFormat === format
163
+ : context.formats.includes(format))) {
164
+ const handle = await open(path, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
165
+ let bytes;
166
+ try {
167
+ const info = await handle.stat();
168
+ if (info.isFile() &&
169
+ info.size > 0 &&
170
+ info.size <= context.limits.max_direct_file_bytes) {
171
+ const buffer = Buffer.alloc(info.size + 1);
172
+ let count = 0;
173
+ while (count < buffer.length) {
174
+ const { bytesRead } = await handle.read(buffer, count, buffer.length - count);
175
+ if (bytesRead === 0)
176
+ break;
177
+ count += bytesRead;
178
+ }
179
+ if (count === info.size) {
180
+ try {
181
+ bytes = new TextDecoder("utf-8", {
182
+ fatal: true,
183
+ ignoreBOM: true,
184
+ }).decode(buffer.subarray(0, count));
185
+ }
186
+ catch {
187
+ /* Binary exports use the normalized selection. */
188
+ }
189
+ }
190
+ }
191
+ }
192
+ finally {
193
+ await handle.close();
194
+ }
195
+ if (bytes !== undefined) {
196
+ let payload;
197
+ try {
198
+ payload = JSON.parse(bytes.replace(/^\uFEFF/u, ""));
199
+ }
200
+ catch {
201
+ /* JSONL and other exports use the normalized selection. */
202
+ }
203
+ const records = nativeRecords(payload, provider);
204
+ if (records &&
205
+ records.length === selection.findings.length &&
206
+ records.every((raw, index) => {
207
+ const reviewed = selection.findings[index];
208
+ if (!isRecord(raw))
209
+ return false;
210
+ const record = canonicalJson(raw);
211
+ return (raw[provider === "endor" ? "uuid" : "id"] ===
212
+ reviewed.source_finding_id &&
213
+ reviewed.source_finding_id === reviewed.source_finding_id.trim() &&
214
+ reviewed.evidence.source_data != null &&
215
+ record === canonicalJson(reviewed.evidence.source_data) &&
216
+ Buffer.byteLength(record) <= context.limits.max_record_bytes);
217
+ }))
218
+ return { format, bytes, digest: hash("sha256", bytes) };
219
+ }
220
+ }
221
+ if (originalFormat && originalFormat !== structuredFormat)
222
+ throw new CodexSecurityError("The original native report is required to resume this private import.");
223
+ return privateReport(selection.findings, context.limits);
224
+ }
225
+ const checkpointSchema = z.object({
226
+ format: privateFormat.default(structuredFormat),
227
+ apiBaseUrl: z.string(),
228
+ accountId: z.string(),
229
+ contextVersion: z.string(),
230
+ sha256: z.string(),
231
+ source: z.object({ provider: z.string(), source_key: z.string() }),
232
+ repository: z.object({ id: z.string(), repo_connector_id: z.string() }),
233
+ uploadRequestId: z.uuid(),
234
+ jobRequestId: z.uuid(),
235
+ fileId: fileId.optional(),
236
+ jobId: jobSchema.shape.id.optional(),
237
+ receipt: jobSchema
238
+ .refine((job) => job.status === "completed" || unsuccessfulJob(job))
239
+ .optional(),
240
+ previousReceipt: jobSchema.refine(unsuccessfulJob).optional(),
241
+ });
242
+ export function unsuccessfulJob(job) {
243
+ return job?.status === "failed" || job?.status === "cancelled";
244
+ }
245
+ export function readPrivateCheckpoint(serialized, expected) {
246
+ const checkpoint = checkpointSchema.parse(JSON.parse(serialized));
247
+ const { uploadRequestId, jobRequestId, fileId, jobId, receipt, previousReceipt, contextVersion, format, sha256, ...scope } = checkpoint;
248
+ const { contextVersion: currentContext, format: selectedFormat, sha256: selectedDigest, ...selectedScope } = expected;
249
+ const sameContext = contextVersion === currentContext;
250
+ if (canonicalJson(scope) !== canonicalJson(selectedScope) ||
251
+ (sameContext && (format !== selectedFormat || sha256 !== selectedDigest)) ||
252
+ (jobId && !fileId) ||
253
+ [receipt, previousReceipt].some((job) => job &&
254
+ (job.input.format !== format ||
255
+ canonicalJson(job.source) !== canonicalJson(scope.source) ||
256
+ job.default_targets.length !== 1 ||
257
+ job.default_targets[0]?.repo_id !== scope.repository.id ||
258
+ job.default_targets[0]?.repo_connector_id !==
259
+ scope.repository.repo_connector_id)) ||
260
+ (receipt &&
261
+ (receipt.id !== jobId ||
262
+ receipt.request_id !== jobRequestId ||
263
+ receipt.input.file_id !== fileId)) ||
264
+ uploadRequestId === jobRequestId)
265
+ throw new CodexSecurityError("Saved private import does not match this account, repository or report.");
266
+ return sameContext ? checkpoint : undefined;
267
+ }
268
+ export class PrivateImportRequestError extends CodexSecurityError {
269
+ status;
270
+ code;
271
+ constructor(status, code, message) {
272
+ super(message);
273
+ this.status = status;
274
+ this.code = code;
275
+ }
276
+ }
277
+ export function privateImportClient(base, credentials, fetch, signal) {
278
+ async function request(path, body) {
279
+ const timeout = AbortSignal.timeout(body === undefined ? 30_000 : 60_000);
280
+ const response = await fetch(`${base}/finding-imports/${path}`, {
281
+ method: body === undefined ? "GET" : "POST",
282
+ body,
283
+ redirect: "error",
284
+ headers: {
285
+ Authorization: `Bearer ${credentials.access_token}`,
286
+ "ChatGPT-Account-ID": credentials.account_id,
287
+ Accept: "application/json",
288
+ ...(typeof body === "string"
289
+ ? { "Content-Type": "application/json" }
290
+ : {}),
291
+ },
292
+ signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
293
+ });
294
+ if (!response.ok) {
295
+ const payload = await response.json().catch(() => undefined);
296
+ const error = z
297
+ .object({
298
+ error: z.object({ code: z.string(), message: z.string().optional() }),
299
+ })
300
+ .safeParse(payload);
301
+ const detail = error.data?.error;
302
+ throw new PrivateImportRequestError(response.status, detail?.code, `Private import failed (HTTP ${response.status}): ${detail?.message ?? detail?.code ?? response.statusText}`);
303
+ }
304
+ return response;
305
+ }
306
+ return {
307
+ async context() {
308
+ return contextSchema.parse(await (await request("context")).json());
309
+ },
310
+ async upload(input) {
311
+ let response;
312
+ if (input.recovering) {
313
+ try {
314
+ response = await request(`file-requests/${input.requestId}`);
315
+ }
316
+ catch (error) {
317
+ if (!(error instanceof PrivateImportRequestError) ||
318
+ (error.status !== 404 &&
319
+ !(error.status === 409 && error.code === "upload_retryable")))
320
+ throw error;
321
+ }
322
+ }
323
+ if (!response) {
324
+ const form = new FormData();
325
+ form.set("request_id", input.requestId);
326
+ form.set("context_version", input.contextVersion);
327
+ form.set("purpose", "report");
328
+ form.set("file", new Blob([input.bytes], { type: "application/json" }), "findings.json");
329
+ response = await request("files", form);
330
+ }
331
+ const file = fileSchema.parse(await response.json());
332
+ if (file.sha256 !== input.digest ||
333
+ file.bytes !== Buffer.byteLength(input.bytes))
334
+ throw new CodexSecurityError("The uploaded file does not match the reviewed report.");
335
+ return file.id;
336
+ },
337
+ async job(input, accepted) {
338
+ let id = input.jobId;
339
+ let response = id
340
+ ? await request(`jobs/${id}`)
341
+ : await request("jobs", JSON.stringify({
342
+ request_id: input.requestId,
343
+ context_version: input.contextVersion,
344
+ source: input.source,
345
+ input: {
346
+ type: "file",
347
+ file_id: input.fileId,
348
+ format: input.format,
349
+ },
350
+ default_targets: [
351
+ {
352
+ type: "repository",
353
+ repo_id: input.repository.id,
354
+ repo_connector_id: input.repository.repo_connector_id,
355
+ },
356
+ ],
357
+ }));
358
+ for (;;) {
359
+ const job = jobSchema.parse(await response.json());
360
+ if ((id !== undefined && job.id !== id) ||
361
+ job.request_id !== input.requestId ||
362
+ job.input.file_id !== input.fileId ||
363
+ job.input.format !== input.format ||
364
+ job.source.provider !== input.source.provider ||
365
+ job.source.source_key !== input.source.source_key ||
366
+ job.default_targets.length !== 1 ||
367
+ job.default_targets[0]?.repo_id !== input.repository.id ||
368
+ job.default_targets[0]?.repo_connector_id !==
369
+ input.repository.repo_connector_id)
370
+ throw new CodexSecurityError("Cloud returned a job for a different private import.");
371
+ if (job.status === "completed" ||
372
+ job.status === "failed" ||
373
+ job.status === "cancelled")
374
+ return job;
375
+ if (!id) {
376
+ id = job.id;
377
+ await accepted(id);
378
+ }
379
+ const retry = response.headers.get("Retry-After");
380
+ const seconds = retry === null ? 0 : Number(retry);
381
+ await delay(Math.max(Number.isFinite(seconds) ? seconds : 0, job.poll_after_seconds ?? 1) * 1000, undefined, { signal });
382
+ response = await request(`jobs/${id}`);
383
+ }
384
+ },
385
+ };
386
+ }
387
+ //# sourceMappingURL=private-finding-import.js.map