import * as z from "zod" import { defineAction } from "../../../automation/actions" import { TRELLO_READ_SCOPE } from "./scopes" import { getTrelloApi } from "@automate.ax/integration-contracts/trello" import { TRELLO_PROVIDER_WORKSPACE_SCHEMA, TRELLO_WORKSPACE_SCHEMA, toTrelloWorkspace, } from "@automate.ax/integration-contracts/trello" const TRELLO_ACCOUNT = "trello" const WORKSPACE_FIELDS = "id,name,displayName,dateLastActivity,url,website" /** Lists Workspaces visible to the connected Trello member. */ export const listTrelloWorkspaces = defineAction("List Trello Workspaces") .describe("Lists Workspaces visible to the connected Trello member.") .account(TRELLO_ACCOUNT, TRELLO_READ_SCOPE) .input( z.object({ /** Which public or member Workspaces to return. */ filter: z.enum(["all", "members", "none", "public"]).prefault("all"), }), ) .output(TRELLO_WORKSPACE_SCHEMA.array()) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => ( await getTrelloApi(account.secret).request("members/me/organizations", { query: { fields: WORKSPACE_FIELDS, filter: input.filter }, responseSchema: TRELLO_PROVIDER_WORKSPACE_SCHEMA.array(), }) ).map(toTrelloWorkspace), ) /** Retrieves one Trello Workspace. */ export const getTrelloWorkspace = defineAction("Get Trello Workspace") .describe("Retrieves one Trello Workspace by ID or URL-safe name.") .account(TRELLO_ACCOUNT, TRELLO_READ_SCOPE) .input( z.object({ /** Stable Workspace ID or URL-safe Workspace name. */ workspace: z.string().trim().min(1), }), ) .output(TRELLO_WORKSPACE_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => toTrelloWorkspace( await getTrelloApi(account.secret).request( `organizations/${encodeURIComponent(input.workspace)}`, { query: { fields: WORKSPACE_FIELDS }, responseSchema: TRELLO_PROVIDER_WORKSPACE_SCHEMA, }, ), ), )