5.6 KiB
Blog publishing and SEO metadata (Phase 4G)
Staff create and edit organization-scoped blog articles, explicitly publish reviewed draft versions, and withdraw content with a reason. Revisions to a published article remain private working text until publication replaces the public snapshot at its existing slug. This is the next provider-independent growth milestone while Instagram, Etsy and WhatsApp integrations remain deferred.
| Method | Route | Access |
|---|---|---|
| GET | /api/v1/blog-articles |
blog.read; paginated staff records, optional state filter. |
| GET | /api/v1/blog-articles/:id |
blog.read; working text and latest publication metadata/snapshot. |
| POST | /api/v1/blog-articles |
blog.manage; create a draft. |
| PATCH | /api/v1/blog-articles/:id |
blog.manage; edit working text at its current version. |
| POST | /api/v1/blog-articles/:id/publication |
blog.publish; publish { "version": 0 }. |
| POST | /api/v1/blog-articles/:id/withdrawal |
blog.publish; withdraw with { "reason": "Editorial correction needed" }. |
| GET | /api/v1/storefront/:organizationId/blog |
Public, shared storefront rate limit; published article summaries and SEO metadata. |
| GET | /api/v1/storefront/:organizationId/blog/:slug |
Public, shared storefront rate limit; latest published text and SEO metadata. |
Create with slug, title, summary, body, and a UUID idempotencyKey. Slugs use the existing lowercase, hyphen-separated catalog convention and are permanent within an organization. Title is single-line plain text up to 160 characters, summary up to 500, and body multiline plain text up to 20,000. All are required and trimmed. HTML, angle brackets, and unsafe control characters are rejected; body line breaks and tabs are supported. PATCH accepts the current version and at least one of title/summary/body. Identity, slug, scope, lifecycle metadata, and public snapshot are never client-editable.
Creation retries with the same key and normalized input return the same article; changed input returns IDEMPOTENCY_CONFLICT (409). Duplicate organization/slug returns RECORD_CONFLICT (409). Successful edits increment version and record blog.updated. Publishing checks the reviewed version, copies title/summary/body into the public snapshot, records publication version/time/staff, increments the working version, and audits blog.published. Repeating the latest successful publication version makes no new changes or audit record. Older publication commands after republishing return BLOG_CHANGED (409). An exact latest-publication retry after further draft edits leaves those edits unpublished. Editors do not require publication permission to save private changes.
Public responses expose only slug, published title/summary, publication date, and seo: { title, description } derived from that snapshot. Detail adds published body; list omits body and uses existing limit/offset pagination. Draft content, staff identities, internal scope, keys, hashes, and version counters are absent. Draft, withdrawn, and foreign-organization detail requests return BLOG_NOT_FOUND (404). Staff reads are separately permission-gated, and all writes recheck live session and permission inside the existing organization lock.
Withdrawal is terminal, immediate, and reasoned; it does not erase the last public snapshot or audit evidence. Repeating the same reason is safe; a different reason, edit, or publication after withdrawal returns BLOG_STATE_CONFLICT (409). The slug remains reserved. Public routing no longer exposes withdrawn records. Replace an irreversibly withdrawn article with a new slug when needed.
The frontend must render body as text, preserving paragraphs, and escape all text used in HTML metadata. This API supplies content and metadata; it does not render pages, generate HTML/Markdown, invent a canonical domain, submit a sitemap, or guarantee search indexing/ranking. Frontend canonical links, sitemap/robots integration, rich text, media and structured data are separate delivery work.
Deploy the additive table/type migration before the application. Existing system Owners gain blog.read, blog.manage, and blog.publish; custom roles require explicit grants. Scoped staff foreign keys, unique slugs/creation keys, native revision/transition guards, and exact snapshot checks protect persistence. Deletes and withdrawn-record rewrites are rejected. Prior migrations remain unchanged. Older code ignores this table; preserve article rows and audit events on rollback.
The latest public snapshot is retained, while the audit trail records editorial actions without storing old article bodies. Full revision history and restoration can be added when editorial rollback is required. Verification covers unpublished/draft privacy, live text separation, republication, metadata projection, independent permissions, scoped access, plain-text/size validation, stale and concurrent commands, creation retries, reasoned withdrawal, native snapshot/delete guards, and migration drift. Native multi-connection concurrency verification remains dependent on the existing PostgreSQL CI setup.