@preventive/triage 1.0.0-alpha.8 → 1.0.0-alpha.80

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 (442) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +16 -78
  4. package/cli.js +6 -0
  5. package/client/dependency-paths.d.ts +3 -0
  6. package/client/dependency-paths.js +36 -0
  7. package/client/finding-link.js +305 -0
  8. package/client/linked-findings.d.ts +1 -0
  9. package/client/linked-findings.js +115 -0
  10. package/common/bundle-commit.d.ts +1 -0
  11. package/common/bundle-commit.js +4 -0
  12. package/common/bundle-compare-diff.d.ts +6 -0
  13. package/common/bundle-compare-diff.js +377 -0
  14. package/common/bundle-compare-inputs.d.ts +3 -0
  15. package/common/bundle-compare-inputs.js +141 -0
  16. package/common/bundle-compare-versions.js +172 -0
  17. package/common/bundle-comparison.d.ts +8 -0
  18. package/common/bundle-comparison.js +69 -0
  19. package/common/bundle-imports.js +20 -0
  20. package/common/bundle-metadata.d.ts +15 -0
  21. package/common/bundle-metadata.js +226 -0
  22. package/common/bundle-pkg-of.d.ts +1 -0
  23. package/common/bundle-pkg-of.js +90 -0
  24. package/common/bundle-reasons.d.ts +6 -0
  25. package/common/bundle-reasons.js +58 -0
  26. package/common/bundle-source-links.d.ts +6 -0
  27. package/common/bundle-source-links.js +216 -0
  28. package/common/bundle-sourcemap.d.ts +10 -0
  29. package/common/bundle-sourcemap.js +100 -0
  30. package/common/bundle-sources.d.ts +10 -0
  31. package/common/bundle-sources.js +374 -0
  32. package/common/bundle-stats.js +41 -0
  33. package/common/bundle-tabs.js +1 -0
  34. package/common/code-language.js +66 -0
  35. package/common/default-scan-models.ts +36 -0
  36. package/common/dependency-reviews.d.ts +18 -0
  37. package/common/dependency-reviews.js +64 -0
  38. package/common/finding-duplicates.js +63 -0
  39. package/common/finding-filters.js +313 -0
  40. package/common/finding-id.js +47 -0
  41. package/common/finding-repo.d.ts +5 -0
  42. package/common/finding-repo.js +67 -0
  43. package/common/github-issue-labels.d.ts +1 -0
  44. package/common/github-issue-labels.js +11 -0
  45. package/common/github-pr.ts +56 -0
  46. package/common/gzip.js +59 -0
  47. package/common/line-diff.d.ts +14 -0
  48. package/common/line-diff.js +181 -0
  49. package/common/linked-workspace-groups.js +63 -0
  50. package/common/managed/agent-tasks.ts +292 -0
  51. package/common/managed/comments.ts +43 -0
  52. package/common/managed/dependency-routes.js +25 -0
  53. package/common/managed/directory-packages.ts +28 -0
  54. package/common/managed/finding-detail.d.ts +5 -0
  55. package/common/managed/finding-detail.js +75 -0
  56. package/common/managed/finding-values.d.ts +2 -0
  57. package/common/managed/finding-values.js +138 -0
  58. package/common/managed/github-agents.ts +114 -0
  59. package/common/managed/github-logins.ts +49 -0
  60. package/common/managed/lite-name.d.ts +2 -0
  61. package/common/managed/lite-name.js +20 -0
  62. package/common/managed/npm-packages.d.ts +9 -0
  63. package/common/managed/npm-packages.js +63 -0
  64. package/common/managed/permissions.ts +31 -0
  65. package/common/managed/report-content.ts +72 -0
  66. package/common/managed/report-filter.ts +120 -0
  67. package/common/managed/repository-alias.ts +65 -0
  68. package/common/managed/review-view-routes.js +23 -0
  69. package/common/managed/risk-routes.js +30 -0
  70. package/common/managed/roles.ts +41 -0
  71. package/common/managed/routes.d.ts +2 -0
  72. package/common/managed/routes.js +385 -0
  73. package/common/managed/scan-models.ts +6 -0
  74. package/common/managed/stasis-config.ts +7 -0
  75. package/common/managed/team-app.d.ts +19 -0
  76. package/common/managed/team-app.js +129 -0
  77. package/common/managed/team-filters.js +26 -0
  78. package/common/managed/triage.ts +83 -0
  79. package/common/managed/upload-seal.ts +126 -0
  80. package/common/pretty-json.js +98 -0
  81. package/common/pretty-kinds.js +20 -0
  82. package/common/pretty-print.d.ts +6 -0
  83. package/common/pretty-print.js +36 -0
  84. package/common/pretty-sourcemap.js +70 -0
  85. package/common/repo-commit.d.ts +4 -0
  86. package/common/repo-commit.js +30 -0
  87. package/common/revalidation-conflicts.js +48 -0
  88. package/common/revalidation-input-groups.js +56 -0
  89. package/common/save-error-reason.ts +20 -7
  90. package/common/scan-server.ts +13 -0
  91. package/common/security-links.d.ts +5 -0
  92. package/common/security-links.js +33 -0
  93. package/common/server-info.ts +46 -0
  94. package/common/sourcemap-listing.js +78 -0
  95. package/common/sourcemap-mappings.js +136 -0
  96. package/common/sourcemap-unlist.js +85 -0
  97. package/common/stasis-files.d.ts +5 -0
  98. package/common/stasis-files.js +20 -0
  99. package/common/stasis-tgz.d.ts +6 -0
  100. package/common/stasis-tgz.js +27 -0
  101. package/common/utf8.d.ts +3 -0
  102. package/common/utf8.js +45 -0
  103. package/common/whitespace-insensitive.js +19 -0
  104. package/common/workspace-app.js +91 -0
  105. package/common/workspace-groups.js +176 -0
  106. package/out/activity.js +2 -0
  107. package/out/brotli-fallback.js +3 -3
  108. package/out/chunk-2XUEZHIP.js +28 -0
  109. package/out/chunk-55YIWY3H.js +5 -0
  110. package/out/chunk-5AVGKFMR.js +1 -0
  111. package/out/chunk-5CJKUV53.js +1 -0
  112. package/out/chunk-5EAVJAD2.js +3 -0
  113. package/out/chunk-5M2X3QPK.js +6 -0
  114. package/out/chunk-5QWPKTCE.js +40 -0
  115. package/out/chunk-6CCSTJWB.js +1 -0
  116. package/out/chunk-6VOB5WXX.js +2 -0
  117. package/out/chunk-6Y6PZ2BU.js +9 -0
  118. package/out/chunk-74JZTGTO.js +11 -0
  119. package/out/chunk-7BKKYVWR.js +7 -0
  120. package/out/chunk-7C7DWL7I.js +1 -0
  121. package/out/chunk-7HP2VYIC.js +2 -0
  122. package/out/chunk-7YFJUT2P.js +1 -0
  123. package/out/chunk-7YO4QV5P.js +1 -0
  124. package/out/chunk-A4BBBHQU.js +1 -0
  125. package/out/chunk-B64CTMVU.js +4 -0
  126. package/out/chunk-BEKYZCPX.js +14 -0
  127. package/out/chunk-C4Z6ZBXV.js +10 -0
  128. package/out/chunk-CU3FPB3P.js +1 -0
  129. package/out/chunk-DEVAORP2.js +1 -0
  130. package/out/chunk-DUASGS2O.js +8 -0
  131. package/out/chunk-DUS5ARE2.js +53 -0
  132. package/out/chunk-EEJA7JBI.js +13 -0
  133. package/out/chunk-FSU2PLJL.js +1 -0
  134. package/out/chunk-GBMAXAYK.js +3 -0
  135. package/out/chunk-GO7FT4OD.js +1 -0
  136. package/out/chunk-GX5UXWT4.js +1 -0
  137. package/out/chunk-ITUKKCCK.js +10 -0
  138. package/out/chunk-IYPY47MC.js +1 -0
  139. package/out/chunk-JXBRWLMA.js +4 -0
  140. package/out/chunk-K4XJHM2T.js +1 -0
  141. package/out/chunk-LBD3M3J6.js +1 -0
  142. package/out/chunk-LVSLM7HB.js +1 -0
  143. package/out/chunk-LVW7WWV4.js +1 -0
  144. package/out/chunk-MV66NL3G.js +3 -0
  145. package/out/chunk-N57OWFKY.js +15 -0
  146. package/out/chunk-NRPC74AM.js +1 -0
  147. package/out/chunk-OOJM4CTU.js +1 -0
  148. package/out/chunk-OWSEQOL5.js +1 -0
  149. package/out/chunk-PKLVXUEI.js +11 -0
  150. package/out/chunk-PLGH63UC.js +2 -0
  151. package/out/chunk-PNHBZGDD.js +1 -0
  152. package/out/chunk-PTFYDJUP.js +1 -0
  153. package/out/chunk-PWFUOLZK.js +17 -0
  154. package/out/chunk-PXK7EU4V.js +1 -0
  155. package/out/chunk-QD3IBSF4.js +7 -0
  156. package/out/chunk-QI66YA4F.js +1 -0
  157. package/out/chunk-QRKFPLA4.js +80 -0
  158. package/out/chunk-R3NZFXVR.js +1 -0
  159. package/out/chunk-R5O6FAW4.js +2 -0
  160. package/out/chunk-RPNO56H2.js +1 -0
  161. package/out/chunk-SSPDMA6D.js +1 -0
  162. package/out/chunk-SZWPYLPC.js +1 -0
  163. package/out/chunk-TUII34K2.js +1 -0
  164. package/out/chunk-UJP4PQJA.js +1 -0
  165. package/out/chunk-UJSJMXEG.js +1 -0
  166. package/out/chunk-UR4WYMIP.js +1 -0
  167. package/out/chunk-VHEXSGGP.js +1 -0
  168. package/out/chunk-VYYUMYVW.js +9 -0
  169. package/out/chunk-VZPPX6MV.js +1 -0
  170. package/out/chunk-WCDYSIKG.js +1 -0
  171. package/out/chunk-XM4RLC4A.js +2 -0
  172. package/out/chunk-YKCRCNYZ.js +266 -0
  173. package/out/chunk-ZQHLECTI.js +1 -0
  174. package/out/client-managed-import.js +4 -0
  175. package/out/client-managed.js +37 -0
  176. package/out/client-sync.js +11 -17
  177. package/out/compare.js +26 -0
  178. package/out/dialogs.js +40 -0
  179. package/out/github-issue-authorized.html +3 -0
  180. package/out/github-issue-authorized.js +1 -0
  181. package/out/graph.js +19 -4
  182. package/out/index.html +104 -24
  183. package/out/prism.js +14 -10
  184. package/out/scan.js +2 -0
  185. package/out/stasis.svg +20 -0
  186. package/out/terminal.js +367 -39
  187. package/out/view.css +1 -1
  188. package/out/view.js +19 -147
  189. package/package.json +409 -64
  190. package/risk/actions/findings.js +161 -0
  191. package/risk/actions/resolve.js +287 -0
  192. package/risk/actions/scripts/commands.js +182 -0
  193. package/risk/actions/scripts/grade.js +113 -0
  194. package/risk/actions/scripts/packages.js +123 -0
  195. package/risk/actions/scripts/shell.js +169 -0
  196. package/risk/actions/uses.js +94 -0
  197. package/risk/actions/workflow.js +183 -0
  198. package/risk/files/characters.js +341 -0
  199. package/risk/files/hosts.js +206 -0
  200. package/risk/files/readability.js +185 -0
  201. package/risk/files/runs-code.js +563 -0
  202. package/risk/files/script.js +402 -0
  203. package/risk/files/source-map-link.js +43 -0
  204. package/risk/files/stamps.js +47 -0
  205. package/risk/index.d.ts +294 -0
  206. package/risk/index.js +12 -0
  207. package/risk/npm/assess.js +285 -0
  208. package/risk/npm/combined.js +68 -0
  209. package/risk/npm/compare.js +236 -0
  210. package/risk/npm/dependencies.js +172 -0
  211. package/risk/npm/diff.js +79 -0
  212. package/risk/npm/downloads.js +84 -0
  213. package/risk/npm/files.js +445 -0
  214. package/risk/npm/held.js +67 -0
  215. package/risk/npm/install-scripts.js +34 -0
  216. package/risk/npm/malware.js +38 -0
  217. package/risk/npm/manifest.js +65 -0
  218. package/risk/npm/new-dependency.js +60 -0
  219. package/risk/npm/old-version.js +108 -0
  220. package/risk/npm/registry.js +393 -0
  221. package/risk/npm/release.js +85 -0
  222. package/risk/npm/score.js +59 -0
  223. package/risk/npm/specs.js +124 -0
  224. package/risk/npm/tarball.js +169 -0
  225. package/server-common/database-config.ts +16 -0
  226. package/server-common/initialize.ts +18 -0
  227. package/server-common/npm-advisories.ts +101 -0
  228. package/{server → server-common}/origin.ts +5 -5
  229. package/server-common/reap.ts +48 -0
  230. package/server-common/scan-config.ts +19 -0
  231. package/server-common/standalone.ts +29 -0
  232. package/server-common/storage-crypto.ts +182 -0
  233. package/server-common/storage-log.ts +38 -0
  234. package/server-common/vercel-blob.ts +103 -0
  235. package/server-e2e/app.ts +487 -0
  236. package/{server → server-e2e}/bus-receiver.ts +2 -1
  237. package/{server → server-e2e}/cli.js +9 -4
  238. package/{server → server-e2e}/config.ts +50 -42
  239. package/{server → server-e2e}/db-neon.ts +2 -2
  240. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  241. package/{server → server-e2e}/db-stmt.ts +2 -2
  242. package/{server → server-e2e}/db.ts +7 -7
  243. package/{server → server-e2e}/http.ts +44 -13
  244. package/{server → server-e2e}/hub.ts +40 -9
  245. package/server-e2e/index.ts +17 -0
  246. package/server-e2e/lifecycle.ts +95 -0
  247. package/{server → server-e2e}/neon-driver.ts +2 -2
  248. package/{server → server-e2e}/npm-proxy.ts +12 -145
  249. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  250. package/{server → server-e2e}/objstore/blob.ts +1 -1
  251. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  252. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  253. package/{server → server-e2e}/objstore/init.ts +19 -27
  254. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  255. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  256. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  257. package/{server → server-e2e}/objstore/rest.ts +3 -3
  258. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  259. package/{server → server-e2e}/objstore/store.ts +7 -7
  260. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  261. package/{server → server-e2e}/pubsub.ts +12 -9
  262. package/{server → server-e2e}/sign.ts +4 -4
  263. package/{server → server-e2e}/sse-server.ts +60 -33
  264. package/{server → server-e2e}/static.ts +18 -17
  265. package/{server → server-e2e}/sync-handlers.ts +64 -30
  266. package/{server → server-e2e}/ws-server.ts +20 -9
  267. package/server-managed/activity.ts +247 -0
  268. package/server-managed/agent-merges.ts +109 -0
  269. package/server-managed/app-agents.ts +23 -0
  270. package/server-managed/avatar-store.ts +13 -0
  271. package/server-managed/blob-store.ts +26 -0
  272. package/server-managed/brotli.ts +10 -0
  273. package/server-managed/bundle-advisories.ts +79 -0
  274. package/server-managed/bundle-advisory-inventory.ts +85 -0
  275. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  276. package/server-managed/bundle-build-diagnostics.js +23 -0
  277. package/server-managed/bundle-build-leases.ts +41 -0
  278. package/server-managed/bundle-build-worker.js +380 -0
  279. package/server-managed/bundle-build.ts +326 -0
  280. package/server-managed/bundle-cache.ts +261 -0
  281. package/server-managed/bundle-catalog.ts +29 -0
  282. package/server-managed/bundle-commits.ts +133 -0
  283. package/server-managed/bundle-dependency-reviews.ts +91 -0
  284. package/server-managed/bundle-store.ts +24 -0
  285. package/server-managed/bundle-summary-cache.ts +139 -0
  286. package/server-managed/bundle-validation.ts +33 -0
  287. package/server-managed/bundle.ts +151 -0
  288. package/server-managed/cache-storage.ts +20 -0
  289. package/server-managed/cli.js +21 -0
  290. package/server-managed/combined.ts +43 -0
  291. package/server-managed/comments.ts +138 -0
  292. package/server-managed/commit-coauthors.ts +105 -0
  293. package/server-managed/commit-lockfiles.ts +78 -0
  294. package/server-managed/comparison.ts +51 -0
  295. package/server-managed/config.ts +163 -0
  296. package/server-managed/content-access.ts +15 -0
  297. package/server-managed/crypto.ts +25 -0
  298. package/server-managed/db-methods.ts +1914 -0
  299. package/server-managed/db-neon.ts +398 -0
  300. package/server-managed/db-schema.ts +263 -0
  301. package/server-managed/db-table-names.ts +22 -0
  302. package/server-managed/db.ts +149 -0
  303. package/server-managed/dependabot-access.ts +61 -0
  304. package/server-managed/dependabot-alerts.ts +180 -0
  305. package/server-managed/dependency-review-comments.ts +143 -0
  306. package/server-managed/dependency-reviews.ts +369 -0
  307. package/server-managed/github-accounts.ts +59 -0
  308. package/server-managed/github-actions.ts +71 -0
  309. package/server-managed/github-app.ts +347 -0
  310. package/server-managed/github-errors.ts +92 -0
  311. package/server-managed/github-graphql.ts +42 -0
  312. package/server-managed/github-issue-links.ts +264 -0
  313. package/server-managed/github-issue-oauth.ts +30 -0
  314. package/server-managed/github-issues.ts +157 -0
  315. package/server-managed/github-link-oauth.ts +56 -0
  316. package/server-managed/github-links.ts +204 -0
  317. package/server-managed/github-metadata.ts +213 -0
  318. package/server-managed/github-oauth.ts +264 -0
  319. package/server-managed/github-pulls.ts +257 -0
  320. package/server-managed/github-requests.ts +181 -0
  321. package/server-managed/github-users.ts +30 -0
  322. package/server-managed/github-values.ts +26 -0
  323. package/server-managed/history-windows.ts +172 -0
  324. package/server-managed/http-response.ts +76 -0
  325. package/server-managed/http.ts +6324 -0
  326. package/server-managed/import-triage.ts +51 -0
  327. package/server-managed/index.ts +204 -0
  328. package/server-managed/kept-briefly.ts +37 -0
  329. package/server-managed/kept.ts +28 -0
  330. package/server-managed/link-reports.ts +149 -0
  331. package/server-managed/listed-activity.ts +39 -0
  332. package/server-managed/locked-packages.ts +234 -0
  333. package/server-managed/lockfile-scope.ts +58 -0
  334. package/server-managed/lru.ts +30 -0
  335. package/server-managed/managed-issues.ts +92 -0
  336. package/server-managed/management-catalog.ts +45 -0
  337. package/server-managed/management.ts +116 -0
  338. package/server-managed/npm-delta-worker.js +142 -0
  339. package/server-managed/npm-delta.ts +277 -0
  340. package/server-managed/npm-insights.ts +455 -0
  341. package/server-managed/npm-kept.ts +265 -0
  342. package/server-managed/npm-loads.ts +259 -0
  343. package/server-managed/npm-manifest.ts +117 -0
  344. package/server-managed/npm-packages.ts +469 -0
  345. package/server-managed/npm-patch-paths.ts +86 -0
  346. package/server-managed/npm-patch.ts +455 -0
  347. package/server-managed/npm-provenance.ts +127 -0
  348. package/server-managed/npm-risk.ts +287 -0
  349. package/server-managed/object-storage-disk.ts +147 -0
  350. package/server-managed/object-storage-vercel.ts +71 -0
  351. package/server-managed/object-storage.ts +82 -0
  352. package/server-managed/package-entry-points.ts +127 -0
  353. package/server-managed/pretty-copies.ts +22 -0
  354. package/server-managed/pretty-format.d.ts +3 -0
  355. package/server-managed/pretty-format.js +13 -0
  356. package/server-managed/pretty-print.ts +442 -0
  357. package/server-managed/public-workspace.ts +243 -0
  358. package/server-managed/pull-comment-reviews.ts +161 -0
  359. package/server-managed/pull-dependencies.ts +370 -0
  360. package/server-managed/pull-dependency-reviews.ts +407 -0
  361. package/server-managed/pull-reviews.ts +202 -0
  362. package/server-managed/queue.ts +54 -0
  363. package/server-managed/release-commits.ts +85 -0
  364. package/server-managed/rename-diff-worker.js +30 -0
  365. package/server-managed/rename-diff.ts +237 -0
  366. package/server-managed/repo-path.ts +21 -0
  367. package/server-managed/report-migration.ts +32 -0
  368. package/server-managed/report-opening.ts +77 -0
  369. package/server-managed/report-query.ts +10 -0
  370. package/server-managed/report-response.ts +16 -0
  371. package/server-managed/report-sources.ts +185 -0
  372. package/server-managed/report-store.ts +77 -0
  373. package/server-managed/repository-actions.ts +220 -0
  374. package/server-managed/repository-agents.ts +422 -0
  375. package/server-managed/repository-aliases.ts +119 -0
  376. package/server-managed/repository-browser.ts +361 -0
  377. package/server-managed/repository-changes.ts +280 -0
  378. package/server-managed/repository-code.ts +222 -0
  379. package/server-managed/repository-dependency-reviews.ts +182 -0
  380. package/server-managed/repository-discovery.ts +83 -0
  381. package/server-managed/repository-history.ts +428 -0
  382. package/server-managed/repository-issues.ts +293 -0
  383. package/server-managed/repository-policy.ts +27 -0
  384. package/server-managed/repository-pulls.ts +207 -0
  385. package/server-managed/repository-pulse.ts +477 -0
  386. package/server-managed/repository-risk-assess.ts +108 -0
  387. package/server-managed/repository-risk-audit.ts +78 -0
  388. package/server-managed/repository-risk-caches.ts +37 -0
  389. package/server-managed/repository-risk-read.ts +260 -0
  390. package/server-managed/repository-risk-stasis.ts +61 -0
  391. package/server-managed/repository-risk-turn.ts +97 -0
  392. package/server-managed/repository-risk.ts +516 -0
  393. package/server-managed/repository-squashes.ts +160 -0
  394. package/server-managed/repository-stamp.ts +41 -0
  395. package/server-managed/request-timing.ts +63 -0
  396. package/server-managed/reviewed-dependencies.ts +170 -0
  397. package/server-managed/revisions.ts +35 -0
  398. package/server-managed/scan-downloads.ts +121 -0
  399. package/server-managed/session.ts +132 -0
  400. package/server-managed/slugs.ts +38 -0
  401. package/server-managed/solidity-entry-points.ts +71 -0
  402. package/server-managed/sql-postgres.ts +34 -0
  403. package/server-managed/sql.ts +107 -0
  404. package/server-managed/stasis-config.ts +147 -0
  405. package/server-managed/stasis-dependencies.ts +221 -0
  406. package/server-managed/static.ts +28 -0
  407. package/server-managed/storage-command.ts +16 -0
  408. package/server-managed/storage-db.ts +183 -0
  409. package/server-managed/storage-encryption.ts +288 -0
  410. package/server-managed/storage-maintenance.ts +259 -0
  411. package/server-managed/storage-payload.ts +121 -0
  412. package/server-managed/storage-stores.ts +91 -0
  413. package/server-managed/storage.ts +82 -0
  414. package/server-managed/team-app-summaries.ts +56 -0
  415. package/server-managed/team-app.ts +156 -0
  416. package/server-managed/team-catalog.ts +7 -0
  417. package/server-managed/team-feed.ts +180 -0
  418. package/server-managed/team-npm-scopes.ts +103 -0
  419. package/server-managed/team-reports.ts +368 -0
  420. package/server-managed/triage-response.ts +16 -0
  421. package/server-managed/type-only-proof.js +161 -0
  422. package/server-managed/type-only-worker.js +31 -0
  423. package/server-managed/type-only.ts +135 -0
  424. package/server-managed/uploads.ts +106 -0
  425. package/server-managed/upstream-cache.ts +256 -0
  426. package/server-managed/view-as.ts +58 -0
  427. package/server-managed/worker-turns.ts +76 -0
  428. package/server-managed/workspace-shares.ts +170 -0
  429. package/server.ts +70 -0
  430. package/strip-types-loader.js +13 -10
  431. package/server/index.ts +0 -480
  432. package/server/lifecycle.ts +0 -208
  433. /package/{LICENSE → LICENSE-MIT} +0 -0
  434. /package/{server → server-e2e}/auth.ts +0 -0
  435. /package/{server → server-e2e}/config.example.json +0 -0
  436. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  437. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  438. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  439. /package/{server → server-e2e}/peer.ts +0 -0
  440. /package/{server → server-e2e}/sse-session.ts +0 -0
  441. /package/{server → server-e2e}/util.ts +0 -0
  442. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,516 @@
1
+ // Every connected repository's npm packages, as its lockfiles lock them, each
2
+ // assessed by risk (npm-risk.ts), for admins: GET /api/admin/repositories/risk
3
+ // answers a line at a time as each is found and assessed, and stops once its
4
+ // reader leaves (`signal`).
5
+ //
6
+ // A repository's lockfiles are listed at its default branch's head by
7
+ // @preventive/upstream's findRepoLockfiles; of them, those of npm's ecosystem
8
+ // that @preventive/lockfile reads (package-lock.json and npm-shrinkwrap.json
9
+ // of `lockfileVersion: 3`, pnpm-lock.yaml of pnpm 9 to 12, and Yarn 1's
10
+ // yarn.lock) are read for their packages. A package from npm's registry is
11
+ // assessed once a scan, however many lockfiles lock it; one from another
12
+ // host with an integrity, such as a company's mirror of npm's, as npm's
13
+ // package of its name and version where npm's integrity is among it; one
14
+ // from elsewhere (git, a tarball with no integrity, a file) is listed, not
15
+ // assessed. Repositories are read a few at a time (READ_AHEAD), each told in
16
+ // turn, as GitHub's limits are the caller's; packages are assessed meanwhile, as many at a time as npm-risk.ts
17
+ // makes spare assessments: those with no risk line kept first, those a
18
+ // Stasis build installs before the rest, then those only devDependencies
19
+ // need in every lockfile that locks them (LockedPackage `dev`), as an install
20
+ // of no devDependencies leaves them out; then those told stale, in the same
21
+ // order (LEFT_OVER). A Stasis build still to be made isn't waited for: the
22
+ // versions it installs keep their place among the rest till it is made, the
23
+ // scan asking again what Stasis made as its page does (repository-risk-stasis.ts),
24
+ // and those still to assess then go first. A lockfile's packages of npm's
25
+ // registry or a mirror are asked of npm's advisories all at once, as `npm
26
+ // audit` asks, each advisory told with whether it is of malware (upstream's
27
+ // `malware`), which alone is a supply chain's risk; the rest are
28
+ // vulnerabilities, told beside. A repository's Dependabot alerts of npm's, open or dismissed,
29
+ // are told once its lockfiles' advisories are, each with the versions its
30
+ // lockfile locks that it covers, for the page to blend them into npm's; one
31
+ // whose alerts couldn't be had tells why, and the scan goes on. Its GitHub
32
+ // Actions are told once its lockfiles are, the references they make
33
+ // resolved as the scan goes on (repository-actions.ts). And what Stasis
34
+ // reaches of each of its stasis.config.json files, as its dependency review
35
+ // has a build tell it (stasis-dependencies.ts), told once its lockfiles are:
36
+ // the versions a build installs, or that it is still to be made, which isn't
37
+ // waited for, its page asking for it again (GET
38
+ // /api/admin/repositories/risk/stasis), or why it failed. A repository GitHub
39
+ // has archived is told so as it is opened, and read no further: nothing
40
+ // installs from it anew.
41
+ import type { LockfileFormat } from '@preventive/upstream/github.js'
42
+ import { type ActionsSource, type Severity, npmMalwareAdvisory } from '../risk/index.js'
43
+ import { isNpmPackageName, isNpmPackageSpec } from '../common/managed/npm-packages.js'
44
+ import { type RiskCaches, riskCaches } from './repository-risk-caches.ts'
45
+ import type { KeptStore } from './npm-kept.ts'
46
+ import type { LockedPackage } from './locked-packages.ts'
47
+ import { type Queue, inTurns, queue } from './queue.ts'
48
+ import type { DownloadsSource } from './scan-downloads.ts'
49
+ import { type AssessedPackage, type AssessingSource, RISK_KEPT_MS, type RiskFailure, assessPackage, failureOf } from './repository-risk-assess.ts'
50
+ import { type AdvisoryRow, type Audit, type AuditSource, auditLockfiles } from './repository-risk-audit.ts'
51
+ import { type DependabotRead, type ListedLockfile, type LockfileRead, type OpenedRepository, type RepositoryArchived, type RepositoryFailure, type RepositoryRead, SCAN_READ_KEPT_MS,
52
+ type StasisConfigsRead, readRepository, stasisBuilding, stasisVersions } from './repository-risk-read.ts'
53
+ import { STASIS_AGAIN_MS, type StasisBuild, type StasisReach, stasisReach } from './repository-risk-stasis.ts'
54
+ import { type Turn, assessingTurn } from './repository-risk-turn.ts'
55
+ import type { StasisRead } from './stasis-dependencies.ts'
56
+ import { type DependabotAlert, alertVersions } from './dependabot-alerts.ts'
57
+ import { type ActionLine, type ActionRef, type WorkflowLine, type WorkflowsLine, type WorkflowsRead, actionsLines,
58
+ lockedNames, resolvingActions } from './repository-actions.ts'
59
+
60
+ export { RISK_KEPT_MS, highestSeverity } from './repository-risk-assess.ts'
61
+ export { riskCaches } from './repository-risk-caches.ts'
62
+ export { SCAN_READ_KEPT_MS } from './repository-risk-read.ts'
63
+
64
+ // A repository to read: where `paths` are given, a team's directories in it,
65
+ // only the lockfiles in them or above them, as a workspace's root lockfile
66
+ // locks them too.
67
+ export interface RepositoryRiskRepo { repoId: number; fullName: string; paths?: readonly string[] }
68
+
69
+ interface RepositoryRiskSource<R extends RepositoryRiskRepo> extends AuditSource, AssessingSource {
70
+ repos(): Promise<R[]>
71
+ // Opened to read, or `archived` where GitHub has it so, read no further.
72
+ open(repo: R): Promise<OpenedRepository | { archived: true }>
73
+ // Whether a team lists a package's scope, its own packages.
74
+ teamScoped(name: string): Promise<boolean>
75
+ // Where risk lines are kept beyond this instance, as RiskCaches keeps them
76
+ // in it (npm-kept.ts riskLineStore, the database's).
77
+ risks?: KeptStore<RiskLine>
78
+ // Where a repository's lockfiles as listed at a commit, and a lockfile's
79
+ // packages by its blob, are kept beyond this instance, as RiskCaches keeps
80
+ // them in it (npm-kept.ts scanReadStore, the database's), each read for
81
+ // SCAN_READ_KEPT_MS: a scan answered in parts (`partMs`) goes on from
82
+ // where the last stopped on whichever instance answers the next.
83
+ listings?: KeptStore<ListedLockfile[]>
84
+ lockfiles?: KeptStore<LockfileRead>
85
+ // Where a scan answered in parts keeps, from one part to the next, the
86
+ // repositories it told whole (`partMs`): the next tells none of them again,
87
+ // nor asks GitHub of them, but looks up their packages' risks as their
88
+ // lockfiles are kept (`lockfiles`), as the reader has the rest already.
89
+ progress?: { read(): Promise<{ at: number; value: ScanProgress } | null>; write(progress: ScanProgress): Promise<void> } | undefined
90
+ // Readies npm's downloads of packages before they are assessed
91
+ // (scan-downloads.ts); without it, each assessment asks its own.
92
+ downloads?: DownloadsSource
93
+ // GitHub as references are resolved with; none without it.
94
+ actions?: ActionsSource
95
+ // Where Actions' files read and references resolved are kept.
96
+ actionFiles?: KeptStore<WorkflowsRead>
97
+ actionLines?: KeptStore<ActionLine>
98
+ // What Stasis has made of a build still to be made as its repository was
99
+ // read, as known now, asking GitHub nothing, nor for a build, as its page
100
+ // asks for them; none watched without it.
101
+ stasisBuilt?(build: StasisBuild): Promise<StasisRead>
102
+ }
103
+
104
+ // A Dependabot alert as a scan tells it: with the versions of its package
105
+ // the lockfile it is of locks that it covers, none where it is of none read
106
+ // (a package.json, bun's lockfile), and whether it is of malware, by the rule
107
+ // upstream tells an advisory's by (risk's npmMalwareAdvisory).
108
+ type DependabotAlertRow = DependabotAlert & { versions: string[]; malware: boolean }
109
+
110
+ // A risk line is of npm's package of its name and version, or, with an
111
+ // `integrity`, of a mirror's that its lockfiles hold to it; its `score` risk's
112
+ // of it, out of 100 (assessNpm `score`, risk/npm/score.js).
113
+ export type RepositoryRiskLine =
114
+ | { type: 'repos'; repos: { id: number; fullName: string }[] }
115
+ | ({ type: 'repo'; id: number } & ({ commit: string; lockfiles: { path: string; format: LockfileFormat }[] } | RiskFailure | { archived: true }))
116
+ | ({ type: 'lockfile'; repo: number; path: string; format: LockfileFormat } & ({ packages: LockedPackage[] } | RiskFailure))
117
+ | ({ type: 'risk'; name: string; version: string; integrity?: string; stale?: { assessedAt: number } }
118
+ & ({ published: string | null; severity: Severity | null; score: number; findings: { id: string; severity: Severity; takenDown?: true }[] } | RiskFailure))
119
+ | ({ type: 'advisories'; repo: number; path: string } & ({ advisories: AdvisoryRow[] } | RiskFailure))
120
+ | ({ type: 'dependabot'; repo: number } & ({ alerts: DependabotAlertRow[] } | RiskFailure))
121
+ | ({ type: 'stasis'; repo: number } & StasisConfigsRead)
122
+ | WorkflowsLine | WorkflowLine | ActionLine
123
+ | { type: 'done' }
124
+ // The scan stopped for its part's time (repositoryRiskLines `partMs`), what
125
+ // it told kept: to be asked again, from where it stopped.
126
+ | { type: 'continue' }
127
+
128
+ // The repositories a scan answered in parts told whole by a part's end: each
129
+ // by its id, its name and a team's directories in it then, and its
130
+ // lockfiles' keys (`${format}\0${sha}`) of those read, the references its
131
+ // Actions make, to resolve, the versions its Stasis builds made install
132
+ // (versionKey), assessed before the rest, and its builds still to be made,
133
+ // to watch.
134
+ export interface ScanProgress { repos: ToldRepository[] }
135
+ interface ToldRepository { id: number; name: string; paths: readonly string[] | null; lockfiles: string[]; actions?: ActionRef[]; stasis?: string[]
136
+ building?: { commit: string; configs: string[] } }
137
+
138
+ export type RiskLine = Extract<RepositoryRiskLine, { type: 'risk' }>
139
+
140
+ // How many repositories are read at once (repository-risk-read.ts), ahead of
141
+ // the one told: each asks GitHub one thing after another (opening it, and
142
+ // its head) even where all else is kept.
143
+ const READ_AHEAD = 6
144
+ // How many lockfiles' advisories are asked of npm at once, those of the
145
+ // repositories read ahead as they are read, each told in its turn.
146
+ const AUDITS_AT_ONCE = 4
147
+ // How long a part's progress, written as it ends (`progress`), is waited on.
148
+ const PROGRESS_WRITE_MS = 5000
149
+ // How many kept risk lines are read of the source's `risks` at once.
150
+ const KEPT_READ = 500
151
+ const shared = riskCaches()
152
+
153
+ interface Scan {
154
+ source: RepositoryRiskSource<RepositoryRiskRepo>
155
+ caches: RiskCaches
156
+ signal: AbortSignal
157
+ lines: Queue<RepositoryRiskLine>
158
+ // Each lockfile's packages not yet seen, to look up as kept (lookUp); those
159
+ // already seen, by seenKey, each with whether only devDependencies need it
160
+ // so far; those of them with none kept, put off as long as that holds; and
161
+ // those told stale, to assess again once those with none kept are: each by
162
+ // seenKey till given a turn.
163
+ lookups: Queue<AssessedPackage[]>
164
+ seen: Map<string, boolean>
165
+ dev: Map<string, AssessedPackage>
166
+ stale: Map<string, AssessedPackage>
167
+ // What it knows of Stasis's builds (repository-risk-stasis.ts); and the turn
168
+ // under way (assessing), of those stale or not, to give or hurry those told
169
+ // Stasis's since.
170
+ reach: StasisReach
171
+ turn: { turn: Turn; stale: boolean } | null
172
+ // The repositories told whole, this part or one before (ScanProgress).
173
+ told: Map<number, ToldRepository>
174
+ actions: ReturnType<typeof resolvingActions> | null
175
+ audits: ReturnType<typeof inTurns>
176
+ }
177
+
178
+ // A package as a scan meets it: by its name, version and a mirror's integrity.
179
+ const seenKey = (pkg: AssessedPackage) => `${pkg.name}@${pkg.version}\0${pkg.integrity ?? ''}`
180
+ const isStasis = (scan: Scan, pkg: AssessedPackage) => scan.reach.has(pkg)
181
+
182
+ // A package's key, as its risk line is kept: its name, version and a
183
+ // mirror's integrity, and whether a team lists its scope.
184
+ const riskKey = (pkg: AssessedPackage, teamScoped: boolean) => `${seenKey(pkg)}\0${teamScoped}`
185
+ // Whether a line kept `at` is told as it is: within RISK_KEPT_MS, and kept
186
+ // since risk told a score (assessNpm `score`).
187
+ const isFresh = ({ at, line }: { at: number; line: RiskLine }) => Date.now() - at < RISK_KEPT_MS && ('error' in line || typeof line.score === 'number')
188
+
189
+ // A package assessed (assess), its line told, and kept, in RiskCaches and the
190
+ // source's `risks`, where it tells what risk found, or that a mirror's copy
191
+ // isn't npm's.
192
+ async function assessed(scan: Scan, pkg: AssessedPackage): Promise<void> {
193
+ let teamScoped
194
+ try { teamScoped = await scan.source.teamScoped(pkg.name) } catch (error) { scan.lines.add({ type: 'risk', ...pkg, ...failureOf(error) }); return }
195
+ const key = riskKey(pkg, teamScoped)
196
+ const line = await assessPackage(scan.source, scan.signal, pkg, teamScoped)
197
+ if (line && (!('error' in line) || line.error === 'integrity-mismatch')) {
198
+ const at = Date.now()
199
+ scan.caches.risks.set(key, { at, line })
200
+ await scan.source.risks?.write(key, line, at)
201
+ }
202
+ if (line) scan.lines.add(line)
203
+ }
204
+
205
+ // Risk lines kept of `keys`, by key: in this instance's memory, else the
206
+ // source's `risks`, KEPT_READ at a time.
207
+ async function keptLines({ source, caches }: Scan, keys: string[]) {
208
+ const kept = new Map<string, { at: number; line: RiskLine }>()
209
+ const left = keys.filter(key => { const hit = caches.risks.get(key); if (hit) kept.set(key, hit); return !hit })
210
+ for (let from = 0; source.risks && from < left.length; from += KEPT_READ) {
211
+ for (const [key, { at, value }] of await source.risks.readMany(left.slice(from, from + KEPT_READ))) {
212
+ caches.risks.set(key, { at, line: value })
213
+ kept.set(key, { at, line: value })
214
+ }
215
+ }
216
+ return kept
217
+ }
218
+
219
+ // Each lockfile's packages, as assessLater gives them: their risk lines as
220
+ // kept, however old, told at once, a fresh one as it is and an older one as
221
+ // stale (`stale`, when it was assessed), its package assessed again once
222
+ // those with none kept are (`scan.stale`); those with none given to `assess`,
223
+ // but those only devDependencies need so far, and no Stasis build installs,
224
+ // put off (`scan.dev`).
225
+ async function lookUp(scan: Scan, assess: (packages: AssessedPackage[]) => void) {
226
+ for (let packages = await scan.lookups.take(); packages !== undefined; packages = await scan.lookups.take()) {
227
+ const keyed: { pkg: AssessedPackage; key: string }[] = []
228
+ for (const pkg of packages) {
229
+ try { keyed.push({ pkg, key: riskKey(pkg, await scan.source.teamScoped(pkg.name)) }) } catch (error) { scan.lines.add({ type: 'risk', ...pkg, ...failureOf(error) }) }
230
+ }
231
+ const kept = await keptLines(scan, keyed.map(({ key }) => key))
232
+ const missing: AssessedPackage[] = []
233
+ for (const { pkg, key } of keyed) {
234
+ const hit = kept.get(key)
235
+ if (hit && isFresh(hit)) scan.lines.add(hit.line)
236
+ else if (hit) { scan.lines.add({ ...hit.line, stale: { assessedAt: hit.at } }); scan.stale.set(seenKey(pkg), pkg) }
237
+ else if (scan.seen.get(seenKey(pkg)) === true && !isStasis(scan, pkg)) scan.dev.set(seenKey(pkg), pkg)
238
+ else missing.push(pkg)
239
+ }
240
+ if (missing.length > 0) assess(missing)
241
+ }
242
+ }
243
+
244
+ // The packages `feed` gives assessed in a turn (repository-risk-turn.ts), of
245
+ // those `stale` or not, Stasis's before the rest: once all given it are told,
246
+ // or the scan stops. It is the turn under way till then (reach).
247
+ async function assessing(scan: Scan, feed: (assess: (packages: AssessedPackage[]) => void) => Promise<void>, stale = false) {
248
+ await assessingTurn({ signal: scan.signal, downloads: scan.source.downloads, key: seenKey, first: pkg => isStasis(scan, pkg), assess: pkg => assessed(scan, pkg) },
249
+ turn => { scan.turn = { turn, stale }; return feed(packages => { turn.give(packages) }) })
250
+ scan.turn = null
251
+ }
252
+
253
+ // A lockfile's packages of npm's registry or a mirror not yet seen this scan,
254
+ // to look up as kept (lookUp), and assess where none is; and one seen as only
255
+ // devDependencies need it, and put off, that this lockfile needs otherwise,
256
+ // to look up again and assess now.
257
+ function assessLater(scan: Scan, packages: LockedPackage[]) {
258
+ const fresh: AssessedPackage[] = []
259
+ for (const { name, version, source, integrity, dev = false } of packages) {
260
+ if ((source !== 'registry' && source !== 'mirror') || version === null || !isNpmPackageName(name) || !isNpmPackageSpec(version)) continue
261
+ const pkg = { name, version, ...integrity === undefined ? {} : { integrity } }
262
+ const key = seenKey(pkg)
263
+ const was = scan.seen.get(key)
264
+ if (was === false || (was && dev)) continue
265
+ scan.seen.set(key, dev)
266
+ if (was === undefined) scan.reach.seen(pkg)
267
+ if (was === undefined || scan.dev.delete(key)) fresh.push(pkg)
268
+ }
269
+ if (fresh.length > 0) scan.lookups.add(fresh)
270
+ }
271
+
272
+ // `versions` told Stasis's (StasisReach), as a repository is told, before its
273
+ // lockfiles are given to assessLater, or as a build is made since: those
274
+ // seen of each already that wait for a turn of the kind under way (put off as
275
+ // only devDependencies need them, or stale) given it now, and those it has
276
+ // hurried, where they still wait.
277
+ function reach(scan: Scan, versions: readonly string[]) {
278
+ const at = scan.turn, moved = scan.reach.add(versions)
279
+ if (!at || moved.length === 0) return
280
+ const waiting = at.stale ? scan.stale : scan.dev
281
+ const now = moved.filter(pkg => waiting.has(seenKey(pkg)))
282
+ if (now.length > 0 && at.turn.give(now)) for (const pkg of now) waiting.delete(seenKey(pkg))
283
+ at.turn.hurry(moved)
284
+ }
285
+
286
+ // A build watched made (StasisReach `watch`): the versions it installs told
287
+ // Stasis's, and kept with its repository told, for a part after.
288
+ function madeSince(scan: Scan, build: StasisBuild, versions: string[]) {
289
+ reach(scan, versions)
290
+ const told = scan.told.get(build.repoId)
291
+ if (!told) return
292
+ told.stasis = [...new Set([...told.stasis ?? [], ...versions])]
293
+ if (told.building) told.building = { ...told.building, configs: told.building.configs.filter(config => config !== build.config) }
294
+ }
295
+
296
+ export type LockfileLine = Extract<RepositoryRiskLine, { type: 'lockfile' }>
297
+
298
+ // A lockfile's advisories line, of its audit (repository-risk-audit.ts auditLockfile).
299
+ const advisoriesLine = ({ repo, path }: LockfileLine, audit: Audit) => ({ type: 'advisories', repo, path, ...Array.isArray(audit) ? { advisories: audit } : audit } as const)
300
+
301
+ // A repository read, its lockfiles' audits asked meanwhile, AUDITS_AT_ONCE
302
+ // across the scan (auditLockfiles), to tell in turn once access is checked again.
303
+ type Audited = (RepositoryRead & { audits: Promise<Audit | null>[] }) | RepositoryFailure | RepositoryArchived
304
+ const audited = (scan: Scan, read: RepositoryRead | RepositoryFailure | RepositoryArchived | null): Audited | null => (read === null || 'type' in read ? read : { ...read, audits: auditLockfiles(scan.source, scan.caches.advisories,
305
+ scan.signal, read.lockfiles.map(({ sha, line }) => ({ key: `${line.format}\0${sha}`, packages: 'packages' in line ? line.packages : null })), scan.audits) })
306
+
307
+ type DependabotLine = Extract<RepositoryRiskLine, { type: 'dependabot' }>
308
+
309
+ // A repository's Dependabot alerts' line, each alert with the versions the
310
+ // lockfile it is of locks that it covers (`lockfiles`, a repository read's),
311
+ // or why they couldn't be had.
312
+ function dependabotLine(repo: number, read: DependabotRead, lockfiles: RepositoryRead['lockfiles']): DependabotLine {
313
+ if ('error' in read) return { type: 'dependabot', repo, ...read }
314
+ const locked = new Map(lockfiles.flatMap(({ line }) => 'packages' in line ? [[line.path, line.packages] as const] : []))
315
+ return { type: 'dependabot', repo, alerts: read.alerts.map(alert => ({ ...alert, versions: alertVersions(alert, locked.get(alert.manifest)),
316
+ malware: npmMalwareAdvisory({ id: alert.ghsa, aliases: alert.aliases, cwe: alert.cwe, title: alert.title }) })) }
317
+ }
318
+
319
+ // A repository's alerts checked again just before they are told, as access to
320
+ // the repository is (DependabotRead `recheck`): why not, where the user's
321
+ // access to them is withdrawn since they were read.
322
+ async function rechecked(read: DependabotRead): Promise<DependabotRead> {
323
+ if (!('alerts' in read) || !read.recheck) return read
324
+ try { await read.recheck() } catch (error) { return failureOf(error, 'checking access to its Dependabot alerts again') }
325
+ return read
326
+ }
327
+
328
+ // A repository read (repository-risk-read.ts readRepository) told: its
329
+ // line, or why it couldn't be read, then its lockfiles', and their
330
+ // advisories, asked as it was read, its packages assessed meanwhile, then
331
+ // its Dependabot alerts.
332
+ // Access to it is checked again
333
+ // just before, however long ago it was read, as GitHub may have withdrawn it.
334
+ async function tellRepository(scan: Scan, repo: RepositoryRiskRepo, read: Audited | null) {
335
+ if (!read || scan.signal.aborted) return
336
+ if ('type' in read) { scan.lines.add(read); return }
337
+ try { await read.recheck() } catch (error) {
338
+ if (!scan.signal.aborted) scan.lines.add({ type: 'repo', id: repo.repoId, ...failureOf(error, 'checking access to it again') })
339
+ return
340
+ }
341
+ if (scan.signal.aborted) return
342
+ const { commit, lockfiles } = read
343
+ scan.lines.add({ type: 'repo', id: repo.repoId, commit, lockfiles: lockfiles.map(({ line: { path, format } }) => ({ path, format })) })
344
+ const building = stasisBuilding(read.stasis), reached = stasisVersions(read.stasis)
345
+ reach(scan, reached)
346
+ scan.reach.building(building.map(config => ({ repoId: repo.repoId, commit, config })))
347
+ for (const { line } of lockfiles) {
348
+ scan.lines.add(line)
349
+ if ('packages' in line) assessLater(scan, line.packages)
350
+ }
351
+ if (read.stasis) scan.lines.add({ type: 'stasis', repo: repo.repoId, ...read.stasis })
352
+ const refs = read.actions ? tellActions(scan, repo, read.actions, lockfiles) : []
353
+ for (const [at, { line }] of lockfiles.entries()) {
354
+ if (scan.signal.aborted) return
355
+ const audit = await read.audits[at]
356
+ if (audit) scan.lines.add(advisoriesLine(line, audit))
357
+ }
358
+ if (scan.signal.aborted) return
359
+ const dependabot = read.dependabot && await rechecked(read.dependabot)
360
+ if (scan.signal.aborted) return
361
+ if (dependabot) scan.lines.add(dependabotLine(repo.repoId, dependabot, lockfiles))
362
+ scan.told.set(repo.repoId, { id: repo.repoId, name: repo.fullName, paths: repo.paths ?? null,
363
+ lockfiles: lockfiles.flatMap(({ sha, line }) => 'packages' in line ? [`${line.format}\0${sha}`] : []), ...refs.length > 0 ? { actions: refs } : {}, ...reached.length > 0 ? { stasis: reached } : {},
364
+ ...building.length > 0 ? { building: { commit, configs: building } } : {} })
365
+ }
366
+
367
+ // A repository's Actions told, and the references they make to resolve.
368
+ function tellActions(scan: Scan, repo: RepositoryRiskRepo, read: WorkflowsRead, lockfiles: RepositoryRead['lockfiles']) {
369
+ const locked = lockfiles.flatMap(({ line }) => 'packages' in line ? [lockedNames(line.path, line.packages)] : [])
370
+ const { lines, refs } = actionsLines(repo.repoId, repo.fullName.split('/')[0]!, read, locked)
371
+ for (const line of lines) scan.lines.add(line)
372
+ scan.actions?.add(refs)
373
+ return refs
374
+ }
375
+
376
+ // Whether an earlier part told `repo` whole, by its name and a team's
377
+ // directories in it as they are now, its packages then looked up as its
378
+ // lockfiles are kept, those its Stasis builds made install before the rest,
379
+ // those still to be made watched, GitHub asked nothing of it: not where one
380
+ // isn't. It is told as read then, its default branch's head not asked again.
381
+ async function toldBefore(scan: Scan, repo: RepositoryRiskRepo) {
382
+ const told = scan.told.get(repo.repoId)
383
+ if (!told || told.name !== repo.fullName || JSON.stringify(told.paths) !== JSON.stringify(repo.paths ?? null)) return false
384
+ const reads: LockedPackage[][] = [], unknown = told.lockfiles.filter(key => !scan.caches.lockfiles.get(key))
385
+ const stored = unknown.length > 0 && scan.source.lockfiles ? await scan.source.lockfiles.readMany(unknown) : null
386
+ for (const key of told.lockfiles) {
387
+ const read = scan.caches.lockfiles.get(key) ?? stored?.get(key)?.value
388
+ if (!read || !('packages' in read)) return false
389
+ reads.push(read.packages)
390
+ }
391
+ reach(scan, told.stasis ?? [])
392
+ const { building } = told
393
+ if (building) scan.reach.building(building.configs.map(config => ({ repoId: told.id, commit: building.commit, config })))
394
+ for (const packages of reads) assessLater(scan, packages)
395
+ scan.actions?.add(told.actions ?? [])
396
+ return true
397
+ }
398
+
399
+ // Each repository, READ_AHEAD read at a time, each told in turn, but those an
400
+ // earlier part told whole (ScanProgress), read of none.
401
+ async function readRepositories(scan: Scan) {
402
+ const repos = await scan.source.repos()
403
+ scan.lines.add({ type: 'repos', repos: repos.map(repo => ({ id: repo.repoId, fullName: repo.fullName })) })
404
+ // Those still listed: one no longer is read again should it be once more.
405
+ const listed = new Set(repos.map(repo => repo.repoId))
406
+ // Those within SCAN_READ_KEPT_MS, as their lockfiles are kept that long.
407
+ const kept = await scan.source.progress?.read()
408
+ const progress = kept && Date.now() - kept.at < SCAN_READ_KEPT_MS ? kept.value.repos : []
409
+ for (const told of progress) if (listed.has(told.id)) scan.told.set(told.id, told)
410
+ const reads: Promise<Audited | null>[] = []
411
+ const read = (at: number) => {
412
+ if (reads[at]) return reads[at]
413
+ const repo = repos[at]!
414
+ const started = reads[at] = toldBefore(scan, repo).then(async told => (told ? null : audited(scan, await readRepository(scan, repo))))
415
+ // One read ahead and no longer waited on, as the scan stopped, fails alone.
416
+ started.catch(() => {})
417
+ return started
418
+ }
419
+ for (const [at, repo] of repos.entries()) {
420
+ if (scan.signal.aborted) return
421
+ for (let ahead = at; ahead < Math.min(at + READ_AHEAD, repos.length); ahead++) void read(ahead)
422
+ await tellRepository(scan, repo, await read(at))
423
+ }
424
+ }
425
+
426
+ // What is left to assess once the repositories are read, a turn at a time,
427
+ // each taken as it begins, as a build made since may tell more Stasis's:
428
+ // those with none kept that only devDependencies need, then the stale ones,
429
+ // those a Stasis build installs, those more than devDependencies need, and
430
+ // those only devDependencies need.
431
+ const isDev = (scan: Scan, pkg: AssessedPackage) => scan.seen.get(seenKey(pkg)) === true
432
+ const LEFT_OVER: { stale: boolean; of(scan: Scan, pkg: AssessedPackage): boolean }[] = [{ stale: false, of: () => true }, { stale: true, of: isStasis },
433
+ { stale: true, of: (scan, pkg) => !isDev(scan, pkg) }, { stale: true, of: () => true }]
434
+
435
+ // The scan's work, behind its lines (repositoryRiskLines), `done` last, its
436
+ // lines closed once it ends, its failure given to `fail`; the builds still to
437
+ // be made watched meanwhile, every `everyMs`, none waited for.
438
+ async function runScan(scan: Scan, fail: (error: unknown) => void, everyMs: number) {
439
+ const watching = new AbortController(), { stasisBuilt } = scan.source
440
+ const watch = stasisBuilt ? scan.reach.watch(build => stasisBuilt(build), (build, versions) => { madeSince(scan, build, versions) },
441
+ AbortSignal.any([scan.signal, watching.signal]), everyMs) : null
442
+ try {
443
+ // Those with no risk line kept assessed first, as their lockfiles are read,
444
+ // those a Stasis build installs before the rest,
445
+ await assessing(scan, async assess => {
446
+ const looking = lookUp(scan, assess)
447
+ // stopped at once where reading fails;
448
+ try { await readRepositories(scan) } catch (error) { fail(error) } finally { scan.lookups.close() }
449
+ await looking
450
+ })
451
+ // then those only devDependencies need, and those told stale, in turn.
452
+ for (const { stale, of } of LEFT_OVER) {
453
+ const from = stale ? scan.stale : scan.dev, left = [...from.values()].filter(pkg => of(scan, pkg))
454
+ for (const pkg of left) from.delete(seenKey(pkg))
455
+ if (!scan.signal.aborted && left.length > 0) await assessing(scan, assess => { assess(left); return Promise.resolve() }, stale)
456
+ }
457
+ await scan.actions?.close()
458
+ if (!scan.signal.aborted) scan.lines.add({ type: 'done' })
459
+ } catch (error) { fail(error) } finally { watching.abort(); await watch; scan.lines.close() }
460
+ }
461
+
462
+ // The scan's lines, in the order they are found: the repositories first,
463
+ // then each repository's lockfiles and their packages once read and access
464
+ // is checked again, and each package's risk: as kept, however old, at once
465
+ // (lookUp), then those with none kept once assessed, while the repositories
466
+ // are still being read, those a Stasis build installs first, then those only
467
+ // devDependencies need, then those told stale once assessed again, in the
468
+ // same order (LEFT_OVER), a Stasis build made meanwhile asked of every
469
+ // `stasisEveryMs` (STASIS_AGAIN_MS); `done` last. Ends at once, the work
470
+ // under way given up on, where `signal` aborts or the lines are no longer read. A failure of
471
+ // a repository, a lockfile or a package is told in its line; one of the scan
472
+ // itself is thrown, the lines before it told. What it reads is kept in
473
+ // `caches` (RiskCaches), the instance's own unless given. Given `partMs`, it
474
+ // stops once that long, as a function time-limited must (Vercel's), the work
475
+ // under way given up on, its last line `continue`, for its reader to ask
476
+ // again: those it assessed are kept, and told at once then, and the
477
+ // repositories it told whole kept as its source's `progress`.
478
+ export async function* repositoryRiskLines<R extends RepositoryRiskRepo>(source: RepositoryRiskSource<R>, signal: AbortSignal, caches = shared,
479
+ { partMs = null, stasisEveryMs = STASIS_AGAIN_MS }: { partMs?: number | null; stasisEveryMs?: number } = {}): AsyncGenerator<RepositoryRiskLine> {
480
+ const part = new AbortController(), stopped = new AbortController()
481
+ const parting = partMs === null ? undefined : setTimeout(() => { part.abort() }, partMs)
482
+ const running = AbortSignal.any([signal, stopped.signal, part.signal])
483
+ // The lines told until the part's time is up, those found by then told, and
484
+ // none waited for: the work under way, such as a request to GitHub, which
485
+ // isn't given up on at once, outlasting it.
486
+ const lines = queue<RepositoryRiskLine>(AbortSignal.any([signal, part.signal]), { drain: true })
487
+ const actions = source.actions ? resolvingActions({ source: source.actions, signal: running, tell: line => { lines.add(line) }, memory: caches.actions,
488
+ answers: caches.actionAnswers, store: source.actionLines }) : null
489
+ const scan: Scan = { source, caches, signal: running, lines, lookups: queue(running), seen: new Map(), dev: new Map(), stale: new Map(), reach: stasisReach(),
490
+ turn: null, told: new Map(), actions, audits: inTurns(AUDITS_AT_ONCE) }
491
+ // A failure of the scan itself kept, to throw once the lines before it are
492
+ // told, and the scan stopped.
493
+ const failed: unknown[] = []
494
+ void runScan(scan, error => { failed.push(error); stopped.abort() }, stasisEveryMs)
495
+ try {
496
+ let done = false
497
+ for (let line = await scan.lines.take(); line !== undefined; line = await scan.lines.take()) {
498
+ done ||= line.type === 'done'
499
+ yield line
500
+ }
501
+ if (done || signal.aborted) return
502
+ if (part.signal.aborted) {
503
+ // Not waited on past PROGRESS_WRITE_MS, within what Vercel's limit
504
+ // leaves past the part's: the next part then goes on from less.
505
+ let timer
506
+ await Promise.race([source.progress?.write({ repos: [...scan.told.values()] }), new Promise(resolve => { timer = setTimeout(resolve, PROGRESS_WRITE_MS) })])
507
+ clearTimeout(timer)
508
+ yield { type: 'continue' }
509
+ }
510
+ else if (failed.length > 0) throw failed[0]
511
+ } finally {
512
+ // A GitHub request under way isn't waited on: it settles on its own.
513
+ clearTimeout(parting)
514
+ stopped.abort()
515
+ }
516
+ }