@notionhq/workers 0.3.0 → 0.5.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/block.d.ts +1 -1
- package/dist/block.d.ts.map +1 -1
- package/dist/builder.d.ts +7 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +13 -0
- package/dist/capabilities/ai_connector.js +1 -1
- package/dist/capabilities/automation.js +1 -1
- package/dist/capabilities/context.d.ts +2 -1
- package/dist/capabilities/context.d.ts.map +1 -1
- package/dist/capabilities/context.js +21 -3
- package/dist/capabilities/stateful-capability.js +1 -1
- package/dist/capabilities/sync.d.ts +11 -1
- package/dist/capabilities/sync.d.ts.map +1 -1
- package/dist/capabilities/sync.js +25 -5
- package/dist/capabilities/tool.d.ts +21 -0
- package/dist/capabilities/tool.d.ts.map +1 -1
- package/dist/capabilities/tool.js +3 -2
- package/dist/capabilities/webhook.js +1 -1
- package/dist/capabilities/workflow.d.ts +50 -0
- package/dist/capabilities/workflow.d.ts.map +1 -0
- package/dist/capabilities/workflow.js +40 -0
- package/dist/capabilities/workflow.test.d.ts +2 -0
- package/dist/capabilities/workflow.test.d.ts.map +1 -0
- package/dist/error.d.ts +36 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +14 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/schema-builder.d.ts.map +1 -1
- package/dist/triggers.d.ts +365 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.generated.d.ts +246 -0
- package/dist/triggers.generated.d.ts.map +1 -0
- package/dist/triggers.generated.js +239 -0
- package/dist/triggers.js +0 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/worker.d.ts +33 -2
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +34 -0
- package/package.json +9 -2
- package/src/block.ts +40 -40
- package/src/builder.ts +20 -0
- package/src/capabilities/ai_connector.ts +1 -1
- package/src/capabilities/automation.ts +1 -1
- package/src/capabilities/context.ts +45 -3
- package/src/capabilities/stateful-capability.ts +1 -1
- package/src/capabilities/sync.test.ts +172 -1
- package/src/capabilities/sync.ts +46 -5
- package/src/capabilities/tool.test.ts +63 -0
- package/src/capabilities/tool.ts +23 -1
- package/src/capabilities/webhook.ts +1 -1
- package/src/capabilities/workflow.test.ts +184 -0
- package/src/capabilities/workflow.ts +119 -0
- package/src/error.ts +40 -0
- package/src/index.ts +22 -2
- package/src/schema-builder.ts +1 -0
- package/src/triggers.generated.ts +489 -0
- package/src/triggers.ts +504 -0
- package/src/types.ts +20 -0
- package/src/worker.ts +101 -8
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
const triggers = {
|
|
2
|
+
/**
|
|
3
|
+
* Declare that a workflow can run on `slack.message` events.
|
|
4
|
+
*
|
|
5
|
+
* A message was posted in a subscribed Slack channel.
|
|
6
|
+
*/
|
|
7
|
+
slackMessage() {
|
|
8
|
+
return {
|
|
9
|
+
type: "slack.message"
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
/**
|
|
13
|
+
* Declare that a workflow can run on `slack.reaction.added` events.
|
|
14
|
+
*
|
|
15
|
+
* A reaction was added to a Slack message.
|
|
16
|
+
*/
|
|
17
|
+
slackReactionAdded() {
|
|
18
|
+
return {
|
|
19
|
+
type: "slack.reaction.added"
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Declare that a workflow can run on `slack.app.mention` events.
|
|
24
|
+
*
|
|
25
|
+
* The Notion app was mentioned in a Slack message.
|
|
26
|
+
*/
|
|
27
|
+
slackAppMention() {
|
|
28
|
+
return {
|
|
29
|
+
type: "slack.app.mention"
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Declare that a workflow can run on `discord.interaction` events.
|
|
34
|
+
*
|
|
35
|
+
* A Discord interaction was received.
|
|
36
|
+
*/
|
|
37
|
+
discordInteraction() {
|
|
38
|
+
return {
|
|
39
|
+
type: "discord.interaction"
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Declare that a workflow can run on `mail.email.received` events.
|
|
44
|
+
*
|
|
45
|
+
* An email was received.
|
|
46
|
+
*/
|
|
47
|
+
mailEmailReceived() {
|
|
48
|
+
return {
|
|
49
|
+
type: "mail.email.received"
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* Declare that a workflow can run on `mail.email.sent` events.
|
|
54
|
+
*
|
|
55
|
+
* An email was sent.
|
|
56
|
+
*/
|
|
57
|
+
mailEmailSent() {
|
|
58
|
+
return {
|
|
59
|
+
type: "mail.email.sent"
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Declare that a workflow can run on `mail.label.applied` events.
|
|
64
|
+
*
|
|
65
|
+
* A label was applied to an email.
|
|
66
|
+
*/
|
|
67
|
+
mailLabelApplied() {
|
|
68
|
+
return {
|
|
69
|
+
type: "mail.label.applied"
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* Declare that a workflow can run on `calendar.event.created` events.
|
|
74
|
+
*
|
|
75
|
+
* A calendar event was created.
|
|
76
|
+
*/
|
|
77
|
+
calendarEventCreated() {
|
|
78
|
+
return {
|
|
79
|
+
type: "calendar.event.created"
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Declare that a workflow can run on `calendar.event.updated` events.
|
|
84
|
+
*
|
|
85
|
+
* A calendar event was updated.
|
|
86
|
+
*/
|
|
87
|
+
calendarEventUpdated() {
|
|
88
|
+
return {
|
|
89
|
+
type: "calendar.event.updated"
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Declare that a workflow can run on `calendar.event.canceled` events.
|
|
94
|
+
*
|
|
95
|
+
* A calendar event was canceled.
|
|
96
|
+
*/
|
|
97
|
+
calendarEventCanceled() {
|
|
98
|
+
return {
|
|
99
|
+
type: "calendar.event.canceled"
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* Declare that a workflow can run on `notion.page.created` events.
|
|
104
|
+
*
|
|
105
|
+
* A page has been added to a database.
|
|
106
|
+
*/
|
|
107
|
+
notionPageCreated() {
|
|
108
|
+
return {
|
|
109
|
+
type: "notion.page.created"
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* Declare that a workflow can run on `notion.page.updated` events.
|
|
114
|
+
*
|
|
115
|
+
* A page was updated.
|
|
116
|
+
*/
|
|
117
|
+
notionPageUpdated() {
|
|
118
|
+
return {
|
|
119
|
+
type: "notion.page.updated"
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Declare that a workflow can run on `notion.page.deleted` events.
|
|
124
|
+
*
|
|
125
|
+
* A page was deleted.
|
|
126
|
+
*/
|
|
127
|
+
notionPageDeleted() {
|
|
128
|
+
return {
|
|
129
|
+
type: "notion.page.deleted"
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Declare that a workflow can run on `notion.meetingNote.summary.completed` events.
|
|
134
|
+
*
|
|
135
|
+
* A meeting note's AI summary finished generating.
|
|
136
|
+
*/
|
|
137
|
+
notionMeetingNoteSummaryCompleted() {
|
|
138
|
+
return {
|
|
139
|
+
type: "notion.meetingNote.summary.completed"
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Declare that a workflow can run on `notion.page.discussion.comment.added` events.
|
|
144
|
+
*
|
|
145
|
+
* A comment was added to a page discussion.
|
|
146
|
+
*/
|
|
147
|
+
notionCommentAdded() {
|
|
148
|
+
return {
|
|
149
|
+
type: "notion.page.discussion.comment.added"
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
/**
|
|
153
|
+
* Declare that a workflow can run on `notion.agent.mentioned` events.
|
|
154
|
+
*
|
|
155
|
+
* An agent was mentioned in page content or a person property.
|
|
156
|
+
*/
|
|
157
|
+
notionAgentMentioned() {
|
|
158
|
+
return {
|
|
159
|
+
type: "notion.agent.mentioned"
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* Declare that a workflow can run on `notion.button.pressed` events.
|
|
164
|
+
*
|
|
165
|
+
* A button block was pressed.
|
|
166
|
+
*/
|
|
167
|
+
notionButtonPressed() {
|
|
168
|
+
return {
|
|
169
|
+
type: "notion.button.pressed"
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Declare that a workflow can run on `notion.database.agent.updated` events.
|
|
174
|
+
*
|
|
175
|
+
* A database agent's configuration was updated.
|
|
176
|
+
*/
|
|
177
|
+
notionDatabaseAgentUpdated() {
|
|
178
|
+
return {
|
|
179
|
+
type: "notion.database.agent.updated"
|
|
180
|
+
};
|
|
181
|
+
},
|
|
182
|
+
/**
|
|
183
|
+
* Declare that a workflow can run on `webhooks.webhook` events.
|
|
184
|
+
*
|
|
185
|
+
* An incoming webhook request was received.
|
|
186
|
+
*/
|
|
187
|
+
webhook() {
|
|
188
|
+
return {
|
|
189
|
+
type: "webhooks.webhook"
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* Declare that a workflow can run on `googleDriveOauth.filesChanged` events.
|
|
194
|
+
*
|
|
195
|
+
* Files changed in a watched Google Drive folder or drive.
|
|
196
|
+
*/
|
|
197
|
+
googleDriveOauthFilesChanged() {
|
|
198
|
+
return {
|
|
199
|
+
type: "googleDriveOauth.filesChanged"
|
|
200
|
+
};
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* Declare that a workflow can run on `recurrence` events.
|
|
204
|
+
*
|
|
205
|
+
* A recurring schedule fired.
|
|
206
|
+
*/
|
|
207
|
+
recurrence() {
|
|
208
|
+
return {
|
|
209
|
+
type: "recurrence"
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const WORKFLOW_TRIGGER_TYPES = [
|
|
214
|
+
"slack.message",
|
|
215
|
+
"slack.reaction.added",
|
|
216
|
+
"slack.app.mention",
|
|
217
|
+
"discord.interaction",
|
|
218
|
+
"mail.email.received",
|
|
219
|
+
"mail.email.sent",
|
|
220
|
+
"mail.label.applied",
|
|
221
|
+
"calendar.event.created",
|
|
222
|
+
"calendar.event.updated",
|
|
223
|
+
"calendar.event.canceled",
|
|
224
|
+
"notion.page.created",
|
|
225
|
+
"notion.page.updated",
|
|
226
|
+
"notion.page.deleted",
|
|
227
|
+
"notion.meetingNote.summary.completed",
|
|
228
|
+
"notion.page.discussion.comment.added",
|
|
229
|
+
"notion.agent.mentioned",
|
|
230
|
+
"notion.button.pressed",
|
|
231
|
+
"notion.database.agent.updated",
|
|
232
|
+
"webhooks.webhook",
|
|
233
|
+
"googleDriveOauth.filesChanged",
|
|
234
|
+
"recurrence"
|
|
235
|
+
];
|
|
236
|
+
export {
|
|
237
|
+
WORKFLOW_TRIGGER_TYPES,
|
|
238
|
+
triggers
|
|
239
|
+
};
|
package/dist/triggers.js
ADDED
|
File without changes
|
package/dist/types.d.ts
CHANGED
|
@@ -122,6 +122,24 @@ export interface ImageIcon {
|
|
|
122
122
|
* All possible icon types
|
|
123
123
|
*/
|
|
124
124
|
export type Icon = EmojiIcon | NoticonIcon | ImageIcon;
|
|
125
|
+
/**
|
|
126
|
+
* Cover image for a Notion page.
|
|
127
|
+
*/
|
|
128
|
+
export interface ImageCover {
|
|
129
|
+
type: "image";
|
|
130
|
+
/**
|
|
131
|
+
* The URL of the image (must be a valid http/https URL)
|
|
132
|
+
*/
|
|
133
|
+
url: string;
|
|
134
|
+
/**
|
|
135
|
+
* Vertical image position, from 0 (top) to 1 (bottom).
|
|
136
|
+
*/
|
|
137
|
+
position?: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* All possible cover types
|
|
141
|
+
*/
|
|
142
|
+
export type Cover = ImageCover;
|
|
125
143
|
/**
|
|
126
144
|
* Person reference - represents a user in a people property
|
|
127
145
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,GAClB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEhC;;;GAGG;AACH,KAAK,SAAS,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,WAAW,GACpB,SAAS,GACT,MAAM,GACN,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,GACN,QAAQ,GACR,MAAM,GACN,KAAK,CAAC;AAET;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,YAAY,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAA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YAAY,GAAG,QAAQ,GAAG,cAAc,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C,MAAM,MAAM,cAAc,GAAG;IAC5B,cAAc,CAAC,EAAE,IAAI,CAAC;CACtB,CAAC"}
|
package/dist/worker.d.ts
CHANGED
|
@@ -6,12 +6,15 @@ import type { SyncCapability, SyncConfiguration } from "./capabilities/sync.js";
|
|
|
6
6
|
import type { ToolCapability, ToolConfiguration } from "./capabilities/tool.js";
|
|
7
7
|
import type { WebhookCapability, WebhookConfiguration, WebhookEvent } from "./capabilities/webhook.js";
|
|
8
8
|
import { WebhookVerificationError } from "./capabilities/webhook.js";
|
|
9
|
+
import type { WorkflowCapability, WorkflowConfiguration, WorkflowEvent } from "./capabilities/workflow.js";
|
|
9
10
|
import type { PacerDeclaration } from "./pacer_internal.js";
|
|
10
11
|
import type { Schema } from "./schema.js";
|
|
12
|
+
import type { WorkflowTrigger } from "./triggers.generated.js";
|
|
11
13
|
import type { HandlerOptions, JSONValue } from "./types.js";
|
|
12
|
-
export type { AutomationConfiguration, AutomationEvent,
|
|
14
|
+
export type { AiConnectorConfiguration, AutomationConfiguration, AutomationEvent, CapabilityContext, NotionManagedOAuthConfiguration, OAuthConfiguration, SyncConfiguration, ToolConfiguration, UserManagedOAuthConfiguration, WebhookConfiguration, WebhookEvent, WorkflowConfiguration, WorkflowEvent, };
|
|
13
15
|
export { WebhookVerificationError };
|
|
14
|
-
type Capability = SyncCapability | AiConnectorCapability | ToolCapability<any, any> | AutomationCapability | OAuthCapability | WebhookCapability;
|
|
16
|
+
type Capability = SyncCapability | AiConnectorCapability | ToolCapability<any, any> | AutomationCapability | WorkflowCapability | OAuthCapability | WebhookCapability;
|
|
17
|
+
export type CapabilityType = Capability["_tag"];
|
|
15
18
|
/**
|
|
16
19
|
* Configuration for a database that Notion creates and manages on behalf
|
|
17
20
|
* of the worker. The database is created on first deploy and its schema
|
|
@@ -298,6 +301,34 @@ export declare class Worker {
|
|
|
298
301
|
* @returns The capability object.
|
|
299
302
|
*/
|
|
300
303
|
automation(key: string, config: AutomationConfiguration): AutomationCapability;
|
|
304
|
+
/**
|
|
305
|
+
* Register a workflow capability.
|
|
306
|
+
*
|
|
307
|
+
* Example:
|
|
308
|
+
*
|
|
309
|
+
* ```ts
|
|
310
|
+
* import { Worker } from "@notionhq/workers";
|
|
311
|
+
* import { triggers } from "@notionhq/workers/triggers";
|
|
312
|
+
*
|
|
313
|
+
* const worker = new Worker();
|
|
314
|
+
* export default worker;
|
|
315
|
+
*
|
|
316
|
+
* worker.workflow("sendWelcomeEmail", {
|
|
317
|
+
* title: "Send Welcome Email",
|
|
318
|
+
* description: "Sends a welcome email when a new user is added",
|
|
319
|
+
* triggers: [triggers.notionPageCreated()],
|
|
320
|
+
* execute: async (event) => {
|
|
321
|
+
* console.log(event.page);
|
|
322
|
+
* console.log(event.content);
|
|
323
|
+
* },
|
|
324
|
+
* })
|
|
325
|
+
* ```
|
|
326
|
+
*
|
|
327
|
+
* @param key - The unique key for this capability.
|
|
328
|
+
* @param config - The workflow configuration.
|
|
329
|
+
* @returns The capability object.
|
|
330
|
+
*/
|
|
331
|
+
workflow<const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]]>(key: string, config: WorkflowConfiguration<TTriggers>): WorkflowCapability<TTriggers>;
|
|
301
332
|
/**
|
|
302
333
|
* Register a webhook capability.
|
|
303
334
|
*
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,MAAM,gCA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;;;;;;OA+BG;IACH,UAAU,CACT,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,uBAAuB,GAC7B,oBAAoB;IAOvB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,QAAQ,CACP,KAAK,CAAC,SAAS,SAAS,SAAS,CAAC,eAAe,EAAE,GAAG,eAAe,EAAE,CAAC,EAExE,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC,GACtC,kBAAkB,CAAC,SAAS,CAAC;IAOhC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,iBAAiB;IAOrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,GAAG,eAAe;IAO/D;;OAEG;IACH,IAAI,YAAY,IAAI,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC,EAAE,CAMhE;IAED,IAAI,QAAQ,IAAI,cAAc,CAO7B;IAED;;;;;;;OAOG;IACG,GAAG,CACR,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,cAAmB,GAC1B,OAAO,CAAC,OAAO,CAAC;CAoCnB"}
|
package/dist/worker.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createWebhookCapability,
|
|
8
8
|
WebhookVerificationError
|
|
9
9
|
} from "./capabilities/webhook.js";
|
|
10
|
+
import { createWorkflowCapability } from "./capabilities/workflow.js";
|
|
10
11
|
import { pacerWait } from "./pacer_internal.js";
|
|
11
12
|
import { createRequire } from "node:module";
|
|
12
13
|
const SDK_VERSION = (() => {
|
|
@@ -253,6 +254,39 @@ class Worker {
|
|
|
253
254
|
this.#capabilities.set(key, capability);
|
|
254
255
|
return capability;
|
|
255
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Register a workflow capability.
|
|
259
|
+
*
|
|
260
|
+
* Example:
|
|
261
|
+
*
|
|
262
|
+
* ```ts
|
|
263
|
+
* import { Worker } from "@notionhq/workers";
|
|
264
|
+
* import { triggers } from "@notionhq/workers/triggers";
|
|
265
|
+
*
|
|
266
|
+
* const worker = new Worker();
|
|
267
|
+
* export default worker;
|
|
268
|
+
*
|
|
269
|
+
* worker.workflow("sendWelcomeEmail", {
|
|
270
|
+
* title: "Send Welcome Email",
|
|
271
|
+
* description: "Sends a welcome email when a new user is added",
|
|
272
|
+
* triggers: [triggers.notionPageCreated()],
|
|
273
|
+
* execute: async (event) => {
|
|
274
|
+
* console.log(event.page);
|
|
275
|
+
* console.log(event.content);
|
|
276
|
+
* },
|
|
277
|
+
* })
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @param key - The unique key for this capability.
|
|
281
|
+
* @param config - The workflow configuration.
|
|
282
|
+
* @returns The capability object.
|
|
283
|
+
*/
|
|
284
|
+
workflow(key, config) {
|
|
285
|
+
this.#validateUniqueKey(key);
|
|
286
|
+
const capability = createWorkflowCapability(key, config);
|
|
287
|
+
this.#capabilities.set(key, capability);
|
|
288
|
+
return capability;
|
|
289
|
+
}
|
|
256
290
|
/**
|
|
257
291
|
* Register a webhook capability.
|
|
258
292
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notionhq/workers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "An SDK for building workers for the Notion Workers platform",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"types": "./dist/schema-builder.d.ts",
|
|
30
30
|
"default": "./dist/schema-builder.js"
|
|
31
31
|
},
|
|
32
|
+
"./triggers": {
|
|
33
|
+
"types": "./dist/triggers.generated.d.ts",
|
|
34
|
+
"default": "./dist/triggers.generated.js"
|
|
35
|
+
},
|
|
32
36
|
"./types": {
|
|
33
37
|
"types": "./dist/types.d.ts",
|
|
34
38
|
"default": "./dist/types.js"
|
|
@@ -59,6 +63,9 @@
|
|
|
59
63
|
"build:watch": "concurrently --group \"npm run build:watch:types\" \"npm run build:watch:js\"",
|
|
60
64
|
"build:watch:types": "tsc --watch",
|
|
61
65
|
"build:watch:js": "esbuild --watch --format=esm --outdir=dist --target=esnext --packages=external ./src/**.ts ./src/**/*.ts",
|
|
66
|
+
"generate": "tsx scripts/generate-triggers.ts",
|
|
67
|
+
"generate:check": "tsx scripts/generate-triggers.ts --check",
|
|
68
|
+
"sync:triggers": "tsx scripts/sync-triggers.ts",
|
|
62
69
|
"test": "vitest run"
|
|
63
70
|
},
|
|
64
71
|
"devDependencies": {
|
|
@@ -70,7 +77,7 @@
|
|
|
70
77
|
"vitest": "^4.0.8"
|
|
71
78
|
},
|
|
72
79
|
"peerDependencies": {
|
|
73
|
-
"@notionhq/client": "
|
|
80
|
+
"@notionhq/client": ">=2.2.15"
|
|
74
81
|
},
|
|
75
82
|
"dependencies": {
|
|
76
83
|
"ajv": "^8.17.1",
|
package/src/block.ts
CHANGED
|
@@ -473,57 +473,57 @@ type Block =
|
|
|
473
473
|
|
|
474
474
|
// Export all types
|
|
475
475
|
export type {
|
|
476
|
-
|
|
477
|
-
RichTextItem,
|
|
478
|
-
RichTextBase,
|
|
479
|
-
RichTextAnnotations,
|
|
480
|
-
TextContent,
|
|
481
|
-
EquationContent,
|
|
482
|
-
MentionContent,
|
|
483
|
-
DateMention,
|
|
484
|
-
CustomEmojiMention,
|
|
485
|
-
LinkPreviewMention,
|
|
486
|
-
LinkMention,
|
|
476
|
+
AIBlock,
|
|
487
477
|
ApiColor,
|
|
488
|
-
|
|
478
|
+
AudioBlock,
|
|
479
|
+
Block,
|
|
480
|
+
BlockBase,
|
|
481
|
+
BookmarkBlock,
|
|
482
|
+
BreadcrumbBlock,
|
|
483
|
+
BulletedListItemBlock,
|
|
484
|
+
CalloutBlock,
|
|
485
|
+
ChildDatabaseBlock,
|
|
486
|
+
ChildPageBlock,
|
|
487
|
+
CodeBlock,
|
|
488
|
+
ColumnBlock,
|
|
489
|
+
ColumnListBlock,
|
|
490
|
+
CustomEmojiMention,
|
|
491
|
+
DateMention,
|
|
492
|
+
DividerBlock,
|
|
493
|
+
EmbedBlock,
|
|
489
494
|
EmojiIcon,
|
|
495
|
+
EquationBlock,
|
|
496
|
+
EquationContent,
|
|
497
|
+
ExternalFile,
|
|
490
498
|
ExternalIcon,
|
|
499
|
+
FileBlock,
|
|
491
500
|
FileIcon,
|
|
492
501
|
FileObject,
|
|
493
|
-
ExternalFile,
|
|
494
|
-
HostedFile,
|
|
495
|
-
BlockBase,
|
|
496
|
-
ParagraphBlock,
|
|
497
502
|
Heading1Block,
|
|
498
503
|
Heading2Block,
|
|
499
504
|
Heading3Block,
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
ToDoBlock,
|
|
503
|
-
ToggleBlock,
|
|
504
|
-
QuoteBlock,
|
|
505
|
-
CalloutBlock,
|
|
506
|
-
CodeBlock,
|
|
507
|
-
EquationBlock,
|
|
508
|
-
DividerBlock,
|
|
509
|
-
BreadcrumbBlock,
|
|
510
|
-
TableOfContentsBlock,
|
|
511
|
-
ColumnListBlock,
|
|
512
|
-
ColumnBlock,
|
|
505
|
+
HostedFile,
|
|
506
|
+
Icon,
|
|
513
507
|
ImageBlock,
|
|
514
|
-
|
|
515
|
-
AudioBlock,
|
|
516
|
-
PDFBlock,
|
|
517
|
-
FileBlock,
|
|
518
|
-
EmbedBlock,
|
|
519
|
-
BookmarkBlock,
|
|
508
|
+
LinkMention,
|
|
520
509
|
LinkPreviewBlock,
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
510
|
+
LinkPreviewMention,
|
|
511
|
+
MentionContent,
|
|
512
|
+
NumberedListItemBlock,
|
|
513
|
+
ParagraphBlock,
|
|
514
|
+
PDFBlock,
|
|
515
|
+
QuoteBlock,
|
|
516
|
+
RichText,
|
|
517
|
+
RichTextAnnotations,
|
|
518
|
+
RichTextBase,
|
|
519
|
+
RichTextItem,
|
|
524
520
|
TableBlock,
|
|
521
|
+
TableOfContentsBlock,
|
|
525
522
|
TableRowBlock,
|
|
526
|
-
|
|
523
|
+
TemplateBlock,
|
|
524
|
+
TextContent,
|
|
525
|
+
ToDoBlock,
|
|
526
|
+
ToggleBlock,
|
|
527
527
|
UnsupportedBlock,
|
|
528
|
-
|
|
528
|
+
VideoBlock,
|
|
529
529
|
};
|
package/src/builder.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NoticonName } from "./icon-names.js";
|
|
2
2
|
import type {
|
|
3
|
+
Cover,
|
|
3
4
|
DateValue,
|
|
4
5
|
Icon,
|
|
5
6
|
NoticonColor,
|
|
@@ -310,3 +311,22 @@ export function imageIcon(url: string): Icon {
|
|
|
310
311
|
url,
|
|
311
312
|
};
|
|
312
313
|
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Creates an image cover from an external URL.
|
|
317
|
+
* @param url - The URL of the image (e.g., "https://example.com/cover.png")
|
|
318
|
+
* @param position - Vertical image position, from 0 (top) to 1 (bottom). Defaults to 0.5.
|
|
319
|
+
*/
|
|
320
|
+
export function imageCover(url: string, position = 0.5): Cover {
|
|
321
|
+
if (!Number.isFinite(position) || position < 0 || position > 1) {
|
|
322
|
+
throw new Error(
|
|
323
|
+
`Invalid cover position: ${position}. Expected a number between 0 and 1.`,
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
type: "image",
|
|
329
|
+
url,
|
|
330
|
+
position,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
@@ -154,7 +154,7 @@ export function createAiConnectorCapability<
|
|
|
154
154
|
runtimeContext?: StatefulRuntimeContext<State>,
|
|
155
155
|
options?: HandlerOptions,
|
|
156
156
|
) {
|
|
157
|
-
const capabilityContext = createCapabilityContext();
|
|
157
|
+
const capabilityContext = createCapabilityContext("ai_connector");
|
|
158
158
|
const state = runtimeContext?.state ?? runtimeContext?.userContext;
|
|
159
159
|
|
|
160
160
|
initPacerState(runtimeContext?.pacers, pacerDeclarations);
|
|
@@ -105,7 +105,7 @@ export function createAutomationCapability(
|
|
|
105
105
|
options?: HandlerOptions,
|
|
106
106
|
): Promise<{ status: "success" } | undefined> {
|
|
107
107
|
try {
|
|
108
|
-
const capabilityContext = createCapabilityContext();
|
|
108
|
+
const capabilityContext = createCapabilityContext("automation");
|
|
109
109
|
await config.execute(event, capabilityContext);
|
|
110
110
|
|
|
111
111
|
if (options?.concreteOutput) {
|
|
@@ -1,22 +1,64 @@
|
|
|
1
1
|
import { Client } from "@notionhq/client";
|
|
2
2
|
import type { ClientOptions } from "@notionhq/client/build/src/Client.js";
|
|
3
|
+
import type { CapabilityType } from "../worker.js";
|
|
3
4
|
|
|
4
5
|
export type CapabilityContext = {
|
|
5
6
|
/** Notion API SDK client for this execution. */
|
|
6
7
|
notion: Client;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
const FIX_STEPS =
|
|
11
|
+
"\n\nTo fix this:\n" +
|
|
12
|
+
"1. Create a connection at https://app.notion.com/developers/connections\n" +
|
|
13
|
+
"2. Give the connection access to the relevant pages/databases\n" +
|
|
14
|
+
"3. Add NOTION_API_TOKEN=<your-token> to your .env file\n" +
|
|
15
|
+
"4. For deployed workers, run: ntn workers env push";
|
|
16
|
+
|
|
17
|
+
function missingTokenMessage(capabilityType: CapabilityType): string {
|
|
18
|
+
if (capabilityType === "tool") {
|
|
19
|
+
return (
|
|
20
|
+
"NOTION_API_TOKEN is not set. " +
|
|
21
|
+
"When tools are called through a Custom Agent, the platform sets NOTION_API_TOKEN automatically, " +
|
|
22
|
+
"using the permissions of the Custom Agent. " +
|
|
23
|
+
"Outside of that context (e.g. ntn workers exec), you must set it yourself." +
|
|
24
|
+
FIX_STEPS
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
"NOTION_API_TOKEN is not set. " +
|
|
30
|
+
`context.notion requires an API token to make requests in ${capabilityType} capabilities to Notion.` +
|
|
31
|
+
FIX_STEPS
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createUnauthenticatedNotionProxy(
|
|
36
|
+
capabilityType: CapabilityType,
|
|
37
|
+
): Client {
|
|
38
|
+
return new Proxy({} as Client, {
|
|
39
|
+
get(_target, prop) {
|
|
40
|
+
if (prop === "then" || typeof prop === "symbol") {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
throw new Error(missingTokenMessage(capabilityType));
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createCapabilityContext(
|
|
49
|
+
capabilityType: CapabilityType,
|
|
50
|
+
): CapabilityContext {
|
|
10
51
|
const options: ClientOptions = {};
|
|
11
52
|
|
|
12
53
|
if (process.env.NOTION_API_BASE_URL) {
|
|
13
54
|
options.baseUrl = process.env.NOTION_API_BASE_URL;
|
|
14
55
|
}
|
|
15
56
|
|
|
16
|
-
if (process.env.NOTION_API_TOKEN) {
|
|
17
|
-
|
|
57
|
+
if (!process.env.NOTION_API_TOKEN) {
|
|
58
|
+
return { notion: createUnauthenticatedNotionProxy(capabilityType) };
|
|
18
59
|
}
|
|
19
60
|
|
|
61
|
+
options.auth = process.env.NOTION_API_TOKEN;
|
|
20
62
|
const notion = new Client(options);
|
|
21
63
|
|
|
22
64
|
return { notion };
|
|
@@ -48,7 +48,7 @@ export function parseSchedule(schedule: Schedule): SyncSchedule {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const match = schedule.match(/^(\d+)(m|h|d)$/);
|
|
51
|
-
if (!match
|
|
51
|
+
if (!match?.[1] || !match[2]) {
|
|
52
52
|
throw new Error(
|
|
53
53
|
`Invalid schedule format: "${schedule}". Use "continuous" or an interval like "30m", "1h", "1d".`,
|
|
54
54
|
);
|