import { CLOSE_LEAD_STATUS_SCHEMA, CLOSE_OPPORTUNITY_STATUS_SCHEMA, CLOSE_PIPELINE_SCHEMA, CLOSE_USER_SCHEMA, closePageSchema, } from "@automate.ax/integration-contracts/close" import * as z from "zod" import { defineAction } from "../../../automation/actions" import { getCloseApi, CLOSE_ACCOUNT, CLOSE_PAGINATION_SCHEMA } from "./lib" /** Retrieves the connected Close user. */ export const getCurrentCloseUser = defineAction("Get current Close user") .describe( "Retrieves the user and organization represented by the connected account.", ) .account(CLOSE_ACCOUNT) .input(z.object({})) .output(CLOSE_USER_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account }) => getCloseApi(account.secret).request("me/", { responseSchema: CLOSE_USER_SCHEMA, }), ) /** Lists users in the connected Close organization. */ export const listCloseUsers = defineAction("List Close users") .describe("Lists sales reps and other users in the Close organization.") .account(CLOSE_ACCOUNT) .input(z.object(CLOSE_PAGINATION_SCHEMA)) .output(closePageSchema(CLOSE_USER_SCHEMA)) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => getCloseApi(account.secret).request("user/", { query: { _limit: input.limit, _skip: input.skip }, responseSchema: closePageSchema(CLOSE_USER_SCHEMA), }), ) /** Lists Close lead statuses. */ export const listCloseLeadStatuses = defineAction("List Close lead statuses") .describe("Lists the stages that can be assigned to Close leads.") .account(CLOSE_ACCOUNT) .input(z.object({})) .output(closePageSchema(CLOSE_LEAD_STATUS_SCHEMA)) .retry({ replaySafety: "safe" }) .handler(async ({ account }) => getCloseApi(account.secret).request("status/lead/", { responseSchema: closePageSchema(CLOSE_LEAD_STATUS_SCHEMA), }), ) /** Lists Close opportunity pipelines. */ export const listClosePipelines = defineAction("List Close pipelines") .describe("Lists Close pipelines and their ordered opportunity statuses.") .account(CLOSE_ACCOUNT) .input(z.object({})) .output(closePageSchema(CLOSE_PIPELINE_SCHEMA)) .retry({ replaySafety: "safe" }) .handler(async ({ account }) => getCloseApi(account.secret).request("pipeline/", { responseSchema: closePageSchema(CLOSE_PIPELINE_SCHEMA), }), ) /** Lists Close opportunity statuses. */ export const listCloseOpportunityStatuses = defineAction( "List Close opportunity statuses", ) .describe("Lists active, won, and lost stages across Close pipelines.") .account(CLOSE_ACCOUNT) .input(z.object({})) .output(closePageSchema(CLOSE_OPPORTUNITY_STATUS_SCHEMA)) .retry({ replaySafety: "safe" }) .handler(async ({ account }) => getCloseApi(account.secret).request("status/opportunity/", { responseSchema: closePageSchema(CLOSE_OPPORTUNITY_STATUS_SCHEMA), }), )