@bridge-ds/core 0.2.0 → 0.3.0

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.
@@ -1,9 +1,59 @@
1
1
  import { type BridgeConfig } from './config';
2
+ import type { ClassicProtection, Ruleset, RulesetPayload } from './protection';
3
+ /**
4
+ * What an auth failure means for the token:
5
+ * - "rejected": GitHub refused the token itself (401). It was revoked, regenerated or has expired; every call
6
+ * with it will fail until it is replaced.
7
+ * - "missing-permission": the token works but lacks a permission this call needs (403 "Resource not accessible
8
+ * by personal access token", or a permission GitHub names in X-Accepted-GitHub-Permissions).
9
+ * Undefined for everything else, including rate limits and a missing token.
10
+ */
11
+ export type GitHubAuthState = 'rejected' | 'missing-permission';
12
+ /** Fine-grained token permission names, as GitHub spells them (issues, pull_requests, contents...). */
13
+ export type GitHubPermission = string;
14
+ export interface GitHubErrorInfo {
15
+ auth?: GitHubAuthState | undefined;
16
+ /** The permission the call needed, when GitHub or the endpoint tells (only with auth "missing-permission"). */
17
+ permission?: GitHubPermission | undefined;
18
+ }
2
19
  export declare class GitHubError extends Error {
3
20
  readonly status: number;
4
21
  readonly detail?: string | undefined;
5
- constructor(status: number, message: string, detail?: string | undefined);
22
+ /** Set when the failure is about the token: rejected (401) or missing a permission (403). */
23
+ readonly auth: GitHubAuthState | undefined;
24
+ /** With auth "missing-permission": the permission the call needed, when known. */
25
+ readonly permission: GitHubPermission | undefined;
26
+ constructor(status: number, message: string, detail?: string | undefined, info?: GitHubErrorInfo);
6
27
  }
28
+ /** True when `err` says GitHub refused the token itself (revoked, regenerated or expired). */
29
+ export declare const isTokenRejected: (err: unknown) => boolean;
30
+ /** True when `err` says the token works but lacks a permission for that call. */
31
+ export declare const isMissingPermission: (err: unknown) => boolean;
32
+ /** "pull_requests" -> "Pull requests", as GitHub labels it on the token page. */
33
+ export declare function permissionLabel(permission: GitHubPermission): string;
34
+ /** Where a fine-grained token's permissions are edited. */
35
+ export declare const TOKEN_SETTINGS_URL = "https://github.com/settings/personal-access-tokens";
36
+ /** The one sentence for a token GitHub no longer accepts. */
37
+ export declare const TOKEN_REJECTED_MESSAGE = "Your GitHub token stopped working. It was revoked, regenerated or has expired: replace it with a new one.";
38
+ /**
39
+ * "This token cannot create issues. Add Issues: Read and write on GitHub." `action` is a verb phrase
40
+ * ("create issues"); without it the sentence names only the permission.
41
+ */
42
+ export declare function missingPermissionMessage(permission: GitHubPermission | undefined, action?: string): string;
43
+ /**
44
+ * The permission a refused call needed. GitHub names it in X-Accepted-GitHub-Permissions ("issues=write",
45
+ * alternatives split by ";"); otherwise the endpoint says it (/issues, /pulls, /contents, /git...).
46
+ */
47
+ export declare function requiredPermission(path: string, acceptedHeader?: string | null): GitHubPermission | undefined;
48
+ /**
49
+ * Classifies a GitHub error response for the token. 401 with a token sent = rejected. 403 (not a rate limit,
50
+ * not archived) where GitHub names a permission or says the resource is not accessible = missing permission.
51
+ */
52
+ export declare function classifyAuth(status: number, detail: string, opts?: {
53
+ path?: string;
54
+ acceptedPermissions?: string | null;
55
+ withToken?: boolean;
56
+ }): GitHubErrorInfo;
7
57
  export interface RepoInfo {
8
58
  fullName: string;
9
59
  defaultBranch: string;
@@ -80,6 +130,8 @@ export interface CheckRun {
80
130
  status: string;
81
131
  conclusion: string | null;
82
132
  url: string | undefined;
133
+ /** Slug of the GitHub App that reported it ("github-actions", "vercel"), when GitHub says. */
134
+ app?: string | undefined;
83
135
  }
84
136
  export interface CommitSummary {
85
137
  sha: string;
@@ -231,6 +283,13 @@ export declare class GitHubClient {
231
283
  /** Best effort: labels need the repo to allow it; failure is not fatal. */
232
284
  addLabels(issueNumber: number, labels: string[]): Promise<boolean>;
233
285
  addComment(issueNumber: number, body: string): Promise<void>;
286
+ /** Comments on an issue or pull request, oldest first (first 100: the sticky preview comment is posted early). */
287
+ listIssueComments(issueNumber: number): Promise<{
288
+ id: number;
289
+ body: string;
290
+ author: string;
291
+ updatedAt: string;
292
+ }[]>;
234
293
  createIssue(input: {
235
294
  title: string;
236
295
  body: string;
@@ -244,6 +303,34 @@ export declare class GitHubClient {
244
303
  perPage?: number;
245
304
  }): Promise<IssueSummary[]>;
246
305
  getIssue(n: number): Promise<IssueSummary>;
306
+ /** Edits an issue: its body, or closes it with a reason ("not_planned" for a declined request). */
307
+ updateIssue(n: number, patch: {
308
+ body?: string;
309
+ state?: 'open' | 'closed';
310
+ state_reason?: 'completed' | 'not_planned' | 'reopened';
311
+ }): Promise<IssueSummary>;
312
+ /** Adds people to an issue's assignees (GitHub ignores logins that cannot be assigned: the result says who is). */
313
+ addAssignees(n: number, logins: string[]): Promise<string[]>;
314
+ /** People with at least `permission` on the repository (reading the list needs push access). First 100. */
315
+ listCollaborators(permission?: 'pull' | 'triage' | 'push' | 'maintain' | 'admin'): Promise<{
316
+ login: string;
317
+ avatarUrl: string;
318
+ }[]>;
319
+ /** Whether a token is sent with each request (TeamReader). */
320
+ get hasToken(): boolean;
321
+ /** Every page of a list endpoint (per_page 100), up to `maxPages`. */
322
+ private paginate;
323
+ /** Every member login of an organization team (needs read:org, or Members: Read on a fine-grained token). */
324
+ listTeamMembers(org: string, slug: string): Promise<string[]>;
325
+ /** A user's membership of a team: "active", "pending", or null when GitHub says they are not a member (404). */
326
+ getTeamMembership(org: string, slug: string, login: string): Promise<'active' | 'pending' | null>;
327
+ /** "User" or "Organization" for a login, null when GitHub does not know it. */
328
+ getAccountType(login: string): Promise<'User' | 'Organization' | null>;
329
+ /** The organization's teams this token can see. */
330
+ listOrgTeams(org: string): Promise<{
331
+ slug: string;
332
+ name: string;
333
+ }[]>;
247
334
  /** Create or update a binary file (base64 content) on a branch, e.g. a Figma export attached to a request. */
248
335
  putBase64File(input: {
249
336
  path: string;
@@ -311,6 +398,23 @@ export declare class GitHubClient {
311
398
  conclusion: string | null;
312
399
  }[];
313
400
  }>;
401
+ /** Commit statuses of a commit, newest first (Vercel reports each project as "Vercel – <project>"). */
402
+ listCommitStatuses(sha: string): Promise<{
403
+ context: string;
404
+ state: string;
405
+ target_url: string | null;
406
+ description: string | null;
407
+ }[]>;
408
+ /**
409
+ * GitHub deployments of a commit with their latest status (environment "Preview – <project>", environment_url the
410
+ * preview). Latest per environment only, so it costs one read plus one per environment.
411
+ */
412
+ listDeployments(sha: string): Promise<{
413
+ id: number;
414
+ environment: string;
415
+ state: string | null;
416
+ environmentUrl: string | null;
417
+ }[]>;
314
418
  getPullRequest(n: number): Promise<PullRequest & PullRequestSummary & {
315
419
  body: string;
316
420
  mergeable: boolean | null;
@@ -328,6 +432,20 @@ export declare class GitHubClient {
328
432
  body: string;
329
433
  }): Promise<Review>;
330
434
  listCheckRuns(ref: string): Promise<CheckRun[]>;
435
+ /** Rulesets that apply to the repository, without their rules (GET /rulesets; read access is enough). */
436
+ listRulesets(): Promise<Ruleset[]>;
437
+ /** One ruleset with its rules. */
438
+ getRuleset(id: number): Promise<Ruleset>;
439
+ /** Creates a repository ruleset. Needs admin on the repo (fine-grained token: Administration read and write). */
440
+ createRuleset(payload: RulesetPayload): Promise<Ruleset>;
441
+ /** Replaces a repository ruleset (same permissions as createRuleset). */
442
+ updateRuleset(id: number, payload: RulesetPayload): Promise<Ruleset>;
443
+ /**
444
+ * Classic branch protection of `branch`: the settings, null when the branch has none (404), undefined when this
445
+ * token cannot read them (403: the endpoint needs admin). On a 403 the public branch summary still tells
446
+ * whether the branch is protected at all: `protected: false` means there is nothing to read, so null.
447
+ */
448
+ getBranchProtection(branch: string): Promise<ClassicProtection | null | undefined>;
331
449
  /** Create a check run (needs a GitHub App token; personal tokens are refused by GitHub). */
332
450
  createCheckRun(input: {
333
451
  name: string;
@@ -342,7 +460,7 @@ export declare class GitHubClient {
342
460
  }): Promise<CheckRun>;
343
461
  removeLabel(issueNumber: number, label: string): Promise<void>;
344
462
  }
345
- export declare function friendlyMessage(status: number, detail: string): string;
463
+ export declare function friendlyMessage(status: number, detail: string, info?: GitHubErrorInfo): string;
346
464
  export interface RepoFiles {
347
465
  commitSha: string;
348
466
  treeSha: string;
package/dist/index.d.ts CHANGED
@@ -18,18 +18,25 @@ export * from './layered';
18
18
  export * from './token-edits';
19
19
  export * from './layered-review';
20
20
  export * from './governance';
21
+ export * from './rights';
22
+ export * from './teams';
23
+ export * from './protection';
24
+ export * from './protection-github';
21
25
  export * from './usage';
22
26
  export * from './github-client';
23
27
  export * from './history';
24
28
  export * from './history-github';
25
29
  export * from './history-demo';
26
30
  export * from './previews';
31
+ export * from './previews-github';
27
32
  export * from './ramps';
28
33
  export * from './brand';
29
34
  export * from './docs-draft';
35
+ export * from './docs-ai';
30
36
  export * from './requests';
31
37
  export * from './change-drafts';
32
38
  export * from './draft-exchange';
33
39
  export * from './explorations';
34
40
  export * from './explorations-github';
41
+ export * from './requests-github';
35
42
  export * from './component-spec';