manicanldes-backend/docs/product-reviews-api.md

57 lines
6.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Verified product reviews (Phase 4B)
Purchase eligibility uses **manual staff verification of external completed-purchase evidence**, as selected for this milestone. It does not infer a purchase from a pending checkout, reserve stock, change order status, or claim gateway/delivery verification. Public reviews identify the method as `MANUAL`.
| Method | Path under `/api/v1` | Access |
| ------ | --------------------------------------------------------- | -------------------------------------------------------------------- |
| GET | `/reviews/eligibility` | Active user; own eligible verification IDs/variant IDs/dates |
| GET | `/reviews` | Active user; own submissions and computed moderation status |
| POST | `/reviews` | Active user; submit against own active verification |
| GET | `/review-verifications` | `reviews.verify`; optional `userId`, `variantId` filters |
| POST | `/review-verifications` | `reviews.verify`; record checked external purchase evidence |
| POST | `/review-verifications/:id/revoke` | `reviews.verify`; permanently revoke incorrect evidence |
| GET | `/review-moderation` | `reviews.read`; optional `variantId`, `status` filters |
| POST | `/review-moderation/:id/decision` | `reviews.moderate`; approve/reject, or hide an approved review |
| GET | `/storefront/:organizationId/products/:productId/reviews` | Public, shared storefront rate limit; approved verified reviews only |
All list endpoints use `limit` (1–100, default 25) and `offset` (0–10,000, default 0). Private resources are scoped to the authenticated organization; customers cannot read another user's eligibility or submissions. Unknown input fields are rejected.
Staff first check external evidence for the specific active customer and variant, then submit:
```json
{
"userId": "b92c23e5-794d-47e7-a7f4-428b84543fa1",
"variantId": "983a3a76-b3b7-4a63-9796-1393a63c2e0b",
"reference": "EXTERNAL-RECEIPT-123",
"note": "Receipt and completed purchase checked",
"idempotencyKey": "10fc5585-34a6-4ead-b5ce-d83418eb50df"
}
```
The verifier must differ from the customer. References are exact, trimmed identifiers (3–100 characters), unique per organization and variant, so one receipt may cover different variants but cannot be reassigned to multiple customers for the same variant. Notes require 3–1,000 characters. Historical variants can receive verification records, but new reviews require an active variant and published product.
Customer submission example:
```json
{
"verificationId": "62386f2a-4a74-4de2-93cc-ab60490c33e2",
"rating": 5,
"displayName": "Candle customer",
"title": "Lovely fragrance",
"body": "The candle burns evenly and smells wonderful.",
"idempotencyKey": "4aeec80a-4a4b-4d72-9b44-b385b2d06147"
}
```
Rating is an integer 1–5. Display name is an explicit public alias of 1–80 characters, title 3–160, body 10–2,000. Text is trimmed, plain single-line text. The API publishes the supplied alias rather than the user's private account name or email. One immutable submission is allowed per customer/organization/variant, even with repeated purchases. Editing, replacement after rejection, and customer withdrawal are outside this milestone; staff can hide approved content.
Moderation body: `{ "decision": "APPROVED", "note": "Content checked", "idempotencyKey": "<uuid>" }`. `REJECTED` is also allowed for a pending submission. A different staff member must moderate the customer's review. An approved review may receive one `HIDDEN` decision; hidden/rejected content cannot be republished. Notes require 3–1,000 characters. Revoked purchase evidence prevents approval. Moderation history is immutable and ordered; status is computed as `PENDING`, `APPROVED`, `REJECTED`, or `HIDDEN`.
Revocation body: `{ "reason": "Evidence was invalidated", "idempotencyKey": "<uuid>" }`, with a 3–1,000-character reason. Revoking evidence blocks new submissions and immediately excludes any associated review from public results. It does not rewrite moderation history. Customers' own review responses expose `purchaseVerified: false` after revocation.
Public responses include only review ID, variant ID, rating, explicit display name, title, body, creation date, `verifiedPurchase: true`, and `verificationMethod: "MANUAL"`. No customer/account identifiers, evidence references, staff notes, hashes, or moderation history are exposed. Public publication additionally requires a currently published product and active variant. Missing/private products return 404; a published product with no eligible reviews returns an empty array.
Each write uses a UUID idempotency key. Verification/revocation/moderation namespaces are separately organization-scoped; submissions are customer/organization-scoped. Identical retries return the current record; changed content returns a specific 409 replay conflict. Retries do not duplicate audit events. Self-verification/moderation and missing permissions return 403; scoped misses return 404; duplicate submissions, revoked eligibility, and invalid transitions return 409.
Deploy the append-only migration before the application. It adds four tables, scoped foreign keys, unique constraints, rating/text checks, immutable-record guards, and moderation/verification transition guards. Existing system Owner roles receive `reviews.verify`, `reviews.read`, and `reviews.moderate`; custom roles need explicit grants. Evidence references and notes are available only through the verification permission. Moderation queues expose the customer ID and decision history but omit evidence references and notes. Existing checkout/payment/provider behavior remains unchanged.