Skip to content

feat(content): connect a brand's Webflow site for Send to CMS (Send to CMS #1331, phase 2 part 1: Webflow connection) - #1503

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

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-webflow-connect

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

#1331, phase 2 (native connectors), part 1: connecting a brand's Webflow site. Webflow goes first because www.ansvisor.com runs on it. This PR is server only. It adds the connection and where pages go, not the sending, which is the next PR.

It follows the route planned on #1331: Composio with API-key auth. Webflow has no Composio-managed OAuth app, so a brand pastes a Webflow site token.

Connection (00283, brand_cms_connections)

  • One row per brand and CMS. A site token covers one site, so the connection belongs to the brand, not the workspace (unlike Search Console's).
  • The token never touches our tables. Composio keeps it as an API-key connected account under the brand's own Composio user (brand_<id>). We keep the account id, as integration_connections does for GSC.
  • What's stored:
    • the site and the collection pages go to;
    • field_map, which says which collection field takes each part of a page (body → a RichText field; metaTitle, metaDescription and jsonLd → PlainText fields). An item's name and slug always go to Webflow's own name and slug.
  • status is auth_failed when Webflow refuses the saved token.
  • Who can do what: members read their brands' rows through RLS. Only the service role writes; the API checks for admins and managers.

Routes (/api/cms/brands/:brandId/webflow, rate-limited with cmsLimiter):

  • GET: the connection, for any member (Settings and the Send dialog). Composio's ids are never sent.
  • POST { token }: connect, or replace the token. Admins and managers only.
    • Webflow is asked for the token's sites first. A token it refuses, or one that reaches no site, is removed from Composio again and never saved.
    • A new token for the same site keeps the collection and field map. A token for another site starts over.
    • A new token is a second Composio account until the first goes (initiate refuses a second active account without allowMultiple). So it's connected with allowMultiple, and once it's saved, the brand's other Webflow accounts are removed: the replaced token's and any a failed removal left.
  • GET /collections?siteId=: the site's collections.
  • GET /collections/:collectionId?siteId=: the collection's editable fields, plus a suggested map read from field slugs and names (post-body, post-summary, seo-title, meta-description, schema…). It answers only for a collection on a site the token reaches.
  • PUT { siteId?, collectionId, fieldMap }: saves where pages go. It's checked against Webflow:
    • the site must be one the token reaches, and the collection must be on that site;
    • each part must go to a field of the right type, one field per part, and a body field is required;
    • every field the collection requires has to be one Send to CMS always fills (body, meta title, meta description; a page's meta description falls back to its opening words in part 2). The JSON-LD field can't be required, since a page may have none. Otherwise, creating an item would fail at send time.
    • The save is tied to the account the request read. If the token was replaced meanwhile, nothing is written and the answer is changed.
  • DELETE: removes the brand's Webflow accounts at Composio, then the row.
    • If Composio can't let go of the token, the row stays and the answer is 502, so a disconnect that didn't happen isn't shown as one.
    • On a server without Webflow set up, the row just goes.
  • Status: auth_failed is set only for a 401 or a Composio account that's gone. It marks only the token that got the refusal. A later successful read sets the connection back to connected.

Errors come back with a code the web names to the person: not_configured, invalid, forbidden, not_in_workspace, not_found, not_connected, auth_failed, missing_scopes (the token needs Sites read and CMS read/write), no_access (a 403: a site or collection the token doesn't reach; the status isn't changed), no_site, invalid_map (with problems), changed and failed.

  • Webflow's own error text is read to pick the code, but it is never shown or logged, since it may quote the request.
  • Failures are logged by error name only.

Composio (lib/composio.js) adds four functions. Webflow is kept out of PROVIDERS, whose shared connect flow is the workspace's OAuth.

  • isWebflowConfigured.
  • connectWebflowToken: connectedAccounts.initiate with AuthScheme.APIKey and allowMultiple. initiate still serves non-OAuth schemes after the 2026 link() change.
  • forgetWebflowAccounts.
  • executeWebflowTool: runs on the brand's own connected account, with toolkit version 20260826_00.

composio.test.js covers them with a mocked SDK.

Webflow (lib/cms/webflow.js): listSites, listCollections, getCollection, suggestFieldMap and checkFieldMap. They read Composio's answer whether it's wrapped or bare.

What's yours (needs a key)

  1. Create a Composio auth config for the Webflow toolkit with API key auth. Set COMPOSIO_WEBFLOW_AUTH_CONFIG_ID on the API; see server/.env.example. Without it, everything answers not_configured and phase 1 works as before.

  2. Run a real test with a site token (scopes: Sites read, CMS read and write), on ansvisor.com's site if you like:

    • connect;
    • list the collections;
    • check that the suggested map for the blog collection reads right;
    • connect a second token, then check in Composio that only one account is left.

    These come from Composio's Webflow docs and haven't been tried against a live account: the connection field api_key, and the tool argument names site_id and collection_id.

  3. feat(catalog): connect a store with its own sign-in, kept encrypted by the API, with a connector harness and CONNECTORS.md (00282, #1263 part 3) #1501 adds an encrypted connector credential store. If you'd rather keep the site token there and call Webflow's Data API directly than use Composio, the Webflow calls are all in lib/cms/webflow.js, so that's a one-file swap. Say which you prefer before part 2 lands.

Next in the stack

  • Part 2 (server): send to Webflow.
    • Package → fields.
    • Rich text cleaned for Webflow: tables as lists; no images until CHAT-06.
    • Create the item as a draft, or update it in place by its external_id.
    • Same 200 a day and 25 per send. content_draft_deliveries.target.
  • Part 3 (web): the Webflow card in Settings › Integrations: token, collection and field map.
  • Part 4 (web): the destination in the Send dialog (editor, Library row, bulk).
  • Part 5 (docs).

Deploy order

  1. Apply 00283, then deploy the API. Without the table, the GET route fails.
  2. Nothing reads the table until part 3, and nothing changes for phase 1.
  3. The Composio API key needs tool-execution permission, as it does for Search Console.

Related issue

Part of #1331 (phase 2, Webflow).

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/routes/cms.test.js src/lib/cms/webflow.test.js.
  2. Apply 00283 on a dev database. As a member, GET /api/cms/brands/<brand>/webflow gives { configured: false, connection: null } without the env var.
  3. With the env var and a Composio API key:
    • POST a site token: you get back the site and collectionId: null;
    • GET .../collections, then GET .../collections/<id>: you get the fields and a suggested map;
    • PUT the map: the connection now shows the collection. A wrong type returns invalid_map with problems;
    • DELETE: the row is gone, and the connected account is gone in Composio.

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 second-account refusal, three races and the 403 reading. Its fixes are the last commit.

Server: npm run format, npm run lint and npm test (2,622 passed) pass. bash supabase/build-schema.sh was run. 00283 is applied on the dev database. npm run version:check reports the compose images at 0.2.0, as it does on main.

🤖 Generated with Claude Code

cihan-gyk and others added 2 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]>

@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:

  • 00283's table and grants.
    • RLS is on. anon and authenticated lose the default grants, authenticated gets select back, and service_role writes.
    • The one policy lets a member read the rows of their own workspace's brands, as integration_connections (00045) does. With no write policy, only the server writes.
    • Members can read the Composio account and user ids through it, as they can on integration_connections. They're of no use without the server's Composio key.
    • if not exists and drop policy if exists make it safe to run again. schema.sql is the build script's output.
  • Who can call what.
    • Every route checks that the brand is in the caller's workspace (assertBrandAccess) before it reads by brand id.
    • Reading the connection is open to any member. Connecting, listing collections and fields, saving the map and disconnecting are for admins and managers only.
    • The brand id must be a guid, and site and collection ids must match [A-Za-z0-9_-]{1,100}, before any of them reaches a Composio tool.
    • Every call that reaches Composio is behind cmsLimiter (60 per user per 15 minutes).
  • The token's path.
    • The token arrives once in the POST body and goes straight to connectedAccounts.initiate. It isn't written to our tables, sent back or logged.
    • Composio and Webflow failures are logged by error name only. Their text is read to pick a code (run()), then dropped, and the answer is in our own words.
    • No answer carries Composio's ids, and the request logger doesn't log bodies.
  • One Composio account per brand.
    • The account is made under the brand's own Composio user (brand_<id>, apart from Search Console's org_<id>). Only the server keeps its id, on the brand's row. Every tool call runs with that row's user and account.
    • A token Webflow refuses, or one that reaches no site, is removed again and never saved. Once a new token is saved, the brand's other Webflow accounts are removed.
    • Disconnect removes the accounts at Composio before the row. If Composio can't remove them, the row stays and the answer is 502.
  • A refused token.
    • Only a 401 or an account that's gone sets auth_failed, and only on the account the refusal came back for.
    • A 403 (a site or collection the token doesn't reach) leaves the status alone. A later read that works sets it back to connected.
  • The map.
    • The site must be one the token reaches, and the collection must be on it.
    • Each part must go to a field of the right type, and the collection must require nothing that Send to CMS doesn't fill.
    • The map is written only while the row still has the account it was checked with.
  • Without the setting.
    • Without COMPOSIO_WEBFLOW_AUTH_CONFIG_ID, reading the connection answers configured: false and every other route answers not_configured.
    • Nothing else reads the table, and phase 1 is untouched.
  • Merge. It merges on current main with a conflict only in schema.sql.

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

  1. server/src/lib/brand-delete.js:36-47: deleting a brand removes its brand_cms_connections row through the cascade. Its Webflow account stays at Composio, though, holding a site token that can write to the brand's CMS, under a Composio user nothing points to anymore. In run(), remove the brand's Webflow accounts before the brand row goes: call forgetWebflowAccounts(`brand_${brandId}`) when isWebflowConfigured(), best effort, and log a failure by name. Add a test.
  2. server/src/lib/composio.js:294-301: forgetWebflowAccounts deletes every account the list returns and relies on Composio's userIds filter alone. Check that each account's user is entityId before deleting it, and skip it otherwise. Then a filter the API ever ignores can't remove another brand's token.

@gkhngyk
gkhngyk merged commit d4bbb21 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