@odla-ai/crm 0.3.2 → 0.5.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 +41 -1
- package/dist/index.cjs +390 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +136 -2
- package/dist/index.d.ts +136 -2
- package/dist/index.js +390 -12
- package/dist/index.js.map +1 -1
- package/dist/ui/index.d.ts +37 -1
- package/dist/ui/index.js +82 -28
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
- package/ui.css +4 -0
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,8 @@ declare const CRM_NS: {
|
|
|
8
8
|
readonly emailLog: "crm_email_log";
|
|
9
9
|
readonly view: "crm_view";
|
|
10
10
|
readonly config: "crm_config";
|
|
11
|
+
readonly origin: "crm_record_origin";
|
|
12
|
+
readonly delivery: "crm_record_delivery";
|
|
11
13
|
};
|
|
12
14
|
/** Generic promoted columns a type's custom fields can claim for indexed
|
|
13
15
|
* sort/filter: four strings, three numbers, two dates. Slots are per-type
|
|
@@ -75,7 +77,7 @@ interface SerializedSchema {
|
|
|
75
77
|
links: Record<string, SerializedLink>;
|
|
76
78
|
}
|
|
77
79
|
/**
|
|
78
|
-
* The pre-serialized (wire-shape) odla-db schema for the
|
|
80
|
+
* The pre-serialized (wire-shape) odla-db schema for the ten crm
|
|
79
81
|
* namespaces; POST it to `/app/:id/schema` as `{ schema: CRM_SCHEMA }`.
|
|
80
82
|
* One generic `crm_record` holds every record type (the type registry is
|
|
81
83
|
* app config, not schema); natural-key uniqueness on tags, links, channels,
|
|
@@ -328,6 +330,32 @@ interface CrmConfigRow {
|
|
|
328
330
|
settings: Record<string, unknown>;
|
|
329
331
|
updatedAt: number;
|
|
330
332
|
}
|
|
333
|
+
/** Structured upstream identity for a record received from another app. */
|
|
334
|
+
interface CrmRecordOrigin {
|
|
335
|
+
id: string;
|
|
336
|
+
key: string;
|
|
337
|
+
recordId: string;
|
|
338
|
+
sourceId: string;
|
|
339
|
+
sourceRecordId: string;
|
|
340
|
+
sourceUrl?: string;
|
|
341
|
+
payloadVersion: number;
|
|
342
|
+
firstReceivedAt: number;
|
|
343
|
+
lastReceivedAt: number;
|
|
344
|
+
}
|
|
345
|
+
/** Latest delivery state for one local record → remote target edge. */
|
|
346
|
+
interface CrmRecordDelivery {
|
|
347
|
+
id: string;
|
|
348
|
+
key: string;
|
|
349
|
+
recordId: string;
|
|
350
|
+
targetId: string;
|
|
351
|
+
remoteRecordId?: string;
|
|
352
|
+
status: "delivered" | "failed";
|
|
353
|
+
attempts: number;
|
|
354
|
+
payloadVersion: number;
|
|
355
|
+
lastAttemptAt: number;
|
|
356
|
+
deliveredAt?: number;
|
|
357
|
+
error?: string;
|
|
358
|
+
}
|
|
331
359
|
/** Outcome of validating + coercing input for a type (see `prepare`). On
|
|
332
360
|
* success, `attrs` are the columns to WRITE (never null — odla-db rejects null
|
|
333
361
|
* on a typed scalar) and `retract` names the slots/promoted columns to CLEAR
|
|
@@ -386,6 +414,9 @@ interface TypeFacets {
|
|
|
386
414
|
interface TypeDef {
|
|
387
415
|
label: string;
|
|
388
416
|
labelPlural?: string;
|
|
417
|
+
/** Optional admin collection group. Hosts can keep people and portfolio
|
|
418
|
+
* records in separate workspaces without moving either outside the CRM. */
|
|
419
|
+
workspace?: string;
|
|
389
420
|
/** Field mapped to the promoted `name` column. Default `"name"`. */
|
|
390
421
|
nameField?: string;
|
|
391
422
|
/** `email`-typed field mapped to `primaryEmail` (lowercased) and backed by
|
|
@@ -443,6 +474,12 @@ interface Crm {
|
|
|
443
474
|
* request runs.
|
|
444
475
|
*/
|
|
445
476
|
declare function defineCrm(config: CrmConfig): Crm;
|
|
477
|
+
/**
|
|
478
|
+
* Compose independently-owned CRM config fragments. Duplicate type, relation,
|
|
479
|
+
* or template ids fail closed so adopting a feature preset cannot silently
|
|
480
|
+
* replace a host's operating pipeline or email classification.
|
|
481
|
+
*/
|
|
482
|
+
declare function composeCrmConfigs(...configs: readonly CrmConfig[]): CrmConfig;
|
|
446
483
|
|
|
447
484
|
/** The stage a new record of this type starts in (first declared stage). */
|
|
448
485
|
declare function initialStage(def: TypeDef): string | undefined;
|
|
@@ -486,6 +523,45 @@ declare class CrmNotFoundError extends Error {
|
|
|
486
523
|
constructor(what: string);
|
|
487
524
|
}
|
|
488
525
|
|
|
526
|
+
/** CRM resources that can be shared into a Discussion message. */
|
|
527
|
+
declare const CRM_DISCUSSION_REFERENCE_KINDS: readonly ["crm:record", "crm:activity"];
|
|
528
|
+
/** One CRM resource kind understood by the native CRM destination. */
|
|
529
|
+
type CrmDiscussionReferenceKind = (typeof CRM_DISCUSSION_REFERENCE_KINDS)[number];
|
|
530
|
+
/** Canonical CRM destination target parsed from an `odla-ref` deep link. */
|
|
531
|
+
interface CrmDiscussionReferenceTarget {
|
|
532
|
+
kind: CrmDiscussionReferenceKind;
|
|
533
|
+
type: string;
|
|
534
|
+
recordId: string;
|
|
535
|
+
activityId?: string;
|
|
536
|
+
}
|
|
537
|
+
/** Product-owned projection returned to Discussion typeahead and exact lookup. */
|
|
538
|
+
interface CrmDiscussionReference {
|
|
539
|
+
/** Canonical CRM kind used in stored Discussion ref markup. */
|
|
540
|
+
kind: CrmDiscussionReferenceKind;
|
|
541
|
+
/** Opaque durable product id; never infer CRM access from its segments. */
|
|
542
|
+
id: string;
|
|
543
|
+
/** Product-authored primary display name. */
|
|
544
|
+
label: string;
|
|
545
|
+
/** Short product-authored secondary context for the picker. */
|
|
546
|
+
hint: string;
|
|
547
|
+
/** Bounded product-authored context safe to show an LLM or person. */
|
|
548
|
+
summary: string;
|
|
549
|
+
/** Current product status at inspection time. */
|
|
550
|
+
status: string;
|
|
551
|
+
/** Human-readable native surface the link opens. */
|
|
552
|
+
destination: string;
|
|
553
|
+
/** Same-origin native link; navigation is not mutation authority. */
|
|
554
|
+
href: string;
|
|
555
|
+
}
|
|
556
|
+
/** Durable ref id: `type/recordId`, plus an activity id for feed entries. */
|
|
557
|
+
declare function crmDiscussionReferenceId(target: CrmDiscussionReferenceTarget): string;
|
|
558
|
+
/** Canonical value stored in the stable `odla-ref` query parameter. */
|
|
559
|
+
declare function formatCrmDiscussionReference(target: CrmDiscussionReferenceTarget): string;
|
|
560
|
+
/** Parse and validate a CRM `odla-ref`; malformed and cross-product refs fail closed. */
|
|
561
|
+
declare function parseCrmDiscussionReference(input: URL | string): CrmDiscussionReferenceTarget | null;
|
|
562
|
+
/** Build a Chapter-compatible CRM deep link and retain the exact ref for focus. */
|
|
563
|
+
declare function crmDiscussionReferenceHref(current: URL, target: CrmDiscussionReferenceTarget, basePath?: string): string;
|
|
564
|
+
|
|
489
565
|
/** What every op needs: the resolved config, the injected db, test overrides. */
|
|
490
566
|
interface CrmDeps {
|
|
491
567
|
crm: Crm;
|
|
@@ -762,6 +838,47 @@ declare function removeLink(deps: CrmDeps, opts: {
|
|
|
762
838
|
/** Every link touching a record, either direction. */
|
|
763
839
|
declare function listLinks(deps: CrmDeps, recordId: string): Promise<CrmLink[]>;
|
|
764
840
|
|
|
841
|
+
/** Stable natural key for an upstream record identity. */
|
|
842
|
+
declare function recordOriginKey(sourceId: string, sourceRecordId: string): string;
|
|
843
|
+
/** Look up a structured origin row by upstream site + record id. */
|
|
844
|
+
declare function getRecordOrigin(deps: CrmDeps, sourceId: string, sourceRecordId: string): Promise<CrmRecordOrigin | null>;
|
|
845
|
+
/** Resolve the local CRM record identified by an upstream origin. */
|
|
846
|
+
declare function getRecordByOrigin(deps: CrmDeps, sourceId: string, sourceRecordId: string): Promise<CrmRecord | null>;
|
|
847
|
+
/** Idempotently bind one upstream record identity to a local CRM record. */
|
|
848
|
+
declare function upsertRecordOrigin(deps: CrmDeps, opts: {
|
|
849
|
+
recordId: string;
|
|
850
|
+
sourceId: string;
|
|
851
|
+
sourceRecordId: string;
|
|
852
|
+
sourceUrl?: string;
|
|
853
|
+
payloadVersion: number;
|
|
854
|
+
mutationId?: string;
|
|
855
|
+
}): Promise<{
|
|
856
|
+
origin: CrmRecordOrigin;
|
|
857
|
+
duplicate: boolean;
|
|
858
|
+
}>;
|
|
859
|
+
/** List every upstream identity attached to a local record. */
|
|
860
|
+
declare function listRecordOrigins(deps: CrmDeps, recordId: string): Promise<CrmRecordOrigin[]>;
|
|
861
|
+
/** Stable natural key for one local record → target delivery edge. */
|
|
862
|
+
declare function recordDeliveryKey(recordId: string, targetId: string): string;
|
|
863
|
+
/** Record one success or failure while retaining the latest edge state. */
|
|
864
|
+
declare function recordDeliveryAttempt(deps: CrmDeps, opts: {
|
|
865
|
+
recordId: string;
|
|
866
|
+
targetId: string;
|
|
867
|
+
status: "delivered" | "failed";
|
|
868
|
+
payloadVersion: number;
|
|
869
|
+
remoteRecordId?: string;
|
|
870
|
+
error?: string;
|
|
871
|
+
mutationId?: string;
|
|
872
|
+
}): Promise<{
|
|
873
|
+
delivery: CrmRecordDelivery;
|
|
874
|
+
duplicate: boolean;
|
|
875
|
+
}>;
|
|
876
|
+
/** List delivery state for one record, or every edge to one target. */
|
|
877
|
+
declare function listRecordDeliveries(deps: CrmDeps, filter: {
|
|
878
|
+
recordId?: string;
|
|
879
|
+
targetId?: string;
|
|
880
|
+
}): Promise<CrmRecordDelivery[]>;
|
|
881
|
+
|
|
765
882
|
/** Append a note/call/meeting or open a follow-up task on a record. */
|
|
766
883
|
declare function addActivity(deps: CrmDeps, opts: {
|
|
767
884
|
recordId: string;
|
|
@@ -1062,6 +1179,13 @@ interface BillingProvider {
|
|
|
1062
1179
|
interface CrmActor {
|
|
1063
1180
|
userId: string;
|
|
1064
1181
|
email?: string;
|
|
1182
|
+
/** Explicit product ACL for the read-only Discussion projection. Ordinary
|
|
1183
|
+
* CRM routes do not consult or grant this marker. */
|
|
1184
|
+
discussionReferenceScope?: "all";
|
|
1185
|
+
}
|
|
1186
|
+
/** Actor accepted by the product-owned CRM reference projection. */
|
|
1187
|
+
interface CrmDiscussionReferenceActor extends CrmActor {
|
|
1188
|
+
discussionReferenceScope: "all";
|
|
1065
1189
|
}
|
|
1066
1190
|
/** Everything `createCrmRoutes` needs from the host worker. */
|
|
1067
1191
|
interface CrmRouteOpts {
|
|
@@ -1070,6 +1194,10 @@ interface CrmRouteOpts {
|
|
|
1070
1194
|
/** Host-owned auth: resolve the request to an admin actor or null (401).
|
|
1071
1195
|
* The unsubscribe endpoints are the only routes that skip this. */
|
|
1072
1196
|
authorize: (req: Request) => Promise<CrmActor | null> | CrmActor | null;
|
|
1197
|
+
/** Optional host authority seam for read-only Discussion reference lookup.
|
|
1198
|
+
* Verify exact CRM product, crm.read capability, canonical audience,
|
|
1199
|
+
* principal, current app lifetime/environment, and agent grant provenance. */
|
|
1200
|
+
authorizeDiscussionReferences?: (req: Request) => Promise<CrmDiscussionReferenceActor | null> | CrmDiscussionReferenceActor | null;
|
|
1073
1201
|
/** Email transport; omit for log-only behavior. */
|
|
1074
1202
|
sender?: CrmEmailSender;
|
|
1075
1203
|
/** Sender address for outbound mail (verified from-address). */
|
|
@@ -1081,6 +1209,8 @@ interface CrmRouteOpts {
|
|
|
1081
1209
|
baseUrl?: string;
|
|
1082
1210
|
/** Mount point. Default "/api/crm". */
|
|
1083
1211
|
basePath?: string;
|
|
1212
|
+
/** Native UI mount used by returned Discussion deep links. Default "/admin/". */
|
|
1213
|
+
discussionBasePath?: string;
|
|
1084
1214
|
/** Injectable clock/id factory (tests). */
|
|
1085
1215
|
now?: () => number;
|
|
1086
1216
|
newId?: () => string;
|
|
@@ -1112,6 +1242,10 @@ interface RecordDetail {
|
|
|
1112
1242
|
tags: CrmTag[];
|
|
1113
1243
|
channels: CrmContactChannel[];
|
|
1114
1244
|
links: CrmLink[];
|
|
1245
|
+
/** Structured upstream identities; absent only from pre-upgrade custom APIs. */
|
|
1246
|
+
origins?: CrmRecordOrigin[];
|
|
1247
|
+
/** Latest outbound state per target; absent only from pre-upgrade custom APIs. */
|
|
1248
|
+
deliveries?: CrmRecordDelivery[];
|
|
1115
1249
|
}
|
|
1116
1250
|
/** One list window plus the total matching count. */
|
|
1117
1251
|
interface RecordPage {
|
|
@@ -1338,4 +1472,4 @@ declare const crmIntegration: CrmIntegrationDescriptor;
|
|
|
1338
1472
|
*/
|
|
1339
1473
|
declare function createCrmIntegration(crm: Crm, options?: CrmIntegrationOptions): CrmIntegrationDescriptor;
|
|
1340
1474
|
|
|
1341
|
-
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 CrmIntegrationOptions, type CrmIntegrationProbe, type CrmIntegrationSeed, 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, createCrmIntegration, 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 };
|
|
1475
|
+
export { ACTIVITY_KINDS, type ActivityKind, type AttrType, type BillingEvent, type BillingProvider, CONFIG_KEY, CONSENT_STATES, CRM_DISCUSSION_REFERENCE_KINDS, 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 CrmDiscussionReference, type CrmDiscussionReferenceActor, type CrmDiscussionReferenceKind, type CrmDiscussionReferenceTarget, type CrmEmailLogRow, type CrmEmailSender, type CrmEntityRef, CrmInputError, type CrmIntegrationDescriptor, type CrmIntegrationOptions, type CrmIntegrationProbe, type CrmIntegrationSeed, type CrmLink, type CrmListParams, type CrmLookup, CrmNotFoundError, type CrmOp, type CrmQuery, type CrmRecord, type CrmRecordDelivery, type CrmRecordOrigin, 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, composeCrmConfigs, createCrmIntegration, createCrmRoutes, createRecord, crmDiscussionReferenceHref, crmDiscussionReferenceId, crmIntegration, crmRules, defaultTemplates, defineCrm, deleteView, emailChannelOps, foldEmailStatus, formatCrmDiscussionReference, getConfig, getRecord, getRecordByOrigin, getRecordOrigin, initialStage, linkIdentity, lintTemplate, listActivities, listChannels, listEmailLog, listLinks, listRecordDeliveries, listRecordOrigins, listRecords, listTags, listTasks, listViews, mustGetRecord, needsRebalance, normalizeTag, parseCrmDiscussionReference, prepare, rankBetween, rebalancePlan, rebalanceRanks, recordCanEmail, recordDeliveryAttempt, recordDeliveryKey, recordOriginKey, removeLink, removeTag, renderTemplate, resolveDeps, resolveSortColumn, rowToRecord, saveConfig, saveView, searchTextFor, sendTemplatedEmail, setArchived, setRank, setStage, stageIndexOf, templateVars, typeSummary, updateRecord, updateTask, updateView, upsertRecordOrigin };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ declare const CRM_NS: {
|
|
|
8
8
|
readonly emailLog: "crm_email_log";
|
|
9
9
|
readonly view: "crm_view";
|
|
10
10
|
readonly config: "crm_config";
|
|
11
|
+
readonly origin: "crm_record_origin";
|
|
12
|
+
readonly delivery: "crm_record_delivery";
|
|
11
13
|
};
|
|
12
14
|
/** Generic promoted columns a type's custom fields can claim for indexed
|
|
13
15
|
* sort/filter: four strings, three numbers, two dates. Slots are per-type
|
|
@@ -75,7 +77,7 @@ interface SerializedSchema {
|
|
|
75
77
|
links: Record<string, SerializedLink>;
|
|
76
78
|
}
|
|
77
79
|
/**
|
|
78
|
-
* The pre-serialized (wire-shape) odla-db schema for the
|
|
80
|
+
* The pre-serialized (wire-shape) odla-db schema for the ten crm
|
|
79
81
|
* namespaces; POST it to `/app/:id/schema` as `{ schema: CRM_SCHEMA }`.
|
|
80
82
|
* One generic `crm_record` holds every record type (the type registry is
|
|
81
83
|
* app config, not schema); natural-key uniqueness on tags, links, channels,
|
|
@@ -328,6 +330,32 @@ interface CrmConfigRow {
|
|
|
328
330
|
settings: Record<string, unknown>;
|
|
329
331
|
updatedAt: number;
|
|
330
332
|
}
|
|
333
|
+
/** Structured upstream identity for a record received from another app. */
|
|
334
|
+
interface CrmRecordOrigin {
|
|
335
|
+
id: string;
|
|
336
|
+
key: string;
|
|
337
|
+
recordId: string;
|
|
338
|
+
sourceId: string;
|
|
339
|
+
sourceRecordId: string;
|
|
340
|
+
sourceUrl?: string;
|
|
341
|
+
payloadVersion: number;
|
|
342
|
+
firstReceivedAt: number;
|
|
343
|
+
lastReceivedAt: number;
|
|
344
|
+
}
|
|
345
|
+
/** Latest delivery state for one local record → remote target edge. */
|
|
346
|
+
interface CrmRecordDelivery {
|
|
347
|
+
id: string;
|
|
348
|
+
key: string;
|
|
349
|
+
recordId: string;
|
|
350
|
+
targetId: string;
|
|
351
|
+
remoteRecordId?: string;
|
|
352
|
+
status: "delivered" | "failed";
|
|
353
|
+
attempts: number;
|
|
354
|
+
payloadVersion: number;
|
|
355
|
+
lastAttemptAt: number;
|
|
356
|
+
deliveredAt?: number;
|
|
357
|
+
error?: string;
|
|
358
|
+
}
|
|
331
359
|
/** Outcome of validating + coercing input for a type (see `prepare`). On
|
|
332
360
|
* success, `attrs` are the columns to WRITE (never null — odla-db rejects null
|
|
333
361
|
* on a typed scalar) and `retract` names the slots/promoted columns to CLEAR
|
|
@@ -386,6 +414,9 @@ interface TypeFacets {
|
|
|
386
414
|
interface TypeDef {
|
|
387
415
|
label: string;
|
|
388
416
|
labelPlural?: string;
|
|
417
|
+
/** Optional admin collection group. Hosts can keep people and portfolio
|
|
418
|
+
* records in separate workspaces without moving either outside the CRM. */
|
|
419
|
+
workspace?: string;
|
|
389
420
|
/** Field mapped to the promoted `name` column. Default `"name"`. */
|
|
390
421
|
nameField?: string;
|
|
391
422
|
/** `email`-typed field mapped to `primaryEmail` (lowercased) and backed by
|
|
@@ -443,6 +474,12 @@ interface Crm {
|
|
|
443
474
|
* request runs.
|
|
444
475
|
*/
|
|
445
476
|
declare function defineCrm(config: CrmConfig): Crm;
|
|
477
|
+
/**
|
|
478
|
+
* Compose independently-owned CRM config fragments. Duplicate type, relation,
|
|
479
|
+
* or template ids fail closed so adopting a feature preset cannot silently
|
|
480
|
+
* replace a host's operating pipeline or email classification.
|
|
481
|
+
*/
|
|
482
|
+
declare function composeCrmConfigs(...configs: readonly CrmConfig[]): CrmConfig;
|
|
446
483
|
|
|
447
484
|
/** The stage a new record of this type starts in (first declared stage). */
|
|
448
485
|
declare function initialStage(def: TypeDef): string | undefined;
|
|
@@ -486,6 +523,45 @@ declare class CrmNotFoundError extends Error {
|
|
|
486
523
|
constructor(what: string);
|
|
487
524
|
}
|
|
488
525
|
|
|
526
|
+
/** CRM resources that can be shared into a Discussion message. */
|
|
527
|
+
declare const CRM_DISCUSSION_REFERENCE_KINDS: readonly ["crm:record", "crm:activity"];
|
|
528
|
+
/** One CRM resource kind understood by the native CRM destination. */
|
|
529
|
+
type CrmDiscussionReferenceKind = (typeof CRM_DISCUSSION_REFERENCE_KINDS)[number];
|
|
530
|
+
/** Canonical CRM destination target parsed from an `odla-ref` deep link. */
|
|
531
|
+
interface CrmDiscussionReferenceTarget {
|
|
532
|
+
kind: CrmDiscussionReferenceKind;
|
|
533
|
+
type: string;
|
|
534
|
+
recordId: string;
|
|
535
|
+
activityId?: string;
|
|
536
|
+
}
|
|
537
|
+
/** Product-owned projection returned to Discussion typeahead and exact lookup. */
|
|
538
|
+
interface CrmDiscussionReference {
|
|
539
|
+
/** Canonical CRM kind used in stored Discussion ref markup. */
|
|
540
|
+
kind: CrmDiscussionReferenceKind;
|
|
541
|
+
/** Opaque durable product id; never infer CRM access from its segments. */
|
|
542
|
+
id: string;
|
|
543
|
+
/** Product-authored primary display name. */
|
|
544
|
+
label: string;
|
|
545
|
+
/** Short product-authored secondary context for the picker. */
|
|
546
|
+
hint: string;
|
|
547
|
+
/** Bounded product-authored context safe to show an LLM or person. */
|
|
548
|
+
summary: string;
|
|
549
|
+
/** Current product status at inspection time. */
|
|
550
|
+
status: string;
|
|
551
|
+
/** Human-readable native surface the link opens. */
|
|
552
|
+
destination: string;
|
|
553
|
+
/** Same-origin native link; navigation is not mutation authority. */
|
|
554
|
+
href: string;
|
|
555
|
+
}
|
|
556
|
+
/** Durable ref id: `type/recordId`, plus an activity id for feed entries. */
|
|
557
|
+
declare function crmDiscussionReferenceId(target: CrmDiscussionReferenceTarget): string;
|
|
558
|
+
/** Canonical value stored in the stable `odla-ref` query parameter. */
|
|
559
|
+
declare function formatCrmDiscussionReference(target: CrmDiscussionReferenceTarget): string;
|
|
560
|
+
/** Parse and validate a CRM `odla-ref`; malformed and cross-product refs fail closed. */
|
|
561
|
+
declare function parseCrmDiscussionReference(input: URL | string): CrmDiscussionReferenceTarget | null;
|
|
562
|
+
/** Build a Chapter-compatible CRM deep link and retain the exact ref for focus. */
|
|
563
|
+
declare function crmDiscussionReferenceHref(current: URL, target: CrmDiscussionReferenceTarget, basePath?: string): string;
|
|
564
|
+
|
|
489
565
|
/** What every op needs: the resolved config, the injected db, test overrides. */
|
|
490
566
|
interface CrmDeps {
|
|
491
567
|
crm: Crm;
|
|
@@ -762,6 +838,47 @@ declare function removeLink(deps: CrmDeps, opts: {
|
|
|
762
838
|
/** Every link touching a record, either direction. */
|
|
763
839
|
declare function listLinks(deps: CrmDeps, recordId: string): Promise<CrmLink[]>;
|
|
764
840
|
|
|
841
|
+
/** Stable natural key for an upstream record identity. */
|
|
842
|
+
declare function recordOriginKey(sourceId: string, sourceRecordId: string): string;
|
|
843
|
+
/** Look up a structured origin row by upstream site + record id. */
|
|
844
|
+
declare function getRecordOrigin(deps: CrmDeps, sourceId: string, sourceRecordId: string): Promise<CrmRecordOrigin | null>;
|
|
845
|
+
/** Resolve the local CRM record identified by an upstream origin. */
|
|
846
|
+
declare function getRecordByOrigin(deps: CrmDeps, sourceId: string, sourceRecordId: string): Promise<CrmRecord | null>;
|
|
847
|
+
/** Idempotently bind one upstream record identity to a local CRM record. */
|
|
848
|
+
declare function upsertRecordOrigin(deps: CrmDeps, opts: {
|
|
849
|
+
recordId: string;
|
|
850
|
+
sourceId: string;
|
|
851
|
+
sourceRecordId: string;
|
|
852
|
+
sourceUrl?: string;
|
|
853
|
+
payloadVersion: number;
|
|
854
|
+
mutationId?: string;
|
|
855
|
+
}): Promise<{
|
|
856
|
+
origin: CrmRecordOrigin;
|
|
857
|
+
duplicate: boolean;
|
|
858
|
+
}>;
|
|
859
|
+
/** List every upstream identity attached to a local record. */
|
|
860
|
+
declare function listRecordOrigins(deps: CrmDeps, recordId: string): Promise<CrmRecordOrigin[]>;
|
|
861
|
+
/** Stable natural key for one local record → target delivery edge. */
|
|
862
|
+
declare function recordDeliveryKey(recordId: string, targetId: string): string;
|
|
863
|
+
/** Record one success or failure while retaining the latest edge state. */
|
|
864
|
+
declare function recordDeliveryAttempt(deps: CrmDeps, opts: {
|
|
865
|
+
recordId: string;
|
|
866
|
+
targetId: string;
|
|
867
|
+
status: "delivered" | "failed";
|
|
868
|
+
payloadVersion: number;
|
|
869
|
+
remoteRecordId?: string;
|
|
870
|
+
error?: string;
|
|
871
|
+
mutationId?: string;
|
|
872
|
+
}): Promise<{
|
|
873
|
+
delivery: CrmRecordDelivery;
|
|
874
|
+
duplicate: boolean;
|
|
875
|
+
}>;
|
|
876
|
+
/** List delivery state for one record, or every edge to one target. */
|
|
877
|
+
declare function listRecordDeliveries(deps: CrmDeps, filter: {
|
|
878
|
+
recordId?: string;
|
|
879
|
+
targetId?: string;
|
|
880
|
+
}): Promise<CrmRecordDelivery[]>;
|
|
881
|
+
|
|
765
882
|
/** Append a note/call/meeting or open a follow-up task on a record. */
|
|
766
883
|
declare function addActivity(deps: CrmDeps, opts: {
|
|
767
884
|
recordId: string;
|
|
@@ -1062,6 +1179,13 @@ interface BillingProvider {
|
|
|
1062
1179
|
interface CrmActor {
|
|
1063
1180
|
userId: string;
|
|
1064
1181
|
email?: string;
|
|
1182
|
+
/** Explicit product ACL for the read-only Discussion projection. Ordinary
|
|
1183
|
+
* CRM routes do not consult or grant this marker. */
|
|
1184
|
+
discussionReferenceScope?: "all";
|
|
1185
|
+
}
|
|
1186
|
+
/** Actor accepted by the product-owned CRM reference projection. */
|
|
1187
|
+
interface CrmDiscussionReferenceActor extends CrmActor {
|
|
1188
|
+
discussionReferenceScope: "all";
|
|
1065
1189
|
}
|
|
1066
1190
|
/** Everything `createCrmRoutes` needs from the host worker. */
|
|
1067
1191
|
interface CrmRouteOpts {
|
|
@@ -1070,6 +1194,10 @@ interface CrmRouteOpts {
|
|
|
1070
1194
|
/** Host-owned auth: resolve the request to an admin actor or null (401).
|
|
1071
1195
|
* The unsubscribe endpoints are the only routes that skip this. */
|
|
1072
1196
|
authorize: (req: Request) => Promise<CrmActor | null> | CrmActor | null;
|
|
1197
|
+
/** Optional host authority seam for read-only Discussion reference lookup.
|
|
1198
|
+
* Verify exact CRM product, crm.read capability, canonical audience,
|
|
1199
|
+
* principal, current app lifetime/environment, and agent grant provenance. */
|
|
1200
|
+
authorizeDiscussionReferences?: (req: Request) => Promise<CrmDiscussionReferenceActor | null> | CrmDiscussionReferenceActor | null;
|
|
1073
1201
|
/** Email transport; omit for log-only behavior. */
|
|
1074
1202
|
sender?: CrmEmailSender;
|
|
1075
1203
|
/** Sender address for outbound mail (verified from-address). */
|
|
@@ -1081,6 +1209,8 @@ interface CrmRouteOpts {
|
|
|
1081
1209
|
baseUrl?: string;
|
|
1082
1210
|
/** Mount point. Default "/api/crm". */
|
|
1083
1211
|
basePath?: string;
|
|
1212
|
+
/** Native UI mount used by returned Discussion deep links. Default "/admin/". */
|
|
1213
|
+
discussionBasePath?: string;
|
|
1084
1214
|
/** Injectable clock/id factory (tests). */
|
|
1085
1215
|
now?: () => number;
|
|
1086
1216
|
newId?: () => string;
|
|
@@ -1112,6 +1242,10 @@ interface RecordDetail {
|
|
|
1112
1242
|
tags: CrmTag[];
|
|
1113
1243
|
channels: CrmContactChannel[];
|
|
1114
1244
|
links: CrmLink[];
|
|
1245
|
+
/** Structured upstream identities; absent only from pre-upgrade custom APIs. */
|
|
1246
|
+
origins?: CrmRecordOrigin[];
|
|
1247
|
+
/** Latest outbound state per target; absent only from pre-upgrade custom APIs. */
|
|
1248
|
+
deliveries?: CrmRecordDelivery[];
|
|
1115
1249
|
}
|
|
1116
1250
|
/** One list window plus the total matching count. */
|
|
1117
1251
|
interface RecordPage {
|
|
@@ -1338,4 +1472,4 @@ declare const crmIntegration: CrmIntegrationDescriptor;
|
|
|
1338
1472
|
*/
|
|
1339
1473
|
declare function createCrmIntegration(crm: Crm, options?: CrmIntegrationOptions): CrmIntegrationDescriptor;
|
|
1340
1474
|
|
|
1341
|
-
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 CrmIntegrationOptions, type CrmIntegrationProbe, type CrmIntegrationSeed, 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, createCrmIntegration, 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 };
|
|
1475
|
+
export { ACTIVITY_KINDS, type ActivityKind, type AttrType, type BillingEvent, type BillingProvider, CONFIG_KEY, CONSENT_STATES, CRM_DISCUSSION_REFERENCE_KINDS, 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 CrmDiscussionReference, type CrmDiscussionReferenceActor, type CrmDiscussionReferenceKind, type CrmDiscussionReferenceTarget, type CrmEmailLogRow, type CrmEmailSender, type CrmEntityRef, CrmInputError, type CrmIntegrationDescriptor, type CrmIntegrationOptions, type CrmIntegrationProbe, type CrmIntegrationSeed, type CrmLink, type CrmListParams, type CrmLookup, CrmNotFoundError, type CrmOp, type CrmQuery, type CrmRecord, type CrmRecordDelivery, type CrmRecordOrigin, 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, composeCrmConfigs, createCrmIntegration, createCrmRoutes, createRecord, crmDiscussionReferenceHref, crmDiscussionReferenceId, crmIntegration, crmRules, defaultTemplates, defineCrm, deleteView, emailChannelOps, foldEmailStatus, formatCrmDiscussionReference, getConfig, getRecord, getRecordByOrigin, getRecordOrigin, initialStage, linkIdentity, lintTemplate, listActivities, listChannels, listEmailLog, listLinks, listRecordDeliveries, listRecordOrigins, listRecords, listTags, listTasks, listViews, mustGetRecord, needsRebalance, normalizeTag, parseCrmDiscussionReference, prepare, rankBetween, rebalancePlan, rebalanceRanks, recordCanEmail, recordDeliveryAttempt, recordDeliveryKey, recordOriginKey, removeLink, removeTag, renderTemplate, resolveDeps, resolveSortColumn, rowToRecord, saveConfig, saveView, searchTextFor, sendTemplatedEmail, setArchived, setRank, setStage, stageIndexOf, templateVars, typeSummary, updateRecord, updateTask, updateView, upsertRecordOrigin };
|