@theholocron/github-client 1.58.0-alpha.13 → 1.58.0-alpha.15

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
@@ -412,6 +412,12 @@ interface OrgProperty {
412
412
  required?: boolean;
413
413
  /** The values a `single_select` or `multi_select` property accepts; `null` for any other type. */
414
414
  allowed_values?: string[] | null;
415
+ /** The value a repository gets when it sets none, or `null`. */
416
+ default_value?: string | string[] | null;
417
+ /** A line saying what the property is for, or `null`. */
418
+ description?: string | null;
419
+ /** Who may edit the property's value on a repository: `org_actors` or `org_and_repo_actors`, or `null`. */
420
+ values_editable_by?: string | null;
415
421
  }
416
422
  /** One custom property value set on a repository. */
417
423
  interface RepoPropertyValue {
@@ -799,6 +805,41 @@ export declare function createAppJWT(creds: GitHubAppCredentials, now?: number):
799
805
  export declare function getInstallationAccessToken(creds: GitHubAppCredentials, installationId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<InstallationAccessToken>;
800
806
  /** The whole flow in one call — an already-authenticated `GitHubClient` scoped to one installation. */
801
807
  export declare function createInstallationClient(creds: GitHubAppCredentials, installationId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubClient>;
808
+ /** The account an App or one of its installations belongs to. */
809
+ interface GitHubAppAccount {
810
+ /** The user or organization login. */
811
+ login: string;
812
+ /** `User` or `Organization` (GitHub also reports `Enterprise` for an enterprise-owned App). */
813
+ type: string;
814
+ }
815
+ /** An App as `GET /app` reports it. */
816
+ interface GitHubApp {
817
+ /** The App's URL name, as in `github.com/apps/<slug>`. */
818
+ slug: string;
819
+ /** The App's display name. */
820
+ name: string;
821
+ /** Who owns the App: decides which settings page its permissions live on. */
822
+ owner: GitHubAppAccount | null;
823
+ /** The permissions the App asks for now: name to `read`, `write` or `admin`. */
824
+ permissions: Record<string, string>;
825
+ /** The webhook events the App is subscribed to now. */
826
+ events: string[];
827
+ }
828
+ /** One installation of an App as `GET /app/installations` reports it. */
829
+ interface GitHubAppInstallation {
830
+ /** The installation id. */
831
+ id: number;
832
+ /** The account the App is installed on. */
833
+ account: GitHubAppAccount | null;
834
+ /** What this installation has accepted: it lags the App's own list until an owner accepts a new request. */
835
+ permissions: Record<string, string>;
836
+ /** The events delivered to this installation. */
837
+ events: string[];
838
+ }
839
+ /** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
840
+ export declare function getApp(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubApp>;
841
+ /** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
842
+ export declare function listAppInstallations(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubAppInstallation[]>;
802
843
  /**
803
844
  * GitHub's own webhook mechanics — signature verification and header/
804
845
  * payload shapes. Pure functions, no REST call, no auth token: these
@@ -966,6 +1007,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
966
1007
  properties: {
967
1008
  getValues: (repo: string) => Promise<RepoPropertyValue[]>;
968
1009
  orgSchema: (org: string) => Promise<OrgProperty[]>;
1010
+ setOrgProperty: (org: string, property: OrgProperty) => Promise<OrgProperty>;
969
1011
  setProperties: (repo: string, values: Record<string, string | string[]>) => Promise<void>;
970
1012
  };
971
1013
  pulls: {
@@ -1035,4 +1077,4 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
1035
1077
  };
1036
1078
  /** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
1037
1079
  export type GitHubClient = ReturnType<typeof createGitHubClient>;
1038
- export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreatePagesPayload, CreatePullInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitDirectoryEntry, GitHubAppCredentials, GitHubCheckRun, GitHubClientOptions, GitHubContents, GitHubEnvironment, GitHubInstallationWebhookPayload, GitHubIssue, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, GraphQLClient, InstallationAccessToken, IssueSearchParams, ListDirectoryOptions, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
1080
+ export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreatePagesPayload, CreatePullInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitDirectoryEntry, GitHubApp, GitHubAppAccount, GitHubAppCredentials, GitHubAppInstallation, GitHubCheckRun, GitHubClientOptions, GitHubContents, GitHubEnvironment, GitHubInstallationWebhookPayload, GitHubIssue, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, GraphQLClient, InstallationAccessToken, IssueSearchParams, ListDirectoryOptions, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
package/dist/index.mjs CHANGED
@@ -345,6 +345,19 @@ function properties(rest) {
345
345
  */
346
346
  orgSchema: (org) => rest.request(`/orgs/${segment(org)}/properties/schema`),
347
347
  /**
348
+ * Creates or replaces one custom property definition of the organization. GitHub replaces the whole definition,
349
+ * so send back every field the property already has (`orgSchema` has them); a field left out is reset.
350
+ * The token needs write access to the organization's custom properties (`Custom properties: admin`).
351
+ */
352
+ setOrgProperty: (org, property) => {
353
+ const { property_name, ...definition } = property;
354
+ const body = Object.fromEntries(Object.entries(definition).filter(([, v]) => v !== void 0));
355
+ return rest.request(`/orgs/${segment(org)}/properties/schema/${segment(property_name)}`, {
356
+ method: "PUT",
357
+ body
358
+ });
359
+ },
360
+ /**
348
361
  * `value` is a plain string for `string`/`single_select`/`true_false`
349
362
  * custom properties, or a string array for `multi_select` ones —
350
363
  * GitHub's own PATCH body accepts either per property. A single-string
@@ -891,6 +904,62 @@ async function createInstallationClient(creds, installationId, opts = {}) {
891
904
  fetch: opts.fetch
892
905
  });
893
906
  }
907
+ // src/app-info/app-info.ts
908
+ /**
909
+ * What a GitHub App is right now, read with the App's own JWT (`GET /app`, `GET /app/installations`). GitHub has no
910
+ * endpoint that changes an existing App's permissions or event subscriptions, so these reads are how a caller
911
+ * checks the settings page was done by hand.
912
+ *
913
+ * https://docs.github.com/en/rest/apps/apps#get-the-authenticated-app
914
+ * https://docs.github.com/en/rest/apps/apps#list-installations-for-the-authenticated-app
915
+ */
916
+ const PAGE_SIZE = 100;
917
+ const account = (value) => {
918
+ const { login, type } = value ?? {};
919
+ return typeof login === "string" ? {
920
+ login,
921
+ type: typeof type === "string" ? type : ""
922
+ } : null;
923
+ };
924
+ async function appGet(creds, path, opts) {
925
+ const jwt = await createAppJWT(creds);
926
+ const baseUrl = opts.baseUrl ?? "https://api.github.com";
927
+ const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl}${path}`, { headers: {
928
+ authorization: `Bearer ${jwt}`,
929
+ accept: "application/vnd.github+json",
930
+ "x-github-api-version": "2022-11-28"
931
+ } });
932
+ if (!res.ok) {
933
+ const body = await res.text().catch(() => "");
934
+ throw new ProviderApiError(`GitHub GET ${path} → ${res.status}`, res.status, body);
935
+ }
936
+ return res.json();
937
+ }
938
+ /** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
939
+ async function getApp(creds, opts = {}) {
940
+ const raw = await appGet(creds, "/app", opts);
941
+ return {
942
+ slug: String(raw.slug),
943
+ name: String(raw.name),
944
+ owner: account(raw.owner),
945
+ permissions: raw.permissions ?? {},
946
+ events: raw.events ?? []
947
+ };
948
+ }
949
+ /** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
950
+ async function listAppInstallations(creds, opts = {}) {
951
+ const installations = [];
952
+ for (let page = 1;; page++) {
953
+ const raws = await appGet(creds, `/app/installations?per_page=${PAGE_SIZE}&page=${page}`, opts);
954
+ for (const raw of raws) installations.push({
955
+ id: Number(raw.id),
956
+ account: account(raw.account),
957
+ permissions: raw.permissions ?? {},
958
+ events: raw.events ?? []
959
+ });
960
+ if (raws.length < PAGE_SIZE) return installations;
961
+ }
962
+ }
894
963
  // src/webhooks/webhooks.ts
895
964
  /**
896
965
  * GitHub's own webhook mechanics — signature verification and header/
@@ -964,4 +1033,4 @@ function createGitHubClient(opts) {
964
1033
  workflows: workflows(rest)
965
1034
  };
966
1035
  }
967
- export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getInstallationAccessToken, parseGitHubWebhookHeaders, parseTokenExpiration, verifyGitHubWebhookSignature };
1036
+ export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getApp, getInstallationAccessToken, listAppInstallations, parseGitHubWebhookHeaders, parseTokenExpiration, verifyGitHubWebhookSignature };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/github-client",
3
- "version": "1.58.0-alpha.13",
3
+ "version": "1.58.0-alpha.15",
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.1",
36
- "@theholocron/http-client": "^1.58.0-alpha.13"
35
+ "@theholocron/http-client": "^1.58.0-alpha.15",
36
+ "@theholocron/observability": "^0.7.0-alpha.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^26",
@@ -45,10 +45,10 @@
45
45
  "tsdown": "^0.23.4",
46
46
  "typescript": "^5.9.3",
47
47
  "vitest": "^5.0.5",
48
+ "@theholocron/tsconfig": "^8.9.0-alpha.9",
48
49
  "@theholocron/eslint-config": "^8.9.0-alpha.9",
49
50
  "@theholocron/tsdown-config": "^8.9.0-alpha.9",
50
- "@theholocron/vitest-config": "^8.9.0-alpha.9",
51
- "@theholocron/tsconfig": "^8.9.0-alpha.9"
51
+ "@theholocron/vitest-config": "^8.9.0-alpha.9"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22.0.0"