@odla-ai/crm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,755 @@
1
+ import { DataTableColumn, ComboboxItem } from '@odla-ai/ui/components';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+
5
+ /** Generic promoted columns a type's custom fields can claim for indexed
6
+ * sort/filter: four strings, three numbers, two dates. Slots are per-type
7
+ * virtual — every slot query is ANDed with `type`, so "person.n1" and
8
+ * "company.n1" can mean different fields. */
9
+ declare const CRM_SLOTS: readonly ["s1", "s2", "s3", "s4", "n1", "n2", "n3", "d1", "d2"];
10
+ /** One generic promoted column a field can claim. */
11
+ type CrmSlot = (typeof CRM_SLOTS)[number];
12
+ /** Consent state of a contact channel (see `applyConsentEvent`). */
13
+ declare const CONSENT_STATES: readonly ["subscribed", "unsubscribed", "bounced", "suppressed"];
14
+ /** A contact channel's consent standing. */
15
+ type ConsentState = (typeof CONSENT_STATES)[number];
16
+ /** Denormalized per-record contactability, folded from the primary email
17
+ * channel so list views can filter/sort on it: `none` = no email channel. */
18
+ declare const EMAIL_STATUSES: readonly ["ok", "unsubscribed", "bounced", "suppressed", "none"];
19
+ /** The record-level contactability fold. */
20
+ type EmailStatus = (typeof EMAIL_STATUSES)[number];
21
+ /** Activity kinds; `task` rows additionally carry status/dueAt/waitingOn. */
22
+ declare const ACTIVITY_KINDS: readonly ["note", "task", "call", "meeting", "stage_change", "system"];
23
+ /** What kind of feed entry an activity row is. */
24
+ type ActivityKind = (typeof ACTIVITY_KINDS)[number];
25
+ /** Task lifecycle for `kind: "task"` activities. */
26
+ declare const TASK_STATUSES: readonly ["open", "waiting", "done"];
27
+ /** Where a follow-up task stands. */
28
+ type TaskStatus = (typeof TASK_STATUSES)[number];
29
+
30
+ /** Wire-shape attribute value kinds odla-db stores. */
31
+ type AttrType = "string" | "number" | "boolean" | "date" | "json";
32
+ /** One serialized attribute: its type and index/uniqueness flags. */
33
+ interface SerializedAttr {
34
+ type: AttrType;
35
+ unique: boolean;
36
+ indexed: boolean;
37
+ optional: boolean;
38
+ }
39
+ /** One serialized namespace: its attribute map. */
40
+ interface SerializedEntity {
41
+ attrs: Record<string, SerializedAttr>;
42
+ }
43
+ /** One end of a serialized schema link. */
44
+ interface SerializedLinkEnd {
45
+ on: string;
46
+ has: "one" | "many";
47
+ label: string;
48
+ }
49
+ /** A serialized schema link (unused by crm — relations are rows). */
50
+ interface SerializedLink {
51
+ forward: SerializedLinkEnd;
52
+ reverse: SerializedLinkEnd;
53
+ }
54
+ /** The wire-shape schema POSTed to `/app/:id/schema`. */
55
+ interface SerializedSchema {
56
+ entities: Record<string, SerializedEntity>;
57
+ links: Record<string, SerializedLink>;
58
+ }
59
+
60
+ /** Per-namespace CEL rule strings (missing action = deny). */
61
+ interface CrmRule {
62
+ view?: string;
63
+ create?: string;
64
+ update?: string;
65
+ delete?: string;
66
+ }
67
+ /** Namespace → rule set, as installed at `/app/:id/admin/rules`. */
68
+ type CrmRules = Record<string, CrmRule>;
69
+
70
+ /** Scalar values odla-db attrs and where-clauses accept. */
71
+ type CrmScalar = string | number | boolean | null;
72
+ /** Attr payload of one op. Typed `any` on purpose: the real odla-db
73
+ * `transact` constrains attrs to its own `Value` type, and `any` is the one
74
+ * shape assignable in both directions with no cast. */
75
+ type CrmAttrs = Record<string, any>;
76
+ /** One CRM record of any configured type. Custom field values live complete
77
+ * in `fields`; slot columns (`s1`…`d2`) are an index mirror of the fields the
78
+ * type config promoted. */
79
+ interface CrmRecord {
80
+ id: string;
81
+ type: string;
82
+ name: string;
83
+ primaryEmail?: string;
84
+ stage?: string;
85
+ stageIndex?: number;
86
+ stageChangedAt?: number;
87
+ rank?: number;
88
+ score?: number;
89
+ ownerId?: string;
90
+ emailStatus?: EmailStatus;
91
+ clerkUserId?: string;
92
+ stripeCustomerId?: string;
93
+ subscriptionId?: string;
94
+ billingStatus?: string;
95
+ renewalAt?: number;
96
+ mrr?: number;
97
+ s1?: string;
98
+ s2?: string;
99
+ s3?: string;
100
+ s4?: string;
101
+ n1?: number;
102
+ n2?: number;
103
+ n3?: number;
104
+ d1?: number;
105
+ d2?: number;
106
+ fields: Record<string, unknown>;
107
+ searchText: string;
108
+ archived: boolean;
109
+ createdAt: number;
110
+ updatedAt: number;
111
+ archivedAt?: number;
112
+ }
113
+ /** A tag join row (`recordId:tag` natural key) — cohorts + provenance. */
114
+ interface CrmTag {
115
+ id: string;
116
+ key: string;
117
+ recordId: string;
118
+ tag: string;
119
+ createdAt: number;
120
+ }
121
+ /** A record↔record relation row with its config-declared label. */
122
+ interface CrmLink {
123
+ id: string;
124
+ key: string;
125
+ fromId: string;
126
+ toId: string;
127
+ relation: string;
128
+ createdAt: number;
129
+ }
130
+ /** A feed entry: note/call/meeting, follow-up task, or stage-change audit. */
131
+ interface CrmActivity {
132
+ id: string;
133
+ recordId: string;
134
+ kind: ActivityKind;
135
+ body: string;
136
+ status?: TaskStatus;
137
+ dueAt?: number;
138
+ waitingOn?: string;
139
+ assigneeId?: string;
140
+ authorId: string;
141
+ createdAt: number;
142
+ completedAt?: number;
143
+ meta?: Record<string, unknown>;
144
+ }
145
+ /** A consent-bearing contact channel (email/phone) of one record. */
146
+ interface CrmContactChannel {
147
+ id: string;
148
+ key: string;
149
+ recordId: string;
150
+ kind: "email" | "phone";
151
+ value: string;
152
+ isPrimary: boolean;
153
+ consent: ConsentState;
154
+ consentAt: number;
155
+ consentSource?: string;
156
+ unsubscribeToken: string;
157
+ createdAt: number;
158
+ }
159
+ /** A saved list question: filters + sort + columns, personal or shared. */
160
+ interface CrmView {
161
+ id: string;
162
+ name: string;
163
+ type: string;
164
+ ownerId?: string;
165
+ shared: boolean;
166
+ filters: Record<string, unknown>;
167
+ sort: {
168
+ field: string;
169
+ dir: "asc" | "desc";
170
+ } | null;
171
+ columns: string[];
172
+ createdAt: number;
173
+ updatedAt: number;
174
+ }
175
+ /** One owner-editable template stored on the config row. The template CLASS
176
+ * (transactional vs marketing) is code config (`defineCrm` templates), not
177
+ * data — an owner edit can't reclassify a send past the consent gate. */
178
+ interface StoredTemplate {
179
+ subject: string;
180
+ text: string;
181
+ enabled: boolean;
182
+ }
183
+ /** The runtime-editable crm_config singleton as read back. */
184
+ interface CrmConfigRow {
185
+ id: string;
186
+ key: string;
187
+ notificationEmail?: string;
188
+ replyTo?: string;
189
+ debugEmail?: string;
190
+ emailTemplates: Record<string, StoredTemplate>;
191
+ settings: Record<string, unknown>;
192
+ updatedAt: number;
193
+ }
194
+ /** Outcome of validating + coercing input for a type (see `prepare`). */
195
+ type PreparedWrite = {
196
+ ok: true;
197
+ attrs: CrmAttrs;
198
+ } | {
199
+ ok: false;
200
+ errors: Record<string, string>;
201
+ };
202
+
203
+ /** Value kinds a custom field can hold. `email`/`url`/`enum` are validated
204
+ * strings; `date` accepts epoch ms or ISO strings and stores epoch ms. */
205
+ type FieldType = "string" | "number" | "boolean" | "date" | "email" | "url" | "enum" | "json";
206
+ /** One custom field of a record type: value kind, validation, slot promotion. */
207
+ interface FieldDef {
208
+ type: FieldType;
209
+ label?: string;
210
+ required?: boolean;
211
+ /** Allowed values — `enum` fields only. */
212
+ options?: readonly string[];
213
+ /** Promote to an indexed slot column for server-side sort/filter. String-ish
214
+ * fields take `s1`–`s4`, numbers `n1`–`n3`, dates `d1`–`d2`. */
215
+ slot?: CrmSlot;
216
+ /** Include in the FTS haystack. Defaults to true for string-ish fields. */
217
+ search?: boolean;
218
+ }
219
+ /** One pipeline stage; declaration order is the sort order (`stageIndex`). */
220
+ interface StageDef {
221
+ id: string;
222
+ label?: string;
223
+ /** Terminal stages have no outgoing transitions unless `transitions`
224
+ * explicitly declares some. */
225
+ terminal?: boolean;
226
+ }
227
+ /** A type's stage machine: ordered stages, allowed edges, gates. */
228
+ interface PipelineDef {
229
+ stages: readonly StageDef[];
230
+ /** Allowed edges per stage id. A stage with no entry accepts any move
231
+ * (unless terminal). */
232
+ transitions?: Record<string, readonly string[]>;
233
+ /** Per-target-stage gate: return an error string to block, null to allow. */
234
+ gates?: Record<string, (record: CrmRecord) => string | null>;
235
+ }
236
+ /** Opt-in built-in concerns for a type (identity/billing/email/rank). */
237
+ interface TypeFacets {
238
+ identity?: boolean;
239
+ billing?: boolean;
240
+ email?: boolean;
241
+ rank?: "manual" | "score" | "both";
242
+ }
243
+ /** One record type: its fields, pipeline, facets, and hooks. */
244
+ interface TypeDef {
245
+ label: string;
246
+ labelPlural?: string;
247
+ /** Field mapped to the promoted `name` column. Default `"name"`. */
248
+ nameField?: string;
249
+ /** `email`-typed field mapped to `primaryEmail` (lowercased) and backed by
250
+ * a consent-bearing contact channel. */
251
+ emailField?: string;
252
+ fields: Record<string, FieldDef>;
253
+ pipeline?: PipelineDef;
254
+ facets?: TypeFacets;
255
+ /** Computes the record's `score` column (rank facet "score"/"both"). */
256
+ scorer?: (record: CrmRecord) => number;
257
+ /** Post-commit hooks per target stage id — e.g. S&S "approved" promotes the
258
+ * member's Clerk role. Fired by the route layer AFTER the stage write. */
259
+ onTransition?: Record<string, (record: CrmRecord) => void | Promise<void>>;
260
+ }
261
+ /** A typed record↔record relation (e.g. person works_at company). */
262
+ interface RelationDef {
263
+ from: string;
264
+ to: string;
265
+ label: string;
266
+ reverseLabel?: string;
267
+ }
268
+ /** Declares a template's contract in code: its variables and its consent
269
+ * CLASS. Subject/body/enabled live on the data row (owner-editable). */
270
+ interface TemplateSpec {
271
+ vars: readonly string[];
272
+ class: "transactional" | "marketing";
273
+ defaults?: {
274
+ subject: string;
275
+ text: string;
276
+ };
277
+ }
278
+ /** The whole app-level CRM configuration `defineCrm` validates. */
279
+ interface CrmConfig {
280
+ types: Record<string, TypeDef>;
281
+ relations?: Record<string, RelationDef>;
282
+ templates?: Record<string, TemplateSpec>;
283
+ }
284
+ /** The resolved engine `defineCrm` returns: static schema/rules plus the
285
+ * config-aware operations the route factory and ops modules run on. */
286
+ interface Crm {
287
+ config: CrmConfig;
288
+ schema: SerializedSchema;
289
+ rules: CrmRules;
290
+ type(name: string): TypeDef;
291
+ prepare(type: string, input: Record<string, unknown>, existing?: CrmRecord): PreparedWrite;
292
+ canTransition(type: string, record: CrmRecord, to: string): string | null;
293
+ initialStage(type: string): string | undefined;
294
+ stageIndex(type: string, stage: string): number;
295
+ }
296
+
297
+ /** Comparison filter for one slotted custom field. */
298
+ interface FieldFilter {
299
+ eq?: CrmScalar;
300
+ in?: CrmScalar[];
301
+ gte?: number | string;
302
+ lte?: number | string;
303
+ }
304
+ /** The serializable filter set (also the saved-view `filters` payload). */
305
+ interface ViewFilters {
306
+ search?: string;
307
+ stage?: string[];
308
+ emailStatus?: string[];
309
+ billingStatus?: string[];
310
+ ownerId?: string;
311
+ /** Exact tag — resolved to record ids first (join rows). */
312
+ tag?: string;
313
+ /** Include archived records (default: live only). */
314
+ archived?: boolean;
315
+ /** Slotted-field predicates, keyed by config field name. */
316
+ fields?: Record<string, FieldFilter>;
317
+ }
318
+ /** One-field sort (odla-db orders on exactly one indexed field). */
319
+ interface CrmSort {
320
+ field: string;
321
+ dir: "asc" | "desc";
322
+ }
323
+ /** Everything a list window can ask for: filters + sort + paging. */
324
+ interface CrmListParams extends ViewFilters {
325
+ type: string;
326
+ sort?: CrmSort;
327
+ limit?: number;
328
+ offset?: number;
329
+ }
330
+
331
+ /** The serializable definition of a saved view. */
332
+ interface ViewSpec {
333
+ name: string;
334
+ type: string;
335
+ filters: ViewFilters;
336
+ sort: CrmSort | null;
337
+ columns: string[];
338
+ shared: boolean;
339
+ }
340
+
341
+ /** Partial config update; explicit null clears an address. */
342
+ interface ConfigPatch {
343
+ notificationEmail?: string | null;
344
+ replyTo?: string | null;
345
+ debugEmail?: string | null;
346
+ emailTemplates?: Record<string, Partial<StoredTemplate>>;
347
+ settings?: Record<string, unknown>;
348
+ }
349
+
350
+ /** Tile counts for one record type. */
351
+ interface TypeSummary {
352
+ type: string;
353
+ total: number;
354
+ /** Live records per pipeline stage (types with a pipeline). */
355
+ stages: Record<string, number>;
356
+ /** Open + waiting follow-up tasks across all records. */
357
+ openTasks: number;
358
+ }
359
+
360
+ /** Where the routes live and how to authenticate against them. */
361
+ interface CrmClientOptions {
362
+ /** Origin of the host worker, e.g. "" (same-origin) or a full URL. */
363
+ baseUrl?: string;
364
+ /** Route mount point. Default "/api/crm". */
365
+ basePath?: string;
366
+ fetch?: typeof globalThis.fetch;
367
+ /** Per-request auth headers (called each request — tokens rotate). */
368
+ headers?: () => Promise<Record<string, string>> | Record<string, string>;
369
+ }
370
+ /** A record composed with its tags, channels, and links. */
371
+ interface RecordDetail {
372
+ record: CrmRecord;
373
+ tags: CrmTag[];
374
+ channels: CrmContactChannel[];
375
+ links: CrmLink[];
376
+ }
377
+ /** One list window plus the total matching count. */
378
+ interface RecordPage {
379
+ records: CrmRecord[];
380
+ total: number;
381
+ limit: number;
382
+ offset: number;
383
+ }
384
+ /** Typed access to every crm route. Methods reject with
385
+ * {@link CrmClientError} on non-2xx responses. */
386
+ declare class CrmClient {
387
+ private readonly base;
388
+ private readonly doFetch;
389
+ private readonly headers?;
390
+ constructor(options?: CrmClientOptions);
391
+ private request;
392
+ listRecords(params: CrmListParams): Promise<RecordPage>;
393
+ getRecord(id: string): Promise<RecordDetail>;
394
+ createRecord(body: {
395
+ type: string;
396
+ input: Record<string, unknown>;
397
+ ownerId?: string;
398
+ stage?: string;
399
+ mutationId?: string;
400
+ }): Promise<{
401
+ id: string;
402
+ duplicate: boolean;
403
+ record: CrmRecord;
404
+ }>;
405
+ updateRecord(id: string, body: {
406
+ input?: Record<string, unknown>;
407
+ ownerId?: string | null;
408
+ mutationId?: string;
409
+ }): Promise<{
410
+ record: CrmRecord;
411
+ duplicate: boolean;
412
+ }>;
413
+ setArchived(id: string, archived: boolean): Promise<{
414
+ duplicate: boolean;
415
+ }>;
416
+ setStage(id: string, to: string, mutationId?: string): Promise<{
417
+ record: CrmRecord;
418
+ from: string | null;
419
+ duplicate: boolean;
420
+ hookError?: string;
421
+ }>;
422
+ setRank(id: string, body: {
423
+ beforeId?: string;
424
+ afterId?: string;
425
+ }): Promise<{
426
+ rank: number;
427
+ rebalanceNeeded: boolean;
428
+ }>;
429
+ addTag(id: string, tag: string): Promise<{
430
+ tag: string;
431
+ duplicate: boolean;
432
+ }>;
433
+ removeTag(id: string, tag: string): Promise<{
434
+ duplicate: boolean;
435
+ }>;
436
+ setLink(id: string, body: {
437
+ relation: string;
438
+ toId: string;
439
+ remove?: boolean;
440
+ }): Promise<{
441
+ duplicate: boolean;
442
+ }>;
443
+ linkIdentity(id: string, email?: string): Promise<{
444
+ linked: boolean;
445
+ clerkUserId?: string;
446
+ }>;
447
+ sendEmail(id: string, body: {
448
+ templateId: string;
449
+ vars?: Record<string, string>;
450
+ dedupeKey?: string;
451
+ channelId?: string;
452
+ force?: boolean;
453
+ }): Promise<{
454
+ sent: boolean;
455
+ reason?: string;
456
+ }>;
457
+ listActivities(recordId: string, opts?: {
458
+ kind?: string;
459
+ limit?: number;
460
+ }): Promise<{
461
+ activities: CrmActivity[];
462
+ }>;
463
+ addActivity(recordId: string, body: {
464
+ kind: string;
465
+ body: string;
466
+ dueAt?: number;
467
+ assigneeId?: string;
468
+ waitingOn?: string;
469
+ }): Promise<{
470
+ id: string;
471
+ duplicate: boolean;
472
+ }>;
473
+ updateTask(id: string, body: {
474
+ status?: string;
475
+ dueAt?: number | null;
476
+ assigneeId?: string | null;
477
+ waitingOn?: string | null;
478
+ body?: string;
479
+ }): Promise<{
480
+ activity: CrmActivity;
481
+ duplicate: boolean;
482
+ }>;
483
+ listTasks(opts?: {
484
+ assigneeId?: string;
485
+ status?: string[];
486
+ limit?: number;
487
+ }): Promise<{
488
+ tasks: CrmActivity[];
489
+ }>;
490
+ listViews(type?: string): Promise<{
491
+ views: CrmView[];
492
+ }>;
493
+ saveView(spec: ViewSpec): Promise<{
494
+ id: string;
495
+ duplicate: boolean;
496
+ }>;
497
+ updateView(id: string, spec: Partial<ViewSpec>): Promise<{
498
+ view: CrmView;
499
+ duplicate: boolean;
500
+ }>;
501
+ deleteView(id: string): Promise<{
502
+ duplicate: boolean;
503
+ }>;
504
+ summary(type: string): Promise<TypeSummary>;
505
+ getConfig(): Promise<{
506
+ config: CrmConfigRow | null;
507
+ }>;
508
+ saveConfig(patch: ConfigPatch): Promise<{
509
+ config: CrmConfigRow;
510
+ duplicate: boolean;
511
+ }>;
512
+ emailLog(opts?: {
513
+ recordId?: string;
514
+ limit?: number;
515
+ }): Promise<{
516
+ log: Record<string, unknown>[];
517
+ }>;
518
+ rebalance(type: string): Promise<{
519
+ count: number;
520
+ }>;
521
+ }
522
+
523
+ /** The list state `useCrmQuery` maintains and the ways to move it. */
524
+ interface CrmQuery {
525
+ params: CrmListParams;
526
+ page: RecordPage | null;
527
+ loading: boolean;
528
+ error: string | null;
529
+ /** Merge filter/sort changes; resets the offset (a new question starts at
530
+ * page one). */
531
+ update(patch: Partial<Omit<CrmListParams, "type">>): void;
532
+ /** Move the window without resetting anything else. */
533
+ setOffset(offset: number): void;
534
+ setSort(sort: CrmSort): void;
535
+ setSearch(search: string): void;
536
+ refresh(): void;
537
+ }
538
+ /** Server-driven list state for one record type. Refetches on every param
539
+ * change; out-of-order responses are discarded, so a slow page never
540
+ * overwrites a newer one. */
541
+ declare function useCrmQuery(client: CrmClient, type: string, initial?: Partial<Omit<CrmListParams, "type">>): CrmQuery;
542
+ /** The detail state `useCrmRecord` maintains. */
543
+ interface CrmRecordState {
544
+ detail: RecordDetail | null;
545
+ loading: boolean;
546
+ error: string | null;
547
+ refresh(): void;
548
+ }
549
+ /** One record's composed detail (record + tags + channels + links). */
550
+ declare function useCrmRecord(client: CrmClient, id: string | null): CrmRecordState;
551
+
552
+ /** Map a UI column key to the server sort field, or null when unsortable. */
553
+ declare function sortFieldFor(crm: Crm, type: string, key: string): string | null;
554
+ /** DataTable columns for `keys` — promoted names or config field names.
555
+ * Unknown keys are skipped (a stale saved view never crashes the list). */
556
+ declare function columnsFor(crm: Crm, type: string, keys: readonly string[]): DataTableColumn<CrmRecord>[];
557
+ /** The default column set for a type: name, pipeline stage when there is
558
+ * one, email when the type has an email field, then its slotted fields,
559
+ * then updatedAt. */
560
+ declare function defaultColumns(crm: Crm, type: string): string[];
561
+
562
+ /** Props for {@link CrmList}. */
563
+ interface CrmListProps {
564
+ crm: Crm;
565
+ type: string;
566
+ /** The list state from `useCrmQuery` — owned by the caller so the shell,
567
+ * bulk bar, and view editor can share it. */
568
+ query: CrmQuery;
569
+ /** Column keys (promoted or config field names). Default: the type's
570
+ * `defaultColumns`. */
571
+ columns?: readonly string[];
572
+ onOpenRecord?: (record: CrmRecord) => void;
573
+ selectable?: boolean;
574
+ selected?: readonly (string | number)[];
575
+ onSelectionChange?: (keys: (string | number)[]) => void;
576
+ /** Extra toolbar content (bulk bar, view editor…). */
577
+ toolbar?: ReactNode;
578
+ }
579
+ /**
580
+ * Server-driven record list. Sort clicks and the filter box call back into
581
+ * the query (the table renders rows as given); the stage chips filter types
582
+ * with a pipeline; Pagination walks the offset window against the reported
583
+ * total.
584
+ */
585
+ declare function CrmList({ crm, type, query, columns, onOpenRecord, selectable, selected, onSelectionChange, toolbar, }: CrmListProps): react.JSX.Element;
586
+
587
+ /** Props for {@link CrmShell}. */
588
+ interface CrmShellProps {
589
+ crm: Crm;
590
+ /** Active navigation state (a type, optionally a saved view of it). */
591
+ active: {
592
+ type: string;
593
+ viewId?: string;
594
+ };
595
+ /** Saved views for the active type (from `client.listViews(type)`). */
596
+ views?: readonly CrmView[];
597
+ onNavigate: (target: {
598
+ type: string;
599
+ viewId?: string;
600
+ }) => void;
601
+ /** Renders a Settings item that fires this when present. */
602
+ onOpenSettings?: () => void;
603
+ header?: ReactNode;
604
+ children: ReactNode;
605
+ }
606
+ /**
607
+ * Left search-and-settings frame for a CRM admin surface. The sidebar lists
608
+ * every configured record type, the active type's saved views, and an
609
+ * optional settings entry; the main slot is yours (usually a `CrmList` +
610
+ * record panel).
611
+ */
612
+ declare function CrmShell({ crm, active, views, onNavigate, onOpenSettings, header, children }: CrmShellProps): react.JSX.Element;
613
+
614
+ /** Props for {@link RecordPanel}. */
615
+ interface RecordPanelProps {
616
+ crm: Crm;
617
+ detail: RecordDetail;
618
+ onSaveFields: (input: Record<string, unknown>) => void;
619
+ onMoveStage: (to: string) => Promise<unknown>;
620
+ onAddTag: (tag: string) => void;
621
+ onRemoveTag: (tag: string) => void;
622
+ onLinkIdentity?: () => void;
623
+ saving?: boolean;
624
+ fieldErrors?: Record<string, string>;
625
+ /** The Activity tab's content — pass an `ActivityFeed` wired to the
626
+ * record's feed (data loading stays with the caller). */
627
+ activitySlot?: ReactNode;
628
+ }
629
+ /**
630
+ * Facet-composed record detail. The panel renders what the type declares:
631
+ * pipeline control only with a pipeline, identity/billing cards only when
632
+ * those facets are on.
633
+ */
634
+ declare function RecordPanel({ crm, detail, onSaveFields, onMoveStage, onAddTag, onRemoveTag, onLinkIdentity, saving, fieldErrors, activitySlot, }: RecordPanelProps): react.JSX.Element;
635
+
636
+ /** Props for {@link FieldsForm}. */
637
+ interface FieldsFormProps {
638
+ crm: Crm;
639
+ type: string;
640
+ /** Existing record for edit mode; omit to create. */
641
+ record?: CrmRecord | null;
642
+ onSubmit: (input: Record<string, unknown>) => void;
643
+ submitting?: boolean;
644
+ /** Per-field errors from the server's 400 (`CrmClientError.fields`). */
645
+ errors?: Record<string, string>;
646
+ submitLabel?: string;
647
+ }
648
+ /**
649
+ * Config-driven create/edit form. Drafts locally, submits the full input
650
+ * map (create) or only what the admin changed is still fine — the server
651
+ * merges partially. Server-side field errors render under their inputs.
652
+ */
653
+ declare function FieldsForm({ crm, type, record, onSubmit, submitting, errors, submitLabel, }: FieldsFormProps): react.JSX.Element;
654
+
655
+ /** Props for {@link StageControl}. */
656
+ interface StageControlProps {
657
+ crm: Crm;
658
+ record: CrmRecord;
659
+ /** Perform the move (usually `client.setStage`); throw/reject to surface
660
+ * the error inline. */
661
+ onMove: (to: string) => Promise<unknown>;
662
+ disabled?: boolean;
663
+ }
664
+ /** Stage selector + Move button for records whose type has a pipeline.
665
+ * Renders nothing for pipeline-less types. */
666
+ declare function StageControl({ crm, record, onMove, disabled }: StageControlProps): react.JSX.Element | null;
667
+
668
+ /** Props for {@link TagEditor}. */
669
+ interface TagEditorProps {
670
+ tags: readonly CrmTag[];
671
+ onAdd: (tag: string) => void;
672
+ onRemove: (tag: string) => void;
673
+ /** Suggestion source (e.g. distinct tags in use). Default: none. */
674
+ suggest?: (query: string) => Promise<readonly ComboboxItem[]> | readonly ComboboxItem[];
675
+ disabled?: boolean;
676
+ }
677
+ /** Chip list + typeahead adder over the `.chips` contract. */
678
+ declare function TagEditor({ tags, onAdd, onRemove, suggest, disabled }: TagEditorProps): react.JSX.Element;
679
+
680
+ /** Props for {@link IdentityCard}. */
681
+ interface IdentityCardProps {
682
+ record: CrmRecord;
683
+ /** Attempt the $users email match (usually `client.linkIdentity`). */
684
+ onLink?: () => void;
685
+ linking?: boolean;
686
+ }
687
+ /** Clerk account linkage: the matched user id, or a "find account" action. */
688
+ declare function IdentityCard({ record, onLink, linking }: IdentityCardProps): react.JSX.Element;
689
+ /** The billing cache columns, read-only (adapters land with @odla-ai/stripe). */
690
+ declare function BillingCard({ record }: {
691
+ record: CrmRecord;
692
+ }): react.JSX.Element;
693
+ /** Props for {@link ChannelsCard}. */
694
+ interface ChannelsCardProps {
695
+ channels: readonly CrmContactChannel[];
696
+ }
697
+ /** Contact channels with consent badges — the truthful answer to "may we
698
+ * email this person?". */
699
+ declare function ChannelsCard({ channels }: ChannelsCardProps): react.JSX.Element;
700
+
701
+ /** Props for {@link ActivityFeed}. */
702
+ interface ActivityFeedProps {
703
+ activities: readonly CrmActivity[];
704
+ onAddNote: (body: string) => void;
705
+ onAddTask: (task: {
706
+ body: string;
707
+ dueAt?: number;
708
+ waitingOn?: string;
709
+ }) => void;
710
+ /** Toggle a task between done and open. */
711
+ onToggleTask: (activity: CrmActivity, done: boolean) => void;
712
+ busy?: boolean;
713
+ }
714
+ /** Composer (note ⇄ task) above the newest-first feed. */
715
+ declare function ActivityFeed({ activities, onAddNote, onAddTask, onToggleTask, busy }: ActivityFeedProps): react.JSX.Element;
716
+
717
+ /** One bulk operation offered over the current selection. */
718
+ interface BulkAction {
719
+ id: string;
720
+ label: string;
721
+ run: (selected: readonly (string | number)[]) => void | Promise<void>;
722
+ }
723
+ /** Props for {@link BulkBar}. */
724
+ interface BulkBarProps {
725
+ selected: readonly (string | number)[];
726
+ actions: readonly BulkAction[];
727
+ onClear: () => void;
728
+ busy?: boolean;
729
+ }
730
+ /** Renders nothing until something is selected. */
731
+ declare function BulkBar({ selected, actions, onClear, busy }: BulkBarProps): react.JSX.Element | null;
732
+
733
+ /** Props for {@link ViewEditor}. */
734
+ interface ViewEditorProps {
735
+ /** The current list state to snapshot (from `useCrmQuery().params`). */
736
+ current: {
737
+ type: string;
738
+ filters: ViewFilters;
739
+ sort: CrmSort | null;
740
+ columns: string[];
741
+ };
742
+ /** Persist (usually `client.saveView`); reject to surface the error. */
743
+ onSave: (spec: {
744
+ name: string;
745
+ type: string;
746
+ filters: ViewFilters;
747
+ sort: CrmSort | null;
748
+ columns: string[];
749
+ shared: boolean;
750
+ }) => Promise<unknown>;
751
+ }
752
+ /** Name + shared toggle + save; collapses back to a button after saving. */
753
+ declare function ViewEditor({ current, onSave }: ViewEditorProps): react.JSX.Element;
754
+
755
+ export { ActivityFeed, type ActivityFeedProps, BillingCard, type BulkAction, BulkBar, type BulkBarProps, ChannelsCard, type ChannelsCardProps, CrmList, type CrmListProps, type CrmQuery, type CrmRecordState, CrmShell, type CrmShellProps, FieldsForm, type FieldsFormProps, IdentityCard, type IdentityCardProps, RecordPanel, type RecordPanelProps, StageControl, type StageControlProps, TagEditor, type TagEditorProps, ViewEditor, type ViewEditorProps, columnsFor, defaultColumns, sortFieldFor, useCrmQuery, useCrmRecord };