| 1 | import { env } from "cloudflare:workers"; |
| 2 | |
| 3 | import { |
| 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. */ |
| 17 | export const admin = billingAdminClient(env.BILLING); |
| 18 | |
| 19 | /** The public price book, read-only, from the same service. */ |
| 20 | export const priceBook = () => billingClient(env.BILLING).prices(); |
| 21 | |
| 22 | /** Staff-only identity: every workspace, its owners and members. */ |
| 23 | export const identity = identityAdminClient(env.IDENTITY); |
| 24 | |
| 25 | /** Staff-only accounts: a person's email addresses and security log. */ |
| 26 | export const accountsAdmin = accountsAdminClient(env.IDENTITY); |
| 27 | |
| 28 | /** The workspace's plan, caps and pause, as billing gives them to every service. */ |
| 29 | export const entitlements = (workspace: string) => billingClient(env.BILLING).entitlements(workspace); |
| 30 | |
| 31 | /** The event log, read-only: sudo lists `abuse.flagged`. */ |
| 32 | export const events = eventsClient(env.EVENTS); |
| 33 | |
| 34 | /** The status page's incidents (apps/status's `StatusAdmin` entrypoint). */ |
| 35 | export const statusAdmin = env.STATUS as unknown as StatusAdminApi; |
| 36 | |
| 37 | /** A workspace's self-hosted runners, and removing them (actions' admin_* methods). */ |
| 38 | export const runnersAdmin = runnersAdminClient(env.ACTIONS); |
| 39 | |
| 40 | /** A workspace's projects, read as the workspace itself, which sees them all. */ |
| 41 | export 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. */ |
| 47 | export const telemetry = telemetryClient(env.TELEMETRY); |
| 48 | |
| 49 | /** STAFF_EMAILS, for suggesting staff in the incident roles. */ |
| 50 | export const staffEmails = (): string => env.STAFF_EMAILS ?? ""; |