Skip to content

feat(content): send Content Editor pages to the brand's Webflow collection as draft items (Send to CMS #1331, phase 2 part 2: Webflow send) - #1504

Merged
gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-webflow-send
Oct 25, 2026
Merged

gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-webflow-send

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

#1331, phase 2, part 2: sending pages to Webflow. This builds on #1503 (the brand's Webflow connection) and is stacked on it: merge #1503 first. Server only. The Send dialog's destination (part 4) and the Settings card (part 3) come next.

POST /api/content-drafts/send takes target

  • 'webhook' is the default, so phase 1 and its callers are unchanged.
  • With 'webflow', each page goes to the brand's Webflow collection as a draft item, through lib/cms/webflow-delivery.js.
  • Nothing is published. Webflow's own publish puts an item live, as Send content from the Content Editor and Library to a CMS (webhook first, then WordPress and Webflow) #1331 asks ("drafts only").
  • The same rules as phase 1 apply:
    • admins and managers only;
    • 200 deliveries a day per workspace (reserve_content_deliveries);
    • 25 pages per send, sent one after another with the pause.

Before reserving, the send is refused with a code the web names to the person:

  • webflow_not_configured (503);
  • no_webflow;
  • webflow_refused (the saved token was refused);
  • webflow_not_ready (no collection, or no body field);
  • in_progress.

One page's send

  • Update or create: the item the page's last Webflow send made in this collection is updated in place.
    • That's found by external_id on the delivery, with target_collection.
    • The item's draft or live state is left as it is: a live item's change waits for Webflow's next publish.
    • If that item was deleted in Webflow (not_found), a new draft item is made. Any other refusal of the update fails the send, and no second item is made.
  • The item's fields come from the brand's field map (feat(content): connect a brand's Webflow site for Send to CMS (Send to CMS #1331, phase 2 part 1: Webflow connection) #1503):
    • name ← title, slug ← slug;
    • body ← the publishable HTML, made rich text;
    • meta title ← meta title, or the title;
    • meta description ← meta description, or the page's opening words (at most 160 characters);
    • JSON-LD ← its JSON, for an embed in the collection template. Every < is escaped. It's empty when the page has none, so a page sent again loses what it dropped.
  • The slug keeps what Webflow takes (ç → c). A slug in another script falls back to page-<draft id>, the same on every send.
  • Rich text (lib/cms/webflow-items.js) keeps what Webflow's rich text keeps:
    • Tables: Webflow has none, so a table becomes a list with one item per row ("Header: cell · …"). A cell's paragraphs, items and lines are kept a space apart, with its links. A table a figure wraps (WordPress) is kept, and a table inside a cell is read once.
    • Media: images and media are left out until workspace files exist (CHAT-06). A figure holding an image goes with its caption.
    • Removed: scripts, embeds, forms, rules and comments.
    • Changed: a stray H1 becomes an H2. Code blocks, definition lists, captions, loose words and orphan list items become paragraphs. Attributes go, except a link's href and target.
    • The single-page answer says whether the item was updated, and how many tables and images changed (updated, changed), for part 4's dialog.
  • Refusals:
    • auth_failed marks the connection auth_failed (only the account that was refused), and a batch stops there, closing the remaining pages with the reason.
    • A taken slug says what to do.
  • The item id is always kept, even when the delivery's row was written meanwhile. Otherwise the next send would make a second item and fail on its slug.

00284

  • Adds content_draft_deliveries.target ('webhook' | 'webflow', default 'webhook') and target_collection.
  • reserve_content_deliveries takes p_target text default 'webhook'. The old six-argument function is dropped and recreated in the same migration. The API before this PR calls it with six named arguments and still works.
  • For Webflow, it refuses (delivery_in_progress) any page a send still has queued. This runs under the cap's advisory lock, so two sends of one page can't both make an item. Rows left queued by a stopped server are still closed first (after 30 minutes).
  • Adding the columns validates the two check constraints over content_draft_deliveries, under its lock. The table is small (a few rows on prod).
  • Tried on the dev database inside a rolled-back transaction:
    • the six-argument call → webhook;
    • p_target => 'webflow' → webflow;
    • a second Webflow reserve of the same page → delivery_in_progress;
    • a webhook reserve of it → allowed.

The webhook callback (/webhooks/content-drafts/:deliveryId/status) now answers only for webhook deliveries. A Webflow delivery's id gets the same 401 as an unknown one, so a webhook secret can't change Webflow rows.

The phase-1 refactor: deliver() was split into sendToWebhooks and a shared write. The webhook path writes the same fields, error text and callback-first answer as before. Its tests are unchanged except the new p_target: 'webhook' argument.

Related issue

Part of #1331 (phase 2, Webflow). Stacked on #1503.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. From server/, run npx vitest run src/lib/cms src/lib/content-delivery.test.js src/routes/webhook-content-draft-callback.test.js src/routes/content-drafts-send.test.js.
  2. Real Webflow (needs feat(content): connect a brand's Webflow site for Send to CMS (Send to CMS #1331, phase 2 part 1: Webflow connection) #1503's env var and a site token; yours):
    • connect a brand and map its blog collection;
    • POST /api/content-drafts/send with { brandId, target: 'webflow', pages: [...] } as the editor sends them;
    • check the item in Webflow: a draft, body without images, a table as a list;
    • send it again: the same item is updated (updated: true), and no second item appears;
    • delete the item in Webflow and send again: a new draft item is made.

Deploy order

  1. Apply 00284 before the API: a new API calling p_target without it breaks webhook sends too. 00283 (feat(content): connect a brand's Webflow site for Send to CMS (Send to CMS #1331, phase 2 part 1: Webflow connection) #1503) goes first.
  2. Then deploy the API. The web doesn't send target until part 4.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no web change
  • yarn typecheck passes (run from web/): no web change
  • yarn format:check passes (run from web/): no web change
  • Changes are focused — one concern per PR

A pre-push review found the table cells, figure-wrapped tables, a slug fallback that changed per send, a double send, a lost item id, the batch after a refusal and the callback reaching Webflow rows. Its fixes are the last commit.

Server: npm run format, npm run lint and npm test (2,646 passed) pass. bash supabase/build-schema.sh was run. 00284 is applied on the dev database.

🤖 Generated with Claude Code

cihan-gyk and others added 4 commits October 25, 2026 16:49
…o CMS ansvisor#1331, phase 2 part 1: Webflow connection)

A brand connects its Webflow site with a site token, kept by Composio as
an API-key connected account under the brand's own Composio user, picks
the collection pages go to and which of its fields takes the body, meta
title, meta description and JSON-LD. 00283 adds brand_cms_connections
(members read; the server writes for admins and managers). Routes under
/api/cms/brands/:brandId/webflow connect, list collections and fields
with a suggested map, save the map and disconnect. The token is never
stored, logged or sent back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…refusals narrowly (pre-push review)

- A new token is a second Composio account until the first is removed,
  so connect with allowMultiple; once the new one is saved, the brand's
  other Webflow accounts go (forgetWebflowAccounts), and a disconnect
  removes them all, keeping the row when Composio can't.
- Writes are tied to the account the request read: a map checked with a
  token replaced meanwhile isn't saved (409 changed), a late refusal marks
  only its own token, and a disconnect leaves a token connected meanwhile.
- Only a 401 or a missing Composio account is auth_failed; a 403 is
  no_access and changes nothing; a successful read connects a refused
  connection again.
- A collection's fields are given only for one on a site the token reaches.
- A missing brand answers not_found; a required field can't be the JSON-LD's.
- Unused exports dropped; composio.test.js covers the Webflow helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ction as draft items (Send to CMS ansvisor#1331, phase 2 part 2: Webflow send)

POST /api/content-drafts/send takes target 'webflow': each page becomes a
draft item in the brand's collection (00283) by its field map, or updates
the item its last send made there (a new one when it was deleted in
Webflow). Webflow's rich text has no tables, so a table goes as a list;
images wait for workspace files (CHAT-06); the meta description falls back
to the page's opening words; JSON-LD goes as its JSON to its own field.
The same 200 a day, 25 per send and pause apply. 00284 adds the
delivery's target and the item's collection, and reserve_content_deliveries
takes the target ('webhook' by default, so the earlier API still works).
A token Webflow refuses marks the connection auth_failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as they are (pre-push review)

- A table cell keeps its paragraphs, items and lines a space apart, and
  its links; a table a figure wraps is kept, a table in a cell read once;
  words or items outside a block become paragraphs; comments go; a
  picture counts as one image.
- A slug with nothing Latin left falls back to the draft's id, the same on
  every send, not the delivery's.
- 00284: a second Webflow send of a page while one is queued is refused
  under the cap's lock (in_progress), so two sends can't make two items.
- The item's id is kept even when the delivery's row was written meanwhile.
- A batch stops once Webflow refuses the token, closing the rest.
- The webhook callback answers only for webhook deliveries.
- An emptied JSON-LD field clears the item's old one; every "<" in it is
  escaped; the opening words stay within 160 characters.
- A taken slug says what to do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with follow-ups to fix before it's turned on.

What I checked:

  • 00284.
    • target defaults to webhook, so every existing row reads as a webhook delivery. Both new columns have their checks, and the table is small.
    • reserve_content_deliveries is dropped and made again in the same migration. Its body is 00262's plus the target and the in-progress refusal.
    • It is still security definer with search_path = public, revoked from public, anon and authenticated, and granted to service_role only.
    • The API on main calls it with six named arguments and gets the default. So once 00284 is applied, webhook sends keep working until the deploy.
    • The in-progress check runs under the workspace's advisory lock, before the insert, so a refused send uses none of the quota. A row a stopped server left queued is closed first.
  • Who can send. Unchanged: the brand must be in the caller's workspace, only admins and managers can send, and target is an enum that defaults to webhook.
  • Quota. A Webflow send goes through the same reserve_content_deliveries: 200 a day per workspace, counted across both targets, 25 pages per send, sent 2 seconds apart.
  • The Composio account. The connection is read by the brand id that was checked, and the item calls run on that row's user and account.
  • Before reserving. A server without Webflow set up, a brand with no connection, a refused token, and a missing collection or body field are each refused with their code before anything is reserved.
  • The token. This code never touches it.
    • Failures are logged by error name only.
    • The stored error is our own text, and response_excerpt and http_status stay empty for Webflow.
  • A refused token.
    • Only the refused account is marked auth_failed.
    • A batch stops there and closes the rest with the reason.
    • Later sends are refused before reserving until Settings reads a token Webflow takes.
  • The callback.
    • It now answers only for webhook deliveries, so a webhook secret can't mark a Webflow delivery published or set its item id.
    • lastItem reads only Webflow rows of the same collection.
  • What goes to Webflow.
    • The HTML is cleaned twice: first by cleanPublishHtml, which drops unsafe link schemes, then by a whitelist that keeps only a link's href and target.
    • Every < in the JSON-LD is escaped.
  • Phase 1. The webhook path writes the same fields and gives the same answers as before. Its tests changed only for the new argument.
  • What's live. Without COMPOSIO_WEBFLOW_AUTH_CONFIG_ID, target: 'webflow' is refused (webflow_not_configured) before reserving, and the web doesn't send target until part 4. On current main, the only conflict is in schema.sql.

Follow-ups (please fix before Webflow is turned on):

  1. server/src/lib/cms/webflow.js:151-175: "nothing is published" depends on Composio's tool arguments, which haven't been tried on a live account.

    • If WEBFLOW_CREATE_COLLECTION_ITEM ignores is_draft, Webflow makes the item a non-draft, and the brand's next site publish puts it live.
    • The update passes fieldData where the create passes field_data, so one of them may not be the tool's name.
    • If the update tool sends its own draft default, sending a page again could turn a draft into a non-draft.

    Fixes:

    • Read isDraft back from the create's answer. Treat anything but true as a failed send and log it, so a wrong argument shows on the first send, not at the brand's next publish.
    • Add these to the live test:
      • send a page twice and check that the item is still a draft and has the new text;
      • send a published item again and check that nothing changes on the live site until Webflow publishes;
      • send a page with a long JSON-LD (an FAQ) and check that the PlainText field takes it.
  2. server/src/lib/cms/webflow-delivery.js:22: the item id that content-delivery.js:360-372 keeps when a row was written meanwhile lands on a failed row. That's the case the test covers: a row closed as interrupted. lastItem reads only sent and published rows, so the next send still makes a second item and fails on its slug, which is what the fallback was there to prevent. A Webflow delivery gets an external_id only when its item was made. Drop the status filter, keep external_id is not null, and add a test.

@gkhngyk
gkhngyk merged commit 1525d0d into ansvisor:main Oct 25, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants