@brain-toolkit/issue-forge 0.0.0-stage → 0.1.0
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/CHANGELOG.md +5 -0
- package/README.md +43 -2
- package/dist/GithubAppClient-CPCXnpDO.d.ts +103 -0
- package/dist/chunk-RQKDVDLH.js +471 -0
- package/dist/chunk-RQKDVDLH.js.map +1 -0
- package/dist/feedback/index.cjs +911 -0
- package/dist/feedback/index.cjs.map +1 -0
- package/dist/feedback/index.d.ts +236 -0
- package/dist/feedback/index.js +567 -0
- package/dist/feedback/index.js.map +1 -0
- package/dist/index.cjs +515 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/package.json +74 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
GithubAppClient: () => GithubAppClient,
|
|
34
|
+
GithubAppIssueForgeGateway: () => GithubAppIssueForgeGateway,
|
|
35
|
+
GithubAppRepoContentGateway: () => GithubAppRepoContentGateway,
|
|
36
|
+
GithubWebhookVerifier: () => GithubWebhookVerifier,
|
|
37
|
+
IssueForgeError: () => IssueForgeError,
|
|
38
|
+
createGithubAppClient: () => createGithubAppClient,
|
|
39
|
+
createGithubAppIssueForge: () => createGithubAppIssueForge,
|
|
40
|
+
createGithubAppRepoContent: () => createGithubAppRepoContent,
|
|
41
|
+
createGithubWebhookVerifier: () => createGithubWebhookVerifier
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(src_exports);
|
|
44
|
+
|
|
45
|
+
// src/errors/IssueForgeError.ts
|
|
46
|
+
var IssueForgeError = class extends Error {
|
|
47
|
+
code = "ISSUE_FORGE_FAILED";
|
|
48
|
+
/** HTTP 状态码;网络错误等无响应时为 null */
|
|
49
|
+
status;
|
|
50
|
+
constructor(message, status) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = "IssueForgeError";
|
|
53
|
+
this.status = status;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/github/GithubAppClient.ts
|
|
58
|
+
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
59
|
+
var GITHUB_API = "https://api.github.com";
|
|
60
|
+
var GITHUB_API_VERSION = "2022-11-28";
|
|
61
|
+
var DEFAULT_USER_AGENT = "brain-toolkit-issue-forge";
|
|
62
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
63
|
+
var APP_JWT_TTL_SEC = 9 * 60;
|
|
64
|
+
var APP_JWT_CLOCK_SKEW_SEC = 60;
|
|
65
|
+
var TOKEN_REFRESH_MARGIN_MS = 2 * 60 * 1e3;
|
|
66
|
+
var GithubAppClient = class {
|
|
67
|
+
cache;
|
|
68
|
+
userAgent;
|
|
69
|
+
constructor(options) {
|
|
70
|
+
this.cache = options.cache;
|
|
71
|
+
this.userAgent = options.userAgent?.trim() || DEFAULT_USER_AGENT;
|
|
72
|
+
}
|
|
73
|
+
async request(config, path, init) {
|
|
74
|
+
const token = await this.getInstallationToken(config);
|
|
75
|
+
const headers = this.headers(`Bearer ${token}`);
|
|
76
|
+
if (init.accept) {
|
|
77
|
+
headers.Accept = init.accept;
|
|
78
|
+
}
|
|
79
|
+
if (init.body !== void 0) {
|
|
80
|
+
headers["Content-Type"] = "application/json";
|
|
81
|
+
}
|
|
82
|
+
const response = await this.send(`${GITHUB_API}${path}`, {
|
|
83
|
+
method: init.method,
|
|
84
|
+
headers,
|
|
85
|
+
...init.body !== void 0 ? { body: JSON.stringify(init.body) } : {}
|
|
86
|
+
});
|
|
87
|
+
if (response.status === 401 || response.status === 403) {
|
|
88
|
+
await this.cache.removeItem(this.tokenCacheKey(config));
|
|
89
|
+
}
|
|
90
|
+
return response;
|
|
91
|
+
}
|
|
92
|
+
async toError(stage, response) {
|
|
93
|
+
let detail = "";
|
|
94
|
+
try {
|
|
95
|
+
const json = await response.json();
|
|
96
|
+
detail = typeof json.message === "string" ? json.message : "";
|
|
97
|
+
} catch {
|
|
98
|
+
detail = "";
|
|
99
|
+
}
|
|
100
|
+
return new IssueForgeError(
|
|
101
|
+
`${stage}: HTTP ${String(response.status)}${detail ? ` ${detail}` : ""}`,
|
|
102
|
+
response.status
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
async getInstallationToken(config) {
|
|
106
|
+
const cacheKey = this.tokenCacheKey(config);
|
|
107
|
+
const cached = await this.cache.getItem(cacheKey);
|
|
108
|
+
if (cached?.token) {
|
|
109
|
+
return cached.token;
|
|
110
|
+
}
|
|
111
|
+
const response = await this.send(
|
|
112
|
+
`${GITHUB_API}/app/installations/${encodeURIComponent(config.installationId)}/access_tokens`,
|
|
113
|
+
{
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers: this.headers(`Bearer ${this.signAppJwt(config)}`)
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
throw await this.toError("installation token", response);
|
|
120
|
+
}
|
|
121
|
+
const json = await response.json();
|
|
122
|
+
if (typeof json.token !== "string" || !json.token) {
|
|
123
|
+
throw new IssueForgeError(
|
|
124
|
+
"installation token: empty token",
|
|
125
|
+
response.status
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const expiresAtMs = typeof json.expires_at === "string" ? Date.parse(json.expires_at) : Number.NaN;
|
|
129
|
+
const ttlMs = Number.isFinite(expiresAtMs) ? expiresAtMs - Date.now() - TOKEN_REFRESH_MARGIN_MS : 0;
|
|
130
|
+
if (ttlMs > 0) {
|
|
131
|
+
await this.cache.setItem(
|
|
132
|
+
cacheKey,
|
|
133
|
+
{ token: json.token },
|
|
134
|
+
{ ttlMs }
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return json.token;
|
|
138
|
+
}
|
|
139
|
+
signAppJwt(config) {
|
|
140
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
141
|
+
try {
|
|
142
|
+
return import_jsonwebtoken.default.sign(
|
|
143
|
+
{
|
|
144
|
+
iat: nowSec - APP_JWT_CLOCK_SKEW_SEC,
|
|
145
|
+
exp: nowSec + APP_JWT_TTL_SEC,
|
|
146
|
+
iss: config.appId
|
|
147
|
+
},
|
|
148
|
+
this.normalizePrivateKey(config.privateKey),
|
|
149
|
+
{ algorithm: "RS256" }
|
|
150
|
+
);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw new IssueForgeError(
|
|
153
|
+
`invalid GitHub App private key: ${error instanceof Error ? error.message : String(error)}`,
|
|
154
|
+
null
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
normalizePrivateKey(raw) {
|
|
159
|
+
return raw.replace(/\\n/g, "\n").replace(/\r\n/g, "\n").trim();
|
|
160
|
+
}
|
|
161
|
+
async send(url, init) {
|
|
162
|
+
try {
|
|
163
|
+
return await fetch(url, {
|
|
164
|
+
...init,
|
|
165
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
166
|
+
});
|
|
167
|
+
} catch (error) {
|
|
168
|
+
throw new IssueForgeError(
|
|
169
|
+
`GitHub request failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
170
|
+
null
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
headers(authorization) {
|
|
175
|
+
return {
|
|
176
|
+
Accept: "application/vnd.github+json",
|
|
177
|
+
Authorization: authorization,
|
|
178
|
+
"User-Agent": this.userAgent,
|
|
179
|
+
"X-GitHub-Api-Version": GITHUB_API_VERSION
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
tokenCacheKey(config) {
|
|
183
|
+
return `issue-forge:github:installation-token:${config.appId}:${config.installationId}`;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/github/GithubAppRepoContentGateway.ts
|
|
188
|
+
var ACCEPT_RAW = "application/vnd.github.raw+json";
|
|
189
|
+
var GithubAppRepoContentGateway = class {
|
|
190
|
+
constructor(client, config) {
|
|
191
|
+
this.client = client;
|
|
192
|
+
this.config = config;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @override
|
|
196
|
+
*/
|
|
197
|
+
async readTextFile(path) {
|
|
198
|
+
const response = await this.client.request(
|
|
199
|
+
this.config,
|
|
200
|
+
this.contentsPath(path),
|
|
201
|
+
{ method: "GET", accept: ACCEPT_RAW }
|
|
202
|
+
);
|
|
203
|
+
if (response.status === 404) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
if (!response.ok) {
|
|
207
|
+
throw await this.client.toError("read file", response);
|
|
208
|
+
}
|
|
209
|
+
return response.text();
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* @override
|
|
213
|
+
*/
|
|
214
|
+
async hasFile(path, branch) {
|
|
215
|
+
const response = await this.client.request(
|
|
216
|
+
this.config,
|
|
217
|
+
`${this.contentsPath(path)}?ref=${encodeURIComponent(branch)}`,
|
|
218
|
+
{ method: "GET" }
|
|
219
|
+
);
|
|
220
|
+
if (response.status === 404) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
if (!response.ok) {
|
|
224
|
+
throw await this.client.toError("has file", response);
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* @override
|
|
230
|
+
*/
|
|
231
|
+
async ensureBranch(branch, initialFile) {
|
|
232
|
+
const found = await this.client.request(
|
|
233
|
+
this.config,
|
|
234
|
+
`${this.repoPath()}/git/ref/heads/${this.encodePath(branch)}`,
|
|
235
|
+
{ method: "GET" }
|
|
236
|
+
);
|
|
237
|
+
if (found.ok) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (found.status !== 404) {
|
|
241
|
+
throw await this.client.toError("get branch", found);
|
|
242
|
+
}
|
|
243
|
+
const treeSha = await this.postForSha("create tree", "/git/trees", {
|
|
244
|
+
tree: [
|
|
245
|
+
{
|
|
246
|
+
path: initialFile.path,
|
|
247
|
+
mode: "100644",
|
|
248
|
+
type: "blob",
|
|
249
|
+
content: initialFile.content
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
});
|
|
253
|
+
const commitSha = await this.postForSha("create commit", "/git/commits", {
|
|
254
|
+
message: `chore: \u521D\u59CB\u5316 ${branch} \u5206\u652F`,
|
|
255
|
+
tree: treeSha,
|
|
256
|
+
parents: []
|
|
257
|
+
});
|
|
258
|
+
const created = await this.client.request(
|
|
259
|
+
this.config,
|
|
260
|
+
`${this.repoPath()}/git/refs`,
|
|
261
|
+
{
|
|
262
|
+
method: "POST",
|
|
263
|
+
body: { ref: `refs/heads/${branch}`, sha: commitSha }
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
if (!created.ok && created.status !== 422) {
|
|
267
|
+
throw await this.client.toError("create branch", created);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* @override
|
|
272
|
+
*/
|
|
273
|
+
async uploadFile(input) {
|
|
274
|
+
const response = await this.client.request(
|
|
275
|
+
this.config,
|
|
276
|
+
this.contentsPath(input.path),
|
|
277
|
+
{
|
|
278
|
+
method: "PUT",
|
|
279
|
+
body: {
|
|
280
|
+
message: input.message,
|
|
281
|
+
content: input.contentBase64,
|
|
282
|
+
branch: input.branch
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
if (response.ok) {
|
|
287
|
+
const json = await response.json();
|
|
288
|
+
return { url: this.requireHtmlUrl(json.content?.html_url, response) };
|
|
289
|
+
}
|
|
290
|
+
if (response.status === 422) {
|
|
291
|
+
return this.readExisting(input);
|
|
292
|
+
}
|
|
293
|
+
throw await this.client.toError("upload file", response);
|
|
294
|
+
}
|
|
295
|
+
async readExisting(input) {
|
|
296
|
+
const response = await this.client.request(
|
|
297
|
+
this.config,
|
|
298
|
+
`${this.contentsPath(input.path)}?ref=${encodeURIComponent(input.branch)}`,
|
|
299
|
+
{ method: "GET" }
|
|
300
|
+
);
|
|
301
|
+
if (!response.ok) {
|
|
302
|
+
throw await this.client.toError("upload file", response);
|
|
303
|
+
}
|
|
304
|
+
const json = await response.json();
|
|
305
|
+
return { url: this.requireHtmlUrl(json.html_url, response) };
|
|
306
|
+
}
|
|
307
|
+
async postForSha(stage, path, body) {
|
|
308
|
+
const response = await this.client.request(
|
|
309
|
+
this.config,
|
|
310
|
+
`${this.repoPath()}${path}`,
|
|
311
|
+
{ method: "POST", body }
|
|
312
|
+
);
|
|
313
|
+
if (!response.ok) {
|
|
314
|
+
throw await this.client.toError(stage, response);
|
|
315
|
+
}
|
|
316
|
+
const json = await response.json();
|
|
317
|
+
if (typeof json.sha !== "string" || !json.sha) {
|
|
318
|
+
throw new IssueForgeError(
|
|
319
|
+
`${stage}: unexpected response`,
|
|
320
|
+
response.status
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
return json.sha;
|
|
324
|
+
}
|
|
325
|
+
requireHtmlUrl(value, response) {
|
|
326
|
+
if (typeof value !== "string" || !value) {
|
|
327
|
+
throw new IssueForgeError(
|
|
328
|
+
"upload file: unexpected response",
|
|
329
|
+
response.status
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
return value;
|
|
333
|
+
}
|
|
334
|
+
contentsPath(path) {
|
|
335
|
+
return `${this.repoPath()}/contents/${this.encodePath(path)}`;
|
|
336
|
+
}
|
|
337
|
+
encodePath(path) {
|
|
338
|
+
return path.split("/").filter((segment) => segment.length > 0).map((segment) => encodeURIComponent(segment)).join("/");
|
|
339
|
+
}
|
|
340
|
+
repoPath() {
|
|
341
|
+
return `/repos/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}`;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/github/GithubAppIssueForgeGateway.ts
|
|
346
|
+
var COMMENTS_PAGE_SIZE = 100;
|
|
347
|
+
var GithubAppIssueForgeGateway = class {
|
|
348
|
+
constructor(client, config) {
|
|
349
|
+
this.client = client;
|
|
350
|
+
this.config = config;
|
|
351
|
+
this.assets = new GithubAppRepoContentGateway(client, config);
|
|
352
|
+
}
|
|
353
|
+
assets;
|
|
354
|
+
/**
|
|
355
|
+
* @override
|
|
356
|
+
*/
|
|
357
|
+
async createIssue(input) {
|
|
358
|
+
const first = await this.postIssue(input, input.labels);
|
|
359
|
+
if (first.ok) {
|
|
360
|
+
return this.readCreated(first);
|
|
361
|
+
}
|
|
362
|
+
if (first.status === 422 && input.labels.length > 0) {
|
|
363
|
+
const retry = await this.postIssue(input, []);
|
|
364
|
+
if (retry.ok) {
|
|
365
|
+
return this.readCreated(retry);
|
|
366
|
+
}
|
|
367
|
+
throw await this.client.toError("create issue", retry);
|
|
368
|
+
}
|
|
369
|
+
throw await this.client.toError("create issue", first);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* @override
|
|
373
|
+
*/
|
|
374
|
+
async createComment(issue, body) {
|
|
375
|
+
const response = await this.client.request(
|
|
376
|
+
this.config,
|
|
377
|
+
`${this.repoPath()}/issues/${String(issue.issueNumber)}/comments`,
|
|
378
|
+
{ method: "POST", body: { body } }
|
|
379
|
+
);
|
|
380
|
+
if (!response.ok) {
|
|
381
|
+
throw await this.client.toError("create comment", response);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* @override
|
|
386
|
+
*/
|
|
387
|
+
async listComments(issue) {
|
|
388
|
+
const comments = [];
|
|
389
|
+
let page = 1;
|
|
390
|
+
for (; ; ) {
|
|
391
|
+
const response = await this.client.request(
|
|
392
|
+
this.config,
|
|
393
|
+
`${this.repoPath()}/issues/${String(issue.issueNumber)}/comments?per_page=${String(COMMENTS_PAGE_SIZE)}&page=${String(page)}`,
|
|
394
|
+
{ method: "GET" }
|
|
395
|
+
);
|
|
396
|
+
if (!response.ok) {
|
|
397
|
+
throw await this.client.toError("list comments", response);
|
|
398
|
+
}
|
|
399
|
+
const json = await response.json();
|
|
400
|
+
for (const item of json) {
|
|
401
|
+
if (typeof item.body === "string") {
|
|
402
|
+
comments.push({ body: item.body });
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (json.length < COMMENTS_PAGE_SIZE) {
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
page += 1;
|
|
409
|
+
}
|
|
410
|
+
return comments;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* @override
|
|
414
|
+
*/
|
|
415
|
+
async uploadAsset(input) {
|
|
416
|
+
const branch = input.branch?.trim() || "feedback-assets";
|
|
417
|
+
await this.assets.uploadFile({
|
|
418
|
+
path: input.path,
|
|
419
|
+
contentBase64: input.contentBase64,
|
|
420
|
+
branch,
|
|
421
|
+
message: input.message?.trim() || `chore(feedback): upload ${input.path}`
|
|
422
|
+
});
|
|
423
|
+
const encodedPath = input.path.split("/").filter((segment) => segment.length > 0).map((segment) => encodeURIComponent(segment)).join("/");
|
|
424
|
+
return {
|
|
425
|
+
url: `https://github.com/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}/raw/${encodeURIComponent(branch)}/${encodedPath}`
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
postIssue(input, labels) {
|
|
429
|
+
return this.client.request(this.config, `${this.repoPath()}/issues`, {
|
|
430
|
+
method: "POST",
|
|
431
|
+
body: {
|
|
432
|
+
title: input.title,
|
|
433
|
+
body: input.body,
|
|
434
|
+
...labels.length > 0 ? { labels: [...labels] } : {}
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
async readCreated(response) {
|
|
439
|
+
const json = await response.json();
|
|
440
|
+
if (typeof json.number !== "number" || typeof json.html_url !== "string") {
|
|
441
|
+
throw new IssueForgeError(
|
|
442
|
+
"create issue: unexpected response",
|
|
443
|
+
response.status
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
issueNumber: json.number,
|
|
448
|
+
issueUrl: json.html_url,
|
|
449
|
+
...typeof json.node_id === "string" ? { resourceKey: json.node_id } : {}
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
repoPath() {
|
|
453
|
+
return `/repos/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}`;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// src/github/GithubWebhookVerifier.ts
|
|
458
|
+
var import_crypto = require("crypto");
|
|
459
|
+
var SIGNATURE_PREFIX = "sha256=";
|
|
460
|
+
var GithubWebhookVerifier = class {
|
|
461
|
+
constructor(secret) {
|
|
462
|
+
this.secret = secret;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* @override
|
|
466
|
+
*/
|
|
467
|
+
async verify(rawBody, signatureHeader) {
|
|
468
|
+
if (signatureHeader == null || signatureHeader.trim() === "") {
|
|
469
|
+
return { ok: false, reason: "signature_header_missing" };
|
|
470
|
+
}
|
|
471
|
+
if (!signatureHeader.startsWith(SIGNATURE_PREFIX)) {
|
|
472
|
+
return { ok: false, reason: "signature_header_invalid" };
|
|
473
|
+
}
|
|
474
|
+
const secret = this.secret.trim();
|
|
475
|
+
if (!secret) {
|
|
476
|
+
return { ok: false, reason: "secret_not_configured" };
|
|
477
|
+
}
|
|
478
|
+
const expected = Buffer.from(
|
|
479
|
+
SIGNATURE_PREFIX + (0, import_crypto.createHmac)("sha256", secret).update(rawBody, "utf8").digest("hex"),
|
|
480
|
+
"utf8"
|
|
481
|
+
);
|
|
482
|
+
const received = Buffer.from(signatureHeader, "utf8");
|
|
483
|
+
if (expected.length !== received.length || !(0, import_crypto.timingSafeEqual)(expected, received)) {
|
|
484
|
+
return { ok: false, reason: "digest_mismatch" };
|
|
485
|
+
}
|
|
486
|
+
return { ok: true };
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
// src/github/createGithubAppForge.ts
|
|
491
|
+
function createGithubAppClient(options) {
|
|
492
|
+
return new GithubAppClient(options);
|
|
493
|
+
}
|
|
494
|
+
function createGithubAppIssueForge(client, config) {
|
|
495
|
+
return new GithubAppIssueForgeGateway(client, config);
|
|
496
|
+
}
|
|
497
|
+
function createGithubAppRepoContent(client, config) {
|
|
498
|
+
return new GithubAppRepoContentGateway(client, config);
|
|
499
|
+
}
|
|
500
|
+
function createGithubWebhookVerifier(secret) {
|
|
501
|
+
return new GithubWebhookVerifier(secret);
|
|
502
|
+
}
|
|
503
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
504
|
+
0 && (module.exports = {
|
|
505
|
+
GithubAppClient,
|
|
506
|
+
GithubAppIssueForgeGateway,
|
|
507
|
+
GithubAppRepoContentGateway,
|
|
508
|
+
GithubWebhookVerifier,
|
|
509
|
+
IssueForgeError,
|
|
510
|
+
createGithubAppClient,
|
|
511
|
+
createGithubAppIssueForge,
|
|
512
|
+
createGithubAppRepoContent,
|
|
513
|
+
createGithubWebhookVerifier
|
|
514
|
+
});
|
|
515
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors/IssueForgeError.ts","../src/github/GithubAppClient.ts","../src/github/GithubAppRepoContentGateway.ts","../src/github/GithubAppIssueForgeGateway.ts","../src/github/GithubWebhookVerifier.ts","../src/github/createGithubAppForge.ts"],"sourcesContent":["export type {\n ForgeAssetUploadedType,\n ForgeAssetUploadInputType,\n ForgeIssueCreatedType,\n ForgeIssueCreateInputType,\n ForgeIssueRefType,\n GithubAppAuthConfigType,\n IssueForgeTokenCacheInterface,\n IssueWebhookVerifyResultType\n} from './types/IssueForgeTypes';\n\nexport type {\n ForgeIssueCommentType,\n IssueForgeGatewayInterface\n} from './interfaces/IssueForgeGatewayInterface';\nexport type {\n IssueForgeRepoContentInterface,\n IssueForgeRepoFileType,\n IssueForgeRepoFileUploadedType,\n IssueForgeRepoFileUploadInputType\n} from './interfaces/IssueForgeRepoContentInterface';\nexport type { IssueWebhookVerifierInterface } from './interfaces/IssueWebhookVerifierInterface';\n\nexport { IssueForgeError } from './errors/IssueForgeError';\n\nexport { GithubAppClient } from './github/GithubAppClient';\nexport type {\n GithubAppClientOptionsType,\n GithubAppRequestType\n} from './github/GithubAppClient';\nexport { GithubAppIssueForgeGateway } from './github/GithubAppIssueForgeGateway';\nexport { GithubAppRepoContentGateway } from './github/GithubAppRepoContentGateway';\nexport { GithubWebhookVerifier } from './github/GithubWebhookVerifier';\nexport {\n createGithubAppClient,\n createGithubAppIssueForge,\n createGithubAppRepoContent,\n createGithubWebhookVerifier\n} from './github/createGithubAppForge';\nexport type { CreateGithubAppClientOptionsType } from './github/createGithubAppForge';\n","/**\n * Forge API 调用失败(换票、建 Issue、上传等)。\n */\nexport class IssueForgeError extends Error {\n public readonly code = 'ISSUE_FORGE_FAILED' as const;\n /** HTTP 状态码;网络错误等无响应时为 null */\n public readonly status: number | null;\n\n constructor(message: string, status: number | null) {\n super(message);\n this.name = 'IssueForgeError';\n this.status = status;\n }\n}\n","import jwt from 'jsonwebtoken';\nimport { IssueForgeError } from '../errors/IssueForgeError';\nimport type {\n GithubAppAuthConfigType,\n IssueForgeTokenCacheInterface\n} from '../types/IssueForgeTypes';\n\nconst GITHUB_API = 'https://api.github.com';\nconst GITHUB_API_VERSION = '2022-11-28';\nconst DEFAULT_USER_AGENT = 'brain-toolkit-issue-forge';\n/** Contents 大图 PUT / 弱网下 10s 易超时;评论与普通 GET 也共用此上限 */\nconst REQUEST_TIMEOUT_MS = 60_000;\nconst APP_JWT_TTL_SEC = 9 * 60;\nconst APP_JWT_CLOCK_SKEW_SEC = 60;\nconst TOKEN_REFRESH_MARGIN_MS = 2 * 60 * 1000;\n\ntype CachedTokenType = {\n readonly token: string;\n};\n\nexport type GithubAppRequestType = {\n readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH';\n readonly body?: unknown;\n readonly accept?: string;\n};\n\nexport type GithubAppClientOptionsType = {\n readonly cache: IssueForgeTokenCacheInterface;\n readonly userAgent?: string;\n};\n\n/**\n * 以 GitHub App installation 身份调用 REST API(低层;config 仍按次传入以便多仓复用同一 client)。\n */\nexport class GithubAppClient {\n protected readonly cache: IssueForgeTokenCacheInterface;\n protected readonly userAgent: string;\n\n constructor(options: GithubAppClientOptionsType) {\n this.cache = options.cache;\n this.userAgent = options.userAgent?.trim() || DEFAULT_USER_AGENT;\n }\n\n public async request(\n config: GithubAppAuthConfigType,\n path: string,\n init: GithubAppRequestType\n ): Promise<Response> {\n const token = await this.getInstallationToken(config);\n const headers: Record<string, string> = this.headers(`Bearer ${token}`);\n if (init.accept) {\n headers.Accept = init.accept;\n }\n if (init.body !== undefined) {\n headers['Content-Type'] = 'application/json';\n }\n const response = await this.send(`${GITHUB_API}${path}`, {\n method: init.method,\n headers,\n ...(init.body !== undefined ? { body: JSON.stringify(init.body) } : {})\n });\n if (response.status === 401 || response.status === 403) {\n await this.cache.removeItem(this.tokenCacheKey(config));\n }\n return response;\n }\n\n public async toError(\n stage: string,\n response: Response\n ): Promise<IssueForgeError> {\n let detail = '';\n try {\n const json = (await response.json()) as { readonly message?: unknown };\n detail = typeof json.message === 'string' ? json.message : '';\n } catch {\n detail = '';\n }\n return new IssueForgeError(\n `${stage}: HTTP ${String(response.status)}${detail ? ` ${detail}` : ''}`,\n response.status\n );\n }\n\n protected async getInstallationToken(\n config: GithubAppAuthConfigType\n ): Promise<string> {\n const cacheKey = this.tokenCacheKey(config);\n const cached = await this.cache.getItem<CachedTokenType>(cacheKey);\n if (cached?.token) {\n return cached.token;\n }\n\n const response = await this.send(\n `${GITHUB_API}/app/installations/${encodeURIComponent(config.installationId)}/access_tokens`,\n {\n method: 'POST',\n headers: this.headers(`Bearer ${this.signAppJwt(config)}`)\n }\n );\n if (!response.ok) {\n throw await this.toError('installation token', response);\n }\n const json = (await response.json()) as {\n readonly token?: unknown;\n readonly expires_at?: unknown;\n };\n if (typeof json.token !== 'string' || !json.token) {\n throw new IssueForgeError(\n 'installation token: empty token',\n response.status\n );\n }\n const expiresAtMs =\n typeof json.expires_at === 'string'\n ? Date.parse(json.expires_at)\n : Number.NaN;\n const ttlMs = Number.isFinite(expiresAtMs)\n ? expiresAtMs - Date.now() - TOKEN_REFRESH_MARGIN_MS\n : 0;\n if (ttlMs > 0) {\n await this.cache.setItem<CachedTokenType>(\n cacheKey,\n { token: json.token },\n { ttlMs }\n );\n }\n return json.token;\n }\n\n protected signAppJwt(config: GithubAppAuthConfigType): string {\n const nowSec = Math.floor(Date.now() / 1000);\n try {\n return jwt.sign(\n {\n iat: nowSec - APP_JWT_CLOCK_SKEW_SEC,\n exp: nowSec + APP_JWT_TTL_SEC,\n iss: config.appId\n },\n this.normalizePrivateKey(config.privateKey),\n { algorithm: 'RS256' }\n );\n } catch (error) {\n throw new IssueForgeError(\n `invalid GitHub App private key: ${error instanceof Error ? error.message : String(error)}`,\n null\n );\n }\n }\n\n protected normalizePrivateKey(raw: string): string {\n return raw.replace(/\\\\n/g, '\\n').replace(/\\r\\n/g, '\\n').trim();\n }\n\n protected async send(url: string, init: RequestInit): Promise<Response> {\n try {\n return await fetch(url, {\n ...init,\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)\n });\n } catch (error) {\n throw new IssueForgeError(\n `GitHub request failed: ${error instanceof Error ? error.message : String(error)}`,\n null\n );\n }\n }\n\n protected headers(authorization: string): Record<string, string> {\n return {\n Accept: 'application/vnd.github+json',\n Authorization: authorization,\n 'User-Agent': this.userAgent,\n 'X-GitHub-Api-Version': GITHUB_API_VERSION\n };\n }\n\n protected tokenCacheKey(config: GithubAppAuthConfigType): string {\n return `issue-forge:github:installation-token:${config.appId}:${config.installationId}`;\n }\n}\n","import { IssueForgeError } from '../errors/IssueForgeError';\nimport type {\n IssueForgeRepoContentInterface,\n IssueForgeRepoFileType,\n IssueForgeRepoFileUploadedType,\n IssueForgeRepoFileUploadInputType\n} from '../interfaces/IssueForgeRepoContentInterface';\nimport type { GithubAppAuthConfigType } from '../types/IssueForgeTypes';\nimport type { GithubAppClient } from './GithubAppClient';\n\nconst ACCEPT_RAW = 'application/vnd.github.raw+json';\n\n/**\n * GitHub App 仓库内容网关(形态 B:构造时绑定 auth/config)。\n */\nexport class GithubAppRepoContentGateway\n implements IssueForgeRepoContentInterface\n{\n constructor(\n protected readonly client: GithubAppClient,\n protected readonly config: GithubAppAuthConfigType\n ) {}\n\n /**\n * @override\n */\n public async readTextFile(path: string): Promise<string | null> {\n const response = await this.client.request(\n this.config,\n this.contentsPath(path),\n { method: 'GET', accept: ACCEPT_RAW }\n );\n if (response.status === 404) {\n return null;\n }\n if (!response.ok) {\n throw await this.client.toError('read file', response);\n }\n return response.text();\n }\n\n /**\n * @override\n */\n public async hasFile(path: string, branch: string): Promise<boolean> {\n const response = await this.client.request(\n this.config,\n `${this.contentsPath(path)}?ref=${encodeURIComponent(branch)}`,\n { method: 'GET' }\n );\n if (response.status === 404) {\n return false;\n }\n if (!response.ok) {\n throw await this.client.toError('has file', response);\n }\n return true;\n }\n\n /**\n * @override\n */\n public async ensureBranch(\n branch: string,\n initialFile: IssueForgeRepoFileType\n ): Promise<void> {\n const found = await this.client.request(\n this.config,\n `${this.repoPath()}/git/ref/heads/${this.encodePath(branch)}`,\n { method: 'GET' }\n );\n if (found.ok) {\n return;\n }\n if (found.status !== 404) {\n throw await this.client.toError('get branch', found);\n }\n\n const treeSha = await this.postForSha('create tree', '/git/trees', {\n tree: [\n {\n path: initialFile.path,\n mode: '100644',\n type: 'blob',\n content: initialFile.content\n }\n ]\n });\n const commitSha = await this.postForSha('create commit', '/git/commits', {\n message: `chore: 初始化 ${branch} 分支`,\n tree: treeSha,\n parents: []\n });\n const created = await this.client.request(\n this.config,\n `${this.repoPath()}/git/refs`,\n {\n method: 'POST',\n body: { ref: `refs/heads/${branch}`, sha: commitSha }\n }\n );\n if (!created.ok && created.status !== 422) {\n throw await this.client.toError('create branch', created);\n }\n }\n\n /**\n * @override\n */\n public async uploadFile(\n input: IssueForgeRepoFileUploadInputType\n ): Promise<IssueForgeRepoFileUploadedType> {\n const response = await this.client.request(\n this.config,\n this.contentsPath(input.path),\n {\n method: 'PUT',\n body: {\n message: input.message,\n content: input.contentBase64,\n branch: input.branch\n }\n }\n );\n if (response.ok) {\n const json = (await response.json()) as {\n readonly content?: { readonly html_url?: unknown };\n };\n return { url: this.requireHtmlUrl(json.content?.html_url, response) };\n }\n if (response.status === 422) {\n return this.readExisting(input);\n }\n throw await this.client.toError('upload file', response);\n }\n\n protected async readExisting(\n input: IssueForgeRepoFileUploadInputType\n ): Promise<IssueForgeRepoFileUploadedType> {\n const response = await this.client.request(\n this.config,\n `${this.contentsPath(input.path)}?ref=${encodeURIComponent(input.branch)}`,\n { method: 'GET' }\n );\n if (!response.ok) {\n throw await this.client.toError('upload file', response);\n }\n const json = (await response.json()) as { readonly html_url?: unknown };\n return { url: this.requireHtmlUrl(json.html_url, response) };\n }\n\n protected async postForSha(\n stage: string,\n path: string,\n body: unknown\n ): Promise<string> {\n const response = await this.client.request(\n this.config,\n `${this.repoPath()}${path}`,\n { method: 'POST', body }\n );\n if (!response.ok) {\n throw await this.client.toError(stage, response);\n }\n const json = (await response.json()) as { readonly sha?: unknown };\n if (typeof json.sha !== 'string' || !json.sha) {\n throw new IssueForgeError(\n `${stage}: unexpected response`,\n response.status\n );\n }\n return json.sha;\n }\n\n protected requireHtmlUrl(value: unknown, response: Response): string {\n if (typeof value !== 'string' || !value) {\n throw new IssueForgeError(\n 'upload file: unexpected response',\n response.status\n );\n }\n return value;\n }\n\n protected contentsPath(path: string): string {\n return `${this.repoPath()}/contents/${this.encodePath(path)}`;\n }\n\n protected encodePath(path: string): string {\n return path\n .split('/')\n .filter((segment) => segment.length > 0)\n .map((segment) => encodeURIComponent(segment))\n .join('/');\n }\n\n protected repoPath(): string {\n return `/repos/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}`;\n }\n}\n","import { IssueForgeError } from '../errors/IssueForgeError';\nimport type {\n ForgeIssueCommentType,\n IssueForgeGatewayInterface\n} from '../interfaces/IssueForgeGatewayInterface';\nimport type {\n ForgeAssetUploadedType,\n ForgeAssetUploadInputType,\n ForgeIssueCreatedType,\n ForgeIssueCreateInputType,\n ForgeIssueRefType,\n GithubAppAuthConfigType\n} from '../types/IssueForgeTypes';\nimport type { GithubAppClient } from './GithubAppClient';\nimport { GithubAppRepoContentGateway } from './GithubAppRepoContentGateway';\n\nconst COMMENTS_PAGE_SIZE = 100;\n\n/**\n * GitHub App Issue 网关(形态 B:构造时绑定 auth/config)。\n */\nexport class GithubAppIssueForgeGateway implements IssueForgeGatewayInterface {\n protected readonly assets: GithubAppRepoContentGateway;\n\n constructor(\n protected readonly client: GithubAppClient,\n protected readonly config: GithubAppAuthConfigType\n ) {\n this.assets = new GithubAppRepoContentGateway(client, config);\n }\n\n /**\n * @override\n */\n public async createIssue(\n input: ForgeIssueCreateInputType\n ): Promise<ForgeIssueCreatedType> {\n const first = await this.postIssue(input, input.labels);\n if (first.ok) {\n return this.readCreated(first);\n }\n if (first.status === 422 && input.labels.length > 0) {\n const retry = await this.postIssue(input, []);\n if (retry.ok) {\n return this.readCreated(retry);\n }\n throw await this.client.toError('create issue', retry);\n }\n throw await this.client.toError('create issue', first);\n }\n\n /**\n * @override\n */\n public async createComment(\n issue: ForgeIssueRefType,\n body: string\n ): Promise<void> {\n const response = await this.client.request(\n this.config,\n `${this.repoPath()}/issues/${String(issue.issueNumber)}/comments`,\n { method: 'POST', body: { body } }\n );\n if (!response.ok) {\n throw await this.client.toError('create comment', response);\n }\n }\n\n /**\n * @override\n */\n public async listComments(\n issue: ForgeIssueRefType\n ): Promise<readonly ForgeIssueCommentType[]> {\n const comments: ForgeIssueCommentType[] = [];\n let page = 1;\n for (;;) {\n const response = await this.client.request(\n this.config,\n `${this.repoPath()}/issues/${String(issue.issueNumber)}/comments?per_page=${String(COMMENTS_PAGE_SIZE)}&page=${String(page)}`,\n { method: 'GET' }\n );\n if (!response.ok) {\n throw await this.client.toError('list comments', response);\n }\n const json = (await response.json()) as ReadonlyArray<{\n readonly body?: unknown;\n }>;\n for (const item of json) {\n if (typeof item.body === 'string') {\n comments.push({ body: item.body });\n }\n }\n if (json.length < COMMENTS_PAGE_SIZE) {\n break;\n }\n page += 1;\n }\n return comments;\n }\n\n /**\n * @override\n */\n public async uploadAsset(\n input: ForgeAssetUploadInputType\n ): Promise<ForgeAssetUploadedType> {\n const branch = input.branch?.trim() || 'feedback-assets';\n await this.assets.uploadFile({\n path: input.path,\n contentBase64: input.contentBase64,\n branch,\n message: input.message?.trim() || `chore(feedback): upload ${input.path}`\n });\n const encodedPath = input.path\n .split('/')\n .filter((segment) => segment.length > 0)\n .map((segment) => encodeURIComponent(segment))\n .join('/');\n return {\n url: `https://github.com/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}/raw/${encodeURIComponent(branch)}/${encodedPath}`\n };\n }\n\n protected postIssue(\n input: ForgeIssueCreateInputType,\n labels: readonly string[]\n ): Promise<Response> {\n return this.client.request(this.config, `${this.repoPath()}/issues`, {\n method: 'POST',\n body: {\n title: input.title,\n body: input.body,\n ...(labels.length > 0 ? { labels: [...labels] } : {})\n }\n });\n }\n\n protected async readCreated(\n response: Response\n ): Promise<ForgeIssueCreatedType> {\n const json = (await response.json()) as {\n readonly number?: unknown;\n readonly html_url?: unknown;\n readonly node_id?: unknown;\n };\n if (typeof json.number !== 'number' || typeof json.html_url !== 'string') {\n throw new IssueForgeError(\n 'create issue: unexpected response',\n response.status\n );\n }\n return {\n issueNumber: json.number,\n issueUrl: json.html_url,\n ...(typeof json.node_id === 'string'\n ? { resourceKey: json.node_id }\n : {})\n };\n }\n\n protected repoPath(): string {\n return `/repos/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}`;\n }\n}\n","import { createHmac, timingSafeEqual } from 'crypto';\nimport type { IssueWebhookVerifierInterface } from '../interfaces/IssueWebhookVerifierInterface';\nimport type { IssueWebhookVerifyResultType } from '../types/IssueForgeTypes';\n\nconst SIGNATURE_PREFIX = 'sha256=';\n\n/**\n * GitHub Webhook HMAC-SHA256 验签(形态 B:构造时绑定 secret)。\n */\nexport class GithubWebhookVerifier implements IssueWebhookVerifierInterface {\n constructor(protected readonly secret: string) {}\n\n /**\n * @override\n */\n public async verify(\n rawBody: string,\n signatureHeader: string | null\n ): Promise<IssueWebhookVerifyResultType> {\n if (signatureHeader == null || signatureHeader.trim() === '') {\n return { ok: false, reason: 'signature_header_missing' };\n }\n if (!signatureHeader.startsWith(SIGNATURE_PREFIX)) {\n return { ok: false, reason: 'signature_header_invalid' };\n }\n const secret = this.secret.trim();\n if (!secret) {\n return { ok: false, reason: 'secret_not_configured' };\n }\n\n const expected = Buffer.from(\n SIGNATURE_PREFIX +\n createHmac('sha256', secret).update(rawBody, 'utf8').digest('hex'),\n 'utf8'\n );\n const received = Buffer.from(signatureHeader, 'utf8');\n if (\n expected.length !== received.length ||\n !timingSafeEqual(expected, received)\n ) {\n return { ok: false, reason: 'digest_mismatch' };\n }\n return { ok: true };\n }\n}\n","import type { IssueForgeGatewayInterface } from '../interfaces/IssueForgeGatewayInterface';\nimport type { IssueForgeRepoContentInterface } from '../interfaces/IssueForgeRepoContentInterface';\nimport type { IssueWebhookVerifierInterface } from '../interfaces/IssueWebhookVerifierInterface';\nimport type {\n GithubAppAuthConfigType,\n IssueForgeTokenCacheInterface\n} from '../types/IssueForgeTypes';\nimport { GithubAppClient } from './GithubAppClient';\nimport { GithubAppIssueForgeGateway } from './GithubAppIssueForgeGateway';\nimport { GithubAppRepoContentGateway } from './GithubAppRepoContentGateway';\nimport { GithubWebhookVerifier } from './GithubWebhookVerifier';\n\nexport type CreateGithubAppClientOptionsType = {\n readonly cache: IssueForgeTokenCacheInterface;\n readonly userAgent?: string;\n};\n\n/**\n * 创建可复用的 GitHub App HTTP 客户端(多仓可共用,按次传 config)。\n */\nexport function createGithubAppClient(\n options: CreateGithubAppClientOptionsType\n): GithubAppClient {\n return new GithubAppClient(options);\n}\n\n/**\n * 绑定 config 的 Issue 网关(形态 B)。\n */\nexport function createGithubAppIssueForge(\n client: GithubAppClient,\n config: GithubAppAuthConfigType\n): IssueForgeGatewayInterface {\n return new GithubAppIssueForgeGateway(client, config);\n}\n\n/**\n * 绑定 config 的仓库内容网关(形态 B)。\n */\nexport function createGithubAppRepoContent(\n client: GithubAppClient,\n config: GithubAppAuthConfigType\n): IssueForgeRepoContentInterface {\n return new GithubAppRepoContentGateway(client, config);\n}\n\n/**\n * 绑定 webhook secret 的验签器(形态 B)。\n */\nexport function createGithubWebhookVerifier(\n secret: string\n): IssueWebhookVerifierInterface {\n return new GithubWebhookVerifier(secret);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzB,OAAO;AAAA;AAAA,EAEP;AAAA,EAEhB,YAAY,SAAiB,QAAuB;AAClD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;;;ACbA,0BAAgB;AAOhB,IAAM,aAAa;AACnB,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAE3B,IAAM,qBAAqB;AAC3B,IAAM,kBAAkB,IAAI;AAC5B,IAAM,yBAAyB;AAC/B,IAAM,0BAA0B,IAAI,KAAK;AAoBlC,IAAM,kBAAN,MAAsB;AAAA,EACR;AAAA,EACA;AAAA,EAEnB,YAAY,SAAqC;AAC/C,SAAK,QAAQ,QAAQ;AACrB,SAAK,YAAY,QAAQ,WAAW,KAAK,KAAK;AAAA,EAChD;AAAA,EAEA,MAAa,QACX,QACA,MACA,MACmB;AACnB,UAAM,QAAQ,MAAM,KAAK,qBAAqB,MAAM;AACpD,UAAM,UAAkC,KAAK,QAAQ,UAAU,KAAK,EAAE;AACtE,QAAI,KAAK,QAAQ;AACf,cAAQ,SAAS,KAAK;AAAA,IACxB;AACA,QAAI,KAAK,SAAS,QAAW;AAC3B,cAAQ,cAAc,IAAI;AAAA,IAC5B;AACA,UAAM,WAAW,MAAM,KAAK,KAAK,GAAG,UAAU,GAAG,IAAI,IAAI;AAAA,MACvD,QAAQ,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