Skip to content
50 linesCodeBlameRaw
1import { env } from "cloudflare:workers";
2
3import {
4 type StatusAdminApi,
5 accountsAdminClient,
6 billingAdminClient,
7 billingClient,
8 eventsClient,
9 identityAdminClient,
10 projectsClient,
11 runnersAdminClient,
12 telemetryClient,
13 type User,
14} from "@g1t/contracts";
15
16/** Staff-only billing, on the billing service. */
17export const admin = billingAdminClient(env.BILLING);
18
19/** The public price book, read-only, from the same service. */
20export const priceBook = () => billingClient(env.BILLING).prices();
21
22/** Staff-only identity: every workspace, its owners and members. */
23export const identity = identityAdminClient(env.IDENTITY);
24
25/** Staff-only accounts: a person's email addresses and security log. */
26export const accountsAdmin = accountsAdminClient(env.IDENTITY);
27
28/** The workspace's plan, caps and pause, as billing gives them to every service. */
29export const entitlements = (workspace: string) => billingClient(env.BILLING).entitlements(workspace);
30
31/** The event log, read-only: sudo lists `abuse.flagged`. */
32export const events = eventsClient(env.EVENTS);
33
34/** The status page's incidents (apps/status's `StatusAdmin` entrypoint). */
35export const statusAdmin = env.STATUS as unknown as StatusAdminApi;
36
37/** A workspace's self-hosted runners, and removing them (actions' admin_* methods). */
38export const runnersAdmin = runnersAdminClient(env.ACTIONS);
39
40/** A workspace's projects, read as the workspace itself, which sees them all. */
41export const workspaceProjects = (slug: string) => {
42 const workspace: User = { id: `staff:${slug}`, username: slug, kind: "workspace", verified: true, workspaces: [{ slug, role: "member" }] };
43 return projectsClient(env.PROJECTS).list(slug, workspace);
44};
45
46/** Projects' telemetry: their ingest tokens, to see and revoke. */
47export const telemetry = telemetryClient(env.TELEMETRY);
48
49/** STAFF_EMAILS, for suggesting staff in the incident roles. */
50export const staffEmails = (): string => env.STAFF_EMAILS ?? "";