@preventive/triage 1.0.0-alpha.86 → 1.0.0-alpha.88
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-compare-diff.js +3 -2
- package/common/default-scan-models.ts +1 -0
- package/common/dependency-reviews.d.ts +1 -0
- package/common/dependency-reviews.js +3 -0
- package/common/github-issue-labels.d.ts +3 -1
- package/common/github-issue-labels.js +37 -6
- package/common/line-diff.d.ts +2 -1
- package/common/line-diff.js +12 -5
- package/common/managed/roles.ts +7 -0
- package/common/managed/routes.js +7 -6
- package/common/pretty-json.js +25 -0
- package/common/pretty-print.d.ts +1 -0
- package/common/pretty-print.js +5 -0
- package/out/activity.js +2 -2
- package/out/{chunk-ULI2BIWN.js → chunk-3TJCEPHF.js} +1 -1
- package/out/chunk-4GHLPL2P.js +1 -0
- package/out/chunk-5PWEAEA5.js +1 -0
- package/out/chunk-7KUZQB6S.js +267 -0
- package/out/{chunk-YU3IUQY6.js → chunk-A4HSJCXG.js} +1 -1
- package/out/{chunk-ZQQALNFP.js → chunk-BZJU5EEV.js} +1 -1
- package/out/{chunk-6CCSTJWB.js → chunk-ESXA7KID.js} +1 -1
- package/out/{chunk-CE2FMDK3.js → chunk-TKPNRQNN.js} +1 -1
- package/out/{chunk-GM6GP6TA.js → chunk-U6JONPTN.js} +2 -2
- package/out/chunk-VRFGZ6MV.js +1 -0
- package/out/{chunk-XHYX3Q34.js → chunk-XRAAYXPR.js} +1 -1
- package/out/chunk-ZPIUN4FW.js +55 -0
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +28 -28
- package/out/compare.js +13 -13
- package/out/dialogs.js +38 -38
- package/out/graph.js +1 -1
- 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 +2 -2
- package/risk/files/script.js +19 -9
- package/server-e2e/config.ts +3 -1
- package/server-managed/bundle-build-worker.js +13 -6
- package/server-managed/bundle-build.ts +7 -5
- package/server-managed/dependabot-access.ts +41 -17
- package/server-managed/dependabot-alerts.ts +19 -2
- package/server-managed/github-issues.ts +26 -14
- package/server-managed/github-users.ts +23 -0
- package/server-managed/http.ts +271 -123
- package/server-managed/npm-delta-worker.js +56 -8
- package/server-managed/npm-delta.ts +1 -1
- package/server-managed/npm-patch.ts +3 -1
- package/server-managed/pretty-format.d.ts +3 -2
- package/server-managed/pretty-format.js +17 -3
- package/server-managed/pretty-print.ts +18 -16
- package/server-managed/repository-browser.ts +3 -2
- package/server-managed/repository-risk-assess.ts +10 -0
- package/server-managed/stasis-dependencies.ts +14 -5
- package/server-managed/type-only-proof.js +22 -2
- package/out/chunk-2F7GGMMR.js +0 -266
- package/out/chunk-R7HUX4PF.js +0 -1
- package/out/chunk-V4U7URJF.js +0 -54
- package/out/chunk-WOCJFOXN.js +0 -1
- package/out/chunk-ZQHKSKD7.js +0 -1
- /package/out/{chunk-6WMQVUT2.js → chunk-WBK5ZN4K.js} +0 -0
|
@@ -149,12 +149,13 @@ const RENAME_LIMIT = 250
|
|
|
149
149
|
// The files of `onlyBase` renamed to one of `onlyOther`, both by path as the
|
|
150
150
|
// other bundle lays them out, within a package: `Map<base path, other path>`,
|
|
151
151
|
// as @preventive/compare's compareTrees finds them, by content as git diff -M
|
|
152
|
-
// does
|
|
152
|
+
// does, where their paths say so, and a script or style sheet by its text as
|
|
153
|
+
// a build reformats it (renamesByForm). Whether a renamed file changed is
|
|
153
154
|
// sameContent's to say, not this reading's. A path no UTF-8 holds is left out.
|
|
154
155
|
function renamesOf(onlyBase, onlyOther, base, other, pkgOf) {
|
|
155
156
|
const entries = (rows, files, side) => rows.filter(({ path }) => path !== '' && path.isWellFormed())
|
|
156
157
|
.map(({ path }, at) => ({ name: path, data: treeData(files.get(path), `${side}${at}`) }))
|
|
157
|
-
const options = { paths: 'keys', renameGroup: pkgOf, renameLimit: RENAME_LIMIT, lines: false }
|
|
158
|
+
const options = { paths: 'keys', renameGroup: pkgOf, renameLimit: RENAME_LIMIT, renamesByForm: true, lines: false }
|
|
158
159
|
const changes = compareTrees(entries(onlyBase, base, 'a'), entries(onlyOther, other, 'b'), options)
|
|
159
160
|
return new Map(changes.filter(({ status }) => status === 'renamed').map(change => [change.old.path, change.new.path]))
|
|
160
161
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { npmMalwareAdvisory } from '../risk/npm/malware.js'
|
|
2
2
|
|
|
3
|
+
// Drafts published in one request at most (POST /api/npm/reviews/publish).
|
|
4
|
+
export const MAX_PUBLISHED_REVIEWS = 200
|
|
5
|
+
|
|
3
6
|
export const REVIEW_VERDICTS = {
|
|
4
7
|
accept: 'Accept',
|
|
5
8
|
'accept-with-nits': 'Accept with nits (non-blocking)',
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function issueAdvisoryUrl(finding: unknown): string | null
|
|
2
|
+
export function issueLabelChoices(finding: unknown, configured?: string): string[][]
|
|
3
|
+
export function newIssueLabels(finding: unknown, configured?: string): string[]
|
|
@@ -1,11 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { isHttpUrl } from '@preventive/report'
|
|
2
|
+
|
|
3
|
+
// The link of the advisory a finding's issue is on, which the issue opens on
|
|
4
|
+
// in place of the finding's source (`Advisory: <url>`, ui/view/issue-draft.js);
|
|
5
|
+
// null for a finding on none.
|
|
6
|
+
export function issueAdvisoryUrl(finding) {
|
|
7
|
+
const url = finding?.advisory?.url
|
|
8
|
+
return isHttpUrl(url) ? url : null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// The labels a finding's new issue asks for, each a list of names of which
|
|
12
|
+
// it gets the first its repository has: `deepview`; `security` for a
|
|
13
|
+
// security finding; `dependencies`, else `deps`, for one on an advisory;
|
|
14
|
+
// then each of `configured` (GITHUB_NEW_ISSUE_LABELS, comma-separated).
|
|
15
|
+
// Names are trimmed, empty ones dropped, and a label asked for again, in any
|
|
16
|
+
// case, asked for once. Shared by GitHub's prefilled form and managed API
|
|
17
|
+
// issue creation (server-managed/github-issues.ts).
|
|
18
|
+
export function issueLabelChoices(finding, configured = '') {
|
|
3
19
|
const seen = new Set()
|
|
4
|
-
return ['deepview', ...(isSecurity ? ['security'] : []),
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
20
|
+
return [['deepview'], ...(finding?.isSecurity === true ? [['security']] : []),
|
|
21
|
+
...(issueAdvisoryUrl(finding) ? [['dependencies', 'deps']] : []), ...configured.split(',').map(name => [name])]
|
|
22
|
+
.map(names => names.map(name => name.trim()).filter(Boolean))
|
|
23
|
+
.filter(names => {
|
|
24
|
+
const key = names.join('\0').toLowerCase()
|
|
25
|
+
if (names.length === 0 || seen.has(key)) return false
|
|
8
26
|
seen.add(key)
|
|
9
27
|
return true
|
|
10
28
|
})
|
|
11
29
|
}
|
|
30
|
+
|
|
31
|
+
// Every name those ask for, once, for GitHub's prefilled form, which sets
|
|
32
|
+
// only the labels the repository has: unable to tell which, it is handed
|
|
33
|
+
// both `dependencies` and `deps`.
|
|
34
|
+
export function newIssueLabels(finding, configured = '') {
|
|
35
|
+
const seen = new Set()
|
|
36
|
+
return issueLabelChoices(finding, configured).flat().filter(name => {
|
|
37
|
+
const key = name.toLowerCase()
|
|
38
|
+
if (seen.has(key)) return false
|
|
39
|
+
seen.add(key)
|
|
40
|
+
return true
|
|
41
|
+
})
|
|
42
|
+
}
|
package/common/line-diff.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export function indentHiddenBlocks(before: string, after: string): ChangeBlock[]
|
|
|
9
9
|
export function markedCounts(blocks: readonly ChangeBlock[], marks: readonly ChangeBlock[] | null): { additions: number; deletions: number; renamed: number; marked: Set<number> }
|
|
10
10
|
export function diffSize(before: string, after: string, ignoreWhitespace?: boolean | 'leading'): { marks: number; lines: number }
|
|
11
11
|
export const isLargeDiff: (before: string, after: string) => boolean
|
|
12
|
-
export function typeFolds(before: string, after: string, runs: { runs: [number, number][]; otherRuns: [number, number][] }): { before: string; after: string; lineOf: { a: number[]; b: number[] }; lines: { a: number; b: number } } | null
|
|
12
|
+
export function typeFolds(before: string, after: string, runs: { runs: [number, number][]; otherRuns: [number, number][] }): { before: string; after: string; whole: { a: string; b: string }; lineOf: { a: number[]; b: number[] }; lines: { a: number; b: number } } | false | null
|
|
13
|
+
export function copiesRuns(a: { text: string; runs?: [number, number][] }, b: { text: string; runs?: [number, number][] }): { runs: [number, number][]; otherRuns: [number, number][] } | null
|
|
13
14
|
export function withSharedBlankLines(before: string, after: string, blankBefore: readonly number[], blankAfter: readonly number[]): { before: string; after: string }
|
|
14
15
|
export function blocksHold(before: string, after: string, blocks: unknown, ignoreWhitespace?: boolean | 'leading'): boolean
|
package/common/line-diff.js
CHANGED
|
@@ -90,9 +90,10 @@ export function withSharedBlankLines(before, after, blankBefore, blankAfter) {
|
|
|
90
90
|
// A file that changed in types alone but for what runs (type-only.js
|
|
91
91
|
// typeProof), its types set aside: `before` and `after` the texts of each
|
|
92
92
|
// side's lines that run (`runs`, `otherRuns`, `[from, to)` each), diffed in
|
|
93
|
-
// place of the files'; `lineOf` each of their lines' line in its file, and
|
|
94
|
-
// `lines` the file's count, for diffRows to show where the types stand.
|
|
95
|
-
// where
|
|
93
|
+
// place of the files' (`whole`); `lineOf` each of their lines' line in its file, and
|
|
94
|
+
// `lines` the file's count, for diffRows to show where the types stand. False
|
|
95
|
+
// where what runs reads alike on both sides, its types alone changed; else
|
|
96
|
+
// null where that would hide no change.
|
|
96
97
|
export function typeFolds(before, after, { runs, otherRuns }) {
|
|
97
98
|
const side = (text, ranges) => {
|
|
98
99
|
const lineOf = [], lines = textLines(text)
|
|
@@ -104,10 +105,16 @@ export function typeFolds(before, after, { runs, otherRuns }) {
|
|
|
104
105
|
types: lines.filter((_, i) => !shown.has(i)).join('\n') }
|
|
105
106
|
}
|
|
106
107
|
const a = side(before, runs), b = side(after, otherRuns)
|
|
107
|
-
if (a.
|
|
108
|
-
|
|
108
|
+
if (a.run === b.run) return false
|
|
109
|
+
if (a.types === b.types) return null
|
|
110
|
+
return { before: a.text, after: b.text, whole: { a: before, b: after }, lineOf: { a: a.lineOf, b: b.lineOf }, lines: { a: a.lines, b: b.lines } }
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
const NO_RUNS = Object.freeze([])
|
|
114
|
+
// Two printed copies' lines that run, as typeFolds takes them, where each kept
|
|
115
|
+
// them or has no text; else null.
|
|
116
|
+
export const copiesRuns = (a, b) => ([a, b].every(copy => copy.text === '' || copy.runs) ? { runs: a.runs ?? NO_RUNS, otherRuns: b.runs ?? NO_RUNS } : null)
|
|
117
|
+
|
|
111
118
|
// The lines `blocks` add and remove, but for those that are one of `marks`, counted apart (`renamed`, `marked`).
|
|
112
119
|
export function markedCounts(blocks, marks) {
|
|
113
120
|
const told = new Set((marks ?? []).map(({ a0, a1, b0, b1 }) => `${a0},${a1},${b0},${b1}`))
|
package/common/managed/roles.ts
CHANGED
|
@@ -39,3 +39,10 @@ export function canReadRepositoryCode(session: { role: Role; publicShare?: boole
|
|
|
39
39
|
export function canScanTeamRisk(session: { role: Role; publicShare?: boolean } | null | undefined): boolean {
|
|
40
40
|
return session != null && !session.publicShare && roleAtLeast(session.role, 'manage')
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
// Who scans one repository's risk, on its Risk tab: admins alone, as the
|
|
44
|
+
// server scans one repository for them alone (server-managed/http.ts
|
|
45
|
+
// mayReadRisk), signed in. A public link scans none.
|
|
46
|
+
export function canScanRepositoryRisk(session: { role: Role; publicShare?: boolean } | null | undefined): boolean {
|
|
47
|
+
return session != null && !session.publicShare && session.role === 'admin'
|
|
48
|
+
}
|
package/common/managed/routes.js
CHANGED
|
@@ -166,8 +166,8 @@ function parseNpmRoute(path, hash, search) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// The code viewer: a directory of a repository at a commit, on its Code,
|
|
169
|
-
// Search, Treemap, Compare, Commits, Issues, Pull requests, Agents, Pulse
|
|
170
|
-
// or
|
|
169
|
+
// Search, Treemap, Compare, Commits, Issues, Pull requests, Agents, Pulse,
|
|
170
|
+
// Replay or Risk tab, `/repo/<repo id>/<commit>[/<tab>…][?path=<directory>]`,
|
|
171
171
|
// the repository's root where it names no directory. Code, the tab a bare
|
|
172
172
|
// link opens, names its file by number and its lines in the fragment, as a
|
|
173
173
|
// bundle's Code does: `/code/<file>#L4`. Compare names the commit compared
|
|
@@ -178,10 +178,11 @@ function parseNpmRoute(path, hash, search) {
|
|
|
178
178
|
// branch's head, or on the revision a route held in memory names (`ref`),
|
|
179
179
|
// and its route then names the commit it opened. Links from before it moved
|
|
180
180
|
// name it under `/manage/code/`, and open the same.
|
|
181
|
-
export const REPOSITORY_CODE_TABS = new Set(['code', 'search', 'treemap', 'compare', 'commits', 'issues', 'pulls', 'agents', 'pulse', 'replay'])
|
|
181
|
+
export const REPOSITORY_CODE_TABS = new Set(['code', 'search', 'treemap', 'compare', 'commits', 'issues', 'pulls', 'agents', 'pulse', 'replay', 'risk'])
|
|
182
182
|
// The tabs reading none of the directory's files, which a directory at a
|
|
183
|
-
// commit shows alone
|
|
184
|
-
|
|
183
|
+
// commit shows alone: its Activity views, and its Risk, which scans the
|
|
184
|
+
// repository as its default branch has it.
|
|
185
|
+
export const REPOSITORY_FILELESS_TABS = new Set(['commits', 'issues', 'pulls', 'agents', 'pulse', 'replay', 'risk'])
|
|
185
186
|
// The Activity views' sub-tabs past their first: Issues' and Pull requests'
|
|
186
187
|
// closed ones (open, the first), Pulse's periods (a month, the first),
|
|
187
188
|
// Replay's commits played (the last 300, the first), and one agent's
|
|
@@ -219,7 +220,7 @@ function repositoryCodePath(route) {
|
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
function parseRepositoryCodeRoute(url) {
|
|
222
|
-
const match = /^\/(?:repo|manage\/code)\/([1-9]\d*)(?:\/([a-f\d]{40})(?:\/(code|search|treemap|compare|commits|history|issues|pulls|agents|pulse|replay)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u
|
|
223
|
+
const match = /^\/(?:repo|manage\/code)\/([1-9]\d*)(?:\/([a-f\d]{40})(?:\/(code|search|treemap|compare|commits|history|issues|pulls|agents|pulse|replay|risk)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u
|
|
223
224
|
.exec(url.pathname.replace(/\/$/u, ''))
|
|
224
225
|
if (!match) return undefined
|
|
225
226
|
const repoId = Number(match[1])
|
package/common/pretty-json.js
CHANGED
|
@@ -6,6 +6,31 @@ export const jsonPrinted = path => /\.json$/iu.test(path)
|
|
|
6
6
|
// The widths prettyJSON folds to in the pretty-print toggle's layouts.
|
|
7
7
|
export const JSON_LAYOUT_WIDTHS = { indented: 0, folded: 120 }
|
|
8
8
|
|
|
9
|
+
// A text's lines, a final newline ending the last rather than starting another.
|
|
10
|
+
const lineCount = text => (text === '' ? 0 : text.split('\n').length - (text.endsWith('\n') ? 1 : 0))
|
|
11
|
+
|
|
12
|
+
// Whether folding saves enough to offer: of `indented` lines, folded to
|
|
13
|
+
// `folded`, more than ten, and more than a tenth.
|
|
14
|
+
export const foldSaves = (indented, folded) => indented - folded > Math.max(10, indented / 10)
|
|
15
|
+
|
|
16
|
+
// Whether a JSON file's own copies may offer folding: not a package.json's,
|
|
17
|
+
// kept short and read often, which is folded only once the toggle is.
|
|
18
|
+
export const offersFold = path => !/(?:^|\/)package\.json$/u.test(path)
|
|
19
|
+
|
|
20
|
+
// Whether a file's copies, `[indented, folded]`, fold enough of its lines to
|
|
21
|
+
// offer folding (foldSaves).
|
|
22
|
+
export const copiesFold = ([indented, folded]) => foldSaves(lineCount(indented), lineCount(folded))
|
|
23
|
+
|
|
24
|
+
// Whether a comparison's JSON file offers folding: where its copies fold
|
|
25
|
+
// enough of either side's lines (copiesFold), and of those its diff changes,
|
|
26
|
+
// `changed(before, after)` counting them, or null where too many to count.
|
|
27
|
+
// `sides` its two sides' copies, `[indented, folded]`, '' both for a side it lacks.
|
|
28
|
+
export function comparisonFolds(sides, changed) {
|
|
29
|
+
if (!sides.some(copies => copies[0] !== '' && copiesFold(copies))) return false
|
|
30
|
+
const [indented, folded] = [0, 1].map(layout => changed(sides[0][layout], sides[1][layout]))
|
|
31
|
+
return indented !== null && folded !== null && foldSaves(indented, folded)
|
|
32
|
+
}
|
|
33
|
+
|
|
9
34
|
const isContainer = value => value !== null && typeof value === 'object'
|
|
10
35
|
|
|
11
36
|
// `value` on one line, `{ "a": [1, 2] }`, or null where that is longer than
|
package/common/pretty-print.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export const MAX_PRETTY_BYTES: number
|
|
|
4
4
|
export function prettyExtension(path: string): string | null
|
|
5
5
|
export function needsPrettyPrint(path: string, text: string, read?: () => { category: string }): boolean
|
|
6
6
|
export function layoutBlankList(blank: unknown): number[] | null
|
|
7
|
+
export function runRangeList(runs: unknown): [number, number][] | null
|
package/common/pretty-print.js
CHANGED
|
@@ -34,3 +34,8 @@ export function needsPrettyPrint(path, text, read = () => npmFileReadability(pat
|
|
|
34
34
|
// with its text (server-managed/pretty-print.ts, `{ text, blank }`): `blank`
|
|
35
35
|
// where it is lines' numbers in order, else null.
|
|
36
36
|
export const layoutBlankList = blank => (Array.isArray(blank) && blank.every((line, i) => Number.isSafeInteger(line) && line > (blank[i - 1] ?? -1)) ? blank : null)
|
|
37
|
+
|
|
38
|
+
// Lines `[from, to)` as the server tells them, in order, apart: a declaration
|
|
39
|
+
// file's copy's lines that run, or a proof's; else null.
|
|
40
|
+
export const runRangeList = runs => (Array.isArray(runs) && runs.every((range, i) => Array.isArray(range) && range.length === 2
|
|
41
|
+
&& range.every(Number.isSafeInteger) && range[0] >= (runs[i - 1]?.[1] ?? 0) && range[1] > range[0]) ? runs : null)
|