@framers/agentos-ext-github 0.1.5 → 0.2.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/README.md +87 -1
- package/dist/GitHubRepoIndexer.d.ts +20 -8
- package/dist/GitHubRepoIndexer.d.ts.map +1 -1
- package/dist/GitHubRepoIndexer.js +11 -6
- package/dist/GitHubRepoIndexer.js.map +1 -1
- package/dist/__tests__/app.test.d.ts +7 -0
- package/dist/__tests__/app.test.d.ts.map +1 -0
- package/dist/__tests__/app.test.js +248 -0
- package/dist/__tests__/app.test.js.map +1 -0
- package/dist/__tests__/documents.test.d.ts +7 -0
- package/dist/__tests__/documents.test.d.ts.map +1 -0
- package/dist/__tests__/documents.test.js +235 -0
- package/dist/__tests__/documents.test.js.map +1 -0
- package/dist/__tests__/indexer.test.js +14 -0
- package/dist/__tests__/indexer.test.js.map +1 -1
- package/dist/app/credential.d.ts +43 -0
- package/dist/app/credential.d.ts.map +1 -0
- package/dist/app/credential.js +74 -0
- package/dist/app/credential.js.map +1 -0
- package/dist/app/http.d.ts +61 -0
- package/dist/app/http.d.ts.map +1 -0
- package/dist/app/http.js +128 -0
- package/dist/app/http.js.map +1 -0
- package/dist/app/installations.d.ts +48 -0
- package/dist/app/installations.d.ts.map +1 -0
- package/dist/app/installations.js +61 -0
- package/dist/app/installations.js.map +1 -0
- package/dist/app/reconcile.d.ts +61 -0
- package/dist/app/reconcile.d.ts.map +1 -0
- package/dist/app/reconcile.js +89 -0
- package/dist/app/reconcile.js.map +1 -0
- package/dist/app/userFlow.d.ts +43 -0
- package/dist/app/userFlow.d.ts.map +1 -0
- package/dist/app/userFlow.js +54 -0
- package/dist/app/userFlow.js.map +1 -0
- package/dist/app/webhook.d.ts +15 -0
- package/dist/app/webhook.d.ts.map +1 -0
- package/dist/app/webhook.js +23 -0
- package/dist/app/webhook.js.map +1 -0
- package/dist/documents/GitHubDocumentsConnector.d.ts +80 -0
- package/dist/documents/GitHubDocumentsConnector.d.ts.map +1 -0
- package/dist/documents/GitHubDocumentsConnector.js +158 -0
- package/dist/documents/GitHubDocumentsConnector.js.map +1 -0
- package/dist/documents/index.d.ts +24 -0
- package/dist/documents/index.d.ts.map +1 -0
- package/dist/documents/index.js +24 -0
- package/dist/documents/index.js.map +1 -0
- package/dist/documents/tree.d.ts +71 -0
- package/dist/documents/tree.d.ts.map +1 -0
- package/dist/documents/tree.js +115 -0
- package/dist/documents/tree.js.map +1 -0
- package/manifest.json +5 -3
- package/package.json +16 -3
package/dist/app/http.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview GitHub's REST API over an injected `fetch`: one call with the headers every call carries, the pages
|
|
3
|
+
* of a listing followed through its `Link` header, and the small readers that turn an answer into typed fields. An
|
|
4
|
+
* answer outside 2xx throws {@link GitHubApiError}, whose message names the status and nothing of the answer's body.
|
|
5
|
+
* @module agentos-ext-github/app/http
|
|
6
|
+
*/
|
|
7
|
+
/** The REST API version every call pins (`X-GitHub-Api-Version`). */
|
|
8
|
+
export const GITHUB_API_VERSION = '2026-03-10';
|
|
9
|
+
/** GitHub's REST API. */
|
|
10
|
+
export const GITHUB_API_BASE = 'https://api.github.com';
|
|
11
|
+
/** GitHub answered a status outside 2xx. The message holds the status alone, never the answer's body. */
|
|
12
|
+
export class GitHubApiError extends Error {
|
|
13
|
+
status;
|
|
14
|
+
/** @param status The HTTP status GitHub answered. */
|
|
15
|
+
constructor(status) {
|
|
16
|
+
super(`GitHub answered ${status}`);
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.name = 'GitHubApiError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The headers of a call: the bearer, the media type, the pinned API version and the pack's user agent. */
|
|
22
|
+
export function githubHeaders(token, accept = 'application/vnd.github+json') {
|
|
23
|
+
return {
|
|
24
|
+
authorization: `Bearer ${token}`,
|
|
25
|
+
accept,
|
|
26
|
+
'x-github-api-version': GITHUB_API_VERSION,
|
|
27
|
+
'user-agent': 'agentos-ext-github',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Releases an answer's body unread. */
|
|
31
|
+
export async function discardBody(response) {
|
|
32
|
+
try {
|
|
33
|
+
await response.body?.cancel();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// The body is not needed; a failed cancel changes nothing for the caller.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Sends one call; an answer outside 2xx is discarded and thrown as {@link GitHubApiError}. */
|
|
40
|
+
export async function githubSend(fetchImpl, url, request) {
|
|
41
|
+
const headers = githubHeaders(request.token, request.accept);
|
|
42
|
+
if (request.body !== undefined)
|
|
43
|
+
headers['content-type'] = 'application/json';
|
|
44
|
+
const response = await fetchImpl(url, { method: request.method ?? 'GET', headers, body: request.body, signal: request.signal });
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
await discardBody(response);
|
|
47
|
+
throw new GitHubApiError(response.status);
|
|
48
|
+
}
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
/** An answer's JSON, or `undefined` when it has no body (a 202 or a 204). */
|
|
52
|
+
async function answerOf(response) {
|
|
53
|
+
const text = await response.text();
|
|
54
|
+
if (text === '')
|
|
55
|
+
return undefined;
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(text);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// The parser's message would quote the body.
|
|
61
|
+
throw new Error('GitHub answered a body that is not JSON');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* One call to `url` (an address under the API's base), answering its JSON, or `undefined` for an answer without a
|
|
66
|
+
* body. Sends `Authorization: Bearer <token>`, `Accept: application/vnd.github+json` unless told otherwise,
|
|
67
|
+
* `X-GitHub-Api-Version` and `User-Agent`.
|
|
68
|
+
*/
|
|
69
|
+
export async function githubFetch(fetchImpl, url, request) {
|
|
70
|
+
return answerOf(await githubSend(fetchImpl, url, request));
|
|
71
|
+
}
|
|
72
|
+
/** The address a `Link` header names as `rel="next"`, or null. */
|
|
73
|
+
export function nextPage(link) {
|
|
74
|
+
if (link === null)
|
|
75
|
+
return null;
|
|
76
|
+
const match = /<([^>]*)>\s*;\s*rel="next"/.exec(link);
|
|
77
|
+
return match === null ? null : match[1];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Each page of a listing as its JSON, following `Link: <...>; rel="next"`. A next page on another origin than the
|
|
81
|
+
* first is refused, so the bearer never leaves the API it was sent to.
|
|
82
|
+
*/
|
|
83
|
+
export async function* githubPages(fetchImpl, url, request) {
|
|
84
|
+
const origin = new URL(url).origin;
|
|
85
|
+
let next = url;
|
|
86
|
+
while (next !== null) {
|
|
87
|
+
const response = await githubSend(fetchImpl, next, request);
|
|
88
|
+
const link = response.headers.get('link');
|
|
89
|
+
yield await answerOf(response);
|
|
90
|
+
next = nextPage(link);
|
|
91
|
+
if (next !== null && new URL(next).origin !== origin)
|
|
92
|
+
throw new Error('GitHub named a next page on another origin');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Every item of a listing across its pages; `items` takes a page's JSON and answers its items. */
|
|
96
|
+
export async function pages(fetchImpl, url, request, items) {
|
|
97
|
+
const all = [];
|
|
98
|
+
for await (const page of githubPages(fetchImpl, url, request))
|
|
99
|
+
all.push(...items(page));
|
|
100
|
+
return all;
|
|
101
|
+
}
|
|
102
|
+
/** An answer's object; `what` names it in the error when it is not one. */
|
|
103
|
+
export function objectOf(value, what) {
|
|
104
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
105
|
+
throw new Error(`GitHub answered ${what} that is not an object`);
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
/** An answer's array; `what` names it in the error when it is not one. */
|
|
109
|
+
export function arrayOf(value, what) {
|
|
110
|
+
if (!Array.isArray(value))
|
|
111
|
+
throw new Error(`GitHub answered ${what} that is not a list`);
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
/** A number field of an answer's object. */
|
|
115
|
+
export function numberIn(fields, key, what) {
|
|
116
|
+
const value = fields[key];
|
|
117
|
+
if (typeof value !== 'number')
|
|
118
|
+
throw new Error(`GitHub answered ${what} without a number ${key}`);
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
/** A string field of an answer's object. */
|
|
122
|
+
export function stringIn(fields, key, what) {
|
|
123
|
+
const value = fields[key];
|
|
124
|
+
if (typeof value !== 'string')
|
|
125
|
+
throw new Error(`GitHub answered ${what} without a string ${key}`);
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/app/http.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qEAAqE;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAE/C,yBAAyB;AACzB,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC;AAmBxD,yGAAyG;AACzG,MAAM,OAAO,cAAe,SAAQ,KAAK;IAElB;IADrB,qDAAqD;IACrD,YAAqB,MAAc;QACjC,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;QADhB,WAAM,GAAN,MAAM,CAAQ;QAEjC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,2GAA2G;AAC3G,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,MAAM,GAAG,6BAA6B;IACjF,OAAO;QACL,aAAa,EAAE,UAAU,KAAK,EAAE;QAChC,MAAM;QACN,sBAAsB,EAAE,kBAAkB;QAC1C,YAAY,EAAE,oBAAoB;KACnC,CAAC;AACJ,CAAC;AAED,wCAAwC;AACxC,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAkB;IAClD,IAAI,CAAC;QACH,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,C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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview What a user token reaches (the person, the app's installations they can access, and the repositories
|
|
3
|
+
* of an installation they can read) and the app's own installations, listed and removed with its JWT. Each function
|
|
4
|
+
* takes `{ fetchImpl, apiBase }` last: `fetch` and GitHub's API when absent.
|
|
5
|
+
* @module agentos-ext-github/app/installations
|
|
6
|
+
*/
|
|
7
|
+
import type { GitHubAppCredential } from './credential.js';
|
|
8
|
+
import { type GitHubApiOptions } from './http.js';
|
|
9
|
+
/** The person a user token belongs to. */
|
|
10
|
+
export interface GitHubUser {
|
|
11
|
+
id: number;
|
|
12
|
+
login: string;
|
|
13
|
+
}
|
|
14
|
+
/** The account an installation is on: a user's or an organization's login, or an enterprise's slug. */
|
|
15
|
+
export interface GitHubAccount {
|
|
16
|
+
login: string;
|
|
17
|
+
id: number;
|
|
18
|
+
}
|
|
19
|
+
/** One installation of the app; GitHub may answer it without an account. */
|
|
20
|
+
export interface GitHubInstallation {
|
|
21
|
+
id: number;
|
|
22
|
+
account: GitHubAccount | null;
|
|
23
|
+
}
|
|
24
|
+
/** A repository a user token can read in an installation. */
|
|
25
|
+
export interface UserRepository {
|
|
26
|
+
id: number;
|
|
27
|
+
fullName: string;
|
|
28
|
+
defaultBranch: string;
|
|
29
|
+
}
|
|
30
|
+
/** The person a user token belongs to (`GET /user`): the GitHub id and login a link is made by. */
|
|
31
|
+
export declare function userOfToken(token: string, { fetchImpl, apiBase }?: GitHubApiOptions): Promise<GitHubUser>;
|
|
32
|
+
/** The app's installations a user token can access (`GET /user/installations`), across every page. */
|
|
33
|
+
export declare function installationsOfUser(token: string, { fetchImpl, apiBase }?: GitHubApiOptions): Promise<GitHubInstallation[]>;
|
|
34
|
+
/**
|
|
35
|
+
* The repositories of an installation a user token can read (`GET /user/installations/{installation_id}/repositories`),
|
|
36
|
+
* across every page: those the person owns, collaborates on or reaches through an organization.
|
|
37
|
+
*/
|
|
38
|
+
export declare function repositoriesOfUser(token: string, installationId: number, { fetchImpl, apiBase }?: GitHubApiOptions): Promise<UserRepository[]>;
|
|
39
|
+
/** Every installation of the app (`GET /app/installations`, with its JWT), across every page. */
|
|
40
|
+
export declare function listInstallations(credential: GitHubAppCredential, { fetchImpl, apiBase }?: GitHubApiOptions): Promise<GitHubInstallation[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Uninstalls the app from an account (`DELETE /app/installations/{installation_id}`, with its JWT). Answers without an
|
|
43
|
+
* error on 202 (GitHub has taken the removal and does it in the background at the pinned API version), on 204 (the
|
|
44
|
+
* answer of earlier versions) and on 404 (the installation is already gone); the answer's body is never read. Any
|
|
45
|
+
* other status throws {@link GitHubApiError}.
|
|
46
|
+
*/
|
|
47
|
+
export declare function uninstallInstallation(credential: GitHubAppCredential, installationId: number, { fetchImpl, apiBase }?: GitHubApiOptions): Promise<void>;
|
|
48
|
+
//# sourceMappingURL=installations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installations.d.ts","sourceRoot":"","sources":["../../src/app/installations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAWL,KAAK,gBAAgB,EACtB,MAAM,WAAW,CAAC;AAEnB,0CAA0C;AAC1C,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,uGAAuG;AACvG,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;CAC/B;AAED,6DAA6D;AAC7D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB;AAcD,mGAAmG;AACnG,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAiB,EAAE,OAAyB,EAAE,GAAE,gBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,CAG7I;AAED,sGAAsG;AACtG,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAiB,EAAE,OAAyB,EAAE,GAAE,gBAAqB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAI/J;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,EAAE,SAAiB,EAAE,OAAyB,EAAE,GAAE,gBAAqB,GACtE,OAAO,CAAC,cAAc,EAAE,CAAC,CAW3B;AAED,iGAAiG;AACjG,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,mBAAmB,EAAE,EAAE,SAAiB,EAAE,OAAyB,EAAE,GAAE,gBAAqB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAE/K;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,mBAAmB,EAC/B,cAAc,EAAE,MAAM,EACtB,EAAE,SAAiB,EAAE,OAAyB,EAAE,GAAE,gBAAqB,GACtE,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview What a user token reaches (the person, the app's installations they can access, and the repositories
|
|
3
|
+
* of an installation they can read) and the app's own installations, listed and removed with its JWT. Each function
|
|
4
|
+
* takes `{ fetchImpl, apiBase }` last: `fetch` and GitHub's API when absent.
|
|
5
|
+
* @module agentos-ext-github/app/installations
|
|
6
|
+
*/
|
|
7
|
+
import { arrayOf, discardBody, GITHUB_API_BASE, GitHubApiError, githubFetch, githubSend, numberIn, objectOf, pages, stringIn, } from './http.js';
|
|
8
|
+
function installationOf(value) {
|
|
9
|
+
const fields = objectOf(value, 'an installation');
|
|
10
|
+
const account = fields.account === null || fields.account === undefined ? null : objectOf(fields.account, "an installation's account");
|
|
11
|
+
return {
|
|
12
|
+
id: numberIn(fields, 'id', 'an installation'),
|
|
13
|
+
account: account === null
|
|
14
|
+
? null
|
|
15
|
+
: { login: stringIn(account, typeof account.login === 'string' ? 'login' : 'slug', "an installation's account"), id: numberIn(account, 'id', "an installation's account") },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** The person a user token belongs to (`GET /user`): the GitHub id and login a link is made by. */
|
|
19
|
+
export async function userOfToken(token, { fetchImpl = fetch, apiBase = GITHUB_API_BASE } = {}) {
|
|
20
|
+
const user = objectOf(await githubFetch(fetchImpl, `${apiBase}/user`, { token }), 'a user');
|
|
21
|
+
return { id: numberIn(user, 'id', 'a user'), login: stringIn(user, 'login', 'a user') };
|
|
22
|
+
}
|
|
23
|
+
/** The app's installations a user token can access (`GET /user/installations`), across every page. */
|
|
24
|
+
export async function installationsOfUser(token, { fetchImpl = fetch, apiBase = GITHUB_API_BASE } = {}) {
|
|
25
|
+
return pages(fetchImpl, `${apiBase}/user/installations?per_page=100`, { token }, (page) => arrayOf(objectOf(page, 'a page of installations').installations, 'a page of installations').map(installationOf));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The repositories of an installation a user token can read (`GET /user/installations/{installation_id}/repositories`),
|
|
29
|
+
* across every page: those the person owns, collaborates on or reaches through an organization.
|
|
30
|
+
*/
|
|
31
|
+
export async function repositoriesOfUser(token, installationId, { fetchImpl = fetch, apiBase = GITHUB_API_BASE } = {}) {
|
|
32
|
+
return pages(fetchImpl, `${apiBase}/user/installations/${installationId}/repositories?per_page=100`, { token }, (page) => arrayOf(objectOf(page, 'a page of repositories').repositories, 'a page of repositories').map((value) => {
|
|
33
|
+
const repository = objectOf(value, 'a repository');
|
|
34
|
+
return {
|
|
35
|
+
id: numberIn(repository, 'id', 'a repository'),
|
|
36
|
+
fullName: stringIn(repository, 'full_name', 'a repository'),
|
|
37
|
+
defaultBranch: stringIn(repository, 'default_branch', 'a repository'),
|
|
38
|
+
};
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
/** Every installation of the app (`GET /app/installations`, with its JWT), across every page. */
|
|
42
|
+
export async function listInstallations(credential, { fetchImpl = fetch, apiBase = GITHUB_API_BASE } = {}) {
|
|
43
|
+
return pages(fetchImpl, `${apiBase}/app/installations?per_page=100`, { token: credential.jwt() }, (page) => arrayOf(page, 'a page of installations').map(installationOf));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Uninstalls the app from an account (`DELETE /app/installations/{installation_id}`, with its JWT). Answers without an
|
|
47
|
+
* error on 202 (GitHub has taken the removal and does it in the background at the pinned API version), on 204 (the
|
|
48
|
+
* answer of earlier versions) and on 404 (the installation is already gone); the answer's body is never read. Any
|
|
49
|
+
* other status throws {@link GitHubApiError}.
|
|
50
|
+
*/
|
|
51
|
+
export async function uninstallInstallation(credential, installationId, { fetchImpl = fetch, apiBase = GITHUB_API_BASE } = {}) {
|
|
52
|
+
try {
|
|
53
|
+
await discardBody(await githubSend(fetchImpl, `${apiBase}/app/installations/${installationId}`, { token: credential.jwt(), method: 'DELETE' }));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error instanceof GitHubApiError && error.status === 404)
|
|
57
|
+
return;
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=installations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installations.js","sourceRoot":"","sources":["../../src/app/installations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,cAAc,EACd,WAAW,EACX,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,QAAQ,GAET,MAAM,WAAW,CAAC;AA2BnB,SAAS,cAAc,CAAC,KAAc;IACpC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,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;AAC5K,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,UAA+B,EAC/B,cAAsB,EACtB,EAAE,SAAS,GAAG,KAAK,EAAE,OAAO,GAAG,eAAe,KAAuB,EAAE;IAEvE,IAAI,CAAC;QACH,MAAM,WAAW,CAAC,MAAM,UAAU,CAAC,SAAS,EAAE,GAAG,OAAO,sBAAsB,cAAc,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IAClJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,cAAc,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG;YAAE,OAAO;QACpE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The daily reconcile of a GitHub App's links, for what its webhook deliveries missed: deliveries are lost
|
|
3
|
+
* while a server is down, and GitHub does not deliver a failed one again by itself.
|
|
4
|
+
* @module agentos-ext-github/app/reconcile
|
|
5
|
+
*/
|
|
6
|
+
import type { GitHubAppCredential } from './credential.js';
|
|
7
|
+
import { type GitHubApiOptions } from './http.js';
|
|
8
|
+
/** A repository of a link, with the head of its default branch last read (null when none was read yet). */
|
|
9
|
+
export interface ReconcileRepository {
|
|
10
|
+
id: number;
|
|
11
|
+
fullName: string;
|
|
12
|
+
defaultBranch: string;
|
|
13
|
+
headCommit: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** A link: an installation and the repositories read through it. */
|
|
16
|
+
export interface ReconcileLink {
|
|
17
|
+
installationId: number;
|
|
18
|
+
repositories: readonly ReconcileRepository[];
|
|
19
|
+
}
|
|
20
|
+
/** The window of deliveries to look at, and where calls go. */
|
|
21
|
+
export interface ReconcileOptions extends GitHubApiOptions {
|
|
22
|
+
/** The start of the window: failed deliveries since then are asked for again. */
|
|
23
|
+
since: Date;
|
|
24
|
+
}
|
|
25
|
+
/** A repository whose default branch moved past the head last read. */
|
|
26
|
+
export interface MovedRepository {
|
|
27
|
+
installationId: number;
|
|
28
|
+
repositoryId: number;
|
|
29
|
+
/** The head to read. */
|
|
30
|
+
head: string;
|
|
31
|
+
}
|
|
32
|
+
/** A repository whose head could not be read, with GitHub's status (for example 404 or 422 once it left the installation). */
|
|
33
|
+
export interface UnreadableRepository {
|
|
34
|
+
installationId: number;
|
|
35
|
+
repositoryId: number;
|
|
36
|
+
status: number;
|
|
37
|
+
}
|
|
38
|
+
/** What the reconcile found and did. */
|
|
39
|
+
export interface ReconcileOutcome {
|
|
40
|
+
/** Installations the app no longer has: their links and documents go. */
|
|
41
|
+
gone: number[];
|
|
42
|
+
/** Repositories to compare by tree, as a push to their default branch is. */
|
|
43
|
+
moved: MovedRepository[];
|
|
44
|
+
/** Deliveries asked for again. */
|
|
45
|
+
redelivered: number[];
|
|
46
|
+
/** Repositories whose head GitHub would not answer. */
|
|
47
|
+
unreadable: UnreadableRepository[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reconciles a GitHub App's links with GitHub: an installation that `GET /app/installations` no longer lists is
|
|
51
|
+
* answered gone; each repository of the other links has its default branch's head read with an installation token
|
|
52
|
+
* narrowed to it and is answered moved when the head differs from the one last read, or unreadable with GitHub's
|
|
53
|
+
* status; and the app's failed deliveries since `since` are asked for again
|
|
54
|
+
* (`GET /app/hook/deliveries`, `POST /app/hook/deliveries/{delivery_id}/attempts`).
|
|
55
|
+
*
|
|
56
|
+
* @param credential The app's credential.
|
|
57
|
+
* @param links The links to check.
|
|
58
|
+
* @param options The window's start, and where calls go.
|
|
59
|
+
*/
|
|
60
|
+
export declare function reconcileInstallations(credential: GitHubAppCredential, links: readonly ReconcileLink[], { since, fetchImpl, apiBase }: ReconcileOptions): Promise<ReconcileOutcome>;
|
|
61
|
+
//# sourceMappingURL=reconcile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../../src/app/reconcile.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAWL,KAAK,gBAAgB,EACtB,MAAM,WAAW,CAAC;AAGnB,2GAA2G;AAC3G,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAC9C;AAED,+DAA+D;AAC/D,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,iFAAiF;IACjF,KAAK,EAAE,IAAI,CAAC;CACb;AAED,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,8HAA8H;AAC9H,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,yEAAyE;IACzE,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,6EAA6E;IAC7E,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,kCAAkC;IAClC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,uDAAuD;IACvD,UAAU,EAAE,oBAAoB,EAAE,CAAC;CACpC;AAgDD;;;;;;;;;;GAUG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,mBAAmB,EAC/B,KAAK,EAAE,SAAS,aAAa,EAAE,EAC/B,EAAE,KAAK,EAAE,SAAiB,EAAE,OAAyB,EAAE,EAAE,gBAAgB,GACxE,OAAO,CAAC,gBAAgB,CAAC,CA2B3B"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The daily reconcile of a GitHub App's links, for what its webhook deliveries missed: deliveries are lost
|
|
3
|
+
* while a server is down, and GitHub does not deliver a failed one again by itself.
|
|
4
|
+
* @module agentos-ext-github/app/reconcile
|
|
5
|
+
*/
|
|
6
|
+
import { arrayOf, discardBody, GITHUB_API_BASE, GitHubApiError, githubFetch, githubPages, githubSend, numberIn, objectOf, stringIn, } from './http.js';
|
|
7
|
+
import { listInstallations } from './installations.js';
|
|
8
|
+
function deliveryOf(value) {
|
|
9
|
+
const fields = objectOf(value, 'a delivery');
|
|
10
|
+
const status = numberIn(fields, 'status_code', 'a delivery');
|
|
11
|
+
return {
|
|
12
|
+
id: numberIn(fields, 'id', 'a delivery'),
|
|
13
|
+
guid: stringIn(fields, 'guid', 'a delivery'),
|
|
14
|
+
deliveredAt: Date.parse(stringIn(fields, 'delivered_at', 'a delivery')),
|
|
15
|
+
succeeded: status >= 200 && status < 300,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Asks again for each event of the window that no attempt delivered: the newest failed attempt of each delivery guid
|
|
20
|
+
* with no successful attempt since `since`. GitHub lists deliveries newest first, so the pages stop at the first one
|
|
21
|
+
* that reaches past the window.
|
|
22
|
+
*/
|
|
23
|
+
async function redeliverFailures(credential, since, fetchImpl, apiBase) {
|
|
24
|
+
const attemptsByGuid = new Map();
|
|
25
|
+
for await (const page of githubPages(fetchImpl, `${apiBase}/app/hook/deliveries?per_page=100`, { token: credential.jwt() })) {
|
|
26
|
+
const deliveries = arrayOf(page, 'a page of deliveries').map(deliveryOf);
|
|
27
|
+
for (const delivery of deliveries) {
|
|
28
|
+
if (!(delivery.deliveredAt >= since))
|
|
29
|
+
continue;
|
|
30
|
+
const attempts = attemptsByGuid.get(delivery.guid);
|
|
31
|
+
if (attempts === undefined)
|
|
32
|
+
attemptsByGuid.set(delivery.guid, [delivery]);
|
|
33
|
+
else
|
|
34
|
+
attempts.push(delivery);
|
|
35
|
+
}
|
|
36
|
+
if (deliveries.length === 0 || deliveries.some((delivery) => !(delivery.deliveredAt >= since)))
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
const redelivered = [];
|
|
40
|
+
for (const attempts of attemptsByGuid.values()) {
|
|
41
|
+
if (attempts.some((attempt) => attempt.succeeded))
|
|
42
|
+
continue;
|
|
43
|
+
const latest = attempts.reduce((newest, attempt) => (attempt.deliveredAt > newest.deliveredAt ? attempt : newest));
|
|
44
|
+
await discardBody(await githubSend(fetchImpl, `${apiBase}/app/hook/deliveries/${latest.id}/attempts`, { token: credential.jwt(), method: 'POST' }));
|
|
45
|
+
redelivered.push(latest.id);
|
|
46
|
+
}
|
|
47
|
+
return redelivered;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reconciles a GitHub App's links with GitHub: an installation that `GET /app/installations` no longer lists is
|
|
51
|
+
* answered gone; each repository of the other links has its default branch's head read with an installation token
|
|
52
|
+
* narrowed to it and is answered moved when the head differs from the one last read, or unreadable with GitHub's
|
|
53
|
+
* status; and the app's failed deliveries since `since` are asked for again
|
|
54
|
+
* (`GET /app/hook/deliveries`, `POST /app/hook/deliveries/{delivery_id}/attempts`).
|
|
55
|
+
*
|
|
56
|
+
* @param credential The app's credential.
|
|
57
|
+
* @param links The links to check.
|
|
58
|
+
* @param options The window's start, and where calls go.
|
|
59
|
+
*/
|
|
60
|
+
export async function reconcileInstallations(credential, links, { since, fetchImpl = fetch, apiBase = GITHUB_API_BASE }) {
|
|
61
|
+
const listed = new Set((await listInstallations(credential, { fetchImpl, apiBase })).map((installation) => installation.id));
|
|
62
|
+
const gone = [];
|
|
63
|
+
const moved = [];
|
|
64
|
+
const unreadable = [];
|
|
65
|
+
for (const link of links) {
|
|
66
|
+
if (!listed.has(link.installationId)) {
|
|
67
|
+
if (!gone.includes(link.installationId))
|
|
68
|
+
gone.push(link.installationId);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
for (const repository of link.repositories) {
|
|
72
|
+
try {
|
|
73
|
+
const token = await credential.installationToken(link.installationId, [repository.id]);
|
|
74
|
+
const branch = objectOf(await githubFetch(fetchImpl, `${apiBase}/repos/${repository.fullName}/branches/${encodeURIComponent(repository.defaultBranch)}`, { token }), 'a branch');
|
|
75
|
+
const head = stringIn(objectOf(branch.commit, "a branch's commit"), 'sha', "a branch's commit");
|
|
76
|
+
if (head !== repository.headCommit)
|
|
77
|
+
moved.push({ installationId: link.installationId, repositoryId: repository.id, head });
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (!(error instanceof GitHubApiError))
|
|
81
|
+
throw error;
|
|
82
|
+
unreadable.push({ installationId: link.installationId, repositoryId: repository.id, status: error.status });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const redelivered = await redeliverFailures(credential, since.getTime(), fetchImpl, apiBase);
|
|
87
|
+
return { gone, moved, redelivered, unreadable };
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=reconcile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.js","sourceRoot":"","sources":["../../src/app/reconcile.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,cAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,QAAQ,GAET,MAAM,WAAW,CAAC;AAC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E,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7H,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,CAAC,KAAK,YAAY,cAAc,CAAC;oBAAE,MAAM,KAAK,CAAC;gBACpD,UAAU,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9G,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAC7F,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A GitHub App's user authorization on a web server: GitHub's authorize address with `state` and PKCE,
|
|
3
|
+
* and the code exchanged for a user access token, on the auth module's `RedirectOAuthFlow`. The token proves who the
|
|
4
|
+
* person is and which installations and repositories they can reach; it is used once and dropped, so the flow has no
|
|
5
|
+
* store.
|
|
6
|
+
* @module agentos-ext-github/app/userFlow
|
|
7
|
+
*/
|
|
8
|
+
import { RedirectOAuthFlow, type RedirectBegin, type RedirectOAuthConfig } from '@framers/agentos/auth';
|
|
9
|
+
/** The app's OAuth client: its client id and client secret. */
|
|
10
|
+
export interface GitHubAppClient {
|
|
11
|
+
clientId: string;
|
|
12
|
+
clientSecret: string;
|
|
13
|
+
}
|
|
14
|
+
/** GitHub's authorize and token addresses; a stand-in's in tests. */
|
|
15
|
+
export interface GitHubOAuthEndpoints {
|
|
16
|
+
authorize: string;
|
|
17
|
+
token: string;
|
|
18
|
+
}
|
|
19
|
+
/** github.com's own authorize and token addresses. */
|
|
20
|
+
export declare const GITHUB_OAUTH_ENDPOINTS: GitHubOAuthEndpoints;
|
|
21
|
+
/**
|
|
22
|
+
* The user's web flow for a GitHub App: `begin` answers the authorize address with the state and the PKCE verifier
|
|
23
|
+
* for the caller to keep, and `complete` checks the state and exchanges the code (with `code_verifier`, asking for a
|
|
24
|
+
* JSON answer) for the user's token. A GitHub App's permissions are the app's, not the token's, so the address carries
|
|
25
|
+
* no `scope`.
|
|
26
|
+
*/
|
|
27
|
+
export declare class GitHubAppUserFlow extends RedirectOAuthFlow {
|
|
28
|
+
private readonly client;
|
|
29
|
+
private readonly endpoints;
|
|
30
|
+
/** The provider's id. */
|
|
31
|
+
readonly providerId = "github";
|
|
32
|
+
/**
|
|
33
|
+
* @param client The app's client id and client secret.
|
|
34
|
+
* @param fetchImpl The fetch the code is exchanged with.
|
|
35
|
+
* @param endpoints GitHub's authorize and token addresses.
|
|
36
|
+
*/
|
|
37
|
+
constructor(client: GitHubAppClient, fetchImpl?: typeof fetch, endpoints?: GitHubOAuthEndpoints);
|
|
38
|
+
/** GitHub's addresses and the app's client, with no scopes. */
|
|
39
|
+
protected getConfig(): RedirectOAuthConfig;
|
|
40
|
+
/** The authorize address with the state and the PKCE challenge, leaving out the empty `scope` the base would send. */
|
|
41
|
+
begin(input: Parameters<RedirectOAuthFlow['begin']>[0]): RedirectBegin;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=userFlow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userFlow.d.ts","sourceRoot":"","sources":["../../src/app/userFlow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAExG,+DAA+D;AAC/D,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qEAAqE;AACrE,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,sDAAsD;AACtD,eAAO,MAAM,sBAAsB,EAAE,oBAGpC,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,iBAAiB;IAS1C,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAoD,OAAO,CAAC,QAAQ,CAAC,SAAS;IARjH,yBAAyB;IACzB,QAAQ,CAAC,UAAU,YAAY;IAE/B;;;;OAIG;gBAC0B,MAAM,EAAE,eAAe,EAAE,SAAS,GAAE,OAAO,KAAa,EAAmB,SAAS,GAAE,oBAA6C;IAIhK,+DAA+D;IAC/D,SAAS,CAAC,SAAS,IAAI,mBAAmB;IAU1C,sHAAsH;IAC7G,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa;CAMhF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A GitHub App's user authorization on a web server: GitHub's authorize address with `state` and PKCE,
|
|
3
|
+
* and the code exchanged for a user access token, on the auth module's `RedirectOAuthFlow`. The token proves who the
|
|
4
|
+
* person is and which installations and repositories they can reach; it is used once and dropped, so the flow has no
|
|
5
|
+
* store.
|
|
6
|
+
* @module agentos-ext-github/app/userFlow
|
|
7
|
+
*/
|
|
8
|
+
import { RedirectOAuthFlow } from '@framers/agentos/auth';
|
|
9
|
+
/** github.com's own authorize and token addresses. */
|
|
10
|
+
export const GITHUB_OAUTH_ENDPOINTS = {
|
|
11
|
+
authorize: 'https://github.com/login/oauth/authorize',
|
|
12
|
+
token: 'https://github.com/login/oauth/access_token',
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The user's web flow for a GitHub App: `begin` answers the authorize address with the state and the PKCE verifier
|
|
16
|
+
* for the caller to keep, and `complete` checks the state and exchanges the code (with `code_verifier`, asking for a
|
|
17
|
+
* JSON answer) for the user's token. A GitHub App's permissions are the app's, not the token's, so the address carries
|
|
18
|
+
* no `scope`.
|
|
19
|
+
*/
|
|
20
|
+
export class GitHubAppUserFlow extends RedirectOAuthFlow {
|
|
21
|
+
client;
|
|
22
|
+
endpoints;
|
|
23
|
+
/** The provider's id. */
|
|
24
|
+
providerId = 'github';
|
|
25
|
+
/**
|
|
26
|
+
* @param client The app's client id and client secret.
|
|
27
|
+
* @param fetchImpl The fetch the code is exchanged with.
|
|
28
|
+
* @param endpoints GitHub's authorize and token addresses.
|
|
29
|
+
*/
|
|
30
|
+
constructor(client, fetchImpl = fetch, endpoints = GITHUB_OAUTH_ENDPOINTS) {
|
|
31
|
+
super(null, fetchImpl);
|
|
32
|
+
this.client = client;
|
|
33
|
+
this.endpoints = endpoints;
|
|
34
|
+
}
|
|
35
|
+
/** GitHub's addresses and the app's client, with no scopes. */
|
|
36
|
+
getConfig() {
|
|
37
|
+
return {
|
|
38
|
+
authorizationEndpoint: this.endpoints.authorize,
|
|
39
|
+
tokenEndpoint: this.endpoints.token,
|
|
40
|
+
scopes: [],
|
|
41
|
+
clientId: this.client.clientId,
|
|
42
|
+
clientSecret: this.client.clientSecret,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** The authorize address with the state and the PKCE challenge, leaving out the empty `scope` the base would send. */
|
|
46
|
+
begin(input) {
|
|
47
|
+
const begun = super.begin(input);
|
|
48
|
+
const address = new URL(begun.url);
|
|
49
|
+
if (address.searchParams.get('scope') === '')
|
|
50
|
+
address.searchParams.delete('scope');
|
|
51
|
+
return { ...begun, url: address.toString() };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=userFlow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userFlow.js","sourceRoot":"","sources":["../../src/app/userFlow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAgD,MAAM,uBAAuB,CAAC;AAcxG,sDA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the hex HMAC SHA-256 of the raw
|
|
3
|
+
* body under the webhook's secret.
|
|
4
|
+
* @module agentos-ext-github/app/webhook
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* True when `header` is `sha256=` and 64 hex digits that equal the HMAC SHA-256 of the raw body under the secret,
|
|
8
|
+
* compared in constant time. A missing header, another algorithm or another length is false.
|
|
9
|
+
*
|
|
10
|
+
* @param body The delivery's body exactly as received, before any parsing.
|
|
11
|
+
* @param header The `X-Hub-Signature-256` header, or null when the delivery had none.
|
|
12
|
+
* @param secret The webhook's secret.
|
|
13
|
+
*/
|
|
14
|
+
export declare function verifyWebhookSignature(body: Uint8Array, header: string | null, secret: string): boolean;
|
|
15
|
+
//# sourceMappingURL=webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/app/webhook.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAMvG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A webhook delivery's signature: `X-Hub-Signature-256` is `sha256=` and the hex HMAC SHA-256 of the raw
|
|
3
|
+
* body under the webhook's secret.
|
|
4
|
+
* @module agentos-ext-github/app/webhook
|
|
5
|
+
*/
|
|
6
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
7
|
+
/**
|
|
8
|
+
* True when `header` is `sha256=` and 64 hex digits that equal the HMAC SHA-256 of the raw body under the secret,
|
|
9
|
+
* compared in constant time. A missing header, another algorithm or another length is false.
|
|
10
|
+
*
|
|
11
|
+
* @param body The delivery's body exactly as received, before any parsing.
|
|
12
|
+
* @param header The `X-Hub-Signature-256` header, or null when the delivery had none.
|
|
13
|
+
* @param secret The webhook's secret.
|
|
14
|
+
*/
|
|
15
|
+
export function verifyWebhookSignature(body, header, secret) {
|
|
16
|
+
const match = header === null ? null : /^sha256=([0-9a-f]{64})$/i.exec(header);
|
|
17
|
+
if (match === null)
|
|
18
|
+
return false;
|
|
19
|
+
const given = Buffer.from(match[1], 'hex');
|
|
20
|
+
const expected = createHmac('sha256', secret).update(body).digest();
|
|
21
|
+
return given.length === expected.length && timingSafeEqual(given, expected);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../src/app/webhook.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAgB,EAAE,MAAqB,EAAE,MAAc;IAC5F,MAAM,KAAK,GAAG,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/E,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;IACpE,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC9E,CAAC"}
|