g1t/packages/contracts/src/clients.ts
| 1 | import type { ActionsApi } from "./actions"; |
| 2 | import type { BillingAdminApi, BillingApi } from "./billing"; |
| 3 | import type { DeploymentsApi } from "./deployments"; |
| 4 | import type { ProjectsApi } from "./projects"; |
| 5 | import type { EventsApi } from "./events"; |
| 6 | import type { IdentityAdminApi, IdentityApi } from "./identity"; |
| 7 | import type { IntegrationsApi } from "./integrations"; |
| 8 | import type { WebhooksApi } from "./webhooks"; |
| 9 | import type { ReposApi } from "./repos"; |
| 10 | import type { WorkApi } from "./work"; |
| 11 | import type { RunnersApi } from "./runners"; |
| 12 | |
| 13 | /** A service binding, as far as these clients need it. */ |
| 14 | export type ServiceBinding = { |
| 15 | fetch(input: string, init?: RequestInit): Promise<Response>; |
| 16 | }; |
| 17 | |
| 18 | /** |
| 19 | * Calls a method on a service that speaks the JSON protocol used by the |
| 20 | * Rust services: `POST /rpc/<method>` with the arguments as the body. |
| 21 | */ |
| 22 | async function rpc<T>( |
| 23 | service: ServiceBinding, |
| 24 | method: string, |
| 25 | args: object, |
| 26 | ): Promise<T> { |
| 27 | // The hostname is ignored; a service binding always reaches its service. |
| 28 | const response = await service.fetch(`https://service/rpc/${method}`, { |
| 29 | method: "POST", |
| 30 | headers: { "content-type": "application/json" }, |
| 31 | body: JSON.stringify(args), |
| 32 | }); |
| 33 | if (!response.ok) { |
| 34 | throw new Error(`${method} failed with status ${response.status}`); |
| 35 | } |
| 36 | return (await response.json()) as T; |
| 37 | } |
| 38 | |
| 39 | export function identityClient(service: ServiceBinding): IdentityApi { |
| 40 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 41 | return { |
| 42 | register: (username, email, password, inviteCode, client) => |
| 43 | call("register", { username, email, password, invite_code: inviteCode ?? null, client: client ?? null }), |
| 44 | signIn: (username, password, client) => call("sign_in", { username, password, client: client ?? null }), |
| 45 | signOut: (sessionToken) => call("sign_out", { sessionToken }), |
| 46 | resendVerification: (user) => call("resend_verification", { user }), |
| 47 | verifyEmail: (token) => call("verify_email", { token }), |
| 48 | requestPasswordReset: (email, client) => call("request_password_reset", { email, client: client ?? null }), |
| 49 | resetPassword: (token, password) => |
| 50 | call("reset_password", { token, password }), |
| 51 | deviceStart: (clientName) => call("device_start", { clientName }), |
| 52 | deviceLookup: (userCode) => call("device_lookup", { userCode }), |
| 53 | deviceResolve: (userCode, user, approve) => |
| 54 | call("device_resolve", { userCode, user, approve }), |
| 55 | deviceClaim: (deviceCode) => call("device_claim", { deviceCode }), |
| 56 | oauthAuthorize: (user, approval) => call("oauth_authorize", { user, ...approval }), |
| 57 | oauthExchange: (code, codeVerifier, clientId, redirectUri) => |
| 58 | call("oauth_exchange", { code, codeVerifier, clientId, redirectUri }), |
| 59 | oauthRefresh: (refreshToken, clientId) => |
| 60 | call("oauth_refresh", { refreshToken, clientId }), |
| 61 | listOAuthGrants: (user) => call("list_oauth_grants", { user }), |
| 62 | revokeOAuthGrant: (user, id) => call("revoke_oauth_grant", { user, id }), |
| 63 | updateOAuthGrant: (user, id, grant) => |
| 64 | call("update_oauth_grant", { user, id, scopes: grant.scopes }), |
| 65 | createWorkspace: (user, slug, name) => call("create_workspace", { user, slug, name }), |
| 66 | getWorkspace: (slug) => call("get_workspace", { slug }), |
| 67 | listMembers: (slug, viewer) => call("list_members", { slug, viewer }), |
| 68 | addMember: (actor, slug, username) => call("add_member", { actor, slug, username }), |
| 69 | removeMember: (actor, slug, username) => |
| 70 | call("remove_member", { actor, slug, username }), |
| 71 | updateWorkspace: (actor, slug, details) => |
| 72 | call("update_workspace", { actor, slug, ...details }), |
| 73 | renameWorkspace: (actor, slug, newSlug) => call("rename_workspace", { actor, slug, newSlug }), |
| 74 | checkWorkspaceRename: (actor, slug, newSlug) => |
| 75 | call("check_workspace_rename", { actor, slug, newSlug }), |
| 76 | resolveSlug: (slug) => call("resolve_slug", { slug }), |
| 77 | deleteWorkspace: (actor, slug, confirm) => call("delete_workspace", { actor, slug, confirm }), |
| 78 | checkWorkspaceDeletion: (actor, slug) => call("check_workspace_deletion", { actor, slug }), |
| 79 | setWorkspaceAvatar: (actor, slug, image) => call("set_workspace_avatar", { actor, slug, image }), |
| 80 | setUserAvatar: (user, image) => call("set_user_avatar", { user, image }), |
| 81 | listWorkspaceTokens: (slug, viewer) => call("list_workspace_tokens", { slug, viewer }), |
| 82 | createWorkspaceToken: (actor, slug, name, grant) => |
| 83 | call("create_workspace_token", { |
| 84 | actor, |
| 85 | slug, |
| 86 | name, |
| 87 | scopes: grant?.scopes ?? null, |
| 88 | ttl_seconds: grant?.ttlSeconds ?? null, |
| 89 | }), |
| 90 | removeWorkspaceToken: (actor, slug, id) => |
| 91 | call("remove_workspace_token", { actor, slug, id }), |
| 92 | userForSession: (sessionToken) => call("user_for_session", { sessionToken }), |
| 93 | registration: () => call("registration", {}), |
| 94 | listInvites: (user) => call("list_invites", { user }), |
| 95 | createInvite: (user, options = {}) => |
| 96 | call("create_invite", { user, email: options.email ?? null, workspace: options.workspace ?? null }), |
| 97 | revokeInvite: (user, id) => call("revoke_invite", { user, id }), |
| 98 | checkInvite: (code, client, options = {}) => |
| 99 | call("check_invite", { |
| 100 | code, |
| 101 | client: client ?? null, |
| 102 | viewer: options.viewer ?? null, |
| 103 | any_status: options.anyStatus ?? false, |
| 104 | }), |
| 105 | acceptInvite: (user, code) => call("accept_invite", { user, code }), |
| 106 | inviteMember: (actor, slug, email) => call("invite_member", { actor, slug, email }), |
| 107 | workspaceInvites: (slug, viewer) => call("workspace_invites", { slug, viewer }), |
| 108 | revokeWorkspaceInvite: (actor, slug, id) => call("revoke_workspace_invite", { actor, slug, id }), |
| 109 | requestAccess: (email, about, client) => call("request_access", { email, about, client: client ?? null }), |
| 110 | userForGitCredentials: (username, secret) => |
| 111 | call("user_for_git_credentials", { username, secret }), |
| 112 | userForAccessToken: (token) => call("user_for_access_token", { token }), |
| 113 | userForSshKey: (fingerprint) => call("user_for_ssh_key", { fingerprint }), |
| 114 | userByUsername: (username) => call("user_by_username", { username }), |
| 115 | usernames: (ids) => call("usernames", { ids }), |
| 116 | profile: (username) => call("profile", { username }), |
| 117 | updateProfile: (actor, fields) => call("update_profile", { actor, ...fields }), |
| 118 | profileWorkspaces: (username, viewer, publicIn) => |
| 119 | call("profile_workspaces", { username, viewer, public: publicIn }), |
| 120 | listSshKeys: (user) => call("list_ssh_keys", { user }), |
| 121 | addSshKey: (user, title, publicKey) => |
| 122 | call("add_ssh_key", { user, title, publicKey }), |
| 123 | removeSshKey: (user, id) => call("remove_ssh_key", { user, id }), |
| 124 | listAccessTokens: (user) => call("list_access_tokens", { user }), |
| 125 | createAccessToken: (user, name, ttlSeconds, grant) => |
| 126 | call("create_access_token", { |
| 127 | user, |
| 128 | name, |
| 129 | ttlSeconds, |
| 130 | scopes: grant?.scopes ?? null, |
| 131 | listed: grant?.listed ?? false, |
| 132 | }), |
| 133 | updateAccessToken: (user, id, grant) => |
| 134 | call("update_access_token", { user, id, scopes: grant.scopes }), |
| 135 | createAgentToken: (onBehalfOf, scope, ttlSeconds) => |
| 136 | call("create_agent_token", { onBehalfOf, scope, ttlSeconds }), |
| 137 | removeAccessToken: (user, id) => call("remove_access_token", { user, id }), |
| 138 | createRunCredential: (input) => call("create_run_credential", input), |
| 139 | bindRunCredentials: (tokenHashes, runId) => call("bind_run_credentials", { tokenHashes, runId }), |
| 140 | revokeRunCredentials: (target) => call("revoke_run_credentials", target), |
| 141 | // Who has access to a repository; see access.ts. |
| 142 | repoAccess: (owner, name, viewer) => call("repo_access", { viewer, path: { namespace: owner, name } }), |
| 143 | addCollaborator: (actor, owner, name, invitee, role) => |
| 144 | call("add_collaborator", { actor, path: { namespace: owner, name }, invitee, role }), |
| 145 | setCollaboratorRole: (actor, owner, name, username, role) => |
| 146 | call("set_collaborator_role", { actor, path: { namespace: owner, name }, username, role }), |
| 147 | removeCollaborator: (actor, owner, name, username) => |
| 148 | call("remove_collaborator", { actor, path: { namespace: owner, name }, username }), |
| 149 | collaboratorPermission: (viewer, owner, name, username) => |
| 150 | call("collaborator_permission", { viewer, path: { namespace: owner, name }, username }), |
| 151 | myRepoInvitations: (user) => call("my_repo_invitations", { user }), |
| 152 | respondRepoInvitation: (user, id, accept) => call("respond_repo_invitation", { user, id, accept }), |
| 153 | revokeRepoInvitation: (actor, owner, name, id) => |
| 154 | call("revoke_repo_invitation", { actor, path: { namespace: owner, name }, id }), |
| 155 | setBasePermission: (actor, slug, base) => call("set_base_permission", { actor, slug, base_permission: base }), |
| 156 | outsideCollaborators: (viewer, slug) => call("outside_collaborators", { viewer, slug }), |
| 157 | }; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * The slug a renamed workspace has now, for a `workspace.renamed` handler: |
| 162 | * asked of identity by the workspace's id, so that renames delivered twice |
| 163 | * or out of order converge. Falls back to the event's `to`. |
| 164 | */ |
| 165 | export async function currentWorkspaceSlug( |
| 166 | identity: ServiceBinding, |
| 167 | renamed: { workspaceId: string; to: string }, |
| 168 | ): Promise<string> { |
| 169 | const names = await identityClient(identity).usernames([renamed.workspaceId]); |
| 170 | return names[renamed.workspaceId] ?? renamed.to; |
| 171 | } |
| 172 | |
| 173 | /** The slugs whose rows move to `current`: the two a rename names, less `current`. */ |
| 174 | export function staleSlugs(renamed: { from: string; to: string }, current: string): string[] { |
| 175 | return [...new Set([renamed.from, renamed.to])].filter((slug) => slug !== current); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Where a transferred repository is now, as `namespace/name`, for a |
| 180 | * `repo.transferred` handler: asked of repos by id, so transfers delivered |
| 181 | * twice or out of order converge. Falls back to the event's destination. |
| 182 | */ |
| 183 | export async function currentRepoPath( |
| 184 | repos: ServiceBinding, |
| 185 | transferred: { repoId: string; name: string; to: string }, |
| 186 | ): Promise<string> { |
| 187 | const path = await rpc<{ namespace: string; name: string } | null>(repos, "path_by_id", { id: transferred.repoId }); |
| 188 | return path ? `${path.namespace}/${path.name}` : `${transferred.to}/${transferred.name}`; |
| 189 | } |
| 190 | |
| 191 | /** The paths whose rows move to `current`: the two a transfer names, less `current`. */ |
| 192 | export function stalePaths(transferred: { name: string; from: string; to: string }, current: string): string[] { |
| 193 | return [...new Set([transferred.from, transferred.to].map((ns) => `${ns}/${transferred.name}`))].filter( |
| 194 | (path) => path !== current, |
| 195 | ); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * A repository's path change, from `repo.transferred` or `repo.renamed`, |
| 200 | * read the same way: the two paths (`namespace/name`) the event names, old |
| 201 | * then new. Null for any other event. |
| 202 | */ |
| 203 | export type RepoMove = { repoId: string; paths: [string, string] }; |
| 204 | |
| 205 | export function repoMove(event: { type: string; data: unknown }): RepoMove | null { |
| 206 | const data = event.data as Record<string, string>; |
| 207 | if (event.type === "repo.transferred") { |
| 208 | return { repoId: data.repoId!, paths: [`${data.from}/${data.name}`, `${data.to}/${data.name}`] }; |
| 209 | } |
| 210 | if (event.type === "repo.renamed") { |
| 211 | return { repoId: data.repoId!, paths: [`${data.namespace}/${data.from}`, `${data.namespace}/${data.to}`] }; |
| 212 | } |
| 213 | return null; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Where a moved repository is now, as `namespace/name`: asked of repos by |
| 218 | * id, so moves delivered twice or out of order converge. Falls back to the |
| 219 | * event's new path. |
| 220 | */ |
| 221 | export async function currentMovedPath(repos: ServiceBinding, move: RepoMove): Promise<string> { |
| 222 | const path = await rpc<{ namespace: string; name: string } | null>(repos, "path_by_id", { id: move.repoId }); |
| 223 | return path ? `${path.namespace}/${path.name}` : move.paths[1]; |
| 224 | } |
| 225 | |
| 226 | /** The paths whose rows move to `current`: the two a move names, less `current`. */ |
| 227 | export function staleMovedPaths(move: RepoMove, current: string): string[] { |
| 228 | return [...new Set(move.paths)].filter((path) => path !== current); |
| 229 | } |
| 230 | |
| 231 | /** Staff-only identity. Only sudo binds to it; see `IdentityAdminApi`. */ |
| 232 | export function identityAdminClient(service: ServiceBinding): IdentityAdminApi { |
| 233 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 234 | return { |
| 235 | workspaces: (query) => call("admin_workspaces", { query: query ?? null }), |
| 236 | workspace: (slug) => call("admin_workspace", { slug }), |
| 237 | waitlist: (query, status) => call("admin_waitlist", { query: query ?? null, status: status ?? null }), |
| 238 | waitlistPending: () => call("admin_waitlist_pending", {}), |
| 239 | decideWaitlist: (id, approve, staff, note) => call("admin_decide_waitlist", { id, approve, staff, note: note ?? null }), |
| 240 | invites: (query) => call("admin_invites", { query: query ?? null }), |
| 241 | revokeInvite: (id, staff) => call("admin_revoke_invite", { id, staff }), |
| 242 | mintInvite: (email, staff) => call("admin_mint_invite", { email, staff }), |
| 243 | grantInvites: (target, name, amount, note, staff) => |
| 244 | call("admin_grant_invites", { target, name, amount, note, staff }), |
| 245 | inviteTree: (username) => call("admin_invite_tree", { username }), |
| 246 | workspaceInvites: (slug) => call("admin_workspace_invites", { slug }), |
| 247 | }; |
| 248 | } |
| 249 | |
| 250 | export function reposClient(service: ServiceBinding): ReposApi { |
| 251 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 252 | return { |
| 253 | get: (path, viewer) => call("get", { path, viewer }), |
| 254 | getById: (id, viewer) => call("get_by_id", { id, viewer }), |
| 255 | readable: (ids, viewer) => call("readable", { ids, viewer }), |
| 256 | publicNamespaces: (ownerId) => call("public_namespaces", { ownerId }), |
| 257 | list: (viewer, options = {}) => call("list", { viewer, ...options }), |
| 258 | create: (owner, input) => call("create", { owner, ...input }), |
| 259 | update: (actor, path, changes) => call("update", { actor, path, ...changes }), |
| 260 | transfer: (actor, path, to) => call("transfer", { actor, path, to }), |
| 261 | delete: (actor, path, confirm) => call("delete", { actor, path, confirm }), |
| 262 | deleted: (viewer, namespace) => call("deleted", { viewer, namespace }), |
| 263 | restore: (actor, path) => call("restore", { actor, path }), |
| 264 | purge: (actor, path, confirm) => call("purge", { actor, path, confirm }), |
| 265 | rename: (actor, path, name) => call("rename", { actor, path, name }), |
| 266 | archive: (actor, path, archived) => call("archive", { actor, path, archived }), |
| 267 | setVisibility: (actor, path, isPrivate, confirm) => call("set_visibility", { actor, path, isPrivate, confirm }), |
| 268 | setDefaultBranch: (actor, path, branch) => call("set_default_branch", { actor, path, branch }), |
| 269 | renameBranch: (actor, path, from, to) => call("rename_branch", { actor, path, from, to }), |
| 270 | resolveBranch: (repoId, branch) => call("resolve_branch", { repoId, branch }), |
| 271 | statusById: (id) => call("status_by_id", { id }), |
| 272 | resolvePath: (path) => call("resolve_path", { path }), |
| 273 | tree: (path, viewer, ref, treePath) => |
| 274 | call("tree", { path, viewer, ref, treePath }), |
| 275 | blob: (path, viewer, ref, filePath) => |
| 276 | call("blob", { path, viewer, ref, filePath }), |
| 277 | log: (path, viewer, ref, limit) => call("log", { path, viewer, ref, limit }), |
| 278 | blame: (path, viewer, ref, filePath) => call("blame", { path, viewer, ref, filePath }), |
| 279 | forkForPull: (sourceId, pullId, actor) => |
| 280 | call("fork_for_pull", { sourceId, pullId, actor }), |
| 281 | gitAccess: (path, viewer, service) => |
| 282 | call("git_access", { path, viewer, service }), |
| 283 | branches: (path, viewer) => call("branches", { path, viewer }), |
| 284 | commitFile: (repo, actor, file) => call("commit_file", { repo, actor, ...file }), |
| 285 | land: (sourceId, actor, branch) => call("land", { sourceId, actor, branch }), |
| 286 | compare: (repoId, viewer, base, head) => call("compare", { repoId, viewer, base, head }), |
| 287 | }; |
| 288 | } |
| 289 | |
| 290 | export function workClient(service: ServiceBinding): WorkApi { |
| 291 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 292 | return { |
| 293 | openIssue: (actor, repo, input) => call("open_issue", { actor, repo, ...input }), |
| 294 | delegateIssue: (actor, repo, input) => call("delegate_issue", { actor, repo, ...input }), |
| 295 | listIssues: (repo, viewer, filter = {}) => call("list_issues", { repo, viewer, ...filter }), |
| 296 | getIssue: (repo, number, viewer) => call("get_issue", { repo, number, viewer }), |
| 297 | updateIssue: (actor, repo, number, input) => |
| 298 | call("update_issue", { actor, repo, number, ...input }), |
| 299 | closeIssue: (actor, repo, number, reason) => |
| 300 | call("close_issue", { actor, repo, number, reason }), |
| 301 | reopenIssue: (actor, repo, number) => call("reopen_issue", { actor, repo, number }), |
| 302 | listLabels: (repo, viewer) => call("list_labels", { repo, viewer }), |
| 303 | counts: (repo, viewer) => call("counts", { repo, viewer }), |
| 304 | addComment: (actor, repo, number, comment) => |
| 305 | call("add_comment", { actor, repo, number, ...comment }), |
| 306 | startChecks: (pullId) => call("start_checks", { pullId }), |
| 307 | reportChecks: (runId, token, report) => |
| 308 | call("report_checks", { runId, token, ...report }), |
| 309 | startReview: (pullId) => call("start_review", { pullId }), |
| 310 | failReview: (runId, token, error) => call("report_review", { runId, token, error }), |
| 311 | startMergecheck: (pullId) => call("start_mergecheck", { pullId }), |
| 312 | failMergecheck: (pullId, token, error) => call("report_mergecheck", { pullId, token, error }), |
| 313 | advance: (pullId) => call("advance", { pullId }), |
| 314 | stall: (pullId, reason) => call("stall", { pullId, reason }), |
| 315 | managedPulls: (repoId) => call("managed_pulls", { repoId }), |
| 316 | queue: (repo, viewer) => call("queue", { repo, viewer }), |
| 317 | queueBuild: (repoId) => call("queue_build", { repoId }), |
| 318 | failQueue: (entryId, token, error) => call("report_queue", { entryId, token, error }), |
| 319 | removeFromQueue: (actor, repo, number) => call("remove_from_queue", { actor, repo, number }), |
| 320 | messageAgent: (actor, repo, number, body) => call("message_agent", { actor, repo, number, body }), |
| 321 | catchUpJob: (pullId) => call("catch_up_job", { pullId }), |
| 322 | wakeForMessages: (pullId) => call("wake_for_messages", { pullId }), |
| 323 | getSettings: (repo, viewer) => call("get_settings", { repo, viewer }), |
| 324 | seenChecks: (repo, viewer) => call("seen_checks", { repo, viewer }), |
| 325 | updateSettings: (actor, repo, settings) => |
| 326 | call("update_settings", { actor, repo, settings }), |
| 327 | openPull: (actor, repo, input) => call("open_pull", { actor, repo, ...input }), |
| 328 | listPulls: (repo, viewer, state) => call("list_pulls", { repo, viewer, state }), |
| 329 | pullsForRepos: (repoIds, viewer, limit) => call("pulls_for_repos", { repoIds, viewer, limit }), |
| 330 | getPull: (repo, number, viewer) => call("get_pull", { repo, number, viewer }), |
| 331 | updatePull: (actor, repo, number, changes) => |
| 332 | call("update_pull", { actor, repo, number, ...changes }), |
| 333 | catchUpPull: (actor, repo, number) => call("catch_up_pull", { actor, repo, number }), |
| 334 | readyPull: (actor, repo, number, summary) => |
| 335 | call("ready_pull", { actor, repo, number, summary }), |
| 336 | closePull: (actor, repo, number) => call("close_pull", { actor, repo, number }), |
| 337 | mergePull: (actor, repo, number, options = {}) => |
| 338 | call("merge_pull", { actor, repo, number, ...options }), |
| 339 | listActivePulls: (viewer) => call("list_active_pulls", { viewer }), |
| 340 | byAuthor: (username, viewer, filter = {}) => call("by_author", { username, viewer, ...filter }), |
| 341 | startPlan: (actor, repo, brief) => call("start_plan", { actor, repo, brief }), |
| 342 | failPlan: (planId, token, error) => call("report_plan", { planId, token, error }), |
| 343 | getPlan: (repo, viewer, id) => call("get_plan", { repo, viewer, id }), |
| 344 | listPlans: (repo, viewer) => call("list_plans", { repo, viewer }), |
| 345 | applyPlan: (actor, repo, id, options = {}) => |
| 346 | call("apply_plan", { actor, repo, id, ...options }), |
| 347 | queueIssue: (actor, repo, number, queued) => |
| 348 | call("queue_issue", { actor, repo, number, queued }), |
| 349 | readyIssues: (repoId) => call("ready_issues", { repoId }), |
| 350 | listAssignedIssues: (viewer) => call("list_assigned_issues", { viewer }), |
| 351 | appendSession: (actor, repo, number, entries) => |
| 352 | call("append_session", { actor, repo, number, entries }), |
| 353 | readSession: (repo, number, viewer, afterSeq = 0) => |
| 354 | call("read_session", { repo, number, viewer, afterSeq }), |
| 355 | }; |
| 356 | } |
| 357 | |
| 358 | export function billingClient(service: ServiceBinding): BillingApi { |
| 359 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 360 | return { |
| 361 | status: () => call("status", {}), |
| 362 | account: (workspace, viewer) => call("account", { workspace, viewer }), |
| 363 | ledger: (workspace, viewer) => call("ledger", { workspace, viewer }), |
| 364 | statement: (workspace, viewer, month = null, group = "day") => call("statement", { workspace, viewer, month, group }), |
| 365 | statementEntries: (workspace, viewer, filter) => |
| 366 | call("statement_entries", { |
| 367 | workspace, |
| 368 | viewer, |
| 369 | month: filter.month, |
| 370 | kind: filter.kind, |
| 371 | day: filter.day ?? null, |
| 372 | project: filter.project ?? null, |
| 373 | before: filter.before ?? null, |
| 374 | }), |
| 375 | usage: (workspace, viewer, since) => call("usage", { workspace, viewer, since }), |
| 376 | checkout: (actor, workspace, amountCents, returnUrl, method = "card") => |
| 377 | call("checkout", { actor, workspace, amountCents, returnUrl, method }), |
| 378 | confirm: (workspace, viewer, session) => call("confirm", { workspace, viewer, session }), |
| 379 | canStart: (workspace) => call("can_start", { workspace }), |
| 380 | trial: (workspace, exempt) => call("trial", { workspace, exempt }), |
| 381 | startRun: (run) => call("start_run", run), |
| 382 | features: (workspace, viewer) => call("features", { workspace, viewer }), |
| 383 | subscribe: (actor, workspace, feature, returnUrl) => |
| 384 | call("subscribe", { actor, workspace, feature, returnUrl }), |
| 385 | confirmSubscription: (workspace, viewer, session) => |
| 386 | call("confirm_subscription", { workspace, viewer, session }), |
| 387 | cancelSubscription: (actor, workspace, feature, resume = false) => |
| 388 | call("cancel_subscription", { actor, workspace, feature, resume }), |
| 389 | hasFeature: (workspace, feature) => call("has_feature", { workspace, feature }), |
| 390 | chargeFeature: (charge) => call("charge_feature", charge), |
| 391 | billingPortal: (actor, workspace, returnUrl) => call("billing_portal", { actor, workspace, return_url: returnUrl }), |
| 392 | recordSandbox: (usage) => call("record_sandbox", usage), |
| 393 | limit: (workspace, viewer) => call("limit", { workspace, viewer }), |
| 394 | checkLimit: (workspace) => call("check_limit", { workspace }), |
| 395 | prices: () => call("prices", {}), |
| 396 | notePending: (workspace, source, costMicros, detail = null) => call("note_pending", { workspace, source, costMicros, detail }), |
| 397 | usageMeters: (workspace, viewer) => call("usage_meters", { workspace, viewer }), |
| 398 | setSpendLimit: (actor, workspace, spendLimitMicros, useFullLimit = false, raiseOnce = false) => |
| 399 | call("set_spend_limit", { actor, workspace, spendLimitMicros, use_full_limit: useFullLimit, raise_once: raiseOnce }), |
| 400 | invoices: (workspace, viewer) => call("invoices", { workspace, viewer }), |
| 401 | entitlements: (workspace) => call("entitlements", { workspace }), |
| 402 | reserve: (reservation) => call("reserve", reservation), |
| 403 | settle: (reservationId, actualMicros) => call("settle", { reservationId, actualMicros }), |
| 404 | cardCheck: (actor, workspace, returnUrl) => call("card_check", { actor, workspace, returnUrl }), |
| 405 | confirmCardCheck: (workspace, viewer, session) => call("confirm_card_check", { workspace, viewer, session }), |
| 406 | requestLimit: (actor, workspace, request) => call("request_limit", { actor, workspace, ...request }), |
| 407 | limitRequests: (workspace, viewer) => call("limit_requests", { workspace, viewer }), |
| 408 | confirmSpike: (actor, workspace, keepGoing) => call("confirm_spike", { actor, workspace, keepGoing }), |
| 409 | setCaps: (actor, workspace, caps) => call("set_caps", { actor, workspace, ...caps }), |
| 410 | }; |
| 411 | } |
| 412 | |
| 413 | export function billingAdminClient(service: ServiceBinding): BillingAdminApi { |
| 414 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 415 | return { |
| 416 | accounts: (query) => call("admin_accounts", { query: query ?? null }), |
| 417 | account: (id) => call("admin_account", { id }), |
| 418 | setTerms: (id, terms, by) => call("admin_set_terms", { id, terms, by }), |
| 419 | setAllowances: (id, allowances, note, by) => call("admin_set_allowances", { id, allowances, note, by }), |
| 420 | createEnterprise: (name, workspaces, by) => call("admin_create_enterprise", { name, workspaces, by }), |
| 421 | attach: (workspace, account, by) => call("admin_attach", { workspace, account, by }), |
| 422 | credit: (workspace, amountMicros, note, by) => call("admin_credit", { workspace, amount_micros: amountMicros, note, by }), |
| 423 | billingLink: (workspace, by) => call("admin_billing_link", { workspace, by }), |
| 424 | stripe: (setup = false, by) => call("admin_stripe", { setup, by: by ?? null }), |
| 425 | enterpriseBilling: (id, email, by) => call("admin_enterprise_billing", { id, email, by }), |
| 426 | invoiceEnterprise: (id, by) => call("admin_invoice_enterprise", { id, by }), |
| 427 | accountsFor: (workspaces) => call("admin_accounts", { query: null, workspaces }), |
| 428 | signals: () => call("admin_signals", {}), |
| 429 | overview: () => call("admin_overview", {}), |
| 430 | sales: (workspace) => call("admin_sales", { workspace }), |
| 431 | setSales: (workspace, record, by) => |
| 432 | call("admin_set_sales", { |
| 433 | workspace, |
| 434 | stage: record.stage, |
| 435 | owner: record.owner ?? null, |
| 436 | next_step: record.nextStep ?? null, |
| 437 | next_at: record.nextAt ?? null, |
| 438 | by, |
| 439 | }), |
| 440 | addNote: (workspace, text, by) => call("admin_add_note", { workspace, text, by }), |
| 441 | workspaceInvoices: (workspace) => call("admin_workspace_invoices", { workspace }), |
| 442 | allInvoices: (filter = {}) => call("admin_invoices", { status: filter.status ?? null, month: filter.month ?? null }), |
| 443 | audit: (filter = {}) => |
| 444 | call("admin_audit", { by: filter.by ?? null, action: filter.action ?? null, before: filter.before ?? null }), |
| 445 | limitRequests: (status = "open") => call("admin_limit_requests", { status }), |
| 446 | decideLimitRequest: (id, decision, amountMicros, note, by) => |
| 447 | call("admin_decide_limit_request", { id, decision, amount_micros: amountMicros, note, by }), |
| 448 | overages: () => call("admin_overages", {}), |
| 449 | goodwill: (workspace, amountMicros, reason, by, day = null) => |
| 450 | call("admin_goodwill", { workspace, amount_micros: amountMicros, reason, by, day }), |
| 451 | velocity: () => call("admin_velocity", {}), |
| 452 | recordPayment: (workspace, amountMicros, reference, note, by) => |
| 453 | call("admin_record_payment", { workspace, amount_micros: amountMicros, reference, note, by }), |
| 454 | }; |
| 455 | } |
| 456 | |
| 457 | export function eventsClient(service: ServiceBinding): EventsApi { |
| 458 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 459 | return { |
| 460 | publish: (events) => call("publish", { events }), |
| 461 | list: (query) => call("list", query), |
| 462 | }; |
| 463 | } |
| 464 | |
| 465 | export function integrationsClient(service: ServiceBinding): IntegrationsApi { |
| 466 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 467 | return { |
| 468 | list: (workspace, viewer) => call("list", { workspace, viewer }), |
| 469 | connect: (actor, workspace, input) => call("connect", { actor, workspace, ...input }), |
| 470 | update: (actor, workspace, id, input) => call("update", { actor, workspace, id, ...input }), |
| 471 | disconnect: (actor, workspace, id) => call("disconnect", { actor, workspace, id }), |
| 472 | test: (actor, workspace, id) => call("test", { actor, workspace, id }), |
| 473 | deliveries: (workspace, viewer, id) => call("deliveries", { workspace, viewer, id }), |
| 474 | resolve: (workspace, viewer, reference) => call("resolve", { workspace, viewer, reference }), |
| 475 | references: (workspace, text, limit) => call("references", { workspace, text, limit }), |
| 476 | import: (actor, repo, reference, assign) => call("import", { actor, repo, reference, assign }), |
| 477 | links: (repo, number) => call("links", { repo, number }), |
| 478 | modelProvider: (workspace) => call("model_provider", { workspace }), |
| 479 | openModelSession: (run) => call("open_model_session", run), |
| 480 | modelUpstream: (token) => call("model_upstream", { token }), |
| 481 | routes: (workspace, viewer) => call("routes", { workspace, viewer }), |
| 482 | setRoutes: (actor, workspace, routes) => call("set_routes", { actor, workspace, routes }), |
| 483 | }; |
| 484 | } |
| 485 | |
| 486 | export function webhooksClient(service: ServiceBinding): WebhooksApi { |
| 487 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 488 | return { |
| 489 | list: (viewer, owner) => call("list", { viewer, ...owner }), |
| 490 | create: (actor, owner, input) => call("create", { actor, ...owner, ...input }), |
| 491 | update: (actor, owner, id, input) => call("update", { actor, ...owner, id, ...input }), |
| 492 | delete: (actor, owner, id) => call("delete", { actor, ...owner, id }), |
| 493 | ping: (actor, owner, id) => call("ping", { actor, ...owner, id }), |
| 494 | deliveries: (viewer, owner, id) => call("deliveries", { viewer, ...owner, id }), |
| 495 | redeliver: (actor, owner, deliveryId) => call("redeliver", { actor, ...owner, deliveryId }), |
| 496 | }; |
| 497 | } |
| 498 | |
| 499 | export function actionsClient(service: ServiceBinding): ActionsApi { |
| 500 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 501 | return { |
| 502 | workflows: (repo, viewer) => call("workflows", { repo, viewer }), |
| 503 | runs: (repo, viewer, filter = {}) => call("runs", { repo, viewer, ...filter }), |
| 504 | run: (repo, viewer, id) => call("run", { repo, viewer, id }), |
| 505 | logs: (repo, viewer, job, after = 0) => call("logs", { repo, viewer, job, after }), |
| 506 | dispatch: (actor, repo, workflow, ref, inputs) => call("dispatch", { actor, repo, workflow, ref, inputs }), |
| 507 | cancel: (actor, repo, id) => call("cancel", { actor, repo, id }), |
| 508 | rerun: (actor, repo, id, failedOnly = false) => call("rerun", { actor, repo, id, failed_only: failedOnly }), |
| 509 | setWorkflowEnabled: (actor, repo, workflow, enabled) => |
| 510 | call("set_workflow_enabled", { actor, repo, workflow, enabled }), |
| 511 | settings: (actor, owner, kind) => call("settings", { actor, ...owner, kind }), |
| 512 | setSetting: (actor, owner, kind, name, value, options = {}) => |
| 513 | call("set_setting", { actor, ...owner, kind, name, value, ...options }), |
| 514 | deleteSetting: (actor, owner, kind, name, id) => call("delete_setting", { actor, ...owner, kind, name, id }), |
| 515 | }; |
| 516 | } |
| 517 | |
| 518 | |
| 519 | /** Self-hosted runners, kept by the actions service. */ |
| 520 | export function runnersClient(service: ServiceBinding): RunnersApi { |
| 521 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 522 | return { |
| 523 | stuck: (viewer) => call("stuck_jobs", { viewer }), |
| 524 | list: (actor, owner) => call("runners", { actor, ...owner }), |
| 525 | createToken: (actor, owner, group) => call("create_registration_token", { actor, ...owner, group }), |
| 526 | remove: (actor, owner, id) => call("remove_runner", { actor, ...owner, id }), |
| 527 | groups: (actor, workspace) => call("runner_groups", { actor, workspace }), |
| 528 | setGroup: (actor, workspace, group) => call("set_runner_group", { actor, workspace, ...group }), |
| 529 | deleteGroup: (actor, workspace, id) => call("delete_runner_group", { actor, workspace, id }), |
| 530 | settings: (actor, owner) => call("runner_settings", { actor, ...owner }), |
| 531 | setSettings: (actor, owner, change) => call("set_runner_settings", { actor, ...owner, ...change }), |
| 532 | }; |
| 533 | } |
| 534 | |
| 535 | export function deploymentsClient(service: ServiceBinding): DeploymentsApi { |
| 536 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 537 | return { |
| 538 | settings: (project, viewer) => call("settings", { project, viewer }), |
| 539 | updateSettings: (actor, project, changes) => call("update_settings", { actor, project, changes }), |
| 540 | list: (project, viewer) => call("list", { project, viewer }), |
| 541 | get: (project, id, viewer) => call("get", { project, id, viewer }), |
| 542 | redeploy: (actor, project, branch) => call("redeploy", { actor, project, branch }), |
| 543 | takeDown: (actor, project, branch) => call("take_down", { actor, project, branch }), |
| 544 | stack: (actor, project, branch) => call("stack", { actor, project, branch }), |
| 545 | overview: (workspace, viewer) => call("overview", { workspace, viewer }), |
| 546 | usage: (workspace, viewer) => call("usage", { workspace, viewer }), |
| 547 | domains: (project, viewer) => call("domains", { project, viewer }), |
| 548 | addDomain: (actor, project, hostname, options = {}) => |
| 549 | call("add_domain", { actor, project, hostname, twin: !!options.twin }), |
| 550 | removeDomain: (actor, project, id) => call("remove_domain", { actor, project, id }), |
| 551 | refreshDomain: (actor, project, id) => call("refresh_domain", { actor, project, id }), |
| 552 | }; |
| 553 | } |
| 554 | |
| 555 | export function projectsClient(service: ServiceBinding): ProjectsApi { |
| 556 | const call = <T>(method: string, args: object) => rpc<T>(service, method, args); |
| 557 | return { |
| 558 | list: (workspace, viewer) => call("list", { workspace, viewer }), |
| 559 | get: (workspace, slug, viewer) => call("get", { workspace, slug, viewer }), |
| 560 | byRepo: (repoId) => call("by_repo", { repoId }), |
| 561 | create: (actor, workspace, input) => call("create", { actor, workspace, input }), |
| 562 | update: (actor, workspace, slug, changes) => call("update", { actor, workspace, slug, changes }), |
| 563 | dependencies: (workspace, slug, viewer) => call("dependencies", { workspace, slug, viewer }), |
| 564 | addDependency: (actor, workspace, slug, on, as) => call("add_dependency", { actor, workspace, slug, on, as }), |
| 565 | removeDependency: (actor, workspace, slug, on) => call("remove_dependency", { actor, workspace, slug, on }), |
| 566 | graph: (projectId) => call("graph", { projectId }), |
| 567 | }; |
| 568 | } |