import { defineAction } from "../../../automation/actions" import type { Webflow } from "webflow-api" import * as serializers from "webflow-api/serialization" import * as z from "zod" import { getWebflowApi, webflowAction, webflowActionSchemas, webflowInputSchema, webflowObjectSchema, webflowRequest, type WebflowInputValue, } from "../lib" type SiteInput = WebflowInputValue & { siteId: string } type PageInput = WebflowInputValue & { pageId: string } type ComponentInput = SiteInput & { componentId: string } /** Lists static, CMS template, utility, and localized pages for a site. */ export const listWebflowPages = webflowAction< SiteInput, Webflow.PageList >( defineAction("List Webflow pages") .describe("Lists pages for a site with locale and pagination controls.") .account("webflow", "pages:read") .input( webflowInputSchema>( webflowActionSchemas.parameters(["siteId"], { limit: z.number().int().min(1).max(100).optional(), localeId: z.string().trim().min(1).optional(), offset: z.number().int().nonnegative().optional(), }), ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account, input }) => await getWebflowApi(account).pages.list( input.siteId, webflowRequest(input, "siteId"), ), ), ) /** Retrieves title, SEO, Open Graph, locale, and publishing metadata. */ export const getWebflowPageMetadata = webflowAction< PageInput, Webflow.Page >( defineAction("Get Webflow page metadata") .describe("Retrieves metadata and publishing state for one page.") .account("webflow", "pages:read") .input( webflowInputSchema>( webflowActionSchemas.parameters(["pageId"], { localeId: z.string().trim().min(1).optional(), }), ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account, input }) => await getWebflowApi(account).pages.getMetadata( input.pageId, webflowRequest(input, "pageId"), ), ), ) /** Updates editable metadata and search settings for one Webflow page. */ export const updateWebflowPageSettings = webflowAction< PageInput, Webflow.Page >( defineAction("Update Webflow page settings") .describe("Updates page title, slug, SEO, Open Graph, and draft settings.") .account("webflow", "pages:write") .input( webflowInputSchema>( webflowActionSchemas.parameters(["pageId"], { localeId: z.string().trim().min(1).optional(), }), serializers.PageMetadataWrite, ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "unsafe" }) .handler( async ({ account, input }) => await getWebflowApi(account).pages.updatePageSettings( input.pageId, webflowRequest(input, "pageId"), ), ), ) /** Retrieves editable text and component-instance content from a static page. */ export const getWebflowPageContent = webflowAction< PageInput, Webflow.Dom >( defineAction("Get Webflow page content") .describe("Retrieves editable DOM content from one static page.") .account("webflow", "pages:read") .input( webflowInputSchema>( webflowActionSchemas.parameters(["pageId"], { limit: z.number().int().min(1).max(100).optional(), localeId: z.string().trim().min(1).optional(), offset: z.number().int().nonnegative().optional(), }), ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account, input }) => await getWebflowApi(account).pages.getContent( input.pageId, webflowRequest(input, "pageId"), ), ), ) /** Updates text and component-instance content on one static page. */ export const updateWebflowPageContent = webflowAction< PageInput, Webflow.UpdateStaticContentResponse >( defineAction("Update Webflow page content") .describe("Updates editable DOM nodes on one static page and locale.") .account("webflow", "pages:write") .input( webflowInputSchema>( webflowActionSchemas.parameters(["pageId"], { localeId: z.string().trim().min(1).optional(), }), serializers.PageDomWrite, ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "unsafe" }) .handler( async ({ account, input }) => await getWebflowApi(account).pages.updateStaticContent( input.pageId, webflowRequest(input, "pageId"), ), ), ) /** Lists reusable components defined in one Webflow site. */ export const listWebflowComponents = webflowAction< SiteInput, Webflow.ComponentList >( defineAction("List Webflow components") .describe("Lists reusable components defined in a Webflow site.") .account("webflow", "components:read") .input( webflowInputSchema>( webflowActionSchemas.parameters(["siteId"], { branchId: z.string().trim().min(1).optional(), limit: z.number().int().min(1).max(100).optional(), offset: z.number().int().nonnegative().optional(), }), ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account, input }) => await getWebflowApi(account).components.list( input.siteId, webflowRequest(input, "siteId"), ), ), ) /** Retrieves editable DOM content for one Webflow component. */ export const getWebflowComponentContent = webflowAction< ComponentInput, Webflow.ComponentDom >( defineAction("Get Webflow component content") .describe("Retrieves editable DOM content for one reusable component.") .account("webflow", "components:read") .input( webflowInputSchema>( webflowActionSchemas.parameters(["siteId", "componentId"], { branchId: z.string().trim().min(1).optional(), limit: z.number().int().min(1).max(100).optional(), localeId: z.string().trim().min(1).optional(), offset: z.number().int().nonnegative().optional(), }), ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account, input }) => await getWebflowApi(account).components.getContent( input.siteId, input.componentId, webflowRequest(input, "siteId", "componentId"), ), ), ) /** Updates editable DOM content for one Webflow component. */ export const updateWebflowComponentContent = webflowAction< ComponentInput, Webflow.ComponentsUpdateContentResponse >( defineAction("Update Webflow component content") .describe("Updates editable DOM nodes in one reusable component.") .account("webflow", "components:write") .input( webflowInputSchema>( webflowActionSchemas.parameters(["siteId", "componentId"], { branchId: z.string().trim().min(1).optional(), localeId: z.string().trim().min(1).optional(), }), serializers.ComponentDomWrite, ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "unsafe" }) .handler( async ({ account, input }) => await getWebflowApi(account).components.updateContent( input.siteId, input.componentId, webflowRequest(input, "siteId", "componentId"), ), ), ) /** Retrieves component property definitions and values. */ export const getWebflowComponentProperties = webflowAction< ComponentInput, Webflow.ComponentProperties >( defineAction("Get Webflow component properties") .describe("Retrieves editable properties for one reusable component.") .account("webflow", "components:read") .input( webflowInputSchema< ComponentInput >( webflowActionSchemas.parameters(["siteId", "componentId"], { branchId: z.string().trim().min(1).optional(), limit: z.number().int().min(1).max(100).optional(), localeId: z.string().trim().min(1).optional(), offset: z.number().int().nonnegative().optional(), }), ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "safe" }) .handler( async ({ account, input }) => await getWebflowApi(account).components.getProperties( input.siteId, input.componentId, webflowRequest(input, "siteId", "componentId"), ), ), ) /** Updates editable property values for one Webflow component. */ export const updateWebflowComponentProperties = webflowAction< ComponentInput, Webflow.ComponentsUpdatePropertiesResponse >( defineAction("Update Webflow component properties") .describe("Updates property values on one reusable component.") .account("webflow", "components:write") .input( webflowInputSchema>( webflowActionSchemas.parameters(["siteId", "componentId"], { branchId: z.string().trim().min(1).optional(), localeId: z.string().trim().min(1).optional(), }), serializers.ComponentPropertiesWrite, ), ) .output(webflowObjectSchema()) .retry({ replaySafety: "unsafe" }) .handler( async ({ account, input }) => await getWebflowApi(account).components.updateProperties( input.siteId, input.componentId, webflowRequest(input, "siteId", "componentId"), ), ), )