@preventive/upstream 1.0.0-alpha.0 → 1.0.0-alpha.10

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 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`, or for
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; not for `github` packages, which are their own.
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 `github`
29
- // packages, whose repository's published advisories are their only
30
- // source, and for `repoAdvisories`; by itself it asks nothing else.
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
@@ -35,6 +39,11 @@ export interface AdvisoryOptions {
35
39
  // the one npm's metadata, crates.io or Packagist names, looked up
36
40
  // through the cache. Needs `github`.
37
41
  repoAdvisories?: boolean
42
+ // Also returns each advisory's full text, as `details`. OSV's records
43
+ // and a repository's listing already carry it; npm's registry does not,
44
+ // and its rows take OSV's record of their GHSA, one more request each
45
+ // (no GitHub client needed).
46
+ details?: boolean
38
47
  }
39
48
 
40
49
  // One advisory on one package, with the versions asked about that it
@@ -43,18 +52,36 @@ export interface Advisory {
43
52
  ecosystem: Ecosystem
44
53
  name: string
45
54
  // `registry`: npm's, as `npm audit` has it, one row per vulnerable
46
- // range. `osv`: RustSec for cargo, OSV's Packagist records for composer.
55
+ // range. `osv`: OSV's records for cargo and composer, RustSec's, GitHub's
56
+ // and malicious packages' (MAL-…) among them; of the records naming each
57
+ // other as aliases, directly or through others, a version is reported
58
+ // under one only: RustSec's, else the GHSA, else the first by id. Each
59
+ // has the others' ids among its aliases.
47
60
  // `repository`: published on the package's repository, one row per
48
61
  // range, holding only the versions the others' answer does not report
49
- // under that GHSA.
62
+ // under that GHSA. The only source for `soldeer` and `github`, where
63
+ // every range counts, whichever package it names.
50
64
  source: 'registry' | 'osv' | 'repository'
51
- // A GHSA, RUSTSEC-…, DRUPAL-CORE-…, or npm:<id> for a registry row
52
- // without a GHSA.
65
+ // A GHSA, RUSTSEC-…, MAL-…, DRUPAL-CORE-… or another OSV id, or
66
+ // npm:<id> for a registry row without a GHSA.
53
67
  id: string
54
68
  // The id itself, or an OSV record's one GHSA alias.
55
69
  ghsa?: string
70
+ // GitHub's page for the GHSA, with it: a `repository` row's on its
71
+ // repository (https://github.com/owner/name/security/advisories/GHSA-…),
72
+ // which has it before GitHub reviews it into its advisory database; any
73
+ // other's in that database (https://github.com/advisories/GHSA-…). An
74
+ // `osv` row without one has osv.dev's page for its record
75
+ // (https://osv.dev/vulnerability/RUSTSEC-…). Built, never fetched: only
76
+ // a registry row without a GHSA (npm:<id>) has none.
77
+ url?: string
56
78
  aliases: string[]
57
79
  title?: string
80
+ // With `details`, the advisory's full text, Markdown as published: an
81
+ // OSV record's `details`, a repository advisory's `description`, or for
82
+ // a registry row, OSV's record of its GHSA. Absent where there is none:
83
+ // a registry row without a GHSA, or with one OSV does not have yet.
84
+ details?: string
58
85
  // `critical`, `high`, `moderate`, `low`; GitHub's `medium` reads
59
86
  // `moderate`. RustSec has none.
60
87
  severity?: string
@@ -75,8 +102,12 @@ export interface Advisory {
75
102
  // Every package, and every one of its versions, is checked against its
76
103
  // ecosystem's rules before the first request; a name given twice is
77
104
  // merged, and must not name two repositories. npm is asked 250 names a
78
- // request, OSV 1000 versions; a repository gone, renamed or blocked adds
79
- // nothing. Any other failure, a malformed answer, or one about something
80
- // not asked, throws: nothing is left out quietly. Sorted by ecosystem and
81
- // name. Versions are matched by npm's semver, from the npm beside node.
105
+ // request, OSV 1000 versions, Soldeer one project, and with `details`, OSV
106
+ // one GHSA among npm's rows; a project Soldeer does not have or that names
107
+ // no GitHub repository, and a repository gone, renamed or blocked, add
108
+ // nothing, and a GHSA OSV does not have adds no `details`. Any other
109
+ // failure, a malformed answer, or one about something not asked, throws:
110
+ // nothing is left out quietly.
111
+ // Sorted by ecosystem and name. Versions are matched by npm's semver, from
112
+ // the npm beside node, or by the semver peer where there is no npm.
82
113
  export function advisories(packages: Iterable<Package>, options?: AdvisoryOptions): Promise<Advisory[]>
package/cargo.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ // Hand-written against cargo.js; a change to either belongs with the other.
2
+ //
3
+ // A name is asserted to be a crate name, a version an exact semver
4
+ // version, and a checksum 64 lowercase hex digits, before any request or
5
+ // cache path. The cache is setCacheDir's (npm.js).
6
+
7
+ export { HttpError } from './npm.js'
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
+
14
+ // A published version's .crate, whole, in memory. `checksum` is its
15
+ // sha256 as Cargo.lock records it; without one, crates.io's index is read
16
+ // for it on every call, cached crate or not. Either way the bytes are
17
+ // checked against it, whether they were downloaded from static.crates.io
18
+ // (before they are cached) or read from a cache.
19
+ //
20
+ // Cargo's own cache is read first, and never written: each registry's
21
+ // `<name>-<version>.crate` under $CARGO_HOME/registry/cache, else under
22
+ // `~/.cargo`. A file there that does not match is passed over. One in
23
+ // setCacheDir's cache that does not match throws.
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 ADDED
@@ -0,0 +1,3 @@
1
+ export { getCrate, verifyChecksum } from './src/cargo/crate.js'
2
+ export { resolveCrateRepos } from './src/cargo/repos.js'
3
+ export { HttpError } from './src/http.js'
package/github.d.ts CHANGED
@@ -1,16 +1,17 @@
1
1
  // Hand-written against github.js; a change to either belongs with the other.
2
2
  //
3
- // Every method checks its arguments hard before any request is built:
4
- // an options object holding only the keys listed here, a repo that is
3
+ // Every method checks its arguments hard before any request is built: an
4
+ // options object holding only the keys listed here, a repo that is
5
5
  // `owner/name` by GitHub's rules, branches and tags that git would take,
6
- // full commit shas, paths with no empty, `.` or `..` component, titles
7
- // and headlines on one line. A bad one is a rejection naming the method;
8
- // nothing is sent. Every URL is built from checked, encoded segments and
9
- // has to come back out of URL parsing unchanged. Redirects are refused,
10
- // except the tarball's, so an answer is about the repo asked for. A
11
- // response is read up to a size limit (64 MiB of JSON, 128 MiB of a file,
12
- // 512 MiB of a tarball) and within a timeout (30 seconds, 5 minutes for a
13
- // tarball), and what it says goes into an error message escaped.
6
+ // full commit shas and tree ids, paths with no empty, `.` or `..`
7
+ // component, titles and headlines on one line. A bad one is a rejection
8
+ // naming the method; nothing is sent. Every URL is built from checked,
9
+ // encoded segments and has to come back out of URL parsing unchanged.
10
+ // Redirects are refused, except the tarballs', so an answer is about the
11
+ // repo asked for. A response is read up to a size limit (64 MiB of JSON,
12
+ // 128 MiB of a file, 512 MiB of a tarball) and within a timeout (30
13
+ // seconds, 5 minutes for a tarball), and what it says goes into an error
14
+ // message escaped.
14
15
 
15
16
  // `owner/name`.
16
17
  export type RepoName = string
@@ -24,6 +25,16 @@ export interface ClientOptions {
24
25
 
25
26
  export type PullRequestStatus = 'open' | 'draft' | 'closed' | 'merged'
26
27
 
28
+ // An entry of a directory, as git has it, `path` its name: a file
29
+ // (`100644`, `100755` executable) or a symlink (`120000`) is a blob, a
30
+ // directory (`040000`) a tree, a submodule (`160000`) the commit it is at.
31
+ export interface RepoDirEntry {
32
+ path: string
33
+ mode: '100644' | '100755' | '120000' | '040000' | '160000'
34
+ type: 'blob' | 'tree' | 'commit'
35
+ sha: string
36
+ }
37
+
27
38
  // A failed request: `status` is the HTTP status GitHub answered with.
28
39
  export class HttpError extends Error {
29
40
  name: 'HttpError'
@@ -54,12 +65,55 @@ export interface Client {
54
65
  getRepoFile(options: { repo: RepoName; path: string; ref?: string }): Promise<string>
55
66
  // The head of `branch`, or of the default branch without one.
56
67
  getRepoHead(options: { repo: RepoName; branch?: string }): Promise<{ branch: string; oid: string }>
57
- // The repo's gzipped tarball at the full commit `sha`, whole, in memory.
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 }>
72
+ // The repo's gzipped tarball at the full commit `sha`, whole, in memory:
73
+ // getRepoTreeTarball's for the tree GitHub names for that commit, asked
74
+ // on every call, cached or not. So its top directory is named for the
75
+ // tree, and files marked `export-subst` are as committed, not rewritten.
58
76
  getRepoTarball(options: { repo: RepoName; sha: string }): Promise<Uint8Array>
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>
82
+ // The gzipped tarball of a tree, the repo's own or any subdirectory's, by
83
+ // its id, whole, in memory: GitHub's, its files under one top directory.
84
+ // Its files are hashed back into git's tree and the id must be `tree`,
85
+ // whether downloaded or read from setCacheDir's cache (npm.js), where it
86
+ // is kept by the id alone, for good; a cached copy that does not match
87
+ // throws. A tarball shows a submodule as an empty directory, leaves out
88
+ // a subtree with no file in it, and has a file marked `eol=crlf` with
89
+ // CRLF where git has LF, as a checkout writes it: the submodule's commit,
90
+ // the subtrees and the blobs come from GitHub's listings of the trees,
91
+ // asked only then, cached or not, a CRLF file is taken only where the
92
+ // tree's .gitattributes have git write it so, and the id must still come
93
+ // out `tree`. The bytes are GitHub's: the tree as a checkout with no
94
+ // `core.autocrlf` writes it, the same for every repo. So GitHub's tarball
95
+ // is refused for a tree with files marked `export-ignore`, which it
96
+ // leaves out, or `ident`, `filter` or `working-tree-encoding` beside
97
+ // `eol=crlf`, or `eol=crlf` on a file git has with both CRLF and LF; for
98
+ // one with .gitattributes rules src/attributes.js does not read; and from
99
+ // a repo set to include Git LFS objects in archives, which replace the
100
+ // pointers git has; that repo still gets a tree already cached, pointers
101
+ // and all.
102
+ getRepoTreeTarball(options: { repo: RepoName; tree: string }): Promise<Uint8Array>
59
103
  // The repository's published security advisories, as GitHub's
60
- // repository advisory objects. One page of 100: GitHub pages this list
61
- // by cursor, so a repository with a full page is refused.
104
+ // repository advisory objects: every page of 100, each found by the
105
+ // cursor in the one before's Link header. More than 100 pages is an
106
+ // error.
62
107
  listRepoAdvisories(options: { repo: RepoName }): Promise<any[]>
108
+ // The entries of `directory` in the full commit `sha`, or of its root,
109
+ // found as getRepoTreeId finds it: GitHub's listing, hashed back to the
110
+ // tree's id, so none is left out or changed.
111
+ listRepoDir(options: { repo: RepoName; sha: string; directory?: string }): Promise<RepoDirEntry[]>
112
+ // Every page of the repo's tags, as GitHub lists them, each with the
113
+ // commit GitHub names for it, an annotated tag's included, which
114
+ // getRepoTag checks is one; more than `maxPages` (100 by default) pages
115
+ // of 100 is an error, as is a tag with no commit.
116
+ listRepoTags(options: { repo: RepoName; maxPages?: number }): Promise<{ tag: string; oid: string }[]>
63
117
  // Every page of `GET /user/repos`, as GitHub's repository objects; more
64
118
  // than `maxPages` (100 by default) pages of 100 is an error.
65
119
  listUserRepos(options?: { maxPages?: number }): Promise<any[]>
package/npm.d.ts CHANGED
@@ -6,16 +6,39 @@
6
6
  // cache path, otherwise. Responses are read up to a size limit and within
7
7
  // a timeout, as github.d.ts describes, and lookups for many names go to
8
8
  // the registry eight at a time.
9
+ //
10
+ // Where NPM_TOKEN is set, it is sent with the requests for a scoped
11
+ // package, so a private one can be read.
12
+
13
+ // Where a program called `name` keeps its cache for this user, as each
14
+ // platform has it, read from the environment when called. macOS:
15
+ // ~/Library/Caches/<name>. Windows: %LOCALAPPDATA%\<name>\Cache, the
16
+ // `Cache` apart from the program's other local data there. Elsewhere, the
17
+ // XDG Base Directory spec's: $XDG_CACHE_HOME/<name>, or ~/.cache/<name>
18
+ // where it is unset, empty or relative, which the spec has ignored.
19
+ // Undefined where no absolute directory is found to start from: a home
20
+ // directory that is relative, empty or unknown. Nothing is made. `name` is
21
+ // 6 to 32 of a-z, A-Z, 0-9, `_` and `-`, so one directory name the same on
22
+ // every platform.
23
+ export function cacheDirFor(name: string): string | undefined
24
+
25
+ // cacheDirFor('PreventiveMeasures'), read once, when this module is first
26
+ // imported: where setCacheDir() caches.
27
+ export const defaultCacheDir: string | undefined
9
28
 
10
- // Where cached answers live, resolved when set. Unset by default, and
11
- // unset means no cache: every read misses and every write is skipped.
29
+ // Where cached answers are written and read, resolved when set: `dir`, or
30
+ // defaultCacheDir where it is left out, which throws where there is none.
31
+ // Unset until this is called, and unset again by `false`, which means no
32
+ // cache: every read of it misses and every write is skipped. getTarball
33
+ // reads ours all the same, set or not.
12
34
  //
13
35
  // The directory is trusted: a package's repo is answered from it as it
14
36
  // was written, with no request. Point it only at storage that nothing
15
37
  // less trusted than the caller can write, never a cache shared with or
16
- // restored from lower-trust jobs. Tarballs don't rely on this, since they
17
- // are checked against the registry's integrity on every call.
18
- export function setCacheDir(dir: string): void
38
+ // restored from lower-trust jobs. Tarballs, crates (cargo.js), zips
39
+ // (soldeer.js) and tree tarballs (github.js) don't rely on this, since
40
+ // they are checked against their integrity on every call.
41
+ export function setCacheDir(dir?: string | false): void
19
42
 
20
43
  // A failed request: `status` is the HTTP status the registry answered
21
44
  // with (404 for a package or version it does not have).
@@ -46,8 +69,11 @@ export interface PackageRepo {
46
69
  export function resolvePackageRepos(packageNames: Iterable<string>, options?: { cachedOnly?: boolean }): Promise<Map<string, PackageRepo>>
47
70
 
48
71
  // The disk cache resolvePackageRepos reads and writes, a month per entry.
49
- // A read answers null for anything but a usable entry; a write answers
50
- // false where it could not write, and never throws.
72
+ // A read answers null for anything but a usable entry, one written by a
73
+ // release that resolved repos by other rules included; a write answers
74
+ // false where it could not write, and never throws. A write takes the
75
+ // `github` a lookup gives, `owner/name` with no trailing `.git`, so what
76
+ // it writes reads back.
51
77
  export function readPackageRepoCache(name: string): Promise<PackageRepo | null>
52
78
  export function writePackageRepoCache(name: string, github: string, directory?: string): Promise<boolean>
53
79
 
@@ -80,10 +106,11 @@ export function verifyDist(name: string, version: string, dist: Dist): Promise<v
80
106
  // for. Either way the bytes are checked against `dist.integrity`, whether
81
107
  // they were downloaded (before they are cached) or read from a cache.
82
108
  //
83
- // Other tools' caches are read first, and never written: npm's (cacache
84
- // under npm_config_cache, else npm's default, `~/.npm` outside Windows;
85
- // and npm 4's `<name>/<version>/package.tgz` there), then
86
- // `~/.audit/cache/tgz/<org>:<name>-<version>.tgz`. A file there that does
87
- // not match is passed over. One in setCacheDir's cache that does not
88
- // match throws.
109
+ // Other caches are read first, and never written: npm's (cacache under
110
+ // npm_config_cache, else npm's default, `~/.npm` outside Windows; and npm
111
+ // 4's `<name>/<version>/package.tgz` there), then
112
+ // `~/.audit/cache/tgz/<org>:<name>-<version>.tgz`, then defaultCacheDir
113
+ // and cacheDirFor('stasis'), as setCacheDir files a tarball in either,
114
+ // whether set or not. A file there that does not match is passed over.
115
+ // Then setCacheDir's cache, where one that does not match throws.
89
116
  export function getTarball(name: string, version: string, dist?: Dist): Promise<Uint8Array>
package/npm.js CHANGED
@@ -1,4 +1,4 @@
1
- export { setCacheDir } from './src/cache.js'
1
+ export { cacheDirFor, defaultCacheDir, setCacheDir } from './src/cache.js'
2
2
  export { HttpError } from './src/http.js'
3
3
  export { getGitHub, readPackageRepoCache, resolvePackageRepos, writePackageRepoCache } from './src/npm/repos.js'
4
4
  export { getMeta, getTarball, verifyDist } from './src/npm/tarball.js'
package/package.d.ts CHANGED
@@ -4,14 +4,14 @@ export interface PackageRepoLink {
4
4
  // `owner/name`, by GitHub's own rules.
5
5
  github?: string
6
6
  // Where in that repo the package sits, `/`-separated, as the tree path
7
- // itself (a homepage URL's decoded); absent at its root, and whenever
8
- // `github` is.
7
+ // itself (a homepage URL's decoded; a `repository.directory`'s `\` read
8
+ // as `/`); absent at its root, and whenever `github` is.
9
9
  directory?: string
10
10
  // `https://github.com/<github>`, whenever there is a `github`.
11
11
  url?: string
12
12
  }
13
13
 
14
- // Read off `bugs`, `repository` and `homepage`, in that order, from a
14
+ // Read off `repository`, `bugs` and `homepage`, in that order, from a
15
15
  // package.json or the registry's document for a version of one. Both
16
16
  // fields absent where nothing in it names a GitHub repo; a throw only
17
17
  // for something that is not an object at all.