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