@theholocron/github-client 1.58.0-alpha.52 → 1.58.0-alpha.53

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/index.d.mts CHANGED
@@ -104,6 +104,8 @@ interface CreateCheckRunInput {
104
104
  output?: CheckRunOutput;
105
105
  /** URL for the "Details" link on the check run. GitHub defaults to the check suite's own summary page when omitted. */
106
106
  details_url?: string;
107
+ /** When the run started, an ISO time; GitHub uses the time of the request when omitted. */
108
+ started_at?: string;
107
109
  }
108
110
  /** A check run as GitHub returns it, with only the fields this client reads. */
109
111
  interface GitHubCheckRun {
@@ -123,6 +125,11 @@ interface GitHubCheckRun {
123
125
  details_url?: string | null;
124
126
  /** When the run started, an ISO time; absent while it is queued. */
125
127
  started_at?: string | null;
128
+ /** The GitHub App that posted the run; absent from a payload that leaves it out. */
129
+ app?: {
130
+ id: number;
131
+ slug?: string;
132
+ } | null;
126
133
  }
127
134
  /** The body of an `updateCheckRun()` request; every field is optional. */
128
135
  interface UpdateCheckRunInput {
@@ -135,6 +142,21 @@ interface UpdateCheckRunInput {
135
142
  /** URL for the "Details" link on the check run. */
136
143
  details_url?: string;
137
144
  }
145
+ /** The state of a commit status. */
146
+ type CommitStatusState = "error" | "failure" | "pending" | "success";
147
+ /** One commit status as GitHub returns it, with only the fields this client reads. */
148
+ interface GitHubCommitStatus {
149
+ /** The status's numeric id. */
150
+ id: number;
151
+ /** The context that posted it, such as `codecov/patch`. */
152
+ context: string;
153
+ /** Where the context stands. */
154
+ state: CommitStatusState;
155
+ /** The link the status points to, `null` when it set none. */
156
+ target_url: string | null;
157
+ /** When the status was created, an ISO time. */
158
+ created_at: string;
159
+ }
138
160
  /** A deployment environment of a repository and its protection settings. */
139
161
  interface GitHubEnvironment {
140
162
  /** The environment's name. */
@@ -1025,6 +1047,45 @@ interface GitHubAppInstallation {
1025
1047
  export declare function getApp(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubApp>;
1026
1048
  /** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
1027
1049
  export declare function listAppInstallations(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubAppInstallation[]>;
1050
+ /** One delivery of a webhook event to the App, as `GET /app/hook/deliveries` reports it. */
1051
+ interface GitHubAppDelivery {
1052
+ /** The delivery's id, which a redelivery is asked for by. */
1053
+ id: number;
1054
+ /** The delivery's GUID, shared by the first attempt and every redelivery of it (`X-GitHub-Delivery`). */
1055
+ guid: string;
1056
+ /** When it was delivered, an ISO time. */
1057
+ deliveredAt: string;
1058
+ /** Whether this attempt was itself a redelivery. */
1059
+ redelivery: boolean;
1060
+ /** The HTTP status the App's endpoint answered, or `0` when it gave none (a timeout, a refused connection). */
1061
+ statusCode: number;
1062
+ /** GitHub's own word for the outcome: `OK`, or the failure (`Invalid HTTP Response: 500`, `Timed out`). */
1063
+ status: string;
1064
+ /** The event, such as `check_run`. */
1065
+ event: string;
1066
+ /** The event's action, `null` for an event with none. */
1067
+ action: string | null;
1068
+ /** The installation it was for, `null` when it was for none. */
1069
+ installationId: number | null;
1070
+ }
1071
+ /** What {@link listAppDeliveries} reads. */
1072
+ interface ListAppDeliveriesOptions extends Pick<GitHubClientOptions, "baseUrl" | "fetch"> {
1073
+ /** Stop at deliveries older than this ISO time. Without it, every page up to `maxPages` is read. */
1074
+ since?: string;
1075
+ /** The most pages to read, 100 deliveries each; defaults to 10, so 1,000 deliveries. */
1076
+ maxPages?: number;
1077
+ }
1078
+ /**
1079
+ * The webhook deliveries of the App this JWT identifies, newest first (`GET /app/hook/deliveries`), a page at a time by
1080
+ * the cursor GitHub hands back, until a delivery older than `since`, the last page, or `maxPages`. A delivery older than
1081
+ * `since` is left out. Needs no repository permission: the App's own JWT is the credential.
1082
+ */
1083
+ export declare function listAppDeliveries(creds: GitHubAppCredentials, opts?: ListAppDeliveriesOptions): Promise<GitHubAppDelivery[]>;
1084
+ /**
1085
+ * Asks GitHub to deliver one webhook delivery again (`POST /app/hook/deliveries/{id}/attempts`). GitHub answers 202 and
1086
+ * sends it asynchronously, so this says only that it was accepted.
1087
+ */
1088
+ export declare function redeliverAppDelivery(creds: GitHubAppCredentials, deliveryId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<void>;
1028
1089
  /**
1029
1090
  * GitHub's own webhook mechanics — signature verification and header/
1030
1091
  * payload shapes. Pure functions, no REST call, no auth token: these
@@ -1133,6 +1194,9 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
1133
1194
  createCheckRun: (repo: string, input: CreateCheckRunInput) => Promise<GitHubCheckRun>;
1134
1195
  updateCheckRun: (repo: string, checkRunId: number, input: UpdateCheckRunInput) => Promise<GitHubCheckRun>;
1135
1196
  };
1197
+ statuses: {
1198
+ listCommitStatuses: (repo: string, ref: string) => Promise<GitHubCommitStatus[]>;
1199
+ };
1136
1200
  environments: {
1137
1201
  listEnvironments: (repo: string) => Promise<GitHubEnvironment[]>;
1138
1202
  upsertEnvironment: (repo: string, name: string, body: Record<string, unknown>) => Promise<void>;
@@ -1292,4 +1356,4 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
1292
1356
  };
1293
1357
  /** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
1294
1358
  export type GitHubClient = ReturnType<typeof createGitHubClient>;
1295
- export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreateHookInput, CreatePagesPayload, CreatePullInput, CreatePullRequestInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitDirectoryEntry, GitHubApp, GitHubAppAccount, GitHubAppCredentials, GitHubAppInstallation, GitHubCheckRun, GitHubClientOptions, GitHubContents, GitHubEnvironment, GitHubHook, GitHubInstallationWebhookPayload, GitHubIssue, GitHubIssueComment, GitHubIssueField, GitHubIssueFieldOption, GitHubIssueFieldValue, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, GraphQLClient, HookScope, InstallationAccessToken, IssueFieldValueInput, IssueSearchParams, IssueTypeColor, IssueTypeInput, ListDirectoryOptions, OrgIssueTypeInfo, OrgProperty, OrgSecretInfo, OrgSecretVisibility, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdateHookInput, UpdatePagesPayload, UpdatePullRequestInput, VariableScope, VariableVisibility, WorkflowRunFilter };
1359
+ export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CommitStatusState, CreateCheckRunInput, CreateHookInput, CreatePagesPayload, CreatePullInput, CreatePullRequestInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitDirectoryEntry, GitHubApp, GitHubAppAccount, GitHubAppCredentials, GitHubAppDelivery, GitHubAppInstallation, GitHubCheckRun, GitHubClientOptions, GitHubCommitStatus, GitHubContents, GitHubEnvironment, GitHubHook, GitHubInstallationWebhookPayload, GitHubIssue, GitHubIssueComment, GitHubIssueField, GitHubIssueFieldOption, GitHubIssueFieldValue, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, GraphQLClient, HookScope, InstallationAccessToken, IssueFieldValueInput, IssueSearchParams, IssueTypeColor, IssueTypeInput, ListAppDeliveriesOptions, ListDirectoryOptions, OrgIssueTypeInfo, OrgProperty, OrgSecretInfo, OrgSecretVisibility, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdateHookInput, UpdatePagesPayload, UpdatePullRequestInput, VariableScope, VariableVisibility, WorkflowRunFilter };
package/dist/index.mjs CHANGED
@@ -811,6 +811,26 @@ function security(rest) {
811
811
  })
812
812
  };
813
813
  }
814
+ // src/statuses/statuses.ts
815
+ /** Page size and the most pages {@link statuses}`.listCommitStatuses` reads: 100 a page over 10 pages. */
816
+ const STATUS_PAGE_SIZE = 100;
817
+ const STATUS_MAX_PAGES = 10;
818
+ function statuses(rest) {
819
+ return {
820
+ /**
821
+ * Every commit status on a ref, newest first (`GET /commits/{ref}/statuses`), read a page at a time until a page comes
822
+ * back short. A context that posted more than once appears once per post: the first one is the current state.
823
+ */
824
+ listCommitStatuses: async (repo, ref) => {
825
+ const all = [];
826
+ for (let page = 1; page <= STATUS_MAX_PAGES; page++) {
827
+ const batch = await rest.request(`${repoBase(repo)}/commits/${ref}/statuses?per_page=${STATUS_PAGE_SIZE}&page=${page}`);
828
+ all.push(...batch);
829
+ if (batch.length < STATUS_PAGE_SIZE) break;
830
+ }
831
+ return all;
832
+ } };
833
+ }
814
834
  // src/teams/teams.ts
815
835
  const PAGE$1 = 100;
816
836
  /** A guard so a runaway listing cannot loop forever: 50 pages of 100 is far more than any team. */
@@ -1144,19 +1164,25 @@ const account = (value) => {
1144
1164
  type: typeof type === "string" ? type : ""
1145
1165
  } : null;
1146
1166
  };
1147
- async function appGet(creds, path, opts) {
1167
+ async function appFetch(creds, path, opts, method = "GET") {
1148
1168
  const jwt = await createAppJWT(creds);
1149
1169
  const baseUrl = opts.baseUrl ?? "https://api.github.com";
1150
- const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl}${path}`, { headers: {
1151
- authorization: `Bearer ${jwt}`,
1152
- accept: "application/vnd.github+json",
1153
- "x-github-api-version": "2022-11-28"
1154
- } });
1170
+ const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl}${path}`, {
1171
+ method,
1172
+ headers: {
1173
+ authorization: `Bearer ${jwt}`,
1174
+ accept: "application/vnd.github+json",
1175
+ "x-github-api-version": "2022-11-28"
1176
+ }
1177
+ });
1155
1178
  if (!res.ok) {
1156
1179
  const body = await res.text().catch(() => "");
1157
- throw new ProviderApiError(`GitHub GET ${path} → ${res.status}`, res.status, body);
1180
+ throw new ProviderApiError(`GitHub ${method} ${path} → ${res.status}`, res.status, body);
1158
1181
  }
1159
- return res.json();
1182
+ return res;
1183
+ }
1184
+ async function appGet(creds, path, opts) {
1185
+ return (await appFetch(creds, path, opts)).json();
1160
1186
  }
1161
1187
  /** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
1162
1188
  async function getApp(creds, opts = {}) {
@@ -1183,6 +1209,47 @@ async function listAppInstallations(creds, opts = {}) {
1183
1209
  if (raws.length < PAGE_SIZE) return installations;
1184
1210
  }
1185
1211
  }
1212
+ const DELIVERY_PAGES = 10;
1213
+ /** The `cursor` of the `rel="next"` link of a `Link` header, `undefined` when there is none. */
1214
+ function nextCursor(link) {
1215
+ const next = link?.split(",").find((part) => part.includes("rel=\"next\""));
1216
+ return /[?&]cursor=([^&>]+)/.exec(next ?? "")?.[1];
1217
+ }
1218
+ /**
1219
+ * The webhook deliveries of the App this JWT identifies, newest first (`GET /app/hook/deliveries`), a page at a time by
1220
+ * the cursor GitHub hands back, until a delivery older than `since`, the last page, or `maxPages`. A delivery older than
1221
+ * `since` is left out. Needs no repository permission: the App's own JWT is the credential.
1222
+ */
1223
+ async function listAppDeliveries(creds, opts = {}) {
1224
+ const deliveries = [];
1225
+ let cursor;
1226
+ for (let page = 0; page < (opts.maxPages ?? DELIVERY_PAGES); page++) {
1227
+ const res = await appFetch(creds, `/app/hook/deliveries?per_page=${PAGE_SIZE}${cursor === void 0 ? "" : `&cursor=${cursor}`}`, opts);
1228
+ const raws = await res.json();
1229
+ for (const raw of raws) deliveries.push({
1230
+ id: Number(raw.id),
1231
+ guid: String(raw.guid),
1232
+ deliveredAt: String(raw.delivered_at),
1233
+ redelivery: raw.redelivery === true,
1234
+ statusCode: Number(raw.status_code ?? 0),
1235
+ status: String(raw.status ?? ""),
1236
+ event: String(raw.event),
1237
+ action: typeof raw.action === "string" ? raw.action : null,
1238
+ installationId: typeof raw.installation_id === "number" ? raw.installation_id : null
1239
+ });
1240
+ cursor = nextCursor(res.headers.get("link"));
1241
+ const oldest = deliveries.at(-1);
1242
+ if (cursor === void 0 || opts.since !== void 0 && oldest !== void 0 && oldest.deliveredAt < opts.since) break;
1243
+ }
1244
+ return opts.since === void 0 ? deliveries : deliveries.filter((delivery) => delivery.deliveredAt >= opts.since);
1245
+ }
1246
+ /**
1247
+ * Asks GitHub to deliver one webhook delivery again (`POST /app/hook/deliveries/{id}/attempts`). GitHub answers 202 and
1248
+ * sends it asynchronously, so this says only that it was accepted.
1249
+ */
1250
+ async function redeliverAppDelivery(creds, deliveryId, opts = {}) {
1251
+ await appFetch(creds, `/app/hook/deliveries/${deliveryId}/attempts`, opts, "POST");
1252
+ }
1186
1253
  // src/webhooks/webhooks.ts
1187
1254
  /**
1188
1255
  * GitHub's own webhook mechanics — signature verification and header/
@@ -1236,6 +1303,7 @@ function createGitHubClient(opts) {
1236
1303
  return {
1237
1304
  branches: branches(rest),
1238
1305
  checks: checks(rest),
1306
+ statuses: statuses(rest),
1239
1307
  environments: environments(rest),
1240
1308
  git: git(rest),
1241
1309
  /** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
@@ -1259,4 +1327,4 @@ function createGitHubClient(opts) {
1259
1327
  workflows: workflows(rest)
1260
1328
  };
1261
1329
  }
1262
- export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getApp, getInstallationAccessToken, listAppInstallations, parseGitHubWebhookHeaders, parseTokenExpiration, verifyGitHubWebhookSignature };
1330
+ export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getApp, getInstallationAccessToken, listAppDeliveries, listAppInstallations, parseGitHubWebhookHeaders, parseTokenExpiration, redeliverAppDelivery, verifyGitHubWebhookSignature };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/github-client",
3
- "version": "1.58.0-alpha.52",
3
+ "version": "1.58.0-alpha.53",
4
4
  "description": "A TypeScript client for the GitHub REST API",
5
5
  "keywords": [
6
6
  "github",
@@ -32,8 +32,8 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@theholocron/observability": "^0.7.0-alpha.6",
36
- "@theholocron/http-client": "^1.58.0-alpha.52"
35
+ "@theholocron/http-client": "^1.58.0-alpha.53",
36
+ "@theholocron/observability": "^0.7.0-alpha.6"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^26",
@@ -47,8 +47,8 @@
47
47
  "vitest": "^5.1.0",
48
48
  "@theholocron/tsconfig": "^8.9.0-alpha.22",
49
49
  "@theholocron/eslint-config": "^8.9.0-alpha.22",
50
- "@theholocron/vitest-config": "^8.9.0-alpha.22",
51
- "@theholocron/tsdown-config": "^8.9.0-alpha.22"
50
+ "@theholocron/tsdown-config": "^8.9.0-alpha.22",
51
+ "@theholocron/vitest-config": "^8.9.0-alpha.22"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22.0.0"