import * as z from "zod" import { defineAction } from "../../../automation/actions" import { findLabelId, getGmailApi, } from "@automate.ax/integration-contracts/gmail" import { GMAIL_LABELS_WRITE_REQUIREMENT } from "../lib/scopes" /** Permanently deletes a user-owned Gmail label and returns its label ID. */ export const deleteGmailLabel = defineAction("Delete Gmail label") .describe("Permanently deletes a user-owned Gmail label.") .account("google", GMAIL_LABELS_WRITE_REQUIREMENT) .input( z.object({ /** Gmail label display name or immutable ID to delete. */ label: z.string().min(1), }), ) .output(z.string()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => { const gmailApi = getGmailApi(account.secret) const labelId = await findLabelId(gmailApi, input.label) await gmailApi.users.labels.delete({ id: labelId, userId: "me", }) return labelId })