Skip to content

feat(content): send Content Editor pages to the brand's webhook as content packages, and take back where they went live (Send to CMS #1331, part 1: server) - #1437

Merged
gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-send-server
Oct 24, 2026

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Send to CMS, phase 1 (webhook), part 1: the server (#1331). Admins and managers send Content Editor pages to the brand's webhook as content packages. The workspace's own automation (Zapier, Make, n8n, its CMS) turns them into posts and may call back with the address each went live at.

It follows the decisions on #1331:

  • admins and managers only, checked on the server;
  • slug and meta filled from the page, editable, saved on the draft;
  • 25 pages per send, sent one after another in the background;
  • 200 deliveries per workspace a day;
  • no send from Action Center.

The web parts (the editor's Send dialog, the Library's row and bulk send, the webhook's new event in Configure Webhook) come next.

Migration 00262_content_draft_deliveries

  • content_drafts gets slug, meta_title, meta_description, published_url and published_at.
  • content_draft_deliveries has one row per page sent:
    • its status (queued → sent / failed → published);
    • what the webhook answered (HTTP status, the first 2,000 characters, an error);
    • its batch, and the title and slug sent, kept when the draft goes.
    • Members read their workspace's rows; the server writes them.
    • It is a table of its own so a delivery doesn't move the draft's updated_at (as 00249).
  • reserve_content_deliveries queues as many pages as the last 24 hours leave room for. It runs under a per-organization advisory lock, so sends at once can't pass the cap together (as 00243). It is SECURITY DEFINER and granted to service_role only.
    • First it closes rows still queued after 15 minutes (a server that stopped mid-batch) as "Not sent: interrupted", as 00249 closes runs. That way the Library tells them from a batch still going.
  • published_url on both tables takes http(s) only.
  • webhook_configs_events_allowed adds content_draft.sent.
  • supabase/schema.sql is rebuilt.

Sending (lib/content-delivery.js)

  • The package, schemaVersion: 1:
    • event: 'content_draft.sent';
    • delivery { id, batchId, sentAt };
    • page { draftId, title, slug, metaTitle, metaDescription, html, author, featuredImage };
    • brand { name, domain, industry }, as the opportunity webhook sends it;
    • callback_url, callback_method.
  • The HTML comes from the browser, built by the CE-057 export helpers, which are DOM-only. It is cleaned here once more with cheerio as a second guard:
    • no script but JSON-LD;
    • no frames, forms, document-level tags or SVG animation;
    • no on* handlers;
    • link and source attributes only http(s), mailto, tel or relative, and data:image/… for an image's src.
    • The scheme is read as browsers read it: tabs, newlines and leading control characters are taken out first, so java	script: is dropped.
  • Headers: X-Webhook-Secret as the other webhooks send it, and X-Ansvisor-Signature: sha256=<HMAC of the raw body with the webhook's secret>, so a receiver can check the body. delivery.sentAt is inside the signed body, for a receiver that rejects old ones.
  • A webhook without a secret gets no callback_url, since the secret is what authenticates the callback.
  • With several subscribed webhooks, a delivery is sent once any of them takes it, and keeps that one's answer.
  • One page is sent while the request waits. Up to 25 are queued and sent in the background, one after another, each row updated as it goes.
    • A page deleted or archived before its turn is closed as failed rather than sent.
    • A crash on one page closes it and the batch goes on.
  • Pages: they must be the brand's and not archived; a page named twice goes once.
  • A bad page answers 400 with the field that is wrong (e.g. pages.2.slug). Slugs take letters, digits, -, _ and single dots.
  • Answers that stop a send: no_webhook / webhook_not_subscribed (409), not_found (404), daily_limit (429).

SSRF-safe POST (lib/safe-post.js) works as safe-fetch.js reads pages:

  • http(s), with no credentials in the address;
  • every address the host resolves to must be public, checked in the connection's own lookup;
  • any port, since a workspace's n8n or CMS often listens on its own;
  • self-hosted, a private address is allowed (http://n8n:5678/… on the workspace's own network), as the other webhooks reach it with plain fetch. Only the scheme and credentials are checked;
  • no redirect is followed;
  • 15 s, and the answer is read up to 8 KB.

Routes

  • POST /api/content-drafts/send takes { brandId, pages: [...] } and checks the brand's access, then the member's role (admin or manager).
  • POST /webhooks/content-drafts/:deliveryId/published takes { url }:
    • it is public, mounted before the JWT middleware with /webhooks/content's rate limiters;
    • it is authenticated by a subscribed webhook's secret, compared timing-safe;
    • a wrong secret, an unknown or malformed delivery and an unsubscribed webhook all answer the same 401;
    • it takes an http(s) URL, normalised as the browser reads it;
    • it counts whatever the delivery reads: a valid delivery id with its webhook's secret proves the package arrived. Many automations publish and call back before they answer the send (n8n "Respond to Webhook" last, Make's webhook response), or after the send gave up waiting (as content.js notes for the opportunity callback). The send's own result then doesn't overwrite published;
    • it marks the delivery published, and its page too when it is the page's latest delivery, so an older one's late callback doesn't move the page's address back.

Deploy order: the migration, then the server. The web parts follow. Applied and checked on the dev DB; the reservation was tried inside a rolled-back transaction (a cap of 2 took 2 of 3 pages, then 0).

Also in safe-fetch.js: the IPv4-compatible (::/96) and IPv4-translated (::ffff:0:0:0/96) IPv6 ranges are blocked, so [::127.0.0.1] no longer passes. Page reads (Optimize by URL) get this too.

Pre-push review: one high finding, fixed: a callback that came before the webhook's answer was refused (409) and its URL lost. Also fixed:

  • queued rows a restart leaves;
  • scheme-hiding links and SVG animate passing the second clean;
  • self-hosted private webhooks;
  • the IPv6 ranges;
  • published_url http(s) only;
  • the callback URL normalised;
  • the featured image's length;
  • the slug's characters;
  • no callback without a secret;
  • several webhooks' answers;
  • pages deleted or archived mid-batch;
  • the slug/meta write's errors logged;
  • older callbacks;
  • the 400's field.

@gkhngyk: please confirm self-hosted may post to private addresses, as its other webhooks already do. On Cloud it never does.

Related issue

Part of #1331 (phase 1). Doesn't close it.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation

How to test

  1. Apply 00262, then point a brand's webhook (Configure Webhook) at a request bin with the content_draft.sent event. Until the web part lands, set the event on the row in webhook_configs.
  2. As a manager, POST /api/content-drafts/send with { brandId, pages: [{ draftId, title, slug, html }] }:
    • the bin gets the package, with both headers;
    • the answer's delivery reads sent;
    • the draft keeps the slug.
  3. As an analyst: 403. With no subscribed webhook: 409 webhook_not_subscribed.
  4. Send 3 pages: the answer lists 3 queued deliveries under one batchId, and the bin gets them one after another.
  5. POST /webhooks/content-drafts/<deliveryId>/published with X-Webhook-Secret and { "url": "https://…" }: the delivery and the page read published. With a wrong secret: 401.

Checklist

  • server/: npm run format, npm run lint, npm test (194 files, 2,350 tests) pass
  • bash supabase/build-schema.sh: schema.sql is in this PR
  • Tests:
    • safe-post.test.js:
      • posts with its headers;
      • non-2xx and redirects answered as they are, none followed;
      • the answer capped;
      • a slow webhook given up on;
      • a name or IPv6 form resolving to a private address never reached on Cloud, and reached self-hosted;
      • checkWebhookUrl's refusals.
    • content-delivery.test.js:
      • the second clean, with scheme-hiding links;
      • the signature;
      • no callback without a secret;
      • the answer of the webhook that took it;
      • a page deleted mid-batch closed;
      • one page sent as the package, with its headers, slug and meta;
      • a failed delivery written;
      • a batch sent one after another in the pages' order;
      • the daily cap;
      • pages of another brand and missing webhooks refused.
    • content-drafts-send.test.js: the route, admins and managers only, its 400s and its codes.
    • webhook-content-draft-callback.test.js:
      • published at the address;
      • the same 401 for every failure;
      • http(s) only, normalised;
      • counted before the send's answer or after it gave up;
      • the page moved only by its latest delivery.
  • Root npm run version:check fails on main already (compose images 0.2.0 vs 0.3.0); not touched here

🤖 Generated with Claude Code

…ntent packages, and take back where they went live (Send to CMS ansvisor#1331, part 1: server)

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 23, 2026
…svisor#1331, part 1)

guard_content_draft_server_columns (00247) now refuses a member's write
of content_drafts.published_url and published_at, as of the other
columns the server keeps: only the webhook callback (service role) sets
where the page went live. Slug and meta stay editable.

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

Copy link
Copy Markdown
Collaborator Author

Follow-up commit ed620031, found while reviewing the web part (#1438):

  • guard_content_draft_server_columns (00247) didn't cover the new content_drafts.published_url / published_at. A member, analysts included, could set the "Live at" link with a direct Supabase update.
  • 00262 now redefines the function. It is identical to 00247's apart from those two columns, refused on insert and update. Only the webhook callback (service role) sets them; slug and meta stay editable.
  • schema.sql is rebuilt.

Checked on the dev DB inside a rolled-back transaction, as the demo user with the authenticated role:

  • a slug update goes through;
  • published_url and published_at updates get 42501 content draft column is managed server-side.

The web part is #1438. It should be deployed after this PR and after 00262 is applied on prod; the details are in its description.

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

A few fixes before merge:

  1. Bulk sends have no pause between pages. The agreed decision on #1331 is "delivered one at a time in a background job with a short pause", to stay under the CMSs' per-minute caps. deliverBatch (server/src/lib/content-delivery.js:273-295) sends the next page as soon as the last one answers, so a fast catch hook gets all 25 within a few seconds. Add a short wait between pages (for example a PAUSE_MS of 2 s, skipped after the last page) and cover it in the batch test with fake timers.

  2. The package and callback are narrower than #1331's phase 1 plan. schemaVersion: 1 is what workspaces will build their automations on, so either add these now or get the narrower v1 agreed on #1331 first:

    • contentPackage (content-delivery.js:142-167) leaves out method, sourceUrl, pageType, language, jsonLd[] and brand.id. method and sourceUrl matter most: without them, a workflow can't tell an optimized page from a new one, so it creates a second post instead of updating the live one. The server already reads the draft, so method, source_url and page_type can come from the row, not the browser. jsonLd[] can be read out of the cleaned HTML, since Webflow-style rich-text fields drop <script>.
    • The callback (server/src/routes/webhook-content-draft-callback.js:28-38) only takes { url }. The plan has { status: "published" | "failed", externalId?, url? }. Zapier and Make answer 2xx before the CMS step runs, so a post the CMS rejects stays "sent" forever unless the workflow can report failed. external_id isn't stored on the delivery either (00262:35-59).
    • When the page moves to Published, the plan also keeps a publish version in History. 00215 reserves that origin for the server (content_draft_snapshot(p_draft_id, 'publish') as service_role), and the callback doesn't call it.
  3. Low: the callback checks the URL's length before normalizing it (webhook-content-draft-callback.js:29, :71). new URL(...).href percent-encodes non-ASCII, so a URL under 2,048 characters can come out over it. The column check then fails and the caller gets a 500 instead of a 400. Check url.length <= 2048 after normalizing.

  4. Low: each send's sweep of rows still queued after 15 minutes (00262:112-116) walks the organization's whole delivery history through content_draft_deliveries_org_created, and the history grows by up to 200 rows a day. Since 00262 isn't applied yet, add a partial index: on public.content_draft_deliveries (organization_id) where status = 'queued'.

  5. Follow-up, separate PR: the other webhook senders (dispatchBrandWebhook, the opportunity send and the webhook test in routes/content.js) still post with plain fetch. Moving them onto postJson gives them the same address, redirect, timeout and size guards.

Checked and fine:

  • Callback auth. It only accepts the secret of an active webhook on the delivery's own brand that takes content_draft.sent, compared timing-safe. Every failure gets the same 401, and it uses the existing rate limiters.
  • Send route. The 25-page and 200-a-day caps hold. The advisory lock, interrupt sweep and partial reservation behave as described: I ran a pg_temp copy in a rolled-back transaction.
  • RLS and grants on content_draft_deliveries. Members can only read their own organization's rows, and only service_role can execute reserve_content_deliveries.
  • guard_content_draft_server_columns. It matches prod's current body (00247) line for line, plus the two new columns on insert and update.
  • 00262. It applies cleanly on top of prod.
  • safe-post. On Cloud it refuses private addresses, both IP literals and resolved names. It follows no redirects, stops at 15 s and reads at most 8 KB. The new IPv6 ranges work.

…ck with the CMS's id

- a 2 s pause between a batch's pages, none before the first
- the callback is /webhooks/content-drafts/:deliveryId/status with
  { status: "published" | "failed", url?, externalId?, reason? }: unmapped
  fields ("", null) read as left out, a numeric post id as text, an address
  checked after the browser reads it, without sign-in details
- published keeps the page in History as a "publish" version; failed marks
  the delivery failed unless it was published; a callback that lands before
  the webhook answers keeps its word
- the package names what the draft is from its row: method, sourceUrl,
  pageType, language (its Language rule, My rules for an untouched draft,
  else the brand's) and jsonLd; the brand goes with its id
- 00262: external_id, a partial index on queued sends, and
  content_draft_last_deliveries(uuid[]) for the Library's marks

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

Copy link
Copy Markdown
Collaborator Author

Thanks. All items are in 13aee06.

  1. Pause between pages.
    • PAUSE_MS is 2 s between a batch's pages, with none before the first.
    • Both batch tests use fake timers.
    • One test checks that nothing goes at 1,999 ms and the second page goes at 2,000 ms.
  2. Callback. It is now POST /webhooks/content-drafts/:deliveryId/status with { status: "published" | "failed", url?, externalId?, reason? }.
    • published needs url. The URL is checked after new URL().href normalizes it (≤ 2,048), and an address with sign-in details is refused.
    • externalId is stored in a new external_id column (1–200 characters, in 00262). A numeric id (WordPress, Ghost) is taken as text.
    • Fields sent as "" or null count as left out, since Zapier and Make send unmapped fields that way.
    • On the page's latest delivery, published also calls content_draft_snapshot(p_draft_id, 'publish') as service_role. keep_version skips it when History's latest version is already this page, and the comments say so.
    • A repeated callback changes nothing.
    • failed marks the delivery failed with reason. It writes with .neq('status','published'), so a published send stays published, even when the two callbacks race.
    • deliver() now writes with .eq('status','queued'). A callback that lands before the webhook answers keeps its word, published or failed, and the send's answer returns what that callback said.
  3. Package.
    • The package now carries method, sourceUrl, pageType and language, read from the draft's row (not the browser), plus brand.id.
    • The language is the draft's Language rule when it is on. For a draft no one has set rules on, it comes from the workspace's My rules (content_rule_sets, as effectiveRules reads them). Otherwise it is the brand's language, then en.
    • languageCodeOf accepts a leading two-letter word only when it is a known code, so "UK English" is en, not Ukrainian.
    • jsonLd lists the JSON-LD blocks, found with the same type check as the clean. It is parsed once per page, not once per webhook.
  4. 00262.

One note on the 15-minute "interrupted" rule. A batch of 25 pages with three subscribed webhooks that all time out could run past 15 minutes, and a send in that window would close its later pages as interrupted. With one webhook, the worst case is about 7 minutes. I left it as it is. Say if you'd rather have a longer window.

Server checks: format, lint and all 2,359 tests pass. The docs in #1441 are updated to match.

cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
…ansvisor#1437 review)

- the callback is /status with { status, url?, externalId?, reason? }
- the package's jsonLd, method, sourceUrl, pageType, language and brand.id
- links to http, https, mailto, tel or relative addresses; the callback
  shares the opportunity callback's limits; a 2 s pause between pages

Co-Authored-By: Claude Opus 5.5 <[email protected]>
reserve_content_deliveries closed a send left queued with sent_at = now(),
so the Library dated it to the workspace's next send. It leaves sent_at
empty now: the send reads at its created_at.

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

Copy link
Copy Markdown
Collaborator Author

One more small change in 00262 (5109eef), from the #1439/#1440 follow-ups. reserve_content_deliveries no longer sets sent_at = now() when it closes a send left queued as interrupted. Such a row now reads at its own created_at, not at the workspace's next send. It is applied on the dev DB, and schema.sql is rebuilt.

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

One fix before merge. Everything else from the last review is done.

Last review:

  1. Pause between pages: done (PAUSE_MS, with fake-timer tests).
  2. Package and callback: done.
    • method, sourceUrl, pageType, language and brand.id come from the database rows, and jsonLd comes from the cleaned HTML.
    • The callback takes status, url, externalId and reason, stores external_id, and keeps a publish version.
  3. URL length checked after normalizing: done.
  4. Partial index for the queued sweep: done.
  5. Other webhook senders moved onto postJson: still a follow-up for a separate PR.

New:

  1. A re-sent page that goes live at the same address isn't kept in History.
    • The "said again" check compares against the draft (server/src/routes/webhook-content-draft-callback.js:162), not the delivery.
    • Here is what happens: a published page is edited and sent again, and the CMS updates the post in place. That is the update-the-post flow the package now points workflows to with method and sourceUrl. The new delivery's callback finds the draft already published at that URL, so it skips both the draft write and content_draft_snapshot.
    • As a result, History keeps the first publish's text as the published version, and the page's published_at stays at the first publish. The docs in #1441 say the page as published is kept in History.
    • Fix: make the repeat check per delivery.
      • Read published_url along with the delivery (line 93 already reads status).
      • Skip the writes only when this same delivery is already published at the same url.
      • Otherwise, update the draft and call the snapshot. content_draft_keep_version already skips a version that's identical to the latest one.
      • Skipping the delivery's own update in the repeat case also stops a retry from moving its published_at.
    • Test: send a published page a second time, change the page, call back published at the same address, and check that a second publish version is kept.

On the 15-minute "interrupted" window: 30 minutes would cover a batch where three webhooks time out on every page (about 20 minutes). A server that really stopped would still be closed by the next send. Since 00262 isn't applied yet, the change costs nothing. This is optional; 15 minutes is fine if you prefer it.

Checked and fine:

  • 00262 on prod. It applies cleanly (I ran it in a transaction and rolled it back). Inside that rolled-back transaction, signed in as members of two different workspaces:
    • content_draft_last_deliveries returns only the caller's own workspace's rows, one per page (the latest). Another workspace's row for the same page id doesn't replace the caller's own.
    • anon can't execute it.
    • Members can't insert deliveries or call reserve_content_deliveries.
    • The sweep closes a queued row older than 15 minutes as interrupted, and leaves sent_at empty.
    • A member's write of published_url is refused, and a slug write goes through.
  • external_id. Its check matches what the callback accepts: up to 200 characters, with a number stored as text.
  • Callback.
    • Authentication is unchanged.
    • Races between published and failed end as published in either order: the failed write is conditional, the published write isn't.
    • The snapshot call as service_role passes content_draft_snapshot's membership and origin checks.
  • deliver(). The .eq('status', 'queued') write leaves a callback's earlier result in place and returns it.
  • Package fields. deliveryPage drops anything else the browser sends. The server sets:
    • method, sourceUrl and pageType from the draft row;
    • language from the draft's rules, the workspace's My rules, or the brand;
    • brand.id from the brand row;
    • jsonLd from the HTML after it's cleaned.

@gkhngyk

gkhngyk commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

One more low item, on your 15-minute question: a batch can still be going after 15 minutes.

  • All of a batch's rows get created_at when they're reserved, not when each page's turn comes. deliver() posts to each subscribed webhook in turn, with a 15 s timeout.
  • So a batch takes up to 25 × n × 15 s, plus 48 s of pauses: about 13 minutes with two webhooks timing out on every page, and about 20 minutes with three.
  • Past 15 minutes, the Library reads its later pages as interrupted. A send started meanwhile also closes them in reserve_content_deliveries, so a page the CMS did receive ends up marked failed.
  • Fix: raise the window to 30 minutes in reserve_content_deliveries (00262, line 144) and in the web's INTERRUPTED_AFTER_MS (feat(content): send the Library's selected pages to the CMS together (Send to CMS #1331, part 3b: bulk) #1440, cms-send-client.ts:111). Change both together.
  • A server that really stopped is still closed by the next send. Since 00262 isn't applied yet, the change costs nothing.

cihan-gyk and others added 2 commits October 24, 2026 13:44
…h 30 minutes before it reads as interrupted

- the callback's "said again" check is the delivery's own: a new send of a
  page live at the same address (its post updated in place) moves the
  draft's published_at and keeps a "publish" version; the same delivery
  said twice changes nothing, its time included
- 00262: a send left queued closes as interrupted after 30 minutes, not
  15: a batch with webhooks timing out can run about 20

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…redoes a page write that failed

The delivery row is marked published only once the draft and its
"publish" version are written: a write that fails answers 500, and the
workflow's retry, finding the delivery not yet published, does it all
again. A retry of one already said keeps a CMS id it adds.

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

Copy link
Copy Markdown
Collaborator Author

Thanks. Both items are done in 429d829 and cffb209.

  1. Re-sent page kept in History. The repeat check is now per delivery.
    • The callback reads published_url with the delivery's status.
    • It skips the writes only when this same delivery is already published at the same url. In that case it changes nothing, its published_at included. It only stores an externalId the retry adds.
    • Otherwise it updates the draft and calls content_draft_snapshot (origin publish).
    • Test: "keeps the page as published again when a new send goes live at the same address". It sends a published page again with changed text, calls back published at the same address, and checks that a second publish version is kept and published_at moves.
  2. Delivery written last. The delivery row is marked published only after the draft and its version are written. A write that fails answers 500. The workflow's retry then finds the delivery not yet published and does it all again. Test: "does it all again on the retry of a callback whose page write failed".
  3. 30 minutes. reserve_content_deliveries in 00262 now closes a send left queued after 30 minutes. schema.sql is rebuilt. The web side (INTERRUPTED_AFTER_MS) moved to 30 minutes too, in feat(content): send a Library page to the CMS from its row, and show each row's last send (Send to CMS #1331, part 3a: Library row) #1439 (9c8ba70).

Checks: npm run format, npm run lint and npm test pass (2,362 tests).

The other webhook senders moving onto postJson stays a follow-up for a separate PR.

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

All items done. Looks good.

Last review:

  1. Re-sent page kept in History: done.
    • The repeat check is per delivery now (server/src/routes/webhook-content-draft-callback.js:144). Writes are skipped only when this same delivery is already published at the same url, and then only an externalId the retry adds is stored.
    • A new delivery that goes live at the same address updates the draft, moves its published_at and calls content_draft_snapshot. The new test covers it.
  2. 30-minute window: done.
    • It is in reserve_content_deliveries (00262, line 144) and in the web's INTERRUPTED_AFTER_MS (cms-send-client.ts in #1439/#1440). That is the only place the web reads it.
    • With 30 minutes, a batch of 25 still fits with up to four webhooks timing out on every page.
  3. Moving the other webhook senders onto postJson stays a follow-up for a separate PR, as agreed.

New commits, checked and fine:

  • Delivery written last (line 182).
    • A draft write that fails answers 500 and leaves the delivery unpublished, so the workflow's retry does it all again. The retry test covers it.
    • The snapshot stays best-effort (logged, not retried). keep_version already skips a repeat, so a retry doesn't add a second version.
    • A failed callback that lands between the draft write and the delivery write is overwritten by the published write, so published still wins in either order.
    • deliver()'s .eq('status', 'queued') write still leaves the callback's result in place.
  • 00262 on prod. The final version applies cleanly. I ran it in a transaction and rolled it back. Inside that transaction:
    • The sweep closes a row queued 31 minutes ago as interrupted, with sent_at left empty. It leaves a row queued 20 minutes ago alone.
    • Signed in as members of two different workspaces, content_draft_last_deliveries returned each caller only their own workspace's latest row for the same page id.
    • A member's write of published_url is refused, and a slug write goes through. A member can't insert a delivery.
    • anon can't execute the read function, and authenticated can't execute reserve_content_deliveries.
    • As service_role, the callback's draft write and content_draft_snapshot(..., 'publish') both go through.

@gkhngyk
gkhngyk merged commit 128e822 into ansvisor:main Oct 24, 2026
5 checks passed
gkhngyk pushed a commit that referenced this pull request Oct 24, 2026
…k (Send to CMS #1331, part 4) (#1441)

* docs(content): document Send to CMS and the content_draft.sent webhook (Send to CMS #1331, part 4)

- a Send to CMS guide: setting up the webhook, sending one page or up to
  25 from the Library, the row icons, and building the workflow in n8n,
  Make or Zapier with the callback that reports the live address
- the Webhooks reference: the content_draft.sent event (opt-in), its
  package, the X-Ansvisor-Signature HMAC, the published callback and the
  delivery rules (2xx, 15 s, no redirects, 25 a send, 200 a day)
- the Content Editor guide points to it from the editor and the Library

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

* docs(content): match Send to CMS's status callback and package fields (#1437 review)

- the callback is /status with { status, url?, externalId?, reason? }
- the package's jsonLd, method, sourceUrl, pageType, language and brand.id
- links to http, https, mailto, tel or relative addresses; the callback
  shares the opportunity callback's limits; a 2 s pause between pages

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

* docs(content): say a bulk send's later requests stop when its dialog closes (#1440)

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
gkhngyk pushed a commit that referenced this pull request Oct 27, 2026
…does (#1437 review) (#1568)

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