@theholocron/github-client 1.58.0-alpha.57 → 1.58.0-alpha.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,6 +37,11 @@ const blob = await client.git.createBlob("owner/name", "file contents");
37
37
  // (one request each) and returns a flat list of full paths.
38
38
  const entries = await client.git.listDirectory("owner/name", ".holocron", { recursive: true });
39
39
  // [{ name, path, type: "file" | "dir" | "symlink" | "submodule", size, sha }]
40
+
41
+ // The same list in ONE request, through the git trees API. It answers `undefined`, and the caller lists the
42
+ // directory the other way, when it cannot answer for certain: a `ref` that is not the default branch, a full
43
+ // commit SHA or a branch name with no slash, a tree GitHub cut short, a 404 or a 422.
44
+ const tree = await client.git.listTree("owner/name", ".holocron", { ref: commitSha });
40
45
  ```
41
46
 
42
47
  ## Namespaces
@@ -55,7 +60,7 @@ const entries = await client.git.listDirectory("owner/name", ".holocron", { recu
55
60
  | `labels` | `listLabels`, `createLabel`, `updateLabel`, `deleteLabel` |
56
61
  | `topics` | `setTopics` |
57
62
  | `properties` | `setProperties` |
58
- | `git` | `getRef`, `getCommit`, `getTree`, `getContents`, `listDirectory`, `putContents`, `createBlob`, `createTree`, `createCommit`, `createRef`, `updateRef`, `createPull` |
63
+ | `git` | `getRef`, `getCommit`, `getTree`, `getContents`, `listDirectory`, `listTree`, `putContents`, `createBlob`, `createTree`, `createCommit`, `createRef`, `updateRef`, `createPull` |
59
64
  | `checks` | `createCheckRun` |
60
65
 
61
66
  GitHub accepts at most 50 annotations per check-run request. Slice with the
package/dist/index.d.mts CHANGED
@@ -1097,6 +1097,19 @@ export declare function listAppDeliveries(creds: GitHubAppCredentials, opts?: Li
1097
1097
  * sends it asynchronously, so this says only that it was accepted.
1098
1098
  */
1099
1099
  export declare function redeliverAppDelivery(creds: GitHubAppCredentials, deliveryId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<void>;
1100
+ /**
1101
+ * The installation of the App this JWT identifies on one repository (`GET /repos/{repo}/installation`), or `undefined`
1102
+ * when the App is not installed there (404). A caller with no webhook to read the installation id from (a scheduled
1103
+ * job) finds it here before it asks for an installation token. Needs only the App's own JWT.
1104
+ *
1105
+ * `repo` must be exactly `owner/name`: anything else (extra segments, an empty segment, `.` or `..`) throws before a
1106
+ * request is made, and each segment is URL-encoded, so a malformed value can never reach another route.
1107
+ *
1108
+ * https://docs.github.com/en/rest/apps/apps#get-a-repository-installation-for-the-authenticated-app
1109
+ *
1110
+ * @throws Error when `repo` is not `owner/name`.
1111
+ */
1112
+ export declare function getRepoInstallation(creds: GitHubAppCredentials, repo: string, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubAppInstallation | undefined>;
1100
1113
  /**
1101
1114
  * GitHub's own webhook mechanics — signature verification and header/
1102
1115
  * payload shapes. Pure functions, no REST call, no auth token: these
@@ -1219,6 +1232,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
1219
1232
  getTree: (repo: string, sha: string, recursive?: boolean) => Promise<GitTree>;
1220
1233
  getContents: (repo: string, path: string, ref?: string) => Promise<GitContents>;
1221
1234
  listDirectory: (repo: string, path: string, options?: ListDirectoryOptions) => Promise<GitDirectoryEntry[]>;
1235
+ listTree: (repo: string, path: string, options?: Pick<ListDirectoryOptions, "ref">) => Promise<GitDirectoryEntry[] | undefined>;
1222
1236
  putContents: (repo: string, path: string, input: PutContentsInput) => Promise<PutContentsResult>;
1223
1237
  createBlob: (repo: string, content: string, encoding?: string) => Promise<GitBlob>;
1224
1238
  createTree: (repo: string, tree: Array<{
package/dist/index.mjs CHANGED
@@ -175,6 +175,12 @@ function environments(rest) {
175
175
  };
176
176
  }
177
177
  // src/git/git.ts
178
+ /** What a git tree entry is, in the words of the contents API: a blob is a file, unless its mode says symlink. */
179
+ function treeEntryType(item) {
180
+ if (item.type === "tree") return "dir";
181
+ if (item.type === "commit") return "submodule";
182
+ return item.mode === "120000" ? "symlink" : "file";
183
+ }
178
184
  function git(rest) {
179
185
  return {
180
186
  getRef: (repo, branch) => rest.request(`${repoBase(repo)}/git/ref/heads/${branch}`),
@@ -220,6 +226,36 @@ function git(rest) {
220
226
  return list(path.replace(/^\/+|\/+$/g, ""));
221
227
  },
222
228
  /**
229
+ * Lists a directory and everything under it in ONE request, through the git trees API
230
+ * (`GET /repos/:repo/git/trees/<ref>:<path>?recursive=1`), as the same flat list of full paths
231
+ * `listDirectory(..., { recursive: true })` returns, which makes one request per directory. It answers
232
+ * `undefined`, so the caller can list the directory the other way, when it cannot answer for certain:
233
+ * a `ref` that is not the default branch, a full commit SHA or a branch name with no slash (a name with a
234
+ * slash is ambiguous in this form and GitHub answers 404), a tree GitHub cut short (`truncated`), a directory GitHub says it does not have (404) or a
235
+ * request it cannot read (422). Any other failure throws. Checked against the live API with `HEAD`, a
236
+ * commit SHA and a plain branch name, and a missing directory.
237
+ */
238
+ listTree: async (repo, path, options = {}) => {
239
+ const dir = path.replace(/^\/+|\/+$/g, "");
240
+ const ref = options.ref ?? "HEAD";
241
+ if (!/^(HEAD|[0-9a-f]{40}|[\w.-]+)$/i.test(ref)) return void 0;
242
+ let tree;
243
+ try {
244
+ tree = await rest.request(`${repoBase(repo)}/git/trees/${ref}:${filePath(dir)}`, { query: { recursive: "1" } });
245
+ } catch (err) {
246
+ if (err instanceof ProviderApiError && (err.status === 404 || err.status === 422)) return void 0;
247
+ throw err;
248
+ }
249
+ if (tree.truncated) return void 0;
250
+ return tree.tree.map((item) => ({
251
+ name: item.path.slice(item.path.lastIndexOf("/") + 1),
252
+ path: `${dir}/${item.path}`,
253
+ type: treeEntryType(item),
254
+ size: item.size ?? 0,
255
+ sha: item.sha
256
+ }));
257
+ },
258
+ /**
223
259
  * `PUT /repos/:repo/contents/:path` — creates or updates one file in a single commit. Pass `sha` when
224
260
  * updating so a concurrent change is refused (409) and not silently overwritten.
225
261
  */
@@ -1264,6 +1300,37 @@ async function listAppDeliveries(creds, opts = {}) {
1264
1300
  async function redeliverAppDelivery(creds, deliveryId, opts = {}) {
1265
1301
  await appFetch(creds, `/app/hook/deliveries/${deliveryId}/attempts`, opts, "POST");
1266
1302
  }
1303
+ /**
1304
+ * The installation of the App this JWT identifies on one repository (`GET /repos/{repo}/installation`), or `undefined`
1305
+ * when the App is not installed there (404). A caller with no webhook to read the installation id from (a scheduled
1306
+ * job) finds it here before it asks for an installation token. Needs only the App's own JWT.
1307
+ *
1308
+ * `repo` must be exactly `owner/name`: anything else (extra segments, an empty segment, `.` or `..`) throws before a
1309
+ * request is made, and each segment is URL-encoded, so a malformed value can never reach another route.
1310
+ *
1311
+ * https://docs.github.com/en/rest/apps/apps#get-a-repository-installation-for-the-authenticated-app
1312
+ *
1313
+ * @throws Error when `repo` is not `owner/name`.
1314
+ */
1315
+ async function getRepoInstallation(creds, repo, opts = {}) {
1316
+ const parts = repo.split("/");
1317
+ if (parts.length !== 2 || parts.some((p) => p === "" || p === "." || p === "..")) throw new Error(`a repository is "owner/name", not "${repo}"`);
1318
+ const [owner, name] = parts.map(encodeURIComponent);
1319
+ let raw;
1320
+ try {
1321
+ raw = await appGet(creds, `/repos/${owner}/${name}/installation`, opts);
1322
+ } catch (err) {
1323
+ if (err instanceof ProviderApiError && err.status === 404) return void 0;
1324
+ throw err;
1325
+ }
1326
+ return {
1327
+ id: Number(raw.id),
1328
+ account: account(raw.account),
1329
+ permissions: raw.permissions ?? {},
1330
+ events: raw.events ?? [],
1331
+ suspended: typeof raw.suspended_at === "string"
1332
+ };
1333
+ }
1267
1334
  // src/webhooks/webhooks.ts
1268
1335
  /**
1269
1336
  * GitHub's own webhook mechanics — signature verification and header/
@@ -1341,4 +1408,4 @@ function createGitHubClient(opts) {
1341
1408
  workflows: workflows(rest)
1342
1409
  };
1343
1410
  }
1344
- export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getApp, getInstallationAccessToken, listAppDeliveries, listAppInstallations, parseGitHubWebhookHeaders, parseTokenExpiration, redeliverAppDelivery, suspendAppInstallation, unsuspendAppInstallation, verifyGitHubWebhookSignature };
1411
+ export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getApp, getInstallationAccessToken, getRepoInstallation, listAppDeliveries, listAppInstallations, parseGitHubWebhookHeaders, parseTokenExpiration, redeliverAppDelivery, suspendAppInstallation, unsuspendAppInstallation, verifyGitHubWebhookSignature };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/github-client",
3
- "version": "1.58.0-alpha.57",
3
+ "version": "1.58.0-alpha.59",
4
4
  "description": "A TypeScript client for the GitHub REST API",
5
5
  "keywords": [
6
6
  "github",
@@ -32,23 +32,23 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@theholocron/http-client": "^1.58.0-alpha.57",
35
+ "@theholocron/http-client": "^1.58.0-alpha.59",
36
36
  "@theholocron/observability": "^0.7.0-alpha.7"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^26",
40
- "@vitest/coverage-v8": "^5.1.0",
40
+ "@vitest/coverage-v8": "^5.1.1",
41
41
  "@vitest/eslint-plugin": "^1.6.28",
42
42
  "eslint": "^10.15.0",
43
43
  "eslint-plugin-n": "^18.5.0",
44
44
  "globals": "^17.14.0",
45
45
  "tsdown": "^0.23.7",
46
46
  "typescript": "^6.0.3",
47
- "vitest": "^5.1.0",
48
- "@theholocron/tsdown-config": "^8.9.0-alpha.22",
49
- "@theholocron/vitest-config": "^8.9.0-alpha.22",
50
- "@theholocron/tsconfig": "^8.9.0-alpha.22",
51
- "@theholocron/eslint-config": "^8.9.0-alpha.22"
47
+ "vitest": "^5.1.1",
48
+ "@theholocron/eslint-config": "^8.9.0-alpha.23",
49
+ "@theholocron/tsconfig": "^8.9.0-alpha.23",
50
+ "@theholocron/tsdown-config": "^8.9.0-alpha.23",
51
+ "@theholocron/vitest-config": "^8.9.0-alpha.23"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22.0.0"