@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.
- package/README.md +114 -0
- package/dist/index.cjs +2184 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1290 -0
- package/dist/index.d.ts +1290 -0
- package/dist/index.js +2161 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/index.d.ts +755 -0
- package/dist/ui/index.js +775 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +83 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1290 @@
|
|
|
1
|
+
/** The odla-db namespaces @odla-ai/crm installs and writes. */
|
|
2
|
+
declare const CRM_NS: {
|
|
3
|
+
readonly record: "crm_record";
|
|
4
|
+
readonly tag: "crm_tag";
|
|
5
|
+
readonly link: "crm_link";
|
|
6
|
+
readonly activity: "crm_activity";
|
|
7
|
+
readonly channel: "crm_contact_channel";
|
|
8
|
+
readonly emailLog: "crm_email_log";
|
|
9
|
+
readonly view: "crm_view";
|
|
10
|
+
readonly config: "crm_config";
|
|
11
|
+
};
|
|
12
|
+
/** Generic promoted columns a type's custom fields can claim for indexed
|
|
13
|
+
* sort/filter: four strings, three numbers, two dates. Slots are per-type
|
|
14
|
+
* virtual — every slot query is ANDed with `type`, so "person.n1" and
|
|
15
|
+
* "company.n1" can mean different fields. */
|
|
16
|
+
declare const CRM_SLOTS: readonly ["s1", "s2", "s3", "s4", "n1", "n2", "n3", "d1", "d2"];
|
|
17
|
+
/** One generic promoted column a field can claim. */
|
|
18
|
+
type CrmSlot = (typeof CRM_SLOTS)[number];
|
|
19
|
+
/** Consent state of a contact channel (see `applyConsentEvent`). */
|
|
20
|
+
declare const CONSENT_STATES: readonly ["subscribed", "unsubscribed", "bounced", "suppressed"];
|
|
21
|
+
/** A contact channel's consent standing. */
|
|
22
|
+
type ConsentState = (typeof CONSENT_STATES)[number];
|
|
23
|
+
/** Denormalized per-record contactability, folded from the primary email
|
|
24
|
+
* channel so list views can filter/sort on it: `none` = no email channel. */
|
|
25
|
+
declare const EMAIL_STATUSES: readonly ["ok", "unsubscribed", "bounced", "suppressed", "none"];
|
|
26
|
+
/** The record-level contactability fold. */
|
|
27
|
+
type EmailStatus = (typeof EMAIL_STATUSES)[number];
|
|
28
|
+
/** Activity kinds; `task` rows additionally carry status/dueAt/waitingOn. */
|
|
29
|
+
declare const ACTIVITY_KINDS: readonly ["note", "task", "call", "meeting", "stage_change", "system"];
|
|
30
|
+
/** What kind of feed entry an activity row is. */
|
|
31
|
+
type ActivityKind = (typeof ACTIVITY_KINDS)[number];
|
|
32
|
+
/** Task lifecycle for `kind: "task"` activities. */
|
|
33
|
+
declare const TASK_STATUSES: readonly ["open", "waiting", "done"];
|
|
34
|
+
/** Where a follow-up task stands. */
|
|
35
|
+
type TaskStatus = (typeof TASK_STATUSES)[number];
|
|
36
|
+
/** Promoted `crm_record` columns list queries may sort on, beyond per-type
|
|
37
|
+
* slot fields. All are indexed in the schema — odla-db orders on exactly one
|
|
38
|
+
* indexed field per query. */
|
|
39
|
+
declare const SORTABLE_COLUMNS: readonly ["name", "primaryEmail", "stageIndex", "stageChangedAt", "rank", "score", "emailStatus", "billingStatus", "renewalAt", "createdAt", "updatedAt"];
|
|
40
|
+
/** The singleton `crm_config` row's natural key. */
|
|
41
|
+
declare const CONFIG_KEY = "default";
|
|
42
|
+
/** Server list-window defaults, aligned with odla-db's query limits
|
|
43
|
+
* (default 100, max 1000). */
|
|
44
|
+
declare const DEFAULT_LIMIT = 50;
|
|
45
|
+
/** Hard per-window row cap for list routes (odla-db allows up to 1000). */
|
|
46
|
+
declare const MAX_LIMIT = 200;
|
|
47
|
+
|
|
48
|
+
/** Wire-shape attribute value kinds odla-db stores. */
|
|
49
|
+
type AttrType = "string" | "number" | "boolean" | "date" | "json";
|
|
50
|
+
/** One serialized attribute: its type and index/uniqueness flags. */
|
|
51
|
+
interface SerializedAttr {
|
|
52
|
+
type: AttrType;
|
|
53
|
+
unique: boolean;
|
|
54
|
+
indexed: boolean;
|
|
55
|
+
optional: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** One serialized namespace: its attribute map. */
|
|
58
|
+
interface SerializedEntity {
|
|
59
|
+
attrs: Record<string, SerializedAttr>;
|
|
60
|
+
}
|
|
61
|
+
/** One end of a serialized schema link. */
|
|
62
|
+
interface SerializedLinkEnd {
|
|
63
|
+
on: string;
|
|
64
|
+
has: "one" | "many";
|
|
65
|
+
label: string;
|
|
66
|
+
}
|
|
67
|
+
/** A serialized schema link (unused by crm — relations are rows). */
|
|
68
|
+
interface SerializedLink {
|
|
69
|
+
forward: SerializedLinkEnd;
|
|
70
|
+
reverse: SerializedLinkEnd;
|
|
71
|
+
}
|
|
72
|
+
/** The wire-shape schema POSTed to `/app/:id/schema`. */
|
|
73
|
+
interface SerializedSchema {
|
|
74
|
+
entities: Record<string, SerializedEntity>;
|
|
75
|
+
links: Record<string, SerializedLink>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The pre-serialized (wire-shape) odla-db schema for the eight crm
|
|
79
|
+
* namespaces; POST it to `/app/:id/schema` as `{ schema: CRM_SCHEMA }`.
|
|
80
|
+
* One generic `crm_record` holds every record type (the type registry is
|
|
81
|
+
* app config, not schema); natural-key uniqueness on tags, links, channels,
|
|
82
|
+
* and the config row makes those writes idempotent upserts.
|
|
83
|
+
*/
|
|
84
|
+
declare const CRM_SCHEMA: SerializedSchema;
|
|
85
|
+
|
|
86
|
+
/** Per-namespace CEL rule strings (missing action = deny). */
|
|
87
|
+
interface CrmRule {
|
|
88
|
+
view?: string;
|
|
89
|
+
create?: string;
|
|
90
|
+
update?: string;
|
|
91
|
+
delete?: string;
|
|
92
|
+
}
|
|
93
|
+
/** Namespace → rule set, as installed at `/app/:id/admin/rules`. */
|
|
94
|
+
type CrmRules = Record<string, CrmRule>;
|
|
95
|
+
/**
|
|
96
|
+
* Deny-all rules for every crm namespace; install at `/app/:id/admin/rules`.
|
|
97
|
+
* The route factory (admin key) is the only door — see the header note for
|
|
98
|
+
* why the CRM cannot be rule-governed client-side.
|
|
99
|
+
*/
|
|
100
|
+
declare const CRM_RULES: CrmRules;
|
|
101
|
+
/**
|
|
102
|
+
* Rules factory, mirroring `chatRules()`. Today it returns the deny-all set;
|
|
103
|
+
* it exists so a future member-facing surface (e.g. "records I own are
|
|
104
|
+
* visible to me") can widen specific namespaces without apps changing their
|
|
105
|
+
* provisioning call shape.
|
|
106
|
+
*/
|
|
107
|
+
declare function crmRules(): CrmRules;
|
|
108
|
+
|
|
109
|
+
/** Scalar values odla-db attrs and where-clauses accept. */
|
|
110
|
+
type CrmScalar = string | number | boolean | null;
|
|
111
|
+
/** Natural-key lookup ref for idempotent upserts (odla-db lookup shape). */
|
|
112
|
+
interface CrmLookup {
|
|
113
|
+
ns: string;
|
|
114
|
+
attr: string;
|
|
115
|
+
value: CrmScalar;
|
|
116
|
+
}
|
|
117
|
+
/** How an op names its row: a raw id, or a natural-key lookup. */
|
|
118
|
+
type CrmEntityRef = string | CrmLookup;
|
|
119
|
+
/** Attr payload of one op. Typed `any` on purpose: the real odla-db
|
|
120
|
+
* `transact` constrains attrs to its own `Value` type, and `any` is the one
|
|
121
|
+
* shape assignable in both directions with no cast. */
|
|
122
|
+
type CrmAttrs = Record<string, any>;
|
|
123
|
+
/** One transact operation (update = attr-merge upsert). */
|
|
124
|
+
type CrmOp = {
|
|
125
|
+
t: "update";
|
|
126
|
+
ns: string;
|
|
127
|
+
id: CrmEntityRef;
|
|
128
|
+
attrs: CrmAttrs;
|
|
129
|
+
} | {
|
|
130
|
+
t: "merge";
|
|
131
|
+
ns: string;
|
|
132
|
+
id: CrmEntityRef;
|
|
133
|
+
attrs: CrmAttrs;
|
|
134
|
+
} | {
|
|
135
|
+
t: "delete";
|
|
136
|
+
ns: string;
|
|
137
|
+
id: CrmEntityRef;
|
|
138
|
+
};
|
|
139
|
+
/** An InstaQL-style query object (namespace → node). */
|
|
140
|
+
type CrmQuery = Record<string, unknown>;
|
|
141
|
+
/** A row as odla-db returns it: id plus attrs. */
|
|
142
|
+
type CrmRow = {
|
|
143
|
+
id: string;
|
|
144
|
+
} & Record<string, unknown>;
|
|
145
|
+
/** Query result: namespace → rows. */
|
|
146
|
+
type CrmResult = Record<string, CrmRow[]>;
|
|
147
|
+
/** Aggregate request/response (the odla-db `aggregate` endpoint's shape). */
|
|
148
|
+
interface CrmAggregateSpec {
|
|
149
|
+
count?: boolean;
|
|
150
|
+
sum?: string;
|
|
151
|
+
avg?: string;
|
|
152
|
+
min?: string;
|
|
153
|
+
max?: string;
|
|
154
|
+
}
|
|
155
|
+
/** Aggregate response fields, present per requested spec. */
|
|
156
|
+
interface CrmAggregateResult {
|
|
157
|
+
count?: number;
|
|
158
|
+
sum?: number;
|
|
159
|
+
avg?: number;
|
|
160
|
+
min?: number | string | null;
|
|
161
|
+
max?: number | string | null;
|
|
162
|
+
}
|
|
163
|
+
/** The injected odla client. A real @odla-ai/db `AdminDb` satisfies this —
|
|
164
|
+
* `transact` accepts flat op arrays and `mutationId` gives exactly-once
|
|
165
|
+
* application (`duplicate: true` on replay). */
|
|
166
|
+
interface CrmDb {
|
|
167
|
+
query(query: CrmQuery): Promise<CrmResult>;
|
|
168
|
+
transact(ops: CrmOp[], opts?: {
|
|
169
|
+
mutationId?: string;
|
|
170
|
+
}): Promise<{
|
|
171
|
+
txId: number;
|
|
172
|
+
duplicate: boolean;
|
|
173
|
+
}>;
|
|
174
|
+
aggregate(ns: string, spec: CrmAggregateSpec, queryOpts?: Record<string, unknown>): Promise<CrmAggregateResult>;
|
|
175
|
+
}
|
|
176
|
+
/** The injected email transport. Wrap @odla-ai/email's `sendMessage(sender,
|
|
177
|
+
* payload)` (or any provider) — crm builds the payload, the host owns
|
|
178
|
+
* delivery. Must resolve to a receipt or throw. */
|
|
179
|
+
interface CrmEmailSender {
|
|
180
|
+
send(payload: {
|
|
181
|
+
from: string;
|
|
182
|
+
to: string[];
|
|
183
|
+
subject: string;
|
|
184
|
+
text?: string;
|
|
185
|
+
html?: string;
|
|
186
|
+
replyTo?: string;
|
|
187
|
+
headers?: Record<string, string>;
|
|
188
|
+
}): Promise<{
|
|
189
|
+
messageId: string;
|
|
190
|
+
}>;
|
|
191
|
+
}
|
|
192
|
+
/** One CRM record of any configured type. Custom field values live complete
|
|
193
|
+
* in `fields`; slot columns (`s1`…`d2`) are an index mirror of the fields the
|
|
194
|
+
* type config promoted. */
|
|
195
|
+
interface CrmRecord {
|
|
196
|
+
id: string;
|
|
197
|
+
type: string;
|
|
198
|
+
name: string;
|
|
199
|
+
primaryEmail?: string;
|
|
200
|
+
stage?: string;
|
|
201
|
+
stageIndex?: number;
|
|
202
|
+
stageChangedAt?: number;
|
|
203
|
+
rank?: number;
|
|
204
|
+
score?: number;
|
|
205
|
+
ownerId?: string;
|
|
206
|
+
emailStatus?: EmailStatus;
|
|
207
|
+
clerkUserId?: string;
|
|
208
|
+
stripeCustomerId?: string;
|
|
209
|
+
subscriptionId?: string;
|
|
210
|
+
billingStatus?: string;
|
|
211
|
+
renewalAt?: number;
|
|
212
|
+
mrr?: number;
|
|
213
|
+
s1?: string;
|
|
214
|
+
s2?: string;
|
|
215
|
+
s3?: string;
|
|
216
|
+
s4?: string;
|
|
217
|
+
n1?: number;
|
|
218
|
+
n2?: number;
|
|
219
|
+
n3?: number;
|
|
220
|
+
d1?: number;
|
|
221
|
+
d2?: number;
|
|
222
|
+
fields: Record<string, unknown>;
|
|
223
|
+
searchText: string;
|
|
224
|
+
archived: boolean;
|
|
225
|
+
createdAt: number;
|
|
226
|
+
updatedAt: number;
|
|
227
|
+
archivedAt?: number;
|
|
228
|
+
}
|
|
229
|
+
/** A tag join row (`recordId:tag` natural key) — cohorts + provenance. */
|
|
230
|
+
interface CrmTag {
|
|
231
|
+
id: string;
|
|
232
|
+
key: string;
|
|
233
|
+
recordId: string;
|
|
234
|
+
tag: string;
|
|
235
|
+
createdAt: number;
|
|
236
|
+
}
|
|
237
|
+
/** A record↔record relation row with its config-declared label. */
|
|
238
|
+
interface CrmLink {
|
|
239
|
+
id: string;
|
|
240
|
+
key: string;
|
|
241
|
+
fromId: string;
|
|
242
|
+
toId: string;
|
|
243
|
+
relation: string;
|
|
244
|
+
createdAt: number;
|
|
245
|
+
}
|
|
246
|
+
/** A feed entry: note/call/meeting, follow-up task, or stage-change audit. */
|
|
247
|
+
interface CrmActivity {
|
|
248
|
+
id: string;
|
|
249
|
+
recordId: string;
|
|
250
|
+
kind: ActivityKind;
|
|
251
|
+
body: string;
|
|
252
|
+
status?: TaskStatus;
|
|
253
|
+
dueAt?: number;
|
|
254
|
+
waitingOn?: string;
|
|
255
|
+
assigneeId?: string;
|
|
256
|
+
authorId: string;
|
|
257
|
+
createdAt: number;
|
|
258
|
+
completedAt?: number;
|
|
259
|
+
meta?: Record<string, unknown>;
|
|
260
|
+
}
|
|
261
|
+
/** A consent-bearing contact channel (email/phone) of one record. */
|
|
262
|
+
interface CrmContactChannel {
|
|
263
|
+
id: string;
|
|
264
|
+
key: string;
|
|
265
|
+
recordId: string;
|
|
266
|
+
kind: "email" | "phone";
|
|
267
|
+
value: string;
|
|
268
|
+
isPrimary: boolean;
|
|
269
|
+
consent: ConsentState;
|
|
270
|
+
consentAt: number;
|
|
271
|
+
consentSource?: string;
|
|
272
|
+
unsubscribeToken: string;
|
|
273
|
+
createdAt: number;
|
|
274
|
+
}
|
|
275
|
+
/** One audited send attempt (success, failure, or log-only). */
|
|
276
|
+
interface CrmEmailLogRow {
|
|
277
|
+
id: string;
|
|
278
|
+
recordId?: string;
|
|
279
|
+
channelId?: string;
|
|
280
|
+
to: string;
|
|
281
|
+
templateId: string;
|
|
282
|
+
subject: string;
|
|
283
|
+
transport: "sent" | "log-only";
|
|
284
|
+
redirected?: boolean;
|
|
285
|
+
dedupeKey?: string;
|
|
286
|
+
messageId?: string;
|
|
287
|
+
error?: string;
|
|
288
|
+
sentAt: number;
|
|
289
|
+
}
|
|
290
|
+
/** A saved list question: filters + sort + columns, personal or shared. */
|
|
291
|
+
interface CrmView {
|
|
292
|
+
id: string;
|
|
293
|
+
name: string;
|
|
294
|
+
type: string;
|
|
295
|
+
ownerId?: string;
|
|
296
|
+
shared: boolean;
|
|
297
|
+
filters: Record<string, unknown>;
|
|
298
|
+
sort: {
|
|
299
|
+
field: string;
|
|
300
|
+
dir: "asc" | "desc";
|
|
301
|
+
} | null;
|
|
302
|
+
columns: string[];
|
|
303
|
+
createdAt: number;
|
|
304
|
+
updatedAt: number;
|
|
305
|
+
}
|
|
306
|
+
/** One owner-editable template stored on the config row. The template CLASS
|
|
307
|
+
* (transactional vs marketing) is code config (`defineCrm` templates), not
|
|
308
|
+
* data — an owner edit can't reclassify a send past the consent gate. */
|
|
309
|
+
interface StoredTemplate {
|
|
310
|
+
subject: string;
|
|
311
|
+
text: string;
|
|
312
|
+
enabled: boolean;
|
|
313
|
+
}
|
|
314
|
+
/** The runtime-editable crm_config singleton as read back. */
|
|
315
|
+
interface CrmConfigRow {
|
|
316
|
+
id: string;
|
|
317
|
+
key: string;
|
|
318
|
+
notificationEmail?: string;
|
|
319
|
+
replyTo?: string;
|
|
320
|
+
debugEmail?: string;
|
|
321
|
+
emailTemplates: Record<string, StoredTemplate>;
|
|
322
|
+
settings: Record<string, unknown>;
|
|
323
|
+
updatedAt: number;
|
|
324
|
+
}
|
|
325
|
+
/** Outcome of validating + coercing input for a type (see `prepare`). */
|
|
326
|
+
type PreparedWrite = {
|
|
327
|
+
ok: true;
|
|
328
|
+
attrs: CrmAttrs;
|
|
329
|
+
} | {
|
|
330
|
+
ok: false;
|
|
331
|
+
errors: Record<string, string>;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/** Value kinds a custom field can hold. `email`/`url`/`enum` are validated
|
|
335
|
+
* strings; `date` accepts epoch ms or ISO strings and stores epoch ms. */
|
|
336
|
+
type FieldType = "string" | "number" | "boolean" | "date" | "email" | "url" | "enum" | "json";
|
|
337
|
+
/** One custom field of a record type: value kind, validation, slot promotion. */
|
|
338
|
+
interface FieldDef {
|
|
339
|
+
type: FieldType;
|
|
340
|
+
label?: string;
|
|
341
|
+
required?: boolean;
|
|
342
|
+
/** Allowed values — `enum` fields only. */
|
|
343
|
+
options?: readonly string[];
|
|
344
|
+
/** Promote to an indexed slot column for server-side sort/filter. String-ish
|
|
345
|
+
* fields take `s1`–`s4`, numbers `n1`–`n3`, dates `d1`–`d2`. */
|
|
346
|
+
slot?: CrmSlot;
|
|
347
|
+
/** Include in the FTS haystack. Defaults to true for string-ish fields. */
|
|
348
|
+
search?: boolean;
|
|
349
|
+
}
|
|
350
|
+
/** One pipeline stage; declaration order is the sort order (`stageIndex`). */
|
|
351
|
+
interface StageDef {
|
|
352
|
+
id: string;
|
|
353
|
+
label?: string;
|
|
354
|
+
/** Terminal stages have no outgoing transitions unless `transitions`
|
|
355
|
+
* explicitly declares some. */
|
|
356
|
+
terminal?: boolean;
|
|
357
|
+
}
|
|
358
|
+
/** A type's stage machine: ordered stages, allowed edges, gates. */
|
|
359
|
+
interface PipelineDef {
|
|
360
|
+
stages: readonly StageDef[];
|
|
361
|
+
/** Allowed edges per stage id. A stage with no entry accepts any move
|
|
362
|
+
* (unless terminal). */
|
|
363
|
+
transitions?: Record<string, readonly string[]>;
|
|
364
|
+
/** Per-target-stage gate: return an error string to block, null to allow. */
|
|
365
|
+
gates?: Record<string, (record: CrmRecord) => string | null>;
|
|
366
|
+
}
|
|
367
|
+
/** Opt-in built-in concerns for a type (identity/billing/email/rank). */
|
|
368
|
+
interface TypeFacets {
|
|
369
|
+
identity?: boolean;
|
|
370
|
+
billing?: boolean;
|
|
371
|
+
email?: boolean;
|
|
372
|
+
rank?: "manual" | "score" | "both";
|
|
373
|
+
}
|
|
374
|
+
/** One record type: its fields, pipeline, facets, and hooks. */
|
|
375
|
+
interface TypeDef {
|
|
376
|
+
label: string;
|
|
377
|
+
labelPlural?: string;
|
|
378
|
+
/** Field mapped to the promoted `name` column. Default `"name"`. */
|
|
379
|
+
nameField?: string;
|
|
380
|
+
/** `email`-typed field mapped to `primaryEmail` (lowercased) and backed by
|
|
381
|
+
* a consent-bearing contact channel. */
|
|
382
|
+
emailField?: string;
|
|
383
|
+
fields: Record<string, FieldDef>;
|
|
384
|
+
pipeline?: PipelineDef;
|
|
385
|
+
facets?: TypeFacets;
|
|
386
|
+
/** Computes the record's `score` column (rank facet "score"/"both"). */
|
|
387
|
+
scorer?: (record: CrmRecord) => number;
|
|
388
|
+
/** Post-commit hooks per target stage id — e.g. S&S "approved" promotes the
|
|
389
|
+
* member's Clerk role. Fired by the route layer AFTER the stage write. */
|
|
390
|
+
onTransition?: Record<string, (record: CrmRecord) => void | Promise<void>>;
|
|
391
|
+
}
|
|
392
|
+
/** A typed record↔record relation (e.g. person works_at company). */
|
|
393
|
+
interface RelationDef {
|
|
394
|
+
from: string;
|
|
395
|
+
to: string;
|
|
396
|
+
label: string;
|
|
397
|
+
reverseLabel?: string;
|
|
398
|
+
}
|
|
399
|
+
/** Declares a template's contract in code: its variables and its consent
|
|
400
|
+
* CLASS. Subject/body/enabled live on the data row (owner-editable). */
|
|
401
|
+
interface TemplateSpec {
|
|
402
|
+
vars: readonly string[];
|
|
403
|
+
class: "transactional" | "marketing";
|
|
404
|
+
defaults?: {
|
|
405
|
+
subject: string;
|
|
406
|
+
text: string;
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/** The whole app-level CRM configuration `defineCrm` validates. */
|
|
410
|
+
interface CrmConfig {
|
|
411
|
+
types: Record<string, TypeDef>;
|
|
412
|
+
relations?: Record<string, RelationDef>;
|
|
413
|
+
templates?: Record<string, TemplateSpec>;
|
|
414
|
+
}
|
|
415
|
+
/** The resolved engine `defineCrm` returns: static schema/rules plus the
|
|
416
|
+
* config-aware operations the route factory and ops modules run on. */
|
|
417
|
+
interface Crm {
|
|
418
|
+
config: CrmConfig;
|
|
419
|
+
schema: SerializedSchema;
|
|
420
|
+
rules: CrmRules;
|
|
421
|
+
type(name: string): TypeDef;
|
|
422
|
+
prepare(type: string, input: Record<string, unknown>, existing?: CrmRecord): PreparedWrite;
|
|
423
|
+
canTransition(type: string, record: CrmRecord, to: string): string | null;
|
|
424
|
+
initialStage(type: string): string | undefined;
|
|
425
|
+
stageIndex(type: string, stage: string): number;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Validate an app's CRM configuration and return the resolved {@link Crm}
|
|
429
|
+
* engine. Throws (with a `types.person.fields.…`-style path) on slot
|
|
430
|
+
* collisions, enum/slot type disagreements, unknown pipeline edges, reserved
|
|
431
|
+
* field names, or dangling name/email field references — at boot, before any
|
|
432
|
+
* request runs.
|
|
433
|
+
*/
|
|
434
|
+
declare function defineCrm(config: CrmConfig): Crm;
|
|
435
|
+
|
|
436
|
+
/** The stage a new record of this type starts in (first declared stage). */
|
|
437
|
+
declare function initialStage(def: TypeDef): string | undefined;
|
|
438
|
+
/** Position of a stage in the declared order — denormalized onto the record
|
|
439
|
+
* as `stageIndex` so "sort by pipeline position" is a single-field order. */
|
|
440
|
+
declare function stageIndexOf(def: TypeDef, stage: string): number;
|
|
441
|
+
/**
|
|
442
|
+
* Why this record may not move to `to` — or null when the move is allowed.
|
|
443
|
+
* Checks, in order: the type has a pipeline, the target exists, the source
|
|
444
|
+
* isn't terminal (unless it declares explicit outgoing transitions), the
|
|
445
|
+
* edge is allowed, and the target's gate passes.
|
|
446
|
+
*/
|
|
447
|
+
declare function canTransition(def: TypeDef, record: CrmRecord, to: string): string | null;
|
|
448
|
+
|
|
449
|
+
/** The FTS haystack: name + email + every searchable field value, lowercased.
|
|
450
|
+
* String-ish fields are searchable by default; other types opt in with
|
|
451
|
+
* `search: true`. Exported for the write paths that must rebuild it. */
|
|
452
|
+
declare function searchTextFor(def: TypeDef, name: string, email: string | null, fields: Record<string, unknown>): string;
|
|
453
|
+
/**
|
|
454
|
+
* Validate + coerce `input` (keyed by config field name) for one type.
|
|
455
|
+
* Create (no `existing`): required fields must be present, and the
|
|
456
|
+
* `nameField` always (a record without a name is unlistable). Update:
|
|
457
|
+
* partial — unnamed fields keep their stored values. Returns the full attrs
|
|
458
|
+
* to write: promoted `name`/`primaryEmail`, every slot the type claims
|
|
459
|
+
* (mirrored or null), the complete `fields` json (source of truth), and the
|
|
460
|
+
* rebuilt `searchText` — or `{ ok: false, errors }` keyed by field.
|
|
461
|
+
*/
|
|
462
|
+
declare function prepare(def: TypeDef, input: Record<string, unknown>, existing?: CrmRecord): PreparedWrite;
|
|
463
|
+
|
|
464
|
+
/** Caller-fault error (bad type, unknown field, blocked transition…) — the
|
|
465
|
+
* route layer maps it to a 400. `fields` carries per-field messages when the
|
|
466
|
+
* failure came from input validation. */
|
|
467
|
+
declare class CrmInputError extends Error {
|
|
468
|
+
readonly fields?: Record<string, string>;
|
|
469
|
+
constructor(message: string, fields?: Record<string, string>);
|
|
470
|
+
}
|
|
471
|
+
/** Missing entity — the route layer maps it to a 404. */
|
|
472
|
+
declare class CrmNotFoundError extends Error {
|
|
473
|
+
constructor(what: string);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** What every op needs: the resolved config, the injected db, test overrides. */
|
|
477
|
+
interface CrmDeps {
|
|
478
|
+
crm: Crm;
|
|
479
|
+
db: CrmDb;
|
|
480
|
+
/** Clock override (default `Date.now`). */
|
|
481
|
+
now?: () => number;
|
|
482
|
+
/** Id/token factory override (default `crypto.randomUUID`). */
|
|
483
|
+
newId?: () => string;
|
|
484
|
+
}
|
|
485
|
+
/** {@link CrmDeps} with the injectable defaults filled in. */
|
|
486
|
+
interface ResolvedDeps {
|
|
487
|
+
crm: Crm;
|
|
488
|
+
db: CrmDb;
|
|
489
|
+
now: () => number;
|
|
490
|
+
newId: () => string;
|
|
491
|
+
}
|
|
492
|
+
/** Fill the injectable defaults. */
|
|
493
|
+
declare function resolveDeps(deps: CrmDeps): ResolvedDeps;
|
|
494
|
+
|
|
495
|
+
/** Comparison filter for one slotted custom field. */
|
|
496
|
+
interface FieldFilter {
|
|
497
|
+
eq?: CrmScalar;
|
|
498
|
+
in?: CrmScalar[];
|
|
499
|
+
gte?: number | string;
|
|
500
|
+
lte?: number | string;
|
|
501
|
+
}
|
|
502
|
+
/** The serializable filter set (also the saved-view `filters` payload). */
|
|
503
|
+
interface ViewFilters {
|
|
504
|
+
search?: string;
|
|
505
|
+
stage?: string[];
|
|
506
|
+
emailStatus?: string[];
|
|
507
|
+
billingStatus?: string[];
|
|
508
|
+
ownerId?: string;
|
|
509
|
+
/** Exact tag — resolved to record ids first (join rows). */
|
|
510
|
+
tag?: string;
|
|
511
|
+
/** Include archived records (default: live only). */
|
|
512
|
+
archived?: boolean;
|
|
513
|
+
/** Slotted-field predicates, keyed by config field name. */
|
|
514
|
+
fields?: Record<string, FieldFilter>;
|
|
515
|
+
}
|
|
516
|
+
/** One-field sort (odla-db orders on exactly one indexed field). */
|
|
517
|
+
interface CrmSort {
|
|
518
|
+
field: string;
|
|
519
|
+
dir: "asc" | "desc";
|
|
520
|
+
}
|
|
521
|
+
/** Everything a list window can ask for: filters + sort + paging. */
|
|
522
|
+
interface CrmListParams extends ViewFilters {
|
|
523
|
+
type: string;
|
|
524
|
+
sort?: CrmSort;
|
|
525
|
+
limit?: number;
|
|
526
|
+
offset?: number;
|
|
527
|
+
}
|
|
528
|
+
type Where = Record<string, unknown>;
|
|
529
|
+
/** Resolve a sort field to its physical indexed column: a promoted column
|
|
530
|
+
* name as-is, or a slotted config field via the type's slot claim. Throws
|
|
531
|
+
* {@link CrmInputError} for anything else (odla-db cannot order on it). */
|
|
532
|
+
declare function resolveSortColumn(crm: Crm, type: string, field: string): string;
|
|
533
|
+
/** The compiled odla-db query options for one list window. */
|
|
534
|
+
interface CompiledList {
|
|
535
|
+
opts: {
|
|
536
|
+
where: {
|
|
537
|
+
and: Where[];
|
|
538
|
+
};
|
|
539
|
+
order: Record<string, "asc" | "desc">;
|
|
540
|
+
limit: number;
|
|
541
|
+
offset: number;
|
|
542
|
+
search?: string;
|
|
543
|
+
};
|
|
544
|
+
limit: number;
|
|
545
|
+
offset: number;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Compile list params into `QueryOpts` for `crm_record`. `tagRecordIds`
|
|
549
|
+
* (when the caller pre-resolved a tag filter) narrows via `id $in`; an empty
|
|
550
|
+
* id list is the caller's short-circuit — don't compile, the result is [].
|
|
551
|
+
*/
|
|
552
|
+
declare function compileList(crm: Crm, params: CrmListParams, tagRecordIds?: string[]): CompiledList;
|
|
553
|
+
|
|
554
|
+
/** Spacing between ranks after a rebalance (and the first record's rank). */
|
|
555
|
+
declare const RANK_STEP = 1024;
|
|
556
|
+
/** Below this gap between neighbors, float64 midpoints are getting close to
|
|
557
|
+
* exhaustion (each insert halves the gap; 2^-20 leaves ~30 more halvings). */
|
|
558
|
+
declare const RANK_EPSILON: number;
|
|
559
|
+
/**
|
|
560
|
+
* The rank to write for a record placed between `before` and `after`
|
|
561
|
+
* (either may be absent at the list edges; both absent = first record).
|
|
562
|
+
* `before` is the neighbor that sorts earlier (smaller rank).
|
|
563
|
+
*/
|
|
564
|
+
declare function rankBetween(before?: number, after?: number): number;
|
|
565
|
+
/** True when two neighbors have converged so far that midpoint inserts
|
|
566
|
+
* between them are about to stop producing distinct ranks. */
|
|
567
|
+
declare function needsRebalance(before: number, after: number): boolean;
|
|
568
|
+
/**
|
|
569
|
+
* Fresh evenly-spaced ranks for records in their current display order.
|
|
570
|
+
* Returns one `{ id, rank }` per input, `RANK_STEP` apart starting at
|
|
571
|
+
* `RANK_STEP` — apply as a batch update.
|
|
572
|
+
*/
|
|
573
|
+
declare function rebalancePlan(orderedIds: readonly string[]): Array<{
|
|
574
|
+
id: string;
|
|
575
|
+
rank: number;
|
|
576
|
+
}>;
|
|
577
|
+
|
|
578
|
+
/** Everything that can change a channel's consent. `unsubscribe.token` is
|
|
579
|
+
* the emailed link, `unsubscribe.oneclick` the RFC 8058 POST; `contact.optin`
|
|
580
|
+
* is an action by the contact themself (form, reply, re-confirmation). */
|
|
581
|
+
type ConsentEvent = "unsubscribe.token" | "unsubscribe.oneclick" | "bounce.hard" | "admin.suppress" | "admin.resubscribe" | "contact.optin";
|
|
582
|
+
/** The machine's answer: the next state, or why the move is invalid. */
|
|
583
|
+
type ConsentOutcome = {
|
|
584
|
+
state: ConsentState;
|
|
585
|
+
} | {
|
|
586
|
+
error: string;
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* Apply one consent event to a channel's current state. Returns the next
|
|
590
|
+
* state, or an error for the one invalid move (admin-resubscribing an
|
|
591
|
+
* unsubscribed contact). Idempotent by construction: repeating an event
|
|
592
|
+
* never changes the outcome.
|
|
593
|
+
*/
|
|
594
|
+
declare function applyConsentEvent(current: ConsentState, event: ConsentEvent): ConsentOutcome;
|
|
595
|
+
/** May this channel receive a send of the given class right now?
|
|
596
|
+
* `suppressed`/`bounced` block everything; `unsubscribed` blocks marketing
|
|
597
|
+
* only (transactional lifecycle mail still delivers). */
|
|
598
|
+
declare function canEmail(consent: ConsentState, cls: "transactional" | "marketing"): boolean;
|
|
599
|
+
|
|
600
|
+
/** Substitute `{{var}}` tokens from `vars`; unknown tokens render as "". */
|
|
601
|
+
declare function renderTemplate(template: string, vars: Record<string, string>): string;
|
|
602
|
+
/** The distinct `{{var}}` names a template references, in first-seen order. */
|
|
603
|
+
declare function templateVars(template: string): string[];
|
|
604
|
+
/**
|
|
605
|
+
* Template health check for the settings UI: which referenced vars aren't
|
|
606
|
+
* in the declared contract (typos — they'd silently render as ""), and which
|
|
607
|
+
* declared vars go unused (usually fine, occasionally a forgotten insert).
|
|
608
|
+
*/
|
|
609
|
+
declare function lintTemplate(template: string, knownVars: readonly string[]): {
|
|
610
|
+
unknown: string[];
|
|
611
|
+
unused: string[];
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
/** Cast a raw row to {@link CrmRecord}, defaulting the json fields. */
|
|
615
|
+
declare function rowToRecord(row: CrmRow): CrmRecord;
|
|
616
|
+
/** Load one record by id, or null. */
|
|
617
|
+
declare function getRecord(deps: CrmDeps, id: string): Promise<CrmRecord | null>;
|
|
618
|
+
/** Load one record by id; {@link CrmNotFoundError} (404) when missing. */
|
|
619
|
+
declare function mustGetRecord(deps: CrmDeps, id: string): Promise<CrmRecord>;
|
|
620
|
+
/** One list window + the total matching count (for pagination). A `tag`
|
|
621
|
+
* filter resolves to record ids first (join rows, capped at 1000). */
|
|
622
|
+
declare function listRecords(deps: CrmDeps, params: CrmListParams): Promise<{
|
|
623
|
+
records: CrmRecord[];
|
|
624
|
+
total: number;
|
|
625
|
+
limit: number;
|
|
626
|
+
offset: number;
|
|
627
|
+
}>;
|
|
628
|
+
/** Create a record of `type` from custom-field input. Also creates (or
|
|
629
|
+
* upserts) the primary email contact channel when the type declares an
|
|
630
|
+
* `emailField`. New records rank at `now` so manual order defaults to
|
|
631
|
+
* creation order. */
|
|
632
|
+
declare function createRecord(deps: CrmDeps, opts: {
|
|
633
|
+
type: string;
|
|
634
|
+
input: Record<string, unknown>;
|
|
635
|
+
ownerId?: string;
|
|
636
|
+
stage?: string;
|
|
637
|
+
mutationId?: string;
|
|
638
|
+
}): Promise<{
|
|
639
|
+
id: string;
|
|
640
|
+
duplicate: boolean;
|
|
641
|
+
record: CrmRecord;
|
|
642
|
+
}>;
|
|
643
|
+
/** Partial update of custom fields (+ owner). A changed `emailField` value
|
|
644
|
+
* repoints the primary channel — the old address keeps its consent history,
|
|
645
|
+
* a returning address keeps its earlier consent. */
|
|
646
|
+
declare function updateRecord(deps: CrmDeps, opts: {
|
|
647
|
+
id: string;
|
|
648
|
+
input: Record<string, unknown>;
|
|
649
|
+
ownerId?: string | null;
|
|
650
|
+
mutationId?: string;
|
|
651
|
+
}): Promise<{
|
|
652
|
+
record: CrmRecord;
|
|
653
|
+
duplicate: boolean;
|
|
654
|
+
}>;
|
|
655
|
+
/** Archive (soft-delete) or restore. Archived records drop out of default
|
|
656
|
+
* list windows but keep every tag/activity/channel row. */
|
|
657
|
+
declare function setArchived(deps: CrmDeps, opts: {
|
|
658
|
+
id: string;
|
|
659
|
+
archived: boolean;
|
|
660
|
+
mutationId?: string;
|
|
661
|
+
}): Promise<{
|
|
662
|
+
duplicate: boolean;
|
|
663
|
+
}>;
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Move a record to stage `to`. Refused (400-style {@link CrmInputError})
|
|
667
|
+
* when the pipeline's transitions/gates say no. Appends the audit activity
|
|
668
|
+
* in the same tx; returns the type's `onTransition` hook for the caller to
|
|
669
|
+
* fire AFTER commit (post-commit side effects like a Clerk role promotion
|
|
670
|
+
* never hold the write hostage).
|
|
671
|
+
*/
|
|
672
|
+
declare function setStage(deps: CrmDeps, opts: {
|
|
673
|
+
id: string;
|
|
674
|
+
to: string;
|
|
675
|
+
authorId: string;
|
|
676
|
+
mutationId?: string;
|
|
677
|
+
}): Promise<{
|
|
678
|
+
record: CrmRecord;
|
|
679
|
+
from: string | null;
|
|
680
|
+
duplicate: boolean;
|
|
681
|
+
hook?: (record: CrmRecord) => void | Promise<void>;
|
|
682
|
+
}>;
|
|
683
|
+
/**
|
|
684
|
+
* Place a record between two neighbors (either end open). Neighbors must be
|
|
685
|
+
* same-type records that already carry ranks; reports `rebalanceNeeded`
|
|
686
|
+
* when the gap between them has nearly collapsed.
|
|
687
|
+
*/
|
|
688
|
+
declare function setRank(deps: CrmDeps, opts: {
|
|
689
|
+
id: string;
|
|
690
|
+
beforeId?: string;
|
|
691
|
+
afterId?: string;
|
|
692
|
+
mutationId?: string;
|
|
693
|
+
}): Promise<{
|
|
694
|
+
rank: number;
|
|
695
|
+
rebalanceNeeded: boolean;
|
|
696
|
+
duplicate: boolean;
|
|
697
|
+
}>;
|
|
698
|
+
/** Rewrite a type's live records to evenly-spaced ranks in their current
|
|
699
|
+
* rank order (first 1000 — beyond that, rebalance in windows). */
|
|
700
|
+
declare function rebalanceRanks(deps: CrmDeps, opts: {
|
|
701
|
+
type: string;
|
|
702
|
+
mutationId?: string;
|
|
703
|
+
}): Promise<{
|
|
704
|
+
count: number;
|
|
705
|
+
duplicate: boolean;
|
|
706
|
+
}>;
|
|
707
|
+
|
|
708
|
+
/** Tags are lowercased, trimmed, ≤ 64 chars — exact-match filters, so case
|
|
709
|
+
* variants must collapse to one cohort. */
|
|
710
|
+
declare function normalizeTag(raw: string): string;
|
|
711
|
+
/** Idempotently tag a record (natural-key upsert). */
|
|
712
|
+
declare function addTag(deps: CrmDeps, opts: {
|
|
713
|
+
recordId: string;
|
|
714
|
+
tag: string;
|
|
715
|
+
mutationId?: string;
|
|
716
|
+
}): Promise<{
|
|
717
|
+
tag: string;
|
|
718
|
+
duplicate: boolean;
|
|
719
|
+
}>;
|
|
720
|
+
/** Remove a tag by natural key; a no-op when absent. */
|
|
721
|
+
declare function removeTag(deps: CrmDeps, opts: {
|
|
722
|
+
recordId: string;
|
|
723
|
+
tag: string;
|
|
724
|
+
mutationId?: string;
|
|
725
|
+
}): Promise<{
|
|
726
|
+
duplicate: boolean;
|
|
727
|
+
}>;
|
|
728
|
+
/** A record's tags, oldest first. */
|
|
729
|
+
declare function listTags(deps: CrmDeps, recordId: string): Promise<CrmTag[]>;
|
|
730
|
+
/** Create a config-declared relation between two records after checking the
|
|
731
|
+
* endpoints' types match the relation's from/to declaration. */
|
|
732
|
+
declare function addLink(deps: CrmDeps, opts: {
|
|
733
|
+
relation: string;
|
|
734
|
+
fromId: string;
|
|
735
|
+
toId: string;
|
|
736
|
+
mutationId?: string;
|
|
737
|
+
}): Promise<{
|
|
738
|
+
duplicate: boolean;
|
|
739
|
+
}>;
|
|
740
|
+
/** Remove a relation by natural key; a no-op when absent. */
|
|
741
|
+
declare function removeLink(deps: CrmDeps, opts: {
|
|
742
|
+
relation: string;
|
|
743
|
+
fromId: string;
|
|
744
|
+
toId: string;
|
|
745
|
+
mutationId?: string;
|
|
746
|
+
}): Promise<{
|
|
747
|
+
duplicate: boolean;
|
|
748
|
+
}>;
|
|
749
|
+
/** Every link touching a record, either direction. */
|
|
750
|
+
declare function listLinks(deps: CrmDeps, recordId: string): Promise<CrmLink[]>;
|
|
751
|
+
|
|
752
|
+
/** Append a note/call/meeting or open a follow-up task on a record. */
|
|
753
|
+
declare function addActivity(deps: CrmDeps, opts: {
|
|
754
|
+
recordId: string;
|
|
755
|
+
kind: ActivityKind;
|
|
756
|
+
body: string;
|
|
757
|
+
authorId: string;
|
|
758
|
+
dueAt?: number;
|
|
759
|
+
assigneeId?: string;
|
|
760
|
+
waitingOn?: string;
|
|
761
|
+
meta?: Record<string, unknown>;
|
|
762
|
+
mutationId?: string;
|
|
763
|
+
}): Promise<{
|
|
764
|
+
id: string;
|
|
765
|
+
duplicate: boolean;
|
|
766
|
+
}>;
|
|
767
|
+
/** Patch a task's lifecycle fields. Moving to `done` stamps `completedAt`;
|
|
768
|
+
* reopening clears it. Only `task` activities accept status changes. */
|
|
769
|
+
declare function updateTask(deps: CrmDeps, opts: {
|
|
770
|
+
id: string;
|
|
771
|
+
status?: TaskStatus;
|
|
772
|
+
dueAt?: number | null;
|
|
773
|
+
assigneeId?: string | null;
|
|
774
|
+
waitingOn?: string | null;
|
|
775
|
+
body?: string;
|
|
776
|
+
mutationId?: string;
|
|
777
|
+
}): Promise<{
|
|
778
|
+
activity: CrmActivity;
|
|
779
|
+
duplicate: boolean;
|
|
780
|
+
}>;
|
|
781
|
+
/** A record's activity feed, newest first. */
|
|
782
|
+
declare function listActivities(deps: CrmDeps, opts: {
|
|
783
|
+
recordId: string;
|
|
784
|
+
kind?: ActivityKind;
|
|
785
|
+
limit?: number;
|
|
786
|
+
offset?: number;
|
|
787
|
+
}): Promise<CrmActivity[]>;
|
|
788
|
+
/** Open follow-ups across records, soonest due first — the "Waiting on"
|
|
789
|
+
* board. Defaults to open+waiting; filter to one assignee for "mine". */
|
|
790
|
+
declare function listTasks(deps: CrmDeps, opts?: {
|
|
791
|
+
assigneeId?: string;
|
|
792
|
+
status?: TaskStatus[];
|
|
793
|
+
dueBefore?: number;
|
|
794
|
+
limit?: number;
|
|
795
|
+
offset?: number;
|
|
796
|
+
}): Promise<CrmActivity[]>;
|
|
797
|
+
|
|
798
|
+
/** The natural key of a contact channel row. */
|
|
799
|
+
declare const channelKey: (recordId: string, kind: string, value: string) => string;
|
|
800
|
+
/** A record's `emailStatus` is its primary channel's consent, with
|
|
801
|
+
* "subscribed" reading as "ok" and no channel at all as "none". */
|
|
802
|
+
declare function foldEmailStatus(consent: ConsentState | null): EmailStatus;
|
|
803
|
+
/** All channels of a record (a handful of rows — no paging). */
|
|
804
|
+
declare function listChannels(deps: CrmDeps, recordId: string): Promise<CrmContactChannel[]>;
|
|
805
|
+
/**
|
|
806
|
+
* Ops that make `email` the record's primary email channel: upsert by
|
|
807
|
+
* natural key (an address the record had before keeps its consent history),
|
|
808
|
+
* demote any other primary, or — with `email: null` — just demote. Returns
|
|
809
|
+
* the ops plus the `emailStatus` the record should fold to.
|
|
810
|
+
*/
|
|
811
|
+
declare function emailChannelOps(deps: CrmDeps, recordId: string, email: string | null, existing: readonly CrmContactChannel[]): {
|
|
812
|
+
ops: CrmOp[];
|
|
813
|
+
emailStatus: EmailStatus;
|
|
814
|
+
};
|
|
815
|
+
/**
|
|
816
|
+
* Apply one consent event to the channel holding `token` (unsubscribe links)
|
|
817
|
+
* or to `channelId` (admin actions). Writes the channel's new consent and,
|
|
818
|
+
* when it is the record's primary email channel, folds the record's
|
|
819
|
+
* `emailStatus`. Idempotent under `mutationId`.
|
|
820
|
+
*/
|
|
821
|
+
declare function applyConsent(deps: CrmDeps, opts: {
|
|
822
|
+
token?: string;
|
|
823
|
+
channelId?: string;
|
|
824
|
+
event: ConsentEvent;
|
|
825
|
+
mutationId?: string;
|
|
826
|
+
}): Promise<{
|
|
827
|
+
state: ConsentState;
|
|
828
|
+
recordId: string;
|
|
829
|
+
duplicate: boolean;
|
|
830
|
+
}>;
|
|
831
|
+
|
|
832
|
+
/** The serializable definition of a saved view. */
|
|
833
|
+
interface ViewSpec {
|
|
834
|
+
name: string;
|
|
835
|
+
type: string;
|
|
836
|
+
filters: ViewFilters;
|
|
837
|
+
sort: CrmSort | null;
|
|
838
|
+
columns: string[];
|
|
839
|
+
shared: boolean;
|
|
840
|
+
}
|
|
841
|
+
/** Persist a new view after dry-running its spec through the compiler. */
|
|
842
|
+
declare function saveView(deps: CrmDeps, opts: {
|
|
843
|
+
spec: ViewSpec;
|
|
844
|
+
ownerId: string;
|
|
845
|
+
mutationId?: string;
|
|
846
|
+
}): Promise<{
|
|
847
|
+
id: string;
|
|
848
|
+
duplicate: boolean;
|
|
849
|
+
}>;
|
|
850
|
+
/** Update a view you own (shared views are editable by their owner only —
|
|
851
|
+
* the route layer passes the acting admin as `ownerId`). */
|
|
852
|
+
declare function updateView(deps: CrmDeps, opts: {
|
|
853
|
+
id: string;
|
|
854
|
+
spec: Partial<ViewSpec>;
|
|
855
|
+
ownerId: string;
|
|
856
|
+
mutationId?: string;
|
|
857
|
+
}): Promise<{
|
|
858
|
+
view: CrmView;
|
|
859
|
+
duplicate: boolean;
|
|
860
|
+
}>;
|
|
861
|
+
/** Delete a view you own. */
|
|
862
|
+
declare function deleteView(deps: CrmDeps, opts: {
|
|
863
|
+
id: string;
|
|
864
|
+
ownerId: string;
|
|
865
|
+
mutationId?: string;
|
|
866
|
+
}): Promise<{
|
|
867
|
+
duplicate: boolean;
|
|
868
|
+
}>;
|
|
869
|
+
/** Views visible to a viewer: everything shared plus their own, optionally
|
|
870
|
+
* narrowed to one record type. */
|
|
871
|
+
declare function listViews(deps: CrmDeps, opts: {
|
|
872
|
+
viewerId: string;
|
|
873
|
+
type?: string;
|
|
874
|
+
}): Promise<CrmView[]>;
|
|
875
|
+
|
|
876
|
+
/** Seed copy for every declared template: the spec's defaults, enabled; a
|
|
877
|
+
* spec without defaults seeds empty and DISABLED (nothing sends until the
|
|
878
|
+
* owner writes copy). */
|
|
879
|
+
declare function defaultTemplates(crm: Crm): Record<string, StoredTemplate>;
|
|
880
|
+
/** Read the crm_config singleton, or null before the first save. */
|
|
881
|
+
declare function getConfig(deps: CrmDeps): Promise<CrmConfigRow | null>;
|
|
882
|
+
/** Partial config update; explicit null clears an address. */
|
|
883
|
+
interface ConfigPatch {
|
|
884
|
+
notificationEmail?: string | null;
|
|
885
|
+
replyTo?: string | null;
|
|
886
|
+
debugEmail?: string | null;
|
|
887
|
+
emailTemplates?: Record<string, Partial<StoredTemplate>>;
|
|
888
|
+
settings?: Record<string, unknown>;
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Upsert the singleton config row (natural key, idempotent). Template edits
|
|
892
|
+
* are validated against the code-declared registry — an id `defineCrm`
|
|
893
|
+
* never declared is refused, so data rows can't invent send paths. First
|
|
894
|
+
* write seeds every declared template's default copy.
|
|
895
|
+
*/
|
|
896
|
+
declare function saveConfig(deps: CrmDeps, patch: ConfigPatch, opts?: {
|
|
897
|
+
mutationId?: string;
|
|
898
|
+
}): Promise<{
|
|
899
|
+
config: CrmConfigRow;
|
|
900
|
+
duplicate: boolean;
|
|
901
|
+
}>;
|
|
902
|
+
|
|
903
|
+
/** Inputs for one templated send (see {@link sendTemplatedEmail}). */
|
|
904
|
+
interface SendEmailOpts {
|
|
905
|
+
recordId: string;
|
|
906
|
+
/** Defaults to the record's primary email channel. */
|
|
907
|
+
channelId?: string;
|
|
908
|
+
templateId: string;
|
|
909
|
+
vars: Record<string, string>;
|
|
910
|
+
/** Retry identity: a prior successful send with this key short-circuits. */
|
|
911
|
+
dedupeKey: string;
|
|
912
|
+
/** Sender address (env-owned, e.g. the verified EMAIL_FROM). */
|
|
913
|
+
from: string;
|
|
914
|
+
/** Anything but "production" redirects to the config debugEmail (subject
|
|
915
|
+
* gets a "[dev] " prefix) or falls back to log-only. */
|
|
916
|
+
envName: string;
|
|
917
|
+
/** Absolute origin for links (unsubscribe). */
|
|
918
|
+
baseUrl: string;
|
|
919
|
+
/** Route mount point for the unsubscribe link. Default "/api/crm". */
|
|
920
|
+
basePath?: string;
|
|
921
|
+
/** Admin test-send: bypasses the enabled flag — NEVER the consent gate. */
|
|
922
|
+
force?: boolean;
|
|
923
|
+
}
|
|
924
|
+
/** What happened to the send — delivered, gated, logged, or failed. */
|
|
925
|
+
interface SendEmailResult {
|
|
926
|
+
sent: boolean;
|
|
927
|
+
/** Why nothing was delivered (gates, log-only, transport error). */
|
|
928
|
+
reason?: string;
|
|
929
|
+
transport?: "sent" | "log-only";
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Render and send one templated email to a record's contact channel, with
|
|
933
|
+
* consent gating, dedupe, dev redirection, and an unconditional audit row.
|
|
934
|
+
* Marketing-class sends get `{{unsubscribeUrl}}` plus RFC 8058 one-click
|
|
935
|
+
* headers automatically.
|
|
936
|
+
*/
|
|
937
|
+
declare function sendTemplatedEmail(deps: CrmDeps & {
|
|
938
|
+
sender?: CrmEmailSender;
|
|
939
|
+
}, opts: SendEmailOpts): Promise<SendEmailResult>;
|
|
940
|
+
/** Recent sends for the settings audit table, newest first. */
|
|
941
|
+
declare function listEmailLog(deps: CrmDeps, opts?: {
|
|
942
|
+
recordId?: string;
|
|
943
|
+
limit?: number;
|
|
944
|
+
offset?: number;
|
|
945
|
+
}): Promise<Record<string, unknown>[]>;
|
|
946
|
+
/** Guard for host-owned send paths (broadcasts, billing emails): may this
|
|
947
|
+
* record receive `cls` mail right now? */
|
|
948
|
+
declare function recordCanEmail(deps: CrmDeps, recordId: string, cls: "transactional" | "marketing"): Promise<boolean>;
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Look up `$users` by (lowercased) email and stamp the record's
|
|
952
|
+
* `clerkUserId`. Uses the record's `primaryEmail` unless an explicit email
|
|
953
|
+
* is given. Returns `linked: false` when no account exists yet — call again
|
|
954
|
+
* after the person signs in (idempotent under `mutationId`).
|
|
955
|
+
*/
|
|
956
|
+
declare function linkIdentity(deps: CrmDeps, opts: {
|
|
957
|
+
recordId: string;
|
|
958
|
+
email?: string;
|
|
959
|
+
mutationId?: string;
|
|
960
|
+
}): Promise<{
|
|
961
|
+
linked: boolean;
|
|
962
|
+
clerkUserId?: string;
|
|
963
|
+
duplicate?: boolean;
|
|
964
|
+
}>;
|
|
965
|
+
|
|
966
|
+
/** Tile counts for one record type. */
|
|
967
|
+
interface TypeSummary {
|
|
968
|
+
type: string;
|
|
969
|
+
total: number;
|
|
970
|
+
/** Live records per pipeline stage (types with a pipeline). */
|
|
971
|
+
stages: Record<string, number>;
|
|
972
|
+
/** Open + waiting follow-up tasks across all records. */
|
|
973
|
+
openTasks: number;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Tile counts for one record type: total live records, per-stage counts,
|
|
977
|
+
* and the open-task load. Each count is an indexed-where aggregate; a type
|
|
978
|
+
* with S stages costs S+2 calls, issued concurrently.
|
|
979
|
+
*/
|
|
980
|
+
declare function typeSummary(deps: CrmDeps, type: string): Promise<TypeSummary>;
|
|
981
|
+
|
|
982
|
+
/** A provider webhook, normalized. `eventId` becomes the tx mutationId. */
|
|
983
|
+
interface BillingEvent {
|
|
984
|
+
provider: string;
|
|
985
|
+
eventId: string;
|
|
986
|
+
kind: "payment.succeeded" | "payment.refunded" | "subscription.canceled" | "ignored";
|
|
987
|
+
/** payment.succeeded: was this the subscription-creating first invoice? */
|
|
988
|
+
first?: boolean;
|
|
989
|
+
/** Next renewal, epoch ms. */
|
|
990
|
+
renewalAt?: number;
|
|
991
|
+
amountCents?: number;
|
|
992
|
+
customerId?: string;
|
|
993
|
+
subscriptionId?: string;
|
|
994
|
+
/** Provider metadata's record id when present — the primary join key;
|
|
995
|
+
* `customerId` lookup is the fallback. */
|
|
996
|
+
recordId?: string;
|
|
997
|
+
}
|
|
998
|
+
/** One live subscription as the provider reports it (admin billing tab). */
|
|
999
|
+
interface SubscriptionSnapshot {
|
|
1000
|
+
subscriptionId: string;
|
|
1001
|
+
customerId: string;
|
|
1002
|
+
/** Provider-native status: active | past_due | canceled | … */
|
|
1003
|
+
status: string;
|
|
1004
|
+
cancelAtPeriodEnd: boolean;
|
|
1005
|
+
currentPeriodEnd?: number;
|
|
1006
|
+
amountCents?: number;
|
|
1007
|
+
dashboardUrls: {
|
|
1008
|
+
customer?: string;
|
|
1009
|
+
subscription?: string;
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
/** What a payment adapter must offer. Implementations own credentials
|
|
1013
|
+
* (e.g. closing over the tenant vault) — crm never sees a secret key. */
|
|
1014
|
+
interface BillingProvider {
|
|
1015
|
+
readonly id: string;
|
|
1016
|
+
configured(): Promise<boolean>;
|
|
1017
|
+
/** Subscription-first flow: create customer + incomplete subscription,
|
|
1018
|
+
* return the client secret an inline Payment Element confirms. */
|
|
1019
|
+
createSubscription(opts: {
|
|
1020
|
+
recordId: string;
|
|
1021
|
+
email: string;
|
|
1022
|
+
name: string;
|
|
1023
|
+
metadata?: Record<string, string>;
|
|
1024
|
+
}): Promise<{
|
|
1025
|
+
customerId: string;
|
|
1026
|
+
subscriptionId: string;
|
|
1027
|
+
clientSecret: string;
|
|
1028
|
+
publishableKey: string | null;
|
|
1029
|
+
}>;
|
|
1030
|
+
listSubscriptions(opts?: {
|
|
1031
|
+
cursor?: string;
|
|
1032
|
+
}): Promise<{
|
|
1033
|
+
rows: SubscriptionSnapshot[];
|
|
1034
|
+
nextCursor?: string;
|
|
1035
|
+
}>;
|
|
1036
|
+
refund(opts: {
|
|
1037
|
+
chargeId?: string;
|
|
1038
|
+
subscriptionId?: string;
|
|
1039
|
+
}): Promise<{
|
|
1040
|
+
refundId: string;
|
|
1041
|
+
}>;
|
|
1042
|
+
/** HMAC-verify a raw webhook body and normalize it; null = bad signature
|
|
1043
|
+
* (the route answers 400 and the provider retries). */
|
|
1044
|
+
verifyAndParse(rawBody: string, signatureHeader: string): Promise<BillingEvent | null>;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/** The authenticated admin performing a request (host-resolved — the crm
|
|
1048
|
+
* routes are an admin surface; end-user access is a future rules story). */
|
|
1049
|
+
interface CrmActor {
|
|
1050
|
+
userId: string;
|
|
1051
|
+
email?: string;
|
|
1052
|
+
}
|
|
1053
|
+
/** Everything `createCrmRoutes` needs from the host worker. */
|
|
1054
|
+
interface CrmRouteOpts {
|
|
1055
|
+
crm: Crm;
|
|
1056
|
+
db: CrmDb;
|
|
1057
|
+
/** Host-owned auth: resolve the request to an admin actor or null (401).
|
|
1058
|
+
* The unsubscribe endpoints are the only routes that skip this. */
|
|
1059
|
+
authorize: (req: Request) => Promise<CrmActor | null> | CrmActor | null;
|
|
1060
|
+
/** Email transport; omit for log-only behavior. */
|
|
1061
|
+
sender?: CrmEmailSender;
|
|
1062
|
+
/** Sender address for outbound mail (verified from-address). */
|
|
1063
|
+
from?: string;
|
|
1064
|
+
/** Only exactly "production" delivers to real recipients — anything else
|
|
1065
|
+
* dev-redirects or logs only. Defaults fail-safe to "development". */
|
|
1066
|
+
envName?: string;
|
|
1067
|
+
/** Absolute origin for links in emails (unsubscribe). */
|
|
1068
|
+
baseUrl?: string;
|
|
1069
|
+
/** Mount point. Default "/api/crm". */
|
|
1070
|
+
basePath?: string;
|
|
1071
|
+
/** Injectable clock/id factory (tests). */
|
|
1072
|
+
now?: () => number;
|
|
1073
|
+
newId?: () => string;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
/**
|
|
1077
|
+
* Build the crm fetch handler. Returns `null` for requests outside
|
|
1078
|
+
* `basePath` (default `/api/crm`) so the host worker falls through to its
|
|
1079
|
+
* own routes; inside it, every route requires `authorize` to resolve an
|
|
1080
|
+
* admin actor (401 otherwise) EXCEPT the public unsubscribe pair, where the
|
|
1081
|
+
* per-channel token is the credential. Domain errors map to 400/404 JSON;
|
|
1082
|
+
* anything unexpected is a 500 without internals.
|
|
1083
|
+
*/
|
|
1084
|
+
declare function createCrmRoutes(options: CrmRouteOpts): (req: Request) => Promise<Response | null>;
|
|
1085
|
+
|
|
1086
|
+
/** Where the routes live and how to authenticate against them. */
|
|
1087
|
+
interface CrmClientOptions {
|
|
1088
|
+
/** Origin of the host worker, e.g. "" (same-origin) or a full URL. */
|
|
1089
|
+
baseUrl?: string;
|
|
1090
|
+
/** Route mount point. Default "/api/crm". */
|
|
1091
|
+
basePath?: string;
|
|
1092
|
+
fetch?: typeof globalThis.fetch;
|
|
1093
|
+
/** Per-request auth headers (called each request — tokens rotate). */
|
|
1094
|
+
headers?: () => Promise<Record<string, string>> | Record<string, string>;
|
|
1095
|
+
}
|
|
1096
|
+
/** A record composed with its tags, channels, and links. */
|
|
1097
|
+
interface RecordDetail {
|
|
1098
|
+
record: CrmRecord;
|
|
1099
|
+
tags: CrmTag[];
|
|
1100
|
+
channels: CrmContactChannel[];
|
|
1101
|
+
links: CrmLink[];
|
|
1102
|
+
}
|
|
1103
|
+
/** One list window plus the total matching count. */
|
|
1104
|
+
interface RecordPage {
|
|
1105
|
+
records: CrmRecord[];
|
|
1106
|
+
total: number;
|
|
1107
|
+
limit: number;
|
|
1108
|
+
offset: number;
|
|
1109
|
+
}
|
|
1110
|
+
/** Typed access to every crm route. Methods reject with
|
|
1111
|
+
* {@link CrmClientError} on non-2xx responses. */
|
|
1112
|
+
declare class CrmClient {
|
|
1113
|
+
private readonly base;
|
|
1114
|
+
private readonly doFetch;
|
|
1115
|
+
private readonly headers?;
|
|
1116
|
+
constructor(options?: CrmClientOptions);
|
|
1117
|
+
private request;
|
|
1118
|
+
listRecords(params: CrmListParams): Promise<RecordPage>;
|
|
1119
|
+
getRecord(id: string): Promise<RecordDetail>;
|
|
1120
|
+
createRecord(body: {
|
|
1121
|
+
type: string;
|
|
1122
|
+
input: Record<string, unknown>;
|
|
1123
|
+
ownerId?: string;
|
|
1124
|
+
stage?: string;
|
|
1125
|
+
mutationId?: string;
|
|
1126
|
+
}): Promise<{
|
|
1127
|
+
id: string;
|
|
1128
|
+
duplicate: boolean;
|
|
1129
|
+
record: CrmRecord;
|
|
1130
|
+
}>;
|
|
1131
|
+
updateRecord(id: string, body: {
|
|
1132
|
+
input?: Record<string, unknown>;
|
|
1133
|
+
ownerId?: string | null;
|
|
1134
|
+
mutationId?: string;
|
|
1135
|
+
}): Promise<{
|
|
1136
|
+
record: CrmRecord;
|
|
1137
|
+
duplicate: boolean;
|
|
1138
|
+
}>;
|
|
1139
|
+
setArchived(id: string, archived: boolean): Promise<{
|
|
1140
|
+
duplicate: boolean;
|
|
1141
|
+
}>;
|
|
1142
|
+
setStage(id: string, to: string, mutationId?: string): Promise<{
|
|
1143
|
+
record: CrmRecord;
|
|
1144
|
+
from: string | null;
|
|
1145
|
+
duplicate: boolean;
|
|
1146
|
+
hookError?: string;
|
|
1147
|
+
}>;
|
|
1148
|
+
setRank(id: string, body: {
|
|
1149
|
+
beforeId?: string;
|
|
1150
|
+
afterId?: string;
|
|
1151
|
+
}): Promise<{
|
|
1152
|
+
rank: number;
|
|
1153
|
+
rebalanceNeeded: boolean;
|
|
1154
|
+
}>;
|
|
1155
|
+
addTag(id: string, tag: string): Promise<{
|
|
1156
|
+
tag: string;
|
|
1157
|
+
duplicate: boolean;
|
|
1158
|
+
}>;
|
|
1159
|
+
removeTag(id: string, tag: string): Promise<{
|
|
1160
|
+
duplicate: boolean;
|
|
1161
|
+
}>;
|
|
1162
|
+
setLink(id: string, body: {
|
|
1163
|
+
relation: string;
|
|
1164
|
+
toId: string;
|
|
1165
|
+
remove?: boolean;
|
|
1166
|
+
}): Promise<{
|
|
1167
|
+
duplicate: boolean;
|
|
1168
|
+
}>;
|
|
1169
|
+
linkIdentity(id: string, email?: string): Promise<{
|
|
1170
|
+
linked: boolean;
|
|
1171
|
+
clerkUserId?: string;
|
|
1172
|
+
}>;
|
|
1173
|
+
sendEmail(id: string, body: {
|
|
1174
|
+
templateId: string;
|
|
1175
|
+
vars?: Record<string, string>;
|
|
1176
|
+
dedupeKey?: string;
|
|
1177
|
+
channelId?: string;
|
|
1178
|
+
force?: boolean;
|
|
1179
|
+
}): Promise<{
|
|
1180
|
+
sent: boolean;
|
|
1181
|
+
reason?: string;
|
|
1182
|
+
}>;
|
|
1183
|
+
listActivities(recordId: string, opts?: {
|
|
1184
|
+
kind?: string;
|
|
1185
|
+
limit?: number;
|
|
1186
|
+
}): Promise<{
|
|
1187
|
+
activities: CrmActivity[];
|
|
1188
|
+
}>;
|
|
1189
|
+
addActivity(recordId: string, body: {
|
|
1190
|
+
kind: string;
|
|
1191
|
+
body: string;
|
|
1192
|
+
dueAt?: number;
|
|
1193
|
+
assigneeId?: string;
|
|
1194
|
+
waitingOn?: string;
|
|
1195
|
+
}): Promise<{
|
|
1196
|
+
id: string;
|
|
1197
|
+
duplicate: boolean;
|
|
1198
|
+
}>;
|
|
1199
|
+
updateTask(id: string, body: {
|
|
1200
|
+
status?: string;
|
|
1201
|
+
dueAt?: number | null;
|
|
1202
|
+
assigneeId?: string | null;
|
|
1203
|
+
waitingOn?: string | null;
|
|
1204
|
+
body?: string;
|
|
1205
|
+
}): Promise<{
|
|
1206
|
+
activity: CrmActivity;
|
|
1207
|
+
duplicate: boolean;
|
|
1208
|
+
}>;
|
|
1209
|
+
listTasks(opts?: {
|
|
1210
|
+
assigneeId?: string;
|
|
1211
|
+
status?: string[];
|
|
1212
|
+
limit?: number;
|
|
1213
|
+
}): Promise<{
|
|
1214
|
+
tasks: CrmActivity[];
|
|
1215
|
+
}>;
|
|
1216
|
+
listViews(type?: string): Promise<{
|
|
1217
|
+
views: CrmView[];
|
|
1218
|
+
}>;
|
|
1219
|
+
saveView(spec: ViewSpec): Promise<{
|
|
1220
|
+
id: string;
|
|
1221
|
+
duplicate: boolean;
|
|
1222
|
+
}>;
|
|
1223
|
+
updateView(id: string, spec: Partial<ViewSpec>): Promise<{
|
|
1224
|
+
view: CrmView;
|
|
1225
|
+
duplicate: boolean;
|
|
1226
|
+
}>;
|
|
1227
|
+
deleteView(id: string): Promise<{
|
|
1228
|
+
duplicate: boolean;
|
|
1229
|
+
}>;
|
|
1230
|
+
summary(type: string): Promise<TypeSummary>;
|
|
1231
|
+
getConfig(): Promise<{
|
|
1232
|
+
config: CrmConfigRow | null;
|
|
1233
|
+
}>;
|
|
1234
|
+
saveConfig(patch: ConfigPatch): Promise<{
|
|
1235
|
+
config: CrmConfigRow;
|
|
1236
|
+
duplicate: boolean;
|
|
1237
|
+
}>;
|
|
1238
|
+
emailLog(opts?: {
|
|
1239
|
+
recordId?: string;
|
|
1240
|
+
limit?: number;
|
|
1241
|
+
}): Promise<{
|
|
1242
|
+
log: Record<string, unknown>[];
|
|
1243
|
+
}>;
|
|
1244
|
+
rebalance(type: string): Promise<{
|
|
1245
|
+
count: number;
|
|
1246
|
+
}>;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
interface IntegrationSetting {
|
|
1250
|
+
key: string;
|
|
1251
|
+
description: string;
|
|
1252
|
+
public: boolean;
|
|
1253
|
+
pattern?: string;
|
|
1254
|
+
perEnv: boolean;
|
|
1255
|
+
source: string;
|
|
1256
|
+
}
|
|
1257
|
+
interface IntegrationSecret {
|
|
1258
|
+
key: string;
|
|
1259
|
+
description: string;
|
|
1260
|
+
pattern?: string;
|
|
1261
|
+
vault: boolean;
|
|
1262
|
+
}
|
|
1263
|
+
interface IntegrationProvision {
|
|
1264
|
+
human: string[];
|
|
1265
|
+
cli: string[];
|
|
1266
|
+
doctor: string[];
|
|
1267
|
+
}
|
|
1268
|
+
/** The CRM's descriptor shape: the shared base plus the schema + deny-all
|
|
1269
|
+
* rules provisioning installs (the chat-style extension). */
|
|
1270
|
+
interface CrmIntegrationDescriptor {
|
|
1271
|
+
id: string;
|
|
1272
|
+
title: string;
|
|
1273
|
+
npm: string;
|
|
1274
|
+
settings: IntegrationSetting[];
|
|
1275
|
+
secrets: IntegrationSecret[];
|
|
1276
|
+
schema: SerializedSchema;
|
|
1277
|
+
rules: CrmRules;
|
|
1278
|
+
provision: IntegrationProvision;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* The concrete descriptor for @odla-ai/crm — consumed by the odla CLI,
|
|
1282
|
+
* `odla doctor`, and the docs. Data only: it describes what installing the
|
|
1283
|
+
* CRM means (push {@link CRM_SCHEMA}, install deny-all {@link CRM_RULES},
|
|
1284
|
+
* seed the `crm_config` row, mount `createCrmRoutes` in the app worker); it
|
|
1285
|
+
* performs none of it. Billing secrets arrive with the @odla-ai/stripe
|
|
1286
|
+
* adapter (M2) — the M1 surface needs no vault entries.
|
|
1287
|
+
*/
|
|
1288
|
+
declare const crmIntegration: CrmIntegrationDescriptor;
|
|
1289
|
+
|
|
1290
|
+
export { ACTIVITY_KINDS, type ActivityKind, type AttrType, type BillingEvent, type BillingProvider, CONFIG_KEY, CONSENT_STATES, CRM_NS, CRM_RULES, CRM_SCHEMA, CRM_SLOTS, type CompiledList, type ConfigPatch, type ConsentEvent, type ConsentOutcome, type ConsentState, type Crm, type CrmActivity, type CrmActor, type CrmAggregateResult, type CrmAggregateSpec, type CrmAttrs, CrmClient, type CrmClientOptions, type CrmConfig, type CrmConfigRow, type CrmContactChannel, type CrmDb, type CrmDeps, type CrmEmailLogRow, type CrmEmailSender, type CrmEntityRef, CrmInputError, type CrmIntegrationDescriptor, type CrmLink, type CrmListParams, type CrmLookup, CrmNotFoundError, type CrmOp, type CrmQuery, type CrmRecord, type CrmResult, type CrmRouteOpts, type CrmRow, type CrmRule, type CrmRules, type CrmScalar, type CrmSlot, type CrmSort, type CrmTag, type CrmView, DEFAULT_LIMIT, EMAIL_STATUSES, type EmailStatus, type FieldDef, type FieldFilter, type FieldType, MAX_LIMIT, type PipelineDef, type PreparedWrite, RANK_EPSILON, RANK_STEP, type RelationDef, SORTABLE_COLUMNS, type SendEmailOpts, type SendEmailResult, type SerializedAttr, type SerializedEntity, type SerializedLink, type SerializedLinkEnd, type SerializedSchema, type StageDef, type StoredTemplate, type SubscriptionSnapshot, TASK_STATUSES, type TaskStatus, type TemplateSpec, type TypeDef, type TypeFacets, type TypeSummary, type ViewFilters, type ViewSpec, addActivity, addLink, addTag, applyConsent, applyConsentEvent, canEmail, canTransition, channelKey, compileList, createCrmRoutes, createRecord, crmIntegration, crmRules, defaultTemplates, defineCrm, deleteView, emailChannelOps, foldEmailStatus, getConfig, getRecord, initialStage, linkIdentity, lintTemplate, listActivities, listChannels, listEmailLog, listLinks, listRecords, listTags, listTasks, listViews, mustGetRecord, needsRebalance, normalizeTag, prepare, rankBetween, rebalancePlan, rebalanceRanks, recordCanEmail, removeLink, removeTag, renderTemplate, resolveDeps, resolveSortColumn, rowToRecord, saveConfig, saveView, searchTextFor, sendTemplatedEmail, setArchived, setRank, setStage, stageIndexOf, templateVars, typeSummary, updateRecord, updateTask, updateView };
|