@automate.ax/integration-contracts 0.55.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.
Files changed (136) hide show
  1. package/dist/airtable/api.d.ts +19 -0
  2. package/dist/airtable/api.js +44 -0
  3. package/dist/airtable/index.d.ts +353 -0
  4. package/dist/airtable/index.js +32 -0
  5. package/dist/airtable/schemas.d.ts +716 -0
  6. package/dist/airtable/schemas.js +184 -0
  7. package/dist/asana/api.d.ts +70 -0
  8. package/dist/asana/api.js +119 -0
  9. package/dist/asana/index.d.ts +384 -0
  10. package/dist/asana/index.js +38 -0
  11. package/dist/asana/schemas.d.ts +1060 -0
  12. package/dist/asana/schemas.js +512 -0
  13. package/dist/brevo/api.d.ts +31 -0
  14. package/dist/brevo/api.js +64 -0
  15. package/dist/brevo/index.d.ts +822 -0
  16. package/dist/brevo/index.js +51 -0
  17. package/dist/brevo/schemas.d.ts +1217 -0
  18. package/dist/brevo/schemas.js +332 -0
  19. package/dist/github/index.d.ts +37 -0
  20. package/dist/github/index.js +106 -0
  21. package/dist/github/schemas.d.ts +8014 -0
  22. package/dist/github/schemas.js +113 -0
  23. package/dist/gmail/gmail.d.ts +172 -0
  24. package/dist/gmail/gmail.js +405 -0
  25. package/dist/gmail/index.d.ts +262 -0
  26. package/dist/gmail/index.js +23 -0
  27. package/dist/gmail/schemas.d.ts +444 -0
  28. package/dist/gmail/schemas.js +242 -0
  29. package/dist/google-calendar/event-schemas.d.ts +117 -0
  30. package/dist/google-calendar/event-schemas.js +13 -0
  31. package/dist/google-calendar/google-calendar.d.ts +147 -0
  32. package/dist/google-calendar/google-calendar.js +583 -0
  33. package/dist/google-calendar/index.d.ts +365 -0
  34. package/dist/google-calendar/index.js +24 -0
  35. package/dist/google-calendar/schemas.d.ts +592 -0
  36. package/dist/google-calendar/schemas.js +379 -0
  37. package/dist/google-forms/event-schemas.d.ts +105 -0
  38. package/dist/google-forms/event-schemas.js +20 -0
  39. package/dist/google-forms/google-forms.d.ts +243 -0
  40. package/dist/google-forms/google-forms.js +581 -0
  41. package/dist/google-forms/index.d.ts +141 -0
  42. package/dist/google-forms/index.js +20 -0
  43. package/dist/google-forms/schemas.d.ts +618 -0
  44. package/dist/google-forms/schemas.js +383 -0
  45. package/dist/linear/api.d.ts +63 -0
  46. package/dist/linear/api.js +88 -0
  47. package/dist/linear/index.d.ts +1338 -0
  48. package/dist/linear/index.js +55 -0
  49. package/dist/linear/schemas.d.ts +1795 -0
  50. package/dist/linear/schemas.js +760 -0
  51. package/dist/outlook/graph.d.ts +34 -0
  52. package/dist/outlook/graph.js +98 -0
  53. package/dist/outlook/index.d.ts +115 -0
  54. package/dist/outlook/index.js +11 -0
  55. package/dist/outlook/schemas.d.ts +529 -0
  56. package/dist/outlook/schemas.js +312 -0
  57. package/dist/resend/index.d.ts +707 -0
  58. package/dist/resend/index.js +54 -0
  59. package/dist/resend/schemas.d.ts +1033 -0
  60. package/dist/resend/schemas.js +377 -0
  61. package/dist/slack/index.d.ts +151 -0
  62. package/dist/slack/index.js +22 -0
  63. package/dist/slack/schemas.d.ts +641 -0
  64. package/dist/slack/schemas.js +581 -0
  65. package/dist/teams/graph.d.ts +33 -0
  66. package/dist/teams/graph.js +95 -0
  67. package/dist/teams/index.d.ts +164 -0
  68. package/dist/teams/index.js +21 -0
  69. package/dist/teams/schemas.d.ts +675 -0
  70. package/dist/teams/schemas.js +365 -0
  71. package/dist/trello/api.d.ts +69 -0
  72. package/dist/trello/api.js +140 -0
  73. package/dist/trello/event-schemas.d.ts +1101 -0
  74. package/dist/trello/event-schemas.js +233 -0
  75. package/dist/trello/index.d.ts +721 -0
  76. package/dist/trello/index.js +35 -0
  77. package/dist/trello/schemas.d.ts +283 -0
  78. package/dist/trello/schemas.js +401 -0
  79. package/dist/triggers.d.ts +26 -0
  80. package/dist/triggers.js +33 -0
  81. package/dist/vercel/index.d.ts +1065 -0
  82. package/dist/vercel/index.js +114 -0
  83. package/dist/vercel/schemas.d.ts +1518 -0
  84. package/dist/vercel/schemas.js +335 -0
  85. package/dist/whatsapp/api.d.ts +62 -0
  86. package/dist/whatsapp/api.js +121 -0
  87. package/dist/whatsapp/index.d.ts +614 -0
  88. package/dist/whatsapp/index.js +35 -0
  89. package/dist/whatsapp/schemas.d.ts +926 -0
  90. package/dist/whatsapp/schemas.js +326 -0
  91. package/package.json +169 -0
  92. package/src/airtable/api.ts +66 -0
  93. package/src/airtable/index.ts +41 -0
  94. package/src/airtable/schemas.ts +231 -0
  95. package/src/asana/api.ts +171 -0
  96. package/src/asana/index.ts +49 -0
  97. package/src/asana/schemas.ts +655 -0
  98. package/src/brevo/api.ts +89 -0
  99. package/src/brevo/index.ts +66 -0
  100. package/src/brevo/schemas.ts +449 -0
  101. package/src/github/index.ts +217 -0
  102. package/src/github/schemas.ts +435 -0
  103. package/src/gmail/gmail.ts +577 -0
  104. package/src/gmail/index.ts +26 -0
  105. package/src/gmail/schemas.ts +327 -0
  106. package/src/google-calendar/event-schemas.ts +16 -0
  107. package/src/google-calendar/google-calendar.ts +727 -0
  108. package/src/google-calendar/index.ts +27 -0
  109. package/src/google-calendar/schemas.ts +529 -0
  110. package/src/google-forms/event-schemas.ts +26 -0
  111. package/src/google-forms/google-forms.ts +683 -0
  112. package/src/google-forms/index.ts +23 -0
  113. package/src/google-forms/schemas.ts +499 -0
  114. package/src/linear/api.ts +141 -0
  115. package/src/linear/index.ts +71 -0
  116. package/src/linear/schemas.ts +1060 -0
  117. package/src/outlook/graph.ts +132 -0
  118. package/src/outlook/index.ts +14 -0
  119. package/src/outlook/schemas.ts +388 -0
  120. package/src/resend/index.ts +70 -0
  121. package/src/resend/schemas.ts +462 -0
  122. package/src/slack/index.ts +29 -0
  123. package/src/slack/schemas.ts +737 -0
  124. package/src/teams/graph.ts +130 -0
  125. package/src/teams/index.ts +27 -0
  126. package/src/teams/schemas.ts +463 -0
  127. package/src/trello/api.ts +190 -0
  128. package/src/trello/event-schemas.ts +290 -0
  129. package/src/trello/index.ts +45 -0
  130. package/src/trello/schemas.ts +507 -0
  131. package/src/triggers.ts +68 -0
  132. package/src/vercel/index.ts +147 -0
  133. package/src/vercel/schemas.ts +594 -0
  134. package/src/whatsapp/api.ts +171 -0
  135. package/src/whatsapp/index.ts +46 -0
  136. package/src/whatsapp/schemas.ts +341 -0
@@ -0,0 +1,132 @@
1
+ import { z } from "zod"
2
+
3
+ const GRAPH_BASE_URL = "https://graph.microsoft.com/v1.0/"
4
+ const MICROSOFT_SECRET_SCHEMA = z.object({
5
+ accessToken: z.string().min(1),
6
+ })
7
+ const GRAPH_ERROR_SCHEMA = z.looseObject({
8
+ error: z
9
+ .looseObject({
10
+ code: z.string().optional(),
11
+ message: z.string().optional(),
12
+ })
13
+ .optional(),
14
+ })
15
+
16
+ /** Options accepted by the authenticated Outlook Graph request helper. */
17
+ export interface OutlookGraphRequestOptions {
18
+ /** JSON-serializable request body. */
19
+ body?: unknown
20
+
21
+ /** Additional HTTP headers. */
22
+ headers?: RequestInit["headers"]
23
+
24
+ /** HTTP method. */
25
+ method?: string
26
+ }
27
+
28
+ /**
29
+ * Creates a small authenticated Microsoft Graph client for Outlook APIs.
30
+ *
31
+ * The raw `fetch` method is an escape hatch for provider features not yet
32
+ * represented by a built-in action. `request` parses JSON and reports Graph
33
+ * errors with their provider code and message.
34
+ *
35
+ * @param secret - Refreshed Microsoft OAuth integration secret.
36
+ */
37
+ export function getOutlookGraphApi(secret: Record<string, unknown>) {
38
+ const { accessToken } = MICROSOFT_SECRET_SCHEMA.parse(secret)
39
+
40
+ /**
41
+ * Performs one authenticated Graph request.
42
+ *
43
+ * @param path - Relative or absolute Microsoft Graph URL.
44
+ * @param init - Standard fetch request options.
45
+ */
46
+ async function graphFetch(path: string, init?: RequestInit) {
47
+ const headers = new Headers(init?.headers)
48
+ headers.set("Accept", "application/json")
49
+ headers.set("Authorization", `Bearer ${accessToken}`)
50
+ if (!headers.has("Prefer")) headers.set("Prefer", 'IdType="ImmutableId"')
51
+ return fetch(new URL(path.replace(/^\//, ""), GRAPH_BASE_URL), {
52
+ ...init,
53
+ headers,
54
+ })
55
+ }
56
+
57
+ /**
58
+ * Performs one authenticated Graph JSON request.
59
+ *
60
+ * @param path - Relative or absolute Microsoft Graph URL.
61
+ * @param options - HTTP method, body, and headers.
62
+ */
63
+ async function request(
64
+ path: string,
65
+ options: OutlookGraphRequestOptions = {},
66
+ ): Promise<unknown> {
67
+ const headers = new Headers(options.headers)
68
+ if (options.body !== undefined) {
69
+ headers.set("Content-Type", "application/json")
70
+ }
71
+ const response = await graphFetch(path, {
72
+ body:
73
+ options.body === undefined ? undefined : JSON.stringify(options.body),
74
+ headers,
75
+ method: options.method,
76
+ })
77
+
78
+ if (!response.ok) {
79
+ const payload = GRAPH_ERROR_SCHEMA.safeParse(
80
+ await response.json().catch(() => undefined),
81
+ )
82
+ const graphError = payload.success ? payload.data.error : undefined
83
+ const detail = [graphError?.code, graphError?.message]
84
+ .filter(Boolean)
85
+ .join(": ")
86
+ throw new Error(
87
+ `Microsoft Graph request failed with ${response.status} ${response.statusText}${detail ? `: ${detail}` : ""}.`,
88
+ )
89
+ }
90
+
91
+ if (response.status === 202 || response.status === 204) return undefined
92
+ return response.json()
93
+ }
94
+
95
+ return {
96
+ /** Performs an authenticated request and returns the raw Response. */
97
+ fetch: graphFetch,
98
+
99
+ /** Performs an authenticated request and returns its untrusted JSON value. */
100
+ request,
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Reads Graph collection pages until the requested limit is reached.
106
+ *
107
+ * @param request - Authenticated Graph JSON request function.
108
+ * @param path - Initial relative Graph path.
109
+ * @param itemSchema - Schema for one collection item.
110
+ * @param limit - Maximum total items.
111
+ */
112
+ export async function listOutlookGraphCollection<T>(
113
+ request: (path: string) => Promise<unknown>,
114
+ path: string,
115
+ itemSchema: z.ZodType<T>,
116
+ limit: number,
117
+ ) {
118
+ const pageSchema = z.object({
119
+ "@odata.nextLink": z.string().optional(),
120
+ value: itemSchema.array(),
121
+ })
122
+ const items: T[] = []
123
+ let nextPath: string | undefined = path
124
+
125
+ while (nextPath && items.length < limit) {
126
+ const page = pageSchema.parse(await request(nextPath))
127
+ items.push(...page.value)
128
+ nextPath = page["@odata.nextLink"]
129
+ }
130
+
131
+ return items.slice(0, limit)
132
+ }
@@ -0,0 +1,14 @@
1
+ import { z } from "zod"
2
+ import { OUTLOOK_MESSAGE_SCHEMA } from "./schemas"
3
+
4
+ export * from "./graph"
5
+ export * from "./schemas"
6
+
7
+ export const OUTLOOK_TRIGGER_CONFIG_SCHEMA = z.object({})
8
+
9
+ export const outlookTriggerContracts = {
10
+ "outlook.email.received": {
11
+ configSchema: OUTLOOK_TRIGGER_CONFIG_SCHEMA,
12
+ eventSchema: OUTLOOK_MESSAGE_SCHEMA,
13
+ },
14
+ } as const
@@ -0,0 +1,388 @@
1
+ import { z } from "zod"
2
+
3
+ const OPTIONAL_DATE_SCHEMA = z
4
+ .union([
5
+ z.date(),
6
+ z.iso.datetime({ offset: true }).transform((value) => new Date(value)),
7
+ ])
8
+ .nullish()
9
+ .transform((value) => value ?? undefined)
10
+ const OPTIONAL_STRING_SCHEMA = z
11
+ .string()
12
+ .nullish()
13
+ .transform((value) => value ?? undefined)
14
+
15
+ export const OUTLOOK_BODY_TYPE_SCHEMA = z.enum(["text", "html"])
16
+ export const OUTLOOK_IMPORTANCE_SCHEMA = z.enum(["low", "normal", "high"])
17
+ export const OUTLOOK_FLAG_STATUS_SCHEMA = z.enum([
18
+ "notFlagged",
19
+ "complete",
20
+ "flagged",
21
+ ])
22
+
23
+ export const OUTLOOK_EMAIL_ADDRESS_SCHEMA = z.object({
24
+ /** SMTP email address. */
25
+ address: z.string(),
26
+
27
+ /** Display name supplied by Microsoft Graph. */
28
+ name: OPTIONAL_STRING_SCHEMA,
29
+ })
30
+
31
+ export const OUTLOOK_RECIPIENT_SCHEMA = z.union([
32
+ z.email(),
33
+ OUTLOOK_EMAIL_ADDRESS_SCHEMA,
34
+ ])
35
+ export const OUTLOOK_RECIPIENTS_SCHEMA = z.union([
36
+ OUTLOOK_RECIPIENT_SCHEMA,
37
+ OUTLOOK_RECIPIENT_SCHEMA.array().min(1),
38
+ ])
39
+
40
+ export const OUTLOOK_BODY_SCHEMA = z.object({
41
+ /** Body content as returned by Graph. */
42
+ content: z.string(),
43
+
44
+ /** Lowercase body media type. */
45
+ contentType: z
46
+ .enum(["text", "html"])
47
+ .or(z.enum(["Text", "HTML"]))
48
+ .transform((value) =>
49
+ value === "Text" ? "text" : value === "HTML" ? "html" : value,
50
+ ),
51
+ })
52
+
53
+ const OUTLOOK_FOLLOWUP_FLAG_SCHEMA = z.object({
54
+ /** Date and time the flag was completed. */
55
+ completedAt: z
56
+ .object({ dateTime: z.string(), timeZone: z.string() })
57
+ .nullish()
58
+ .transform((value) => value ?? undefined),
59
+
60
+ /** Due date and its Outlook timezone. */
61
+ dueAt: z
62
+ .object({ dateTime: z.string(), timeZone: z.string() })
63
+ .nullish()
64
+ .transform((value) => value ?? undefined),
65
+
66
+ /** Current follow-up state. */
67
+ status: OUTLOOK_FLAG_STATUS_SCHEMA,
68
+ })
69
+
70
+ export const OUTLOOK_MESSAGE_SCHEMA = z.object({
71
+ /** Outlook categories assigned to the message. */
72
+ categories: z.string().array().prefault([]),
73
+
74
+ /** Opaque conversation identifier shared by related messages. */
75
+ conversationId: OPTIONAL_STRING_SCHEMA,
76
+
77
+ /** Time the message was created in the mailbox. */
78
+ createdAt: OPTIONAL_DATE_SCHEMA,
79
+
80
+ /** Follow-up flag state and dates. */
81
+ flag: OUTLOOK_FOLLOWUP_FLAG_SCHEMA.optional(),
82
+
83
+ /** Sender shown in the From header. */
84
+ from: OUTLOOK_EMAIL_ADDRESS_SCHEMA.nullish().transform(
85
+ (value) => value ?? undefined,
86
+ ),
87
+
88
+ /** Whether the message contains one or more attachments. */
89
+ hasAttachments: z.boolean().prefault(false),
90
+
91
+ /** Provider message identifier. */
92
+ messageId: z.string(),
93
+
94
+ /** RFC 5322 Message-ID. */
95
+ internetMessageId: OPTIONAL_STRING_SCHEMA,
96
+
97
+ /** Provider-defined message importance. */
98
+ importance: OUTLOOK_IMPORTANCE_SCHEMA.prefault("normal"),
99
+
100
+ /** Focused Inbox classification. */
101
+ inferenceClassification: z
102
+ .enum(["focused", "other"])
103
+ .nullish()
104
+ .transform((value) => value ?? undefined),
105
+
106
+ /** Whether this message is an unsent draft. */
107
+ isDraft: z.boolean().prefault(false),
108
+
109
+ /** Whether the message has been read. */
110
+ isRead: z.boolean().prefault(false),
111
+
112
+ /** Time the message was last modified. */
113
+ modifiedAt: OPTIONAL_DATE_SCHEMA,
114
+
115
+ /** Opaque containing folder identifier. */
116
+ parentFolderId: OPTIONAL_STRING_SCHEMA,
117
+
118
+ /** Short body preview generated by Outlook. */
119
+ preview: OPTIONAL_STRING_SCHEMA,
120
+
121
+ /** Time the message arrived in the mailbox. */
122
+ receivedAt: OPTIONAL_DATE_SCHEMA,
123
+
124
+ /** Addresses preferred for replies. */
125
+ replyTo: OUTLOOK_EMAIL_ADDRESS_SCHEMA.array().prefault([]),
126
+
127
+ /** Account that submitted the message. */
128
+ sender: OUTLOOK_EMAIL_ADDRESS_SCHEMA.nullish().transform(
129
+ (value) => value ?? undefined,
130
+ ),
131
+
132
+ /** Time the message was sent. */
133
+ sentAt: OPTIONAL_DATE_SCHEMA,
134
+
135
+ /** Subject line. */
136
+ subject: z
137
+ .string()
138
+ .nullish()
139
+ .transform((value) => value ?? ""),
140
+
141
+ /** Primary recipients. */
142
+ to: OUTLOOK_EMAIL_ADDRESS_SCHEMA.array().prefault([]),
143
+
144
+ /** Carbon-copy recipients. */
145
+ cc: OUTLOOK_EMAIL_ADDRESS_SCHEMA.array().prefault([]),
146
+
147
+ /** Blind-copy recipients. */
148
+ bcc: OUTLOOK_EMAIL_ADDRESS_SCHEMA.array().prefault([]),
149
+
150
+ /** Outlook web URL for the message. */
151
+ webLink: OPTIONAL_STRING_SCHEMA,
152
+
153
+ /** Message body, when requested from Graph. */
154
+ body: OUTLOOK_BODY_SCHEMA.nullish().transform((value) => value ?? undefined),
155
+
156
+ /** Graph concurrency token. */
157
+ etag: z.string().optional(),
158
+ })
159
+
160
+ export const GRAPH_MESSAGE_SCHEMA = z
161
+ .looseObject({
162
+ "@odata.etag": z.string().optional(),
163
+ bccRecipients: z
164
+ .object({ emailAddress: OUTLOOK_EMAIL_ADDRESS_SCHEMA })
165
+ .array()
166
+ .optional(),
167
+ body: OUTLOOK_BODY_SCHEMA.nullish(),
168
+ bodyPreview: z.string().nullish(),
169
+ categories: z.string().array().optional(),
170
+ ccRecipients: z
171
+ .object({ emailAddress: OUTLOOK_EMAIL_ADDRESS_SCHEMA })
172
+ .array()
173
+ .optional(),
174
+ conversationId: z.string().nullish(),
175
+ createdDateTime: z.string().nullish(),
176
+ flag: z
177
+ .object({
178
+ completedDateTime: z
179
+ .object({ dateTime: z.string(), timeZone: z.string() })
180
+ .nullish(),
181
+ dueDateTime: z
182
+ .object({ dateTime: z.string(), timeZone: z.string() })
183
+ .nullish(),
184
+ flagStatus: OUTLOOK_FLAG_STATUS_SCHEMA,
185
+ })
186
+ .optional(),
187
+ from: z.object({ emailAddress: OUTLOOK_EMAIL_ADDRESS_SCHEMA }).nullish(),
188
+ hasAttachments: z.boolean().optional(),
189
+ id: z.string(),
190
+ importance: OUTLOOK_IMPORTANCE_SCHEMA.optional(),
191
+ inferenceClassification: z.enum(["focused", "other"]).nullish(),
192
+ internetMessageId: z.string().nullish(),
193
+ isDraft: z.boolean().optional(),
194
+ isRead: z.boolean().optional(),
195
+ lastModifiedDateTime: z.string().nullish(),
196
+ parentFolderId: z.string().nullish(),
197
+ receivedDateTime: z.string().nullish(),
198
+ replyTo: z
199
+ .object({ emailAddress: OUTLOOK_EMAIL_ADDRESS_SCHEMA })
200
+ .array()
201
+ .optional(),
202
+ sender: z.object({ emailAddress: OUTLOOK_EMAIL_ADDRESS_SCHEMA }).nullish(),
203
+ sentDateTime: z.string().nullish(),
204
+ subject: z.string().nullish(),
205
+ toRecipients: z
206
+ .object({ emailAddress: OUTLOOK_EMAIL_ADDRESS_SCHEMA })
207
+ .array()
208
+ .optional(),
209
+ webLink: z.string().nullish(),
210
+ })
211
+ .transform((message) =>
212
+ OUTLOOK_MESSAGE_SCHEMA.parse({
213
+ bcc: message.bccRecipients?.map(({ emailAddress }) => emailAddress),
214
+ body: message.body,
215
+ categories: message.categories,
216
+ cc: message.ccRecipients?.map(({ emailAddress }) => emailAddress),
217
+ conversationId: message.conversationId,
218
+ createdAt: message.createdDateTime,
219
+ etag: message["@odata.etag"],
220
+ flag: message.flag
221
+ ? {
222
+ completedAt: message.flag.completedDateTime,
223
+ dueAt: message.flag.dueDateTime,
224
+ status: message.flag.flagStatus,
225
+ }
226
+ : undefined,
227
+ from: message.from?.emailAddress,
228
+ hasAttachments: message.hasAttachments,
229
+ importance: message.importance,
230
+ inferenceClassification: message.inferenceClassification,
231
+ internetMessageId: message.internetMessageId,
232
+ isDraft: message.isDraft,
233
+ isRead: message.isRead,
234
+ messageId: message.id,
235
+ modifiedAt: message.lastModifiedDateTime,
236
+ parentFolderId: message.parentFolderId,
237
+ preview: message.bodyPreview,
238
+ receivedAt: message.receivedDateTime,
239
+ replyTo: message.replyTo?.map(({ emailAddress }) => emailAddress),
240
+ sender: message.sender?.emailAddress,
241
+ sentAt: message.sentDateTime,
242
+ subject: message.subject,
243
+ to: message.toRecipients?.map(({ emailAddress }) => emailAddress),
244
+ webLink: message.webLink,
245
+ }),
246
+ )
247
+
248
+ /**
249
+ * Normalizes an untrusted Microsoft Graph message payload.
250
+ *
251
+ * @param payload - Provider message payload.
252
+ */
253
+ export function normalizeOutlookMessage(payload: unknown) {
254
+ return GRAPH_MESSAGE_SCHEMA.parse(payload)
255
+ }
256
+
257
+ export const OUTLOOK_MAIL_FOLDER_SCHEMA = z.object({
258
+ /** Number of child folders directly beneath this folder. */
259
+ childFolderCount: z.number().int().prefault(0),
260
+
261
+ /** Human-readable folder name. */
262
+ displayName: z.string(),
263
+
264
+ /** Whether the folder is hidden in Outlook. */
265
+ isHidden: z.boolean().prefault(false),
266
+
267
+ /** Opaque provider folder identifier. */
268
+ folderId: z.string(),
269
+
270
+ /** Total messages directly contained in the folder. */
271
+ totalItemCount: z.number().int().prefault(0),
272
+
273
+ /** Unread messages directly contained in the folder. */
274
+ unreadItemCount: z.number().int().prefault(0),
275
+ })
276
+
277
+ export const GRAPH_MAIL_FOLDER_SCHEMA = z
278
+ .looseObject({
279
+ childFolderCount: z.number().int().optional(),
280
+ displayName: z.string(),
281
+ id: z.string(),
282
+ isHidden: z.boolean().optional(),
283
+ totalItemCount: z.number().int().optional(),
284
+ unreadItemCount: z.number().int().optional(),
285
+ })
286
+ .transform((folder) =>
287
+ OUTLOOK_MAIL_FOLDER_SCHEMA.parse({
288
+ ...folder,
289
+ folderId: folder.id,
290
+ }),
291
+ )
292
+
293
+ export const OUTLOOK_PROFILE_SCHEMA = z.object({
294
+ /** User's primary email address, when available. */
295
+ email: OPTIONAL_STRING_SCHEMA,
296
+
297
+ /** Display name configured in Microsoft 365. */
298
+ displayName: z.string(),
299
+
300
+ /** Microsoft Graph user identifier. */
301
+ userId: z.string(),
302
+
303
+ /** User principal name used to sign in. */
304
+ userPrincipalName: z.string(),
305
+ })
306
+
307
+ export const GRAPH_PROFILE_SCHEMA = z
308
+ .looseObject({
309
+ displayName: z.string(),
310
+ id: z.string(),
311
+ mail: z.string().nullish(),
312
+ userPrincipalName: z.string(),
313
+ })
314
+ .transform((profile) =>
315
+ OUTLOOK_PROFILE_SCHEMA.parse({
316
+ displayName: profile.displayName,
317
+ email: profile.mail,
318
+ userId: profile.id,
319
+ userPrincipalName: profile.userPrincipalName,
320
+ }),
321
+ )
322
+
323
+ export const OUTLOOK_ATTACHMENT_SCHEMA = z.object({
324
+ /** Content-ID used by inline HTML content. */
325
+ contentId: OPTIONAL_STRING_SCHEMA,
326
+
327
+ /** Content location supplied by the sender. */
328
+ contentLocation: OPTIONAL_STRING_SCHEMA,
329
+
330
+ /** MIME media type. */
331
+ contentType: OPTIONAL_STRING_SCHEMA,
332
+
333
+ /** Downloaded file contents, when included by Graph. */
334
+ file: z.instanceof(File).optional(),
335
+
336
+ /** Opaque provider attachment identifier. */
337
+ attachmentId: z.string(),
338
+
339
+ /** Whether the attachment is displayed inline. */
340
+ isInline: z.boolean().prefault(false),
341
+
342
+ /** Attachment filename. */
343
+ name: z.string(),
344
+
345
+ /** Attachment size in bytes. */
346
+ size: z.number().int().nonnegative().prefault(0),
347
+
348
+ /** Graph attachment resource kind. */
349
+ type: z.enum(["file", "item", "reference", "unknown"]),
350
+ })
351
+
352
+ export const GRAPH_ATTACHMENT_SCHEMA = z
353
+ .looseObject({
354
+ "@odata.type": z.string().optional(),
355
+ contentBytes: z.string().optional(),
356
+ contentId: z.string().nullish(),
357
+ contentLocation: z.string().nullish(),
358
+ contentType: z.string().nullish(),
359
+ id: z.string(),
360
+ isInline: z.boolean().optional(),
361
+ name: z.string(),
362
+ size: z.number().int().optional(),
363
+ })
364
+ .transform((attachment) => {
365
+ return OUTLOOK_ATTACHMENT_SCHEMA.parse({
366
+ attachmentId: attachment.id,
367
+ contentId: attachment.contentId,
368
+ contentLocation: attachment.contentLocation,
369
+ contentType: attachment.contentType,
370
+ file: attachment.contentBytes
371
+ ? new File(
372
+ [Buffer.from(attachment.contentBytes, "base64")],
373
+ attachment.name,
374
+ { type: attachment.contentType ?? "" },
375
+ )
376
+ : undefined,
377
+ isInline: attachment.isInline,
378
+ name: attachment.name,
379
+ size: attachment.size,
380
+ type: attachment["@odata.type"]?.includes("fileAttachment")
381
+ ? "file"
382
+ : attachment["@odata.type"]?.includes("itemAttachment")
383
+ ? "item"
384
+ : attachment["@odata.type"]?.includes("referenceAttachment")
385
+ ? "reference"
386
+ : "unknown",
387
+ })
388
+ })
@@ -0,0 +1,70 @@
1
+ import { z } from "zod"
2
+ import {
3
+ RESEND_EMAIL_BOUNCED_EVENT_SCHEMA,
4
+ RESEND_EMAIL_CLICKED_EVENT_SCHEMA,
5
+ RESEND_EMAIL_COMPLAINED_EVENT_SCHEMA,
6
+ RESEND_EMAIL_DELIVERED_EVENT_SCHEMA,
7
+ RESEND_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA,
8
+ RESEND_EMAIL_EVENT_SCHEMA,
9
+ RESEND_EMAIL_FAILED_EVENT_SCHEMA,
10
+ RESEND_EMAIL_OPENED_EVENT_SCHEMA,
11
+ RESEND_EMAIL_RECEIVED_EVENT_SCHEMA,
12
+ RESEND_EMAIL_SCHEDULED_EVENT_SCHEMA,
13
+ RESEND_EMAIL_SENT_EVENT_SCHEMA,
14
+ RESEND_EMAIL_SUPPRESSED_EVENT_SCHEMA,
15
+ } from "./schemas"
16
+
17
+ export * from "./schemas"
18
+
19
+ export const RESEND_TRIGGER_CONFIG_SCHEMA = z.object({})
20
+
21
+ export const resendTriggerContracts = {
22
+ "resend.email.bounced": {
23
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
24
+ eventSchema: RESEND_EMAIL_BOUNCED_EVENT_SCHEMA,
25
+ },
26
+ "resend.email.clicked": {
27
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
28
+ eventSchema: RESEND_EMAIL_CLICKED_EVENT_SCHEMA,
29
+ },
30
+ "resend.email.complained": {
31
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
32
+ eventSchema: RESEND_EMAIL_COMPLAINED_EVENT_SCHEMA,
33
+ },
34
+ "resend.email.delivered": {
35
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
36
+ eventSchema: RESEND_EMAIL_DELIVERED_EVENT_SCHEMA,
37
+ },
38
+ "resend.email.deliveryDelayed": {
39
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
40
+ eventSchema: RESEND_EMAIL_DELIVERY_DELAYED_EVENT_SCHEMA,
41
+ },
42
+ "resend.email.event": {
43
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
44
+ eventSchema: RESEND_EMAIL_EVENT_SCHEMA,
45
+ },
46
+ "resend.email.failed": {
47
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
48
+ eventSchema: RESEND_EMAIL_FAILED_EVENT_SCHEMA,
49
+ },
50
+ "resend.email.opened": {
51
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
52
+ eventSchema: RESEND_EMAIL_OPENED_EVENT_SCHEMA,
53
+ },
54
+ "resend.email.received": {
55
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
56
+ eventSchema: RESEND_EMAIL_RECEIVED_EVENT_SCHEMA,
57
+ },
58
+ "resend.email.scheduled": {
59
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
60
+ eventSchema: RESEND_EMAIL_SCHEDULED_EVENT_SCHEMA,
61
+ },
62
+ "resend.email.sent": {
63
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
64
+ eventSchema: RESEND_EMAIL_SENT_EVENT_SCHEMA,
65
+ },
66
+ "resend.email.suppressed": {
67
+ configSchema: RESEND_TRIGGER_CONFIG_SCHEMA,
68
+ eventSchema: RESEND_EMAIL_SUPPRESSED_EVENT_SCHEMA,
69
+ },
70
+ } as const