@preventive/triage 1.0.0-alpha.66 → 1.0.0-alpha.68
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/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.js +1 -1
- package/common/bundle-reasons.d.ts +4 -0
- package/common/bundle-reasons.js +38 -1
- package/common/bundle-sources.d.ts +1 -0
- package/common/bundle-sources.js +22 -0
- package/common/managed/npm-packages.js +3 -3
- package/common/managed/routes.js +37 -18
- package/common/managed/stasis-config.ts +7 -0
- package/out/activity.js +4 -4
- package/out/{chunk-J2FWBXFV.js → chunk-2F3CYNPZ.js} +1 -1
- package/out/chunk-2HGKTQ5Q.js +52 -0
- package/out/chunk-4RS3NDOG.js +1 -0
- package/out/chunk-CGRIZ5M5.js +1 -0
- package/out/{chunk-Z6VEV2QL.js → chunk-D37M7J4B.js} +1 -1
- package/out/chunk-GZ46SSTF.js +1 -0
- package/out/{chunk-IZ6MYRYB.js → chunk-HETCVNO4.js} +1 -1
- package/out/chunk-MPXVKVPF.js +3 -0
- package/out/{chunk-24AKGEH3.js → chunk-NB4JBTKK.js} +1 -1
- package/out/{chunk-OVGR4D3M.js → chunk-OAWY4T6R.js} +1 -1
- package/out/chunk-QPGM3DTI.js +42 -0
- package/out/chunk-SCN2TBP2.js +247 -0
- package/out/chunk-VG5RH6KN.js +2 -0
- package/out/chunk-WFDXHPT2.js +12 -0
- package/out/client-managed-import.js +2 -2
- package/out/client-managed.js +19 -19
- package/out/compare.js +12 -12
- package/out/dialogs.js +38 -38
- package/out/graph.js +8 -8
- package/out/index.html +9 -9
- package/out/scan.js +2 -2
- package/out/view.css +1 -1
- package/out/view.js +15 -15
- package/package.json +11 -8
- package/server-managed/activity.ts +21 -12
- package/server-managed/bundle-build-diagnostics.d.ts +1 -1
- package/server-managed/bundle-build-worker.js +140 -19
- package/server-managed/bundle-build.ts +102 -21
- package/server-managed/bundle-cache.ts +28 -6
- package/server-managed/bundle-dependency-reviews.ts +38 -22
- package/server-managed/commit-lockfiles.ts +2 -1
- package/server-managed/db-neon.ts +5 -2
- package/server-managed/dependency-review-comments.ts +38 -16
- package/server-managed/dependency-reviews.ts +17 -14
- package/server-managed/http.ts +178 -70
- package/server-managed/locked-packages.ts +34 -14
- package/server-managed/lockfile-scope.ts +10 -1
- package/server-managed/npm-kept.ts +10 -0
- package/server-managed/npm-patch.ts +188 -53
- package/server-managed/public-workspace.ts +3 -2
- package/server-managed/pull-dependencies.ts +58 -37
- package/server-managed/pull-dependency-reviews.ts +35 -22
- package/server-managed/report-sources.ts +6 -3
- package/server-managed/repository-dependency-reviews.ts +4 -2
- package/server-managed/repository-issues.ts +14 -11
- package/server-managed/stasis-dependencies.ts +170 -0
- package/out/chunk-65PLAG3I.js +0 -12
- package/out/chunk-DCBXCBLL.js +0 -52
- package/out/chunk-F3UI65ZI.js +0 -42
- package/out/chunk-FAG6E5RC.js +0 -3
- package/out/chunk-OBZWBTZL.js +0 -247
- package/out/chunk-PTFQKLKO.js +0 -1
- package/out/chunk-QVKFY4FA.js +0 -1
- package/out/chunk-SYXT3SFP.js +0 -2
- package/out/chunk-WL3SPQB4.js +0 -1
- /package/out/{chunk-WCPJDAYA.js → chunk-D6NVKGGG.js} +0 -0
package/server-managed/http.ts
CHANGED
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
// { pulls }, one GitHub fails told { number, error } | 400/401/403/404/409/429/502
|
|
56
56
|
// GET /api/admin/repositories/branch-dependencies?repoId= → the versions the default branch's lockfiles lock that want review, where
|
|
57
57
|
// its review is in effect for the reader, GitHub not asked where it reviews none | 400/401/403/404/409/429/502
|
|
58
|
-
// GET /api/admin/repositories/lockfiles?repoId= → the lockfiles of the default branch its dependency review reads, by their
|
|
58
|
+
// GET /api/admin/repositories/lockfiles?repoId= → the lockfiles of the default branch its dependency review reads, and its stasis.config.json files, by their
|
|
59
59
|
// paths, for its settings to name | 400/401/403/404/409/429/502
|
|
60
60
|
// GET /api/admin/repositories/pulse?repoId=&weeks=1|4|13|52 → the default branch's commits and lines a week and a day over
|
|
61
61
|
// the last year, its contributors and when in the period they commit, counted from its commits as Commits keeps them (how many are
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
// POST /api/admin/reports/set-repo → admin|manage attaches/detaches a report's repo | 401/403/404
|
|
76
76
|
// GET /api/admin/reports/<id>/location → admin|manage live location suggestion | 401/403/404/503
|
|
77
77
|
// GET /api/bundles/<id>/{metadata,contents} → authorized encoded bytes | 401/404/422
|
|
78
|
-
// GET /api/bundles/<id>/advisories → published dependency advisories (security access) | 401/403/404
|
|
78
|
+
// GET /api/bundles/<id>/advisories → published dependency advisories (security access), of one ?reason= or ?entry= point where given | 400/401/403/404
|
|
79
79
|
// GET /api/bundles/<id>/dependency-review → what the npm versions it bundles want of review, as the lockfiles installing it lock
|
|
80
80
|
// them at the commit it was built from, where its repository's review is in effect for a reader of all of it | 401/404/409/413/422/429/502
|
|
81
81
|
// GET /api/bundles/<id>/validation → its last validation the reader may see, else none; POST validates it anew: its own code
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
// reads them there | 400/401/404
|
|
116
116
|
// GET /api/npm/package?name=&version= → a published version's manifest and files | 400/401/404/413/429/502
|
|
117
117
|
// GET /api/npm/package?name=&version=&patchHash=&patchRepoId=&patchCommit=&patchPath= → its files as a pnpm patch of a
|
|
118
|
-
// repository the reader reads all of changes them | 400/401/403/404/409/413/422/429/502
|
|
118
|
+
// repository the reader reads all of changes them, its path looked for where left out, as kept where all three are | 400/401/403/404/409/413/422/429/502
|
|
119
119
|
// GET /api/npm/versions?name= → its dist-tags, versions, when each was published and its first was, and whether a team lists its scope | 400/401/404/429/502
|
|
120
120
|
// GET /api/npm/download?name=&version= → its tarball | 400/401/404/413/429/502
|
|
121
121
|
// GET /api/npm/stats?name= → its downloads over the last year and its GitHub repository's figures | 400/401/404/429/502
|
|
@@ -148,7 +148,8 @@ import { pipeline } from 'node:stream/promises'
|
|
|
148
148
|
import { setTimeout as delay } from 'node:timers/promises'
|
|
149
149
|
import { type KeptStore, REPOSITORY_READ_KEPT_MS, authoredCommitStore, branchTipStore, bundleValidationStore, codeHeadStore, codeTreeStore, commitPullStore, githubTagStore, historyChangeStore, historyPageStore, historySquashStore, historyTreeStore,
|
|
150
150
|
issueListStore, lockfileReadStore,
|
|
151
|
-
npmDeltaStore, npmPublishTimeStore, npmVersionStore, ownKeptPrunes, pullDependencyStore, pullListStore, repositoryReadStore, reviewBaselineStore, riskLineStore,
|
|
151
|
+
npmDeltaStore, npmPublishTimeStore, npmVersionStore, ownKeptPrunes, patchStore, pullDependencyStore, pullListStore, repositoryReadStore, reviewBaselineStore, riskLineStore,
|
|
152
|
+
scanReadStore, stasisDependencyStore } from './npm-kept.ts'
|
|
152
153
|
import { plainObject } from './npm-manifest.ts'
|
|
153
154
|
import { type NpmDelta, deltaKey, keptNpmDeltas, npmDelta } from './npm-delta.ts'
|
|
154
155
|
import { ADVISORIES_TIMEOUT_MS, fetchBundleAdvisories } from './bundle-advisories.ts'
|
|
@@ -225,26 +226,28 @@ import { teamAppKey, teamAppStates, withWorkspaceSummary } from './team-app.ts'
|
|
|
225
226
|
import { hashToken, randomToken, safeEqual } from './crypto.ts'
|
|
226
227
|
import { canDeleteComment, parseCommentBody } from '../common/managed/comments.ts'
|
|
227
228
|
import { ManagedMutationError, reportReferenceSnapshot } from './management.ts'
|
|
228
|
-
import { BundleBuildError, buildRepositoryBundle, parseBundleBuild, withBundleBuildLease } from './bundle-build.ts'
|
|
229
|
+
import { BundleBuildError, buildRepositoryBundle, buildRepositoryLockfile, parseBundleBuild, withBundleBuildLease } from './bundle-build.ts'
|
|
229
230
|
import { NpmPackageError, type NpmReader, type NpmVersionDocument, type NpmVersionStore, VERSION_KEPT_MS, canReadPrivateNpm, npmFileRows, npmPublishTime, npmScopesCount, npmTarballFilename, readNpmVersion, readNpmVersions, readTogether } from './npm-packages.ts'
|
|
230
231
|
import { loadNpmFiles, loadNpmPackageBody, loadNpmTarball } from './npm-loads.ts'
|
|
231
|
-
import { type
|
|
232
|
+
import { type ReadPatch, type RequestedPatch, foundPatch, keptPatch, patchedFiles, readPatch, requestedPatch, withPatchFiles } from './npm-patch.ts'
|
|
232
233
|
import { type RepositoryCodeKept, loadRepositoryCodeBody, repositoryCodeFits, repositoryCodeKept } from './repository-code.ts'
|
|
233
|
-
import { type ChangesStore, type CommitChanges, type CommitTree, TREES_READ, changesAsked, changesWithin, directoryFiles, repositoryChanges } from './repository-changes.ts'
|
|
234
|
+
import { type ChangesStore, type CommitChanges, type CommitTree, TREES_READ, changesAsked, changesWithin, directoryFiles, repositoryChanges, repositoryTree } from './repository-changes.ts'
|
|
234
235
|
import { COAUTHORS_READ, coauthorsOf } from './commit-coauthors.ts'
|
|
235
236
|
import { type AllHeads, type HistoryCommit, type HistoryPages, MAX_HISTORY_PAGE, historyFrom, historyStarts, openPullHeads,
|
|
236
237
|
repositoryAllHeads, repositoryAllHistory, repositoryHistory, repositoryRefTips } from './repository-history.ts'
|
|
237
238
|
import { type KnownMerges, type SquashedPull, type Squashes, squashedPulls } from './repository-squashes.ts'
|
|
238
239
|
import { AGENTS_READ_VERSION, type AuthoredCommit, type BranchTip, type BranchTips, COMMITS_CURSOR, type CommitPulls, repositoryAgents } from './repository-agents.ts'
|
|
239
240
|
import { DEPENDENCIES_LABEL, ISSUES_CURSOR, ISSUES_READ_VERSION, OPEN_PULLS_READ, OPEN_PULLS_SIZES, repositoryIssues, repositoryItem, repositoryLabel, repositoryOpenPulls } from './repository-issues.ts'
|
|
240
|
-
import { type GithubAsked, type ListedLockfile, type LockfileRead, type LockfileStore, MAX_LOCKED, PULL_DEPENDENCIES_READ, type PullCommits,
|
|
241
|
-
type
|
|
241
|
+
import { type DirectoryDependencies, type GithubAsked, type ListedLockfile, type LockfileRead, type LockfileStore, MAX_LOCKED, PULL_DEPENDENCIES_READ, type PullCommits,
|
|
242
|
+
type PullDependencies,
|
|
243
|
+
type PullDependencyStore, type PullRefs, lockfileFormat, pullDependenciesAt, pullRefs } from './pull-dependencies.ts'
|
|
242
244
|
import { eachOf } from './queue.ts'
|
|
243
245
|
import { lockedAt, lockedIn, lockfilesAt } from './commit-lockfiles.ts'
|
|
244
|
-
import { MAX_REQUIRED_REVIEWS, type RepoDependencyReview } from './repository-dependency-reviews.ts'
|
|
245
|
-
import { EVERY_LOCKFILE, heldTo, reviewedIn, scopeOf } from './lockfile-scope.ts'
|
|
246
|
+
import { MAX_REQUIRED_REVIEWS, type PublishedReview, type RepoDependencyReview } from './repository-dependency-reviews.ts'
|
|
247
|
+
import { EVERY_LOCKFILE, type LockfileScope, heldTo, isStasisConfig, reviewedIn, scopeOf, stasisConfigs } from './lockfile-scope.ts'
|
|
248
|
+
import { type StasisDependencyReader, stasisDependencyReader, stasisDirectory, withReach } from './stasis-dependencies.ts'
|
|
246
249
|
import { type BundledVersion, bundleDependencies, installsBundle } from './bundle-dependency-reviews.ts'
|
|
247
|
-
import { type ReviewBaselineStore, baselineFor, heldDependencies, reviewedDependencies, reviewedPackages } from './pull-dependency-reviews.ts'
|
|
250
|
+
import { type CommentReviews, type ReviewBaselineStore, baselineFor, heldDependencies, reviewedDependencies, reviewedPackages } from './pull-dependency-reviews.ts'
|
|
248
251
|
import { formattedPull, withFormatted } from './dependency-review-comments.ts'
|
|
249
252
|
import type { ReviewedDependencies } from './reviewed-dependencies.ts'
|
|
250
253
|
import { commentReviews } from './pull-comment-reviews.ts'
|
|
@@ -2006,17 +2009,22 @@ async function handleRepositoryChanges(res: ServerResponse, deps: ManagedHttpDep
|
|
|
2006
2009
|
async function handleRepositoryTree(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
|
|
2007
2010
|
const commit = query.get('commit') ?? ''
|
|
2008
2011
|
if (!SHA.test(commit)) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
2009
|
-
const store = historyTreeStore<CommitTree>(deps.db, deps.config.debug)
|
|
2010
2012
|
await readForReplay(res, deps, cookie, query, async (fullName, token, repoId, path) => {
|
|
2011
|
-
const
|
|
2012
|
-
const value = (await store.read(`${repoId}\0${TREES_READ}\0${sha}`))?.value
|
|
2013
|
-
return value && Array.isArray(value.files) && Array.isArray(value.sizes) && value.sizes.length === value.files.length ? value : null
|
|
2014
|
-
}, write: (sha: string, tree: CommitTree) => store.write(`${repoId}\0${TREES_READ}\0${sha}`, tree, Date.now()) }
|
|
2015
|
-
const tree = await directoryFiles(fullName, token, commit, path, kept)
|
|
2013
|
+
const tree = await directoryFiles(fullName, token, commit, path, commitTreeKept(deps, repoId))
|
|
2016
2014
|
return { commit, path, ...tree ?? { files: null, sizes: null, cut: false } }
|
|
2017
2015
|
})
|
|
2018
2016
|
}
|
|
2019
2017
|
|
|
2018
|
+
// The files repository `repoId`'s commits hold, each kept whole by the commit
|
|
2019
|
+
// and the rules it is read by (historyTreeStore, TREES_READ).
|
|
2020
|
+
function commitTreeKept(deps: ManagedHttpDeps, repoId: number) {
|
|
2021
|
+
const store = historyTreeStore<CommitTree>(deps.db, deps.config.debug)
|
|
2022
|
+
return { read: async (sha: string) => {
|
|
2023
|
+
const value = (await store.read(`${repoId}\0${TREES_READ}\0${sha}`))?.value
|
|
2024
|
+
return value && Array.isArray(value.files) && Array.isArray(value.sizes) && value.sizes.length === value.files.length ? value : null
|
|
2025
|
+
}, write: (sha: string, tree: CommitTree) => store.write(`${repoId}\0${TREES_READ}\0${sha}`, tree, Date.now()) }
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2020
2028
|
// What Replay reads of repository `repoId` within `path` (`read`, with its
|
|
2021
2029
|
// name and the reader's token), as the history is read: with the reader's
|
|
2022
2030
|
// own GitHub access, within their grants as the code is, a directory they
|
|
@@ -2386,15 +2394,19 @@ function sendRefusal(res: ServerResponse, { status, error, retryAfter }: Refusal
|
|
|
2386
2394
|
// GitHub's failure `err`, as a request is refused for it: a token GitHub
|
|
2387
2395
|
// rejects told as GitHub failing (502), never as the reader's session refused.
|
|
2388
2396
|
const githubRefusal = (err: GithubApiError) => refusal(err.status === 401 ? 502 : err.status, err.message, err.retryAfter)
|
|
2389
|
-
// The whole of repository `
|
|
2397
|
+
// The whole of repository `repo`, where the session `cookie` names may
|
|
2390
2398
|
// read all of it, and who reads it; else why not: none of it
|
|
2391
|
-
// (`no-repository`), or only some (`no-directory`).
|
|
2399
|
+
// (`no-repository`), or only some (`no-directory`). `repo` its id, or its
|
|
2400
|
+
// name (`owner/name`), which the one connected repository its reader reads
|
|
2401
|
+
// answers to: one none has, or several, is none of theirs.
|
|
2392
2402
|
type WholeAccess = { repo: SelectedRepo; user: StoredUser }
|
|
2393
|
-
async function wholeRepositoryAccess(deps: ManagedHttpDeps, cookie: string | undefined,
|
|
2403
|
+
async function wholeRepositoryAccess(deps: ManagedHttpDeps, cookie: string | undefined, repo: number | string, { handed = false } = {}): Promise<WholeAccess | Refusal> {
|
|
2394
2404
|
const s = await readSession(deps.config, deps.db, cookie, Date.now(), { handed })
|
|
2395
2405
|
if (s == null) return refusal(401, 'unauthenticated')
|
|
2396
2406
|
if (!roleAtLeast(s.user.role, 'view')) return refusal(403, 'forbidden')
|
|
2397
|
-
|
|
2407
|
+
const grants = await repositoryGrants(deps, s.user)
|
|
2408
|
+
const ids = typeof repo === 'number' ? [repo] : grants.repos.filter(item => item.fullName.toLowerCase() === repo.toLowerCase()).map(item => item.repoId)
|
|
2409
|
+
return ids.length === 1 ? wholeAccessIn(grants, s.user, ids[0]!) : refusal(404, 'no-repository')
|
|
2398
2410
|
}
|
|
2399
2411
|
function wholeAccessIn(grants: Awaited<ReturnType<typeof repositoryGrants>>, user: StoredUser, repoId: number): WholeAccess | Refusal {
|
|
2400
2412
|
const access = repositoryAccessIn(grants, repoId, '')
|
|
@@ -2424,18 +2436,44 @@ async function readWholeRepositoryOf<T>(deps: ManagedHttpDeps, access: WholeAcce
|
|
|
2424
2436
|
}
|
|
2425
2437
|
}
|
|
2426
2438
|
|
|
2427
|
-
// The patch `patch` names (npm-patch.ts),
|
|
2428
|
-
//
|
|
2429
|
-
// held to its hash: as kept,
|
|
2430
|
-
//
|
|
2431
|
-
|
|
2439
|
+
// The patch `patch` names (npm-patch.ts), and where it was read (`source`),
|
|
2440
|
+
// read of the whole of its repository as readWholeRepositoryOf reads it,
|
|
2441
|
+
// with its reader's own GitHub access, and held to its hash: as kept, for
|
|
2442
|
+
// good (patchStore), else with that access checked again after; one named
|
|
2443
|
+
// without its path looked for among its commit's patches (foundPatch), of a
|
|
2444
|
+
// repository whose dependency review is on alone; one named by its hash
|
|
2445
|
+
// alone as kept alone (keptPatchOf); else why it was refused. Its failing to
|
|
2446
|
+
// read or to apply throws.
|
|
2447
|
+
async function npmPatchOf(deps: ManagedHttpDeps, cookie: string | undefined, patch: RequestedPatch): Promise<ReadPatch | Refusal> {
|
|
2448
|
+
if (!('repoId' in patch)) return keptPatchOf(deps, cookie, patch.hash)
|
|
2432
2449
|
const access = await wholeRepositoryAccess(deps, cookie, patch.repoId)
|
|
2433
2450
|
if ('error' in access) return access
|
|
2451
|
+
const { repoId } = access.repo, { hash, commit, path } = patch
|
|
2434
2452
|
const read = await readWholeRepositoryOf(deps, access, async (fullName, token) => {
|
|
2435
|
-
const asked: GithubAsked = { github: false }
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2453
|
+
const asked: GithubAsked = { github: false }, kept = patchStore(deps.db, deps.config.debug)
|
|
2454
|
+
const listed = async () => (await deps.db.repoDependencyReview(repoId))?.enabled ? repositoryTree(fullName, token, commit, commitTreeKept(deps, repoId)) : null
|
|
2455
|
+
const value = path === undefined ? await foundPatch(fullName, token, { hash, repoId, commit }, kept, listed, asked)
|
|
2456
|
+
: await readPatch(fullName, token, { hash, repoId, commit, path }, kept, asked)
|
|
2457
|
+
return { value, kept: !asked.github }
|
|
2458
|
+
}, () => wholeRepositoryAccess(deps, cookie, repoId))
|
|
2459
|
+
return 'error' in read ? read : read.value
|
|
2460
|
+
}
|
|
2461
|
+
// The patch `hash` names as kept, of a connected repository its reader may
|
|
2462
|
+
// read all of, the first of theirs that keeps it (npm-patch.ts keptPatch), as
|
|
2463
|
+
// readWholeRepositoryOf reads what is kept, GitHub asked for none of it; else
|
|
2464
|
+
// `404 patch-not-kept`, as one never read here, or read only of a repository
|
|
2465
|
+
// they can't read all of, is none of theirs.
|
|
2466
|
+
async function keptPatchOf(deps: ManagedHttpDeps, cookie: string | undefined, hash: string): Promise<ReadPatch | Refusal> {
|
|
2467
|
+
const s = await readSession(deps.config, deps.db, cookie, Date.now())
|
|
2468
|
+
if (s == null) return refusal(401, 'unauthenticated')
|
|
2469
|
+
if (!roleAtLeast(s.user.role, 'view')) return refusal(403, 'forbidden')
|
|
2470
|
+
const grants = await repositoryGrants(deps, s.user)
|
|
2471
|
+
const readable = grants.repos.flatMap(repo => { const whole = wholeAccessIn(grants, s.user, repo.repoId); return 'error' in whole ? [] : [whole] })
|
|
2472
|
+
const held = await keptPatch(readable.map(one => one.repo.repoId), hash, patchStore(deps.db, deps.config.debug))
|
|
2473
|
+
const access = held && readable.find(one => one.repo.repoId === held.source.repoId)
|
|
2474
|
+
if (!access) return refusal(404, 'patch-not-kept')
|
|
2475
|
+
const read = await readWholeRepositoryOf(deps, access, () => Promise.resolve({ value: held, kept: true }), () => wholeRepositoryAccess(deps, cookie, access.repo.repoId))
|
|
2476
|
+
return 'error' in read ? read : read.value
|
|
2439
2477
|
}
|
|
2440
2478
|
// The patch a request's fields name, as npm-patch.ts requestedPatch takes them.
|
|
2441
2479
|
const patchFields = (field: (key: string) => unknown) => requestedPatch({ hash: field('patchHash'), repoId: field('patchRepoId'), commit: field('patchCommit'), path: field('patchPath') })
|
|
@@ -2568,11 +2606,12 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
|
|
|
2568
2606
|
commits?: PullCommits) {
|
|
2569
2607
|
const kept = pullDependencyKept(deps, repoId)
|
|
2570
2608
|
const reading: { told?: PullDependencies } = {}
|
|
2571
|
-
|
|
2609
|
+
// With the branches they are of, where told, kept with them.
|
|
2610
|
+
const answered = commits ? { value: { baseRef: commits.baseRef, headRef: commits.headRef, fork: commits.fork, commits: `${commits.base}...${commits.head}` }, kept: true }
|
|
2572
2611
|
: await keptAnswer(deps, `${repoId}\0pull-commits\0${PULL_DEPENDENCIES_READ}\0${number}`, async () => {
|
|
2573
|
-
const read = await pullDependenciesAt(fullName, token, number, kept)
|
|
2574
|
-
reading.told =
|
|
2575
|
-
return
|
|
2612
|
+
const { told, ...read } = await pullDependenciesAt(fullName, token, number, kept)
|
|
2613
|
+
reading.told = told
|
|
2614
|
+
return read
|
|
2576
2615
|
}, undefined, false, stampOf(deps, repoId, fullName, token))
|
|
2577
2616
|
// What its commits tell, as read, else as kept by them, else, no longer
|
|
2578
2617
|
// kept, read again: by those given, without asking GitHub for them.
|
|
@@ -2581,7 +2620,13 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
|
|
|
2581
2620
|
// Where its review is on, those of lockfiles it leaves out told to none,
|
|
2582
2621
|
// whoever asks.
|
|
2583
2622
|
const setting = await deps.db.repoDependencyReview(repoId)
|
|
2584
|
-
|
|
2623
|
+
// With what the stasis.config.json files it holds to reach, each a
|
|
2624
|
+
// directory of its own, none waited for; a lockfile's versions those reach
|
|
2625
|
+
// not marked as its package manager's alone (withReach).
|
|
2626
|
+
const asked: GithubAsked = { github: false }
|
|
2627
|
+
const scoped = setting?.enabled ? withReach(heldDependencies({ ...pulled, lockfiles: [...pulled.lockfiles,
|
|
2628
|
+
...await stasisDirectories(deps, fullName, token, repoId, setting.lockfiles, pulled.base, pulled.head, asked, pullRefs(answered.value.baseRef, answered.value.headRef, answered.value.fork))] },
|
|
2629
|
+
setting.lockfiles)) : pulled
|
|
2585
2630
|
const now = review ? await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(scoped)) : null
|
|
2586
2631
|
// Its review by the lockfiles they were told by, though they have changed
|
|
2587
2632
|
// since; turned off meanwhile, all of them, as where it is off.
|
|
@@ -2594,11 +2639,55 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
|
|
|
2594
2639
|
// open (pull-comment-reviews.ts reads whether it is with them).
|
|
2595
2640
|
const parse = reviewed?.parseComments
|
|
2596
2641
|
const comments = state && parse ? commentReviews({ fullName, number, token, parse, reviewers: accounts => repoReviewers(deps, repoId, accounts) }) : null
|
|
2597
|
-
// The
|
|
2598
|
-
const
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2642
|
+
// The reviews its comments make, as read for its review, the reader's own among them.
|
|
2643
|
+
const commented: PublishedReview[] = []
|
|
2644
|
+
const noting: CommentReviews | null = comments && (async wanting => {
|
|
2645
|
+
const read = await comments(wanting)
|
|
2646
|
+
commented.push(...read.reviews)
|
|
2647
|
+
return read
|
|
2648
|
+
})
|
|
2649
|
+
// Each patch its lockfiles name by its hash alone with its file (npm-patch.ts), where its review is in effect.
|
|
2650
|
+
const patched = state ? await withPatchFiles(told, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked) : told
|
|
2651
|
+
const dependencies = await reviewedDependencies(patched, state, { baseline, baselineUnread: unread, baselineError: error, reviewed, commentReviews: noting })
|
|
2652
|
+
// The comment the host formats of the reader's reviews of its versions, for
|
|
2653
|
+
// its copy button, but those its comments make of theirs already.
|
|
2654
|
+
const formatted = await formattedPull(reviewed, deps.db, user.id, told, state, { repository: fullName, number }, commented)
|
|
2655
|
+
return { value: { number: told.number, ...dependencies, ...formatted ? { formatted } : {} }, kept: answered.kept && held !== null && !asked.github }
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
// What the stasis.config.json files repository `repoId`'s review holds to
|
|
2659
|
+
// (`scope`) have Stasis reach, each a directory of dependencies by its own
|
|
2660
|
+
// path (stasis-dependencies.ts stasisDirectory): at `head`, against `base`
|
|
2661
|
+
// where one is given. None is waited for: one not built yet is built behind
|
|
2662
|
+
// the answer (stasisReader), told the branch its commit is of where `refs`
|
|
2663
|
+
// names it, a pull request's head's, or its base's, which holds `base`. An
|
|
2664
|
+
// open pull request's head that is a fork's (`refs.fork`) is no commit of
|
|
2665
|
+
// the repository's own, which Stasis refuses: nothing is built for it.
|
|
2666
|
+
function stasisDirectories(deps: ManagedHttpDeps, fullName: string, token: string, repoId: number, scope: LockfileScope, base: string | null, head: string,
|
|
2667
|
+
asked: GithubAsked, refs: PullRefs = {}): Promise<DirectoryDependencies[]> {
|
|
2668
|
+
if (refs.fork) return Promise.resolve(stasisConfigs(scope).map(config => ({ paths: [config], error: 'stasis-failed', detail: 'commit-not-own' })))
|
|
2669
|
+
const reader = stasisReader(deps), reads = lockfileKept(deps, repoId)
|
|
2670
|
+
return Promise.all(stasisConfigs(scope).map(config => stasisDirectory(config, base, head,
|
|
2671
|
+
commit => reader.read({ repoId, fullName }, token, commit, config, commit === head ? refs.headRef : refs.baseRef),
|
|
2672
|
+
(commit, held) => lockedAt(fullName, token, commit, reads, held, asked))))
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
// What reads repositories' Stasis dependencies, one a database: kept by it,
|
|
2676
|
+
// each built in the build worker under the deployment's lease
|
|
2677
|
+
// (buildRepositoryLockfile), behind the answer asking for it (trackBehind).
|
|
2678
|
+
const stasisReaders = new WeakMap<ManagedDb, StasisDependencyReader>()
|
|
2679
|
+
function stasisReader(deps: ManagedHttpDeps): StasisDependencyReader {
|
|
2680
|
+
let reader = stasisReaders.get(deps.db)
|
|
2681
|
+
if (!reader) {
|
|
2682
|
+
reader = stasisDependencyReader({
|
|
2683
|
+
store: stasisDependencyStore(deps.db, deps.config.debug),
|
|
2684
|
+
build: (input, github, token, signal) => buildRepositoryLockfile(deps.db, { input, github, token, cacheDir: deps.config.upstreamCacheDir ?? null }, signal),
|
|
2685
|
+
behind: work => { trackBehind(deps, work) },
|
|
2686
|
+
stopping: () => deps.isShuttingDown(),
|
|
2687
|
+
})
|
|
2688
|
+
stasisReaders.set(deps.db, reader)
|
|
2689
|
+
}
|
|
2690
|
+
return reader
|
|
2602
2691
|
}
|
|
2603
2692
|
|
|
2604
2693
|
// GET /api/admin/repositories/branch-dependencies: what the lockfiles of the
|
|
@@ -2633,10 +2722,15 @@ async function branchDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
|
|
|
2633
2722
|
const reads = lockfileKept(deps, repoId)
|
|
2634
2723
|
const read = await lockedAt(fullName, token, head, reads, path => heldTo(setting.lockfiles, path), asked)
|
|
2635
2724
|
const { packages, paths } = lockedIn(read)
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2725
|
+
// And what the stasis.config.json files it holds to reach there (stasisDirectories, withReach).
|
|
2726
|
+
const locked = withReach({ base: head, head, cut: false, lockfiles: [
|
|
2727
|
+
{ paths, added: [], more: 0, locked: packages.slice(0, MAX_LOCKED), moreLocked: Math.max(0, packages.length - MAX_LOCKED) },
|
|
2728
|
+
...read.unread.map(path => ({ paths: [path], error: lockfileFormat(path) === 'bun' ? 'lockfile-unsupported' : 'lockfile-unreadable' })),
|
|
2729
|
+
...await stasisDirectories(deps, fullName, token, repoId, setting.lockfiles, null, head, asked)] }, read.lockfiles)
|
|
2730
|
+
const now = await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(locked))
|
|
2639
2731
|
if (!now) return { value: { head, review: null }, kept: !asked.github }
|
|
2732
|
+
// Every patch there kept, those its lockfiles name the files of too, for a link to find by its hash alone.
|
|
2733
|
+
const told = await withPatchFiles(locked, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked, { keepNamed: true })
|
|
2640
2734
|
// Told by the lockfiles it held to as they were read, though they have
|
|
2641
2735
|
// changed since.
|
|
2642
2736
|
const state = { ...now, lockfiles: setting.lockfiles }
|
|
@@ -2649,13 +2743,16 @@ async function branchDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
|
|
|
2649
2743
|
// GET /api/admin/repositories/lockfiles: the lockfiles of the repository's
|
|
2650
2744
|
// default branch its dependency review reads (commit-lockfiles.ts), by their
|
|
2651
2745
|
// paths, with their formats, at its head, as its pulse reads it, for its
|
|
2652
|
-
// settings to name those it holds to (lockfile-scope.ts)
|
|
2746
|
+
// settings to name those it holds to (lockfile-scope.ts); and the
|
|
2747
|
+
// stasis.config.json files there (`configs`), which it may hold to as well.
|
|
2653
2748
|
async function handleRepositoryLockfiles(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
|
|
2654
2749
|
const repoId = askedRepoId(query)
|
|
2655
2750
|
if (repoId === null) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
2656
2751
|
await answerWholeRepository(res, deps, cookie, repoId, async (fullName, token) => {
|
|
2657
2752
|
const head = (await defaultTip(deps, repoId, fullName, token)).sha
|
|
2658
|
-
return { value: { head, lockfiles:
|
|
2753
|
+
if (!head) return { value: { head, lockfiles: [], configs: [] }, kept: false }
|
|
2754
|
+
const [lockfiles, tree] = await Promise.all([lockfilesAt(fullName, token, head, lockfileKept(deps, repoId)), repositoryTree(fullName, token, head, commitTreeKept(deps, repoId))])
|
|
2755
|
+
return { value: { head, lockfiles: lockfiles.map(({ path, format }) => ({ path, format })), configs: (tree?.files ?? []).filter(isStasisConfig) }, kept: false }
|
|
2659
2756
|
})
|
|
2660
2757
|
}
|
|
2661
2758
|
|
|
@@ -2826,10 +2923,10 @@ type OpenPullsPage = { items?: unknown; more?: unknown; after?: unknown; commits
|
|
|
2826
2923
|
// Each open pull request's base's and head's commits a page of them names,
|
|
2827
2924
|
// into `commits` by its number.
|
|
2828
2925
|
function pageCommits(page: OpenPullsPage, commits: Map<number, PullCommits>) {
|
|
2829
|
-
for (const pull of Array.isArray(page.commits) ? page.commits as { number?: unknown; base?: unknown; head?: unknown }[] : []) {
|
|
2830
|
-
const { number, base, head } = pull ?? {}
|
|
2926
|
+
for (const pull of Array.isArray(page.commits) ? page.commits as { number?: unknown; base?: unknown; head?: unknown; baseRef?: unknown; headRef?: unknown; fork?: unknown }[] : []) {
|
|
2927
|
+
const { number, base, head, baseRef, headRef, fork } = pull ?? {}
|
|
2831
2928
|
if (Number.isSafeInteger(number) && typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head)) {
|
|
2832
|
-
commits.set(number as number, { base, head })
|
|
2929
|
+
commits.set(number as number, { base, head, ...pullRefs(baseRef, headRef, fork) })
|
|
2833
2930
|
}
|
|
2834
2931
|
}
|
|
2835
2932
|
}
|
|
@@ -3479,7 +3576,7 @@ async function handleBundleChanges(res: ServerResponse, deps: ManagedHttpDeps, s
|
|
|
3479
3576
|
|
|
3480
3577
|
// Published dependency advisories require security access, independently of access to
|
|
3481
3578
|
// unpublished dependency findings. Managers retain their normal bundle access.
|
|
3482
|
-
async function handleBundleAdvisories(res: ServerResponse, deps: ManagedHttpDeps, session: ManagedSession, id: string, teamId: string | null, reason: string, repoAdvisories: boolean, details: boolean) {
|
|
3579
|
+
async function handleBundleAdvisories(res: ServerResponse, deps: ManagedHttpDeps, session: ManagedSession, id: string, teamId: string | null, reason: string, entry: string, repoAdvisories: boolean, details: boolean) {
|
|
3483
3580
|
const authorize = async () => {
|
|
3484
3581
|
const access = await deps.db.getBundleAccessSnapshot(session.id, Date.now(), id, teamId)
|
|
3485
3582
|
if (!access) { sendJson(res, 401, { error: 'unauthenticated' }); return null }
|
|
@@ -3494,11 +3591,11 @@ async function handleBundleAdvisories(res: ServerResponse, deps: ManagedHttpDeps
|
|
|
3494
3591
|
if (record.kind !== 'stasis') { sendJson(res, 422, { error: 'unsupported-bundle' }); return }
|
|
3495
3592
|
if (!deps.bundleCache) { sendJson(res, 503, { error: 'unavailable' }); return }
|
|
3496
3593
|
let inventory: BundleAdvisoryInventory | null | undefined
|
|
3497
|
-
try { inventory = await deps.bundleCache.advisoryInventory(record, reason) }
|
|
3594
|
+
try { inventory = await deps.bundleCache.advisoryInventory(record, reason, entry) }
|
|
3498
3595
|
catch { sendJson(res, 422, { error: 'bundle-unavailable' }); return }
|
|
3499
3596
|
if (!(await authorize())) return
|
|
3500
3597
|
if (inventory === null) { sendJson(res, 413, { error: 'payload-too-large' }); return }
|
|
3501
|
-
if (inventory === undefined) { sendJson(res, 400, { error: 'unknown-reason' }); return }
|
|
3598
|
+
if (inventory === undefined) { sendJson(res, 400, { error: entry ? 'unknown-entry' : 'unknown-reason' }); return }
|
|
3502
3599
|
if (Buffer.byteLength(JSON.stringify(inventory)) > MAX_PACKAGE_INVENTORY_BYTES) { sendJson(res, 413, { error: 'payload-too-large' }); return }
|
|
3503
3600
|
const controller = new AbortController()
|
|
3504
3601
|
const onClose = () => { if (!res.writableEnded) controller.abort() }
|
|
@@ -3596,9 +3693,10 @@ async function bundleDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
|
|
|
3596
3693
|
const installing = (await lockfilesAt(fullName, token, commit, reads, asked)).map(({ path }) => path).filter(path => installsBundle(path, directory))
|
|
3597
3694
|
if (!reviewedIn(setting.lockfiles, installing)) return { value: { review: null }, kept: !asked.github }
|
|
3598
3695
|
const read = await lockedAt(fullName, token, commit, reads, path => installsBundle(path, directory) && heldTo(setting.lockfiles, path), asked)
|
|
3599
|
-
const { told, ...bundle } = bundleDependencies(bundled, read, commit)
|
|
3600
|
-
const now = await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(
|
|
3696
|
+
const { told: locked, ...bundle } = bundleDependencies(bundled, read, commit)
|
|
3697
|
+
const now = await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(locked), setting)
|
|
3601
3698
|
if (!now) return { value: { review: null }, kept: !asked.github }
|
|
3699
|
+
const told = await withPatchFiles(locked, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked)
|
|
3602
3700
|
const state = { ...now, lockfiles: setting.lockfiles }
|
|
3603
3701
|
const reviewed = deps.reviewedDependencies ?? null
|
|
3604
3702
|
const { baseline, unread: baselineUnread, error } = reviewed ? { baseline: null, unread: [], error: null }
|
|
@@ -4867,10 +4965,11 @@ function reviewChange(res: ServerResponse, body: Record<string, unknown>): Revie
|
|
|
4867
4965
|
// each change but a revocation loads both versions' files, of tarballs held
|
|
4868
4966
|
// to their integrity and to their shasum where npm tells one (npm-loads.ts),
|
|
4869
4967
|
// and the review keeps those shasums. A patched version's (`patchHash`) are
|
|
4870
|
-
// its files as its patch changes them, the patch read where the
|
|
4871
|
-
// (`patchRepoId`, `patchCommit`, `patchPath`), of the whole of a
|
|
4872
|
-
// its reader reads (npmPatchOf),
|
|
4873
|
-
//
|
|
4968
|
+
// its files as its patch changes them, the patch read as kept, else where the
|
|
4969
|
+
// request says (`patchRepoId`, `patchCommit`, `patchPath`), of the whole of a
|
|
4970
|
+
// repository its reader reads (npmPatchOf), the review keeping where it was
|
|
4971
|
+
// read; and a patched base's (`basePatchHash`) as its patch, kept, changes
|
|
4972
|
+
// them. Access to both versions is rechecked before returning or saving annotations.
|
|
4874
4973
|
async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, params: URLSearchParams): Promise<void> {
|
|
4875
4974
|
const method = req.method ?? 'GET'
|
|
4876
4975
|
if (!['GET', 'POST'].includes(method)) { send405(res, 'GET, POST'); return }
|
|
@@ -4888,17 +4987,19 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
4888
4987
|
const baseVersion = field('baseVersion') ?? null
|
|
4889
4988
|
const baseIntegrity = field('baseIntegrity') ?? null
|
|
4890
4989
|
const patchHash = field('patchHash') ?? null
|
|
4990
|
+
const basePatchHash = field('basePatchHash') ?? null
|
|
4891
4991
|
// Where its patch is, where it names that: its hash alone where only listed.
|
|
4892
4992
|
const patch = patchFields(field)
|
|
4893
4993
|
const validIntegrity = (value: unknown): value is string => typeof value === 'string' && value.length > 0 && value.length <= 1024
|
|
4894
4994
|
if (field('ecosystem') !== 'npm' || !isNpmPackageName(name) || !isNpmPackageSpec(version) || !validIntegrity(integrity)
|
|
4895
4995
|
|| (basePackage !== null || baseVersion !== null || baseIntegrity !== null)
|
|
4896
4996
|
&& (!isNpmPackageName(basePackage) || !isNpmPackageSpec(baseVersion) || !validIntegrity(baseIntegrity))
|
|
4897
|
-
|| (patchHash !== null && !isPatchHash(patchHash)) || patch === 'invalid') {
|
|
4997
|
+
|| (patchHash !== null && !isPatchHash(patchHash)) || patch === 'invalid' || (basePatchHash !== null && (!isPatchHash(basePatchHash) || basePackage === null))) {
|
|
4898
4998
|
sendJson(res, 400, { error: 'bad-review-context' }); return
|
|
4899
4999
|
}
|
|
4900
5000
|
const context: ReviewContext = { ecosystem: 'npm', package: name, version, integrity, patchHash: patchHash as string | null,
|
|
4901
|
-
basePackage: basePackage as string | null, baseVersion: baseVersion as string | null, baseIntegrity: baseIntegrity as string | null
|
|
5001
|
+
basePackage: basePackage as string | null, baseVersion: baseVersion as string | null, baseIntegrity: baseIntegrity as string | null,
|
|
5002
|
+
basePatchHash: basePatchHash as string | null }
|
|
4902
5003
|
let change: ReviewChange | null = null
|
|
4903
5004
|
if (mutation) {
|
|
4904
5005
|
change = reviewChange(res, body)
|
|
@@ -4925,16 +5026,18 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
4925
5026
|
const reading = change && change.action !== 'revoke'
|
|
4926
5027
|
const patchRead = reading && patch ? await npmPatchOf(deps, cookie, patch) : null
|
|
4927
5028
|
if (patchRead && 'error' in patchRead) { sendRefusal(res, patchRead); return }
|
|
5029
|
+
const basePatchRead = reading && basePatchHash ? await npmPatchOf(deps, cookie, { hash: basePatchHash as string }) : null
|
|
5030
|
+
if (basePatchRead && 'error' in basePatchRead) { sendRefusal(res, basePatchRead); return }
|
|
4928
5031
|
const loads = reading ? [doc, ...base ? [base] : []].map(loadNpmFiles) : []
|
|
4929
5032
|
let tarballs: ReviewedTarballs | undefined
|
|
4930
5033
|
try {
|
|
4931
5034
|
const files = await Promise.all(loads.map(load => load.result))
|
|
4932
5035
|
if (loads.length > 0) {
|
|
4933
|
-
tarballs = { shasum: doc.dist.shasum, baseShasum: base?.dist.shasum ?? null,
|
|
4934
|
-
...patchRead && patch ? { patch: { repoId: patch.repoId, commit: patch.commit, path: patch.path } } : {} }
|
|
5036
|
+
tarballs = { shasum: doc.dist.shasum, baseShasum: base?.dist.shasum ?? null, ...patchRead ? { patch: patchRead.source } : {} }
|
|
4935
5037
|
}
|
|
4936
5038
|
if (change?.action === 'publish' || change?.action === 'save') {
|
|
4937
|
-
const
|
|
5039
|
+
const patchOf = [patchRead, basePatchRead]
|
|
5040
|
+
const maps = files.map((list, at) => new Map<string, unknown>(npmFileRows(patchOf[at] ? patchedFiles(list, patchOf[at].files) : list)
|
|
4938
5041
|
.map(([path, size, text, digest]) => [path, text ?? { format: 'digest', size, digest }])))
|
|
4939
5042
|
const after = maps[0]!, before = maps[1] ?? new Map<string, unknown>()
|
|
4940
5043
|
const diff = computeBundleDiff(before, after, () => '.')
|
|
@@ -5058,9 +5161,12 @@ async function handleNpm(req: IncomingMessage, res: ServerResponse, deps: Manage
|
|
|
5058
5161
|
const diffed = path === NPM_RENAME_DIFF_PATH && params.has('path') ? renameDiffRequest(params) : null
|
|
5059
5162
|
if (path === NPM_RENAME_DIFF_PATH && params.has('path') && !diffed) { sendJson(res, 400, { error: 'bad-file' }); return }
|
|
5060
5163
|
// The patch a patched version's files and comparison are of, where named
|
|
5061
|
-
// (`patchHash`, `patchRepoId`, `patchCommit`, `patchPath`), as Review reads them
|
|
5164
|
+
// (`patchHash`, `patchRepoId`, `patchCommit`, `patchPath`), as Review reads them;
|
|
5165
|
+
// and the one a comparison's other version is of, by its hash alone, as kept (`otherPatchHash`).
|
|
5062
5166
|
const patch = patchFields(key => params.get(key))
|
|
5063
|
-
|
|
5167
|
+
const otherPatch = params.has('otherPatchHash') ? requestedPatch({ hash: params.get('otherPatchHash') }) : null
|
|
5168
|
+
if (patch === 'invalid' || (patch && path !== NPM_PACKAGE_PATH && path !== NPM_COMPARISON_PATH)
|
|
5169
|
+
|| otherPatch === 'invalid' || (otherPatch && (path !== NPM_COMPARISON_PATH || otherSpec === '(empty)'))) {
|
|
5064
5170
|
sendJson(res, 400, { error: 'bad-patch' }); return
|
|
5065
5171
|
}
|
|
5066
5172
|
const reader = await npmReader(deps, cookie, otherName === name ? [name] : [name, otherName], { handed: true })
|
|
@@ -5187,18 +5293,20 @@ async function handleNpm(req: IncomingMessage, res: ServerResponse, deps: Manage
|
|
|
5187
5293
|
// Overview reads beside them (comparison.ts): the version shown against
|
|
5188
5294
|
// the one compared with, or `(empty)`, none, as Review reads a first
|
|
5189
5295
|
// version; as `patch` changes its files, where named, the patch read
|
|
5190
|
-
// first (npmPatchOf). Read of both, each
|
|
5191
|
-
// once worked out.
|
|
5296
|
+
// first (npmPatchOf), and `otherPatch` the other's. Read of both, each
|
|
5297
|
+
// package's access checked again once worked out.
|
|
5192
5298
|
if (path === NPM_COMPARISON_PATH) {
|
|
5193
5299
|
const old = otherSpec === '(empty)' ? null : await otherDoc()
|
|
5194
5300
|
const patched = patch ? await npmPatchOf(deps, cookie, patch) : null
|
|
5195
5301
|
if (patched && 'error' in patched) { sendRefusal(res, patched); return }
|
|
5302
|
+
const oldPatched = otherPatch ? await npmPatchOf(deps, cookie, otherPatch) : null
|
|
5303
|
+
if (oldPatched && 'error' in oldPatched) { sendRefusal(res, oldPatched); return }
|
|
5196
5304
|
dropIdle(res)
|
|
5197
5305
|
const loads = [doc, ...old ? [old] : []].map(loadNpmFiles)
|
|
5198
5306
|
let body
|
|
5199
5307
|
try {
|
|
5200
5308
|
const [files, oldFiles] = await Promise.all(loads.map(load => load.result))
|
|
5201
|
-
body = await comparisonBody(old ? npmComparedSide(old.dist.integrity, oldFiles!) : emptySide(),
|
|
5309
|
+
body = await comparisonBody(old ? npmComparedSide(old.dist.integrity, oldPatched ? patchedFiles(oldFiles!, oldPatched.files) : oldFiles!) : emptySide(),
|
|
5202
5310
|
npmComparedSide(doc.dist.integrity, patched ? patchedFiles(files!, patched.files) : files!))
|
|
5203
5311
|
} finally { for (const load of loads) load.release() }
|
|
5204
5312
|
const current = await npmReader(deps, cookie, otherName === name ? [name] : [name, otherName])
|
|
@@ -5268,7 +5376,7 @@ async function handleNpm(req: IncomingMessage, res: ServerResponse, deps: Manage
|
|
|
5268
5376
|
if ('error' in patched) { sendRefusal(res, patched); return }
|
|
5269
5377
|
const load = loadNpmFiles(doc)
|
|
5270
5378
|
let body
|
|
5271
|
-
try { body = await patchedVersionBody(doc, patch, patchedFiles(await load.result, patched.files)) } finally { load.release() }
|
|
5379
|
+
try { body = await patchedVersionBody(doc, { hash: patch.hash, ...patched.source }, patchedFiles(await load.result, patched.files)) } finally { load.release() }
|
|
5272
5380
|
if (!(await recheck(doc.private))) { body.stream.destroy(); return }
|
|
5273
5381
|
dropIdle(res)
|
|
5274
5382
|
await sendEncoded(req, res, body, 'application/json')
|
|
@@ -5574,7 +5682,7 @@ export function createManagedRequestHandler(deps: ManagedHttpDeps): Handler {
|
|
|
5574
5682
|
const bundleAdvisories = /^\/api\/bundles\/([a-f\d-]{36})\/advisories$/iu.exec(path)
|
|
5575
5683
|
if (bundleAdvisories) {
|
|
5576
5684
|
if (method !== 'GET') { send405(res, 'GET'); return }
|
|
5577
|
-
await handleBundleAdvisories(res, deps, workspaceSession!.session, bundleAdvisories[1]!, url.searchParams.get('team'), url.searchParams.get('reason') ?? '', url.searchParams.get('repoAdvisories') === 'true', url.searchParams.get('details') === 'true')
|
|
5685
|
+
await handleBundleAdvisories(res, deps, workspaceSession!.session, bundleAdvisories[1]!, url.searchParams.get('team'), url.searchParams.get('reason') ?? '', url.searchParams.get('entry') ?? '', url.searchParams.get('repoAdvisories') === 'true', url.searchParams.get('details') === 'true')
|
|
5578
5686
|
return
|
|
5579
5687
|
}
|
|
5580
5688
|
const bundleValidationRoute = /^\/api\/bundles\/([a-f\d-]{36})\/validation$/iu.exec(path)
|
|
@@ -7,6 +7,7 @@ import { LockfileError, parseNpmLockfile } from '@preventive/lockfile/npm.js'
|
|
|
7
7
|
import { parsePnpmLockfile } from '@preventive/lockfile/pnpm.js'
|
|
8
8
|
import { parseYarn1Lockfile } from '@preventive/lockfile/yarn1.js'
|
|
9
9
|
import type { LockfileFormat } from '@preventive/upstream/github.js'
|
|
10
|
+
import { isPatchHash } from '../common/managed/npm-packages.js'
|
|
10
11
|
import type { ReviewedLockfile } from './reviewed-dependencies.ts'
|
|
11
12
|
|
|
12
13
|
export interface LockedPackage {
|
|
@@ -27,18 +28,27 @@ export interface LockedPackage {
|
|
|
27
28
|
// Where its reviews ask: the sha1 Yarn 1 writes after a tarball's `#`, in
|
|
28
29
|
// hex (`shasum`); the hash of the patch pnpm applies to it
|
|
29
30
|
// (`patchHash`, its patchedDependencies'), and the patch's file, where the
|
|
30
|
-
// lockfile names one (`patchPath`, pnpm
|
|
31
|
+
// lockfile names one (`patchPath`, pnpm 10's): from the lockfile's
|
|
31
32
|
// directory as read, from the repository's root once that is known
|
|
32
|
-
// (patchedIn)
|
|
33
|
+
// (patchedIn), with that directory then (`patchDir`, '' the root), whence
|
|
34
|
+
// a patch its lockfile names by its hash alone, as pnpm 11 and later do,
|
|
35
|
+
// is found, its file told as one named is (npm-patch.ts withPatchFiles);
|
|
36
|
+
// and the lockfile's format.
|
|
33
37
|
shasum?: string
|
|
34
38
|
patchHash?: string
|
|
35
39
|
patchPath?: string
|
|
40
|
+
patchDir?: string
|
|
36
41
|
lockfile?: ReviewedLockfile
|
|
37
42
|
// Where only the importers' devDependencies reach it, as npm's `dev` flag
|
|
38
43
|
// says, and an install of no devDependencies leaves it out: in npm's and
|
|
39
44
|
// pnpm's lockfiles. Yarn 1's says nothing of it, which only the
|
|
40
45
|
// package.json files do, and none of its are.
|
|
41
46
|
dev?: true
|
|
47
|
+
// A version a Stasis build holds that no lockfile read locks, which can't
|
|
48
|
+
// be reviewed (`unlocked`); and a lockfile's that the stasis.config.json
|
|
49
|
+
// beside it reaches not (`unreached`, stasis-dependencies.ts withReach).
|
|
50
|
+
unlocked?: true
|
|
51
|
+
unreached?: true
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
// A package as each reader resolves one, its name the one it is published
|
|
@@ -51,13 +61,14 @@ interface ReadPackage { name: string; version: string | undefined; resolution: R
|
|
|
51
61
|
patchPath?: string | undefined }
|
|
52
62
|
|
|
53
63
|
// The packages of a lockfile of `format`, as its reader resolves them, a
|
|
54
|
-
// patched one of pnpm's with its patch's file where the lockfile names it
|
|
64
|
+
// patched one of pnpm's with its patch's file where the lockfile names it,
|
|
65
|
+
// but one pnpm 9 names by an md5, which reviews don't read (isPatchHash).
|
|
55
66
|
// Versions go unchecked against ranges, as only what is locked is asked for.
|
|
56
67
|
function packagesOf(format: LockfileFormat, text: string): ReadPackage[] {
|
|
57
68
|
if (format === 'npm') return Object.values(parseNpmLockfile(text, { checkVersions: false }).packages)
|
|
58
69
|
if (format === 'pnpm') {
|
|
59
70
|
const { lockfile, env } = parsePnpmLockfile(text)
|
|
60
|
-
const files = new Map(Object.values(lockfile?.patchedDependencies ?? {}).flatMap(({ hash, path }) => path ? [[hash, path] as const] : []))
|
|
71
|
+
const files = new Map(Object.values(lockfile?.patchedDependencies ?? {}).flatMap(({ hash, path }) => path && isPatchHash(hash) ? [[hash, path] as const] : []))
|
|
61
72
|
return [...Object.values(env?.packages ?? {}), ...Object.values(lockfile?.packages ?? {})]
|
|
62
73
|
.map(pkg => pkg.patchHash !== undefined && files.has(pkg.patchHash) ? { ...pkg, patchPath: files.get(pkg.patchHash) } : pkg)
|
|
63
74
|
}
|
|
@@ -126,18 +137,27 @@ export function lockedPackages(format: LockfileFormat, text: string, { review =
|
|
|
126
137
|
return [...found.values()]
|
|
127
138
|
}
|
|
128
139
|
|
|
129
|
-
// `
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const parts = path.split('/').slice(0, -1)
|
|
136
|
-
for (const part of patchPath.split('/')) {
|
|
137
|
-
if (part === '..') { if (parts.pop() === undefined) return rest as T }
|
|
140
|
+
// `path`, from directory `dir` ('' the repository's root), from the root;
|
|
141
|
+
// null where it leads outside the repository, or names nothing.
|
|
142
|
+
export function pathFrom(dir: string, path: string): string | null {
|
|
143
|
+
const parts = dir === '' ? [] : dir.split('/')
|
|
144
|
+
for (const part of path.split('/')) {
|
|
145
|
+
if (part === '..') { if (parts.pop() === undefined) return null }
|
|
138
146
|
else if (part !== '.' && part !== '') parts.push(part)
|
|
139
147
|
}
|
|
140
|
-
return parts.length > 0 ?
|
|
148
|
+
return parts.length > 0 ? parts.join('/') : null
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// `pkg` as a lockfile at `path` locks it, a patched one with the lockfile's
|
|
152
|
+
// directory (LockedPackage `patchDir`); and, read with its patch's file
|
|
153
|
+
// from that directory (`patchPath`), with that file from the repository's
|
|
154
|
+
// root, none where it names one outside it.
|
|
155
|
+
export function patchedIn<T extends LockedPackage>(path: string, pkg: T): T {
|
|
156
|
+
if (pkg.patchHash === undefined) return pkg
|
|
157
|
+
const { patchPath, ...rest } = pkg
|
|
158
|
+
const patchDir = path.slice(0, Math.max(path.lastIndexOf('/'), 0))
|
|
159
|
+
const file = patchPath === undefined ? null : pathFrom(patchDir, patchPath)
|
|
160
|
+
return { ...rest, patchDir, ...file === null ? {} : { patchPath: file } } as T
|
|
141
161
|
}
|
|
142
162
|
|
|
143
163
|
// Whether a lockfile at `path` is a test's fixture or example: under a
|
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
// request's lockfiles (pull-dependencies.ts) is reviewed where one of its
|
|
7
7
|
// lockfiles is held to; one none of whose are, not at all (`excluded`), nor
|
|
8
8
|
// failing the review where it couldn't be read.
|
|
9
|
+
// Among those it names alone (`include`), a stasis.config.json too: it
|
|
10
|
+
// holds its review to the versions its entries reach (stasis-dependencies.ts).
|
|
11
|
+
import { isStasisConfig } from '../common/managed/stasis-config.ts'
|
|
12
|
+
|
|
13
|
+
export { isStasisConfig }
|
|
9
14
|
export interface LockfileScope { mode: 'exclude' | 'include'; paths: string[] }
|
|
10
15
|
export const EVERY_LOCKFILE: LockfileScope = { mode: 'exclude', paths: [] }
|
|
11
16
|
const MAX_SCOPED_LOCKFILES = 100
|
|
@@ -22,10 +27,11 @@ function namedPath(path: unknown): path is string {
|
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
// A scope as a request sends it, each path once, in order; null for one
|
|
25
|
-
// that isn't one.
|
|
30
|
+
// that isn't one, as one leaving a stasis.config.json out isn't.
|
|
26
31
|
export function scopeOf(value: unknown): LockfileScope | null {
|
|
27
32
|
const { mode, paths } = (value ?? {}) as { mode?: unknown; paths?: unknown }
|
|
28
33
|
if ((mode !== 'exclude' && mode !== 'include') || !Array.isArray(paths) || paths.length > MAX_SCOPED_LOCKFILES || !paths.every(namedPath)) return null
|
|
34
|
+
if (mode === 'exclude' && (paths as string[]).some(isStasisConfig)) return null
|
|
29
35
|
return { mode, paths: [...new Set(paths as string[])].toSorted() }
|
|
30
36
|
}
|
|
31
37
|
|
|
@@ -47,3 +53,6 @@ export function heldTo(scope: LockfileScope, path: string) {
|
|
|
47
53
|
// Whether a directory of lockfiles at `paths` is reviewed: where one is
|
|
48
54
|
// held to, or it names none.
|
|
49
55
|
export const reviewedIn = (scope: LockfileScope, paths: string[]) => paths.length === 0 || paths.some(path => heldTo(scope, path))
|
|
56
|
+
// The stasis.config.json files `scope` holds to, by their paths: those it
|
|
57
|
+
// names alone.
|
|
58
|
+
export const stasisConfigs = (scope: LockfileScope) => scope.mode === 'include' ? scope.paths.filter(isStasisConfig) : []
|