@notionhq/workers 0.2.0 → 0.4.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 (60) hide show
  1. package/dist/capabilities/ai_connector.d.ts +97 -0
  2. package/dist/capabilities/ai_connector.d.ts.map +1 -0
  3. package/dist/capabilities/ai_connector.js +54 -0
  4. package/dist/capabilities/ai_connector.test.d.ts +2 -0
  5. package/dist/capabilities/ai_connector.test.d.ts.map +1 -0
  6. package/dist/capabilities/automation.d.ts.map +1 -1
  7. package/dist/capabilities/automation.js +11 -11
  8. package/dist/capabilities/context.d.ts +2 -1
  9. package/dist/capabilities/context.d.ts.map +1 -1
  10. package/dist/capabilities/context.js +21 -3
  11. package/dist/capabilities/output.d.ts +5 -0
  12. package/dist/capabilities/output.d.ts.map +1 -0
  13. package/dist/capabilities/output.js +10 -0
  14. package/dist/capabilities/stateful-capability.d.ts +30 -0
  15. package/dist/capabilities/stateful-capability.d.ts.map +1 -0
  16. package/dist/capabilities/stateful-capability.js +50 -0
  17. package/dist/capabilities/stateful-capability.test.d.ts +2 -0
  18. package/dist/capabilities/stateful-capability.test.d.ts.map +1 -0
  19. package/dist/capabilities/sync.d.ts +9 -19
  20. package/dist/capabilities/sync.d.ts.map +1 -1
  21. package/dist/capabilities/sync.js +34 -61
  22. package/dist/capabilities/tool.d.ts +21 -0
  23. package/dist/capabilities/tool.d.ts.map +1 -1
  24. package/dist/capabilities/tool.js +8 -22
  25. package/dist/capabilities/webhook.d.ts +101 -0
  26. package/dist/capabilities/webhook.d.ts.map +1 -0
  27. package/dist/capabilities/webhook.js +47 -0
  28. package/dist/error.d.ts +36 -0
  29. package/dist/error.d.ts.map +1 -1
  30. package/dist/error.js +14 -0
  31. package/dist/index.d.ts +5 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -0
  34. package/dist/pacer_internal.d.ts +7 -0
  35. package/dist/pacer_internal.d.ts.map +1 -1
  36. package/dist/pacer_internal.js +17 -0
  37. package/dist/schema.d.ts +28 -11
  38. package/dist/schema.d.ts.map +1 -1
  39. package/dist/schema.js +2 -2
  40. package/dist/worker.d.ts +92 -9
  41. package/dist/worker.d.ts.map +1 -1
  42. package/dist/worker.js +111 -1
  43. package/package.json +2 -2
  44. package/src/capabilities/ai_connector.test.ts +341 -0
  45. package/src/capabilities/ai_connector.ts +194 -0
  46. package/src/capabilities/automation.ts +11 -7
  47. package/src/capabilities/context.ts +45 -3
  48. package/src/capabilities/output.ts +8 -0
  49. package/src/capabilities/stateful-capability.test.ts +25 -0
  50. package/src/capabilities/stateful-capability.ts +87 -0
  51. package/src/capabilities/sync.test.ts +197 -4
  52. package/src/capabilities/sync.ts +58 -87
  53. package/src/capabilities/tool.test.ts +63 -0
  54. package/src/capabilities/tool.ts +28 -13
  55. package/src/capabilities/webhook.ts +148 -0
  56. package/src/error.ts +40 -0
  57. package/src/index.ts +28 -1
  58. package/src/pacer_internal.ts +34 -0
  59. package/src/schema.ts +29 -12
  60. package/src/worker.ts +139 -10
@@ -2,6 +2,7 @@ import { Ajv } from "ajv";
2
2
  import addFormats from "ajv-formats";
3
3
  import { getSchema } from "../schema-builder.js";
4
4
  import { createCapabilityContext } from "./context.js";
5
+ import { writeOutput } from "./output.js";
5
6
  function validateRequiredProperties(schema, path = "") {
6
7
  if ("type" in schema && schema.type === "object" && "properties" in schema) {
7
8
  const propKeys = Object.keys(schema.properties).sort();
@@ -109,15 +110,11 @@ function createToolCapability(key, config) {
109
110
  _tag: "error",
110
111
  error: { name: error.name, message: error.message, trace: error.stack }
111
112
  };
112
- process.stdout.write(
113
- `
114
- <__notion_output__>${JSON.stringify(result)}</__notion_output__>
115
- `
116
- );
113
+ writeOutput(result);
117
114
  return result;
118
115
  }
119
116
  try {
120
- const capabilityContext = createCapabilityContext();
117
+ const capabilityContext = createCapabilityContext("tool");
121
118
  const result = await config.execute(input, capabilityContext);
122
119
  if (validateOutput && !validateOutput(result)) {
123
120
  const error = new InvalidToolOutputError(
@@ -134,21 +131,13 @@ function createToolCapability(key, config) {
134
131
  trace: error.stack
135
132
  }
136
133
  };
137
- process.stdout.write(
138
- `
139
- <__notion_output__>${JSON.stringify(result2)}</__notion_output__>
140
- `
141
- );
134
+ writeOutput(result2);
142
135
  return result2;
143
136
  }
144
137
  if (options?.concreteOutput) {
145
138
  return result;
146
139
  }
147
- process.stdout.write(
148
- `
149
- <__notion_output__>${JSON.stringify({ _tag: "success", value: result })}</__notion_output__>
150
- `
151
- );
140
+ writeOutput({ _tag: "success", value: result });
152
141
  return {
153
142
  _tag: "success",
154
143
  value: result
@@ -164,11 +153,7 @@ function createToolCapability(key, config) {
164
153
  _tag: "error",
165
154
  error: { name: error.name, message: error.message, trace: error.stack }
166
155
  };
167
- process.stdout.write(
168
- `
169
- <__notion_output__>${JSON.stringify(result)}</__notion_output__>
170
- `
171
- );
156
+ writeOutput(result);
172
157
  return result;
173
158
  }
174
159
  }
@@ -179,7 +164,8 @@ function createToolCapability(key, config) {
179
164
  title: config.title,
180
165
  description: config.description,
181
166
  schema: inputSchema,
182
- outputSchema
167
+ outputSchema,
168
+ hints: config.hints
183
169
  },
184
170
  handler
185
171
  };
@@ -0,0 +1,101 @@
1
+ import { ExecutionError } from "../error.js";
2
+ import type { HandlerOptions } from "../types.js";
3
+ import type { CapabilityContext } from "./context.js";
4
+ /**
5
+ * A single incoming webhook request.
6
+ */
7
+ export interface WebhookEvent {
8
+ /**
9
+ * Unique ID for this webhook delivery, stable across retries.
10
+ * Best-effort idempotency key — prefer using the webhook provider's
11
+ * own delivery/event ID when available, since providers may redeliver
12
+ * the same event with a new deliveryId.
13
+ */
14
+ deliveryId: string;
15
+ /**
16
+ * The parsed JSON body of the incoming request, or an empty object if
17
+ * the body is not valid JSON.
18
+ */
19
+ body: Record<string, unknown>;
20
+ /**
21
+ * The raw request body as a string, useful for signature verification.
22
+ */
23
+ rawBody: string;
24
+ /**
25
+ * The HTTP headers from the incoming request
26
+ */
27
+ headers: Record<string, string>;
28
+ /**
29
+ * The HTTP method of the incoming request (e.g. "POST")
30
+ */
31
+ method: string;
32
+ }
33
+ /**
34
+ * Throw this error from your webhook execute handler to signal that
35
+ * signature verification failed. After 5 consecutive verification
36
+ * failures, the platform will short-circuit and reject all incoming
37
+ * requests for this webhook without executing the handler.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * worker.webhook("onGithubPush", {
42
+ * title: "GitHub Push",
43
+ * description: "Handles GitHub push events",
44
+ * execute: async (events) => {
45
+ * const secret = process.env.GITHUB_WEBHOOK_SECRET;
46
+ * if (!secret) {
47
+ * throw new WebhookVerificationError("GITHUB_WEBHOOK_SECRET not set");
48
+ * }
49
+ * for (const event of events) {
50
+ * if (!verifyGitHubSignature(event.rawBody, event.headers, secret)) {
51
+ * throw new WebhookVerificationError("Invalid GitHub signature");
52
+ * }
53
+ * // ... handle verified event
54
+ * }
55
+ * },
56
+ * });
57
+ * ```
58
+ */
59
+ export declare class WebhookVerificationError extends ExecutionError {
60
+ constructor(cause?: unknown);
61
+ }
62
+ /**
63
+ * Configuration for a webhook capability
64
+ */
65
+ export interface WebhookConfiguration {
66
+ /**
67
+ * Title of the webhook - shown in the UI when viewing webhooks
68
+ */
69
+ title: string;
70
+ /**
71
+ * Description of what this webhook does - shown in the UI
72
+ */
73
+ description: string;
74
+ /**
75
+ * The function that executes when the webhook is triggered.
76
+ * Receives an array of events (currently always a single event,
77
+ * but may be batched in the future).
78
+ *
79
+ * To signal a verification failure, throw a `WebhookVerificationError`.
80
+ * After 5 consecutive verification failures, the platform will
81
+ * short-circuit and stop executing the handler.
82
+ *
83
+ * @param events - The incoming webhook events
84
+ * @param context - The capability execution context (Notion client, etc.)
85
+ * @returns A promise that resolves when the webhook processing completes
86
+ */
87
+ execute: (events: WebhookEvent[], context: CapabilityContext) => Promise<void> | void;
88
+ }
89
+ export type WebhookCapability = ReturnType<typeof createWebhookCapability>;
90
+ export declare function createWebhookCapability(key: string, config: WebhookConfiguration): {
91
+ _tag: "webhook";
92
+ key: string;
93
+ config: {
94
+ title: string;
95
+ description: string;
96
+ };
97
+ handler(events: WebhookEvent[], options?: HandlerOptions): Promise<{
98
+ status: "success";
99
+ } | undefined>;
100
+ };
101
+ //# sourceMappingURL=webhook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/capabilities/webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,wBAAyB,SAAQ,cAAc;gBAC/C,KAAK,CAAC,EAAE,OAAO;CAI3B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;;;;OAYG;IACH,OAAO,EAAE,CACR,MAAM,EAAE,YAAY,EAAE,EACtB,OAAO,EAAE,iBAAiB,KACtB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE3E,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,oBAAoB;;;;;;;oBAUlB,YAAY,EAAE,YACZ,cAAc,GACtB,OAAO,CAAC;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;EA6B9C"}
@@ -0,0 +1,47 @@
1
+ import { ExecutionError } from "../error.js";
2
+ import { createCapabilityContext } from "./context.js";
3
+ import { writeOutput } from "./output.js";
4
+ class WebhookVerificationError extends ExecutionError {
5
+ constructor(cause) {
6
+ super(cause ?? "Webhook signature verification failed");
7
+ this.name = "WebhookVerificationError";
8
+ }
9
+ }
10
+ function createWebhookCapability(key, config) {
11
+ return {
12
+ _tag: "webhook",
13
+ key,
14
+ config: {
15
+ title: config.title,
16
+ description: config.description
17
+ },
18
+ async handler(events, options) {
19
+ try {
20
+ const capabilityContext = createCapabilityContext("webhook");
21
+ await config.execute(events, capabilityContext);
22
+ if (options?.concreteOutput) {
23
+ return { status: "success" };
24
+ } else {
25
+ writeOutput({ _tag: "success", value: { status: "success" } });
26
+ }
27
+ } catch (err) {
28
+ const error = err instanceof ExecutionError ? err : new ExecutionError(err);
29
+ if (!options?.concreteOutput) {
30
+ writeOutput({
31
+ _tag: "error",
32
+ error: {
33
+ name: error.name,
34
+ message: error.message,
35
+ trace: error.stack
36
+ }
37
+ });
38
+ }
39
+ throw error;
40
+ }
41
+ }
42
+ };
43
+ }
44
+ export {
45
+ WebhookVerificationError,
46
+ createWebhookCapability
47
+ };
package/dist/error.d.ts CHANGED
@@ -5,6 +5,42 @@ export declare class ExecutionError extends Error {
5
5
  readonly cause: unknown;
6
6
  constructor(cause: unknown);
7
7
  }
8
+ /**
9
+ * Throw this error from your sync execute handler to signal that the
10
+ * external API returned a rate-limit response (e.g. HTTP 429).
11
+ *
12
+ * When the platform receives this error it applies exponential backoff
13
+ * instead of retrying immediately. If `retryAfter` is provided, the
14
+ * platform will wait at least that many seconds before the next attempt.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * worker.sync("issues", {
19
+ * database: issuesDb,
20
+ * execute: async (state, ctx) => {
21
+ * const res = await fetch("https://api.example.com/issues");
22
+ * if (res.status === 429) {
23
+ * const retryAfter = Number(res.headers.get("Retry-After"));
24
+ * throw new RateLimitError({
25
+ * retryAfter: Number.isFinite(retryAfter) ? retryAfter : undefined,
26
+ * });
27
+ * }
28
+ * // ...
29
+ * },
30
+ * });
31
+ * ```
32
+ */
33
+ export declare class RateLimitError extends ExecutionError {
34
+ /**
35
+ * Optional number of seconds the external API asked us to wait
36
+ * before retrying. The platform takes the max of this value and its
37
+ * own exponential-backoff delay.
38
+ */
39
+ readonly retryAfter: number | undefined;
40
+ constructor(options?: {
41
+ retryAfter?: number;
42
+ });
43
+ }
8
44
  /**
9
45
  * Helper for exhaustive switch statements. TypeScript will error if a case is not handled.
10
46
  */
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACxC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;gBAEZ,KAAK,EAAE,OAAO;CAK1B;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACxC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;gBAEZ,KAAK,EAAE,OAAO;CAK1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,cAAe,SAAQ,cAAc;IACjD;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE5B,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;CAK7C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C"}
package/dist/error.js CHANGED
@@ -6,10 +6,24 @@ class ExecutionError extends Error {
6
6
  this.cause = cause;
7
7
  }
8
8
  }
9
+ class RateLimitError extends ExecutionError {
10
+ /**
11
+ * Optional number of seconds the external API asked us to wait
12
+ * before retrying. The platform takes the max of this value and its
13
+ * own exponential-backoff delay.
14
+ */
15
+ retryAfter;
16
+ constructor(options) {
17
+ super("Rate limited by external API");
18
+ this.name = "RateLimitError";
19
+ this.retryAfter = options?.retryAfter;
20
+ }
21
+ }
9
22
  function unreachable(value) {
10
23
  throw new Error(`Unreachable: ${value}`);
11
24
  }
12
25
  export {
13
26
  ExecutionError,
27
+ RateLimitError,
14
28
  unreachable
15
29
  };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  export { emojiIcon, imageIcon, notionIcon, place } from "./builder.js";
2
+ export type { AiConnectorArchetype, AiConnectorCapability, AiConnectorChange, AiConnectorChangeUpsert, AiConnectorChatAuthor, AiConnectorChatChannel, AiConnectorChatMessage, AiConnectorChatRecord, AiConnectorConfiguration, AiConnectorExecutionResult, AiConnectorMode, AiConnectorProjectBlock, AiConnectorProjectRecord, AiConnectorRecordByArchetype, } from "./capabilities/ai_connector.js";
2
3
  export type { AutomationCapability, AutomationConfiguration, AutomationEvent, PageObjectResponse, } from "./capabilities/automation.js";
3
4
  export type { CapabilityContext } from "./capabilities/context.js";
4
5
  export type { NotionManagedOAuthConfiguration, OAuthCapability, OAuthConfiguration, UserManagedOAuthConfiguration, } from "./capabilities/oauth.js";
5
6
  export type { SyncCapability, SyncChange, SyncChangeDelete, SyncChangeUpsert, SyncConfiguration, SyncExecutionResult, SyncMode, } from "./capabilities/sync.js";
6
- export type { ToolCapability, ToolConfiguration } from "./capabilities/tool.js";
7
+ export type { ToolCapability, ToolConfiguration, ToolHints, } from "./capabilities/tool.js";
8
+ export type { WebhookCapability, WebhookConfiguration, WebhookEvent, } from "./capabilities/webhook.js";
9
+ export { WebhookVerificationError } from "./capabilities/webhook.js";
10
+ export { RateLimitError } from "./error.js";
7
11
  export type { AnyJSONSchema, JSONSchema } from "./json-schema.js";
8
12
  export type { Infer, SchemaBuilder } from "./schema-builder.js";
9
13
  export { getSchema, j } from "./schema-builder.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACvE,YAAY,EACX,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,kBAAkB,GAClB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,YAAY,EACX,+BAA+B,EAC/B,eAAe,EACf,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACX,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,GACR,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChF,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EACX,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,QAAQ,GACR,MAAM,YAAY,CAAC;AACpB,YAAY,EACX,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,cAAc,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index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AW,EACX,UAAU,EACV,QAAQ,GACR,MAAM,YAAY,CAAC;AACpB,YAAY,EACX,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,cAAc,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import { emojiIcon, imageIcon, notionIcon, place } from "./builder.js";
2
+ import { WebhookVerificationError } from "./capabilities/webhook.js";
3
+ import { RateLimitError } from "./error.js";
2
4
  import { getSchema, j } from "./schema-builder.js";
3
5
  import { Worker } from "./worker.js";
4
6
  export {
7
+ RateLimitError,
8
+ WebhookVerificationError,
5
9
  Worker,
6
10
  emojiIcon,
7
11
  getSchema,
@@ -1,6 +1,13 @@
1
1
  export type PacerState = {
2
2
  pacers: Record<string, PacerEntry>;
3
3
  };
4
+ export type PacerDeclaration = {
5
+ readonly key: string;
6
+ readonly config: {
7
+ allowedRequests: number;
8
+ intervalMs: number;
9
+ };
10
+ };
4
11
  export declare function setPacerState(state: PacerState): void;
5
12
  export declare function getPacerState(): PacerState;
6
13
  //# sourceMappingURL=pacer_internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pacer_internal.d.ts","sourceRoot":"","sources":["../src/pacer_internal.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACnC,CAAC;AAIF,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAErD;AAED,wBAAgB,aAAa,IAAI,UAAU,CAE1C"}
1
+ {"version":3,"file":"pacer_internal.d.ts","sourceRoot":"","sources":["../src/pacer_internal.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CACjE,CAAC;AAIF,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAErD;AAED,wBAAgB,aAAa,IAAI,UAAU,CAE1C"}
@@ -5,6 +5,22 @@ function setPacerState(state) {
5
5
  function getPacerState() {
6
6
  return pacerState;
7
7
  }
8
+ function initPacerState(runtimePacers, declarations) {
9
+ const pacers = runtimePacers ?? {};
10
+ if (Object.keys(pacers).length === 0 && declarations && declarations.length > 0) {
11
+ const localPacers = {};
12
+ for (const decl of declarations) {
13
+ localPacers[decl.key] = {
14
+ lastScheduledAtMs: 0,
15
+ allowedRequests: decl.config.allowedRequests,
16
+ intervalMs: decl.config.intervalMs
17
+ };
18
+ }
19
+ setPacerState({ pacers: localPacers });
20
+ } else {
21
+ setPacerState({ pacers });
22
+ }
23
+ }
8
24
  async function pacerWait(key) {
9
25
  const state = getPacerState();
10
26
  const entry = state.pacers[key];
@@ -27,6 +43,7 @@ async function pacerWait(key) {
27
43
  }
28
44
  export {
29
45
  getPacerState,
46
+ initPacerState,
30
47
  pacerWait,
31
48
  setPacerState
32
49
  };
package/dist/schema.d.ts CHANGED
@@ -48,10 +48,10 @@ export type PropertyConfiguration = {
48
48
  } | {
49
49
  type: "relation";
50
50
  /**
51
- * The export name of the sync capability that defines the related database.
52
- * This must match the export name used when defining the related sync capability.
51
+ * The key of the related database declaration.
52
+ * This must match the key passed to `worker.database()`.
53
53
  */
54
- relatedSyncKey: string;
54
+ relatedDatabaseKey: string;
55
55
  config: {
56
56
  twoWay: false;
57
57
  } | {
@@ -143,26 +143,43 @@ export declare function people(): PropertyConfiguration;
143
143
  */
144
144
  export declare function place(): PropertyConfiguration;
145
145
  /**
146
- * Creates a relation property definition that references another sync capability.
147
- * The related database must be defined by a sync capability in the same worker.
146
+ * Creates a relation property definition that references another database.
147
+ * The related database must be declared in the same worker.
148
148
  *
149
- * @param relatedSyncKey - The export name of the sync capability that defines the related database.
149
+ * @param relatedDatabaseKey - The key of the related database declaration.
150
150
  * @example
151
151
  * ```typescript
152
- * export const projectsSync = sync({...});
152
+ * const projects = worker.database("projects", {
153
+ * type: "managed",
154
+ * initialTitle: "Projects",
155
+ * primaryKeyProperty: "Project ID",
156
+ * schema: {
157
+ * properties: {
158
+ * "Project Name": Schema.title(),
159
+ * "Project ID": Schema.richText(),
160
+ * },
161
+ * },
162
+ * });
153
163
  *
154
- * export const tasksSync = sync({
164
+ * const tasks = worker.database("tasks", {
165
+ * type: "managed",
166
+ * initialTitle: "Tasks",
167
+ * primaryKeyProperty: "Task ID",
155
168
  * schema: {
156
169
  * properties: {
157
170
  * "Task Title": Schema.title(),
158
- * "Project": Schema.relation("projectsSync"),
171
+ * "Project": Schema.relation("projects"),
159
172
  * },
160
173
  * },
161
- * ...
174
+ * });
175
+ *
176
+ * export const tasksSync = worker.sync("tasksSync", {
177
+ * database: tasks,
178
+ * execute: async () => ({ changes: [], hasMore: false }),
162
179
  * });
163
180
  * ```
164
181
  */
165
- export declare function relation(relatedSyncKey: string, config?: {
182
+ export declare function relation(relatedDatabaseKey: string, config?: {
166
183
  twoWay: false;
167
184
  } | {
168
185
  twoWay: true;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB,OAAO,GACP,WAAW,GACX,KAAK,GACL,OAAO,GACP,cAAc,GACd,UAAU,GACV,MAAM,GACN,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,cAAc,GACd,QAAQ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AACH,wBAAgB,WAAW,IAAI,qBAAqB,CAEnD;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,qBAAqB,CAEhD;AAED;;GAEG;AACH,wBAAgB,IAAI,IAAI,qBAAqB,CAE5C;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,qBAAqB,CAEnE;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU,GAAG,qBAAqB,CAEpE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,qBAAqB,CAErE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,qBAAqB,CAE1E;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE;IAC9B,MAAM,EAAE,WAAW,EAAE,CAAC;CACtB,GAAG,qBAAqB,CAExB;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,qBAAqB,CAE9C;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,qBAAqB,CAE7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,QAAQ,CACvB,kBAAkB,EAAE,MAAM,EAC1B,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,GACxE,qBAAqB,CAMvB"}
package/dist/schema.js CHANGED
@@ -40,10 +40,10 @@ function people() {
40
40
  function place() {
41
41
  return { type: "place" };
42
42
  }
43
- function relation(relatedSyncKey, config) {
43
+ function relation(relatedDatabaseKey, config) {
44
44
  return {
45
45
  type: "relation",
46
- relatedSyncKey,
46
+ relatedDatabaseKey,
47
47
  config: config ?? { twoWay: false }
48
48
  };
49
49
  }
package/dist/worker.d.ts CHANGED
@@ -1,12 +1,18 @@
1
+ import type { AiConnectorArchetype, AiConnectorCapability, AiConnectorConfiguration } from "./capabilities/ai_connector.js";
1
2
  import type { AutomationCapability, AutomationConfiguration, AutomationEvent } from "./capabilities/automation.js";
2
3
  import type { CapabilityContext } from "./capabilities/context.js";
3
4
  import type { NotionManagedOAuthConfiguration, OAuthCapability, OAuthConfiguration, UserManagedOAuthConfiguration } from "./capabilities/oauth.js";
4
5
  import type { SyncCapability, SyncConfiguration } from "./capabilities/sync.js";
5
6
  import type { ToolCapability, ToolConfiguration } from "./capabilities/tool.js";
7
+ import type { WebhookCapability, WebhookConfiguration, WebhookEvent } from "./capabilities/webhook.js";
8
+ import { WebhookVerificationError } from "./capabilities/webhook.js";
9
+ import type { PacerDeclaration } from "./pacer_internal.js";
6
10
  import type { Schema } from "./schema.js";
7
11
  import type { HandlerOptions, JSONValue } from "./types.js";
8
- export type { AutomationConfiguration, AutomationEvent, CapabilityContext, OAuthConfiguration, NotionManagedOAuthConfiguration, UserManagedOAuthConfiguration, SyncConfiguration, ToolConfiguration, };
9
- type Capability = SyncCapability | ToolCapability<any, any> | AutomationCapability | OAuthCapability;
12
+ export type { AutomationConfiguration, AutomationEvent, AiConnectorConfiguration, CapabilityContext, OAuthConfiguration, NotionManagedOAuthConfiguration, UserManagedOAuthConfiguration, SyncConfiguration, ToolConfiguration, WebhookConfiguration, WebhookEvent, };
13
+ export { WebhookVerificationError };
14
+ type Capability = SyncCapability | AiConnectorCapability | ToolCapability<any, any> | AutomationCapability | OAuthCapability | WebhookCapability;
15
+ export type CapabilityType = Capability["_tag"];
10
16
  /**
11
17
  * Configuration for a database that Notion creates and manages on behalf
12
18
  * of the worker. The database is created on first deploy and its schema
@@ -87,13 +93,7 @@ export type PacerHandle = {
87
93
  */
88
94
  wait(): Promise<void>;
89
95
  };
90
- /**
91
- * A pacer declaration as it appears in the manifest.
92
- */
93
- export type PacerDeclaration = {
94
- readonly key: string;
95
- readonly config: PacerConfig;
96
- };
96
+ export type { PacerDeclaration };
97
97
  /** A capability entry stripped of its handler, used in the manifest. */
98
98
  type CapabilityManifestEntry = Pick<Capability, "_tag" | "key" | "config">;
99
99
  /**
@@ -189,6 +189,60 @@ export declare class Worker {
189
189
  * @returns The capability object.
190
190
  */
191
191
  sync<PK extends string, S extends Schema<PK>, Context = unknown>(key: string, config: SyncConfiguration<PK, S, Context>): SyncCapability;
192
+ /**
193
+ * Register an AI connector capability.
194
+ *
195
+ * Example:
196
+ *
197
+ * ```ts
198
+ * const worker = new Worker();
199
+ * export default worker;
200
+ *
201
+ * worker.aiConnector("supportChats", {
202
+ * aiConnectorId: "connector-record-id",
203
+ * archetype: "chat",
204
+ * mode: "incremental",
205
+ * schedule: "15m",
206
+ * execute: async (state) => ({
207
+ * changes: [
208
+ * {
209
+ * type: "upsert",
210
+ * key: "thread-1",
211
+ * record: {
212
+ * createdAt: "2026-01-01T00:00:00Z",
213
+ * updatedAt: "2026-01-01T00:00:00Z",
214
+ * channel: {
215
+ * id: "channel-1",
216
+ * name: "Support",
217
+ * },
218
+ * threadId: "thread-1",
219
+ * messages: [
220
+ * {
221
+ * id: "message-1",
222
+ * content: "Hello from support",
223
+ * timestamp: "2026-01-01T00:00:00Z",
224
+ * author: {
225
+ * id: "user-1",
226
+ * username: "alice",
227
+ * },
228
+ * },
229
+ * ],
230
+ * },
231
+ * },
232
+ * ],
233
+ * hasMore: false,
234
+ * }),
235
+ * });
236
+ * ```
237
+ *
238
+ * `aiConnectorId` must be the Notion record ID of an existing custom
239
+ * connector in the workspace where you deploy this worker.
240
+ *
241
+ * @param key - The unique key for this capability.
242
+ * @param config - The AI connector configuration.
243
+ * @returns The capability object.
244
+ */
245
+ aiConnector<A extends AiConnectorArchetype, Context = unknown>(key: string, config: AiConnectorConfiguration<A, Context>): AiConnectorCapability;
192
246
  /**
193
247
  * Register a tool capability.
194
248
  *
@@ -245,6 +299,35 @@ export declare class Worker {
245
299
  * @returns The capability object.
246
300
  */
247
301
  automation(key: string, config: AutomationConfiguration): AutomationCapability;
302
+ /**
303
+ * Register a webhook capability.
304
+ *
305
+ * Webhooks expose an HTTP endpoint that external services can call.
306
+ * When hit, the request is processed by the worker's execute function.
307
+ *
308
+ * Example:
309
+ *
310
+ * ```ts
311
+ * const worker = new Worker();
312
+ * export default worker;
313
+ *
314
+ * worker.webhook("onGithubPush", {
315
+ * title: "GitHub Push Webhook",
316
+ * description: "Handles push events from GitHub",
317
+ * execute: async (events, { notion }) => {
318
+ * for (const event of events) {
319
+ * console.log("Received webhook:", event.body);
320
+ * console.log("Headers:", event.headers);
321
+ * }
322
+ * },
323
+ * })
324
+ * ```
325
+ *
326
+ * @param key - The unique key for this capability. Used as the webhook name in the URL.
327
+ * @param config - The webhook configuration.
328
+ * @returns The capability object.
329
+ */
330
+ webhook(key: string, config: WebhookConfiguration): WebhookCapability;
248
331
  /**
249
332
  * Register an OAuth capability.
250
333
  *
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EACX,+BAA+B,EAC/B,eAAe,EACf,kBAAkB,EAClB,6BAA6B,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5D,YAAY,EACX,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,+BAA+B,EAC/B,6BAA6B,EA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