import { defineAction } from "../../../automation/actions" import type { Webflow } from "webflow-api" import * as serializers from "webflow-api/serialization" import { getWebflowApi, webflowAction, webflowActionSchemas, webflowInputSchema, webflowObjectSchema, webflowRequest, type WebflowInputValue, } from "../lib" type SiteInput = WebflowInputValue & { siteId: string } /** Retrieves the Webflow user represented by the connected OAuth token. */ export const getCurrentWebflowUser = webflowAction< Record, Webflow.AuthorizedUser >( defineAction("Get current Webflow user") .describe("Retrieves the user represented by the connected OAuth token.") .account("webflow", "authorized_user:read") .input( webflowInputSchema>(webflowActionSchemas.empty), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account }) => await getWebflowApi(account).token.authorizedBy(), ), ) /** Retrieves metadata and scope assignments for the connected OAuth token. */ export const getWebflowAuthorization = webflowAction< Record, Webflow.Authorization >( defineAction("Get Webflow authorization") .describe("Retrieves metadata and scopes for the connected OAuth token.") .account("webflow") .input( webflowInputSchema>(webflowActionSchemas.empty), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account }) => await getWebflowApi(account).token.introspect(), ), ) /** Lists all Webflow sites accessible to the connected account. */ export const listWebflowSites = webflowAction< Record, Webflow.Sites >( defineAction("List Webflow sites") .describe("Lists every site accessible to the connected Webflow account.") .account("webflow", "sites:read") .input( webflowInputSchema>(webflowActionSchemas.empty), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler(async ({ account }) => await getWebflowApi(account).sites.list()), ) /** Retrieves metadata, domains, locales, and publishing state for one site. */ export const getWebflowSite = webflowAction( defineAction("Get Webflow site") .describe("Retrieves metadata and publishing state for one Webflow site.") .account("webflow", "sites:read") .input(webflowInputSchema(webflowActionSchemas.id("siteId"))) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account, input }) => await getWebflowApi(account).sites.get(input.siteId), ), ) /** Lists the custom domains configured for one Webflow site. */ export const listWebflowCustomDomains = webflowAction< SiteInput, Webflow.Domains >( defineAction("List Webflow custom domains") .describe("Lists custom domains and their publishing state for a site.") .account("webflow", "sites:read") .input(webflowInputSchema(webflowActionSchemas.id("siteId"))) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account, input }) => await getWebflowApi(account).sites.getCustomDomain(input.siteId), ), ) /** Publishes a Webflow site or individual page to selected domains. */ export const publishWebflowSite = webflowAction< SiteInput, Webflow.SitesPublishResponse >( defineAction("Publish Webflow site") .describe("Publishes a site or page to its Webflow and custom domains.") .account("webflow", "sites:write") .input( webflowInputSchema>( webflowActionSchemas.id("siteId"), serializers.SitesPublishRequest, ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "unsafe" }) .handler( async ({ account, input }) => await getWebflowApi(account).sites.publish( input.siteId, webflowRequest(input, "siteId"), ), ), )