@preventive/triage 1.0.0-alpha.9 → 1.0.0-alpha.90

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