Skip to content

feat(cms): send pages to a brand's Framer collection as draft items (#1331) - #1576

Merged
gkhngyk merged 16 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-framer-send
Oct 28, 2026
Merged

gkhngyk merged 16 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-framer-send

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Send to CMS, phase 2 (#1331): Framer, part 2: pages go to the brand's Framer collection as draft items. Server only.

Stacked on #1575 (connect). This PR's own change is its last commit.

Writing an item (lib/cms/framer.js writeItem, one connection per page):

  • First send: a new item, draft: true, so it stays out of the site until someone publishes it in Framer. Framer's addItems doesn't return the new id. So the collection is read again, and the id is the one item holding the page's slug among ids that weren't there before. None, or more than one, fails: "Framer didn't say which item it made."
  • Sending again: updates the item the page's last Framer send made in that collection (target_collection).
    • draft isn't sent, so the item keeps its state.
    • On an item that's already published, the change goes live with the site's next publish, as Webflow's does.
    • An item deleted in Framer, or a switch to another collection, gets a new item.
  • Slug clash: another item holding the page's slug stops the send, with the slug and the collection named (slug_taken). The check runs on both paths.
  • A send that broke halfway: addItems can succeed and the read after it fail (a drop, the 30 s timeout). The item then exists, but its id isn't kept.
    • The read after addItems is tried once more.
    • On the next send, an item holding the slug that is still a draft and has exactly this page's title is taken as this page's own and updated. Without that, the page would be locked by its own item.
    • A draft made by hand in Framer with the same slug and the same title would be taken too. It's said in the code.

What goes (lib/cms/framer-items.js, by the brand's field map):

  • Title → a text field (cut at 256 characters).
  • Page → the formatted text field, as HTML (contentType: 'html'), as Export makes it ready.
    • Tables stay tables: Framer's rich text has them, unlike Webflow's. A first row of header cells becomes the head. colspan and rowspan stay when they're whole numbers from 1 to 1000.
    • Images and other media are left out and counted (changed.images), as for Webflow. Framer takes images as its own assets.
    • Scripts, forms and the like are dropped. An H1 becomes an H2, since the title has its own field.
    • The shared rich-text steps are exported from webflow-items.js and reused. Webflow's output is unchanged, and its tests pass as they were.
  • Meta title and meta description → text fields when mapped. The description falls back to the page's opening words, as for Webflow.
  • JSON-LD → its text field when mapped. An empty string clears it when the page has none, as for Webflow.
  • Slug: Webflow's form (lowercase, accents dropped, dots and _ turned into -), else the title's, else page-<draft id>.

lib/cms/framer-delivery.js sendToFramer follows webflow-delivery.js:

  • The key comes from brand_cms_credentials.
  • A missing key, or Framer refusing it, marks the connection auth_failed (conditional on updated_at) and stops a bulk send, as for WordPress.
  • Other failures fail that page, in our words. Unexpected errors are logged by name only.
  • The result carries:
    • externalId and collectionId;
    • updated;
    • live: the updated item isn't a draft, so the change waits for the site's next publish. That's not WordPress's meaning of live; the web says it per target;
    • changed: { images }.

lib/content-delivery.js:

  • 'framer' joins the targets, with framerFor. Its codes follow Webflow's and WordPress's:
    • framer_not_configured (503);
    • no_framer (409);
    • framer_refused (409);
    • framer_not_ready (409): no collection, or no title or page field.
  • Reserving, the 200-a-day cap, one queued send per page (00295) and bulk sends work as for the other CMSs.

Not here: images (Framer assets), the published check (part 3), and the web (parts 4 and 5).

A busy Framer in a bulk send (TOKEN_SESSION_LIMIT or POOL_EXHAUSTED) fails that page, and the batch goes on, as for Webflow and WordPress. Stopping the batch would save nothing, since its rows are reserved up front, and the pool error is retryable. A short wait and one retry inside sendToFramer could be a small follow-up.

Related issue

Part of #1331 (phase 2, Framer). Stacked on #1575.

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. cd server && npx vitest run src/lib/cms src/lib/content-delivery.test.js
  2. With a real project (gkhngyk), connected and with a collection picked (feat(cms): connect a brand's Framer project for Send to CMS (#1331) #1575): POST /api/content-drafts/send with target: 'framer' for a ready page.
    • A draft item appears in the collection with the page's title, slug and content.
    • Send again: the same item is updated.
    • Publish the item in Framer, send again: still the same item, and the change shows after the next site publish.
    • Worth checking in Framer: that tables arrive as tables, and how the formatted text field shows h2–h6, lists, quotes and code.

Checklist

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

Server only: npm run format, npm run lint and npm test (3,087 tests) pass in server/.

A pre-push review's findings are folded in: the send that broke halfway (read retried, own draft taken back), the new id looked for among new items only, colspan and rowspan, a mixed first row, and the JSON-LD comment. Each new case fails with its fix reverted; I checked that by reverting the new-id filter and the title match one at a time.

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 27, 2026 10:18
…ord and send pages to it as draft posts (ansvisor#1331)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… read when the Library opens and daily (ansvisor#1331)

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

# Conflicts:
#	server/src/lib/content-delivery.test.js
#	supabase/schema.sql
Node 20 is end of life since 2026-04-30, and Framer's official Server API
package (framer-api, for Send to CMS ansvisor#1331) needs Node 22 or later for its
global WebSocket. Node 24 is LTS until April 2028. The Dockerfile, CI's
server job and the server README move to 24; the web job stays on 20.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…#1331)

Framer's official Server API (framer-api, needs Node 22+): a brand's
project connects with an API key made in it, sealed as WordPress's
sign-in is. 00295 adds provider 'framer' (site_id = project id) and the
'framer' delivery target, and reserve_content_deliveries keeps one queued
send per page for it too. Routes check the project, list the user's own
collections with their fields, save the collection and field map (title
to text, page to formatted text, required fields refused as for Webflow)
and disconnect (Framer has no API to revoke a key).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nsvisor#1331)

writeItem adds a draft item (draft: true) or updates the one the page's
last Framer send made in that collection, keeping its state; the new id is
read back by slug among new items, a clashing slug stops the send, and a
draft with the page's slug and title left by a send that broke halfway is
taken back. framer-items.js keeps tables (Framer's rich text has them),
leaves media out and counts it, and maps title, page, meta and JSON-LD to
the brand's fields. content-delivery.js gains the 'framer' target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 7 commits October 28, 2026 03:07
… has ended

Since ansvisor#1589 a workspace whose plan has ended can't write, but taking back an
outside account's access stays open (COST_STOPPING), as Webflow's disconnect
does. WordPress's disconnect revokes the Application Password where the site
allows, so it joins the list.

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

Since ansvisor#1589 a workspace whose plan has ended can't write, but taking back an
outside account's access stays open (COST_STOPPING), as Webflow's and
WordPress's disconnects do. Framer's disconnect deletes the project's API
key, so it joins the list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's product blocks (ansvisor#1607) are a grid of linked cards; Framer's formatted
text has no grid, so the cards ran together in one paragraph. They now go as
Webflow's do (productsAsList): a list, a product an item, its name linked and
its price after it.

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

Copy link
Copy Markdown
Collaborator Author

Merged #1575's new head in (1ea6030). webflow-items.js: this PR's helpers stay. Main's product-grid code (#1607) is now an exported productsAsList($), called after tables and before media as on main. In fieldDataFor, jsonLdText does the JSON-LD and #1600's date line follows, as you asked. One fix: Framer's formatted text has no grid, so a product card or grid now goes to Framer as a list ("Name $189.00", the name linked), the same as Webflow, with the same fixture in its test. Checks: typecheck on every web tip, the server suite at #1579 (3,522 tests), and the whole web suite (4,438 tests) and yarn build at #1580.

gkhngyk added a commit that referenced this pull request Oct 28, 2026
* fix(cms): give a Webflow item sent again a date when it has none

Follow-up from #1600 (item 1). Only a new item was given the day it's
sent; an item sent again kept its date. So a brand that maps an optional
date later, or makes its date required in Webflow, kept an empty date on
every item sent before, and a send again left it empty.

When the field map gives a date, sendToWebflow now reads the item before
updating it (getItem, which says which fields hold a value) and, when its
date is empty, sends today's with the update. An item that can't be read
is updated without a date, as before; without a date field nothing is
read.

The Send to CMS guide's field table lists the Date field (#1507's
follow-up) and says an item sent again keeps its date, or gets one.

fieldDataFor (webflow-items.js) is unchanged, so this doesn't meet the
Framer PRs' edit at its end (#1576, #1579).

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

* docs(cms): say which Webflow items are given the day they're sent

Review follow-up. The comment above createItem still said only a new item
is given the day it's sent, but an item sent again with an empty date now
gets it too. It names both now. Comment only; webflow-items.js untouched.

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

* fix(cms): keep a Webflow item's date when the read didn't see its fields

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[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

Reviewed this PR's own change: #1575's head a5e9577 → 1ea6030, 10 server files. It merges clean on main (cfd8a35).

What I checked

  • The send. framerFor refuses before anything is reserved when: there's no key store (503), nothing is connected, the key was refused, or there's no collection with title and body fields. That's the same rule as the web's "ready". The page goes through #1569's reservation (00295 adds 'framer' to the "not twice at once" list), the daily cap and batches, as Webflow's do.
  • Which item is written. The page's last Framer send in this collection is updated while that item is still there, and its draft state stays as it is. A slug held by another item stops the send before anything is written. A draft holding the page's slug and its exact title is taken over as a half-done send, and the docs say so. After addItems, the new item is the single new one with the slug; anything else fails, so no wrong id is kept. Each send is one connection with the 30 s timeout from #1575.
  • The HTML sent. toFramerHtml drops scripts, styles, forms, embeds, iframes, media and comments. Every other element is either on a short allow-list or gives way to its content. Attributes go except a link's href/target and a cell's colspan/rowspan (whole numbers 1–1000 only). JSON-LD has its own text field, with < escaped.
  • Webflow refactor. toWebflowRichText is split into exported steps, in the same order as before. Webflow's item tests pass unchanged, and on adversarial input it times the same as main's.
  • Errors. Framer's refusals use our words. A refused key marks the connection only if it's still the one the send read. Any other error is logged by name and recorded as "Framer could not be reached".
  • Speed. New loops over page text (tables, spans, slug) are linear on 100 KB inputs. Slug: 4 ms. Plain text: 30 ms.
  • Tests: CMS, delivery and send route tests on the stack: 16 files, 275 passed. Full server suite: 3,809 passed. eslint and prettier are clean.

Follow-ups

  1. Reading every item. writeItem reads the whole collection with every item's fields, twice for a new item, to find one item and one slug. That's fine for blogs of a few hundred items, but it grows with the collection. If framer-api can read one item by id (or filter by slug), use that.
  2. "Images aren't sent yet" is in the toast and the docs. Worth one tracking issue so it isn't lost behind CHAT-06.

@gkhngyk
gkhngyk merged commit 6f2e619 into ansvisor:main Oct 28, 2026
4 of 5 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants