repo-sdk 0.3.0 → 0.3.1

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 CHANGED
@@ -16,6 +16,11 @@ interface GitHubAppAuth {
16
16
  installationId?: string | number;
17
17
  /** Account (org or user) whose installation to act as; alternative to installationId. */
18
18
  owner?: string;
19
+ /**
20
+ * Restrict the minted installation token to these repository names within the
21
+ * installation's account. Omitted: every repository the installation can access.
22
+ */
23
+ repositories?: string[];
19
24
  }
20
25
  interface GitHubTokenProviderAuth {
21
26
  /** Mints a bearer token per request; re-invoked with `forceRefresh` after a 401, then retried once. */
package/dist/github.js CHANGED
@@ -124,6 +124,7 @@ var AppTokenSource = class {
124
124
  userAgent;
125
125
  installationId;
126
126
  owner;
127
+ repositories;
127
128
  cached;
128
129
  refresh;
129
130
  constructor(options) {
@@ -139,6 +140,7 @@ var AppTokenSource = class {
139
140
  this.userAgent = options.userAgent;
140
141
  this.installationId = options.installationId === void 0 ? void 0 : String(options.installationId);
141
142
  this.owner = options.owner;
143
+ this.repositories = options.repositories;
142
144
  }
143
145
  async getToken() {
144
146
  return (await this.resolveToken()).token;
@@ -174,7 +176,7 @@ var AppTokenSource = class {
174
176
  privateKey: this.privateKey
175
177
  });
176
178
  const installationId = await this.resolveInstallationId(jwt);
177
- const data = await this.appRequest(`/app/installations/${installationId}/access_tokens`, "POST", jwt);
179
+ const data = await this.appRequest(`/app/installations/${installationId}/access_tokens`, "POST", jwt, this.repositories === void 0 ? void 0 : { repositories: this.repositories });
178
180
  const token = {
179
181
  token: data.token,
180
182
  expiresAt: new Date(data.expires_at)
@@ -218,19 +220,22 @@ var AppTokenSource = class {
218
220
  });
219
221
  return String(installations[0].id);
220
222
  }
221
- async appRequest(path, method, jwt) {
223
+ async appRequest(path, method, jwt, body) {
222
224
  const url = joinUrl(this.baseUrl, path);
223
225
  const { fetchImpl } = this;
226
+ const headers = {
227
+ Authorization: `Bearer ${jwt}`,
228
+ Accept: "application/vnd.github+json",
229
+ "X-GitHub-Api-Version": this.apiVersion,
230
+ "User-Agent": this.userAgent
231
+ };
232
+ if (body !== void 0) headers["Content-Type"] = "application/json";
224
233
  let response;
225
234
  try {
226
235
  response = await fetchImpl(url, {
227
236
  method,
228
- headers: {
229
- Authorization: `Bearer ${jwt}`,
230
- Accept: "application/vnd.github+json",
231
- "X-GitHub-Api-Version": this.apiVersion,
232
- "User-Agent": this.userAgent
233
- }
237
+ headers,
238
+ body: body === void 0 ? void 0 : JSON.stringify(body)
234
239
  });
235
240
  } catch (error) {
236
241
  throw new RepoError(`Request to ${path} failed`, {
@@ -319,6 +324,7 @@ function createTokenSource(auth, baseUrl, fetchImpl) {
319
324
  privateKey: auth.privateKey,
320
325
  installationId: auth.installationId,
321
326
  owner: auth.owner,
327
+ repositories: auth.repositories,
322
328
  baseUrl,
323
329
  fetchImpl,
324
330
  apiVersion: API_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Unified TypeScript SDK for git providers — GitHub, GitLab, Bitbucket, Azure DevOps, Gitea",
5
5
  "license": "MIT",
6
6
  "author": "Robin Genz <mail@robingenz.dev>",