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

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-563V5VVT.js +266 -0
  111. package/out/chunk-5AVGKFMR.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-5UJHJWFU.js +4 -0
  116. package/out/chunk-6CCSTJWB.js +1 -0
  117. package/out/chunk-6VOB5WXX.js +2 -0
  118. package/out/chunk-6WMQVUT2.js +3 -0
  119. package/out/chunk-6Y6PZ2BU.js +9 -0
  120. package/out/chunk-74JZTGTO.js +11 -0
  121. package/out/chunk-7BKKYVWR.js +7 -0
  122. package/out/chunk-7C7DWL7I.js +1 -0
  123. package/out/chunk-7HP2VYIC.js +2 -0
  124. package/out/chunk-7YFJUT2P.js +1 -0
  125. package/out/chunk-7YO4QV5P.js +1 -0
  126. package/out/chunk-A4BBBHQU.js +1 -0
  127. package/out/chunk-B64CTMVU.js +4 -0
  128. package/out/chunk-BEKYZCPX.js +14 -0
  129. package/out/chunk-C4Z6ZBXV.js +10 -0
  130. package/out/chunk-CU3FPB3P.js +1 -0
  131. package/out/chunk-DEVAORP2.js +1 -0
  132. package/out/chunk-DOYTKRIR.js +53 -0
  133. package/out/chunk-DUASGS2O.js +8 -0
  134. package/out/chunk-EEJA7JBI.js +13 -0
  135. package/out/chunk-FSU2PLJL.js +1 -0
  136. package/out/chunk-GO7FT4OD.js +1 -0
  137. package/out/chunk-GX5UXWT4.js +1 -0
  138. package/out/chunk-H4FEC57K.js +1 -0
  139. package/out/chunk-ITUKKCCK.js +10 -0
  140. package/out/chunk-IYPY47MC.js +1 -0
  141. package/out/chunk-K4XJHM2T.js +1 -0
  142. package/out/chunk-LBD3M3J6.js +1 -0
  143. package/out/chunk-LVSLM7HB.js +1 -0
  144. package/out/chunk-LVW7WWV4.js +1 -0
  145. package/out/chunk-N57OWFKY.js +15 -0
  146. package/out/chunk-NRPC74AM.js +1 -0
  147. package/out/chunk-OAWQNDAO.js +3 -0
  148. package/out/chunk-OOJM4CTU.js +1 -0
  149. package/out/chunk-PEE47ANR.js +1 -0
  150. package/out/chunk-PKLVXUEI.js +11 -0
  151. package/out/chunk-PLGH63UC.js +2 -0
  152. package/out/chunk-PNHBZGDD.js +1 -0
  153. package/out/chunk-PTFYDJUP.js +1 -0
  154. package/out/chunk-PWFUOLZK.js +17 -0
  155. package/out/chunk-PXK7EU4V.js +1 -0
  156. package/out/chunk-QD3IBSF4.js +7 -0
  157. package/out/chunk-QI66YA4F.js +1 -0
  158. package/out/chunk-QRKFPLA4.js +80 -0
  159. package/out/chunk-R3NZFXVR.js +1 -0
  160. package/out/chunk-R5O6FAW4.js +2 -0
  161. package/out/chunk-RPNO56H2.js +1 -0
  162. package/out/chunk-SSPDMA6D.js +1 -0
  163. package/out/chunk-SZWPYLPC.js +1 -0
  164. package/out/chunk-TUII34K2.js +1 -0
  165. package/out/chunk-UJP4PQJA.js +1 -0
  166. package/out/chunk-UJSJMXEG.js +1 -0
  167. package/out/chunk-UR4WYMIP.js +1 -0
  168. package/out/chunk-VHEXSGGP.js +1 -0
  169. package/out/chunk-VYYUMYVW.js +9 -0
  170. package/out/chunk-WCDYSIKG.js +1 -0
  171. package/out/chunk-WFBVS4QI.js +1 -0
  172. package/out/chunk-XM4RLC4A.js +2 -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 +354 -0
  199. package/risk/files/hosts.js +206 -0
  200. package/risk/files/readability.js +185 -0
  201. package/risk/files/runs-code.js +568 -0
  202. package/risk/files/script.js +410 -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 +269 -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 +1915 -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 +158 -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 +6327 -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,78 @@
1
+ // A lockfile's advisories, as a repository risk scan asks them
2
+ // (repository-risk.ts): npm's registry's of its packages of the registry or
3
+ // a mirror, asked at once, as `npm audit` asks, each told with whether it is
4
+ // of malware, as upstream tells (`malware`); kept by the lockfile's blob, in
5
+ // the instance's memory and the source's `audits`, for RISK_KEPT_MS, as npm
6
+ // publishes advisories, or why they couldn't be had for AUDIT_FAILED_KEPT_MS.
7
+ import type { Advisory } from '@preventive/upstream/advisories.js'
8
+ import { isExactVersion } from '@preventive/upstream/semver.js'
9
+ import { isNpmPackageName } from '../common/managed/npm-packages.js'
10
+ import type { LockedPackage } from './locked-packages.ts'
11
+ import type { Lru } from './lru.ts'
12
+ import type { KeptStore } from './npm-kept.ts'
13
+ import { RISK_KEPT_MS, type RiskFailure, failureOf } from './repository-risk-assess.ts'
14
+
15
+ export type AdvisoryRow = Omit<Advisory, 'malware'> & { malware: boolean }
16
+ // A lockfile's advisories, or why they couldn't be had.
17
+ export type Audit = AdvisoryRow[] | RiskFailure
18
+
19
+ export interface AuditSource {
20
+ // npm's registry's advisories of these packages' versions, asked at once.
21
+ advisories(packages: { name: string; versions: string[] }[], signal: AbortSignal): Promise<Advisory[]>
22
+ // Where audits are kept beyond this instance, by the lockfile's blob.
23
+ audits?: KeptStore<Audit>
24
+ }
25
+
26
+ // How long a lockfile's advisories that couldn't be had are told so, rather
27
+ // than asked again: a scan's next parts don't wait on an audit that failed,
28
+ // as by timing out, again and again.
29
+ const AUDIT_FAILED_KEPT_MS = 10 * 60_000
30
+
31
+ // Whether an audit kept `at` is told as it is: its advisories within
32
+ // RISK_KEPT_MS, why they couldn't be had within AUDIT_FAILED_KEPT_MS.
33
+ const isFresh = ({ at, audit }: { at: number; audit: Audit }) => Date.now() - at < (Array.isArray(audit) ? RISK_KEPT_MS : AUDIT_FAILED_KEPT_MS)
34
+
35
+ // The audits of lockfiles, each of its `packages` by its `key` (auditLockfile),
36
+ // `inTurn` with others, asked at once: each null where it has none to ask
37
+ // of, or once `signal` aborts. Each is the caller's to tell once it may.
38
+ export function auditLockfiles(source: AuditSource, memory: Lru<{ at: number; audit: Audit }>, signal: AbortSignal,
39
+ lockfiles: { key: string; packages: readonly LockedPackage[] | null }[], inTurn: <T>(work: () => Promise<T>) => Promise<T>): Promise<Audit | null>[] {
40
+ return lockfiles.map(({ key, packages }) => {
41
+ const audit = packages ? inTurn(() => (signal.aborted ? Promise.resolve(null) : auditLockfile(source, memory, signal, key, packages))) : Promise.resolve(null)
42
+ // One no longer waited on, as the scan stopped, fails alone.
43
+ audit.catch(() => {})
44
+ return audit
45
+ })
46
+ }
47
+
48
+ // The audit of a lockfile's `packages`, by its `key` as kept (`memory`, then
49
+ // the source's), else asked and kept; null where it locks none to ask of, or
50
+ // once `signal` aborts.
51
+ async function auditLockfile(source: AuditSource, memory: Lru<{ at: number; audit: Audit }>, signal: AbortSignal, key: string,
52
+ packages: readonly LockedPackage[]): Promise<Audit | null> {
53
+ let kept = memory.get(key)
54
+ if (!kept || !isFresh(kept)) {
55
+ const stored = await source.audits?.read(key)
56
+ kept = stored ? { at: stored.at, audit: stored.value } : undefined
57
+ }
58
+ if (kept && isFresh(kept)) { memory.set(key, kept); return kept.audit }
59
+ const asked = new Map<string, Set<string>>()
60
+ for (const { name, version, source: from } of packages) {
61
+ if ((from !== 'registry' && from !== 'mirror') || !isNpmPackageName(name) || !isExactVersion(version)) continue
62
+ if (!asked.has(name)) asked.set(name, new Set())
63
+ asked.get(name)!.add(version)
64
+ }
65
+ if (asked.size === 0) return null
66
+ let audit: Audit
67
+ try {
68
+ audit = (await source.advisories([...asked].map(([name, versions]) => ({ name, versions: [...versions] })), signal))
69
+ .map(advisory => ({ ...advisory, malware: advisory.malware === true }))
70
+ } catch (error) {
71
+ if (signal.aborted) return null
72
+ audit = failureOf(error)
73
+ }
74
+ const now = Date.now()
75
+ memory.set(key, { at: now, audit })
76
+ await source.audits?.write(key, audit, now)
77
+ return audit
78
+ }
@@ -0,0 +1,37 @@
1
+ // What repository risk scans keep between them (repository-risk.ts), in this
2
+ // instance's memory.
3
+ import { type Lru, lru } from './lru.ts'
4
+ import { type ActionAnswers, type ActionLine, type WorkflowsRead, answerWeight } from './repository-actions.ts'
5
+ import type { Audit } from './repository-risk-audit.ts'
6
+ import type { ListedLockfile, LockfileRead } from './repository-risk-read.ts'
7
+ import type { RiskLine } from './repository-risk.ts'
8
+
9
+ // What scans keep between them, in this instance's memory: a repository's
10
+ // lockfiles as listed at a commit, and a lockfile's packages by its blob,
11
+ // neither of which changes; a lockfile's advisories, asked again after
12
+ // RISK_KEPT_MS, as npm publishes advisories; and a package's risk line,
13
+ // told stale after RISK_KEPT_MS and assessed again, as risk tells again what
14
+ // of a package changes in time (a deprecation, its age, its downloads). A
15
+ // lockfile's, and its packages' lines, are told only once access to its
16
+ // repository is checked as when it was read.
17
+ export interface RiskCaches {
18
+ listings: Lru<ListedLockfile[]>
19
+ lockfiles: Lru<LockfileRead>
20
+ risks: Lru<{ at: number; line: RiskLine }>
21
+ advisories: Lru<{ at: number; audit: Audit }>
22
+ actionFiles: Lru<WorkflowsRead>
23
+ actions: Lru<{ at: number; line: ActionLine }>
24
+ actionAnswers: ActionAnswers
25
+ }
26
+ export const riskCaches = (): RiskCaches => ({
27
+ listings: lru(1000),
28
+ // By the packages they hold, a few hundred bytes each.
29
+ lockfiles: lru(200_000, read => 'packages' in read ? read.packages.length + 1 : 1),
30
+ risks: lru(50_000),
31
+ advisories: lru(50_000, kept => Array.isArray(kept.audit) ? kept.audit.length + 1 : 1),
32
+ // By their text, a kilobyte at a time.
33
+ actionFiles: lru(64 * 1024, read => 'files' in read ? read.files.reduce((sum, file) => sum + ('text' in file ? Math.ceil(file.text.length / 1024) : 1), 1) : 1),
34
+ actions: lru(10_000),
35
+ // What GitHub answered of public repositories' actions, by answerWeight.
36
+ actionAnswers: lru(200_000, answerWeight),
37
+ })
@@ -0,0 +1,260 @@
1
+ // A repository as a repository risk scan reads it of GitHub
2
+ // (repository-risk.ts): opened at its default branch's head, its lockfiles
3
+ // of npm's ecosystem listed (findRepoLockfiles), those of its `paths` alone,
4
+ // each read for its packages (@preventive/lockfile), and access to it checked
5
+ // again before they are told (`recheck`); and its Dependabot alerts, open or dismissed, of
6
+ // npm's, where the source asks them (dependabot-alerts.ts), asked meanwhile
7
+ // and never kept, a failure to have them its own, its GitHub Actions
8
+ // (repository-actions.ts), and what Stasis reaches of each of its
9
+ // stasis.config.json files, where the source reads them
10
+ // (StasisConfigsRead). A listing is kept by the commit it was listed at,
11
+ // its Actions' files too, and a lockfile's packages by its blob: in the
12
+ // instance's memory, and the source's `listings`, `actionFiles` and
13
+ // `lockfiles` for SCAN_READ_KEPT_MS, so that only opening a repository and
14
+ // checking access to it again ask GitHub where all else is kept.
15
+ import { createHash } from 'node:crypto'
16
+ import type { LockfileFormat, RepoLockfile } from '@preventive/upstream/github.js'
17
+ import type { AlertsRead } from './dependabot-access.ts'
18
+ import type { DependabotAlert } from './dependabot-alerts.ts'
19
+ import { type LockedPackage, isTestFixture, lockedPackages, yarnManifests } from './locked-packages.ts'
20
+ import type { Lru } from './lru.ts'
21
+ import type { KeptStore } from './npm-kept.ts'
22
+ import { inTurns } from './queue.ts'
23
+ import { type WorkflowsRead, lastingRead, readActions } from './repository-actions.ts'
24
+ import { type RiskFailure, failureOf } from './repository-risk-assess.ts'
25
+ import type { LockfileLine, RepositoryRiskLine, RepositoryRiskRepo } from './repository-risk.ts'
26
+ import type { StasisDependency } from './bundle-build.ts'
27
+ import { isStasisConfig } from './lockfile-scope.ts'
28
+ import type { StasisRead } from './stasis-dependencies.ts'
29
+
30
+ // The formats of npm's ecosystem, as findRepoLockfiles names them, and those
31
+ // of them read here.
32
+ const NPM_LOCKFILE_FORMATS: ReadonlySet<LockfileFormat> = new Set(['npm', 'pnpm', 'yarn', 'bun', 'deno'])
33
+ const READ_FORMATS: ReadonlySet<LockfileFormat> = new Set(['npm', 'pnpm', 'yarn'])
34
+
35
+ // How long the source's `listings` and `lockfiles` are read for: what
36
+ // GitHub has at a commit or a blob doesn't change, how it is read here may.
37
+ export const SCAN_READ_KEPT_MS = 24 * 60 * 60_000
38
+ // How many of a repository's lockfiles are read at once: each one GitHub is
39
+ // asked for where it isn't kept, then parsed.
40
+ const LOCKFILES_AT_ONCE = 4
41
+
42
+ export type ListedLockfile = Pick<RepoLockfile, 'path' | 'format' | 'sha'>
43
+ export type LockfileRead = { packages: LockedPackage[] } | RiskFailure
44
+ // A repository's Dependabot alerts, those of its `paths` alone, with access to
45
+ // them to check again before they are told (`recheck`), or why they couldn't
46
+ // be had.
47
+ export type DependabotRead = { alerts: DependabotAlert[]; recheck?(): Promise<void> } | RiskFailure
48
+ export type RepositoryFailure = Extract<RepositoryRiskLine, { type: 'repo'; error: string }>
49
+ // A repository GitHub has archived, which a scan reads no further: its
50
+ // history alone, nothing that installs anew.
51
+ export type RepositoryArchived = Extract<RepositoryRiskLine, { type: 'repo'; archived: true }>
52
+ // What Stasis reaches of a stasis.config.json, as a dependency review's
53
+ // build of it tells (stasis-dependencies.ts): the versions it installs
54
+ // (`dependencies`), that its build is still to be made (`pending`), or why it
55
+ // failed.
56
+ // `lockfiles`, those its `lockfiles` names, from the repository's root,
57
+ // where it names some: those its builds install from (namedLockfiles).
58
+ export type StasisConfigRow = { path: string; lockfiles?: string[] } & ({ dependencies: StasisDependency[] } | { pending: true } | RiskFailure)
59
+ // A repository's stasis.config.json files, those of its `paths` alone, each
60
+ // what Stasis reaches of it, or why they couldn't be listed.
61
+ export type StasisConfigsRead = { configs: StasisConfigRow[] } | RiskFailure
62
+
63
+ // A version, as Stasis tells those it installs, whatever its integrity.
64
+ export const versionKey = ({ name, version }: { name: string; version: string }) => `${name}@${version}`
65
+ // The versions a repository's Stasis builds made install (versionKey); none
66
+ // of those still to be made, which aren't waited for.
67
+ export const stasisVersions = (read: StasisConfigsRead | null): string[] => [...new Set(read && 'configs' in read
68
+ ? read.configs.flatMap(config => 'dependencies' in config ? config.dependencies.map(versionKey) : []) : [])]
69
+ // The paths of a repository's stasis.config.json files whose builds are still
70
+ // to be made.
71
+ export const stasisBuilding = (read: StasisConfigsRead | null): string[] => read && 'configs' in read ? read.configs.flatMap(config => 'pending' in config ? [config.path] : []) : []
72
+
73
+ // A config's row of its read: a failed build told by its code (`detail`).
74
+ export function stasisConfigRow(path: string, read: StasisRead): StasisConfigRow {
75
+ if (read.status === 'ready') return { path, dependencies: read.dependencies }
76
+ return read.status === 'pending' ? { path, pending: true } : { path, error: 'stasis-failed', detail: read.error }
77
+ }
78
+
79
+ // A repository opened at its default branch's head (`commit`): its lockfiles,
80
+ // as findRepoLockfiles lists them, each with its blob's id, and a file's
81
+ // text; `recheck` checks access to it again, throwing where it is gone; and
82
+ // `dependabot`, where asked, its Dependabot alerts of npm's, open or dismissed, as GitHub
83
+ // has them now, with access to them to check again before they are told.
84
+ export interface OpenedRepository {
85
+ commit: string
86
+ lockfiles(): Promise<ListedLockfile[]>
87
+ file(path: string): Promise<string>
88
+ recheck(): Promise<void>
89
+ dependabot?(): Promise<AlertsRead>
90
+ // Its workflows' paths, none where it has none.
91
+ workflows?(): Promise<string[]>
92
+ // Its files' paths at `commit`, of which its stasis.config.json files are
93
+ // told (isStasisConfig); and what Stasis reaches of the one at `config`,
94
+ // as a dependency review's reader has it (stasis-dependencies.ts), its
95
+ // build asked for where none is kept yet, never waited for.
96
+ files?(): Promise<string[]>
97
+ stasis?(config: string): Promise<StasisRead>
98
+ }
99
+
100
+ // What a repository is read with: the scan's source and caches, and its
101
+ // signal.
102
+ interface RepositoryReading<R extends RepositoryRiskRepo> {
103
+ source: { open(repo: R): Promise<OpenedRepository | { archived: true }>; listings?: KeptStore<ListedLockfile[]>; lockfiles?: KeptStore<LockfileRead>;
104
+ actionFiles?: KeptStore<WorkflowsRead> }
105
+ caches: { listings: Lru<ListedLockfile[]>; lockfiles: Lru<LockfileRead>; actionFiles: Lru<WorkflowsRead> }
106
+ signal: AbortSignal
107
+ }
108
+
109
+ // A repository read: its commit, its lockfiles' lines, each with its blob's
110
+ // id, its Dependabot alerts where asked, and access to it to check again just
111
+ // before they are told (OpenedRepository `recheck`), as GitHub may have
112
+ // withdrawn it meanwhile.
113
+ export interface RepositoryRead {
114
+ commit: string
115
+ lockfiles: { sha: string; line: LockfileLine }[]
116
+ dependabot: DependabotRead | null
117
+ // Its Actions' files, where it lists its workflows.
118
+ actions: WorkflowsRead | null
119
+ // Its stasis.config.json files, where it has some and the source reads them.
120
+ stasis: StasisConfigsRead | null
121
+ recheck(): Promise<void>
122
+ }
123
+
124
+ // Whether a lockfile at `path` is of `paths` (RepositoryRiskRepo), as a
125
+ // stasis.config.json is.
126
+ export function lockfileOf(path: string, paths: readonly string[] | undefined) {
127
+ const dir = path.slice(0, Math.max(path.lastIndexOf('/'), 0))
128
+ return !paths || paths.some(scope => dir === '' || dir === scope || dir.startsWith(`${scope}/`) || scope.startsWith(`${dir}/`))
129
+ }
130
+
131
+ // What is kept by `key`: in this instance's memory, else in `store` within
132
+ // SCAN_READ_KEPT_MS, else `read` and kept in both, where it is to be.
133
+ async function keptRead<T>(memory: Lru<T>, store: KeptStore<T> | undefined, key: string, read: () => Promise<T>, keep = (_value: T) => true) {
134
+ const known = memory.get(key)
135
+ if (known !== undefined) return known
136
+ const kept = await store?.read(key)
137
+ if (kept && Date.now() - kept.at < SCAN_READ_KEPT_MS) { memory.set(key, kept.value); return kept.value }
138
+ const value = await read()
139
+ if (!keep(value)) return value
140
+ memory.set(key, value)
141
+ await store?.write(key, value, Date.now())
142
+ return value
143
+ }
144
+
145
+ // A lockfile's line, its packages or why they couldn't be had: as kept by its
146
+ // blob, else read from GitHub and kept; with the `sha` it is kept by, a
147
+ // yarn.lock's with its package.json files' (yarnManifests), which alone say
148
+ // what only devDependencies need, and change while it may not.
149
+ async function readLockfile({ source, caches }: RepositoryReading<RepositoryRiskRepo>, repo: number, opened: OpenedRepository,
150
+ { path, format, sha }: ListedLockfile): Promise<{ sha: string; line: LockfileLine }> {
151
+ const at = { type: 'lockfile', repo, path, format } as const
152
+ if (!READ_FORMATS.has(format)) return { sha, line: { ...at, error: 'unsupported-format' } }
153
+ try {
154
+ const manifests = format === 'yarn' ? await yarnManifests(path, file => opened.file(file), opened.files) : null
155
+ const kept = manifests ? `${sha}+${createHash('sha256').update(JSON.stringify(manifests)).digest('hex').slice(0, 16)}` : sha
156
+ return { sha: kept, line: { ...at, ...await keptRead(caches.lockfiles, source.lockfiles, `${format}\0${kept}`, async (): Promise<LockfileRead> => {
157
+ const text = await opened.file(path)
158
+ try { return { packages: lockedPackages(format, text, { manifests }) } } catch (error) {
159
+ return { error: 'lockfile-unreadable', ...error instanceof Error ? { detail: error.message.slice(0, 500) } : {} }
160
+ }
161
+ }) } }
162
+ } catch (error) { return { sha, line: { ...at, ...failureOf(error) } } }
163
+ }
164
+
165
+ // A repository opened and its lockfiles of npm's ecosystem listed, as kept
166
+ // for its commit or else from GitHub, those of its `paths` alone; its line
167
+ // telling why where either failed, or that GitHub has it archived, read no
168
+ // further; null where the scan stopped.
169
+ async function listLockfiles<R extends RepositoryRiskRepo>(reading: RepositoryReading<R>, repo: R):
170
+ Promise<{ opened: OpenedRepository; lockfiles: ListedLockfile[] } | RepositoryFailure | RepositoryArchived | null> {
171
+ let doing = 'opening it'
172
+ try {
173
+ const opened = await reading.source.open(repo)
174
+ if (reading.signal.aborted) return null
175
+ if ('archived' in opened) return { type: 'repo', id: repo.repoId, archived: true } as const
176
+ doing = 'listing its lockfiles'
177
+ const listed = await keptRead(reading.caches.listings, reading.source.listings, `${repo.repoId}@${opened.commit}`, () => opened.lockfiles())
178
+ const lockfiles = listed.filter(({ path, format }) => NPM_LOCKFILE_FORMATS.has(format) && lockfileOf(path, repo.paths))
179
+ return { opened, lockfiles }
180
+ } catch (error) {
181
+ return reading.signal.aborted ? null : { type: 'repo', id: repo.repoId, ...failureOf(error, doing) } as const
182
+ }
183
+ }
184
+
185
+ // A repository's Dependabot alerts of its `paths` (RepositoryRiskRepo), as
186
+ // its lockfiles are, or why they couldn't be had; null where they aren't
187
+ // asked.
188
+ async function readDependabot(opened: OpenedRepository, paths: readonly string[] | undefined): Promise<DependabotRead | null> {
189
+ if (!opened.dependabot) return null
190
+ try {
191
+ const { alerts, recheck } = await opened.dependabot()
192
+ return { alerts: alerts.filter(alert => lockfileOf(alert.manifest, paths)), recheck }
193
+ } catch (error) {
194
+ return failureOf(error, 'asking its Dependabot alerts')
195
+ }
196
+ }
197
+
198
+ // A repository's stasis.config.json files of its `paths` (RepositoryRiskRepo),
199
+ // as its lockfiles are, each what Stasis reaches of it; or why they couldn't
200
+ // be listed; null where it has none, or the source reads none.
201
+ async function readStasis(opened: OpenedRepository, paths: readonly string[] | undefined): Promise<StasisConfigsRead | null> {
202
+ const { files, stasis } = opened
203
+ if (!files || !stasis) return null
204
+ let configs
205
+ try { configs = (await files()).filter(path => isStasisConfig(path) && lockfileOf(path, paths)) } catch (error) {
206
+ return failureOf(error, 'listing its stasis.config.json files')
207
+ }
208
+ if (configs.length === 0) return null
209
+ return { configs: await Promise.all(configs.map(async path => {
210
+ const lockfiles = await opened.file(path).then(namedLockfiles(path), () => null)
211
+ try { return { ...stasisConfigRow(path, await stasis(path)), ...lockfiles && { lockfiles } } } catch (error) { return { path, ...failureOf(error) } }
212
+ })) }
213
+ }
214
+
215
+ // The lockfiles a stasis.config.json at `path` names (`lockfiles`), from its
216
+ // directory, as Stasis installs from those alone, each from the repository's
217
+ // root; null where it names none, or isn't JSON, or one is out of the
218
+ // repository.
219
+ export const namedLockfiles = (path: string) => (text: string): string[] | null => {
220
+ let named: unknown
221
+ try { named = (JSON.parse(text) as { lockfiles?: unknown } | null)?.lockfiles } catch { return null }
222
+ if (!Array.isArray(named) || named.length === 0 || !named.every(each => typeof each === 'string' && each !== '')) return null
223
+ const resolved = (named as string[]).map(each => {
224
+ const parts = path.split('/').slice(0, -1)
225
+ for (const part of each.split('/')) {
226
+ if (part === '..') { if (parts.pop() === undefined) return null } else if (part !== '' && part !== '.') parts.push(part)
227
+ }
228
+ return parts.join('/')
229
+ })
230
+ return resolved.every(Boolean) ? resolved as string[] : null
231
+ }
232
+
233
+ // A repository read: its lockfiles listed and read, a few at once, its
234
+ // Dependabot alerts asked, its Actions read and its stasis.config.json files
235
+ // asked meanwhile; its line telling why where listing
236
+ // failed, or that it is archived; null where the scan stopped. A test's
237
+ // fixture or example its reader refuses (isTestFixture) is left out, as a
238
+ // test may keep one so on purpose.
239
+ export async function readRepository<R extends RepositoryRiskRepo>(reading: RepositoryReading<R>, repo: R): Promise<RepositoryRead | RepositoryFailure | RepositoryArchived | null> {
240
+ const listed = await listLockfiles(reading, repo)
241
+ if (!listed || 'type' in listed) return listed
242
+ const { opened } = listed
243
+ const alerting = readDependabot(opened, repo.paths)
244
+ const reaching = readStasis(opened, repo.paths)
245
+ const { workflows } = opened
246
+ const acting = workflows ? keptRead(reading.caches.actionFiles, reading.source.actionFiles, `${repo.repoId}@${opened.commit}`,
247
+ () => readActions({ workflows, file: path => opened.file(path) }), lastingRead) : Promise.resolve(null)
248
+ acting.catch(() => {})
249
+ const inTurn = inTurns(LOCKFILES_AT_ONCE)
250
+ const lines = await Promise.all(listed.lockfiles.map(lockfile => inTurn(() => (reading.signal.aborted ? Promise.resolve(null) : readLockfile(reading, repo.repoId, opened, lockfile)))))
251
+ const lockfiles: RepositoryRead['lockfiles'] = []
252
+ for (const read of lines) {
253
+ if (!read) return null
254
+ if (!('error' in read.line && read.line.error === 'lockfile-unreadable' && isTestFixture(read.line.path))) lockfiles.push(read)
255
+ }
256
+ const dependabot = await alerting
257
+ const actions = await acting
258
+ const stasis = await reaching
259
+ return reading.signal.aborted ? null : { commit: opened.commit, lockfiles, dependabot, actions, stasis, recheck: () => opened.recheck() }
260
+ }
@@ -0,0 +1,61 @@
1
+ // What a repository risk scan knows of Stasis's builds (repository-risk.ts):
2
+ // the versions those made install (versionKey), Stasis's wherever they are
3
+ // locked, as the page tells them apart (repository-risk.js stasisReach),
4
+ // assessed before the rest; the packages seen of each version, to move up
5
+ // once it is told Stasis's; and the builds still to be made as their
6
+ // repositories were read, watched: asked again every STASIS_AGAIN_MS what
7
+ // Stasis has made of them, as their page asks, none ever waited for.
8
+ import { setTimeout as delay } from 'node:timers/promises'
9
+ import type { AssessedPackage } from './repository-risk-assess.ts'
10
+ import { versionKey } from './repository-risk-read.ts'
11
+ import type { StasisRead } from './stasis-dependencies.ts'
12
+
13
+ // As often as a page asks again of the builds it shows still to be made
14
+ // (repository-risk.js STASIS_POLL_MS).
15
+ export const STASIS_AGAIN_MS = 30_000
16
+
17
+ // A build still to be made: of the stasis.config.json at `config` of
18
+ // repository `repoId` at `commit`.
19
+ export interface StasisBuild { repoId: number; commit: string; config: string }
20
+
21
+ export interface StasisReach {
22
+ // Whether a Stasis build made installs its version.
23
+ has(pkg: AssessedPackage): boolean
24
+ // A package the scan sees, the first time.
25
+ seen(pkg: AssessedPackage): void
26
+ // `versions` told Stasis's: the packages seen of those new to it.
27
+ add(versions: readonly string[]): AssessedPackage[]
28
+ // Builds still to be made, to watch.
29
+ building(builds: StasisBuild[]): void
30
+ // Those watched asked of `built` every `everyMs`, till `signal` aborts:
31
+ // each made since given to `made` with the versions it installs, once; one
32
+ // failed let go, one still to be made asked again.
33
+ watch(built: (build: StasisBuild) => Promise<StasisRead>, made: (build: StasisBuild, versions: string[]) => void, signal: AbortSignal, everyMs: number): Promise<void>
34
+ }
35
+
36
+ export function stasisReach(): StasisReach {
37
+ const builds = new Map<string, StasisBuild>(), reached = new Set<string>(), seen = new Map<string, AssessedPackage[]>()
38
+ return {
39
+ has: pkg => reached.has(versionKey(pkg)),
40
+ seen(pkg) { seen.set(versionKey(pkg), [...seen.get(versionKey(pkg)) ?? [], pkg]) },
41
+ add(versions) {
42
+ const fresh = [...new Set(versions)].filter(version => !reached.has(version))
43
+ for (const version of fresh) reached.add(version)
44
+ return fresh.flatMap(version => seen.get(version) ?? [])
45
+ },
46
+ building(told) { for (const build of told) builds.set(`${build.repoId}\0${build.commit}\0${build.config}`, build) },
47
+ async watch(built, made, signal, everyMs) {
48
+ for (;;) {
49
+ try { await delay(everyMs, undefined, { signal }) } catch { return }
50
+ for (const [key, build] of builds) {
51
+ let read: StasisRead
52
+ try { read = await built(build) } catch { continue }
53
+ if (signal.aborted) return
54
+ if (read.status === 'pending') continue
55
+ builds.delete(key)
56
+ if (read.status === 'ready') made(build, [...new Set(read.dependencies.map(versionKey))])
57
+ }
58
+ }
59
+ },
60
+ }
61
+ }
@@ -0,0 +1,97 @@
1
+ // A turn of a repository risk scan's assessments (repository-risk.ts): the
2
+ // packages given it, each assessed once, as many at a time as npm-risk.ts
3
+ // makes spare assessments, those `first` (the scan's Stasis's) before the
4
+ // rest, each given to the assessors once its downloads are readied, where
5
+ // the scan readies them (scan-downloads.ts); once all it is given are
6
+ // assessed, or the scan stops, those given once its feed is over too. One
7
+ // given that is `first` only since, as a Stasis build made since installs
8
+ // it, is hurried where it is still waiting: its downloads readied before the
9
+ // rest, or put before the rest waiting for an assessor.
10
+ import { MAX_SPARE_ASSESSMENTS } from './npm-risk.ts'
11
+ import { type Queue, queue } from './queue.ts'
12
+ import { type AssessedPackage, BUSY_RETRIES, BUSY_WAIT_MS, isBusy } from './repository-risk-assess.ts'
13
+ import { type DownloadsSource, readyingDownloads } from './scan-downloads.ts'
14
+
15
+ export interface Turn {
16
+ // Packages to assess: those given it before not again. False, none taken,
17
+ // once the turn is over.
18
+ give(packages: AssessedPackage[]): boolean
19
+ // Those of `packages` given it that are `first` now, hurried.
20
+ hurry(packages: AssessedPackage[]): void
21
+ }
22
+
23
+ export interface TurnOptions {
24
+ signal: AbortSignal
25
+ downloads: DownloadsSource | undefined
26
+ // A package as the scan tells it apart (repository-risk.ts seenKey).
27
+ key(pkg: AssessedPackage): string
28
+ first(pkg: AssessedPackage): boolean
29
+ assess(pkg: AssessedPackage): Promise<void>
30
+ }
31
+
32
+ // Where a package given is: its downloads being readied, waiting for an
33
+ // assessor, or taken by one.
34
+ type Given = 'readying' | 'pending' | 'taken'
35
+
36
+ async function assessor({ key, assess }: TurnOptions, pending: Queue<AssessedPackage>, given: Map<string, Given>, done: () => void) {
37
+ for (let next = await pending.take(); next !== undefined; next = await pending.take()) {
38
+ // One hurried is in line twice: assessed once.
39
+ if (given.get(key(next)) === 'taken') continue
40
+ given.set(key(next), 'taken')
41
+ try { await assess(next) } finally { done() }
42
+ }
43
+ }
44
+
45
+ // The packages `feed` gives the turn assessed, once `feed` ends and all
46
+ // given it are: those given it since too, it being over only then.
47
+ export async function assessingTurn(options: TurnOptions, feed: (turn: Turn) => Promise<void>): Promise<void> {
48
+ const { signal, downloads, key, first } = options
49
+ const pending = queue<AssessedPackage>(signal)
50
+ const given = new Map<string, Given>()
51
+ // Whether an assessor failed; what waits for the last of those given once
52
+ // `feed` is over; whether it is; how many given are still to be assessed;
53
+ // and whether the turn is over.
54
+ let broken = false, drained = () => {}, fed = false, left = 0, over = false
55
+ const done = () => { left--; if (fed && left === 0) drained() }
56
+ const toAssessors = (pkg: AssessedPackage) => { given.set(key(pkg), 'pending'); pending.add(pkg, first(pkg)) }
57
+ const readying = downloads ? readyingDownloads<AssessedPackage>(downloads, signal, toAssessors, { busy: isBusy, retries: BUSY_RETRIES, waitMs: BUSY_WAIT_MS }) : null
58
+ // One failing ends the wait for the rest, its failure thrown as the turn ends.
59
+ const assessors = Array.from({ length: MAX_SPARE_ASSESSMENTS }, () => assessor(options, pending, given, done).catch((error: unknown) => { broken = true; drained(); throw error }))
60
+ const turn: Turn = {
61
+ give(packages) {
62
+ if (over) return false
63
+ const fresh = packages.filter(pkg => !given.has(key(pkg)))
64
+ left += fresh.length
65
+ if (!readying) { for (const pkg of fresh) toAssessors(pkg); return true }
66
+ for (const pkg of fresh) given.set(key(pkg), 'readying')
67
+ const firsts = fresh.filter(first)
68
+ if (firsts.length > 0) readying.add(firsts, true)
69
+ if (firsts.length < fresh.length) readying.add(fresh.filter(pkg => !first(pkg)))
70
+ return true
71
+ },
72
+ hurry(packages) {
73
+ if (over) return
74
+ const names: string[] = []
75
+ for (const pkg of packages) {
76
+ if (!first(pkg)) continue
77
+ const at = given.get(key(pkg))
78
+ if (at === 'readying') names.push(pkg.name)
79
+ else if (at === 'pending') pending.add(pkg, true)
80
+ }
81
+ if (names.length > 0) readying?.hurry(names)
82
+ },
83
+ }
84
+ try { await feed(turn) } finally {
85
+ fed = true
86
+ if (left > 0 && !signal.aborted && !broken) {
87
+ await new Promise<void>(resolve => {
88
+ drained = resolve
89
+ signal.addEventListener('abort', () => { resolve() }, { once: true })
90
+ })
91
+ }
92
+ over = true
93
+ await readying?.close()
94
+ pending.close()
95
+ }
96
+ await Promise.all(assessors)
97
+ }