import * as z from "zod" import { defineAction } from "../../../automation/actions" import { getGmailApi, toGmailLabel, } from "@automate.ax/integration-contracts/gmail" import { GMAIL_LABELS_WRITE_REQUIREMENT } from "../lib/scopes" import { LABEL_COLOR_SCHEMA, LABEL_LIST_VISIBILITY_SCHEMA, LABEL_SCHEMA, MESSAGE_LIST_VISIBILITY_SCHEMA, } from "@automate.ax/integration-contracts/gmail" /** Creates a user-owned Gmail label and returns its complete metadata. */ export const createGmailLabel = defineAction("Create Gmail label") .describe("Creates a user-owned Gmail label.") .account("google", GMAIL_LABELS_WRITE_REQUIREMENT) .input( z.object({ /** Optional supported Gmail label color. */ color: LABEL_COLOR_SCHEMA.optional(), /** Visibility in Gmail's label list. */ labelListVisibility: LABEL_LIST_VISIBILITY_SCHEMA.optional(), /** Visibility beside messages in Gmail's message list. */ messageListVisibility: MESSAGE_LIST_VISIBILITY_SCHEMA.optional(), /** Human-readable label name. */ name: z.string().min(1), }), ) .output(LABEL_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => { const { data: label } = await getGmailApi( account.secret, ).users.labels.create({ requestBody: input, userId: "me", }) return toGmailLabel(label) })