Skip to content

feat(cms): connect a brand's Framer project for Send to CMS (#1331) - #1575

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

gkhngyk merged 13 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-framer-server

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Send to CMS, phase 2 (#1331): Framer, part 1: connecting a brand's Framer project, server only.

The user picked a native connector over a workflow guide. Framer now has an official Server API, the framer-api npm package (MIT, published by Framer). With it, pages can go into a project's CMS collection as draft items, as they go to Webflow. Sending comes in part 2.

Stacked on #1570 (WordPress's server parts: the sealed brand_cms_credentials, the CMS target list) and #1574 (Node 24). framer-api needs Node 22 or later, for the global WebSocket. This PR's own change is its last commit.

New dependency: framer-api@^5.1.0 (the user approved it).

  • Its dependencies are devalue and std-env, with csstype as a peer.
  • It connects to one fixed address, wss://api.framer.com/channel/headless-plugin, never to an address a person types.
  • package-lock.json also takes its root version from package.json (0.2.0 → 0.3.0, npm's own fix).
  • server/yarn.lock isn't touched: npm is the server's package manager.

Migration 00295_cms_framer.sql:

  • brand_cms_connections.provider takes 'framer'. A Framer row needs site_id.
  • A Framer connection keeps these columns:
    • site_id: the project's id, the one Framer connects to;
    • site_name: the project's name;
    • site_url: its published address, or null while it isn't published;
    • account: the user the key acts as;
    • collection_id, collection_name and field_map: as Webflow's.
  • The API key is sealed in brand_cms_credentials, as WordPress's sign-in is. The table doesn't change.
  • content_draft_deliveries.target takes 'framer'. reserve_content_deliveries is 00294's with 'framer' added to the CMSs a page isn't queued for twice. Only its list changes, and its grants stay as they were.
  • supabase/schema.sql is rebuilt.

lib/cms/framer.js:

  • projectRef takes the project's address as the editor shows it (https://framer.com/projects/Name--<id>) or its id. It reads the id the way framer-api does. Any other host, http, a port or a malformed id is refused before Framer is called. A ?branch= is left out, so pages go to the main branch.

  • withProject connects, runs one task and always disconnects: on success, on failure, and after a timeout (30 s). A connection that opens after the timeout is closed as it opens. Framer can take up to 15 s to acknowledge a close; the answer waits 5 s at most.

  • Errors. framer-api's codes become ours:

    • UNAUTHORIZED → auth_failed;
    • PROJECT_CLOSED, NODE_NOT_FOUND → not_found;
    • TOKEN_SESSION_LIMIT, POOL_EXHAUSTED → busy;
    • TIMEOUT → unreachable;
    • INVALID_REQUEST → invalid.

    PROJECT_CLOSED that comes after the connection opened, when it dropped mid-call, is unreachable instead.

    Framer's own messages never go out; ours replace them. The key is never in a message, a log or an answer.

  • checkProject reads the project's name, the key's user and the published address. Framer's isAllowedTo exists only for plugins, not on the Server API in 5.1.0. So a key whose user can only view the project can still connect; it's found at the first send.

  • listCollections and collectionOf list the user's own collections (managedBy: 'user'). Each comes with its fields, whether each field is required, and the field its slugs come from. A plugin's collections are read-only.

  • checkFieldMap:

    • a page's title goes to a text field and the page to a formatted text field, both required;
    • meta title, meta description and JSON-LD go to text fields, optional;
    • each part needs a field of its own.

    As for Webflow, a collection with a required field that Send to CMS doesn't always fill is refused, and the error names the field. A required field mapped to JSON-LD counts as unfilled, since some pages have none.

Routes /api/cms/brands/:brandId/framer:

  • GET, for members: { configured, connection }. configured is CONNECTOR_CREDENTIALS_KEY being set, as for WordPress. The connection carries no key.
  • POST { project, apiKey }, for admins and managers: checks the project with the key, then keeps the connection and the sealed key.
    • A new key for the same project keeps the collection and fields. Another project starts over.
    • If sealing the key fails, the row is marked auth_failed.
  • GET /collections: the project's collections and fields, with the saved key. A refused key marks the connection auth_failed; a later success marks it connected again.
  • PUT { collectionId, fieldMap }: checks the map against the collection's fields. A misfit gets 400 invalid_map, with what's wrong. fieldMap takes the five parts only, so another key is 400 invalid. The write is conditional on updated_at: a connection changed meanwhile gets 409 changed.
  • DELETE: removes the connection and its key. revoked: false always, since Framer has no API to revoke a key; the person deletes it in the project's Site Settings.
  • Status codes:
    • invalid 400, no_access 403, not_found 404, busy 429;
    • unreachable and failed 502;
    • auth_failed 409, not 401, since the web reads 401 as an expired session.

.env.example:

  • The CONNECTOR_CREDENTIALS_KEY note names Framer's keys too.
  • A note on FRAMER_API_LOG_LEVEL. framer-api prints to the console itself, past our logger. At its default level (warn), an error Framer sends on an open connection is printed in Framer's words. silent prints nothing. Our answers and logs never carry Framer's messages, and the key isn't in them.

@gkhngyk, two things about framer-api worth knowing:

  • It can write a debug archive. When Framer's server asks for one (a debug-archive message), the package writes debug-archive-<date>.zip into the process's working directory. No client setting turns this off. The write isn't awaited or caught: in a directory it can't write to, it becomes an unhandled rejection, and Node exits (pm2 restarts it). In our image the working directory (/ansvisor-server) is writable. Say if you'd rather have a process-level guard as a separate PR.
  • A short race, as WordPress has. A POST keeps the row before it seals the key. A GET /collections or PUT in that moment reads the old key for the new project, and Framer refuses it. The connection is then marked auth_failed until the next GET /collections succeeds.

Next: part 2 sends pages to the collection as draft items. Then part 3, the published check; part 4, the Settings card; part 5, the Send dialog's target; and part 6, the docs. Plan: draft items through Collection.addItems({ slug, draft: true, fieldData }); the page goes live when the person publishes the site in Framer.

Related issue

Part of #1331 (phase 2, Framer). Stacked on #1570 → #1569, and #1574.

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/framer.test.js src/routes/cms-framer.test.js
  2. With a real project (gkhngyk): make an API key in the project's Site Settings › General. Set CONNECTOR_CREDENTIALS_KEY. As an admin:
    • POST /api/cms/brands/<id>/framer with { "project": "<the project's address>", "apiKey": "<key>" }: the connection comes back with the project's name, the key's user and its published address.
    • GET …/framer/collections: the project's own collections, with their fields.
    • PUT …/framer with a collection and { title, body } field ids saves. A wrong field type is refused with what's wrong.

00295 was run on the dev DB in a rolled-back transaction:

  • a Framer row without site_id is refused, and WordPress's rule is unchanged;
  • the target check takes framer;
  • reserve_content_deliveries has framer, and authenticated still can't run it;
  • a second run goes through.

It isn't applied on dev yet; it will be with the web part.

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,044 tests) pass in server/.
  • bash supabase/build-schema.sh was run.

A pre-push review's findings are folded in:

  • a failed credentials read is a 500, and no longer marks the connection refused;
  • required fields;
  • PROJECT_CLOSED mid-call;
  • fieldMap takes known keys only;
  • the log-level note;
  • tests for the PUT roles and states, the 400 and 502 answers, a connection that opens after the timeout, the published address, name lengths, and ?branch= and -- in a project's name.

After those fixes I ran prettier, lint and the CMS and route tests again: 13 files, 204 tests.

🤖 Generated with Claude Code

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

Copy link
Copy Markdown
Collaborator Author

Merged #1570's new head in (a5e9577), with #1574 already in it. schema.sql was rebuilt. As for WordPress in #1569, the Framer disconnect is now in COST_STOPPING, so an ended workspace can still remove it (test updated). Note: this PR's own commit also moves server/package-lock.json's version line from 0.2.0 to 0.3.0, a side effect of the install that added framer-api. 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 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: its head a5e9577 against #1570's head (da8e326) merged with #1574 (facc453). That's 12 files: framer-api, lib/cms/framer.js, routes/cms-framer.js, the subscription allow-list line, 00295 and the rebuilt schema.sql. It merges clean on main (cfd8a35).

Where it sits. The branch is built on #1570 (which carries #1569) and on #1574. Both are on main now, so this PR lands only Framer's own change. At merge time, main's read-only rules apply to Framer's routes as to WordPress's: reading the connection and its collections stays open, connecting and saving the target are refused once the plan has ended, and disconnecting stays open.

What I checked

  • Where the API connects. Only to wss://api.framer.com/channel/headless-plugin. What a person types is used only as a project id: projectRef takes 20 letters and digits, or a https://framer.com/projects/… address (no other host, no http, no port, no user info), and drops ?branch=. The only way to point the client elsewhere is a server env var (FRAMER_HEADLESS_SERVER_URL), not a request. The published address Framer returns is stored (https only, ≤ 2,048 characters) and never fetched.
  • The key. It's checked with Framer, then sealed with CONNECTOR_CREDENTIALS_KEY through #1569's saveCmsCredentials. shape() never returns it. Failures are logged by error name only, and Framer's own messages are replaced by ours. If sealing fails after the row is kept, the row is marked auth_failed, so a send can't use the previous key on the new project.
  • Who. GET checks the brand is in the caller's organization. POST, GET /collections, PUT and DELETE go through assertWriter (admins and managers) on the server. DELETE is the only Framer route allowed while the plan has ended (COST_STOPPING), as WordPress's is. Another organization's brand id gets 404/403 from assertBrandAccess.
  • Bounded work. Each use opens one connection and always closes it. The whole use has a 30 s timeout, and closing waits at most 5 s. A connection that opens late is closed as it opens. Inputs are capped (project ≤ 2,048, key ≤ 512, ids ≤ 100 printable characters), and fieldMap is .strict(). projectRef's regex is linear, and timed under 1 ms on 2 KB inputs.
  • Field map. checkFieldMap matches the web's rules: title → string, body → formattedText, each field used once, and required fields must take a part that's always filled. JSON-LD doesn't count as filled.
  • Node 20. The production API runs node:20 today. I started src/server.js from this head (and from the whole stack merged) under Node 20.18.1, with placeholder env and no .env. It starts and answers. framer-api imports fine: it only reads globalThis.WebSocket at load, and that's undefined on Node 20. Only a Framer call fails, with a TypeError at connect time: the routes answer 500 failed ("Something went wrong with Framer"), a send fails as "Framer could not be reached", and the daily check logs a warning per brand. Nothing else in the API is affected. The Docker image this stack brings is Node 24, so this only matters for a deploy that keeps Node 20.
  • Tests: server suite on the merged stack, 271 files, 3,809 passed. The Framer test files also pass under Node 20. eslint and prettier are clean.

Follow-ups

  1. Node 20, for self-hosters. A server on Node 20 shows "Something went wrong with Framer" with no reason. A check in withProject (typeof globalThis.WebSocket !== 'function') that answers something like unavailable: "Framer needs Node 22 or later on the API server", plus a line in the card, would explain it. The docs (#1581) already state the requirement.
  2. framer-api's debug archive. As you noted, Framer's server can make the process write a zip into the working directory, and a write that fails is an unhandled rejection that restarts the process. A process-level unhandledRejection log-and-continue, or running from a writable directory only, is worth a small separate PR.
  3. The POST race you described (the row is kept before the key is sealed). An order that seals first, or keeps the row and the key in one RPC, would close it. It's low risk: same brand, and it heals on the next successful read.

@gkhngyk
gkhngyk merged commit 1a556ae into ansvisor:main Oct 28, 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