g1t/packages/contracts/src/identity.ts

647 lines26,525 bytesCodeBlame
1import type { AccessClient, BasePermission, RepoGrant } from "./access";
2import type { Acting, CreateRunCredentialInput, RunBinding } from "./audit";
3import type { RepoPath } from "./repos";
4import type { Result } from "./result";
5
6export type User = {
7 id: string;
8 username: string;
9 /**
10 * `workspace` when a workspace is acting through one of its own access
11 * tokens: `id` is then the workspace's and `username` its slug. `system`
12 * is g1t itself doing platform work, such as a security update
13 * (`username` `g1t`). Absent means `user`.
14 */
15 kind?: "user" | "workspace" | "agent" | "system";
16 /**
17 * Whether the account's email address is confirmed. Only set on users
18 * resolved from credentials; unverified accounts cannot change anything.
19 */
20 verified?: boolean;
21 /**
22 * The workspaces this user belongs to. Set on users resolved from
23 * credentials, so any service can authorize from it.
24 */
25 workspaces?: Membership[];
26 /**
27 * The person's uploaded avatar: the SHA-256 of its bytes, served at
28 * `/avatars/<avatar>`. Only set on the signed-in person; absent means
29 * the generated letter avatar.
30 */
31 avatar?: string;
32 /**
33 * Set on an agent resolved from its token: who it acts for ("g1t-agent
34 * on behalf of syntaqx"), with which credential, and what it may do.
35 */
36 acting?: Acting;
37 /**
38 * The repositories this user has a role on directly, whether or not they
39 * belong to its workspace. Set with `workspaces`; see `access.ts`.
40 */
41 grants?: RepoGrant[];
42 /**
43 * Set on a user resolved from an access token: its scopes (null for full
44 * access) and the workspaces or repositories it reaches. See scopes.ts.
45 */
46 token?: {
47 token_id: string;
48 scopes?: string[] | null;
49 legacy?: boolean;
50 };
51};
52
53/** What a member may do: an owner also manages the workspace's members. */
54export type Role = "owner" | "member";
55
56export type Membership = {
57 /** The workspace's name in URLs: `g1t.sh/<slug>`. */
58 slug: string;
59 role: Role;
60 /** Its display name. Set on users resolved from credentials. */
61 name?: string;
62 /** Its uploaded icon, as `Workspace.avatar`. */
63 avatar?: string;
64 /** The workspace's base permission: what members get on every repository. Absent means `write`. */
65 base_permission?: BasePermission;
66};
67
68/** How long an old workspace slug redirects, and stays reserved for it, after a rename. */
69export const SLUG_HOLD_DAYS = 90;
70
71/** How long a workspace must wait between renames. */
72export const RENAME_COOLDOWN_HOURS = 24;
73
74/** The largest avatar that can be uploaded, in bytes. */
75export const MAX_AVATAR_BYTES = 1024 * 1024;
76
77/**
78 * A workspace: the owner of repositories, and the first segment of their
79 * URLs. A person's own space and a team's are the same thing.
80 */
81export type Workspace = {
82 id: string;
83 slug: string;
84 name: string;
85 /** One line saying what the workspace is for. */
86 description: string | null;
87 /** RFC 3339. */
88 createdAt: string;
89 memberCount: number;
90 /**
91 * The workspace's uploaded icon: the SHA-256 of its bytes, served at
92 * `/avatars/<avatar>`. Null means the generated letter avatar.
93 */
94 avatar: string | null;
95 /** What every member gets on each repository; owners have Admin. */
96 basePermission?: BasePermission;
97};
98
99export type Member = {
100 username: string;
101 role: Role;
102 /** Their display name, when they set one. */
103 name?: string | null;
104 /** Their uploaded avatar's hash, served at `/avatars/<avatar>`; null for the generated letter avatar. */
105 avatar?: string | null;
106};
107
108/** An owner of a workspace, as staff see them. */
109export type AdminOwner = { username: string; email: string | null };
110
111/** A workspace as staff see it. Mirrors `AdminWorkspace` in `crates/contracts/src/identity.rs`. */
112export type AdminWorkspace = {
113 slug: string;
114 name: string;
115 /** RFC 3339. */
116 createdAt: string;
117 owners: AdminOwner[];
118 memberCount: number;
119};
120
121/** A member of a workspace, as staff see them. */
122export type AdminMember = { username: string; email: string | null; role: Role; /** RFC 3339. */ joined: string };
123
124export type AdminWorkspaceDetail = {
125 slug: string;
126 name: string;
127 description: string | null;
128 /** RFC 3339. */
129 createdAt: string;
130 /** Owners first, then by username. */
131 members: AdminMember[];
132};
133
134/** The most workspaces one `workspaces` call returns. */
135export const ADMIN_WORKSPACES_LIMIT = 500;
136
137/**
138 * Whether anyone may make an account, or only someone with an invite.
139 * Identity's `REGISTRATION_MODE`; unset means `invite`.
140 */
141export type RegistrationMode = "invite" | "open";
142
143/** How many invites a person may have out at once, unless identity's `INVITES_PER_USER` says otherwise. */
144export const INVITES_PER_USER = 5;
145/** How long an invite works, unless identity's `INVITE_TTL_DAYS` says otherwise. */
146export const INVITE_TTL_DAYS = 30;
147
148/** Only a pending invite can be used or revoked. Revoked and expired ones never used give the invite back. */
149export type InviteStatus = "pending" | "redeemed" | "expired" | "revoked";
150
151/** One invite. Mirrors `Invite` in `crates/contracts/src/identity.rs`. */
152export type Invite = {
153 id: string;
154 /** `g1t-k7m2-…`: returned when it is made, and to its maker while pending. */
155 code: string | null;
156 /** The code's first group, such as `g1t-k7m2`. */
157 hint: string;
158 /** Only this address can use it. */
159 email: string | null;
160 /** `account` makes an account; `workspace` joins an existing one to `workspace`. */
161 kind: "account" | "workspace";
162 /** The workspace using it joins. */
163 workspace: string | null;
164 status: InviteStatus;
165 /** Whose allowance it used. */
166 chargedTo: "user" | "workspace" | "none";
167 /** Its maker's username; null when g1t staff made it. */
168 invitedBy: string | null;
169 /** The account that used it. */
170 redeemedBy: string | null;
171 /** RFC 3339. */
172 createdAt: string;
173 /** RFC 3339. */
174 expiresAt: string;
175 redeemedAt: string | null;
176 revokedAt: string | null;
177 /** The staff member who minted it; only in staff views. */
178 staff?: string | null;
179};
180
181/** How many invites someone may have out. `limit` and `remaining` are null for no limit. */
182export type Allowance = { limit: number | null; used: number; remaining: number | null };
183
184export type InvitesOverview = {
185 mode: RegistrationMode;
186 allowance: Allowance;
187 /** Workspaces the person owns that were granted invites to share. */
188 workspaces: { slug: string; allowance: Allowance }[];
189 invites: Invite[];
190};
191
192/** What a valid code is for, before it is used. */
193export type InvitePreview = {
194 kind: "account" | "workspace";
195 /** Pending, unless `anyStatus` asked about a code that is spent. */
196 status: InviteStatus;
197 /** Null when g1t staff sent it. */
198 invitedBy: { username: string; name: string | null; avatar: string | null } | null;
199 workspace: ProfileWorkspace | null;
200 /** The repository it accepts an invitation to, such as `{ name: "flagon-io/g1t", role: "write" }`. */
201 repository: { name: string; role: string } | null;
202 /** Partly hidden, such as `a•••@example.com`. */
203 email: string | null;
204 /** The bound address in full, while the invite is pending: it fills in and locks the sign-up form. */
205 address: string | null;
206 /** Whether the bound address has a g1t account already: sign in to accept. */
207 hasAccount: boolean;
208 /** With a viewer: whether it is theirs (for one of their confirmed addresses, or used by them). */
209 forViewer: boolean | null;
210 expiresAt: string;
211};
212
213export type WaitlistStatus = "waiting" | "invited" | "dismissed";
214
215export type WaitlistEntry = {
216 id: string;
217 email: string;
218 about: string | null;
219 status: WaitlistStatus;
220 inviteId: string | null;
221 decidedBy: string | null;
222 decidedAt: string | null;
223 /** What staff wrote when approving; it went in the invite email. */
224 note: string | null;
225 /** The account made with the invite, once it was used. */
226 joinedAs: string | null;
227 /** When they first asked. */
228 createdAt: string;
229 /** When they last asked. */
230 updatedAt: string;
231};
232
233export type InviteGrant = { amount: number; note: string | null; grantedBy: string; createdAt: string };
234export type InviteTreeNode = { username: string; joinedAt: string; invited: InviteTreeNode[] };
235
236/** Where a person came from and whom they brought. For a workspace, `username` is its slug. */
237export type InviteTree = {
238 username: string;
239 /** Who invited them, then who invited that person, and so on. */
240 invitedBy: string[];
241 /** The staff member who minted their invite, when staff did. */
242 staff: string | null;
243 allowance: Allowance;
244 grants: InviteGrant[];
245 invites: Invite[];
246 /** Whom they invited, three levels down. */
247 invited: InviteTreeNode[];
248};
249
250/** The most rows one staff listing of invites or the waitlist returns. */
251export const ADMIN_INVITES_LIMIT = 500;
252
253/**
254 * Staff-only identity, for sudo.g1t.sh. It takes no viewer and checks no
255 * membership: only sudo calls it, over its service binding, once Cloudflare
256 * Access and its staff list have let someone in. Never call it on behalf of
257 * a customer.
258 */
259export interface IdentityAdminApi {
260 /** Every workspace, newest first, at most 500; `query` matches slug, name, or an owner's username or email. */
261 workspaces(query?: string): Promise<AdminWorkspace[]>;
262 /** One workspace with all its members, or null. */
263 workspace(slug: string): Promise<AdminWorkspaceDetail | null>;
264
265 /** The waitlist, newest first; `query` matches the address or what they said. */
266 waitlist(query?: string | null, status?: WaitlistStatus | null): Promise<WaitlistEntry[]>;
267 /** How many requests are waiting, for the navigation's badge. */
268 waitlistPending(): Promise<number>;
269 /**
270 * Approving mints an invite bound to the address and emails it, with
271 * `note` (up to 500 characters) if given; dismissing only marks it.
272 */
273 decideWaitlist(id: string, approve: boolean, staff: string, note?: string | null): Promise<Result<WaitlistEntry>>;
274 /** Invites, newest first; `query` is a code's start, or part of an email, inviter or redeemer. */
275 invites(query?: string | null): Promise<Invite[]>;
276 revokeInvite(id: string, staff: string): Promise<Result<Invite>>;
277 /** An invite that uses nobody's allowance, optionally bound to (and emailed to) `email`. */
278 mintInvite(email: string | null, staff: string): Promise<Result<Invite>>;
279 /** More invites (or fewer, with a negative amount) for a person or a workspace. */
280 grantInvites(
281 target: "user" | "workspace",
282 name: string,
283 amount: number,
284 note: string,
285 staff: string,
286 ): Promise<Result<Allowance>>;
287 /** Where a person came from and whom they brought, or null. */
288 inviteTree(username: string): Promise<InviteTree | null>;
289 /** A workspace's granted invites and the invites made for it, or null. */
290 workspaceInvites(slug: string): Promise<InviteTree | null>;
291}
292
293/** Who is asking. Every read and write in every service takes one. */
294export type Viewer = User | null;
295
296export type SshKey = {
297 id: string;
298 title: string;
299 fingerprint: string;
300 /** RFC 3339. */
301 createdAt: string;
302};
303
304export type AccessToken = {
305 id: string;
306 name: string;
307 /** RFC 3339. */
308 createdAt: string;
309 /** RFC 3339, to within a few minutes. Null until it is first used. */
310 lastUsedAt: string | null;
311 /**
312 * For a workspace's token, the username of the member who made it. Null
313 * once that account is gone, and on personal tokens.
314 */
315 createdBy: string | null;
316 /** Its scopes, as `resource:level`. Null: full access. */
317 scopes: string[] | null;
318 /** Made before tokens had scopes: full access until someone narrows it. */
319 legacy: boolean;
320 /** RFC 3339. Null: it does not expire. */
321 expiresAt: string | null;
322};
323
324/** What a new or changed token may do. */
325export type TokenGrant = {
326 /** Null: full access. */
327 scopes: string[] | null;
328};
329
330export type DeviceStart = {
331 /** Secret held by the tool and exchanged for a token once approved. */
332 deviceCode: string;
333 /** Short code shown to the person, e.g. `WDJB-MJHT`. */
334 userCode: string;
335 /** Seconds until both codes stop working. */
336 expiresIn: number;
337 /** Seconds the tool should wait between polls. */
338 interval: number;
339};
340
341export type DeviceRequest = { userCode: string; clientName: string };
342
343export type DeviceClaim =
344 | { status: "pending" | "denied" | "expired" }
345 | { status: "approved"; token: string; user: User };
346
347/** What the site passes on once a person has approved an application. */
348export type OAuthApproval = {
349 clientId: string;
350 /** Shown wherever the application's access is listed. */
351 clientName: string;
352 redirectUri: string;
353 /** PKCE challenge, method S256. */
354 codeChallenge: string;
355 /** What the person granted. Null: full access. */
356 scopes: string[] | null;
357};
358
359export type OAuthTokens = {
360 accessToken: string;
361 /** Works once; using it returns the next one. */
362 refreshToken: string;
363 /** Seconds until the access token stops working. */
364 expiresIn: number;
365 /** The scopes granted, space-separated, or `*` for full access. */
366 scope?: string | null;
367};
368
369/** An application a person has signed in to. */
370export type OAuthGrant = {
371 id: string;
372 clientName: string;
373 /** RFC 3339. */
374 createdAt: string;
375 /** RFC 3339. */
376 lastUsedAt: string;
377 /** What the person granted. Null: full access. */
378 scopes: string[] | null;
379 /** Signed in before applications had scopes: full access until narrowed. */
380 legacy: boolean;
381};
382
383/** Accounts, credentials and sessions. */
384/** What stands between a workspace and its deletion; nothing when both counts are 0 and `billing` is null. */
385export type WorkspaceDeletion = {
386 repositories: number;
387 projects: number;
388 /** Why billing cannot close it yet, in words for its owner. */
389 billing: string | null;
390};
391
392export interface IdentityApi extends AccessClient {
393 /**
394 * Creates an account and signs it in. While registration is invite-only,
395 * `inviteCode` must be an unused, unexpired invite (and, when it names an
396 * email, that address); it is ignored while registration is open.
397 */
398 register(
399 username: string,
400 email: string,
401 password: string,
402 inviteCode?: string | null,
403 /** Who is asking, such as the visitor's IP address, for rate limits. */
404 client?: string | null,
405 ): Promise<Result<{ user: User; sessionToken: string }>>;
406 /** Verifies a username and password for website sign-in. */
407 /**
408 * Verifies a username, or any confirmed address of the account, and its
409 * password. Wrong passwords are counted against the account and `client`
410 * (the visitor's IP address); past a limit nothing is checked for a while.
411 */
412 signIn(username: string, password: string, client?: string | null): Promise<Result<{ user: User; sessionToken: string }>>;
413 signOut(sessionToken: string): Promise<void>;
414
415 /** Sends the confirmation email again. */
416 resendVerification(user: User): Promise<Result<boolean>>;
417 /** Confirms the address the emailed token was sent to. */
418 verifyEmail(token: string): Promise<Result<User>>;
419 /** Emails a reset link if the address has an account. Always resolves. */
420 /**
421 * Any confirmed address of an account works; the link goes to it, and the
422 * primary and backup are told. A few an hour per address and per `client`.
423 */
424 requestPasswordReset(email: string, client?: string | null): Promise<boolean>;
425 /** Sets a new password from an emailed token and ends every session. */
426 resetPassword(token: string, password: string): Promise<Result<User>>;
427
428 /**
429 * Device sign-in (RFC 8628). A tool starts a request, a person approves
430 * its short code in a browser, and the tool claims an access token.
431 */
432 deviceStart(clientName: string): Promise<DeviceStart>;
433 /** What a user code is asking for, or null if it is not valid. */
434 deviceLookup(userCode: string): Promise<DeviceRequest | null>;
435 deviceResolve(userCode: string, user: User, approve: boolean): Promise<Result<boolean>>;
436 deviceClaim(deviceCode: string): Promise<DeviceClaim>;
437
438 /**
439 * OAuth 2.1 for applications that sign a person in through the browser.
440 * The caller has checked the client and its redirect address; this
441 * returns the one-time code the application exchanges for tokens.
442 */
443 oauthAuthorize(user: User, approval: OAuthApproval): Promise<{ code: string }>;
444 /** Redeems a code. It works once, for that client, with the PKCE verifier. */
445 oauthExchange(code: string, codeVerifier: string, clientId: string, redirectUri: string): Promise<Result<OAuthTokens>>;
446 /** Trades a refresh token for new tokens; the old ones stop working. */
447 oauthRefresh(refreshToken: string, clientId: string): Promise<Result<OAuthTokens>>;
448 /** Applications the user has signed in to, most recently used first. */
449 listOAuthGrants(user: User): Promise<OAuthGrant[]>;
450 /** Signs an application out. */
451 revokeOAuthGrant(user: User, id: string): Promise<void>;
452 /** Changes what an application may do, at once and when it refreshes. */
453 updateOAuthGrant(user: User, id: string, grant: TokenGrant): Promise<Result<OAuthGrant>>;
454
455 createWorkspace(user: User, slug: string, name: string): Promise<Result<Workspace>>;
456 /** Public details of a workspace, or null. */
457 getWorkspace(slug: string): Promise<Workspace | null>;
458 /** Members only. */
459 listMembers(slug: string, viewer: Viewer): Promise<Result<Member[]>>;
460 /** Owners only. */
461 addMember(actor: User, slug: string, username: string): Promise<Result<boolean>>;
462 /** Owners only. */
463 removeMember(actor: User, slug: string, username: string): Promise<Result<boolean>>;
464 /** Owners only. An empty name falls back to the slug. */
465 updateWorkspace(actor: User, slug: string, details: { name: string; description: string }): Promise<Result<Workspace>>;
466 /**
467 * Owners only. Changes the slug, the first segment of the workspace's
468 * URLs; the display name is untouched. The old slug redirects to the new
469 * one, and stays reserved for this workspace, for `SLUG_HOLD_DAYS`.
470 * Publishes `workspace.renamed`.
471 */
472 renameWorkspace(actor: User, slug: string, newSlug: string): Promise<Result<Workspace>>;
473 /** Whether `renameWorkspace` would be allowed, changing nothing. */
474 checkWorkspaceRename(actor: User, slug: string, newSlug: string): Promise<Result<boolean>>;
475 /**
476 * The workspace's current slug when `slug` is one it was renamed from
477 * within `SLUG_HOLD_DAYS`; null otherwise, including for a slug in use.
478 */
479 resolveSlug(slug: string): Promise<string | null>;
480 /**
481 * Owners only, a person only. `confirm` is the slug, typed out. Refused
482 * while the workspace holds repositories or projects, or billing cannot
483 * settle it. Its slug is never given to anyone else; the person whose
484 * username it is may make it again. Publishes `workspace.deleted`.
485 */
486 deleteWorkspace(actor: User, slug: string, confirm: string): Promise<Result<boolean>>;
487 /** What stands in the way of `deleteWorkspace`, changing nothing. */
488 checkWorkspaceDeletion(actor: User, slug: string): Promise<Result<WorkspaceDeletion>>;
489 /**
490 * Owners only. `image` is the file in base64: PNG, JPEG, WebP or GIF, at
491 * most `MAX_AVATAR_BYTES`, checked by its bytes. Null removes the icon.
492 */
493 setWorkspaceAvatar(actor: User, slug: string, image: string | null): Promise<Result<Workspace>>;
494 /** A person's own avatar, as `setWorkspaceAvatar`: the new one, or null. */
495 setUserAvatar(user: User, image: string | null): Promise<Result<string | null>>;
496
497 /**
498 * A workspace's own access tokens. They belong to the workspace, act as
499 * it, and keep working when the member who made one leaves. Members only.
500 */
501 listWorkspaceTokens(slug: string, viewer: Viewer): Promise<Result<AccessToken[]>>;
502 /** Owners only. The plaintext token is returned once and never stored. */
503 createWorkspaceToken(
504 actor: User,
505 slug: string,
506 name: string,
507 grant?: TokenGrant & { ttlSeconds?: number },
508 ): Promise<Result<{ token: string; info: AccessToken }>>;
509 /** Owners only. */
510 removeWorkspaceToken(actor: User, slug: string, id: string): Promise<Result<boolean>>;
511
512 userForSession(sessionToken: string): Promise<Viewer>;
513
514 /** Whether registration is invite-only. */
515 registration(): Promise<RegistrationMode>;
516 /** A person's invites and what they have left. */
517 listInvites(user: User): Promise<InvitesOverview>;
518 /**
519 * A person makes an invite, optionally for one address (emailed to it),
520 * using one of theirs or, with `workspace`, one the workspace was granted.
521 * People only: never an agent or a workspace's token.
522 */
523 createInvite(user: User, options?: { email?: string | null; workspace?: string | null }): Promise<Result<Invite>>;
524 /** Its maker, or an owner of its workspace, revokes a pending invite; the invite comes back. */
525 revokeInvite(user: User, id: string): Promise<Result<Invite>>;
526 /**
527 * What a code is for. Unknown, used, revoked and expired codes all get the
528 * same answer, unless `anyStatus`: then a real code that is spent is
529 * described, with its `status`. `viewer` sets `forViewer`.
530 */
531 checkInvite(
532 code: string,
533 client?: string | null,
534 options?: { viewer?: User | null; anyStatus?: boolean },
535 ): Promise<Result<InvitePreview>>;
536 /**
537 * A signed-in person uses a workspace invite sent to their address, or one
538 * sent with a repository invitation; returns the workspace's slug, or
539 * `workspace/repo`.
540 */
541 acceptInvite(user: User, code: string): Promise<Result<string>>;
542 /** Owners only. Invites an address into a workspace, always with an invite bound to it. */
543 inviteMember(actor: User, slug: string, email: string): Promise<Result<Invite>>;
544 /** Owners only: the workspace's invites, newest first. */
545 workspaceInvites(slug: string, viewer: Viewer): Promise<Result<Invite[]>>;
546 /** Owners only. */
547 revokeWorkspaceInvite(actor: User, slug: string, id: string): Promise<Result<Invite>>;
548 /** Someone without an invite asks for one. Always the same answer for a valid address. */
549 requestAccess(email: string, about: string, client?: string | null): Promise<Result<boolean>>;
550
551 /** Verifies git credentials: the account password or an access token. */
552 userForGitCredentials(username: string, secret: string): Promise<Viewer>;
553 /** Resolves a `g1t_…` access token, as sent to the API and MCP server. */
554 userForAccessToken(token: string): Promise<Viewer>;
555 userForSshKey(fingerprint: string): Promise<Viewer>;
556 userByUsername(username: string): Promise<Viewer>;
557 /** The names behind account and workspace ids; unknown ids are left out. */
558 usernames(ids: string[]): Promise<Record<string, string>>;
559
560 /** A person's public profile, or null if there is no such account. Never an email address. */
561 profile(username: string): Promise<Profile | null>;
562 /** A person changes their own profile. Every field is replaced; an empty one is cleared. */
563 updateProfile(actor: User, fields: ProfileFields): Promise<Result<Profile>>;
564 /**
565 * The workspaces a profile shows `viewer`: those the viewer belongs to
566 * as well, and those of `publicIn` (where the person made a public
567 * project) that the person really belongs to. Nothing else.
568 */
569 profileWorkspaces(username: string, viewer: Viewer, publicIn: string[]): Promise<ProfileWorkspace[]>;
570
571 listSshKeys(user: User): Promise<SshKey[]>;
572 /** Takes one line in OpenSSH public key format. */
573 addSshKey(user: User, title: string, publicKey: string): Promise<Result<SshKey>>;
574 removeSshKey(user: User, id: string): Promise<void>;
575
576 listAccessTokens(user: User): Promise<AccessToken[]>;
577 /**
578 * The plaintext token is returned once and never stored. With
579 * `ttlSeconds` the token expires and is left out of token lists; that
580 * form is used for hosted agents. A token made for a workspace acting
581 * through a token of its own belongs to that workspace too.
582 */
583 createAccessToken(
584 user: User,
585 name: string,
586 ttlSeconds?: number,
587 grant?: TokenGrant & { listed?: boolean },
588 ): Promise<{ token: string; info: AccessToken }>;
589 /** Changes what one of a person's tokens may do; the token is unchanged. */
590 updateAccessToken(user: User, id: string, grant: TokenGrant): Promise<Result<AccessToken>>;
591 /**
592 * A token for a g1t agent working for `onBehalfOf`: it acts as
593 * `g1t-agent`, in `scope.repo` only, and only for `scope.operations`.
594 */
595 createAgentToken(
596 onBehalfOf: User,
597 scope: AgentScope,
598 ttlSeconds: number,
599 ): Promise<{ token: string; info: AccessToken }>;
600 removeAccessToken(user: User, id: string): Promise<void>;
601 /**
602 * A token for one sandbox run: it acts as the agent on behalf of
603 * `onBehalfOf`, can do only what the run's kind needs in `repo`, and
604 * expires after `ttlSeconds`. See `audit.ts`.
605 */
606 createRunCredential(input: CreateRunCredentialInput): Promise<{ token: string; info: AccessToken }>;
607 /** Ties tokens, by the SHA-256 of their text in hex, to the agent run their sandbox recorded. */
608 bindRunCredentials(tokenHashes: string[], runId: string): Promise<boolean>;
609 /** Ends a sandbox's run credentials, by hash or by run. Never touches another token. */
610 revokeRunCredentials(target: { tokenHashes?: string[]; runId?: string | null }): Promise<boolean>;
611}
612
613
614/** What an agent's token may do: these operations, in this repository. */
615export type AgentScope = { repo: RepoPath; operations: string[]; run?: RunBinding };
616
617/** The most characters each profile field takes. Mirrors `crates/contracts/src/identity.rs`. */
618export const PROFILE_LIMITS = { name: 80, bio: 160, location: 80, website: 200, pronouns: 40 } as const;
619
620/** What anyone may see about a person, at `g1t.sh/u/<username>`. */
621export type Profile = {
622 username: string;
623 /** The name they go by, if they gave one. */
624 name: string | null;
625 bio: string | null;
626 location: string | null;
627 /** Always an `https://` address. */
628 website: string | null;
629 pronouns: string | null;
630 /** The uploaded avatar's hash, served at `/avatars/<avatar>`. */
631 avatar: string | null;
632 /** When the account was made. RFC 3339. */
633 createdAt: string;
634};
635
636/** What a person may change on their profile. Empty clears a field. */
637export type ProfileFields = {
638 name: string;
639 bio: string;
640 location: string;
641 /** `https://…`; a bare `example.com` is taken as `https://example.com`. */
642 website: string;
643 pronouns: string;
644};
645
646/** A workspace on a person's profile. */
647export type ProfileWorkspace = { slug: string; name: string; avatar: string | null };