@notionhq/apps 0.0.29 → 0.0.31
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/notion-as-code/custom-agent.d.ts +6 -5
- package/dist/notion-as-code/custom-agent.d.ts.map +1 -1
- package/dist/notion-as-code/custom-agent.js +15 -4
- package/dist/notion-as-code/index.d.ts +1 -1
- package/dist/notion-as-code/index.d.ts.map +1 -1
- package/dist/notion-as-code/intents.d.ts +7 -1
- package/dist/notion-as-code/intents.d.ts.map +1 -1
- package/dist/workflow-access.d.ts +8 -3
- package/dist/workflow-access.d.ts.map +1 -1
- package/dist/workflow-access.js +33 -34
- package/dist/workflow.d.ts +1 -1
- package/dist/workflow.d.ts.map +1 -1
- package/package.json +1 -3
- package/skills/notion-as-code/SKILL.md +10 -7
- package/src/index.ts +1 -1
- package/src/notion-as-code/custom-agent.test.ts +62 -3
- package/src/notion-as-code/custom-agent.ts +19 -10
- package/src/notion-as-code/index.ts +0 -1
- package/src/notion-as-code/intents.ts +4 -1
- package/src/notion-as-code/notion-as-code-types.test.ts +21 -11
- package/src/workflow-access.ts +56 -51
- package/src/workflow.ts +1 -1
- package/AGENTS.md +0 -137
- package/docs/BUILD.md +0 -268
- package/docs/CONNECTIONS.md +0 -213
- package/docs/workflow-inputs.md +0 -28
package/docs/CONNECTIONS.md
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
# Workflow connections
|
|
2
|
-
|
|
3
|
-
Workflow connections declare services that a workflow needs to work properly. Connections require explicit authentication during setup before the workflow can use them. Each connection has a stable binding that links it to its configured credentials and permissions.
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
import { workflow } from "@notionhq/apps";
|
|
7
|
-
import { connections } from "@notionhq/apps/workflow";
|
|
8
|
-
import { triggers } from "@notionhq/apps/triggers";
|
|
9
|
-
|
|
10
|
-
export default workflow({
|
|
11
|
-
name: "List work calendars",
|
|
12
|
-
description: "List calendars available through the work connection",
|
|
13
|
-
triggers: [triggers.notionPageCreated()],
|
|
14
|
-
connections: { work: connections.calendar() },
|
|
15
|
-
handler: async (_event, context) => {
|
|
16
|
-
const calendars = await context.connections.work.listCalendars({});
|
|
17
|
-
console.log(calendars.accounts);
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
The object property name is the connection key. Provider factories do not take a key option. Keys must begin with a letter and contain at most 128 letters, numbers, underscores, or hyphens; `constructor` and `prototype` are reserved. A workflow can declare up to 100 connections.
|
|
23
|
-
|
|
24
|
-
## Trigger a workflow from a connection
|
|
25
|
-
|
|
26
|
-
Use a trigger callback to check connection keys against the workflow’s declared providers:
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
export default workflow({
|
|
30
|
-
name: "Support messages",
|
|
31
|
-
description: "Run when a message arrives in the configured support channel",
|
|
32
|
-
connections: { support: connections.slack() },
|
|
33
|
-
triggers: ({ triggers }) => [triggers.slackMessage({ connectionKey: "support" })],
|
|
34
|
-
handler: async (event, context) => {
|
|
35
|
-
console.log(event);
|
|
36
|
-
const user = await context.connections.support.findUserByEmail({
|
|
37
|
-
email: "person@example.com",
|
|
38
|
-
});
|
|
39
|
-
console.log(user);
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
The callback’s `triggers.slackMessage` accepts only Slack keys declared in `connections`. In this example, `"typo"` is a type error, and a Calendar connection named `"support"` would not satisfy a Slack trigger. Keys come from the object properties, so saving `const slack = connections.slack()` and declaring `{ support: slack }` still restricts the trigger to `"support"`.
|
|
45
|
-
|
|
46
|
-
The callback runs once when `workflow` is called. Its result is serialized as the ordinary trigger array, and the handler’s event type is inferred from those triggers. Returning a keyed trigger from an imported helper is checked too. Existing static trigger arrays remain supported and validate connection keys at runtime; use the callback for compile-time checking. Unbound triggers, including existing calls without `connectionKey`, keep their existing behavior.
|
|
47
|
-
|
|
48
|
-
Deployment creates a disabled trigger attached to that connection. Configure the account, channel or calendar, and enable the trigger through workflow setup before publishing. Redeploying preserves its configuration. The server checks the binding at publication and execution, so a trigger on another connection cannot invoke this declaration.
|
|
49
|
-
|
|
50
|
-
Calendar, Mail, Slack, Google Drive OAuth, and Discord currently have generated connection trigger helpers. Providers without registered public trigger events do not gain helpers merely by supporting actions. Existing helper calls without `connectionKey` keep their existing behavior. For `connections: { calendar: connections.calendar() }`, use `triggers.calendarEventCreated({ connectionKey: "calendar" })`.
|
|
51
|
-
|
|
52
|
-
Removing a declaration retains the configured trigger, but it can no longer invoke the capability unless another declaration allows it. Renaming a key creates a new connection and disabled trigger. Two keys can declare the same event type independently; repeating the same type and key is rejected.
|
|
53
|
-
|
|
54
|
-
## Use provider methods
|
|
55
|
-
|
|
56
|
-
Use the typed provider client to invoke a method:
|
|
57
|
-
|
|
58
|
-
```ts
|
|
59
|
-
const calendars = await context.connections.work.listCalendars({});
|
|
60
|
-
const user = await context.connections.support.findUserByEmail({
|
|
61
|
-
email: "person@example.com",
|
|
62
|
-
});
|
|
63
|
-
console.log(user?.displayName);
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Method inputs and results come from Tool Core's workflow projections. The SDK generates provider clients from those contracts, including any wire input or output transformations. Adding another registered provider generates its client from that provider's Tool Core methods.
|
|
67
|
-
|
|
68
|
-
The handler context exposes only the declared keys, each with its provider's client type. With `{ work: connections.calendar(), support: connections.slack() }`, `context.connections.work` is a Calendar client and `context.connections.support` is a Slack client. Missing keys and methods from the wrong provider are type errors. Omitting connections exposes no clients.
|
|
69
|
-
|
|
70
|
-
Two names can use the same provider:
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
connections: {
|
|
74
|
-
support: connections.slack(),
|
|
75
|
-
internal: connections.slack(),
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
`context.connections.support` and `context.connections.internal` use separately configured workflow bindings. Reusing a declaration across workflows does not share credentials.
|
|
80
|
-
|
|
81
|
-
For a separate declarations object, let TypeScript infer its type or use `satisfies WorkflowConnectionDeclarations`. A broad `WorkflowConnectionDeclarations` annotation loses the exact keys and providers. Reusable helpers can accept `WorkflowContext<typeof declarations>`.
|
|
82
|
-
|
|
83
|
-
### Migrating from connection arrays
|
|
84
|
-
|
|
85
|
-
Replace `connections: [connections.calendar({ key: "work" })]` with `connections: { work: connections.calendar() }`, then replace `context.connections.calendar("work")` with `context.connections.work`. For an old declaration with no explicit key, use the provider name as the object property to preserve its existing binding. Arrays and factory key options are no longer supported.
|
|
86
|
-
|
|
87
|
-
The SDK serializes the object to the existing manifest array of `{ key, type }` requirements. Keeping the same key and provider preserves the server binding.
|
|
88
|
-
|
|
89
|
-
## Supported providers and setup
|
|
90
|
-
|
|
91
|
-
The registry generates clients for Calendar, Mail, Slack, Google Drive OAuth, Discord, Cursor, Box, Confluence, Gmail, Google Calendar, Google Drive, Outlook, and Salesforce. Only eligible Tool Core methods are generated; this does not expose every operation in those services.
|
|
92
|
-
|
|
93
|
-
Each connection must be authenticated and granted access through the workflow’s setup flow before use. The server handles provider-specific authentication and checks that setup is complete. App code declares a provider under a binding key; declaring a connection never grants permissions.
|
|
94
|
-
|
|
95
|
-
Providers outside the supported list are not currently available as workflow connections. Unsupported declarations receive an unavailable-provider error.
|
|
96
|
-
|
|
97
|
-
### Mail
|
|
98
|
-
|
|
99
|
-
`connections.mail()` uses the personal Mail connection and selected accounts configured in workflow setup. It is separate from the admin-enabled `connections.gmail()` and `connections.outlook()` search connectors.
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
import { workflow } from "@notionhq/apps";
|
|
103
|
-
import { connections } from "@notionhq/apps/workflow";
|
|
104
|
-
|
|
105
|
-
export default workflow({
|
|
106
|
-
name: "Read unread mail",
|
|
107
|
-
description: "Search the configured mailbox when an email arrives",
|
|
108
|
-
connections: { inbox: connections.mail() },
|
|
109
|
-
triggers: ({ triggers }) => [triggers.mailEmailReceived({ connectionKey: "inbox" })],
|
|
110
|
-
handler: async (_event, context) => {
|
|
111
|
-
await context.step("Search unread mail", async () => {
|
|
112
|
-
const result = await context.connections.inbox.searchEmails({
|
|
113
|
-
userEmailAddress: "me@example.com",
|
|
114
|
-
query: "is:unread",
|
|
115
|
-
count: 20,
|
|
116
|
-
});
|
|
117
|
-
if (result.isError) throw new Error("Mailbox search failed");
|
|
118
|
-
return result;
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Mail exposes reads such as `searchEmails`, `viewThreadContent`, `readAttachment`, and `listLabels`, plus writes such as `sendNewEmail`, draft creation, and label updates. Search accepts `pageToken` for pagination. Results preserve the Mail tool response, including `content`, optional `structuredContent`, and `isError`; inspect the provider's response before using its contents. The server enforces selected accounts and action permissions on every call.
|
|
125
|
-
|
|
126
|
-
### Mail and Calendar write approval
|
|
127
|
-
|
|
128
|
-
Mail and Calendar write methods are available in configured workflows, including sending email and creating, updating, or canceling calendar events. Configuring and publishing the workflow authorizes unattended execution within the connection's permissions. The server automatically approves ordinary action confirmations for the workflow's granted Mail and Calendar connections; app code does not need to approve individual calls.
|
|
129
|
-
|
|
130
|
-
Account and calendar permissions still apply. Auto-approval does not grant access to an unselected mailbox, enable disallowed sending, or make a read-only calendar writable. Other confirmation requirements are not automatically approved. Direct agent calls retain their existing confirmation behavior.
|
|
131
|
-
|
|
132
|
-
## Regenerate provider clients
|
|
133
|
-
|
|
134
|
-
From `apps-sdk`, with a compatible sibling `notion-next` checkout and its mise toolchain installed:
|
|
135
|
-
|
|
136
|
-
```sh
|
|
137
|
-
pnpm exec tsx scripts/sync-connections.ts
|
|
138
|
-
pnpm exec tsx scripts/sync-connections.ts --check
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
Pass a checkout path as the final argument if it is elsewhere. The script uses the server checkout’s mise toolchain because the repositories can use different Node versions. You can also run these commands directly from `notion-next`:
|
|
142
|
-
|
|
143
|
-
```sh
|
|
144
|
-
notion tool-core codegen-script-types --connections --path ../apps-sdk/src
|
|
145
|
-
notion tool-core codegen-script-types --connections --path ../apps-sdk/src --check
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### How generation works
|
|
149
|
-
|
|
150
|
-
1. The generator reads `src/shared/workflows/connectionProviders.ts` in `notion-next`. Each entry selects a provider; the server owns its authentication and readiness checks.
|
|
151
|
-
2. For each provider, it reads the corresponding workflow module's effects. It keeps effects backed by a Tool Core definition, exposed to script agents, and not excluded from the connection API. Mail and Calendar include writes because the workflow runtime can approve their action confirmations. Other providers include only read-only methods or methods without a confirmation policy. Server permission checks still apply; workflows do not yet support human confirmation steps.
|
|
152
|
-
3. It reads the exact Tool Core definition stored on each workflow effect projection, so providers with multiple tool versions use the contract selected by their module.
|
|
153
|
-
4. The existing script-type emitter renders the method's wire input and result types. It honors input field mappings and declared output projections, so the types describe the workflow endpoint contract.
|
|
154
|
-
5. It also reads each provider module’s trigger definitions and emits `connection-trigger-definitions.generated.ts`. The SDK trigger generator intersects these with the public `TriggerEventMap` to generate supported `connectionKey` options, descriptions, event types, and provider-scoped trigger creators. Internal events are not exposed.
|
|
155
|
-
6. It writes `<provider>.generated.ts` with types and thin client methods, plus `providers.generated.ts` with keyless declaration helpers, the provider-to-client type map, and the client factory. The runtime transport stays in `connections.ts`.
|
|
156
|
-
|
|
157
|
-
### Updating the SDK after a Tool Core change
|
|
158
|
-
|
|
159
|
-
Use compatible checkouts of both repositories.
|
|
160
|
-
|
|
161
|
-
1. Update the operation's Tool Core contract and workflow projection in `notion-next`. Changes to input/output schemas, effect exposure, or provider registration can require regeneration.
|
|
162
|
-
2. Run `pnpm exec tsx scripts/sync-connections.ts` and its `--check` variant from `apps-sdk`. This regenerates provider clients, trigger metadata, and trigger helpers together. After using the direct server command instead, run `pnpm run generate` in `apps-sdk` as well.
|
|
163
|
-
3. In `apps-sdk`, run `pnpm run typecheck`, `pnpm run lint`, `pnpm test`, `pnpm run build:types`, and `pnpm run build:js`.
|
|
164
|
-
4. Commit all changed generated provider files in the SDK PR, and link the corresponding server PR. Review wire compatibility and deploy server support before consumers rely on new methods.
|
|
165
|
-
|
|
166
|
-
For a new provider, add its server registry entry and supported module type, and ensure its workflow module implements connection setup, permission checks, and Tool Core-backed effects. Then regenerate. Registration alone does not create authentication or port legacy operations into Tool Core. Regeneration adds the provider’s declaration helper and typed methods to the SDK.
|
|
167
|
-
|
|
168
|
-
`--check` compares checked-in output with the selected local server checkout. SDK CI currently checks compilation and tests but does **not** check out `notion-next` or enforce cross-repository provider-codegen freshness. Synchronization is manual today. Generated files must not be edited by hand, and removed providers require removing their obsolete generated files as well.
|
|
169
|
-
|
|
170
|
-
This does not require app developers to import server code or install Tool Core at runtime.
|
|
171
|
-
|
|
172
|
-
## Runtime and rollout
|
|
173
|
-
|
|
174
|
-
The runtime automatically connects each declared key to the account configured during workflow setup. For example, `context.connections.work` uses the connection configured as `work`. App code does not manage connection IDs or credentials.
|
|
175
|
-
|
|
176
|
-
Provider method calls currently require the server's local/development environment and `public_api_runtime_sdk_tools` and `workers_call_function` gates. A personal access token alone does not enable these endpoints. Developer portal connection setup UI wiring is a separate follow-up. Renaming a requirement key creates a new binding; removing a requirement does not revoke or delete the server's existing configured module.
|
|
177
|
-
|
|
178
|
-
## Generic OAuth
|
|
179
|
-
|
|
180
|
-
Use `connections.oauth()` for an OAuth 2.0 provider without a generated provider client:
|
|
181
|
-
|
|
182
|
-
```ts
|
|
183
|
-
export default workflow({
|
|
184
|
-
name: "Read GitHub repositories",
|
|
185
|
-
description: "Read repositories using this workflow's GitHub authorization",
|
|
186
|
-
triggers: [triggers.scheduled()],
|
|
187
|
-
connections: {
|
|
188
|
-
github: connections.oauth({
|
|
189
|
-
authorizationEndpoint: "https://github.com/login/oauth/authorize",
|
|
190
|
-
tokenEndpoint: "https://github.com/login/oauth/access_token",
|
|
191
|
-
clientId: "your-oauth-app-client-id",
|
|
192
|
-
clientSecretEnv: "GITHUB_CLIENT_SECRET",
|
|
193
|
-
scope: "repo",
|
|
194
|
-
}),
|
|
195
|
-
},
|
|
196
|
-
handler: async (_event, context) => {
|
|
197
|
-
const token = await context.connections.github.accessToken();
|
|
198
|
-
const response = await fetch("https://api.github.com/user/repos", {
|
|
199
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
200
|
-
});
|
|
201
|
-
if (!response.ok) throw new Error(`GitHub returned ${response.status}`);
|
|
202
|
-
console.log(await response.json());
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Store the client secret in the app's Workers secrets under the name supplied by `clientSecretEnv`. The declaration contains the secret's name, not its value. Optional `authorizationParams` supports provider options such as `access_type: "offline"`; it cannot override state, callback, client ID, scope, or PKCE fields. Optional `accessTokenExpireMs` supplies a positive default expiry for providers that omit it.
|
|
208
|
-
|
|
209
|
-
Each workflow instance requires separate authorization, even when instances share the same app and declaration. The SDK reads only the access token bound to the current run and does not fall back to app-level `worker.oauth` tokens. The server refreshes tokens before execution; `accessToken()` does not make a refresh request during a long-running handler.
|
|
210
|
-
|
|
211
|
-
This SDK change requires the matching server OAuth implementation before deployment. In the workflow settings, find the declared connection in **Access**, alongside other provider connections. Choose **Connect** beside the declared key, authorize with the provider, and close the authorization window to refresh status. **Reconnect** replaces authorization for that workflow instance; If the client secret is missing, setup shows the secret name to configure. Setup requires full access to the app and workflow editor access. Store the client secret before connecting, and register the app OAuth callback URL with the provider. The SDK does not configure the provider’s OAuth app for you.
|
|
212
|
-
|
|
213
|
-
Generic OAuth provides authentication for your own API calls. It does not generate provider methods or provider triggers. Unlike the generated Tool Core clients, this helper is maintained directly in the SDK.
|
package/docs/workflow-inputs.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Workflow input values
|
|
2
|
-
|
|
3
|
-
Use `input` from `@notionhq/apps` to describe a `context.wait.forInput` form:
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
const response = await context.wait.forInput("Launch details", {
|
|
7
|
-
input: {
|
|
8
|
-
teams: input.multiSelect(["Design", "Engineering"]),
|
|
9
|
-
owners: input.person(),
|
|
10
|
-
window: input.date(),
|
|
11
|
-
attachments: input.files({ optional: true }),
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
- `teams` is an array of the declared options, typed as `("Design" | "Engineering")[]`.
|
|
17
|
-
- `owners` is a `string[]` of all selected user IDs, including when only one person
|
|
18
|
-
is selected. This replaces the previous scalar `string` response.
|
|
19
|
-
- `window` is `{ start: string; end?: string; timeZone?: string }`, not a string.
|
|
20
|
-
Date-only endpoints use `YYYY-MM-DD`; timed endpoints use local `YYYY-MM-DDTHH:mm`
|
|
21
|
-
together with the selected IANA `timeZone`. Ranges retain both endpoints.
|
|
22
|
-
The type is available as `WorkflowInputDate` from `@notionhq/apps/workflow`.
|
|
23
|
-
- `attachments` is a `string[]` with one URL or Notion attachment block ID per item,
|
|
24
|
-
in property order. Attachment display names are not returned as URLs.
|
|
25
|
-
|
|
26
|
-
Empty required multi-select, person, and file inputs keep the request waiting. Empty optional
|
|
27
|
-
inputs are omitted. Selections outside the declared options keep the request waiting
|
|
28
|
-
so the respondent can correct them.
|