# stapel-posts 0.1.0

Short posts in a scope (a workspace, a tenant): an optional title, plain text, optional pictures with a chosen cover. What a post is comes from its KIND (an open registry): who may write it (a capability the host's scope provider answers, or any member), whether it needs a title, who reads it (the whole scope, or the author and processors only), and an optional LIFECYCLE — states, allowed transitions, who may move a post, a due time — with an append-only history and an overdue flag. Announcements, resident requests and helpdesk tickets are kinds, not modules. Discussion is a chat room about the post opened through stapel-chat's chat.open_subject_room by name; posts.subject_cards renders its header. Moderation takes a post down through moderation.completed; GDPR erasure deletes the person's posts and blanks their id on others' history.

Contract: axes 1 · surface 4 · extension points 6 · operations 8 · error codes 58 · flows 2.
Generated from docs/capabilities.json by `stapel-llms-txt` — do not edit; drift-gated by `make contract-check`.

## Configuration axes — what a product switches on
Settings keys; `default` is what you get by saying nothing. Turning an axis off unmounts the operations it gates.
- WRITE_REQUIRES_ACCOUNT [bool, default true] — Who may post
  Whether a guest session (no registered account) may write posts. true (default): sign-in required. false: guests write like members, still subject to each kind's capability. Values: true, false.

## Usage surface — call these before writing your own
This is the answer to "does Stapel already have something for X?". `instead of` names the outside symbol this one displaces.
### predicate
- get_kind — stapel_posts.kinds.get_kind
  One kind as a Kind; raises UnknownKind for a name not registered here.
- kind_names — stapel_posts.kinds.kind_names
  The registered kind names, sorted.
- kind_policies — stapel_posts.kinds.kind_policies
  Every registered kind's policy, built-ins merged with KINDS and completed from the built-in post policy.
- lifecycle — stapel_posts.kinds.lifecycle
  One LIFECYCLES entry as a Lifecycle (allowed moves, terminal states, labels), or None.

## Extension points — what a product replaces, fork-free
- KINDS [registry]
  Open registry {kind: policy | None} merged over the built-in 'post': write_capability, moderate_capability, title (required|optional|none), lifecycle, read (scope|author), author_edits (always|initial|never), discussion, notify_state_change. A policy states only what differs.
- LIFECYCLES [registry]
  {name: {initial, states: {s: {label, terminal?}}, transitions: {from: [to]}, transition_capability, due_hours?}}. Changing statuses is a settings edit (plus a data migration for rows in a removed state); system check E002 refuses an inconsistent machine.
- SCOPE_PROVIDER [strategy]
  resolve(request) -> scope_key, can_read(request, scope), has_capability(request, scope, capability). The shipped one is single-scope; a workspace host writes its own (E005 when workspaces is installed).
- STAPEL_POSTS_POST_PRESENTER / STAPEL_POSTS_STATE_CHANGE_PRESENTER [presenter]
  Swap keys (STAPEL_SWAP) for the post and history presenters.
- moderation.completed [comm_event]
  Consumed for target type posts_post: rejected hides the post (its author still sees it), approved on a blocked row publishes it again.
- posts.post.state_changed [comm_event]
  One event per lifecycle move (from, to, actor, change id), so a projection, an SLA board or a notifier follows requests without polling.

## Fits with — fleet dependencies
- stapel-cdn (optional) — uploads behind the image refs; cdn.describe_many fills the image objects
- stapel-chat (optional) — chat.open_subject_room (>=0.13.0) opens THE room about a post; the host registers the 'post' subject type with posts.subject_cards. Without it discussions answer 503
- stapel-core (required) — comm bus (posts.* emits, Functions, user.merged and moderation.completed consumers), AnchorPagination, GDPR owner protocol, AppSettings, the mandate-aware scope mixin
- stapel-moderation (optional) — the posts_post target type reads posts.moderation_content and takes posts down through moderation.completed
- stapel-notifications (optional) — posts.state_changed reaches the author when a processor moves their post
- stapel-profiles (optional) — profiles.public_cards renders author cards (null without it)

## HTTP operations (8) — call by operationId, never by a typed path
Paths are relative to `/posts/api/v1/posts/`.
### Posts
- POST / — posts_create
- DELETE /{post_id}/ — posts_destroy
- POST /{post_id}/discussion/ — posts_discussion_create
- GET /{post_id}/history/ — posts_history_list
- GET / — posts_list
- PATCH /{post_id}/ — posts_partial_update
- GET /{post_id}/ — posts_retrieve
- POST /{post_id}/transition/ — posts_transition_create

## Error codes (58) — the StapelError envelope
Render `t(code, params)`; branch UX on the remediation. Localized text lives in docs/errors.<lang>.md, not here.
- error.400.bad_request [400] fix_input
- error.400.captcha_invalid [400] retry
- error.400.captcha_required [400] retry
- error.400.expected_list [400] fix_input
- error.400.field.blank [400] fix_input {field}
- error.400.field.does_not_exist [400] fix_input {field}
- error.400.field.invalid [400] fix_input {field}
- error.400.field.invalid_choice [400] fix_input {field}
- error.400.field.max_length [400] fix_input {field,max_length}
- error.400.field.max_value [400] fix_input {field,max_value}
- error.400.field.min_length [400] fix_input {field,min_length}
- error.400.field.min_value [400] fix_input {field,min_value}
- error.400.field.null [400] fix_input {field}
- error.400.field.required [400] fix_input {field}
- error.400.field.unique [400] fix_input {field}
- error.400.invalid_ad_id [400] fix_input
- error.400.posts_body_too_long [400] fix_input {max}
- error.400.posts_cover_not_an_image [400] fix_input
- error.400.posts_empty_post [400] fix_input
- error.400.posts_image_ref_invalid [400] fix_input
- error.400.posts_no_lifecycle [400] fix_input
- error.400.posts_title_not_allowed [400] fix_input
- error.400.posts_title_required [400] fix_input
- error.400.posts_too_many_images [400] fix_input {max}
- error.400.posts_unknown_kind [400] fix_input
- error.400.too_many_ids [400] fix_input {requested,limit}
- error.400.validation_error [400] fix_input
- error.400.verification_failed [400] verify
- error.400.verification_invalid_factor [400] verify
- error.401.unauthorized [401] reauthenticate
- error.402.payment_required [402] retry
- error.403.forbidden [403] retry
- error.403.network_blocked [403] contact_support
- error.403.posts_forbidden [403] retry
- error.403.posts_write_requires_account [403] reauthenticate
- error.403.verification_enrollment_required [403] verify
- error.403.verification_required [403] verify
- error.404.ad_not_found [404] retry
- error.404.not_found [404] retry
- error.404.posts_post_not_found [404] retry
- error.404.verification_challenge_not_found [404] verify
- error.405.method_not_allowed [405] retry
- error.406.not_acceptable [406] retry
- error.408.request_timeout [408] retry
- error.409.conflict [409] fix_input
- error.409.posts_not_editable [409] fix_input
- error.409.posts_transition_not_allowed [409] fix_input {from_state,to_state}
- error.410.gone [410] retry
- error.413.payload_too_large [413] retry
- error.415.unsupported_media_type [415] retry
- error.422.unprocessable_entity [422] wait_and_retry
- error.423.locked [423] wait_and_retry
- error.423.verification_locked [423] wait_and_retry
- error.429.rate_limit [429] wait_and_retry {retry_after_display,retry_after,retry_after_minutes}
- error.429.too_many_requests [429] wait_and_retry
- error.500.internal [500] contact_support
- error.503.mandate_unavailable [503] retry
- error.503.posts_discussion_unavailable [503] wait_and_retry

## Documented flows (2) — full steps in docs/flows.json
- posts.publish — Publish a post
- posts.track — Track a request
