@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
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
// so the absent peer dep is never loaded under test.
|
|
14
14
|
//
|
|
15
15
|
// In production the wrapper is only ever imported on the Neon path
|
|
16
|
-
// (
|
|
16
|
+
// (an e2e database URL set), where the operator has installed the peer dep
|
|
17
17
|
// (`pnpm add @neondatabase/serverless`) so the re-export resolves. A
|
|
18
18
|
// SQLite-only deploy never imports this module — the dynamic `import()`
|
|
19
|
-
// sites are gated behind the
|
|
19
|
+
// sites are gated behind the configured database URL branch in `index.ts`.
|
|
20
20
|
//
|
|
21
21
|
// `@ts-ignore` rather than `@ts-expect-error`: when the peer dep IS
|
|
22
22
|
// installed the specifier resolves and tsc sees a real type, which
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// the request body and answers with the upstream's JSON.
|
|
9
9
|
//
|
|
10
10
|
// The route is mounted at `/api/npm-advisories`. The same-origin
|
|
11
|
-
// gate runs inside `dispatchNpmAdvisories` below (server/http.ts
|
|
11
|
+
// gate runs inside `dispatchNpmAdvisories` below (server-e2e/http.ts
|
|
12
12
|
// calls the dispatcher directly without a pre-check), so any
|
|
13
13
|
// browser request from a foreign origin is rejected with 403 before
|
|
14
14
|
// we ever issue a fetch — non-browser callers that omit Origin are
|
|
@@ -25,37 +25,23 @@
|
|
|
25
25
|
//
|
|
26
26
|
// Outbound fetch carries an `AbortController` so a hung upstream
|
|
27
27
|
// (slow-loris response, TLS stall) tears down after
|
|
28
|
-
// `
|
|
28
|
+
// `NPM_ADVISORIES_TIMEOUT_MS`, and a client that closes its connection
|
|
29
29
|
// mid-fetch propagates an abort through the same controller — so a
|
|
30
30
|
// stranded in-flight call doesn't block SIGTERM drain.
|
|
31
31
|
|
|
32
32
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
33
33
|
import { Buffer } from 'node:buffer'
|
|
34
34
|
import { errStack } from './util.ts'
|
|
35
|
+
import { NPM_ADVISORIES_TIMEOUT_MS, fetchNpmAdvisories } from '../server-common/npm-advisories.ts'
|
|
35
36
|
|
|
36
37
|
type HasHeaders = { headers: IncomingMessage['headers'] }
|
|
37
38
|
|
|
38
39
|
export const NPM_ADVISORIES_PATH = '/api/npm-advisories'
|
|
39
|
-
const UPSTREAM_URL = 'https://registry.npmjs.org/-/npm/v1/security/advisories/bulk'
|
|
40
|
-
|
|
41
40
|
// 1 MiB is generous: the bulk endpoint accepts `{ packageName:
|
|
42
41
|
// [versions] }` maps, and even a bundle with thousands of pinned
|
|
43
42
|
// versions serialises to well under this. Anything bigger is almost
|
|
44
43
|
// certainly malformed input or a probe.
|
|
45
44
|
const REQUEST_BODY_LIMIT = 1 * 1024 * 1024
|
|
46
|
-
// 4 MiB caps the upstream response. The advisories endpoint
|
|
47
|
-
// returns at most a few CVEs per package, so even a bundle with
|
|
48
|
-
// hundreds of affected packages comes in well under this — a
|
|
49
|
-
// runaway / hostile upstream gets cut off before we burn arbitrary
|
|
50
|
-
// memory buffering it.
|
|
51
|
-
const RESPONSE_BODY_LIMIT = 4 * 1024 * 1024
|
|
52
|
-
// Hard deadline on the upstream call. The bulk endpoint typically
|
|
53
|
-
// answers in well under a second; 30 s leaves plenty of headroom
|
|
54
|
-
// for a slow path but caps a hung TLS / slow-loris connection so
|
|
55
|
-
// a stranded fetch can't pin the inflight slot through SIGTERM
|
|
56
|
-
// drain. Triggered via AbortController.
|
|
57
|
-
const UPSTREAM_TIMEOUT_MS = 30_000
|
|
58
|
-
|
|
59
45
|
export type NpmProxyDeps = {
|
|
60
46
|
debug: boolean
|
|
61
47
|
}
|
|
@@ -129,11 +115,12 @@ function deny(res: ServerResponse, status: number, reason: string): void {
|
|
|
129
115
|
// Same shape as `deny` but for the richer multi-field envelopes
|
|
130
116
|
// (upstream-not-json / upstream-too-large) — these can't reuse
|
|
131
117
|
// `deny` because the body carries more than `{ error }`.
|
|
132
|
-
function writeJsonEnvelope(res: ServerResponse, status: number, body:
|
|
118
|
+
function writeJsonEnvelope(res: ServerResponse, status: number, body: unknown): void {
|
|
133
119
|
if (!canWrite(res)) return
|
|
134
120
|
try {
|
|
135
|
-
|
|
136
|
-
res.
|
|
121
|
+
const out = JSON.stringify(body)
|
|
122
|
+
res.writeHead(status, { 'content-type': 'application/json', 'cache-control': 'no-store', 'content-length': Buffer.byteLength(out) })
|
|
123
|
+
res.end(out)
|
|
137
124
|
} catch {}
|
|
138
125
|
}
|
|
139
126
|
|
|
@@ -154,7 +141,7 @@ async function readRequestBody(req: IncomingMessage): Promise<Buffer | null> {
|
|
|
154
141
|
return Buffer.concat(chunks)
|
|
155
142
|
}
|
|
156
143
|
|
|
157
|
-
|
|
144
|
+
async function handleNpmAdvisories(
|
|
158
145
|
deps: NpmProxyDeps,
|
|
159
146
|
req: IncomingMessage,
|
|
160
147
|
res: ServerResponse,
|
|
@@ -162,7 +149,7 @@ export async function handleNpmAdvisories(
|
|
|
162
149
|
if (req.method !== 'POST') { deny(res, 405, 'method-not-allowed'); return }
|
|
163
150
|
// Single controller drives both the upstream deadline timer AND
|
|
164
151
|
// the client-disconnect propagation: a fetch hung past
|
|
165
|
-
//
|
|
152
|
+
// NPM_ADVISORIES_TIMEOUT_MS and a browser tab closed mid-fetch both end
|
|
166
153
|
// up aborting the same signal, which undici threads through into
|
|
167
154
|
// the body reader. Without this the inflight slot pinned by
|
|
168
155
|
// `track()` could outlive both a dead client and a wedged
|
|
@@ -187,7 +174,7 @@ export async function handleNpmAdvisories(
|
|
|
187
174
|
// doesn't fire a no-op abort — itself a no-op on a settled
|
|
188
175
|
// controller, but skipping the log noise.)
|
|
189
176
|
const controller = new AbortController()
|
|
190
|
-
const timer = setTimeout(() => { try { controller.abort() } catch {} },
|
|
177
|
+
const timer = setTimeout(() => { try { controller.abort() } catch {} }, NPM_ADVISORIES_TIMEOUT_MS)
|
|
191
178
|
const onResClose = (): void => {
|
|
192
179
|
if (!res.writableEnded) controller.abort()
|
|
193
180
|
}
|
|
@@ -219,130 +206,10 @@ export async function handleNpmAdvisories(
|
|
|
219
206
|
try { req.destroy() } catch {}
|
|
220
207
|
return
|
|
221
208
|
}
|
|
222
|
-
await
|
|
209
|
+
const result = await fetchNpmAdvisories(body, controller.signal, deps.debug)
|
|
210
|
+
writeJsonEnvelope(res, result.status, result.body)
|
|
223
211
|
} finally {
|
|
224
212
|
clearTimeout(timer)
|
|
225
213
|
res.off('close', onResClose)
|
|
226
214
|
}
|
|
227
215
|
}
|
|
228
|
-
|
|
229
|
-
async function handleNpmAdvisoriesInner(
|
|
230
|
-
deps: NpmProxyDeps,
|
|
231
|
-
body: Buffer,
|
|
232
|
-
res: ServerResponse,
|
|
233
|
-
signal: AbortSignal,
|
|
234
|
-
): Promise<void> {
|
|
235
|
-
let upstream: Response
|
|
236
|
-
try {
|
|
237
|
-
upstream = await fetch(UPSTREAM_URL, {
|
|
238
|
-
method: 'POST',
|
|
239
|
-
// Force JSON — the bulk endpoint requires it. Drop every
|
|
240
|
-
// client-supplied header to keep an upstream fingerprint from
|
|
241
|
-
// leaking through (cookies, auth, custom UA, ...). The
|
|
242
|
-
// registry's bulk endpoint doesn't need any of them for a
|
|
243
|
-
// public lookup.
|
|
244
|
-
headers: { 'content-type': 'application/json', 'accept': 'application/json' },
|
|
245
|
-
// Re-wrap as a plain Uint8Array — Buffer's underlying
|
|
246
|
-
// ArrayBufferLike type doesn't satisfy fetch's BodyInit
|
|
247
|
-
// narrowing (it can't statically rule out SharedArrayBuffer),
|
|
248
|
-
// but a copy through Uint8Array is zero-cost in practice and
|
|
249
|
-
// unambiguously typed.
|
|
250
|
-
body: new Uint8Array(body),
|
|
251
|
-
signal,
|
|
252
|
-
})
|
|
253
|
-
} catch (err: unknown) {
|
|
254
|
-
if (deps.debug) console.warn('npm-advisories upstream error:', errStack(err))
|
|
255
|
-
// Client already gone — `canWrite` (inside `deny`) gates the
|
|
256
|
-
// write so a destroyed / writableEnded socket doesn't trip
|
|
257
|
-
// ERR_STREAM_DESTROYED on the way out.
|
|
258
|
-
deny(res, 502, 'upstream-unreachable')
|
|
259
|
-
return
|
|
260
|
-
}
|
|
261
|
-
// Assert JSON on the upstream body. The Content-Type header is
|
|
262
|
-
// unreliable (Cloudflare in front of registry.npmjs.org strips it
|
|
263
|
-
// from some responses; a captive portal / WAF can declare HTML on
|
|
264
|
-
// a body that's actually JSON or vice-versa), so we don't lean on
|
|
265
|
-
// it — instead we buffer the body and parse. A successful
|
|
266
|
-
// JSON.parse is the strongest guarantee we can hand the UI's
|
|
267
|
-
// `await res.json()`. Buffering is bounded by
|
|
268
|
-
// `RESPONSE_BODY_LIMIT`; the advisories endpoint's payloads sit
|
|
269
|
-
// well under that.
|
|
270
|
-
const upstreamContentType = upstream.headers.get('content-type') ?? ''
|
|
271
|
-
let buffered: Buffer | null
|
|
272
|
-
try {
|
|
273
|
-
buffered = await readUpstreamBody(upstream)
|
|
274
|
-
} catch (err: unknown) {
|
|
275
|
-
if (deps.debug) console.warn('npm-advisories upstream body error:', errStack(err))
|
|
276
|
-
deny(res, 502, 'upstream-unreachable')
|
|
277
|
-
return
|
|
278
|
-
}
|
|
279
|
-
if (buffered === null) {
|
|
280
|
-
if (deps.debug) console.warn(`npm-advisories upstream too large: status=${upstream.status}`)
|
|
281
|
-
writeJsonEnvelope(res, 502, { error: 'upstream-too-large', upstreamStatus: upstream.status })
|
|
282
|
-
return
|
|
283
|
-
}
|
|
284
|
-
// Treat the body as UTF-8 — `JSON.parse` operates on a string and
|
|
285
|
-
// the registry's responses are always UTF-8 in practice. A
|
|
286
|
-
// non-UTF-8 byte sequence still decodes (with U+FFFD
|
|
287
|
-
// substitution); the subsequent JSON.parse fails and routes
|
|
288
|
-
// through the error branch.
|
|
289
|
-
const text = buffered.toString('utf8')
|
|
290
|
-
let parsed: unknown
|
|
291
|
-
try {
|
|
292
|
-
parsed = JSON.parse(text)
|
|
293
|
-
} catch {
|
|
294
|
-
if (deps.debug) console.warn(`npm-advisories upstream non-JSON: status=${upstream.status} ct=${upstreamContentType || '<none>'} bytes=${buffered.byteLength}`)
|
|
295
|
-
writeJsonEnvelope(res, 502, {
|
|
296
|
-
error: 'upstream-not-json',
|
|
297
|
-
upstreamStatus: upstream.status,
|
|
298
|
-
upstreamContentType: upstreamContentType || null,
|
|
299
|
-
})
|
|
300
|
-
return
|
|
301
|
-
}
|
|
302
|
-
if (!canWrite(res)) return
|
|
303
|
-
// Re-stringify rather than echoing `text` so the wire shape we
|
|
304
|
-
// emit is canonical (no upstream whitespace / BOM / trailing
|
|
305
|
-
// junk after the parsed value rides along), and so the client
|
|
306
|
-
// can rely on a single JSON document per response.
|
|
307
|
-
const out = JSON.stringify(parsed)
|
|
308
|
-
try {
|
|
309
|
-
res.writeHead(upstream.status, {
|
|
310
|
-
'content-type': 'application/json',
|
|
311
|
-
'cache-control': 'no-store',
|
|
312
|
-
'content-length': Buffer.byteLength(out),
|
|
313
|
-
})
|
|
314
|
-
res.end(out)
|
|
315
|
-
} catch {}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// Buffer the upstream response body up to RESPONSE_BODY_LIMIT.
|
|
319
|
-
// Returns null if the cap is exceeded (caller maps to a 502
|
|
320
|
-
// `upstream-too-large`), or the cumulative Buffer otherwise. A
|
|
321
|
-
// transport error mid-read (e.g. AbortSignal fired by the deadline
|
|
322
|
-
// timer or by `req` close) throws — the caller catches it.
|
|
323
|
-
//
|
|
324
|
-
// `finally { reader.cancel() }` is load-bearing on the error and
|
|
325
|
-
// cap-exceeded paths: leaving the reader locked to the body holds
|
|
326
|
-
// the underlying undici TCP socket out of the connection pool until
|
|
327
|
-
// GC, and the cap-exceeded path explicitly needs to tear the
|
|
328
|
-
// transfer down so we don't keep buffering bytes we'll never use.
|
|
329
|
-
// On the clean-drain path (done:true), cancel() is a no-op.
|
|
330
|
-
async function readUpstreamBody(upstream: Response): Promise<Buffer | null> {
|
|
331
|
-
if (!upstream.body) return Buffer.alloc(0)
|
|
332
|
-
const reader = upstream.body.getReader()
|
|
333
|
-
const chunks: Uint8Array[] = []
|
|
334
|
-
let received = 0
|
|
335
|
-
try {
|
|
336
|
-
for (;;) {
|
|
337
|
-
const { done, value } = await reader.read()
|
|
338
|
-
if (done) break
|
|
339
|
-
if (!value) continue
|
|
340
|
-
received += value.byteLength
|
|
341
|
-
if (received > RESPONSE_BODY_LIMIT) return null
|
|
342
|
-
chunks.push(value)
|
|
343
|
-
}
|
|
344
|
-
return Buffer.concat(chunks)
|
|
345
|
-
} finally {
|
|
346
|
-
try { await reader.cancel() } catch {}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Vercel Blob Private Storage BlobBackend. Paired with the Neon DB
|
|
2
|
-
// plane in `server/index.ts` when `BLOB_READ_WRITE_TOKEN` is set;
|
|
2
|
+
// plane in `server-e2e/index.ts` when `BLOB_READ_WRITE_TOKEN` is set;
|
|
3
3
|
// the combination is the supported multi-replica deployment shape
|
|
4
4
|
// (Neon for metadata, Vercel Blob for bytes — both serverless, both
|
|
5
5
|
// HTTP-backed, no shared filesystem required).
|
|
@@ -35,108 +35,10 @@
|
|
|
35
35
|
// any single resource), and the stale-staging TTL sweep drops orphan
|
|
36
36
|
// staging blobs.
|
|
37
37
|
|
|
38
|
-
import { PassThrough
|
|
39
|
-
import { Buffer } from 'node:buffer'
|
|
38
|
+
import { PassThrough } from 'node:stream'
|
|
40
39
|
import type { BlobBackend, OpenLiveResult, StagingWriter } from './blob.ts'
|
|
41
40
|
import { errMsg } from '../util.ts'
|
|
42
|
-
|
|
43
|
-
// Minimal structural shape of the bits of `@vercel/blob` we use.
|
|
44
|
-
// Kept local so the optional peer dep doesn't have to type-resolve
|
|
45
|
-
// for SQLite-only deployments. Real type details live in the
|
|
46
|
-
// installed package; the fields/parameters we touch here are stable
|
|
47
|
-
// per the SDK v2 public surface.
|
|
48
|
-
//
|
|
49
|
-
// `put` accepts the SDK's full `PutBody` union (string | Readable |
|
|
50
|
-
// Buffer | Blob | ArrayBuffer | ReadableStream | File). We only ever
|
|
51
|
-
// pass a Node `PassThrough` (a Readable), but the wider type lets
|
|
52
|
-
// callers reuse this signature for future buffer/blob bodies without
|
|
53
|
-
// type gymnastics. `copy` accepts `allowOverwrite` — REQUIRED for
|
|
54
|
-
// version bumps since the live pathname is reused on re-upload.
|
|
55
|
-
type VercelBlobBody = Readable | Buffer | string | Blob | ArrayBuffer | ReadableStream<Uint8Array>
|
|
56
|
-
type VercelBlobSdk = {
|
|
57
|
-
put: (
|
|
58
|
-
pathname: string,
|
|
59
|
-
body: VercelBlobBody,
|
|
60
|
-
options: {
|
|
61
|
-
access: 'private' | 'public'
|
|
62
|
-
allowOverwrite?: boolean
|
|
63
|
-
contentType?: string
|
|
64
|
-
token?: string
|
|
65
|
-
multipart?: boolean
|
|
66
|
-
abortSignal?: AbortSignal
|
|
67
|
-
cacheControlMaxAge?: number
|
|
68
|
-
},
|
|
69
|
-
) => Promise<{ url: string; pathname: string }>
|
|
70
|
-
head: (
|
|
71
|
-
pathname: string,
|
|
72
|
-
options?: { token?: string; abortSignal?: AbortSignal },
|
|
73
|
-
) => Promise<{ size: number; pathname: string; url: string }>
|
|
74
|
-
get: (
|
|
75
|
-
pathname: string,
|
|
76
|
-
options: {
|
|
77
|
-
access: 'private' | 'public'
|
|
78
|
-
token?: string
|
|
79
|
-
useCache?: boolean
|
|
80
|
-
abortSignal?: AbortSignal
|
|
81
|
-
},
|
|
82
|
-
) => Promise<{
|
|
83
|
-
statusCode: 200 | 304
|
|
84
|
-
stream: ReadableStream<Uint8Array> | null
|
|
85
|
-
blob: { size: number | null }
|
|
86
|
-
} | null>
|
|
87
|
-
copy: (
|
|
88
|
-
fromPathname: string,
|
|
89
|
-
toPathname: string,
|
|
90
|
-
options: {
|
|
91
|
-
access: 'private' | 'public'
|
|
92
|
-
allowOverwrite?: boolean
|
|
93
|
-
token?: string
|
|
94
|
-
contentType?: string
|
|
95
|
-
cacheControlMaxAge?: number
|
|
96
|
-
},
|
|
97
|
-
) => Promise<{ url: string; pathname: string }>
|
|
98
|
-
del: (
|
|
99
|
-
urlOrPathname: string | string[],
|
|
100
|
-
options?: { token?: string; abortSignal?: AbortSignal },
|
|
101
|
-
) => Promise<void>
|
|
102
|
-
list: (options: {
|
|
103
|
-
prefix?: string
|
|
104
|
-
cursor?: string
|
|
105
|
-
limit?: number
|
|
106
|
-
mode?: 'expanded' | 'folded'
|
|
107
|
-
token?: string
|
|
108
|
-
}) => Promise<{
|
|
109
|
-
// `uploadedAt` (a Date per the SDK v2 surface) is the blob's
|
|
110
|
-
// creation time — used by the reaper's GC grace window. Optional
|
|
111
|
-
// in the type because the `folded` listing path ignores it (only
|
|
112
|
-
// `listLiveBlobs` reads it, and it uses the default expanded mode).
|
|
113
|
-
blobs: Array<{ pathname: string; size: number; uploadedAt?: Date | string | number }>
|
|
114
|
-
folders?: string[]
|
|
115
|
-
cursor?: string
|
|
116
|
-
hasMore: boolean
|
|
117
|
-
}>
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Recognise "blob is gone" errors uniformly across read/write/delete
|
|
121
|
-
// paths so callers can treat them as success (delete) or
|
|
122
|
-
// not-found (read). The SDK exposes BlobNotFoundError as a class with
|
|
123
|
-
// `.name === 'BlobNotFoundError'`; checking the name string avoids
|
|
124
|
-
// importing the class at the top level (which would force the optional
|
|
125
|
-
// peer dep to resolve).
|
|
126
|
-
//
|
|
127
|
-
// Class-name check ONLY — the SDK's internal mapper turns every API
|
|
128
|
-
// `not_found` into BlobNotFoundError-by-name, so a bare-404 transport
|
|
129
|
-
// leak doesn't reach here. A broader `/does not exist|\b404\b/` match
|
|
130
|
-
// is DANGEROUS: it also matches BlobStoreNotFoundError's "This store
|
|
131
|
-
// does not exist.", so a config fault (revoked token, deleted store)
|
|
132
|
-
// would silently surface as every-blob-missing across reads/unlinks,
|
|
133
|
-
// masking the fatal misconfiguration. The tight name check lets
|
|
134
|
-
// BlobStoreNotFoundError / other classes propagate as real exceptions.
|
|
135
|
-
function isNotFound(err: unknown): boolean {
|
|
136
|
-
if (err == null || typeof err !== 'object') return false
|
|
137
|
-
const name = (err as { name?: unknown }).name
|
|
138
|
-
return typeof name === 'string' && name === 'BlobNotFoundError'
|
|
139
|
-
}
|
|
41
|
+
import { type VercelBlobSdk, isNotFound, loadVercelBlobSdk } from '../../server-common/vercel-blob.ts'
|
|
140
42
|
|
|
141
43
|
function liveBlobPath(tag: string, contentHash: string): string {
|
|
142
44
|
return `${tag}/${contentHash}.bin`
|
|
@@ -293,7 +195,7 @@ function buildStatStaging(sdk: VercelBlobSdk, token: string): BlobBackend['statS
|
|
|
293
195
|
const h = await sdk.head(stagingBlobPath(tag, stagingId), { token })
|
|
294
196
|
return h.size
|
|
295
197
|
} catch (err) {
|
|
296
|
-
if (isNotFound(err)) return null
|
|
198
|
+
if (isNotFound(err, sdk)) return null
|
|
297
199
|
throw err
|
|
298
200
|
}
|
|
299
201
|
}
|
|
@@ -363,8 +265,8 @@ function buildOpenLiveReader(sdk: VercelBlobSdk, token: string): BlobBackend['op
|
|
|
363
265
|
// `not-found` would emit a 404 the FS backend never emits for the
|
|
364
266
|
// same condition (blob-fs.ts maps ENOENT → `unavailable`), telling
|
|
365
267
|
// the client the resource is gone for good when it should refetch.
|
|
366
|
-
// See server/README.md's GET status table.
|
|
367
|
-
if (isNotFound(err)) return { ok: false, reason: 'unavailable', detail: 'vercel-get-not-found' }
|
|
268
|
+
// See server-e2e/README.md's GET status table.
|
|
269
|
+
if (isNotFound(err, sdk)) return { ok: false, reason: 'unavailable', detail: 'vercel-get-not-found' }
|
|
368
270
|
throw err
|
|
369
271
|
}
|
|
370
272
|
// SDK returned null (no blob) — same "bytes missing for a live row"
|
|
@@ -395,7 +297,7 @@ function buildOpenLiveReader(sdk: VercelBlobSdk, token: string): BlobBackend['op
|
|
|
395
297
|
// Blob vanished between get() and the head() size fallback (a
|
|
396
298
|
// racing reaper GC) — still the "live row present, bytes gone"
|
|
397
299
|
// transient, so `unavailable` (503), matching the get() path above.
|
|
398
|
-
if (isNotFound(headErr)) return { ok: false, reason: 'unavailable', detail: 'vercel-head-not-found' }
|
|
300
|
+
if (isNotFound(headErr, sdk)) return { ok: false, reason: 'unavailable', detail: 'vercel-head-not-found' }
|
|
399
301
|
throw headErr
|
|
400
302
|
}
|
|
401
303
|
}
|
|
@@ -426,7 +328,7 @@ function buildOpenLiveReader(sdk: VercelBlobSdk, token: string): BlobBackend['op
|
|
|
426
328
|
function buildUnlink(sdk: VercelBlobSdk, token: string, op: 'staging' | 'live', toPath: (tag: string, id: string) => string): (tag: string, id: string) => Promise<void> {
|
|
427
329
|
return async (tag, id) => {
|
|
428
330
|
try { await sdk.del(toPath(tag, id), { token }) } catch (err) {
|
|
429
|
-
if (isNotFound(err)) return
|
|
331
|
+
if (isNotFound(err, sdk)) return
|
|
430
332
|
// Don't propagate — the DB-side row drop has already
|
|
431
333
|
// committed by the time the caller reaches here, and the
|
|
432
334
|
// reaper picks up the stranded blob on its next sweep. Same
|
|
@@ -493,7 +395,7 @@ export type VercelBlobBackendOptions = {
|
|
|
493
395
|
// Vercel Blob R/W token, typically from BLOB_READ_WRITE_TOKEN.
|
|
494
396
|
// The SDK also reads it from process.env, but passing it
|
|
495
397
|
// explicitly here keeps the env-var → boot config path single-
|
|
496
|
-
// sourced through server/index.ts (matches the Neon
|
|
398
|
+
// sourced through server-e2e/index.ts (matches the Neon database URL
|
|
497
399
|
// handling — env-read at boot, threaded as a parameter).
|
|
498
400
|
token: string
|
|
499
401
|
// Test seam: inject a stub of the @vercel/blob module to avoid
|
|
@@ -507,7 +409,7 @@ export async function openVercelBlobBackend(opts: VercelBlobBackendOptions): Pro
|
|
|
507
409
|
// dep. `@ts-ignore` (not `@ts-expect-error`) so an operator who
|
|
508
410
|
// DOES install `@vercel/blob` doesn't trip TS2578 "unused
|
|
509
411
|
// directive" — same pattern as db-neon.ts.
|
|
510
|
-
const sdk: VercelBlobSdk = opts.sdk ?? (await
|
|
412
|
+
const sdk: VercelBlobSdk = opts.sdk ?? (await loadVercelBlobSdk())
|
|
511
413
|
const token = opts.token
|
|
512
414
|
return {
|
|
513
415
|
// No-op: Vercel Blob has no folder concept. The pathname's
|
|
@@ -533,9 +435,3 @@ export async function openVercelBlobBackend(opts: VercelBlobBackendOptions): Pro
|
|
|
533
435
|
listStagingIds: buildListStagingIds(sdk, token, (tag) => `${tag}/.staging/`),
|
|
534
436
|
}
|
|
535
437
|
}
|
|
536
|
-
|
|
537
|
-
async function loadSdk(): Promise<VercelBlobSdk> {
|
|
538
|
-
// @ts-ignore optional peer dep: '@vercel/blob'
|
|
539
|
-
const mod = (await import('@vercel/blob')) as VercelBlobSdk
|
|
540
|
-
return mod
|
|
541
|
-
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// the Neon DB plane for multi-replica
|
|
12
12
|
// deployments)
|
|
13
13
|
//
|
|
14
|
-
// Selected at boot in `server/index.ts` and passed to `openObjstore`
|
|
14
|
+
// Selected at boot in `server-e2e/index.ts` and passed to `openObjstore`
|
|
15
15
|
// / `openNeonObjstore`. The DB-plane code in ./store.ts, ./rest.ts,
|
|
16
16
|
// and ./reaper.ts goes through `handle.blob.*` and is backend-
|
|
17
17
|
// agnostic — no `if (vercel) … else` branching in consumers.
|
|
@@ -35,8 +35,8 @@ export type FetchMintGuard = {
|
|
|
35
35
|
size: () => number
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const DEFAULT_FETCH_MINT_WINDOW_MS = 60_000
|
|
39
|
+
const DEFAULT_FETCH_MINT_MAX_ENTRIES = 50_000
|
|
40
40
|
|
|
41
41
|
export function createFetchMintGuard(
|
|
42
42
|
{ windowMs = DEFAULT_FETCH_MINT_WINDOW_MS, maxEntries = DEFAULT_FETCH_MINT_MAX_ENTRIES }:
|
|
@@ -48,9 +48,9 @@ export type ObjstoreDeps = {
|
|
|
48
48
|
// Cross-instance pub/sub for objstore-deleted. Fired alongside the
|
|
49
49
|
// local `broadcast` after a successful delete so peers on OTHER
|
|
50
50
|
// server instances see the version drop in real time. Carries the
|
|
51
|
-
// full (tag, resourceTag, version) tuple inline — the workspace_object
|
|
51
|
+
// full (tag, resourceTag, version, incarnation) tuple inline — the workspace_object
|
|
52
52
|
// row is gone post-delete, so the bus payload IS the wire data.
|
|
53
|
-
publishObjDeleted: (tag: string, resourceTag: string, version: number) => void
|
|
53
|
+
publishObjDeleted: (tag: string, resourceTag: string, version: number, incarnation: string) => void
|
|
54
54
|
getNonce: (socket: WebSocket) => string | undefined
|
|
55
55
|
debug: boolean
|
|
56
56
|
// Auth gate for the FIRST put-begin against a never-before-seen
|
|
@@ -106,9 +106,9 @@ async function handlePutBegin(deps: ObjstoreDeps, socket: WebSocket, msg: Objsto
|
|
|
106
106
|
const resourceTag = msg.resourceTag
|
|
107
107
|
// Auth gate for the FIRST action against a never-before-seen
|
|
108
108
|
// workspace tag (no rows in workspace_revision AND none in
|
|
109
|
-
// workspace_object). Mirrors handleSave in server/index.ts; runs
|
|
109
|
+
// workspace_object). Mirrors handleSave in server-e2e/index.ts; runs
|
|
110
110
|
// AFTER sig verify so `unauthorized` only reaches a legitimate
|
|
111
|
-
// signer. Config-driven (server/config.json `password`), no-op when
|
|
111
|
+
// signer. Config-driven (server-e2e/config.json `password`), no-op when
|
|
112
112
|
// unconfigured.
|
|
113
113
|
if (deps.authGate && deps.sendUnauthorized && await deps.authGate(socket, tag)) {
|
|
114
114
|
if (socket.readyState !== socket.OPEN) return
|
|
@@ -191,13 +191,14 @@ async function handleDelete(deps: ObjstoreDeps, socket: WebSocket, msg: Objstore
|
|
|
191
191
|
// observes its own PUTs as echo events. The same symmetry on
|
|
192
192
|
// `onDeleted` lets `session.onDeleted` fire for the session's
|
|
193
193
|
// own deletes — pinned by `tests/objstore-client-races.test.js`.
|
|
194
|
-
|
|
194
|
+
// A successful nonempty delete matched this authenticated incarnation.
|
|
195
|
+
deps.broadcast(tag, { type: 'objstore-deleted', workspaceTag: tag, resourceTag, version: result.deletedVersion, incarnation: prevIncarnation! }, null)
|
|
195
196
|
// Cross-instance fan-out (Neon mode). The workspace_object row is
|
|
196
197
|
// gone post-delete so the bus payload carries (tag, resourceTag,
|
|
197
|
-
// version) inline; the receiver builds its `objstore-deleted`
|
|
198
|
+
// version, incarnation) inline; the receiver builds its `objstore-deleted`
|
|
198
199
|
// broadcast directly from the bus envelope. SQLite mode publishes
|
|
199
200
|
// to a no-op.
|
|
200
|
-
deps.publishObjDeleted(tag, resourceTag, result.deletedVersion)
|
|
201
|
+
deps.publishObjDeleted(tag, resourceTag, result.deletedVersion, prevIncarnation!)
|
|
201
202
|
if (deps.debug) console.log(`objstore delete → ${debugTag(tag)}/${resourceTag.slice(0, 8)}…`)
|
|
202
203
|
}
|
|
203
204
|
|
|
@@ -228,7 +229,7 @@ async function handleFetch(deps: ObjstoreDeps, socket: WebSocket, msg: ObjstoreF
|
|
|
228
229
|
// the reaper's TTL pass within `STAGING_TTL_MS_DEFAULT` — no per-
|
|
229
230
|
// socket bookkeeping is needed on disconnect today. If that ever
|
|
230
231
|
// changes, wire a `cleanupSocket(socket)` into both this bundle and
|
|
231
|
-
// server/
|
|
232
|
+
// server-e2e/ws-server.ts's per-socket close handler.
|
|
232
233
|
|
|
233
234
|
export type ObjstoreHandlers = {
|
|
234
235
|
handlePutBegin: (s: WebSocket, m: ObjstorePutBeginMsg) => Promise<void>
|
|
@@ -15,12 +15,12 @@ import { errStack } from '../util.ts'
|
|
|
15
15
|
|
|
16
16
|
export type ObjstoreInitDeps = {
|
|
17
17
|
// Pre-opened storage handle, sharing the SQLite connection with
|
|
18
|
-
// the workspace_revision handle in server/db.ts.
|
|
18
|
+
// the workspace_revision handle in server-e2e/db.ts.
|
|
19
19
|
handle: Handle
|
|
20
20
|
reapIntervalMs: number
|
|
21
|
-
//
|
|
21
|
+
// Automatic-sweep switch (OBJSTORE_REAP_DISABLED). When true, NEITHER the boot
|
|
22
22
|
// sweep nor the periodic timer runs: `startupReap` resolves immediately
|
|
23
|
-
// and
|
|
23
|
+
// and no timer is installed. Orphaned/superseded blobs and stale
|
|
24
24
|
// staging rows then accumulate unbounded — only safe if an external job
|
|
25
25
|
// handles GC. Omitted/false → reaper runs (the default). See config.ts.
|
|
26
26
|
reapDisabled?: boolean
|
|
@@ -28,9 +28,9 @@ export type ObjstoreInitDeps = {
|
|
|
28
28
|
broadcast: (tag: string, msg: object, except: WebSocket | null) => void
|
|
29
29
|
// Cross-instance pub/sub publishers. SQLite mode passes no-ops; Neon
|
|
30
30
|
// mode passes Postgres LISTEN/NOTIFY-backed implementations. See
|
|
31
|
-
// server/pubsub.ts for the bus design.
|
|
31
|
+
// server-e2e/pubsub.ts for the bus design.
|
|
32
32
|
publishObjPut: (tag: string, resourceTag: string) => void
|
|
33
|
-
publishObjDeleted: (tag: string, resourceTag: string, version: number) => void
|
|
33
|
+
publishObjDeleted: (tag: string, resourceTag: string, version: number, incarnation: string) => void
|
|
34
34
|
getNonce: (socket: WebSocket) => string | undefined
|
|
35
35
|
debug: boolean
|
|
36
36
|
// Auth gate for the FIRST objstore-put-begin against a workspace
|
|
@@ -45,7 +45,7 @@ export type ObjstoreInitDeps = {
|
|
|
45
45
|
// process behaviour). Multi-replica deployments MUST supply a
|
|
46
46
|
// shared secret here so a token minted on one replica's WS plane
|
|
47
47
|
// validates on another replica's REST plane (the WS-to-REST hop
|
|
48
|
-
// is not load-balancer-pinned). See server/index.ts boot logic
|
|
48
|
+
// is not load-balancer-pinned). See server-e2e/index.ts boot logic
|
|
49
49
|
// for the env var (`OBJSTORE_TOKEN_SECRET`).
|
|
50
50
|
tokenSecret?: TokenSecret
|
|
51
51
|
// New-workspace operator gate for the REST put-begin mint — returns
|
|
@@ -59,6 +59,7 @@ export type ObjstoreInitDeps = {
|
|
|
59
59
|
export type ObjstoreInit = {
|
|
60
60
|
handlers: ObjstoreHandlers
|
|
61
61
|
restDeps: ObjstoreRestDeps
|
|
62
|
+
reap: () => Promise<void>
|
|
62
63
|
startupReap: Promise<void>
|
|
63
64
|
// Cancels the periodic timer AND resolves only after any
|
|
64
65
|
// currently-in-flight sweep has finished, so shutdown can safely
|
|
@@ -102,31 +103,22 @@ export function initObjstore(deps: ObjstoreInitDeps): ObjstoreInit {
|
|
|
102
103
|
let inFlight: Promise<void> | null = null
|
|
103
104
|
function enqueueSweep(): Promise<void> {
|
|
104
105
|
if (inFlight) return inFlight
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
// cleaned, and operators need to see it. Inner catch makes the
|
|
108
|
-
// promise resolve so callers (startupReap awaiter + setInterval)
|
|
109
|
-
// don't have to handle rejection.
|
|
110
|
-
const p = reapOrphans(handle).catch((err) => {
|
|
111
|
-
console.warn('objstore reaper error:', errStack(err))
|
|
112
|
-
}).finally(() => { if (inFlight === p) inFlight = null })
|
|
106
|
+
// Keep failures visible to explicit callers; automatic sweeps log them.
|
|
107
|
+
const p = reapOrphans(handle).finally(() => { if (inFlight === p) inFlight = null })
|
|
113
108
|
inFlight = p
|
|
114
109
|
return p
|
|
115
110
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
// nothing to clear or drain. Loud, unconditional warning — with GC off,
|
|
120
|
-
// orphaned/superseded blobs and stale staging rows are never reclaimed
|
|
121
|
-
// (they accumulate until an external job, if any, collects them).
|
|
111
|
+
const drain = async () => { if (inFlight) await inFlight.catch(() => {}) }
|
|
112
|
+
const automaticSweep = () => enqueueSweep().catch(err => console.warn('objstore reaper error:', errStack(err)))
|
|
113
|
+
// Explicit cleanup remains available when automatic sweeps are disabled.
|
|
122
114
|
if (deps.reapDisabled) {
|
|
123
|
-
console.warn('objstore: reaper DISABLED (OBJSTORE_REAP_DISABLED) —
|
|
124
|
-
return { handlers, restDeps, startupReap: Promise.resolve(), stopReaper:
|
|
115
|
+
console.warn('objstore: automatic reaper DISABLED (OBJSTORE_REAP_DISABLED) — use /api/reap or an external cleanup job')
|
|
116
|
+
return { handlers, restDeps, reap: enqueueSweep, startupReap: Promise.resolve(), stopReaper: drain }
|
|
125
117
|
}
|
|
126
118
|
// Caller awaits this before accepting traffic so a fresh boot
|
|
127
119
|
// can't hand out list / fetch / put-begin against a tag whose
|
|
128
120
|
// on-disk state still has stranded files from a prior crash.
|
|
129
|
-
const startupReap =
|
|
121
|
+
const startupReap = automaticSweep()
|
|
130
122
|
// Jittered start of the periodic timer. Multi-replica deploys
|
|
131
123
|
// (Neon + Vercel Blob) commonly boot N replicas in tight lock-step
|
|
132
124
|
// (deploy rollout, cluster restart), which would otherwise sync every
|
|
@@ -139,20 +131,20 @@ export function initObjstore(deps: ObjstoreInitDeps): ObjstoreInit {
|
|
|
139
131
|
let reapTimer: ReturnType<typeof setInterval> | null = null
|
|
140
132
|
const jitterMs = Math.floor(Math.random() * deps.reapIntervalMs)
|
|
141
133
|
const firstTimer = setTimeout(() => {
|
|
142
|
-
|
|
143
|
-
reapTimer = setInterval(
|
|
134
|
+
void automaticSweep()
|
|
135
|
+
reapTimer = setInterval(automaticSweep, deps.reapIntervalMs)
|
|
144
136
|
reapTimer.unref?.()
|
|
145
137
|
}, deps.reapIntervalMs + jitterMs)
|
|
146
138
|
firstTimer.unref?.()
|
|
147
139
|
return {
|
|
148
|
-
handlers, restDeps, startupReap,
|
|
140
|
+
handlers, restDeps, reap: enqueueSweep, startupReap,
|
|
149
141
|
stopReaper: async () => {
|
|
150
142
|
clearTimeout(firstTimer)
|
|
151
143
|
if (reapTimer) clearInterval(reapTimer)
|
|
152
144
|
// Drain whichever sweep is currently running (startup or
|
|
153
145
|
// periodic) — either could be mid-readdir/unlink at SIGTERM
|
|
154
146
|
// time and would otherwise outlive `handle.close()`.
|
|
155
|
-
|
|
147
|
+
await drain()
|
|
156
148
|
},
|
|
157
149
|
}
|
|
158
150
|
}
|
|
@@ -121,7 +121,7 @@ async function reapStaleStagingRows(handle: Handle, now: number, stagingTtlMs: n
|
|
|
121
121
|
// Push the staleness filter into SQL so the
|
|
122
122
|
// `workspace_object_staging_begun_at_idx` index handles the scan.
|
|
123
123
|
// The snapshot is O(stale-rows) cluster-wide. DB-layout audit
|
|
124
|
-
// `server/objstore/store.ts`.
|
|
124
|
+
// `server-e2e/objstore/store.ts`.
|
|
125
125
|
const staleBefore = now - stagingTtlMs
|
|
126
126
|
const staging = await handle.listAllStaging.all(staleBefore) as StagingRow[]
|
|
127
127
|
for (const s of staging) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// envelope so clients parse one shape; the 409 variant additionally
|
|
4
4
|
// carries the live version/incarnation so a PUT / put-begin can rebase.
|
|
5
5
|
// Reasons (400/401/403/404/405/409/410/411/500/503) are documented in
|
|
6
|
-
// server/README.md and the client decides recovery from the code —
|
|
6
|
+
// server-e2e/README.md and the client decides recovery from the code —
|
|
7
7
|
// probe-distinguishing defense isn't a goal: the richer PUT/GET reasons are
|
|
8
8
|
// reachable only after the bearer-token check, while the public surfaces (an
|
|
9
9
|
// unauthed GET/PUT, or the signature-authed POST mint) expose only
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// fetch/put return the SAME token shape the WS path sends, for the UNCHANGED
|
|
10
10
|
// bearer-token GET / PUT byte transfers; delete mutates in place and returns
|
|
11
11
|
// `{ deletedVersion }` (no token — there are no bytes to move). See
|
|
12
|
-
// server/README.md "REST endpoints & tokens".
|
|
12
|
+
// server-e2e/README.md "REST endpoints & tokens".
|
|
13
13
|
|
|
14
14
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
15
15
|
import { Buffer } from 'node:buffer'
|
|
@@ -219,6 +219,6 @@ async function handleRestDelete(
|
|
|
219
219
|
// fans out to subscribers (including the originator, matching the WS path's
|
|
220
220
|
// `except: null`) so peers' `onDeleted` fire.
|
|
221
221
|
if (result.deletedVersion === 0) return
|
|
222
|
-
deps.broadcast(route.tag, { type: 'objstore-deleted', workspaceTag: route.tag, resourceTag: route.resourceTag, version: result.deletedVersion }, null)
|
|
223
|
-
deps.publishObjDeleted(route.tag, route.resourceTag, result.deletedVersion)
|
|
222
|
+
deps.broadcast(route.tag, { type: 'objstore-deleted', workspaceTag: route.tag, resourceTag: route.resourceTag, version: result.deletedVersion, incarnation: prevIncarnation! }, null)
|
|
223
|
+
deps.publishObjDeleted(route.tag, route.resourceTag, result.deletedVersion, prevIncarnation!)
|
|
224
224
|
}
|