Skip to content

feat(content): mark a page Published at its live address from the API (CE-013, part 1: server) - #1510

Merged
gkhngyk merged 24 commits into
ansvisor:mainfrom
cihan-gyk:feature/ce-013-publish
Oct 25, 2026
Merged

gkhngyk merged 24 commits into
ansvisor:mainfrom
cihan-gyk:feature/ce-013-publish

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

CE-013 "Published state with live URL and citation tracking", part 1: server. The spec (§6, item 22) reads: "Published (user gives the live URL; tracking starts)"; §15, item 68: "publishing starts its impact measurement".

Where it sits: stacked on #1509, because it shares lib/content-published.js with Send to CMS's published paths. Merge the #1503–#1509 chain first. Part 2 (web: the Mark published dialog, and the Live page tab measuring the address) follows. No migration.

Today: the Library's status menu flips status to published with no address. The editor's Published button is disabled. The Live page tab measures only an optimized page's source_url, so a created page is never measured.

POST /api/content-drafts/:draftId/publish { url }

  • Who: any member of the brand's workspace, as the status menu allows. Access is checked on the draft's own brand.
  • Refused: an archived or missing page answers 404, and an address that isn't http(s), or that carries sign-in details, answers 400 invalid_url. liveAddress is shared with the webhook callback.
  • What it does: sets status: published, published_url and published_at (the server's columns, 00262), and keeps a "publish" version in History (00215).
  • Answer: { publishedUrl, publishedAt, taskCompleted, onBrandDomain }. An address off the brand's domains is kept, but its numbers can't be read, so the web says so.

A linked action, the same whether a person publishes the page or a CMS does (webhook callback, Webflow check):

  • Measured: the live address joins what the action is measured on, in payload.publishedPages (keyed by draft), which basketScope reads beside payload.pages, once each. This is the measurement from-content-draft.js points to ("a new page has its address only then").
    • payload.pages stays the list of pages the action works through, so the drawer's "Pages to optimize" and Ready's check of them are unchanged.
    • Only an address on the brand's domains is measured.
    • A page published again moves to its new address.
    • The payload is written only if it's unchanged since it was read; if another write landed first, it's read again.
  • The Publish task (publish_content) is completed once all of the action's work is live, mirroring how Ready completes its tasks:
    • a Create task needs a published create draft;
    • an Optimize or Refresh task needs a published optimize draft for each page it names;
    • archived drafts don't count.
    • Only open tasks (todo, in progress) are completed, and skip_reason is cleared; a task someone skipped stays skipped.
    • The completion goes into the action's History (action_events, task_status, with the address).
  • Measurement start: the action's own measurement still starts when a person closes it (completed_at), as validate.js does today.
  • Errors: if the action's part fails, the page stays published and the failure is logged.

Related issue

Content Editor spec (Drive), CE-013. Builds on #1331's published paths (#1509).

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/lib/content-published.test.js src/routes/content-drafts-publish.test.js src/routes/webhook-content-draft-callback.test.js src/lib/action-center/basket-metrics.test.js. The publish tests run on in-memory tables whose filters apply.
  2. On a dev database, use a draft linked to an action (Start → Team):
    • POST /api/content-drafts/<id>/publish with { "url": "https://<brand domain>/blog/x" };
    • the draft is Published with the address, and History has a "Published" version;
    • the action's payload has publishedPages, and its Publish task is completed, with an entry in its History;
    • post an address on another domain: onBrandDomain: false, and it leaves publishedPages.

Deploy order

After #1503–#1509, then the API. Nothing calls this route until part 2.

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 these. Their fixes are the last commit:

  • the live address written into payload.pages, which would have shown a phantom page to optimize and blocked Ready;
  • Publish completed before the action's other pages had drafts;
  • skipped tasks overwritten;
  • the payload race;
  • a failed action step reported as a failed publish;
  • CMS publishes not reaching the action.

Server: npm run format, npm run lint and npm test (2,670 passed) pass.

🤖 Generated with Claude Code

cihan-gyk and others added 11 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]>
…ction as draft items (Send to CMS ansvisor#1331, phase 2 part 2: Webflow send)

POST /api/content-drafts/send takes target 'webflow': each page becomes a
draft item in the brand's collection (00283) by its field map, or updates
the item its last send made there (a new one when it was deleted in
Webflow). Webflow's rich text has no tables, so a table goes as a list;
images wait for workspace files (CHAT-06); the meta description falls back
to the page's opening words; JSON-LD goes as its JSON to its own field.
The same 200 a day, 25 per send and pause apply. 00284 adds the
delivery's target and the item's collection, and reserve_content_deliveries
takes the target ('webhook' by default, so the earlier API still works).
A token Webflow refuses marks the connection auth_failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as they are (pre-push review)

- A table cell keeps its paragraphs, items and lines a space apart, and
  its links; a table a figure wraps is kept, a table in a cell read once;
  words or items outside a block become paragraphs; comments go; a
  picture counts as one image.
- A slug with nothing Latin left falls back to the draft's id, the same on
  every send, not the delivery's.
- 00284: a second Webflow send of a page while one is queued is refused
  under the cap's lock (in_progress), so two sends can't make two items.
- The item's id is kept even when the delivery's row was written meanwhile.
- A batch stops once Webflow refuses the token, closing the rest.
- The webhook callback answers only for webhook deliveries.
- An emptied JSON-LD field clears the item's old one; every "<" in it is
  escaped; the opening words stay within 160 characters.
- A taken slug says what to do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… in Settings › Integrations (Send to CMS ansvisor#1331, phase 2 part 3: Webflow card)

A Webflow card under the product catalog: admins and managers paste the
brand's site token (sent from the browser to the API's proxy once, never
through a server action), pick the site and collection pages go to, and
which field takes the page content, meta title, meta description and
JSON-LD (the collection's suggested map first), replace the token and
disconnect; members see where pages go. A refused token asks for a new
one; a connection changed meanwhile is read again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…CMS (Send to CMS ansvisor#1331, phase 2 part 4: send target)

Once Settings has the brand's Webflow collection ready, the editor's and
the Library's Send dialogs offer where pages go: Webflow (a draft item in
the collection, the first choice) or the workflow's webhook, remembered
per brand in this browser. A Webflow send says whether the item was made
or updated and what Webflow's rich text couldn't keep (tables as lists,
images not yet); its refusals are named; the Library marks a page sent
there as a draft item in Webflow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ow isn't ready (pre-push review)

- A brand's Webflow that can't be read holds the send, with Try again,
  instead of reading as no Webflow and sending to the webhook.
- Webflow connected but not ready (its token refused, no collection) shows
  in the picker, off, with what to do; the webhook is then picked in view.
- The description is neutral until the target is read.
- The bulk dialog clears a refusal when the target changes, and says a
  page (not "this page") is already on its way to Webflow.
- A collection without a name reads as "your collection".
- Tests: a send held while reading, a failed read and Try again, the
  remembered choice read back, not-ready Webflow, the last send's line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… there (Send to CMS ansvisor#1331, phase 2 part 6: Webflow published)

Nothing calls back when a Webflow item goes live, so the API reads the
items its sends made: each page's latest send to Webflow not seen live yet
(up to 25 a brand, the last 60 days), and marks a live one published at
its address on the site (its custom domain or webflow.io host, the
collection's slug and the item's). The Library asks once as it opens for a
brand with pages in Webflow (any member, a brand at most every two
minutes), and a daily sweep reads every connected brand. Marking a page
published is shared with the webhook's callback (content-published.js).
A token refused while reading marks the connection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed it after the send (pre-push review)

- A live page sent again stays sent until Webflow publishes it again: the
  item counts only when its lastPublished is at or after the send.
- An item deleted in Webflow closes its send (Removed in Webflow), so the
  page's next send makes a new item and the check stops reading it.
- One item's failure doesn't stop the check; three in a row do.
- The Library reads a brand's 10 newest sends; the daily sweep reads up to
  100 a brand, its brands shuffled so the deadline leaves out others daily.
- A site's host is the custom domain published to last, else webflow.io.
- An item wrapped as { item } is read; logs carry the error's code.
- The Library's reload isn't lost when its filter changes meanwhile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… (CE-013, part 1: server)

POST /api/content-drafts/:draftId/publish { url } lets any member of the
brand's workspace mark a page Published at the http(s) address it's live
at: the draft gets published_url / published_at (the server's columns)
and a "publish" version in History, and a linked action gets the live page
to be measured on and, once every page it names is live, its Publish task
done. The answer says whether the address is on the brand's domains. The
CMS paths and this share markDraftPublished and liveAddress.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Publish only when all its work is live (pre-push review)

- The live address goes to payload.publishedPages (by draft), read beside
  payload.pages by basketScope, so the pages an action works through (and
  Ready's check of them) stay as they were; only an address on the brand's
  domains is measured, and a page published again moves.
- Publish is done once the action's work is live: a published create draft
  for a Create task, a published optimize draft for each page an Optimize
  or Refresh task names; archived drafts don't count.
- Only open tasks (todo, in progress) are completed, skip_reason cleared;
  a skipped one stays.
- The payload is written only as read, read again when another write
  landed first.
- The page stays published when the action's part fails (logged), and a
  page its CMS published tells its action too (markDraftPublished).
- Tests run on tables whose filters apply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 25, 2026

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

What I checked:

  • Who can call it. It sits behind the API's sign-in and its general limiter. The draft is read by id, and access is checked on the draft's own brand, so another workspace's draft answers 403 and a missing or archived one answers 404 (both tested). Any member can call it. That matches the Library's status menu and what members can already change on drafts, actions and tasks, so no role gains anything. published_url is still written only by the server (00262).
  • Addresses. It takes http(s) only, with no user or password, up to 2,048 characters. liveAddress is now shared with the webhook callback. Nothing fetches the address: it's stored, its host is matched against the brand's domains for the action (onBrandDomain), and it's shown as a link. So there's no SSRF path. If part 2's Live page tab ever fetches it, that should go through safe-fetch.
  • What it changes. On the draft: published, the address and the time, plus a "publish" version in History (content_draft_snapshot skips it when History's latest version is already this page). On a linked action of the same brand that isn't deleted:
    • payload.publishedPages[draftId], only for an address on the brand's domains. It moves when the page is published again and is dropped when the new address is off the domains. It's written only if updated_at hasn't changed since the read, and tried again otherwise.
    • Open Publish tasks are completed, skip_reason is cleared, and each gets an action_events entry. Skipped tasks stay skipped.
    • If the action's part fails, that's logged, and the page stays published.
  • What it starts. Nothing runs in the background, and no trigger reacts to a completed task. The action's measurement still starts only when a person closes it. basketScope reads the live page in both windows, with each page counted once, so before and after stay comparable. payload.pages is untouched, so the drawer and Ready's checks are unchanged. generate.js never rewrites a payload, so publishedPages stays.
  • CMS paths. The webhook callback (live today) and the Webflow check go through the same markDraftPublished. So a workflow's publish now completes a linked action's Publish task too, and the callback answers as before when the action's part fails.

Low, follow-up (part 2 is a fine time):

  1. server/src/lib/content-published.js:136-152: workPublished reads drafts, not tasks. That gets two cases wrong:
    • A page published without Mark ready completes Publish while the action's Create or Optimize task stays open, even though Publish depends on them. That happens when the page is sent straight to a CMS, or marked published at an address. Fix: complete the page's own task too, as Mark ready does (by the draft's method), or leave Publish open until those tasks are done.
    • A Create or Optimize task someone skipped still needs its draft to be live, so Publish never completes on its own. Fix: count only the work whose task isn't skipped.
  2. web/src/lib/actions/content-drafts.ts:1498-1499: moving a published page back to Draft or In review reopens only the tasks Ready completed. The Publish task this route completed stays done, and publishedPages keeps the address, so the action goes on measuring a page the person took back. Fix: reopen the Publish task whose latest event names the draft, as reopenDraftTasks reads events, and drop the draft's publishedPages entry.

cihan-gyk and others added 12 commits October 25, 2026 19:40
…-settings

# Conflicts:
#	server/.env.example
#	supabase/schema.sql
…sed parts by their labels, tell members a refused token stops sends (review)

- A saved part whose field was deleted or changed type in Webflow is left
  out when the fields arrive, so what's saved is what the pickers show.
- The API's problems name a part by its label ("Meta title: …"), in a
  list read out as an alert; the token hint describes its field.
- With the token refused, a member reads that pages can't go to Webflow
  until an admin or manager pastes a new one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_webhook for a Webflow not ready, and move between targets with the arrow keys (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ebflow, in case it wasn't (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, and don't hold Publish for skipped work (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… so, and keep Try again off while sending (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ction's pages as the web does (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 25, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Thanks. Both are fixed: the server part here (7e29233), the unpublish part in #1511 (093a2d2). #1509's new head is merged in (dbe2d82, no conflicts).

  1. workPublished reads tasks now (content-published.js):
    • A page published without Mark ready completes its own task, as Mark ready does (ownTasks, the web's completeDraftTasks rule). That's Create for a create draft, Optimize or Refresh for an optimize draft. For an action naming several pages, that waits until each page has a ready or published draft. Each change names the draft ({ taskId, to: 'completed', draftId }), so taking the page back reopens it through reopenDraftTasks. This runs for every path through markDraftPublished: Mark published, the webhook callback and the Webflow check.
    • Skipped work isn't waited for: a Create or Optimize task someone skipped no longer holds Publish.
    • Tasks are completed only if their status is still what was read, and only one actually changed gets a History entry and counts, so a task skipped in the drawer meanwhile stays skipped with no false "completed" (be57be3, from a pre-push review). actions.updated_at is bumped once, after the writes.
    • payload.pages is read as the web's actionPages reads it (http(s) addresses, once each), so a stray entry can't hold Publish forever.
    • Tests: own task + Publish in one go; a multi-page Optimize (the work is done once each page has a ready draft, and Publish waits until both are live); skipped Create; a task changed meanwhile.
  2. Moving a published page back to Draft or In review is done in feat(content): ask where a page is live when it's marked published, and measure it there (CE-013, part 2: web) #1511's setContentDraftStatus; see there.

Server: format, lint, npm test (2,741 passed).

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

What I checked:

  • Earlier follow-up 1: Done (7e29233, be57be3).
    • A page published without Mark ready now completes its own task, as Mark ready does (ownTasks, server/src/lib/content-published.js:205-219). That's Create for a create draft, and Optimize or Refresh for an optimize draft.
      • On an action that names several pages, it waits until each page has a ready or published draft. That's the web's completeDraftTasks rule.
      • The action's drafts are read after this draft is saved as published, so it counts itself.
    • Skipped work no longer holds up Publish (workPublished, :153-166). A skipped task of the page's own stays skipped (TASK_DONE), and so does a skipped Publish task (OPEN_TASKS).
    • Named pages. payload.pages is read the way the web's actionPages reads it (namedPages, :141-145), so a stray entry can't hold up Publish for good. An action's page and its draft's source_url are the same string:
      • the drawer starts a page's draft with the page it lists;
      • an action made from a draft names that draft's source_url.
  • Races.
    • Changed meanwhile. A task is completed only if its status is still the one read (completeTasks, :174-196). Only a row that actually changed gets a History entry and counts. So a task skipped in the drawer meanwhile stays skipped, and two publishes at once complete a task only once.
    • Two pages live at once. Say two pages of one action go live together (two callbacks, or the Webflow check and Mark published). Each saves its own draft before it reads the action's drafts, so at least one of them sees both live and completes Publish.
    • The action row. actions.updated_at is bumped once, after the writes. setLivePage still writes the payload only while updated_at is unchanged.
  • Reopening.
    • Each completion names the draft ({ taskId, to: 'completed', draftId }). Taking the page back therefore reopens its own task through reopenDraftTasks, as it does after Ready.
  • Earlier follow-up 2: Done in #1511 (093a2d2, 591b0a3). A published page moved back to Draft or In review reopens the Publish task, whichever page's publish completed it, and leaves publishedPages.
  • Merges. 64c95ed and dbe2d82 change nothing beyond merging their parents. The PR contains #1509's new head and main, and merges cleanly.
  • Before the API is deployed. This PR is server-only, so nobody sees a change until the API goes out. After that, a webhook callback (live today) also completes a linked action's Create or Optimize task when a workflow publishes the page.

Low (description only):

  1. The description's "The Publish task" section doesn't mention the page's own task. Add a line saying that any publish (Mark published, the webhook callback, the Webflow check) also completes the page's Create, Optimize or Refresh task, as Mark ready does. Then the squash message records the change on the live webhook path.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants