@automate.ax/integration-contracts 0.98.0 → 0.99.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.
@@ -12,107 +12,164 @@ export const RESEND_EMAIL_EVENT_TYPES = [
12
12
  "email.sent",
13
13
  "email.suppressed",
14
14
  ];
15
+ export const RESEND_CONTACT_EVENT_TYPES = [
16
+ "contact.created",
17
+ "contact.updated",
18
+ "contact.deleted",
19
+ ];
20
+ export const RESEND_DOMAIN_EVENT_TYPES = [
21
+ "domain.created",
22
+ "domain.updated",
23
+ "domain.deleted",
24
+ ];
25
+ export const RESEND_SUPPRESSION_EVENT_TYPES = [
26
+ "suppression.added",
27
+ "suppression.removed",
28
+ ];
29
+ /** Every webhook event currently supported by Resend. */
30
+ export const RESEND_EVENT_TYPES = [
31
+ ...RESEND_EMAIL_EVENT_TYPES,
32
+ ...RESEND_CONTACT_EVENT_TYPES,
33
+ ...RESEND_DOMAIN_EVENT_TYPES,
34
+ ...RESEND_SUPPRESSION_EVENT_TYPES,
35
+ ];
15
36
  const RESEND_EMAIL_DATA_SCHEMA = z.object({
16
- /** Stable broadcast campaign ID, when the email came from a broadcast. */
17
37
  broadcastId: z.string().optional(),
18
- /** When Resend created the email. */
19
38
  createdAt: z.iso.datetime({ offset: true }),
20
- /** Stable Resend email ID. */
21
39
  emailId: z.string(),
22
- /** Sender address, optionally including a display name. */
23
40
  from: z.string(),
24
- /** RFC Message-ID header value. */
25
- messageId: z.string().optional(),
26
- /** Email subject. */
41
+ headers: z.object({ name: z.string(), value: z.string() }).array().optional(),
42
+ messageId: z.string(),
27
43
  subject: z.string(),
28
- /** Tags associated with the email. */
29
44
  tags: z.record(z.string(), z.string()).optional(),
30
- /** Stable template ID, when the email used a template. */
31
45
  templateId: z.string().optional(),
32
- /** Recipient addresses affected by this event. */
33
46
  to: z.string().array(),
34
47
  });
35
48
  const RESEND_BOUNCE_SCHEMA = z
36
49
  .looseObject({
37
- /** SMTP diagnostic responses returned by the receiving server. */
38
50
  diagnosticCode: z.string().array().optional(),
39
- /** Detailed bounce message returned by the receiving server. */
40
51
  message: z.string(),
41
- /** Provider bounce subtype. */
42
52
  subType: z.string(),
43
- /** Provider bounce type. */
44
53
  type: z.string(),
45
54
  })
46
55
  .catchall(z.json());
47
56
  const RESEND_CLICK_SCHEMA = z
48
57
  .looseObject({
49
- /** IP address that requested the tracked link. */
50
58
  ipAddress: z.string(),
51
- /** URL requested through the tracked link. */
52
59
  link: z.string(),
53
- /** When the tracked link was requested. */
54
60
  timestamp: z.iso.datetime({ offset: true }),
55
- /** User agent that requested the tracked link. */
56
61
  userAgent: z.string(),
57
62
  })
58
63
  .catchall(z.json());
59
64
  const RESEND_FAILED_SCHEMA = z
60
- .looseObject({
61
- /** Provider reason for the send failure. */
62
- reason: z.string(),
63
- })
65
+ .looseObject({ reason: z.string() })
64
66
  .catchall(z.json());
65
- const RESEND_SUPPRESSED_SCHEMA = z
67
+ const RESEND_EMAIL_SUPPRESSED_SCHEMA = z
66
68
  .looseObject({
67
- /** Explanation of why Resend suppressed the email. */
69
+ diagnosticCode: z.string().array().optional(),
68
70
  message: z.string(),
69
- /** Provider suppression type. */
71
+ reason: z.string().optional(),
70
72
  type: z.string(),
71
73
  })
72
74
  .catchall(z.json());
73
75
  const RESEND_RECEIVED_EMAIL_ATTACHMENT_SCHEMA = z
74
76
  .looseObject({
75
- /** MIME content disposition, when supplied. */
76
77
  contentDisposition: z.string().nullable(),
77
- /** Content-ID header, when supplied. */
78
78
  contentId: z.string().nullable(),
79
- /** Attachment MIME type. */
80
79
  contentType: z.string(),
81
- /** Attachment filename, when supplied. */
82
80
  filename: z.string().nullable(),
83
- /** Stable Resend attachment ID. */
84
81
  id: z.string(),
85
82
  })
86
83
  .catchall(z.json());
87
84
  const RESEND_RECEIVED_EMAIL_DATA_SCHEMA = z.object({
88
- /** Metadata for attachments included with the inbound email. */
89
85
  attachments: RESEND_RECEIVED_EMAIL_ATTACHMENT_SCHEMA.array(),
90
- /** Blind-copy recipient addresses. */
91
86
  bcc: z.string().array(),
92
- /** Copy recipient addresses. */
93
87
  cc: z.string().array(),
94
- /** When Resend created the inbound email record. */
95
88
  createdAt: z.iso.datetime({ offset: true }),
96
- /** Stable Resend email ID. */
97
89
  emailId: z.string(),
98
- /** Bare sender address. */
99
90
  from: z.string(),
100
- /** RFC Message-ID header value. */
101
91
  messageId: z.string(),
102
- /** Addresses the email was forwarded for. */
103
92
  receivedFor: z.string().array().optional(),
104
- /** Email subject. */
105
93
  subject: z.string(),
106
- /** Direct recipient addresses. */
107
94
  to: z.string().array(),
108
95
  });
96
+ const RESEND_CONTACT_DATA_SCHEMA = z.object({
97
+ audienceId: z.string().optional(),
98
+ createdAt: z.iso.datetime({ offset: true }),
99
+ email: z.email(),
100
+ firstName: z.string().nullable().optional(),
101
+ id: z.string(),
102
+ lastName: z.string().nullable().optional(),
103
+ segmentIds: z.string().array().optional(),
104
+ unsubscribed: z.boolean(),
105
+ updatedAt: z.iso.datetime({ offset: true }),
106
+ });
107
+ export const RESEND_DOMAIN_STATUSES = [
108
+ "verified",
109
+ "partially_verified",
110
+ "partially_failed",
111
+ "failed",
112
+ "pending",
113
+ "not_started",
114
+ ];
115
+ export const RESEND_DOMAIN_REGIONS = [
116
+ "us-east-1",
117
+ "eu-west-1",
118
+ "sa-east-1",
119
+ "ap-northeast-1",
120
+ ];
121
+ export const RESEND_DOMAIN_RECORD_STATUSES = [
122
+ "pending",
123
+ "verified",
124
+ "failed",
125
+ "temporary_failure",
126
+ "not_started",
127
+ ];
128
+ const RESEND_DOMAIN_CAPABILITIES_SCHEMA = z.object({
129
+ receiving: z.enum(["enabled", "disabled"]).optional(),
130
+ sending: z.enum(["enabled", "disabled"]).optional(),
131
+ });
132
+ const RESEND_DOMAIN_RECORD_SCHEMA = z.object({
133
+ name: z.string(),
134
+ priority: z.number().optional(),
135
+ record: z.enum(["SPF", "DKIM", "Receiving MX", "Tracking", "TrackingCAA"]),
136
+ status: z.enum(RESEND_DOMAIN_RECORD_STATUSES),
137
+ ttl: z.string(),
138
+ type: z.enum(["MX", "TXT", "CNAME", "CAA"]),
139
+ value: z.string(),
140
+ });
141
+ const RESEND_DOMAIN_DATA_SCHEMA = z.object({
142
+ capabilities: RESEND_DOMAIN_CAPABILITIES_SCHEMA.optional(),
143
+ createdAt: z.iso.datetime({ offset: true }),
144
+ id: z.string(),
145
+ name: z.string(),
146
+ records: RESEND_DOMAIN_RECORD_SCHEMA.array(),
147
+ region: z.enum(RESEND_DOMAIN_REGIONS),
148
+ status: z.enum(RESEND_DOMAIN_STATUSES),
149
+ });
150
+ export const RESEND_SUPPRESSION_ORIGINS = [
151
+ "bounce",
152
+ "complaint",
153
+ "manual",
154
+ ];
155
+ const RESEND_SUPPRESSION_DATA_SCHEMA = z.object({
156
+ createdAt: z.iso.datetime({ offset: true }),
157
+ email: z.email(),
158
+ id: z.string(),
159
+ origin: z.enum(RESEND_SUPPRESSION_ORIGINS),
160
+ sourceId: z.string().nullable(),
161
+ });
109
162
  const RESEND_PROVIDER_EMAIL_DATA_SCHEMA = z
110
163
  .looseObject({
111
164
  broadcast_id: z.string().optional(),
112
165
  created_at: z.iso.datetime({ offset: true }),
113
166
  email_id: z.string(),
114
167
  from: z.string(),
115
- message_id: z.string().optional(),
168
+ headers: z
169
+ .object({ name: z.string(), value: z.string() })
170
+ .array()
171
+ .optional(),
172
+ message_id: z.string(),
116
173
  subject: z.string(),
117
174
  tags: z.record(z.string(), z.string()).optional(),
118
175
  template_id: z.string().optional(),
@@ -142,55 +199,75 @@ const RESEND_PROVIDER_RECEIVED_EMAIL_DATA_SCHEMA = z
142
199
  to: z.string().array(),
143
200
  })
144
201
  .catchall(z.json());
145
- const RESEND_PROVIDER_EMAIL_EVENT_SCHEMA = z
202
+ const RESEND_PROVIDER_CONTACT_DATA_SCHEMA = z
146
203
  .looseObject({
204
+ audience_id: z.string().optional(),
147
205
  created_at: z.iso.datetime({ offset: true }),
148
- data: RESEND_PROVIDER_EMAIL_DATA_SCHEMA,
149
- type: z.enum(RESEND_EMAIL_EVENT_TYPES),
206
+ email: z.email(),
207
+ first_name: z.string().nullable().optional(),
208
+ id: z.string(),
209
+ last_name: z.string().nullable().optional(),
210
+ segment_ids: z.string().array().optional(),
211
+ unsubscribed: z.boolean(),
212
+ updated_at: z.iso.datetime({ offset: true }),
150
213
  })
151
214
  .catchall(z.json());
152
- const RESEND_PROVIDER_EMAIL_SENT_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({ type: z.literal("email.sent") });
153
- const RESEND_PROVIDER_EMAIL_DELIVERED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
154
- type: z.literal("email.delivered"),
155
- });
156
- const RESEND_PROVIDER_EMAIL_BOUNCED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
157
- data: RESEND_PROVIDER_EMAIL_DATA_SCHEMA.extend({
158
- bounce: RESEND_BOUNCE_SCHEMA,
159
- }),
160
- type: z.literal("email.bounced"),
161
- });
162
- const RESEND_PROVIDER_EMAIL_FAILED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
163
- data: RESEND_PROVIDER_EMAIL_DATA_SCHEMA.extend({
164
- failed: RESEND_FAILED_SCHEMA,
165
- }),
166
- type: z.literal("email.failed"),
167
- });
168
- const RESEND_PROVIDER_EMAIL_OPENED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({ type: z.literal("email.opened") });
169
- const RESEND_PROVIDER_EMAIL_CLICKED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
170
- data: RESEND_PROVIDER_EMAIL_DATA_SCHEMA.extend({
171
- click: RESEND_CLICK_SCHEMA,
172
- }),
173
- type: z.literal("email.clicked"),
174
- });
175
- const RESEND_PROVIDER_EMAIL_COMPLAINED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
176
- type: z.literal("email.complained"),
177
- });
178
- const RESEND_PROVIDER_EMAIL_RECEIVED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
179
- data: RESEND_PROVIDER_RECEIVED_EMAIL_DATA_SCHEMA,
180
- type: z.literal("email.received"),
181
- });
182
- const RESEND_PROVIDER_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
183
- type: z.literal("email.delivery_delayed"),
184
- });
185
- const RESEND_PROVIDER_EMAIL_SCHEDULED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
186
- type: z.literal("email.scheduled"),
187
- });
188
- const RESEND_PROVIDER_EMAIL_SUPPRESSED_EVENT_SCHEMA = RESEND_PROVIDER_EMAIL_EVENT_SCHEMA.extend({
189
- data: RESEND_PROVIDER_EMAIL_DATA_SCHEMA.extend({
190
- suppressed: RESEND_SUPPRESSED_SCHEMA,
191
- }),
192
- type: z.literal("email.suppressed"),
193
- });
215
+ const RESEND_PROVIDER_DOMAIN_DATA_SCHEMA = z
216
+ .looseObject({
217
+ capabilities: RESEND_DOMAIN_CAPABILITIES_SCHEMA.optional(),
218
+ created_at: z.iso.datetime({ offset: true }),
219
+ id: z.string(),
220
+ name: z.string(),
221
+ records: RESEND_DOMAIN_RECORD_SCHEMA.array(),
222
+ region: z.enum(RESEND_DOMAIN_REGIONS),
223
+ status: z.enum(RESEND_DOMAIN_STATUSES),
224
+ })
225
+ .catchall(z.json());
226
+ const RESEND_PROVIDER_SUPPRESSION_DATA_SCHEMA = z
227
+ .looseObject({
228
+ created_at: z.iso.datetime({ offset: true }),
229
+ email: z.email(),
230
+ id: z.string(),
231
+ origin: z.enum(RESEND_SUPPRESSION_ORIGINS),
232
+ source_id: z.string().nullable(),
233
+ })
234
+ .catchall(z.json());
235
+ /**
236
+ * Creates one provider webhook envelope schema.
237
+ *
238
+ * @param type - Exact Resend event type.
239
+ * @param data - Provider event data schema.
240
+ */
241
+ function providerEventSchema(type, data) {
242
+ return z
243
+ .looseObject({
244
+ created_at: z.iso.datetime({ offset: true }),
245
+ data,
246
+ type: z.literal(type),
247
+ })
248
+ .catchall(z.json());
249
+ }
250
+ const RESEND_PROVIDER_EMAIL_SENT_EVENT_SCHEMA = providerEventSchema("email.sent", RESEND_PROVIDER_EMAIL_DATA_SCHEMA);
251
+ const RESEND_PROVIDER_EMAIL_SCHEDULED_EVENT_SCHEMA = providerEventSchema("email.scheduled", RESEND_PROVIDER_EMAIL_DATA_SCHEMA);
252
+ const RESEND_PROVIDER_EMAIL_DELIVERED_EVENT_SCHEMA = providerEventSchema("email.delivered", RESEND_PROVIDER_EMAIL_DATA_SCHEMA);
253
+ const RESEND_PROVIDER_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA = providerEventSchema("email.delivery_delayed", RESEND_PROVIDER_EMAIL_DATA_SCHEMA);
254
+ const RESEND_PROVIDER_EMAIL_COMPLAINED_EVENT_SCHEMA = providerEventSchema("email.complained", RESEND_PROVIDER_EMAIL_DATA_SCHEMA);
255
+ const RESEND_PROVIDER_EMAIL_BOUNCED_EVENT_SCHEMA = providerEventSchema("email.bounced", RESEND_PROVIDER_EMAIL_DATA_SCHEMA.extend({ bounce: RESEND_BOUNCE_SCHEMA }));
256
+ const RESEND_PROVIDER_EMAIL_OPENED_EVENT_SCHEMA = providerEventSchema("email.opened", RESEND_PROVIDER_EMAIL_DATA_SCHEMA);
257
+ const RESEND_PROVIDER_EMAIL_CLICKED_EVENT_SCHEMA = providerEventSchema("email.clicked", RESEND_PROVIDER_EMAIL_DATA_SCHEMA.extend({ click: RESEND_CLICK_SCHEMA }));
258
+ const RESEND_PROVIDER_EMAIL_RECEIVED_EVENT_SCHEMA = providerEventSchema("email.received", RESEND_PROVIDER_RECEIVED_EMAIL_DATA_SCHEMA);
259
+ const RESEND_PROVIDER_EMAIL_FAILED_EVENT_SCHEMA = providerEventSchema("email.failed", RESEND_PROVIDER_EMAIL_DATA_SCHEMA.extend({ failed: RESEND_FAILED_SCHEMA }));
260
+ const RESEND_PROVIDER_EMAIL_SUPPRESSED_EVENT_SCHEMA = providerEventSchema("email.suppressed", RESEND_PROVIDER_EMAIL_DATA_SCHEMA.extend({
261
+ suppressed: RESEND_EMAIL_SUPPRESSED_SCHEMA,
262
+ }));
263
+ const RESEND_PROVIDER_CONTACT_CREATED_EVENT_SCHEMA = providerEventSchema("contact.created", RESEND_PROVIDER_CONTACT_DATA_SCHEMA);
264
+ const RESEND_PROVIDER_CONTACT_UPDATED_EVENT_SCHEMA = providerEventSchema("contact.updated", RESEND_PROVIDER_CONTACT_DATA_SCHEMA);
265
+ const RESEND_PROVIDER_CONTACT_DELETED_EVENT_SCHEMA = providerEventSchema("contact.deleted", RESEND_PROVIDER_CONTACT_DATA_SCHEMA);
266
+ const RESEND_PROVIDER_DOMAIN_CREATED_EVENT_SCHEMA = providerEventSchema("domain.created", RESEND_PROVIDER_DOMAIN_DATA_SCHEMA);
267
+ const RESEND_PROVIDER_DOMAIN_UPDATED_EVENT_SCHEMA = providerEventSchema("domain.updated", RESEND_PROVIDER_DOMAIN_DATA_SCHEMA);
268
+ const RESEND_PROVIDER_DOMAIN_DELETED_EVENT_SCHEMA = providerEventSchema("domain.deleted", RESEND_PROVIDER_DOMAIN_DATA_SCHEMA);
269
+ const RESEND_PROVIDER_SUPPRESSION_ADDED_EVENT_SCHEMA = providerEventSchema("suppression.added", RESEND_PROVIDER_SUPPRESSION_DATA_SCHEMA);
270
+ const RESEND_PROVIDER_SUPPRESSION_REMOVED_EVENT_SCHEMA = providerEventSchema("suppression.removed", RESEND_PROVIDER_SUPPRESSION_DATA_SCHEMA);
194
271
  const RESEND_PROVIDER_WEBHOOK_SCHEMA = z.discriminatedUnion("type", [
195
272
  RESEND_PROVIDER_EMAIL_BOUNCED_EVENT_SCHEMA,
196
273
  RESEND_PROVIDER_EMAIL_CLICKED_EVENT_SCHEMA,
@@ -203,59 +280,36 @@ const RESEND_PROVIDER_WEBHOOK_SCHEMA = z.discriminatedUnion("type", [
203
280
  RESEND_PROVIDER_EMAIL_SCHEDULED_EVENT_SCHEMA,
204
281
  RESEND_PROVIDER_EMAIL_SENT_EVENT_SCHEMA,
205
282
  RESEND_PROVIDER_EMAIL_SUPPRESSED_EVENT_SCHEMA,
283
+ RESEND_PROVIDER_CONTACT_CREATED_EVENT_SCHEMA,
284
+ RESEND_PROVIDER_CONTACT_UPDATED_EVENT_SCHEMA,
285
+ RESEND_PROVIDER_CONTACT_DELETED_EVENT_SCHEMA,
286
+ RESEND_PROVIDER_DOMAIN_CREATED_EVENT_SCHEMA,
287
+ RESEND_PROVIDER_DOMAIN_UPDATED_EVENT_SCHEMA,
288
+ RESEND_PROVIDER_DOMAIN_DELETED_EVENT_SCHEMA,
289
+ RESEND_PROVIDER_SUPPRESSION_ADDED_EVENT_SCHEMA,
290
+ RESEND_PROVIDER_SUPPRESSION_REMOVED_EVENT_SCHEMA,
206
291
  ]);
207
- export const RESEND_EMAIL_SENT_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
208
- /** Original provider webhook envelope. */
209
- event: RESEND_PROVIDER_EMAIL_SENT_EVENT_SCHEMA,
210
- });
211
- export const RESEND_EMAIL_DELIVERED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
212
- /** Original provider webhook envelope. */
213
- event: RESEND_PROVIDER_EMAIL_DELIVERED_EVENT_SCHEMA,
214
- });
215
- export const RESEND_EMAIL_BOUNCED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
216
- /** Bounce details from the receiving server. */
217
- bounce: RESEND_BOUNCE_SCHEMA,
218
- /** Original provider webhook envelope. */
219
- event: RESEND_PROVIDER_EMAIL_BOUNCED_EVENT_SCHEMA,
220
- });
221
- export const RESEND_EMAIL_FAILED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
222
- /** Original provider webhook envelope. */
223
- event: RESEND_PROVIDER_EMAIL_FAILED_EVENT_SCHEMA,
224
- /** Send failure details. */
225
- failed: RESEND_FAILED_SCHEMA,
226
- });
227
- export const RESEND_EMAIL_OPENED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
228
- /** Original provider webhook envelope. */
229
- event: RESEND_PROVIDER_EMAIL_OPENED_EVENT_SCHEMA,
230
- });
231
- export const RESEND_EMAIL_CLICKED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
232
- /** Click tracking details. */
233
- click: RESEND_CLICK_SCHEMA,
234
- /** Original provider webhook envelope. */
235
- event: RESEND_PROVIDER_EMAIL_CLICKED_EVENT_SCHEMA,
236
- });
237
- export const RESEND_EMAIL_COMPLAINED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
238
- /** Original provider webhook envelope. */
239
- event: RESEND_PROVIDER_EMAIL_COMPLAINED_EVENT_SCHEMA,
240
- });
292
+ /**
293
+ * Attaches one provider event envelope to normalized email data.
294
+ *
295
+ * @param event - Exact provider email-event schema.
296
+ */
297
+ function emailEventSchema(event) {
298
+ return RESEND_EMAIL_DATA_SCHEMA.extend({ event });
299
+ }
300
+ export const RESEND_EMAIL_SENT_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_SENT_EVENT_SCHEMA);
301
+ export const RESEND_EMAIL_SCHEDULED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_SCHEDULED_EVENT_SCHEMA);
302
+ export const RESEND_EMAIL_DELIVERED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_DELIVERED_EVENT_SCHEMA);
303
+ export const RESEND_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA);
304
+ export const RESEND_EMAIL_COMPLAINED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_COMPLAINED_EVENT_SCHEMA);
305
+ export const RESEND_EMAIL_BOUNCED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_BOUNCED_EVENT_SCHEMA).extend({ bounce: RESEND_BOUNCE_SCHEMA });
306
+ export const RESEND_EMAIL_OPENED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_OPENED_EVENT_SCHEMA);
307
+ export const RESEND_EMAIL_CLICKED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_CLICKED_EVENT_SCHEMA).extend({ click: RESEND_CLICK_SCHEMA });
241
308
  export const RESEND_EMAIL_RECEIVED_EVENT_SCHEMA = RESEND_RECEIVED_EMAIL_DATA_SCHEMA.extend({
242
- /** Original provider webhook envelope. */
243
309
  event: RESEND_PROVIDER_EMAIL_RECEIVED_EVENT_SCHEMA,
244
310
  });
245
- export const RESEND_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
246
- /** Original provider webhook envelope. */
247
- event: RESEND_PROVIDER_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA,
248
- });
249
- export const RESEND_EMAIL_SCHEDULED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
250
- /** Original provider webhook envelope. */
251
- event: RESEND_PROVIDER_EMAIL_SCHEDULED_EVENT_SCHEMA,
252
- });
253
- export const RESEND_EMAIL_SUPPRESSED_EVENT_SCHEMA = RESEND_EMAIL_DATA_SCHEMA.extend({
254
- /** Original provider webhook envelope. */
255
- event: RESEND_PROVIDER_EMAIL_SUPPRESSED_EVENT_SCHEMA,
256
- /** Details explaining why Resend suppressed the email. */
257
- suppressed: RESEND_SUPPRESSED_SCHEMA,
258
- });
311
+ export const RESEND_EMAIL_FAILED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_FAILED_EVENT_SCHEMA).extend({ failed: RESEND_FAILED_SCHEMA });
312
+ export const RESEND_EMAIL_SUPPRESSED_EVENT_SCHEMA = emailEventSchema(RESEND_PROVIDER_EMAIL_SUPPRESSED_EVENT_SCHEMA).extend({ suppressed: RESEND_EMAIL_SUPPRESSED_SCHEMA });
259
313
  export const RESEND_EMAIL_EVENT_SCHEMA = z.union([
260
314
  RESEND_EMAIL_BOUNCED_EVENT_SCHEMA,
261
315
  RESEND_EMAIL_CLICKED_EVENT_SCHEMA,
@@ -269,13 +323,80 @@ export const RESEND_EMAIL_EVENT_SCHEMA = z.union([
269
323
  RESEND_EMAIL_SENT_EVENT_SCHEMA,
270
324
  RESEND_EMAIL_SUPPRESSED_EVENT_SCHEMA,
271
325
  ]);
326
+ /**
327
+ * Attaches one provider event envelope to normalized contact data.
328
+ *
329
+ * @param event - Exact provider contact-event schema.
330
+ */
331
+ function contactEventSchema(event) {
332
+ return RESEND_CONTACT_DATA_SCHEMA.extend({ event });
333
+ }
334
+ export const RESEND_CONTACT_CREATED_EVENT_SCHEMA = contactEventSchema(RESEND_PROVIDER_CONTACT_CREATED_EVENT_SCHEMA);
335
+ export const RESEND_CONTACT_UPDATED_EVENT_SCHEMA = contactEventSchema(RESEND_PROVIDER_CONTACT_UPDATED_EVENT_SCHEMA);
336
+ export const RESEND_CONTACT_DELETED_EVENT_SCHEMA = contactEventSchema(RESEND_PROVIDER_CONTACT_DELETED_EVENT_SCHEMA);
337
+ export const RESEND_CONTACT_EVENT_SCHEMA = z.union([
338
+ RESEND_CONTACT_CREATED_EVENT_SCHEMA,
339
+ RESEND_CONTACT_UPDATED_EVENT_SCHEMA,
340
+ RESEND_CONTACT_DELETED_EVENT_SCHEMA,
341
+ ]);
342
+ /**
343
+ * Attaches one provider event envelope to normalized domain data.
344
+ *
345
+ * @param event - Exact provider domain-event schema.
346
+ */
347
+ function domainEventSchema(event) {
348
+ return RESEND_DOMAIN_DATA_SCHEMA.extend({ event });
349
+ }
350
+ export const RESEND_DOMAIN_CREATED_EVENT_SCHEMA = domainEventSchema(RESEND_PROVIDER_DOMAIN_CREATED_EVENT_SCHEMA);
351
+ export const RESEND_DOMAIN_UPDATED_EVENT_SCHEMA = domainEventSchema(RESEND_PROVIDER_DOMAIN_UPDATED_EVENT_SCHEMA);
352
+ export const RESEND_DOMAIN_DELETED_EVENT_SCHEMA = domainEventSchema(RESEND_PROVIDER_DOMAIN_DELETED_EVENT_SCHEMA);
353
+ export const RESEND_DOMAIN_EVENT_SCHEMA = z.union([
354
+ RESEND_DOMAIN_CREATED_EVENT_SCHEMA,
355
+ RESEND_DOMAIN_UPDATED_EVENT_SCHEMA,
356
+ RESEND_DOMAIN_DELETED_EVENT_SCHEMA,
357
+ ]);
358
+ /**
359
+ * Attaches one provider event envelope to normalized suppression data.
360
+ *
361
+ * @param event - Exact provider suppression-event schema.
362
+ */
363
+ function suppressionEventSchema(event) {
364
+ return RESEND_SUPPRESSION_DATA_SCHEMA.extend({ event });
365
+ }
366
+ export const RESEND_SUPPRESSION_ADDED_EVENT_SCHEMA = suppressionEventSchema(RESEND_PROVIDER_SUPPRESSION_ADDED_EVENT_SCHEMA);
367
+ export const RESEND_SUPPRESSION_REMOVED_EVENT_SCHEMA = suppressionEventSchema(RESEND_PROVIDER_SUPPRESSION_REMOVED_EVENT_SCHEMA);
368
+ export const RESEND_SUPPRESSION_EVENT_SCHEMA = z.union([
369
+ RESEND_SUPPRESSION_ADDED_EVENT_SCHEMA,
370
+ RESEND_SUPPRESSION_REMOVED_EVENT_SCHEMA,
371
+ ]);
372
+ export const RESEND_EVENT_SCHEMA = z.union([
373
+ RESEND_EMAIL_EVENT_SCHEMA,
374
+ RESEND_CONTACT_EVENT_SCHEMA,
375
+ RESEND_DOMAIN_EVENT_SCHEMA,
376
+ RESEND_SUPPRESSION_EVENT_SCHEMA,
377
+ ]);
378
+ /**
379
+ * Normalizes one authenticated Resend webhook.
380
+ *
381
+ * @param value - Untrusted provider webhook payload.
382
+ */
383
+ export function normalizeResendEvent(value) {
384
+ return normalizeProviderEvent(RESEND_PROVIDER_WEBHOOK_SCHEMA.parse(value));
385
+ }
272
386
  /**
273
387
  * Normalizes one authenticated Resend email webhook.
274
388
  *
275
389
  * @param value - Untrusted provider webhook payload.
276
390
  */
277
391
  export function normalizeResendEmailEvent(value) {
278
- const event = RESEND_PROVIDER_WEBHOOK_SCHEMA.parse(value);
392
+ return RESEND_EMAIL_EVENT_SCHEMA.parse(normalizeResendEvent(value));
393
+ }
394
+ /**
395
+ * Normalizes one validated provider event by its exact type.
396
+ *
397
+ * @param event - Validated Resend provider event.
398
+ */
399
+ function normalizeProviderEvent(event) {
279
400
  switch (event.type) {
280
401
  case "email.bounced":
281
402
  return RESEND_EMAIL_BOUNCED_EVENT_SCHEMA.parse({
@@ -324,41 +445,41 @@ export function normalizeResendEmailEvent(value) {
324
445
  suppressed: event.data.suppressed,
325
446
  });
326
447
  case "email.complained":
327
- return RESEND_EMAIL_COMPLAINED_EVENT_SCHEMA.parse({
328
- ...normalizeResendEmailData(event.data),
329
- event,
330
- });
331
448
  case "email.delivered":
332
- return RESEND_EMAIL_DELIVERED_EVENT_SCHEMA.parse({
333
- ...normalizeResendEmailData(event.data),
334
- event,
335
- });
336
449
  case "email.delivery_delayed":
337
- return RESEND_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA.parse({
338
- ...normalizeResendEmailData(event.data),
339
- event,
340
- });
341
450
  case "email.opened":
342
- return RESEND_EMAIL_OPENED_EVENT_SCHEMA.parse({
343
- ...normalizeResendEmailData(event.data),
344
- event,
345
- });
346
451
  case "email.scheduled":
347
- return RESEND_EMAIL_SCHEDULED_EVENT_SCHEMA.parse({
348
- ...normalizeResendEmailData(event.data),
349
- event,
350
- });
351
452
  case "email.sent":
352
- return RESEND_EMAIL_SENT_EVENT_SCHEMA.parse({
453
+ return {
353
454
  ...normalizeResendEmailData(event.data),
354
455
  event,
355
- });
456
+ };
457
+ case "contact.created":
458
+ case "contact.updated":
459
+ case "contact.deleted":
460
+ return {
461
+ ...normalizeResendContactData(event.data),
462
+ event,
463
+ };
464
+ case "domain.created":
465
+ case "domain.updated":
466
+ case "domain.deleted":
467
+ return {
468
+ ...normalizeResendDomainData(event.data),
469
+ event,
470
+ };
471
+ case "suppression.added":
472
+ case "suppression.removed":
473
+ return {
474
+ ...normalizeResendSuppressionData(event.data),
475
+ event,
476
+ };
356
477
  }
357
478
  }
358
479
  /**
359
- * Normalizes common outbound email webhook data.
480
+ * Normalizes shared Resend email event fields.
360
481
  *
361
- * @param data - Provider-native email data.
482
+ * @param data - Provider email event data.
362
483
  */
363
484
  function normalizeResendEmailData(data) {
364
485
  return {
@@ -368,10 +489,61 @@ function normalizeResendEmailData(data) {
368
489
  createdAt: data.created_at,
369
490
  emailId: data.email_id,
370
491
  from: data.from,
371
- ...(data.message_id === undefined ? {} : { messageId: data.message_id }),
492
+ ...(data.headers === undefined ? {} : { headers: data.headers }),
493
+ messageId: data.message_id,
372
494
  subject: data.subject,
373
495
  ...(data.tags === undefined ? {} : { tags: data.tags }),
374
496
  ...(data.template_id === undefined ? {} : { templateId: data.template_id }),
375
497
  to: data.to,
376
498
  };
377
499
  }
500
+ /**
501
+ * Normalizes shared Resend contact event fields.
502
+ *
503
+ * @param data - Provider contact event data.
504
+ */
505
+ function normalizeResendContactData(data) {
506
+ return {
507
+ ...(data.audience_id === undefined ? {} : { audienceId: data.audience_id }),
508
+ createdAt: data.created_at,
509
+ email: data.email,
510
+ ...(data.first_name === undefined ? {} : { firstName: data.first_name }),
511
+ id: data.id,
512
+ ...(data.last_name === undefined ? {} : { lastName: data.last_name }),
513
+ ...(data.segment_ids === undefined ? {} : { segmentIds: data.segment_ids }),
514
+ unsubscribed: data.unsubscribed,
515
+ updatedAt: data.updated_at,
516
+ };
517
+ }
518
+ /**
519
+ * Normalizes shared Resend domain event fields.
520
+ *
521
+ * @param data - Provider domain event data.
522
+ */
523
+ function normalizeResendDomainData(data) {
524
+ return {
525
+ ...(data.capabilities === undefined
526
+ ? {}
527
+ : { capabilities: data.capabilities }),
528
+ createdAt: data.created_at,
529
+ id: data.id,
530
+ name: data.name,
531
+ records: data.records,
532
+ region: data.region,
533
+ status: data.status,
534
+ };
535
+ }
536
+ /**
537
+ * Normalizes shared Resend suppression event fields.
538
+ *
539
+ * @param data - Provider suppression event data.
540
+ */
541
+ function normalizeResendSuppressionData(data) {
542
+ return {
543
+ createdAt: data.created_at,
544
+ email: data.email,
545
+ id: data.id,
546
+ origin: data.origin,
547
+ sourceId: data.source_id,
548
+ };
549
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automate.ax/integration-contracts",
3
- "version": "0.98.0",
3
+ "version": "0.99.0",
4
4
  "description": "Shared integration payload contracts and provider primitives for Automate.ax.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -48,7 +48,7 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@automate.ax/codec": "0.98.0",
51
+ "@automate.ax/codec": "0.99.0",
52
52
  "@cfworker/json-schema": "^4.1.1",
53
53
  "@googleapis/calendar": "^15.0.0",
54
54
  "@googleapis/forms": "^6.0.1",