repo-sdk 0.3.2 → 0.3.3
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/dist/github.d.ts +6 -0
- package/dist/github.js +13 -1
- package/package.json +1 -1
package/dist/github.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ interface GitHubAppAuth {
|
|
|
21
21
|
* installation's account. Omitted: every repository the installation can access.
|
|
22
22
|
*/
|
|
23
23
|
repositories?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Restrict the minted installation token to these repository ids. Ids survive a
|
|
26
|
+
* repository rename, so prefer them over `repositories` when the repository is
|
|
27
|
+
* stored long-term. Mutually exclusive with `repositories`.
|
|
28
|
+
*/
|
|
29
|
+
repositoryIds?: Array<string | number>;
|
|
24
30
|
}
|
|
25
31
|
interface GitHubTokenProviderAuth {
|
|
26
32
|
/** Mints a bearer token per request; re-invoked with `forceRefresh` after a 401, then retried once. */
|
package/dist/github.js
CHANGED
|
@@ -125,6 +125,7 @@ var AppTokenSource = class {
|
|
|
125
125
|
installationId;
|
|
126
126
|
owner;
|
|
127
127
|
repositories;
|
|
128
|
+
repositoryIds;
|
|
128
129
|
cached;
|
|
129
130
|
refresh;
|
|
130
131
|
constructor(options) {
|
|
@@ -132,6 +133,10 @@ var AppTokenSource = class {
|
|
|
132
133
|
code: "validation",
|
|
133
134
|
provider: "github"
|
|
134
135
|
});
|
|
136
|
+
if (options.repositories !== void 0 && options.repositoryIds !== void 0) throw new RepoError("GitHub App auth accepts either repositories or repositoryIds, not both", {
|
|
137
|
+
code: "validation",
|
|
138
|
+
provider: "github"
|
|
139
|
+
});
|
|
135
140
|
this.appId = String(options.appId);
|
|
136
141
|
this.privateKey = options.privateKey;
|
|
137
142
|
this.baseUrl = options.baseUrl;
|
|
@@ -141,6 +146,7 @@ var AppTokenSource = class {
|
|
|
141
146
|
this.installationId = options.installationId === void 0 ? void 0 : String(options.installationId);
|
|
142
147
|
this.owner = options.owner;
|
|
143
148
|
this.repositories = options.repositories;
|
|
149
|
+
this.repositoryIds = options.repositoryIds?.map(Number);
|
|
144
150
|
}
|
|
145
151
|
async getToken() {
|
|
146
152
|
return (await this.resolveToken()).token;
|
|
@@ -176,7 +182,7 @@ var AppTokenSource = class {
|
|
|
176
182
|
privateKey: this.privateKey
|
|
177
183
|
});
|
|
178
184
|
const installationId = await this.resolveInstallationId(jwt);
|
|
179
|
-
const data = await this.appRequest(`/app/installations/${installationId}/access_tokens`, "POST", jwt, this.
|
|
185
|
+
const data = await this.appRequest(`/app/installations/${installationId}/access_tokens`, "POST", jwt, this.tokenScope());
|
|
180
186
|
const token = {
|
|
181
187
|
token: data.token,
|
|
182
188
|
expiresAt: new Date(data.expires_at)
|
|
@@ -184,6 +190,11 @@ var AppTokenSource = class {
|
|
|
184
190
|
this.cached = token;
|
|
185
191
|
return token;
|
|
186
192
|
}
|
|
193
|
+
/** Body of the access-token request; `undefined` mints an unrestricted token. */
|
|
194
|
+
tokenScope() {
|
|
195
|
+
if (this.repositoryIds !== void 0) return { repository_ids: this.repositoryIds };
|
|
196
|
+
if (this.repositories !== void 0) return { repositories: this.repositories };
|
|
197
|
+
}
|
|
187
198
|
async resolveInstallationId(jwt) {
|
|
188
199
|
if (this.installationId !== void 0) return this.installationId;
|
|
189
200
|
this.installationId = this.owner === void 0 ? await this.lookupSingleInstallation(jwt) : await this.lookupOwnerInstallation(jwt, this.owner);
|
|
@@ -325,6 +336,7 @@ function createTokenSource(auth, baseUrl, fetchImpl) {
|
|
|
325
336
|
installationId: auth.installationId,
|
|
326
337
|
owner: auth.owner,
|
|
327
338
|
repositories: auth.repositories,
|
|
339
|
+
repositoryIds: auth.repositoryIds,
|
|
328
340
|
baseUrl,
|
|
329
341
|
fetchImpl,
|
|
330
342
|
apiVersion: API_VERSION,
|
package/package.json
CHANGED