Skip to content

feat(cms): connect a brand's Wix site with its owner's API key and send pages to its Blog as draft posts (#1331) - #1721

Merged
gkhngyk merged 67 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-wix-connect
Oct 29, 2026
Merged

gkhngyk merged 67 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-wix-connect

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Send to CMS, Wix (#1331 phase 2), server part. After Webflow, WordPress and Framer, a brand connects its Wix site. It gives the site's id (or its dashboard's address) and an API key that the site's owner makes in Wix's API Keys Manager. Pages go to the site's Blog as draft posts. Nothing is published.

  • Migration 00372_cms_wix.sql:
    • brand_cms_connections and content_draft_deliveries.target take wix. A Wix row needs site_id, and account: the member who owns the posts, since Wix's Blog needs an owner.
    • The API key is sealed in brand_cms_credentials, as WordPress's sign-in and Framer's key are.
    • reserve_content_deliveries is 00295's, with wix added to the CMSs a page can't be sent to twice at once.
  • lib/cms/wix.js:
    • Every call sends Authorization: <key> and wix-site-id, to https://www.wixapis.com only, through connectors/http.js (https only, no redirects). The site and post ids are GUID-checked before they go into a header or a path.
    • checkSite checks before anything is kept:
      • the Blog answers;
      • the key may use Wix's Ricos converter, tried on one line, which Wix doesn't keep;
      • there is a member to own the posts: the owner of the newest post, else the site's first member.
      • It also reads the site's name when the key is allowed to.
    • The page's HTML becomes Wix rich content through Wix's converter. It goes in pieces of up to 29,000 characters (Wix's limit is 30,000), and a long block is split at its children.
    • A published post is written as its draft version (UPDATE_PUBLICATION), so the post people read stays as it was until it's published in Wix. A scheduled post is written as a draft.
  • lib/cms/wix-delivery.js:
    • A page updates the post its last Wix send made on that site; otherwise a new draft post is made.
    • The title, meta description and JSON-LD go as the post's SEO tags (< escaped in the JSON-LD).
    • Images stay out (Wix shows only Media Manager images) and are counted.
    • A refused key marks the connection, so Settings asks for a new one.
  • routes/cms-wix.js:
    • GET /api/cms/brands/:id/wix is for any member.
    • POST ({ siteId, apiKey }) and DELETE are for admins and managers only, behind cmsLimiter.
    • The key is never logged or sent back; failures are logged by error name only.
    • Disconnect stays open on a read-only workspace (COST_STOPPING).
  • content-delivery.js sends target wix. Main now has Framer's send (feat(cms): send pages to a brand's Framer collection as draft items (#1331) #1576), so the merge puts Wix beside Framer: the connection, the NATIVE entry, the error codes and their tests. I resolved that conflict by hand.

What follows: the Settings card and the Send target (feature/cms-wix-web), the published check (feature/cms-wix-published), and docs (docs/cms-wix).

Migration: 00372. It is numbered below 00374 (menu access, already on main) and depends only on 00295 (on main). Per the branch's commit, it was applied on the dev DB. schema.sql was rebuilt with bash supabase/build-schema.sh.

Not stacked: #1580, which it was built on, is on main.

Related issue

Part of #1331 (Send to CMS).

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/wix.test.js src/lib/cms/wix-delivery.test.js src/routes/cms-wix.test.js src/lib/content-delivery.test.js src/middleware/subscription.test.js. Wix's answers are faked from its API reference.
  2. With a real Wix site (gkhngyk). Set CONNECTOR_CREDENTIALS_KEY. In Wix, the site's owner makes a key in Account Settings › API Keys Manager with Manage Blog (Wix Blog) and Manage Ricos Document (Ricos), with the site picked. As an admin:
    • POST /api/cms/brands/<id>/wix with { "siteId": "<site id or dashboard address>", "apiKey": "<key>" }: the connection comes back with the site's name. The key isn't in the answer or in the logs.
    • POST /api/content-drafts/send with "target": "wix": a draft post appears on the Blog, with its SEO title, description and JSON-LD, and without images. Send it again: the same post is updated.
    • Publish the post in Wix, then send again: the post's draft version changes, and the live post doesn't until you publish it.
    • A key without the Ricos permission is refused at connect with no_ricos_permission.

For your review: with no post on the Blog, the member who owns the posts is the first one Wix's Members query returns. On a site with a members area, that could be a member who isn't the owner. The person sees the writer on the draft in Wix and can change it there.

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. What ran on this head (after merging main ce9a3dc):

  • npm run lint in server/;
  • Prettier --check on the changed server files;
  • the Wix, content-delivery, subscription, send-route and Framer-delivery tests (7 files, 119 tests);
  • bash supabase/build-schema.sh;
  • the embed-hint scan from fix/ambiguous-embed-guard, on the top of the Wix chain.

The full npm test wasn't run this round. Before main's Framer merges, the branch's full test run passed, except files that timed out under machine load; run alone, those passed.

🤖 Generated with Claude Code

cihan-gyk and others added 30 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
The Send dialog (editor, Library row, bulk) offers the brand's WordPress
site beside Webflow and the webhook. A remembered CMS that isn't ready
goes to the webhook, never the other CMS. The toast says when a live post
got a new draft and when JSON-LD was left out. The Library marks rows sent
to WordPress and asks /wordpress-status once per brand per visit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
…ons (ansvisor#1331)

The Framer card connects the brand's project with an API key made in it,
lists the project's own collections with their fields, suggests and saves
which field takes the title, the page, meta and JSON-LD (required fields
it can't fill and missing title or page fields marked), replaces the key,
shows a refused key, and disconnects with a reminder to delete the key in
Framer, which has no API to revoke it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Send dialog (editor, Library row, bulk) offers the brand's Framer
collection beside Webflow, WordPress and the webhook, in a 2x2 grid when
all four are there. Framer is ready with a collection and its title and
page fields; a remembered CMS that isn't ready goes to the webhook. The
toast says made or updated, images left out, and that a non-draft item's
change waits for the site's next publish. The Library marks rows sent to
Framer and asks /framer-status once per brand per visit.

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]>
… 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]>
…nd pages to its Blog as draft posts (ansvisor#1331)

Send to CMS, Wix (phase 2), server. After Webflow, WordPress and Framer, a
brand connects its Wix site: the site's id (or its dashboard's address) and
an API key its owner makes in Wix's API Keys Manager with the Wix Blog
permissions. Pages go to the site's Blog as draft posts; nothing publishes.

- 00372: brand_cms_connections and content_draft_deliveries take 'wix'
  (site_id and the posts' owner member in `account`); the key is sealed in
  brand_cms_credentials as WordPress's sign-in is; reserve_content_deliveries
  keeps a page from being sent to Wix twice at once. Applied on the dev DB.
- lib/cms/wix.js: Authorization: <key> with wix-site-id; checkSite (the
  Blog answers, a member owns the posts: its newest post's, else its first
  member; the site's name when the key may read it); the page's HTML
  turned into Wix's rich content by Wix's converter in pieces of 10,000
  characters; draft posts created, read and updated, a live post as its
  draft version (UPDATE_PUBLICATION), never the post people read.
- lib/cms/wix-delivery.js: a page updates the post its last send made on
  that site, else makes one; title, meta description and JSON-LD go as the
  post's SEO tags; images stay out and are counted; a refused key marks the
  connection for a new one.
- routes/cms-wix.js: GET / POST { siteId, apiKey } / DELETE, admins and
  managers to write; the key is never logged or sent back. Disconnecting
  works after a plan ends. content-delivery.js sends target 'wix'.

Real Wix keys are tried by the maintainer; tests run against a fake of the
API (its answers as Wix's reference shows them).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/src/components/content/send-to-cms-dialog.tsx
Main now has Framer's send (ansvisor#1576) and published check (ansvisor#1579): Wix is
added beside Framer as a delivery target in content-delivery.js (its
connection, the NATIVE entry, the codes) and in its tests.
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (conflict in supabase/schema.sql only, regenerated with build-schema.sh; 00372 doesn't collide with main's migrations). The Wix server tests and the subscription middleware test pass; server lint clean. This PR changes no web files (its web/ is main's), so typecheck is main's.

@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

At merge time: main's demo brand guard now covers Wix's connect and disconnect routes (DEMO_GUARDED), like WordPress and Framer.

Reviewed this PR's own change (main → 22a2176), read as merged on main 3b7611c. It merges on main with one conflict, in supabase/schema.sql only (regenerated with build-schema.sh; nothing else to resolve). The Wix stack is this PR → #1749 (Settings card and Send target) → #1750 (published check), each containing the one before; #1722 (docs) sits apart on the docs chain. No PR in the set supersedes another, and none should be closed.

What I checked

  • Outbound requests. Every call goes to the fixed https://www.wixapis.com through the connectors' client (connectors/http.js): https only, no redirect followed, 30 s per attempt, a body cap, and a POST never sent twice. Nothing the person types becomes a host. The site id is taken out of what they paste as a GUID only, and post ids are GUID-checked before they go into a path; the member id kept at connect is GUID-checked too.
  • The API key. Checked with Wix first (Blog read, one converter call that Wix doesn't keep, a member to own the posts), then sealed under CONNECTOR_CREDENTIALS_KEY in brand_cms_credentials, bound to the connection, as WordPress's and Framer's are. The GET answer (shape) never carries it, errors are logged by name only, and nothing the API sends back quotes it. If sealing fails after the row is written, the row is marked refused, so a send can't use an older key on the new site.
  • Who can do what. Connect and disconnect go through assertWriter (admins and managers of the brand's organization) on the server; the GET is assertBrandAccess. Every query runs on the brand id after that check, so another organization's connection can't be read or changed. Connect sits behind cmsLimiter.
  • Read-only workspace. Connect is refused with the 402 body (not in COST_STOPPING); disconnect is open there, as WordPress's and Framer's are, and subscription.test.js covers it. subscription-guard-coverage.test.ts passes on the stack merged with main.
  • Sending. wixFor refuses a refused key before anything is reserved. A refused key during a send marks only the connection the send read (updated_at match), so one connected again meanwhile keeps its new key. A page updates the post its last Wix send made on the same site; a published post gets its draft version written (UPDATE_PUBLICATION), so the live post doesn't change. Scripts are taken out before the converter; JSON-LD goes as an SEO tag with every < escaped. Images are left out and counted.
  • Wiring. Matches WordPress/Framer: the NATIVE entry, DELIVERY_TARGETS, the error codes, the router, .env.example.
  • Migration 00372 read in full (notes below).
  • Embeds: none added in this part.
  • Tests: full server suite on the stack merged with main (#1750's tip + main): 298 files, 4,164 passed; one known timing test (content-people) failed under load and passes alone. eslint and prettier are clean on every touched file.

Migration 00372

  • The number is free: main has 00371 and 00373–00376, and no open PR uses 00372.
  • It differs from 00295 only by adding wix: to the provider check, to provider_fields (a Wix row needs site_id and account), to the delivery target check, and to the CMSs that reserve_content_deliveries refuses to send a page to twice at once. It also updates the comments.
  • reserve_content_deliveries keeps its signature, security definer with search_path = public, and execute for service_role only.
  • Nothing later on main redefines these objects, so applying it after 00379/00400–00404 is fine.
  • Re-adding the two check constraints scans brand_cms_connections and content_draft_deliveries once, under a short exclusive lock. Both tables are small. It is idempotent (drop constraint if exists, create or replace).

Before merging

  • Order: apply 00372, deploy the API, then merge the web parts (#1749, #1750). Without the migration, a Wix connect fails at the row's check (500) and a send to Wix fails at the reserve. Without this API, the web's Wix card says it can't read the connection, and the Send dialog leaves Wix out.
  • CONNECTOR_CREDENTIALS_KEY must be set on the API (it already is wherever WordPress works).

Follow-ups

  1. nodePieces builds each piece's empty tag with $(node).clone().empty(), which copies the whole block before emptying it. On a deeply nested page that makes the split work grow with size × depth, and on a very deep one it runs out of stack (the send then fails with "Wix could not be reached"). A shallow copy (node.cloneNode(false)) gives the same tag without the copy.
  2. A long page goes to Wix's converter in up to ~35 calls, one after another, and none is retried. One 429 in the middle fails the page. A short wait-and-retry on 429 for the converter, or one call per page where it fits, would make long pages more reliable.
  3. The member who owns new posts is the author of the newest published post, else the first member Wix returns (as the description says). On a site with a members area, that can be someone other than the owner. Worth a line in the card after connect ("Posts are written as …").

@gkhngyk
gkhngyk merged commit 24aed35 into ansvisor:main Oct 29, 2026
3 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