@catamorphic/github 0.0.0-stage → 0.1.0-alpha.30

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/dist/api.d.ts ADDED
@@ -0,0 +1,366 @@
1
+ import { type FetchLike, type GithubCheckRun, type GithubCheckRunFields, type GithubComment, type GithubPullRequest, type GithubPullRequestFile, type GithubPullRequestReview, type GithubPullRequestStatus, type GithubRepo, type GithubRepositoryEvent, type GithubReviewComment, type GithubReviewEvent, type GithubReviewThread, type GithubReviewThreadComment, type GithubUser } from "./types.js";
2
+ export interface GithubApiOptions {
3
+ fetch?: FetchLike;
4
+ baseUrl?: string;
5
+ signal?: AbortSignal;
6
+ }
7
+ /** Minimal REST client: a user access token, or anonymous public reads. */
8
+ export declare class GithubApi {
9
+ private readonly accessToken;
10
+ private readonly fetch;
11
+ private readonly baseUrl;
12
+ private readonly signal?;
13
+ constructor(accessToken: string | null, opts?: GithubApiOptions);
14
+ private request;
15
+ private requestPages;
16
+ /** A call GitHub answers with no body (204), such as a DELETE. */
17
+ private requestNoContent;
18
+ /**
19
+ * One GraphQL request against {@link githubGraphqlUrl} of the API base.
20
+ * HTTP failures throw {@link GithubApiError}; an answer carrying `errors`
21
+ * throws {@link GithubGraphqlError}, so a partial answer is never taken
22
+ * for a whole one.
23
+ */
24
+ graphql<T>(query: string, variables?: Readonly<Record<string, unknown>>): Promise<T>;
25
+ /**
26
+ * Every review thread of a pull request with all of its comments, oldest
27
+ * first, following GraphQL's pages.
28
+ */
29
+ reviewThreads(input: {
30
+ fullName: string;
31
+ number: number;
32
+ }): Promise<GithubReviewThread[]>;
33
+ /**
34
+ * One review thread by node id: where it lives, whether it is resolved,
35
+ * and its first and last comments. Null when the id names no review
36
+ * thread.
37
+ */
38
+ reviewThread(input: {
39
+ threadId: string;
40
+ }): Promise<{
41
+ id: string;
42
+ isResolved: boolean;
43
+ repository: string;
44
+ number: number;
45
+ firstComment: GithubReviewThreadComment | null;
46
+ lastComment: GithubReviewThreadComment | null;
47
+ } | null>;
48
+ /** Mark a review thread resolved (GraphQL `resolveReviewThread`). */
49
+ resolveReviewThread(input: {
50
+ threadId: string;
51
+ }): Promise<{
52
+ id: string;
53
+ isResolved: boolean;
54
+ }>;
55
+ /** Replace a pull request's description. */
56
+ updatePullRequest(input: {
57
+ fullName: string;
58
+ number: number;
59
+ body: string;
60
+ }): Promise<{
61
+ number: number;
62
+ url: string;
63
+ body: string;
64
+ }>;
65
+ /** A pull request's reviews, oldest first. */
66
+ listReviews(input: {
67
+ fullName: string;
68
+ number: number;
69
+ }): Promise<GithubPullRequestReview[]>;
70
+ review(input: {
71
+ fullName: string;
72
+ number: number;
73
+ reviewId: number;
74
+ }): Promise<GithubPullRequestReview>;
75
+ /**
76
+ * Dismiss a review that approved or requested changes, so it no longer
77
+ * counts toward the pull request's review decision.
78
+ */
79
+ dismissReview(input: {
80
+ fullName: string;
81
+ number: number;
82
+ reviewId: number;
83
+ message: string;
84
+ }): Promise<GithubPullRequestReview>;
85
+ /** A pull request review comment (an inline comment) by id. */
86
+ reviewComment(input: {
87
+ fullName: string;
88
+ commentId: number;
89
+ }): Promise<GithubComment>;
90
+ /** An issue or pull request conversation comment by id. */
91
+ issueComment(input: {
92
+ fullName: string;
93
+ commentId: number;
94
+ }): Promise<GithubComment>;
95
+ updateIssueComment(input: {
96
+ fullName: string;
97
+ commentId: number;
98
+ body: string;
99
+ }): Promise<GithubComment>;
100
+ /** Whether an issue number names a pull request. */
101
+ issueKind(input: {
102
+ fullName: string;
103
+ number: number;
104
+ }): Promise<"issue" | "pull_request">;
105
+ /** An issue's or pull request's conversation comments, oldest first. */
106
+ issueComments(input: {
107
+ fullName: string;
108
+ number: number;
109
+ }): Promise<GithubComment[]>;
110
+ /** A pull request's inline review comments, oldest first. */
111
+ reviewComments(input: {
112
+ fullName: string;
113
+ number: number;
114
+ }): Promise<GithubComment[]>;
115
+ /** Check runs on a commit, by name when given, with the App that made each. */
116
+ checkRuns(input: {
117
+ fullName: string;
118
+ sha: string;
119
+ name?: string;
120
+ }): Promise<Array<{
121
+ id: number;
122
+ externalId: string | null;
123
+ app: string | null;
124
+ status: string;
125
+ conclusion: string | null;
126
+ url: string | null;
127
+ }>>;
128
+ deleteIssueComment(input: {
129
+ fullName: string;
130
+ commentId: number;
131
+ }): Promise<void>;
132
+ getUser(): Promise<GithubUser>;
133
+ getRepo(fullName: string): Promise<GithubRepo>;
134
+ /**
135
+ * Create an empty repository for the authenticated user, or in
136
+ * `organization` when given. Nothing is initialized, so the first push
137
+ * defines its history.
138
+ */
139
+ createRepo(input: {
140
+ name: string;
141
+ organization?: string;
142
+ private: boolean;
143
+ description?: string;
144
+ }): Promise<GithubRepo>;
145
+ /**
146
+ * Open a pull request. `head` and `base` are branch names in the same
147
+ * repository (cross-fork PRs are out of scope for now).
148
+ */
149
+ createPullRequest(fullName: string, input: {
150
+ title: string;
151
+ head: string;
152
+ base: string;
153
+ body?: string;
154
+ }): Promise<{
155
+ url: string;
156
+ number: number;
157
+ }>;
158
+ pullRequestDiscussion(input: {
159
+ fullName: string;
160
+ number: number;
161
+ }): Promise<{
162
+ state: string;
163
+ reviewDecision: null;
164
+ assignees: {
165
+ login: string;
166
+ }[];
167
+ reviewRequests: {
168
+ login: string;
169
+ }[];
170
+ reviews: {
171
+ id: number;
172
+ body: string;
173
+ author: {
174
+ login: string;
175
+ } | null;
176
+ createdAt: string;
177
+ url: string;
178
+ state?: string | undefined;
179
+ path?: string | undefined;
180
+ line?: number | null | undefined;
181
+ replyToId?: number | undefined;
182
+ diffHunk?: string | undefined;
183
+ side?: "LEFT" | "RIGHT" | undefined;
184
+ }[];
185
+ comments: {
186
+ id: number;
187
+ body: string;
188
+ author: {
189
+ login: string;
190
+ } | null;
191
+ createdAt: string;
192
+ url: string;
193
+ state?: string | undefined;
194
+ path?: string | undefined;
195
+ line?: number | null | undefined;
196
+ replyToId?: number | undefined;
197
+ diffHunk?: string | undefined;
198
+ side?: "LEFT" | "RIGHT" | undefined;
199
+ }[];
200
+ inlineComments: {
201
+ id: number;
202
+ body: string;
203
+ author: {
204
+ login: string;
205
+ } | null;
206
+ createdAt: string;
207
+ url: string;
208
+ state?: string | undefined;
209
+ path?: string | undefined;
210
+ line?: number | null | undefined;
211
+ replyToId?: number | undefined;
212
+ diffHunk?: string | undefined;
213
+ side?: "LEFT" | "RIGHT" | undefined;
214
+ }[];
215
+ inlineCommentsUnavailable: boolean;
216
+ statusCheckRollup: {
217
+ name: string;
218
+ status: string;
219
+ conclusion: string | null;
220
+ detailsUrl: string;
221
+ }[];
222
+ }>;
223
+ commentOnPullRequest(input: {
224
+ fullName: string;
225
+ number: number;
226
+ body: string;
227
+ replyTo?: number;
228
+ }): Promise<{
229
+ id: number;
230
+ body: string;
231
+ author: {
232
+ login: string;
233
+ } | null;
234
+ createdAt: string;
235
+ url: string;
236
+ state?: string | undefined;
237
+ path?: string | undefined;
238
+ line?: number | null | undefined;
239
+ replyToId?: number | undefined;
240
+ diffHunk?: string | undefined;
241
+ side?: "LEFT" | "RIGHT" | undefined;
242
+ }>;
243
+ /**
244
+ * Submit a pull request review, optionally with inline comments anchored
245
+ * to lines of the diff. Without `event` the review stays pending on GitHub;
246
+ * `COMMENT` publishes it without a verdict.
247
+ */
248
+ createReview(input: {
249
+ fullName: string;
250
+ number: number;
251
+ event?: GithubReviewEvent;
252
+ body?: string;
253
+ /** The revision reviewed; defaults to the pull request's current head. */
254
+ commitId?: string;
255
+ comments?: readonly GithubReviewComment[];
256
+ }): Promise<{
257
+ id: number;
258
+ url: string;
259
+ state: string;
260
+ }>;
261
+ /** Report a check run on a commit (requires the app's `checks` permission). */
262
+ createCheckRun(input: GithubCheckRunFields & {
263
+ fullName: string;
264
+ name: string;
265
+ headSha: string;
266
+ }): Promise<GithubCheckRun>;
267
+ updateCheckRun(input: GithubCheckRunFields & {
268
+ fullName: string;
269
+ checkRunId: number;
270
+ name?: string;
271
+ }): Promise<GithubCheckRun>;
272
+ /** Tie each review to the exact revision the reviewer inspected. */
273
+ reviewPullRequest(input: {
274
+ fullName: string;
275
+ number: number;
276
+ headSha: string;
277
+ decision: "APPROVE" | "REQUEST_CHANGES";
278
+ body: string;
279
+ }): Promise<void>;
280
+ mergePullRequest(input: {
281
+ fullName: string;
282
+ number: number;
283
+ headSha: string;
284
+ }): Promise<{
285
+ sha: string;
286
+ }>;
287
+ /** GitHub includes direct and team requests in review-requested:@me. */
288
+ private requestedReviewNumbers;
289
+ /** Open pull requests, most recently updated first. */
290
+ listPullRequests(fullName: string): Promise<GithubPullRequest[]>;
291
+ /** Read an individual pull request, including completed proposals. */
292
+ pullRequest(input: {
293
+ fullName: string;
294
+ number: number;
295
+ }): Promise<GithubPullRequest>;
296
+ /**
297
+ * Where a pull request stands: open, draft, merged or closed, how much it
298
+ * changes, how many comments it has and what its head's checks say. A
299
+ * token that cannot read checks still reads the rest.
300
+ */
301
+ pullRequestStatus(input: {
302
+ fullName: string;
303
+ number: number;
304
+ /** Anonymous chip reads reserve their smaller rate limit for status. */
305
+ includeChecks?: boolean;
306
+ }): Promise<GithubPullRequestStatus>;
307
+ /** Check runs and commit statuses on one commit, counted together. */
308
+ private checksOf;
309
+ /** Changed files of a pull request, with unified-diff patches. */
310
+ pullRequestFiles(fullName: string, number: number): Promise<GithubPullRequestFile[]>;
311
+ /** Repository activity available to the connected user. */
312
+ listRepositoryEvents(fullName: string): Promise<GithubRepositoryEvent[]>;
313
+ /**
314
+ * Complete polling surface for desktop Watchers. The repository Events API
315
+ * omits some check and Actions transitions, so merge state-stamped snapshots
316
+ * from the dedicated APIs. Unsupported permission slices degrade to the
317
+ * events the connected user can read instead of disabling the monitor.
318
+ */
319
+ listRepositoryWatchEvents(fullName: string): Promise<GithubRepositoryEvent[]>;
320
+ private optionalRequest;
321
+ /**
322
+ * Repositories the authenticated user can access. GitHub supports this one
323
+ * endpoint for GitHub App user tokens, fine-grained tokens, and the OAuth
324
+ * token exposed by `gh`, so every credential source follows the same API.
325
+ */
326
+ listAccessibleRepos(opts?: {
327
+ perPage?: number;
328
+ }): Promise<GithubRepo[]>;
329
+ /** Repositories a GitHub App installation token can reach. */
330
+ listInstallationRepos(): Promise<GithubRepo[]>;
331
+ }
332
+ /**
333
+ * The GraphQL endpoint beside a REST API base: `https://api.github.com/graphql`
334
+ * for github.com (and GHE.com's `api.<subdomain>.ghe.com`), and `/api/graphql`
335
+ * for GitHub Enterprise Server, whose REST base is `https://HOST/api/v3`.
336
+ */
337
+ export declare function githubGraphqlUrl(apiBaseUrl?: string): string;
338
+ /**
339
+ * Git-over-HTTPS credentials for a user access token. GitHub accepts the
340
+ * token as the password with the fixed `x-access-token` username.
341
+ */
342
+ export declare function gitCredentialsFor(accessToken: string): {
343
+ username: string;
344
+ password: string;
345
+ };
346
+ /** True when the remote URL points at github.com (https or ssh form). */
347
+ export declare function isGithubRemoteUrl(url: string): boolean;
348
+ /**
349
+ * The repository and number of a pull request's web address
350
+ * (`https://github.com/owner/repo/pull/12`, anything after the number
351
+ * ignored), under `webBaseUrl` for GitHub Enterprise. Null otherwise.
352
+ */
353
+ export declare function pullRequestFromUrl({ url, webBaseUrl, }: {
354
+ url: string;
355
+ webBaseUrl?: string;
356
+ }): {
357
+ fullName: string;
358
+ number: number;
359
+ } | null;
360
+ /**
361
+ * Extract `owner/repo` from a github.com clone URL
362
+ * (`https://github.com/owner/repo.git`, `git@github.com:owner/repo.git`).
363
+ * Returns null for anything that is not a github.com remote.
364
+ */
365
+ export declare function repoFullNameFromUrl(url: string): string | null;
366
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAGd,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAElB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,U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E;AACzE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,GAAG,EACH,UAAiC,GAClC,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAW9C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM9D"}
@@ -0,0 +1,84 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ import { type FetchLike, type GithubAppCredentials, type GithubInstallation, type GithubInstallationToken, type GithubPermissions } from "./types.js";
3
+ /** Parse and check a GitHub App private key (PKCS#1 or PKCS#8 PEM). */
4
+ export declare function parseGithubAppPrivateKey(privateKey: string): KeyObject;
5
+ /**
6
+ * Sign a GitHub App JWT (RS256): issued a minute in the past, expiring nine
7
+ * minutes from now, with the app ID (or client ID) as issuer. App JWTs only
8
+ * authenticate `/app/...` endpoints, chiefly minting installation tokens.
9
+ */
10
+ export declare function createGithubAppJwt(args: GithubAppCredentials & {
11
+ now?: number;
12
+ }): string;
13
+ export interface GithubAppAuthOptions {
14
+ fetch?: FetchLike;
15
+ /** REST API base; GitHub Enterprise Server uses `https://HOST/api/v3`. */
16
+ apiBaseUrl?: string;
17
+ /** Clock, for tests. */
18
+ now?: () => number;
19
+ /** Tokens closer than this to expiry are minted again. Default 5 minutes. */
20
+ refreshSkewMs?: number;
21
+ /**
22
+ * How long one call as the App may take before it fails. Default 30
23
+ * seconds: a mint every caller of a token shares must never wait forever.
24
+ */
25
+ timeoutMs?: number;
26
+ }
27
+ /**
28
+ * GitHub App server-side authentication. Holds no credentials itself: every
29
+ * call names the app, so one instance (and its token cache) can serve every
30
+ * connection a host brokers. Installation tokens are cached per app key,
31
+ * installation, repositories, and permissions, and minted again shortly
32
+ * before they expire; concurrent requests share one mint.
33
+ */
34
+ export declare class GithubAppAuth {
35
+ private readonly fetch;
36
+ private readonly apiBaseUrl;
37
+ private readonly now;
38
+ private readonly refreshSkewMs;
39
+ private readonly timeoutMs;
40
+ private readonly tokens;
41
+ constructor(options?: GithubAppAuthOptions);
42
+ appJwt(args: {
43
+ app: GithubAppCredentials;
44
+ }): string;
45
+ /**
46
+ * An installation access token, optionally narrowed to repository names
47
+ * (without the owner) and a subset of the installation's permissions.
48
+ */
49
+ installationToken(args: {
50
+ app: GithubAppCredentials;
51
+ installationId: number;
52
+ repositories?: readonly string[];
53
+ permissions?: GithubPermissions;
54
+ }): Promise<GithubInstallationToken>;
55
+ /** Every installation of the app. */
56
+ listInstallations(args: {
57
+ app: GithubAppCredentials;
58
+ }): Promise<GithubInstallation[]>;
59
+ installation(args: {
60
+ app: GithubAppCredentials;
61
+ installationId: number;
62
+ }): Promise<GithubInstallation>;
63
+ /**
64
+ * The installation covering an owner (user or organization), or one
65
+ * repository of it. Null when the app is not installed there.
66
+ */
67
+ findInstallation(args: {
68
+ app: GithubAppCredentials;
69
+ owner: string;
70
+ repository?: string;
71
+ }): Promise<GithubInstallation | null>;
72
+ /**
73
+ * Revoke and forget every cached installation token of an app, for example
74
+ * when its connection is removed. Revocation is best-effort: tokens expire
75
+ * within the hour regardless.
76
+ */
77
+ revokeCachedTokens(args: {
78
+ app: GithubAppCredentials;
79
+ }): Promise<void>;
80
+ private mint;
81
+ private appRequest;
82
+ private sweep;
83
+ }
84
+ //# sourceMappingURL=app-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-auth.d.ts","sourceRoot":"","sources":["../src/app-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,oBAAoB,EAEzB,KAAK,kBAAkB,EACvB,KAAK,u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iBAAiB,CAAC,IAAI,EAAE;QAC5B,GAAG,EAAE,oBAAoB,CAAC;KAC3B,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAUhC;IAEK,YAAY,CAAC,IAAI,EAAE;QACvB,GAAG,EAAE,oBAAoB,CAAC;QAC1B,cAAc,EAAE,MAAM,CAAC;KACxB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAQ9B;IAED;;;OAGG;IACG,gBAAgB,CAAC,IAAI,EAAE;QAC3B,GAAG,EAAE,oBAAoB,CAAC;QAC1B,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAmBrC;IAED;;;;OAIG;IACG,kBAAkB,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,oBAAoB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB3E;YAEa,IAAI;YAsCJ,UAAU;IA6BxB,OAAO,CAAC,KAAK;CAOd"}
@@ -0,0 +1,7 @@
1
+ export { GithubApi, type GithubApiOptions, gitCredentialsFor, githubGraphqlUrl, isGithubRemoteUrl, pullRequestFromUrl, repoFullNameFromUrl, } from "./api.js";
2
+ export { createGithubAppJwt, GithubAppAuth, type GithubAppAuthOptions, parseGithubAppPrivateKey, } from "./app-auth.js";
3
+ export { buildGithubAppManifest, convertGithubAppManifest, DEFAULT_GITHUB_APP_EVENTS, DEFAULT_GITHUB_APP_PERMISSIONS, type GithubAppManifest, type GithubAppManifestOptions, githubAppManifestForm, } from "./manifest.js";
4
+ export { buildAuthorizeUrl, buildInstallationUrl, exchangeCode, isTokenStale, pollDeviceToken, refreshAccessToken, requestDeviceCode, revokeUserToken, } from "./oauth.js";
5
+ export { type GithubRestMethod, type GithubRestRequest, type GithubRestResponse, githubRestRequest, githubRestUrl, repositoryFromRestPath, } from "./rest.js";
6
+ export { type DeviceCodeGrant, type FetchLike, type GithubActor, GithubApiError, type GithubAppConfig, type GithubAppCredentials, type GithubAppRegistration, GithubAuthError, type GithubCheckRun, type GithubCheckRunAnnotation, type GithubCheckRunFields, type GithubComment, GithubGraphqlError, type GithubInstallation, type GithubInstallationToken, type GithubJson, type GithubPermissionLevel, type GithubPermissions, type GithubPullRequest, type GithubPullRequestFile, type GithubPullRequestReview, type GithubPullRequestStatus, type GithubRepo, type GithubRepositoryEvent, type GithubReviewComment, type GithubReviewEvent, type GithubReviewThread, type GithubReviewThreadComment, type GithubTokenSet, type GithubUser, } from "./types.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,KAAK,oBAAoB,EACzB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,8BAA8B,EAC9B,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,iBAAiB,EACjB,aAAa,EACb,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,qBAAq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