@classytic/crm 0.5.0 → 0.5.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to `@classytic/crm` are documented here.
4
4
 
5
+ ## [0.5.1] — 2026-06-14
6
+
7
+ ### Fixed — declaration bundle
8
+
9
+ - **fix: declaration bundle exported mangled aliases; consumer named imports
10
+ now resolve.** The published `dist/index.d.ts` re-exported every public
11
+ symbol under a minified alias (`export { AccountRepository as A, CRM_EVENTS
12
+ as Rr, … }`), so downstream `import { AccountRepository, CRM_EVENTS } from
13
+ '@classytic/crm'` failed with TS2305 / TS2460. Root cause: the `./events`
14
+ entry re-exports a strict subset of the `index` barrel, which made
15
+ `rolldown-plugin-dts` alias every name on the superset (`index`) entry when
16
+ both were emitted in a single pass. Build now runs `index` and `events` as
17
+ two independent tsdown passes (array config) so each `.d.ts` exports real
18
+ names. `tsdown` bumped `^0.14.2` → `^0.21.10` to match sibling packages.
19
+ No runtime/API change.
20
+
5
21
  ## [0.5.0] — 2026-06-14
6
22
 
7
23
  Stack upgrade + verified correctness fixes + PACKAGE_RULES compliance. No
package/dist/events.d.ts CHANGED
@@ -1,2 +1,413 @@
1
- import { $n as ContactUpdated, Ar as PipelineArchived, Bn as ActivityOutcomeRecorded, Cr as OpportunityAssigned, Dr as OpportunityStageAdvanced, Er as OpportunityLost, Fn as AccountEnriched, Fr as SubscriptionCreated, Gn as CampaignCompleted, Hn as ActivityRescheduled, In as AccountMerged, Ir as SubscriptionUnsubscribed, Jn as CampaignResumed, Kn as CampaignCreated, Ln as AccountUpdated, Lr as crmEventDefinitions, Mr as SubscriptionBounced, Nn as AccountAssigned, Nr as SubscriptionComplained, Or as OpportunityStageRegressed, Pn as AccountCreated, Pr as SubscriptionConfirmed, Qn as ContactMerged, Rn as ActivityCancelled, Rr as CRM_EVENTS, Sr as OpportunityAmountChanged, Tr as OpportunityExtended, Un as CampaignActivated, Vn as ActivityPlanned, Wn as CampaignArchived, Xn as ContactCreated, Yn as ContactAssigned, Zn as ContactEnriched, _r as LeadStatusChanged, ar as CrmEventSchema, br as NoteAdded, cr as EmailEventComplained, dr as LeadAssigned, er as ConversationAssigned, fr as LeadConverted, gr as LeadScored, hr as LeadEnriched, ir as CrmEventDefinition, jr as PipelineCreated, kr as OpportunityWon, lr as EmailEventOpened, mr as LeadDisqualified, n as createEvent, nr as ConversationReopened, or as EmailEventBounced, pr as LeadCreated, qn as CampaignPaused, rr as ConversationResolved, sr as EmailEventClicked, t as InProcessCrmBus, tr as ConversationCreated, ur as EmailEventUnsubscribed, vr as MessageReceived, wr as OpportunityCreated, xr as OpportunityAbandoned, yr as MessageSent, zn as ActivityCompleted, zr as CrmEventName } from "./index.js";
1
+ import { z } from "zod";
2
+ import { DomainEvent, EventHandler, EventMeta, EventTransport } from "@classytic/primitives/events";
3
+ import * as _$mongoose from "mongoose";
4
+ import { OperationContext } from "@classytic/primitives/context";
5
+
6
+ //#region src/events/event-constants.d.ts
7
+ /** PACKAGE_RULES rule 12: `package:resource.verb`. */
8
+ declare const CRM_EVENTS: {
9
+ readonly LEAD_CREATED: "crm:lead.created";
10
+ readonly LEAD_STATUS_CHANGED: "crm:lead.status_changed";
11
+ readonly LEAD_SCORED: "crm:lead.scored";
12
+ readonly LEAD_CONVERTED: "crm:lead.converted";
13
+ readonly LEAD_DISQUALIFIED: "crm:lead.disqualified";
14
+ readonly ACCOUNT_CREATED: "crm:account.created";
15
+ readonly ACCOUNT_UPDATED: "crm:account.updated";
16
+ readonly CONTACT_CREATED: "crm:contact.created";
17
+ readonly CONTACT_UPDATED: "crm:contact.updated";
18
+ readonly OPPORTUNITY_CREATED: "crm:opportunity.created";
19
+ readonly OPPORTUNITY_STAGE_ADVANCED: "crm:opportunity.stage_advanced";
20
+ readonly OPPORTUNITY_STAGE_REGRESSED: "crm:opportunity.stage_regressed";
21
+ readonly OPPORTUNITY_WON: "crm:opportunity.won";
22
+ readonly OPPORTUNITY_LOST: "crm:opportunity.lost";
23
+ readonly OPPORTUNITY_ABANDONED: "crm:opportunity.abandoned";
24
+ readonly PIPELINE_CREATED: "crm:pipeline.created";
25
+ readonly PIPELINE_ARCHIVED: "crm:pipeline.archived";
26
+ readonly ACTIVITY_PLANNED: "crm:activity.planned";
27
+ readonly ACTIVITY_COMPLETED: "crm:activity.completed";
28
+ readonly ACTIVITY_CANCELLED: "crm:activity.cancelled";
29
+ readonly NOTE_ADDED: "crm:note.added";
30
+ readonly CAMPAIGN_CREATED: "crm:campaign.created";
31
+ readonly CAMPAIGN_ACTIVATED: "crm:campaign.activated";
32
+ readonly CAMPAIGN_PAUSED: "crm:campaign.paused";
33
+ readonly CAMPAIGN_RESUMED: "crm:campaign.resumed";
34
+ readonly CAMPAIGN_COMPLETED: "crm:campaign.completed";
35
+ readonly CAMPAIGN_ARCHIVED: "crm:campaign.archived";
36
+ readonly SUBSCRIPTION_CREATED: "crm:subscription.created";
37
+ readonly SUBSCRIPTION_CONFIRMED: "crm:subscription.confirmed";
38
+ readonly SUBSCRIPTION_UNSUBSCRIBED: "crm:subscription.unsubscribed";
39
+ readonly SUBSCRIPTION_BOUNCED: "crm:subscription.bounced";
40
+ readonly SUBSCRIPTION_COMPLAINED: "crm:subscription.complained";
41
+ readonly EMAIL_EVENT_OPENED: "crm:email_event.opened";
42
+ readonly EMAIL_EVENT_CLICKED: "crm:email_event.clicked";
43
+ readonly EMAIL_EVENT_BOUNCED: "crm:email_event.bounced";
44
+ readonly EMAIL_EVENT_COMPLAINED: "crm:email_event.complained";
45
+ readonly EMAIL_EVENT_UNSUBSCRIBED: "crm:email_event.unsubscribed";
46
+ readonly LEAD_ENRICHED: "crm:lead.enriched";
47
+ readonly LEAD_ASSIGNED: "crm:lead.assigned";
48
+ readonly CONTACT_ENRICHED: "crm:contact.enriched";
49
+ readonly CONTACT_ASSIGNED: "crm:contact.assigned";
50
+ readonly CONTACT_MERGED: "crm:contact.merged";
51
+ readonly ACCOUNT_ENRICHED: "crm:account.enriched";
52
+ readonly ACCOUNT_ASSIGNED: "crm:account.assigned";
53
+ readonly ACCOUNT_MERGED: "crm:account.merged";
54
+ readonly OPPORTUNITY_ASSIGNED: "crm:opportunity.assigned";
55
+ readonly OPPORTUNITY_AMOUNT_CHANGED: "crm:opportunity.amount_changed";
56
+ readonly OPPORTUNITY_EXTENDED: "crm:opportunity.extended";
57
+ readonly ACTIVITY_RESCHEDULED: "crm:activity.rescheduled";
58
+ readonly ACTIVITY_OUTCOME_RECORDED: "crm:activity.outcome_recorded";
59
+ readonly CONVERSATION_CREATED: "crm:conversation.created";
60
+ readonly CONVERSATION_ASSIGNED: "crm:conversation.assigned";
61
+ readonly CONVERSATION_RESOLVED: "crm:conversation.resolved";
62
+ readonly CONVERSATION_REOPENED: "crm:conversation.reopened";
63
+ readonly MESSAGE_RECEIVED: "crm:message.received";
64
+ readonly MESSAGE_SENT: "crm:message.sent";
65
+ };
66
+ type CrmEventName = (typeof CRM_EVENTS)[keyof typeof CRM_EVENTS];
67
+ //#endregion
68
+ //#region src/events/event-catalog.d.ts
69
+ /** JSON-Schema object produced by `z.toJSONSchema` — what arc's registry consumes. */
70
+ type CrmEventSchema = Record<string, unknown>;
71
+ /** Structurally identical to arc's `EventDefinitionOutput` — do NOT import arc. */
72
+ interface CrmEventDefinition<TSchema extends z.ZodType = z.ZodType> {
73
+ name: CrmEventName;
74
+ version: number;
75
+ description: string;
76
+ zodSchema: TSchema;
77
+ schema: CrmEventSchema;
78
+ create(payload: z.infer<TSchema>, meta?: Partial<EventMeta>): DomainEvent<z.infer<TSchema>>;
79
+ }
80
+ declare const LeadCreated: CrmEventDefinition<z.ZodObject<{
81
+ leadId: z.ZodString;
82
+ email: z.ZodOptional<z.ZodString>;
83
+ score: z.ZodNumber;
84
+ }, z.core.$strip>>;
85
+ declare const LeadStatusChanged: CrmEventDefinition<z.ZodObject<{
86
+ leadId: z.ZodString;
87
+ from: z.ZodString;
88
+ to: z.ZodString;
89
+ }, z.core.$strip>>;
90
+ declare const LeadScored: CrmEventDefinition<z.ZodObject<{
91
+ leadId: z.ZodString;
92
+ score: z.ZodNumber;
93
+ }, z.core.$strip>>;
94
+ declare const LeadConverted: CrmEventDefinition<z.ZodObject<{
95
+ leadId: z.ZodString;
96
+ contactId: z.ZodString;
97
+ accountId: z.ZodOptional<z.ZodString>;
98
+ opportunityId: z.ZodString;
99
+ }, z.core.$strip>>;
100
+ declare const LeadDisqualified: CrmEventDefinition<z.ZodObject<{
101
+ leadId: z.ZodString;
102
+ reason: z.ZodString;
103
+ }, z.core.$strip>>;
104
+ declare const LeadEnriched: CrmEventDefinition<z.ZodObject<{
105
+ leadId: z.ZodString;
106
+ fields: z.ZodArray<z.ZodString>;
107
+ provider: z.ZodOptional<z.ZodString>;
108
+ }, z.core.$strip>>;
109
+ declare const LeadAssigned: CrmEventDefinition<z.ZodObject<{
110
+ leadId: z.ZodString;
111
+ ownerId: z.ZodString;
112
+ previousOwnerId: z.ZodOptional<z.ZodString>;
113
+ }, z.core.$strip>>;
114
+ declare const AccountCreated: CrmEventDefinition<z.ZodObject<{
115
+ accountId: z.ZodString;
116
+ name: z.ZodString;
117
+ }, z.core.$strip>>;
118
+ declare const AccountUpdated: CrmEventDefinition<z.ZodObject<{
119
+ accountId: z.ZodString;
120
+ }, z.core.$strip>>;
121
+ declare const AccountEnriched: CrmEventDefinition<z.ZodObject<{
122
+ accountId: z.ZodString;
123
+ fields: z.ZodArray<z.ZodString>;
124
+ provider: z.ZodOptional<z.ZodString>;
125
+ }, z.core.$strip>>;
126
+ declare const AccountAssigned: CrmEventDefinition<z.ZodObject<{
127
+ accountId: z.ZodString;
128
+ ownerId: z.ZodString;
129
+ previousOwnerId: z.ZodOptional<z.ZodString>;
130
+ }, z.core.$strip>>;
131
+ declare const AccountMerged: CrmEventDefinition<z.ZodObject<{
132
+ primaryId: z.ZodString;
133
+ secondaryId: z.ZodString;
134
+ strategy: z.ZodEnum<{
135
+ preferPrimary: "preferPrimary";
136
+ preferSecondary: "preferSecondary";
137
+ }>;
138
+ }, z.core.$strip>>;
139
+ declare const ContactCreated: CrmEventDefinition<z.ZodObject<{
140
+ contactId: z.ZodString;
141
+ email: z.ZodOptional<z.ZodString>;
142
+ }, z.core.$strip>>;
143
+ declare const ContactUpdated: CrmEventDefinition<z.ZodObject<{
144
+ contactId: z.ZodString;
145
+ }, z.core.$strip>>;
146
+ declare const ContactEnriched: CrmEventDefinition<z.ZodObject<{
147
+ contactId: z.ZodString;
148
+ fields: z.ZodArray<z.ZodString>;
149
+ provider: z.ZodOptional<z.ZodString>;
150
+ }, z.core.$strip>>;
151
+ declare const ContactAssigned: CrmEventDefinition<z.ZodObject<{
152
+ contactId: z.ZodString;
153
+ ownerId: z.ZodString;
154
+ previousOwnerId: z.ZodOptional<z.ZodString>;
155
+ }, z.core.$strip>>;
156
+ declare const ContactMerged: CrmEventDefinition<z.ZodObject<{
157
+ primaryId: z.ZodString;
158
+ secondaryId: z.ZodString;
159
+ strategy: z.ZodEnum<{
160
+ preferPrimary: "preferPrimary";
161
+ preferSecondary: "preferSecondary";
162
+ }>;
163
+ }, z.core.$strip>>;
164
+ declare const OpportunityCreated: CrmEventDefinition<z.ZodObject<{
165
+ opportunityId: z.ZodString;
166
+ pipelineId: z.ZodString;
167
+ stageId: z.ZodString;
168
+ }, z.core.$strip>>;
169
+ declare const OpportunityStageAdvanced: CrmEventDefinition<z.ZodObject<{
170
+ opportunityId: z.ZodString;
171
+ from: z.ZodObject<{
172
+ stageId: z.ZodString;
173
+ sequence: z.ZodNumber;
174
+ }, z.core.$strip>;
175
+ to: z.ZodObject<{
176
+ stageId: z.ZodString;
177
+ sequence: z.ZodNumber;
178
+ }, z.core.$strip>;
179
+ }, z.core.$strip>>;
180
+ declare const OpportunityStageRegressed: CrmEventDefinition<z.ZodObject<{
181
+ opportunityId: z.ZodString;
182
+ from: z.ZodObject<{
183
+ stageId: z.ZodString;
184
+ sequence: z.ZodNumber;
185
+ }, z.core.$strip>;
186
+ to: z.ZodObject<{
187
+ stageId: z.ZodString;
188
+ sequence: z.ZodNumber;
189
+ }, z.core.$strip>;
190
+ }, z.core.$strip>>;
191
+ declare const OpportunityWon: CrmEventDefinition<z.ZodObject<{
192
+ opportunityId: z.ZodString;
193
+ amount: z.ZodOptional<z.ZodNumber>;
194
+ }, z.core.$strip>>;
195
+ declare const OpportunityLost: CrmEventDefinition<z.ZodObject<{
196
+ opportunityId: z.ZodString;
197
+ lostReasonId: z.ZodOptional<z.ZodString>;
198
+ }, z.core.$strip>>;
199
+ declare const OpportunityAbandoned: CrmEventDefinition<z.ZodObject<{
200
+ opportunityId: z.ZodString;
201
+ }, z.core.$strip>>;
202
+ declare const OpportunityAssigned: CrmEventDefinition<z.ZodObject<{
203
+ opportunityId: z.ZodString;
204
+ ownerId: z.ZodString;
205
+ previousOwnerId: z.ZodOptional<z.ZodString>;
206
+ }, z.core.$strip>>;
207
+ declare const OpportunityAmountChanged: CrmEventDefinition<z.ZodObject<{
208
+ opportunityId: z.ZodString;
209
+ amount: z.ZodNumber;
210
+ previousAmount: z.ZodOptional<z.ZodNumber>;
211
+ reason: z.ZodOptional<z.ZodString>;
212
+ by: z.ZodOptional<z.ZodString>;
213
+ }, z.core.$strip>>;
214
+ declare const OpportunityExtended: CrmEventDefinition<z.ZodObject<{
215
+ opportunityId: z.ZodString;
216
+ expectedCloseAt: z.ZodISODateTime;
217
+ previousExpectedCloseAt: z.ZodOptional<z.ZodISODateTime>;
218
+ reason: z.ZodOptional<z.ZodString>;
219
+ by: z.ZodOptional<z.ZodString>;
220
+ }, z.core.$strip>>;
221
+ declare const PipelineCreated: CrmEventDefinition<z.ZodObject<{
222
+ pipelineId: z.ZodString;
223
+ }, z.core.$strip>>;
224
+ declare const PipelineArchived: CrmEventDefinition<z.ZodObject<{
225
+ pipelineId: z.ZodString;
226
+ }, z.core.$strip>>;
227
+ declare const ActivityPlanned: CrmEventDefinition<z.ZodObject<{
228
+ activityId: z.ZodString;
229
+ type: z.ZodString;
230
+ subjectKind: z.ZodString;
231
+ subjectId: z.ZodString;
232
+ }, z.core.$strip>>;
233
+ declare const ActivityCompleted: CrmEventDefinition<z.ZodObject<{
234
+ activityId: z.ZodString;
235
+ completedAt: z.ZodISODateTime;
236
+ }, z.core.$strip>>;
237
+ declare const ActivityCancelled: CrmEventDefinition<z.ZodObject<{
238
+ activityId: z.ZodString;
239
+ reason: z.ZodOptional<z.ZodString>;
240
+ }, z.core.$strip>>;
241
+ declare const ActivityRescheduled: CrmEventDefinition<z.ZodObject<{
242
+ activityId: z.ZodString;
243
+ dueDate: z.ZodISODateTime;
244
+ previousDueDate: z.ZodOptional<z.ZodISODateTime>;
245
+ reason: z.ZodOptional<z.ZodString>;
246
+ by: z.ZodOptional<z.ZodString>;
247
+ }, z.core.$strip>>;
248
+ declare const ActivityOutcomeRecorded: CrmEventDefinition<z.ZodObject<{
249
+ activityId: z.ZodString;
250
+ outcome: z.ZodRecord<z.ZodString, z.ZodUnknown>;
251
+ }, z.core.$strip>>;
252
+ declare const NoteAdded: CrmEventDefinition<z.ZodObject<{
253
+ noteId: z.ZodString;
254
+ subjectKind: z.ZodString;
255
+ subjectId: z.ZodString;
256
+ }, z.core.$strip>>;
257
+ declare const CampaignCreated: CrmEventDefinition<z.ZodObject<{
258
+ campaignId: z.ZodString;
259
+ name: z.ZodString;
260
+ }, z.core.$strip>>;
261
+ declare const CampaignActivated: CrmEventDefinition<z.ZodObject<{
262
+ campaignId: z.ZodString;
263
+ }, z.core.$strip>>;
264
+ declare const CampaignPaused: CrmEventDefinition<z.ZodObject<{
265
+ campaignId: z.ZodString;
266
+ reason: z.ZodOptional<z.ZodString>;
267
+ }, z.core.$strip>>;
268
+ declare const CampaignResumed: CrmEventDefinition<z.ZodObject<{
269
+ campaignId: z.ZodString;
270
+ }, z.core.$strip>>;
271
+ declare const CampaignCompleted: CrmEventDefinition<z.ZodObject<{
272
+ campaignId: z.ZodString;
273
+ actualRevenueAmount: z.ZodOptional<z.ZodNumber>;
274
+ }, z.core.$strip>>;
275
+ declare const CampaignArchived: CrmEventDefinition<z.ZodObject<{
276
+ campaignId: z.ZodString;
277
+ }, z.core.$strip>>;
278
+ declare const SubscriptionCreated: CrmEventDefinition<z.ZodObject<{
279
+ subscriptionId: z.ZodString;
280
+ contactId: z.ZodString;
281
+ campaignId: z.ZodString;
282
+ requiresConfirmation: z.ZodBoolean;
283
+ }, z.core.$strip>>;
284
+ declare const SubscriptionConfirmed: CrmEventDefinition<z.ZodObject<{
285
+ subscriptionId: z.ZodString;
286
+ contactId: z.ZodString;
287
+ campaignId: z.ZodString;
288
+ confirmedAt: z.ZodISODateTime;
289
+ }, z.core.$strip>>;
290
+ declare const SubscriptionUnsubscribed: CrmEventDefinition<z.ZodObject<{
291
+ subscriptionId: z.ZodString;
292
+ contactId: z.ZodString;
293
+ campaignId: z.ZodString;
294
+ reason: z.ZodOptional<z.ZodString>;
295
+ }, z.core.$strip>>;
296
+ declare const SubscriptionBounced: CrmEventDefinition<z.ZodObject<{
297
+ subscriptionId: z.ZodString;
298
+ contactId: z.ZodString;
299
+ campaignId: z.ZodString;
300
+ reason: z.ZodOptional<z.ZodString>;
301
+ }, z.core.$strip>>;
302
+ declare const SubscriptionComplained: CrmEventDefinition<z.ZodObject<{
303
+ subscriptionId: z.ZodString;
304
+ contactId: z.ZodString;
305
+ campaignId: z.ZodString;
306
+ }, z.core.$strip>>;
307
+ declare const EmailEventOpened: CrmEventDefinition<z.ZodObject<{
308
+ eventId: z.ZodString;
309
+ kind: z.ZodString;
310
+ subjectKind: z.ZodString;
311
+ subjectId: z.ZodString;
312
+ campaignId: z.ZodOptional<z.ZodString>;
313
+ }, z.core.$strip>>;
314
+ declare const EmailEventClicked: CrmEventDefinition<z.ZodObject<{
315
+ eventId: z.ZodString;
316
+ kind: z.ZodString;
317
+ subjectKind: z.ZodString;
318
+ subjectId: z.ZodString;
319
+ campaignId: z.ZodOptional<z.ZodString>;
320
+ }, z.core.$strip>>;
321
+ declare const EmailEventBounced: CrmEventDefinition<z.ZodObject<{
322
+ eventId: z.ZodString;
323
+ kind: z.ZodString;
324
+ subjectKind: z.ZodString;
325
+ subjectId: z.ZodString;
326
+ campaignId: z.ZodOptional<z.ZodString>;
327
+ }, z.core.$strip>>;
328
+ declare const EmailEventComplained: CrmEventDefinition<z.ZodObject<{
329
+ eventId: z.ZodString;
330
+ kind: z.ZodString;
331
+ subjectKind: z.ZodString;
332
+ subjectId: z.ZodString;
333
+ campaignId: z.ZodOptional<z.ZodString>;
334
+ }, z.core.$strip>>;
335
+ declare const EmailEventUnsubscribed: CrmEventDefinition<z.ZodObject<{
336
+ eventId: z.ZodString;
337
+ kind: z.ZodString;
338
+ subjectKind: z.ZodString;
339
+ subjectId: z.ZodString;
340
+ campaignId: z.ZodOptional<z.ZodString>;
341
+ }, z.core.$strip>>;
342
+ declare const ConversationCreated: CrmEventDefinition<z.ZodObject<{
343
+ conversationId: z.ZodString;
344
+ channel: z.ZodString;
345
+ participantKind: z.ZodString;
346
+ participantId: z.ZodString;
347
+ }, z.core.$strip>>;
348
+ declare const ConversationAssigned: CrmEventDefinition<z.ZodObject<{
349
+ conversationId: z.ZodString;
350
+ assigneeId: z.ZodString;
351
+ previousAssigneeId: z.ZodOptional<z.ZodString>;
352
+ }, z.core.$strip>>;
353
+ declare const ConversationResolved: CrmEventDefinition<z.ZodObject<{
354
+ conversationId: z.ZodString;
355
+ status: z.ZodString;
356
+ previousStatus: z.ZodString;
357
+ }, z.core.$strip>>;
358
+ declare const ConversationReopened: CrmEventDefinition<z.ZodObject<{
359
+ conversationId: z.ZodString;
360
+ status: z.ZodString;
361
+ previousStatus: z.ZodString;
362
+ }, z.core.$strip>>;
363
+ declare const MessageReceived: CrmEventDefinition<z.ZodObject<{
364
+ messageId: z.ZodString;
365
+ conversationId: z.ZodString;
366
+ direction: z.ZodString;
367
+ externalMessageId: z.ZodOptional<z.ZodString>;
368
+ }, z.core.$strip>>;
369
+ declare const MessageSent: CrmEventDefinition<z.ZodObject<{
370
+ messageId: z.ZodString;
371
+ conversationId: z.ZodString;
372
+ direction: z.ZodString;
373
+ externalMessageId: z.ZodOptional<z.ZodString>;
374
+ }, z.core.$strip>>;
375
+ declare const crmEventDefinitions: ReadonlyArray<CrmEventDefinition>;
376
+ //#endregion
377
+ //#region src/engine/engine-types.d.ts
378
+ interface CrmLogger {
379
+ info?(msg: string, meta?: Record<string, unknown>): void;
380
+ warn?(msg: string, meta?: Record<string, unknown>): void;
381
+ error?(msg: string, meta?: Record<string, unknown>): void;
382
+ debug?(msg: string, meta?: Record<string, unknown>): void;
383
+ }
384
+ /**
385
+ * Operation context threaded through every domain verb. Extends
386
+ * primitives' `OperationContext` and narrows `IdLike` to types Mongoose
387
+ * stores cleanly. Host-specific extras go through the inherited
388
+ * `metadata?` field — keep the typed surface tight.
389
+ */
390
+ interface CrmContext extends OperationContext {
391
+ organizationId?: string | _$mongoose.Types.ObjectId;
392
+ actorId?: string | _$mongoose.Types.ObjectId;
393
+ /** Mongo transaction session (passed through to mongokit). */
394
+ session?: unknown;
395
+ }
396
+ //#endregion
397
+ //#region src/events/helpers.d.ts
398
+ declare function createEvent<T>(type: string, payload: T, ctx?: CrmContext, meta?: Partial<EventMeta>): DomainEvent<T>;
399
+ //#endregion
400
+ //#region src/events/in-process-bus.d.ts
401
+ declare class InProcessCrmBus implements EventTransport {
402
+ readonly name = "in-process-crm";
403
+ private subs;
404
+ private logger?;
405
+ constructor(options?: {
406
+ logger?: CrmLogger;
407
+ });
408
+ publish(event: DomainEvent): Promise<void>;
409
+ subscribe(pattern: string, handler: EventHandler): Promise<() => void>;
410
+ close(): Promise<void>;
411
+ }
412
+ //#endregion
2
413
  export { AccountAssigned, AccountCreated, AccountEnriched, AccountMerged, AccountUpdated, ActivityCancelled, ActivityCompleted, ActivityOutcomeRecorded, ActivityPlanned, ActivityRescheduled, CRM_EVENTS, CampaignActivated, CampaignArchived, CampaignCompleted, CampaignCreated, CampaignPaused, CampaignResumed, ContactAssigned, ContactCreated, ContactEnriched, ContactMerged, ContactUpdated, ConversationAssigned, ConversationCreated, ConversationReopened, ConversationResolved, CrmEventDefinition, CrmEventName, CrmEventSchema, EmailEventBounced, EmailEventClicked, EmailEventComplained, EmailEventOpened, EmailEventUnsubscribed, InProcessCrmBus, LeadAssigned, LeadConverted, LeadCreated, LeadDisqualified, LeadEnriched, LeadScored, LeadStatusChanged, MessageReceived, MessageSent, NoteAdded, OpportunityAbandoned, OpportunityAmountChanged, OpportunityAssigned, OpportunityCreated, OpportunityExtended, OpportunityLost, OpportunityStageAdvanced, OpportunityStageRegressed, OpportunityWon, PipelineArchived, PipelineCreated, SubscriptionBounced, SubscriptionComplained, SubscriptionConfirmed, SubscriptionCreated, SubscriptionUnsubscribed, createEvent, crmEventDefinitions };
package/dist/events.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createEvent as createEvent$1, matchEventPattern } from "@classytic/primitives/events";
2
1
  import { z } from "zod";
2
+ import { createEvent as createEvent$1, matchEventPattern } from "@classytic/primitives/events";
3
3
  //#region src/events/event-constants.ts
4
4
  /** PACKAGE_RULES rule 12: `package:resource.verb`. */
5
5
  const CRM_EVENTS = {
@@ -61,62 +61,6 @@ const CRM_EVENTS = {
61
61
  MESSAGE_SENT: "crm:message.sent"
62
62
  };
63
63
  //#endregion
64
- //#region src/events/helpers.ts
65
- /**
66
- * Event creation helper.
67
- *
68
- * Thin wrapper around `@classytic/primitives`' `createEvent` that fills the
69
- * shared `EventMeta` from a `CrmContext` (userId/actorId, organizationId,
70
- * correlationId). Use this instead of importing `createEvent` directly so
71
- * the `source: 'crm'` stamp + tenant scoping stay consistent.
72
- */
73
- function createEvent(type, payload, ctx, meta) {
74
- return createEvent$1(type, payload, {
75
- source: "crm",
76
- ...ctx?.actorId !== void 0 ? { actorId: String(ctx.actorId) } : {},
77
- ...ctx?.organizationId !== void 0 ? { organizationId: String(ctx.organizationId) } : {},
78
- ...ctx?.correlationId !== void 0 ? { correlationId: ctx.correlationId } : {},
79
- ...meta
80
- });
81
- }
82
- //#endregion
83
- //#region src/events/in-process-bus.ts
84
- /**
85
- * In-process event bus — default fallback when no `eventTransport` is
86
- * provided to `createCrm`. Structurally identical to arc's
87
- * `MemoryEventTransport`; pattern matching is delegated to primitives.
88
- * Handler errors are swallowed — event emission never blocks writes.
89
- */
90
- var InProcessCrmBus = class {
91
- name = "in-process-crm";
92
- subs = [];
93
- logger;
94
- constructor(options) {
95
- if (options?.logger) this.logger = options.logger;
96
- }
97
- async publish(event) {
98
- const matching = this.subs.filter((s) => matchEventPattern(s.pattern, event.type));
99
- for (const sub of matching) try {
100
- await sub.handler(event);
101
- } catch (err) {
102
- this.logger?.error?.(`[crm] event handler error [${event.type}]`, { error: err instanceof Error ? err.message : String(err) });
103
- }
104
- }
105
- async subscribe(pattern, handler) {
106
- const sub = {
107
- pattern,
108
- handler
109
- };
110
- this.subs.push(sub);
111
- return () => {
112
- this.subs = this.subs.filter((s) => s !== sub);
113
- };
114
- }
115
- async close() {
116
- this.subs = [];
117
- }
118
- };
119
- //#endregion
120
64
  //#region src/events/event-catalog.ts
121
65
  /**
122
66
  * Zod-source event catalog (PACKAGE_RULES rule 18).
@@ -713,4 +657,60 @@ const crmEventDefinitions = [
713
657
  MessageSent
714
658
  ];
715
659
  //#endregion
660
+ //#region src/events/helpers.ts
661
+ /**
662
+ * Event creation helper.
663
+ *
664
+ * Thin wrapper around `@classytic/primitives`' `createEvent` that fills the
665
+ * shared `EventMeta` from a `CrmContext` (userId/actorId, organizationId,
666
+ * correlationId). Use this instead of importing `createEvent` directly so
667
+ * the `source: 'crm'` stamp + tenant scoping stay consistent.
668
+ */
669
+ function createEvent(type, payload, ctx, meta) {
670
+ return createEvent$1(type, payload, {
671
+ source: "crm",
672
+ ...ctx?.actorId !== void 0 ? { actorId: String(ctx.actorId) } : {},
673
+ ...ctx?.organizationId !== void 0 ? { organizationId: String(ctx.organizationId) } : {},
674
+ ...ctx?.correlationId !== void 0 ? { correlationId: ctx.correlationId } : {},
675
+ ...meta
676
+ });
677
+ }
678
+ //#endregion
679
+ //#region src/events/in-process-bus.ts
680
+ /**
681
+ * In-process event bus — default fallback when no `eventTransport` is
682
+ * provided to `createCrm`. Structurally identical to arc's
683
+ * `MemoryEventTransport`; pattern matching is delegated to primitives.
684
+ * Handler errors are swallowed — event emission never blocks writes.
685
+ */
686
+ var InProcessCrmBus = class {
687
+ name = "in-process-crm";
688
+ subs = [];
689
+ logger;
690
+ constructor(options) {
691
+ if (options?.logger) this.logger = options.logger;
692
+ }
693
+ async publish(event) {
694
+ const matching = this.subs.filter((s) => matchEventPattern(s.pattern, event.type));
695
+ for (const sub of matching) try {
696
+ await sub.handler(event);
697
+ } catch (err) {
698
+ this.logger?.error?.(`[crm] event handler error [${event.type}]`, { error: err instanceof Error ? err.message : String(err) });
699
+ }
700
+ }
701
+ async subscribe(pattern, handler) {
702
+ const sub = {
703
+ pattern,
704
+ handler
705
+ };
706
+ this.subs.push(sub);
707
+ return () => {
708
+ this.subs = this.subs.filter((s) => s !== sub);
709
+ };
710
+ }
711
+ async close() {
712
+ this.subs = [];
713
+ }
714
+ };
715
+ //#endregion
716
716
  export { AccountAssigned, AccountCreated, AccountEnriched, AccountMerged, AccountUpdated, ActivityCancelled, ActivityCompleted, ActivityOutcomeRecorded, ActivityPlanned, ActivityRescheduled, CRM_EVENTS, CampaignActivated, CampaignArchived, CampaignCompleted, CampaignCreated, CampaignPaused, CampaignResumed, ContactAssigned, ContactCreated, ContactEnriched, ContactMerged, ContactUpdated, ConversationAssigned, ConversationCreated, ConversationReopened, ConversationResolved, EmailEventBounced, EmailEventClicked, EmailEventComplained, EmailEventOpened, EmailEventUnsubscribed, InProcessCrmBus, LeadAssigned, LeadConverted, LeadCreated, LeadDisqualified, LeadEnriched, LeadScored, LeadStatusChanged, MessageReceived, MessageSent, NoteAdded, OpportunityAbandoned, OpportunityAmountChanged, OpportunityAssigned, OpportunityCreated, OpportunityExtended, OpportunityLost, OpportunityStageAdvanced, OpportunityStageRegressed, OpportunityWon, PipelineArchived, PipelineCreated, SubscriptionBounced, SubscriptionComplained, SubscriptionConfirmed, SubscriptionCreated, SubscriptionUnsubscribed, createEvent, crmEventDefinitions };