@preventive/triage 1.0.0-alpha.9 → 1.0.0-alpha.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +16 -78
- package/cli.js +6 -0
- package/client/dependency-paths.d.ts +3 -0
- package/client/dependency-paths.js +36 -0
- package/client/finding-link.js +305 -0
- package/client/linked-findings.d.ts +1 -0
- package/client/linked-findings.js +115 -0
- package/common/bundle-commit.d.ts +1 -0
- package/common/bundle-commit.js +4 -0
- package/common/bundle-compare-diff.d.ts +6 -0
- package/common/bundle-compare-diff.js +378 -0
- package/common/bundle-compare-inputs.d.ts +3 -0
- package/common/bundle-compare-inputs.js +141 -0
- package/common/bundle-compare-versions.js +172 -0
- package/common/bundle-comparison.d.ts +8 -0
- package/common/bundle-comparison.js +69 -0
- package/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.d.ts +15 -0
- package/common/bundle-metadata.js +226 -0
- package/common/bundle-pkg-of.d.ts +1 -0
- package/common/bundle-pkg-of.js +90 -0
- package/common/bundle-reasons.d.ts +6 -0
- package/common/bundle-reasons.js +58 -0
- package/common/bundle-source-links.d.ts +6 -0
- package/common/bundle-source-links.js +216 -0
- package/common/bundle-sourcemap.d.ts +10 -0
- package/common/bundle-sourcemap.js +100 -0
- package/common/bundle-sources.d.ts +10 -0
- package/common/bundle-sources.js +374 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +80 -0
- package/common/default-scan-models.ts +37 -0
- package/common/dependency-reviews.d.ts +19 -0
- package/common/dependency-reviews.js +67 -0
- package/common/finding-duplicates.js +63 -0
- package/common/finding-filters.js +313 -0
- package/common/finding-id.js +47 -0
- package/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/github-issue-labels.d.ts +3 -0
- package/common/github-issue-labels.js +42 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +15 -0
- package/common/line-diff.js +188 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +43 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/directory-packages.ts +28 -0
- package/common/managed/finding-detail.d.ts +5 -0
- package/common/managed/finding-detail.js +75 -0
- package/common/managed/finding-values.d.ts +2 -0
- package/common/managed/finding-values.js +138 -0
- package/common/managed/github-agents.ts +114 -0
- package/common/managed/github-logins.ts +49 -0
- package/common/managed/lite-name.d.ts +2 -0
- package/common/managed/lite-name.js +20 -0
- package/common/managed/npm-packages.d.ts +9 -0
- package/common/managed/npm-packages.js +63 -0
- package/common/managed/permissions.ts +31 -0
- package/common/managed/report-content.ts +72 -0
- package/common/managed/report-filter.ts +120 -0
- package/common/managed/repository-alias.ts +65 -0
- package/common/managed/review-view-routes.js +23 -0
- package/common/managed/risk-routes.js +30 -0
- package/common/managed/roles.ts +48 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +386 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/stasis-config.ts +7 -0
- package/common/managed/team-app.d.ts +19 -0
- package/common/managed/team-app.js +129 -0
- package/common/managed/team-filters.js +26 -0
- package/common/managed/triage.ts +83 -0
- package/common/managed/upload-seal.ts +126 -0
- package/common/npm-token.d.ts +2 -0
- package/common/npm-token.js +14 -0
- package/common/pretty-json.js +123 -0
- package/common/pretty-kinds.js +20 -0
- package/common/pretty-print.d.ts +7 -0
- package/common/pretty-print.js +41 -0
- package/common/pretty-sourcemap.js +70 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/common/revalidation-conflicts.js +48 -0
- package/common/revalidation-input-groups.js +56 -0
- package/common/scan-server.ts +13 -0
- package/common/security-links.d.ts +5 -0
- package/common/security-links.js +33 -0
- package/common/server-info.ts +46 -0
- package/common/sourcemap-listing.js +78 -0
- package/common/sourcemap-mappings.js +136 -0
- package/common/sourcemap-unlist.js +85 -0
- package/common/stasis-files.d.ts +5 -0
- package/common/stasis-files.js +20 -0
- package/common/stasis-tgz.d.ts +6 -0
- package/common/stasis-tgz.js +27 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/whitespace-insensitive.js +19 -0
- package/common/workspace-app.js +91 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +2 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-3DOSBILK.js +4 -0
- package/out/chunk-55YIWY3H.js +5 -0
- package/out/chunk-5AVGKFMR.js +1 -0
- package/out/chunk-5PWEAEA5.js +1 -0
- package/out/chunk-6VOB5WXX.js +2 -0
- package/out/chunk-6Y6PZ2BU.js +9 -0
- package/out/chunk-74JZTGTO.js +11 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-7HP2VYIC.js +2 -0
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-A4BBBHQU.js +1 -0
- package/out/chunk-B64CTMVU.js +4 -0
- package/out/chunk-BEKYZCPX.js +14 -0
- package/out/chunk-BZJU5EEV.js +1 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-CJVMNJDZ.js +3 -0
- package/out/chunk-CU3FPB3P.js +1 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-DUASGS2O.js +8 -0
- package/out/chunk-EEJA7JBI.js +13 -0
- package/out/chunk-ESXA7KID.js +1 -0
- package/out/chunk-FSU2PLJL.js +1 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GX5UXWT4.js +1 -0
- package/out/chunk-HGWFRZNC.js +267 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-JZAROLQT.js +40 -0
- package/out/chunk-K4XJHM2T.js +1 -0
- package/out/chunk-KP2XM324.js +6 -0
- package/out/chunk-LRWB6QVO.js +1 -0
- package/out/chunk-LVSLM7HB.js +1 -0
- package/out/chunk-LVW7WWV4.js +1 -0
- package/out/chunk-N57OWFKY.js +15 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-PKLVXUEI.js +11 -0
- package/out/chunk-PLGH63UC.js +2 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QD3IBSF4.js +7 -0
- package/out/chunk-QI66YA4F.js +1 -0
- package/out/chunk-QRKFPLA4.js +80 -0
- package/out/chunk-R3NZFXVR.js +1 -0
- package/out/chunk-R5O6FAW4.js +2 -0
- package/out/chunk-RAM3GDAD.js +1 -0
- package/out/chunk-RPNO56H2.js +1 -0
- package/out/chunk-SMNFBOLO.js +10 -0
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-SZTCJVZJ.js +55 -0
- package/out/chunk-SZWPYLPC.js +1 -0
- package/out/chunk-TKPNRQNN.js +3 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-UJP4PQJA.js +1 -0
- package/out/chunk-UJSJMXEG.js +1 -0
- package/out/chunk-UR4WYMIP.js +1 -0
- package/out/chunk-UTYWTUTC.js +1 -0
- package/out/chunk-VHEXSGGP.js +1 -0
- package/out/chunk-VYYUMYVW.js +9 -0
- package/out/chunk-WBK5ZN4K.js +3 -0
- package/out/chunk-WCDYSIKG.js +1 -0
- package/out/chunk-XM4RLC4A.js +2 -0
- package/out/chunk-XRAAYXPR.js +1 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +35 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +26 -0
- package/out/dialogs.js +40 -0
- package/out/github-issue-authorized.html +3 -0
- package/out/github-issue-authorized.js +1 -0
- package/out/graph.js +19 -5
- package/out/index.html +105 -25
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +367 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -148
- package/package.json +416 -64
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +287 -0
- package/risk/actions/scripts/commands.js +182 -0
- package/risk/actions/scripts/grade.js +113 -0
- package/risk/actions/scripts/packages.js +123 -0
- package/risk/actions/scripts/shell.js +169 -0
- package/risk/actions/uses.js +94 -0
- package/risk/actions/workflow.js +183 -0
- package/risk/files/characters.js +354 -0
- package/risk/files/hosts.js +206 -0
- package/risk/files/readability.js +185 -0
- package/risk/files/runs-code.js +568 -0
- package/risk/files/script.js +420 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +309 -0
- package/risk/index.js +12 -0
- package/risk/npm/assess.js +303 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +236 -0
- package/risk/npm/dependencies.js +172 -0
- package/risk/npm/diff.js +79 -0
- package/risk/npm/downloads.js +84 -0
- package/risk/npm/files.js +445 -0
- package/risk/npm/held.js +67 -0
- package/risk/npm/install-scripts.js +34 -0
- package/risk/npm/malware.js +38 -0
- package/risk/npm/manifest.js +65 -0
- package/risk/npm/new-dependency.js +60 -0
- package/risk/npm/old-version.js +108 -0
- package/risk/npm/registry.js +401 -0
- package/risk/npm/release.js +85 -0
- package/risk/npm/score.js +59 -0
- package/risk/npm/specs.js +124 -0
- package/risk/npm/tarball.js +169 -0
- package/server-common/database-config.ts +16 -0
- package/server-common/initialize.ts +18 -0
- package/server-common/npm-advisories.ts +101 -0
- package/{server → server-common}/origin.ts +5 -5
- package/server-common/reap.ts +48 -0
- package/server-common/scan-config.ts +19 -0
- package/server-common/standalone.ts +29 -0
- package/server-common/storage-crypto.ts +182 -0
- package/server-common/storage-log.ts +38 -0
- package/server-common/vercel-blob.ts +103 -0
- package/server-e2e/app.ts +487 -0
- package/{server → server-e2e}/bus-receiver.ts +2 -1
- package/{server → server-e2e}/cli.js +9 -4
- package/{server → server-e2e}/config.ts +52 -42
- package/{server → server-e2e}/db-neon.ts +2 -2
- package/{server → server-e2e}/db-revision-sql.ts +1 -1
- package/{server → server-e2e}/db-stmt.ts +2 -2
- package/{server → server-e2e}/db.ts +7 -7
- package/{server → server-e2e}/http.ts +44 -13
- package/{server → server-e2e}/hub.ts +40 -9
- package/server-e2e/index.ts +17 -0
- package/server-e2e/lifecycle.ts +95 -0
- package/{server → server-e2e}/neon-driver.ts +2 -2
- package/{server → server-e2e}/npm-proxy.ts +12 -145
- package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
- package/{server → server-e2e}/objstore/blob.ts +1 -1
- package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
- package/{server → server-e2e}/objstore/handlers.ts +9 -8
- package/{server → server-e2e}/objstore/init.ts +19 -27
- package/{server → server-e2e}/objstore/reaper.ts +1 -1
- package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
- package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
- package/{server → server-e2e}/objstore/rest.ts +3 -3
- package/{server → server-e2e}/objstore/store-neon.ts +6 -10
- package/{server → server-e2e}/objstore/store.ts +7 -7
- package/{server → server-e2e}/objstore/tokens.ts +2 -2
- package/{server → server-e2e}/pubsub.ts +12 -9
- package/{server → server-e2e}/sign.ts +4 -4
- package/{server → server-e2e}/sse-server.ts +3 -3
- package/{server → server-e2e}/static.ts +18 -17
- package/{server → server-e2e}/sync-handlers.ts +56 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +269 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +21 -0
- package/server-managed/blob-store.ts +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +176 -0
- package/server-managed/bundle-advisory-inventory.ts +85 -0
- package/server-managed/bundle-build-diagnostics.d.ts +10 -0
- package/server-managed/bundle-build-diagnostics.js +23 -0
- package/server-managed/bundle-build-leases.ts +41 -0
- package/server-managed/bundle-build-worker.js +387 -0
- package/server-managed/bundle-build.ts +328 -0
- package/server-managed/bundle-cache.ts +261 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +91 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +139 -0
- package/server-managed/bundle-validation.ts +33 -0
- package/server-managed/bundle.ts +151 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +43 -0
- package/server-managed/comments.ts +138 -0
- package/server-managed/commit-coauthors.ts +105 -0
- package/server-managed/commit-lockfiles.ts +78 -0
- package/server-managed/comparison.ts +51 -0
- package/server-managed/config.ts +163 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1950 -0
- package/server-managed/db-neon.ts +401 -0
- package/server-managed/db-schema.ts +271 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +150 -0
- package/server-managed/dependabot-access.ts +85 -0
- package/server-managed/dependabot-alerts.ts +197 -0
- package/server-managed/dependency-review-comments.ts +158 -0
- package/server-managed/dependency-reviews.ts +369 -0
- package/server-managed/github-accounts.ts +59 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +347 -0
- package/server-managed/github-errors.ts +92 -0
- package/server-managed/github-graphql.ts +42 -0
- package/server-managed/github-issue-links.ts +264 -0
- package/server-managed/github-issue-oauth.ts +30 -0
- package/server-managed/github-issues.ts +169 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +218 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +290 -0
- package/server-managed/github-requests.ts +181 -0
- package/server-managed/github-users.ts +53 -0
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +6722 -0
- package/server-managed/import-triage.ts +51 -0
- package/server-managed/index.ts +204 -0
- package/server-managed/kept-briefly.ts +37 -0
- package/server-managed/kept.ts +28 -0
- package/server-managed/known-listings.ts +112 -0
- package/server-managed/link-reports.ts +149 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +234 -0
- package/server-managed/lockfile-scope.ts +58 -0
- package/server-managed/lru.ts +30 -0
- package/server-managed/managed-issues.ts +92 -0
- package/server-managed/management-catalog.ts +45 -0
- package/server-managed/management.ts +116 -0
- package/server-managed/npm-delta-worker.js +203 -0
- package/server-managed/npm-delta.ts +277 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +274 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +477 -0
- package/server-managed/npm-patch-paths.ts +86 -0
- package/server-managed/npm-patch.ts +457 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +310 -0
- package/server-managed/object-storage-disk.ts +147 -0
- package/server-managed/object-storage-vercel.ts +71 -0
- package/server-managed/object-storage.ts +82 -0
- package/server-managed/package-entry-points.ts +127 -0
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +4 -0
- package/server-managed/pretty-format.js +27 -0
- package/server-managed/pretty-print.ts +444 -0
- package/server-managed/public-workspace.ts +242 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +370 -0
- package/server-managed/pull-dependency-reviews.ts +458 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/pulse-walk.ts +164 -0
- package/server-managed/queue.ts +54 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +30 -0
- package/server-managed/rename-diff.ts +237 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-opening.ts +77 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +185 -0
- package/server-managed/report-store.ts +77 -0
- package/server-managed/repository-actions.ts +220 -0
- package/server-managed/repository-agents.ts +422 -0
- package/server-managed/repository-aliases.ts +119 -0
- package/server-managed/repository-browser.ts +362 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +222 -0
- package/server-managed/repository-dependency-reviews.ts +220 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +444 -0
- package/server-managed/repository-issues.ts +293 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +409 -0
- package/server-managed/repository-risk-assess.ts +179 -0
- package/server-managed/repository-risk-audit.ts +145 -0
- package/server-managed/repository-risk-caches.ts +56 -0
- package/server-managed/repository-risk-kept.ts +86 -0
- package/server-managed/repository-risk-read.ts +296 -0
- package/server-managed/repository-risk-stasis.ts +61 -0
- package/server-managed/repository-risk-turn.ts +97 -0
- package/server-managed/repository-risk.ts +528 -0
- package/server-managed/repository-squashes.ts +160 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +170 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +121 -0
- package/server-managed/session.ts +132 -0
- package/server-managed/slugs.ts +38 -0
- package/server-managed/solidity-entry-points.ts +71 -0
- package/server-managed/sql-postgres.ts +34 -0
- package/server-managed/sql.ts +107 -0
- package/server-managed/stasis-config.ts +147 -0
- package/server-managed/stasis-dependencies.ts +280 -0
- package/server-managed/static.ts +28 -0
- package/server-managed/storage-command.ts +16 -0
- package/server-managed/storage-db.ts +183 -0
- package/server-managed/storage-encryption.ts +288 -0
- package/server-managed/storage-maintenance.ts +259 -0
- package/server-managed/storage-payload.ts +121 -0
- package/server-managed/storage-stores.ts +91 -0
- package/server-managed/storage.ts +82 -0
- package/server-managed/team-app-summaries.ts +57 -0
- package/server-managed/team-app.ts +162 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-icons.ts +50 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-progress.ts +77 -0
- package/server-managed/team-reports.ts +369 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +181 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +135 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +275 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +170 -0
- package/server.ts +70 -0
- package/strip-types-loader.js +13 -10
- package/server/index.ts +0 -480
- package/server/lifecycle.ts +0 -208
- /package/{LICENSE → LICENSE-MIT} +0 -0
- /package/{server → server-e2e}/auth.ts +0 -0
- /package/{server → server-e2e}/config.example.json +0 -0
- /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
- /package/{server → server-e2e}/objstore/fs.ts +0 -0
- /package/{server → server-e2e}/objstore/sign.ts +0 -0
- /package/{server → server-e2e}/peer.ts +0 -0
- /package/{server → server-e2e}/sse-session.ts +0 -0
- /package/{server → server-e2e}/util.ts +0 -0
- /package/{server → server-e2e}/validation.ts +0 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
// Team content is filtered as one workspace, with separate report envelopes.
|
|
2
|
+
// Bounded snapshots retain filtered content and visibility for repeated reads.
|
|
3
|
+
import { mergeLinkGroups } from './link-reports.ts'
|
|
4
|
+
import { Buffer } from 'node:buffer'
|
|
5
|
+
import { createHash } from 'node:crypto'
|
|
6
|
+
import { backfillFindingIds, reportEntries, stampSecurityGroups } from '@preventive/report'
|
|
7
|
+
import { managedFindingSourcePaths, readManagedReport } from '../common/managed/report-content.ts'
|
|
8
|
+
import { filterReportData, projectFinding } from '../common/managed/report-filter.ts'
|
|
9
|
+
import { revalidationLinks, securityLinks } from '../common/security-links.js'
|
|
10
|
+
import { treeDependencyDirectory } from '../client/dependency-paths.js'
|
|
11
|
+
import { liteWorkspace } from '../common/managed/finding-detail.js'
|
|
12
|
+
import { managedTeamView } from '../common/managed/team-app.js'
|
|
13
|
+
import { packTeamReports, unpackTeamReport } from '../common/managed/finding-values.js'
|
|
14
|
+
import type { BlobStore } from './blob-store.ts'
|
|
15
|
+
import type { ManagedDb, TeamReportAccessSnapshot } from './db.ts'
|
|
16
|
+
import type { TeamWorkspaceSummary } from './team-app.ts'
|
|
17
|
+
import { triageWireEntry } from './triage-response.ts'
|
|
18
|
+
import { visibleManagedIssues } from './managed-issues.ts'
|
|
19
|
+
import { MAX_REPORT_QUERY_BYTES, MAX_REPORT_QUERY_COUNT } from './report-query.ts'
|
|
20
|
+
import { ourRepoSlugs } from '../common/finding-repo.js'
|
|
21
|
+
|
|
22
|
+
type Finding = Record<string, unknown>
|
|
23
|
+
// `confirmedDefault` where a manager switched the report to open on Confirmed,
|
|
24
|
+
// and `opensAsApp` where it opens as an App view on its own, so switched or by
|
|
25
|
+
// its rows (common/managed/team-app.js), which its team's view counts as
|
|
26
|
+
// holding it off Confirmed none of its findings (common/finding-filters.js
|
|
27
|
+
// confirmedCoverage); each left out otherwise.
|
|
28
|
+
type TeamReport = { id: string; filename: string; data: unknown; repo: { github: string | null; directory: string }; confirmedDefault?: true; opensAsApp?: true }
|
|
29
|
+
type ReportVisibility = { ids: Set<string>; sourcePaths: Set<string> }
|
|
30
|
+
type Visibility = Map<string, ReportVisibility>
|
|
31
|
+
const VISIBILITY_CACHE_MAX_ITEMS = 250_000
|
|
32
|
+
const VISIBILITY_CACHE_MAX_SNAPSHOTS = 32
|
|
33
|
+
const caches = new WeakMap<ManagedDb, Map<string, Visibility>>()
|
|
34
|
+
const REPORT_CACHE_BYTES = 16 * 1024 * 1024
|
|
35
|
+
// A workspace's encoded reports, the same without their findings' detail for
|
|
36
|
+
// the board (`lite`), its reports' file trees apart, and its team's catalog
|
|
37
|
+
// summary (team-app.ts).
|
|
38
|
+
type EncodedWorkspace = { reports: Buffer; lite: Buffer; trees: Buffer; summary: TeamWorkspaceSummary }
|
|
39
|
+
// One as kept: without its whole reports where they would not fit
|
|
40
|
+
// (retainReports).
|
|
41
|
+
type RetainedWorkspace = Omit<EncodedWorkspace, 'reports'> & { reports?: Buffer }
|
|
42
|
+
export type TeamResponsePart = 'reports' | 'lite' | 'trees'
|
|
43
|
+
// The part a team's `reports` or `trees` route asks for.
|
|
44
|
+
export const teamResponsePart = (route: string, url: URL): TeamResponsePart =>
|
|
45
|
+
route === 'trees' ? 'trees' : url.searchParams.get('lite') === '1' ? 'lite' : 'reports'
|
|
46
|
+
const reportCaches = new WeakMap<ManagedDb, Map<string, RetainedWorkspace>>()
|
|
47
|
+
const encodedBytes = ({ reports, lite, trees }: RetainedWorkspace) => (reports?.length ?? 0) + lite.length + trees.length
|
|
48
|
+
// A workspace's report reads at once. Its reports' sizes are bounded together
|
|
49
|
+
// before any is read, and each is held parsed till the build ends, so more at
|
|
50
|
+
// once costs only the raw bytes in flight: a cold build of a team's reports
|
|
51
|
+
// is so many storage round trips one after another.
|
|
52
|
+
const WORKSPACE_READS_AT_ONCE = 16
|
|
53
|
+
// Its whole reports, by far its largest part, are kept with the rest where
|
|
54
|
+
// they fit, and left out where they do not: the board's copy and the trees,
|
|
55
|
+
// which a team's view opens on, are kept all the same, so that opening it
|
|
56
|
+
// again reads none of its reports, its whole reports built again apart.
|
|
57
|
+
function retainReports(db: ManagedDb, key: string, encoded: EncodedWorkspace) {
|
|
58
|
+
let kept: RetainedWorkspace = encoded
|
|
59
|
+
if (encodedBytes(kept) > REPORT_CACHE_BYTES) { const { reports: _reports, ...rest } = encoded; kept = rest }
|
|
60
|
+
if (encodedBytes(kept) > REPORT_CACHE_BYTES) return
|
|
61
|
+
let cache = reportCaches.get(db)
|
|
62
|
+
if (!cache) { cache = new Map(); reportCaches.set(db, cache) }
|
|
63
|
+
cache.delete(key)
|
|
64
|
+
let total = encodedBytes(kept) + [...cache.values()].reduce((sum, value) => sum + encodedBytes(value), 0)
|
|
65
|
+
for (const [oldest, value] of cache) {
|
|
66
|
+
if (total <= REPORT_CACHE_BYTES && cache.size < VISIBILITY_CACHE_MAX_SNAPSHOTS) break
|
|
67
|
+
cache.delete(oldest); total -= encodedBytes(value)
|
|
68
|
+
}
|
|
69
|
+
cache.set(key, kept)
|
|
70
|
+
}
|
|
71
|
+
function visibilityWeight(visible: Visibility): number {
|
|
72
|
+
return [...visible.values()].reduce((sum, v) => sum + v.ids.size + v.sourcePaths.size, 0)
|
|
73
|
+
}
|
|
74
|
+
function retainVisibility(db: ManagedDb, key: string, visible: Visibility): void {
|
|
75
|
+
let cache = caches.get(db)
|
|
76
|
+
// Replacement contributes its weight once and does not evict a peer merely
|
|
77
|
+
// because the cache already holds the maximum number of snapshots.
|
|
78
|
+
cache?.delete(key)
|
|
79
|
+
const incoming = visibilityWeight(visible)
|
|
80
|
+
if (incoming > VISIBILITY_CACHE_MAX_ITEMS) return
|
|
81
|
+
if (!cache) { cache = new Map(); caches.set(db, cache) }
|
|
82
|
+
let total = incoming + [...cache.values()].reduce((sum, entry) => sum + visibilityWeight(entry), 0)
|
|
83
|
+
for (const [oldest, entry] of cache) {
|
|
84
|
+
if (cache.size < VISIBILITY_CACHE_MAX_SNAPSHOTS && total <= VISIBILITY_CACHE_MAX_ITEMS) break
|
|
85
|
+
cache.delete(oldest)
|
|
86
|
+
total -= visibilityWeight(entry)
|
|
87
|
+
}
|
|
88
|
+
cache.set(key, visible)
|
|
89
|
+
}
|
|
90
|
+
export class TeamReportsError extends Error {
|
|
91
|
+
status: number
|
|
92
|
+
constructor(status: number, error: string) { super(error); this.status = status }
|
|
93
|
+
}
|
|
94
|
+
export function teamSnapshotKey(snapshot: TeamReportAccessSnapshot): string {
|
|
95
|
+
return JSON.stringify([snapshot.user.id, snapshot.user.role, snapshot.teamId, snapshot.hiddenReportId ?? null, snapshot.reports, snapshot.repositories, snapshot.linkRevision])
|
|
96
|
+
}
|
|
97
|
+
// What a built workspace is kept by: everything its build reads, and nothing
|
|
98
|
+
// of who asked. A user's role and grants decide which reports (and which
|
|
99
|
+
// hidden preview) their snapshot holds and each one's permissions, all of it
|
|
100
|
+
// in the key, so members whose snapshots agree share one build.
|
|
101
|
+
function workspaceKey(snapshot: TeamReportAccessSnapshot): string {
|
|
102
|
+
return JSON.stringify([snapshot.teamId, snapshot.hiddenReportId ?? null, snapshot.reports, snapshot.repositories, snapshot.linkRevision])
|
|
103
|
+
}
|
|
104
|
+
export async function teamSnapshot(db: ManagedDb, sessionId: string, teamId: string, reportId: string | null = null): Promise<TeamReportAccessSnapshot> {
|
|
105
|
+
const snapshot = await db.getTeamReportAccessSnapshot(sessionId, Date.now(), teamId, reportId)
|
|
106
|
+
if (!snapshot) throw new TeamReportsError(401, 'unauthenticated')
|
|
107
|
+
if (!snapshot.teamId) throw new TeamReportsError(404, 'no-team')
|
|
108
|
+
if (reportId !== null && !snapshot.reports.some(report => report.id === reportId)) throw new TeamReportsError(404, 'no-report')
|
|
109
|
+
return snapshot
|
|
110
|
+
}
|
|
111
|
+
export async function recheckTeam(db: ManagedDb, sessionId: string, snapshot: TeamReportAccessSnapshot): Promise<void> {
|
|
112
|
+
if (teamSnapshotKey(await teamSnapshot(db, sessionId, snapshot.teamId!, snapshot.reportId)) !== teamSnapshotKey(snapshot)) throw new TeamReportsError(404, 'workspace-changed')
|
|
113
|
+
}
|
|
114
|
+
function groupsOf(data: unknown): Finding[][] {
|
|
115
|
+
return (reportEntries(data) ?? []).map(entry => (Array.isArray(entry) ? entry : [entry]).filter(
|
|
116
|
+
(finding): finding is Finding => finding !== null && typeof finding === 'object' && !Array.isArray(finding),
|
|
117
|
+
))
|
|
118
|
+
}
|
|
119
|
+
// A links document counts by its links, every other report by its findings.
|
|
120
|
+
function hasContent(data: unknown): boolean {
|
|
121
|
+
const links = linksOf(data)
|
|
122
|
+
if (links) return links.length > 0
|
|
123
|
+
return (reportEntries(data) ?? []).some(entry => !Array.isArray(entry) || entry.length > 0)
|
|
124
|
+
}
|
|
125
|
+
function linksOf(data: unknown): string[][] | null {
|
|
126
|
+
const record = data as { source?: string; links?: string[][] }
|
|
127
|
+
if (record?.source !== 'links' || !Array.isArray(record.links)) return null
|
|
128
|
+
if (!record.links.every(ids => Array.isArray(ids) && ids.every(id => typeof id === 'string'))) throw new TeamReportsError(422, 'unreadable-links')
|
|
129
|
+
return record.links
|
|
130
|
+
}
|
|
131
|
+
// A report's file tree goes apart, asked for by its graph or Files alone
|
|
132
|
+
// (loadTeamTreesResponse). The report tells in its place how many files it
|
|
133
|
+
// holds (`treeFiles`) and the dependency directory it names
|
|
134
|
+
// (`treeDependencies`), which classifies findings as the tree itself would
|
|
135
|
+
// (client/dependency-paths.js). Each file's is sent without the hash of its
|
|
136
|
+
// tree (`treeHash`), which no team view reads.
|
|
137
|
+
function withoutTree(report: TeamReport): string | null {
|
|
138
|
+
const tree = (report.data as { tree?: unknown } | null)?.tree
|
|
139
|
+
if (!tree || typeof tree !== 'object' || Array.isArray(tree)) return null
|
|
140
|
+
const { tree: _tree, ...data } = report.data as Finding
|
|
141
|
+
const named = treeDependencyDirectory(tree)
|
|
142
|
+
report.data = { ...data, treeFiles: Object.keys(tree).length, ...(named ? { treeDependencies: named } : {}) }
|
|
143
|
+
const files = Object.entries(tree).map(([file, entry]) => {
|
|
144
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return [file, entry]
|
|
145
|
+
const { treeHash: _treeHash, ...kept } = entry as Finding
|
|
146
|
+
return [file, kept]
|
|
147
|
+
})
|
|
148
|
+
return `${JSON.stringify(report.id)}:${JSON.stringify(Object.fromEntries(files))}`
|
|
149
|
+
}
|
|
150
|
+
// The snapshot's reports, read WORKSPACE_READS_AT_ONCE at a time, in its
|
|
151
|
+
// order, their findings' IDs backfilled.
|
|
152
|
+
async function readWorkspaceReports(store: BlobStore, snapshot: TeamReportAccessSnapshot): Promise<TeamReport[]> {
|
|
153
|
+
const reports: TeamReport[] = []
|
|
154
|
+
let inputBytes = 0, next = 0
|
|
155
|
+
// Bound both remote reads and raw buffers, retaining stable report order for
|
|
156
|
+
// the cross-report classification that follows. Finish workers on failure.
|
|
157
|
+
const results = await Promise.allSettled(Array.from({ length: Math.min(WORKSPACE_READS_AT_ONCE, snapshot.reports.length) }, async () => {
|
|
158
|
+
while (next < snapshot.reports.length) {
|
|
159
|
+
const index = next++
|
|
160
|
+
const access = snapshot.reports[index]!
|
|
161
|
+
|
|
162
|
+
const bytes = await store.get(access.id)
|
|
163
|
+
if (!bytes) throw new TeamReportsError(503, 'unavailable')
|
|
164
|
+
inputBytes += bytes.length
|
|
165
|
+
if (inputBytes > MAX_REPORT_QUERY_BYTES) throw new TeamReportsError(413, 'batch-too-large')
|
|
166
|
+
const parsed = readManagedReport(bytes.toString('utf8'), access.filename)
|
|
167
|
+
if (!parsed.data) throw new TeamReportsError(422, 'unreadable-report')
|
|
168
|
+
// Backfill before filtering so links, annotations and the client agree on
|
|
169
|
+
// IDs even when hiding a component would change the original row shape.
|
|
170
|
+
await backfillFindingIds(groupsOf(parsed.data).flat())
|
|
171
|
+
reports[index] = { id: access.id, filename: access.filename, data: parsed.data, repo: access.repo, ...access.confirmedDefault ? { confirmedDefault: true as const } : {} }
|
|
172
|
+
}
|
|
173
|
+
}))
|
|
174
|
+
for (const result of results) if (result.status === 'rejected') throw result.reason
|
|
175
|
+
return reports
|
|
176
|
+
}
|
|
177
|
+
async function buildTeamWorkspace(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot): Promise<EncodedWorkspace & { visible: Visibility }> {
|
|
178
|
+
if (snapshot.reports.length > MAX_REPORT_QUERY_COUNT || snapshot.reports.reduce((n, r) => n + r.byteSize, 0) > MAX_REPORT_QUERY_BYTES) throw new TeamReportsError(413, 'batch-too-large')
|
|
179
|
+
const reports = await readWorkspaceReports(store, snapshot)
|
|
180
|
+
const globalLinks = snapshot.linkRevision ? await db.getEnabledLinkGroups(snapshot.linkRevision) : []
|
|
181
|
+
const groups = reports.flatMap(report => groupsOf(report.data).map(group => group.map(f => projectFinding(f, report.data as Finding)!)))
|
|
182
|
+
// Unknown IDs can connect known findings. App findings link to the inputs
|
|
183
|
+
// they revalidated in other reports, as the App view counts them.
|
|
184
|
+
stampSecurityGroups(groups, { linkedIds: securityLinks([
|
|
185
|
+
...globalLinks, ...reports.flatMap(report => linksOf(report.data) ?? []), ...revalidationLinks(groups.flat()),
|
|
186
|
+
]).linkedIds })
|
|
187
|
+
const securityIds = new Set(groups.flat().filter(f => f['isSecurity'] === true).map(f => String(f['id'])))
|
|
188
|
+
const allIds = new Set<string>(), visible: Visibility = new Map()
|
|
189
|
+
for (let i = 0; i < reports.length; i++) {
|
|
190
|
+
const access = snapshot.reports[i]!, report = reports[i]!
|
|
191
|
+
// A finding's `repo` none of the team's (common/finding-repo.js
|
|
192
|
+
// isStrayRepo) is removed before anything reads it.
|
|
193
|
+
const ours = ourRepoSlugs([...snapshot.repositories.map(repo => repo.github), access.repo.github])
|
|
194
|
+
report.data = filterReportData(report.data, access.permissions, access.repo, securityIds, ours)
|
|
195
|
+
if (report.data && typeof report.data === 'object' && ('think' in report.data || 'reportRepo' in report.data)) {
|
|
196
|
+
const { think: _think, reportRepo: _reportRepo, ...data } = report.data as Finding
|
|
197
|
+
report.data = data
|
|
198
|
+
}
|
|
199
|
+
const ids = new Set<string>()
|
|
200
|
+
for (const finding of groupsOf(report.data).flat()) {
|
|
201
|
+
// Preserve linked security classification for the UI lens, including a
|
|
202
|
+
// linked component that a dependency permission will hide from the UI.
|
|
203
|
+
finding['isSecurity'] = securityIds.has(String(finding['id']))
|
|
204
|
+
// The hash of its file's tree, the fingerprint its ID was derived from,
|
|
205
|
+
// whether its run thought and the repository its report named, which
|
|
206
|
+
// nothing a team view reads, nor an export (@preventive/report
|
|
207
|
+
// write-md-finding.js) writes.
|
|
208
|
+
delete finding['treeHash']
|
|
209
|
+
delete finding['_idBasis']
|
|
210
|
+
delete finding['think']
|
|
211
|
+
delete finding['reportRepo']
|
|
212
|
+
if (typeof finding['id'] === 'string') { ids.add(finding['id']); allIds.add(finding['id']) }
|
|
213
|
+
}
|
|
214
|
+
visible.set(report.id, { ids, sourcePaths: managedFindingSourcePaths(groupsOf(report.data).flat()) })
|
|
215
|
+
}
|
|
216
|
+
for (const report of reports) {
|
|
217
|
+
const links = linksOf(report.data)
|
|
218
|
+
// Hidden previews are independently authorized; preserve a hidden links
|
|
219
|
+
// document even though its referenced findings are outside this response.
|
|
220
|
+
if (links && !snapshot.hiddenReportId) report.data = { source: 'links', findings: [], links: links.map(ids => [...new Set(ids.filter(id => allIds.has(id)))]).filter(ids => ids.length >= 2) }
|
|
221
|
+
}
|
|
222
|
+
const trees = Buffer.from(`{"trees":{${reports.map(withoutTree).filter(tree => tree !== null).join(',')}}}`)
|
|
223
|
+
const links = mergeLinkGroups(globalLinks, allIds)
|
|
224
|
+
// Its rows read once (common/managed/team-app.js managedTeamView) for both
|
|
225
|
+
// what its catalog entry tells and the board's copy: its findings without
|
|
226
|
+
// their detail, and in App mode its rows as the App view shows them
|
|
227
|
+
// (common/managed/finding-detail.js).
|
|
228
|
+
const view = managedTeamView(Object.assign(reports.map(({ filename, data, confirmedDefault }) => ({ filename, data, confirmedDefault })), { links }))
|
|
229
|
+
// As the reader's own grants leave each report, which they would open alone.
|
|
230
|
+
view.opensAsApp.forEach((opens, index) => { if (opens) reports[index]!.opensAsApp = true })
|
|
231
|
+
const lite = liteWorkspace(reports, links, view)
|
|
232
|
+
const restricted = snapshot.reports.some(report => !report.permissions.dependencies || !report.permissions.security)
|
|
233
|
+
const encoded = {
|
|
234
|
+
// Bounded together, as when the trees were sent with their reports.
|
|
235
|
+
reports: encodeReports(reports, links, trees.length),
|
|
236
|
+
lite: encodeReports(lite.reports, links, 0, { folded: lite.folded, lens: lite.lens }),
|
|
237
|
+
trees,
|
|
238
|
+
// Its App classification, the reports a restricted reader finds nothing
|
|
239
|
+
// in, which its catalog leaves out, and how many findings each shows.
|
|
240
|
+
summary: { app: view.app, empty: restricted ? reports.filter(report => !hasContent(report.data)).map(report => report.id) : [],
|
|
241
|
+
findings: Object.fromEntries(reports.map(report => [report.id, visible.get(report.id)?.ids.size ?? 0])) },
|
|
242
|
+
}
|
|
243
|
+
retainVisibility(db, workspaceKey(snapshot), visible)
|
|
244
|
+
retainReports(db, workspaceKey(snapshot), encoded)
|
|
245
|
+
return { ...encoded, visible }
|
|
246
|
+
}
|
|
247
|
+
// `{ reports, links }` as a response sends them, `spent` bytes already
|
|
248
|
+
// counted against the bound; `folded` and its `lens` where the board's copy
|
|
249
|
+
// left out rows App mode does not show (common/managed/finding-detail.js).
|
|
250
|
+
// The values its reports and their findings tell again and again (their
|
|
251
|
+
// severity, file, model, repository and so on) are sent once each, in
|
|
252
|
+
// `values`, and its findings' field names once for each shape of them, in
|
|
253
|
+
// `keys` (common/managed/finding-values.js).
|
|
254
|
+
function encodeReports(reports: readonly TeamReport[], links: readonly string[][], spent: number,
|
|
255
|
+
{ folded = false, lens = null }: { folded?: false | 'rows' | 'app'; lens?: unknown } = {}): Buffer {
|
|
256
|
+
let outputBytes = spent + 14
|
|
257
|
+
const parts = [Buffer.from('{"reports":[')]
|
|
258
|
+
const packed = packTeamReports(reports)
|
|
259
|
+
for (const [index, report] of packed.reports.entries()) {
|
|
260
|
+
const bytes = Buffer.from(JSON.stringify(report))
|
|
261
|
+
outputBytes += bytes.length + 1
|
|
262
|
+
if (outputBytes > MAX_REPORT_QUERY_BYTES) throw new TeamReportsError(413, 'batch-too-large')
|
|
263
|
+
if (index) parts.push(Buffer.from(','))
|
|
264
|
+
parts.push(bytes)
|
|
265
|
+
}
|
|
266
|
+
const tail = JSON.stringify({ ...links.length > 0 ? { links } : {}, ...folded ? { folded, lens } : {}, ...packed.values ? { values: packed.values } : {}, ...packed.keys ? { keys: packed.keys } : {} })
|
|
267
|
+
const suffix = Buffer.from(tail === '{}' ? ']}' : `],${tail.slice(1)}`)
|
|
268
|
+
if (outputBytes + suffix.length > MAX_REPORT_QUERY_BYTES) throw new TeamReportsError(413, 'batch-too-large')
|
|
269
|
+
parts.push(suffix)
|
|
270
|
+
return Buffer.concat(parts)
|
|
271
|
+
}
|
|
272
|
+
const pendingWorkspaces = new WeakMap<ManagedDb, Map<string, ReturnType<typeof buildTeamWorkspace>>>()
|
|
273
|
+
async function loadTeamWorkspace(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot) {
|
|
274
|
+
let pending = pendingWorkspaces.get(db)
|
|
275
|
+
if (!pending) { pending = new Map(); pendingWorkspaces.set(db, pending) }
|
|
276
|
+
const key = workspaceKey(snapshot)
|
|
277
|
+
const existing = pending.get(key)
|
|
278
|
+
if (existing) return existing
|
|
279
|
+
const job = buildTeamWorkspace(db, store, snapshot)
|
|
280
|
+
pending.set(key, job)
|
|
281
|
+
try { return await job } finally { pending.delete(key) }
|
|
282
|
+
}
|
|
283
|
+
// Treat the encoded body as immutable and recheck access before sending it.
|
|
284
|
+
// Warm HTTP reads need neither a parsed copy nor another serialization pass.
|
|
285
|
+
// Its `lite` reports and its `trees`, by report ID (withoutTree), are of the
|
|
286
|
+
// same snapshot and take the same recheck.
|
|
287
|
+
export async function loadTeamReportsResponse(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot,
|
|
288
|
+
part: TeamResponsePart = 'reports'): Promise<Buffer> {
|
|
289
|
+
const cached = reportCaches.get(db)?.get(workspaceKey(snapshot))
|
|
290
|
+
return cached?.[part] ?? (await loadTeamWorkspace(db, store, snapshot))[part]
|
|
291
|
+
}
|
|
292
|
+
// A team's catalog summary (team-app.ts), as its workspace was built.
|
|
293
|
+
export async function loadTeamSummary(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot): Promise<TeamWorkspaceSummary> {
|
|
294
|
+
return reportCaches.get(db)?.get(workspaceKey(snapshot))?.summary ?? (await loadTeamWorkspace(db, store, snapshot)).summary
|
|
295
|
+
}
|
|
296
|
+
export async function loadTeamReports(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot): Promise<TeamReport[]> {
|
|
297
|
+
// Object consumers get their own copy, including when sharing a cold load.
|
|
298
|
+
const body = JSON.parse((await loadTeamReportsResponse(db, store, snapshot)).toString('utf8')) as { reports: TeamReport[]; values?: unknown; keys?: unknown }
|
|
299
|
+
return body.reports.map(report => unpackTeamReport(report, body)!)
|
|
300
|
+
}
|
|
301
|
+
async function teamVisibility(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot): Promise<Visibility> {
|
|
302
|
+
// A large snapshot may deliberately remain uncached, or be evicted by
|
|
303
|
+
// another request. Authorization uses this load's result in either case.
|
|
304
|
+
return caches.get(db)?.get(workspaceKey(snapshot)) ?? (await loadTeamWorkspace(db, store, snapshot)).visible
|
|
305
|
+
}
|
|
306
|
+
// The findings `visible`'s reports show, each once.
|
|
307
|
+
const findingIdsOf = (visible: Visibility) => new Set([...visible.values()].flatMap(report => [...report.ids]))
|
|
308
|
+
export async function teamWorkspaceFindingIds(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot): Promise<Set<string>> {
|
|
309
|
+
return findingIdsOf(await teamVisibility(db, store, snapshot))
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// What a focused team's annotations are at, for the snapshot reading them, as
|
|
313
|
+
// its feed tells it (team-feed.ts serveUserTeamFeed) and its annotations
|
|
314
|
+
// answer it (loadTeamAnnotations): the snapshot's key and the revision of
|
|
315
|
+
// every visible finding's annotations (getAnnotationRevision), its workspace's
|
|
316
|
+
// findings being `ids` (teamWorkspaceFindingIds).
|
|
317
|
+
export async function teamAnnotationRevision(db: ManagedDb, snapshot: TeamReportAccessSnapshot, ids: readonly string[]): Promise<string> {
|
|
318
|
+
return JSON.stringify([teamSnapshotKey(snapshot), await db.getAnnotationRevision(ids)])
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// A revision as the client is told it: a digest, telling only whether what it
|
|
322
|
+
// covers changed, none of the finding IDs, batches or issues it is read from.
|
|
323
|
+
export const annotationRevisionDigest = (revision: string): string => createHash('sha256').update(revision).digest('base64url')
|
|
324
|
+
export async function teamReportVisibility(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot, reportId: string): Promise<ReportVisibility> {
|
|
325
|
+
if (!snapshot.reports.some(r => r.id === reportId)) throw new TeamReportsError(404, 'no-report')
|
|
326
|
+
const visible = await teamVisibility(db, store, snapshot)
|
|
327
|
+
return visible.get(reportId)!
|
|
328
|
+
}
|
|
329
|
+
// A report's visibility for the session's current snapshot. A workspace built
|
|
330
|
+
// (or waited for) here outlives that snapshot's read, so the team's access is
|
|
331
|
+
// read again after it; one kept is answered with no read in between, which
|
|
332
|
+
// leaves nothing for another snapshot read to guard.
|
|
333
|
+
async function sessionReportVisibility(db: ManagedDb, store: BlobStore, sessionId: string, teamId: string, reportId: string): Promise<ReportVisibility> {
|
|
334
|
+
const snapshot = await teamSnapshot(db, sessionId, teamId, reportId)
|
|
335
|
+
const kept = caches.get(db)?.get(workspaceKey(snapshot))?.get(reportId)
|
|
336
|
+
if (kept) return kept
|
|
337
|
+
const visible = await teamReportVisibility(db, store, snapshot, reportId)
|
|
338
|
+
await recheckTeam(db, sessionId, snapshot)
|
|
339
|
+
return visible
|
|
340
|
+
}
|
|
341
|
+
export async function teamFindingIds(db: ManagedDb, store: BlobStore, sessionId: string, teamId: string, reportId: string): Promise<Set<string>> {
|
|
342
|
+
return (await sessionReportVisibility(db, store, sessionId, teamId, reportId)).ids
|
|
343
|
+
}
|
|
344
|
+
export async function teamSourcePaths(db: ManagedDb, store: BlobStore, sessionId: string, teamId: string, reportId: string): Promise<Set<string>> {
|
|
345
|
+
return (await sessionReportVisibility(db, store, sessionId, teamId, reportId)).sourcePaths
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Serialize shared annotation bodies once. Reports carry only the annotated
|
|
349
|
+
// finding IDs visible in that report; callers revalidate access before sending.
|
|
350
|
+
// With them, the digest of the revision the whole workspace's are at, as the
|
|
351
|
+
// team's feed tells it (`revision`), read before them: a write between leaves
|
|
352
|
+
// it older than what is sent, so the feed's next differs and the client reads
|
|
353
|
+
// again, never the reverse.
|
|
354
|
+
export async function loadTeamAnnotations(db: ManagedDb, store: BlobStore, snapshot: TeamReportAccessSnapshot, reportId: string | null = null) {
|
|
355
|
+
// Restrict annotation reads only after classifying the complete workspace:
|
|
356
|
+
// links and findings in other reports can affect this report's visibility.
|
|
357
|
+
if (reportId !== null && !snapshot.reports.some(r => r.id === reportId)) throw new TeamReportsError(404, 'no-report')
|
|
358
|
+
const workspace = await teamVisibility(db, store, snapshot)
|
|
359
|
+
const visible = reportId === null ? workspace : new Map([[reportId, workspace.get(reportId)!]])
|
|
360
|
+
const all = findingIdsOf(workspace), ids = findingIdsOf(visible)
|
|
361
|
+
const revision = await teamAnnotationRevision(db, snapshot, [...all])
|
|
362
|
+
const { triage, comments, issues: savedIssues } = await db.getAnnotations([...ids])
|
|
363
|
+
const issues = Object.fromEntries(visibleManagedIssues(savedIssues, snapshot)
|
|
364
|
+
.map(issue => [issue.findingId, { url: issue.issueUrl!, autoFix: issue.autoFixUrl, duplicateOf: issue.duplicateOfUrl }]))
|
|
365
|
+
const entries = Object.fromEntries(triage.map(row => [row.findingId, triageWireEntry(row)]))
|
|
366
|
+
const annotated = new Set([...triage.map(row => row.findingId), ...comments.map(comment => comment.findingId), ...Object.keys(issues)])
|
|
367
|
+
const reports = Object.fromEntries([...visible].map(([id, report]) => [id, [...report.ids].filter(finding => annotated.has(finding))]))
|
|
368
|
+
return { reports, entries, comments, issues, revision: annotationRevisionDigest(revision) }
|
|
369
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TriageRow } from './db.ts'
|
|
2
|
+
import { type TriageEntryPatch, isTriageBucket } from '../common/managed/triage.ts'
|
|
3
|
+
|
|
4
|
+
// A stored triage row (current state or a trail event) → its wire entry: only
|
|
5
|
+
// set fields present, `false` kept for flagged (the explicit un-flag tombstone
|
|
6
|
+
// must round-trip), and null for the row of a cleared entry (every field
|
|
7
|
+
// null) — the reader adopts the clear.
|
|
8
|
+
export function triageWireEntry(row: Pick<TriageRow, 'color' | 'triage' | 'comment' | 'fix' | 'flagged'>, legacyHistory = false): TriageEntryPatch | null {
|
|
9
|
+
const e: TriageEntryPatch = {}
|
|
10
|
+
if (row.color != null) e.color = row.color
|
|
11
|
+
if (isTriageBucket(row.triage)) e.triage = row.triage
|
|
12
|
+
if (legacyHistory && row.comment != null) e.comment = row.comment
|
|
13
|
+
if (row.fix != null) e.fix = row.fix
|
|
14
|
+
if (row.flagged != null) e.flagged = row.flagged
|
|
15
|
+
return Object.keys(e).length > 0 ? e : null
|
|
16
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Whether a pair of a comparison's files changed in types alone (type-only.ts),
|
|
2
|
+
// told in a worker (type-only-worker.js): each a file a side, `{ path, text }`,
|
|
3
|
+
// a side not there null, its path as it is, which says what a file is.
|
|
4
|
+
//
|
|
5
|
+
// typeOnlyStamped: as @preventive/compare's compareTrees stamps a change
|
|
6
|
+
// `typeOnly`. Two paths pair as one change wherever compareTrees takes them
|
|
7
|
+
// for a rename at all; where it doesn't, the pair is types only where each of
|
|
8
|
+
// its two changes is: the file gone erasing whole, and the one come erasing
|
|
9
|
+
// whole or leaving a single bare `export {}`, which nothing loaded before.
|
|
10
|
+
//
|
|
11
|
+
// typeOnlyRuns: one it doesn't stamp may still hold types alone but for what
|
|
12
|
+
// runs on each side, each side there a declaration file proveTypeOnly proves,
|
|
13
|
+
// its runtime what changed: a module load added, gone or another, or a file
|
|
14
|
+
// added or removed that loads one, as a zod schema's declarations do. Told
|
|
15
|
+
// then are the lines that hold what runs on each side (`runs` the base's,
|
|
16
|
+
// `otherRuns` the other's, none for a side not there), for the viewer to diff
|
|
17
|
+
// those alone with its types set aside: the hashbang, each statement Node's
|
|
18
|
+
// type stripping leaves to run (a module load, `export {}`, `export default`
|
|
19
|
+
// of a name), each comment it keeps that may be one a tool reads (a
|
|
20
|
+
// triple-slash directive, a source map or source URL pragma), told wide of
|
|
21
|
+
// the proof's own grammar for them, so none it reads is ever set aside, and
|
|
22
|
+
// each enum, whose members compile into what reads them (runLines). A
|
|
23
|
+
// line holding any of it is told whole; a range is `[from, to)` of lines
|
|
24
|
+
// counted from zero, as the viewer splits a text at `\n`. None are told of
|
|
25
|
+
// a pair where a diff of those lines would not show what changed: a
|
|
26
|
+
// triple-slash comment that leads one side, where a directive steers, and
|
|
27
|
+
// stands below a statement on the other, where it is prose, its line the same
|
|
28
|
+
// on both (`moved`). Its diff is drawn whole, as one not proven is.
|
|
29
|
+
//
|
|
30
|
+
// Each sets aside a file's own source map comment, as tsc writes one with a
|
|
31
|
+
// declaration map: its last line exactly `//# sourceMappingURL=` its own name
|
|
32
|
+
// `.map`, a newline after it or none (withoutOwnMap). It names the file's own
|
|
33
|
+
// map, for a debugger alone, and is taken for one of its types: the file is
|
|
34
|
+
// proven, and its lines that run told, without it.
|
|
35
|
+
import { stripTypeScriptTypes } from 'node:module'
|
|
36
|
+
import { compareTrees, proveTypeOnly } from '@preventive/compare'
|
|
37
|
+
import { parseSync } from 'oxc-parser'
|
|
38
|
+
|
|
39
|
+
// A declaration file as compareTrees takes one: `.d.ts`, `.d.mts`, `.d.cts`,
|
|
40
|
+
// and `.d.css.ts` for a `.css` file's.
|
|
41
|
+
const DECLARATION = /\.d\.(?:[^./]+\.)?[cm]?ts$/u
|
|
42
|
+
// A comment that may be a directive (`/// <reference .../>`) or a pragma
|
|
43
|
+
// (`//# sourceMappingURL=`, and its legacy `//@` and block forms).
|
|
44
|
+
const STEERING = /^\/(?:\/\/|[/*][#@])/u
|
|
45
|
+
const BLANK = /^\s*$/u
|
|
46
|
+
|
|
47
|
+
const tree = file => (file ? [{ name: file.path, data: file.text }] : [])
|
|
48
|
+
|
|
49
|
+
// A file without its own source map comment, where its last line is that and
|
|
50
|
+
// nothing else: `//# sourceMappingURL=` and its name, `user.d.ts.map` for
|
|
51
|
+
// `types/user.d.ts`, ending the file with a newline or without. Any other
|
|
52
|
+
// name or spelling, or anything after it, and the file is as it is; so too
|
|
53
|
+
// where its own name is not plain (PLAIN_NAME): one holding a line terminator
|
|
54
|
+
// would end the comment within it, and what follows would run, so no other
|
|
55
|
+
// character than Latin letters, digits, `-`, `_` and `.` is taken in one.
|
|
56
|
+
const PLAIN_NAME = /^[A-Za-z0-9._-]+$/u
|
|
57
|
+
const plainName = path => {
|
|
58
|
+
const name = path.slice(path.lastIndexOf('/') + 1)
|
|
59
|
+
return PLAIN_NAME.test(name) ? name : null
|
|
60
|
+
}
|
|
61
|
+
function withoutOwnMap(file) {
|
|
62
|
+
if (file === null) return null
|
|
63
|
+
const name = plainName(file.path)
|
|
64
|
+
if (name === null) return file
|
|
65
|
+
const comment = `//# sourceMappingURL=${name}.map`
|
|
66
|
+
for (const last of [comment, `${comment}\n`]) {
|
|
67
|
+
const before = file.text.endsWith(last) ? file.text.slice(0, -last.length) : null
|
|
68
|
+
if (before !== null && (before === '' || before === '\uFEFF' || before.endsWith('\n'))) return { ...file, text: before }
|
|
69
|
+
}
|
|
70
|
+
return file
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Two the same but for their own source map comments changed nothing else:
|
|
74
|
+
// in types alone, where each is a declaration file proven to hold types alone.
|
|
75
|
+
export function typeOnlyStamped(from, to) {
|
|
76
|
+
const [base, other] = [from, to].map(withoutOwnMap)
|
|
77
|
+
const changes = compareTrees(tree(base), tree(other), { paths: 'keys', lines: false, renames: Number.MIN_VALUE })
|
|
78
|
+
if (changes.length > 0) return changes.every(change => change.typeOnly === true)
|
|
79
|
+
return [base, other].every(file => file !== null && DECLARATION.test(file.path) && proveTypeOnly(file.text).proven)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Each enum a program declares, wherever it stands: exported, or within a
|
|
83
|
+
// namespace, a module or `declare global`. Stripping erases one whole, yet its
|
|
84
|
+
// members are values: tsc writes a const enum's member into the code that
|
|
85
|
+
// reads it (`E.A` emitted as `1`), and a const enum's member may be computed
|
|
86
|
+
// from any enum's, so a change to one changes what runs elsewhere, and none is
|
|
87
|
+
// folded as types alone. Statements alone hold one, so lists of them alone are
|
|
88
|
+
// walked, a work list as namespaces nest.
|
|
89
|
+
function enumsOf(program) {
|
|
90
|
+
const found = [], lists = [program.body]
|
|
91
|
+
while (lists.length > 0) {
|
|
92
|
+
for (const statement of lists.pop()) {
|
|
93
|
+
let node = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement
|
|
94
|
+
if (node?.type === 'TSEnumDeclaration') found.push(node)
|
|
95
|
+
while (node?.type === 'TSModuleDeclaration') node = node.body
|
|
96
|
+
if (node?.type === 'TSModuleBlock') lists.push(node.body)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return found
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// The lines of a text proven to hold types alone but for what runs that hold
|
|
103
|
+
// any of that, as merged ranges (`lines`), and its triple-slash comments, by
|
|
104
|
+
// whether each leads it (`leading`, `below`). Stripping blanks what it erases
|
|
105
|
+
// in place, each character to a blank, so a statement it leaves blank is
|
|
106
|
+
// erased and one it leaves anything of runs, as the proof found, and a comment
|
|
107
|
+
// it leaves is kept; what it reads starts past a byte order mark, and so do
|
|
108
|
+
// the offsets in its tree. An enum, which stripping blanks, is told among them
|
|
109
|
+
// all the same (enumsOf), so that no fold sets one aside as types alone.
|
|
110
|
+
function runLines(text) {
|
|
111
|
+
const shift = text.startsWith('\uFEFF') ? 1 : 0
|
|
112
|
+
const body = text.slice(shift)
|
|
113
|
+
const code = stripTypeScriptTypes(body, { mode: 'strip' })
|
|
114
|
+
const { program, comments } = parseSync('file.ts', body, { lang: 'ts', sourceType: 'module' })
|
|
115
|
+
const kept = ({ start, end }) => code.slice(start, end)
|
|
116
|
+
const steering = comments.filter(comment => STEERING.test(kept(comment)))
|
|
117
|
+
const spans = [...program.hashbang ? [program.hashbang] : [], ...program.body.filter(statement => !BLANK.test(kept(statement))), ...steering, ...enumsOf(program)]
|
|
118
|
+
const starts = [0]
|
|
119
|
+
for (let at = text.indexOf('\n'); at !== -1; at = text.indexOf('\n', at + 1)) starts.push(at + 1)
|
|
120
|
+
// The line an offset of the text is on: the last whose start is at most it.
|
|
121
|
+
const lineAt = offset => {
|
|
122
|
+
let high = starts.length - 1, low = 0
|
|
123
|
+
while (low < high) {
|
|
124
|
+
const mid = Math.ceil((low + high) / 2)
|
|
125
|
+
if (starts[mid] <= offset) low = mid
|
|
126
|
+
else high = mid - 1
|
|
127
|
+
}
|
|
128
|
+
return low
|
|
129
|
+
}
|
|
130
|
+
const ranges = []
|
|
131
|
+
for (const { start, end } of spans.toSorted((a, b) => a.start - b.start)) {
|
|
132
|
+
const from = lineAt(shift + start), to = lineAt(shift + Math.max(start, end - 1)) + 1
|
|
133
|
+
const last = ranges.at(-1)
|
|
134
|
+
if (last && from <= last[1]) last[1] = Math.max(last[1], to)
|
|
135
|
+
else ranges.push([from, to])
|
|
136
|
+
}
|
|
137
|
+
// Its triple-slash comments, by their text: those that lead it, before its
|
|
138
|
+
// first statement, where alone a directive steers, and those below one.
|
|
139
|
+
const first = program.body[0]?.start ?? Infinity
|
|
140
|
+
const slashed = leads => new Set(steering.filter(comment => (comment.start < first) === leads).map(kept).filter(comment => comment.startsWith('///')))
|
|
141
|
+
return { lines: ranges, leading: slashed(true), below: slashed(false) }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Whether a triple-slash comment that leads `one` side stands only below a
|
|
145
|
+
// statement on the `other`: a directive that steers on one alone, though its
|
|
146
|
+
// line reads the same on both.
|
|
147
|
+
const moved = (one, other) => [...one.leading].some(comment => !other.leading.has(comment) && other.below.has(comment))
|
|
148
|
+
|
|
149
|
+
// A declaration file's lines that run, as the proof tells them, but for its own
|
|
150
|
+
// map comment; null for any other file, or where they can't be told.
|
|
151
|
+
export function declarationRuns(path, text) {
|
|
152
|
+
if (!DECLARATION.test(path)) return null
|
|
153
|
+
try {
|
|
154
|
+
return runLines(withoutOwnMap({ path, text }).text).lines
|
|
155
|
+
} catch {
|
|
156
|
+
return null
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// What a file's lines that run depend on besides its text: a declaration
|
|
161
|
+
// file's name, which its own map comment names, or '' where it is no plain
|
|
162
|
+
// name (withoutOwnMap); null for any other file.
|
|
163
|
+
export const runsName = path => (DECLARATION.test(path) ? plainName(path) ?? '' : null)
|
|
164
|
+
|
|
165
|
+
// `{ runs, otherRuns }` where each side there is a declaration file proven to
|
|
166
|
+
// hold types alone but for what runs, and no directive steers on one side
|
|
167
|
+
// alone unseen (`moved`); else false, and where the proof throws, as no
|
|
168
|
+
// check should. Asked of a pair not stamped, which always runs some.
|
|
169
|
+
export function typeOnlyRuns(...pair) {
|
|
170
|
+
const [from, to] = pair.map(withoutOwnMap)
|
|
171
|
+
const sides = [from, to].filter(file => file !== null)
|
|
172
|
+
if (sides.length === 0 || !sides.every(file => DECLARATION.test(file.path))) return false
|
|
173
|
+
try {
|
|
174
|
+
if (!sides.every(file => proveTypeOnly(file.text).proven)) return false
|
|
175
|
+
const [base, other] = [from, to].map(file => (file ? runLines(file.text) : null))
|
|
176
|
+
if (base && other && (moved(base, other) || moved(other, base))) return false
|
|
177
|
+
return { runs: base?.lines ?? [], otherRuns: other?.lines ?? [] }
|
|
178
|
+
} catch {
|
|
179
|
+
return false
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Which of a comparison's pairs of files changed in types alone (type-only.ts),
|
|
2
|
+
// off the server's event loop, as type-only-proof.js tells each. Told first,
|
|
3
|
+
// `{ stamped }`, is whether each is stamped, by pair: what runs is worked out
|
|
4
|
+
// after, so that it cannot cost a stamp the worker's deadline, however long
|
|
5
|
+
// one file's takes. Then, where asked for (`runsUntil` a time, not null),
|
|
6
|
+
// what runs of each pair not stamped, `{ at, runs, otherRuns }` as each is
|
|
7
|
+
// found, the smallest files first, so that one that takes long keeps the
|
|
8
|
+
// fewest waiting, and none begun once `runsUntil` has come. Last, its answer,
|
|
9
|
+
// by pair: `true`, `{ runs, otherRuns }` for one that holds types alone but
|
|
10
|
+
// for what runs, or `false`, as for one not asked for or not come to.
|
|
11
|
+
import { parentPort, workerData } from 'node:worker_threads'
|
|
12
|
+
import { typeOnlyRuns, typeOnlyStamped } from './type-only-proof.js'
|
|
13
|
+
|
|
14
|
+
const { pairs, runsUntil } = workerData
|
|
15
|
+
// Node worker messages have no browser target origin.
|
|
16
|
+
// oxlint-disable-next-line unicorn/require-post-message-target-origin
|
|
17
|
+
const tell = told => parentPort.postMessage(told)
|
|
18
|
+
const answer = pairs.map(([from, to]) => typeOnlyStamped(from, to))
|
|
19
|
+
tell({ stamped: answer })
|
|
20
|
+
if (runsUntil !== null) {
|
|
21
|
+
const size = ([from, to]) => (from?.text.length ?? 0) + (to?.text.length ?? 0)
|
|
22
|
+
const rest = [...pairs.keys()].filter(at => !answer[at]).toSorted((a, b) => size(pairs[a]) - size(pairs[b]))
|
|
23
|
+
for (const at of rest) {
|
|
24
|
+
if (Date.now() >= runsUntil) break
|
|
25
|
+
const runs = typeOnlyRuns(...pairs[at])
|
|
26
|
+
if (!runs) continue
|
|
27
|
+
answer[at] = runs
|
|
28
|
+
tell({ at, ...runs })
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
tell(answer)
|