1// The one host this tool may call, for reads and writes
2export const domains = {
3"api.badges.example.com": "read_write",
4};
5
6export const input = z.object({
7email: z.string().email().describe("Who is leaving"),
8ticket_id: z.string().optional().describe("Their ticket"),
9});
10type Input = z.infer<typeof input>;
11
12const API = "https://api.badges.example.com/v2";
13
14export default async function run({ email, ticket_id }: Input) {
15const token = env.BADGE_API_KEY;
16
17// **Find the cardholder**
18const found = await http.get(`${API}/cardholders`, {
19query: { email },
20auth: { type: "bearer", token },
21});
22const holder =
23found.body.data[0] ?? fail(`No cardholder for ${email}.`);
24
25// **Suspend their badge**
26await http.post(`${API}/cardholders/${holder.id}/suspend`, {
27json: { reason: "Offboarded" },
28auth: { type: "bearer", token },
29});
30
31// **Note it on the ticket**
32await risotto.add_ticket_comment({
33ticket_id,
34comment: `Badge ${holder.badge} suspended for ${email}.`,
35});
36
37return `Suspended badge ${holder.badge} for ${email}.`;
38}