Repository navigation
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
Conversation
…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
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups to fix before it's turned on.
What I checked:
- 00284.
targetdefaults towebhook, so every existing row reads as a webhook delivery. Both new columns have their checks, and the table is small.reserve_content_deliveriesis 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 definerwithsearch_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
targetis an enum that defaults towebhook. - 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
erroris our own text, andresponse_excerptandhttp_statusstay 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.
- Only the refused account is marked
- 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.
lastItemreads 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'shrefandtarget. - Every
<in the JSON-LD is escaped.
- The HTML is cleaned twice: first by
- 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 sendtargetuntil part 4. On current main, the only conflict is inschema.sql.
Follow-ups (please fix before Webflow is turned on):
-
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_ITEMignoresis_draft, Webflow makes the item a non-draft, and the brand's next site publish puts it live. - The update passes
fieldDatawhere the create passesfield_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
isDraftback from the create's answer. Treat anything buttrueas 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.
- If
-
server/src/lib/cms/webflow-delivery.js:22: the item id thatcontent-delivery.js:360-372keeps when a row was written meanwhile lands on afailedrow. That's the case the test covers: a row closed as interrupted.lastItemreads onlysentandpublishedrows, 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 anexternal_idonly when its item was made. Drop the status filter, keepexternal_id is not null, and add a test.
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/sendtakestarget'webhook'is the default, so phase 1 and its callers are unchanged.'webflow', each page goes to the brand's Webflow collection as a draft item, throughlib/cms/webflow-delivery.js.reserve_content_deliveries);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
external_idon the delivery, withtarget_collection.not_found), a new draft item is made. Any other refusal of the update fails the send, and no second item is made.<is escaped. It's empty when the page has none, so a page sent again loses what it dropped.ç→c). A slug in another script falls back topage-<draft id>, the same on every send.lib/cms/webflow-items.js) keeps what Webflow's rich text keeps:hrefandtarget.updated,changed), for part 4's dialog.auth_failedmarks the connectionauth_failed(only the account that was refused), and a batch stops there, closing the remaining pages with the reason.00284
content_draft_deliveries.target('webhook' | 'webflow', default'webhook') andtarget_collection.reserve_content_deliveriestakesp_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.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).content_draft_deliveries, under its lock. The table is small (a few rows on prod).webhook;p_target => 'webflow'→webflow;delivery_in_progress;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 intosendToWebhooksand a shared write. The webhook path writes the same fields, error text and callback-first answer as before. Its tests are unchanged except the newp_target: 'webhook'argument.Related issue
Part of #1331 (phase 2, Webflow). Stacked on #1503.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
server/, runnpx 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.POST /api/content-drafts/sendwith{ brandId, target: 'webflow', pages: [...] }as the editor sends them;updated: true), and no second item appears;Deploy order
p_targetwithout 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.targetuntil part 4.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no web changeyarn typecheckpasses (run fromweb/): no web changeyarn format:checkpasses (run fromweb/): no web changeA 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 lintandnpm test(2,646 passed) pass.bash supabase/build-schema.shwas run. 00284 is applied on the dev database.🤖 Generated with Claude Code