@notionhq/apps 0.0.27 → 0.0.28

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.
@@ -2,6 +2,7 @@
2
2
  import type { ConnectionActionInvoker } from "./connection-actions.js"
3
3
  import type { WorkflowConnection } from "./connections.js"
4
4
  import { CalendarConnectionClient } from "./calendar.generated.js"
5
+ import { MailConnectionClient } from "./mail.generated.js"
5
6
  import { SlackConnectionClient } from "./slack.generated.js"
6
7
  import { GoogleDriveOauthConnectionClient } from "./googleDriveOauth.generated.js"
7
8
  import { DiscordConnectionClient } from "./discord.generated.js"
@@ -15,6 +16,7 @@ import { OutlookConnectionClient } from "./outlook.generated.js"
15
16
  import { SalesforceConnectionClient } from "./salesforce.generated.js"
16
17
  export const connections = {
17
18
  calendar,
19
+ mail,
18
20
  slack,
19
21
  googleDriveOauth,
20
22
  discord,
@@ -29,6 +31,7 @@ export const connections = {
29
31
  }
30
32
  export type ConnectionClients = {
31
33
  calendar: CalendarConnectionClient
34
+ mail: MailConnectionClient
32
35
  slack: SlackConnectionClient
33
36
  googleDriveOauth: GoogleDriveOauthConnectionClient
34
37
  discord: DiscordConnectionClient
@@ -48,6 +51,8 @@ export function createConnectionClient(
48
51
  switch (provider) {
49
52
  case "calendar":
50
53
  return new CalendarConnectionClient(invoker)
54
+ case "mail":
55
+ return new MailConnectionClient(invoker)
51
56
  case "slack":
52
57
  return new SlackConnectionClient(invoker)
53
58
  case "googleDriveOauth":
@@ -77,6 +82,9 @@ export function createConnectionClient(
77
82
  function calendar(): WorkflowConnection<"calendar"> {
78
83
  return { type: "calendar" }
79
84
  }
85
+ function mail(): WorkflowConnection<"mail"> {
86
+ return { type: "mail" }
87
+ }
80
88
  function slack(): WorkflowConnection<"slack"> {
81
89
  return { type: "slack" }
82
90
  }
@@ -102,19 +102,25 @@ export type DiscordInteractionTrigger<TKey extends string = string> = {
102
102
  connectionKey?: TKey;
103
103
  };
104
104
 
105
- /** An email was received. */
106
- export type MailEmailReceivedTrigger = {
105
+ /** Triggers immediately when a new email is received in Notion Mail */
106
+ export type MailEmailReceivedTrigger<TKey extends string = string> = {
107
107
  type: "mail.email.received";
108
+ /** Key of the declared mail connection. */
109
+ connectionKey?: TKey;
108
110
  };
109
111
 
110
- /** An email was sent. */
111
- export type MailEmailSentTrigger = {
112
+ /** Triggers immediately when a new email is sent from Notion Mail */
113
+ export type MailEmailSentTrigger<TKey extends string = string> = {
112
114
  type: "mail.email.sent";
115
+ /** Key of the declared mail connection. */
116
+ connectionKey?: TKey;
113
117
  };
114
118
 
115
- /** A label was applied to an email. */
116
- export type MailLabelAppliedTrigger = {
119
+ /** Triggers immediately when a label is applied to an email in Notion Mail */
120
+ export type MailLabelAppliedTrigger<TKey extends string = string> = {
117
121
  type: "mail.label.applied";
122
+ /** Key of the declared mail connection. */
123
+ connectionKey?: TKey;
118
124
  };
119
125
 
120
126
  /** Triggers immediately when a calendar event is created */
@@ -248,33 +254,36 @@ export const triggers = {
248
254
  /**
249
255
  * Declare that a workflow can run on `mail.email.received` events.
250
256
  *
251
- * An email was received.
257
+ * Triggers immediately when a new email is received in Notion Mail
252
258
  */
253
- mailEmailReceived(): MailEmailReceivedTrigger {
259
+ mailEmailReceived<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): MailEmailReceivedTrigger<TKey> {
254
260
  return {
255
261
  type: "mail.email.received",
262
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
256
263
  };
257
264
  },
258
265
 
259
266
  /**
260
267
  * Declare that a workflow can run on `mail.email.sent` events.
261
268
  *
262
- * An email was sent.
269
+ * Triggers immediately when a new email is sent from Notion Mail
263
270
  */
264
- mailEmailSent(): MailEmailSentTrigger {
271
+ mailEmailSent<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): MailEmailSentTrigger<TKey> {
265
272
  return {
266
273
  type: "mail.email.sent",
274
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
267
275
  };
268
276
  },
269
277
 
270
278
  /**
271
279
  * Declare that a workflow can run on `mail.label.applied` events.
272
280
  *
273
- * A label was applied to an email.
281
+ * Triggers immediately when a label is applied to an email in Notion Mail
274
282
  */
275
- mailLabelApplied(): MailLabelAppliedTrigger {
283
+ mailLabelApplied<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): MailLabelAppliedTrigger<TKey> {
276
284
  return {
277
285
  type: "mail.label.applied",
286
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
278
287
  };
279
288
  },
280
289
 
@@ -443,9 +452,9 @@ export type WorkflowTriggerCreators<TConnections extends WorkflowConnectionDecla
443
452
  slackReactionAdded(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "slack"> }): SlackReactionAddedTrigger<WorkflowConnectionKeys<TConnections, "slack">>;
444
453
  slackAppMention(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "slack"> }): SlackAppMentionTrigger<WorkflowConnectionKeys<TConnections, "slack">>;
445
454
  discordInteraction(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "discord"> }): DiscordInteractionTrigger<WorkflowConnectionKeys<TConnections, "discord">>;
446
- mailEmailReceived(): MailEmailReceivedTrigger;
447
- mailEmailSent(): MailEmailSentTrigger;
448
- mailLabelApplied(): MailLabelAppliedTrigger;
455
+ mailEmailReceived(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "mail"> }): MailEmailReceivedTrigger<WorkflowConnectionKeys<TConnections, "mail">>;
456
+ mailEmailSent(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "mail"> }): MailEmailSentTrigger<WorkflowConnectionKeys<TConnections, "mail">>;
457
+ mailLabelApplied(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "mail"> }): MailLabelAppliedTrigger<WorkflowConnectionKeys<TConnections, "mail">>;
449
458
  calendarEventCreated(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "calendar"> }): CalendarEventCreatedTrigger<WorkflowConnectionKeys<TConnections, "calendar">>;
450
459
  calendarEventUpdated(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "calendar"> }): CalendarEventUpdatedTrigger<WorkflowConnectionKeys<TConnections, "calendar">>;
451
460
  calendarEventCanceled(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "calendar"> }): CalendarEventCanceledTrigger<WorkflowConnectionKeys<TConnections, "calendar">>;
@@ -468,9 +477,9 @@ export type WorkflowTriggerForConnections<TConnections extends WorkflowConnectio
468
477
  | SlackReactionAddedTrigger<WorkflowConnectionKeys<TConnections, "slack">>
469
478
  | SlackAppMentionTrigger<WorkflowConnectionKeys<TConnections, "slack">>
470
479
  | DiscordInteractionTrigger<WorkflowConnectionKeys<TConnections, "discord">>
471
- | MailEmailReceivedTrigger
472
- | MailEmailSentTrigger
473
- | MailLabelAppliedTrigger
480
+ | MailEmailReceivedTrigger<WorkflowConnectionKeys<TConnections, "mail">>
481
+ | MailEmailSentTrigger<WorkflowConnectionKeys<TConnections, "mail">>
482
+ | MailLabelAppliedTrigger<WorkflowConnectionKeys<TConnections, "mail">>
474
483
  | CalendarEventCreatedTrigger<WorkflowConnectionKeys<TConnections, "calendar">>
475
484
  | CalendarEventUpdatedTrigger<WorkflowConnectionKeys<TConnections, "calendar">>
476
485
  | CalendarEventCanceledTrigger<WorkflowConnectionKeys<TConnections, "calendar">>
@@ -3,6 +3,19 @@ import { triggers } from "./triggers.generated.js";
3
3
  import { connections, workflow, type WorkflowConnectionDeclarations } from "./workflow.js";
4
4
 
5
5
  it("infers only the declared provider clients", () => {
6
+ workflow({
7
+ name: "Mail",
8
+ description: "Read the configured mailbox",
9
+ connections: { inbox: connections.mail() },
10
+ triggers: ({ triggers }) => [triggers.mailEmailReceived({ connectionKey: "inbox" })],
11
+ handler(_event, context) {
12
+ expectTypeOf<keyof typeof context.connections>().toEqualTypeOf<"inbox">();
13
+ expectTypeOf(context.connections.inbox.searchEmails).toBeFunction();
14
+ expectTypeOf(context.connections.inbox.listLabels).toBeFunction();
15
+ expectTypeOf(context.connections.inbox.sendNewEmail).toBeFunction();
16
+ expectTypeOf(context.connections.inbox.createMailBlock).toBeFunction();
17
+ },
18
+ });
6
19
  workflow({
7
20
  name: "Calendar",
8
21
  description: "Calendar only",
@@ -11,6 +24,9 @@ it("infers only the declared provider clients", () => {
11
24
  handler(_event, context) {
12
25
  expectTypeOf<keyof typeof context.connections>().toEqualTypeOf<"work">();
13
26
  expectTypeOf(context.connections.work.listCalendars).toBeFunction();
27
+ expectTypeOf(context.connections.work.createEvents).toBeFunction();
28
+ expectTypeOf(context.connections.work.updateEvents).toBeFunction();
29
+ expectTypeOf(context.connections.work.cancelEvents).toBeFunction();
14
30
  },
15
31
  });
16
32
  const requirements = {