import { defineAction } from "../../../automation/actions" import { getGmailApi } from "@automate.ax/integration-contracts/gmail" import { GMAIL_PROFILE_REQUIREMENT } from "../lib/scopes" import { PROFILE_SCHEMA } from "@automate.ax/integration-contracts/gmail" /** Returns basic mailbox information for the authenticated Gmail account. */ export const getGmailProfile = defineAction("Get Gmail profile") .describe("Gets the authenticated Gmail address and mailbox totals.") .account("google", GMAIL_PROFILE_REQUIREMENT) .output(PROFILE_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account }) => { const { data: profile } = await getGmailApi( account.secret, ).users.getProfile({ userId: "me", }) if (!profile.emailAddress) { throw new Error("Gmail returned an incomplete profile.") } return { emailAddress: profile.emailAddress, historyId: profile.historyId ?? undefined, messagesTotal: profile.messagesTotal ?? undefined, threadsTotal: profile.threadsTotal ?? undefined, } })