Reviews
Ratings and reviews of catalog products and other records, one per user and subject, verified against paid orders, moderated before or after publishing, with an aggregate a public storefront can read.
reviews lets signed-in users rate and review a catalog product or another record they can read. Each user writes one review per subject and can replace it. A review is marked verified when the orders module shows the reviewer paid for the product, and a moderator publishes or rejects it before or after it goes live.
Moderating, replying and reading the queue need reviews.manage. Admins get it. Writing a review needs no permission: any signed-in user who can read the subject can review it.
better-supabase add reviewsThe module needs tenant, permissions and moderation. With catalog installed, products are reviewable (subject type product); with orders installed, reviews of a product carry verified.
Server code calls the reviews instance on db, in the caller's organization. With gen.hooks set, better-supabase gen writes the hooks:
export const { useList: useReviews } = defineDataHooks(
"reviews",
(db: AppDb) => db.reviews,
);import { createReviews } from "better-supabase/blocks/reviews";
await db.reviews
.submit(organizationId, "product", productId, {
rating: 5,
title: "Fits well",
body: "True to size and the fabric holds up.",
authorName: "Ada",
})
.orThrow();"use client";
import { useReviews } from "@/lib/supabase/hooks";
const rows = useReviews({ limit: 50 });Who can review
A product can be reviewed while it is active and either listed on a published public storefront or readable by the caller through catalog.read. Any other subject type must be named in on (or the subject registry), and the reviewer must be a member of the subject's organization who can read the row.
export default defineConfig({
blocks: {
reviews: {
on: { course: { table: "public.courses" } },
options: { moderation: "post", requirePurchase: true },
},
},
});| Option | Default | What it does |
|---|---|---|
scale | 5 | The highest rating, from 2 to 10 |
maxBodyLength | 5000 | The longest body and reply |
moderation | pre | pre waits for publish; post publishes at once and moderators reject |
requirePurchase | false | Only customers with a paid, uncancelled order for the product can review |
requirePurchase needs the orders block with its tables. Submitting again replaces the caller's review and, under pre-moderation, sends it back to pending.
The product page
reviewPage pages a subject's published reviews by keyset (ADR 1077), newest first, without author ids. list stays as the capped convenience list and is deprecated. Anonymous visitors can call it for products on a public storefront. summary returns the count, mean rating and histogram of up to 200 subjects of one type, read from the review_stats table the module keeps current, so a product grid costs one call.
const page = await reviews
.list(organizationId, "product", productId, { pageSize: 20, verified: true })
.orThrow();
const stats = await reviews
.summary(organizationId, "product", productIds)
.orThrow();
// stats[productId]: { count: 12, average: 4.25, histogram: { 5: 7, 4: 3, 3: 2 } }Subjects without a published review are left out of summary.
Paging reviews
reviewPage({ organizationId, subjectType, subjectId }) returns { items, hasMore, nextCursor }. Sorts are publishedAt (the default, newest first) and rating. Filters are rating and verified (lists of values, a review matches any of them), facets are rating and verified, and q searches the title and the body. reviewFacets counts the values of each facet under the same filters, reviewCount returns { value, exact }, and get(reviewId) returns the caller's own review in any status or a published review of a subject the caller can read, or a not_found error. Anonymous visitors can page the reviews of a public storefront's products. The SQL functions are page_reviews and get_review.
const page = await reviews
.reviewPage({
organizationId,
subjectType: "product",
subjectId: productId,
filters: { rating: ["4", "5"], verified: ["true"] },
sort: { by: "rating" },
q: "battery",
limit: 20,
})
.orThrow();
const facets = await reviews
.reviewFacets({
organizationId,
subjectType: "product",
subjectId: productId,
})
.orThrow();A cursor belongs to the sort it came from. A sort, filter, facet or text the entity does not declare returns an invalid_input error. Block lists describes the options every block list shares. mine returns the caller's own review in any status, with the rejection reason, so the product page can show it next to the form.
Moderation
Each review has a moderation item (subject type review), so reviews share the moderation queue, reports and bans with comments and other content. A review is pending while its item waits for a decision, published while it is visible, and rejected while it is hidden or removed; the item's reason becomes the rejection reason.
queue(organizationId) lists pending reviews for moderators; pass status: null for every status, a list such as status: ["pending", "rejected"] for a review in any of those statuses (an empty list leaves the status off), or subjectType and subjectId for one subject. publish, reject(reviewId, reason) and reply(reviewId, text) need reviews.manage; publish approves the review's item and reject hides it. A moderator with moderation.manage can decide on reviews from the moderation queue as well, with the same effect, and members can report a published review. The author sees the rejection reason, and everyone sees the reply under the review. With the notifications module installed, the author is notified when their review is published, rejected or answered. remove deletes a review for its author or a moderator, with its moderation item.
The last decision lives on the item (decidedBy, decidedAt from moderation.item({ type: "review", id })), not on the review.
Errors
| Hint | Cause |
|---|---|
REVIEW_FORBIDDEN | the caller can't read the subject, or lacks reviews.manage |
REVIEW_INVALID | a rating outside the scale, or a body or reply over maxBodyLength |
REVIEW_NOT_FOUND | no review the caller can see has this id |
REVIEW_PURCHASE_REQUIRED | requirePurchase is on and the caller has no paid order for the product |
Events
The block records review.submitted, review.published, review.rejected, review.replied and review.deleted with organizationId, id, subjectType, subjectId, authorId, rating, status and verified. See events.
The block takes hooks around its methods, and before_review_submit and after_review_submit run in the database; see extending blocks.
Without the client
db.reviews is this client. Code that does not go through bsb.db() builds it with a transport and an organization id:
import { createReviews } from "better-supabase/blocks/reviews";
const reviews = createReviews({ transport });
await reviews
.submit(organizationId, "product", productId, {
rating: 5,
title: "Fits well",
body: "True to size and the fabric holds up.",
authorName: "Ada",
})
.orThrow();Last updated on
Invoices
Invoices an organization sends its own customers, with drafts and lines, a gapless number on issue, payments and refunds, credit notes, void and write-off, overdue and aging per currency, and invoices from accepted quotes.
Billable time
Price tracked time with an hourly rate card per organization, member and record, preview what it would bill, and turn it into draft invoice lines in bigint minor units.