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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +16 -78
  4. package/cli.js +6 -0
  5. package/client/dependency-paths.d.ts +3 -0
  6. package/client/dependency-paths.js +36 -0
  7. package/client/finding-link.js +305 -0
  8. package/client/linked-findings.d.ts +1 -0
  9. package/client/linked-findings.js +115 -0
  10. package/common/bundle-commit.d.ts +1 -0
  11. package/common/bundle-commit.js +4 -0
  12. package/common/bundle-compare-diff.d.ts +6 -0
  13. package/common/bundle-compare-diff.js +377 -0
  14. package/common/bundle-compare-inputs.d.ts +3 -0
  15. package/common/bundle-compare-inputs.js +141 -0
  16. package/common/bundle-compare-versions.js +172 -0
  17. package/common/bundle-comparison.d.ts +8 -0
  18. package/common/bundle-comparison.js +69 -0
  19. package/common/bundle-imports.js +20 -0
  20. package/common/bundle-metadata.d.ts +15 -0
  21. package/common/bundle-metadata.js +226 -0
  22. package/common/bundle-pkg-of.d.ts +1 -0
  23. package/common/bundle-pkg-of.js +90 -0
  24. package/common/bundle-reasons.d.ts +6 -0
  25. package/common/bundle-reasons.js +58 -0
  26. package/common/bundle-source-links.d.ts +6 -0
  27. package/common/bundle-source-links.js +216 -0
  28. package/common/bundle-sourcemap.d.ts +10 -0
  29. package/common/bundle-sourcemap.js +100 -0
  30. package/common/bundle-sources.d.ts +10 -0
  31. package/common/bundle-sources.js +374 -0
  32. package/common/bundle-stats.js +41 -0
  33. package/common/bundle-tabs.js +1 -0
  34. package/common/code-language.js +66 -0
  35. package/common/default-scan-models.ts +36 -0
  36. package/common/dependency-reviews.d.ts +18 -0
  37. package/common/dependency-reviews.js +64 -0
  38. package/common/finding-duplicates.js +63 -0
  39. package/common/finding-filters.js +313 -0
  40. package/common/finding-id.js +47 -0
  41. package/common/finding-repo.d.ts +5 -0
  42. package/common/finding-repo.js +67 -0
  43. package/common/github-issue-labels.d.ts +1 -0
  44. package/common/github-issue-labels.js +11 -0
  45. package/common/github-pr.ts +56 -0
  46. package/common/gzip.js +59 -0
  47. package/common/line-diff.d.ts +14 -0
  48. package/common/line-diff.js +181 -0
  49. package/common/linked-workspace-groups.js +63 -0
  50. package/common/managed/agent-tasks.ts +292 -0
  51. package/common/managed/comments.ts +43 -0
  52. package/common/managed/dependency-routes.js +25 -0
  53. package/common/managed/directory-packages.ts +28 -0
  54. package/common/managed/finding-detail.d.ts +5 -0
  55. package/common/managed/finding-detail.js +75 -0
  56. package/common/managed/finding-values.d.ts +2 -0
  57. package/common/managed/finding-values.js +138 -0
  58. package/common/managed/github-agents.ts +114 -0
  59. package/common/managed/github-logins.ts +49 -0
  60. package/common/managed/lite-name.d.ts +2 -0
  61. package/common/managed/lite-name.js +20 -0
  62. package/common/managed/npm-packages.d.ts +9 -0
  63. package/common/managed/npm-packages.js +63 -0
  64. package/common/managed/permissions.ts +31 -0
  65. package/common/managed/report-content.ts +72 -0
  66. package/common/managed/report-filter.ts +120 -0
  67. package/common/managed/repository-alias.ts +65 -0
  68. package/common/managed/review-view-routes.js +23 -0
  69. package/common/managed/risk-routes.js +30 -0
  70. package/common/managed/roles.ts +41 -0
  71. package/common/managed/routes.d.ts +2 -0
  72. package/common/managed/routes.js +385 -0
  73. package/common/managed/scan-models.ts +6 -0
  74. package/common/managed/stasis-config.ts +7 -0
  75. package/common/managed/team-app.d.ts +19 -0
  76. package/common/managed/team-app.js +129 -0
  77. package/common/managed/team-filters.js +26 -0
  78. package/common/managed/triage.ts +83 -0
  79. package/common/managed/upload-seal.ts +126 -0
  80. package/common/pretty-json.js +98 -0
  81. package/common/pretty-kinds.js +20 -0
  82. package/common/pretty-print.d.ts +6 -0
  83. package/common/pretty-print.js +36 -0
  84. package/common/pretty-sourcemap.js +70 -0
  85. package/common/repo-commit.d.ts +4 -0
  86. package/common/repo-commit.js +30 -0
  87. package/common/revalidation-conflicts.js +48 -0
  88. package/common/revalidation-input-groups.js +56 -0
  89. package/common/save-error-reason.ts +20 -7
  90. package/common/scan-server.ts +13 -0
  91. package/common/security-links.d.ts +5 -0
  92. package/common/security-links.js +33 -0
  93. package/common/server-info.ts +46 -0
  94. package/common/sourcemap-listing.js +78 -0
  95. package/common/sourcemap-mappings.js +136 -0
  96. package/common/sourcemap-unlist.js +85 -0
  97. package/common/stasis-files.d.ts +5 -0
  98. package/common/stasis-files.js +20 -0
  99. package/common/stasis-tgz.d.ts +6 -0
  100. package/common/stasis-tgz.js +27 -0
  101. package/common/utf8.d.ts +3 -0
  102. package/common/utf8.js +45 -0
  103. package/common/whitespace-insensitive.js +19 -0
  104. package/common/workspace-app.js +91 -0
  105. package/common/workspace-groups.js +176 -0
  106. package/out/activity.js +2 -0
  107. package/out/brotli-fallback.js +3 -3
  108. package/out/chunk-2XUEZHIP.js +28 -0
  109. package/out/chunk-55YIWY3H.js +5 -0
  110. package/out/chunk-5AVGKFMR.js +1 -0
  111. package/out/chunk-5CJKUV53.js +1 -0
  112. package/out/chunk-5EAVJAD2.js +3 -0
  113. package/out/chunk-5M2X3QPK.js +6 -0
  114. package/out/chunk-5QWPKTCE.js +40 -0
  115. package/out/chunk-6CCSTJWB.js +1 -0
  116. package/out/chunk-6VOB5WXX.js +2 -0
  117. package/out/chunk-6Y6PZ2BU.js +9 -0
  118. package/out/chunk-74JZTGTO.js +11 -0
  119. package/out/chunk-7BKKYVWR.js +7 -0
  120. package/out/chunk-7C7DWL7I.js +1 -0
  121. package/out/chunk-7HP2VYIC.js +2 -0
  122. package/out/chunk-7YFJUT2P.js +1 -0
  123. package/out/chunk-7YO4QV5P.js +1 -0
  124. package/out/chunk-A4BBBHQU.js +1 -0
  125. package/out/chunk-B64CTMVU.js +4 -0
  126. package/out/chunk-BEKYZCPX.js +14 -0
  127. package/out/chunk-C4Z6ZBXV.js +10 -0
  128. package/out/chunk-CU3FPB3P.js +1 -0
  129. package/out/chunk-DEVAORP2.js +1 -0
  130. package/out/chunk-DUASGS2O.js +8 -0
  131. package/out/chunk-DUS5ARE2.js +53 -0
  132. package/out/chunk-EEJA7JBI.js +13 -0
  133. package/out/chunk-FSU2PLJL.js +1 -0
  134. package/out/chunk-GBMAXAYK.js +3 -0
  135. package/out/chunk-GO7FT4OD.js +1 -0
  136. package/out/chunk-GX5UXWT4.js +1 -0
  137. package/out/chunk-ITUKKCCK.js +10 -0
  138. package/out/chunk-IYPY47MC.js +1 -0
  139. package/out/chunk-JXBRWLMA.js +4 -0
  140. package/out/chunk-K4XJHM2T.js +1 -0
  141. package/out/chunk-LBD3M3J6.js +1 -0
  142. package/out/chunk-LVSLM7HB.js +1 -0
  143. package/out/chunk-LVW7WWV4.js +1 -0
  144. package/out/chunk-MV66NL3G.js +3 -0
  145. package/out/chunk-N57OWFKY.js +15 -0
  146. package/out/chunk-NRPC74AM.js +1 -0
  147. package/out/chunk-OOJM4CTU.js +1 -0
  148. package/out/chunk-OWSEQOL5.js +1 -0
  149. package/out/chunk-PKLVXUEI.js +11 -0
  150. package/out/chunk-PLGH63UC.js +2 -0
  151. package/out/chunk-PNHBZGDD.js +1 -0
  152. package/out/chunk-PTFYDJUP.js +1 -0
  153. package/out/chunk-PWFUOLZK.js +17 -0
  154. package/out/chunk-PXK7EU4V.js +1 -0
  155. package/out/chunk-QD3IBSF4.js +7 -0
  156. package/out/chunk-QI66YA4F.js +1 -0
  157. package/out/chunk-QRKFPLA4.js +80 -0
  158. package/out/chunk-R3NZFXVR.js +1 -0
  159. package/out/chunk-R5O6FAW4.js +2 -0
  160. package/out/chunk-RPNO56H2.js +1 -0
  161. package/out/chunk-SSPDMA6D.js +1 -0
  162. package/out/chunk-SZWPYLPC.js +1 -0
  163. package/out/chunk-TUII34K2.js +1 -0
  164. package/out/chunk-UJP4PQJA.js +1 -0
  165. package/out/chunk-UJSJMXEG.js +1 -0
  166. package/out/chunk-UR4WYMIP.js +1 -0
  167. package/out/chunk-VHEXSGGP.js +1 -0
  168. package/out/chunk-VYYUMYVW.js +9 -0
  169. package/out/chunk-VZPPX6MV.js +1 -0
  170. package/out/chunk-WCDYSIKG.js +1 -0
  171. package/out/chunk-XM4RLC4A.js +2 -0
  172. package/out/chunk-YKCRCNYZ.js +266 -0
  173. package/out/chunk-ZQHLECTI.js +1 -0
  174. package/out/client-managed-import.js +4 -0
  175. package/out/client-managed.js +37 -0
  176. package/out/client-sync.js +11 -17
  177. package/out/compare.js +26 -0
  178. package/out/dialogs.js +40 -0
  179. package/out/github-issue-authorized.html +3 -0
  180. package/out/github-issue-authorized.js +1 -0
  181. package/out/graph.js +19 -4
  182. package/out/index.html +104 -24
  183. package/out/prism.js +14 -10
  184. package/out/scan.js +2 -0
  185. package/out/stasis.svg +20 -0
  186. package/out/terminal.js +367 -39
  187. package/out/view.css +1 -1
  188. package/out/view.js +19 -147
  189. package/package.json +409 -64
  190. package/risk/actions/findings.js +161 -0
  191. package/risk/actions/resolve.js +287 -0
  192. package/risk/actions/scripts/commands.js +182 -0
  193. package/risk/actions/scripts/grade.js +113 -0
  194. package/risk/actions/scripts/packages.js +123 -0
  195. package/risk/actions/scripts/shell.js +169 -0
  196. package/risk/actions/uses.js +94 -0
  197. package/risk/actions/workflow.js +183 -0
  198. package/risk/files/characters.js +341 -0
  199. package/risk/files/hosts.js +206 -0
  200. package/risk/files/readability.js +185 -0
  201. package/risk/files/runs-code.js +563 -0
  202. package/risk/files/script.js +402 -0
  203. package/risk/files/source-map-link.js +43 -0
  204. package/risk/files/stamps.js +47 -0
  205. package/risk/index.d.ts +294 -0
  206. package/risk/index.js +12 -0
  207. package/risk/npm/assess.js +285 -0
  208. package/risk/npm/combined.js +68 -0
  209. package/risk/npm/compare.js +236 -0
  210. package/risk/npm/dependencies.js +172 -0
  211. package/risk/npm/diff.js +79 -0
  212. package/risk/npm/downloads.js +84 -0
  213. package/risk/npm/files.js +445 -0
  214. package/risk/npm/held.js +67 -0
  215. package/risk/npm/install-scripts.js +34 -0
  216. package/risk/npm/malware.js +38 -0
  217. package/risk/npm/manifest.js +65 -0
  218. package/risk/npm/new-dependency.js +60 -0
  219. package/risk/npm/old-version.js +108 -0
  220. package/risk/npm/registry.js +393 -0
  221. package/risk/npm/release.js +85 -0
  222. package/risk/npm/score.js +59 -0
  223. package/risk/npm/specs.js +124 -0
  224. package/risk/npm/tarball.js +169 -0
  225. package/server-common/database-config.ts +16 -0
  226. package/server-common/initialize.ts +18 -0
  227. package/server-common/npm-advisories.ts +101 -0
  228. package/{server → server-common}/origin.ts +5 -5
  229. package/server-common/reap.ts +48 -0
  230. package/server-common/scan-config.ts +19 -0
  231. package/server-common/standalone.ts +29 -0
  232. package/server-common/storage-crypto.ts +182 -0
  233. package/server-common/storage-log.ts +38 -0
  234. package/server-common/vercel-blob.ts +103 -0
  235. package/server-e2e/app.ts +487 -0
  236. package/{server → server-e2e}/bus-receiver.ts +2 -1
  237. package/{server → server-e2e}/cli.js +9 -4
  238. package/{server → server-e2e}/config.ts +50 -42
  239. package/{server → server-e2e}/db-neon.ts +2 -2
  240. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  241. package/{server → server-e2e}/db-stmt.ts +2 -2
  242. package/{server → server-e2e}/db.ts +7 -7
  243. package/{server → server-e2e}/http.ts +44 -13
  244. package/{server → server-e2e}/hub.ts +40 -9
  245. package/server-e2e/index.ts +17 -0
  246. package/server-e2e/lifecycle.ts +95 -0
  247. package/{server → server-e2e}/neon-driver.ts +2 -2
  248. package/{server → server-e2e}/npm-proxy.ts +12 -145
  249. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  250. package/{server → server-e2e}/objstore/blob.ts +1 -1
  251. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  252. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  253. package/{server → server-e2e}/objstore/init.ts +19 -27
  254. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  255. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  256. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  257. package/{server → server-e2e}/objstore/rest.ts +3 -3
  258. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  259. package/{server → server-e2e}/objstore/store.ts +7 -7
  260. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  261. package/{server → server-e2e}/pubsub.ts +12 -9
  262. package/{server → server-e2e}/sign.ts +4 -4
  263. package/{server → server-e2e}/sse-server.ts +60 -33
  264. package/{server → server-e2e}/static.ts +18 -17
  265. package/{server → server-e2e}/sync-handlers.ts +64 -30
  266. package/{server → server-e2e}/ws-server.ts +20 -9
  267. package/server-managed/activity.ts +247 -0
  268. package/server-managed/agent-merges.ts +109 -0
  269. package/server-managed/app-agents.ts +23 -0
  270. package/server-managed/avatar-store.ts +13 -0
  271. package/server-managed/blob-store.ts +26 -0
  272. package/server-managed/brotli.ts +10 -0
  273. package/server-managed/bundle-advisories.ts +79 -0
  274. package/server-managed/bundle-advisory-inventory.ts +85 -0
  275. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  276. package/server-managed/bundle-build-diagnostics.js +23 -0
  277. package/server-managed/bundle-build-leases.ts +41 -0
  278. package/server-managed/bundle-build-worker.js +380 -0
  279. package/server-managed/bundle-build.ts +326 -0
  280. package/server-managed/bundle-cache.ts +261 -0
  281. package/server-managed/bundle-catalog.ts +29 -0
  282. package/server-managed/bundle-commits.ts +133 -0
  283. package/server-managed/bundle-dependency-reviews.ts +91 -0
  284. package/server-managed/bundle-store.ts +24 -0
  285. package/server-managed/bundle-summary-cache.ts +139 -0
  286. package/server-managed/bundle-validation.ts +33 -0
  287. package/server-managed/bundle.ts +151 -0
  288. package/server-managed/cache-storage.ts +20 -0
  289. package/server-managed/cli.js +21 -0
  290. package/server-managed/combined.ts +43 -0
  291. package/server-managed/comments.ts +138 -0
  292. package/server-managed/commit-coauthors.ts +105 -0
  293. package/server-managed/commit-lockfiles.ts +78 -0
  294. package/server-managed/comparison.ts +51 -0
  295. package/server-managed/config.ts +163 -0
  296. package/server-managed/content-access.ts +15 -0
  297. package/server-managed/crypto.ts +25 -0
  298. package/server-managed/db-methods.ts +1914 -0
  299. package/server-managed/db-neon.ts +398 -0
  300. package/server-managed/db-schema.ts +263 -0
  301. package/server-managed/db-table-names.ts +22 -0
  302. package/server-managed/db.ts +149 -0
  303. package/server-managed/dependabot-access.ts +61 -0
  304. package/server-managed/dependabot-alerts.ts +180 -0
  305. package/server-managed/dependency-review-comments.ts +143 -0
  306. package/server-managed/dependency-reviews.ts +369 -0
  307. package/server-managed/github-accounts.ts +59 -0
  308. package/server-managed/github-actions.ts +71 -0
  309. package/server-managed/github-app.ts +347 -0
  310. package/server-managed/github-errors.ts +92 -0
  311. package/server-managed/github-graphql.ts +42 -0
  312. package/server-managed/github-issue-links.ts +264 -0
  313. package/server-managed/github-issue-oauth.ts +30 -0
  314. package/server-managed/github-issues.ts +157 -0
  315. package/server-managed/github-link-oauth.ts +56 -0
  316. package/server-managed/github-links.ts +204 -0
  317. package/server-managed/github-metadata.ts +213 -0
  318. package/server-managed/github-oauth.ts +264 -0
  319. package/server-managed/github-pulls.ts +257 -0
  320. package/server-managed/github-requests.ts +181 -0
  321. package/server-managed/github-users.ts +30 -0
  322. package/server-managed/github-values.ts +26 -0
  323. package/server-managed/history-windows.ts +172 -0
  324. package/server-managed/http-response.ts +76 -0
  325. package/server-managed/http.ts +6324 -0
  326. package/server-managed/import-triage.ts +51 -0
  327. package/server-managed/index.ts +204 -0
  328. package/server-managed/kept-briefly.ts +37 -0
  329. package/server-managed/kept.ts +28 -0
  330. package/server-managed/link-reports.ts +149 -0
  331. package/server-managed/listed-activity.ts +39 -0
  332. package/server-managed/locked-packages.ts +234 -0
  333. package/server-managed/lockfile-scope.ts +58 -0
  334. package/server-managed/lru.ts +30 -0
  335. package/server-managed/managed-issues.ts +92 -0
  336. package/server-managed/management-catalog.ts +45 -0
  337. package/server-managed/management.ts +116 -0
  338. package/server-managed/npm-delta-worker.js +142 -0
  339. package/server-managed/npm-delta.ts +277 -0
  340. package/server-managed/npm-insights.ts +455 -0
  341. package/server-managed/npm-kept.ts +265 -0
  342. package/server-managed/npm-loads.ts +259 -0
  343. package/server-managed/npm-manifest.ts +117 -0
  344. package/server-managed/npm-packages.ts +469 -0
  345. package/server-managed/npm-patch-paths.ts +86 -0
  346. package/server-managed/npm-patch.ts +455 -0
  347. package/server-managed/npm-provenance.ts +127 -0
  348. package/server-managed/npm-risk.ts +287 -0
  349. package/server-managed/object-storage-disk.ts +147 -0
  350. package/server-managed/object-storage-vercel.ts +71 -0
  351. package/server-managed/object-storage.ts +82 -0
  352. package/server-managed/package-entry-points.ts +127 -0
  353. package/server-managed/pretty-copies.ts +22 -0
  354. package/server-managed/pretty-format.d.ts +3 -0
  355. package/server-managed/pretty-format.js +13 -0
  356. package/server-managed/pretty-print.ts +442 -0
  357. package/server-managed/public-workspace.ts +243 -0
  358. package/server-managed/pull-comment-reviews.ts +161 -0
  359. package/server-managed/pull-dependencies.ts +370 -0
  360. package/server-managed/pull-dependency-reviews.ts +407 -0
  361. package/server-managed/pull-reviews.ts +202 -0
  362. package/server-managed/queue.ts +54 -0
  363. package/server-managed/release-commits.ts +85 -0
  364. package/server-managed/rename-diff-worker.js +30 -0
  365. package/server-managed/rename-diff.ts +237 -0
  366. package/server-managed/repo-path.ts +21 -0
  367. package/server-managed/report-migration.ts +32 -0
  368. package/server-managed/report-opening.ts +77 -0
  369. package/server-managed/report-query.ts +10 -0
  370. package/server-managed/report-response.ts +16 -0
  371. package/server-managed/report-sources.ts +185 -0
  372. package/server-managed/report-store.ts +77 -0
  373. package/server-managed/repository-actions.ts +220 -0
  374. package/server-managed/repository-agents.ts +422 -0
  375. package/server-managed/repository-aliases.ts +119 -0
  376. package/server-managed/repository-browser.ts +361 -0
  377. package/server-managed/repository-changes.ts +280 -0
  378. package/server-managed/repository-code.ts +222 -0
  379. package/server-managed/repository-dependency-reviews.ts +182 -0
  380. package/server-managed/repository-discovery.ts +83 -0
  381. package/server-managed/repository-history.ts +428 -0
  382. package/server-managed/repository-issues.ts +293 -0
  383. package/server-managed/repository-policy.ts +27 -0
  384. package/server-managed/repository-pulls.ts +207 -0
  385. package/server-managed/repository-pulse.ts +477 -0
  386. package/server-managed/repository-risk-assess.ts +108 -0
  387. package/server-managed/repository-risk-audit.ts +78 -0
  388. package/server-managed/repository-risk-caches.ts +37 -0
  389. package/server-managed/repository-risk-read.ts +260 -0
  390. package/server-managed/repository-risk-stasis.ts +61 -0
  391. package/server-managed/repository-risk-turn.ts +97 -0
  392. package/server-managed/repository-risk.ts +516 -0
  393. package/server-managed/repository-squashes.ts +160 -0
  394. package/server-managed/repository-stamp.ts +41 -0
  395. package/server-managed/request-timing.ts +63 -0
  396. package/server-managed/reviewed-dependencies.ts +170 -0
  397. package/server-managed/revisions.ts +35 -0
  398. package/server-managed/scan-downloads.ts +121 -0
  399. package/server-managed/session.ts +132 -0
  400. package/server-managed/slugs.ts +38 -0
  401. package/server-managed/solidity-entry-points.ts +71 -0
  402. package/server-managed/sql-postgres.ts +34 -0
  403. package/server-managed/sql.ts +107 -0
  404. package/server-managed/stasis-config.ts +147 -0
  405. package/server-managed/stasis-dependencies.ts +221 -0
  406. package/server-managed/static.ts +28 -0
  407. package/server-managed/storage-command.ts +16 -0
  408. package/server-managed/storage-db.ts +183 -0
  409. package/server-managed/storage-encryption.ts +288 -0
  410. package/server-managed/storage-maintenance.ts +259 -0
  411. package/server-managed/storage-payload.ts +121 -0
  412. package/server-managed/storage-stores.ts +91 -0
  413. package/server-managed/storage.ts +82 -0
  414. package/server-managed/team-app-summaries.ts +56 -0
  415. package/server-managed/team-app.ts +156 -0
  416. package/server-managed/team-catalog.ts +7 -0
  417. package/server-managed/team-feed.ts +180 -0
  418. package/server-managed/team-npm-scopes.ts +103 -0
  419. package/server-managed/team-reports.ts +368 -0
  420. package/server-managed/triage-response.ts +16 -0
  421. package/server-managed/type-only-proof.js +161 -0
  422. package/server-managed/type-only-worker.js +31 -0
  423. package/server-managed/type-only.ts +135 -0
  424. package/server-managed/uploads.ts +106 -0
  425. package/server-managed/upstream-cache.ts +256 -0
  426. package/server-managed/view-as.ts +58 -0
  427. package/server-managed/worker-turns.ts +76 -0
  428. package/server-managed/workspace-shares.ts +170 -0
  429. package/server.ts +70 -0
  430. package/strip-types-loader.js +13 -10
  431. package/server/index.ts +0 -480
  432. package/server/lifecycle.ts +0 -208
  433. /package/{LICENSE → LICENSE-MIT} +0 -0
  434. /package/{server → server-e2e}/auth.ts +0 -0
  435. /package/{server → server-e2e}/config.example.json +0 -0
  436. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  437. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  438. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  439. /package/{server → server-e2e}/peer.ts +0 -0
  440. /package/{server → server-e2e}/sse-session.ts +0 -0
  441. /package/{server → server-e2e}/util.ts +0 -0
  442. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,54 @@
1
+ // Items in the order they are added, those added `first` before the rest,
2
+ // each taken once by whichever reader asks first: none once closed and all
3
+ // taken, or once `signal` aborts, but those added by then where `drain`, none
4
+ // waited for.
5
+ export interface Queue<T> { add(item: T, first?: boolean): void; close(): void; take(): Promise<T | undefined> }
6
+ export function queue<T>(signal: AbortSignal, { drain = false } = {}): Queue<T> {
7
+ const firsts: T[] = [], items: T[] = []
8
+ const waiting: (() => void)[] = []
9
+ let closed = false
10
+ const wake = () => { for (const resolve of waiting.splice(0)) resolve() }
11
+ signal.addEventListener('abort', wake, { once: true })
12
+ return {
13
+ add(item, first = false) { (first ? firsts : items).push(item); wake() },
14
+ close() { closed = true; wake() },
15
+ async take() {
16
+ for (;;) {
17
+ if (signal.aborted && !drain) return undefined
18
+ const item = firsts.length > 0 ? firsts.shift() : items.shift()
19
+ if (item !== undefined || closed || signal.aborted) return item
20
+ await new Promise<void>(resolve => { waiting.push(resolve) })
21
+ }
22
+ },
23
+ }
24
+ }
25
+
26
+ // Work done `count` at a time, in the order asked, the rest waiting their
27
+ // turn.
28
+ export function inTurns(count: number): <T>(work: () => Promise<T>) => Promise<T> {
29
+ let active = 0
30
+ const waiting: (() => void)[] = []
31
+ return async work => {
32
+ if (active < count) active++
33
+ else await new Promise<void>(resolve => { waiting.push(resolve) })
34
+ try { return await work() } finally {
35
+ const next = waiting.shift()
36
+ if (next) next()
37
+ else active--
38
+ }
39
+ }
40
+ }
41
+
42
+ // Runs `run` for each of `items`, as many at once as `parallel`, each's
43
+ // result in its place.
44
+ export async function eachOf<T, R>(items: T[], parallel: number, run: (item: T) => Promise<R>): Promise<R[]> {
45
+ const results: R[] = []
46
+ let next = 0
47
+ await Promise.all(Array.from({ length: Math.min(parallel, items.length) }, async () => {
48
+ while (next < items.length) {
49
+ const at = next++
50
+ results[at] = await run(items[at]!)
51
+ }
52
+ }))
53
+ return results
54
+ }
@@ -0,0 +1,85 @@
1
+ // The commits that release a repository, for its Pulse (repository-pulse.ts
2
+ // commitStats): one a tag names that changes no code, only package.json
3
+ // files (at least one, in any directory), the lockfiles beside them
4
+ // (RELEASE_LOCKFILES) and changelogs written in Markdown (RELEASE_CHANGELOG,
5
+ // a changeset's file among them), as `npm version` and a release's tooling
6
+ // leave one. What each commit changes is read as Replay reads it, kept by
7
+ // the commit (repository-changes.ts repositoryChanges).
8
+ import { type ChangesStore, type CommitChanges, repositoryChanges } from './repository-changes.ts'
9
+ import { githubGraphql } from './github-graphql.ts'
10
+ import { SHA, timeOf } from './github-values.ts'
11
+ import { type Connection, nextCursor } from './repository-history.ts'
12
+
13
+ // The tags read, a page a query, the latest commits' first, as many pages as
14
+ // TAG_PAGES; of the commits they name, as many as RELEASES_READ have their
15
+ // files read.
16
+ const TAG_PAGE = 100
17
+ const TAG_PAGES = 5
18
+ const RELEASES_READ = 200
19
+ // An annotated tag's target, its own target in turn, through as many as
20
+ // TAG_DEPTH annotated tags.
21
+ const TAG_DEPTH = 3
22
+ const RELEASE_LOCKFILES = new Set(['package-lock.json', 'npm-shrinkwrap.json', 'pnpm-lock.yaml', 'yarn.lock', 'bun.lock', 'bun.lockb'])
23
+ const RELEASE_CHANGELOG = /^(?:changelog|changes|history|news|releases?)(?:[._-][^/]*)?\.(?:md|markdown)$/iu
24
+ const CHANGESET = /(?:^|\/)\.changeset\/[^/]+\.md$/iu
25
+
26
+ const tagTarget = (depth: number): string => `target { __typename oid ... on Commit { committedDate }${depth > 0 ? ` ... on Tag { ${tagTarget(depth - 1)} }` : ''} }`
27
+ const TAGS_QUERY = `query($owner: String!, $name: String!, $after: String) {
28
+ repository(owner: $owner, name: $name) {
29
+ refs(refPrefix: "refs/tags/", first: ${TAG_PAGE}, after: $after, orderBy: { field: TAG_COMMIT_DATE, direction: DESC }) {
30
+ pageInfo { hasNextPage endCursor }
31
+ nodes { ${tagTarget(TAG_DEPTH)} }
32
+ }
33
+ }
34
+ }`
35
+ type TagTarget = { __typename?: unknown; oid?: unknown; committedDate?: unknown; target?: TagTarget | null } | null | undefined
36
+ type TagsPage = { repository?: { refs?: Connection<{ target?: TagTarget }> | null } | null }
37
+
38
+ // The commit a tag names, through its annotated tags, and when it was
39
+ // committed; null for one naming no commit (a tree, a blob).
40
+ function taggedCommit(target: TagTarget, depth = TAG_DEPTH): { oid: string; at: number } | null {
41
+ if (target?.__typename === 'Tag' && depth > 0) return taggedCommit(target.target, depth - 1)
42
+ const at = timeOf(target?.committedDate)
43
+ return target?.__typename === 'Commit' && typeof target.oid === 'string' && SHA.test(target.oid) && at !== null ? { oid: target.oid, at } : null
44
+ }
45
+
46
+ // The commits the repository's tags name committed since `since`, the
47
+ // latest first, as many pages of them as TAG_PAGES.
48
+ async function taggedCommits(fullName: string, token: string, since: number, fetchImpl: typeof fetch = globalThis.fetch): Promise<Set<string>> {
49
+ const [owner, name] = fullName.split('/') as [string, string]
50
+ const tagged = new Set<string>()
51
+ let after: string | null = null
52
+ for (let pages = 0; pages < TAG_PAGES; pages++) {
53
+ const page = await githubGraphql(TAGS_QUERY, { owner, name, after }, token, fetchImpl) as TagsPage | null
54
+ const refs = page?.repository?.refs
55
+ const commits = (refs?.nodes ?? []).flatMap(node => taggedCommit(node?.target) ?? [])
56
+ for (const commit of commits) if (commit.at >= since) tagged.add(commit.oid)
57
+ after = nextCursor(refs?.pageInfo)
58
+ if (after === null || commits.some(commit => commit.at < since)) break
59
+ }
60
+ return tagged
61
+ }
62
+
63
+ // Whether a path is one a release changes: a package.json, a lockfile beside
64
+ // one, or a changelog in Markdown.
65
+ const releaseFile = (path: string) => {
66
+ const base = path.slice(path.lastIndexOf('/') + 1)
67
+ return base === 'package.json' || RELEASE_LOCKFILES.has(base) || RELEASE_CHANGELOG.test(base) || CHANGESET.test(path)
68
+ }
69
+
70
+ // Whether what a commit changes is a release's: a package.json at least, and
71
+ // nothing a release changes none of, a rename's both paths alike; one
72
+ // GitHub listed only some files of, not.
73
+ export function releaseChanges({ files, more }: CommitChanges): boolean {
74
+ const paths = files.flatMap(([path, status, from]) => status === 'R' ? [path, from] : [path])
75
+ return !more && paths.some(path => path.slice(path.lastIndexOf('/') + 1) === 'package.json') && paths.every(releaseFile)
76
+ }
77
+
78
+ // The commits since `since` that release the repository: those its tags
79
+ // name whose changes are a release's, each read as Replay reads it (`kept`),
80
+ // as many as RELEASES_READ, sorted.
81
+ export async function releaseCommits(fullName: string, token: string, since: number, kept: ChangesStore, fetchImpl: typeof fetch = globalThis.fetch): Promise<string[]> {
82
+ const tagged = [...await taggedCommits(fullName, token, since, fetchImpl)].slice(0, RELEASES_READ)
83
+ const changes = await repositoryChanges(fullName, token, tagged, kept, fetchImpl)
84
+ return tagged.filter(sha => { const read = changes.get(sha); return read ? releaseChanges(read) : false }).toSorted()
85
+ }
@@ -0,0 +1,30 @@
1
+ // Compare's diff with renamed names hidden (rename-diff.ts), worked out off the
2
+ // server's event loop by @preventive/compare's renamedDiffs: the old side given
3
+ // the new side's names, not formatted again (each line where the old side's was),
4
+ // diffed with whitespace changes shown and hidden, and the blocks checked to
5
+ // take it to the new side. `{ before, blocks, reason, reads, assumed, marks,
6
+ // ignoringWhitespace }`: the old side as diffed, the change blocks, why the
7
+ // old side is as it was where its names could not be given safely, the
8
+ // properties through which either side reads names (a view marks renamed
9
+ // lines rather than hiding them where any are read, as a rename may then
10
+ // change what the code does), what a name renamed at a script's top level
11
+ // was taken as its own for (`module`, the other side being one; `minified`,
12
+ // a minifier having renamed them all), which it is not where the script runs
13
+ // as a classic one, its top level's names globals, and the blocks of the diff
14
+ // of the files as they are that differ in renamed names alone;
15
+ // `ignoringWhitespace` the blocks and those marked with whitespace changes
16
+ // hidden, as diff -b hides them. Blocks that would not take the old side to
17
+ // the new are thrown, and so answer nothing.
18
+ import { parentPort, workerData } from 'node:worker_threads'
19
+ import { renamedDiffs } from '@preventive/compare/names.js'
20
+
21
+ const { before, after, extension, otherExtension } = workerData
22
+ const diff = await renamedDiffs(before, after, { extension, otherExtension, whitespace: ['none', 'change'] })
23
+ // A check that should never fail did, or a step gave way: told, the file shown with its names.
24
+ for (const warning of diff.warnings) console.warn(`managed: rename diff: ${warning}`)
25
+ const [shown, hidden] = diff.diffs
26
+ const answer = { before: diff.before, blocks: shown.blocks, reason: diff.reason, reads: diff.reads, assumed: diff.assumed, marks: shown.marks,
27
+ ignoringWhitespace: { blocks: hidden.blocks, marks: hidden.marks } }
28
+ // Node worker messages have no browser target origin.
29
+ // oxlint-disable-next-line unicorn/require-post-message-target-origin
30
+ parentPort.postMessage(answer)
@@ -0,0 +1,237 @@
1
+ // Compare's diff of a JavaScript file minified on both sides with the names a
2
+ // minifier renamed alike hidden (GET /api/bundles/:id/rename-diff, GET
3
+ // /api/npm/rename-diff): both sides pretty-printed, as the pretty-print toggle
4
+ // has them (pretty-print.ts), then diffed by @preventive/compare's
5
+ // renamedDiffs in a worker, off the event loop and two at a time per process,
6
+ // with whitespace changes shown and hidden both. Answered as Brotli-encoded
7
+ // JSON, `{ before, blocks, reason, reads, assumed, marks, ignoringWhitespace }`
8
+ // (rename-diff-worker.js), the two files' hashes, `hash` and `otherHash`, and
9
+ // those of the two copies diffed, `prettyHash` and `otherPrettyHash`, which
10
+ // the viewer checks are those it asked about and draws: one file's asked for
11
+ // by both its sides' paths and hashes, or every pair a comparison's viewer
12
+ // diffs so, a line each (renamedPairs). The last few answers are kept in
13
+ // memory by both files' hashes, a private npm version's never, each side read
14
+ // again through the pretty-print cache first, which checks that its source
15
+ // holds a file of that hash. Access is the caller's to check.
16
+ import { Buffer } from 'node:buffer'
17
+ import { promisify } from 'node:util'
18
+ import { brotliDecompress } from 'node:zlib'
19
+ import { layoutPackageDirs, treeLayout } from '@preventive/compare'
20
+ import { computeFileHash } from '@preventive/report'
21
+ import { FILE_HASH } from '../common/bundle-metadata.js'
22
+ import { computeBundleDiff } from '../common/bundle-compare-diff.js'
23
+ import { bundlePkgOf } from '../common/bundle-pkg-of.js'
24
+ import { needsPrettyPrint, prettyExtension } from '../common/pretty-print.js'
25
+ import { type ChangeBlock, blocksHold, textLines } from '../common/line-diff.js'
26
+ import type { OpenedBlob } from './blob-store.ts'
27
+ import { encodeBrotli } from './brotli.ts'
28
+ import { pathOrder } from './npm-packages.ts'
29
+ import { type ComparedSide, PrettyError, type PrettyRequest, opened, prettyText } from './pretty-print.ts'
30
+ import { workerTurns } from './worker-turns.ts'
31
+
32
+ // What a minifier renames: JavaScript, as the viewer offers it for.
33
+ const RENAMABLE = new Set(['js', 'mjs', 'cjs'])
34
+ // Diffs worked out at once per process, each in a worker of its own, and
35
+ // those waiting their turn past them (a Diff view asks for all it shows at
36
+ // once), any more refused.
37
+ const MAX_ACTIVE_DIFFS = 2
38
+ const MAX_WAITING_DIFFS = 16
39
+ // The longest a diff may take, its wait for a worker included, and the most
40
+ // text it is asked of: both sides pretty-printed, which the largest files
41
+ // formatted (MAX_PRETTY_BYTES) stay under.
42
+ const DIFF_TIMEOUT_MS = 60_000
43
+ const MAX_DIFF_CHARS = 64 * 1024 * 1024
44
+ // Answers kept, the one read last last: each holds the old side as diffed.
45
+ // As many as a comparison's viewer may ask for beside the pairs it has come
46
+ // (renamedPairs), so that neither is worked out twice.
47
+ const KEPT_DIFFS = 32
48
+
49
+ // `blocks` and `marks` with whitespace changes shown, `ignoringWhitespace`'s
50
+ // hidden as diff -b hides them.
51
+ export interface RenameDiff {
52
+ before: string; blocks: ChangeBlock[]; reason: string | null; reads: string[]; assumed: string[]; marks: ChangeBlock[]
53
+ ignoringWhitespace: { blocks: ChangeBlock[]; marks: ChangeBlock[] }
54
+ }
55
+
56
+ export interface RenameDiffRequest { base: PrettyRequest; other: PrettyRequest }
57
+
58
+ // The two files a request names, a base's `path` and `hash` and the other
59
+ // side's `otherPath` and `otherHash`, or null where either is no JavaScript
60
+ // file named by its hash.
61
+ export function renameDiffRequest(params: URLSearchParams): RenameDiffRequest | null {
62
+ const side = (path: string, hash: string): PrettyRequest | null => {
63
+ const extension = prettyExtension(path)
64
+ return extension !== null && RENAMABLE.has(extension) && FILE_HASH.test(hash) ? { path, hash, extension } : null
65
+ }
66
+ const base = side(params.get('path') ?? '', params.get('hash') ?? ''), other = side(params.get('otherPath') ?? '', params.get('otherHash') ?? '')
67
+ return base && other ? { base, other } : null
68
+ }
69
+
70
+ const workers = workerTurns({ what: 'rename diff', active: MAX_ACTIVE_DIFFS, waiting: MAX_WAITING_DIFFS, error: PrettyError,
71
+ busy: 'diff-busy', timeout: 'diff-timeout', failed: 'undiffable' })
72
+ const kept = new Map<string, Buffer>()
73
+ const pending = new Map<string, Promise<Buffer>>()
74
+
75
+ // Whether a worker's answer is one as rename-diff-worker.js gives it, its
76
+ // blocks taking the old side it answered to the new one asked of, whitespace
77
+ // changes shown and hidden: checked again here, apart from the worker, as an
78
+ // answer that is not would hide a change.
79
+ function answers(diff: unknown, original: string, after: string): diff is RenameDiff {
80
+ const { before, blocks, reason, reads, assumed, marks, ignoringWhitespace } = (diff ?? {}) as Partial<RenameDiff>
81
+ const strings = (list: unknown) => Array.isArray(list) && list.every(item => typeof item === 'string')
82
+ return typeof before === 'string' && (reason === null || typeof reason === 'string') && strings(reads) && strings(assumed)
83
+ && blocksHold(before, after, blocks, false) && marksFit(original, after, marks)
84
+ && blocksHold(before, after, ignoringWhitespace?.blocks, true) && marksFit(original, after, ignoringWhitespace?.marks)
85
+ }
86
+
87
+ // Whether marked blocks (rename-diff-worker.js) are blocks of the diff of the
88
+ // two files as they are: in order, apart, within both, each as many lines on
89
+ // either side.
90
+ function marksFit(before: string, after: string, marks: unknown): boolean {
91
+ if (!Array.isArray(marks)) return false
92
+ const [olds, news] = [textLines(before).length, textLines(after).length]
93
+ let i = 0, j = 0
94
+ for (const mark of marks as Partial<ChangeBlock>[]) {
95
+ const { a0, a1, b0, b1 } = mark ?? {}
96
+ if (![a0, a1, b0, b1].every(Number.isInteger)) return false
97
+ const [x0, x1, y0, y1] = [a0, a1, b0, b1] as [number, number, number, number]
98
+ if (x0 < i || y0 < j || x1 <= x0 || x1 - x0 !== y1 - y0 || x1 > olds || y1 > news) return false
99
+ i = x1
100
+ j = y1
101
+ }
102
+ return true
103
+ }
104
+
105
+ // The two sides diffed in a worker, its answer checked (answers).
106
+ function inWorker(before: string, after: string, { base, other }: RenameDiffRequest, deadline: number): Promise<RenameDiff> {
107
+ if (before.length + after.length > MAX_DIFF_CHARS) throw new PrettyError(413, 'diff-too-large')
108
+ return workers.run(new URL('./rename-diff-worker.js', import.meta.url), {
109
+ workerData: { before, after, extension: base.extension, otherExtension: other.extension }, execArgv: [],
110
+ resourceLimits: { maxOldGenerationSizeMb: 1024 },
111
+ }, answer => {
112
+ if (answers(answer, before, after)) return answer
113
+ console.warn('managed: a rename diff answered what does not take its old side to the new')
114
+ return null
115
+ }, deadline)
116
+ }
117
+
118
+ // `work` given until `deadline`: past it, answered 504 and left to finish on its own.
119
+ function byDeadline<T>(work: Promise<T>, deadline: number): Promise<T> {
120
+ let timer: ReturnType<typeof setTimeout> | undefined
121
+ const late = new Promise<never>((_, reject) => { timer = setTimeout(() => { reject(new PrettyError(504, 'diff-timeout')) }, deadline - Date.now()) })
122
+ return Promise.race([work, late]).finally(() => { clearTimeout(timer) })
123
+ }
124
+
125
+ // An answer as sent, naming the files asked about and the pretty-printed
126
+ // copies of them it was worked out from.
127
+ async function encoded(diff: RenameDiff, { base, other }: RenameDiffRequest, [before, after]: [string, string]): Promise<Buffer> {
128
+ const [prettyHash, otherPrettyHash] = await Promise.all([computeFileHash(before), computeFileHash(after)])
129
+ return encodeBrotli(Buffer.from(JSON.stringify({ ...diff, hash: base.hash, otherHash: other.hash, prettyHash, otherPrettyHash })))
130
+ }
131
+
132
+ // The answer for the two files a request names, Brotli-encoded, `texts`
133
+ // reading both sides pretty-printed (and so checking each is its source's):
134
+ // kept by their hashes where `keep`, readers asking for one meanwhile sharing
135
+ // it. A minute for it, its wait for a worker included.
136
+ export async function renameDiffOf(request: RenameDiffRequest, texts: () => Promise<[string, string]>, keep = true): Promise<OpenedBlob> {
137
+ return opened(await answerOf(request, texts, keep))
138
+ }
139
+
140
+ // Sides `verified` to be the files the request names (renamedPairs) are read
141
+ // only where no answer is kept or on its way; others are read first, as
142
+ // reading them checks they are.
143
+ async function answerOf(request: RenameDiffRequest, texts: () => Promise<[string, string]>, keep: boolean, verified = false): Promise<Buffer> {
144
+ // Sides not kept are formatted again for each diff (pretty-print.ts), so
145
+ // they are read in its turn: the files a Diff view asks for at once wait
146
+ // here rather than being refused by the formats running. Within its minute
147
+ // too, its turn not held past it by a version's files still downloading.
148
+ if (!keep) {
149
+ const deadline = Date.now() + DIFF_TIMEOUT_MS
150
+ let sides: [string, string] = ['', '']
151
+ const diff = await workers.inTurn(deadline, async () => {
152
+ sides = await byDeadline(texts(), deadline)
153
+ return inWorker(sides[0], sides[1], request, deadline)
154
+ })
155
+ return encoded(diff, request, sides)
156
+ }
157
+ // A file's type is part of how it is read: the same text as a script and as a module differ.
158
+ const key = `${request.base.hash}\0${request.base.extension}\0${request.other.hash}\0${request.other.extension}`
159
+ const held = () => {
160
+ const found = kept.get(key)
161
+ if (found) {
162
+ kept.delete(key)
163
+ kept.set(key, found)
164
+ }
165
+ return found ?? pending.get(key)
166
+ }
167
+ let answer = verified ? held() : undefined
168
+ if (!answer) {
169
+ const [before, after] = await texts()
170
+ answer = held()
171
+ if (!answer) {
172
+ const deadline = Date.now() + DIFF_TIMEOUT_MS
173
+ const job = workers.inTurn(deadline, () => inWorker(before, after, request, deadline)).then(diff => encoded(diff, request, [before, after])).finally(() => pending.delete(key))
174
+ pending.set(key, answer = job)
175
+ }
176
+ }
177
+ const body = await answer
178
+ kept.set(key, body)
179
+ if (kept.size > KEPT_DIFFS) kept.delete(kept.keys().next().value!)
180
+ return body
181
+ }
182
+
183
+ const decompress = promisify(brotliDecompress)
184
+
185
+ // What a minifier renames, by its path's extension.
186
+ const renamable = ({ extension }: PrettyRequest) => RENAMABLE.has(extension)
187
+
188
+ // One of a comparison's pairs of files (renamedPairs), its sides named as a
189
+ // request names them, with its answer as renameDiffOf sends it, or why it has
190
+ // none, as a PrettyError tells it.
191
+ export type RenamedLine = { path: string; hash: string; otherPath: string; otherHash: string } & (Partial<RenameDiff> | { error: string; status: number })
192
+
193
+ // The files that changed between a comparison's two sides, as its viewer
194
+ // pairs them (ui/view/bundle-comparison.js prepareComparison): at one path as
195
+ // the other side lays them out, or renamed within a package, as the bundles
196
+ // record their packages; every file there, those that can be formatted by
197
+ // their texts and the rest by their hashes. A file the viewer pairs otherwise
198
+ // (its files are its resources too) it asks about alone.
199
+ export function comparedFiles(sides: readonly [ComparedSide, ComparedSide]) {
200
+ const [olds, news] = sides.map(({ files, hashes }) => {
201
+ const texts = new Map(files.map(file => [file.path, file.text]))
202
+ return new Map<string, unknown>([...hashes].map(([path, hash]) => [path, texts.get(path) ?? { format: 'digest', digest: hash }]))
203
+ }) as [Map<string, unknown>, Map<string, unknown>]
204
+ const layout = treeLayout(olds.keys(), news.keys())
205
+ const packageDirs = layoutPackageDirs(sides[0].packageDirs, sides[1].packageDirs, layout)
206
+ return computeBundleDiff(olds, news, path => bundlePkgOf(path, { packageDir: packageDirs?.get(path) }), layout).files
207
+ }
208
+
209
+ // The pairs of JavaScript files minified on both sides that changed between a
210
+ // comparison's two sides, paired as its viewer pairs them (comparedFiles),
211
+ // each diffed as renameDiffOf diffs it, from both sides' copies, kept or
212
+ // made, as they are iterated: in path order, one after another, leaving a
213
+ // worker to the files a viewer asks for alone (a pair it reads otherwise, one
214
+ // it shows first).
215
+ export function renamedPairs([base, other]: readonly [ComparedSide, ComparedSide], keep = true): AsyncGenerator<RenamedLine> {
216
+ const formattable = ({ files }: ComparedSide) => new Map(files.map(file => [file.path, file]))
217
+ const [olds, news] = [formattable(base), formattable(other)]
218
+ const pairs = comparedFiles([base, other]).changed.flatMap(({ path, basePath = path }) => {
219
+ const [from, to] = [olds.get(basePath), news.get(path)]
220
+ return from && to && from.hash !== to.hash && [from, to].every(file => renamable(file) && needsPrettyPrint(file.path, file.text)) ? [[from, to] as const] : []
221
+ }).toSorted(([, a], [, b]) => pathOrder(a.path, b.path))
222
+ return (async function* () {
223
+ for (const [from, to] of pairs) {
224
+ const request = { base: { path: from.path, hash: from.hash, extension: from.extension }, other: { path: to.path, hash: to.hash, extension: to.extension } }
225
+ const named = { path: from.path, hash: from.hash, otherPath: to.path, otherHash: to.hash }
226
+ const copy = async (side: ComparedSide, { text, ...file }: typeof from) => prettyText(await side.kept(file) ?? await side.made(file, text))
227
+ let body
228
+ try { body = await answerOf(request, async () => [await copy(base, from), await copy(other, to)], keep, true) }
229
+ catch (err) {
230
+ if (!(err instanceof PrettyError)) throw err
231
+ yield { ...named, error: err.message, status: err.status }
232
+ continue
233
+ }
234
+ yield { ...JSON.parse((await decompress(body)).toString('utf8')) as Partial<RenameDiff>, ...named }
235
+ }
236
+ })()
237
+ }
@@ -0,0 +1,21 @@
1
+ const MAX_TEAM_PATH = 500
2
+
3
+ // Canonicalize only equivalent Git paths: '/' separates components and empty
4
+ // or '.' components do not change the directory. Reject ambiguous input rather
5
+ // than deleting characters from directory names used for authorization.
6
+ // `{ ok:false }` makes the handler 400; `{ path:null }` means the whole repo.
7
+ export function normalizeTeamPath(raw: unknown): { ok: true; path: string | null } | { ok: false } {
8
+ if (typeof raw !== 'string') return { ok: true, path: null }
9
+ // Spaces and backslashes can be literal parts of Git directory names.
10
+ // Neither trimming nor treating '\\' as a separator preserves that identity.
11
+ if (/\p{Cc}/u.test(raw) || raw.includes('\\') || raw !== raw.trim()) return { ok: false }
12
+ const segments: string[] = []
13
+ for (const seg of raw.split('/')) {
14
+ if (seg === '' || seg === '.') continue
15
+ if (seg === '..' || seg !== seg.trim()) return { ok: false }
16
+ segments.push(seg)
17
+ }
18
+ const path = segments.join('/')
19
+ if (path.length > MAX_TEAM_PATH) return { ok: false }
20
+ return { ok: true, path: path === '' ? null : path }
21
+ }
@@ -0,0 +1,32 @@
1
+ // SQLite deployments store report blobs beside the database. Recover location
2
+ // metadata before introducing directory-based team access. Schema and data move
3
+ // together so a missing/corrupt blob leaves the migration retryable after repair.
4
+ import { readFileSync } from 'node:fs'
5
+ import { join } from 'node:path'
6
+ import type { DatabaseSync } from 'node:sqlite'
7
+ import { reportRepoGithub } from '@preventive/report'
8
+ import { readManagedReport } from '../common/managed/report-content.ts'
9
+ import { normalizeTeamPath } from './repo-path.ts'
10
+ import { isBlobId } from './object-storage.ts'
11
+ import { sqliteTransaction } from './sql.ts'
12
+
13
+ export function migrateReportLocations(db: DatabaseSync, reportDir: string): void {
14
+ const columns = db.prepare('PRAGMA table_info(managed_report)').all() as { name: string }[]
15
+ if (columns.some((column) => column.name === 'repo_directory')) return
16
+ sqliteTransaction(db, 'BEGIN IMMEDIATE', () => {
17
+ db.exec("ALTER TABLE managed_report ADD COLUMN repo_directory TEXT NOT NULL DEFAULT ''")
18
+ const update = db.prepare('UPDATE managed_report SET repo_directory = ?, repo_embedded = ? WHERE id = ?')
19
+ const reports = db.prepare('SELECT id, filename FROM managed_report').all() as { id: string, filename: string }[]
20
+ for (const { id, filename } of reports) {
21
+ // Same opaque UUID boundary as the blob store; never splice arbitrary
22
+ // database text into a filesystem path during an upgrade.
23
+ if (!isBlobId(id)) throw new Error(`Invalid legacy report id: ${id}`)
24
+ const { data } = readManagedReport(readFileSync(join(reportDir, id), 'utf8'), filename)
25
+ if (data == null) throw new Error(`Cannot migrate location of unreadable report ${id}`)
26
+ const embedded = reportRepoGithub(data) != null
27
+ const directory = normalizeTeamPath(data.repo?.directory)
28
+ if (!directory.ok) throw new Error(`Cannot migrate invalid directory of report ${id}`)
29
+ update.run(directory.path ?? '', embedded ? 1 : 0, id)
30
+ }
31
+ })
32
+ }
@@ -0,0 +1,77 @@
1
+ // Whether a stored report may be switched to open on Confirmed (Manage →
2
+ // Reports), told of its content alone: where its pass leaves Confirmed rows of
3
+ // its own but it is no App view on its own, by the stricter rule App mode
4
+ // keeps (common/workspace-app.js confirmedDefaultOffered). A switched report's
5
+ // findings count as covered wherever Confirmed would hide them
6
+ // (common/finding-filters.js confirmedCoverage), both for the outcome a view
7
+ // opens on and for its team's App mode.
8
+ //
9
+ // Read as a report is uploaded, and kept (managed_report confirmed_offered):
10
+ // its bytes never change. One uploaded before the column is read as the
11
+ // reports page lists it, a bounded share of them each time, or as its switch
12
+ // is asked for.
13
+ import { backfillFindingIds, reportEntries } from '@preventive/report'
14
+ import { readManagedReport } from '../common/managed/report-content.ts'
15
+ import { managedReportConfirmedDefaultOffered } from '../common/managed/team-app.js'
16
+ import type { BlobStore } from './blob-store.ts'
17
+ import type { ManagedDb } from './db.ts'
18
+ import { eachOf } from './queue.ts'
19
+
20
+ // Of a report's parsed content, its findings' IDs backfilled first as a team's
21
+ // are (team-reports.ts), which it changes in place. A report whose rows cannot
22
+ // be read this way has no switch to offer.
23
+ export async function confirmedDefaultOffered(filename: string, data: unknown): Promise<boolean> {
24
+ try {
25
+ const findings = (reportEntries(data) ?? []).flatMap(entry => Array.isArray(entry) ? entry : [entry])
26
+ .filter((finding): finding is Record<string, unknown> => finding !== null && typeof finding === 'object' && !Array.isArray(finding))
27
+ await backfillFindingIds(findings)
28
+ return managedReportConfirmedDefaultOffered(filename, data)
29
+ } catch (error) {
30
+ console.warn('managed: reading a report for its opening failed:', error)
31
+ return false
32
+ }
33
+ }
34
+
35
+ // Of a stored report, read of its blob: null where its bytes cannot be read
36
+ // now, so a later read tries again.
37
+ async function readStored(store: BlobStore, report: { id: string; filename: string }): Promise<boolean | null> {
38
+ const bytes = await store.get(report.id).catch(() => null)
39
+ if (!bytes) return null
40
+ const { data } = readManagedReport(bytes.toString('utf8'), report.filename)
41
+ return data == null ? false : confirmedDefaultOffered(report.filename, data)
42
+ }
43
+
44
+ // The same, kept.
45
+ export async function readConfirmedOffered(db: ManagedDb, store: BlobStore, report: { id: string; filename: string }): Promise<boolean | null> {
46
+ const offered = await readStored(store, report)
47
+ if (offered !== null) await db.setReportsConfirmedOffered([{ id: report.id, offered }])
48
+ return offered
49
+ }
50
+
51
+ // At most this many bytes of reports not read yet are read for one listing,
52
+ // two at a time, and kept in one write; the rest wait for the next.
53
+ const LISTING_READ_BYTES = 64 * 1024 * 1024
54
+ const LISTING_READS_AT_ONCE = 2
55
+
56
+ // The listed reports, those not read for their opening yet read, as many as
57
+ // fit the bound: the first always, however large.
58
+ export async function withConfirmedOffered<T extends { id: string; filename: string; byteSize: number; confirmedOffered: boolean | null }>(
59
+ db: ManagedDb, store: BlobStore, reports: readonly T[]): Promise<T[]> {
60
+ let budget = LISTING_READ_BYTES
61
+ const unread = reports.filter(report => {
62
+ if (report.confirmedOffered !== null || budget <= 0) return false
63
+ budget -= report.byteSize
64
+ return true
65
+ })
66
+ if (unread.length === 0) return [...reports]
67
+ const read = new Map<string, boolean>()
68
+ await eachOf(unread, LISTING_READS_AT_ONCE, async report => {
69
+ const offered = await readStored(store, report).catch((error: unknown) => {
70
+ console.warn('managed: reading a report for its opening failed:', error)
71
+ return null
72
+ })
73
+ if (offered !== null) read.set(report.id, offered)
74
+ })
75
+ if (read.size > 0) await db.setReportsConfirmedOffered([...read].map(([id, offered]) => ({ id, offered })))
76
+ return reports.map(report => read.has(report.id) ? { ...report, confirmedOffered: read.get(report.id)! } : report)
77
+ }
@@ -0,0 +1,10 @@
1
+ // Large workspaces remain a single request. Bound both the stored input and
2
+ // the encoded response, independently of the per-upload size limit.
3
+ export const MAX_REPORT_QUERY_COUNT = 4096
4
+ export const MAX_REPORT_QUERY_BYTES = 1024 * 1024 * 1024
5
+
6
+ // The import catalog scans a bounded page, not the whole installation. A
7
+ // report larger than the byte target occupies a page by itself; upload limits
8
+ // still bound that single report and the cursor must always make progress.
9
+ export const FINDING_CATALOG_PAGE_COUNT = 128
10
+ export const FINDING_CATALOG_PAGE_BYTES = 32 * 1024 * 1024
@@ -0,0 +1,16 @@
1
+ import { MIMEType } from 'node:util'
2
+
3
+ // The metadata envelope is opt-in. Wildcards keep the legacy raw report;
4
+ // an explicit, acceptable application/json range requests the envelope.
5
+ export function acceptsReportMetadata(accept: string | undefined): boolean {
6
+ // Commas inside quoted media-type parameters do not separate ranges.
7
+ for (const range of accept?.match(/(?:[^",]|"(?:\\.|[^"\\])*")+/gu) ?? []) {
8
+ try {
9
+ const media = new MIMEType(range.trim())
10
+ if (media.essence !== 'application/json') continue
11
+ const quality = media.params.get('q') ?? '1'
12
+ if (/^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/u.test(quality) && Number(quality) > 0) return true
13
+ } catch { /* Ignore malformed media ranges. */ }
14
+ }
15
+ return false
16
+ }