repo-sdk 0.3.0 → 0.3.2
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 +1 -1
- package/dist/azure-devops.js +1 -1
- package/dist/bitbucket.js +1 -1
- package/dist/git-http.js +1 -1
- package/dist/gitea.js +1 -1
- package/dist/github.d.ts +5 -0
- package/dist/github.js +15 -9
- package/dist/gitlab.js +1 -1
- package/dist/{http-BcC1vIan.js → http-DOXOhL_I.js} +18 -2
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
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';
|
package/dist/azure-devops.js
CHANGED
|
@@ -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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
@@ -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
|
@@ -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-
|
|
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 = [
|
|
@@ -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
|
-
|
|
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/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-
|
|
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:
|
|
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