@automate.ax/integration-contracts 0.103.2 → 0.105.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.
@@ -110,8 +110,8 @@ export declare const SLACK_REACTION_ITEM_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodO
110
110
  conversationId: z.ZodString;
111
111
  conversationType: z.ZodOptional<z.ZodEnum<{
112
112
  group: "group";
113
- channel: "channel";
114
113
  im: "im";
114
+ channel: "channel";
115
115
  mpim: "mpim";
116
116
  }>>;
117
117
  messageTimestamp: z.ZodString;
@@ -134,10 +134,10 @@ export declare const GRAPH_MEMBER_SCHEMA: z.ZodPipe<z.ZodObject<{
134
134
  }>>;
135
135
  export declare const TEAMS_CHAT_SCHEMA: z.ZodObject<{
136
136
  chatType: z.ZodEnum<{
137
+ meeting: "meeting";
137
138
  group: "group";
138
139
  unknownFutureValue: "unknownFutureValue";
139
140
  oneOnOne: "oneOnOne";
140
- meeting: "meeting";
141
141
  }>;
142
142
  createdAt: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodDate, z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>]>>>, z.ZodTransform<Date | undefined, Date | null | undefined>>;
143
143
  chatId: z.ZodString;
@@ -148,10 +148,10 @@ export declare const TEAMS_CHAT_SCHEMA: z.ZodObject<{
148
148
  }, z.core.$strip>;
149
149
  export declare const GRAPH_CHAT_SCHEMA: z.ZodPipe<z.ZodObject<{
150
150
  chatType: z.ZodEnum<{
151
+ meeting: "meeting";
151
152
  group: "group";
152
153
  unknownFutureValue: "unknownFutureValue";
153
154
  oneOnOne: "oneOnOne";
154
- meeting: "meeting";
155
155
  }>;
156
156
  createdDateTime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
157
157
  id: z.ZodString;
@@ -160,7 +160,7 @@ export declare const GRAPH_CHAT_SCHEMA: z.ZodPipe<z.ZodObject<{
160
160
  topic: z.ZodOptional<z.ZodNullable<z.ZodString>>;
161
161
  webUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
162
162
  }, z.core.$loose>, z.ZodTransform<{
163
- chatType: "group" | "unknownFutureValue" | "oneOnOne" | "meeting";
163
+ chatType: "meeting" | "group" | "unknownFutureValue" | "oneOnOne";
164
164
  createdAt: Date | undefined;
165
165
  chatId: string;
166
166
  updatedAt: Date | undefined;
@@ -169,7 +169,7 @@ export declare const GRAPH_CHAT_SCHEMA: z.ZodPipe<z.ZodObject<{
169
169
  webUrl: string | undefined;
170
170
  }, {
171
171
  [x: string]: unknown;
172
- chatType: "group" | "unknownFutureValue" | "oneOnOne" | "meeting";
172
+ chatType: "meeting" | "group" | "unknownFutureValue" | "oneOnOne";
173
173
  id: string;
174
174
  createdDateTime?: string | null | undefined;
175
175
  lastUpdatedDateTime?: string | null | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automate.ax/integration-contracts",
3
- "version": "0.103.2",
3
+ "version": "0.105.0",
4
4
  "description": "Shared integration payload contracts and provider primitives for Automate.ax.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,7 +49,7 @@
49
49
  }
50
50
  },
51
51
  "dependencies": {
52
- "@automate.ax/codec": "0.103.2",
52
+ "@automate.ax/codec": "0.105.0",
53
53
  "@cfworker/json-schema": "^4.1.1",
54
54
  "@googleapis/calendar": "^15.0.0",
55
55
  "@googleapis/forms": "^6.0.1",
@@ -10,6 +10,7 @@ import {
10
10
  CLOSE_MEETING_SCHEMA,
11
11
  CLOSE_OPPORTUNITY_SCHEMA,
12
12
  CLOSE_SEQUENCE_SUBSCRIPTION_SCHEMA,
13
+ CLOSE_SMART_VIEW_SCHEMA,
13
14
  CLOSE_SMS_SCHEMA,
14
15
  CLOSE_TASK_SCHEMA,
15
16
  } from "./schemas"
@@ -228,6 +229,13 @@ export const CLOSE_WEBHOOK_PAYLOAD_SCHEMA = z.object({
228
229
  })
229
230
 
230
231
  export const CLOSE_TRIGGER_CONFIG_SCHEMA = z.object({})
232
+ export const CLOSE_SMART_VIEW_MEMBERSHIP_TRIGGER_CONFIG_SCHEMA = z.object({
233
+ smartViewId: z.string().startsWith("save_"),
234
+ })
235
+ export const CLOSE_SMART_VIEW_MEMBERSHIP_EVENT_SCHEMA = z.object({
236
+ leadId: z.string().startsWith("lead_"),
237
+ smartViewId: z.string().startsWith("save_"),
238
+ })
231
239
 
232
240
  // Event snapshots can omit fields that are required by the current REST
233
241
  // resource. Close's documented opportunity-won webhook is one such payload.
@@ -244,6 +252,7 @@ const CLOSE_MEETING_EVENT_DATA_SCHEMA = CLOSE_MEETING_SCHEMA.partial()
244
252
  const CLOSE_OPPORTUNITY_EVENT_DATA_SCHEMA = CLOSE_OPPORTUNITY_SCHEMA.partial()
245
253
  const CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA =
246
254
  CLOSE_SEQUENCE_SUBSCRIPTION_SCHEMA.partial()
255
+ const CLOSE_SMART_VIEW_EVENT_DATA_SCHEMA = CLOSE_SMART_VIEW_SCHEMA.partial()
247
256
  const CLOSE_SMS_EVENT_DATA_SCHEMA = CLOSE_SMS_SCHEMA.partial()
248
257
  const CLOSE_DELETED_EVENT_DATA_SCHEMA = z.union([
249
258
  z.null(),
@@ -388,6 +397,16 @@ const SEMANTIC_EVENTS = {
388
397
  "updated",
389
398
  CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
390
399
  ],
400
+ "close.smartView.created": [
401
+ "saved_search",
402
+ "created",
403
+ CLOSE_SMART_VIEW_EVENT_DATA_SCHEMA,
404
+ ],
405
+ "close.smartView.updated": [
406
+ "saved_search",
407
+ "updated",
408
+ CLOSE_SMART_VIEW_EVENT_DATA_SCHEMA,
409
+ ],
391
410
  "close.sms.received": [
392
411
  "activity.sms",
393
412
  "created",
@@ -432,6 +451,8 @@ export const CLOSE_SEMANTIC_EVENT_TYPES = [
432
451
  "close.sequenceSubscription.paused",
433
452
  "close.sequenceSubscription.resumed",
434
453
  "close.sequenceSubscription.updated",
454
+ "close.smartView.created",
455
+ "close.smartView.updated",
435
456
  "close.sms.received",
436
457
  "close.sms.sent",
437
458
  "close.task.completed",
@@ -440,6 +461,11 @@ export const CLOSE_SEMANTIC_EVENT_TYPES = [
440
461
  "close.task.updated",
441
462
  ] as const satisfies readonly (keyof typeof SEMANTIC_EVENTS)[]
442
463
 
464
+ export const CLOSE_SMART_VIEW_MEMBERSHIP_EVENT_TYPES = [
465
+ "close.smartView.leadEntered",
466
+ "close.smartView.leadExited",
467
+ ] as const
468
+
443
469
  export const closeTriggerContracts = {
444
470
  "close.event": {
445
471
  configSchema: CLOSE_TRIGGER_CONFIG_SCHEMA,
@@ -600,6 +626,24 @@ export const closeTriggerContracts = {
600
626
  "updated",
601
627
  CLOSE_SEQUENCE_SUBSCRIPTION_EVENT_DATA_SCHEMA,
602
628
  ),
629
+ "close.smartView.created": semanticContract(
630
+ "saved_search",
631
+ "created",
632
+ CLOSE_SMART_VIEW_EVENT_DATA_SCHEMA,
633
+ ),
634
+ "close.smartView.updated": semanticContract(
635
+ "saved_search",
636
+ "updated",
637
+ CLOSE_SMART_VIEW_EVENT_DATA_SCHEMA,
638
+ ),
639
+ "close.smartView.leadEntered": {
640
+ configSchema: CLOSE_SMART_VIEW_MEMBERSHIP_TRIGGER_CONFIG_SCHEMA,
641
+ eventSchema: CLOSE_SMART_VIEW_MEMBERSHIP_EVENT_SCHEMA,
642
+ },
643
+ "close.smartView.leadExited": {
644
+ configSchema: CLOSE_SMART_VIEW_MEMBERSHIP_TRIGGER_CONFIG_SCHEMA,
645
+ eventSchema: CLOSE_SMART_VIEW_MEMBERSHIP_EVENT_SCHEMA,
646
+ },
603
647
  "close.sms.received": semanticContract(
604
648
  "activity.sms",
605
649
  "created",
@@ -622,10 +666,7 @@ export const closeTriggerContracts = {
622
666
  "close.task.updated": taskContract("updated", CLOSE_TASK_EVENT_DATA_SCHEMA),
623
667
  } as const satisfies Record<
624
668
  string,
625
- {
626
- configSchema: typeof CLOSE_TRIGGER_CONFIG_SCHEMA
627
- eventSchema: z.ZodType
628
- }
669
+ { configSchema: z.ZodType; eventSchema: z.ZodType }
629
670
  >
630
671
 
631
672
  /**
@@ -80,6 +80,50 @@ export const CLOSE_CONTACT_SCHEMA = z.object({
80
80
  urls: CLOSE_CONTACT_URL_SCHEMA.array().prefault([]),
81
81
  })
82
82
 
83
+ export const CLOSE_SMART_VIEW_TYPE_SCHEMA = z.enum([
84
+ "lead",
85
+ "contact",
86
+ "opportunity",
87
+ "call",
88
+ "email",
89
+ "sms",
90
+ "meeting",
91
+ "note",
92
+ "whatsapp_message",
93
+ "custom_activity",
94
+ "form_submission",
95
+ ])
96
+
97
+ export const CLOSE_SMART_VIEW_SHARING_SETTINGS_SCHEMA = z.object({
98
+ createdAt: DATE_SCHEMA.nullable(),
99
+ createdById: z.string().nullable(),
100
+ groupIds: z.string().array(),
101
+ updatedAt: DATE_SCHEMA.nullable(),
102
+ updatedById: z.string().nullable(),
103
+ userIds: z.string().array(),
104
+ wholeOrg: z.boolean(),
105
+ })
106
+
107
+ export const CLOSE_SMART_VIEW_SCHEMA = z.object({
108
+ createdAt: DATE_SCHEMA,
109
+ description: z.string().nullable(),
110
+ id: z.string(),
111
+ isShared: z.boolean(),
112
+ isUserDependent: z.boolean().nullable(),
113
+ name: z.string(),
114
+ organizationId: z.string(),
115
+ query: z.string().nullable(),
116
+ selectedFields: CLOSE_OBJECT_SCHEMA.array().nullable().optional(),
117
+ sharedWith: z.string().array().nullable().optional(),
118
+ sharingSettings:
119
+ CLOSE_SMART_VIEW_SHARING_SETTINGS_SCHEMA.nullable().optional(),
120
+ sQuery: CLOSE_OBJECT_SCHEMA.nullable(),
121
+ type: CLOSE_SMART_VIEW_TYPE_SCHEMA,
122
+ updatedAt: DATE_SCHEMA,
123
+ userId: z.string().nullable(),
124
+ usedRecently: z.boolean().optional(),
125
+ })
126
+
83
127
  export const CLOSE_OPPORTUNITY_STATUS_TYPE_SCHEMA = z.enum([
84
128
  "active",
85
129
  "lost",
@@ -1,6 +1,6 @@
1
1
  import * as z from "zod"
2
2
  import {
3
- NOTION_EVENT_SCHEMA,
3
+ NOTION_PUBLIC_EVENT_SCHEMA,
4
4
  notionSemanticEventSchema,
5
5
  type NotionSemanticWebhookEvent,
6
6
  type NotionWebhookEvent,
@@ -144,7 +144,7 @@ export const notionTriggerContracts: NotionTriggerContracts = {
144
144
  "notion.dataSource.undeleted": semanticContract("data_source.undeleted"),
145
145
  "notion.event": {
146
146
  configSchema: NOTION_TRIGGER_CONFIG_SCHEMA,
147
- eventSchema: NOTION_EVENT_SCHEMA,
147
+ eventSchema: NOTION_PUBLIC_EVENT_SCHEMA,
148
148
  },
149
149
  "notion.fileUpload.completed": semanticContract("file_upload.completed"),
150
150
  "notion.fileUpload.created": semanticContract("file_upload.created"),
@@ -29,6 +29,7 @@ import type {
29
29
  ViewDeletedWebhookPayload,
30
30
  ViewUpdatedWebhookPayload,
31
31
  } from "@notionhq/client"
32
+ import type { CamelCasedPropertiesDeep } from "type-fest"
32
33
  import * as z from "zod"
33
34
 
34
35
  type OfficialNotionWebhookEvent =
@@ -294,15 +295,29 @@ const RAW_NOTION_EVENT_SCHEMA = z.discriminatedUnion("type", [
294
295
  ]) satisfies z.ZodType<ExpectedNotionWebhookEvent>
295
296
 
296
297
  /** Current portable Notion webhook payload validated at ingress. */
297
- export type NotionWebhookEvent = z.infer<typeof RAW_NOTION_EVENT_SCHEMA>
298
+ type ProviderNotionWebhookEvent = z.infer<typeof RAW_NOTION_EVENT_SCHEMA>
298
299
 
299
- export type NotionWebhookEventType = NotionWebhookEvent["type"]
300
+ /** Public camelCase representation of a Notion webhook payload. */
301
+ export type NotionWebhookEvent =
302
+ CamelCasedPropertiesDeep<ExpectedNotionWebhookEvent>
303
+
304
+ export type NotionWebhookEventType = ProviderNotionWebhookEvent["type"]
300
305
 
301
306
  export type NotionSemanticWebhookEvent<TType extends NotionWebhookEventType> =
302
307
  Extract<NotionWebhookEvent, { type: TType }>
303
308
 
304
309
  /** Exact current Notion webhook schema shared by ingress and triggers. */
305
- export const NOTION_EVENT_SCHEMA = RAW_NOTION_EVENT_SCHEMA
310
+ export const NOTION_EVENT_SCHEMA =
311
+ RAW_NOTION_EVENT_SCHEMA.transform(camelCaseNotionEvent)
312
+
313
+ /** Validates an already-normalized Notion webhook event for trigger delivery. */
314
+ export const NOTION_PUBLIC_EVENT_SCHEMA = z.custom<NotionWebhookEvent>(
315
+ (value) =>
316
+ typeof value === "object" &&
317
+ value !== null &&
318
+ "type" in value &&
319
+ typeof value.type === "string",
320
+ )
306
321
 
307
322
  /**
308
323
  * Runtime schema for one semantic Notion webhook event.
@@ -314,7 +329,7 @@ export function notionSemanticEventSchema<TType extends NotionWebhookEventType>(
314
329
  ) {
315
330
  return z.custom<NotionSemanticWebhookEvent<TType>>(
316
331
  (value) =>
317
- RAW_NOTION_EVENT_SCHEMA.safeParse(value).success &&
332
+ NOTION_PUBLIC_EVENT_SCHEMA.safeParse(value).success &&
318
333
  typeof value === "object" &&
319
334
  value !== null &&
320
335
  "type" in value &&
@@ -323,6 +338,45 @@ export function notionSemanticEventSchema<TType extends NotionWebhookEventType>(
323
338
  )
324
339
  }
325
340
 
341
+ /**
342
+ * Converts provider-native webhook fields before public trigger delivery.
343
+ *
344
+ * @param event - Validated provider webhook payload.
345
+ */
346
+ function camelCaseNotionEvent(
347
+ event: ProviderNotionWebhookEvent,
348
+ ): NotionWebhookEvent {
349
+ // REVIEW: the recursive transform preserves the raw schema's JSON structure
350
+ // while changing only property names.
351
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Raw schema validation guarantees this result's shape.
352
+ return camelCaseNotionValue(event) as NotionWebhookEvent
353
+ }
354
+
355
+ /**
356
+ * Recursively camel-cases object property names in a JSON-compatible value.
357
+ *
358
+ * @param value - Provider-native JSON value.
359
+ */
360
+ function camelCaseNotionValue(value: unknown): unknown {
361
+ if (Array.isArray(value)) return value.map(camelCaseNotionValue)
362
+ if (!isPlainRecord(value)) return value
363
+ return Object.fromEntries(
364
+ Object.entries(value).map(([key, nestedValue]) => [
365
+ key.replace(/_([a-z])/g, (_, letter: string) => letter.toUpperCase()),
366
+ camelCaseNotionValue(nestedValue),
367
+ ]),
368
+ )
369
+ }
370
+
371
+ /**
372
+ * Checks whether a value can have provider field names.
373
+ *
374
+ * @param value - Value to inspect.
375
+ */
376
+ function isPlainRecord(value: unknown): value is Record<string, unknown> {
377
+ return typeof value === "object" && value !== null
378
+ }
379
+
326
380
  /**
327
381
  * Builds one provider webhook schema over the shared delivery envelope.
328
382
  *