@automate.ax/integration-contracts 0.147.1 → 0.148.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/dist/close/events.d.ts +4 -4
- package/dist/close/schemas.d.ts +6 -6
- package/dist/google-drive/index.d.ts +3 -3
- package/dist/kit/api.d.ts +78 -0
- package/dist/kit/api.js +386 -0
- package/dist/kit/events.d.ts +437 -0
- package/dist/kit/events.js +285 -0
- package/dist/kit/index.d.ts +6 -0
- package/dist/kit/index.js +5 -0
- package/dist/kit/openapi-operations.generated.d.ts +5 -0
- package/dist/kit/openapi-operations.generated.js +5 -0
- package/dist/kit/openapi-types.generated.d.ts +9485 -0
- package/dist/kit/openapi-types.generated.js +1 -0
- package/dist/kit/operation-manifest.d.ts +657 -0
- package/dist/kit/operation-manifest.js +98 -0
- package/dist/kit/schemas.d.ts +42 -0
- package/dist/kit/schemas.js +43 -0
- package/dist/kit/types.d.ts +41 -0
- package/dist/kit/types.js +1 -0
- package/dist/notion/schemas.d.ts +108 -108
- package/dist/resend/action-schemas.d.ts +14 -14
- package/dist/triggers.d.ts +2 -1
- package/package.json +9 -2
- package/src/kit/api.ts +523 -0
- package/src/kit/events.ts +352 -0
- package/src/kit/index.ts +6 -0
- package/src/kit/openapi-operations.generated.ts +7 -0
- package/src/kit/openapi-types.generated.ts +9710 -0
- package/src/kit/operation-manifest.ts +771 -0
- package/src/kit/schemas.ts +93 -0
- package/src/kit/types.ts +87 -0
- package/src/triggers.ts +2 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { encodableSchema, type Encodable } from "@automate.ax/codec"
|
|
2
|
+
import * as z from "zod"
|
|
3
|
+
|
|
4
|
+
/** Kit webhook event types currently available for endpoint subscriptions. */
|
|
5
|
+
export const KIT_WEBHOOK_EVENT_TYPES = [
|
|
6
|
+
"subscriber.created",
|
|
7
|
+
"subscriber.activated",
|
|
8
|
+
"subscriber.unsubscribed",
|
|
9
|
+
"subscriber.bounced",
|
|
10
|
+
"subscriber.complained",
|
|
11
|
+
"subscriber.subscribed_to_form",
|
|
12
|
+
"subscriber.added_to_sequence",
|
|
13
|
+
"subscriber.sequence_completed",
|
|
14
|
+
"subscriber.tag_added",
|
|
15
|
+
"subscriber.tag_removed",
|
|
16
|
+
"subscriber.custom_field_value_updated",
|
|
17
|
+
"tag.created",
|
|
18
|
+
"tag.deleted",
|
|
19
|
+
"custom_field.created",
|
|
20
|
+
"custom_field.deleted",
|
|
21
|
+
"sequence.created",
|
|
22
|
+
"sequence.deleted",
|
|
23
|
+
"sequence.published",
|
|
24
|
+
"sequence.disabled",
|
|
25
|
+
"broadcast.created",
|
|
26
|
+
"broadcast.sent",
|
|
27
|
+
"broadcast.deleted",
|
|
28
|
+
"post.published",
|
|
29
|
+
] as const
|
|
30
|
+
|
|
31
|
+
export type KitWebhookEventType = (typeof KIT_WEBHOOK_EVENT_TYPES)[number]
|
|
32
|
+
|
|
33
|
+
const KIT_SUBSCRIBER_SCHEMA = z
|
|
34
|
+
.looseObject({
|
|
35
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
36
|
+
emailAddress: z.email(),
|
|
37
|
+
fields: z.record(z.string(), z.string().nullable()),
|
|
38
|
+
firstName: z.string().nullable(),
|
|
39
|
+
id: z.number().int(),
|
|
40
|
+
state: z.enum(["active", "bounced", "cancelled", "complained", "inactive"]),
|
|
41
|
+
})
|
|
42
|
+
.catchall(encodableSchema)
|
|
43
|
+
const KIT_FORM_SCHEMA = z
|
|
44
|
+
.looseObject({
|
|
45
|
+
archived: z.boolean(),
|
|
46
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
47
|
+
format: z.string(),
|
|
48
|
+
id: z.number().int(),
|
|
49
|
+
name: z.string(),
|
|
50
|
+
type: z.enum(["embed", "hosted"]),
|
|
51
|
+
uid: z.string(),
|
|
52
|
+
})
|
|
53
|
+
.catchall(encodableSchema)
|
|
54
|
+
const KIT_SEQUENCE_SCHEMA = z
|
|
55
|
+
.looseObject({
|
|
56
|
+
active: z.boolean(),
|
|
57
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
58
|
+
emailTemplateId: z.number().int().nullable(),
|
|
59
|
+
hold: z.boolean(),
|
|
60
|
+
id: z.number().int(),
|
|
61
|
+
name: z.string(),
|
|
62
|
+
repeat: z.boolean(),
|
|
63
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
64
|
+
})
|
|
65
|
+
.catchall(encodableSchema)
|
|
66
|
+
const KIT_TAG_SCHEMA = z
|
|
67
|
+
.looseObject({
|
|
68
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
69
|
+
id: z.number().int(),
|
|
70
|
+
name: z.string(),
|
|
71
|
+
})
|
|
72
|
+
.catchall(encodableSchema)
|
|
73
|
+
const KIT_CUSTOM_FIELD_SCHEMA = z
|
|
74
|
+
.looseObject({
|
|
75
|
+
id: z.number().int(),
|
|
76
|
+
key: z.string(),
|
|
77
|
+
label: z.string(),
|
|
78
|
+
name: z.string(),
|
|
79
|
+
value: z.string().nullable().optional(),
|
|
80
|
+
})
|
|
81
|
+
.catchall(encodableSchema)
|
|
82
|
+
const KIT_BROADCAST_SCHEMA = z
|
|
83
|
+
.looseObject({
|
|
84
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
85
|
+
description: z.string().nullable(),
|
|
86
|
+
id: z.number().int(),
|
|
87
|
+
previewText: z.string().nullable(),
|
|
88
|
+
public: z.boolean(),
|
|
89
|
+
publicationId: z.number().int(),
|
|
90
|
+
publishedAt: z.iso.datetime({ offset: true }).nullable(),
|
|
91
|
+
sendAt: z.iso.datetime({ offset: true }).nullable(),
|
|
92
|
+
status: z.string(),
|
|
93
|
+
subject: z.string(),
|
|
94
|
+
})
|
|
95
|
+
.catchall(encodableSchema)
|
|
96
|
+
const KIT_POST_SCHEMA = z
|
|
97
|
+
.looseObject({
|
|
98
|
+
id: z.number().int(),
|
|
99
|
+
isPaid: z.boolean(),
|
|
100
|
+
publicUrl: z.url(),
|
|
101
|
+
publicationId: z.number().int(),
|
|
102
|
+
publishedAt: z.iso.datetime({ offset: true }),
|
|
103
|
+
slug: z.string(),
|
|
104
|
+
title: z.string(),
|
|
105
|
+
})
|
|
106
|
+
.catchall(encodableSchema)
|
|
107
|
+
|
|
108
|
+
const SUBSCRIBER_DATA_SCHEMA = z
|
|
109
|
+
.looseObject({ subscriber: KIT_SUBSCRIBER_SCHEMA })
|
|
110
|
+
.catchall(encodableSchema)
|
|
111
|
+
|
|
112
|
+
const KIT_EVENT_DATA_SCHEMAS = {
|
|
113
|
+
"broadcast.created": z.looseObject({ broadcast: KIT_BROADCAST_SCHEMA }),
|
|
114
|
+
"broadcast.deleted": z.looseObject({ broadcast: KIT_BROADCAST_SCHEMA }),
|
|
115
|
+
"broadcast.sent": z.looseObject({ broadcast: KIT_BROADCAST_SCHEMA }),
|
|
116
|
+
"custom_field.created": z.looseObject({
|
|
117
|
+
customField: KIT_CUSTOM_FIELD_SCHEMA,
|
|
118
|
+
}),
|
|
119
|
+
"custom_field.deleted": z.looseObject({
|
|
120
|
+
customField: KIT_CUSTOM_FIELD_SCHEMA,
|
|
121
|
+
}),
|
|
122
|
+
"post.published": z.looseObject({ post: KIT_POST_SCHEMA }),
|
|
123
|
+
"sequence.created": z.looseObject({ sequence: KIT_SEQUENCE_SCHEMA }),
|
|
124
|
+
"sequence.deleted": z.looseObject({ sequence: KIT_SEQUENCE_SCHEMA }),
|
|
125
|
+
"sequence.disabled": z.looseObject({ sequence: KIT_SEQUENCE_SCHEMA }),
|
|
126
|
+
"sequence.published": z.looseObject({ sequence: KIT_SEQUENCE_SCHEMA }),
|
|
127
|
+
"subscriber.activated": SUBSCRIBER_DATA_SCHEMA,
|
|
128
|
+
"subscriber.added_to_sequence": SUBSCRIBER_DATA_SCHEMA.extend({
|
|
129
|
+
sequence: KIT_SEQUENCE_SCHEMA,
|
|
130
|
+
}),
|
|
131
|
+
"subscriber.bounced": SUBSCRIBER_DATA_SCHEMA,
|
|
132
|
+
"subscriber.complained": SUBSCRIBER_DATA_SCHEMA,
|
|
133
|
+
"subscriber.created": SUBSCRIBER_DATA_SCHEMA,
|
|
134
|
+
"subscriber.custom_field_value_updated": SUBSCRIBER_DATA_SCHEMA.extend({
|
|
135
|
+
customField: KIT_CUSTOM_FIELD_SCHEMA,
|
|
136
|
+
}),
|
|
137
|
+
"subscriber.sequence_completed": SUBSCRIBER_DATA_SCHEMA.extend({
|
|
138
|
+
sequence: KIT_SEQUENCE_SCHEMA,
|
|
139
|
+
}),
|
|
140
|
+
"subscriber.subscribed_to_form": SUBSCRIBER_DATA_SCHEMA.extend({
|
|
141
|
+
form: KIT_FORM_SCHEMA,
|
|
142
|
+
}),
|
|
143
|
+
"subscriber.tag_added": SUBSCRIBER_DATA_SCHEMA.extend({
|
|
144
|
+
tag: KIT_TAG_SCHEMA,
|
|
145
|
+
}),
|
|
146
|
+
"subscriber.tag_removed": SUBSCRIBER_DATA_SCHEMA.extend({
|
|
147
|
+
tag: KIT_TAG_SCHEMA,
|
|
148
|
+
}),
|
|
149
|
+
"subscriber.unsubscribed": SUBSCRIBER_DATA_SCHEMA,
|
|
150
|
+
"tag.created": z.looseObject({ tag: KIT_TAG_SCHEMA }),
|
|
151
|
+
"tag.deleted": z.looseObject({ tag: KIT_TAG_SCHEMA }),
|
|
152
|
+
} as const satisfies Record<KitWebhookEventType, z.ZodType>
|
|
153
|
+
|
|
154
|
+
/** One normalized Kit webhook event narrowed by provider type. */
|
|
155
|
+
export type KitEvent<TType extends KitWebhookEventType = KitWebhookEventType> =
|
|
156
|
+
TType extends KitWebhookEventType
|
|
157
|
+
? {
|
|
158
|
+
readonly [key: string]: Encodable
|
|
159
|
+
created: string
|
|
160
|
+
data: z.output<(typeof KIT_EVENT_DATA_SCHEMAS)[TType]> & {
|
|
161
|
+
readonly [key: string]: Encodable
|
|
162
|
+
}
|
|
163
|
+
id: string
|
|
164
|
+
type: TType
|
|
165
|
+
}
|
|
166
|
+
: never
|
|
167
|
+
|
|
168
|
+
/** One parsed Kit webhook delivery containing one to 100 same-type events. */
|
|
169
|
+
export interface KitWebhookEnvelope {
|
|
170
|
+
readonly [key: string]: Encodable
|
|
171
|
+
deliveryId: number
|
|
172
|
+
events: KitEvent[]
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export const KIT_TRIGGER_CONFIG_SCHEMA = z.object({})
|
|
176
|
+
|
|
177
|
+
/** Validates any currently available normalized Kit event. */
|
|
178
|
+
export const KIT_EVENT_SCHEMA: z.ZodType<KitEvent> = z.custom<KitEvent>(
|
|
179
|
+
(value) => {
|
|
180
|
+
if (
|
|
181
|
+
typeof value !== "object" ||
|
|
182
|
+
value === null ||
|
|
183
|
+
!("type" in value) ||
|
|
184
|
+
typeof value.type !== "string" ||
|
|
185
|
+
!isKitWebhookEventType(value.type)
|
|
186
|
+
) {
|
|
187
|
+
return false
|
|
188
|
+
}
|
|
189
|
+
return kitSemanticEventSchema(value.type).safeParse(value).success
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
/** Parses and normalizes Kit's provider-native delivery envelope. */
|
|
194
|
+
export const KIT_WEBHOOK_ENVELOPE_SCHEMA: z.ZodType<KitWebhookEnvelope> = z
|
|
195
|
+
.preprocess(
|
|
196
|
+
(value) => camelizeKitWebhookValue(value),
|
|
197
|
+
z
|
|
198
|
+
.looseObject({
|
|
199
|
+
deliveryId: z.number().int(),
|
|
200
|
+
events: KIT_EVENT_SCHEMA.array().min(1).max(100),
|
|
201
|
+
})
|
|
202
|
+
.catchall(encodableSchema),
|
|
203
|
+
)
|
|
204
|
+
.refine(
|
|
205
|
+
(delivery) =>
|
|
206
|
+
delivery.events.every((event) => event.type === delivery.events[0]?.type),
|
|
207
|
+
{ message: "Kit webhook deliveries must contain one event type." },
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
/** Platform event type emitted for each exact Kit provider event. */
|
|
211
|
+
export const KIT_EVENT_TYPE_MAP = {
|
|
212
|
+
"broadcast.created": "kit.broadcast.created",
|
|
213
|
+
"broadcast.deleted": "kit.broadcast.deleted",
|
|
214
|
+
"broadcast.sent": "kit.broadcast.sent",
|
|
215
|
+
"custom_field.created": "kit.customField.created",
|
|
216
|
+
"custom_field.deleted": "kit.customField.deleted",
|
|
217
|
+
"post.published": "kit.post.published",
|
|
218
|
+
"sequence.created": "kit.sequence.created",
|
|
219
|
+
"sequence.deleted": "kit.sequence.deleted",
|
|
220
|
+
"sequence.disabled": "kit.sequence.disabled",
|
|
221
|
+
"sequence.published": "kit.sequence.published",
|
|
222
|
+
"subscriber.activated": "kit.subscriber.activated",
|
|
223
|
+
"subscriber.added_to_sequence": "kit.subscriber.addedToSequence",
|
|
224
|
+
"subscriber.bounced": "kit.subscriber.bounced",
|
|
225
|
+
"subscriber.complained": "kit.subscriber.complained",
|
|
226
|
+
"subscriber.created": "kit.subscriber.created",
|
|
227
|
+
"subscriber.custom_field_value_updated":
|
|
228
|
+
"kit.subscriber.customFieldValueUpdated",
|
|
229
|
+
"subscriber.sequence_completed": "kit.subscriber.sequenceCompleted",
|
|
230
|
+
"subscriber.subscribed_to_form": "kit.subscriber.subscribedToForm",
|
|
231
|
+
"subscriber.tag_added": "kit.subscriber.tagAdded",
|
|
232
|
+
"subscriber.tag_removed": "kit.subscriber.tagRemoved",
|
|
233
|
+
"subscriber.unsubscribed": "kit.subscriber.unsubscribed",
|
|
234
|
+
"tag.created": "kit.tag.created",
|
|
235
|
+
"tag.deleted": "kit.tag.deleted",
|
|
236
|
+
} as const satisfies Record<KitWebhookEventType, string>
|
|
237
|
+
|
|
238
|
+
type KitTriggerContract<TEvent> = {
|
|
239
|
+
readonly configSchema: typeof KIT_TRIGGER_CONFIG_SCHEMA
|
|
240
|
+
readonly eventSchema: z.ZodType<TEvent>
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Semantic contracts keyed by every public Kit platform event type. */
|
|
244
|
+
type KitSemanticContracts = {
|
|
245
|
+
readonly [TType in KitWebhookEventType as (typeof KIT_EVENT_TYPE_MAP)[TType]]: KitTriggerContract<
|
|
246
|
+
KitEvent<TType>
|
|
247
|
+
>
|
|
248
|
+
} & { readonly "kit.event": KitTriggerContract<KitEvent> }
|
|
249
|
+
|
|
250
|
+
/** Exact provider-to-platform Kit trigger contract map. */
|
|
251
|
+
export const kitTriggerContracts: KitSemanticContracts = {
|
|
252
|
+
"kit.broadcast.created": contract("broadcast.created"),
|
|
253
|
+
"kit.broadcast.deleted": contract("broadcast.deleted"),
|
|
254
|
+
"kit.broadcast.sent": contract("broadcast.sent"),
|
|
255
|
+
"kit.customField.created": contract("custom_field.created"),
|
|
256
|
+
"kit.customField.deleted": contract("custom_field.deleted"),
|
|
257
|
+
"kit.event": {
|
|
258
|
+
configSchema: KIT_TRIGGER_CONFIG_SCHEMA,
|
|
259
|
+
eventSchema: KIT_EVENT_SCHEMA,
|
|
260
|
+
},
|
|
261
|
+
"kit.post.published": contract("post.published"),
|
|
262
|
+
"kit.sequence.created": contract("sequence.created"),
|
|
263
|
+
"kit.sequence.deleted": contract("sequence.deleted"),
|
|
264
|
+
"kit.sequence.disabled": contract("sequence.disabled"),
|
|
265
|
+
"kit.sequence.published": contract("sequence.published"),
|
|
266
|
+
"kit.subscriber.activated": contract("subscriber.activated"),
|
|
267
|
+
"kit.subscriber.addedToSequence": contract("subscriber.added_to_sequence"),
|
|
268
|
+
"kit.subscriber.bounced": contract("subscriber.bounced"),
|
|
269
|
+
"kit.subscriber.complained": contract("subscriber.complained"),
|
|
270
|
+
"kit.subscriber.created": contract("subscriber.created"),
|
|
271
|
+
"kit.subscriber.customFieldValueUpdated": contract(
|
|
272
|
+
"subscriber.custom_field_value_updated",
|
|
273
|
+
),
|
|
274
|
+
"kit.subscriber.sequenceCompleted": contract("subscriber.sequence_completed"),
|
|
275
|
+
"kit.subscriber.subscribedToForm": contract("subscriber.subscribed_to_form"),
|
|
276
|
+
"kit.subscriber.tagAdded": contract("subscriber.tag_added"),
|
|
277
|
+
"kit.subscriber.tagRemoved": contract("subscriber.tag_removed"),
|
|
278
|
+
"kit.subscriber.unsubscribed": contract("subscriber.unsubscribed"),
|
|
279
|
+
"kit.tag.created": contract("tag.created"),
|
|
280
|
+
"kit.tag.deleted": contract("tag.deleted"),
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Builds a schema narrowed to one exact Kit webhook event.
|
|
285
|
+
*
|
|
286
|
+
* @param type Provider event type.
|
|
287
|
+
*/
|
|
288
|
+
export function kitSemanticEventSchema<TType extends KitWebhookEventType>(
|
|
289
|
+
type: TType,
|
|
290
|
+
): z.ZodType<KitEvent<TType>> {
|
|
291
|
+
const schema = z
|
|
292
|
+
.looseObject({
|
|
293
|
+
created: z.iso.datetime({ offset: true }),
|
|
294
|
+
data: KIT_EVENT_DATA_SCHEMAS[type],
|
|
295
|
+
id: z.uuid(),
|
|
296
|
+
type: z.literal(type),
|
|
297
|
+
})
|
|
298
|
+
.catchall(encodableSchema)
|
|
299
|
+
return z.custom<KitEvent<TType>>((value) => schema.safeParse(value).success)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Returns the broad and exact platform types for one Kit event.
|
|
304
|
+
*
|
|
305
|
+
* @param type Provider event type.
|
|
306
|
+
*/
|
|
307
|
+
export function getKitEventTypes(type: KitWebhookEventType) {
|
|
308
|
+
return ["kit.event", KIT_EVENT_TYPE_MAP[type]] as const
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Builds one semantic trigger contract.
|
|
313
|
+
*
|
|
314
|
+
* @param type Provider event type.
|
|
315
|
+
*/
|
|
316
|
+
function contract<TType extends KitWebhookEventType>(type: TType) {
|
|
317
|
+
return {
|
|
318
|
+
configSchema: KIT_TRIGGER_CONFIG_SCHEMA,
|
|
319
|
+
eventSchema: kitSemanticEventSchema(type),
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Narrows a provider string to a supported Kit event type.
|
|
325
|
+
*
|
|
326
|
+
* @param value Candidate event type.
|
|
327
|
+
*/
|
|
328
|
+
function isKitWebhookEventType(value: string): value is KitWebhookEventType {
|
|
329
|
+
return (KIT_WEBHOOK_EVENT_TYPES as readonly string[]).includes(value)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Converts webhook keys to public camelCase while preserving field names.
|
|
334
|
+
*
|
|
335
|
+
* @param value Provider webhook value.
|
|
336
|
+
* @param parentKey Parent provider key.
|
|
337
|
+
*/
|
|
338
|
+
function camelizeKitWebhookValue(value: unknown, parentKey?: string): unknown {
|
|
339
|
+
if (Array.isArray(value)) {
|
|
340
|
+
return value.map((item) => camelizeKitWebhookValue(item))
|
|
341
|
+
}
|
|
342
|
+
if (typeof value !== "object" || value === null) return value
|
|
343
|
+
if (parentKey === "fields") return value
|
|
344
|
+
return Object.fromEntries(
|
|
345
|
+
Object.entries(value).map(([key, item]) => [
|
|
346
|
+
key.replace(/_([a-z\d])/g, (_match, letter: string) =>
|
|
347
|
+
letter.toUpperCase(),
|
|
348
|
+
),
|
|
349
|
+
camelizeKitWebhookValue(item, key),
|
|
350
|
+
]),
|
|
351
|
+
)
|
|
352
|
+
}
|