@preventive/triage 1.0.0-alpha.9 → 1.0.0-alpha.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +16 -78
- package/cli.js +6 -0
- package/client/dependency-paths.d.ts +3 -0
- package/client/dependency-paths.js +36 -0
- package/client/finding-link.js +305 -0
- package/client/linked-findings.d.ts +1 -0
- package/client/linked-findings.js +115 -0
- package/common/bundle-commit.d.ts +1 -0
- package/common/bundle-commit.js +4 -0
- package/common/bundle-compare-diff.d.ts +6 -0
- package/common/bundle-compare-diff.js +378 -0
- package/common/bundle-compare-inputs.d.ts +3 -0
- package/common/bundle-compare-inputs.js +141 -0
- package/common/bundle-compare-versions.js +172 -0
- package/common/bundle-comparison.d.ts +8 -0
- package/common/bundle-comparison.js +69 -0
- package/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.d.ts +15 -0
- package/common/bundle-metadata.js +226 -0
- package/common/bundle-pkg-of.d.ts +1 -0
- package/common/bundle-pkg-of.js +90 -0
- package/common/bundle-reasons.d.ts +6 -0
- package/common/bundle-reasons.js +58 -0
- package/common/bundle-source-links.d.ts +6 -0
- package/common/bundle-source-links.js +216 -0
- package/common/bundle-sourcemap.d.ts +10 -0
- package/common/bundle-sourcemap.js +100 -0
- package/common/bundle-sources.d.ts +10 -0
- package/common/bundle-sources.js +374 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +80 -0
- package/common/default-scan-models.ts +37 -0
- package/common/dependency-reviews.d.ts +19 -0
- package/common/dependency-reviews.js +67 -0
- package/common/finding-duplicates.js +63 -0
- package/common/finding-filters.js +313 -0
- package/common/finding-id.js +47 -0
- package/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/github-issue-labels.d.ts +3 -0
- package/common/github-issue-labels.js +42 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +15 -0
- package/common/line-diff.js +188 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +43 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/directory-packages.ts +28 -0
- package/common/managed/finding-detail.d.ts +5 -0
- package/common/managed/finding-detail.js +75 -0
- package/common/managed/finding-values.d.ts +2 -0
- package/common/managed/finding-values.js +138 -0
- package/common/managed/github-agents.ts +114 -0
- package/common/managed/github-logins.ts +49 -0
- package/common/managed/lite-name.d.ts +2 -0
- package/common/managed/lite-name.js +20 -0
- package/common/managed/npm-packages.d.ts +9 -0
- package/common/managed/npm-packages.js +63 -0
- package/common/managed/permissions.ts +31 -0
- package/common/managed/report-content.ts +72 -0
- package/common/managed/report-filter.ts +120 -0
- package/common/managed/repository-alias.ts +65 -0
- package/common/managed/review-view-routes.js +23 -0
- package/common/managed/risk-routes.js +30 -0
- package/common/managed/roles.ts +48 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +386 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/stasis-config.ts +7 -0
- package/common/managed/team-app.d.ts +19 -0
- package/common/managed/team-app.js +129 -0
- package/common/managed/team-filters.js +26 -0
- package/common/managed/triage.ts +83 -0
- package/common/managed/upload-seal.ts +126 -0
- package/common/npm-token.d.ts +2 -0
- package/common/npm-token.js +14 -0
- package/common/pretty-json.js +123 -0
- package/common/pretty-kinds.js +20 -0
- package/common/pretty-print.d.ts +7 -0
- package/common/pretty-print.js +41 -0
- package/common/pretty-sourcemap.js +70 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/common/revalidation-conflicts.js +48 -0
- package/common/revalidation-input-groups.js +56 -0
- package/common/scan-server.ts +13 -0
- package/common/security-links.d.ts +5 -0
- package/common/security-links.js +33 -0
- package/common/server-info.ts +46 -0
- package/common/sourcemap-listing.js +78 -0
- package/common/sourcemap-mappings.js +136 -0
- package/common/sourcemap-unlist.js +85 -0
- package/common/stasis-files.d.ts +5 -0
- package/common/stasis-files.js +20 -0
- package/common/stasis-tgz.d.ts +6 -0
- package/common/stasis-tgz.js +27 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/whitespace-insensitive.js +19 -0
- package/common/workspace-app.js +91 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +2 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-3DOSBILK.js +4 -0
- package/out/chunk-55YIWY3H.js +5 -0
- package/out/chunk-5AVGKFMR.js +1 -0
- package/out/chunk-5PWEAEA5.js +1 -0
- package/out/chunk-6VOB5WXX.js +2 -0
- package/out/chunk-6Y6PZ2BU.js +9 -0
- package/out/chunk-74JZTGTO.js +11 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-7HP2VYIC.js +2 -0
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-A4BBBHQU.js +1 -0
- package/out/chunk-B64CTMVU.js +4 -0
- package/out/chunk-BEKYZCPX.js +14 -0
- package/out/chunk-BZJU5EEV.js +1 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-CJVMNJDZ.js +3 -0
- package/out/chunk-CU3FPB3P.js +1 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-DUASGS2O.js +8 -0
- package/out/chunk-EEJA7JBI.js +13 -0
- package/out/chunk-ESXA7KID.js +1 -0
- package/out/chunk-FSU2PLJL.js +1 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GX5UXWT4.js +1 -0
- package/out/chunk-HGWFRZNC.js +267 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-JZAROLQT.js +40 -0
- package/out/chunk-K4XJHM2T.js +1 -0
- package/out/chunk-KP2XM324.js +6 -0
- package/out/chunk-LRWB6QVO.js +1 -0
- package/out/chunk-LVSLM7HB.js +1 -0
- package/out/chunk-LVW7WWV4.js +1 -0
- package/out/chunk-N57OWFKY.js +15 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-PKLVXUEI.js +11 -0
- package/out/chunk-PLGH63UC.js +2 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QD3IBSF4.js +7 -0
- package/out/chunk-QI66YA4F.js +1 -0
- package/out/chunk-QRKFPLA4.js +80 -0
- package/out/chunk-R3NZFXVR.js +1 -0
- package/out/chunk-R5O6FAW4.js +2 -0
- package/out/chunk-RAM3GDAD.js +1 -0
- package/out/chunk-RPNO56H2.js +1 -0
- package/out/chunk-SMNFBOLO.js +10 -0
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-SZTCJVZJ.js +55 -0
- package/out/chunk-SZWPYLPC.js +1 -0
- package/out/chunk-TKPNRQNN.js +3 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-UJP4PQJA.js +1 -0
- package/out/chunk-UJSJMXEG.js +1 -0
- package/out/chunk-UR4WYMIP.js +1 -0
- package/out/chunk-UTYWTUTC.js +1 -0
- package/out/chunk-VHEXSGGP.js +1 -0
- package/out/chunk-VYYUMYVW.js +9 -0
- package/out/chunk-WBK5ZN4K.js +3 -0
- package/out/chunk-WCDYSIKG.js +1 -0
- package/out/chunk-XM4RLC4A.js +2 -0
- package/out/chunk-XRAAYXPR.js +1 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +35 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +26 -0
- package/out/dialogs.js +40 -0
- package/out/github-issue-authorized.html +3 -0
- package/out/github-issue-authorized.js +1 -0
- package/out/graph.js +19 -5
- package/out/index.html +105 -25
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +367 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -148
- package/package.json +416 -64
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +287 -0
- package/risk/actions/scripts/commands.js +182 -0
- package/risk/actions/scripts/grade.js +113 -0
- package/risk/actions/scripts/packages.js +123 -0
- package/risk/actions/scripts/shell.js +169 -0
- package/risk/actions/uses.js +94 -0
- package/risk/actions/workflow.js +183 -0
- package/risk/files/characters.js +354 -0
- package/risk/files/hosts.js +206 -0
- package/risk/files/readability.js +185 -0
- package/risk/files/runs-code.js +568 -0
- package/risk/files/script.js +420 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +309 -0
- package/risk/index.js +12 -0
- package/risk/npm/assess.js +303 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +236 -0
- package/risk/npm/dependencies.js +172 -0
- package/risk/npm/diff.js +79 -0
- package/risk/npm/downloads.js +84 -0
- package/risk/npm/files.js +445 -0
- package/risk/npm/held.js +67 -0
- package/risk/npm/install-scripts.js +34 -0
- package/risk/npm/malware.js +38 -0
- package/risk/npm/manifest.js +65 -0
- package/risk/npm/new-dependency.js +60 -0
- package/risk/npm/old-version.js +108 -0
- package/risk/npm/registry.js +401 -0
- package/risk/npm/release.js +85 -0
- package/risk/npm/score.js +59 -0
- package/risk/npm/specs.js +124 -0
- package/risk/npm/tarball.js +169 -0
- package/server-common/database-config.ts +16 -0
- package/server-common/initialize.ts +18 -0
- package/server-common/npm-advisories.ts +101 -0
- package/{server → server-common}/origin.ts +5 -5
- package/server-common/reap.ts +48 -0
- package/server-common/scan-config.ts +19 -0
- package/server-common/standalone.ts +29 -0
- package/server-common/storage-crypto.ts +182 -0
- package/server-common/storage-log.ts +38 -0
- package/server-common/vercel-blob.ts +103 -0
- package/server-e2e/app.ts +487 -0
- package/{server → server-e2e}/bus-receiver.ts +2 -1
- package/{server → server-e2e}/cli.js +9 -4
- package/{server → server-e2e}/config.ts +52 -42
- package/{server → server-e2e}/db-neon.ts +2 -2
- package/{server → server-e2e}/db-revision-sql.ts +1 -1
- package/{server → server-e2e}/db-stmt.ts +2 -2
- package/{server → server-e2e}/db.ts +7 -7
- package/{server → server-e2e}/http.ts +44 -13
- package/{server → server-e2e}/hub.ts +40 -9
- package/server-e2e/index.ts +17 -0
- package/server-e2e/lifecycle.ts +95 -0
- package/{server → server-e2e}/neon-driver.ts +2 -2
- package/{server → server-e2e}/npm-proxy.ts +12 -145
- package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
- package/{server → server-e2e}/objstore/blob.ts +1 -1
- package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
- package/{server → server-e2e}/objstore/handlers.ts +9 -8
- package/{server → server-e2e}/objstore/init.ts +19 -27
- package/{server → server-e2e}/objstore/reaper.ts +1 -1
- package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
- package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
- package/{server → server-e2e}/objstore/rest.ts +3 -3
- package/{server → server-e2e}/objstore/store-neon.ts +6 -10
- package/{server → server-e2e}/objstore/store.ts +7 -7
- package/{server → server-e2e}/objstore/tokens.ts +2 -2
- package/{server → server-e2e}/pubsub.ts +12 -9
- package/{server → server-e2e}/sign.ts +4 -4
- package/{server → server-e2e}/sse-server.ts +3 -3
- package/{server → server-e2e}/static.ts +18 -17
- package/{server → server-e2e}/sync-handlers.ts +56 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +269 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +21 -0
- package/server-managed/blob-store.ts +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +176 -0
- package/server-managed/bundle-advisory-inventory.ts +85 -0
- package/server-managed/bundle-build-diagnostics.d.ts +10 -0
- package/server-managed/bundle-build-diagnostics.js +23 -0
- package/server-managed/bundle-build-leases.ts +41 -0
- package/server-managed/bundle-build-worker.js +387 -0
- package/server-managed/bundle-build.ts +328 -0
- package/server-managed/bundle-cache.ts +261 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +91 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +139 -0
- package/server-managed/bundle-validation.ts +33 -0
- package/server-managed/bundle.ts +151 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +43 -0
- package/server-managed/comments.ts +138 -0
- package/server-managed/commit-coauthors.ts +105 -0
- package/server-managed/commit-lockfiles.ts +78 -0
- package/server-managed/comparison.ts +51 -0
- package/server-managed/config.ts +163 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1950 -0
- package/server-managed/db-neon.ts +401 -0
- package/server-managed/db-schema.ts +271 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +150 -0
- package/server-managed/dependabot-access.ts +85 -0
- package/server-managed/dependabot-alerts.ts +197 -0
- package/server-managed/dependency-review-comments.ts +158 -0
- package/server-managed/dependency-reviews.ts +369 -0
- package/server-managed/github-accounts.ts +59 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +347 -0
- package/server-managed/github-errors.ts +92 -0
- package/server-managed/github-graphql.ts +42 -0
- package/server-managed/github-issue-links.ts +264 -0
- package/server-managed/github-issue-oauth.ts +30 -0
- package/server-managed/github-issues.ts +169 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +218 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +290 -0
- package/server-managed/github-requests.ts +181 -0
- package/server-managed/github-users.ts +53 -0
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +6722 -0
- package/server-managed/import-triage.ts +51 -0
- package/server-managed/index.ts +204 -0
- package/server-managed/kept-briefly.ts +37 -0
- package/server-managed/kept.ts +28 -0
- package/server-managed/known-listings.ts +112 -0
- package/server-managed/link-reports.ts +149 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +234 -0
- package/server-managed/lockfile-scope.ts +58 -0
- package/server-managed/lru.ts +30 -0
- package/server-managed/managed-issues.ts +92 -0
- package/server-managed/management-catalog.ts +45 -0
- package/server-managed/management.ts +116 -0
- package/server-managed/npm-delta-worker.js +203 -0
- package/server-managed/npm-delta.ts +277 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +274 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +477 -0
- package/server-managed/npm-patch-paths.ts +86 -0
- package/server-managed/npm-patch.ts +457 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +310 -0
- package/server-managed/object-storage-disk.ts +147 -0
- package/server-managed/object-storage-vercel.ts +71 -0
- package/server-managed/object-storage.ts +82 -0
- package/server-managed/package-entry-points.ts +127 -0
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +4 -0
- package/server-managed/pretty-format.js +27 -0
- package/server-managed/pretty-print.ts +444 -0
- package/server-managed/public-workspace.ts +242 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +370 -0
- package/server-managed/pull-dependency-reviews.ts +458 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/pulse-walk.ts +164 -0
- package/server-managed/queue.ts +54 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +30 -0
- package/server-managed/rename-diff.ts +237 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-opening.ts +77 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +185 -0
- package/server-managed/report-store.ts +77 -0
- package/server-managed/repository-actions.ts +220 -0
- package/server-managed/repository-agents.ts +422 -0
- package/server-managed/repository-aliases.ts +119 -0
- package/server-managed/repository-browser.ts +362 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +222 -0
- package/server-managed/repository-dependency-reviews.ts +220 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +444 -0
- package/server-managed/repository-issues.ts +293 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +409 -0
- package/server-managed/repository-risk-assess.ts +179 -0
- package/server-managed/repository-risk-audit.ts +145 -0
- package/server-managed/repository-risk-caches.ts +56 -0
- package/server-managed/repository-risk-kept.ts +86 -0
- package/server-managed/repository-risk-read.ts +296 -0
- package/server-managed/repository-risk-stasis.ts +61 -0
- package/server-managed/repository-risk-turn.ts +97 -0
- package/server-managed/repository-risk.ts +528 -0
- package/server-managed/repository-squashes.ts +160 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +170 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +121 -0
- package/server-managed/session.ts +132 -0
- package/server-managed/slugs.ts +38 -0
- package/server-managed/solidity-entry-points.ts +71 -0
- package/server-managed/sql-postgres.ts +34 -0
- package/server-managed/sql.ts +107 -0
- package/server-managed/stasis-config.ts +147 -0
- package/server-managed/stasis-dependencies.ts +280 -0
- package/server-managed/static.ts +28 -0
- package/server-managed/storage-command.ts +16 -0
- package/server-managed/storage-db.ts +183 -0
- package/server-managed/storage-encryption.ts +288 -0
- package/server-managed/storage-maintenance.ts +259 -0
- package/server-managed/storage-payload.ts +121 -0
- package/server-managed/storage-stores.ts +91 -0
- package/server-managed/storage.ts +82 -0
- package/server-managed/team-app-summaries.ts +57 -0
- package/server-managed/team-app.ts +162 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-icons.ts +50 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-progress.ts +77 -0
- package/server-managed/team-reports.ts +369 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +181 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +135 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +275 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +170 -0
- package/server.ts +70 -0
- package/strip-types-loader.js +13 -10
- package/server/index.ts +0 -480
- package/server/lifecycle.ts +0 -208
- /package/{LICENSE → LICENSE-MIT} +0 -0
- /package/{server → server-e2e}/auth.ts +0 -0
- /package/{server → server-e2e}/config.example.json +0 -0
- /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
- /package/{server → server-e2e}/objstore/fs.ts +0 -0
- /package/{server → server-e2e}/objstore/sign.ts +0 -0
- /package/{server → server-e2e}/peer.ts +0 -0
- /package/{server → server-e2e}/sse-session.ts +0 -0
- /package/{server → server-e2e}/util.ts +0 -0
- /package/{server → server-e2e}/validation.ts +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// A lockfile's advisories, as a repository risk scan asks them
|
|
2
|
+
// (repository-risk.ts): npm's registry's of its packages of the registry or
|
|
3
|
+
// a mirror, asked at once, as `npm audit` asks, each told with whether it is
|
|
4
|
+
// of malware, as upstream tells (`malware`); kept by the lockfile's blob, in
|
|
5
|
+
// the instance's memory and the source's `audits`, for RISK_KEPT_MS, as npm
|
|
6
|
+
// publishes advisories, or why they couldn't be had for AUDIT_FAILED_KEPT_MS.
|
|
7
|
+
// Told with those its packages' repositories publish (the source's
|
|
8
|
+
// `repositories`) as known then, never waited on; where those weren't all
|
|
9
|
+
// known fresh, again with their listings waited on, and where packages'
|
|
10
|
+
// repositories still weren't known, once more (ToldAudit `again`, auditAgain),
|
|
11
|
+
// those still to be had as a scan's part ends had by its next (PendingAudit).
|
|
12
|
+
import { createHash } from 'node:crypto'
|
|
13
|
+
import type { Advisory } from '@preventive/upstream/advisories.js'
|
|
14
|
+
import { isExactVersion } from '@preventive/upstream/semver.js'
|
|
15
|
+
import { isNpmPackageName } from '../common/managed/npm-packages.js'
|
|
16
|
+
import type { LockedPackage } from './locked-packages.ts'
|
|
17
|
+
import type { Lru } from './lru.ts'
|
|
18
|
+
import type { KeptStore } from './npm-kept.ts'
|
|
19
|
+
import { RISK_KEPT_MS, type RiskFailure, failureOf } from './repository-risk-assess.ts'
|
|
20
|
+
|
|
21
|
+
export type AdvisoryRow = Omit<Advisory, 'malware'> & { malware: boolean }
|
|
22
|
+
// A lockfile's advisories, or why they couldn't be had.
|
|
23
|
+
export type Audit = AdvisoryRow[] | RiskFailure
|
|
24
|
+
// A lockfile's audit as told, and whether its repositories' advisories were
|
|
25
|
+
// had (`had`: without them where they couldn't be), and where they weren't
|
|
26
|
+
// all known fresh, how to have it with them as they are then.
|
|
27
|
+
export type ToldAudit = { audit: Audit; had: boolean; again: ((signal: AbortSignal) => Promise<ToldAudit | null>) | null }
|
|
28
|
+
type AskedVersions = { name: string; versions: string[] }[]
|
|
29
|
+
|
|
30
|
+
export interface AuditSource {
|
|
31
|
+
// npm's registry's advisories of these packages' versions, asked at once.
|
|
32
|
+
advisories(packages: AskedVersions, signal: AbortSignal): Promise<Advisory[]>
|
|
33
|
+
// Those their repositories publish of them, as known: none waited on, but
|
|
34
|
+
// with `wait`, those not known fresh, until `signal` aborts. `again` where
|
|
35
|
+
// some weren't known fresh (a package's repository or its listing, asked
|
|
36
|
+
// behind meanwhile).
|
|
37
|
+
repositories?(packages: AskedVersions, signal: AbortSignal, wait: boolean): Promise<{ advisories: Advisory[]; again: boolean }>
|
|
38
|
+
// Where audits are kept beyond this instance, by the lockfile's blob.
|
|
39
|
+
audits?: KeptStore<Audit>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// How long a lockfile's advisories that couldn't be had are told so, rather
|
|
43
|
+
// than asked again: a scan's next parts don't wait on an audit that failed,
|
|
44
|
+
// as by timing out, again and again.
|
|
45
|
+
const AUDIT_FAILED_KEPT_MS = 10 * 60_000
|
|
46
|
+
|
|
47
|
+
// Whether an audit kept `at` is told as it is: its advisories within
|
|
48
|
+
// RISK_KEPT_MS, why they couldn't be had within AUDIT_FAILED_KEPT_MS.
|
|
49
|
+
const isFresh = ({ at, audit }: { at: number; audit: Audit }) => Date.now() - at < (Array.isArray(audit) ? RISK_KEPT_MS : AUDIT_FAILED_KEPT_MS)
|
|
50
|
+
|
|
51
|
+
// The audits of lockfiles, each of its `packages` by its `key` (auditLockfile),
|
|
52
|
+
// `inTurn` with others, asked at once: each null where it has none to ask
|
|
53
|
+
// of, or once `signal` aborts. Each is the caller's to tell once it may.
|
|
54
|
+
export function auditLockfiles(source: AuditSource, memory: Lru<{ at: number; audit: Audit }>, signal: AbortSignal,
|
|
55
|
+
lockfiles: { key: string; packages: readonly LockedPackage[] | null }[], inTurn: <T>(work: () => Promise<T>) => Promise<T>): Promise<ToldAudit | null>[] {
|
|
56
|
+
return lockfiles.map(({ key, packages }) => {
|
|
57
|
+
const audit = packages ? inTurn(() => (signal.aborted ? Promise.resolve(null) : auditLockfile(source, memory, signal, key, packages))) : Promise.resolve(null)
|
|
58
|
+
// One no longer waited on, as the scan stopped, fails alone.
|
|
59
|
+
audit.catch(() => {})
|
|
60
|
+
return audit
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The audit of a lockfile's `packages`, by its `key` as kept (`memory`, then
|
|
65
|
+
// the source's), else asked and kept, told with its repositories'; null
|
|
66
|
+
// where it locks none to ask of, or once `signal` aborts.
|
|
67
|
+
async function auditLockfile(source: AuditSource, memory: Lru<{ at: number; audit: Audit }>, signal: AbortSignal, key: string,
|
|
68
|
+
packages: readonly LockedPackage[]): Promise<ToldAudit | null> {
|
|
69
|
+
const versions = new Map<string, Set<string>>()
|
|
70
|
+
for (const { name, version, source: from } of packages) {
|
|
71
|
+
if ((from !== 'registry' && from !== 'mirror') || !isNpmPackageName(name) || !isExactVersion(version)) continue
|
|
72
|
+
if (!versions.has(name)) versions.set(name, new Set())
|
|
73
|
+
versions.get(name)!.add(version)
|
|
74
|
+
}
|
|
75
|
+
if (versions.size === 0) return null
|
|
76
|
+
const asked = [...versions].map(([name, each]) => ({ name, versions: [...each] }))
|
|
77
|
+
let kept = memory.get(key)
|
|
78
|
+
if (!kept || !isFresh(kept)) {
|
|
79
|
+
const stored = await source.audits?.read(key)
|
|
80
|
+
kept = stored ? { at: stored.at, audit: stored.value } : undefined
|
|
81
|
+
}
|
|
82
|
+
if (kept && isFresh(kept)) { memory.set(key, kept); return await withRepositories(source, kept.audit, asked, signal) }
|
|
83
|
+
let audit: Audit
|
|
84
|
+
try {
|
|
85
|
+
audit = (await source.advisories(asked, signal)).map(advisory => ({ ...advisory, malware: advisory.malware === true }))
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (signal.aborted) return null
|
|
88
|
+
audit = failureOf(error)
|
|
89
|
+
}
|
|
90
|
+
const now = Date.now()
|
|
91
|
+
memory.set(key, { at: now, audit })
|
|
92
|
+
await source.audits?.write(key, audit, now)
|
|
93
|
+
return await withRepositories(source, audit, asked, signal)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const byName = (a: AdvisoryRow, b: AdvisoryRow) => Number(a.name > b.name) - Number(a.name < b.name)
|
|
97
|
+
|
|
98
|
+
// `audit`, where it has advisories, with those its packages' repositories
|
|
99
|
+
// publish, as known (or `waits` times on, as had by the time `signal`
|
|
100
|
+
// aborts): without them where they can't be had, as no audit fails for
|
|
101
|
+
// them. Asked again twice at most.
|
|
102
|
+
async function withRepositories(source: AuditSource, audit: Audit, asked: AskedVersions, signal: AbortSignal, waits = 0): Promise<ToldAudit> {
|
|
103
|
+
if (!source.repositories || !Array.isArray(audit)) return { audit, had: true, again: null }
|
|
104
|
+
const found = await source.repositories(asked, signal, waits > 0).catch(() => null)
|
|
105
|
+
const told = found && found.advisories.length > 0 ? [...audit, ...found.advisories.map(advisory => ({ ...advisory, malware: advisory.malware === true }))].toSorted(byName) : audit
|
|
106
|
+
return { audit: told, had: found !== null, again: waits >= 2 || (found && !found.again) ? null : next => withRepositories(source, audit, asked, next, waits + 1) }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// A lockfile's advisories still to be had again, of a repository a scan told
|
|
110
|
+
// whole, as its progress keeps them for its next part (repository-risk.ts
|
|
111
|
+
// ScanProgress): the lockfile's path and key, and a digest of the audit last
|
|
112
|
+
// told of it.
|
|
113
|
+
export type PendingAudit = { path: string; key: string; told: string }
|
|
114
|
+
const digestOf = (audit: Audit) => createHash('sha256').update(JSON.stringify(audit)).digest('base64url')
|
|
115
|
+
// `audit`, told of the lockfile at `path` by its `key`, noted among `pending`.
|
|
116
|
+
export function pend(pending: PendingAudit[], path: string, key: string, audit: Audit): PendingAudit {
|
|
117
|
+
const entry = { path, key, told: digestOf(audit) }
|
|
118
|
+
pending.push(entry)
|
|
119
|
+
return entry
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// A lockfile's audit `told` had again (its `again`), as `entry` of `pending`
|
|
123
|
+
// notes it was last told: told by `tell` where it changed, with its
|
|
124
|
+
// repositories' had, and so noted; that one where it may change once more,
|
|
125
|
+
// else null, `entry` let go of: but not once `signal` aborts, for a next
|
|
126
|
+
// part to have it.
|
|
127
|
+
export async function auditAgain(told: ToldAudit, pending: PendingAudit[], entry: PendingAudit, signal: AbortSignal, tell: (audit: Audit) => void): Promise<ToldAudit | null> {
|
|
128
|
+
const now = signal.aborted || !told.again ? null : await told.again(signal).catch(() => null)
|
|
129
|
+
if (signal.aborted) return null
|
|
130
|
+
if (now?.had && digestOf(now.audit) !== entry.told) {
|
|
131
|
+
entry.told = digestOf(now.audit)
|
|
132
|
+
tell(now.audit)
|
|
133
|
+
}
|
|
134
|
+
if (now?.again) return now
|
|
135
|
+
const at = pending.indexOf(entry)
|
|
136
|
+
if (at !== -1) pending.splice(at, 1)
|
|
137
|
+
return null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// A lockfile's audit an earlier part of the scan was still to have again
|
|
141
|
+
// (`entry`), its `packages` as kept, to have as auditAgain has it: audited
|
|
142
|
+
// as at first (auditLockfile), its npm advisories as kept, its repositories'
|
|
143
|
+
// as known now.
|
|
144
|
+
export const resumedAudit = (source: AuditSource, memory: Lru<{ at: number; audit: Audit }>, entry: PendingAudit, packages: readonly LockedPackage[]): ToldAudit =>
|
|
145
|
+
({ audit: [], had: false, again: signal => auditLockfile(source, memory, signal, entry.key, packages) })
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// What repository risk scans keep between them (repository-risk.ts), in this
|
|
2
|
+
// instance's memory.
|
|
3
|
+
import { type Lru, lru } from './lru.ts'
|
|
4
|
+
import type { KeptStore } from './npm-kept.ts'
|
|
5
|
+
import { type ActionAnswers, type ActionLine, type WorkflowsRead, answerWeight } from './repository-actions.ts'
|
|
6
|
+
import type { Audit } from './repository-risk-audit.ts'
|
|
7
|
+
import type { ListedLockfile, LockfileRead } from './repository-risk-read.ts'
|
|
8
|
+
import type { RiskLine } from './repository-risk.ts'
|
|
9
|
+
|
|
10
|
+
// What scans keep between them, in this instance's memory: a repository's
|
|
11
|
+
// lockfiles as listed at a commit, and a lockfile's packages by its blob,
|
|
12
|
+
// neither of which changes; a lockfile's advisories, asked again after
|
|
13
|
+
// RISK_KEPT_MS, as npm publishes advisories; and a package's risk line,
|
|
14
|
+
// told stale after RISK_KEPT_MS and assessed again, as risk tells again what
|
|
15
|
+
// of a package changes in time (a deprecation, its age, its downloads). A
|
|
16
|
+
// lockfile's, and its packages' lines, are told only once access to its
|
|
17
|
+
// repository is checked as when it was read.
|
|
18
|
+
export interface RiskCaches {
|
|
19
|
+
listings: Lru<ListedLockfile[]>
|
|
20
|
+
lockfiles: Lru<LockfileRead>
|
|
21
|
+
risks: Lru<{ at: number; line: RiskLine }>
|
|
22
|
+
advisories: Lru<{ at: number; audit: Audit }>
|
|
23
|
+
actionFiles: Lru<WorkflowsRead>
|
|
24
|
+
actions: Lru<{ at: number; line: ActionLine }>
|
|
25
|
+
actionAnswers: ActionAnswers
|
|
26
|
+
}
|
|
27
|
+
export const riskCaches = (): RiskCaches => ({
|
|
28
|
+
listings: lru(1000),
|
|
29
|
+
// By the packages they hold, a few hundred bytes each.
|
|
30
|
+
lockfiles: lru(200_000, read => 'packages' in read ? read.packages.length + 1 : 1),
|
|
31
|
+
risks: lru(50_000),
|
|
32
|
+
advisories: lru(50_000, kept => Array.isArray(kept.audit) ? kept.audit.length + 1 : 1),
|
|
33
|
+
// By their text, a kilobyte at a time.
|
|
34
|
+
actionFiles: lru(64 * 1024, read => 'files' in read ? read.files.reduce((sum, file) => sum + ('text' in file ? Math.ceil(file.text.length / 1024) : 1), 1) : 1),
|
|
35
|
+
actions: lru(10_000),
|
|
36
|
+
// What GitHub answered of public repositories' actions, by answerWeight.
|
|
37
|
+
actionAnswers: lru(200_000, answerWeight),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// How many kept risk lines are read of a source's `risks` at once.
|
|
41
|
+
const KEPT_READ = 500
|
|
42
|
+
|
|
43
|
+
// Risk lines kept of `keys`, by key: in this instance's memory (`caches`),
|
|
44
|
+
// else a source's `risks`, KEPT_READ at a time, held in memory then.
|
|
45
|
+
export async function keptRiskLines(caches: RiskCaches, risks: KeptStore<RiskLine> | undefined, keys: string[]) {
|
|
46
|
+
const kept = new Map<string, { at: number; line: RiskLine }>()
|
|
47
|
+
const left = keys.filter(key => { const hit = caches.risks.get(key); if (hit) kept.set(key, hit); return !hit })
|
|
48
|
+
if (!risks) return kept
|
|
49
|
+
for (let from = 0; from < left.length; from += KEPT_READ) {
|
|
50
|
+
for (const [key, { at, value }] of await risks.readMany(left.slice(from, from + KEPT_READ))) {
|
|
51
|
+
caches.risks.set(key, { at, line: value })
|
|
52
|
+
kept.set(key, { at, line: value })
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return kept
|
|
56
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// What a repository risk scan (repository-risk.ts) told of each repository,
|
|
2
|
+
// but its Dependabot alerts, kept gzipped for its reader (riskKeptStore), for
|
|
3
|
+
// a scan to tell first as it opens; one failing, or archived, kept no more.
|
|
4
|
+
import { gunzipBytes, gzipText } from '../common/gzip.js'
|
|
5
|
+
import { decodeUtf8 } from '../common/utf8.js'
|
|
6
|
+
import type { LockedPackage } from './locked-packages.ts'
|
|
7
|
+
import type { KeptStore } from './npm-kept.ts'
|
|
8
|
+
import type { ActionRef } from './repository-actions.ts'
|
|
9
|
+
import { inTurns } from './queue.ts'
|
|
10
|
+
import { stasisVersions } from './repository-risk-read.ts'
|
|
11
|
+
import type { RepositoryRiskLine, RepositoryRiskRepo } from './repository-risk.ts'
|
|
12
|
+
|
|
13
|
+
// What a scan told of a repository: its name then, its lines, and its Actions' references.
|
|
14
|
+
export interface KeptRepository { name: string; lines: RepositoryRiskLine[]; refs: ActionRef[] }
|
|
15
|
+
// A line of what was kept of a repository, told first, as of when it was read.
|
|
16
|
+
export type KeptLine = RepositoryRiskLine & { kept: number }
|
|
17
|
+
|
|
18
|
+
// Where it is kept, for one reader: read of many repositories at once, kept
|
|
19
|
+
// as each is told whole, and no longer.
|
|
20
|
+
export interface KeptRepositories {
|
|
21
|
+
read(repos: RepositoryRiskRepo[]): Promise<Map<number, { at: number; value: KeptRepository }>>
|
|
22
|
+
write(repo: RepositoryRiskRepo, value: KeptRepository, at: number): Promise<void>
|
|
23
|
+
remove(repo: RepositoryRiskRepo): Promise<void>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// None kept whose gzipped text, in base64, is longer, as a scan of a
|
|
27
|
+
// monorepo of many lockfiles may be; none unpacked past KEPT_TEXT_BYTES.
|
|
28
|
+
const KEPT_BYTES = 8 * 1024 * 1024
|
|
29
|
+
const KEPT_TEXT_BYTES = 128 * 1024 * 1024
|
|
30
|
+
const VERSION = 1
|
|
31
|
+
|
|
32
|
+
// What is kept in `store` for reader `user` (their id and role).
|
|
33
|
+
export function keptRepositories(store: KeptStore<string>, user: { id: string; role: string }): KeptRepositories {
|
|
34
|
+
const keyOf = (repo: RepositoryRiskRepo) => JSON.stringify([VERSION, user.id, user.role, repo.repoId, repo.paths ?? null])
|
|
35
|
+
const valueOf = async (packed: unknown): Promise<KeptRepository | null> => {
|
|
36
|
+
if (typeof packed !== 'string') return null
|
|
37
|
+
try {
|
|
38
|
+
const value = JSON.parse(decodeUtf8(await gunzipBytes(Buffer.from(packed, 'base64'), { maxBytes: KEPT_TEXT_BYTES }))) as Partial<KeptRepository> | null
|
|
39
|
+
return typeof value?.name === 'string' && Array.isArray(value.lines) && Array.isArray(value.refs) ? value as KeptRepository : null
|
|
40
|
+
} catch { return null }
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
async read(repos) {
|
|
44
|
+
const keys = repos.map(keyOf)
|
|
45
|
+
const hits = await store.readMany(keys)
|
|
46
|
+
const kept = new Map<number, { at: number; value: KeptRepository }>()
|
|
47
|
+
await Promise.all(repos.map(async (repo, at) => {
|
|
48
|
+
const hit = hits.get(keys[at]!)
|
|
49
|
+
const value = hit && await valueOf(hit.value)
|
|
50
|
+
if (value) kept.set(repo.repoId, { at: hit.at, value })
|
|
51
|
+
}))
|
|
52
|
+
return kept
|
|
53
|
+
},
|
|
54
|
+
async write(repo, value, at) {
|
|
55
|
+
const packed = Buffer.from(await gzipText(JSON.stringify(value))).toString('base64')
|
|
56
|
+
await (packed.length > KEPT_BYTES ? store.remove(keyOf(repo)) : store.write(keyOf(repo), packed, at))
|
|
57
|
+
},
|
|
58
|
+
remove: repo => store.remove(keyOf(repo)),
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Whether its reader may read a repository now, as opening it asks GitHub;
|
|
63
|
+
// each line to tell; and what the scan is given again (repository-risk.ts reseed).
|
|
64
|
+
interface Telling { signal: AbortSignal; readable(repo: RepositoryRiskRepo): Promise<boolean>; tell(line: KeptLine): void
|
|
65
|
+
reseed(told: { stasis: string[]; packages: LockedPackage[][]; refs: ActionRef[] }): void }
|
|
66
|
+
|
|
67
|
+
// What is kept of `repos` told, each line marked when it was read (`kept`),
|
|
68
|
+
// of each with the name it had then that its reader may still read.
|
|
69
|
+
const READ_AT_ONCE = 20
|
|
70
|
+
const READABLE_AT_ONCE = 6
|
|
71
|
+
export async function tellKept(kept: KeptRepositories, repos: RepositoryRiskRepo[], to: Telling) {
|
|
72
|
+
const asking = inTurns(READABLE_AT_ONCE)
|
|
73
|
+
for (let from = 0; from < repos.length && !to.signal.aborted; from += READ_AT_ONCE) {
|
|
74
|
+
const some = repos.slice(from, from + READ_AT_ONCE)
|
|
75
|
+
const read = await kept.read(some)
|
|
76
|
+
const told = some.map(repo => read.get(repo.repoId)?.value.name === repo.fullName && asking(() => to.readable(repo).catch(() => false)))
|
|
77
|
+
for (const [at, repo] of some.entries()) {
|
|
78
|
+
const hit = read.get(repo.repoId)
|
|
79
|
+
if (!hit || !await told[at] || to.signal.aborted) continue
|
|
80
|
+
const { lines, refs } = hit.value
|
|
81
|
+
for (const line of lines) to.tell({ ...line, kept: hit.at })
|
|
82
|
+
to.reseed({ stasis: stasisVersions(lines.find(line => line.type === 'stasis') ?? null), refs,
|
|
83
|
+
packages: lines.flatMap(line => line.type === 'lockfile' && 'packages' in line ? [line.packages] : []) })
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// A repository as a repository risk scan reads it of GitHub
|
|
2
|
+
// (repository-risk.ts): opened at its default branch's head, its lockfiles
|
|
3
|
+
// of npm's ecosystem listed (findRepoLockfiles), those of its `paths` alone,
|
|
4
|
+
// each read for its packages (@preventive/lockfile), and access to it checked
|
|
5
|
+
// again before they are told (`recheck`); and its Dependabot alerts, open or dismissed, of
|
|
6
|
+
// npm's, where the source asks them (dependabot-alerts.ts), asked meanwhile
|
|
7
|
+
// and never kept, a failure to have them its own, its GitHub Actions
|
|
8
|
+
// (repository-actions.ts), and what Stasis reaches of each of its
|
|
9
|
+
// stasis.config.json files, where the source reads them
|
|
10
|
+
// (StasisConfigsRead). A listing is kept by the commit it was listed at,
|
|
11
|
+
// its Actions' files too, and a lockfile's packages by its blob: in the
|
|
12
|
+
// instance's memory, and the source's `listings`, `actionFiles` and
|
|
13
|
+
// `lockfiles` for SCAN_READ_KEPT_MS, so that only opening a repository and
|
|
14
|
+
// checking access to it again ask GitHub where all else is kept.
|
|
15
|
+
import { createHash } from 'node:crypto'
|
|
16
|
+
import type { LockfileFormat, RepoLockfile } from '@preventive/upstream/github.js'
|
|
17
|
+
import type { AlertsRead } from './dependabot-access.ts'
|
|
18
|
+
import { type DependabotAlert, alertVersions } from './dependabot-alerts.ts'
|
|
19
|
+
import { npmMalwareAdvisory } from '../risk/index.js'
|
|
20
|
+
import { type LockedPackage, isTestFixture, lockedPackages, yarnManifests } from './locked-packages.ts'
|
|
21
|
+
import type { Lru } from './lru.ts'
|
|
22
|
+
import type { KeptStore } from './npm-kept.ts'
|
|
23
|
+
import { inTurns } from './queue.ts'
|
|
24
|
+
import { type WorkflowsRead, lastingRead, readActions } from './repository-actions.ts'
|
|
25
|
+
import { type RiskFailure, failureOf } from './repository-risk-assess.ts'
|
|
26
|
+
import type { LockfileLine, RepositoryRiskLine, RepositoryRiskRepo } from './repository-risk.ts'
|
|
27
|
+
import type { StasisDependency } from './bundle-build.ts'
|
|
28
|
+
import { isStasisConfig } from './lockfile-scope.ts'
|
|
29
|
+
import type { StasisBuilt, StasisRead } from './stasis-dependencies.ts'
|
|
30
|
+
|
|
31
|
+
// The formats of npm's ecosystem, as findRepoLockfiles names them, and those
|
|
32
|
+
// of them read here.
|
|
33
|
+
const NPM_LOCKFILE_FORMATS: ReadonlySet<LockfileFormat> = new Set(['npm', 'pnpm', 'yarn', 'bun', 'deno'])
|
|
34
|
+
const READ_FORMATS: ReadonlySet<LockfileFormat> = new Set(['npm', 'pnpm', 'yarn'])
|
|
35
|
+
|
|
36
|
+
// How long the source's `listings` and `lockfiles` are read for: what
|
|
37
|
+
// GitHub has at a commit or a blob doesn't change, how it is read here may.
|
|
38
|
+
export const SCAN_READ_KEPT_MS = 24 * 60 * 60_000
|
|
39
|
+
// How many of a repository's lockfiles are read at once: each one GitHub is
|
|
40
|
+
// asked for where it isn't kept, then parsed.
|
|
41
|
+
const LOCKFILES_AT_ONCE = 4
|
|
42
|
+
|
|
43
|
+
export type ListedLockfile = Pick<RepoLockfile, 'path' | 'format' | 'sha'>
|
|
44
|
+
export type LockfileRead = { packages: LockedPackage[] } | RiskFailure
|
|
45
|
+
// A repository's Dependabot alerts, those of its `paths` alone, with access to
|
|
46
|
+
// them to check again before they are told (`recheck`), or why they couldn't
|
|
47
|
+
// be had.
|
|
48
|
+
export type DependabotRead = { alerts: DependabotAlert[]; recheck?(): Promise<void> } | RiskFailure
|
|
49
|
+
export type RepositoryFailure = Extract<RepositoryRiskLine, { type: 'repo'; error: string }>
|
|
50
|
+
// A repository GitHub has archived, which a scan reads no further: its
|
|
51
|
+
// history alone, nothing that installs anew.
|
|
52
|
+
export type RepositoryArchived = Extract<RepositoryRiskLine, { type: 'repo'; archived: true }>
|
|
53
|
+
// What Stasis reaches of a stasis.config.json, as a dependency review's
|
|
54
|
+
// build of it tells (stasis-dependencies.ts): the versions it installs
|
|
55
|
+
// (`dependencies`), that its build is still to be made (`pending`), or why it
|
|
56
|
+
// failed.
|
|
57
|
+
// `lockfiles`, those its `lockfiles` names, from the repository's root,
|
|
58
|
+
// where it names some: those its builds install from (namedLockfiles). One
|
|
59
|
+
// still to be made with what the last built of it on its branch installs
|
|
60
|
+
// meanwhile (`dependencies`, of `lastBuilt`, its commit), where one was.
|
|
61
|
+
export type StasisConfigRow = { path: string; lockfiles?: string[] } & ({ dependencies: StasisDependency[] } | { pending: true }
|
|
62
|
+
| { pending: true; dependencies: StasisDependency[]; lastBuilt: string } | RiskFailure)
|
|
63
|
+
// A repository's stasis.config.json files, those of its `paths` alone, each
|
|
64
|
+
// what Stasis reaches of it, or why they couldn't be listed.
|
|
65
|
+
export type StasisConfigsRead = { configs: StasisConfigRow[] } | RiskFailure
|
|
66
|
+
|
|
67
|
+
// A version, as Stasis tells those it installs, whatever its integrity.
|
|
68
|
+
export const versionKey = ({ name, version }: { name: string; version: string }) => `${name}@${version}`
|
|
69
|
+
// The versions a repository's Stasis builds made install (versionKey): of
|
|
70
|
+
// those still to be made, which aren't waited for, what the last built on
|
|
71
|
+
// its branch installs, where one was.
|
|
72
|
+
export const stasisVersions = (read: StasisConfigsRead | null): string[] => [...new Set(read && 'configs' in read
|
|
73
|
+
? read.configs.flatMap(config => 'dependencies' in config ? config.dependencies.map(versionKey) : []) : [])]
|
|
74
|
+
// The paths of a repository's stasis.config.json files whose builds are still
|
|
75
|
+
// to be made.
|
|
76
|
+
export const stasisBuilding = (read: StasisConfigsRead | null): string[] => read && 'configs' in read ? read.configs.flatMap(config => 'pending' in config ? [config.path] : []) : []
|
|
77
|
+
|
|
78
|
+
// A config's read, a build still to be made with the last built at its branch's head (`last`), where one was.
|
|
79
|
+
export type RiskStasisRead = StasisRead | { status: 'pending'; last: StasisBuilt }
|
|
80
|
+
|
|
81
|
+
// A config's row of its read: a failed build told by its code (`detail`).
|
|
82
|
+
export function stasisConfigRow(path: string, read: RiskStasisRead): StasisConfigRow {
|
|
83
|
+
if (read.status === 'ready') return { path, dependencies: read.dependencies }
|
|
84
|
+
if (read.status === 'pending') return 'last' in read ? { path, pending: true, dependencies: read.last.dependencies, lastBuilt: read.last.commit } : { path, pending: true }
|
|
85
|
+
return { path, error: 'stasis-failed', detail: read.error }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// A repository opened at its default branch's head (`commit`): its lockfiles,
|
|
89
|
+
// as findRepoLockfiles lists them, each with its blob's id, and a file's
|
|
90
|
+
// text; `recheck` checks access to it again, throwing where it is gone; and
|
|
91
|
+
// `dependabot`, where asked, its Dependabot alerts of npm's, open or dismissed, as GitHub
|
|
92
|
+
// has them now, with access to them to check again before they are told.
|
|
93
|
+
export interface OpenedRepository {
|
|
94
|
+
commit: string
|
|
95
|
+
lockfiles(): Promise<ListedLockfile[]>
|
|
96
|
+
file(path: string): Promise<string>
|
|
97
|
+
recheck(): Promise<void>
|
|
98
|
+
dependabot?(): Promise<AlertsRead>
|
|
99
|
+
// Its workflows' paths, none where it has none.
|
|
100
|
+
workflows?(): Promise<string[]>
|
|
101
|
+
// Its files' paths at `commit`, of which its stasis.config.json files are
|
|
102
|
+
// told (isStasisConfig); and what Stasis reaches of the one at `config`,
|
|
103
|
+
// as a dependency review's reader has it (stasis-dependencies.ts), its
|
|
104
|
+
// build asked for where none is kept yet, never waited for.
|
|
105
|
+
files?(): Promise<string[]>
|
|
106
|
+
stasis?(config: string): Promise<RiskStasisRead>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// What a repository is read with: the scan's source and caches, and its
|
|
110
|
+
// signal.
|
|
111
|
+
interface RepositoryReading<R extends RepositoryRiskRepo> {
|
|
112
|
+
source: { open(repo: R): Promise<OpenedRepository | { archived: true }>; listings?: KeptStore<ListedLockfile[]>; lockfiles?: KeptStore<LockfileRead>;
|
|
113
|
+
actionFiles?: KeptStore<WorkflowsRead> }
|
|
114
|
+
caches: { listings: Lru<ListedLockfile[]>; lockfiles: Lru<LockfileRead>; actionFiles: Lru<WorkflowsRead> }
|
|
115
|
+
signal: AbortSignal
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// A repository read: its commit, its lockfiles' lines, each with its blob's
|
|
119
|
+
// id, its Dependabot alerts where asked, and access to it to check again just
|
|
120
|
+
// before they are told (OpenedRepository `recheck`), as GitHub may have
|
|
121
|
+
// withdrawn it meanwhile.
|
|
122
|
+
export interface RepositoryRead {
|
|
123
|
+
commit: string
|
|
124
|
+
lockfiles: { sha: string; line: LockfileLine }[]
|
|
125
|
+
dependabot: DependabotRead | null
|
|
126
|
+
// Its Actions' files, where it lists its workflows.
|
|
127
|
+
actions: WorkflowsRead | null
|
|
128
|
+
// Its stasis.config.json files, where it has some and the source reads them.
|
|
129
|
+
stasis: StasisConfigsRead | null
|
|
130
|
+
recheck(): Promise<void>
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Whether a lockfile at `path` is of `paths` (RepositoryRiskRepo), as a
|
|
134
|
+
// stasis.config.json is.
|
|
135
|
+
export function lockfileOf(path: string, paths: readonly string[] | undefined) {
|
|
136
|
+
const dir = path.slice(0, Math.max(path.lastIndexOf('/'), 0))
|
|
137
|
+
return !paths || paths.some(scope => dir === '' || dir === scope || dir.startsWith(`${scope}/`) || scope.startsWith(`${dir}/`))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// What is kept by `key`: in this instance's memory, else in `store` within
|
|
141
|
+
// SCAN_READ_KEPT_MS, else `read` and kept in both, where it is to be.
|
|
142
|
+
async function keptRead<T>(memory: Lru<T>, store: KeptStore<T> | undefined, key: string, read: () => Promise<T>, keep = (_value: T) => true) {
|
|
143
|
+
const known = memory.get(key)
|
|
144
|
+
if (known !== undefined) return known
|
|
145
|
+
const kept = await store?.read(key)
|
|
146
|
+
if (kept && Date.now() - kept.at < SCAN_READ_KEPT_MS) { memory.set(key, kept.value); return kept.value }
|
|
147
|
+
const value = await read()
|
|
148
|
+
if (!keep(value)) return value
|
|
149
|
+
memory.set(key, value)
|
|
150
|
+
await store?.write(key, value, Date.now())
|
|
151
|
+
return value
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// A lockfile's line, its packages or why they couldn't be had: as kept by its
|
|
155
|
+
// blob, else read from GitHub and kept; with the `sha` it is kept by, a
|
|
156
|
+
// yarn.lock's with its package.json files' (yarnManifests), which alone say
|
|
157
|
+
// what only devDependencies need, and change while it may not.
|
|
158
|
+
async function readLockfile({ source, caches }: RepositoryReading<RepositoryRiskRepo>, repo: number, opened: OpenedRepository,
|
|
159
|
+
{ path, format, sha }: ListedLockfile): Promise<{ sha: string; line: LockfileLine }> {
|
|
160
|
+
const at = { type: 'lockfile', repo, path, format } as const
|
|
161
|
+
if (!READ_FORMATS.has(format)) return { sha, line: { ...at, error: 'unsupported-format' } }
|
|
162
|
+
try {
|
|
163
|
+
const manifests = format === 'yarn' ? await yarnManifests(path, file => opened.file(file), opened.files) : null
|
|
164
|
+
const kept = manifests ? `${sha}+${createHash('sha256').update(JSON.stringify(manifests)).digest('hex').slice(0, 16)}` : sha
|
|
165
|
+
return { sha: kept, line: { ...at, ...await keptRead(caches.lockfiles, source.lockfiles, `${format}\0${kept}`, async (): Promise<LockfileRead> => {
|
|
166
|
+
const text = await opened.file(path)
|
|
167
|
+
try { return { packages: lockedPackages(format, text, { manifests }) } } catch (error) {
|
|
168
|
+
return { error: 'lockfile-unreadable', ...error instanceof Error ? { detail: error.message.slice(0, 500) } : {} }
|
|
169
|
+
}
|
|
170
|
+
}) } }
|
|
171
|
+
} catch (error) { return { sha, line: { ...at, ...failureOf(error) } } }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// A repository opened and its lockfiles of npm's ecosystem listed, as kept
|
|
175
|
+
// for its commit or else from GitHub, those of its `paths` alone; its line
|
|
176
|
+
// telling why where either failed, or that GitHub has it archived, read no
|
|
177
|
+
// further; null where the scan stopped.
|
|
178
|
+
async function listLockfiles<R extends RepositoryRiskRepo>(reading: RepositoryReading<R>, repo: R):
|
|
179
|
+
Promise<{ opened: OpenedRepository; lockfiles: ListedLockfile[] } | RepositoryFailure | RepositoryArchived | null> {
|
|
180
|
+
let doing = 'opening it'
|
|
181
|
+
try {
|
|
182
|
+
const opened = await reading.source.open(repo)
|
|
183
|
+
if (reading.signal.aborted) return null
|
|
184
|
+
if ('archived' in opened) return { type: 'repo', id: repo.repoId, archived: true } as const
|
|
185
|
+
doing = 'listing its lockfiles'
|
|
186
|
+
const listed = await keptRead(reading.caches.listings, reading.source.listings, `${repo.repoId}@${opened.commit}`, () => opened.lockfiles())
|
|
187
|
+
const lockfiles = listed.filter(({ path, format }) => NPM_LOCKFILE_FORMATS.has(format) && lockfileOf(path, repo.paths))
|
|
188
|
+
return { opened, lockfiles }
|
|
189
|
+
} catch (error) {
|
|
190
|
+
return reading.signal.aborted ? null : { type: 'repo', id: repo.repoId, ...failureOf(error, doing) } as const
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// A repository's Dependabot alerts of its `paths` (RepositoryRiskRepo), as
|
|
195
|
+
// its lockfiles are, or why they couldn't be had; null where they aren't
|
|
196
|
+
// asked.
|
|
197
|
+
async function readDependabot(opened: OpenedRepository, paths: readonly string[] | undefined): Promise<DependabotRead | null> {
|
|
198
|
+
if (!opened.dependabot) return null
|
|
199
|
+
try {
|
|
200
|
+
const { alerts, recheck } = await opened.dependabot()
|
|
201
|
+
return { alerts: alerts.filter(alert => lockfileOf(alert.manifest, paths)), recheck }
|
|
202
|
+
} catch (error) {
|
|
203
|
+
return failureOf(error, 'asking its Dependabot alerts')
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// A repository's stasis.config.json files of its `paths` (RepositoryRiskRepo),
|
|
208
|
+
// as its lockfiles are, each what Stasis reaches of it; or why they couldn't
|
|
209
|
+
// be listed; null where it has none, or the source reads none.
|
|
210
|
+
async function readStasis(opened: OpenedRepository, paths: readonly string[] | undefined): Promise<StasisConfigsRead | null> {
|
|
211
|
+
const { files, stasis } = opened
|
|
212
|
+
if (!files || !stasis) return null
|
|
213
|
+
let configs
|
|
214
|
+
try { configs = (await files()).filter(path => isStasisConfig(path) && lockfileOf(path, paths)) } catch (error) {
|
|
215
|
+
return failureOf(error, 'listing its stasis.config.json files')
|
|
216
|
+
}
|
|
217
|
+
if (configs.length === 0) return null
|
|
218
|
+
return { configs: await Promise.all(configs.map(async path => {
|
|
219
|
+
const lockfiles = await opened.file(path).then(namedLockfiles(path), () => null)
|
|
220
|
+
try { return { ...stasisConfigRow(path, await stasis(path)), ...lockfiles && { lockfiles } } } catch (error) { return { path, ...failureOf(error) } }
|
|
221
|
+
})) }
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// The lockfiles a stasis.config.json at `path` names (`lockfiles`), from its
|
|
225
|
+
// directory, as Stasis installs from those alone, each from the repository's
|
|
226
|
+
// root; null where it names none, or isn't JSON, or one is out of the
|
|
227
|
+
// repository.
|
|
228
|
+
export const namedLockfiles = (path: string) => (text: string): string[] | null => {
|
|
229
|
+
let named: unknown
|
|
230
|
+
try { named = (JSON.parse(text) as { lockfiles?: unknown } | null)?.lockfiles } catch { return null }
|
|
231
|
+
if (!Array.isArray(named) || named.length === 0 || !named.every(each => typeof each === 'string' && each !== '')) return null
|
|
232
|
+
const resolved = (named as string[]).map(each => {
|
|
233
|
+
const parts = path.split('/').slice(0, -1)
|
|
234
|
+
for (const part of each.split('/')) {
|
|
235
|
+
if (part === '..') { if (parts.pop() === undefined) return null } else if (part !== '' && part !== '.') parts.push(part)
|
|
236
|
+
}
|
|
237
|
+
return parts.join('/')
|
|
238
|
+
})
|
|
239
|
+
return resolved.every(Boolean) ? resolved as string[] : null
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// A repository read: its lockfiles listed and read, a few at once, its
|
|
243
|
+
// Dependabot alerts asked, its Actions read and its stasis.config.json files
|
|
244
|
+
// asked meanwhile; its line telling why where listing
|
|
245
|
+
// failed, or that it is archived; null where the scan stopped. A test's
|
|
246
|
+
// fixture or example its reader refuses (isTestFixture) is left out, as a
|
|
247
|
+
// test may keep one so on purpose.
|
|
248
|
+
export async function readRepository<R extends RepositoryRiskRepo>(reading: RepositoryReading<R>, repo: R): Promise<RepositoryRead | RepositoryFailure | RepositoryArchived | null> {
|
|
249
|
+
const listed = await listLockfiles(reading, repo)
|
|
250
|
+
if (!listed || 'type' in listed) return listed
|
|
251
|
+
const { opened } = listed
|
|
252
|
+
const alerting = readDependabot(opened, repo.paths)
|
|
253
|
+
const reaching = readStasis(opened, repo.paths)
|
|
254
|
+
const { workflows } = opened
|
|
255
|
+
const acting = workflows ? keptRead(reading.caches.actionFiles, reading.source.actionFiles, `${repo.repoId}@${opened.commit}`,
|
|
256
|
+
() => readActions({ workflows, file: path => opened.file(path) }), lastingRead) : Promise.resolve(null)
|
|
257
|
+
acting.catch(() => {})
|
|
258
|
+
const inTurn = inTurns(LOCKFILES_AT_ONCE)
|
|
259
|
+
const lines = await Promise.all(listed.lockfiles.map(lockfile => inTurn(() => (reading.signal.aborted ? Promise.resolve(null) : readLockfile(reading, repo.repoId, opened, lockfile)))))
|
|
260
|
+
const lockfiles: RepositoryRead['lockfiles'] = []
|
|
261
|
+
for (const read of lines) {
|
|
262
|
+
if (!read) return null
|
|
263
|
+
if (!('error' in read.line && read.line.error === 'lockfile-unreadable' && isTestFixture(read.line.path))) lockfiles.push(read)
|
|
264
|
+
}
|
|
265
|
+
const dependabot = await alerting
|
|
266
|
+
const actions = await acting
|
|
267
|
+
const stasis = await reaching
|
|
268
|
+
return reading.signal.aborted ? null : { commit: opened.commit, lockfiles, dependabot, actions, stasis, recheck: () => opened.recheck() }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// A Dependabot alert as a scan tells it: with the versions of its package
|
|
272
|
+
// the lockfile it is of locks that it covers, none where it is of none read
|
|
273
|
+
// (a package.json, bun's lockfile), and whether it is of malware, by the rule
|
|
274
|
+
// upstream tells an advisory's by (risk's npmMalwareAdvisory).
|
|
275
|
+
export type DependabotAlertRow = DependabotAlert & { versions: string[]; malware: boolean }
|
|
276
|
+
|
|
277
|
+
type DependabotLine = Extract<RepositoryRiskLine, { type: 'dependabot' }>
|
|
278
|
+
|
|
279
|
+
// A repository's Dependabot alerts' line, each alert with the versions the
|
|
280
|
+
// lockfile it is of locks that it covers (`lockfiles`, a repository read's),
|
|
281
|
+
// or why they couldn't be had.
|
|
282
|
+
export function dependabotLine(repo: number, read: DependabotRead, lockfiles: RepositoryRead['lockfiles']): DependabotLine {
|
|
283
|
+
if ('error' in read) return { type: 'dependabot', repo, ...read }
|
|
284
|
+
const locked = new Map(lockfiles.flatMap(({ line }) => 'packages' in line ? [[line.path, line.packages] as const] : []))
|
|
285
|
+
return { type: 'dependabot', repo, alerts: read.alerts.map(alert => ({ ...alert, versions: alertVersions(alert, locked.get(alert.manifest)),
|
|
286
|
+
malware: npmMalwareAdvisory({ id: alert.ghsa, aliases: alert.aliases, cwe: alert.cwe, title: alert.title }) })) }
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// A repository's alerts checked again just before they are told, as access to
|
|
290
|
+
// the repository is (DependabotRead `recheck`): why not, where the user's
|
|
291
|
+
// access to them is withdrawn since they were read.
|
|
292
|
+
export async function rechecked(read: DependabotRead): Promise<DependabotRead> {
|
|
293
|
+
if (!('alerts' in read) || !read.recheck) return read
|
|
294
|
+
try { await read.recheck() } catch (error) { return failureOf(error, 'checking access to its Dependabot alerts again') }
|
|
295
|
+
return read
|
|
296
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// What a repository risk scan knows of Stasis's builds (repository-risk.ts):
|
|
2
|
+
// the versions those made install (versionKey), Stasis's wherever they are
|
|
3
|
+
// locked, as the page tells them apart (repository-risk.js stasisReach),
|
|
4
|
+
// assessed before the rest; the packages seen of each version, to move up
|
|
5
|
+
// once it is told Stasis's; and the builds still to be made as their
|
|
6
|
+
// repositories were read, watched: asked again every STASIS_AGAIN_MS what
|
|
7
|
+
// Stasis has made of them, as their page asks, none ever waited for.
|
|
8
|
+
import { setTimeout as delay } from 'node:timers/promises'
|
|
9
|
+
import type { AssessedPackage } from './repository-risk-assess.ts'
|
|
10
|
+
import { versionKey } from './repository-risk-read.ts'
|
|
11
|
+
import type { StasisRead } from './stasis-dependencies.ts'
|
|
12
|
+
|
|
13
|
+
// As often as a page asks again of the builds it shows still to be made
|
|
14
|
+
// (repository-risk.js STASIS_POLL_MS).
|
|
15
|
+
export const STASIS_AGAIN_MS = 30_000
|
|
16
|
+
|
|
17
|
+
// A build still to be made: of the stasis.config.json at `config` of
|
|
18
|
+
// repository `repoId` at `commit`.
|
|
19
|
+
export interface StasisBuild { repoId: number; commit: string; config: string }
|
|
20
|
+
|
|
21
|
+
export interface StasisReach {
|
|
22
|
+
// Whether a Stasis build made installs its version.
|
|
23
|
+
has(pkg: AssessedPackage): boolean
|
|
24
|
+
// A package the scan sees, the first time.
|
|
25
|
+
seen(pkg: AssessedPackage): void
|
|
26
|
+
// `versions` told Stasis's: the packages seen of those new to it.
|
|
27
|
+
add(versions: readonly string[]): AssessedPackage[]
|
|
28
|
+
// Builds still to be made, to watch.
|
|
29
|
+
building(builds: StasisBuild[]): void
|
|
30
|
+
// Those watched asked of `built` every `everyMs`, till `signal` aborts:
|
|
31
|
+
// each made since given to `made` with the versions it installs, once; one
|
|
32
|
+
// failed let go, one still to be made asked again.
|
|
33
|
+
watch(built: (build: StasisBuild) => Promise<StasisRead>, made: (build: StasisBuild, versions: string[]) => void, signal: AbortSignal, everyMs: number): Promise<void>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function stasisReach(): StasisReach {
|
|
37
|
+
const builds = new Map<string, StasisBuild>(), reached = new Set<string>(), seen = new Map<string, AssessedPackage[]>()
|
|
38
|
+
return {
|
|
39
|
+
has: pkg => reached.has(versionKey(pkg)),
|
|
40
|
+
seen(pkg) { seen.set(versionKey(pkg), [...seen.get(versionKey(pkg)) ?? [], pkg]) },
|
|
41
|
+
add(versions) {
|
|
42
|
+
const fresh = [...new Set(versions)].filter(version => !reached.has(version))
|
|
43
|
+
for (const version of fresh) reached.add(version)
|
|
44
|
+
return fresh.flatMap(version => seen.get(version) ?? [])
|
|
45
|
+
},
|
|
46
|
+
building(told) { for (const build of told) builds.set(`${build.repoId}\0${build.commit}\0${build.config}`, build) },
|
|
47
|
+
async watch(built, made, signal, everyMs) {
|
|
48
|
+
for (;;) {
|
|
49
|
+
try { await delay(everyMs, undefined, { signal }) } catch { return }
|
|
50
|
+
for (const [key, build] of builds) {
|
|
51
|
+
let read: StasisRead
|
|
52
|
+
try { read = await built(build) } catch { continue }
|
|
53
|
+
if (signal.aborted) return
|
|
54
|
+
if (read.status === 'pending') continue
|
|
55
|
+
builds.delete(key)
|
|
56
|
+
if (read.status === 'ready') made(build, [...new Set(read.dependencies.map(versionKey))])
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
}
|