Reports
Read-only analytics reports over the separate analytical database (ADR 0012). Served by cmd/reports (:8092), never by the api.
Introduction
This is the **shopper-facing returns API** of the `customer-returns` bounded context (retail network, commerce tier): the front door through which the storefront
Authorize a return (AuthorizeReturn)
Authorizes one order group's return and publishes `ReturnAuthorized`. The group must be SHIPPED or DELIVERED (`group-not-shipped` otherwise); the lines are resolved against the placed group (`validation-failed` on an unknown lineNo) and the disposition is decided from the read models. A repeat of the same key and body replays the first answer when it was the 201. A refusal that depends on state that can change (`group-not-shipped`, `no-return-destination`, `validation-failed`, `concurrent-update`) is not stored -- the key is released and the same key and body executes again.
Cancel a return (CancelReturn)
The shopper's cancellation, allowed while AUTHORIZED (before anything is in transit); publishes `ReturnCancelled` with reason `SHOPPER_REQUESTED` and answers `200` with the CANCELLED authorization. An authorization whose `expiresAt` passed untouched is cancelled by this very call with reason `EXPIRED` and also answers `200` (the lazy expiry IS the cancellation; this route never answers `authorization-expired`). Cancelling again, or after RECEIVED/CLOSED_KEEP, is `409 illegal-transition`.
How far the analytics projection is behind
`asOf` is the CloudEvents time of the newest event the projector applied; `lagSeconds` is now minus `asOf`, never negative. Both are `null` until the first event. The same figure is embedded in every report.
Read one return authorization (GetReturnAuthorization)
The authorization with its lines, disposition, labels and state. A pure read (ADR 0002 A11) that never writes; an authorization past its `expiresAt` that no command has touched yet is answered in its stored state (still `AUTHORIZED`) until the next label, cancellation or outcome expires it. The MCP tool `get_return_authorization` and the A2A skill of the same name answer the same query.
Returns performance per UTC day, reason Pareto and freshness
Per UTC day of the business instant (`authorizedAt`, `receivedAt`): the returns authorized (a return is born authorized, so this is both 'opened' and 'approved'), the returns received (`ReturnCompleted`) and, over the receipts whose authorization is also projected, the p50 and p95 of `receivedAt - authorizedAt` in seconds (`null` on a day without a sample; a negative duration counts as 0). `reasonPareto` ranks the range's authorizations by reason code, at most 5 entries; `share` is over ALL authorizations of the range. `freshness` is the projection's lag. Days without activity are omitted, an empty range answers empty arrays. The return RATE and the refund figures are deliberately absent: their facts are not in this context's own events (ADR 0012).
Liveness
Always 200 while the process runs; proves nothing about the dependencies.
Issue the shopper's reverse label (IssueLabel)
Asks the shipping context's `POST /return-labels` route for the reverse label of `packageNo` (1..5), links the tracking number and publishes `ReturnLabelIssued`. The route is the ONE in-org call this context makes; while it is not configured (or answers anything but 200) the answer is `422 label-unavailable` -- tolerant, never a 500. Only an open physical authorization is labelable.
List an order's return authorizations (ListReturnAuthorizations)
Keyset-paged, newest first. `orderId` is required; `cursor` is the previous page's `nextCursor`; `limit` is 1..100 (default 20). The MCP tool `list_return_authorizations` answers the same query.
Readiness (drain gate)
200 only while Postgres answers a ping AND a Kafka broker answers a metadata request (verdict cached 3s, bounded 2s); 503 with `dependency-unavailable` naming the dead dependency otherwise. Flips to 503 before shutdown drains.
Reports
Reports
Return Authorizations
Return Authorizations