@preventive/triage 1.0.0-alpha.6 → 1.0.0-alpha.60
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 +17 -0
- 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 +3 -0
- package/common/bundle-compare-diff.js +376 -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-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 +2 -0
- package/common/bundle-reasons.js +21 -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 +7 -0
- package/common/bundle-sources.js +333 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +65 -0
- package/common/default-scan-models.ts +35 -0
- package/common/dependency-reviews.d.ts +18 -0
- package/common/dependency-reviews.js +64 -0
- package/common/finding-duplicates.js +58 -0
- package/common/finding-filters.js +274 -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 +1 -0
- package/common/github-issue-labels.js +11 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +8 -0
- package/common/line-diff.js +57 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +34 -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 +44 -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 +7 -0
- package/common/managed/npm-packages.js +51 -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/roles.ts +35 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +363 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/team-app.d.ts +15 -0
- package/common/managed/team-app.js +100 -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/pretty-print.d.ts +5 -0
- package/common/pretty-print.js +24 -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/save-error-reason.ts +20 -7
- 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/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/workspace-app.js +71 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +4 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2SY4PYUQ.js +4 -0
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-4EMM6UCD.js +1 -0
- package/out/chunk-4HI2MSAV.js +17 -0
- package/out/chunk-4ISO5F7Y.js +7 -0
- package/out/chunk-4TQKM3JC.js +42 -0
- package/out/chunk-4XIH7YTX.js +1 -0
- package/out/chunk-6VDDCFHT.js +3 -0
- package/out/chunk-74AEKRES.js +10 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-E3LFSUDJ.js +9 -0
- package/out/chunk-EEQHVKR3.js +1 -0
- package/out/chunk-G3LY2FV4.js +1 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-HAZKDK4M.js +4 -0
- package/out/chunk-HNQNDNIE.js +12 -0
- package/out/chunk-HOB3YPS5.js +1 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-IZ6MYRYB.js +3 -0
- package/out/chunk-J2FWBXFV.js +1 -0
- package/out/chunk-JCIIBLKR.js +1 -0
- package/out/chunk-JFL7WLRV.js +1 -0
- package/out/chunk-JMG5DXII.js +2 -0
- package/out/chunk-JOXLZXMI.js +1 -0
- package/out/chunk-M37X4LCF.js +14 -0
- package/out/chunk-M3Y6SLC4.js +1 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-NXATZJQ2.js +1 -0
- package/out/chunk-OFPDMZJF.js +244 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-OQRSIBSC.js +1 -0
- package/out/chunk-PAD2JHZT.js +1 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PTFQKLKO.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QMVOEBWC.js +13 -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-RRBIJL2B.js +1 -0
- package/out/chunk-SYXT3SFP.js +2 -0
- package/out/chunk-TOXMUOIW.js +5 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-TZS7KERJ.js +52 -0
- package/out/chunk-UCP3JRE2.js +1 -0
- package/out/chunk-VFWMQ3LG.js +2 -0
- package/out/chunk-VRX2APNA.js +9 -0
- package/out/chunk-VZJIHHTQ.js +1 -0
- package/out/chunk-WCPJDAYA.js +10 -0
- package/out/chunk-WMFDQS2L.js +11 -0
- package/out/chunk-WREU7JAG.js +1 -0
- package/out/chunk-Y5ZHFNBD.js +2 -0
- package/out/chunk-YF4M5OCI.js +1 -0
- package/out/chunk-YGRRXC2L.js +1 -0
- package/out/chunk-YTO6AQZM.js +2 -0
- package/out/chunk-Z667U2UJ.js +1 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +34 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +35 -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 -4
- package/out/index.html +106 -8
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +366 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -144
- package/package.json +379 -62
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +250 -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 +76 -0
- package/risk/actions/workflow.js +110 -0
- package/risk/files/characters.js +196 -0
- package/risk/files/hosts.js +205 -0
- package/risk/files/readability.js +177 -0
- package/risk/files/runs-code.js +615 -0
- package/risk/files/script.js +118 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +272 -0
- package/risk/index.js +11 -0
- package/risk/npm/assess.js +285 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +257 -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 +63 -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 +390 -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 +96 -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 +50 -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 +60 -33
- package/{server → server-e2e}/static.ts +31 -21
- package/{server → server-e2e}/sync-handlers.ts +64 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +258 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +13 -0
- package/server-managed/blob-store.ts +17 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +102 -0
- package/server-managed/bundle-advisory-inventory.ts +77 -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 +203 -0
- package/server-managed/bundle-build.ts +232 -0
- package/server-managed/bundle-cache.ts +211 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +140 -0
- package/server-managed/bundle-dependency-reviews.ts +74 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +130 -0
- package/server-managed/bundle-validation.ts +32 -0
- package/server-managed/bundle.ts +119 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +47 -0
- package/server-managed/comments.ts +151 -0
- package/server-managed/commit-coauthors.ts +106 -0
- package/server-managed/commit-lockfiles.ts +76 -0
- package/server-managed/comparison.ts +52 -0
- package/server-managed/config.ts +164 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1958 -0
- package/server-managed/db-neon.ts +484 -0
- package/server-managed/db-schema.ts +238 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +152 -0
- package/server-managed/dependabot-access.ts +60 -0
- package/server-managed/dependabot-alerts.ts +185 -0
- package/server-managed/dependency-review-comments.ts +98 -0
- package/server-managed/dependency-reviews.ts +364 -0
- package/server-managed/github-accounts.ts +60 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +376 -0
- package/server-managed/github-errors.ts +70 -0
- package/server-managed/github-graphql.ts +39 -0
- package/server-managed/github-issue-links.ts +244 -0
- package/server-managed/github-issue-oauth.ts +47 -0
- package/server-managed/github-issues.ts +155 -0
- package/server-managed/github-link-oauth.ts +69 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +213 -0
- package/server-managed/github-oauth.ts +238 -0
- package/server-managed/github-pulls.ts +246 -0
- package/server-managed/github-requests.ts +166 -0
- package/server-managed/github-users.ts +30 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +5855 -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/link-reports.ts +162 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +152 -0
- package/server-managed/lockfile-scope.ts +49 -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 +99 -0
- package/server-managed/npm-delta-worker.js +23 -0
- package/server-managed/npm-delta.ts +194 -0
- package/server-managed/npm-insights.ts +450 -0
- package/server-managed/npm-kept.ts +233 -0
- package/server-managed/npm-loads.ts +264 -0
- package/server-managed/npm-manifest.ts +115 -0
- package/server-managed/npm-packages.ts +454 -0
- package/server-managed/npm-patch.ts +325 -0
- package/server-managed/npm-provenance.ts +123 -0
- package/server-managed/npm-risk.ts +285 -0
- package/server-managed/object-storage-disk.ts +148 -0
- package/server-managed/object-storage-vercel.ts +67 -0
- package/server-managed/object-storage.ts +75 -0
- package/server-managed/package-entry-points.ts +79 -0
- package/server-managed/pretty-print.ts +436 -0
- package/server-managed/public-workspace.ts +238 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +351 -0
- package/server-managed/pull-dependency-reviews.ts +334 -0
- package/server-managed/pull-reviews.ts +205 -0
- package/server-managed/queue.ts +39 -0
- package/server-managed/release-commits.ts +84 -0
- package/server-managed/rename-diff-worker.js +26 -0
- package/server-managed/rename-diff.ts +279 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +35 -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 +85 -0
- package/server-managed/repository-actions.ts +221 -0
- package/server-managed/repository-agents.ts +448 -0
- package/server-managed/repository-aliases.ts +91 -0
- package/server-managed/repository-browser.ts +301 -0
- package/server-managed/repository-changes.ts +284 -0
- package/server-managed/repository-code.ts +215 -0
- package/server-managed/repository-dependency-reviews.ts +166 -0
- package/server-managed/repository-discovery.ts +82 -0
- package/server-managed/repository-history.ts +432 -0
- package/server-managed/repository-issues.ts +195 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +212 -0
- package/server-managed/repository-pulse.ts +471 -0
- package/server-managed/repository-risk-assess.ts +105 -0
- package/server-managed/repository-risk-audit.ts +78 -0
- package/server-managed/repository-risk-read.ts +170 -0
- package/server-managed/repository-risk.ts +491 -0
- package/server-managed/repository-squashes.ts +168 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +149 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +87 -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 +89 -0
- package/server-managed/stasis-config.ts +55 -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 +290 -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 +54 -0
- package/server-managed/team-app.ts +157 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-npm-scopes.ts +106 -0
- package/server-managed/team-reports.ts +351 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-worker.js +19 -0
- package/server-managed/type-only.ts +105 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +252 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/workspace-shares.ts +171 -0
- package/server.ts +70 -0
- 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,238 @@
|
|
|
1
|
+
import { DEPENDENCY_REVIEW_SCHEMA } from './dependency-reviews.ts'
|
|
2
|
+
import { LINK_REPORT_SCHEMA } from './link-reports.ts'
|
|
3
|
+
import { REPOSITORY_ALIAS_SCHEMA } from './repository-aliases.ts'
|
|
4
|
+
import { WORKSPACE_SHARE_SCHEMA } from './workspace-shares.ts'
|
|
5
|
+
import { TEAM_NPM_SCOPE_SCHEMA } from './team-npm-scopes.ts'
|
|
6
|
+
import { GITHUB_LINK_SCHEMA } from './github-links.ts'
|
|
7
|
+
|
|
8
|
+
// Created after the column migration, which predates it on older databases.
|
|
9
|
+
export const VIEW_SESSION_INDEX = 'CREATE INDEX IF NOT EXISTS managed_session_viewer_idx ON managed_session(viewer_session);'
|
|
10
|
+
// What a team's scopes join reports and bundles on: their repository, and the
|
|
11
|
+
// directory in it. Created after the column migrations, as above.
|
|
12
|
+
export const REPO_UPLOAD_INDEXES = `CREATE INDEX IF NOT EXISTS managed_report_repo_idx ON managed_report(repo_id, repo_directory);
|
|
13
|
+
CREATE INDEX IF NOT EXISTS managed_bundle_repo_idx ON managed_bundle(repo_id, repo_directory);`
|
|
14
|
+
|
|
15
|
+
export const MANAGED_SCHEMA = `
|
|
16
|
+
CREATE TABLE IF NOT EXISTS managed_user (
|
|
17
|
+
id TEXT PRIMARY KEY,
|
|
18
|
+
github_user_id INTEGER NOT NULL UNIQUE,
|
|
19
|
+
login TEXT NOT NULL,
|
|
20
|
+
name TEXT,
|
|
21
|
+
avatar_url TEXT,
|
|
22
|
+
role TEXT NOT NULL DEFAULT 'none',
|
|
23
|
+
-- GitHub user-to-server token, persisted so the repositories page can list
|
|
24
|
+
-- the user's repos (GET /user/repos) on demand. Refresh token + expiry are
|
|
25
|
+
-- null for non-expiring tokens (GitHub App with expiring tokens disabled).
|
|
26
|
+
gh_access_token TEXT,
|
|
27
|
+
gh_refresh_token TEXT,
|
|
28
|
+
gh_token_expires_at INTEGER,
|
|
29
|
+
created_at INTEGER NOT NULL,
|
|
30
|
+
updated_at INTEGER NOT NULL,
|
|
31
|
+
-- Presence is independent of admin edits and background token refreshes.
|
|
32
|
+
-- NULL for legacy accounts until a known session authenticates them.
|
|
33
|
+
last_seen_at INTEGER
|
|
34
|
+
) STRICT;
|
|
35
|
+
|
|
36
|
+
CREATE TABLE IF NOT EXISTS managed_session (
|
|
37
|
+
id TEXT PRIMARY KEY,
|
|
38
|
+
user_id TEXT NOT NULL REFERENCES managed_user(id) ON DELETE CASCADE,
|
|
39
|
+
csrf_token TEXT NOT NULL,
|
|
40
|
+
created_at INTEGER NOT NULL,
|
|
41
|
+
expires_at INTEGER NOT NULL,
|
|
42
|
+
-- Private X25519 JWK that this session's uploads are sealed to (see
|
|
43
|
+
-- common/managed/upload-seal.ts). Created on first use.
|
|
44
|
+
upload_key TEXT,
|
|
45
|
+
-- An administrator's read-only view as user_id: the admin's own session,
|
|
46
|
+
-- which must stay valid. Ending that session ends the view.
|
|
47
|
+
viewer_session TEXT REFERENCES managed_session(id) ON DELETE CASCADE
|
|
48
|
+
) STRICT;
|
|
49
|
+
|
|
50
|
+
CREATE INDEX IF NOT EXISTS managed_session_user_idx ON managed_session(user_id);
|
|
51
|
+
CREATE INDEX IF NOT EXISTS managed_session_expires_idx ON managed_session(expires_at);
|
|
52
|
+
|
|
53
|
+
-- Repositories selected to operate on. Keyed by GitHub's numeric repo id
|
|
54
|
+
-- (stable across renames). The row carries everything needed to read the repo's
|
|
55
|
+
-- contents server-side later: installation_id mints an App installation token
|
|
56
|
+
-- (Contents: Read) for PRIVATE repos — NULL means a PUBLIC repo readable without
|
|
57
|
+
-- the App — and full_name + default_branch locate the contents. added_by is the
|
|
58
|
+
-- selector, nulled (not cascaded) if that user is removed so the selection
|
|
59
|
+
-- survives.
|
|
60
|
+
CREATE TABLE IF NOT EXISTS managed_selected_repo (
|
|
61
|
+
repo_id INTEGER PRIMARY KEY,
|
|
62
|
+
full_name TEXT NOT NULL,
|
|
63
|
+
is_private INTEGER NOT NULL,
|
|
64
|
+
installation_id INTEGER,
|
|
65
|
+
default_branch TEXT NOT NULL,
|
|
66
|
+
-- Live browser hint; independent of the default discovered at selection.
|
|
67
|
+
cached_default_branch TEXT,
|
|
68
|
+
html_url TEXT NOT NULL,
|
|
69
|
+
added_by TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
70
|
+
added_at INTEGER NOT NULL,
|
|
71
|
+
updated_at INTEGER NOT NULL,
|
|
72
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
73
|
+
-- Its pull requests' dependencies reviewed (repository-dependency-reviews.ts):
|
|
74
|
+
-- as many published reviews required of each version, and the commit at
|
|
75
|
+
-- whose lockfiles' versions none is (null for none).
|
|
76
|
+
dependency_review INTEGER NOT NULL DEFAULT 0,
|
|
77
|
+
dependency_reviews_required INTEGER NOT NULL DEFAULT 1,
|
|
78
|
+
dependency_review_since TEXT
|
|
79
|
+
) STRICT;
|
|
80
|
+
|
|
81
|
+
CREATE INDEX IF NOT EXISTS selected_repo_full_name_idx ON managed_selected_repo(full_name);
|
|
82
|
+
|
|
83
|
+
-- Bundles uploaded to the server (the "Manage bundles" page). Like reports, the
|
|
84
|
+
-- bytes are stored in the clear (blob-store, keyed by this opaque uuid id) for
|
|
85
|
+
-- the server to operate on. integrity is the content hash (sha512-<base64>,
|
|
86
|
+
-- byte-identical to the client's) so re-uploading the same bytes dedupes (UNIQUE);
|
|
87
|
+
-- it is also the key a report's bundleHashes match to auto-link.
|
|
88
|
+
-- uploaded_by / repo_id are the (nullable) user + repo links, both nulled (not
|
|
89
|
+
-- cascaded) when the referenced user / selected repo goes away.
|
|
90
|
+
CREATE TABLE IF NOT EXISTS managed_bundle (
|
|
91
|
+
id TEXT PRIMARY KEY,
|
|
92
|
+
slug TEXT NOT NULL,
|
|
93
|
+
integrity TEXT NOT NULL UNIQUE,
|
|
94
|
+
filename TEXT NOT NULL,
|
|
95
|
+
kind TEXT,
|
|
96
|
+
byte_size INTEGER NOT NULL,
|
|
97
|
+
uploaded_by TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
98
|
+
-- Durable snapshot of the uploader's login at upload time, so "who uploaded
|
|
99
|
+
-- this" survives the uploader being removed (when uploaded_by nulls out).
|
|
100
|
+
uploaded_by_login TEXT,
|
|
101
|
+
repo_id INTEGER REFERENCES managed_selected_repo(repo_id) ON DELETE SET NULL,
|
|
102
|
+
repo_directory TEXT NOT NULL DEFAULT '',
|
|
103
|
+
visible INTEGER NOT NULL DEFAULT 1,
|
|
104
|
+
uploaded_at INTEGER NOT NULL,
|
|
105
|
+
-- 'upload' or 'build' (generated on this server). A server build of bytes
|
|
106
|
+
-- already stored promotes the row to 'build'; NULL predates the column.
|
|
107
|
+
provenance TEXT,
|
|
108
|
+
-- JSON {preset, conditions, platforms} of a JS/TS server build; NULL otherwise.
|
|
109
|
+
build_conditions TEXT
|
|
110
|
+
) STRICT;
|
|
111
|
+
|
|
112
|
+
CREATE INDEX IF NOT EXISTS managed_bundle_uploaded_at_idx ON managed_bundle(uploaded_at);
|
|
113
|
+
|
|
114
|
+
-- Reports uploaded to the server (the "Manage reports" page). A managed server
|
|
115
|
+
-- is TRUSTED, so the bytes are stored in the clear (blob-store, keyed by this
|
|
116
|
+
-- opaque uuid id) for the server to operate on later; this row carries the
|
|
117
|
+
-- metadata + attribution. uploaded_by / repo_id are the (nullable) user + repo
|
|
118
|
+
-- links, nulled (not cascaded) when the user / selected repo goes away. bundle_id
|
|
119
|
+
-- is the (nullable) auto-resolved link to a stored bundle; bundle_integrity is
|
|
120
|
+
-- the report's declared primary bundle (from its bundleHashes), kept so a later
|
|
121
|
+
-- bundle upload of that integrity can re-link.
|
|
122
|
+
CREATE TABLE IF NOT EXISTS managed_report (
|
|
123
|
+
id TEXT PRIMARY KEY,
|
|
124
|
+
slug TEXT NOT NULL,
|
|
125
|
+
filename TEXT NOT NULL,
|
|
126
|
+
content_type TEXT NOT NULL,
|
|
127
|
+
byte_size INTEGER NOT NULL,
|
|
128
|
+
sha256 TEXT NOT NULL,
|
|
129
|
+
uploaded_by TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
130
|
+
-- Durable snapshot of the uploader's login (see managed_bundle).
|
|
131
|
+
uploaded_by_login TEXT,
|
|
132
|
+
repo_id INTEGER REFERENCES managed_selected_repo(repo_id) ON DELETE SET NULL,
|
|
133
|
+
repo_directory TEXT NOT NULL DEFAULT '',
|
|
134
|
+
repo_embedded INTEGER NOT NULL DEFAULT 0,
|
|
135
|
+
analyzer TEXT,
|
|
136
|
+
visible INTEGER NOT NULL DEFAULT 0,
|
|
137
|
+
bundle_id TEXT REFERENCES managed_bundle(id) ON DELETE SET NULL,
|
|
138
|
+
bundle_integrity TEXT,
|
|
139
|
+
uploaded_at INTEGER NOT NULL
|
|
140
|
+
) STRICT;
|
|
141
|
+
|
|
142
|
+
CREATE INDEX IF NOT EXISTS managed_report_uploaded_at_idx ON managed_report(uploaded_at);
|
|
143
|
+
CREATE INDEX IF NOT EXISTS managed_report_hash_idx ON managed_report(sha256, uploaded_at, id);
|
|
144
|
+
CREATE INDEX IF NOT EXISTS managed_report_bundle_integrity_idx ON managed_report(bundle_integrity);
|
|
145
|
+
CREATE INDEX IF NOT EXISTS managed_report_bundle_hash_idx ON managed_report(bundle_id, sha256);
|
|
146
|
+
|
|
147
|
+
-- Per-finding triage annotations — the managed (trusted-plaintext) counterpart
|
|
148
|
+
-- of the client's localStorage triage map, keyed the same way: by finding id
|
|
149
|
+
-- alone, not by report. Reports mostly repeat one another (a re-scan of the
|
|
150
|
+
-- same code carries the same finding ids) and a finding's triage is shared by
|
|
151
|
+
-- every report that carries it; which ids a viewer may read or write is
|
|
152
|
+
-- decided per report at the endpoint, not here. The wire shape lives in
|
|
153
|
+
-- common/managed/triage.ts. Whole-entry replace, NULL columns are unset;
|
|
154
|
+
-- flagged is tri-state: NULL unset / 1 flagged / 0 an explicit un-flag
|
|
155
|
+
-- tombstone. A cleared entry keeps its row with every field NULL — a
|
|
156
|
+
-- tombstone a reader adopts as "cleared", where a missing row means "never
|
|
157
|
+
-- annotated" (so a stale client copy can't resurrect a teammate's clear).
|
|
158
|
+
-- updated_by is the last writer (nulled when that user is removed);
|
|
159
|
+
-- updated_by_login is the durable login snapshot (see managed_bundle).
|
|
160
|
+
CREATE TABLE IF NOT EXISTS managed_finding_triage (
|
|
161
|
+
finding_id TEXT PRIMARY KEY,
|
|
162
|
+
color TEXT,
|
|
163
|
+
triage TEXT,
|
|
164
|
+
comment TEXT,
|
|
165
|
+
fix TEXT,
|
|
166
|
+
flagged INTEGER,
|
|
167
|
+
updated_by TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
168
|
+
updated_by_login TEXT,
|
|
169
|
+
updated_at INTEGER NOT NULL
|
|
170
|
+
) STRICT;
|
|
171
|
+
|
|
172
|
+
-- The trail behind managed_finding_triage: one row per write that CHANGED an entry,
|
|
173
|
+
-- holding the entry as written (every field NULL = a clear), who wrote it and
|
|
174
|
+
-- when. managed_finding_triage stays the current-state projection reads hit; this is
|
|
175
|
+
-- walked only for a finding's history. The wire is whole-entry replace, so a
|
|
176
|
+
-- snapshot per write is exactly what arrived and "what changed" is the diff
|
|
177
|
+
-- against the previous row for the same id, computed on read. batch_id groups
|
|
178
|
+
-- the rows of one request. seq is the rowid: a total order that breaks ties
|
|
179
|
+
-- on at. actor_id / actor_login follow the uploaded_by / uploaded_by_login
|
|
180
|
+
-- convention (live account, durable login snapshot). Everything is kept by
|
|
181
|
+
-- default — the trail is the record; an operator may bound it per finding
|
|
182
|
+
-- (TRIAGE_HISTORY_LIMIT), in which case a finding's older events are trimmed
|
|
183
|
+
-- as new ones land. An id no report carries any more is the tombstone GC's
|
|
184
|
+
-- concern.
|
|
185
|
+
CREATE TABLE IF NOT EXISTS managed_finding_triage_event (
|
|
186
|
+
seq INTEGER PRIMARY KEY,
|
|
187
|
+
finding_id TEXT NOT NULL,
|
|
188
|
+
batch_id TEXT NOT NULL,
|
|
189
|
+
color TEXT,
|
|
190
|
+
triage TEXT,
|
|
191
|
+
comment TEXT,
|
|
192
|
+
fix TEXT,
|
|
193
|
+
flagged INTEGER,
|
|
194
|
+
actor_id TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
195
|
+
actor_login TEXT,
|
|
196
|
+
at INTEGER NOT NULL
|
|
197
|
+
) STRICT;
|
|
198
|
+
CREATE INDEX IF NOT EXISTS finding_triage_event_finding_idx ON managed_finding_triage_event(finding_id, seq);
|
|
199
|
+
CREATE INDEX IF NOT EXISTS finding_triage_event_actor_at_idx ON managed_finding_triage_event(actor_id, at);
|
|
200
|
+
|
|
201
|
+
-- Teams group users + repos for access scoping. Hidden teams grant no access;
|
|
202
|
+
-- the two link tables below carry the many-many relations.
|
|
203
|
+
CREATE TABLE IF NOT EXISTS managed_team (
|
|
204
|
+
id TEXT PRIMARY KEY,
|
|
205
|
+
slug TEXT NOT NULL,
|
|
206
|
+
name TEXT NOT NULL UNIQUE,
|
|
207
|
+
hidden INTEGER NOT NULL DEFAULT 0,
|
|
208
|
+
dependency_review INTEGER NOT NULL DEFAULT 0,
|
|
209
|
+
created_at INTEGER NOT NULL,
|
|
210
|
+
updated_at INTEGER NOT NULL
|
|
211
|
+
) STRICT;
|
|
212
|
+
|
|
213
|
+
-- Team <-> repo, many-many, with an OPTIONAL path (a subpath of the repo the
|
|
214
|
+
-- team is scoped to; empty path = the whole repo). Distinct paths can coexist;
|
|
215
|
+
-- adding the whole repo replaces them. CASCADE removes links with either side. repo_id
|
|
216
|
+
-- references the selected (operate-on) repos.
|
|
217
|
+
CREATE TABLE IF NOT EXISTS managed_team_repo (
|
|
218
|
+
team_id TEXT NOT NULL REFERENCES managed_team(id) ON DELETE CASCADE,
|
|
219
|
+
repo_id INTEGER NOT NULL REFERENCES managed_selected_repo(repo_id) ON DELETE CASCADE,
|
|
220
|
+
path TEXT NOT NULL DEFAULT '',
|
|
221
|
+
PRIMARY KEY (team_id, repo_id, path)
|
|
222
|
+
) STRICT;
|
|
223
|
+
|
|
224
|
+
CREATE INDEX IF NOT EXISTS team_repo_repo_idx ON managed_team_repo(repo_id);
|
|
225
|
+
|
|
226
|
+
-- Team <-> user, many-many, with per-membership visibility permissions (see
|
|
227
|
+
-- common/managed/permissions.ts) — view_dependencies / view_security, both
|
|
228
|
+
-- default 0 (off). CASCADE so the membership dies with either side.
|
|
229
|
+
CREATE TABLE IF NOT EXISTS managed_team_user (
|
|
230
|
+
team_id TEXT NOT NULL REFERENCES managed_team(id) ON DELETE CASCADE,
|
|
231
|
+
user_id TEXT NOT NULL REFERENCES managed_user(id) ON DELETE CASCADE,
|
|
232
|
+
view_dependencies INTEGER NOT NULL DEFAULT 0,
|
|
233
|
+
view_security INTEGER NOT NULL DEFAULT 0,
|
|
234
|
+
PRIMARY KEY (team_id, user_id)
|
|
235
|
+
) STRICT;
|
|
236
|
+
|
|
237
|
+
CREATE INDEX IF NOT EXISTS team_user_user_idx ON managed_team_user(user_id);
|
|
238
|
+
` + WORKSPACE_SHARE_SCHEMA + LINK_REPORT_SCHEMA + REPOSITORY_ALIAS_SCHEMA + TEAM_NPM_SCOPE_SCHEMA + DEPENDENCY_REVIEW_SCHEMA + GITHUB_LINK_SCHEMA
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Table identifiers are code constants. Renames retain rows and foreign keys;
|
|
2
|
+
// an ambiguous old/new pair must be resolved before the server can start.
|
|
3
|
+
const MANAGED_TABLE_RENAMES = [
|
|
4
|
+
['selected_repo', 'managed_selected_repo'],
|
|
5
|
+
['team_repo', 'managed_team_repo'],
|
|
6
|
+
['team_user', 'managed_team_user'],
|
|
7
|
+
['finding_triage', 'managed_finding_triage'],
|
|
8
|
+
['finding_triage_event', 'managed_finding_triage_event'],
|
|
9
|
+
['finding_comment', 'managed_finding_comment'],
|
|
10
|
+
['finding_comment_event', 'managed_finding_comment_event'],
|
|
11
|
+
] as const
|
|
12
|
+
|
|
13
|
+
export function managedTableRenames(tables: Set<string>) {
|
|
14
|
+
// A fresh installation must not claim similarly named unrelated tables in
|
|
15
|
+
// a shared database. managed_user anchors an existing managed installation.
|
|
16
|
+
if (!tables.has('managed_user')) return []
|
|
17
|
+
const renames = MANAGED_TABLE_RENAMES.filter(([from]) => tables.has(from))
|
|
18
|
+
for (const [from, to] of renames) {
|
|
19
|
+
if (tables.has(to)) throw new Error(`Cannot migrate managed tables: both ${from} and ${to} exist`)
|
|
20
|
+
}
|
|
21
|
+
return renames
|
|
22
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// SQLite bootstrap and legacy upgrades. Runtime methods are shared with Neon.
|
|
2
|
+
import { mkdirSync } from 'node:fs'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { DatabaseSync } from 'node:sqlite'
|
|
5
|
+
import { migrateSlugs } from './slugs.ts'
|
|
6
|
+
import { migrateReportLocations } from './report-migration.ts'
|
|
7
|
+
import { initCommentMethods } from './comments.ts'
|
|
8
|
+
import { initActivityMethods } from './activity.ts'
|
|
9
|
+
import { revisionSchema } from './revisions.ts'
|
|
10
|
+
import { MANAGED_SCHEMA, REPO_UPLOAD_INDEXES, VIEW_SESSION_INDEX } from './db-schema.ts'
|
|
11
|
+
import { GITHUB_LINK_USER_COLUMNS } from './github-links.ts'
|
|
12
|
+
import { REPOSITORY_DEPENDENCY_REVIEW_COLUMNS } from './repository-dependency-reviews.ts'
|
|
13
|
+
import { DEPENDENCY_REVIEW_COLUMNS, DEPENDENCY_REVIEW_INDEXES } from './dependency-reviews.ts'
|
|
14
|
+
import { STORAGE_SCHEMA } from './storage-db.ts'
|
|
15
|
+
import { GITHUB_COMMIT_SCHEMA, GITHUB_METADATA_SCHEMA, GITHUB_STATE_REASON_COLUMN } from './github-metadata.ts'
|
|
16
|
+
import { MANAGED_ISSUE_SCHEMA } from './managed-issues.ts'
|
|
17
|
+
import { BUNDLE_BUILD_LEASE_SCHEMA } from './bundle-build-leases.ts'
|
|
18
|
+
import { UPSTREAM_CACHE_SCHEMA } from './upstream-cache.ts'
|
|
19
|
+
import { TEAM_APP_SUMMARY_SCHEMA } from './team-app-summaries.ts'
|
|
20
|
+
import { managedTableRenames } from './db-table-names.ts'
|
|
21
|
+
import { type ManagedDb, type ManagedDbOptions, createManagedMethods } from './db-methods.ts'
|
|
22
|
+
import { createSqliteDriver, scopeManagedMethods } from './sql.ts'
|
|
23
|
+
export type * from './db-methods.ts'
|
|
24
|
+
|
|
25
|
+
function migrateManagedTableNames(db: DatabaseSync): void {
|
|
26
|
+
db.exec('BEGIN IMMEDIATE')
|
|
27
|
+
try {
|
|
28
|
+
db.exec('CREATE TABLE IF NOT EXISTS managed_schema_version (version INTEGER PRIMARY KEY) STRICT;')
|
|
29
|
+
if (!db.prepare('SELECT version FROM managed_schema_version WHERE version = 3').get()) {
|
|
30
|
+
const rows = db.prepare("SELECT name FROM sqlite_schema WHERE type = 'table'").all() as { name: string }[]
|
|
31
|
+
for (const [from, to] of managedTableRenames(new Set(rows.map(row => row.name)))) {
|
|
32
|
+
db.exec(`ALTER TABLE ${from} RENAME TO ${to}`)
|
|
33
|
+
}
|
|
34
|
+
db.exec('INSERT INTO managed_schema_version VALUES (3)')
|
|
35
|
+
}
|
|
36
|
+
db.exec('COMMIT')
|
|
37
|
+
} catch (err) { db.exec('ROLLBACK'); throw err }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Preserve the legacy single-path links while adding path to their identity.
|
|
41
|
+
function migrateTeamRepoPaths(db: DatabaseSync): void {
|
|
42
|
+
const columns = db.prepare('PRAGMA table_info(managed_team_repo)').all() as { name: string; pk: number }[]
|
|
43
|
+
if (columns.some(column => column.name === 'path' && column.pk === 3)) return
|
|
44
|
+
db.exec('BEGIN IMMEDIATE')
|
|
45
|
+
try {
|
|
46
|
+
db.exec(`CREATE TABLE managed_team_repo_paths (
|
|
47
|
+
team_id TEXT NOT NULL REFERENCES managed_team(id) ON DELETE CASCADE,
|
|
48
|
+
repo_id INTEGER NOT NULL REFERENCES managed_selected_repo(repo_id) ON DELETE CASCADE,
|
|
49
|
+
path TEXT NOT NULL DEFAULT '', PRIMARY KEY (team_id, repo_id, path)
|
|
50
|
+
) STRICT;
|
|
51
|
+
INSERT INTO managed_team_repo_paths SELECT team_id, repo_id, COALESCE(path, '') FROM managed_team_repo;
|
|
52
|
+
DROP TABLE managed_team_repo;
|
|
53
|
+
ALTER TABLE managed_team_repo_paths RENAME TO managed_team_repo;
|
|
54
|
+
CREATE INDEX team_repo_repo_idx ON managed_team_repo(repo_id);`)
|
|
55
|
+
db.exec('COMMIT')
|
|
56
|
+
} catch (err) { db.exec('ROLLBACK'); throw err }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Add `column` to `table` if it's missing (a lightweight migration for DBs that
|
|
60
|
+
// predate the column; `table`/`column` are code constants, never user input).
|
|
61
|
+
function ensureColumn(db: DatabaseSync, table: string, column: string, type: string): boolean {
|
|
62
|
+
const cols = db.prepare(`PRAGMA table_info(${table})`).all() as { name: string }[]
|
|
63
|
+
if (cols.some((c) => c.name === column)) return false
|
|
64
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${type}`)
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function openSqliteManagedDb(path: string, options: ManagedDbOptions = {}): ManagedDb {
|
|
69
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
70
|
+
const db = new DatabaseSync(path)
|
|
71
|
+
try {
|
|
72
|
+
db.exec('PRAGMA journal_mode = WAL;')
|
|
73
|
+
// The bootstrap below commits each schema statement on its own: under
|
|
74
|
+
// FULL, ~120 fsyncs on a new file. Each step checks the schema before
|
|
75
|
+
// changing it and only reads outside the database, so a step lost to a
|
|
76
|
+
// power failure reruns on the next open, and WAL stays consistent under
|
|
77
|
+
// NORMAL. FULL is restored after it; the next commit's fsync of the WAL
|
|
78
|
+
// persists the bootstrap's frames too.
|
|
79
|
+
db.exec('PRAGMA synchronous = NORMAL;')
|
|
80
|
+
db.exec('PRAGMA foreign_keys = ON;')
|
|
81
|
+
migrateManagedTableNames(db)
|
|
82
|
+
db.exec(MANAGED_SCHEMA + GITHUB_METADATA_SCHEMA + GITHUB_COMMIT_SCHEMA + MANAGED_ISSUE_SCHEMA + STORAGE_SCHEMA + BUNDLE_BUILD_LEASE_SCHEMA + UPSTREAM_CACHE_SCHEMA + TEAM_APP_SUMMARY_SCHEMA)
|
|
83
|
+
ensureColumn(db, 'managed_selected_repo', 'cached_default_branch', 'TEXT')
|
|
84
|
+
ensureColumn(db, 'managed_session', 'upload_key', 'TEXT')
|
|
85
|
+
ensureColumn(db, 'managed_session', 'viewer_session', 'TEXT REFERENCES managed_session(id) ON DELETE CASCADE')
|
|
86
|
+
db.exec(VIEW_SESSION_INDEX)
|
|
87
|
+
for (const table of ['managed_report', 'managed_bundle']) {
|
|
88
|
+
ensureColumn(db, table, 'data_key', 'TEXT')
|
|
89
|
+
ensureColumn(db, table, 'storage_encrypted', 'INTEGER NOT NULL DEFAULT 0')
|
|
90
|
+
}
|
|
91
|
+
ensureColumn(db, 'managed_user', 'gh_tokens_encrypted', 'INTEGER NOT NULL DEFAULT 0')
|
|
92
|
+
// Existing names are the sign-in accounts' own: none was chosen yet.
|
|
93
|
+
for (const [column, type] of GITHUB_LINK_USER_COLUMNS) {
|
|
94
|
+
if (ensureColumn(db, 'managed_user', column, type) && column === 'github_name') db.exec('UPDATE managed_user SET github_name = name')
|
|
95
|
+
}
|
|
96
|
+
ensureColumn(db, 'managed_github_metadata', 'state_reason', GITHUB_STATE_REASON_COLUMN)
|
|
97
|
+
ensureColumn(db, 'managed_github_metadata', 'attempted_at', 'INTEGER')
|
|
98
|
+
// Existing public links must opt in too; never preserve an implicit grant.
|
|
99
|
+
ensureColumn(db, 'managed_workspace_share', 'dependencies', 'INTEGER NOT NULL DEFAULT 0')
|
|
100
|
+
ensureColumn(db, 'managed_workspace_share', 'security', 'INTEGER NOT NULL DEFAULT 0')
|
|
101
|
+
migrateTeamRepoPaths(db)
|
|
102
|
+
migrateSlugs(db)
|
|
103
|
+
// Migrate DBs created before a column existed (CREATE TABLE IF NOT EXISTS
|
|
104
|
+
// never alters an already-present table). Idempotent — skipped on fresh DBs.
|
|
105
|
+
const addedLastSeen = ensureColumn(db, 'managed_user', 'last_seen_at', 'INTEGER')
|
|
106
|
+
if (addedLastSeen) {
|
|
107
|
+
// Session creation is known authentication activity. updated_at is not:
|
|
108
|
+
// role changes and token refreshes also wrote it. Keep unknowns NULL.
|
|
109
|
+
db.exec(`UPDATE managed_user SET last_seen_at = (
|
|
110
|
+
SELECT MAX(s.created_at) FROM managed_session s WHERE s.user_id = managed_user.id
|
|
111
|
+
)`)
|
|
112
|
+
}
|
|
113
|
+
ensureColumn(db, 'managed_report', 'uploaded_by_login', 'TEXT')
|
|
114
|
+
ensureColumn(db, 'managed_report', 'repo_embedded', 'INTEGER NOT NULL DEFAULT 0')
|
|
115
|
+
migrateReportLocations(db, join(dirname(path), 'reports'))
|
|
116
|
+
ensureColumn(db, 'managed_report', 'analyzer', 'TEXT')
|
|
117
|
+
// Existing rows predate publication controls and were already visible.
|
|
118
|
+
// Backfill only when adding the column; newly inserted rows still use the
|
|
119
|
+
// hidden default and must be explicitly published.
|
|
120
|
+
const addedVisible = ensureColumn(db, 'managed_report', 'visible', 'INTEGER NOT NULL DEFAULT 0')
|
|
121
|
+
if (addedVisible) db.prepare('UPDATE managed_report SET visible = 1 WHERE visible = 0').run()
|
|
122
|
+
ensureColumn(db, 'managed_bundle', 'uploaded_by_login', 'TEXT')
|
|
123
|
+
ensureColumn(db, 'managed_bundle', 'repo_directory', "TEXT NOT NULL DEFAULT ''")
|
|
124
|
+
db.exec(REPO_UPLOAD_INDEXES)
|
|
125
|
+
ensureColumn(db, 'managed_bundle', 'visible', 'INTEGER NOT NULL DEFAULT 1')
|
|
126
|
+
// Existing rows stay NULL (unknown): some may have been built on the server.
|
|
127
|
+
ensureColumn(db, 'managed_bundle', 'provenance', 'TEXT')
|
|
128
|
+
ensureColumn(db, 'managed_bundle', 'build_conditions', 'TEXT')
|
|
129
|
+
ensureColumn(db, 'managed_team', 'hidden', 'INTEGER NOT NULL DEFAULT 0')
|
|
130
|
+
ensureColumn(db, 'managed_team', 'dependency_review', 'INTEGER NOT NULL DEFAULT 0')
|
|
131
|
+
ensureColumn(db, 'managed_finding_issue', 'auto_fix_url', 'TEXT')
|
|
132
|
+
ensureColumn(db, 'managed_finding_issue', 'auto_fix_checked_at', 'INTEGER')
|
|
133
|
+
ensureColumn(db, 'managed_finding_issue', 'duplicate_of_url', 'TEXT')
|
|
134
|
+
ensureColumn(db, 'managed_selected_repo', 'active', 'INTEGER NOT NULL DEFAULT 1')
|
|
135
|
+
for (const [column, type] of REPOSITORY_DEPENDENCY_REVIEW_COLUMNS) ensureColumn(db, 'managed_selected_repo', column, type)
|
|
136
|
+
for (const [column, type] of DEPENDENCY_REVIEW_COLUMNS) ensureColumn(db, 'managed_dependency_review', column, type)
|
|
137
|
+
db.exec(DEPENDENCY_REVIEW_INDEXES)
|
|
138
|
+
ensureColumn(db, 'managed_finding_triage_event', 'report_id', 'TEXT')
|
|
139
|
+
ensureColumn(db, 'managed_finding_triage_event', 'report', 'TEXT')
|
|
140
|
+
ensureColumn(db, 'managed_finding_triage_event', 'repo', 'TEXT')
|
|
141
|
+
initCommentMethods(db)
|
|
142
|
+
initActivityMethods(db)
|
|
143
|
+
db.exec(revisionSchema())
|
|
144
|
+
db.exec('PRAGMA synchronous = FULL;')
|
|
145
|
+
} catch (err) {
|
|
146
|
+
try { db.close() } catch {}
|
|
147
|
+
throw err
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const driver = createSqliteDriver(db)
|
|
151
|
+
return scopeManagedMethods(createManagedMethods(driver, options), driver)
|
|
152
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// A repository's Dependabot alerts for a repository risk scan, read with the
|
|
2
|
+
// App's installation token where the admin's own access lets them see them on
|
|
3
|
+
// GitHub, as doc/bundles.md's repository risk scan section tells.
|
|
4
|
+
import type { ManagedConfig } from './config.ts'
|
|
5
|
+
import type { SelectedRepo } from './db.ts'
|
|
6
|
+
import { type DependabotAlert, dependabotAlerts } from './dependabot-alerts.ts'
|
|
7
|
+
import { GithubApiError, type GithubIdentity, githubRepoPermission, repoAccessToken, repositoryInstallation } from './github-app.ts'
|
|
8
|
+
|
|
9
|
+
// The levels GitHub lets see a repository's Dependabot alerts by default
|
|
10
|
+
// (maintain's reads `write`).
|
|
11
|
+
const SEES_ALERTS: ReadonlySet<string> = new Set(['admin', 'write'])
|
|
12
|
+
// Failures of verifying the sign-in that are the sign-in's own: no token, or
|
|
13
|
+
// one of another account (repository-browser.ts getIdentity), or one GitHub no
|
|
14
|
+
// longer takes. Any other, as GitHub failing to answer, is told as it is.
|
|
15
|
+
const UNVERIFIED: ReadonlySet<string> = new Set(['no-repository', 'github-unauthorized'])
|
|
16
|
+
|
|
17
|
+
// What of a repository's reader (repository-browser.ts) the alerts are asked
|
|
18
|
+
// with: the user's verified identity, and their permission level where its
|
|
19
|
+
// access gate asked GitHub of it already.
|
|
20
|
+
export interface AlertsReader {
|
|
21
|
+
identity(): Promise<GithubIdentity>
|
|
22
|
+
permission(): string | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Alerts read, and their `recheck`: the user's access to them checked again,
|
|
26
|
+
// asked of GitHub afresh, just before they are told (repository-risk.ts), as
|
|
27
|
+
// access to the repository is, as it may be withdrawn meanwhile.
|
|
28
|
+
export interface AlertsRead { alerts: DependabotAlert[]; recheck(): Promise<void> }
|
|
29
|
+
|
|
30
|
+
// `repo`'s Dependabot alerts (dependabot-alerts.ts), read with the token of
|
|
31
|
+
// the App's installation GitHub tells covers it now, its token checked to read
|
|
32
|
+
// it (github-app.ts repositoryInstallation), never the one its connection
|
|
33
|
+
// keeps, which may no longer cover it, once the user's own permission on it
|
|
34
|
+
// lets them see them; else refused, the alerts not asked:
|
|
35
|
+
// `dependabot-not-installed`, `dependabot-unverified`, or
|
|
36
|
+
// `dependabot-forbidden`, naming their permission. The token is asked each
|
|
37
|
+
// time of repoAccessToken, which renews it before it expires, as the recheck
|
|
38
|
+
// may come long after the alerts are read.
|
|
39
|
+
export async function appDependabotAlerts(config: ManagedConfig, repo: Pick<SelectedRepo, 'repoId' | 'fullName'>, reader: AlertsReader,
|
|
40
|
+
fetchImpl: typeof fetch = globalThis.fetch): Promise<AlertsRead> {
|
|
41
|
+
const id = await repositoryInstallation(config, repo.repoId, repo.fullName, fetchImpl)
|
|
42
|
+
const tokenNow = async () => {
|
|
43
|
+
const token = await repoAccessToken(config, id, fetchImpl)
|
|
44
|
+
if (token == null) throw new GithubApiError(403, 'dependabot-not-installed')
|
|
45
|
+
return token
|
|
46
|
+
}
|
|
47
|
+
const token = await tokenNow()
|
|
48
|
+
let who
|
|
49
|
+
try { who = await reader.identity() } catch (error) {
|
|
50
|
+
throw error instanceof GithubApiError && UNVERIFIED.has(error.message) ? new GithubApiError(403, 'dependabot-unverified') : error
|
|
51
|
+
}
|
|
52
|
+
const seen = (permission: string) => {
|
|
53
|
+
if (!SEES_ALERTS.has(permission)) {
|
|
54
|
+
throw new GithubApiError(403, 'dependabot-forbidden', null, `@${who.login}'s access to this repository (${permission}) doesn't let them see its Dependabot alerts on GitHub`)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
seen(reader.permission() ?? await githubRepoPermission(repo.fullName, token, who, fetchImpl))
|
|
58
|
+
const alerts = await dependabotAlerts(repo.fullName, token, fetchImpl)
|
|
59
|
+
return { alerts, recheck: async () => { seen(await githubRepoPermission(repo.fullName, await tokenNow(), who, fetchImpl)) } }
|
|
60
|
+
}
|