@dual-os/github-api 6.0.3 → 6.0.5

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.
Files changed (66) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +35 -0
  3. package/Runner.js +342 -576
  4. package/Runner.js.map +5 -9
  5. package/bundle-inventory.json +1 -1
  6. package/dist/auth.d.ts +13 -1
  7. package/dist/auth.d.ts.map +1 -1
  8. package/dist/auth.js +5 -3
  9. package/dist/auth.js.map +1 -1
  10. package/dist/channel/github-app-client.d.ts +67 -0
  11. package/dist/channel/github-app-client.d.ts.map +1 -0
  12. package/dist/channel/github-app-client.js +18 -0
  13. package/dist/channel/github-app-client.js.map +9 -0
  14. package/dist/channel/github-app-definition.d.ts +190 -0
  15. package/dist/channel/github-app-definition.d.ts.map +1 -0
  16. package/dist/channel/github-app-definition.js +32 -0
  17. package/dist/channel/github-app-definition.js.map +9 -0
  18. package/dist/channel/github-app.d.ts +126 -0
  19. package/dist/channel/github-app.d.ts.map +1 -0
  20. package/dist/channel/github-app.js +17 -0
  21. package/dist/channel/github-app.js.map +9 -0
  22. package/dist/channel/internal/webhook.d.ts +38 -0
  23. package/dist/channel/internal/webhook.d.ts.map +1 -0
  24. package/dist/channel/internal/webhook.js +22 -0
  25. package/dist/channel/internal/webhook.js.map +9 -0
  26. package/dist/generated/http.js +7 -5
  27. package/dist/generated/http.js.map +1 -1
  28. package/dist/generated/operations.d.ts +1154 -1154
  29. package/dist/generated/operations.d.ts.map +1 -1
  30. package/dist/generated/operations.js +7 -5
  31. package/dist/generated/operations.js.map +1 -1
  32. package/dist/generated/plugin.js +14 -10515
  33. package/dist/generated/plugin.js.map +3 -4
  34. package/dist/plugin.d.ts +10 -0
  35. package/dist/plugin.d.ts.map +1 -0
  36. package/dist/plugin.js +33 -0
  37. package/dist/plugin.js.map +10 -0
  38. package/dist/triggers.d.ts +26 -2
  39. package/dist/triggers.d.ts.map +1 -1
  40. package/dist/triggers.js +8 -6
  41. package/dist/triggers.js.map +1 -1
  42. package/dual-plugin.json +1 -1
  43. package/package.json +1 -1
  44. package/{plugin-t4j28rxn.js → plugin-1b35jx9g.js} +6 -4
  45. package/{plugin-t4j28rxn.js.map → plugin-1b35jx9g.js.map} +2 -2
  46. package/plugin-2qqpmr67.js +108 -0
  47. package/plugin-2qqpmr67.js.map +10 -0
  48. package/{plugin-yzj02c6j.js → plugin-3ryytw13.js} +193 -308
  49. package/{plugin-yzj02c6j.js.map → plugin-3ryytw13.js.map} +5 -6
  50. package/{plugin-3mpmm6hc.js → plugin-5rkcrntd.js} +4 -4
  51. package/plugin-7hfrx1dg.js +167 -0
  52. package/plugin-7hfrx1dg.js.map +10 -0
  53. package/plugin-e0mt19z7.js +377 -0
  54. package/plugin-e0mt19z7.js.map +10 -0
  55. package/{plugin-ahctqzvj.js → plugin-gtd7vh23.js} +4 -4
  56. package/plugin-p1y3h7d7.js +10516 -0
  57. package/plugin-p1y3h7d7.js.map +10 -0
  58. package/plugin-p6f7n836.js +631 -0
  59. package/plugin-p6f7n836.js.map +12 -0
  60. package/plugin-r0m0v72b.js +156 -0
  61. package/plugin-r0m0v72b.js.map +10 -0
  62. package/{plugin-gajxsj3f.js → plugin-w0va8331.js} +2495 -2288
  63. package/{plugin-gajxsj3f.js.map → plugin-w0va8331.js.map} +12 -13
  64. /package/licenses/{@dual-os_sdk@0.8.1 → @dual-os_sdk@0.9.0}/LICENSE +0 -0
  65. /package/{plugin-3mpmm6hc.js.map → plugin-5rkcrntd.js.map} +0 -0
  66. /package/{plugin-ahctqzvj.js.map → plugin-gtd7vh23.js.map} +0 -0
@@ -0,0 +1,631 @@
1
+ // @bun
2
+ import {
3
+ pipeArguments,
4
+ dual,
5
+ pipe,
6
+ hash,
7
+ equals,
8
+ format,
9
+ NodeInspectSymbol,
10
+ toJson,
11
+ PipeInspectableProto,
12
+ withFiber,
13
+ none,
14
+ some,
15
+ isSome,
16
+ match2,
17
+ getOrElse,
18
+ orElse,
19
+ map,
20
+ flatMap,
21
+ Service,
22
+ merge,
23
+ getSuccess,
24
+ takeRight,
25
+ contains,
26
+ flatten,
27
+ filter2,
28
+ every,
29
+ fromInputUnsafe,
30
+ isFinite,
31
+ isZero,
32
+ zero,
33
+ infinity,
34
+ millis,
35
+ toMillis,
36
+ fiberJoin,
37
+ fiberInterrupt,
38
+ succeed2,
39
+ sync,
40
+ void_,
41
+ exitHasInterrupts,
42
+ updateContext,
43
+ contextWith,
44
+ onExitUnsafe,
45
+ forkUnsafe,
46
+ ClockRef,
47
+ isSuccess2,
48
+ effect,
49
+ currentTimeMillis,
50
+ min,
51
+ replace,
52
+ trim,
53
+ startsWith,
54
+ endsWith,
55
+ replaceAll,
56
+ forEach,
57
+ succeed5,
58
+ void_3,
59
+ gen,
60
+ fail5,
61
+ try_2,
62
+ fromOption2,
63
+ flatMap3,
64
+ asSome,
65
+ catchTag,
66
+ mapError2,
67
+ timeout,
68
+ provideService,
69
+ fnUntraced,
70
+ fn,
71
+ decode2,
72
+ encode3,
73
+ toEpochMillis,
74
+ decodeUnknownOption,
75
+ encodeEffect,
76
+ optionalKey,
77
+ Literal,
78
+ String3,
79
+ Struct,
80
+ ArraySchema,
81
+ NullOr,
82
+ Int,
83
+ Natural,
84
+ NonEmptyString,
85
+ fromJsonString,
86
+ DateTimeUtcFromString,
87
+ value2,
88
+ when,
89
+ orElse2,
90
+ exhaustive,
91
+ get3,
92
+ post,
93
+ patch,
94
+ del,
95
+ setHeaders,
96
+ bearerToken,
97
+ prependUrl,
98
+ setUrlParams,
99
+ bodyJsonUnsafe,
100
+ schemaBodyJson,
101
+ HttpClient,
102
+ mapRequest,
103
+ RequestInit,
104
+ AgentChannel_exports
105
+ } from "./plugin-w0va8331.js";
106
+ import {
107
+ apiVersion2,
108
+ Permission2
109
+ } from "./plugin-2qqpmr67.js";
110
+ import {
111
+ NumericId2
112
+ } from "./plugin-7hfrx1dg.js";
113
+
114
+ // ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/MutableHashMap.js
115
+ var TypeId = "~effect/MutableHashMap";
116
+ var MutableHashMapProto = {
117
+ [TypeId]: TypeId,
118
+ [Symbol.iterator]() {
119
+ return this.backing[Symbol.iterator]();
120
+ },
121
+ toString() {
122
+ return `MutableHashMap(${format(Array.from(this))})`;
123
+ },
124
+ toJSON() {
125
+ return {
126
+ _id: "MutableHashMap",
127
+ values: toJson(Array.from(this))
128
+ };
129
+ },
130
+ [NodeInspectSymbol]() {
131
+ return this.toJSON();
132
+ },
133
+ pipe() {
134
+ return pipeArguments(this, arguments);
135
+ }
136
+ };
137
+ var empty = () => {
138
+ const self = Object.create(MutableHashMapProto);
139
+ self.backing = new Map;
140
+ self.buckets = new Map;
141
+ return self;
142
+ };
143
+ var make = (...entries) => fromIterable(entries);
144
+ var fromIterable = (entries) => {
145
+ const self = empty();
146
+ for (const [key, value] of entries) {
147
+ set(self, key, value);
148
+ }
149
+ return self;
150
+ };
151
+ var get = /* @__PURE__ */ dual(2, (self, key) => {
152
+ if (self.backing.has(key)) {
153
+ return some(self.backing.get(key));
154
+ } else if (isSimpleKey(key)) {
155
+ return none();
156
+ }
157
+ const hash2 = hash(key);
158
+ const bucket = self.buckets.get(hash2);
159
+ if (bucket === undefined) {
160
+ return none();
161
+ }
162
+ return getFromBucket(self, bucket, key);
163
+ });
164
+ var isSimpleKey = (u) => typeof u !== "object" && typeof u !== "function";
165
+ var getFromBucket = (self, bucket, key) => {
166
+ for (let i = 0, len = bucket.length;i < len; i++) {
167
+ if (equals(key, bucket[i])) {
168
+ const refKey = bucket[i];
169
+ return some(self.backing.get(refKey));
170
+ }
171
+ }
172
+ return none();
173
+ };
174
+ var set = /* @__PURE__ */ dual(3, (self, key, value) => {
175
+ if (self.backing.has(key) || isSimpleKey(key)) {
176
+ self.backing.set(key, value);
177
+ return self;
178
+ }
179
+ const hash2 = hash(key);
180
+ const bucket = self.buckets.get(hash2);
181
+ if (bucket === undefined) {
182
+ self.buckets.set(hash2, [key]);
183
+ self.backing.set(key, value);
184
+ return self;
185
+ }
186
+ let refKey = getRefKey(bucket, key);
187
+ if (refKey === undefined) {
188
+ bucket.push(key);
189
+ refKey = key;
190
+ }
191
+ self.backing.set(refKey, value);
192
+ return self;
193
+ });
194
+ var getRefKey = (bucket, key) => {
195
+ for (let i = 0, len = bucket.length;i < len; i++) {
196
+ if (equals(key, bucket[i])) {
197
+ return bucket[i];
198
+ }
199
+ }
200
+ };
201
+ var remove = /* @__PURE__ */ dual(2, (self, key_) => {
202
+ if (isSimpleKey(key_)) {
203
+ self.backing.delete(key_);
204
+ return self;
205
+ }
206
+ const hash2 = hash(key_);
207
+ const bucket = self.buckets.get(hash2);
208
+ if (bucket === undefined) {
209
+ return self;
210
+ }
211
+ for (let i = 0, len = bucket.length;i < len; i++) {
212
+ const bkey = bucket[i];
213
+ if (bkey === key_ || equals(key_, bkey)) {
214
+ self.backing.delete(bkey);
215
+ bucket.splice(i, 1);
216
+ break;
217
+ }
218
+ }
219
+ if (bucket.length === 0) {
220
+ self.buckets.delete(hash2);
221
+ }
222
+ return self;
223
+ });
224
+ var size = (self) => self.backing.size;
225
+
226
+ // ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/Cache.js
227
+ var TypeId2 = "~effect/Cache";
228
+ var makeWith = (lookup, options) => contextWith((context) => {
229
+ const self = Object.create(Proto);
230
+ self.lookup = (key) => updateContext(lookup(key), (input) => merge(context, input));
231
+ self.map = make();
232
+ self.capacity = options.capacity;
233
+ self.timeToLive = options.timeToLive ? (exit, key) => fromInputUnsafe(options.timeToLive(exit, key)) : defaultTimeToLive;
234
+ return succeed2(self);
235
+ });
236
+ var Proto = {
237
+ ...PipeInspectableProto,
238
+ [TypeId2]: TypeId2,
239
+ toJSON() {
240
+ return {
241
+ _id: "Cache",
242
+ capacity: this.capacity,
243
+ map: this.map
244
+ };
245
+ }
246
+ };
247
+ var defaultTimeToLive = (_, _key) => infinity;
248
+ var get2 = /* @__PURE__ */ dual(2, (self, key) => withFiber((fiber) => {
249
+ const oentry = get(self.map, key);
250
+ if (isSome(oentry)) {
251
+ remove(self.map, key);
252
+ if (!hasExpired(oentry.value, fiber)) {
253
+ set(self.map, key, oentry.value);
254
+ return oentry.value.await(fiber);
255
+ }
256
+ }
257
+ const entry = new EntryImpl(fiber, self.lookup(key));
258
+ entry.onInterrupt = () => removeEntry(self, key, entry);
259
+ let skipCache = false;
260
+ entry.fiber.addObserver((exit) => {
261
+ entry.onInterrupt = undefined;
262
+ if (exitHasInterrupts(exit)) {
263
+ removeEntry(self, key, entry);
264
+ return;
265
+ }
266
+ const ttl = self.timeToLive(exit, key);
267
+ if (isZero(ttl)) {
268
+ skipCache = true;
269
+ removeEntry(self, key, entry);
270
+ } else if (isFinite(ttl)) {
271
+ entry.expiresAt = fiber.getRef(ClockRef).currentTimeMillisUnsafe() + toMillis(ttl);
272
+ }
273
+ });
274
+ const exit = entry.fiber.pollUnsafe();
275
+ if (!skipCache && (exit === undefined || !exitHasInterrupts(exit))) {
276
+ set(self.map, key, entry);
277
+ }
278
+ if (Number.isFinite(self.capacity)) {
279
+ checkCapacity(self);
280
+ }
281
+ return entry.await(fiber);
282
+ }));
283
+
284
+ class EntryImpl {
285
+ expiresAt;
286
+ awaiters;
287
+ fiber;
288
+ onInterrupt;
289
+ constructor(parent, valueEffect) {
290
+ this.fiber = forkUnsafe(parent, valueEffect, true, true);
291
+ this.awaiters = 0;
292
+ this.expiresAt = undefined;
293
+ }
294
+ await(fiber) {
295
+ if (fiber === undefined)
296
+ return withFiber((fiber) => this.await(fiber));
297
+ const exit = this.fiber.pollUnsafe();
298
+ if (exit)
299
+ return exit;
300
+ this.awaiters++;
301
+ onExitUnsafe(fiber, () => {
302
+ this.awaiters--;
303
+ if (this.awaiters > 0 || this.fiber.pollUnsafe())
304
+ return void_;
305
+ this.onInterrupt?.();
306
+ return fiberInterrupt(this.fiber);
307
+ });
308
+ return fiberJoin(this.fiber);
309
+ }
310
+ }
311
+ var removeEntry = (self, key, entry) => {
312
+ const current = get(self.map, key);
313
+ if (isSome(current) && current.value === entry) {
314
+ remove(self.map, key);
315
+ }
316
+ };
317
+ var hasExpired = (entry, fiber) => {
318
+ if (entry.expiresAt === undefined) {
319
+ return false;
320
+ }
321
+ return fiber.getRef(ClockRef).currentTimeMillisUnsafe() >= entry.expiresAt;
322
+ };
323
+ var checkCapacity = (self) => {
324
+ let diff = size(self.map) - self.capacity;
325
+ if (diff <= 0)
326
+ return;
327
+ for (const [key] of self.map) {
328
+ remove(self.map, key);
329
+ diff--;
330
+ if (diff === 0)
331
+ return;
332
+ }
333
+ };
334
+ var invalidate = /* @__PURE__ */ dual(2, (self, key) => sync(() => {
335
+ remove(self.map, key);
336
+ }));
337
+
338
+ // dist/channel/github-app-client.js
339
+ import { createPrivateKey, sign } from "crypto";
340
+ var apiBase = "https://api.github.com";
341
+ var requiredEvents = [
342
+ "issues",
343
+ "issue_comment",
344
+ "pull_request",
345
+ "pull_request_review_comment"
346
+ ];
347
+ var App = Struct({
348
+ id: NumericId2,
349
+ slug: NonEmptyString
350
+ });
351
+ var AppInstallation = Struct({
352
+ app_id: NumericId2,
353
+ events: ArraySchema(String3),
354
+ permissions: Struct({
355
+ issues: optionalKey(String3),
356
+ pull_requests: optionalKey(String3)
357
+ }),
358
+ suspended_at: optionalKey(NullOr(String3))
359
+ });
360
+ var HookConfig = Struct({
361
+ content_type: optionalKey(String3),
362
+ url: optionalKey(String3)
363
+ });
364
+ var BotUser = Struct({
365
+ id: NumericId2,
366
+ type: Literal("Bot")
367
+ });
368
+ var InstallationToken = Struct({
369
+ expires_at: DateTimeUtcFromString,
370
+ token: NonEmptyString
371
+ });
372
+ var CollaboratorPermission = Struct({
373
+ permission: String3,
374
+ role_name: String3
375
+ });
376
+ var Author = NullOr(Struct({
377
+ id: NumericId2,
378
+ login: NonEmptyString
379
+ }));
380
+ var Comment2 = Struct({
381
+ body: NullOr(String3),
382
+ created_at: AgentChannel_exports.Timestamp,
383
+ id: NumericId2,
384
+ user: Author
385
+ });
386
+ var IssueRecord2 = Struct({
387
+ body: NullOr(String3),
388
+ comments: Natural,
389
+ created_at: AgentChannel_exports.Timestamp,
390
+ title: String3,
391
+ user: Author
392
+ });
393
+ var Created = Struct({ id: NumericId2 });
394
+ var CommentOwner = Struct({
395
+ issue_url: String3,
396
+ user: Author
397
+ });
398
+ var JwtHeader = fromJsonString(Struct({
399
+ alg: Literal("RS256"),
400
+ typ: Literal("JWT")
401
+ }));
402
+ var JwtClaims = fromJsonString(Struct({
403
+ exp: Int,
404
+ iat: Int,
405
+ iss: String3
406
+ }));
407
+ var encoder = new TextEncoder;
408
+ var pemWhitespace = /\s/gu;
409
+ function der(tag, bytes) {
410
+ if (bytes.length < 128)
411
+ return Uint8Array.of(tag, bytes.length, ...bytes);
412
+ if (bytes.length < 256)
413
+ return Uint8Array.of(tag, 129, bytes.length, ...bytes);
414
+ return Uint8Array.of(tag, 130, bytes.length >> 8, bytes.length & 255, ...bytes);
415
+ }
416
+ function pkcs8(pem) {
417
+ const trimmed = trim(pem);
418
+ const pkcs1 = startsWith("-----BEGIN RSA PRIVATE KEY-----")(trimmed);
419
+ const label = pipe(value2(pkcs1), when(true, () => "RSA PRIVATE KEY"), orElse2(() => "PRIVATE KEY"));
420
+ if (!startsWith(`-----BEGIN ${label}-----`)(trimmed) || !endsWith(`-----END ${label}-----`)(trimmed))
421
+ return none();
422
+ const body = pipe(trimmed, replace(`-----BEGIN ${label}-----`, ""), replace(`-----END ${label}-----`, ""), replaceAll(pemWhitespace, ""));
423
+ return pipe(getSuccess(decode2(body)), map((bytes) => {
424
+ if (!pkcs1)
425
+ return bytes;
426
+ return der(48, Uint8Array.of(...[
427
+ 2,
428
+ 1,
429
+ 0,
430
+ 48,
431
+ 13,
432
+ 6,
433
+ 9,
434
+ 42,
435
+ 134,
436
+ 72,
437
+ 134,
438
+ 247
439
+ ], 13, 1, 1, 1, 5, 0, ...der(4, bytes)));
440
+ }));
441
+ }
442
+ function uncertain(sending) {
443
+ if (sending)
444
+ return "unknown_completion";
445
+ return "unavailable";
446
+ }
447
+ function failure(response, sending) {
448
+ const limited = response.headers["x-ratelimit-remaining"] === "0" || response.headers["retry-after"] !== undefined;
449
+ if (response.status === 429 || response.status === 403 && limited)
450
+ return "rate_limited";
451
+ if (response.status === 401 || response.status === 403)
452
+ return "unauthorized";
453
+ if (response.status >= 500)
454
+ return uncertain(sending);
455
+ return "rejected";
456
+ }
457
+ var read = fnUntraced(function* (schema, response, sending = false) {
458
+ if (response.status < 200 || response.status >= 300)
459
+ return yield* AgentChannel_exports.HandlerError.make({ code: failure(response, sending) });
460
+ return yield* pipe(schemaBodyJson(schema)(response), timeout("20 seconds"), mapError2(() => AgentChannel_exports.HandlerError.make({ code: uncertain(sending) })));
461
+ });
462
+ function readFound(schema, response) {
463
+ if (response.status === 404)
464
+ return succeed5(none());
465
+ return asSome(read(schema, response));
466
+ }
467
+ function gone(response) {
468
+ if (response.status === 204 || response.status === 404)
469
+ return void_3;
470
+ return fail5(AgentChannel_exports.HandlerError.make({ code: failure(response, false) }));
471
+ }
472
+ function repositoryPath(repository) {
473
+ return `/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.name)}`;
474
+ }
475
+ function issuePath(issue) {
476
+ return `${repositoryPath(issue)}/issues/${issue.number}`;
477
+ }
478
+ function commentPath(repository, id) {
479
+ return `${repositoryPath(repository)}/issues/comments/${id}`;
480
+ }
481
+ var GitHubAppClient2 = class GitHubAppClient extends Service()("@dual-os/github-app/github-app-client/GitHubAppClient") {
482
+ static layer = effect(this, gen(function* () {
483
+ const http = yield* HttpClient;
484
+ const github = pipe(http, mapRequest((request) => pipe(request, prependUrl(apiBase), setHeaders({
485
+ accept: "application/vnd.github+json",
486
+ "user-agent": "dual-github-app",
487
+ "x-github-api-version": apiVersion2
488
+ }))));
489
+ const send = fn("GitHubAppClient.send")(function* (request, token, sending) {
490
+ return yield* pipe(github.execute(bearerToken(request, token)), provideService(RequestInit, { redirect: "manual" }), timeout("20 seconds"), mapError2(() => AgentChannel_exports.HandlerError.make({ code: uncertain(sending) })));
491
+ });
492
+ const appJwt = fn("GitHubAppClient.appJwt")(function* (auth) {
493
+ const now = Math.floor((yield* currentTimeMillis) / 1000);
494
+ const unsigned = `${encode3(yield* encodeEffect(JwtHeader)({
495
+ alg: "RS256",
496
+ typ: "JWT"
497
+ }))}.${encode3(yield* encodeEffect(JwtClaims)({
498
+ exp: now + 540,
499
+ iat: now - 60,
500
+ iss: auth.appId
501
+ }))}`;
502
+ const key = yield* pipe(pkcs8(auth.privateKey), fromOption2, mapError2(() => AgentChannel_exports.HandlerError.make({ code: "unauthorized" })));
503
+ const signature = yield* pipe(try_2(() => sign("sha256", encoder.encode(unsigned), createPrivateKey({
504
+ format: "der",
505
+ key: Buffer.from(key),
506
+ type: "pkcs8"
507
+ }))), mapError2(() => AgentChannel_exports.HandlerError.make({ code: "unauthorized" })));
508
+ return `${unsigned}.${encode3(new Uint8Array(signature))}`;
509
+ }, catchTag("SchemaError", () => AgentChannel_exports.HandlerError.make({ code: "unauthorized" })));
510
+ const appGet = fn("GitHubAppClient.appGet")(function* (auth, path, schema) {
511
+ return yield* read(schema, yield* send(get3(path), yield* appJwt(auth), false));
512
+ });
513
+ const tokens = yield* makeWith((installation) => gen(function* () {
514
+ const response = yield* send(post(`/app/installations/${installation.installationId}/access_tokens`), yield* appJwt(installation.auth), false);
515
+ const created = yield* read(InstallationToken, response);
516
+ const ttl = toEpochMillis(created.expires_at) - (yield* currentTimeMillis) - 60000;
517
+ if (ttl <= 0)
518
+ return yield* AgentChannel_exports.HandlerError.make({ code: "unavailable" });
519
+ return {
520
+ token: created.token,
521
+ ttl: min(ttl, 3540000)
522
+ };
523
+ }), {
524
+ capacity: 1000,
525
+ timeToLive: (exit) => {
526
+ if (isSuccess2(exit))
527
+ return millis(exit.value.ttl);
528
+ return zero;
529
+ }
530
+ });
531
+ const call = fn("GitHubAppClient.call")(function* (installation, request, sending = false) {
532
+ const minted = yield* get2(tokens, installation);
533
+ const response = yield* send(request, minted.token, sending);
534
+ if (response.status === 401)
535
+ yield* invalidate(tokens, installation);
536
+ return response;
537
+ });
538
+ const checkInstallation = fn("GitHubAppClient.checkInstallation")(function* (installation) {
539
+ const app = yield* appGet(installation.auth, "/app", App);
540
+ const found = yield* appGet(installation.auth, `/app/installations/${installation.installationId}`, AppInstallation);
541
+ if (`${app.id}` !== installation.auth.appId || found.app_id !== app.id)
542
+ return yield* AgentChannel_exports.HandlerError.make({ code: "unauthorized" });
543
+ if (found.suspended_at !== undefined && found.suspended_at !== null || found.permissions.issues !== "write" || found.permissions.pull_requests !== "write" || !every(requiredEvents, (event) => contains(found.events, event)))
544
+ return yield* AgentChannel_exports.HandlerError.make({ code: "rejected" });
545
+ return {
546
+ botUserId: `${(yield* read(BotUser, yield* call(installation, get3(`/users/${encodeURIComponent(`${app.slug}[bot]`)}`)))).id}`,
547
+ slug: app.slug
548
+ };
549
+ });
550
+ const registerWebhook = fn("GitHubAppClient.registerWebhook")(function* (auth, ingressUrl) {
551
+ const hook = yield* read(HookConfig, yield* send(bodyJsonUnsafe(patch("/app/hook/config"), {
552
+ content_type: "json",
553
+ insecure_ssl: "0",
554
+ secret: auth.webhookSecret,
555
+ url: ingressUrl
556
+ }), yield* appJwt(auth), false));
557
+ if (hook.url !== ingressUrl || hook.content_type !== "json")
558
+ return yield* AgentChannel_exports.HandlerError.make({ code: "rejected" });
559
+ });
560
+ const permission = fn("GitHubAppClient.permission")(function* (installation, repository, login) {
561
+ const found = yield* readFound(CollaboratorPermission, yield* call(installation, get3(`${repositoryPath(repository)}/collaborators/${encodeURIComponent(login)}/permission`)));
562
+ return pipe(found, flatMap((role) => pipe(decodeUnknownOption(Permission2)(role.role_name), orElse(() => decodeUnknownOption(Permission2)(role.permission)))), getOrElse(() => "none"));
563
+ });
564
+ const postComment = fn("GitHubAppClient.postComment")(function* (installation, issue, text) {
565
+ const response = yield* call(installation, bodyJsonUnsafe(post(`${issuePath(issue)}/comments`), { body: text }), true);
566
+ return `${(yield* read(Created, response, true)).id}`;
567
+ });
568
+ const checkOwnComment = fn("GitHubAppClient.checkOwnComment")(function* (installation, issue, id, botUserId) {
569
+ const found = yield* readFound(CommentOwner, yield* call(installation, get3(commentPath(issue, id))));
570
+ return yield* match2(found, {
571
+ onNone: () => succeed5(false),
572
+ onSome: (comment) => {
573
+ if (comment.user === null || `${comment.user.id}` !== botUserId || comment.issue_url !== `${apiBase}${issuePath(issue)}`)
574
+ return fail5(AgentChannel_exports.HandlerError.make({ code: "rejected" }));
575
+ return succeed5(true);
576
+ }
577
+ });
578
+ });
579
+ const editComment = fn("GitHubAppClient.editComment")(function* (installation, repository, id, text) {
580
+ const response = yield* call(installation, bodyJsonUnsafe(patch(commentPath(repository, id)), { body: text }));
581
+ return isSome(yield* readFound(Created, response));
582
+ });
583
+ const deleteComment = fn("GitHubAppClient.deleteComment")(function* (installation, repository, id) {
584
+ yield* gone(yield* call(installation, del(commentPath(repository, id))));
585
+ });
586
+ const react = fn("GitHubAppClient.react")(function* (installation, issue, target, content, active) {
587
+ const path = pipe(value2(target), when({ kind: "issue" }, () => `${issuePath(issue)}/reactions`), when({ kind: "comment" }, (comment) => `${commentPath(issue, comment.id)}/reactions`), when({ kind: "review-comment" }, (comment) => `${repositoryPath(issue)}/pulls/comments/${comment.id}/reactions`), exhaustive);
588
+ const response = yield* call(installation, bodyJsonUnsafe(post(path), { content }));
589
+ if (active) {
590
+ yield* read(Created, response);
591
+ return;
592
+ }
593
+ yield* match2(yield* readFound(Created, response), {
594
+ onNone: () => void_3,
595
+ onSome: (reaction) => flatMap3(call(installation, del(`${path}/${reaction.id}`)), gone)
596
+ });
597
+ });
598
+ const readComments = fn("GitHubAppClient.readComments")(function* (installation, issue, limit) {
599
+ const record = yield* read(IssueRecord2, yield* call(installation, get3(issuePath(issue))));
600
+ const last = Math.ceil(record.comments / 100);
601
+ const pages = filter2([
602
+ last - 2,
603
+ last - 1,
604
+ last
605
+ ], (number) => number >= 1 && (last - number) * 100 < limit + 100);
606
+ const comments = yield* forEach(pages, (number) => flatMap3(call(installation, setUrlParams(get3(`${issuePath(issue)}/comments`), {
607
+ page: `${number}`,
608
+ per_page: "100"
609
+ })), (response) => read(ArraySchema(Comment2), response)), { concurrency: 1 });
610
+ return {
611
+ comments: takeRight(flatten(comments), limit),
612
+ issue: record
613
+ };
614
+ });
615
+ return GitHubAppClient.of({
616
+ checkInstallation,
617
+ checkOwnComment,
618
+ deleteComment,
619
+ editComment,
620
+ permission,
621
+ postComment,
622
+ react,
623
+ readComments,
624
+ registerWebhook
625
+ });
626
+ }));
627
+ };
628
+ export { Comment2, IssueRecord2, GitHubAppClient2 };
629
+
630
+ //# debugId=647D02E757151B0164756E2164756E21
631
+ //# sourceMappingURL=plugin-p6f7n836.js.map