Repository navigation
feat(cms): connect a brand's Framer project for Send to CMS (#1331) - #1575
Conversation
…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]>
…re/cms-framer-server
…#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]>
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 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]>
…s-published Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-server 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]>
|
Merged #1570's new head in (a5e9577), with #1574 already in it. |
gkhngyk
left a comment
There was a problem hiding this comment.
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:projectReftakes 20 letters and digits, or ahttps://framer.com/projects/…address (no other host, nohttp, 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_KEYthrough #1569'ssaveCmsCredentials.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 markedauth_failed, so a send can't use the previous key on the new project. - Who.
GETchecks the brand is in the caller's organization.POST,GET /collections,PUTandDELETEgo throughassertWriter(admins and managers) on the server.DELETEis the only Framer route allowed while the plan has ended (COST_STOPPING), as WordPress's is. Another organization's brand id gets 404/403 fromassertBrandAccess. - 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
fieldMapis.strict().projectRef's regex is linear, and timed under 1 ms on 2 KB inputs. - Field map.
checkFieldMapmatches 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:20today. I startedsrc/server.jsfrom this head (and from the whole stack merged) under Node 20.18.1, with placeholder env and no.env. It starts and answers.framer-apiimports fine: it only readsglobalThis.WebSocketat load, and that'sundefinedon Node 20. Only a Framer call fails, with aTypeErrorat connect time: the routes answer 500failed("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
- 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 likeunavailable: "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. 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-levelunhandledRejectionlog-and-continue, or running from a writable directory only, is worth a small separate PR.- 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.
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-apinpm 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-apineeds Node 22 or later, for the globalWebSocket. This PR's own change is its last commit.New dependency:
framer-api@^5.1.0(the user approved it).devalueandstd-env, withcsstypeas a peer.wss://api.framer.com/channel/headless-plugin, never to an address a person types.package-lock.jsonalso takes its root version frompackage.json(0.2.0 → 0.3.0, npm's own fix).server/yarn.lockisn't touched: npm is the server's package manager.Migration
00295_cms_framer.sql:brand_cms_connections.providertakes'framer'. A Framer row needssite_id.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_nameandfield_map: as Webflow's.brand_cms_credentials, as WordPress's sign-in is. The table doesn't change.content_draft_deliveries.targettakes'framer'.reserve_content_deliveriesis 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.sqlis rebuilt.lib/cms/framer.js:projectReftakes the project's address as the editor shows it (https://framer.com/projects/Name--<id>) or its id. It reads the id the wayframer-apidoes. 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.withProjectconnects, 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_CLOSEDthat comes after the connection opened, when it dropped mid-call, isunreachableinstead.Framer's own messages never go out; ours replace them. The key is never in a message, a log or an answer.
checkProjectreads the project's name, the key's user and the published address. Framer'sisAllowedToexists 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.listCollectionsandcollectionOflist 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: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 }.configuredisCONNECTOR_CREDENTIALS_KEYbeing 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.auth_failed.GET /collections: the project's collections and fields, with the saved key. A refused key marks the connectionauth_failed; a later success marks it connected again.PUT { collectionId, fieldMap }: checks the map against the collection's fields. A misfit gets400 invalid_map, with what's wrong.fieldMaptakes the five parts only, so another key is400 invalid. The write is conditional onupdated_at: a connection changed meanwhile gets409 changed.DELETE: removes the connection and its key.revoked: falsealways, since Framer has no API to revoke a key; the person deletes it in the project's Site Settings.invalid400,no_access403,not_found404,busy429;unreachableandfailed502;auth_failed409, not 401, since the web reads 401 as an expired session..env.example:CONNECTOR_CREDENTIALS_KEYnote names Framer's keys too.FRAMER_API_LOG_LEVEL.framer-apiprints 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.silentprints nothing. Our answers and logs never carry Framer's messages, and the key isn't in them.@gkhngyk, two things about
framer-apiworth knowing:debug-archivemessage), the package writesdebug-archive-<date>.zipinto 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.POSTkeeps the row before it seals the key. AGET /collectionsorPUTin that moment reads the old key for the new project, and Framer refuses it. The connection is then markedauth_faileduntil the nextGET /collectionssucceeds.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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/cms/framer.test.js src/routes/cms-framer.test.jsCONNECTOR_CREDENTIALS_KEY. As an admin:POST /api/cms/brands/<id>/framerwith{ "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 …/framerwith 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:
site_idis refused, and WordPress's rule is unchanged;framer;reserve_content_deliverieshasframer, andauthenticatedstill can't run it;It isn't applied on dev yet; it will be with the web part.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Server only:
npm run format,npm run lintandnpm test(3,044 tests) pass inserver/.bash supabase/build-schema.shwas run.A pre-push review's findings are folded in:
PROJECT_CLOSEDmid-call;fieldMaptakes known keys only;?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