repo-sdk 0.3.2 → 0.3.4
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 +22 -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
|
@@ -3,6 +3,15 @@ import { a as isRecord, c as assertSameOriginUrl, d as bytesToBase64Url, i as fi
|
|
|
3
3
|
import { t as HttpClient } from "./http-DOXOhL_I.js";
|
|
4
4
|
import { a as headShaOrUndefined, i as verifyHmacSignature, r as toIncomingWebhook } from "./verify-BBMVxz8q.js";
|
|
5
5
|
//#region src/providers/github/app-auth.ts
|
|
6
|
+
/** GitHub repository ids are positive integers; anything else would only surface as an opaque 422. */
|
|
7
|
+
function toRepositoryId(value) {
|
|
8
|
+
const id = typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;
|
|
9
|
+
if (typeof id !== "number" || !Number.isSafeInteger(id) || id <= 0) throw new RepoError(`Invalid GitHub repository id: ${String(value)}`, {
|
|
10
|
+
code: "validation",
|
|
11
|
+
provider: "github"
|
|
12
|
+
});
|
|
13
|
+
return id;
|
|
14
|
+
}
|
|
6
15
|
const RSA_ALGORITHM_IDENTIFIER = [
|
|
7
16
|
48,
|
|
8
17
|
13,
|
|
@@ -125,6 +134,7 @@ var AppTokenSource = class {
|
|
|
125
134
|
installationId;
|
|
126
135
|
owner;
|
|
127
136
|
repositories;
|
|
137
|
+
repositoryIds;
|
|
128
138
|
cached;
|
|
129
139
|
refresh;
|
|
130
140
|
constructor(options) {
|
|
@@ -132,6 +142,10 @@ var AppTokenSource = class {
|
|
|
132
142
|
code: "validation",
|
|
133
143
|
provider: "github"
|
|
134
144
|
});
|
|
145
|
+
if (options.repositories !== void 0 && options.repositoryIds !== void 0) throw new RepoError("GitHub App auth accepts either repositories or repositoryIds, not both", {
|
|
146
|
+
code: "validation",
|
|
147
|
+
provider: "github"
|
|
148
|
+
});
|
|
135
149
|
this.appId = String(options.appId);
|
|
136
150
|
this.privateKey = options.privateKey;
|
|
137
151
|
this.baseUrl = options.baseUrl;
|
|
@@ -141,6 +155,7 @@ var AppTokenSource = class {
|
|
|
141
155
|
this.installationId = options.installationId === void 0 ? void 0 : String(options.installationId);
|
|
142
156
|
this.owner = options.owner;
|
|
143
157
|
this.repositories = options.repositories;
|
|
158
|
+
this.repositoryIds = options.repositoryIds?.map(toRepositoryId);
|
|
144
159
|
}
|
|
145
160
|
async getToken() {
|
|
146
161
|
return (await this.resolveToken()).token;
|
|
@@ -176,7 +191,7 @@ var AppTokenSource = class {
|
|
|
176
191
|
privateKey: this.privateKey
|
|
177
192
|
});
|
|
178
193
|
const installationId = await this.resolveInstallationId(jwt);
|
|
179
|
-
const data = await this.appRequest(`/app/installations/${installationId}/access_tokens`, "POST", jwt, this.
|
|
194
|
+
const data = await this.appRequest(`/app/installations/${installationId}/access_tokens`, "POST", jwt, this.tokenScope());
|
|
180
195
|
const token = {
|
|
181
196
|
token: data.token,
|
|
182
197
|
expiresAt: new Date(data.expires_at)
|
|
@@ -184,6 +199,11 @@ var AppTokenSource = class {
|
|
|
184
199
|
this.cached = token;
|
|
185
200
|
return token;
|
|
186
201
|
}
|
|
202
|
+
/** Body of the access-token request; `undefined` mints an unrestricted token. */
|
|
203
|
+
tokenScope() {
|
|
204
|
+
if (this.repositoryIds !== void 0) return { repository_ids: this.repositoryIds };
|
|
205
|
+
if (this.repositories !== void 0) return { repositories: this.repositories };
|
|
206
|
+
}
|
|
187
207
|
async resolveInstallationId(jwt) {
|
|
188
208
|
if (this.installationId !== void 0) return this.installationId;
|
|
189
209
|
this.installationId = this.owner === void 0 ? await this.lookupSingleInstallation(jwt) : await this.lookupOwnerInstallation(jwt, this.owner);
|
|
@@ -325,6 +345,7 @@ function createTokenSource(auth, baseUrl, fetchImpl) {
|
|
|
325
345
|
installationId: auth.installationId,
|
|
326
346
|
owner: auth.owner,
|
|
327
347
|
repositories: auth.repositories,
|
|
348
|
+
repositoryIds: auth.repositoryIds,
|
|
328
349
|
baseUrl,
|
|
329
350
|
fetchImpl,
|
|
330
351
|
apiVersion: API_VERSION,
|
package/package.json
CHANGED