Skip to content
854 linesCodeBlameRaw
1import type { AccessClient, BasePermission, RepoGrant } from "./access";
2import type { PermissionAccess, RepositorySelection } from "./fine-grained";
3import type { Acting, CreateRunCredentialInput, RunBinding } from "./audit";
4import type { RepoPath } from "./repos";
5import type { Result } from "./result";
6import type { TeamCreation, TeamsClient } from "./teams";
7import type { DeployKeysClient } from "./deploy-keys";
8
9export type User = {
10 id: string;
11 username: string;
12 /**
13 * `workspace` when a workspace is acting through one of its own access
14 * tokens: `id` is then the workspace's and `username` its slug. `system`
15 * is g1t itself doing platform work, such as a security update
16 * (`username` `g1t`). Absent means `user`.
17 */
18 kind?: "user" | "workspace" | "agent" | "system";
19 /**
20 * Whether the account's email address is confirmed. Only set on users
21 * resolved from credentials; unverified accounts cannot change anything.
22 */
23 verified?: boolean;
24 /**
25 * The workspaces this user belongs to. Set on users resolved from
26 * credentials, so any service can authorize from it.
27 */
28 workspaces?: Membership[];
29 /**
30 * The person's uploaded avatar: the SHA-256 of its bytes, served at
31 * `/avatars/<avatar>`. Only set on the signed-in person; absent means
32 * the generated letter avatar.
33 */
34 avatar?: string;
35 /**
36 * Set on an agent resolved from its token: who it acts for ("g1t
37 * on behalf of syntaqx"), with which credential, and what it may do.
38 */
39 acting?: Acting;
40 /**
41 * The repositories this user has a role on directly, whether or not they
42 * belong to its workspace. Set with `workspaces`; see `access.ts`.
43 */
44 grants?: RepoGrant[];
45 /**
46 * Set on a user resolved from an access token: its scopes (null for full
47 * access) and the workspaces or repositories it reaches. See scopes.ts.
48 */
49 token?: {
50 token_id: string;
51 scopes?: string[] | null;
52 legacy?: boolean;
53 /** The token's name, as its owner gave it. */
54 name?: string;
55 };
56};
57
58/** What a member may do: an owner also manages the workspace's members. */
59export type Role = "owner" | "member";
60
61export type Membership = {
62 /** The workspace's name in URLs: `g1t.sh/<slug>`. */
63 slug: string;
64 role: Role;
65 /** Its display name. Set on users resolved from credentials. */
66 name?: string;
67 /** Its uploaded icon, as `Workspace.avatar`. */
68 avatar?: string;
69 /** The workspace's base permission: what members get on every repository. Absent means `write`. */
70 base_permission?: BasePermission;
71 /** Who may create its teams. Absent means any member. */
72 team_creation?: TeamCreation;
73};
74
75/** How long an old workspace slug redirects, and stays reserved for it, after a rename. */
76export const SLUG_HOLD_DAYS = 90;
77
78/** How long a workspace must wait between renames. */
79export const RENAME_COOLDOWN_HOURS = 24;
80
81/** The largest avatar that can be uploaded, in bytes. */
82export const MAX_AVATAR_BYTES = 1024 * 1024;
83
84/**
85 * Where a workspace keeps its repositories' git data: anywhere g1t stores
86 * it (the default), or in the EU only. It applies to repositories made
87 * after it is set.
88 */
89export type DataResidency = "anywhere" | "eu";
90
91/**
92 * A workspace: the owner of repositories, and the first segment of their
93 * URLs. A person's own space and a team's are the same thing.
94 */
95export type Workspace = {
96 id: string;
97 slug: string;
98 name: string;
99 /** One line saying what the workspace is for. */
100 description: string | null;
101 /** RFC 3339. */
102 createdAt: string;
103 memberCount: number;
104 /**
105 * The workspace's uploaded icon: the SHA-256 of its bytes, served at
106 * `/avatars/<avatar>`. Null means the generated letter avatar.
107 */
108 avatar: string | null;
109 /** What every member gets on each repository; owners have Admin. */
110 basePermission?: BasePermission;
111 /** Who may create its teams. Absent means any member. */
112 teamCreation?: TeamCreation;
113};
114
115export type Member = {
116 username: string;
117 role: Role;
118 /** Their display name, when they set one. */
119 name?: string | null;
120 /** Their uploaded avatar's hash, served at `/avatars/<avatar>`; null for the generated letter avatar. */
121 avatar?: string | null;
122};
123
124/** An owner of a workspace, as staff see them. */
125export type AdminOwner = { username: string; email: string | null };
126
127/** A workspace as staff see it. Mirrors `AdminWorkspace` in `crates/contracts/src/identity.rs`. */
128export type AdminWorkspace = {
129 slug: string;
130 name: string;
131 /** RFC 3339. */
132 createdAt: string;
133 owners: AdminOwner[];
134 memberCount: number;
135};
136
137/** A member of a workspace, as staff see them. */
138export type AdminMember = { username: string; email: string | null; role: Role; /** RFC 3339. */ joined: string };
139
140export type AdminWorkspaceDetail = {
141 slug: string;
142 name: string;
143 description: string | null;
144 /** RFC 3339. */
145 createdAt: string;
146 /** Owners first, then by username. */
147 members: AdminMember[];
148 /** It can never be deleted, by anyone (identity's `PROTECTED_WORKSPACES`). */
149 protected: boolean;
150};
151
152/** The most workspaces one `workspaces` call returns. */
153export const ADMIN_WORKSPACES_LIMIT = 500;
154
155/**
156 * Whether anyone may make an account, or only someone with an invite.
157 * Identity's `REGISTRATION_MODE`; unset means `invite`.
158 */
159export type RegistrationMode = "invite" | "open";
160
161/** How many invites a person may have out at once, unless identity's `INVITES_PER_USER` says otherwise. */
162export const INVITES_PER_USER = 5;
163/** How long an invite works, unless identity's `INVITE_TTL_DAYS` says otherwise. */
164export const INVITE_TTL_DAYS = 30;
165
166/** Only a pending invite can be used or revoked. Revoked and expired ones never used give the invite back. */
167export type InviteStatus = "pending" | "redeemed" | "expired" | "revoked";
168
169/** One invite. Mirrors `Invite` in `crates/contracts/src/identity.rs`. */
170export type Invite = {
171 id: string;
172 /** `g1t-k7m2-…`: returned when it is made, and to its maker while pending. */
173 code: string | null;
174 /** The code's first group, such as `g1t-k7m2`. */
175 hint: string;
176 /** Only this address can use it. */
177 email: string | null;
178 /** `account` makes an account; `workspace` joins an existing one to `workspace`. */
179 kind: "account" | "workspace";
180 /** The workspace using it joins. */
181 workspace: string | null;
182 status: InviteStatus;
183 /** Whose allowance it used. */
184 chargedTo: "user" | "workspace" | "none";
185 /** Its maker's username; null when g1t staff made it. */
186 invitedBy: string | null;
187 /** The account that used it. */
188 redeemedBy: string | null;
189 /** RFC 3339. */
190 createdAt: string;
191 /** RFC 3339. */
192 expiresAt: string;
193 redeemedAt: string | null;
194 revokedAt: string | null;
195 /** The staff member who minted it; only in staff views. */
196 staff?: string | null;
197};
198
199/** How many invites someone may have out. `limit` and `remaining` are null for no limit. */
200export type Allowance = { limit: number | null; used: number; remaining: number | null };
201
202export type InvitesOverview = {
203 mode: RegistrationMode;
204 allowance: Allowance;
205 /** Workspaces the person owns that were granted invites to share. */
206 workspaces: { slug: string; allowance: Allowance }[];
207 invites: Invite[];
208};
209
210/** What a valid code is for, before it is used. */
211export type InvitePreview = {
212 kind: "account" | "workspace";
213 /** Pending, unless `anyStatus` asked about a code that is spent. */
214 status: InviteStatus;
215 /** Null when g1t staff sent it. */
216 invitedBy: { username: string; name: string | null; avatar: string | null } | null;
217 workspace: ProfileWorkspace | null;
218 /** The repository it accepts an invitation to, such as `{ name: "flagon-io/g1t", role: "write" }`. */
219 repository: { name: string; role: string } | null;
220 /** Partly hidden, such as `a•••@example.com`. */
221 email: string | null;
222 /** The bound address in full, while the invite is pending: it fills in and locks the sign-up form. */
223 address: string | null;
224 /** Whether the bound address has a g1t account already: sign in to accept. */
225 hasAccount: boolean;
226 /** With a viewer: whether it is theirs (for one of their confirmed addresses, or used by them). */
227 forViewer: boolean | null;
228 expiresAt: string;
229};
230
231export type WaitlistStatus = "waiting" | "invited" | "dismissed";
232
233export type WaitlistEntry = {
234 id: string;
235 email: string;
236 about: string | null;
237 status: WaitlistStatus;
238 inviteId: string | null;
239 decidedBy: string | null;
240 decidedAt: string | null;
241 /** What staff wrote when approving; it went in the invite email. */
242 note: string | null;
243 /** The account made with the invite, once it was used. */
244 joinedAs: string | null;
245 /** When they first asked. */
246 createdAt: string;
247 /** When they last asked. */
248 updatedAt: string;
249};
250
251export type InviteGrant = { amount: number; note: string | null; grantedBy: string; createdAt: string };
252export type InviteTreeNode = { username: string; joinedAt: string; invited: InviteTreeNode[] };
253
254/** Where a person came from and whom they brought. For a workspace, `username` is its slug. */
255export type InviteTree = {
256 username: string;
257 /** Who invited them, then who invited that person, and so on. */
258 invitedBy: string[];
259 /** The staff member who minted their invite, when staff did. */
260 staff: string | null;
261 allowance: Allowance;
262 grants: InviteGrant[];
263 invites: Invite[];
264 /** Whom they invited, three levels down. */
265 invited: InviteTreeNode[];
266};
267
268/** The most rows one staff listing of invites or the waitlist returns. */
269export const ADMIN_INVITES_LIMIT = 500;
270
271/**
272 * Staff-only identity, for sudo.g1t.sh. It takes no viewer and checks no
273 * membership: only sudo calls it, over its service binding, once Cloudflare
274 * Access and its staff list have let someone in. Never call it on behalf of
275 * a customer.
276 */
277export interface IdentityAdminApi {
278 /** Every workspace, newest first, at most 500; `query` matches slug, name, or an owner's username or email. */
279 workspaces(query?: string): Promise<AdminWorkspace[]>;
280 /** One workspace with all its members, or null. */
281 workspace(slug: string): Promise<AdminWorkspaceDetail | null>;
282
283 /** The waitlist, newest first; `query` matches the address or what they said. */
284 waitlist(query?: string | null, status?: WaitlistStatus | null): Promise<WaitlistEntry[]>;
285 /** How many requests are waiting, for the navigation's badge. */
286 waitlistPending(): Promise<number>;
287 /**
288 * Approving mints an invite bound to the address and emails it, with
289 * `note` (up to 500 characters) if given; dismissing only marks it.
290 */
291 decideWaitlist(id: string, approve: boolean, staff: string, note?: string | null): Promise<Result<WaitlistEntry>>;
292 /** Invites, newest first; `query` is a code's start, or part of an email, inviter or redeemer. */
293 invites(query?: string | null): Promise<Invite[]>;
294 revokeInvite(id: string, staff: string): Promise<Result<Invite>>;
295 /** An invite that uses nobody's allowance, optionally bound to (and emailed to) `email`. */
296 mintInvite(email: string | null, staff: string): Promise<Result<Invite>>;
297 /** More invites (or fewer, with a negative amount) for a person or a workspace. */
298 grantInvites(
299 target: "user" | "workspace",
300 name: string,
301 amount: number,
302 note: string,
303 staff: string,
304 ): Promise<Result<Allowance>>;
305 /** Where a person came from and whom they brought, or null. */
306 inviteTree(username: string): Promise<InviteTree | null>;
307 /** A workspace's granted invites and the invites made for it, or null. */
308 workspaceInvites(slug: string): Promise<InviteTree | null>;
309
310 /** Workspaces owners deleted that are not purged yet, newest first. */
311 deletedWorkspaces(): Promise<DeletedWorkspace[]>;
312 /**
313 * Brings a deleted workspace back, with its members, tokens and what went
314 * with it, while it is still restorable. Publishes `workspace.restored`.
315 */
316 restoreWorkspace(workspaceId: string, staff: string): Promise<Result<boolean>>;
317 /**
318 * Purges a deleted workspace now rather than at `purgeAfter`. `confirm` is
319 * its slug, typed out. Refused for a protected workspace. Publishes
320 * `workspace.deleted`.
321 */
322 purgeWorkspace(workspaceId: string, staff: string, confirm: string): Promise<Result<boolean>>;
323
324 /** Every workspace alias, by name. */
325 aliases(): Promise<WorkspaceAlias[]>;
326 /**
327 * Points `alias` at the workspace whose slug is `workspace`. Refused for
328 * one of the site's routes, anyone's username, a workspace's slug (deleted
329 * or held after a rename) and an existing alias. `note` says why.
330 */
331 setAlias(alias: string, workspace: string, note: string, staff: string): Promise<Result<WorkspaceAlias>>;
332 /** Removes an alias; `reason` goes in sudo's audit log. */
333 removeAlias(alias: string, reason: string, staff: string): Promise<Result<boolean>>;
334}
335
336/**
337 * A name g1t's staff point at a workspace, so its addresses lead there under
338 * the workspace's own name: `g1t`, the product, leads to `flagon-io`, Flagon,
339 * Inc. Staff-managed only; it follows the workspace through renames.
340 */
341export type WorkspaceAlias = {
342 alias: string;
343 workspaceId: string;
344 /** The workspace's slug and name now. */
345 workspace: string;
346 workspaceName: string;
347 /** Why it exists. */
348 note: string;
349 /** The staff member who set it, or `migration`. */
350 createdBy: string;
351 /** RFC 3339. */
352 createdAt: string;
353};
354
355/** Who is asking. Every read and write in every service takes one. */
356export type Viewer = User | null;
357
358export type SshKey = {
359 id: string;
360 title: string;
361 fingerprint: string;
362 /** RFC 3339. */
363 createdAt: string;
364 /** When it last signed in over SSH, RFC 3339, to within 5 minutes; null when it never has. */
365 lastUsedAt: string | null;
366};
367
368export type AccessToken = {
369 id: string;
370 name: string;
371 /** RFC 3339. */
372 createdAt: string;
373 /** RFC 3339, to within a few minutes. Null until it is first used. */
374 lastUsedAt: string | null;
375 /**
376 * For a workspace's token, the username of the member who made it. Null
377 * once that account is gone, and on personal tokens.
378 */
379 createdBy: string | null;
380 /** Its scopes, as `resource:level`. Null: full access. */
381 scopes: string[] | null;
382 /** Made before tokens had scopes: full access until someone narrows it. */
383 legacy: boolean;
384 /** RFC 3339. Null: it does not expire. */
385 expiresAt: string | null;
386 /** Classic, fine-grained, or a workspace's own. */
387 kind?: TokenKind;
388 /** What it is for, as its owner wrote it. */
389 description?: string | null;
390 /** A fine-grained token's resource owner, repositories, permissions and status. */
391 fineGrained?: FineGrainedDetails | null;
392 /** A workspace's own token an owner gave Admin when making it. */
393 admin?: boolean;
394};
395
396export type TokenKind = "classic" | "fine_grained" | "workspace";
397
398/** Whether a fine-grained token may be used on its resource owner. */
399export type TokenStatus = "active" | "pending" | "denied" | "revoked";
400
401export type FineGrainedDetails = {
402 /** The resource owner's slug; null for your own account. */
403 workspace: string | null;
404 repositorySelection: RepositorySelection;
405 /** With `selected`: the repositories, as `owner/name`, that you can see. */
406 repositories: string[];
407 permissions: Partial<Record<string, PermissionAccess>>;
408 status: TokenStatus;
409 /** Why an owner denied or revoked it. */
410 reviewReason?: string | null;
411};
412
413/** What a new fine-grained token is. */
414export type FineGrainedTokenInput = {
415 name: string;
416 description?: string | null;
417 /** Between 1 and 366 days, and no more than the workspace allows. */
418 ttlSeconds: number;
419 /** The resource owner: a workspace's slug, or null for your own account. */
420 workspace: string | null;
421 repositorySelection: RepositorySelection;
422 /** With `selected`: `owner/name` or names in the workspace. */
423 repositories: string[];
424 /** Each permission's level by name; names left out are none. */
425 permissions: Record<string, PermissionAccess>;
426};
427
428/** A workspace's rules for personal access tokens. */
429export type TokenPolicy = {
430 allowClassic: boolean;
431 allowFineGrained: boolean;
432 requireApproval: boolean;
433 /** Null: no limit. */
434 maxLifetimeDays: number | null;
435 forbidNoExpiry: boolean;
436 updatedBy?: string | null;
437 updatedAt?: string | null;
438};
439
440/** A member's personal token that reaches a workspace, as its owners see it. */
441export type MemberToken = {
442 owner: string;
443 token: AccessToken;
444 /** Whether it reaches the workspace now. */
445 reaches: boolean;
446 /** Why not: pending approval, denied, revoked, classic tokens not allowed, lasts too long, never expires. */
447 blockedBy?: string | null;
448};
449
450/** What a new or changed token may do. */
451export type TokenGrant = {
452 /** Null: full access. */
453 scopes: string[] | null;
454};
455
456export type DeviceStart = {
457 /** Secret held by the tool and exchanged for a token once approved. */
458 deviceCode: string;
459 /** Short code shown to the person, e.g. `WDJB-MJHT`. */
460 userCode: string;
461 /** Seconds until both codes stop working. */
462 expiresIn: number;
463 /** Seconds the tool should wait between polls. */
464 interval: number;
465};
466
467export type DeviceRequest = { userCode: string; clientName: string };
468
469export type DeviceClaim =
470 | { status: "pending" | "denied" | "expired" }
471 | { status: "approved"; token: string; user: User };
472
473/** What the site passes on once a person has approved an application. */
474export type OAuthApproval = {
475 clientId: string;
476 /** Shown wherever the application's access is listed. */
477 clientName: string;
478 redirectUri: string;
479 /** PKCE challenge, method S256. */
480 codeChallenge: string;
481 /** What the person granted. Null: full access. */
482 scopes: string[] | null;
483};
484
485export type OAuthTokens = {
486 accessToken: string;
487 /** Works once; using it returns the next one. */
488 refreshToken: string;
489 /** Seconds until the access token stops working. */
490 expiresIn: number;
491 /** The scopes granted, space-separated, or `*` for full access. */
492 scope?: string | null;
493};
494
495/** An application a person has signed in to. */
496export type OAuthGrant = {
497 id: string;
498 clientName: string;
499 /** RFC 3339. */
500 createdAt: string;
501 /** RFC 3339. */
502 lastUsedAt: string;
503 /** What the person granted. Null: full access. */
504 scopes: string[] | null;
505 /** Signed in before applications had scopes: full access until narrowed. */
506 legacy: boolean;
507};
508
509/** Accounts, credentials and sessions. */
510/**
511 * What deleting a workspace takes with it, and what stands in the way:
512 * nothing does while `billing` is null and it is not `protected`.
513 */
514export type WorkspaceDeletion = {
515 /** Its live repositories, deleted with it. */
516 repositories: number;
517 /** Its projects, hidden with it. */
518 projects: number;
519 members: number;
520 /** Why billing cannot close it yet, in words for its owner. */
521 billing: string | null;
522 /** It can never be deleted, by anyone. */
523 protected: boolean;
524};
525
526/** How long a deleted workspace is kept, for g1t's staff to restore, before it is purged. */
527export const WORKSPACE_RESTORE_DAYS = 30;
528
529/**
530 * Workspaces nobody can delete, whatever identity's `PROTECTED_WORKSPACES`
531 * says: Flagon's, which runs g1t. Services that act on `workspace.deleting`
532 * check it too, so one published for it by mistake changes nothing.
533 */
534export const ALWAYS_PROTECTED_WORKSPACES: readonly string[] = ["flagon-io"];
535
536/** Whether `slug` is one of `ALWAYS_PROTECTED_WORKSPACES`, in any case. */
537export function isProtectedWorkspace(slug: string): boolean {
538 return ALWAYS_PROTECTED_WORKSPACES.includes(slug.trim().toLowerCase());
539}
540
541/** A workspace an owner deleted, kept until `purgeAfter` for staff to restore. */
542export type DeletedWorkspace = {
543 workspaceId: string;
544 slug: string;
545 name: string;
546 /** RFC 3339. */
547 deletedAt: string;
548 /** The username of the owner who deleted it. */
549 deletedBy: string;
550 /** RFC 3339: when it is purged unless restored first. */
551 purgeAfter: string;
552 /** What went with it, counted when it was deleted. */
553 went: WorkspaceDeletion;
554 /** Whether staff can still restore it. */
555 restorable: boolean;
556};
557
558export interface IdentityApi extends AccessClient, TeamsClient, DeployKeysClient {
559 /**
560 * Creates an account and signs it in. While registration is invite-only,
561 * `inviteCode` must be an unused, unexpired invite (and, when it names an
562 * email, that address); it is ignored while registration is open.
563 */
564 register(
565 username: string,
566 email: string,
567 password: string,
568 inviteCode?: string | null,
569 /** Who is asking, such as the visitor's IP address, for rate limits. */
570 client?: string | null,
571 ): Promise<Result<{ user: User; sessionToken: string }>>;
572 /** Verifies a username and password for website sign-in. */
573 /**
574 * Verifies a username, or any confirmed address of the account, and its
575 * password. Wrong passwords are counted against the account and `client`
576 * (the visitor's IP address); past a limit nothing is checked for a while.
577 */
578 signIn(username: string, password: string, client?: string | null): Promise<Result<{ user: User; sessionToken: string }>>;
579 signOut(sessionToken: string): Promise<void>;
580
581 /** Sends the confirmation email again. */
582 resendVerification(user: User): Promise<Result<boolean>>;
583 /** Confirms the address the emailed token was sent to. */
584 verifyEmail(token: string): Promise<Result<User>>;
585 /** Emails a reset link if the address has an account. Always resolves. */
586 /**
587 * Any confirmed address of an account works; the link goes to it, and the
588 * primary and backup are told. A few an hour per address and per `client`.
589 */
590 requestPasswordReset(email: string, client?: string | null): Promise<boolean>;
591 /** Sets a new password from an emailed token and ends every session. */
592 resetPassword(token: string, password: string): Promise<Result<User>>;
593
594 /**
595 * Device sign-in (RFC 8628). A tool starts a request, a person approves
596 * its short code in a browser, and the tool claims an access token.
597 */
598 deviceStart(clientName: string): Promise<DeviceStart>;
599 /** What a user code is asking for, or null if it is not valid. */
600 deviceLookup(userCode: string): Promise<DeviceRequest | null>;
601 deviceResolve(userCode: string, user: User, approve: boolean): Promise<Result<boolean>>;
602 deviceClaim(deviceCode: string): Promise<DeviceClaim>;
603
604 /**
605 * OAuth 2.1 for applications that sign a person in through the browser.
606 * The caller has checked the client and its redirect address; this
607 * returns the one-time code the application exchanges for tokens.
608 */
609 oauthAuthorize(user: User, approval: OAuthApproval): Promise<{ code: string }>;
610 /** Redeems a code. It works once, for that client, with the PKCE verifier. */
611 oauthExchange(code: string, codeVerifier: string, clientId: string, redirectUri: string): Promise<Result<OAuthTokens>>;
612 /** Trades a refresh token for new tokens; the old ones stop working. */
613 oauthRefresh(refreshToken: string, clientId: string): Promise<Result<OAuthTokens>>;
614 /** Applications the user has signed in to, most recently used first. */
615 listOAuthGrants(user: User): Promise<OAuthGrant[]>;
616 /** Signs an application out. */
617 revokeOAuthGrant(user: User, id: string): Promise<void>;
618 /** Changes what an application may do, at once and when it refreshes. */
619 updateOAuthGrant(user: User, id: string, grant: TokenGrant): Promise<Result<OAuthGrant>>;
620
621 createWorkspace(user: User, slug: string, name: string): Promise<Result<Workspace>>;
622 /** Public details of a workspace, or null. */
623 getWorkspace(slug: string): Promise<Workspace | null>;
624 /** Where a workspace keeps its repositories' git data; null when there is no such workspace. */
625 workspaceResidency(slug: string): Promise<DataResidency | null>;
626 /**
627 * Owners only. Applies to repositories made from then on. Offer `eu`
628 * only when the repos service's `storageOptions()` says it is available.
629 */
630 setWorkspaceResidency(actor: User, slug: string, residency: DataResidency): Promise<Result<DataResidency>>;
631 /** Members only. */
632 listMembers(slug: string, viewer: Viewer): Promise<Result<Member[]>>;
633 /** Owners only. */
634 addMember(actor: User, slug: string, username: string): Promise<Result<boolean>>;
635 /** Owners only. */
636 removeMember(actor: User, slug: string, username: string): Promise<Result<boolean>>;
637 /** Owners only. An empty name falls back to the slug. */
638 updateWorkspace(actor: User, slug: string, details: { name: string; description: string }): Promise<Result<Workspace>>;
639 /**
640 * Owners only. Changes the slug, the first segment of the workspace's
641 * URLs; the display name is untouched. The old slug redirects to the new
642 * one, and stays reserved for this workspace, for `SLUG_HOLD_DAYS`.
643 * Publishes `workspace.renamed`.
644 */
645 renameWorkspace(actor: User, slug: string, newSlug: string): Promise<Result<Workspace>>;
646 /** Whether `renameWorkspace` would be allowed, changing nothing. */
647 checkWorkspaceRename(actor: User, slug: string, newSlug: string): Promise<Result<boolean>>;
648 /**
649 * The workspace's current slug when `slug` is one it was renamed from
650 * within `SLUG_HOLD_DAYS`, or when `slug` is an alias staff set for it
651 * (`WorkspaceAlias`); null otherwise, including for a slug in use.
652 */
653 resolveSlug(slug: string): Promise<string | null>;
654 /**
655 * Owners only, a person only. `confirm` is the slug, typed out. Refused
656 * for a protected workspace, and while billing cannot settle it. Its
657 * repositories, projects and apps go with it; it is kept for
658 * `WORKSPACE_RESTORE_DAYS`, when g1t's staff can restore it, then purged.
659 * Its slug is never given to anyone else; the person whose username it is
660 * may make it again once it is purged. Publishes `workspace.deleting`.
661 */
662 deleteWorkspace(actor: User, slug: string, confirm: string): Promise<Result<boolean>>;
663 /** What `deleteWorkspace` would take with it, and what stands in its way, changing nothing. */
664 checkWorkspaceDeletion(actor: User, slug: string): Promise<Result<WorkspaceDeletion>>;
665 /**
666 * Owners only. `image` is the file in base64: PNG, JPEG, WebP or GIF, at
667 * most `MAX_AVATAR_BYTES`, checked by its bytes. Null removes the icon.
668 */
669 setWorkspaceAvatar(actor: User, slug: string, image: string | null): Promise<Result<Workspace>>;
670 /** A person's own avatar, as `setWorkspaceAvatar`: the new one, or null. */
671 setUserAvatar(user: User, image: string | null): Promise<Result<string | null>>;
672
673 /**
674 * A workspace's own access tokens. They belong to the workspace, act as
675 * it, and keep working when the member who made one leaves. Members only.
676 */
677 listWorkspaceTokens(slug: string, viewer: Viewer): Promise<Result<AccessToken[]>>;
678 /** Owners only. The plaintext token is returned once and never stored. */
679 createWorkspaceToken(
680 actor: User,
681 slug: string,
682 name: string,
683 grant?: TokenGrant & { ttlSeconds?: number; admin?: boolean },
684 ): Promise<Result<{ token: string; info: AccessToken }>>;
685 /** Owners only. */
686 removeWorkspaceToken(actor: User, slug: string, id: string): Promise<Result<boolean>>;
687
688 /**
689 * A fine-grained personal access token: one resource owner, some of its
690 * repositories, a level for each permission. People only. It starts
691 * pending when its workspace asks for approval and you are not an owner.
692 */
693 createFineGrainedToken(user: User, input: FineGrainedTokenInput): Promise<Result<{ token: string; info: AccessToken }>>;
694 /** Its owner changes it; what is left out stays. Widening it asks for approval again. */
695 updateFineGrainedToken(
696 user: User,
697 id: string,
698 change: Partial<Omit<FineGrainedTokenInput, "ttlSeconds" | "workspace">>,
699 ): Promise<Result<AccessToken>>;
700 /** A workspace's rules for personal access tokens. Members only. */
701 getTokenPolicy(slug: string, viewer: Viewer): Promise<Result<TokenPolicy>>;
702 /** Owners only, as people. `maxLifetimeDays` of 0 removes the limit. */
703 setTokenPolicy(
704 actor: User,
705 slug: string,
706 change: Partial<Omit<TokenPolicy, "updatedBy" | "updatedAt">>,
707 ): Promise<Result<TokenPolicy>>;
708 /** The members' tokens that can reach a workspace. Owners only. */
709 listMemberTokens(
710 actor: User,
711 slug: string,
712 filter?: { status?: TokenStatus; kind?: TokenKind },
713 ): Promise<Result<MemberToken[]>>;
714 /** Approve or deny a fine-grained token waiting for approval. Owners only. */
715 reviewTokenRequest(actor: User, slug: string, id: string, approve: boolean, reason?: string | null): Promise<Result<MemberToken>>;
716 /** Take a member's token out of the workspace. Owners only. */
717 revokeMemberToken(actor: User, slug: string, id: string, reason?: string | null): Promise<Result<boolean>>;
718
719 userForSession(sessionToken: string): Promise<Viewer>;
720
721 /** Whether registration is invite-only. */
722 registration(): Promise<RegistrationMode>;
723 /** A person's invites and what they have left. */
724 listInvites(user: User): Promise<InvitesOverview>;
725 /**
726 * A person makes an invite, optionally for one address (emailed to it),
727 * using one of theirs or, with `workspace`, one the workspace was granted.
728 * People only: never an agent or a workspace's token.
729 */
730 createInvite(user: User, options?: { email?: string | null; workspace?: string | null }): Promise<Result<Invite>>;
731 /** Its maker, or an owner of its workspace, revokes a pending invite; the invite comes back. */
732 revokeInvite(user: User, id: string): Promise<Result<Invite>>;
733 /**
734 * What a code is for. Unknown, used, revoked and expired codes all get the
735 * same answer, unless `anyStatus`: then a real code that is spent is
736 * described, with its `status`. `viewer` sets `forViewer`.
737 */
738 checkInvite(
739 code: string,
740 client?: string | null,
741 options?: { viewer?: User | null; anyStatus?: boolean },
742 ): Promise<Result<InvitePreview>>;
743 /**
744 * A signed-in person uses a workspace invite sent to their address, or one
745 * sent with a repository invitation; returns the workspace's slug, or
746 * `workspace/repo`.
747 */
748 acceptInvite(user: User, code: string): Promise<Result<string>>;
749 /** Owners only. Invites an address into a workspace, always with an invite bound to it. */
750 inviteMember(actor: User, slug: string, email: string): Promise<Result<Invite>>;
751 /** Owners only: the workspace's invites, newest first. */
752 workspaceInvites(slug: string, viewer: Viewer): Promise<Result<Invite[]>>;
753 /** Owners only. */
754 revokeWorkspaceInvite(actor: User, slug: string, id: string): Promise<Result<Invite>>;
755 /** Someone without an invite asks for one. Always the same answer for a valid address. */
756 requestAccess(email: string, about: string, client?: string | null): Promise<Result<boolean>>;
757
758 /** Verifies git credentials: the account password or an access token. */
759 userForGitCredentials(username: string, secret: string): Promise<Viewer>;
760 /** Resolves a `g1t_…` access token, as sent to the API and MCP server. */
761 userForAccessToken(token: string): Promise<Viewer>;
762 userForSshKey(fingerprint: string): Promise<Viewer>;
763 userByUsername(username: string): Promise<Viewer>;
764 /** The names behind account and workspace ids; unknown ids are left out. */
765 usernames(ids: string[]): Promise<Record<string, string>>;
766
767 /** A person's public profile, or null if there is no such account. Never an email address. */
768 profile(username: string): Promise<Profile | null>;
769 /** A person changes their own profile. Every field is replaced; an empty one is cleared. */
770 updateProfile(actor: User, fields: ProfileFields): Promise<Result<Profile>>;
771 /**
772 * The workspaces a profile shows `viewer`: those the viewer belongs to
773 * as well, and those of `publicIn` (where the person made a public
774 * project) that the person really belongs to. Nothing else.
775 */
776 profileWorkspaces(username: string, viewer: Viewer, publicIn: string[]): Promise<ProfileWorkspace[]>;
777
778 listSshKeys(user: User): Promise<SshKey[]>;
779 /** Takes one line in OpenSSH public key format. */
780 addSshKey(user: User, title: string, publicKey: string): Promise<Result<SshKey>>;
781 removeSshKey(user: User, id: string): Promise<void>;
782
783 listAccessTokens(user: User): Promise<AccessToken[]>;
784 /**
785 * The plaintext token is returned once and never stored. With
786 * `ttlSeconds` the token expires and is left out of token lists; that
787 * form is used for hosted agents. A token made for a workspace acting
788 * through a token of its own belongs to that workspace too.
789 */
790 createAccessToken(
791 user: User,
792 name: string,
793 ttlSeconds?: number,
794 grant?: TokenGrant & { listed?: boolean },
795 ): Promise<{ token: string; info: AccessToken }>;
796 /** Changes what one of a person's tokens may do; the token is unchanged. */
797 updateAccessToken(user: User, id: string, grant: TokenGrant): Promise<Result<AccessToken>>;
798 /**
799 * A token for a g1t agent working for `onBehalfOf`: it acts as
800 * `g1t`, in `scope.repo` only, and only for `scope.operations`.
801 */
802 createAgentToken(
803 onBehalfOf: User,
804 scope: AgentScope,
805 ttlSeconds: number,
806 ): Promise<{ token: string; info: AccessToken }>;
807 removeAccessToken(user: User, id: string): Promise<void>;
808 /**
809 * A token for one sandbox run: it acts as the agent on behalf of
810 * `onBehalfOf`, can do only what the run's kind needs in `repo`, and
811 * expires after `ttlSeconds`. See `audit.ts`.
812 */
813 createRunCredential(input: CreateRunCredentialInput): Promise<{ token: string; info: AccessToken }>;
814 /** Ties tokens, by the SHA-256 of their text in hex, to the agent run their sandbox recorded. */
815 bindRunCredentials(tokenHashes: string[], runId: string): Promise<boolean>;
816 /** Ends a sandbox's run credentials, by hash or by run. Never touches another token. */
817 revokeRunCredentials(target: { tokenHashes?: string[]; runId?: string | null }): Promise<boolean>;
818}
819
820
821/** What an agent's token may do: these operations, in this repository. */
822export type AgentScope = { repo: RepoPath; operations: string[]; run?: RunBinding };
823
824/** The most characters each profile field takes. Mirrors `crates/contracts/src/identity.rs`. */
825export const PROFILE_LIMITS = { name: 80, bio: 160, location: 80, website: 200, pronouns: 40 } as const;
826
827/** What anyone may see about a person, at `g1t.sh/u/<username>`. */
828export type Profile = {
829 username: string;
830 /** The name they go by, if they gave one. */
831 name: string | null;
832 bio: string | null;
833 location: string | null;
834 /** Always an `https://` address. */
835 website: string | null;
836 pronouns: string | null;
837 /** The uploaded avatar's hash, served at `/avatars/<avatar>`. */
838 avatar: string | null;
839 /** When the account was made. RFC 3339. */
840 createdAt: string;
841};
842
843/** What a person may change on their profile. Empty clears a field. */
844export type ProfileFields = {
845 name: string;
846 bio: string;
847 location: string;
848 /** `https://…`; a bare `example.com` is taken as `https://example.com`. */
849 website: string;
850 pronouns: string;
851};
852
853/** A workspace on a person's profile. */
854export type ProfileWorkspace = { slug: string; name: string; avatar: string | null };