@automate.ax/integration-contracts 0.87.7 → 0.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,575 @@
1
+ import * as z from "zod";
2
+ import { CLOSE_OBJECT_SCHEMA } from "./api.js";
3
+ import { CLOSE_CALL_SCHEMA, CLOSE_COMMENT_SCHEMA, CLOSE_DATE_SCHEMA, CLOSE_CONTACT_SCHEMA, CLOSE_EMAIL_SCHEMA, CLOSE_LEAD_SCHEMA, CLOSE_MEETING_SCHEMA, CLOSE_OPPORTUNITY_SCHEMA, CLOSE_SEQUENCE_SUBSCRIPTION_SCHEMA, CLOSE_SMS_SCHEMA, CLOSE_TASK_SCHEMA, } from "./schemas.js";
4
+ export const CLOSE_WEBHOOK_EVENT_SELECTIONS = [
5
+ ["lead", "created"],
6
+ ["lead", "updated"],
7
+ ["lead", "deleted"],
8
+ ["lead", "merged"],
9
+ ["contact", "created"],
10
+ ["contact", "updated"],
11
+ ["contact", "deleted"],
12
+ ["opportunity", "created"],
13
+ ["opportunity", "updated"],
14
+ ["opportunity", "deleted"],
15
+ ["task.lead", "created"],
16
+ ["task.lead", "updated"],
17
+ ["task.lead", "deleted"],
18
+ ["task.lead", "completed"],
19
+ ["task.incoming_email", "created"],
20
+ ["task.incoming_email", "updated"],
21
+ ["task.incoming_email", "deleted"],
22
+ ["task.incoming_email", "completed"],
23
+ ["task.email_followup", "created"],
24
+ ["task.email_followup", "updated"],
25
+ ["task.email_followup", "deleted"],
26
+ ["task.email_followup", "completed"],
27
+ ["task.missed_call", "created"],
28
+ ["task.missed_call", "updated"],
29
+ ["task.missed_call", "deleted"],
30
+ ["task.missed_call", "completed"],
31
+ ["task.answered_detached_call", "created"],
32
+ ["task.answered_detached_call", "updated"],
33
+ ["task.answered_detached_call", "deleted"],
34
+ ["task.answered_detached_call", "completed"],
35
+ ["task.voicemail", "created"],
36
+ ["task.voicemail", "updated"],
37
+ ["task.voicemail", "deleted"],
38
+ ["task.voicemail", "completed"],
39
+ ["task.opportunity_due", "created"],
40
+ ["task.opportunity_due", "updated"],
41
+ ["task.opportunity_due", "deleted"],
42
+ ["task.opportunity_due", "completed"],
43
+ ["task.incoming_sms", "created"],
44
+ ["task.incoming_sms", "updated"],
45
+ ["task.incoming_sms", "deleted"],
46
+ ["task.incoming_sms", "completed"],
47
+ ["task.outbound_call", "created"],
48
+ ["task.outbound_call", "updated"],
49
+ ["task.outbound_call", "deleted"],
50
+ ["task.outbound_call", "completed"],
51
+ ["activity.email", "created"],
52
+ ["activity.email", "updated"],
53
+ ["activity.email", "deleted"],
54
+ ["activity.email", "sent"],
55
+ ["activity.email_thread", "created"],
56
+ ["activity.email_thread", "updated"],
57
+ ["activity.email_thread", "deleted"],
58
+ ["unsubscribed_email", "created"],
59
+ ["unsubscribed_email", "deleted"],
60
+ ["activity.call", "created"],
61
+ ["activity.call", "updated"],
62
+ ["activity.call", "deleted"],
63
+ ["activity.call", "answered"],
64
+ ["activity.call", "completed"],
65
+ ["activity.sms", "created"],
66
+ ["activity.sms", "updated"],
67
+ ["activity.sms", "deleted"],
68
+ ["activity.sms", "sent"],
69
+ ["activity.whatsapp_message", "created"],
70
+ ["activity.whatsapp_message", "updated"],
71
+ ["activity.whatsapp_message", "deleted"],
72
+ ["activity.note", "created"],
73
+ ["activity.note", "updated"],
74
+ ["activity.note", "deleted"],
75
+ ["activity.meeting", "created"],
76
+ ["activity.meeting", "updated"],
77
+ ["activity.meeting", "deleted"],
78
+ ["activity.meeting", "scheduled"],
79
+ ["activity.meeting", "started"],
80
+ ["activity.meeting", "completed"],
81
+ ["activity.meeting", "canceled"],
82
+ ["activity.form_submission", "created"],
83
+ ["activity.form_submission", "updated"],
84
+ ["activity.form_submission", "deleted"],
85
+ ["activity.lead_status_change", "created"],
86
+ ["activity.lead_status_change", "updated"],
87
+ ["activity.lead_status_change", "deleted"],
88
+ ["activity.opportunity_status_change", "created"],
89
+ ["activity.opportunity_status_change", "updated"],
90
+ ["activity.opportunity_status_change", "deleted"],
91
+ ["activity.task_completed", "created"],
92
+ ["activity.task_completed", "deleted"],
93
+ ["activity.lead_merge", "created"],
94
+ ["activity.lead_merge", "updated"],
95
+ ["activity.lead_merge", "deleted"],
96
+ ["import", "created"],
97
+ ["import", "updated"],
98
+ ["import", "completed"],
99
+ ["import", "reverting"],
100
+ ["import", "reverted"],
101
+ ["export.lead", "created"],
102
+ ["export.lead", "updated"],
103
+ ["export.lead", "completed"],
104
+ ["export.opportunity", "created"],
105
+ ["export.opportunity", "updated"],
106
+ ["export.opportunity", "completed"],
107
+ ["bulk_action.delete", "created"],
108
+ ["bulk_action.delete", "updated"],
109
+ ["bulk_action.delete", "completed"],
110
+ ["bulk_action.delete", "paused"],
111
+ ["bulk_action.edit", "created"],
112
+ ["bulk_action.edit", "updated"],
113
+ ["bulk_action.edit", "completed"],
114
+ ["bulk_action.edit", "paused"],
115
+ ["bulk_action.email", "created"],
116
+ ["bulk_action.email", "updated"],
117
+ ["bulk_action.email", "completed"],
118
+ ["bulk_action.email", "paused"],
119
+ ["bulk_action.sequence_subscription", "created"],
120
+ ["bulk_action.sequence_subscription", "updated"],
121
+ ["bulk_action.sequence_subscription", "completed"],
122
+ ["bulk_action.sequence_subscription", "paused"],
123
+ ["custom_fields.lead", "created"],
124
+ ["custom_fields.lead", "updated"],
125
+ ["custom_fields.lead", "deleted"],
126
+ ["custom_fields.contact", "created"],
127
+ ["custom_fields.contact", "updated"],
128
+ ["custom_fields.contact", "deleted"],
129
+ ["custom_fields.opportunity", "created"],
130
+ ["custom_fields.opportunity", "updated"],
131
+ ["custom_fields.opportunity", "deleted"],
132
+ ["custom_fields.activity", "created"],
133
+ ["custom_fields.activity", "updated"],
134
+ ["custom_fields.activity", "deleted"],
135
+ ["custom_fields.custom_object", "created"],
136
+ ["custom_fields.custom_object", "updated"],
137
+ ["custom_fields.custom_object", "deleted"],
138
+ ["custom_fields.shared", "created"],
139
+ ["custom_fields.shared", "updated"],
140
+ ["custom_fields.shared", "deleted"],
141
+ ["custom_activity_type", "created"],
142
+ ["custom_activity_type", "updated"],
143
+ ["custom_activity_type", "deleted"],
144
+ ["activity.custom_activity", "created"],
145
+ ["activity.custom_activity", "updated"],
146
+ ["activity.custom_activity", "deleted"],
147
+ ["custom_object_type", "created"],
148
+ ["custom_object_type", "updated"],
149
+ ["custom_object_type", "deleted"],
150
+ ["custom_object", "created"],
151
+ ["custom_object", "updated"],
152
+ ["custom_object", "deleted"],
153
+ ["status.lead", "created"],
154
+ ["status.lead", "updated"],
155
+ ["status.lead", "deleted"],
156
+ ["status.opportunity", "created"],
157
+ ["status.opportunity", "updated"],
158
+ ["status.opportunity", "deleted"],
159
+ ["membership", "activated"],
160
+ ["membership", "deactivated"],
161
+ ["group", "created"],
162
+ ["group", "updated"],
163
+ ["group", "deleted"],
164
+ ["saved_search", "created"],
165
+ ["saved_search", "updated"],
166
+ ["phone_number", "created"],
167
+ ["phone_number", "updated"],
168
+ ["phone_number", "deleted"],
169
+ ["email_template", "created"],
170
+ ["email_template", "updated"],
171
+ ["email_template", "deleted"],
172
+ ["sms_template", "created"],
173
+ ["sms_template", "updated"],
174
+ ["sms_template", "deleted"],
175
+ ["sequence", "created"],
176
+ ["sequence", "updated"],
177
+ ["sequence", "deleted"],
178
+ ["sequence_subscription", "created"],
179
+ ["sequence_subscription", "updated"],
180
+ ["sequence_subscription", "deleted"],
181
+ ["comment", "created"],
182
+ ["comment", "updated"],
183
+ ["comment", "deleted"],
184
+ ["comment_thread", "created"],
185
+ ["comment_thread", "updated"],
186
+ ["comment_thread", "deleted"],
187
+ ];
188
+ export const CLOSE_EVENT_SCHEMA = z.object({
189
+ action: z.string(),
190
+ apiKeyId: z.string().nullable().optional(),
191
+ changedFields: z.string().array().prefault([]),
192
+ createdAt: CLOSE_DATE_SCHEMA,
193
+ data: CLOSE_OBJECT_SCHEMA.nullable(),
194
+ id: z.string(),
195
+ leadId: z.string().nullable(),
196
+ meta: CLOSE_OBJECT_SCHEMA.prefault({}),
197
+ objectId: z.string(),
198
+ objectType: z.string(),
199
+ organizationId: z.string(),
200
+ previousData: CLOSE_OBJECT_SCHEMA.nullable(),
201
+ requestId: z.string().nullable().optional(),
202
+ updatedAt: CLOSE_DATE_SCHEMA,
203
+ userId: z.string().nullable(),
204
+ });
205
+ export const CLOSE_WEBHOOK_PAYLOAD_SCHEMA = z.object({
206
+ event: CLOSE_EVENT_SCHEMA,
207
+ subscriptionId: z.string(),
208
+ });
209
+ export const CLOSE_TRIGGER_CONFIG_SCHEMA = z.object({});
210
+ // Event snapshots can omit fields that are required by the current REST
211
+ // resource. Close's documented opportunity-won webhook is one such payload.
212
+ const CLOSE_CALL_EVENT_DATA_SCHEMA = CLOSE_CALL_SCHEMA.partial();
213
+ const CLOSE_COMMENT_EVENT_DATA_SCHEMA = CLOSE_COMMENT_SCHEMA.partial();
214
+ const CLOSE_CONTACT_EVENT_DATA_SCHEMA = CLOSE_CONTACT_SCHEMA.partial();
215
+ const CLOSE_EMAIL_EVENT_DATA_SCHEMA = CLOSE_EMAIL_SCHEMA.partial();
216
+ const CLOSE_LEAD_EVENT_DATA_SCHEMA = CLOSE_LEAD_SCHEMA.partial();
217
+ const CLOSE_MEETING_EVENT_DATA_SCHEMA = CLOSE_MEETING_SCHEMA.partial();
218
+ const CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA = CLOSE_OPPORTUNITY_SCHEMA.partial();
219
+ const CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA = CLOSE_SEQUENCE_SUBSCRIPTION_SCHEMA.partial();
220
+ const CLOSE_SMS_EVENT_DATA_SCHEMA = CLOSE_SMS_SCHEMA.partial();
221
+ const CLOSE_TASK_EVENT_DATA_SCHEMA = z.union([
222
+ CLOSE_TASK_SCHEMA.options[0].partial(),
223
+ CLOSE_TASK_SCHEMA.options[1].partial(),
224
+ CLOSE_TASK_SCHEMA.options[2].partial(),
225
+ CLOSE_TASK_SCHEMA.options[3].partial(),
226
+ CLOSE_TASK_SCHEMA.options[4].partial(),
227
+ CLOSE_TASK_SCHEMA.options[5].partial(),
228
+ CLOSE_TASK_SCHEMA.options[6].partial(),
229
+ CLOSE_TASK_SCHEMA.options[7].partial(),
230
+ CLOSE_TASK_SCHEMA.options[8].partial(),
231
+ ]);
232
+ const SEMANTIC_EVENTS = {
233
+ "close.call.answered": [
234
+ "activity.call",
235
+ "answered",
236
+ CLOSE_CALL_EVENT_DATA_SCHEMA,
237
+ ],
238
+ "close.call.completed": [
239
+ "activity.call",
240
+ "completed",
241
+ CLOSE_CALL_EVENT_DATA_SCHEMA,
242
+ ],
243
+ "close.comment.created": [
244
+ "comment",
245
+ "created",
246
+ CLOSE_COMMENT_EVENT_DATA_SCHEMA,
247
+ ],
248
+ "close.comment.deleted": ["comment", "deleted", null],
249
+ "close.comment.updated": [
250
+ "comment",
251
+ "updated",
252
+ CLOSE_COMMENT_EVENT_DATA_SCHEMA,
253
+ ],
254
+ "close.contact.created": [
255
+ "contact",
256
+ "created",
257
+ CLOSE_CONTACT_EVENT_DATA_SCHEMA,
258
+ ],
259
+ "close.contact.deleted": ["contact", "deleted", null],
260
+ "close.contact.updated": [
261
+ "contact",
262
+ "updated",
263
+ CLOSE_CONTACT_EVENT_DATA_SCHEMA,
264
+ ],
265
+ "close.email.received": [
266
+ "activity.email",
267
+ "created",
268
+ CLOSE_EMAIL_EVENT_DATA_SCHEMA,
269
+ ],
270
+ "close.email.sent": ["activity.email", "sent", CLOSE_EMAIL_EVENT_DATA_SCHEMA],
271
+ "close.lead.created": ["lead", "created", CLOSE_LEAD_EVENT_DATA_SCHEMA],
272
+ "close.lead.deleted": ["lead", "deleted", null],
273
+ "close.lead.merged": ["lead", "merged", CLOSE_LEAD_EVENT_DATA_SCHEMA],
274
+ "close.lead.updated": ["lead", "updated", CLOSE_LEAD_EVENT_DATA_SCHEMA],
275
+ "close.meeting.canceled": [
276
+ "activity.meeting",
277
+ "canceled",
278
+ CLOSE_MEETING_EVENT_DATA_SCHEMA,
279
+ ],
280
+ "close.meeting.completed": [
281
+ "activity.meeting",
282
+ "completed",
283
+ CLOSE_MEETING_EVENT_DATA_SCHEMA,
284
+ ],
285
+ "close.meeting.scheduled": [
286
+ "activity.meeting",
287
+ "scheduled",
288
+ CLOSE_MEETING_EVENT_DATA_SCHEMA,
289
+ ],
290
+ "close.meeting.started": [
291
+ "activity.meeting",
292
+ "started",
293
+ CLOSE_MEETING_EVENT_DATA_SCHEMA,
294
+ ],
295
+ "close.opportunity.created": [
296
+ "opportunity",
297
+ "created",
298
+ CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA,
299
+ ],
300
+ "close.opportunity.deleted": ["opportunity", "deleted", null],
301
+ "close.opportunity.lost": [
302
+ "opportunity",
303
+ "updated",
304
+ CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA,
305
+ ],
306
+ "close.opportunity.updated": [
307
+ "opportunity",
308
+ "updated",
309
+ CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA,
310
+ ],
311
+ "close.opportunity.won": [
312
+ "opportunity",
313
+ "updated",
314
+ CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA,
315
+ ],
316
+ "close.sequenceSubscription.created": [
317
+ "sequence_subscription",
318
+ "created",
319
+ CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
320
+ ],
321
+ "close.sequenceSubscription.deleted": [
322
+ "sequence_subscription",
323
+ "deleted",
324
+ null,
325
+ ],
326
+ "close.sequenceSubscription.errored": [
327
+ "sequence_subscription",
328
+ "updated",
329
+ CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
330
+ ],
331
+ "close.sequenceSubscription.finished": [
332
+ "sequence_subscription",
333
+ "updated",
334
+ CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
335
+ ],
336
+ "close.sequenceSubscription.goalReached": [
337
+ "sequence_subscription",
338
+ "updated",
339
+ CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
340
+ ],
341
+ "close.sequenceSubscription.paused": [
342
+ "sequence_subscription",
343
+ "updated",
344
+ CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
345
+ ],
346
+ "close.sequenceSubscription.resumed": [
347
+ "sequence_subscription",
348
+ "updated",
349
+ CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
350
+ ],
351
+ "close.sequenceSubscription.updated": [
352
+ "sequence_subscription",
353
+ "updated",
354
+ CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
355
+ ],
356
+ "close.sms.received": [
357
+ "activity.sms",
358
+ "created",
359
+ CLOSE_SMS_EVENT_DATA_SCHEMA,
360
+ ],
361
+ "close.sms.sent": ["activity.sms", "sent", CLOSE_SMS_EVENT_DATA_SCHEMA],
362
+ "close.task.completed": ["task.*", "completed", CLOSE_TASK_EVENT_DATA_SCHEMA],
363
+ "close.task.created": ["task.*", "created", CLOSE_TASK_EVENT_DATA_SCHEMA],
364
+ "close.task.deleted": ["task.*", "deleted", null],
365
+ "close.task.updated": ["task.*", "updated", CLOSE_TASK_EVENT_DATA_SCHEMA],
366
+ };
367
+ export const CLOSE_SEMANTIC_EVENT_TYPES = [
368
+ "close.call.answered",
369
+ "close.call.completed",
370
+ "close.comment.created",
371
+ "close.comment.deleted",
372
+ "close.comment.updated",
373
+ "close.contact.created",
374
+ "close.contact.deleted",
375
+ "close.contact.updated",
376
+ "close.email.received",
377
+ "close.email.sent",
378
+ "close.lead.created",
379
+ "close.lead.deleted",
380
+ "close.lead.merged",
381
+ "close.lead.updated",
382
+ "close.meeting.canceled",
383
+ "close.meeting.completed",
384
+ "close.meeting.scheduled",
385
+ "close.meeting.started",
386
+ "close.opportunity.created",
387
+ "close.opportunity.deleted",
388
+ "close.opportunity.lost",
389
+ "close.opportunity.updated",
390
+ "close.opportunity.won",
391
+ "close.sequenceSubscription.created",
392
+ "close.sequenceSubscription.deleted",
393
+ "close.sequenceSubscription.errored",
394
+ "close.sequenceSubscription.finished",
395
+ "close.sequenceSubscription.goalReached",
396
+ "close.sequenceSubscription.paused",
397
+ "close.sequenceSubscription.resumed",
398
+ "close.sequenceSubscription.updated",
399
+ "close.sms.received",
400
+ "close.sms.sent",
401
+ "close.task.completed",
402
+ "close.task.created",
403
+ "close.task.deleted",
404
+ "close.task.updated",
405
+ ];
406
+ export const closeTriggerContracts = {
407
+ "close.event": {
408
+ configSchema: CLOSE_TRIGGER_CONFIG_SCHEMA,
409
+ eventSchema: CLOSE_EVENT_SCHEMA,
410
+ },
411
+ "close.call.answered": semanticContract("activity.call", "answered", CLOSE_CALL_EVENT_DATA_SCHEMA),
412
+ "close.call.completed": semanticContract("activity.call", "completed", CLOSE_CALL_EVENT_DATA_SCHEMA),
413
+ "close.comment.created": semanticContract("comment", "created", CLOSE_COMMENT_EVENT_DATA_SCHEMA),
414
+ "close.comment.deleted": semanticContract("comment", "deleted", z.null()),
415
+ "close.comment.updated": semanticContract("comment", "updated", CLOSE_COMMENT_EVENT_DATA_SCHEMA),
416
+ "close.contact.created": semanticContract("contact", "created", CLOSE_CONTACT_EVENT_DATA_SCHEMA),
417
+ "close.contact.deleted": semanticContract("contact", "deleted", z.null()),
418
+ "close.contact.updated": semanticContract("contact", "updated", CLOSE_CONTACT_EVENT_DATA_SCHEMA),
419
+ "close.email.received": semanticContract("activity.email", "created", CLOSE_EMAIL_EVENT_DATA_SCHEMA),
420
+ "close.email.sent": semanticContract("activity.email", "sent", CLOSE_EMAIL_EVENT_DATA_SCHEMA),
421
+ "close.lead.created": semanticContract("lead", "created", CLOSE_LEAD_EVENT_DATA_SCHEMA),
422
+ "close.lead.deleted": semanticContract("lead", "deleted", z.null()),
423
+ "close.lead.merged": semanticContract("lead", "merged", CLOSE_LEAD_EVENT_DATA_SCHEMA),
424
+ "close.lead.updated": semanticContract("lead", "updated", CLOSE_LEAD_EVENT_DATA_SCHEMA),
425
+ "close.meeting.canceled": semanticContract("activity.meeting", "canceled", CLOSE_MEETING_EVENT_DATA_SCHEMA),
426
+ "close.meeting.completed": semanticContract("activity.meeting", "completed", CLOSE_MEETING_EVENT_DATA_SCHEMA),
427
+ "close.meeting.scheduled": semanticContract("activity.meeting", "scheduled", CLOSE_MEETING_EVENT_DATA_SCHEMA),
428
+ "close.meeting.started": semanticContract("activity.meeting", "started", CLOSE_MEETING_EVENT_DATA_SCHEMA),
429
+ "close.opportunity.created": semanticContract("opportunity", "created", CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA),
430
+ "close.opportunity.deleted": semanticContract("opportunity", "deleted", z.null()),
431
+ "close.opportunity.lost": semanticContract("opportunity", "updated", CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA),
432
+ "close.opportunity.updated": semanticContract("opportunity", "updated", CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA),
433
+ "close.opportunity.won": semanticContract("opportunity", "updated", CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA),
434
+ "close.sequenceSubscription.created": semanticContract("sequence_subscription", "created", CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA),
435
+ "close.sequenceSubscription.deleted": semanticContract("sequence_subscription", "deleted", z.null()),
436
+ "close.sequenceSubscription.errored": semanticContract("sequence_subscription", "updated", CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA),
437
+ "close.sequenceSubscription.finished": semanticContract("sequence_subscription", "updated", CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA),
438
+ "close.sequenceSubscription.goalReached": semanticContract("sequence_subscription", "updated", CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA),
439
+ "close.sequenceSubscription.paused": semanticContract("sequence_subscription", "updated", CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA),
440
+ "close.sequenceSubscription.resumed": semanticContract("sequence_subscription", "updated", CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA),
441
+ "close.sequenceSubscription.updated": semanticContract("sequence_subscription", "updated", CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA),
442
+ "close.sms.received": semanticContract("activity.sms", "created", CLOSE_SMS_EVENT_DATA_SCHEMA),
443
+ "close.sms.sent": semanticContract("activity.sms", "sent", CLOSE_SMS_EVENT_DATA_SCHEMA),
444
+ "close.task.completed": taskContract("completed", CLOSE_TASK_EVENT_DATA_SCHEMA),
445
+ "close.task.created": taskContract("created", CLOSE_TASK_EVENT_DATA_SCHEMA),
446
+ "close.task.deleted": taskContract("deleted", z.null()),
447
+ "close.task.updated": taskContract("updated", CLOSE_TASK_EVENT_DATA_SCHEMA),
448
+ };
449
+ /**
450
+ * Classifies one normalized Close event into semantic trigger types.
451
+ *
452
+ * @param event - Normalized Close webhook event.
453
+ */
454
+ export function getCloseSemanticEventTypes(event) {
455
+ const exact = CLOSE_SEMANTIC_EVENT_TYPES.filter((type) => {
456
+ const [objectType, action] = SEMANTIC_EVENTS[type];
457
+ return (type !== "close.opportunity.won" &&
458
+ type !== "close.opportunity.lost" &&
459
+ type !== "close.email.received" &&
460
+ type !== "close.sms.received" &&
461
+ type !== "close.sequenceSubscription.errored" &&
462
+ type !== "close.sequenceSubscription.finished" &&
463
+ type !== "close.sequenceSubscription.goalReached" &&
464
+ type !== "close.sequenceSubscription.paused" &&
465
+ type !== "close.sequenceSubscription.resumed" &&
466
+ action === event.action &&
467
+ (objectType === "task.*"
468
+ ? event.objectType.startsWith("task.")
469
+ : objectType === event.objectType));
470
+ });
471
+ if (event.objectType === "opportunity" &&
472
+ event.action === "updated" &&
473
+ event.data &&
474
+ event.previousData &&
475
+ event.changedFields.includes("status_type")) {
476
+ const statusType = event.data.statusType;
477
+ if (statusType !== event.previousData.statusType) {
478
+ if (statusType === "won")
479
+ exact.push("close.opportunity.won");
480
+ if (statusType === "lost")
481
+ exact.push("close.opportunity.lost");
482
+ }
483
+ }
484
+ if (event.action === "created" &&
485
+ event.data &&
486
+ ((event.objectType === "activity.email" &&
487
+ event.data.direction === "incoming") ||
488
+ (event.objectType === "activity.sms" &&
489
+ event.data.direction === "inbound"))) {
490
+ exact.push(event.objectType === "activity.email"
491
+ ? "close.email.received"
492
+ : "close.sms.received");
493
+ }
494
+ if (event.objectType === "sequence_subscription" &&
495
+ event.action === "updated" &&
496
+ event.data &&
497
+ event.previousData &&
498
+ event.changedFields.includes("status") &&
499
+ event.data.status !== event.previousData.status) {
500
+ const status = event.data.status;
501
+ if (status === "active") {
502
+ exact.push("close.sequenceSubscription.resumed");
503
+ }
504
+ else if (status === "error") {
505
+ exact.push("close.sequenceSubscription.errored");
506
+ }
507
+ else if (status === "finished") {
508
+ exact.push("close.sequenceSubscription.finished");
509
+ }
510
+ else if (status === "goal") {
511
+ exact.push("close.sequenceSubscription.goalReached");
512
+ }
513
+ else if (status === "paused") {
514
+ exact.push("close.sequenceSubscription.paused");
515
+ }
516
+ }
517
+ return [...new Set(exact)];
518
+ }
519
+ /**
520
+ * Resolves the provider event selections needed by a Close trigger type.
521
+ *
522
+ * @param type - Registered Close trigger type.
523
+ */
524
+ export function getCloseProviderEventSelection(type) {
525
+ if (type === "close.event")
526
+ return CLOSE_WEBHOOK_EVENT_SELECTIONS;
527
+ if (!isCloseSemanticEventType(type))
528
+ return [];
529
+ const selection = SEMANTIC_EVENTS[type];
530
+ if (selection[0] === "task.*") {
531
+ return CLOSE_WEBHOOK_EVENT_SELECTIONS.filter(([objectType, action]) => objectType.startsWith("task.") && action === selection[1]);
532
+ }
533
+ return CLOSE_WEBHOOK_EVENT_SELECTIONS.filter(([objectType, action]) => objectType === selection[0] && action === selection[1]);
534
+ }
535
+ /**
536
+ * Creates a semantic Close trigger contract.
537
+ *
538
+ * @param objectType - Exact provider object type.
539
+ * @param action - Exact provider action.
540
+ * @param dataSchema - Schema for the event object snapshot.
541
+ */
542
+ function semanticContract(objectType, action, dataSchema) {
543
+ return {
544
+ configSchema: CLOSE_TRIGGER_CONFIG_SCHEMA,
545
+ eventSchema: CLOSE_EVENT_SCHEMA.extend({
546
+ action: z.literal(action),
547
+ data: dataSchema,
548
+ objectType: z.literal(objectType),
549
+ }),
550
+ };
551
+ }
552
+ /**
553
+ * Creates a task-family Close trigger contract.
554
+ *
555
+ * @param action - Exact provider action.
556
+ * @param dataSchema - Schema for the task snapshot.
557
+ */
558
+ function taskContract(action, dataSchema) {
559
+ return {
560
+ configSchema: CLOSE_TRIGGER_CONFIG_SCHEMA,
561
+ eventSchema: CLOSE_EVENT_SCHEMA.extend({
562
+ action: z.literal(action),
563
+ data: dataSchema,
564
+ objectType: z.string().startsWith("task."),
565
+ }),
566
+ };
567
+ }
568
+ /**
569
+ * Checks whether a trigger type has a semantic Close definition.
570
+ *
571
+ * @param type - Candidate trigger type.
572
+ */
573
+ function isCloseSemanticEventType(type) {
574
+ return CLOSE_SEMANTIC_EVENT_TYPES.some((candidate) => candidate === type);
575
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./api.js";
2
+ export * from "./events.js";
3
+ export * from "./schemas.js";
@@ -0,0 +1,3 @@
1
+ export * from "./api.js";
2
+ export * from "./events.js";
3
+ export * from "./schemas.js";