@preventive/upstream 1.12.0 → 1.13.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.
Files changed (52) hide show
  1. package/advisories.d.ts +125 -89
  2. package/cargo.d.ts +59 -35
  3. package/cocoapods.d.ts +44 -57
  4. package/electron.d.ts +35 -25
  5. package/git.d.ts +25 -16
  6. package/github/write.d.ts +60 -29
  7. package/github.d.ts +207 -193
  8. package/npm.d.ts +150 -87
  9. package/package.d.ts +30 -16
  10. package/package.json +1 -1
  11. package/rubygems.d.ts +22 -9
  12. package/semver.d.ts +40 -19
  13. package/soldeer.d.ts +21 -12
  14. package/src/advisories/actions.js +13 -38
  15. package/src/advisories/common.js +29 -1
  16. package/src/advisories/github.js +5 -19
  17. package/src/advisories/index.js +3 -10
  18. package/src/advisories/npm.js +4 -19
  19. package/src/advisories/osv.js +19 -41
  20. package/src/advisories/packagist.js +1 -4
  21. package/src/advisories/patched.js +6 -18
  22. package/src/advisories/repos.js +8 -13
  23. package/src/advisories/rubysec.js +2 -7
  24. package/src/args.js +5 -10
  25. package/src/attributes.js +3 -4
  26. package/src/cache.js +9 -22
  27. package/src/cargo/crate.js +4 -7
  28. package/src/cargo/repos.js +1 -7
  29. package/src/cocoapods.js +3 -19
  30. package/src/download.js +4 -12
  31. package/src/electron.js +6 -8
  32. package/src/github/commit.js +1 -13
  33. package/src/github/read.js +19 -68
  34. package/src/github/write.js +0 -1
  35. package/src/http.js +2 -7
  36. package/src/lockfiles.js +3 -11
  37. package/src/npm/cacache.js +3 -8
  38. package/src/npm/registry.js +10 -4
  39. package/src/npm/repos.js +3 -15
  40. package/src/npm/tarball.js +5 -20
  41. package/src/npm/versions.js +7 -21
  42. package/src/package.js +1 -7
  43. package/src/pool.js +0 -1
  44. package/src/pypi/version.js +1 -5
  45. package/src/remote.js +4 -6
  46. package/src/rubygems/gem.js +2 -2
  47. package/src/rubygems/version.js +2 -10
  48. package/src/semver.js +3 -9
  49. package/src/soldeer.js +0 -4
  50. package/src/tree.js +14 -44
  51. package/src/weak-edges.js +0 -2
  52. package/weak-edges.d.ts +36 -24
package/github/write.d.ts CHANGED
@@ -1,41 +1,72 @@
1
- // Arguments are checked as github.d.ts describes.
1
+ /**
2
+ * A GitHub client that also writes: forks, branches, signed commits and pull requests
3
+ *
4
+ * ```js
5
+ * import { createWriteClient } from '@preventive/upstream/github/write.js'
6
+ * ```
7
+ *
8
+ * Arguments are checked as `@preventive/upstream/github.js` checks them.
9
+ *
10
+ * @module @preventive/upstream/github/write.js
11
+ */
2
12
 
3
- import type { Client, RepoName } from '../github.js'
13
+ import type { Client, RepoName } from '../github.js';
4
14
 
5
- export { HttpError } from '../github.js'
15
+ export { HttpError } from '../github.js';
6
16
 
17
+ /** How `createWriteClient()` authenticates */
7
18
  export interface WriteClientOptions {
8
- // Never anonymous.
9
- token: string
10
- userAgent?: string
19
+ /** Never anonymous */
20
+ token: string;
21
+ /** Default: `'@preventive/upstream'` */
22
+ userAgent?: string;
11
23
  }
12
24
 
13
- export type CommitMessage = string | { headline: string; body?: string }
25
+ /** A commit's headline alone, or a headline and a body */
26
+ export type CommitMessage = string | { headline: string; body?: string };
14
27
 
28
+ /** A `Client` that also writes, as `createWriteClient()` makes it */
15
29
  export interface WriteClient extends Client {
16
- // Into the authenticated user's account, or the given organization.
17
- // Answers GitHub's repo object; `full_name` names the fork.
18
- forkRepo(options: { repo: RepoName; name?: string; organization?: string; defaultBranchOnly?: boolean }): Promise<any>
19
- // At the full commit `oid`, or at the head of the default branch
20
- // without one.
21
- createBranch(options: { repo: RepoName; branch: string; oid?: string }): Promise<any>
22
- // A signed commit on an existing branch, through GraphQL
23
- // createCommitOnBranch. `expectedHeadOid` defaults to the branch head.
30
+ /** Fork `repo` into the token's user's account, or `organization`: GitHub's repo object, `full_name` the fork's */
31
+ forkRepo(options: {
32
+ repo: RepoName;
33
+ name?: string;
34
+ organization?: string;
35
+ defaultBranchOnly?: boolean;
36
+ }): Promise<any>;
37
+ /** Make `branch` at the full commit `oid`, or at the head of the default branch */
38
+ createBranch(options: { repo: RepoName; branch: string; oid?: string }): Promise<any>;
39
+ /**
40
+ * A signed commit on an existing branch, through GraphQL's `createCommitOnBranch`
41
+ *
42
+ * `expectedHeadOid` defaults to the branch's head.
43
+ */
24
44
  createCommit(options: {
25
- repo: RepoName
26
- branch: string
27
- message: CommitMessage
28
- additions?: { path: string; contents: string | Uint8Array }[]
29
- deletions?: (string | { path: string })[]
30
- expectedHeadOid?: string
31
- }): Promise<{ oid: string; url: string }>
32
- // `head` is `owner:branch` for a pull request from a fork.
33
- createPR(options: { repo: RepoName; title: string; head: string; base: string; body?: string; draft?: boolean }): Promise<any>
45
+ repo: RepoName;
46
+ branch: string;
47
+ message: CommitMessage;
48
+ additions?: { path: string; contents: string | Uint8Array }[];
49
+ deletions?: (string | { path: string })[];
50
+ expectedHeadOid?: string;
51
+ }): Promise<{ oid: string; url: string }>;
52
+ /** Open a pull request; `head` is `owner:branch` for one from a fork */
53
+ createPR(options: {
54
+ repo: RepoName;
55
+ title: string;
56
+ head: string;
57
+ base: string;
58
+ body?: string;
59
+ draft?: boolean;
60
+ }): Promise<any>;
34
61
  }
35
62
 
36
- export function createWriteClient(options: WriteClientOptions): WriteClient
63
+ /** Make a client that reads and writes */
64
+ export function createWriteClient(options: WriteClientOptions): WriteClient;
37
65
 
38
- // A GraphQL response's `data`, or a throw carrying the status and body on
39
- // a transport error (an HttpError, as a REST failure is), malformed JSON
40
- // or an `errors` array.
41
- export function parseGraphQLResponse(status: number, text: string): any
66
+ /**
67
+ * A GraphQL response's `data`
68
+ *
69
+ * @throws An `HttpError` for a status other than 2xx, as a REST failure is, and an `Error` for malformed JSON or an
70
+ * `errors` array; the message carries what GitHub answered
71
+ */
72
+ export function parseGraphQLResponse(status: number, text: string): any;
package/github.d.ts CHANGED
@@ -1,44 +1,50 @@
1
- // Every method checks its arguments hard before any request is built: an
2
- // options object holding only the keys listed here, a repo that is
3
- // `owner/name` by GitHub's rules, branches and tags that git would take,
4
- // full commit shas and tree ids, paths with no empty, `.` or `..`
5
- // component, titles and headlines on one line. A bad one is a rejection
6
- // naming the method; nothing is sent. Every URL is built from checked,
7
- // encoded segments and has to come back out of URL parsing unchanged.
8
- // Redirects are refused, so an answer is about the repo asked for, except
9
- // the tarballs' and, where asked, getRepo's for a repo renamed or
10
- // transferred. A response is read up to a size limit (128 MiB of JSON, 128
11
- // MiB of a file, 512 MiB of a tarball) and within a timeout (30 seconds, 5
12
- // minutes for a tarball), and what it says goes into an error message
13
- // escaped.
1
+ /**
2
+ * A GitHub client that reads: repos, refs, files, trees and tarballs held to git's hashes, and advisories
3
+ *
4
+ * ```js
5
+ * import { createClient } from '@preventive/upstream/github.js'
6
+ * ```
7
+ *
8
+ * Every method checks its arguments before any request, and a bad one is a rejection naming the method: a repo is
9
+ * `owner/name` by GitHub's rules, a branch or tag one git would take, a sha a full one, a path one with no empty,
10
+ * `.`, `..` or `.git` part. Redirects are refused, so an answer is about the repo asked for, but for the tarballs'
11
+ * and, where asked, `getRepo()`'s. A response is read up to 128 MiB of JSON within 30 seconds, or 512 MiB of bytes
12
+ * within 5 minutes.
13
+ *
14
+ * @module @preventive/upstream/github.js
15
+ */
14
16
 
15
- // `owner/name`.
16
- export type RepoName = string
17
+ /** `owner/name` */
18
+ export type RepoName = string;
17
19
 
20
+ /** How `createClient()` authenticates */
18
21
  export interface ClientOptions {
19
- // `null` for an anonymous client, which reads public repositories
20
- // without anyone's credentials. Required either way.
21
- token: string | null
22
- userAgent?: string
22
+ /** `null` for an anonymous client, which reads public repositories alone; required either way */
23
+ token: string | null;
24
+ /** Default: `'@preventive/upstream'` */
25
+ userAgent?: string;
23
26
  }
24
27
 
25
- export type PullRequestStatus = 'open' | 'draft' | 'closed' | 'merged'
28
+ /** A pull request's state, a draft and a merged one told apart */
29
+ export type PullRequestStatus = 'open' | 'draft' | 'closed' | 'merged';
26
30
 
27
- // An entry of a directory, as git has it, `path` its name: a file
28
- // (`100644`, `100755` executable) or a symlink (`120000`) is a blob, a
29
- // directory (`040000`) a tree, a submodule (`160000`) the commit it is at.
31
+ /**
32
+ * An entry of a tree, as git has it: a file (`100644`, `100755` executable) or a symlink (`120000`) is a blob, a
33
+ * directory (`040000`) a tree, a submodule (`160000`) the commit it is at
34
+ */
30
35
  export interface RepoDirEntry {
31
- path: string
32
- mode: '100644' | '100755' | '120000' | '040000' | '160000'
33
- type: 'blob' | 'tree' | 'commit'
34
- sha: string
36
+ path: string;
37
+ mode: '100644' | '100755' | '120000' | '040000' | '160000';
38
+ type: 'blob' | 'tree' | 'commit';
39
+ /** Its object's id */
40
+ sha: string;
35
41
  }
36
42
 
37
- // A lockfile's format, by the tool that writes it, with the names it
38
- // writes one under and those of the project files it locks as
39
- // src/lockfiles.js lists them. Those @preventive/lockfile reads are as it
40
- // names the modules that do, yarn as yarn1.js, which reads Yarn 1's alone:
41
- // only the text tells a later Yarn's apart.
43
+ /**
44
+ * A lockfile's format, by the tool that writes it, as `@preventive/lockfile` names its module for it where it has one
45
+ *
46
+ * `yarn`'s is yarn1.js, which reads Yarn 1's alone: only the text tells a later Yarn's apart.
47
+ */
42
48
  export type LockfileFormat =
43
49
  | 'pnpm' | 'npm' | 'yarn' | 'bun' | 'deno'
44
50
  | 'uv' | 'poetry' | 'pylock' | 'pipenv' | 'pdm' | 'pixi' | 'conda-lock'
@@ -47,174 +53,182 @@ export type LockfileFormat =
47
53
  | 'go' | 'dep' | 'nuget' | 'paket' | 'gradle' | 'pub' | 'mix' | 'rebar' | 'julia'
48
54
  | 'stack' | 'cabal' | 'shards' | 'opam' | 'nix' | 'conan' | 'bazel' | 'helm' | 'renv' | 'terraform'
49
55
 
50
- // A file by a lockfile's name: `path` from the repo's root, as getRepoFile
51
- // takes it, and `sha` its blob's id.
56
+ /** A file by a lockfile's name */
52
57
  export interface RepoLockfile {
53
- path: string
54
- format: LockfileFormat
55
- sha: string
58
+ /** From the repo's root, as `getRepoFile()` takes it */
59
+ path: string;
60
+ format: LockfileFormat;
61
+ /** Its blob's id */
62
+ sha: string;
56
63
  }
57
64
 
58
- // A file by a project file's name, as RepoLockfile is, and the formats of
59
- // the lockfiles that may lock its project, in src/lockfiles.js' order:
60
- // whether one does, and where, is the tool's to say, a workspace's at its
61
- // root.
65
+ /** A file by a project file's name, and the formats of the lockfiles that may lock its project */
62
66
  export interface RepoProjectFile {
63
- path: string
64
- formats: LockfileFormat[]
65
- sha: string
67
+ /** From the repo's root, as `getRepoFile()` takes it */
68
+ path: string;
69
+ /** In `LockfileFormat`'s order: whether one does, and where, is the tool's to say, a workspace's at its root */
70
+ formats: LockfileFormat[];
71
+ /** Its blob's id */
72
+ sha: string;
66
73
  }
67
74
 
68
- // A failed request: `status` is the HTTP status GitHub answered with, and
69
- // `headers` its response's (a redirect's `location` among them), on every
70
- // call but a GraphQL one (github/write.js).
71
- export class HttpError extends Error {
72
- name: 'HttpError'
73
- status: number
74
- headers?: Headers
75
+ /** A client that reads only, as `createClient()` makes it */
76
+ export interface Client {
77
+ /**
78
+ * How `head` stands to `base` (each a full commit sha, or a branch or tag name), as GitHub's compare tells it
79
+ *
80
+ * `ahead` where `base` is in `head`'s history, `behind` the other way round, `identical`, or `diverged`; with the
81
+ * commits each has that the other hasn't, and their merge base. GitHub answers for a commit of any fork of the
82
+ * repo too, through the repo's own name: whether one is the repo's own is whether a ref of the repo (its default
83
+ * branch, say) is ahead of it or the same.
84
+ */
85
+ compareCommits(options: { repo: RepoName; base: string; head: string }): Promise<{
86
+ status: 'ahead' | 'behind' | 'identical' | 'diverged';
87
+ aheadBy: number;
88
+ behindBy: number;
89
+ mergeBase: string;
90
+ }>;
91
+ /**
92
+ * Every file by a lockfile's name, and every project file of a tool that writes one, in the full commit `sha`, or
93
+ * under its `directory`, each list sorted by path
94
+ *
95
+ * Also a project file no name tells, by a lockfile beside it named after it: a Python script `uv lock --script`
96
+ * locked, or a Stack or Cabal project file of another name. Read from GitHub's listings, each hashed back to its
97
+ * tree's id, so none is left out or changed. Not looked in: a submodule, or a `node_modules`. A symlink is no
98
+ * file. Refused where a path found is one `getRepoFile()` does not take.
99
+ */
100
+ findRepoLockfiles(options: {
101
+ repo: RepoName;
102
+ sha: string;
103
+ directory?: string;
104
+ }): Promise<{ lockfiles: RepoLockfile[]; projects: RepoProjectFile[] }>;
105
+ /**
106
+ * An advisory by its GHSA id, refused unless it is that one, and published
107
+ *
108
+ * With `repo`, that repository's copy: the maintainer's latest text, there before GitHub reviews it, shaped as a
109
+ * repository advisory (`state`, `patched_versions`, no `type`). Without `repo`, or where the repository is gone,
110
+ * renamed or blocked (301, 404, 410, 451), GitHub's global database's, which has it only once reviewed.
111
+ */
112
+ getAdvisory(options: { ghsa: string; repo?: RepoName }): Promise<{ ghsa_id: string } & Record<string, any>>;
113
+ /**
114
+ * GitHub's `{ permission, role_name, user }` for `username` on `repo`, team, organization and enterprise grants
115
+ * included
116
+ */
117
+ getCollaboratorPermission(options: {
118
+ repo: RepoName;
119
+ username: string;
120
+ }): Promise<{ permission: string; role_name?: string; user: { login: string; id: number } } & Record<string, any>>;
121
+ /** GitHub's `GET /user`: the token's user */
122
+ getCurrentUser(): Promise<any>;
123
+ /** A pull request's title and status, refused unless GitHub answers with that pull request in that repo */
124
+ getPullRequest(options: { repo: RepoName; number: number }): Promise<{ title: string; status: PullRequestStatus }>;
125
+ /**
126
+ * GitHub's repository object, refused unless it is the repo asked for
127
+ *
128
+ * With `followRedirect`, a repository renamed or transferred is asked for once more, by its id: the repository as
129
+ * it is now, whose `full_name` is the name to ask its other calls with. A redirect not followed is an `HttpError`
130
+ * with its status.
131
+ */
132
+ getRepo(options: { repo: RepoName; followRedirect?: boolean }): Promise<any>;
133
+ /**
134
+ * A file's text at `ref`, or on the default branch, held to the blob GitHub names for it
135
+ *
136
+ * Refused for a directory, a symlink or a submodule, and for anything but UTF-8.
137
+ */
138
+ getRepoFile(options: { repo: RepoName; path: string; ref?: string }): Promise<string>;
139
+ /** The commit at the head of `branch`, or of the default branch */
140
+ getRepoHead(options: { repo: RepoName; branch?: string }): Promise<{ branch: string; oid: string }>;
141
+ /**
142
+ * The commit `tag` names, an annotated tag followed through up to 8 tags of tags
143
+ *
144
+ * Refused for a tag of anything but a commit.
145
+ */
146
+ getRepoTag(options: { repo: RepoName; tag: string }): Promise<{ tag: string; oid: string }>;
147
+ /**
148
+ * The tree of the full commit `sha` (a sha1), read off the commit's own object, hashed back to `sha`
149
+ *
150
+ * So the tree is the commit's, whatever GitHub's API, which the other methods read it from, says. The commit alone
151
+ * is fetched as git fetches it, the client's token sent as git sends one. A repository renamed or transferred is
152
+ * an `HttpError` with the redirect's status, for `getRepo()` to follow.
153
+ */
154
+ getCommitTree(options: { repo: RepoName; sha: string }): Promise<string>;
155
+ /**
156
+ * The repo's gzipped tarball at the full commit `sha`: `getRepoTreeTarball()`'s, of the tree GitHub names for it
157
+ *
158
+ * GitHub is asked for the commit's tree on every call, tarball cached or not. The tarball's top directory is named
159
+ * for the tree, and files marked `export-subst` are as committed.
160
+ */
161
+ getRepoTarball(options: { repo: RepoName; sha: string; symlinksAbove?: number }): Promise<Uint8Array>;
162
+ /**
163
+ * The id of the tree at `directory` in the full commit `sha`, or of its root, down GitHub's listings, each hashed
164
+ * back to its id
165
+ *
166
+ * Refused where `directory` is none.
167
+ */
168
+ getRepoTreeId(options: { repo: RepoName; sha: string; directory?: string }): Promise<string>;
169
+ /**
170
+ * GitHub's gzipped tarball of a tree, the repo's or a subdirectory's, by its id, held to it
171
+ *
172
+ * Its files are hashed back into git's tree, which must come out `tree`, whether downloaded or read from
173
+ * `setCacheDir()`'s cache (npm.js), where it is kept by the id for good. The bytes are the tree as a checkout with
174
+ * no `core.autocrlf` writes it: a submodule an empty directory, a file marked `eol=crlf` with CRLF. Refused where
175
+ * that cannot be held to the tree, as for files marked `export-ignore`, `.gitattributes` rules not read here, or a
176
+ * repo set to put Git LFS objects in archives; and for anything `@preventive/archive` refuses in a tarball.
177
+ * `symlinksAbove` lets a symlink climb that many levels above the tarball's root (default: 0): a subdirectory's,
178
+ * its links reaching the repo's root as a monorepo package's LICENSE does, needs as many as it is deep, less one.
179
+ */
180
+ getRepoTreeTarball(options: { repo: RepoName; tree: string; symlinksAbove?: number }): Promise<Uint8Array>;
181
+ /**
182
+ * The repository's published security advisories, as GitHub's repository advisory objects
183
+ *
184
+ * More than 100 pages of 100 is an error.
185
+ */
186
+ listRepoAdvisories(options: { repo: RepoName }): Promise<any[]>;
187
+ /**
188
+ * The entries of `directory` in the full commit `sha`, or of its root, `path` each one's name: GitHub's listing,
189
+ * hashed back to the tree's id, so none is left out or changed
190
+ */
191
+ listRepoDir(options: { repo: RepoName; sha: string; directory?: string }): Promise<RepoDirEntry[]>;
192
+ /**
193
+ * Every entry of the full commit `sha`'s tree, `path` the one from its root, hashed back to the trees' ids, so none
194
+ * is left out, changed or added
195
+ *
196
+ * Where GitHub cuts its listing short (past 100,000 entries or 7 MB), each tree is listed in turn: with `paths`,
197
+ * only the trees those paths are in. Past `maxTrees` trees (default: 500) the rest are left out, and `cut` is true.
198
+ */
199
+ listRepoTree(options: {
200
+ repo: RepoName;
201
+ sha: string;
202
+ paths?: string[];
203
+ maxTrees?: number;
204
+ }): Promise<{ entries: RepoDirEntry[]; cut: boolean }>;
205
+ /**
206
+ * Every branch, with the commit at its head
207
+ *
208
+ * More than `maxPages` (default: 100) pages of 100 is an error.
209
+ */
210
+ listRepoBranches(options: { repo: RepoName; maxPages?: number }): Promise<{ branch: string; oid: string }[]>;
211
+ /**
212
+ * Every tag, with the commit GitHub names for it, an annotated tag's included
213
+ *
214
+ * More than `maxPages` (default: 100) pages of 100 is an error.
215
+ */
216
+ listRepoTags(options: { repo: RepoName; maxPages?: number }): Promise<{ tag: string; oid: string }[]>;
217
+ /**
218
+ * Every page of `GET /user/repos`, as GitHub's repository objects
219
+ *
220
+ * More than `maxPages` (default: 100) pages of 100 is an error.
221
+ */
222
+ listUserRepos(options?: { maxPages?: number }): Promise<any[]>;
75
223
  }
76
224
 
77
- // Reads only.
78
- export interface Client {
79
- // Every file by a lockfile's name, and every project file of a tool that
80
- // writes one, in the full commit `sha`, or under its `directory`, found as
81
- // getRepoTreeId finds it, each list sorted by path; and a project file no
82
- // name tells, by a lockfile beside it named after it: a Python script
83
- // `uv lock --script` locked, or a Stack or Cabal project file of another
84
- // name than stack.yaml or cabal.project. From one listing of the tree
85
- // with every tree under it, each hashed back to its id, so none is left
86
- // out or changed; where GitHub cuts that short, as it does past 100,000
87
- // entries, from the tree's own listing and then each subtree's in turn.
88
- // Not looked in: a submodule, which is another repo's commit, or a
89
- // `node_modules`, of packages installed. A symlink is no file. Refused
90
- // where a path found is one getRepoFile does not take, such as one with a
91
- // control character in it.
92
- // How `head` stands to `base` in the repo (each a full commit sha, or a
93
- // branch or tag name), as GitHub's compare tells it: `ahead` where `base`
94
- // is in `head`'s history, `behind` the other way round, `identical`, or
95
- // `diverged`; with the commits each has that the other hasn't, and their
96
- // merge base. Refused unless the status agrees with those counts, the
97
- // merge base is `base` where `head` is ahead of it or the same, and the
98
- // base GitHub compared is `base` where that is a commit. GitHub answers
99
- // for a commit of any fork of the repo too, through the repo's own name:
100
- // whether one is the repo's own is whether a ref of the repo (its default
101
- // branch, say) is ahead of it or the same.
102
- compareCommits(options: { repo: RepoName; base: string; head: string }): Promise<{ status: 'ahead' | 'behind' | 'identical' | 'diverged'; aheadBy: number; behindBy: number; mergeBase: string }>
103
- findRepoLockfiles(options: { repo: RepoName; sha: string; directory?: string }): Promise<{ lockfiles: RepoLockfile[]; projects: RepoProjectFile[] }>
104
- // An advisory by its GHSA id. With `repo`, that repository's published
105
- // copy: the maintainer's latest text, there before GitHub reviews it,
106
- // and shaped as a repository advisory (`state`, `patched_versions`, no
107
- // `type`). Without `repo`, or with a repository gone, renamed or blocked
108
- // (301, 404, 410, 451), GitHub's global database, which has it only once
109
- // reviewed; any other failure throws. Refused unless it is the one asked
110
- // for, and published.
111
- getAdvisory(options: { ghsa: string; repo?: RepoName }): Promise<{ ghsa_id: string } & Record<string, any>>
112
- // GitHub's `{ permission, role_name, user }` for `username` on `repo`,
113
- // teams, organization and enterprise grants included.
114
- getCollaboratorPermission(options: { repo: RepoName; username: string }): Promise<{ permission: string; role_name?: string; user: { login: string; id: number } } & Record<string, any>>
115
- getCurrentUser(): Promise<any>
116
- // Refused unless GitHub answers with that pull request in that repo.
117
- getPullRequest(options: { repo: RepoName; number: number }): Promise<{ title: string; status: PullRequestStatus }>
118
- // GitHub's repository object, refused unless it is the repo asked for.
119
- // With `followRedirect`, a repository renamed or transferred, which GitHub
120
- // answers with a redirect to it by its id
121
- // (`https://api.github.com/repositories/<id>`), is asked for there, with
122
- // the same token, once: the repository as it is now, refused unless it
123
- // has that id and a `full_name` that is `owner/name`, the name to ask its
124
- // other calls with. A redirect anywhere else, or a second, is refused as
125
- // without it: an HttpError with the redirect's status.
126
- getRepo(options: { repo: RepoName; followRedirect?: boolean }): Promise<any>
127
- // A file's contents as text, at `ref` or the default branch. Refused for
128
- // a directory, a symlink or a submodule, unless the bytes hash to the
129
- // blob GitHub names for the path, and unless valid UTF-8.
130
- getRepoFile(options: { repo: RepoName; path: string; ref?: string }): Promise<string>
131
- // The head of `branch`, or of the default branch without one.
132
- getRepoHead(options: { repo: RepoName; branch?: string }): Promise<{ branch: string; oid: string }>
133
- // The commit `tag` names: GitHub's ref for exactly that tag, an annotated
134
- // one's tag object followed to the commit, through up to 8 tags of tags.
135
- // Refused for a tag on anything but a commit.
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>
150
- // The repo's gzipped tarball at the full commit `sha`, whole, in memory:
151
- // getRepoTreeTarball's for the tree GitHub names for that commit, asked
152
- // on every call, cached or not. So its top directory is named for the
153
- // tree, and files marked `export-subst` are as committed, not rewritten.
154
- getRepoTarball(options: { repo: RepoName; sha: string; symlinksAbove?: number }): Promise<Uint8Array>
155
- // The id of the tree at `directory`, `/`-separated as npm's is, in the
156
- // full commit `sha`, or of its root without one: from the tree GitHub
157
- // names for the commit, down GitHub's listings a directory at a time,
158
- // each hashed back to its id. Refused where `directory` is none.
159
- getRepoTreeId(options: { repo: RepoName; sha: string; directory?: string }): Promise<string>
160
- // The gzipped tarball of a tree, the repo's own or any subdirectory's, by
161
- // its id, whole, in memory: GitHub's, its files under one top directory.
162
- // Its files are hashed back into git's tree and the id must be `tree`,
163
- // whether downloaded or read from setCacheDir's cache (npm.js), where it
164
- // is kept by the id alone, for good; a cached copy that does not match
165
- // throws. A tarball shows a submodule as an empty directory, leaves out
166
- // a subtree with no file in it, and has a file marked `eol=crlf` with
167
- // CRLF where git has LF, as a checkout writes it: the submodule's commit,
168
- // the subtrees and the blobs come from GitHub's listings of the trees,
169
- // asked only then, cached or not, a CRLF file is taken only where the
170
- // tree's .gitattributes have git write it so, and the id must still come
171
- // out `tree`. The bytes are GitHub's: the tree as a checkout with no
172
- // `core.autocrlf` writes it, the same for every repo. So GitHub's tarball
173
- // is refused for a tree with files marked `export-ignore`, which it
174
- // leaves out, or `ident`, `filter` or `working-tree-encoding` beside
175
- // `eol=crlf`, or `eol=crlf` on a file git has with both CRLF and LF; for
176
- // one with .gitattributes rules src/attributes.js does not read; and from
177
- // a repo set to include Git LFS objects in archives, which replace the
178
- // pointers git has; that repo still gets a tree already cached, pointers
179
- // and all.
180
- // It is read as @preventive/archive reads a tarball, and refused for
181
- // anything it refuses: a pax record repeated, a name or a symlink that
182
- // climbs out of it, an absolute symlink. `symlinksAbove` lets a symlink
183
- // climb that many levels above the tarball's root, none unless given: a
184
- // subdirectory's, its links reaching the repo's root as a monorepo
185
- // package's LICENSE does, needs as many as it is deep, less one.
186
- getRepoTreeTarball(options: { repo: RepoName; tree: string; symlinksAbove?: number }): Promise<Uint8Array>
187
- // The repository's published security advisories, as GitHub's
188
- // repository advisory objects: every page of 100, each found by the
189
- // cursor in the one before's Link header. More than 100 pages is an
190
- // error.
191
- listRepoAdvisories(options: { repo: RepoName }): Promise<any[]>
192
- // The entries of `directory` in the full commit `sha`, or of its root,
193
- // found as getRepoTreeId finds it: GitHub's listing, hashed back to the
194
- // tree's id, so none is left out or changed.
195
- listRepoDir(options: { repo: RepoName; sha: string; directory?: string }): Promise<RepoDirEntry[]>
196
- // Every entry of the full commit `sha`'s tree, `path` the one from its
197
- // root: GitHub's listing of the tree with every tree under it, each of
198
- // those hashed back to its id, so none is left out, changed or added.
199
- // Where GitHub cuts that short, past 100,000 entries or 7 MB, its own
200
- // listing instead, then each tree's in it the same way, as GitHub
201
- // advises; with `paths`, only the trees those paths are in, so another
202
- // tree's entries may be left out. No more than `maxTrees` trees (500 by
203
- // default) are listed, six at once: past them, the rest are left out
204
- // too, and `cut` is true.
205
- listRepoTree(options: { repo: RepoName; sha: string; paths?: string[]; maxTrees?: number }): Promise<{ entries: RepoDirEntry[]; cut: boolean }>
206
- // Every page of the repo's branches, as GitHub lists them, each with the
207
- // commit at its head; more than `maxPages` (100 by default) pages of 100
208
- // is an error, as is a branch with no commit.
209
- listRepoBranches(options: { repo: RepoName; maxPages?: number }): Promise<{ branch: string; oid: string }[]>
210
- // Every page of the repo's tags, as GitHub lists them, each with the
211
- // commit GitHub names for it, an annotated tag's included, which
212
- // getRepoTag checks is one; more than `maxPages` (100 by default) pages
213
- // of 100 is an error, as is a tag with no commit.
214
- listRepoTags(options: { repo: RepoName; maxPages?: number }): Promise<{ tag: string; oid: string }[]>
215
- // Every page of `GET /user/repos`, as GitHub's repository objects; more
216
- // than `maxPages` (100 by default) pages of 100 is an error.
217
- listUserRepos(options?: { maxPages?: number }): Promise<any[]>
225
+ /** A failed request: `status` is the HTTP status GitHub answered with */
226
+ export class HttpError extends Error {
227
+ name: 'HttpError';
228
+ status: number;
229
+ /** The response's, a redirect's `location` among them; on every call but a GraphQL one (github/write.js) */
230
+ headers?: Headers;
218
231
  }
219
232
 
220
- export function createClient(options: ClientOptions): Client
233
+ /** Make a client that reads only */
234
+ export function createClient(options: ClientOptions): Client;