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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +16 -78
  4. package/cli.js +6 -0
  5. package/client/dependency-paths.d.ts +3 -0
  6. package/client/dependency-paths.js +36 -0
  7. package/client/finding-link.js +305 -0
  8. package/client/linked-findings.d.ts +1 -0
  9. package/client/linked-findings.js +115 -0
  10. package/common/bundle-commit.d.ts +1 -0
  11. package/common/bundle-commit.js +4 -0
  12. package/common/bundle-compare-diff.d.ts +6 -0
  13. package/common/bundle-compare-diff.js +377 -0
  14. package/common/bundle-compare-inputs.d.ts +3 -0
  15. package/common/bundle-compare-inputs.js +141 -0
  16. package/common/bundle-compare-versions.js +172 -0
  17. package/common/bundle-comparison.d.ts +8 -0
  18. package/common/bundle-comparison.js +69 -0
  19. package/common/bundle-imports.js +20 -0
  20. package/common/bundle-metadata.d.ts +15 -0
  21. package/common/bundle-metadata.js +226 -0
  22. package/common/bundle-pkg-of.d.ts +1 -0
  23. package/common/bundle-pkg-of.js +90 -0
  24. package/common/bundle-reasons.d.ts +6 -0
  25. package/common/bundle-reasons.js +58 -0
  26. package/common/bundle-source-links.d.ts +6 -0
  27. package/common/bundle-source-links.js +216 -0
  28. package/common/bundle-sourcemap.d.ts +10 -0
  29. package/common/bundle-sourcemap.js +100 -0
  30. package/common/bundle-sources.d.ts +10 -0
  31. package/common/bundle-sources.js +374 -0
  32. package/common/bundle-stats.js +41 -0
  33. package/common/bundle-tabs.js +1 -0
  34. package/common/code-language.js +66 -0
  35. package/common/default-scan-models.ts +36 -0
  36. package/common/dependency-reviews.d.ts +18 -0
  37. package/common/dependency-reviews.js +64 -0
  38. package/common/finding-duplicates.js +63 -0
  39. package/common/finding-filters.js +313 -0
  40. package/common/finding-id.js +47 -0
  41. package/common/finding-repo.d.ts +5 -0
  42. package/common/finding-repo.js +67 -0
  43. package/common/github-issue-labels.d.ts +1 -0
  44. package/common/github-issue-labels.js +11 -0
  45. package/common/github-pr.ts +56 -0
  46. package/common/gzip.js +59 -0
  47. package/common/line-diff.d.ts +14 -0
  48. package/common/line-diff.js +181 -0
  49. package/common/linked-workspace-groups.js +63 -0
  50. package/common/managed/agent-tasks.ts +292 -0
  51. package/common/managed/comments.ts +43 -0
  52. package/common/managed/dependency-routes.js +25 -0
  53. package/common/managed/directory-packages.ts +28 -0
  54. package/common/managed/finding-detail.d.ts +5 -0
  55. package/common/managed/finding-detail.js +75 -0
  56. package/common/managed/finding-values.d.ts +2 -0
  57. package/common/managed/finding-values.js +138 -0
  58. package/common/managed/github-agents.ts +114 -0
  59. package/common/managed/github-logins.ts +49 -0
  60. package/common/managed/lite-name.d.ts +2 -0
  61. package/common/managed/lite-name.js +20 -0
  62. package/common/managed/npm-packages.d.ts +9 -0
  63. package/common/managed/npm-packages.js +63 -0
  64. package/common/managed/permissions.ts +31 -0
  65. package/common/managed/report-content.ts +72 -0
  66. package/common/managed/report-filter.ts +120 -0
  67. package/common/managed/repository-alias.ts +65 -0
  68. package/common/managed/review-view-routes.js +23 -0
  69. package/common/managed/risk-routes.js +30 -0
  70. package/common/managed/roles.ts +41 -0
  71. package/common/managed/routes.d.ts +2 -0
  72. package/common/managed/routes.js +385 -0
  73. package/common/managed/scan-models.ts +6 -0
  74. package/common/managed/stasis-config.ts +7 -0
  75. package/common/managed/team-app.d.ts +19 -0
  76. package/common/managed/team-app.js +129 -0
  77. package/common/managed/team-filters.js +26 -0
  78. package/common/managed/triage.ts +83 -0
  79. package/common/managed/upload-seal.ts +126 -0
  80. package/common/pretty-json.js +98 -0
  81. package/common/pretty-kinds.js +20 -0
  82. package/common/pretty-print.d.ts +6 -0
  83. package/common/pretty-print.js +36 -0
  84. package/common/pretty-sourcemap.js +70 -0
  85. package/common/repo-commit.d.ts +4 -0
  86. package/common/repo-commit.js +30 -0
  87. package/common/revalidation-conflicts.js +48 -0
  88. package/common/revalidation-input-groups.js +56 -0
  89. package/common/save-error-reason.ts +20 -7
  90. package/common/scan-server.ts +13 -0
  91. package/common/security-links.d.ts +5 -0
  92. package/common/security-links.js +33 -0
  93. package/common/server-info.ts +46 -0
  94. package/common/sourcemap-listing.js +78 -0
  95. package/common/sourcemap-mappings.js +136 -0
  96. package/common/sourcemap-unlist.js +85 -0
  97. package/common/stasis-files.d.ts +5 -0
  98. package/common/stasis-files.js +20 -0
  99. package/common/stasis-tgz.d.ts +6 -0
  100. package/common/stasis-tgz.js +27 -0
  101. package/common/utf8.d.ts +3 -0
  102. package/common/utf8.js +45 -0
  103. package/common/whitespace-insensitive.js +19 -0
  104. package/common/workspace-app.js +91 -0
  105. package/common/workspace-groups.js +176 -0
  106. package/out/activity.js +2 -0
  107. package/out/brotli-fallback.js +3 -3
  108. package/out/chunk-2XUEZHIP.js +28 -0
  109. package/out/chunk-55YIWY3H.js +5 -0
  110. package/out/chunk-563V5VVT.js +266 -0
  111. package/out/chunk-5AVGKFMR.js +1 -0
  112. package/out/chunk-5EAVJAD2.js +3 -0
  113. package/out/chunk-5M2X3QPK.js +6 -0
  114. package/out/chunk-5QWPKTCE.js +40 -0
  115. package/out/chunk-5UJHJWFU.js +4 -0
  116. package/out/chunk-6CCSTJWB.js +1 -0
  117. package/out/chunk-6VOB5WXX.js +2 -0
  118. package/out/chunk-6WMQVUT2.js +3 -0
  119. package/out/chunk-6Y6PZ2BU.js +9 -0
  120. package/out/chunk-74JZTGTO.js +11 -0
  121. package/out/chunk-7BKKYVWR.js +7 -0
  122. package/out/chunk-7C7DWL7I.js +1 -0
  123. package/out/chunk-7HP2VYIC.js +2 -0
  124. package/out/chunk-7YFJUT2P.js +1 -0
  125. package/out/chunk-7YO4QV5P.js +1 -0
  126. package/out/chunk-A4BBBHQU.js +1 -0
  127. package/out/chunk-B64CTMVU.js +4 -0
  128. package/out/chunk-BEKYZCPX.js +14 -0
  129. package/out/chunk-C4Z6ZBXV.js +10 -0
  130. package/out/chunk-CU3FPB3P.js +1 -0
  131. package/out/chunk-DEVAORP2.js +1 -0
  132. package/out/chunk-DOYTKRIR.js +53 -0
  133. package/out/chunk-DUASGS2O.js +8 -0
  134. package/out/chunk-EEJA7JBI.js +13 -0
  135. package/out/chunk-FSU2PLJL.js +1 -0
  136. package/out/chunk-GO7FT4OD.js +1 -0
  137. package/out/chunk-GX5UXWT4.js +1 -0
  138. package/out/chunk-H4FEC57K.js +1 -0
  139. package/out/chunk-ITUKKCCK.js +10 -0
  140. package/out/chunk-IYPY47MC.js +1 -0
  141. package/out/chunk-K4XJHM2T.js +1 -0
  142. package/out/chunk-LBD3M3J6.js +1 -0
  143. package/out/chunk-LVSLM7HB.js +1 -0
  144. package/out/chunk-LVW7WWV4.js +1 -0
  145. package/out/chunk-N57OWFKY.js +15 -0
  146. package/out/chunk-NRPC74AM.js +1 -0
  147. package/out/chunk-OAWQNDAO.js +3 -0
  148. package/out/chunk-OOJM4CTU.js +1 -0
  149. package/out/chunk-PEE47ANR.js +1 -0
  150. package/out/chunk-PKLVXUEI.js +11 -0
  151. package/out/chunk-PLGH63UC.js +2 -0
  152. package/out/chunk-PNHBZGDD.js +1 -0
  153. package/out/chunk-PTFYDJUP.js +1 -0
  154. package/out/chunk-PWFUOLZK.js +17 -0
  155. package/out/chunk-PXK7EU4V.js +1 -0
  156. package/out/chunk-QD3IBSF4.js +7 -0
  157. package/out/chunk-QI66YA4F.js +1 -0
  158. package/out/chunk-QRKFPLA4.js +80 -0
  159. package/out/chunk-R3NZFXVR.js +1 -0
  160. package/out/chunk-R5O6FAW4.js +2 -0
  161. package/out/chunk-RPNO56H2.js +1 -0
  162. package/out/chunk-SSPDMA6D.js +1 -0
  163. package/out/chunk-SZWPYLPC.js +1 -0
  164. package/out/chunk-TUII34K2.js +1 -0
  165. package/out/chunk-UJP4PQJA.js +1 -0
  166. package/out/chunk-UJSJMXEG.js +1 -0
  167. package/out/chunk-UR4WYMIP.js +1 -0
  168. package/out/chunk-VHEXSGGP.js +1 -0
  169. package/out/chunk-VYYUMYVW.js +9 -0
  170. package/out/chunk-WCDYSIKG.js +1 -0
  171. package/out/chunk-WFBVS4QI.js +1 -0
  172. package/out/chunk-XM4RLC4A.js +2 -0
  173. package/out/chunk-ZQHLECTI.js +1 -0
  174. package/out/client-managed-import.js +4 -0
  175. package/out/client-managed.js +37 -0
  176. package/out/client-sync.js +11 -17
  177. package/out/compare.js +26 -0
  178. package/out/dialogs.js +40 -0
  179. package/out/github-issue-authorized.html +3 -0
  180. package/out/github-issue-authorized.js +1 -0
  181. package/out/graph.js +19 -4
  182. package/out/index.html +104 -24
  183. package/out/prism.js +14 -10
  184. package/out/scan.js +2 -0
  185. package/out/stasis.svg +20 -0
  186. package/out/terminal.js +367 -39
  187. package/out/view.css +1 -1
  188. package/out/view.js +19 -147
  189. package/package.json +409 -64
  190. package/risk/actions/findings.js +161 -0
  191. package/risk/actions/resolve.js +287 -0
  192. package/risk/actions/scripts/commands.js +182 -0
  193. package/risk/actions/scripts/grade.js +113 -0
  194. package/risk/actions/scripts/packages.js +123 -0
  195. package/risk/actions/scripts/shell.js +169 -0
  196. package/risk/actions/uses.js +94 -0
  197. package/risk/actions/workflow.js +183 -0
  198. package/risk/files/characters.js +354 -0
  199. package/risk/files/hosts.js +206 -0
  200. package/risk/files/readability.js +185 -0
  201. package/risk/files/runs-code.js +568 -0
  202. package/risk/files/script.js +410 -0
  203. package/risk/files/source-map-link.js +43 -0
  204. package/risk/files/stamps.js +47 -0
  205. package/risk/index.d.ts +294 -0
  206. package/risk/index.js +12 -0
  207. package/risk/npm/assess.js +285 -0
  208. package/risk/npm/combined.js +68 -0
  209. package/risk/npm/compare.js +236 -0
  210. package/risk/npm/dependencies.js +172 -0
  211. package/risk/npm/diff.js +79 -0
  212. package/risk/npm/downloads.js +84 -0
  213. package/risk/npm/files.js +445 -0
  214. package/risk/npm/held.js +67 -0
  215. package/risk/npm/install-scripts.js +34 -0
  216. package/risk/npm/malware.js +38 -0
  217. package/risk/npm/manifest.js +65 -0
  218. package/risk/npm/new-dependency.js +60 -0
  219. package/risk/npm/old-version.js +108 -0
  220. package/risk/npm/registry.js +393 -0
  221. package/risk/npm/release.js +85 -0
  222. package/risk/npm/score.js +59 -0
  223. package/risk/npm/specs.js +124 -0
  224. package/risk/npm/tarball.js +169 -0
  225. package/server-common/database-config.ts +16 -0
  226. package/server-common/initialize.ts +18 -0
  227. package/server-common/npm-advisories.ts +101 -0
  228. package/{server → server-common}/origin.ts +5 -5
  229. package/server-common/reap.ts +48 -0
  230. package/server-common/scan-config.ts +19 -0
  231. package/server-common/standalone.ts +29 -0
  232. package/server-common/storage-crypto.ts +182 -0
  233. package/server-common/storage-log.ts +38 -0
  234. package/server-common/vercel-blob.ts +103 -0
  235. package/server-e2e/app.ts +487 -0
  236. package/{server → server-e2e}/bus-receiver.ts +2 -1
  237. package/{server → server-e2e}/cli.js +9 -4
  238. package/{server → server-e2e}/config.ts +50 -42
  239. package/{server → server-e2e}/db-neon.ts +2 -2
  240. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  241. package/{server → server-e2e}/db-stmt.ts +2 -2
  242. package/{server → server-e2e}/db.ts +7 -7
  243. package/{server → server-e2e}/http.ts +44 -13
  244. package/{server → server-e2e}/hub.ts +40 -9
  245. package/server-e2e/index.ts +17 -0
  246. package/server-e2e/lifecycle.ts +95 -0
  247. package/{server → server-e2e}/neon-driver.ts +2 -2
  248. package/{server → server-e2e}/npm-proxy.ts +12 -145
  249. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  250. package/{server → server-e2e}/objstore/blob.ts +1 -1
  251. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  252. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  253. package/{server → server-e2e}/objstore/init.ts +19 -27
  254. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  255. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  256. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  257. package/{server → server-e2e}/objstore/rest.ts +3 -3
  258. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  259. package/{server → server-e2e}/objstore/store.ts +7 -7
  260. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  261. package/{server → server-e2e}/pubsub.ts +12 -9
  262. package/{server → server-e2e}/sign.ts +4 -4
  263. package/{server → server-e2e}/sse-server.ts +60 -33
  264. package/{server → server-e2e}/static.ts +18 -17
  265. package/{server → server-e2e}/sync-handlers.ts +64 -30
  266. package/{server → server-e2e}/ws-server.ts +20 -9
  267. package/server-managed/activity.ts +269 -0
  268. package/server-managed/agent-merges.ts +109 -0
  269. package/server-managed/app-agents.ts +23 -0
  270. package/server-managed/avatar-store.ts +13 -0
  271. package/server-managed/blob-store.ts +26 -0
  272. package/server-managed/brotli.ts +10 -0
  273. package/server-managed/bundle-advisories.ts +79 -0
  274. package/server-managed/bundle-advisory-inventory.ts +85 -0
  275. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  276. package/server-managed/bundle-build-diagnostics.js +23 -0
  277. package/server-managed/bundle-build-leases.ts +41 -0
  278. package/server-managed/bundle-build-worker.js +380 -0
  279. package/server-managed/bundle-build.ts +326 -0
  280. package/server-managed/bundle-cache.ts +261 -0
  281. package/server-managed/bundle-catalog.ts +29 -0
  282. package/server-managed/bundle-commits.ts +133 -0
  283. package/server-managed/bundle-dependency-reviews.ts +91 -0
  284. package/server-managed/bundle-store.ts +24 -0
  285. package/server-managed/bundle-summary-cache.ts +139 -0
  286. package/server-managed/bundle-validation.ts +33 -0
  287. package/server-managed/bundle.ts +151 -0
  288. package/server-managed/cache-storage.ts +20 -0
  289. package/server-managed/cli.js +21 -0
  290. package/server-managed/combined.ts +43 -0
  291. package/server-managed/comments.ts +138 -0
  292. package/server-managed/commit-coauthors.ts +105 -0
  293. package/server-managed/commit-lockfiles.ts +78 -0
  294. package/server-managed/comparison.ts +51 -0
  295. package/server-managed/config.ts +163 -0
  296. package/server-managed/content-access.ts +15 -0
  297. package/server-managed/crypto.ts +25 -0
  298. package/server-managed/db-methods.ts +1915 -0
  299. package/server-managed/db-neon.ts +398 -0
  300. package/server-managed/db-schema.ts +263 -0
  301. package/server-managed/db-table-names.ts +22 -0
  302. package/server-managed/db.ts +149 -0
  303. package/server-managed/dependabot-access.ts +61 -0
  304. package/server-managed/dependabot-alerts.ts +180 -0
  305. package/server-managed/dependency-review-comments.ts +158 -0
  306. package/server-managed/dependency-reviews.ts +369 -0
  307. package/server-managed/github-accounts.ts +59 -0
  308. package/server-managed/github-actions.ts +71 -0
  309. package/server-managed/github-app.ts +347 -0
  310. package/server-managed/github-errors.ts +92 -0
  311. package/server-managed/github-graphql.ts +42 -0
  312. package/server-managed/github-issue-links.ts +264 -0
  313. package/server-managed/github-issue-oauth.ts +30 -0
  314. package/server-managed/github-issues.ts +157 -0
  315. package/server-managed/github-link-oauth.ts +56 -0
  316. package/server-managed/github-links.ts +204 -0
  317. package/server-managed/github-metadata.ts +213 -0
  318. package/server-managed/github-oauth.ts +264 -0
  319. package/server-managed/github-pulls.ts +257 -0
  320. package/server-managed/github-requests.ts +181 -0
  321. package/server-managed/github-users.ts +30 -0
  322. package/server-managed/github-values.ts +26 -0
  323. package/server-managed/history-windows.ts +172 -0
  324. package/server-managed/http-response.ts +76 -0
  325. package/server-managed/http.ts +6327 -0
  326. package/server-managed/import-triage.ts +51 -0
  327. package/server-managed/index.ts +204 -0
  328. package/server-managed/kept-briefly.ts +37 -0
  329. package/server-managed/kept.ts +28 -0
  330. package/server-managed/link-reports.ts +149 -0
  331. package/server-managed/listed-activity.ts +39 -0
  332. package/server-managed/locked-packages.ts +234 -0
  333. package/server-managed/lockfile-scope.ts +58 -0
  334. package/server-managed/lru.ts +30 -0
  335. package/server-managed/managed-issues.ts +92 -0
  336. package/server-managed/management-catalog.ts +45 -0
  337. package/server-managed/management.ts +116 -0
  338. package/server-managed/npm-delta-worker.js +142 -0
  339. package/server-managed/npm-delta.ts +277 -0
  340. package/server-managed/npm-insights.ts +455 -0
  341. package/server-managed/npm-kept.ts +265 -0
  342. package/server-managed/npm-loads.ts +259 -0
  343. package/server-managed/npm-manifest.ts +117 -0
  344. package/server-managed/npm-packages.ts +469 -0
  345. package/server-managed/npm-patch-paths.ts +86 -0
  346. package/server-managed/npm-patch.ts +455 -0
  347. package/server-managed/npm-provenance.ts +127 -0
  348. package/server-managed/npm-risk.ts +287 -0
  349. package/server-managed/object-storage-disk.ts +147 -0
  350. package/server-managed/object-storage-vercel.ts +71 -0
  351. package/server-managed/object-storage.ts +82 -0
  352. package/server-managed/package-entry-points.ts +127 -0
  353. package/server-managed/pretty-copies.ts +22 -0
  354. package/server-managed/pretty-format.d.ts +3 -0
  355. package/server-managed/pretty-format.js +13 -0
  356. package/server-managed/pretty-print.ts +442 -0
  357. package/server-managed/public-workspace.ts +243 -0
  358. package/server-managed/pull-comment-reviews.ts +161 -0
  359. package/server-managed/pull-dependencies.ts +370 -0
  360. package/server-managed/pull-dependency-reviews.ts +407 -0
  361. package/server-managed/pull-reviews.ts +202 -0
  362. package/server-managed/queue.ts +54 -0
  363. package/server-managed/release-commits.ts +85 -0
  364. package/server-managed/rename-diff-worker.js +30 -0
  365. package/server-managed/rename-diff.ts +237 -0
  366. package/server-managed/repo-path.ts +21 -0
  367. package/server-managed/report-migration.ts +32 -0
  368. package/server-managed/report-opening.ts +77 -0
  369. package/server-managed/report-query.ts +10 -0
  370. package/server-managed/report-response.ts +16 -0
  371. package/server-managed/report-sources.ts +185 -0
  372. package/server-managed/report-store.ts +77 -0
  373. package/server-managed/repository-actions.ts +220 -0
  374. package/server-managed/repository-agents.ts +422 -0
  375. package/server-managed/repository-aliases.ts +119 -0
  376. package/server-managed/repository-browser.ts +361 -0
  377. package/server-managed/repository-changes.ts +280 -0
  378. package/server-managed/repository-code.ts +222 -0
  379. package/server-managed/repository-dependency-reviews.ts +182 -0
  380. package/server-managed/repository-discovery.ts +83 -0
  381. package/server-managed/repository-history.ts +428 -0
  382. package/server-managed/repository-issues.ts +293 -0
  383. package/server-managed/repository-policy.ts +27 -0
  384. package/server-managed/repository-pulls.ts +207 -0
  385. package/server-managed/repository-pulse.ts +477 -0
  386. package/server-managed/repository-risk-assess.ts +108 -0
  387. package/server-managed/repository-risk-audit.ts +78 -0
  388. package/server-managed/repository-risk-caches.ts +37 -0
  389. package/server-managed/repository-risk-read.ts +260 -0
  390. package/server-managed/repository-risk-stasis.ts +61 -0
  391. package/server-managed/repository-risk-turn.ts +97 -0
  392. package/server-managed/repository-risk.ts +516 -0
  393. package/server-managed/repository-squashes.ts +160 -0
  394. package/server-managed/repository-stamp.ts +41 -0
  395. package/server-managed/request-timing.ts +63 -0
  396. package/server-managed/reviewed-dependencies.ts +170 -0
  397. package/server-managed/revisions.ts +35 -0
  398. package/server-managed/scan-downloads.ts +121 -0
  399. package/server-managed/session.ts +132 -0
  400. package/server-managed/slugs.ts +38 -0
  401. package/server-managed/solidity-entry-points.ts +71 -0
  402. package/server-managed/sql-postgres.ts +34 -0
  403. package/server-managed/sql.ts +107 -0
  404. package/server-managed/stasis-config.ts +147 -0
  405. package/server-managed/stasis-dependencies.ts +221 -0
  406. package/server-managed/static.ts +28 -0
  407. package/server-managed/storage-command.ts +16 -0
  408. package/server-managed/storage-db.ts +183 -0
  409. package/server-managed/storage-encryption.ts +288 -0
  410. package/server-managed/storage-maintenance.ts +259 -0
  411. package/server-managed/storage-payload.ts +121 -0
  412. package/server-managed/storage-stores.ts +91 -0
  413. package/server-managed/storage.ts +82 -0
  414. package/server-managed/team-app-summaries.ts +56 -0
  415. package/server-managed/team-app.ts +156 -0
  416. package/server-managed/team-catalog.ts +7 -0
  417. package/server-managed/team-feed.ts +180 -0
  418. package/server-managed/team-npm-scopes.ts +103 -0
  419. package/server-managed/team-reports.ts +368 -0
  420. package/server-managed/triage-response.ts +16 -0
  421. package/server-managed/type-only-proof.js +161 -0
  422. package/server-managed/type-only-worker.js +31 -0
  423. package/server-managed/type-only.ts +135 -0
  424. package/server-managed/uploads.ts +106 -0
  425. package/server-managed/upstream-cache.ts +256 -0
  426. package/server-managed/view-as.ts +58 -0
  427. package/server-managed/worker-turns.ts +76 -0
  428. package/server-managed/workspace-shares.ts +170 -0
  429. package/server.ts +70 -0
  430. package/strip-types-loader.js +13 -10
  431. package/server/index.ts +0 -480
  432. package/server/lifecycle.ts +0 -208
  433. /package/{LICENSE → LICENSE-MIT} +0 -0
  434. /package/{server → server-e2e}/auth.ts +0 -0
  435. /package/{server → server-e2e}/config.example.json +0 -0
  436. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  437. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  438. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  439. /package/{server → server-e2e}/peer.ts +0 -0
  440. /package/{server → server-e2e}/sse-session.ts +0 -0
  441. /package/{server → server-e2e}/util.ts +0 -0
  442. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,33 @@
1
+ // Links as stampSecurityGroups reads them, shared by the managed server's
2
+ // permission filter and the view's security lens. A star per link is enough
3
+ // for transitive propagation, without a quadratic expansion for large links.
4
+ // `add` extends the lookup while a stamp is running: rows the finding index
5
+ // returns can carry links of their own.
6
+ export function securityLinks(links = []) {
7
+ const edges = new Map()
8
+ const connect = (a, b) => {
9
+ if (!edges.has(a)) edges.set(a, new Set())
10
+ edges.get(a).add(b)
11
+ }
12
+ const add = (ids) => {
13
+ for (const id of ids.slice(1)) { connect(ids[0], id); connect(id, ids[0]) }
14
+ }
15
+ for (const ids of links) add(ids)
16
+ return { add, linkedIds: (id) => edges.get(id) ?? [] }
17
+ }
18
+
19
+ // An App finding can name the source findings it revalidated only by ID, in
20
+ // another row or report. The App view counts those as represented by it, so
21
+ // they are one issue for security too: hiding one side alone would leave the
22
+ // App answer to a hidden security finding, or a source row without its App row.
23
+ // Only App findings: the view ignores inputs on any other finding
24
+ // (finding-filters.js confirmedCoverage, revalidation-input-groups.js).
25
+ export function revalidationLinks(findings) {
26
+ const links = []
27
+ for (const finding of findings) {
28
+ const inputs = finding?.revalidateInputs
29
+ if (finding?.isApp !== true || typeof finding.id !== 'string' || !Array.isArray(inputs)) continue
30
+ links.push([finding.id, ...inputs.filter((id) => typeof id === 'string' && id !== '')])
31
+ }
32
+ return links
33
+ }
@@ -0,0 +1,46 @@
1
+ // The sync-protocol mode a server advertises — shared by the server (which
2
+ // emits it) and the client (which parses + caches it) so a change to the
3
+ // shape surfaces as a compile error on BOTH sides, the same single-source
4
+ // discipline as ./save-error-reason.ts.
5
+ //
6
+ // Delivered to the client as the first `server-info` frame on a sync
7
+ // connection (the WS plane and the SSE+POST fallback share one send path).
8
+ // A client uses it to detect whether a deployment speaks the end-to-end
9
+ // (`e2e`, zero-knowledge) protocol, the trusted `managed` protocol, or both.
10
+ // Combined discovery modes put the default protocol first.
11
+
12
+ export type ServerMode = 'e2e' | 'managed'
13
+
14
+ // Managed-mode entry points the server advertises; null for an e2e server.
15
+ export interface ManagedServerInfo {
16
+ loginPath: string
17
+ cookieName: string
18
+ uploadChunkBytes?: number
19
+ uploadMaxBytes?: { reports: number; bundles: number }
20
+ allowShare?: boolean
21
+ }
22
+
23
+ // GET /api/auth/session's answer. A managed server's GET /api/config also
24
+ // carries it as `session`, null when signed out, so a client can skip asking.
25
+ export interface ManagedSessionInfo {
26
+ user: { id: string; login: string; name: string | null; role: string }
27
+ csrfToken: string
28
+ viewer?: { id: string; login: string; name: string | null }
29
+ // Where the user publishes dependency reviews to some team: an npm
30
+ // version's Review tab is theirs (server-managed/dependency-reviews.ts).
31
+ dependencyReview?: true
32
+ }
33
+
34
+ // The `server-info` frame payload (the `type` discriminant is added at the
35
+ // send site). `managed` is null on e2e-only deployments.
36
+ export interface ServerInfo {
37
+ mode: ServerMode | 'managed+e2e' | 'e2e+managed'
38
+ managed: ManagedServerInfo | null
39
+ deepviewScanServer?: string
40
+ githubNewIssueLabels?: string
41
+ }
42
+
43
+ // The mode-probe route. A client GETs this to learn a server's protocol up
44
+ // front — a managed server has no WS plane to carry the connect frame — and
45
+ // the response body is the same `ServerInfo` shape emitted as that frame.
46
+ export const CONFIG_PATH = '/api/config'
@@ -0,0 +1,78 @@
1
+ // How a source map is listed (pretty-sourcemap.js): its values alone, each
2
+ // key in order, its value as JSON on the key's row, but a list's items each on
3
+ // a row of its own below it, sourcesContent's texts line by line, mappings a
4
+ // line of the generated file to a row, and what follows the JSON (a line end)
5
+ // as JSON on the last row. A segment is its values as the format writes them,
6
+ // from the one before (sourcemap-mappings.js mappingsDeltas), so that a line
7
+ // added above moves none of the rows below.
8
+ import { UNSEEN } from '../risk/files/characters.js'
9
+ import { COPY_LIMIT } from './pretty-json.js'
10
+ import { decodeMappings, encodeMappings, mappingsDeltas } from './sourcemap-mappings.js'
11
+
12
+ // A line of a text written as JSON (`┊`) where it holds a character that
13
+ // shows as another or none (risk/files/characters.js UNSEEN), so that a
14
+ // listing never leaves one to the viewer.
15
+ const UNSEEN_ALL = new RegExp(UNSEEN.source, 'gu')
16
+ function escapeUnseen(char) {
17
+ const point = char.codePointAt(0)
18
+ const units = point > 0xFFFF ? [Math.floor((point - 0x10000) / 0x400) + 0xD800, ((point - 0x10000) % 0x400) + 0xDC00] : [point]
19
+ return units.map(unit => `\\u${unit.toString(16).padStart(4, '0')}`).join('')
20
+ }
21
+ // A JSON value as JSON.stringify writes it, but for its UNSEEN characters
22
+ // escaped: JSON.parse reads it back to the same value.
23
+ export const literal = value => JSON.stringify(value).replaceAll(UNSEEN_ALL, escapeUnseen)
24
+
25
+ // What opens a map's mappings decoded, on its key's row; `}` closes them.
26
+ export const MAPPINGS_OPEN = '{'
27
+
28
+ // A map's mappings as lines of segments, or null where they are shown as
29
+ // written: `sources` (or `names`, where given) no list, mappings the format
30
+ // doesn't allow (decodeMappings), or written otherwise than in the fewest
31
+ // digits, which rows read back wouldn't be.
32
+ function decoded({ mappings, sources, names }) {
33
+ if (typeof mappings !== 'string' || !Array.isArray(sources) || !(names === undefined || Array.isArray(names))) return null
34
+ let lines
35
+ try {
36
+ lines = decodeMappings(mappings, sources.length, names?.length ?? 0)
37
+ } catch {
38
+ return null
39
+ }
40
+ return encodeMappings(lines) === mappings ? lines : null
41
+ }
42
+
43
+ // Whether a value is listed an item to a row: a list of values each of which
44
+ // is null or holds to `each`.
45
+ const listOf = (value, each) => Array.isArray(value) && value.length > 0 && value.every(item => item === null || each(item))
46
+
47
+ // The listing of a map JSON.parse made (`value`), and what followed its JSON
48
+ // in the text (`trailing`, blanks). Throws a RangeError past COPY_LIMIT.
49
+ export function sourcemapListing(value, trailing = '') {
50
+ const lines = [], mappings = decoded(value)
51
+ let length = 0
52
+ const push = line => {
53
+ if ((length += line.length + 1) > COPY_LIMIT) throw new RangeError(`Its listing would run past ${COPY_LIMIT.toLocaleString('en')} characters.`)
54
+ lines.push(line)
55
+ }
56
+ for (const key of Object.keys(value)) {
57
+ const head = `${literal(key)}: `, item = value[key]
58
+ if (key === 'mappings' && mappings) {
59
+ push(`${head}${MAPPINGS_OPEN}`)
60
+ for (const line of mappingsDeltas(mappings)) push(line.length === 0 ? '' : ` ${line.map(values => values.join(' ')).join(', ')}`)
61
+ push('}')
62
+ } else if (key === 'sourcesContent' && listOf(item, text => typeof text === 'string')) {
63
+ push(`${head}[`)
64
+ item.forEach((text, i) => {
65
+ if (text === null) return push(' null')
66
+ push(Array.isArray(value.sources) && i < value.sources.length ? ` ┌ ${literal(value.sources[i])}` : ' ┌')
67
+ for (const line of text.split('\n')) push(UNSEEN.test(line) ? ` ┊ ${literal(line)}` : line === '' ? ' │' : ` │ ${line}`)
68
+ })
69
+ push(']')
70
+ } else if (listOf(item, each => typeof each !== 'object')) {
71
+ push(`${head}[`)
72
+ for (const each of item) push(` ${literal(each)}`)
73
+ push(']')
74
+ } else push(`${head}${literal(item)}`)
75
+ }
76
+ if (trailing !== '') push(literal(trailing))
77
+ return `${lines.join('\n')}\n`
78
+ }
@@ -0,0 +1,136 @@
1
+ // A source map's `mappings` read and written by the format's rules
2
+ // (ECMA-426): a line of segments to each line of the generated file, `;`
3
+ // between lines and `,` between segments, each segment one, four or five
4
+ // base64 VLQ values. The first is a column of the generated line, from the
5
+ // one before on the line; the others are an index into `sources`, a line and
6
+ // a column of that source, and an index into `names`, each from the segment
7
+ // before, whatever its line. Read strictly: whatever the format doesn't allow
8
+ // throws, so a listing (pretty-sourcemap.js) shows mappings as they are or
9
+ // not at all.
10
+
11
+ const DIGITS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
12
+ const DIGIT_OF = new Int8Array(128).fill(-1)
13
+ for (let i = 0; i < DIGITS.length; i++) DIGIT_OF[DIGITS.codePointAt(i)] = i
14
+ // Values are 32-bit, as the format has them: no more than seven digits.
15
+ const LIMIT = 2 ** 31
16
+ const COMMA = 44, SEMICOLON = 59
17
+
18
+ export class MappingsError extends Error {
19
+ constructor(message) {
20
+ super(message)
21
+ this.name = 'MappingsError'
22
+ }
23
+ }
24
+
25
+ // `mappings` as `[line][segment]`, a segment `[column]` (mapped from no
26
+ // source) or `[column, source, line, column]`, with `name` after those where
27
+ // it has one, every value absolute and counted from zero. Throws a
28
+ // MappingsError for any character not a base64 digit or separator, a value
29
+ // cut short or past 32 bits, a segment of two, three or more than five
30
+ // values or none (`,,`, a `,` before a `;`), or one whose column, source,
31
+ // line or name falls outside zero, `sources` (`sourcesCount`) and `names`
32
+ // (`namesCount`).
33
+ export function decodeMappings(mappings, sourcesCount, namesCount) {
34
+ const lines = []
35
+ let line = []
36
+ // The values so far: each a segment's, from the one before.
37
+ let column = 0, name = 0, source = 0, sourceColumn = 0, sourceLine = 0
38
+ let fields = [], shift = 0, value = 0
39
+ const end = (separator, at) => {
40
+ if (shift !== 0) throw new MappingsError(`A value is cut short before ${at}.`)
41
+ if (fields.length === 0) {
42
+ if (separator === COMMA || line.length > 0) throw new MappingsError(`An empty segment at ${at}.`)
43
+ return
44
+ }
45
+ if (fields.length !== 1 && fields.length !== 4 && fields.length !== 5) throw new MappingsError(`A segment of ${fields.length} values before ${at}.`)
46
+ column += fields[0]
47
+ if (column < 0) throw new MappingsError(`A segment before ${at} is at a column before the line's first.`)
48
+ const segment = [column]
49
+ if (fields.length >= 4) {
50
+ source += fields[1]
51
+ sourceLine += fields[2]
52
+ sourceColumn += fields[3]
53
+ if (source < 0 || source >= sourcesCount) throw new MappingsError(`A segment before ${at} names source ${source}, of ${sourcesCount}.`)
54
+ if (sourceLine < 0 || sourceColumn < 0) throw new MappingsError(`A segment before ${at} maps from before its source's first line or column.`)
55
+ segment.push(source, sourceLine, sourceColumn)
56
+ if (fields.length === 5) {
57
+ name += fields[4]
58
+ if (name < 0 || name >= namesCount) throw new MappingsError(`A segment before ${at} names name ${name}, of ${namesCount}.`)
59
+ segment.push(name)
60
+ }
61
+ }
62
+ line.push(segment)
63
+ fields = []
64
+ }
65
+ for (let i = 0; i < mappings.length; i++) {
66
+ const code = mappings.codePointAt(i)
67
+ if (code === COMMA || code === SEMICOLON) {
68
+ end(code, i)
69
+ if (code === SEMICOLON) {
70
+ lines.push(line)
71
+ line = []
72
+ column = 0
73
+ }
74
+ continue
75
+ }
76
+ const digit = DIGIT_OF[code] ?? -1
77
+ if (digit < 0) throw new MappingsError(`${JSON.stringify(mappings[i])} at ${i} is no base64 digit.`)
78
+ value += (digit & 31) * 2 ** shift
79
+ shift += 5
80
+ if (digit & 32) {
81
+ if (shift >= 35) throw new MappingsError(`A value past 32 bits at ${i}.`)
82
+ continue
83
+ }
84
+ const magnitude = Math.floor(value / 2)
85
+ if (magnitude >= LIMIT) throw new MappingsError(`A value past 32 bits at ${i}.`)
86
+ fields.push(value % 2 === 1 ? -magnitude : magnitude)
87
+ value = 0
88
+ shift = 0
89
+ }
90
+ end(SEMICOLON, mappings.length)
91
+ lines.push(line)
92
+ return lines
93
+ }
94
+
95
+ function vlq(number) {
96
+ let text = '', value = number < 0 ? -number * 2 + 1 : number * 2
97
+ do {
98
+ let digit = value % 32
99
+ value = Math.floor(value / 32)
100
+ if (value > 0) digit += 32
101
+ text += DIGITS[digit]
102
+ } while (value > 0)
103
+ return text
104
+ }
105
+
106
+ // Lines of segments as decodeMappings reads them, each value from the one
107
+ // before as the format writes it: a column from the one before on its line,
108
+ // a source, line, column and name from the segment before, whatever its line.
109
+ export function mappingsDeltas(lines) {
110
+ let name = 0, source = 0, sourceColumn = 0, sourceLine = 0
111
+ return lines.map(line => {
112
+ let column = 0
113
+ return line.map(segment => {
114
+ const values = [segment[0] - column]
115
+ column = segment[0]
116
+ if (segment.length >= 4) {
117
+ values.push(segment[1] - source, segment[2] - sourceLine, segment[3] - sourceColumn)
118
+ ;[, source, sourceLine, sourceColumn] = segment
119
+ if (segment.length === 5) {
120
+ values.push(segment[4] - name)
121
+ name = segment[4]
122
+ }
123
+ }
124
+ return values
125
+ })
126
+ })
127
+ }
128
+
129
+ // Lines of segments of values from the one before (mappingsDeltas), written as
130
+ // mappings, each value in the fewest digits.
131
+ export const encodeDeltas = lines => lines.map(line => line.map(values => values.map(vlq).join('')).join(',')).join(';')
132
+
133
+ // Lines of segments as decodeMappings reads them, written as the format
134
+ // writes them: so for mappings as any generator writes them,
135
+ // `encodeMappings(decodeMappings(m, …))` is `m`.
136
+ export const encodeMappings = lines => encodeDeltas(mappingsDeltas(lines))
@@ -0,0 +1,85 @@
1
+ // A source map's listing (sourcemap-listing.js) read back to the text it
2
+ // lists. Any row that isn't a listing's throws.
3
+ import { MAPPINGS_OPEN } from './sourcemap-listing.js'
4
+ import { encodeDeltas } from './sourcemap-mappings.js'
5
+
6
+ const KEY_ROW = /^("(?:[^"\\]|\\.)*"): (.*)$/u
7
+ const STRING_ROW = /^"(?:[^"\\]|\\.)*"$/u
8
+ const VALUE = /^-?\d+$/u
9
+ // What JSON.parse reads past after a value.
10
+ const BLANKS = /^[\t\n\r ]+$/u
11
+
12
+ const fail = (row, why) => {
13
+ throw new Error(`Its listing's row ${row + 1} ${why}`)
14
+ }
15
+
16
+ // A line of a text (`│` as written, `┊` as JSON).
17
+ function textLine(row, i) {
18
+ if (row === ' │') return ''
19
+ if (row.startsWith(' │ ')) return row.slice(4)
20
+ const text = row.startsWith(' ┊ ') ? JSON.parse(row.slice(4)) : null
21
+ return typeof text === 'string' && !text.includes('\n') ? text : fail(i, 'is no line of a text.')
22
+ }
23
+
24
+ // A list's items, from row `i`, and the row past its `]`.
25
+ function itemsFrom(rows, i) {
26
+ const items = []
27
+ for (; i < rows.length; i++) {
28
+ const row = rows[i]
29
+ if (row === ']') return [items, i + 1]
30
+ if (row === ' ┌' || row.startsWith(' ┌ ')) {
31
+ const lines = []
32
+ while (rows[i + 1]?.startsWith(' │') || rows[i + 1]?.startsWith(' ┊')) lines.push(textLine(rows[++i], i))
33
+ if (lines.length === 0) fail(i, 'opens a text with no line.')
34
+ items.push(lines.join('\n'))
35
+ } else if (row.startsWith(' ')) items.push(JSON.parse(row.slice(2)))
36
+ else fail(i, 'is no item of a list.')
37
+ }
38
+ return fail(i - 1, 'ends a list with no `]` after.')
39
+ }
40
+
41
+ // Mappings written back of their rows, a line of the generated file to each
42
+ // (`from` the first's index), each segment its values from the one before.
43
+ function mappingsFrom(rows, from) {
44
+ return encodeDeltas(rows.map((row, k) => {
45
+ if (row === '') return []
46
+ if (!row.startsWith(' ')) fail(from + k, 'is no line of mappings.')
47
+ return row.slice(2).split(', ').map(segment => {
48
+ const values = segment.split(' ')
49
+ if (![1, 4, 5].includes(values.length) || !values.every(each => VALUE.test(each))) fail(from + k, 'gives a segment that reads as none.')
50
+ return values.map(Number)
51
+ })
52
+ }))
53
+ }
54
+
55
+ // The text a listing lists. Throws for rows that aren't a listing's.
56
+ export function unlistSourcemap(text) {
57
+ if (!text.endsWith('\n')) throw new Error('Its listing ends with no line end.')
58
+ const rows = text.slice(0, -1).split('\n'), value = {}
59
+ let i = 0, trailing = ''
60
+ while (i < rows.length) {
61
+ if (i === rows.length - 1 && STRING_ROW.test(rows[i])) {
62
+ trailing = JSON.parse(rows[i])
63
+ if (!BLANKS.test(trailing)) fail(i, 'follows the JSON with more than blanks.')
64
+ break
65
+ }
66
+ const match = KEY_ROW.exec(rows[i])
67
+ if (!match) fail(i, 'names no key.')
68
+ const key = JSON.parse(match[1])
69
+ if (Object.hasOwn(value, key)) fail(i, `names ${match[1]} again.`)
70
+ let item
71
+ if (match[2] === '[') [item, i] = itemsFrom(rows, i + 1)
72
+ else if (match[2] === MAPPINGS_OPEN && key === 'mappings') {
73
+ const end = rows.indexOf('}', i + 1)
74
+ if (end < 0) fail(i, 'opens mappings with no `}` after.')
75
+ item = mappingsFrom(rows.slice(i + 1, end), i + 1)
76
+ i = end + 1
77
+ } else {
78
+ item = JSON.parse(match[2])
79
+ i++
80
+ }
81
+ // Defined, not set: a `__proto__` key is a key like any other in JSON.
82
+ Object.defineProperty(value, key, { value: item, enumerable: true, writable: true, configurable: true })
83
+ }
84
+ return `${JSON.stringify(value)}${trailing}`
85
+ }
@@ -0,0 +1,5 @@
1
+ // Type declarations for `common/stasis-files.js`, for its `.ts` callers
2
+ // without `allowJs`.
3
+ export function isStasisBundleName(name: string): boolean
4
+ export function isStasisTgzName(name: string): boolean
5
+ export function isGzip(bytes: Uint8Array): boolean
@@ -0,0 +1,20 @@
1
+ // Stasis bundles as files: a stasis.code.br (brotli'd JSON) or a .stasis.tgz
2
+ // (a gzipped tar of a stasis.lock.json and the files it attests), each
3
+ // named so alone or after `<name>.` (stasis-core's BUNDLE_FILE and TGZ_FILE).
4
+ // Told apart by their names, as Stasis tells them (stasis-core's isTgzName);
5
+ // stasis-tgz.js reads a .stasis.tgz.
6
+ const BUNDLE_FILES = ['stasis.code.br', 'stasis.tgz']
7
+ const named = (name, file) => name === file || name.endsWith(`.${file}`)
8
+
9
+ // Whether `name` (lowercased, as bundleKind compares it) names a Stasis bundle.
10
+ export const isStasisBundleName = name => BUNDLE_FILES.some(file => named(name, file))
11
+
12
+ // Whether a bundle's file name is a .stasis.tgz's, as bundleKind reads it:
13
+ // its case aside, and a browser's duplicate-download counter before its last
14
+ // extension (`app.stasis (1).tgz`).
15
+ export const isStasisTgzName = name => named(name.toLowerCase().replace(/ \(\d+\)(?=\.[^.]*$)/u, ''), 'stasis.tgz')
16
+
17
+ // gzip's magic: a .stasis.tgz's bytes start so, a stasis.code.br's never
18
+ // (stasis-core's isGzip: brotli so would ask for a window Stasis never writes),
19
+ // as a store that gzips what it keeps tells what to gunzip again.
20
+ export const isGzip = bytes => bytes.length >= 2 && bytes[0] === 0x1f && bytes[1] === 0x8b
@@ -0,0 +1,6 @@
1
+ // Type declarations for `common/stasis-tgz.js`, for its `.ts` callers
2
+ // without `allowJs`.
3
+ export const MAX_STASIS_TGZ_BYTES: number
4
+ // An @exodus/stasis-core Bundle, which stasis-core ships no types for.
5
+ export function readStasisTgz(bytes: Uint8Array, options?: { limit?: number }): Promise<{ bundle: unknown; size: number }>
6
+ export function parseStasisTgz(bytes: Uint8Array, options?: { limit?: number }): Promise<unknown>
@@ -0,0 +1,27 @@
1
+ // A .stasis.tgz read the same in the browser and on the server, on the
2
+ // platform's DecompressionStream and WebCrypto (stasis-files.js tells one).
3
+ import { Bundle } from '@exodus/stasis-core/bundle'
4
+ import { decompress } from '@preventive/archive/compression.js'
5
+ import { unpack } from '@preventive/archive/tar.js'
6
+
7
+ // Its tar's bytes at most, as a stasis.code.br's decoded JSON is held to.
8
+ export const MAX_STASIS_TGZ_BYTES = 512 * 1024 * 1024
9
+
10
+ const base64 = bytes => btoa(Array.from(bytes, byte => String.fromCodePoint(byte)).join(''))
11
+
12
+ // The Bundle of a .stasis.tgz's bytes, as Stasis reads one (src/parse.js
13
+ // readStasisTgz): its tar gunzipped, nothing past its gzip but zeros, and
14
+ // unpacked with @preventive/archive, then Bundle.fromTar's, its
15
+ // stasis.lock.json first and every file held to the digest it attests. fromTar asks each file's
16
+ // digest as it reads it, so each is worked out first (SHA-512, as Stasis's
17
+ // sha512integrity). Throws naming what is wrong, as Stasis does. With the
18
+ // bytes its tar takes (`size`), about what holding the bundle takes.
19
+ export async function readStasisTgz(bytes, { limit = MAX_STASIS_TGZ_BYTES } = {}) {
20
+ const tar = await decompress(bytes, 'gzip', { limit })
21
+ const entries = unpack(tar)
22
+ const digests = new Map(await Promise.all(entries.filter(entry => entry.type !== 'directory').map(async ({ data }) =>
23
+ [data, `sha512-${base64(new Uint8Array(await crypto.subtle.digest('SHA-512', data)))}`])))
24
+ return { bundle: Bundle.fromTar(entries, { integrityOf: data => digests.get(data) }), size: tar.length }
25
+ }
26
+
27
+ export const parseStasisTgz = async (bytes, options) => (await readStasisTgz(bytes, options)).bundle
package/common/utf8.d.ts CHANGED
@@ -11,3 +11,6 @@
11
11
  // narrower declaration is safe.
12
12
  export function encodeUtf8(str: string): Uint8Array<ArrayBuffer>
13
13
  export function decodeUtf8(bytes: Uint8Array | ArrayBuffer | ArrayBufferView): string
14
+ // Bytes `str` takes in UTF-8, measured without encoding when no character
15
+ // is past \xFF. A lone surrogate counts as the U+FFFD it encodes to.
16
+ export function utf8ByteLength(str: string): number
package/common/utf8.js CHANGED
@@ -43,6 +43,51 @@ export function encodeUtf8(str) {
43
43
  return encoder.encode(str)
44
44
  }
45
45
 
46
+ // ASCII characters in a row after which the count hands back to the
47
+ // native scan. A jump costs a call and a step does not, so it pays only
48
+ // across a real gap: at 1, alternating text (`aéaé…`) takes a jump per
49
+ // character, and past 2, text with an accent every few words steps
50
+ // through ASCII the scan crosses faster. Measured on 50 MB of each, 2 was
51
+ // never more than 1.5x the best of the thresholds tried, 1 to 32.
52
+ const ASCII_RUN = 2
53
+
54
+ // The number of bytes `str` takes in UTF-8, without encoding it where
55
+ // that can be helped. A string with no character past \xFF is Latin-1:
56
+ // ASCII takes a byte and \x80-\xFF two, so its size is its length plus
57
+ // its high characters. An engine stores such a string a byte per
58
+ // character, where no character past \xFF can be, so the first test is
59
+ // answered without reading it. Only a string with a wider character is
60
+ // encoded to be measured.
61
+ //
62
+ // The high characters are counted without collecting them: a match array
63
+ // takes an entry apiece, which for Latin-1-heavy text outweighs the
64
+ // encoding this avoids. A native scan jumps to the next one — for ASCII
65
+ // it finds none — and a loop counts on from there while they keep coming,
66
+ // handing back to the scan after a run of ASCII. Sparse text is read
67
+ // natively, dense text by the loop, and neither allocates.
68
+ //
69
+ // This sizes text for display, so unlike `encodeUtf8` it does not refuse
70
+ // a lone surrogate: it counts the U+FFFD that TextEncoder writes for one.
71
+ export function utf8ByteLength(str) {
72
+ if (typeof str !== 'string') {
73
+ throw new TypeError(`utf8ByteLength expects a string, got ${typeof str}`)
74
+ }
75
+ // Code units, not code points: a `u` regexp reads a two-byte string by
76
+ // code point, several times slower, and a surrogate is past \xFF either way.
77
+ // eslint-disable-next-line require-unicode-regexp
78
+ if (/[\u0100-\uFFFF]/.test(str)) return encoder.encode(str).byteLength
79
+ const high = /[\u0080-\u00FF]/gu
80
+ let bytes = str.length
81
+ while (high.test(str)) {
82
+ let i = high.lastIndex - 1
83
+ for (let ascii = 0; i < str.length && ascii < ASCII_RUN; i++) {
84
+ if (str.codePointAt(i) > 0x7F) { bytes++; ascii = 0 } else ascii++
85
+ }
86
+ high.lastIndex = i
87
+ }
88
+ return bytes
89
+ }
90
+
46
91
  export function decodeUtf8(bytes) {
47
92
  // Reject non-BufferSource so a missed destructure / optional field /
48
93
  // misnamed property surfaces here instead of silently defaulting to
@@ -0,0 +1,19 @@
1
+ // The files a view hides whitespace changes in, their lines' indentation
2
+ // alone (changeBlocks' `leading`): JS/TS, JSON, CSS, HTML/XML, PHP, shell and
3
+ // the brace languages, where indentation means nothing outside a string or
4
+ // text that runs over lines, which is not read (a template's, a heredoc's,
5
+ // `<pre>`). Anything else (Python's or YAML's indentation, a Makefile's tabs)
6
+ // shows all of it. Told by the format a stasis bundle records, else by
7
+ // extension, or by a whole #! line known to run Node, Deno, Bun or a shell.
8
+ const INSENSITIVE_FORMATS = new Set(['module', 'commonjs', 'module-typescript', 'commonjs-typescript', 'json', 'xml', 'php', 'shell', 'gradle', 'cmake',
9
+ 'solidity', 'rust', 'java', 'kotlin', 'objc', 'objcpp', 'swift', 'c', 'cpp', 'c-header', 'cpp-header', 'pbxproj'])
10
+ const INSENSITIVE = /\.(?:[cm]?js|jsx|[cm]?ts|tsx|json5?|jsonc|css|scss|less|html?|xhtml|xml|svg|php|sh|bash|zsh|c|h|cc|cpp|cxx|hh|hpp|hxx|java|kts?|go|rs|cs|swift)$/u
11
+ const INSENSITIVE_SCRIPTS = new Set([
12
+ '#!/usr/bin/env node', '#! /usr/bin/env node', '#!/usr/bin/node', '#!/usr/local/bin/node', '#!/usr/bin/env nodejs', '#!/usr/bin/env deno', '#!/usr/bin/env bun',
13
+ '#!/bin/sh', '#! /bin/sh', '#!/bin/sh -e', '#!/usr/bin/env sh', '#!/bin/bash', '#! /bin/bash', '#!/bin/bash -e', '#!/usr/bin/env bash',
14
+ '#!/bin/zsh', '#!/usr/bin/env zsh', '#!/bin/dash',
15
+ ])
16
+ export function whitespaceInsensitive(path, text = '', format = undefined) {
17
+ if (typeof format === 'string') return INSENSITIVE_FORMATS.has(format)
18
+ return INSENSITIVE.test(path.toLowerCase()) || (typeof text === 'string' && INSENSITIVE_SCRIPTS.has(text.split('\n', 1)[0]))
19
+ }
@@ -0,0 +1,91 @@
1
+ import { revalidateKindOf } from '@preventive/report'
2
+ import { activeRevalidateKinds, canLockConfirmed } from './finding-filters.js'
3
+ import { mergeReportGroups } from './workspace-groups.js'
4
+ import { mergeLinkedWorkspaceGroups } from './linked-workspace-groups.js'
5
+
6
+ function appTabs(group) {
7
+ if (group.linkedTabs) return group.linkedTabs
8
+ const app = group.filter((f) => revalidateKindOf(f) === 'revalidation')
9
+ return app.length > 0 ? app : group
10
+ }
11
+
12
+ // Findings imported from another analyzer are App findings by construction,
13
+ // and Confirmed counts one its report holds no pass for as shown. A set of
14
+ // nothing but those is already its own App view, with no pass to fold anything
15
+ // under. The Confirmed lock asks for a pass as well (it has no outcome control
16
+ // to offer without one), so this is asked on its own: a team whose permissions
17
+ // leave only other analyzers' findings opens as App, as it does unrestricted.
18
+ // Such a view opens with no outcome filter, but keeps the confidence range of
19
+ // imports that score themselves (DeepSec's do).
20
+ function onlyUnjudgedImports(groups) {
21
+ const visible = groups.map(appTabs).filter((g) => g.length > 0)
22
+ return visible.length > 0 && visible.every((g) => g.every((f) => f.isApp && f._source && !f._sourcePass && revalidateKindOf(f) === ''))
23
+ }
24
+
25
+ // Evaluate the entire workspace, independent of triage, filters, or the lens
26
+ // left active by another report. Use the same merge and link rules as the view.
27
+ // `countFindings` has a workspace that is not App count its rows too, after
28
+ // the same merging, for a caller that shows it collapsed (managed teams).
29
+ export function workspaceAppMetadata(reports, duplicatesOf = () => [], { countFindings = false } = {}) {
30
+ return metadataOf(appView(reports, duplicatesOf), countFindings)
31
+ }
32
+
33
+ // The IDs of the findings a workspace's basic App view can show: of each row
34
+ // its locked Confirmed shows (ui/view/filters.js filterRevalidateKind), the
35
+ // App tabs, the rest folded under them; none the pass ruled out. Null where it
36
+ // has no such view, or one with no outcome to lock, which shows every row.
37
+ export function workspaceAppRows(reports, duplicatesOf = () => []) {
38
+ return rowsOf(appView(reports, duplicatesOf))
39
+ }
40
+
41
+ // Both, of one merge of its rows.
42
+ export function workspaceApp(reports, duplicatesOf = () => [], { countFindings = false } = {}) {
43
+ const view = appView(reports, duplicatesOf)
44
+ return { metadata: metadataOf(view, countFindings), rows: rowsOf(view) }
45
+ }
46
+
47
+ function metadataOf({ linked, app }, countFindings) {
48
+ if (!app) return countFindings ? { appMode: false, findings: linked.length } : { appMode: false }
49
+ return {
50
+ appMode: true,
51
+ appFindings: linked.filter((group) => appTabs(group).some((f) => f.isApp)).length,
52
+ }
53
+ }
54
+
55
+ function rowsOf({ linked, app }) {
56
+ if (!app || onlyUnjudgedImports(linked)) return null
57
+ const kinds = activeRevalidateKinds('confirmed', '')
58
+ const confirmed = (f) => kinds.includes(revalidateKindOf(f) || (f._source && !f._sourcePass ? 'revalidation' : ''))
59
+ const ids = new Set()
60
+ for (const group of linked) if (group.some(confirmed)) for (const f of appTabs(group)) ids.add(f.id)
61
+ return ids
62
+ }
63
+
64
+ // Whether a managed report may be switched to open on Confirmed whatever
65
+ // Confirmed hides (Manage → Reports, common/finding-filters.js
66
+ // confirmedCoverage): only where the switch changes something, a set whose
67
+ // pass leaves Confirmed rows of its own to show, but which is no basic App
68
+ // view of its own, as the stricter of the two rules has it (canLockConfirmed):
69
+ // Confirmed would hide a finding the opening range shows, or one not LOW the
70
+ // 6–10 band shows below a floor the opening tuned higher. Asked of the set as
71
+ // the App view merges it, with no copy counted as switched already. A set
72
+ // with contradicting verdicts opens with no App layer, and so with no
73
+ // Confirmed to open on; one of nothing but other analyzers' unjudged findings
74
+ // has no pass to have an answer.
75
+ export function confirmedDefaultOffered(reports, duplicatesOf = () => []) {
76
+ const { groups, conflicts } = mergeReportGroups(reports, { hideRuledOut: true })
77
+ if (conflicts.size > 0) return false
78
+ const linked = mergeLinkedWorkspaceGroups(groups, duplicatesOf, appTabs)
79
+ const kinds = activeRevalidateKinds('confirmed', '')
80
+ if (!linked.map(appTabs).some((g) => g.some((f) => kinds.includes(revalidateKindOf(f))))) return false
81
+ return !canLockConfirmed(linked, { tabs: appTabs, kindOf: revalidateKindOf, severityMode: 'corrected' })
82
+ }
83
+
84
+ // A workspace's rows as its basic App view merges them, and whether it has one.
85
+ function appView(reports, duplicatesOf) {
86
+ const { groups, conflicts } = mergeReportGroups(reports, { hideRuledOut: true })
87
+ const linked = mergeLinkedWorkspaceGroups(groups, duplicatesOf, appTabs)
88
+ const app = conflicts.size === 0
89
+ && (onlyUnjudgedImports(linked) || canLockConfirmed(linked, { tabs: appTabs, kindOf: revalidateKindOf, severityMode: 'corrected' }))
90
+ return { linked, app }
91
+ }