Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
1,015 linesCodeBlameRaw
1import type { SoundSettings, SoundSettingsChange } from "./sounds";
2import type { AccessClient, BasePermission, RepoGrant } from "./access";
3import type { Permissions, ScopeLevel, ScopeResource } from "./scopes";
4import type { MemberPrivileges, OrgRole, PolicyHold } from "./members";
5import type { Acting, CreateRunCredentialInput, RunBinding } from "./audit";
6import type { RepoPath } from "./repos";
7import type { Result } from "./result";
8import type { TeamCreation, TeamsClient } from "./teams";
9import type { PeopleClient } from "./people";
10import type { DeployKeysClient } from "./deploy-keys";
11import type { EmailConfirmed } from "./accounts";
12
13export type User = {
14 id: string;
15 /** Lowercased: what the person is found, linked and mentioned by. */
16 username: string;
17 /**
18 * The username as its owner wrote it (`Ana`), when that differs from
19 * `username`: what pages show (`shownUsername`). Set on the signed-in
20 * person and on people looked up by name.
21 */
22 display_username?: string;
23 /**
24 * `workspace` when a workspace is acting through one of its own access
25 * tokens: `id` is then the workspace's and `username` its slug. `system`
26 * is g1t itself doing platform work, such as a security update
27 * (`username` `g1t`). Absent means `user`.
28 */
29 kind?: "user" | "workspace" | "agent" | "system";
30 /**
31 * Whether the account's email address is confirmed. Only set on users
32 * resolved from credentials. An account that has not confirmed it can
33 * only confirm it: see `awaitsConfirmation`.
34 */
35 verified?: boolean;
36 /**
37 * The workspaces this user belongs to. Set on users resolved from
38 * credentials, so any service can authorize from it.
39 */
40 workspaces?: Membership[];
41 /**
42 * The person's uploaded avatar: the SHA-256 of its bytes, served at
43 * `/avatars/<avatar>`. Only set on the signed-in person; absent means
44 * the generated letter avatar.
45 */
46 avatar?: string;
47 /**
48 * Set on an agent resolved from its token: who it acts for ("g1t
49 * on behalf of syntaqx"), with which credential, and what it may do.
50 */
51 acting?: Acting;
52 /**
53 * The repositories this user has a role on directly, whether or not they
54 * belong to its workspace. Set with `workspaces`; see `access.ts`.
55 */
56 grants?: RepoGrant[];
57 /**
58 * Set on a user resolved from an access token: its scopes (null for full
59 * access) and the workspaces or repositories it reaches. See scopes.ts.
60 */
61 token?: {
62 token_id: string;
63 scopes?: string[] | null;
64 legacy?: boolean;
65 /** The token's name, as its owner gave it. */
66 name?: string;
67 /**
68 * A token narrowed to one workspace (or none): its workspace and
69 * repositories. The key is kept from before tokens were one kind.
70 */
71 fine_grained?: {
72 workspace?: string | null;
73 repositories?: "all" | "selected" | "public";
74 repo_ids?: string[];
75 };
76 /** A workspace's own token with Repositories: admin. */
77 admin?: boolean;
78 /** Set on what a deploy key resolves to. */
79 deploy_key?: string;
80 /** The one repository a job's token or a deploy key reaches. */
81 repo?: string;
82 /** Set on a workflow job's token (`G1T_TOKEN`): the run and job it was made for. */
83 job?: { run_id: string; job_id: string; pull_requests?: boolean };
84 /**
85 * A person's token whose owner let it use the website as them, sent as
86 * `Authorization: Bearer` (apps/web, lib/website-token.ts). Not a scope.
87 */
88 website?: boolean;
89 };
90 /**
91 * Workspaces the person belongs to but cannot use until they meet its
92 * policy, such as turning on two-factor authentication. Left out of
93 * `workspaces` and `grants` meanwhile.
94 */
95 held?: PolicyHold[];
96};
97
98/** What a member may do: an owner also manages the workspace's members. */
99export type Role = "owner" | "member";
100
101export type Membership = {
102 /** The workspace's name in URLs: `g1t.sh/<slug>`. */
103 slug: string;
104 role: Role;
105 /** Its display name. Set on users resolved from credentials. */
106 name?: string;
107 /** Its uploaded icon, as `Workspace.avatar`. */
108 avatar?: string;
109 /** The workspace's base permission: what members get on every repository. Absent means `write`. */
110 base_permission?: BasePermission;
111 /** Who may create its teams. Absent means any member. */
112 team_creation?: TeamCreation;
113 /** The roles held besides owner or member. */
114 org_roles?: OrgRole[];
115 /** What the workspace lets its members do. Absent means the defaults. */
116 privileges?: MemberPrivileges;
117 /**
118 * Whether this member uses Code: repositories, issues, pull requests,
119 * checks, deploys. False for people who only use Chat, Docs and agents
120 * (support, sales, finance): they see no repository, whatever the base
121 * permission, and agents treat them as unable to change code. Absent
122 * means true.
123 */
124 code_access?: boolean;
125};
126
127/** Whether a member uses Code. See `Membership.code_access`. */
128export function hasCodeAccess(membership: Pick<Membership, "code_access"> | null | undefined): boolean {
129 return membership?.code_access !== false;
130}
131
132/** How long an old workspace slug redirects, and stays reserved for it, after a rename. */
133export const SLUG_HOLD_DAYS = 90;
134
135/** How long a workspace must wait between renames. */
136export const RENAME_COOLDOWN_HOURS = 24;
137
138/** The largest avatar that can be uploaded, in bytes. */
139export const MAX_AVATAR_BYTES = 1024 * 1024;
140
141/**
142 * Where a workspace keeps its repositories' git data: anywhere g1t stores
143 * it (the default), or in the EU only. It applies to repositories made
144 * after it is set.
145 */
146export type DataResidency = "anywhere" | "eu";
147
148/**
149 * A workspace: the owner of repositories, and the first segment of their
150 * URLs. A person's own space and a team's are the same thing.
151 */
152export type Workspace = {
153 id: string;
154 slug: string;
155 name: string;
156 /** One line saying what the workspace is for. */
157 description: string | null;
158 /** RFC 3339. */
159 createdAt: string;
160 memberCount: number;
161 /**
162 * The workspace's uploaded icon: the SHA-256 of its bytes, served at
163 * `/avatars/<avatar>`. Null means the generated letter avatar.
164 */
165 avatar: string | null;
166 /** What every member gets on each repository; owners have Admin. */
167 basePermission?: BasePermission;
168 /** Who may create its teams. Absent means any member. */
169 teamCreation?: TeamCreation;
170 /** Whether members and outside collaborators need two-factor authentication. */
171 twoFactorRequirementEnabled?: boolean;
172} & Partial<MemberPrivileges>;
173
174export type Member = {
175 username: string;
176 /** The username as its owner wrote it (`Ana`), when that differs from `username`. */
177 display_username?: string;
178 role: Role;
179 /** The roles they hold besides `role`. */
180 org_roles?: OrgRole[];
181 /** Whether two-factor authentication is on; owners only, null for anyone else. */
182 two_factor?: boolean | null;
183 /** Their display name, when they set one. */
184 name?: string | null;
185 /** Their uploaded avatar's hash, served at `/avatars/<avatar>`; null for the generated letter avatar. */
186 avatar?: string | null;
187};
188
189/** An owner of a workspace, as staff see them. */
190export type AdminOwner = { username: string; email: string | null };
191
192/** A workspace as staff see it. Mirrors `AdminWorkspace` in `crates/contracts/src/identity.rs`. */
193export type AdminWorkspace = {
194 slug: string;
195 name: string;
196 /** RFC 3339. */
197 createdAt: string;
198 owners: AdminOwner[];
199 memberCount: number;
200};
201
202/** A member of a workspace, as staff see them. */
203export type AdminMember = { username: string; email: string | null; role: Role; /** RFC 3339. */ joined: string };
204
205export type AdminWorkspaceDetail = {
206 slug: string;
207 name: string;
208 description: string | null;
209 /** RFC 3339. */
210 createdAt: string;
211 /** Owners first, then by username. */
212 members: AdminMember[];
213 /** It can never be deleted, by anyone (identity's `PROTECTED_WORKSPACES`). */
214 protected: boolean;
215 /** Set while staff have it suspended. */
216 suspended?: Suspension | null;
217};
218
219/** The most workspaces one `workspaces` call returns. */
220export const ADMIN_WORKSPACES_LIMIT = 500;
221
222/** How long an invite works, unless identity's `INVITE_TTL_DAYS` says otherwise. */
223export const INVITE_TTL_DAYS = 30;
224/** The most characters an invitation's note keeps (`invite_member`'s `message`). */
225export const MAX_INVITE_MESSAGE = 500;
226
227/** Only a pending invite can be used or revoked. */
228/**
229 * `awaiting_confirmation`: used to make an account that has not confirmed its
230 * email address yet; what it gives is joined when the address is confirmed,
231 * unless it is revoked first.
232 */
233/**
234 * `awaiting_answer`: the account it made is confirmed, and the workspace it
235 * names waits for the person to accept or decline. `declined`: they said no.
236 */
237export type InviteStatus =
238 | "pending"
239 | "awaiting_confirmation"
240 | "awaiting_answer"
241 | "redeemed"
242 | "declined"
243 | "expired"
244 | "revoked";
245
246/** One invite. Mirrors `Invite` in `crates/contracts/src/identity.rs`. */
247export type Invite = {
248 id: string;
249 /** `g1t-k7m2-…`: returned when it is made, and to its maker while pending. */
250 code: string | null;
251 /** The code's first group, such as `g1t-k7m2`. */
252 hint: string;
253 /** Only this address can use it. */
254 email: string | null;
255 /** `account` makes an account; `workspace` joins an existing one to `workspace`. */
256 kind: "account" | "workspace";
257 /** The workspace using it joins. */
258 workspace: string | null;
259 status: InviteStatus;
260 /** Its maker's username; null when g1t staff made it. */
261 invitedBy: string | null;
262 /** The account that used it. */
263 redeemedBy: string | null;
264 /** RFC 3339. */
265 createdAt: string;
266 /** RFC 3339. */
267 expiresAt: string;
268 redeemedAt: string | null;
269 revokedAt: string | null;
270 /** The account a workspace invitation is for, by username: someone invited by username, or the account the invite made. */
271 invitee?: string | null;
272 /** The role `workspace` is joined with; null when it names none. */
273 role?: Role | null;
274 /** The staff member who minted it; only in staff views. */
275 staff?: string | null;
276};
277
278/**
279 * A workspace invitation waiting for its person's answer, as they see it.
280 * Mirrors `WorkspaceInvitation` in `crates/contracts/src/identity.rs`.
281 */
282export type WorkspaceInvitation = {
283 id: string;
284 workspace: ProfileWorkspace;
285 /** The role accepting joins with. */
286 role: Role;
287 /** Null when g1t staff sent it. */
288 invitedBy: { username: string; name: string | null; avatar: string | null } | null;
289 createdAt: string;
290 expiresAt: string;
291};
292
293/** Someone to invite, as `findPeople` finds them: never an email address. */
294export type PersonMatch = { username: string; name: string | null; avatar: string | null };
295
296/** What a valid code is for, before it is used. */
297export type InvitePreview = {
298 kind: "account" | "workspace";
299 /** Pending, unless `anyStatus` asked about a code that is spent. */
300 status: InviteStatus;
301 /** Null when g1t staff sent it. */
302 invitedBy: { username: string; name: string | null; avatar: string | null } | null;
303 workspace: ProfileWorkspace | null;
304 /** The repository it accepts an invitation to, such as `{ name: "flagon-io/g1t", role: "write" }`. */
305 repository: { name: string; role: string } | null;
306 /** Partly hidden, such as `a•••@example.com`. */
307 email: string | null;
308 /** The bound address in full, while the invite is pending: it fills in and locks the sign-up form. */
309 address: string | null;
310 /** Whether the bound address has a g1t account already: sign in to accept. */
311 hasAccount: boolean;
312 /** With a viewer: whether it is theirs (for one of their confirmed addresses, or used by them). */
313 forViewer: boolean | null;
314 expiresAt: string;
315 /**
316 * Whether the page was opened from this pending invite's own email (its
317 * `proof` checked out): the account made with it starts with `address`
318 * confirmed. False without a proof, with a wrong one, or for an invite
319 * bound to no address.
320 */
321 emailProven: boolean;
322};
323
324/**
325 * The shared invite link an account was made with. Before registration
326 * opened, staff handed groups shared links; none are made or used any more.
327 */
328export type SharedInviteSource = { id: string; label: string };
329
330/** Why and since when staff suspended an account or a workspace. */
331export type Suspension = { reason: string; at: string; by: string };
332
333/** An email domain no new account may sign up with; its subdomains too. */
334export type BlockedDomain = { domain: string; reason: string; blockedBy: string; createdAt: string };
335
336/** The most rows one staff listing of invites returns. */
337export const ADMIN_INVITES_LIMIT = 500;
338
339/**
340 * Staff-only identity, for sudo.g1t.sh. It takes no viewer and checks no
341 * membership: only sudo calls it, over its service binding, once Cloudflare
342 * Access and its staff list have let someone in. Never call it on behalf of
343 * a customer.
344 */
345export interface IdentityAdminApi {
346 /** Every workspace, newest first, at most 500; `query` matches slug, name, or an owner's username or email. */
347 workspaces(query?: string): Promise<AdminWorkspace[]>;
348 /** One workspace with all its members, or null. */
349 workspace(slug: string): Promise<AdminWorkspaceDetail | null>;
350
351 /** Invites, newest first; `query` is a code's start, or part of an email, inviter or redeemer. */
352 invites(query?: string | null): Promise<Invite[]>;
353 revokeInvite(id: string, staff: string): Promise<Result<Invite>>;
354
355 /**
356 * Suspends an account (by username): it cannot sign in, and its sessions
357 * and tokens stop at once. `suspend: false` lifts it. A reason is required
358 * to suspend.
359 */
360 suspendUser(username: string, suspend: boolean, reason: string, staff: string): Promise<Result<Suspension | null>>;
361 /** Suspends a workspace (by slug): its own tokens stop. Sudo also holds its compute in billing. */
362 suspendWorkspace(slug: string, suspend: boolean, reason: string, staff: string): Promise<Result<Suspension | null>>;
363 /** Email domains no new account may sign up with. */
364 blockedDomains(): Promise<BlockedDomain[]>;
365 /** Blocks (or with `block: false` unblocks) an email domain; returns the list now. */
366 blockDomain(domain: string, block: boolean, reason: string, staff: string): Promise<Result<BlockedDomain[]>>;
367
368 /** Workspaces owners deleted that are not purged yet, newest first. */
369 deletedWorkspaces(): Promise<DeletedWorkspace[]>;
370 /**
371 * Brings a deleted workspace back, with its members, tokens and what went
372 * with it, while it is still restorable. Publishes `workspace.restored`.
373 */
374 restoreWorkspace(workspaceId: string, staff: string): Promise<Result<boolean>>;
375 /**
376 * Purges a deleted workspace now rather than at `purgeAfter`. `confirm` is
377 * its slug, typed out. Refused for a protected workspace. Publishes
378 * `workspace.deleted`.
379 */
380 purgeWorkspace(workspaceId: string, staff: string, confirm: string): Promise<Result<boolean>>;
381
382 /** Every workspace alias, by name. */
383 aliases(): Promise<WorkspaceAlias[]>;
384 /**
385 * Points `alias` at the workspace whose slug is `workspace`. Refused for
386 * one of the site's routes, anyone's username, a workspace's slug (deleted
387 * or held after a rename) and an existing alias. `note` says why.
388 */
389 setAlias(alias: string, workspace: string, note: string, staff: string): Promise<Result<WorkspaceAlias>>;
390 /** Removes an alias; `reason` goes in sudo's audit log. */
391 removeAlias(alias: string, reason: string, staff: string): Promise<Result<boolean>>;
392}
393
394/**
395 * A name g1t's staff point at a workspace, so its addresses lead there under
396 * the workspace's own name: `g1t`, the product, leads to `flagon-io`, Flagon,
397 * Inc. Staff-managed only; it follows the workspace through renames.
398 */
399export type WorkspaceAlias = {
400 alias: string;
401 workspaceId: string;
402 /** The workspace's slug and name now. */
403 workspace: string;
404 workspaceName: string;
405 /** Why it exists. */
406 note: string;
407 /** The staff member who set it, or `migration`. */
408 createdBy: string;
409 /** RFC 3339. */
410 createdAt: string;
411};
412
413/** Who is asking. Every read and write in every service takes one. */
414export type Viewer = User | null;
415
416/**
417 * Whether this is a person whose account has not confirmed its email
418 * address. Such an account can only confirm it, change it, or sign out.
419 */
420export function awaitsConfirmation(user: Pick<User, "kind" | "verified"> | null | undefined): boolean {
421 return !!user && (user.kind ?? "user") === "user" && !user.verified;
422}
423
424export type SshKey = {
425 id: string;
426 title: string;
427 fingerprint: string;
428 /** RFC 3339. */
429 createdAt: string;
430 /** When it last signed in over SSH, RFC 3339, to within 5 minutes; null when it never has. */
431 lastUsedAt: string | null;
432};
433
434export type AccessToken = {
435 id: string;
436 name: string;
437 /** RFC 3339. */
438 createdAt: string;
439 /** RFC 3339, to within a few minutes. Null until it is first used. */
440 lastUsedAt: string | null;
441 /**
442 * For a workspace's token, the username of the member who made it. Null
443 * once that account is gone, and on personal tokens.
444 */
445 createdBy: string | null;
446 /** Its scopes, as `resource:level`, the highest of each resource. Null: full access. */
447 scopes: string[] | null;
448 /** Made before tokens had scopes: full access until someone narrows it. */
449 legacy: boolean;
450 /** RFC 3339. Null: it does not expire. */
451 expiresAt: string | null;
452 /** Its scopes as permissions: each resource it may use, at the highest level. */
453 permissions?: Permissions;
454 /** What it is for, as its owner wrote it. */
455 description?: string | null;
456 /**
457 * A personal token's reach: the workspace it is made for; null for every
458 * workspace you belong to (or, with `repositorySelection` public, none).
459 * Null on a workspace's own token, which reaches its workspace.
460 */
461 workspace?: string | null;
462 /** Which repositories of that workspace it reaches. */
463 repositorySelection?: RepositorySelection;
464 /** With `selected`: the repositories, as `owner/name`, that you can see. */
465 repositories?: string[];
466 /** Whether a token made for a workspace that approves tokens may be used there yet. */
467 status?: TokenStatus;
468 /** Why an owner denied or revoked it. */
469 reviewReason?: string | null;
470 /** A workspace's own token, acting as the workspace. */
471 workspaceOwned?: boolean;
472 /** A workspace's own token with Repositories: admin, an admin of its repositories. */
473 admin?: boolean;
474 /** A personal token its owner let use the website as them. */
475 website?: boolean;
476};
477
478/** Which repositories a token reaches in its workspace: all, the selected ones, or public ones only. */
479export type RepositorySelection = "all" | "selected" | "public";
480
481/** Whether a token made for a workspace may be used there yet. */
482export type TokenStatus = "active" | "pending" | "denied" | "revoked";
483
484/** A new access token: a person's, or (with `owner`) a workspace's. */
485export type TokenInput = {
486 /** A workspace's slug to make that workspace's token; null for your own. */
487 owner?: string | null;
488 name: string;
489 description?: string | null;
490 /** 1 to 366 days; null for no expiry, where the workspaces it reaches allow that. */
491 ttlSeconds: number | null;
492 /**
493 * A personal token's reach: a workspace's slug, or null for every
494 * workspace you belong to (with `repositorySelection` public: none).
495 */
496 workspace: string | null;
497 repositorySelection: RepositorySelection;
498 /** With `selected`: `owner/name` or names in the workspace. */
499 repositories: string[];
500 /** Each resource's level; left out is no access. */
501 permissions: Partial<Record<ScopeResource, ScopeLevel>>;
502 /** A personal token: whether it may use the website as you. Off unless set. */
503 website?: boolean;
504};
505
506/** A change to a token; what is left out stays. */
507export type TokenChange = Partial<Pick<TokenInput, "name" | "description" | "repositorySelection" | "repositories" | "permissions" | "website">>;
508
509/** A workspace's rules for personal access tokens. */
510export type TokenPolicy = {
511 /** A token made for every workspace of its owner reaches this one. */
512 allowTokensForAllWorkspaces: boolean;
513 /** A token may be made for this workspace alone. */
514 allowTokensForThisWorkspace: boolean;
515 /** A token made for this workspace waits for an owner's approval. */
516 requireApproval: boolean;
517 /** Null: no limit. */
518 maxLifetimeDays: number | null;
519 forbidNoExpiry: boolean;
520 updatedBy?: string | null;
521 updatedAt?: string | null;
522};
523
524/** A member's personal token that reaches a workspace, as its owners see it. */
525export type MemberToken = {
526 owner: string;
527 token: AccessToken;
528 /** Whether it reaches the workspace now. */
529 reaches: boolean;
530 /** Why not: pending approval, denied, revoked, tokens for all workspaces not allowed, tokens made for this workspace not allowed, lasts too long, never expires. */
531 blockedBy?: string | null;
532};
533
534/** What a new or changed token may do. */
535export type TokenGrant = {
536 /** Null: full access. */
537 scopes: string[] | null;
538};
539
540export type DeviceStart = {
541 /** Secret held by the tool and exchanged for a token once approved. */
542 deviceCode: string;
543 /** Short code shown to the person, e.g. `WDJB-MJHT`. */
544 userCode: string;
545 /** Seconds until both codes stop working. */
546 expiresIn: number;
547 /** Seconds the tool should wait between polls. */
548 interval: number;
549};
550
551export type DeviceRequest = { userCode: string; clientName: string };
552
553export type DeviceClaim =
554 | { status: "pending" | "denied" | "expired" }
555 | { status: "approved"; token: string; user: User };
556
557/** What the site passes on once a person has approved an application. */
558export type OAuthApproval = {
559 clientId: string;
560 /** Shown wherever the application's access is listed. */
561 clientName: string;
562 redirectUri: string;
563 /** PKCE challenge, method S256. */
564 codeChallenge: string;
565 /** What the person granted. Null: full access. */
566 scopes: string[] | null;
567};
568
569export type OAuthTokens = {
570 accessToken: string;
571 /** Works once; using it returns the next one. */
572 refreshToken: string;
573 /** Seconds until the access token stops working. */
574 expiresIn: number;
575 /** The scopes granted, space-separated, or `*` for full access. */
576 scope?: string | null;
577};
578
579/** An application a person has signed in to. */
580export type OAuthGrant = {
581 id: string;
582 clientName: string;
583 /** RFC 3339. */
584 createdAt: string;
585 /** RFC 3339. */
586 lastUsedAt: string;
587 /** What the person granted. Null: full access. */
588 scopes: string[] | null;
589 /** Signed in before applications had scopes: full access until narrowed. */
590 legacy: boolean;
591};
592
593/** Accounts, credentials and sessions. */
594/**
595 * What deleting a workspace takes with it, and what stands in the way:
596 * nothing does while `billing` is null and it is not `protected`.
597 */
598export type WorkspaceDeletion = {
599 /** Its live repositories, deleted with it. */
600 repositories: number;
601 /** Its projects, hidden with it. */
602 projects: number;
603 members: number;
604 /** Why billing cannot close it yet, in words for its owner. */
605 billing: string | null;
606 /** It can never be deleted, by anyone. */
607 protected: boolean;
608};
609
610/** How long a deleted workspace is kept, for g1t's staff to restore, before it is purged. */
611export const WORKSPACE_RESTORE_DAYS = 30;
612
613/**
614 * Workspaces nobody can delete, whatever identity's `PROTECTED_WORKSPACES`
615 * says: Flagon's, which runs g1t. Services that act on `workspace.deleting`
616 * check it too, so one published for it by mistake changes nothing.
617 */
618export const ALWAYS_PROTECTED_WORKSPACES: readonly string[] = ["flagon-io"];
619
620/** Whether `slug` is one of `ALWAYS_PROTECTED_WORKSPACES`, in any case. */
621export function isProtectedWorkspace(slug: string): boolean {
622 return ALWAYS_PROTECTED_WORKSPACES.includes(slug.trim().toLowerCase());
623}
624
625/** A workspace an owner deleted, kept until `purgeAfter` for staff to restore. */
626export type DeletedWorkspace = {
627 workspaceId: string;
628 slug: string;
629 name: string;
630 /** RFC 3339. */
631 deletedAt: string;
632 /** The username of the owner who deleted it, or the staff member who deleted it with the account that alone owned it. */
633 deletedBy: string;
634 /** RFC 3339: when it is purged unless restored first. */
635 purgeAfter: string;
636 /** What went with it, counted when it was deleted. */
637 went: WorkspaceDeletion;
638 /** Whether staff can still restore it. */
639 restorable: boolean;
640};
641
642export interface IdentityApi extends AccessClient, TeamsClient, PeopleClient, DeployKeysClient {
643 /**
644 * Creates an account and signs it in. Anyone may register; at most
645 * five accounts an hour per `client`. `inviteCode` is optional: one from an
646 * invitation sent to `email` applies that invitation once the address is
647 * confirmed, and any other code is ignored.
648 */
649 register(
650 username: string,
651 email: string,
652 password: string,
653 inviteCode?: string | null,
654 /** Who is asking, such as the visitor's IP address, for rate limits. */
655 client?: string | null,
656 /**
657 * The `proof` from the invite email's link. When it is the invite's own
658 * and `email` is the address it was sent to, the account starts with that
659 * address confirmed; otherwise it is ignored.
660 */
661 emailProof?: string | null,
662 ): Promise<Result<{ user: User; sessionToken: string }>>;
663 /** Verifies a username and password for website sign-in. */
664 /**
665 * Verifies a username, or any confirmed address of the account, and its
666 * password. Wrong passwords are counted against the account and `client`
667 * (the visitor's IP address); past a limit nothing is checked for a while.
668 */
669 signIn(
670 username: string,
671 password: string,
672 client?: string | null,
673 ): Promise<Result<{ user: User; sessionToken: string; twoFactorChallenge?: string | null }>>;
674 /**
675 * The second step of signing in, for an account with two-factor
676 * authentication: the challenge `signIn` returned, and a code from the
677 * app or a recovery code.
678 */
679 twoFactorSignIn(challenge: string, code: string, client?: string | null): Promise<Result<{ user: User; sessionToken: string }>>;
680 signOut(sessionToken: string): Promise<void>;
681
682 /**
683 * Sends a new confirmation code and link to the primary of an account
684 * that has not confirmed it, at most once a minute.
685 */
686 resendVerification(user: User): Promise<Result<boolean>>;
687 /** Confirms the address the emailed link was sent to, signed in or not; ends the code sent with it. */
688 verifyEmail(token: string): Promise<Result<EmailConfirmed>>;
689 /** Emails a reset link if the address has an account. Always resolves. */
690 /**
691 * Any confirmed address of an account works; the link goes to it, and the
692 * primary and backup are told. A few an hour per address and per `client`.
693 */
694 requestPasswordReset(email: string, client?: string | null): Promise<boolean>;
695 /** Sets a new password from an emailed token and ends every session. */
696 resetPassword(token: string, password: string): Promise<Result<User>>;
697
698 /**
699 * Device sign-in (RFC 8628). A tool starts a request, a person approves
700 * its short code in a browser, and the tool claims an access token.
701 */
702 deviceStart(clientName: string): Promise<DeviceStart>;
703 /** What a user code is asking for, or null if it is not valid. */
704 deviceLookup(userCode: string): Promise<DeviceRequest | null>;
705 deviceResolve(userCode: string, user: User, approve: boolean): Promise<Result<boolean>>;
706 deviceClaim(deviceCode: string): Promise<DeviceClaim>;
707
708 /**
709 * OAuth 2.1 for applications that sign a person in through the browser.
710 * The caller has checked the client and its redirect address; this
711 * returns the one-time code the application exchanges for tokens.
712 */
713 oauthAuthorize(user: User, approval: OAuthApproval): Promise<{ code: string }>;
714 /** Redeems a code. It works once, for that client, with the PKCE verifier. */
715 oauthExchange(code: string, codeVerifier: string, clientId: string, redirectUri: string): Promise<Result<OAuthTokens>>;
716 /** Trades a refresh token for new tokens; the old ones stop working. */
717 oauthRefresh(refreshToken: string, clientId: string): Promise<Result<OAuthTokens>>;
718 /** Applications the user has signed in to, most recently used first. */
719 listOAuthGrants(user: User): Promise<OAuthGrant[]>;
720 /** Signs an application out. */
721 revokeOAuthGrant(user: User, id: string): Promise<void>;
722 /** Changes what an application may do, at once and when it refreshes. */
723 updateOAuthGrant(user: User, id: string, grant: TokenGrant): Promise<Result<OAuthGrant>>;
724
725 createWorkspace(user: User, slug: string, name: string): Promise<Result<Workspace>>;
726 /** Public details of a workspace, or null. */
727 getWorkspace(slug: string): Promise<Workspace | null>;
728 /** Where a workspace keeps its repositories' git data; null when there is no such workspace. */
729 workspaceResidency(slug: string): Promise<DataResidency | null>;
730 /**
731 * Owners only. Applies to repositories made from then on. Offer `eu`
732 * only when the repos service's `storageOptions()` says it is available.
733 */
734 setWorkspaceResidency(actor: User, slug: string, residency: DataResidency): Promise<Result<DataResidency>>;
735 /** Members only. */
736 listMembers(slug: string, viewer: Viewer): Promise<Result<Member[]>>;
737 /** Owners only. */
738 addMember(actor: User, slug: string, username: string): Promise<Result<boolean>>;
739 /** Owners only; your own username is leaving. Never the last owner. */
740 removeMember(actor: User, slug: string, username: string): Promise<Result<boolean>>;
741 /** Owners only: owner or member, and the roles held besides it. Never leaves no owner. */
742 updateMember(actor: User, slug: string, username: string, change: { role?: Role; org_roles?: OrgRole[] }): Promise<Result<Member>>;
743 /** Owners only: `username` becomes an owner, and you a member. */
744 transferOwnership(actor: User, slug: string, username: string): Promise<Result<boolean>>;
745 /** You leave the workspace. Never the last owner. */
746 leaveWorkspace(user: User, slug: string): Promise<Result<boolean>>;
747 /** Owners only: change some member privileges; returns all of them. */
748 setMemberPrivileges(actor: User, slug: string, change: Partial<MemberPrivileges>): Promise<Result<MemberPrivileges>>;
749 /** Owners only, with two-factor on themselves: require it of everyone. */
750 setTwoFactorRequirement(actor: User, slug: string, required: boolean): Promise<Result<boolean>>;
751 /** Owners only. An empty name falls back to the slug. */
752 updateWorkspace(actor: User, slug: string, details: { name: string; description: string }): Promise<Result<Workspace>>;
753 /**
754 * Owners only. Changes the slug, the first segment of the workspace's
755 * URLs; the display name is untouched. The old slug redirects to the new
756 * one, and stays reserved for this workspace, for `SLUG_HOLD_DAYS`.
757 * Publishes `workspace.renamed`.
758 */
759 renameWorkspace(actor: User, slug: string, newSlug: string): Promise<Result<Workspace>>;
760 /** Whether `renameWorkspace` would be allowed, changing nothing. */
761 checkWorkspaceRename(actor: User, slug: string, newSlug: string): Promise<Result<boolean>>;
762 /**
763 * The workspace's current slug when `slug` is one it was renamed from
764 * within `SLUG_HOLD_DAYS`, or when `slug` is an alias staff set for it
765 * (`WorkspaceAlias`); null otherwise, including for a slug in use.
766 */
767 resolveSlug(slug: string): Promise<string | null>;
768 /**
769 * Owners only, a person only. `confirm` is the slug, typed out. Refused
770 * for a protected workspace, and while billing cannot settle it. Its
771 * repositories, projects and apps go with it; it is kept for
772 * `WORKSPACE_RESTORE_DAYS`, when g1t's staff can restore it, then purged.
773 * Its slug is never given to anyone else; the person whose username it is
774 * may make it again once it is purged. Publishes `workspace.deleting`.
775 */
776 deleteWorkspace(actor: User, slug: string, confirm: string): Promise<Result<boolean>>;
777 /** What `deleteWorkspace` would take with it, and what stands in its way, changing nothing. */
778 checkWorkspaceDeletion(actor: User, slug: string): Promise<Result<WorkspaceDeletion>>;
779 /**
780 * Owners only. `image` is the file in base64: PNG, JPEG, WebP or GIF, at
781 * most `MAX_AVATAR_BYTES`, checked by its bytes. Null removes the icon.
782 */
783 setWorkspaceAvatar(actor: User, slug: string, image: string | null): Promise<Result<Workspace>>;
784 /** A person's own avatar, as `setWorkspaceAvatar`: the new one, or null. */
785 setUserAvatar(user: User, image: string | null): Promise<Result<string | null>>;
786
787 /**
788 * A workspace's own access tokens. They belong to the workspace, act as
789 * it, and keep working when the member who made one leaves. Members only.
790 */
791 listWorkspaceTokens(slug: string, viewer: Viewer): Promise<Result<AccessToken[]>>;
792 /** Owners only. */
793 removeWorkspaceToken(actor: User, slug: string, id: string): Promise<Result<boolean>>;
794
795 /**
796 * An access token: yours, or (with `input.owner`, owners only) a
797 * workspace's. People only, signed in. The plaintext token is returned
798 * once and never stored. A personal token made for a workspace that asks
799 * for approval starts pending unless you are an owner there.
800 */
801 createToken(actor: User, input: TokenInput): Promise<Result<{ token: string; info: AccessToken }>>;
802 /**
803 * Changes a token of yours, or (with `owner`, owners only) a
804 * workspace's; what is left out stays. Widening a token made for a
805 * workspace that approves tokens asks for approval again.
806 */
807 updateToken(actor: User, id: string, change: TokenChange, owner?: string | null): Promise<Result<AccessToken>>;
808 /**
809 * A new secret for a token, everything else kept, the old secret refused
810 * from then on: rotating it. `ttlSeconds` is its new lifetime from now
811 * (null: it does not expire), within its workspace's rules. The secret
812 * is shown once.
813 */
814 regenerateToken(actor: User, id: string, ttlSeconds: number | null, owner?: string | null): Promise<Result<{ token: string; info: AccessToken }>>;
815 /** A workspace's rules for personal access tokens. Members only. */
816 getTokenPolicy(slug: string, viewer: Viewer): Promise<Result<TokenPolicy>>;
817 /** Owners only, as people. `maxLifetimeDays` of 0 removes the limit. */
818 setTokenPolicy(
819 actor: User,
820 slug: string,
821 change: Partial<Omit<TokenPolicy, "updatedBy" | "updatedAt">>,
822 ): Promise<Result<TokenPolicy>>;
823 /** The members' tokens that can reach a workspace. Owners only. */
824 listMemberTokens(
825 actor: User,
826 slug: string,
827 filter?: { status?: TokenStatus },
828 ): Promise<Result<MemberToken[]>>;
829 /** Approve or deny a token waiting for approval. Owners only. */
830 reviewTokenRequest(actor: User, slug: string, id: string, approve: boolean, reason?: string | null): Promise<Result<MemberToken>>;
831 /** Take a member's token out of the workspace. Owners only. */
832 revokeMemberToken(actor: User, slug: string, id: string, reason?: string | null): Promise<Result<boolean>>;
833
834 userForSession(sessionToken: string): Promise<Viewer>;
835
836 /**
837 * What a code is for. Unknown, used, revoked and expired codes all get the
838 * same answer, unless `anyStatus`: then a real code that is spent is
839 * described, with its `status`. `viewer` sets `forViewer`; `emailProof`,
840 * the `proof` from the invite email's link, sets `emailProven`.
841 */
842 checkInvite(
843 code: string,
844 client?: string | null,
845 options?: { viewer?: User | null; anyStatus?: boolean; emailProof?: string | null },
846 ): Promise<Result<InvitePreview>>;
847 /**
848 * A signed-in person uses a workspace invite sent to their address, or one
849 * sent with a repository invitation; returns the workspace's slug, or
850 * `workspace/repo`.
851 */
852 acceptInvite(user: User, code: string): Promise<Result<string>>;
853 /**
854 * Owners only. Invites someone into a workspace by address (always with an
855 * invite bound to it) or by `username`: a workspace invitation they accept
856 * or decline. Nobody joins without saying yes. `role` is what they join as.
857 */
858 inviteMember(
859 actor: User,
860 slug: string,
861 who: { email?: string | null; username?: string | null; role?: Role | null; message?: string | null },
862 ): Promise<Result<Invite>>;
863 /** The workspace invitations waiting for the person's answer, newest first. */
864 listInvitations(user: User): Promise<WorkspaceInvitation[]>;
865 /** Joins the invitation's workspace with its role; returns the workspace's slug. */
866 acceptInvitation(user: User, id: string): Promise<Result<string>>;
867 /** Declines it; whoever sent it is told in their inbox. */
868 declineInvitation(user: User, id: string): Promise<Result<boolean>>;
869 /** People to invite, by username prefix or name: a username, a name and an avatar each. */
870 findPeople(query: string, limit?: number): Promise<PersonMatch[]>;
871 /** Owners only: the workspace's invites, newest first. */
872 workspaceInvites(slug: string, viewer: Viewer): Promise<Result<Invite[]>>;
873 /** Owners only. */
874 revokeWorkspaceInvite(actor: User, slug: string, id: string): Promise<Result<Invite>>;
875 /** Owners only: sends a pending invitation again, by email and in the invited account's inbox. Unchanged otherwise. */
876 resendWorkspaceInvite(actor: User, slug: string, id: string): Promise<Result<Invite>>;
877
878 /** Verifies git credentials: the account password or an access token. */
879 userForGitCredentials(username: string, secret: string): Promise<Viewer>;
880 /** Resolves a `g1t_…` access token, as sent to the API and MCP server. */
881 userForAccessToken(token: string): Promise<Viewer>;
882 userForSshKey(fingerprint: string): Promise<Viewer>;
883 userByUsername(username: string): Promise<Viewer>;
884 /** The names behind account and workspace ids; unknown ids are left out. */
885 usernames(ids: string[]): Promise<Record<string, string>>;
886 /**
887 * Internal: the people behind these ids (at most 50) with their
888 * workspaces, roles and repository grants, as a signed-in viewer has
889 * them. For the agents service's audience checks only. Ids of no live
890 * account are left out.
891 */
892 usersForAudience(ids: string[]): Promise<User[]>;
893
894 /** A person's public profile, or null if there is no such account. Never an email address. */
895 profile(username: string): Promise<Profile | null>;
896 /** A person changes their own profile. Every field is replaced; an empty one is cleared. */
897 updateProfile(actor: User, fields: ProfileFields): Promise<Result<Profile>>;
898 /**
899 * The workspaces a profile shows `viewer`: those the viewer belongs to
900 * as well, and those of `publicIn` (where the person made a public
901 * project) that the person really belongs to. Nothing else.
902 */
903 profileWorkspaces(username: string, viewer: Viewer, publicIn: string[]): Promise<ProfileWorkspace[]>;
904
905 /**
906 * The apps `user` pinned to their dock in the workspace `workspace` (a
907 * slug), in the order they set; null when they never saved any there or
908 * are not one of its members. Kept with the account, so every device
909 * shows the same dock.
910 */
911 dockPins(user: User, workspace: string): Promise<string[] | null>;
912 /**
913 * Replaces `user`'s dock pins in `workspace` with `apps`, in that order:
914 * keys of lowercase letters, digits and hyphens, repeats dropped, at
915 * most `MAX_DOCK_PINS`. Which keys are real apps is the caller's to check.
916 */
917 setDockPins(user: User, workspace: string, apps: string[]): Promise<Result<string[]>>;
918
919 /**
920 * How chat sounds and desktop notifications reach `user`, kept with the
921 * account so every device and the desktop app behave the same
922 * (`SoundSettings`). The defaults when they never changed them.
923 */
924 soundSettings(user: User): Promise<SoundSettings>;
925 /**
926 * Changes some of them: only the fields sent change, and `sound_cues`
927 * merges one cue at a time. Returns the settings as kept.
928 */
929 setSoundSettings(user: User, change: SoundSettingsChange): Promise<Result<SoundSettings>>;
930
931 listSshKeys(user: User): Promise<SshKey[]>;
932 /** Takes one line in OpenSSH public key format. */
933 addSshKey(user: User, title: string, publicKey: string): Promise<Result<SshKey>>;
934 removeSshKey(user: User, id: string): Promise<void>;
935
936 listAccessTokens(user: User): Promise<AccessToken[]>;
937 /**
938 * A credential minted for a person or workspace by another service. The
939 * plaintext token is returned once and never stored. With `ttlSeconds`
940 * the token expires and is left out of token lists; that form is used
941 * for hosted agents. Tokens people make use `createToken`.
942 */
943 createAccessToken(
944 user: User,
945 name: string,
946 ttlSeconds?: number,
947 grant?: TokenGrant & { listed?: boolean },
948 ): Promise<{ token: string; info: AccessToken }>;
949 /**
950 * A token for a g1t agent working for `onBehalfOf`: it acts as
951 * `g1t`, in `scope.repo` only, and only for `scope.operations`.
952 */
953 createAgentToken(
954 onBehalfOf: User,
955 scope: AgentScope,
956 ttlSeconds: number,
957 ): Promise<{ token: string; info: AccessToken }>;
958 removeAccessToken(user: User, id: string): Promise<void>;
959 /**
960 * A token for one sandbox run: it acts as the agent on behalf of
961 * `onBehalfOf`, can do only what the run's kind needs in `repo`, and
962 * expires after `ttlSeconds`. See `audit.ts`.
963 */
964 createRunCredential(input: CreateRunCredentialInput): Promise<{ token: string; info: AccessToken }>;
965 /** Ties tokens, by the SHA-256 of their text in hex, to the agent run their sandbox recorded. */
966 bindRunCredentials(tokenHashes: string[], runId: string): Promise<boolean>;
967 /** Ends a sandbox's run credentials, by hash or by run. Never touches another token. */
968 revokeRunCredentials(target: { tokenHashes?: string[]; runId?: string | null }): Promise<boolean>;
969}
970
971
972/** What an agent's token may do: these operations, in this repository. */
973export type AgentScope = { repo: RepoPath; operations: string[]; run?: RunBinding };
974
975/** The most apps a person pins in one workspace. Mirrors `MAX_DOCK_PINS` in `crates/contracts/src/identity.rs`. */
976export const MAX_DOCK_PINS = 24;
977
978/** The most characters each profile field takes. Mirrors `crates/contracts/src/identity.rs`. */
979export const PROFILE_LIMITS = { name: 80, bio: 160, location: 80, website: 200, pronouns: 40, timezone: 64 } as const;
980
981/** What anyone may see about a person, at `g1t.sh/u/<username>`. */
982export type Profile = {
983 /** Lowercased: what the profile is found and linked by. */
984 username: string;
985 /** The username as its owner wrote it (`Ana`), when that differs: what the page shows. */
986 displayUsername?: string | null;
987 /** The name they go by, if they gave one. */
988 name: string | null;
989 bio: string | null;
990 location: string | null;
991 /** Always an `https://` address. */
992 website: string | null;
993 pronouns: string | null;
994 /** The time zone they are in, an IANA name such as `America/Denver`. */
995 timezone: string | null;
996 /** The uploaded avatar's hash, served at `/avatars/<avatar>`. */
997 avatar: string | null;
998 /** When the account was made. RFC 3339. */
999 createdAt: string;
1000};
1001
1002/** What a person may change on their profile. Empty clears a field. */
1003export type ProfileFields = {
1004 name: string;
1005 bio: string;
1006 location: string;
1007 /** `https://…`; a bare `example.com` is taken as `https://example.com`. */
1008 website: string;
1009 pronouns: string;
1010 /** An IANA time zone name, such as `America/Denver`; empty clears it. */
1011 timezone: string;
1012};
1013
1014/** A workspace on a person's profile. */
1015export type ProfileWorkspace = { slug: string; name: string; avatar: string | null };