@preventive/upstream 1.0.0-alpha.3 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/advisories.d.ts +27 -16
- package/cargo.d.ts +18 -1
- package/cargo.js +2 -1
- package/github.d.ts +21 -11
- package/package.json +15 -3
- package/semver.d.ts +2 -1
- package/src/advisories/common.js +8 -4
- package/src/advisories/github.js +24 -8
- package/src/advisories/index.js +5 -5
- package/src/advisories/osv.js +25 -11
- package/src/advisories/repos.js +17 -35
- package/src/args.js +31 -2
- package/src/cache.js +20 -2
- package/src/{cargo.js → cargo/crate.js} +17 -11
- package/src/cargo/repos.js +52 -0
- package/src/github/read.js +57 -16
- package/src/http.js +16 -11
- package/src/npm/repos.js +2 -5
- package/src/npm/tarball.js +1 -6
- package/src/semver-peer.cjs +8 -0
- package/src/semver.js +26 -12
- package/src/soldeer.js +2 -9
- package/src/tree.js +7 -6
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/advisories.d.ts
CHANGED
|
@@ -6,28 +6,32 @@ import type { Client, RepoName } from './github.js'
|
|
|
6
6
|
export { HttpError } from './npm.js'
|
|
7
7
|
|
|
8
8
|
// As purl and stasis name them.
|
|
9
|
-
export type Ecosystem = 'npm' | 'cargo' | 'composer' | 'github'
|
|
9
|
+
export type Ecosystem = 'npm' | 'cargo' | 'composer' | 'soldeer' | 'github'
|
|
10
10
|
|
|
11
11
|
export interface Package {
|
|
12
12
|
ecosystem: Ecosystem
|
|
13
|
-
// An npm package name, a crate name, a Composer `vendor/name`,
|
|
14
|
-
// `github`, the repository `owner/name` itself.
|
|
13
|
+
// An npm package name, a crate name, a Composer `vendor/name`, a Soldeer
|
|
14
|
+
// project name, or for `github`, the repository `owner/name` itself.
|
|
15
15
|
name: string
|
|
16
16
|
// Its GitHub repository, where the caller knows it (package.json,
|
|
17
17
|
// Cargo.toml, installed.json), for `repoAdvisories` to ask without
|
|
18
|
-
// looking it up
|
|
18
|
+
// looking it up, and for a `soldeer` package, to ask instead of the one
|
|
19
|
+
// Soldeer names; not for `github` packages, which are their own.
|
|
19
20
|
github?: RepoName
|
|
20
21
|
// npm and `github`: semver; `github` also takes a branch name or 0.0.0,
|
|
21
22
|
// which every range covers. cargo: semver, build metadata allowed.
|
|
22
23
|
// 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.
|
|
24
|
+
// refused; one semver cannot read is covered by every range. soldeer: as
|
|
25
|
+
// soldeer.lock has it; one semver cannot read (a bare number, a commit)
|
|
26
|
+
// is covered by every range.
|
|
24
27
|
versions: string[]
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
export interface AdvisoryOptions {
|
|
28
|
-
// The client every GitHub request goes through. Required for `
|
|
29
|
-
// packages, whose repository's published advisories are
|
|
30
|
-
// source, and for `repoAdvisories`; by itself it asks nothing
|
|
31
|
+
// The client every GitHub request goes through. Required for `soldeer`
|
|
32
|
+
// and `github` packages, whose repository's published advisories are
|
|
33
|
+
// their only source, and for `repoAdvisories`; by itself it asks nothing
|
|
34
|
+
// else.
|
|
31
35
|
github?: Client
|
|
32
36
|
// Also asks each npm, cargo and composer package's GitHub repository
|
|
33
37
|
// for its published advisories, which it has before GitHub reviews them
|
|
@@ -43,13 +47,18 @@ export interface Advisory {
|
|
|
43
47
|
ecosystem: Ecosystem
|
|
44
48
|
name: string
|
|
45
49
|
// `registry`: npm's, as `npm audit` has it, one row per vulnerable
|
|
46
|
-
// range. `osv`:
|
|
50
|
+
// range. `osv`: OSV's records for cargo and composer, RustSec's, GitHub's
|
|
51
|
+
// and malicious packages' (MAL-…) among them; of the records naming each
|
|
52
|
+
// other as aliases, directly or through others, a version is reported
|
|
53
|
+
// under one only: RustSec's, else the GHSA, else the first by id. Each
|
|
54
|
+
// has the others' ids among its aliases.
|
|
47
55
|
// `repository`: published on the package's repository, one row per
|
|
48
56
|
// range, holding only the versions the others' answer does not report
|
|
49
|
-
// under that GHSA.
|
|
57
|
+
// under that GHSA. The only source for `soldeer` and `github`, where
|
|
58
|
+
// every range counts, whichever package it names.
|
|
50
59
|
source: 'registry' | 'osv' | 'repository'
|
|
51
|
-
// A GHSA, RUSTSEC-…, DRUPAL-CORE
|
|
52
|
-
// without a GHSA.
|
|
60
|
+
// A GHSA, RUSTSEC-…, MAL-…, DRUPAL-CORE-… or another OSV id, or
|
|
61
|
+
// npm:<id> for a registry row without a GHSA.
|
|
53
62
|
id: string
|
|
54
63
|
// The id itself, or an OSV record's one GHSA alias.
|
|
55
64
|
ghsa?: string
|
|
@@ -75,8 +84,10 @@ export interface Advisory {
|
|
|
75
84
|
// Every package, and every one of its versions, is checked against its
|
|
76
85
|
// ecosystem's rules before the first request; a name given twice is
|
|
77
86
|
// merged, and must not name two repositories. npm is asked 250 names a
|
|
78
|
-
// request, OSV 1000 versions
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
87
|
+
// request, OSV 1000 versions, Soldeer one project; a project Soldeer does
|
|
88
|
+
// not have or that names no GitHub repository, and a repository gone,
|
|
89
|
+
// renamed or blocked, add nothing. Any other failure, a malformed answer,
|
|
90
|
+
// or one about something not asked, throws: nothing is left out quietly.
|
|
91
|
+
// Sorted by ecosystem and name. Versions are matched by npm's semver, from
|
|
92
|
+
// the npm beside node, or by the semver peer where there is no npm.
|
|
82
93
|
export function advisories(packages: Iterable<Package>, options?: AdvisoryOptions): Promise<Advisory[]>
|
package/cargo.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
// Hand-written against cargo.js; a change to either belongs with the other.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// A name is asserted to be a crate name, a version an exact semver
|
|
4
4
|
// version, and a checksum 64 lowercase hex digits, before any request or
|
|
5
5
|
// cache path. The cache is setCacheDir's (npm.js).
|
|
6
6
|
|
|
7
7
|
export { HttpError } from './npm.js'
|
|
8
8
|
|
|
9
|
+
// Reads crates.io's index for that version and throws unless its sha256
|
|
10
|
+
// is the one given, as for a checksum read off Cargo.lock. The index is
|
|
11
|
+
// read on every call; nothing is cached.
|
|
12
|
+
export function verifyChecksum(name: string, version: string, checksum: string): Promise<void>
|
|
13
|
+
|
|
9
14
|
// A published version's .crate, whole, in memory. `checksum` is its
|
|
10
15
|
// sha256 as Cargo.lock records it; without one, crates.io's index is read
|
|
11
16
|
// for it on every call, cached crate or not. Either way the bytes are
|
|
@@ -17,3 +22,15 @@ export { HttpError } from './npm.js'
|
|
|
17
22
|
// `~/.cargo`. A file there that does not match is passed over. One in
|
|
18
23
|
// setCacheDir's cache that does not match throws.
|
|
19
24
|
export function getCrate(name: string, version: string, checksum?: string): Promise<Uint8Array>
|
|
25
|
+
|
|
26
|
+
// What resolveCrateRepos maps each resolved name to: `owner/name`, the
|
|
27
|
+
// GitHub repo the crate's `repository` on crates.io names.
|
|
28
|
+
export interface CrateRepo {
|
|
29
|
+
github: string
|
|
30
|
+
}
|
|
31
|
+
// Fail-soft, as npm.js's resolvePackageRepos: a crate crates.io does not
|
|
32
|
+
// have, one naming no GitHub repo, and those of a request that fails are
|
|
33
|
+
// absent from the map. crates.io is asked a hundred names a request, a
|
|
34
|
+
// second apart, as it asks; a repo found is cached for a month, and
|
|
35
|
+
// `cachedOnly` answers from that cache alone and never fetches.
|
|
36
|
+
export function resolveCrateRepos(crateNames: Iterable<string>, options?: { cachedOnly?: boolean }): Promise<Map<string, CrateRepo>>
|
package/cargo.js
CHANGED
package/github.d.ts
CHANGED
|
@@ -65,16 +65,20 @@ export interface Client {
|
|
|
65
65
|
getRepoFile(options: { repo: RepoName; path: string; ref?: string }): Promise<string>
|
|
66
66
|
// The head of `branch`, or of the default branch without one.
|
|
67
67
|
getRepoHead(options: { repo: RepoName; branch?: string }): Promise<{ branch: string; oid: string }>
|
|
68
|
+
// The commit `tag` names: GitHub's ref for exactly that tag, an annotated
|
|
69
|
+
// one's tag object followed to the commit, through up to 8 tags of tags.
|
|
70
|
+
// Refused for a tag on anything but a commit.
|
|
71
|
+
getRepoTag(options: { repo: RepoName; tag: string }): Promise<{ tag: string; oid: string }>
|
|
68
72
|
// The repo's gzipped tarball at the full commit `sha`, whole, in memory:
|
|
69
73
|
// getRepoTreeTarball's for the tree GitHub names for that commit, asked
|
|
70
74
|
// on every call, cached or not. So its top directory is named for the
|
|
71
75
|
// tree, and files marked `export-subst` are as committed, not rewritten.
|
|
72
76
|
getRepoTarball(options: { repo: RepoName; sha: string }): Promise<Uint8Array>
|
|
73
|
-
// The id of the tree at `
|
|
74
|
-
// of its root without one: from the tree GitHub
|
|
75
|
-
// down GitHub's listings a directory at a time,
|
|
76
|
-
// id. Refused where `
|
|
77
|
-
getRepoTreeId(options: { repo: RepoName; sha: string;
|
|
77
|
+
// The id of the tree at `directory`, `/`-separated as npm's is, in the
|
|
78
|
+
// full commit `sha`, or of its root without one: from the tree GitHub
|
|
79
|
+
// names for the commit, down GitHub's listings a directory at a time,
|
|
80
|
+
// each hashed back to its id. Refused where `directory` is none.
|
|
81
|
+
getRepoTreeId(options: { repo: RepoName; sha: string; directory?: string }): Promise<string>
|
|
78
82
|
// The gzipped tarball of a tree, the repo's own or any subdirectory's, by
|
|
79
83
|
// its id, whole, in memory: GitHub's, its files under one top directory.
|
|
80
84
|
// Its files are hashed back into git's tree and the id must be `tree`,
|
|
@@ -90,13 +94,19 @@ export interface Client {
|
|
|
90
94
|
// has; that repo still gets a tree already cached, pointers and all.
|
|
91
95
|
getRepoTreeTarball(options: { repo: RepoName; tree: string }): Promise<Uint8Array>
|
|
92
96
|
// The repository's published security advisories, as GitHub's
|
|
93
|
-
// repository advisory objects
|
|
94
|
-
//
|
|
97
|
+
// repository advisory objects: every page of 100, each found by the
|
|
98
|
+
// cursor in the one before's Link header. More than 100 pages is an
|
|
99
|
+
// error.
|
|
95
100
|
listRepoAdvisories(options: { repo: RepoName }): Promise<any[]>
|
|
96
|
-
// The entries of
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
listRepoDir(options: { repo: RepoName; sha: string;
|
|
101
|
+
// The entries of `directory` in the full commit `sha`, or of its root,
|
|
102
|
+
// found as getRepoTreeId finds it: GitHub's listing, hashed back to the
|
|
103
|
+
// tree's id, so none is left out or changed.
|
|
104
|
+
listRepoDir(options: { repo: RepoName; sha: string; directory?: string }): Promise<RepoDirEntry[]>
|
|
105
|
+
// Every page of the repo's tags, as GitHub lists them, each with the
|
|
106
|
+
// commit GitHub names for it, an annotated tag's included, which
|
|
107
|
+
// getRepoTag checks is one; more than `maxPages` (100 by default) pages
|
|
108
|
+
// of 100 is an error, as is a tag with no commit.
|
|
109
|
+
listRepoTags(options: { repo: RepoName; maxPages?: number }): Promise<{ tag: string; oid: string }[]>
|
|
100
110
|
// Every page of `GET /user/repos`, as GitHub's repository objects; more
|
|
101
111
|
// than `maxPages` (100 by default) pages of 100 is an error.
|
|
102
112
|
listUserRepos(options?: { maxPages?: number }): Promise<any[]>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/upstream",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
4
4
|
"description": "Minimal npm, crates.io and Soldeer registry clients, a GitHub client, and a git checkout reader: the calls we use, nothing more",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
|
+
"LICENSE-APACHE",
|
|
46
|
+
"LICENSE-MIT",
|
|
45
47
|
"advisories.d.ts",
|
|
46
48
|
"advisories.js",
|
|
47
49
|
"cargo.d.ts",
|
|
@@ -68,7 +70,8 @@
|
|
|
68
70
|
"src/advisories/repos.js",
|
|
69
71
|
"src/args.js",
|
|
70
72
|
"src/cache.js",
|
|
71
|
-
"src/cargo.js",
|
|
73
|
+
"src/cargo/crate.js",
|
|
74
|
+
"src/cargo/repos.js",
|
|
72
75
|
"src/download.js",
|
|
73
76
|
"src/git.js",
|
|
74
77
|
"src/github/client.js",
|
|
@@ -80,6 +83,7 @@
|
|
|
80
83
|
"src/package.js",
|
|
81
84
|
"src/pool.js",
|
|
82
85
|
"src/remote.js",
|
|
86
|
+
"src/semver-peer.cjs",
|
|
83
87
|
"src/semver.js",
|
|
84
88
|
"src/tree.js",
|
|
85
89
|
"src/soldeer.js"
|
|
@@ -90,7 +94,7 @@
|
|
|
90
94
|
"scripts": {
|
|
91
95
|
"test": "node --test ./tests/*.test.js"
|
|
92
96
|
},
|
|
93
|
-
"license": "MIT",
|
|
97
|
+
"license": "MIT OR Apache-2.0",
|
|
94
98
|
"author": {
|
|
95
99
|
"name": "Nikita Skovoroda",
|
|
96
100
|
"email": "chalkerx@gmail.com",
|
|
@@ -107,5 +111,13 @@
|
|
|
107
111
|
"homepage": "https://github.com/PreventiveMeasures/libraries/tree/main/upstream",
|
|
108
112
|
"publishConfig": {
|
|
109
113
|
"access": "public"
|
|
114
|
+
},
|
|
115
|
+
"peerDependencies": {
|
|
116
|
+
"semver": "^7.5.2"
|
|
117
|
+
},
|
|
118
|
+
"peerDependenciesMeta": {
|
|
119
|
+
"semver": {
|
|
120
|
+
"optional": true
|
|
121
|
+
}
|
|
110
122
|
}
|
|
111
123
|
}
|
package/semver.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Hand-written against semver.js; a change to either belongs with the other.
|
|
2
2
|
|
|
3
3
|
// npm's own semver, borrowed from the npm beside node and passed through
|
|
4
|
-
// as it is
|
|
4
|
+
// as it is; where there is no npm, the `semver` package, an optional peer
|
|
5
|
+
// dependency. Without either, every call throws, except valid() on a plain
|
|
5
6
|
// MAJOR.MINOR.PATCH with no options.
|
|
6
7
|
export function satisfies(version: string, range: string, options?: { includePrerelease?: boolean; loose?: boolean }): boolean
|
|
7
8
|
export function compareVersions(a: string, b: string, options?: { loose?: boolean }): -1 | 0 | 1
|
package/src/advisories/common.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isStrings, matches } from '../args.js'
|
|
2
|
-
import { satisfies, validRange } from '../semver.js'
|
|
2
|
+
import { satisfies, valid, validRange } from '../semver.js'
|
|
3
3
|
|
|
4
4
|
export const order = (a, b) => (a > b) - (a < b)
|
|
5
5
|
|
|
@@ -8,9 +8,13 @@ const SEMVER = { includePrerelease: true, loose: true }
|
|
|
8
8
|
|
|
9
9
|
export const inRange = (version, range) => satisfies(version, range, SEMVER)
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
export const
|
|
11
|
+
// A version semver cannot read may be in any range. Whatever it reads is
|
|
12
|
+
// a version, `v1.2.3` and `1.2.3+build` included.
|
|
13
|
+
export const mayBeInRange = (version, range) => valid(version) === null || inRange(version, range)
|
|
14
|
+
|
|
15
|
+
// The asked versions a range `covers`. One semver cannot read, range or
|
|
16
|
+
// version, covers them all: a missed advisory is worse than a spare one.
|
|
17
|
+
export const covered = (asked, range, covers = mayBeInRange) => (validRange(range, SEMVER) === null ? [...asked] : asked.filter((version) => covers(version, range)))
|
|
14
18
|
|
|
15
19
|
// Remote text, as long as it is well-formed; anything else is refused as
|
|
16
20
|
// malformed by whoever reads it.
|
package/src/advisories/github.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
|
|
3
|
-
import { assertRepo, assertion, isGhsa, isRefName, isStrings } from '../args.js'
|
|
3
|
+
import { assertRepo, assertSoldeerName, assertSoldeerVersion, assertion, isGhsa, isRefName, isStrings } from '../args.js'
|
|
4
4
|
import { isGone } from '../github/client.js'
|
|
5
5
|
import { recover } from '../http.js'
|
|
6
6
|
import { pool } from '../pool.js'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { covered, isText, mayBeInRange, metrics } from './common.js'
|
|
8
|
+
import { soldeerRepos } from './repos.js'
|
|
9
9
|
|
|
10
10
|
const REPOS_AT_ONCE = 4
|
|
11
11
|
|
|
@@ -59,6 +59,12 @@ async function repositoryAdvisories(github, asked, { repoOf, takes = () => true,
|
|
|
59
59
|
return [...rows.values()]
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// Each asked name's repository: as given, `known`, or else looked up.
|
|
63
|
+
async function reposOf(asked, known, lookUp) {
|
|
64
|
+
const found = await lookUp([...asked.keys()].filter((name) => !known.has(name)))
|
|
65
|
+
return (name) => known.get(name) ?? found.get(name)
|
|
66
|
+
}
|
|
67
|
+
|
|
62
68
|
// A maintainer's advisory is on the repository before GitHub reviews it
|
|
63
69
|
// into the databases the registries answer from. With `repoAdvisories`,
|
|
64
70
|
// each package's repository, `known` or else looked up, adds what it
|
|
@@ -67,22 +73,32 @@ async function repositoryAdvisories(github, asked, { repoOf, takes = () => true,
|
|
|
67
73
|
export async function withRepositories(rows, asked, { github, repoAdvisories, known }, { ecosystem, lookUp, covers }) {
|
|
68
74
|
if (!repoAdvisories) return rows
|
|
69
75
|
const reported = new Set(rows.flatMap((row) => [row.id, row.ghsa, ...row.aliases].filter(isGhsa).flatMap((id) => row.versions.map((version) => `${row.name} ${id} ${version}`))))
|
|
70
|
-
const
|
|
71
|
-
const repoOf = (name) => known.get(name) ?? found.get(name)
|
|
76
|
+
const repoOf = await reposOf(asked, known, lookUp)
|
|
72
77
|
const takes = (name, pkg) => pkg?.ecosystem === ecosystem && pkg.name === name
|
|
73
78
|
const added = await repositoryAdvisories(github, asked, { repoOf, takes, covers })
|
|
74
79
|
return [...rows, ...added.map((row) => ({ ...row, versions: row.versions.filter((version) => !reported.has(`${row.name} ${row.id} ${version}`)) }))]
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
// stasis versions a repository with no version of its own by its branch,
|
|
78
|
-
// or 0.0.0: every range covers those.
|
|
79
|
-
|
|
80
|
-
const coversPlaceholder = (version, range) => version === '0.0.0' || valid(version) === null || inRange(version, range)
|
|
83
|
+
// or 0.0.0: every range covers those.
|
|
84
|
+
const coversPlaceholder = (version, range) => version === '0.0.0' || mayBeInRange(version, range)
|
|
81
85
|
|
|
82
86
|
// Dependencies that are GitHub repositories themselves: every range their
|
|
83
87
|
// own published advisories list counts, whichever package it names.
|
|
84
88
|
export const GITHUB = {
|
|
89
|
+
repositoryOnly: true,
|
|
85
90
|
assertName: assertRepo,
|
|
86
91
|
assertVersion: assertion('a version or a branch name', isRefName),
|
|
87
92
|
advisories: (asked, { github }) => repositoryAdvisories(github, asked, { repoOf: (repo) => repo, covers: coversPlaceholder }),
|
|
88
93
|
}
|
|
94
|
+
|
|
95
|
+
// Soldeer packages, which no advisory database has: the repository each
|
|
96
|
+
// is published from, as given or else as Soldeer's project names it, is
|
|
97
|
+
// their only source, and every range its advisories list counts, whichever
|
|
98
|
+
// package it names (often the npm package the same release went out as).
|
|
99
|
+
export const SOLDEER = {
|
|
100
|
+
repositoryOnly: true,
|
|
101
|
+
assertName: assertSoldeerName,
|
|
102
|
+
assertVersion: assertSoldeerVersion,
|
|
103
|
+
advisories: async (asked, { github, known }) => await repositoryAdvisories(github, asked, { repoOf: await reposOf(asked, known, soldeerRepos) }),
|
|
104
|
+
}
|
package/src/advisories/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
|
|
3
|
-
import { assertArgs, assertBoolean, assertRepo, assertion, optional, sameName } from '../args.js'
|
|
3
|
+
import { assertArgs, assertBoolean, assertRepo, assertion, isIterable, optional, sameName } from '../args.js'
|
|
4
4
|
import { order } from './common.js'
|
|
5
|
-
import { GITHUB, assertClient } from './github.js'
|
|
5
|
+
import { GITHUB, SOLDEER, assertClient } from './github.js'
|
|
6
6
|
import { NPM } from './npm.js'
|
|
7
7
|
import { CARGO, COMPOSER } from './osv.js'
|
|
8
8
|
|
|
9
|
-
const ECOSYSTEMS = { npm: NPM, cargo: CARGO, composer: COMPOSER, github: GITHUB }
|
|
9
|
+
const ECOSYSTEMS = { npm: NPM, cargo: CARGO, composer: COMPOSER, soldeer: SOLDEER, github: GITHUB }
|
|
10
10
|
const byNumbers = new Intl.Collator('en', { numeric: true }).compare
|
|
11
11
|
const assertEcosystem = assertion(`one of ${Object.keys(ECOSYSTEMS).join(', ')}`, (value) => typeof value === 'string' && Object.hasOwn(ECOSYSTEMS, value))
|
|
12
12
|
const assertVersions = assertion('a non-empty array', (value) => Array.isArray(value) && value.length > 0)
|
|
@@ -14,7 +14,7 @@ const assertVersions = assertion('a non-empty array', (value) => Array.isArray(v
|
|
|
14
14
|
// Ecosystem → name → { versions, github? }, a name given twice merged.
|
|
15
15
|
// Every package is checked before any is used.
|
|
16
16
|
function collect(packages) {
|
|
17
|
-
assert.ok(
|
|
17
|
+
assert.ok(isIterable(packages), 'advisories: packages must be an iterable of { ecosystem, name, github?, versions }')
|
|
18
18
|
const byEcosystem = new Map()
|
|
19
19
|
for (const pkg of packages) {
|
|
20
20
|
assertArgs('advisories', pkg, { ecosystem: assertEcosystem, name: null, github: optional(assertRepo), versions: assertVersions }, 'package')
|
|
@@ -37,7 +37,7 @@ export async function advisories(packages, options = {}) {
|
|
|
37
37
|
assertArgs('advisories', options, { github: optional(assertClient), repoAdvisories: optional(assertBoolean) })
|
|
38
38
|
assert.ok(!options.repoAdvisories || options.github, 'advisories: repoAdvisories needs a github client')
|
|
39
39
|
const byEcosystem = collect(packages)
|
|
40
|
-
assert.ok(!
|
|
40
|
+
for (const ecosystem of byEcosystem.keys()) assert.ok(!ECOSYSTEMS[ecosystem].repositoryOnly || options.github, `advisories: ${ecosystem} packages need a github client`)
|
|
41
41
|
const found = await Promise.all([...byEcosystem].map(async ([ecosystem, named]) => {
|
|
42
42
|
const { compare = byNumbers, advisories: find } = ECOSYSTEMS[ecosystem]
|
|
43
43
|
const names = [...named.keys()].toSorted()
|