@preventive/upstream 1.5.1 → 1.7.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 CHANGED
@@ -4,163 +4,77 @@ import type { CacheStore } from './npm.js'
4
4
  export { HttpError } from './npm.js'
5
5
  export type { CacheStore } from './npm.js'
6
6
 
7
- // As purl and stasis name them.
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
- // An npm package name, a crate name, a Composer `vendor/name`, a Soldeer
13
- // project name, or for `github`, the repository `owner/name` itself.
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 GitHub repository, where the caller knows it (package.json,
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
- // npm and `github`: semver; `github` also takes a branch name or 0.0.0,
21
- // which every range covers. cargo: semver, build metadata allowed.
22
- // composer: a release (`v1.2.3`, `1.2.3.4`, `2.0.0-RC1`), dev versions
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[]
22
+ // A `github` package: true to ask its repository alone, its name sent to
23
+ // no other source (OSV), as for one not everyone may read. Any spelling
24
+ // saying so holds for all. Not for other ecosystems.
25
+ internal?: boolean
27
26
  }
28
27
 
29
28
  export interface AdvisoryOptions {
30
- // The client every GitHub request goes through. Required for `soldeer`
31
- // and `github` packages, whose repository's published advisories are
32
- // their only source, and for `repoAdvisories`; by itself it asks nothing
33
- // else.
29
+ // Required for `ruby`, `cocoapods`, `soldeer` and `github` packages and for
30
+ // `repoAdvisories`. With it, gems are also checked against ruby-advisory-db.
34
31
  github?: Client
35
- // Also asks each npm, cargo and composer package's GitHub repository
36
- // for its published advisories, which it has before GitHub reviews them
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`.
32
+ // Also reads advisories each package's repository has published that
33
+ // GitHub hasn't reviewed yet. Needs `github`.
43
34
  repoAdvisories?: boolean
44
- // Where what this call caches is kept, as CacheOptions (npm.js) has it:
45
- // a repository's listing, and each package's repository looked up (an
46
- // npm package's as its version's document). See `advisories`.
35
+ // Where lookups and listings are cached (see CacheOptions); false keeps none.
47
36
  cache?: CacheStore | false
48
- // Also returns each advisory's full text, as `details`. OSV's records
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).
37
+ // Also returns each advisory's full text, as `details`.
52
38
  details?: boolean
53
- // Also asks OSV of each npm package's versions, as cargo and composer
54
- // packages always are, for what the registry does not have: above all
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.
39
+ // Also asks OSV about public npm packages: malware and taken-down
40
+ // releases, which npm's registry has no advisories of.
67
41
  osv?: boolean
68
42
  }
69
43
 
70
- // One advisory on one package, with the versions asked about that it
71
- // covers (never empty): one row an id, however many of its sources answer
72
- // it, or however often one does.
44
+ // One advisory on one package, one row per id, however many sources have it.
73
45
  export interface Advisory {
74
46
  ecosystem: Ecosystem
75
47
  name: string
76
- // `registry`: npm's, as `npm audit` has it. `osv`: OSV's records for
77
- // cargo and composer, and with `osv` for npm, the versions they cover
78
- // that no registry row reports under the same advisory; RustSec's,
79
- // GitHub's and malicious packages' (MAL-...) among them; of the records
80
- // naming each other as aliases, directly or through others, a version is
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.
48
+ // npm's registry, OSV, Packagist, ruby-advisory-db, or the package's
49
+ // repository (the only source for `cocoapods` and `soldeer`).
50
+ source: 'registry' | 'osv' | 'packagist' | 'rubysec' | 'repository'
51
+ // The GHSA where there is one, else its source's (RUSTSEC-..., PYSEC-...,
52
+ // MAL-..., CVE-...), or npm:<id>.
97
53
  id: string
98
- // The id itself, or an OSV record's one GHSA alias.
99
54
  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
55
  url?: string
108
- // The advisory's other ids: an `osv` row's record's own and its group's,
109
- // and with `osv`, a registry row's OSV records' of it.
56
+ // Its other ids.
110
57
  aliases: string[]
111
58
  title?: string
112
- // With `details`, the advisory's full text, Markdown as published: an
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.
59
+ // With `details`: its full text, in Markdown.
116
60
  details?: string
117
- // `critical`, `high`, `moderate`, `low`; GitHub's `medium` reads
118
- // `moderate`. RustSec has none.
61
+ // `critical`, `high`, `moderate` or `low`.
119
62
  severity?: string
120
- // Absent where there is no score (npm spells that 0).
121
63
  cvss?: number
122
64
  cvssVector?: string
123
65
  cwe: string[]
124
- // As written: npm's syntax from the registry, GitHub's
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.
66
+ // The affected range as its source wrote it, where it has one.
132
67
  range?: string
133
- // RustSec's kind for an advisory that is not a vulnerability as such:
134
- // `unmaintained`, `unsound`, `notice`. For an id answered more than once,
135
- // only where each answer gives it.
68
+ // RustSec's `unmaintained`, `unsound` or `notice`: not a vulnerability as
69
+ // such. A yanked crate isn't an advisory: see cargo.js's yankedVersions.
136
70
  informational?: string
137
- // Where the advisory is of malware, not a vulnerability: an OSV MAL-
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.
71
+ // Malware, not a vulnerability.
141
72
  malware?: true
73
+ // The asked versions it affects, never none.
142
74
  versions: string[]
143
75
  }
144
76
 
145
- // Every package, and every one of its versions, is checked against its
146
- // ecosystem's rules before the first request; a name given twice is
147
- // merged, and must not name two repositories. npm is asked 250 names a
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.
77
+ // The advisories on the asked versions, sorted by ecosystem and name. Input
78
+ // is checked before any request; a failed or malformed answer throws rather
79
+ // than leaving anything out.
166
80
  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
@@ -1,3 +1,3 @@
1
- export { getCrate, verifyChecksum } from './src/cargo/crate.js'
1
+ export { getCrate, verifyChecksum, yankedVersions } from './src/cargo/crate.js'
2
2
  export { resolveCrateRepos } from './src/cargo/repos.js'
3
3
  export { HttpError } from './src/http.js'
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
- // Every call that reaches the registry first asserts that the name is a
2
- // string of the shape npm takes, and a version a string that npm's
3
- // semver.valid answers with unchanged; neither goes near a request, or a
4
- // cache path, otherwise. Responses are read up to a size limit and within
5
- // a timeout, as github.d.ts describes, and lookups for many names go to
6
- // the registry eight at a time.
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'), read once, when this module is first
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 written and read, resolved when set: `dir`, or
29
- // defaultCacheDir where it is left out, which throws where there is none.
30
- // Unset until this is called, and unset again by `false`, which means no
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 of the caller's, a database's say, for what would otherwise be
49
- // kept in setCacheDir's cache: `read` answers the value last written
50
- // under that `type` and `key`, or null or undefined for none. A `type` is
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
- // Where a call keeps what it caches: in setCacheDir's cache where `cache`
68
- // is left out; in a store of the caller's in place of it; or with `false`,
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: `status` is the HTTP status the registry answered
76
- // with (404 for a package or version it does not have), and `headers` its
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 registry metadata names it -- getRepo
85
- // (package.js) over its `latest` document: `github` is `owner/name`, and
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
- // Fail-soft: a name that resolves to no repo is absent from the map.
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
- // The disk cache resolvePackageRepos reads and writes, a month per entry.
106
- // A read answers null for anything but a usable entry, one written by a
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
- // Where a published version's tarball is and what it hashes to: exactly
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
- // `gitHead` is the commit the document names, as npm reads it off the git
125
- // checkout it publishes from, where it is a full commit id: 40 lowercase
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
- // getMeta's options: `cache`, and the `dist` a caller already has of that
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
- // The registry's version document, refused unless it is for that name and
166
- // version and its dist is held to the rules above.
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 the registry says each version of a package it lists was published,
187
- // by version, as Date#toISOString writes it: from the whole package's
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 the integrity of that version is the one given, as for a
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, whole, in memory. Without `dist`,
201
- // the version document is fetched on every call, cached tarball or not,
202
- // and kept as getMeta keeps it; with one, it is trusted as given and
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.5.1",
4
- "description": "Minimal npm, crates.io, Soldeer, CocoaPods trunk, GitHub and git checkout clients",
3
+ "version": "1.7.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.2.0"
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
@@ -0,0 +1,2 @@
1
+ export { getGem, verifyChecksum } from './src/rubygems/gem.js'
2
+ export { HttpError } from './src/http.js'