@automate.ax/integration-contracts 0.93.1 → 0.95.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.
@@ -15,38 +15,48 @@ const TRELLO_CARD_SCHEMA = TRELLO_RESOURCE_SCHEMA.extend({
15
15
  idShort: z.number().int().optional(),
16
16
  shortLink: z.string().optional(),
17
17
  });
18
- const TRELLO_LIST_SCHEMA = TRELLO_RESOURCE_SCHEMA;
18
+ const TRELLO_LIST_SCHEMA = TRELLO_RESOURCE_SCHEMA.extend({
19
+ closed: z.boolean().optional(),
20
+ });
19
21
  const TRELLO_MEMBER_SCHEMA = TRELLO_RESOURCE_SCHEMA.extend({
20
22
  fullName: z.string().optional(),
21
23
  username: z.string().optional(),
22
24
  });
25
+ const TRELLO_ATTACHMENT_SCHEMA = TRELLO_RESOURCE_SCHEMA.extend({
26
+ url: z.string().optional(),
27
+ });
28
+ const TRELLO_CHECK_ITEM_SCHEMA = TRELLO_RESOURCE_SCHEMA.extend({
29
+ state: z.enum(["complete", "incomplete"]).optional(),
30
+ });
31
+ const TRELLO_COMMENT_SCHEMA = TRELLO_RESOURCE_SCHEMA.extend({
32
+ text: z.string().optional(),
33
+ });
34
+ const TRELLO_CUSTOM_FIELD_ITEM_SCHEMA = z
35
+ .looseObject({
36
+ id: z.string().optional(),
37
+ idCustomField: z.string().optional(),
38
+ idModel: z.string().optional(),
39
+ idValue: z.string().optional(),
40
+ value: TRELLO_JSON_OBJECT_SCHEMA.optional(),
41
+ })
42
+ .catchall(z.json());
23
43
  const TRELLO_ACTION_DATA_SCHEMA = z
24
44
  .looseObject({
25
- /** Attachment affected by the action, when applicable. */
26
- attachment: TRELLO_RESOURCE_SCHEMA.extend({
27
- url: z.string().optional(),
28
- }).optional(),
29
- /** Board affected by the action. */
45
+ action: TRELLO_COMMENT_SCHEMA.optional(),
46
+ attachment: TRELLO_ATTACHMENT_SCHEMA.optional(),
30
47
  board: TRELLO_BOARD_SCHEMA.optional(),
31
- /** Card affected by the action, when applicable. */
32
48
  card: TRELLO_CARD_SCHEMA.optional(),
33
- /** Checklist affected by the action, when applicable. */
34
49
  checklist: TRELLO_RESOURCE_SCHEMA.optional(),
35
- /** Checklist item affected by the action, when applicable. */
36
- checkItem: TRELLO_RESOURCE_SCHEMA.optional(),
37
- /** List associated with the action. */
50
+ checkItem: TRELLO_CHECK_ITEM_SCHEMA.optional(),
51
+ customField: TRELLO_RESOURCE_SCHEMA.optional(),
52
+ customFieldItem: TRELLO_CUSTOM_FIELD_ITEM_SCHEMA.optional(),
53
+ label: TRELLO_RESOURCE_SCHEMA.optional(),
38
54
  list: TRELLO_LIST_SCHEMA.optional(),
39
- /** Destination list for a move action. */
40
55
  listAfter: TRELLO_LIST_SCHEMA.optional(),
41
- /** Source list for a move action. */
42
56
  listBefore: TRELLO_LIST_SCHEMA.optional(),
43
- /** Member affected by the action, when applicable. */
44
57
  member: TRELLO_MEMBER_SCHEMA.optional(),
45
- /** Previous field values supplied for an update action. */
46
58
  old: TRELLO_JSON_OBJECT_SCHEMA.optional(),
47
- /** Organization affected by the action, when applicable. */
48
59
  organization: TRELLO_RESOURCE_SCHEMA.optional(),
49
- /** Comment or other action text. */
50
60
  text: z.string().optional(),
51
61
  })
52
62
  .catchall(z.json());
@@ -56,18 +66,34 @@ const TRELLO_CARD_ACTION_DATA_SCHEMA = TRELLO_ACTION_DATA_SCHEMA.extend({
56
66
  .catchall(z.json())
57
67
  .optional(),
58
68
  });
69
+ const TRELLO_LIST_ACTION_DATA_SCHEMA = TRELLO_ACTION_DATA_SCHEMA.extend({
70
+ old: z
71
+ .looseObject({ closed: z.boolean().optional() })
72
+ .catchall(z.json())
73
+ .optional(),
74
+ });
59
75
  const TRELLO_WEBHOOK_EVENT_SCHEMA = z.object({
60
76
  action: z
61
77
  .looseObject({
62
78
  data: TRELLO_ACTION_DATA_SCHEMA,
63
79
  date: z.iso.datetime({ offset: true }),
64
80
  id: z.string(),
81
+ idMemberCreator: z.string().optional(),
65
82
  memberCreator: TRELLO_MEMBER_SCHEMA.optional(),
66
83
  type: z.string(),
67
84
  })
68
85
  .catchall(z.json()),
69
86
  model: TRELLO_BOARD_SCHEMA,
70
- webhook: z.looseObject({ id: z.string() }).catchall(z.json()),
87
+ webhook: z
88
+ .looseObject({
89
+ active: z.boolean().optional(),
90
+ callbackURL: z.string().optional(),
91
+ consecutiveFailures: z.number().int().nonnegative().optional(),
92
+ firstConsecutiveFailDate: z.string().nullable().optional(),
93
+ id: z.string(),
94
+ idModel: z.string().optional(),
95
+ })
96
+ .catchall(z.json()),
71
97
  });
72
98
  const TRELLO_CARD_CREATED_ACTION_SCHEMA = z.enum([
73
99
  "copyCard",
@@ -75,6 +101,11 @@ const TRELLO_CARD_CREATED_ACTION_SCHEMA = z.enum([
75
101
  "createCard",
76
102
  "emailCard",
77
103
  ]);
104
+ const TRELLO_CARD_MOVED_ACTION_SCHEMA = z.enum([
105
+ "moveCardFromBoard",
106
+ "moveCardToBoard",
107
+ "updateCard",
108
+ ]);
78
109
  const TRELLO_CARD_UPDATED_ACTION_SCHEMA = z.literal("updateCard");
79
110
  const TRELLO_CARD_COMMENTED_ACTION_SCHEMA = z.literal("commentCard");
80
111
  export const TRELLO_CARD_EVENT_KINDS = [
@@ -82,55 +113,92 @@ export const TRELLO_CARD_EVENT_KINDS = [
82
113
  "moved",
83
114
  "updated",
84
115
  "archived",
116
+ "restored",
117
+ "deleted",
85
118
  "commented",
86
119
  ];
120
+ export const TRELLO_EVENT_KINDS = [
121
+ "card.created",
122
+ "card.moved",
123
+ "card.updated",
124
+ "card.archived",
125
+ "card.restored",
126
+ "card.deleted",
127
+ "card.commented",
128
+ "comment.updated",
129
+ "comment.deleted",
130
+ "attachment.added",
131
+ "attachment.deleted",
132
+ "card.member.added",
133
+ "card.member.removed",
134
+ "card.label.added",
135
+ "card.label.removed",
136
+ "checklist.created",
137
+ "checklist.updated",
138
+ "checklist.deleted",
139
+ "checklist-item.created",
140
+ "checklist-item.updated",
141
+ "checklist-item.completed",
142
+ "checklist-item.deleted",
143
+ "custom-field.created",
144
+ "custom-field.updated",
145
+ "custom-field.deleted",
146
+ "custom-field.value.updated",
147
+ "list.created",
148
+ "list.updated",
149
+ "list.archived",
150
+ "list.restored",
151
+ "list.moved",
152
+ ];
87
153
  export const TRELLO_BOARD_EVENT_SCHEMA = TRELLO_ACTION_DATA_SCHEMA.extend({
88
- /** Stable ID of the Trello action that caused this event. */
89
154
  actionId: z.string(),
90
- /** Trello action category, such as `createCard` or `updateCard`. */
91
155
  actionType: z.string(),
92
- /** Board affected by the action, falling back to the watched board. */
93
156
  board: TRELLO_BOARD_SCHEMA,
94
- /** Complete provider webhook envelope. */
95
157
  event: TRELLO_WEBHOOK_EVENT_SCHEMA,
96
- /** Member responsible for the action, when Trello includes one. */
97
158
  memberCreator: TRELLO_MEMBER_SCHEMA.optional(),
98
- /** When the underlying Trello action occurred. */
99
159
  occurredAt: z.iso.datetime({ offset: true }),
100
- /** Provider webhook that delivered the event. */
101
160
  webhookId: z.string(),
102
161
  });
103
162
  export const TRELLO_CARD_EVENT_SCHEMA = z.object({
104
- /** Stable ID of the Trello action that caused this event. */
105
163
  actionId: z.string(),
106
- /** Provider-native Trello action category. */
107
164
  actionType: z.string(),
108
- /** Board containing the affected card. */
109
165
  board: TRELLO_BOARD_EVENT_SCHEMA.shape.board,
110
- /** Card affected by the action. */
111
166
  card: TRELLO_CARD_SCHEMA,
112
- /** Comment text for card-comment events. */
113
167
  commentText: z.string().optional(),
114
- /** Complete provider webhook envelope. */
115
168
  event: TRELLO_WEBHOOK_EVENT_SCHEMA,
116
- /** List containing the card after the action. */
117
169
  list: TRELLO_LIST_SCHEMA.optional(),
118
- /** Member responsible for the action, when supplied by Trello. */
119
170
  memberCreator: TRELLO_BOARD_EVENT_SCHEMA.shape.memberCreator,
120
- /** When the underlying Trello action occurred. */
121
171
  occurredAt: z.iso.datetime({ offset: true }),
122
- /** List containing the card before a move. */
123
172
  previousList: TRELLO_LIST_SCHEMA.optional(),
124
173
  });
174
+ const TRELLO_RESOURCE_EVENT_SCHEMA = z.object({
175
+ actionId: z.string(),
176
+ actionType: z.string(),
177
+ attachment: TRELLO_ATTACHMENT_SCHEMA.optional(),
178
+ board: TRELLO_BOARD_SCHEMA,
179
+ card: TRELLO_CARD_SCHEMA.optional(),
180
+ checklist: TRELLO_RESOURCE_SCHEMA.optional(),
181
+ checkItem: TRELLO_CHECK_ITEM_SCHEMA.optional(),
182
+ comment: TRELLO_COMMENT_SCHEMA.optional(),
183
+ customField: TRELLO_RESOURCE_SCHEMA.optional(),
184
+ customFieldItem: TRELLO_CUSTOM_FIELD_ITEM_SCHEMA.optional(),
185
+ event: TRELLO_WEBHOOK_EVENT_SCHEMA,
186
+ label: TRELLO_RESOURCE_SCHEMA.optional(),
187
+ list: TRELLO_LIST_SCHEMA.optional(),
188
+ listAfter: TRELLO_LIST_SCHEMA.optional(),
189
+ listBefore: TRELLO_LIST_SCHEMA.optional(),
190
+ member: TRELLO_MEMBER_SCHEMA.optional(),
191
+ memberCreator: TRELLO_MEMBER_SCHEMA.optional(),
192
+ occurredAt: z.iso.datetime({ offset: true }),
193
+ old: TRELLO_JSON_OBJECT_SCHEMA.optional(),
194
+ });
125
195
  export const TRELLO_CARD_CREATED_EVENT_SCHEMA = TRELLO_CARD_EVENT_SCHEMA.extend({
126
196
  actionType: TRELLO_CARD_CREATED_ACTION_SCHEMA,
127
197
  event: trelloWebhookEventSchema(TRELLO_CARD_CREATED_ACTION_SCHEMA),
128
198
  });
129
199
  export const TRELLO_CARD_MOVED_EVENT_SCHEMA = TRELLO_CARD_EVENT_SCHEMA.extend({
130
- actionType: TRELLO_CARD_UPDATED_ACTION_SCHEMA,
131
- event: trelloWebhookEventSchema(TRELLO_CARD_UPDATED_ACTION_SCHEMA),
132
- list: TRELLO_LIST_SCHEMA,
133
- previousList: TRELLO_LIST_SCHEMA,
200
+ actionType: TRELLO_CARD_MOVED_ACTION_SCHEMA,
201
+ event: trelloWebhookEventSchema(TRELLO_CARD_MOVED_ACTION_SCHEMA),
134
202
  });
135
203
  export const TRELLO_CARD_UPDATED_EVENT_SCHEMA = TRELLO_CARD_EVENT_SCHEMA.extend({
136
204
  actionType: TRELLO_CARD_UPDATED_ACTION_SCHEMA,
@@ -139,15 +207,66 @@ export const TRELLO_CARD_UPDATED_EVENT_SCHEMA = TRELLO_CARD_EVENT_SCHEMA.extend(
139
207
  export const TRELLO_CARD_ARCHIVED_EVENT_SCHEMA = TRELLO_CARD_UPDATED_EVENT_SCHEMA.extend({
140
208
  card: TRELLO_CARD_SCHEMA.extend({ closed: z.literal(true) }),
141
209
  });
210
+ export const TRELLO_CARD_RESTORED_EVENT_SCHEMA = TRELLO_CARD_UPDATED_EVENT_SCHEMA.extend({
211
+ card: TRELLO_CARD_SCHEMA.extend({ closed: z.literal(false) }),
212
+ });
213
+ export const TRELLO_CARD_DELETED_EVENT_SCHEMA = TRELLO_CARD_EVENT_SCHEMA.extend({
214
+ actionType: z.literal("deleteCard"),
215
+ event: trelloWebhookEventSchema(z.literal("deleteCard")),
216
+ });
142
217
  export const TRELLO_CARD_COMMENTED_EVENT_SCHEMA = TRELLO_CARD_EVENT_SCHEMA.extend({
143
218
  actionType: TRELLO_CARD_COMMENTED_ACTION_SCHEMA,
144
219
  commentText: z.string(),
145
220
  event: trelloWebhookEventSchema(TRELLO_CARD_COMMENTED_ACTION_SCHEMA),
146
221
  });
222
+ export const TRELLO_COMMENT_UPDATED_EVENT_SCHEMA = resourceEventSchema(z.literal("updateComment"));
223
+ export const TRELLO_COMMENT_DELETED_EVENT_SCHEMA = resourceEventSchema(z.literal("deleteComment"));
224
+ export const TRELLO_ATTACHMENT_ADDED_EVENT_SCHEMA = resourceEventSchema(z.literal("addAttachmentToCard")).extend({ attachment: TRELLO_ATTACHMENT_SCHEMA, card: TRELLO_CARD_SCHEMA });
225
+ export const TRELLO_ATTACHMENT_DELETED_EVENT_SCHEMA = resourceEventSchema(z.literal("deleteAttachmentFromCard")).extend({ attachment: TRELLO_ATTACHMENT_SCHEMA, card: TRELLO_CARD_SCHEMA });
226
+ export const TRELLO_CARD_MEMBER_ADDED_EVENT_SCHEMA = resourceEventSchema(z.literal("addMemberToCard")).extend({ card: TRELLO_CARD_SCHEMA, member: TRELLO_MEMBER_SCHEMA });
227
+ export const TRELLO_CARD_MEMBER_REMOVED_EVENT_SCHEMA = resourceEventSchema(z.literal("removeMemberFromCard")).extend({ card: TRELLO_CARD_SCHEMA, member: TRELLO_MEMBER_SCHEMA });
228
+ export const TRELLO_CARD_LABEL_ADDED_EVENT_SCHEMA = resourceEventSchema(z.literal("addLabelToCard")).extend({ card: TRELLO_CARD_SCHEMA, label: TRELLO_RESOURCE_SCHEMA });
229
+ export const TRELLO_CARD_LABEL_REMOVED_EVENT_SCHEMA = resourceEventSchema(z.literal("removeLabelFromCard")).extend({ card: TRELLO_CARD_SCHEMA, label: TRELLO_RESOURCE_SCHEMA });
230
+ export const TRELLO_CHECKLIST_CREATED_EVENT_SCHEMA = resourceEventSchema(z.literal("addChecklistToCard")).extend({ card: TRELLO_CARD_SCHEMA, checklist: TRELLO_RESOURCE_SCHEMA });
231
+ export const TRELLO_CHECKLIST_UPDATED_EVENT_SCHEMA = resourceEventSchema(z.literal("updateChecklist")).extend({ checklist: TRELLO_RESOURCE_SCHEMA });
232
+ export const TRELLO_CHECKLIST_DELETED_EVENT_SCHEMA = resourceEventSchema(z.literal("removeChecklistFromCard")).extend({ card: TRELLO_CARD_SCHEMA, checklist: TRELLO_RESOURCE_SCHEMA });
233
+ export const TRELLO_CHECKLIST_ITEM_CREATED_EVENT_SCHEMA = resourceEventSchema(z.literal("createCheckItem")).extend({
234
+ checkItem: TRELLO_CHECK_ITEM_SCHEMA,
235
+ checklist: TRELLO_RESOURCE_SCHEMA,
236
+ });
237
+ export const TRELLO_CHECKLIST_ITEM_UPDATED_EVENT_SCHEMA = resourceEventSchema(z.enum(["updateCheckItem", "updateCheckItemStateOnCard"])).extend({ checkItem: TRELLO_CHECK_ITEM_SCHEMA });
238
+ export const TRELLO_CHECKLIST_ITEM_COMPLETED_EVENT_SCHEMA = TRELLO_CHECKLIST_ITEM_UPDATED_EVENT_SCHEMA.extend({
239
+ actionType: z.literal("updateCheckItemStateOnCard"),
240
+ checkItem: TRELLO_CHECK_ITEM_SCHEMA.extend({
241
+ state: z.literal("complete"),
242
+ }),
243
+ event: trelloWebhookEventSchema(z.literal("updateCheckItemStateOnCard")),
244
+ });
245
+ export const TRELLO_CHECKLIST_ITEM_DELETED_EVENT_SCHEMA = resourceEventSchema(z.literal("deleteCheckItem")).extend({
246
+ checkItem: TRELLO_CHECK_ITEM_SCHEMA,
247
+ checklist: TRELLO_RESOURCE_SCHEMA,
248
+ });
249
+ export const TRELLO_CUSTOM_FIELD_CREATED_EVENT_SCHEMA = resourceEventSchema(z.literal("addCustomField")).extend({ customField: TRELLO_RESOURCE_SCHEMA });
250
+ export const TRELLO_CUSTOM_FIELD_UPDATED_EVENT_SCHEMA = resourceEventSchema(z.literal("updateCustomField")).extend({ customField: TRELLO_RESOURCE_SCHEMA });
251
+ export const TRELLO_CUSTOM_FIELD_DELETED_EVENT_SCHEMA = resourceEventSchema(z.literal("deleteCustomField")).extend({ customField: TRELLO_RESOURCE_SCHEMA });
252
+ export const TRELLO_CUSTOM_FIELD_VALUE_UPDATED_EVENT_SCHEMA = resourceEventSchema(z.literal("updateCustomFieldItem")).extend({
253
+ card: TRELLO_CARD_SCHEMA,
254
+ customField: TRELLO_RESOURCE_SCHEMA,
255
+ customFieldItem: TRELLO_CUSTOM_FIELD_ITEM_SCHEMA,
256
+ });
257
+ export const TRELLO_LIST_CREATED_EVENT_SCHEMA = resourceEventSchema(z.literal("createList")).extend({ list: TRELLO_LIST_SCHEMA });
258
+ export const TRELLO_LIST_UPDATED_EVENT_SCHEMA = resourceEventSchema(z.literal("updateList")).extend({ list: TRELLO_LIST_SCHEMA });
259
+ export const TRELLO_LIST_ARCHIVED_EVENT_SCHEMA = TRELLO_LIST_UPDATED_EVENT_SCHEMA.extend({
260
+ list: TRELLO_LIST_SCHEMA.extend({ closed: z.literal(true) }),
261
+ });
262
+ export const TRELLO_LIST_RESTORED_EVENT_SCHEMA = TRELLO_LIST_UPDATED_EVENT_SCHEMA.extend({
263
+ list: TRELLO_LIST_SCHEMA.extend({ closed: z.literal(false) }),
264
+ });
265
+ export const TRELLO_LIST_MOVED_EVENT_SCHEMA = resourceEventSchema(z.enum(["moveListFromBoard", "moveListToBoard"])).extend({ list: TRELLO_LIST_SCHEMA });
147
266
  /**
148
267
  * Normalizes one provider-native Trello board webhook payload.
149
268
  *
150
- * @param value - Untrusted Trello webhook body.
269
+ * @param value - Untrusted provider webhook payload.
151
270
  */
152
271
  export function normalizeTrelloBoardEvent(value) {
153
272
  const event = TRELLO_WEBHOOK_EVENT_SCHEMA.parse(value);
@@ -163,43 +282,144 @@ export function normalizeTrelloBoardEvent(value) {
163
282
  });
164
283
  }
165
284
  /**
166
- * Classifies one normalized board action into semantic card event categories.
167
- *
168
- * A single Trello action can intentionally belong to more than one category;
169
- * for example, moving a card is also a card update.
285
+ * Classifies one board action into every supported semantic event.
170
286
  *
171
- * @param event - Normalized board event received from Trello.
287
+ * @param event - Normalized board event.
172
288
  */
173
- export function getTrelloCardEventKinds(event) {
174
- const data = TRELLO_CARD_ACTION_DATA_SCHEMA.parse(event.event.action.data);
289
+ export function getTrelloEventKinds(event) {
290
+ const data = TRELLO_ACTION_DATA_SCHEMA.parse(event.event.action.data);
291
+ const cardData = TRELLO_CARD_ACTION_DATA_SCHEMA.parse(data);
292
+ const listData = TRELLO_LIST_ACTION_DATA_SCHEMA.parse(data);
293
+ const actionType = event.actionType;
175
294
  return [
176
295
  ...([
177
296
  "createCard",
178
297
  "copyCard",
179
298
  "convertToCardFromCheckItem",
180
299
  "emailCard",
181
- ].includes(event.actionType)
182
- ? ["created"]
300
+ ].includes(actionType)
301
+ ? ["card.created"]
302
+ : []),
303
+ ...(actionType === "moveCardFromBoard" ||
304
+ actionType === "moveCardToBoard" ||
305
+ (actionType === "updateCard" && data.listBefore && data.listAfter)
306
+ ? ["card.moved"]
307
+ : []),
308
+ ...(actionType === "updateCard" ? ["card.updated"] : []),
309
+ ...(actionType === "updateCard" &&
310
+ cardData.old?.closed === false &&
311
+ cardData.card?.closed === true
312
+ ? ["card.archived"]
313
+ : []),
314
+ ...(actionType === "updateCard" &&
315
+ cardData.old?.closed === true &&
316
+ cardData.card?.closed === false
317
+ ? ["card.restored"]
318
+ : []),
319
+ ...(actionType === "deleteCard" ? ["card.deleted"] : []),
320
+ ...(actionType === "commentCard" ? ["card.commented"] : []),
321
+ ...(actionType === "updateComment" ? ["comment.updated"] : []),
322
+ ...(actionType === "deleteComment" ? ["comment.deleted"] : []),
323
+ ...(actionType === "addAttachmentToCard"
324
+ ? ["attachment.added"]
325
+ : []),
326
+ ...(actionType === "deleteAttachmentFromCard"
327
+ ? ["attachment.deleted"]
328
+ : []),
329
+ ...(actionType === "addMemberToCard"
330
+ ? ["card.member.added"]
331
+ : []),
332
+ ...(actionType === "removeMemberFromCard"
333
+ ? ["card.member.removed"]
334
+ : []),
335
+ ...(actionType === "addLabelToCard" ? ["card.label.added"] : []),
336
+ ...(actionType === "removeLabelFromCard"
337
+ ? ["card.label.removed"]
338
+ : []),
339
+ ...(actionType === "addChecklistToCard"
340
+ ? ["checklist.created"]
341
+ : []),
342
+ ...(actionType === "updateChecklist"
343
+ ? ["checklist.updated"]
183
344
  : []),
184
- ...(event.actionType === "updateCard" &&
185
- data.listBefore !== undefined &&
186
- data.listAfter !== undefined
187
- ? ["moved"]
345
+ ...(actionType === "removeChecklistFromCard"
346
+ ? ["checklist.deleted"]
188
347
  : []),
189
- ...(event.actionType === "updateCard" ? ["updated"] : []),
190
- ...(event.actionType === "updateCard" &&
191
- data.old?.closed === false &&
192
- data.card?.closed === true
193
- ? ["archived"]
348
+ ...(actionType === "createCheckItem"
349
+ ? ["checklist-item.created"]
350
+ : []),
351
+ ...(actionType === "updateCheckItem" ||
352
+ actionType === "updateCheckItemStateOnCard"
353
+ ? ["checklist-item.updated"]
354
+ : []),
355
+ ...(actionType === "updateCheckItemStateOnCard" &&
356
+ data.checkItem?.state === "complete"
357
+ ? ["checklist-item.completed"]
358
+ : []),
359
+ ...(actionType === "deleteCheckItem"
360
+ ? ["checklist-item.deleted"]
361
+ : []),
362
+ ...(actionType === "addCustomField"
363
+ ? ["custom-field.created"]
364
+ : []),
365
+ ...(actionType === "updateCustomField"
366
+ ? ["custom-field.updated"]
367
+ : []),
368
+ ...(actionType === "deleteCustomField"
369
+ ? ["custom-field.deleted"]
370
+ : []),
371
+ ...(actionType === "updateCustomFieldItem"
372
+ ? ["custom-field.value.updated"]
373
+ : []),
374
+ ...(actionType === "createList" ? ["list.created"] : []),
375
+ ...(actionType === "updateList" ? ["list.updated"] : []),
376
+ ...(actionType === "updateList" &&
377
+ listData.old?.closed === false &&
378
+ listData.list?.closed === true
379
+ ? ["list.archived"]
380
+ : []),
381
+ ...(actionType === "updateList" &&
382
+ listData.old?.closed === true &&
383
+ listData.list?.closed === false
384
+ ? ["list.restored"]
385
+ : []),
386
+ ...(actionType === "moveListFromBoard" || actionType === "moveListToBoard"
387
+ ? ["list.moved"]
194
388
  : []),
195
- ...(event.actionType === "commentCard" ? ["commented"] : []),
196
389
  ];
197
390
  }
198
391
  /**
199
- * Promotes provider-native card action data into the stable semantic payload.
392
+ * Classifies one board action into the card-oriented event categories.
393
+ *
394
+ * @param event - Normalized board event.
395
+ */
396
+ export function getTrelloCardEventKinds(event) {
397
+ return getTrelloEventKinds(event).flatMap((kind) => {
398
+ switch (kind) {
399
+ case "card.created":
400
+ return ["created"];
401
+ case "card.moved":
402
+ return ["moved"];
403
+ case "card.updated":
404
+ return ["updated"];
405
+ case "card.archived":
406
+ return ["archived"];
407
+ case "card.restored":
408
+ return ["restored"];
409
+ case "card.deleted":
410
+ return ["deleted"];
411
+ case "card.commented":
412
+ return ["commented"];
413
+ default:
414
+ return [];
415
+ }
416
+ });
417
+ }
418
+ /**
419
+ * Promotes provider-native card action data into the stable card payload.
200
420
  *
201
- * @param event - Normalized board event classified as a card event.
202
- * @throws When the classified Trello action does not identify a card.
421
+ * @param event - Normalized board event.
422
+ * @throws When the provider action contains no card data.
203
423
  */
204
424
  export function normalizeTrelloCardEvent(event) {
205
425
  const data = TRELLO_CARD_ACTION_DATA_SCHEMA.parse(event.event.action.data);
@@ -220,9 +440,49 @@ export function normalizeTrelloCardEvent(event) {
220
440
  });
221
441
  }
222
442
  /**
223
- * Narrows the provider action type retained under a semantic event.
443
+ * Promotes provider action data into a shared resource-event payload.
444
+ *
445
+ * @param event - Normalized board event.
446
+ */
447
+ export function normalizeTrelloResourceEvent(event) {
448
+ const data = TRELLO_ACTION_DATA_SCHEMA.parse(event.event.action.data);
449
+ return TRELLO_RESOURCE_EVENT_SCHEMA.parse({
450
+ actionId: event.actionId,
451
+ actionType: event.actionType,
452
+ attachment: data.attachment,
453
+ board: event.board,
454
+ card: data.card,
455
+ checklist: data.checklist,
456
+ checkItem: data.checkItem,
457
+ comment: data.action,
458
+ customField: data.customField,
459
+ customFieldItem: data.customFieldItem,
460
+ event: event.event,
461
+ label: data.label,
462
+ list: data.listAfter ?? data.list,
463
+ listAfter: data.listAfter,
464
+ listBefore: data.listBefore,
465
+ member: data.member,
466
+ memberCreator: event.memberCreator,
467
+ occurredAt: event.occurredAt,
468
+ old: data.old,
469
+ });
470
+ }
471
+ /**
472
+ * Narrows the shared resource schema to one provider action type.
473
+ *
474
+ * @param actionType - Supported provider action schema.
475
+ */
476
+ function resourceEventSchema(actionType) {
477
+ return TRELLO_RESOURCE_EVENT_SCHEMA.extend({
478
+ actionType,
479
+ event: trelloWebhookEventSchema(actionType),
480
+ });
481
+ }
482
+ /**
483
+ * Narrows the raw webhook schema to one provider action type.
224
484
  *
225
- * @param actionType - Provider action-type schema for the semantic event.
485
+ * @param actionType - Supported provider action schema.
226
486
  */
227
487
  function trelloWebhookEventSchema(actionType) {
228
488
  return TRELLO_WEBHOOK_EVENT_SCHEMA.extend({