@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,180 @@
|
|
|
1
|
+
import type { ServerResponse } from 'node:http'
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises'
|
|
3
|
+
import type { ManagedHttpDeps } from './http.ts'
|
|
4
|
+
import type { StoredUser, TeamReportAccessSnapshot } from './db.ts'
|
|
5
|
+
import { TeamReportsError, annotationRevisionDigest, teamAnnotationRevision, teamSnapshotKey, teamWorkspaceFindingIds } from './team-reports.ts'
|
|
6
|
+
import type { WorkspaceShareFeedState } from './workspace-shares.ts'
|
|
7
|
+
|
|
8
|
+
// Short database reads work across instances without pinning a Neon connection.
|
|
9
|
+
// All polling belongs to the awaited request; nothing runs after it completes.
|
|
10
|
+
const TEAM_FEED_POLL_MS = 3_000
|
|
11
|
+
export const TEAM_FEED_LIFETIME_MS = 240_000 // below the configured Vercel 300s
|
|
12
|
+
const HEARTBEAT_MS = 15_000
|
|
13
|
+
|
|
14
|
+
type FeedOptions = { pollMs?: number; lifetimeMs?: number }
|
|
15
|
+
type Publish = (event: 'teams' | 'triage', revision: string | undefined) => boolean
|
|
16
|
+
|
|
17
|
+
// Public capabilities remain scoped to their single shared workspace.
|
|
18
|
+
export async function serveTeamFeed(res: ServerResponse, deps: ManagedHttpDeps,
|
|
19
|
+
snapshot: TeamReportAccessSnapshot, recheck: () => Promise<void>,
|
|
20
|
+
options: FeedOptions & { readState?: () => Promise<WorkspaceShareFeedState | null> } = {}): Promise<void> {
|
|
21
|
+
let ids: string[] | undefined
|
|
22
|
+
let previous: WorkspaceShareFeedState | undefined
|
|
23
|
+
const sameAccess = (a: WorkspaceShareFeedState, b?: WorkspaceShareFeedState) => a.grant === b?.grant && a.catalog === b.catalog
|
|
24
|
+
const readState = async () => {
|
|
25
|
+
const state = await options.readState!()
|
|
26
|
+
if (!state) throw new TeamReportsError(404, 'workspace-changed')
|
|
27
|
+
return state
|
|
28
|
+
}
|
|
29
|
+
await serveFeed(res, deps, async publish => {
|
|
30
|
+
const state = options.readState ? await readState() : undefined
|
|
31
|
+
// The first poll still compares the full snapshot loaded before the stream.
|
|
32
|
+
// Unchanged polls validate the live grant without reading report catalogs.
|
|
33
|
+
if (state && sameAccess(state, previous)) {
|
|
34
|
+
if (state.annotations === previous!.annotations) return
|
|
35
|
+
} else await recheck()
|
|
36
|
+
ids ??= [...await teamWorkspaceFindingIds(deps.db, deps.reportStore, snapshot)]
|
|
37
|
+
const triage = await deps.db.getAnnotationRevision(ids)
|
|
38
|
+
const after = options.readState ? await readState() : undefined
|
|
39
|
+
if (!after || !sameAccess(after, state)) await recheck()
|
|
40
|
+
publish('triage', triage)
|
|
41
|
+
// A write during the read must remain pending for the following poll.
|
|
42
|
+
if (after?.annotations === state?.annotations) previous = after
|
|
43
|
+
}, options)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Membership and content notifications cover all of the user's teams. Only
|
|
47
|
+
// the focused team needs report parsing or annotation reads; null is the
|
|
48
|
+
// catalog-only subscription used on landing and management pages.
|
|
49
|
+
export async function serveUserTeamFeed(res: ServerResponse, deps: ManagedHttpDeps,
|
|
50
|
+
sessionId: string, user: StoredUser, teamId: string | null, options: FeedOptions & { reportId?: string | null } = {}): Promise<void> {
|
|
51
|
+
let ids: string[] = [], visibilityKey: string | undefined
|
|
52
|
+
let focused: TeamReportAccessSnapshot | undefined
|
|
53
|
+
let previousState: { catalog: number; annotations: number } | undefined
|
|
54
|
+
const checkUser = (current: { user: Pick<StoredUser, 'id' | 'role'> } | null) => {
|
|
55
|
+
if (!current) throw new TeamReportsError(401, 'unauthenticated')
|
|
56
|
+
if (current.user.id !== user.id || current.user.role !== user.role || current.user.role === 'none') {
|
|
57
|
+
throw new TeamReportsError(403, 'access-changed')
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
await serveFeed(res, deps, async publish => {
|
|
61
|
+
const state = await deps.db.getFeedState(sessionId, Date.now())
|
|
62
|
+
checkUser(state)
|
|
63
|
+
if (state!.catalog === previousState?.catalog && (!teamId || state!.annotations === previousState?.annotations)) return
|
|
64
|
+
if (teamId && focused !== undefined && state!.catalog === previousState?.catalog) {
|
|
65
|
+
// Annotation changes cannot change visibility. Read only this workspace's
|
|
66
|
+
// IDs, then fence against concurrent access/content changes before sending.
|
|
67
|
+
const triage = await teamAnnotationRevision(deps.db, focused, ids)
|
|
68
|
+
const after = await deps.db.getFeedState(sessionId, Date.now())
|
|
69
|
+
checkUser(after)
|
|
70
|
+
if (after!.catalog !== state!.catalog) return
|
|
71
|
+
publish('triage', triage)
|
|
72
|
+
if (after!.annotations === state!.annotations) previousState = state!
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
const catalog = await deps.db.getUserTeamFeedSnapshot(sessionId, Date.now())
|
|
76
|
+
checkUser(catalog)
|
|
77
|
+
// The session read again after the catalog, as the catalog is published
|
|
78
|
+
// next: one statement, as the poll's own check is.
|
|
79
|
+
checkUser(await deps.db.getFeedState(sessionId, Date.now()))
|
|
80
|
+
// Publish catalog state before loading any report blobs. A slow or broken
|
|
81
|
+
// focused report must not hide membership/content changes from the client.
|
|
82
|
+
if (!publish('teams', catalog!.revision)) return
|
|
83
|
+
if (!teamId) {
|
|
84
|
+
// A mutation during the snapshot must cause a fresh read next poll.
|
|
85
|
+
const current = await deps.db.getFeedState(sessionId, Date.now())
|
|
86
|
+
checkUser(current)
|
|
87
|
+
if (current!.catalog === state!.catalog) previousState = state!
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
let triage: string | undefined
|
|
91
|
+
const snapshot = await deps.db.getTeamReportAccessSnapshot(sessionId, Date.now(), teamId, options.reportId)
|
|
92
|
+
if (!snapshot) throw new TeamReportsError(401, 'unauthenticated')
|
|
93
|
+
checkUser(snapshot)
|
|
94
|
+
const key = teamSnapshotKey(snapshot)
|
|
95
|
+
if (key !== visibilityKey) {
|
|
96
|
+
try {
|
|
97
|
+
ids = snapshot.teamId ? [...await teamWorkspaceFindingIds(deps.db, deps.reportStore, snapshot)] : []
|
|
98
|
+
visibilityKey = key
|
|
99
|
+
} catch {
|
|
100
|
+
// Missing, malformed or temporarily unavailable blobs only suspend
|
|
101
|
+
// triage. Retry visibility on the next poll, even for the same key.
|
|
102
|
+
publish('triage', undefined)
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// As GET /api/teams/:id/annotations answers it, so that a client holding
|
|
107
|
+
// that answer knows this tells nothing new.
|
|
108
|
+
if (snapshot.teamId) triage = await teamAnnotationRevision(deps.db, snapshot, ids)
|
|
109
|
+
const current = await deps.db.getTeamReportAccessSnapshot(sessionId, Date.now(), teamId, options.reportId)
|
|
110
|
+
// A concurrent access/content change discards only the annotation read.
|
|
111
|
+
checkUser(current)
|
|
112
|
+
if (!current || teamSnapshotKey(current) !== key) return
|
|
113
|
+
publish('triage', triage)
|
|
114
|
+
focused = snapshot.teamId ? snapshot : undefined
|
|
115
|
+
const after = await deps.db.getFeedState(sessionId, Date.now())
|
|
116
|
+
checkUser(after)
|
|
117
|
+
if (after!.catalog === state!.catalog && after!.annotations === state!.annotations) previousState = state!
|
|
118
|
+
}, { ...options, triageRevision: true })
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// With `triageRevision`, a triage event tells its revision's digest, as the
|
|
122
|
+
// focused team's annotations answer it; else none, as a public share's.
|
|
123
|
+
async function serveFeed(res: ServerResponse, deps: ManagedHttpDeps, read: (publish: Publish) => Promise<void>,
|
|
124
|
+
{ pollMs = TEAM_FEED_POLL_MS, lifetimeMs = TEAM_FEED_LIFETIME_MS, triageRevision = false }: FeedOptions & { triageRevision?: boolean }): Promise<void> {
|
|
125
|
+
const controller = new AbortController()
|
|
126
|
+
const close = () => controller.abort()
|
|
127
|
+
res.once('close', close)
|
|
128
|
+
const deadline = setTimeout(close, lifetimeMs)
|
|
129
|
+
const stopped = () => controller.signal.aborted || res.destroyed || deps.isShuttingDown()
|
|
130
|
+
// Notifications carry no annotation bodies, finding IDs, or global cursors.
|
|
131
|
+
// The catalog's opaque version, and a focused team's annotation revision's
|
|
132
|
+
// digest, let clients reuse an identical REST snapshot; every connection
|
|
133
|
+
// still confirms current access, including after reconnects.
|
|
134
|
+
function write(frame: string): boolean {
|
|
135
|
+
if (stopped()) return false
|
|
136
|
+
if (res.write(frame)) return true
|
|
137
|
+
// Slow consumers reconnect and read current state; never queue a backlog.
|
|
138
|
+
res.destroy()
|
|
139
|
+
return false
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
if (stopped()) return
|
|
143
|
+
res.writeHead(200, { 'content-type': 'text/event-stream; charset=utf-8',
|
|
144
|
+
'cache-control': 'private, no-store, no-transform', 'x-accel-buffering': 'no',
|
|
145
|
+
'x-content-type-options': 'nosniff', 'referrer-policy': 'no-referrer' })
|
|
146
|
+
res.flushHeaders()
|
|
147
|
+
let heartbeat = Date.now()
|
|
148
|
+
const previous = new Map<string, string>()
|
|
149
|
+
const publish: Publish = (event, revision) => {
|
|
150
|
+
if (stopped()) return false
|
|
151
|
+
if (revision === undefined) { previous.delete(event); return true }
|
|
152
|
+
if (revision === previous.get(event)) return true
|
|
153
|
+
const data = event === 'teams' ? JSON.stringify({ revision }) : triageRevision ? JSON.stringify({ revision: annotationRevisionDigest(revision) }) : '{}'
|
|
154
|
+
if (!write(`event: ${event}\ndata: ${data}\n\n`)) return false
|
|
155
|
+
previous.set(event, revision)
|
|
156
|
+
heartbeat = Date.now()
|
|
157
|
+
return true
|
|
158
|
+
}
|
|
159
|
+
while (!stopped()) {
|
|
160
|
+
if (deps.db.withRequest) await deps.db.withRequest(() => read(publish))
|
|
161
|
+
else await read(publish)
|
|
162
|
+
if (stopped()) break
|
|
163
|
+
if (Date.now() - heartbeat >= HEARTBEAT_MS) {
|
|
164
|
+
if (!write(': keepalive\n\n')) break
|
|
165
|
+
heartbeat = Date.now()
|
|
166
|
+
}
|
|
167
|
+
await delay(pollMs, undefined, { signal: controller.signal }).catch(error => {
|
|
168
|
+
if (!controller.signal.aborted) throw error
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
} catch (error) {
|
|
172
|
+
if (!res.headersSent) throw error
|
|
173
|
+
if (error instanceof TeamReportsError) write('event: close\ndata: {}\n\n')
|
|
174
|
+
else if (!stopped()) throw error
|
|
175
|
+
} finally {
|
|
176
|
+
clearTimeout(deadline)
|
|
177
|
+
res.off('close', close)
|
|
178
|
+
if (res.headersSent && !res.destroyed) res.end()
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// A team's icon: the avatar of a GitHub organization owning one of the
|
|
2
|
+
// team's repositories, chosen on Manage → Teams (POST /api/admin/teams/set-icon),
|
|
3
|
+
// or none, the default icon. A user's own account is never offered: only
|
|
4
|
+
// owners GitHub tells are organizations. The organization is kept by its
|
|
5
|
+
// numeric id, which survives a rename, and its login as it was when chosen.
|
|
6
|
+
// The icon stays until it is changed, though the team's repositories change.
|
|
7
|
+
// Its avatar is served as `/api/avatar/org-<id>` (http.ts).
|
|
8
|
+
import type { ManagedConfig } from './config.ts'
|
|
9
|
+
import type { SelectedRepo, TeamIcon } from './db-methods.ts'
|
|
10
|
+
import { accountOf } from './github-accounts.ts'
|
|
11
|
+
import { repoAccessToken } from './github-app.ts'
|
|
12
|
+
import { githubJson } from './github-requests.ts'
|
|
13
|
+
import { LOGIN } from './github-values.ts'
|
|
14
|
+
import { eachOf } from './queue.ts'
|
|
15
|
+
import { currentMetadata } from './repository-browser.ts'
|
|
16
|
+
|
|
17
|
+
// The organizations a team may show, by login, and the owners of its
|
|
18
|
+
// repositories GitHub could not be asked about, by their names' owner.
|
|
19
|
+
export interface TeamIconChoices { organizations: TeamIcon[]; unchecked: string[] }
|
|
20
|
+
|
|
21
|
+
// What `/api/avatar/org-<id>` names: an organization by its id.
|
|
22
|
+
export const ORGANIZATION_AVATAR = /^org-([1-9]\d{0,11})$/u
|
|
23
|
+
// A GitHub login, as a team's icon is asked for by (no App's `[bot]`).
|
|
24
|
+
export const isOrganizationLogin = (value: unknown): value is string => typeof value === 'string' && LOGIN.test(value) && !value.endsWith('[bot]')
|
|
25
|
+
|
|
26
|
+
const ownerOf = (fullName: string) => fullName.split('/', 1)[0]!.toLowerCase()
|
|
27
|
+
const GITHUB_REQUESTS_AT_ONCE = 4
|
|
28
|
+
|
|
29
|
+
// The organizations owning `repos` (a team's), each once, sorted by login, as
|
|
30
|
+
// GitHub tells each repository's owner now, one renamed or transferred since
|
|
31
|
+
// included (currentMetadata); and the owners, as the repositories are named,
|
|
32
|
+
// of those GitHub could not be asked about, past any it told of.
|
|
33
|
+
export async function teamOrganizations(config: ManagedConfig, repos: readonly SelectedRepo[], fetchImpl: typeof fetch): Promise<TeamIconChoices> {
|
|
34
|
+
const told = await eachOf([...repos], GITHUB_REQUESTS_AT_ONCE, async (repo) => {
|
|
35
|
+
try {
|
|
36
|
+
const token = await repoAccessToken(config, repo.installationId, fetchImpl)
|
|
37
|
+
const { owner } = await currentMetadata({ ...repo }, url => githubJson(url, token, fetchImpl), undefined)
|
|
38
|
+
const { id, login } = accountOf(owner as { id?: unknown; login?: unknown } | undefined)
|
|
39
|
+
return { repo, icon: id !== null && (owner as { type?: unknown }).type === 'Organization' ? { id, login: login! } : null }
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.warn(`managed: team icon owner of ${repo.fullName} unread:`, err instanceof Error ? err.message : err)
|
|
42
|
+
return { repo, icon: undefined }
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
const read = new Set(told.flatMap(({ repo, icon }) => icon === undefined ? [] : [ownerOf(repo.fullName)]))
|
|
46
|
+
return {
|
|
47
|
+
organizations: [...new Map(told.flatMap(({ icon }) => icon ? [[icon.id, icon] as const] : [])).values()].toSorted((a, b) => a.login.localeCompare(b.login)),
|
|
48
|
+
unchecked: [...new Set(told.flatMap(({ repo, icon }) => icon === undefined && !read.has(ownerOf(repo.fullName)) ? [ownerOf(repo.fullName)] : []))].toSorted(),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// npm scopes a team lists: its members, whatever their role, may read that
|
|
2
|
+
// scope's private packages in the npm viewer (npm-packages.ts), as admins and
|
|
3
|
+
// managers may read any. Hidden teams grant nothing, as for their content.
|
|
4
|
+
import { MAX_TEAM_NPM_SCOPES, normalizeNpmScope } from '../common/managed/npm-packages.js'
|
|
5
|
+
import type { Role } from '../common/managed/roles.ts'
|
|
6
|
+
import { reviewsIn } from './dependency-reviews.ts'
|
|
7
|
+
import { ManagedMutationError, sessionAdmin } from './management.ts'
|
|
8
|
+
import { type ManagedSql, jsonRows } from './sql.ts'
|
|
9
|
+
|
|
10
|
+
export const TEAM_NPM_SCOPE_SCHEMA = `
|
|
11
|
+
CREATE TABLE IF NOT EXISTS managed_team_npm_scope (
|
|
12
|
+
team_id TEXT NOT NULL REFERENCES managed_team(id) ON DELETE CASCADE,
|
|
13
|
+
scope TEXT NOT NULL,
|
|
14
|
+
PRIMARY KEY (team_id, scope)
|
|
15
|
+
) STRICT;
|
|
16
|
+
`
|
|
17
|
+
|
|
18
|
+
export interface TeamNpmScopeStore {
|
|
19
|
+
// Every team's scopes, sorted, keyed by team id; teams without any are absent.
|
|
20
|
+
listTeamNpmScopes(): Promise<Record<string, string[]>>
|
|
21
|
+
// Replaces a team's scopes; admin only. Answers what changed, or null for no team.
|
|
22
|
+
setTeamNpmScopes(sessionId: string, teamId: string, scopes: unknown): Promise<{ added: string[]; removed: string[] } | null>
|
|
23
|
+
// The scopes a user's visible teams list.
|
|
24
|
+
listUserNpmScopes(userId: string): Promise<string[]>
|
|
25
|
+
// Whether any visible team lists the scope: whoever reads its packages,
|
|
26
|
+
// they are the instance's own, whose new releases aren't flagged (http.ts).
|
|
27
|
+
hasTeamNpmScope(scope: string): Promise<boolean>
|
|
28
|
+
// Who session `sessionId` names now, as readSession reads it, their own
|
|
29
|
+
// or, where `viewerSessionId` names an admin's own one, a view of it: their
|
|
30
|
+
// role, the scopes their teams list (listUserNpmScopes), and whether they
|
|
31
|
+
// read the dependency reviews published to team `teamId`
|
|
32
|
+
// (dependency-reviews.ts reviewsIn); in one statement, as a list of a
|
|
33
|
+
// team's reviews asks again once npm is read. Null where it names none.
|
|
34
|
+
getNpmReviewReader(sessionId: string, viewerSessionId: string | null, now: number, teamId: string): Promise<NpmReviewReader | null>
|
|
35
|
+
}
|
|
36
|
+
export interface NpmReviewReader { id: string; role: Role; scopes: string[]; readsTeam: boolean }
|
|
37
|
+
|
|
38
|
+
// Each distinct scope, normalized; a list with one npm could not publish
|
|
39
|
+
// under, or too many, is refused whole.
|
|
40
|
+
export function parseTeamNpmScopes(input: unknown): string[] {
|
|
41
|
+
if (!Array.isArray(input)) throw new ManagedMutationError(400, 'bad-scopes')
|
|
42
|
+
const scopes = new Set<string>()
|
|
43
|
+
for (const value of input) {
|
|
44
|
+
const scope = normalizeNpmScope(value)
|
|
45
|
+
if (scope === null) throw new ManagedMutationError(400, 'bad-scope')
|
|
46
|
+
scopes.add(scope)
|
|
47
|
+
}
|
|
48
|
+
if (scopes.size > MAX_TEAM_NPM_SCOPES) throw new ManagedMutationError(400, 'too-many-scopes')
|
|
49
|
+
return [...scopes].toSorted()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function teamNpmScopeMethods(db: ManagedSql): TeamNpmScopeStore {
|
|
53
|
+
return {
|
|
54
|
+
async listTeamNpmScopes() {
|
|
55
|
+
const rows = await db.prepare('SELECT team_id AS teamId, scope FROM managed_team_npm_scope ORDER BY team_id, scope').all() as { teamId: string; scope: string }[]
|
|
56
|
+
const result: Record<string, string[]> = {}
|
|
57
|
+
for (const { teamId, scope } of rows) (result[teamId] ??= []).push(scope)
|
|
58
|
+
return result
|
|
59
|
+
},
|
|
60
|
+
async setTeamNpmScopes(sessionId, teamId, input) {
|
|
61
|
+
await sessionAdmin(db, sessionId)
|
|
62
|
+
const scopes = parseTeamNpmScopes(input)
|
|
63
|
+
if (!await db.prepare('SELECT id FROM managed_team WHERE id = ?').get(teamId)) return null
|
|
64
|
+
const current = (await db.prepare('SELECT scope FROM managed_team_npm_scope WHERE team_id = ?').all(teamId) as { scope: string }[]).map(row => row.scope)
|
|
65
|
+
const removed = current.filter(scope => !scopes.includes(scope)).toSorted()
|
|
66
|
+
const added = scopes.filter(scope => !current.includes(scope))
|
|
67
|
+
for (const scope of removed) await db.prepare('DELETE FROM managed_team_npm_scope WHERE team_id = ? AND scope = ?').run(teamId, scope)
|
|
68
|
+
for (const scope of added) await db.prepare('INSERT INTO managed_team_npm_scope (team_id, scope) VALUES (?, ?)').run(teamId, scope)
|
|
69
|
+
return { added, removed }
|
|
70
|
+
},
|
|
71
|
+
async listUserNpmScopes(userId) {
|
|
72
|
+
const rows = await db.prepare(`SELECT DISTINCT ns.scope FROM managed_team_user tu
|
|
73
|
+
JOIN managed_team t ON t.id = tu.team_id AND t.hidden = 0
|
|
74
|
+
JOIN managed_team_npm_scope ns ON ns.team_id = tu.team_id
|
|
75
|
+
WHERE tu.user_id = ? ORDER BY ns.scope`).all(userId) as { scope: string }[]
|
|
76
|
+
return rows.map(row => row.scope)
|
|
77
|
+
},
|
|
78
|
+
getNpmReviewReader: (sessionId, viewerSessionId, now, teamId) => npmReviewReader(db, sessionId, viewerSessionId, now, teamId),
|
|
79
|
+
async hasTeamNpmScope(scope) {
|
|
80
|
+
return !!await db.prepare(`SELECT 1 AS listed FROM managed_team_npm_scope ns
|
|
81
|
+
JOIN managed_team t ON t.id = ns.team_id AND t.hidden = 0
|
|
82
|
+
WHERE ns.scope = ? LIMIT 1`).get(scope)
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// getNpmReviewReader's statement, its session held to what readSession's
|
|
88
|
+
// own are (db-methods.ts selectOwnSessionStmt, selectViewSessionStmt).
|
|
89
|
+
async function npmReviewReader(db: ManagedSql, sessionId: string, viewerSessionId: string | null, now: number, teamId: string): Promise<NpmReviewReader | null> {
|
|
90
|
+
const row = await db.prepare(`WITH reader AS (
|
|
91
|
+
SELECT u.id AS id, u.role AS role FROM managed_session s JOIN managed_user u ON u.id = s.user_id
|
|
92
|
+
WHERE s.id = ? AND s.expires_at > ? AND ((? IS NULL AND s.viewer_session IS NULL) OR (s.viewer_session = ? AND EXISTS (
|
|
93
|
+
SELECT 1 FROM managed_session p JOIN managed_user a ON a.id = p.user_id
|
|
94
|
+
WHERE p.id = s.viewer_session AND p.expires_at > ? AND p.viewer_session IS NULL AND a.role = 'admin')))
|
|
95
|
+
)
|
|
96
|
+
SELECT v.id AS id, v.role AS role,
|
|
97
|
+
(SELECT json_group_array(x.scope ORDER BY x.scope) FROM (SELECT DISTINCT ns.scope AS scope FROM managed_team_user tu
|
|
98
|
+
JOIN managed_team t ON t.id = tu.team_id AND t.hidden = 0 JOIN managed_team_npm_scope ns ON ns.team_id = tu.team_id
|
|
99
|
+
WHERE tu.user_id = v.id) x) AS scopes,
|
|
100
|
+
CASE WHEN EXISTS (SELECT 1 FROM managed_team t JOIN managed_user u ON u.id = v.id WHERE t.id = ? AND ${reviewsIn(false)}) THEN 1 ELSE 0 END AS readsTeam
|
|
101
|
+
FROM reader v`).get(sessionId, now, viewerSessionId, viewerSessionId, now, teamId) as { id: string; role: Role; scopes: unknown; readsTeam: unknown } | undefined
|
|
102
|
+
return row ? { id: row.id, role: row.role, scopes: jsonRows<string>(row.scopes), readsTeam: Number(row.readsTeam) === 1 } : null
|
|
103
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// What the landing counts of each of a reader's teams, and of all of them
|
|
2
|
+
// together: the findings triaged In progress and Fixed, and the GitHub issues
|
|
3
|
+
// (open, closed) and pull requests (open, merged) linked to its findings, as
|
|
4
|
+
// GET /api/teams/<id>/fixes reads them (github-pulls.ts workspaceFixUrls), by
|
|
5
|
+
// their status as last read of GitHub (cachedFixStatuses).
|
|
6
|
+
// GitHub is never asked: an item not read yet counts in neither, as does a
|
|
7
|
+
// pull request closed unmerged. A finding or item several teams share counts
|
|
8
|
+
// once in the total.
|
|
9
|
+
import type { BlobStore } from './blob-store.ts'
|
|
10
|
+
import type { ManagedDb } from './db.ts'
|
|
11
|
+
import { type CachedFixStatus, cachedFixStatuses, workspaceFixUrls } from './github-pulls.ts'
|
|
12
|
+
import { visibleManagedIssues } from './managed-issues.ts'
|
|
13
|
+
import { eachOf } from './queue.ts'
|
|
14
|
+
import { CLASSIFY_CONCURRENCY } from './team-app.ts'
|
|
15
|
+
import { TeamReportsError, recheckTeam, teamSnapshot, teamWorkspaceFindingIds } from './team-reports.ts'
|
|
16
|
+
|
|
17
|
+
export interface TeamProgress {
|
|
18
|
+
inprogress: number
|
|
19
|
+
fixed: number
|
|
20
|
+
issues: { open: number; closed: number }
|
|
21
|
+
pulls: { open: number; merged: number }
|
|
22
|
+
}
|
|
23
|
+
// A team's In progress and Fixed findings, by their IDs, and its linked items'
|
|
24
|
+
// statuses, by their cache keys: what its progress counts, and the total
|
|
25
|
+
// counts each once.
|
|
26
|
+
interface Tally {
|
|
27
|
+
findings: Map<string, 'inprogress' | 'fixed'>
|
|
28
|
+
items: Map<string, CachedFixStatus>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// A team's, as its reader's workspace of it shows it (teamWorkspaceFindingIds);
|
|
32
|
+
// null where it shows none now: too large or unreadable, or changed while it
|
|
33
|
+
// was read. A session ended while it is read ends the request.
|
|
34
|
+
async function tallyTeam(db: ManagedDb, store: BlobStore, sessionId: string, teamId: string): Promise<Tally | null> {
|
|
35
|
+
try {
|
|
36
|
+
const snapshot = await teamSnapshot(db, sessionId, teamId)
|
|
37
|
+
const ids = [...await teamWorkspaceFindingIds(db, store, snapshot)]
|
|
38
|
+
const [rows, issues] = await Promise.all([db.listTriage(ids), db.listManagedIssues(ids)])
|
|
39
|
+
const findings: Tally['findings'] = new Map()
|
|
40
|
+
for (const row of rows) if (row.triage === 'inprogress' || row.triage === 'fixed') findings.set(row.findingId, row.triage)
|
|
41
|
+
const items = await cachedFixStatuses(db, snapshot, workspaceFixUrls(rows.map(row => row.fix), visibleManagedIssues(issues, snapshot)))
|
|
42
|
+
await recheckTeam(db, sessionId, snapshot)
|
|
43
|
+
return { findings, items }
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error instanceof TeamReportsError && error.status !== 401) return null
|
|
46
|
+
throw error
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function count({ findings, items }: Tally): TeamProgress {
|
|
51
|
+
const progress: TeamProgress = { inprogress: 0, fixed: 0, issues: { open: 0, closed: 0 }, pulls: { open: 0, merged: 0 } }
|
|
52
|
+
for (const triage of findings.values()) progress[triage]++
|
|
53
|
+
for (const { kind, status } of items.values()) {
|
|
54
|
+
if (kind === 'issue') {
|
|
55
|
+
if (status === 'open') progress.issues.open++
|
|
56
|
+
else if (status === 'closed') progress.issues.closed++
|
|
57
|
+
} else if (status === 'open' || status === 'draft') progress.pulls.open++
|
|
58
|
+
else if (status === 'merged') progress.pulls.merged++
|
|
59
|
+
}
|
|
60
|
+
return progress
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Those of `teamIds` (a reader's catalog), by team, a team counted none of
|
|
64
|
+
// left out, and their total.
|
|
65
|
+
export async function teamProgress(db: ManagedDb, store: BlobStore, sessionId: string, teamIds: readonly string[]): Promise<{ teams: Record<string, TeamProgress>; total: TeamProgress }> {
|
|
66
|
+
// Each team's workspace a cold instance builds as its catalog does.
|
|
67
|
+
const tallies = await eachOf(teamIds, CLASSIFY_CONCURRENCY, teamId => tallyTeam(db, store, sessionId, teamId))
|
|
68
|
+
const teams: Record<string, TeamProgress> = {}
|
|
69
|
+
const all: Tally = { findings: new Map(), items: new Map() }
|
|
70
|
+
tallies.forEach((tally, index) => {
|
|
71
|
+
if (!tally) return
|
|
72
|
+
teams[teamIds[index]!] = count(tally)
|
|
73
|
+
for (const [id, triage] of tally.findings) all.findings.set(id, triage)
|
|
74
|
+
for (const [key, item] of tally.items) all.items.set(key, item)
|
|
75
|
+
})
|
|
76
|
+
return { teams, total: count(all) }
|
|
77
|
+
}
|