@preventive/upstream 1.5.1 → 1.6.0
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/advisories.d.ts +34 -124
- package/cargo.d.ts +7 -0
- package/cargo.js +1 -1
- package/cocoapods.d.ts +18 -1
- package/cocoapods.js +1 -1
- package/github.d.ts +13 -0
- package/npm.d.ts +35 -141
- package/package.json +18 -3
- package/rubygems.d.ts +12 -0
- package/rubygems.js +2 -0
- package/src/advisories/actions.js +75 -0
- package/src/advisories/common.js +15 -19
- package/src/advisories/github.js +61 -74
- package/src/advisories/index.js +22 -26
- package/src/advisories/npm.js +18 -31
- package/src/advisories/osv.js +149 -38
- package/src/advisories/packagist.js +74 -0
- package/src/advisories/repos.js +61 -9
- package/src/advisories/rubysec.js +157 -0
- package/src/args.js +11 -3
- package/src/cache.js +4 -4
- package/src/cargo/crate.js +51 -5
- package/src/cargo/repos.js +2 -6
- package/src/cocoapods.js +36 -3
- package/src/github/commit.js +137 -0
- package/src/github/read.js +2 -1
- package/src/http.js +9 -2
- package/src/npm/versions.js +7 -15
- package/src/pypi/version.js +49 -0
- package/src/rubygems/gem.js +96 -0
- package/src/rubygems/platform.js +120 -0
- package/src/rubygems/version.js +124 -0
- package/src/tree.js +4 -3
package/advisories.d.ts
CHANGED
|
@@ -4,163 +4,73 @@ import type { CacheStore } from './npm.js'
|
|
|
4
4
|
export { HttpError } from './npm.js'
|
|
5
5
|
export type { CacheStore } from './npm.js'
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
export type Ecosystem = 'npm' | 'cargo' | 'composer' | 'soldeer' | 'github'
|
|
7
|
+
// purl's package types, and `ruby` for Ruby interpreters.
|
|
8
|
+
export type Ecosystem = 'npm' | 'cargo' | 'composer' | 'gem' | 'ruby' | 'pypi' | 'swift' | 'cocoapods' | 'soldeer' | 'github'
|
|
9
9
|
|
|
10
10
|
export interface Package {
|
|
11
11
|
ecosystem: Ecosystem
|
|
12
|
-
//
|
|
13
|
-
//
|
|
12
|
+
// As its lockfile names it: a pod by its root (`Firebase`), a Swift package
|
|
13
|
+
// by its repository in any case (`github.com/vapor/vapor`), a `github` package
|
|
14
|
+
// by `owner/name` as GitHub spells it, a Ruby by its engine (`ruby`, `jruby`).
|
|
14
15
|
name: string
|
|
15
|
-
// Its
|
|
16
|
-
// Cargo.toml, installed.json), for `repoAdvisories` to ask without
|
|
17
|
-
// looking it up, and for a `soldeer` package, to ask instead of the one
|
|
18
|
-
// Soldeer names; not for `github` packages, which are their own.
|
|
16
|
+
// Its repository, where known, so `repoAdvisories` needn't look it up.
|
|
19
17
|
github?: RepoName
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
// refused; one semver cannot read is covered by every range. soldeer: as
|
|
24
|
-
// soldeer.lock has it; one semver cannot read (a bare number, a commit)
|
|
25
|
-
// is covered by every range.
|
|
18
|
+
// As its lockfile writes them, matched by the ecosystem's own rules: Ruby's as
|
|
19
|
+
// Bundler writes it (`3.3.6p108`). A `github` package takes a tag (`v4` its
|
|
20
|
+
// whole line), a branch or a commit; an unversioned Swift pin is refused.
|
|
26
21
|
versions: string[]
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
export interface AdvisoryOptions {
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
// their only source, and for `repoAdvisories`; by itself it asks nothing
|
|
33
|
-
// else.
|
|
25
|
+
// Required for `ruby`, `cocoapods`, `soldeer` and `github` packages and for
|
|
26
|
+
// `repoAdvisories`. With it, gems are also checked against ruby-advisory-db.
|
|
34
27
|
github?: Client
|
|
35
|
-
// Also
|
|
36
|
-
//
|
|
37
|
-
// into the databases above: the package's `github` where given, else
|
|
38
|
-
// the one looked up. An npm package's is the one the document of its
|
|
39
|
-
// newest version asked names, kept for good as getMeta keeps it (none
|
|
40
|
-
// where the registry does not have that version); a crate's and a
|
|
41
|
-
// composer package's, the one crates.io or Packagist names, kept a
|
|
42
|
-
// month. Needs `github`.
|
|
28
|
+
// Also reads advisories each package's repository has published that
|
|
29
|
+
// GitHub hasn't reviewed yet. Needs `github`.
|
|
43
30
|
repoAdvisories?: boolean
|
|
44
|
-
// Where
|
|
45
|
-
// a repository's listing, and each package's repository looked up (an
|
|
46
|
-
// npm package's as its version's document). See `advisories`.
|
|
31
|
+
// Where lookups and listings are cached (see CacheOptions); false keeps none.
|
|
47
32
|
cache?: CacheStore | false
|
|
48
|
-
// Also returns each advisory's full text, as `details`.
|
|
49
|
-
// and a repository's listing already carry it; npm's registry does not,
|
|
50
|
-
// and its rows take OSV's record of their GHSA, one more request each
|
|
51
|
-
// (no GitHub client needed).
|
|
33
|
+
// Also returns each advisory's full text, as `details`.
|
|
52
34
|
details?: boolean
|
|
53
|
-
// Also asks OSV
|
|
54
|
-
//
|
|
55
|
-
// the malicious packages' records (MAL-...), which it has none of, as
|
|
56
|
-
// those of npm releases taken down that GitHub's database has no
|
|
57
|
-
// advisory of. A version a registry row reports under the same advisory,
|
|
58
|
-
// its id among an OSV record's id and aliases, is left to that row,
|
|
59
|
-
// which takes the record's ids among its aliases; the versions a record
|
|
60
|
-
// of the row's own id covers beyond the registry's range join it too.
|
|
61
|
-
// Only packages whose name npm's registry serves without a token (its
|
|
62
|
-
// latest version's document, else, where it has no `latest` tag, a HEAD
|
|
63
|
-
// of the package's; unscoped names too, 32 names at a time) go to OSV;
|
|
64
|
-
// the rest, private ones above all, go to the registry alone.
|
|
65
|
-
// The name decides, not the version: npm takes down malicious versions
|
|
66
|
-
// but keeps their name. Public names are cached for a month.
|
|
35
|
+
// Also asks OSV about public npm packages: malware and taken-down
|
|
36
|
+
// releases, which npm's registry has no advisories of.
|
|
67
37
|
osv?: boolean
|
|
68
38
|
}
|
|
69
39
|
|
|
70
|
-
// One advisory on one package,
|
|
71
|
-
// covers (never empty): one row an id, however many of its sources answer
|
|
72
|
-
// it, or however often one does.
|
|
40
|
+
// One advisory on one package, one row per id, however many sources have it.
|
|
73
41
|
export interface Advisory {
|
|
74
42
|
ecosystem: Ecosystem
|
|
75
43
|
name: string
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
// reported under one only: RustSec's, else the GHSA, else the first by
|
|
82
|
-
// id. Each has the others' ids among its aliases, and stays a row of its
|
|
83
|
-
// own, as its source rates it.
|
|
84
|
-
// `repository`: published on the package's repository, holding only the
|
|
85
|
-
// versions the others' answer does not report under that GHSA. The only
|
|
86
|
-
// source for `soldeer` and `github`, where every range counts, whichever
|
|
87
|
-
// package it names.
|
|
88
|
-
// An id answered more than once -- by npm's registry once a range, by
|
|
89
|
-
// OSV's record of it or its repository for versions beyond the registry's
|
|
90
|
-
// range, by its repository once a range -- is one row: the registry's,
|
|
91
|
-
// else OSV's, else the repository's, with what it lacks of theirs (title,
|
|
92
|
-
// details), the worst severity of them, the highest CVSS score with its
|
|
93
|
-
// own vector, and all their ranges, CWEs and versions.
|
|
94
|
-
source: 'registry' | 'osv' | 'repository'
|
|
95
|
-
// A GHSA, RUSTSEC-..., MAL-..., DRUPAL-CORE-... or another OSV id, or
|
|
96
|
-
// npm:<id> for a registry row without a GHSA.
|
|
44
|
+
// npm's registry, OSV, Packagist, ruby-advisory-db, or the package's
|
|
45
|
+
// repository (the only source for `cocoapods` and `soldeer`).
|
|
46
|
+
source: 'registry' | 'osv' | 'packagist' | 'rubysec' | 'repository'
|
|
47
|
+
// The GHSA where there is one, else its source's (RUSTSEC-..., PYSEC-...,
|
|
48
|
+
// MAL-..., CVE-...), or npm:<id>.
|
|
97
49
|
id: string
|
|
98
|
-
// The id itself, or an OSV record's one GHSA alias.
|
|
99
50
|
ghsa?: string
|
|
100
|
-
// GitHub's page for the GHSA, with it: a `repository` row's on its
|
|
101
|
-
// repository (https://github.com/owner/name/security/advisories/GHSA-...),
|
|
102
|
-
// which has it before GitHub reviews it into its advisory database; any
|
|
103
|
-
// other's in that database (https://github.com/advisories/GHSA-...). An
|
|
104
|
-
// `osv` row without one has osv.dev's page for its record
|
|
105
|
-
// (https://osv.dev/vulnerability/RUSTSEC-...). Built, never fetched: only
|
|
106
|
-
// a registry row without a GHSA (npm:<id>) has none.
|
|
107
51
|
url?: string
|
|
108
|
-
//
|
|
109
|
-
// and with `osv`, a registry row's OSV records' of it.
|
|
52
|
+
// Its other ids.
|
|
110
53
|
aliases: string[]
|
|
111
54
|
title?: string
|
|
112
|
-
// With `details
|
|
113
|
-
// OSV record's `details`, a repository advisory's `description`, or for
|
|
114
|
-
// a registry row, OSV's record of its GHSA. Absent where there is none:
|
|
115
|
-
// a registry row without a GHSA, or with one OSV does not have yet.
|
|
55
|
+
// With `details`: its full text, in Markdown.
|
|
116
56
|
details?: string
|
|
117
|
-
// `critical`, `high`, `moderate
|
|
118
|
-
// `moderate`. RustSec has none.
|
|
57
|
+
// `critical`, `high`, `moderate` or `low`.
|
|
119
58
|
severity?: string
|
|
120
|
-
// Absent where there is no score (npm spells that 0).
|
|
121
59
|
cvss?: number
|
|
122
60
|
cvssVector?: string
|
|
123
61
|
cwe: string[]
|
|
124
|
-
//
|
|
125
|
-
// (`>= 1.0.0, < 1.2.6`) from a repository; OSV's records have none. A
|
|
126
|
-
// repository range semver cannot read, or none, covers every version.
|
|
127
|
-
// Each range its id was answered with that covers an asked version,
|
|
128
|
-
// joined by ` || `; none ('') where one is none. A version only OSV
|
|
129
|
-
// reports may be outside it: hermes-engine's GHSA-f5x2-xv93-4p23 is
|
|
130
|
-
// `<=0.4.3` on npm, the last version known affected, and fixed in 0.5.2
|
|
131
|
-
// by OSV's record of it, which reports 0.5.0 too.
|
|
62
|
+
// The affected range as its source wrote it, where it has one.
|
|
132
63
|
range?: string
|
|
133
|
-
// RustSec's
|
|
134
|
-
//
|
|
135
|
-
// only where each answer gives it.
|
|
64
|
+
// RustSec's `unmaintained`, `unsound` or `notice`: not a vulnerability as
|
|
65
|
+
// such. A yanked crate isn't an advisory: see cargo.js's yankedVersions.
|
|
136
66
|
informational?: string
|
|
137
|
-
//
|
|
138
|
-
// record (its `id` or an alias), CWE-506 (how GitHub files malware), or
|
|
139
|
-
// a `title` with the word "malware". `severity` is left as rated: MAL-
|
|
140
|
-
// records have none, and GitHub rates some malware high.
|
|
67
|
+
// Malware, not a vulnerability.
|
|
141
68
|
malware?: true
|
|
69
|
+
// The asked versions it affects, never none.
|
|
142
70
|
versions: string[]
|
|
143
71
|
}
|
|
144
72
|
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
// request, OSV 1000 versions, Soldeer one project, and with `details`, OSV
|
|
149
|
-
// one GHSA among npm's rows; a project Soldeer does not have or that names
|
|
150
|
-
// no GitHub repository, a repository gone or blocked, and one GitHub
|
|
151
|
-
// redirects anywhere but to a repository by its id, add nothing, and a
|
|
152
|
-
// GHSA OSV does not have adds no `details`. With `osv`, a name npm's
|
|
153
|
-
// registry doesn't serve without a token is taken as private (see `osv`). A repository renamed or
|
|
154
|
-
// transferred, which GitHub redirects to it by its id, is listed by the
|
|
155
|
-
// name it has now, as getRepo's `followRedirect` (github.js) finds it, its
|
|
156
|
-
// rows' `url` on it. Any other failure, a malformed answer, or one about
|
|
157
|
-
// something not asked, throws: nothing is left out quietly.
|
|
158
|
-
// A repository's listing is kept for 90 minutes, as one entry for every
|
|
159
|
-
// spelling of the name it is asked by, one renamed or transferred too,
|
|
160
|
-
// holding only what rows are made from, `details` included: in
|
|
161
|
-
// setCacheDir's cache gzipped, in a `cache` store as it is, or with
|
|
162
|
-
// `cache` false, nowhere. 90 minutes is how late an advisory its
|
|
163
|
-
// maintainer publishes can be seen. One gone or malformed is not kept.
|
|
164
|
-
// Sorted by ecosystem and name. Versions are matched by npm's semver, from
|
|
165
|
-
// the npm beside node, or by the semver peer where there is no npm.
|
|
73
|
+
// The advisories on the asked versions, sorted by ecosystem and name. Input
|
|
74
|
+
// is checked before any request; a failed or malformed answer throws rather
|
|
75
|
+
// than leaving anything out.
|
|
166
76
|
export function advisories(packages: Iterable<Package>, options?: AdvisoryOptions): Promise<Advisory[]>
|
package/cargo.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// version, and a checksum 64 lowercase hex digits, before any request or
|
|
3
3
|
// cache path. The cache is setCacheDir's (npm.js).
|
|
4
4
|
|
|
5
|
+
import type { CacheOptions } from './npm.js'
|
|
6
|
+
|
|
5
7
|
export { HttpError } from './npm.js'
|
|
6
8
|
|
|
7
9
|
// Reads crates.io's index for that version and throws unless its sha256
|
|
@@ -21,6 +23,11 @@ export function verifyChecksum(name: string, version: string, checksum: string):
|
|
|
21
23
|
// setCacheDir's cache that does not match throws.
|
|
22
24
|
export function getCrate(name: string, version: string, checksum?: string): Promise<Uint8Array>
|
|
23
25
|
|
|
26
|
+
// Each asked crate's versions crates.io has yanked, as `cargo audit` warns
|
|
27
|
+
// of, and those it doesn't have (all, for a crate of another registry or a
|
|
28
|
+
// git source). Not advisories, so not in advisories(); cached 90 minutes.
|
|
29
|
+
export function yankedVersions(crates: Iterable<{ name: string, versions: string[] }>, options?: CacheOptions): Promise<Map<string, { yanked: string[], unknown: string[] }>>
|
|
30
|
+
|
|
24
31
|
// What resolveCrateRepos maps each resolved name to: `owner/name`, the
|
|
25
32
|
// GitHub repo the crate's `repository` on crates.io names.
|
|
26
33
|
export interface CrateRepo {
|
package/cargo.js
CHANGED
package/cocoapods.d.ts
CHANGED
|
@@ -29,5 +29,22 @@ export { HttpError } from './npm.js'
|
|
|
29
29
|
//
|
|
30
30
|
// What the pod is built from is not trunk's, and is not fetched here: a
|
|
31
31
|
// commit of a GitHub repo, as a podspec's `source` or CHECKOUT OPTIONS
|
|
32
|
-
// may name, is github.js's getRepoTarball's
|
|
32
|
+
// may name, is github.js's getRepoTarball's; an archive by :http is
|
|
33
|
+
// getPodArchive's.
|
|
33
34
|
export function getPodspec(name: string, version: string, checksum: string): Promise<Uint8Array>
|
|
35
|
+
|
|
36
|
+
// An archive a podspec's `source` names by :http, from GitHub alone, whole,
|
|
37
|
+
// in memory: `url` is https://github.com/<owner>/<repo>/ and a path under
|
|
38
|
+
// it, such as GitHub's archive of a tag, `archive/refs/tags/<tag>.tar.gz`,
|
|
39
|
+
// or a release's asset, `releases/download/<tag>/<file>`, as written, with
|
|
40
|
+
// no query, fragment, credentials or port, and each segment of the path
|
|
41
|
+
// letters, digits, `_`, `.`, `~`, `@`, `-` or a %-escape in capitals. The
|
|
42
|
+
// hash is the podspec's :sha256, in lowercase hex, as cocoapods-downloader
|
|
43
|
+
// checks it; a sha1, which two archives made to collide share, is not
|
|
44
|
+
// taken. GitHub answers with a
|
|
45
|
+
// redirect, to codeload.github.com or to where it keeps a release's files,
|
|
46
|
+
// which is followed, as the bytes are held to the hash whoever answers,
|
|
47
|
+
// downloaded (before they are cached) or read from setCacheDir's cache. They
|
|
48
|
+
// are cached by the hash alone; one in the cache that does not match throws.
|
|
49
|
+
// Each argument is asserted before any request.
|
|
50
|
+
export function getPodArchive(url: string, sha256: string): Promise<Uint8Array>
|
package/cocoapods.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getPodspec } from './src/cocoapods.js'
|
|
1
|
+
export { getPodArchive, getPodspec } from './src/cocoapods.js'
|
|
2
2
|
export { HttpError } from './src/http.js'
|
package/github.d.ts
CHANGED
|
@@ -134,6 +134,19 @@ export interface Client {
|
|
|
134
134
|
// one's tag object followed to the commit, through up to 8 tags of tags.
|
|
135
135
|
// Refused for a tag on anything but a commit.
|
|
136
136
|
getRepoTag(options: { repo: RepoName; tag: string }): Promise<{ tag: string; oid: string }>
|
|
137
|
+
// The id of the tree of the full commit `sha`, a sha1, held to `sha`:
|
|
138
|
+
// read off the commit's own object, which is fetched as git fetches it,
|
|
139
|
+
// from github.com's git-upload-pack over git's protocol v2 (`want`,
|
|
140
|
+
// `deepen 1`, `filter tree:0`, so the commit alone), and hashed, as
|
|
141
|
+
// `commit <size>\0` and its bytes, to `sha`. So the tree is the commit's,
|
|
142
|
+
// whatever GitHub's API would say of it, as getRepoTarball and
|
|
143
|
+
// getRepoTreeId take it from. The packfile is held to its trailer;
|
|
144
|
+
// GitHub's ERR, a side-band error, an answer with no such commit, or one
|
|
145
|
+
// whose first line names no tree, is refused. The client's token, where
|
|
146
|
+
// it has one, is sent as git sends one, by Basic. A redirect is not
|
|
147
|
+
// followed: one for a repository renamed or transferred throws, an
|
|
148
|
+
// HttpError with its status, for getRepo to follow.
|
|
149
|
+
getCommitTree(options: { repo: RepoName; sha: string }): Promise<string>
|
|
137
150
|
// The repo's gzipped tarball at the full commit `sha`, whole, in memory:
|
|
138
151
|
// getRepoTreeTarball's for the tree GitHub names for that commit, asked
|
|
139
152
|
// on every call, cached or not. So its top directory is named for the
|
package/npm.d.ts
CHANGED
|
@@ -1,91 +1,43 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// Where PREVENTIVE_MEASURES_NPM_TOKEN, STASIS_NPM_TOKEN or NPM_TOKEN is
|
|
9
|
-
// set, the first of them not empty, in that order, is sent with the
|
|
10
|
-
// requests for a scoped package, so a private one can be read.
|
|
11
|
-
|
|
12
|
-
// Where a program called `name` keeps its cache for this user, as each
|
|
13
|
-
// platform has it, read from the environment when called. macOS:
|
|
14
|
-
// ~/Library/Caches/<name>. Windows: %LOCALAPPDATA%\<name>\Cache, the
|
|
15
|
-
// `Cache` apart from the program's other local data there. Elsewhere, the
|
|
16
|
-
// XDG Base Directory spec's: $XDG_CACHE_HOME/<name>, or ~/.cache/<name>
|
|
17
|
-
// where it is unset, empty or relative, which the spec has ignored.
|
|
18
|
-
// Undefined where no absolute directory is found to start from: a home
|
|
19
|
-
// directory that is relative, empty or unknown. Nothing is made. `name` is
|
|
20
|
-
// 6 to 32 of a-z, A-Z, 0-9, `_` and `-`, so one directory name the same on
|
|
21
|
-
// every platform.
|
|
1
|
+
// Names and versions are checked before any request. A scoped package is
|
|
2
|
+
// read with PREVENTIVE_MEASURES_NPM_TOKEN, STASIS_NPM_TOKEN or NPM_TOKEN,
|
|
3
|
+
// the first set.
|
|
4
|
+
|
|
5
|
+
// The platform's cache directory for a program called `name` (6 to 32 of
|
|
6
|
+
// a-z, A-Z, 0-9, `_`, `-`); undefined without an absolute home. Nothing is made.
|
|
22
7
|
export function cacheDirFor(name: string): string | undefined
|
|
23
8
|
|
|
24
|
-
// cacheDirFor('PreventiveMeasures'),
|
|
25
|
-
// imported: where setCacheDir() caches.
|
|
9
|
+
// cacheDirFor('PreventiveMeasures'), where setCacheDir() caches by default.
|
|
26
10
|
export const defaultCacheDir: string | undefined
|
|
27
11
|
|
|
28
|
-
// Where cached answers are
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
// cache: every read of it misses and every write is skipped. getTarball
|
|
32
|
-
// reads ours all the same, set or not.
|
|
33
|
-
//
|
|
34
|
-
// The directory is trusted: a package's repo, as recorded or as a version
|
|
35
|
-
// document kept here names it, and for 90 minutes a repository's published
|
|
36
|
-
// advisories (advisories.js), are answered from it as they were written,
|
|
37
|
-
// with no request. Point it only at storage that
|
|
38
|
-
// nothing less trusted than the caller can write, never a cache shared
|
|
39
|
-
// with or restored from lower-trust jobs. Tarballs, crates (cargo.js), zips
|
|
40
|
-
// (soldeer.js), podspecs (cocoapods.js) and tree tarballs (github.js) don't
|
|
41
|
-
// rely on this, since they are checked against their integrity on every
|
|
42
|
-
// call; and the version documents kept here (getMeta) never supply an
|
|
43
|
-
// integrity, only confirm one a caller gives (verifyDist, and getMeta with
|
|
44
|
-
// a `dist`). A call's `cache` option, where it has one, keeps what it
|
|
45
|
-
// caches elsewhere, or writes none of it here.
|
|
12
|
+
// Where cached answers are kept: `dir`, else defaultCacheDir (which throws
|
|
13
|
+
// where there is none); `false` turns the cache off. What's cached is
|
|
14
|
+
// trusted, so point it only at storage nothing less trusted can write.
|
|
46
15
|
export function setCacheDir(dir?: string | false): void
|
|
47
16
|
|
|
48
|
-
// A store
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
// what is kept and a `key` which one: `npm/versions` and `npm/tarballs`
|
|
52
|
-
// with `<name>@<version>` for a version's document and tarball; and for
|
|
53
|
-
// advisories.js, `github/advisories` with the repository's `owner/name` in
|
|
54
|
-
// lowercase for its listing, `cargo/repos`, `composer/repos` and
|
|
55
|
-
// `soldeer/repos` with a package's name for the repository it names, and
|
|
56
|
-
// `npm/public` with an npm package's name that is public, for `osv`.
|
|
57
|
-
// Values are plain JSON data, which `read` may answer as written or as a
|
|
58
|
-
// copy, but a tarball's are its bytes, a Uint8Array. Whatever it answers
|
|
59
|
-
// is checked as a cached file is: one malformed, stale or kept differently
|
|
60
|
-
// is a miss, and a tarball's bytes that do not match throw. A rejection
|
|
61
|
-
// from either is the call's. It is trusted as setCacheDir's directory is.
|
|
17
|
+
// A caller's store in place of setCacheDir's: `read` answers what `write`
|
|
18
|
+
// last stored under `type` and `key`, or null. Values are JSON, a tarball's
|
|
19
|
+
// a Uint8Array; it is trusted as setCacheDir's directory is.
|
|
62
20
|
export interface CacheStore {
|
|
63
21
|
read(type: string, key: string): Promise<unknown>
|
|
64
22
|
write(type: string, key: string, value: unknown): Promise<void>
|
|
65
23
|
}
|
|
66
24
|
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
// nowhere, though setCacheDir's cache is read all the same. Other tools'
|
|
70
|
-
// caches and ours are read for tarballs whatever it is (getTarball).
|
|
25
|
+
// setCacheDir's cache where `cache` is left out, a caller's store in its
|
|
26
|
+
// place, or `false` for none.
|
|
71
27
|
export interface CacheOptions {
|
|
72
28
|
cache?: CacheStore | false
|
|
73
29
|
}
|
|
74
30
|
|
|
75
|
-
// A failed request
|
|
76
|
-
//
|
|
77
|
-
// response's.
|
|
31
|
+
// A failed request, by its HTTP status: 404 for a package or version the
|
|
32
|
+
// registry hasn't.
|
|
78
33
|
export class HttpError extends Error {
|
|
79
34
|
name: 'HttpError'
|
|
80
35
|
status: number
|
|
81
36
|
headers?: Headers
|
|
82
37
|
}
|
|
83
38
|
|
|
84
|
-
// A package's GitHub repo as its
|
|
85
|
-
//
|
|
86
|
-
// `directory` is where in the repo the package sits, `''` at the repo
|
|
87
|
-
// root, absent where it declares none. Throws when the package cannot be
|
|
88
|
-
// fetched or names no GitHub repo.
|
|
39
|
+
// A package's GitHub repo as its `latest` document names it, and where in it
|
|
40
|
+
// the package sits (`''` the root). Throws where it names none.
|
|
89
41
|
export interface GitHubLink {
|
|
90
42
|
github: string
|
|
91
43
|
directory?: string
|
|
@@ -93,47 +45,26 @@ export interface GitHubLink {
|
|
|
93
45
|
}
|
|
94
46
|
export function getGitHub(name: string): Promise<GitHubLink>
|
|
95
47
|
|
|
96
|
-
// What resolvePackageRepos maps each resolved name to.
|
|
97
48
|
export interface PackageRepo {
|
|
98
49
|
github: string
|
|
99
50
|
directory?: string
|
|
100
51
|
}
|
|
101
|
-
//
|
|
102
|
-
// `cachedOnly` answers from the disk cache alone and never fetches.
|
|
52
|
+
// A name that resolves to no repo is left out. `cachedOnly` never fetches.
|
|
103
53
|
export function resolvePackageRepos(packageNames: Iterable<string>, options?: { cachedOnly?: boolean }): Promise<Map<string, PackageRepo>>
|
|
104
54
|
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
// release that resolved repos by other rules included; a write answers
|
|
108
|
-
// false where it could not write, and never throws. A write takes the
|
|
109
|
-
// `github` a lookup gives, `owner/name` with no trailing `.git`, so what
|
|
110
|
-
// it writes reads back; a `directory` left out is unknown, and `''` the
|
|
111
|
-
// repo root.
|
|
55
|
+
// resolvePackageRepos' disk cache, a month an entry: a read answers null for
|
|
56
|
+
// nothing usable, a write false where it couldn't write.
|
|
112
57
|
export function readPackageRepoCache(name: string): Promise<PackageRepo | null>
|
|
113
58
|
export function writePackageRepoCache(name: string, github: string, directory?: string): Promise<boolean>
|
|
114
59
|
|
|
115
|
-
//
|
|
116
|
-
// these two, `tarball` the registry's own URL for that version and
|
|
117
|
-
// `integrity` one `sha512-<base64>`, nothing else (no sha1, second hash
|
|
118
|
-
// or option). A dist given to a function below is held to the same.
|
|
60
|
+
// Exactly a version's own tarball URL and one `sha512-<base64>`.
|
|
119
61
|
export interface Dist {
|
|
120
62
|
tarball: string
|
|
121
63
|
integrity: string
|
|
122
64
|
}
|
|
123
65
|
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
// hex digits, or 64. `repository`, `homepage` and `bugs` are the
|
|
127
|
-
// document's, as the package.json published had them, or npm filled them
|
|
128
|
-
// in from one another: each a string as it is, or for `repository` and
|
|
129
|
-
// `bugs` an object, of which only the strings named below are read. Each is
|
|
130
|
-
// absent where the document has none, or has another shape, or an object
|
|
131
|
-
// with none of those strings. All of it is the publisher's word, held to no
|
|
132
|
-
// repository. `unpackedSize` is the document's dist.unpackedSize: the bytes
|
|
133
|
-
// of the files in the tarball, as the registry counted them when the
|
|
134
|
-
// version was published, held to no tarball. It is absent where the
|
|
135
|
-
// document has none, as for a version published before the registry
|
|
136
|
-
// counted them, or has one that is not a whole number of bytes.
|
|
66
|
+
// All of it the publisher's word, held to no repository or tarball. A field
|
|
67
|
+
// missing or not of its shape is absent.
|
|
137
68
|
export interface PackageMeta {
|
|
138
69
|
name: string
|
|
139
70
|
version: string
|
|
@@ -156,61 +87,24 @@ export interface PackageBugs {
|
|
|
156
87
|
email: string | undefined
|
|
157
88
|
}
|
|
158
89
|
|
|
159
|
-
//
|
|
160
|
-
// version, as a lockfile gives it, held to the rules above.
|
|
90
|
+
// `dist`: one the caller already has, as a lockfile gives it.
|
|
161
91
|
export interface MetaOptions extends CacheOptions {
|
|
162
92
|
dist?: Dist
|
|
163
93
|
}
|
|
164
94
|
|
|
165
|
-
//
|
|
166
|
-
// version
|
|
167
|
-
//
|
|
168
|
-
// With `dist`, npm's own cache comes first, where getTarball looks for
|
|
169
|
-
// npm's tarballs: where it keeps the full packument of that name, as npm 10
|
|
170
|
-
// and later fetch it, and that version's entry there has the given dist's
|
|
171
|
-
// tarball and integrity, that entry answers, with no request, and neither
|
|
172
|
-
// `cache` nor setCacheDir's cache is read or written. An abbreviated
|
|
173
|
-
// packument, as earlier npm fetches, is passed over, as is one whose
|
|
174
|
-
// content does not match the sha512 npm filed it by. What it answers
|
|
175
|
-
// beside the dist is taken from npm's cache as it is from setCacheDir's.
|
|
176
|
-
// Else the document `cache` keeps answers, with no request, where its
|
|
177
|
-
// tarball and integrity are the given dist's; else the registry's is asked
|
|
178
|
-
// for, and throws where they are not.
|
|
179
|
-
//
|
|
180
|
-
// Without `dist`, the registry is asked on every call: a cache never
|
|
181
|
-
// supplies a dist. Kept whole, as `cache` says, and for good once it
|
|
182
|
-
// passes, as the registry never takes a version twice: in setCacheDir's
|
|
183
|
-
// cache, compressed, where `cache` is left out. One refused is not kept.
|
|
95
|
+
// A version's registry document, refused unless it is for that name and
|
|
96
|
+
// version. With `dist`, npm's own cache or ours may answer with no request;
|
|
97
|
+
// without one, the registry is always asked. Kept for good.
|
|
184
98
|
export function getMeta(name: string, version: string, options?: MetaOptions): Promise<PackageMeta>
|
|
185
99
|
|
|
186
|
-
// When
|
|
187
|
-
//
|
|
188
|
-
// document, the only one with `time`, megabytes for some. A version whose
|
|
189
|
-
// time is missing, not an ISO 8601 UTC time, or not one there is, as
|
|
190
|
-
// 2018-02-29, is left out. Refused unless the document is for that name.
|
|
100
|
+
// When each version was published, as Date#toISOString writes it; versions
|
|
101
|
+
// without a valid time are left out. Reads the whole package's document.
|
|
191
102
|
export function getPublishTimes(name: string): Promise<Map<string, string>>
|
|
192
103
|
|
|
193
|
-
// Throws unless
|
|
194
|
-
// dist read off a lockfile: by the version document `cache` keeps, with no
|
|
195
|
-
// request, else by the registry's, kept then as getMeta keeps it. One kept
|
|
196
|
-
// with another integrity, refused, or for another name or version, is
|
|
197
|
-
// passed over for the registry's, which throws where it has another.
|
|
104
|
+
// Throws unless that version's integrity is the one given.
|
|
198
105
|
export function verifyDist(name: string, version: string, dist: Dist, options?: CacheOptions): Promise<void>
|
|
199
106
|
|
|
200
|
-
// A published version's gzipped tarball,
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
// nothing but the tarball is asked for. Either way the bytes are checked
|
|
204
|
-
// against `dist.integrity`, whether they were downloaded (before they are
|
|
205
|
-
// cached) or read from a cache.
|
|
206
|
-
//
|
|
207
|
-
// Other caches are read first, and never written: npm's (cacache under
|
|
208
|
-
// npm_config_cache, else npm's default, `~/.npm` outside Windows; and npm
|
|
209
|
-
// 4's `<name>/<version>/package.tgz` there), then
|
|
210
|
-
// `~/.audit/cache/tgz/<org>:<name>-<version>.tgz`, then defaultCacheDir
|
|
211
|
-
// and cacheDirFor('stasis'), as setCacheDir files a tarball in either,
|
|
212
|
-
// whether set or not. A file there that does not match is passed over.
|
|
213
|
-
// Then setCacheDir's cache, or a `cache` store in its place, where bytes
|
|
214
|
-
// that do not match throw. A tarball downloaded is kept there, unless
|
|
215
|
-
// `cache` is false.
|
|
107
|
+
// A published version's gzipped tarball, checked against its integrity. npm's
|
|
108
|
+
// and other tools' caches are read first, never written; setCacheDir's (or
|
|
109
|
+
// `cache`) is written.
|
|
216
110
|
export function getTarball(name: string, version: string, dist?: Dist, options?: CacheOptions): Promise<Uint8Array>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/upstream",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Minimal npm, crates.io, Soldeer, CocoaPods trunk, GitHub and git checkout clients",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "Minimal npm, crates.io, RubyGems, Soldeer, CocoaPods trunk, GitHub and git checkout clients",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./advisories.js": {
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
"types": "./package.d.ts",
|
|
37
37
|
"default": "./package.js"
|
|
38
38
|
},
|
|
39
|
+
"./rubygems.js": {
|
|
40
|
+
"types": "./rubygems.d.ts",
|
|
41
|
+
"default": "./rubygems.js"
|
|
42
|
+
},
|
|
39
43
|
"./semver.js": {
|
|
40
44
|
"types": "./semver.d.ts",
|
|
41
45
|
"default": "./semver.js"
|
|
@@ -68,18 +72,23 @@
|
|
|
68
72
|
"npm.js",
|
|
69
73
|
"package.d.ts",
|
|
70
74
|
"package.js",
|
|
75
|
+
"rubygems.d.ts",
|
|
76
|
+
"rubygems.js",
|
|
71
77
|
"semver.d.ts",
|
|
72
78
|
"semver.js",
|
|
73
79
|
"soldeer.d.ts",
|
|
74
80
|
"soldeer.js",
|
|
75
81
|
"weak-edges.d.ts",
|
|
76
82
|
"weak-edges.js",
|
|
83
|
+
"src/advisories/actions.js",
|
|
77
84
|
"src/advisories/common.js",
|
|
78
85
|
"src/advisories/github.js",
|
|
79
86
|
"src/advisories/index.js",
|
|
80
87
|
"src/advisories/npm.js",
|
|
81
88
|
"src/advisories/osv.js",
|
|
89
|
+
"src/advisories/packagist.js",
|
|
82
90
|
"src/advisories/repos.js",
|
|
91
|
+
"src/advisories/rubysec.js",
|
|
83
92
|
"src/args.js",
|
|
84
93
|
"src/attributes.js",
|
|
85
94
|
"src/cache.js",
|
|
@@ -89,6 +98,7 @@
|
|
|
89
98
|
"src/download.js",
|
|
90
99
|
"src/git.js",
|
|
91
100
|
"src/github/client.js",
|
|
101
|
+
"src/github/commit.js",
|
|
92
102
|
"src/github/read.js",
|
|
93
103
|
"src/github/write.js",
|
|
94
104
|
"src/http.js",
|
|
@@ -100,7 +110,11 @@
|
|
|
100
110
|
"src/npm/versions.js",
|
|
101
111
|
"src/package.js",
|
|
102
112
|
"src/pool.js",
|
|
113
|
+
"src/pypi/version.js",
|
|
103
114
|
"src/remote.js",
|
|
115
|
+
"src/rubygems/gem.js",
|
|
116
|
+
"src/rubygems/platform.js",
|
|
117
|
+
"src/rubygems/version.js",
|
|
104
118
|
"src/semver-peer.cjs",
|
|
105
119
|
"src/semver.js",
|
|
106
120
|
"src/tree.js",
|
|
@@ -132,7 +146,8 @@
|
|
|
132
146
|
"access": "public"
|
|
133
147
|
},
|
|
134
148
|
"dependencies": {
|
|
135
|
-
"@preventive/archive": "^1.
|
|
149
|
+
"@preventive/archive": "^1.4.0",
|
|
150
|
+
"@preventive/lockfile": "^1.3.0"
|
|
136
151
|
},
|
|
137
152
|
"peerDependencies": {
|
|
138
153
|
"semver": "^7.5.2"
|
package/rubygems.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// rubygems.org's gems. Names, versions, platforms (`ruby` for none) and
|
|
2
|
+
// checksums are checked before any request, and pass as
|
|
3
|
+
// @preventive/lockfile's BundlerSpec has them.
|
|
4
|
+
|
|
5
|
+
export { HttpError } from './npm.js'
|
|
6
|
+
|
|
7
|
+
// Throws unless the compact index has `checksum` for that version and platform.
|
|
8
|
+
export function verifyChecksum(name: string, version: string, platform: string, checksum: string): Promise<void>
|
|
9
|
+
|
|
10
|
+
// A published .gem, checked against `checksum`, else the compact index's.
|
|
11
|
+
// RubyGems' own caches are read first; setCacheDir's (npm.js) is written.
|
|
12
|
+
export function getGem(name: string, version: string, platform: string, checksum?: string): Promise<Uint8Array>
|
package/rubygems.js
ADDED