repo-sdk 0.3.1 → 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/README.md CHANGED
@@ -148,7 +148,7 @@ It reports every capability enabled by default, and a second options argument si
148
148
 
149
149
  ## Errors
150
150
 
151
- Every failure is a `RepoError` with a closed `code` union: `unauthorized`, `forbidden`, `not_found`, `rate_limited`, `validation`, `unsupported`, `provider_error`, `network_error`.
151
+ Every failure is a `RepoError` with a closed `code` union: `unauthorized`, `forbidden`, `not_found`, `rate_limited`, `validation`, `unsupported`, `provider_error`, `invalid_response`, `network_error`.
152
152
 
153
153
  ```ts
154
154
  import { RepoError } from 'repo-sdk';
@@ -1,6 +1,6 @@
1
1
  import { t as RepoError } from "./errors-Cxq_CqYv.js";
2
2
  import { a as isRecord, i as filenameFromContentDisposition, l as decodeCursor, n as commitWebUrlBuilder, s as toCloneUrl, u as encodeCursor } from "./shared-C6m-C4My.js";
3
- import { t as HttpClient } from "./http-BcC1vIan.js";
3
+ import { t as HttpClient } from "./http-DOXOhL_I.js";
4
4
  import { a as headShaOrUndefined, n as timingSafeEqual, r as toIncomingWebhook } from "./verify-BBMVxz8q.js";
5
5
  //#region src/providers/azure-devops/auth.ts
6
6
  /**
package/dist/bitbucket.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as RepoError } from "./errors-Cxq_CqYv.js";
2
2
  import { a as isRecord, c as assertSameOriginUrl, i as filenameFromContentDisposition, l as decodeCursor, n as commitWebUrlBuilder, s as toCloneUrl, t as clampPerPage, u as encodeCursor } from "./shared-C6m-C4My.js";
3
- import { t as HttpClient } from "./http-BcC1vIan.js";
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/bitbucket/index.ts
6
6
  const BASE_URL = "https://api.bitbucket.org/2.0";
package/dist/git-http.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as RepoError } from "./errors-Cxq_CqYv.js";
2
2
  import { f as stringToBase64, l as decodeCursor, s as toCloneUrl, t as clampPerPage, u as encodeCursor } from "./shared-C6m-C4My.js";
3
- import { t as HttpClient } from "./http-BcC1vIan.js";
3
+ import { t as HttpClient } from "./http-DOXOhL_I.js";
4
4
  //#region src/providers/git-http/index.ts
5
5
  const CAPABILITIES = {
6
6
  userProfile: false,
package/dist/gitea.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as RepoError } from "./errors-Cxq_CqYv.js";
2
2
  import { a as isRecord, c as assertSameOriginUrl, i as filenameFromContentDisposition, l as decodeCursor, n as commitWebUrlBuilder, o as parseLinkNext, r as encodeRefPath, s as toCloneUrl, t as clampPerPage, u as encodeCursor } from "./shared-C6m-C4My.js";
3
- import { t as HttpClient } from "./http-BcC1vIan.js";
3
+ import { t as HttpClient } from "./http-DOXOhL_I.js";
4
4
  import { a as headShaOrUndefined, n as timingSafeEqual, r as toIncomingWebhook, t as hmacSha256Hex } from "./verify-BBMVxz8q.js";
5
5
  //#region src/providers/gitea/index.ts
6
6
  const DEFAULT_BASE_URL = "https://gitea.com/api/v1";
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
@@ -1,6 +1,6 @@
1
1
  import { n as codeFromStatus, t as RepoError } from "./errors-Cxq_CqYv.js";
2
2
  import { a as isRecord, c as assertSameOriginUrl, d as bytesToBase64Url, i as filenameFromContentDisposition, l as decodeCursor, n as commitWebUrlBuilder, o as parseLinkNext, r as encodeRefPath, s as toCloneUrl, t as clampPerPage, u as encodeCursor } from "./shared-C6m-C4My.js";
3
- import { t as HttpClient } from "./http-BcC1vIan.js";
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
6
  const RSA_ALGORITHM_IDENTIFIER = [
@@ -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.repositories === void 0 ? void 0 : { repositories: this.repositories });
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/dist/gitlab.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as RepoError } from "./errors-Cxq_CqYv.js";
2
2
  import { a as isRecord, c as assertSameOriginUrl, i as filenameFromContentDisposition, l as decodeCursor, n as commitWebUrlBuilder, o as parseLinkNext, s as toCloneUrl, t as clampPerPage, u as encodeCursor } from "./shared-C6m-C4My.js";
3
- import { t as HttpClient } from "./http-BcC1vIan.js";
3
+ import { t as HttpClient } from "./http-DOXOhL_I.js";
4
4
  import { a as headShaOrUndefined, n as timingSafeEqual, r as toIncomingWebhook } from "./verify-BBMVxz8q.js";
5
5
  //#region src/providers/gitlab/index.ts
6
6
  const DEFAULT_BASE_URL = "https://gitlab.com/api/v4";
@@ -50,10 +50,26 @@ var HttpClient = class {
50
50
  }
51
51
  async json(path, options = {}) {
52
52
  const response = await this.raw(path, options);
53
- return {
54
- data: response.status === 204 ? void 0 : await response.json(),
53
+ if (response.status === 204) return {
54
+ data: void 0,
55
55
  response
56
56
  };
57
+ const text = await response.text();
58
+ try {
59
+ return {
60
+ data: JSON.parse(text),
61
+ response
62
+ };
63
+ } catch (error) {
64
+ const url = this.buildUrl(path, options.query);
65
+ throw new RepoError(`${this.options.provider} returned a non-JSON response from ${url.origin}${url.pathname}`, {
66
+ code: "invalid_response",
67
+ provider: this.options.provider,
68
+ status: response.status,
69
+ cause: error,
70
+ secrets: this.options.secrets?.() ?? []
71
+ });
72
+ }
57
73
  }
58
74
  async toError(response) {
59
75
  const text = await response.text().catch(() => "");
package/dist/index.d.ts CHANGED
@@ -74,7 +74,7 @@ interface DetectWebhookProviderInput {
74
74
  declare function detectWebhookProvider(input: Request | DetectWebhookProviderInput): Promise<ProviderName | undefined>;
75
75
  //#endregion
76
76
  //#region src/errors.d.ts
77
- type RepoErrorCode = 'unauthorized' | 'forbidden' | 'not_found' | 'rate_limited' | 'validation' | 'unsupported' | 'provider_error' | 'network_error';
77
+ type RepoErrorCode = 'unauthorized' | 'forbidden' | 'not_found' | 'rate_limited' | 'validation' | 'unsupported' | 'provider_error' | 'invalid_response' | 'network_error';
78
78
  interface RepoErrorOptions {
79
79
  code: RepoErrorCode;
80
80
  provider: ProviderName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
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>",