CRM
Deals in pipeline stages, quotes made from deals, sales targets, comments, tags, custom fields and follow-up reminders.
The crm preset holds your deals for you: the deals
block stores each deal with its amount, company, owner and close date, and
the pipelines block moves it through stages the
organization edits. Quotes start from a deal, and
targets measure won deals against each rep's quota.
The pipeline's transitions refuse a jump it does not allow, and the people
watching a deal hear about comments, tags and stage moves.
Tables
The app adds no table. Deals live in better_supabase.deals, their stages
in better_supabase.pipeline_stages, and every stage change in
better_supabase.pipeline_stage_history. The deals table takes no writes
from the Data API: create and edit deals through the block's functions
(create_deal, update_deals, close_deal), which check deals.write and
the deal team. Add your own deal columns with alter table ... add column in your own schema files
(your own fields).
Config
The crm preset brings the SaaS blocks (organizations, notifications, the
outbox, ...) plus parties, pipelines, deals, quotes, targets, activities,
tags, comments, an activity feed, custom fields, saved views and search, and
the sales activity blocks below. The
deals block registers deal as a subject, so the config names no
subjects.deal; set the deal page on the block's entity and add reminders
for follow-ups:
import { defineConfig } from "better-supabase/config";
export default defineConfig({
preset: "crm",
blocks: { deals: { names: { deal: { url: "/deals/{id}" } } }, reminders: {} },
});A deal created without a pipeline lands in the organization's default deal pipeline, which the first call creates from the deals block's stages (Qualified to Closed won and Closed lost). An admin can also set up the organization's own pipeline:
const sales = await pipelines
.upsert(organizationId, { subjectType: "deal", key: "sales", name: "Sales" })
.orThrow();
const lead = await pipelines
.saveStage(sales.id, { key: "lead", name: "Lead", category: "open" })
.orThrow();
// ... qualified (open), won (won), lost (lost)
const deal = await deals
.create(organizationId, {
name: "Acme renewal",
closeOn: Temporal.PlainDate.from("2026-12-31"),
pipelineId: sales.id,
stageId: lead.id,
})
.orThrow();The first pipeline of a type becomes its default. The deal's owner (the
caller, unless you pass ownerId) watches it.
Leads and outreach
A lead is a person in contacts with the lead
lifecycle, not a table of its own, so a lead that buys stays the same row.
The preset adds the blocks that find, rank and work those leads:
| Block | Role in the app |
|---|---|
| mail-sync | Each rep's mailbox, synced into activities on the contact |
| sequences | Email steps a lead is enrolled in, sent through the mailbox |
| segments | Saved rules such as "leads in the Netherlands with no owner" |
| assignment | Queues that hand new leads to reps by turn, weight or territory |
| enrichment | Company and person details from a provider, filling empty fields |
| lead-scoring | A score per lead from its fields and activity, rescored on change |
| forecasts | Forecast snapshots of the open deals per period and rep |
Mail sync and enrichment call a provider you pass at runtime (a
MailProvider and an enrichment provider over fetch); the database side
installs without one.
Event flow
Each call takes the record as a subject, deal being { type: "deal", id: dealId }, and acts in the tenant of the block client (see one block per request).
| The user | Call | Event | Watchers get |
|---|---|---|---|
| Creates a deal | deals.create(organizationId, { name, closeOn, ... }) | deal.created | nothing; the owner starts watching |
| Comments on a deal | comments.create(deal, { body }) | message.sent | comment.posted, from comments |
| Tags it | tags.attach(deal, tagId) | subject.tagged | subject.tagged |
| Moves it to another stage | deals.update({ changes: [{ dealId, field: "stageId", value }] }) | deal.updated, pipeline.stage_changed | pipeline.stage_changed, from pipelines |
| Marks it won or lost | deals.win(dealId) or deals.lose(dealId, reason) | pipeline.stage_changed, deal.closed | pipeline.stage_changed and deal.closed, from deals |
| Sends a quote | quotes.fromDeal(dealId) | quote.created | map it if you want |
| Sets a custom field | customFields.setValue(deal, fieldId, value) | field_value.set | subject.field_changed |
| Gets a follow-up reminder | reminders.deliver(payload) | reminder.sent | reminder.due |
Comments and pipelines notify the deal's watchers themselves; the outbox
events in the other rows reach them through a
watcher handler, which leaves out the user who
acted. A sales target with the metric deals.won_amount counts a deal once
it is won.
Transitions
Without transitions, a deal moves from any stage to any other. To refuse a jump, list the moves the pipeline allows:
await pipelines
.setTransitions(sales.id, [
{ from: lead.id, to: qualified.id },
{ from: lead.id, to: lost.id },
{ from: qualified.id, to: won.id },
{ from: qualified.id, to: lost.id },
{ from: lost.id, to: lead.id },
])
.orThrow();A move from Lead onto Won is then rejected: deals.update returns it in
rejected with the hint PIPELINE_TRANSITION_INVALID and keeps the other
changes of the batch, and deals.win fails with the same hint until the deal
is in Qualified.
With ReUI
- Kanban for the pipeline board. Read the columns, with their counts and
totals per currency, from
pipelines.board("deal", pipelineId). On drop, calldeals.updatewith the column's stage id asstageId, and move the card back when the change comes back inrejected. - Data Grid for the deal table: send a batched edit as one
deals.updatecall and show eachrejectedreason in a toast. Filters edit the filter tree of adefineListQueryondeals. - Timeline for the deal's history:
pipeline_stage_historyrows and comments, newest first, or the activity feed.
The ReUI Pro CRM blocks fit the same data (see wire it to ReUI on the deals page); their source is licensed per user, so copy them into your app from reui.io.
Last updated on