PUT
Save legal document

Overview

Writes a legal document in place. There is no create/delete pair here — the slug set is fixed, so this either writes the first revision of a document or replaces the existing one.

Authentication

Bearer admin token. SUPER or MODERATOR only; FINANCE is read-only on this surface.

Request body

Sanitizing

bodyHtml is run through a fixed allowlist before it is written, so the stored value is always safe and readers never have to sanitize:
  • Kept: h1–h4, p, ul/ol/li, strong/b, em/i, u, a, br, hr, blockquote, and table tags.
  • Stripped: <script> (and its contents), <style>, <iframe>, <img>, event handlers such as onclick, style/class/id attributes, and any javascript: or data: URL.
  • Forced: every <a> gets rel="noopener noreferrer".
  • Link schemes are limited to http, https, mailto, tel.
If sanitizing leaves nothing — i.e. the submission was entirely disallowed markup — the request is rejected with 400 VALIDATION_FAILED rather than saving an empty page.
Because sanitizing happens on write, the response body may differ from what you sent. Always re-render the editor from the response rather than from your local draft, or the admin will see markup that is not actually stored.

Versioning

version auto-increments only when the title or bodyHtml actually changed. Toggling isPublished or correcting effectiveAt deliberately does not bump it, so the number stays meaningful as a “has the wording changed?” signal.

Response — 200 OK

The saved document, in the same shape as the get endpoint.

Errors

Audit

A legal.saved audit row is written on success, recording the title, resulting version and publish state. The body itself is not stored in the audit log — it is far too large.

Seeding

A fresh environment is seeded with placeholder copy via pnpm seed:legal, which runs on every deploy. That seed is insert-only: once a document exists it is never touched again, so a deploy can never overwrite copy published through this endpoint.