/sales is the revenue-data surface: an analytics dashboard over real federated
lead data, a read-only Leads Viewer that browses every registered lead
collection, and the Data Export console. It is one of three views over the same
lead stores, alongside Audience (capture) and
Lead Attribution (source).
All three read surfaces derive from the single collection registry in
lib/services/sales/lead-collections.ts — there is deliberately no second
source list.
| Route | Purpose | Guard |
|---|---|---|
/sales | Analytics dashboard (volume, sources, trends over 7/30/90 days) | org:analytics:view (layout.tsx) |
/sales/leads | Leads Viewer — paginated, server-side search/sort/filter over any registered collection | org:analytics:view (route) + org:leads:view / org:analytics:view (API) |
/sales/export | Data Export console | org:analytics:export or org:leads:export (API) |
The subtree gate lives in
layout.tsx
via requirePermission("org:analytics:view"). PII inside the viewer and
exports resolves from org:observability:pii_view — uncleared callers get
masked values (es****@matters.ai), never blanks or raw data.
| Route | Purpose | Guard |
|---|---|---|
GET /api/workspace/sales/analytics | Federated rollups for the dashboard | org:analytics:view or org:leads:view |
GET /api/workspace/sales/leads | Paginated collection browser (25 rows/page) | org:leads:view or org:analytics:view |
POST /api/workspace/sales/export | Preview or download (CSV / XLSX / JSON / NDJSON) | org:analytics:export or org:leads:export |
GET /api/workspace/sales/export/schema | Per-source field discovery | org:analytics:export or org:leads:export |
/api/workspace/sales/export/presets | Saved export recipes | org:analytics:export or org:leads:export |
/api/workspace/sales/export/history | Past runs, read from the audit trail | org:analytics:export or org:leads:export |
/api/workspace/sales/export/archive | Re-downloadable saved artifacts | org:analytics:export or org:leads:export |
/api/workspace/sales/export/schedules | Scheduled (cron) exports | org:analytics:export or org:leads:export |
Search, sort, and filters are all server-side — the table paginates at 25 rows,
so client-side filtering would lie. Rows arrive as the raw document with
canonical values overlaid (see the workEmail-vs-email regression in
Data Export), and the column picker is remembered per
collection in localStorage. The Export these button deep-links into the
export console via /sales/export?sources=<id>&search=<q>.
Deep-dived at Data Export (Sales): multi-source merge, canonical schema, live preview, presets, schedules, GridFS-archived artifacts, and the audit trail.
leadJourney on lead rowsorg:analytics:*, org:leads:*