Skip to content

Newsletter issue blocks: edit every block in DataOps, revisions, two-way Relay sync - #501

Merged
alexeygrigorev merged 14 commits into
mainfrom
feat/newsletter-blocks-relay-sync
Nov 23, 2026
Merged

alexeygrigorev merged 14 commits into
mainfrom
feat/newsletter-blocks-relay-sync

Conversation

@alexeygrigorev

Copy link
Copy Markdown
Member

Staff can now edit every block of a newsletter issue in DataOps, not only the sponsor doc. Each edit becomes a revision you can read from the CLI, and blocks sync with Relay in both directions.

What's in it

  • Issue page (/newsletter/<issue>): a "Content blocks" section. Every block is a form whose fields mirror Relay's block types (intro, sponsor, event spotlight, course updates, events list, recording, article, and the rest). Each block has Save and History buttons and shows "In sync" or "Edited, not synced". The section also has "Check Relay" (a dry run) and "Sync with Relay". The first time, an issue with no blocks offers "Import blocks from Relay".
  • Revisions: every edit, import and Relay pull appends a before/after revision for one block. Read them with:
    • dataops newsletter revisions <issue> [--block <id>] [--origin edit] [--diff] [--rev N]
  • CLI: dataops newsletter blocks <issue> [--show] [--import weekly-304 --target production|dev], block-edit, blocks-sync [--dry-run].
  • API: /api/newsletter-issues/:id/blocks with GET, POST /import, PUT /:blockId (with version), POST /sync (dryRun) and GET /revisions.

Sync decision: two-way, three-way merge per block

We did not make DataOps the only source of truth. Relay still renders and sends the newsletter, and its blocks still get written outside DataOps: Relay's editor, template autofill, and newsletter relay-sync for the sponsor block. Rebuilding Relay from DataOps would silently overwrite those edits.

Instead, each block stores the content both sides last agreed on, as a hash plus Relay's updated_at. A sync then does this for each block:

  • Changed only in DataOps: pushed to Relay (one PUT per block).
  • Changed only in Relay: pulled into DataOps, recorded as a relay-pull revision.
  • Changed on both sides: a conflict. The whole sync is refused with 409 and nothing is written.
  • New in Relay: added. Deleted in Relay: removed if unchanged here, otherwise a conflict.

Safeguards:

  • Just before each push, the Relay block is read again. If it changed since the plan was made, the sync stops with 409 and that block is not overwritten.
  • Pushes are refused once the Relay campaign has left draft.
  • A block body over 7 KB is refused before any write (Relay's CloudFront WAF rejects bodies over about 8 KB).
  • Every Relay call has a 15 s timeout, and errors name the call that failed.
  • Edits are optimistic: a stale block version gets 409.

Relay targets are fixed, and each has its own runtime secret: production uses relay-production.dtc-newsletter-api-key, dev uses relay-dev.api-keys. The key is never returned or logged. Nothing in this PR sends a newsletter, campaign or test email.

Tests

  • Backend tests/newsletter-blocks.test.ts (fake Relay): import per target, edit with revision and diff, stale or invalid edit, push and pull round-trip, refusal on conflict, race between plan and push, campaign lock, Relay 404 and timeout, body cap.
  • CLI test/newsletter-blocks.test.mjs, frontend test/newsletter-blocks.test.mjs.

@alexeygrigorev
alexeygrigorev merged commit 34eea1d into main Nov 23, 2026
4 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.

1 participant