@notionhq/apps 0.0.13 → 0.0.14
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/README.md +32 -28
- package/dist/box.generated.d.ts +164 -0
- package/dist/box.generated.d.ts.map +1 -0
- package/dist/box.generated.js +24 -0
- package/dist/calendar.generated.d.ts +1036 -0
- package/dist/calendar.generated.d.ts.map +1 -0
- package/dist/calendar.generated.js +42 -0
- package/dist/cli/build.js +7 -6
- package/dist/confluence.generated.d.ts +98 -0
- package/dist/confluence.generated.d.ts.map +1 -0
- package/dist/confluence.generated.js +18 -0
- package/dist/connection-actions.d.ts +2 -0
- package/dist/connection-actions.d.ts.map +1 -0
- package/dist/connection-actions.js +0 -0
- package/dist/connection-trigger-definitions.generated.d.ts +34 -0
- package/dist/connection-trigger-definitions.generated.d.ts.map +1 -0
- package/dist/connection-trigger-definitions.generated.js +45 -0
- package/dist/connections.d.ts +15 -0
- package/dist/connections.d.ts.map +1 -0
- package/dist/connections.js +79 -0
- package/dist/connections.test.d.ts +2 -0
- package/dist/connections.test.d.ts.map +1 -0
- package/dist/cursor.generated.d.ts +154 -0
- package/dist/cursor.generated.d.ts.map +1 -0
- package/dist/cursor.generated.js +18 -0
- package/dist/discord.generated.d.ts +279 -0
- package/dist/discord.generated.d.ts.map +1 -0
- package/dist/discord.generated.js +33 -0
- package/dist/gmail.generated.d.ts +184 -0
- package/dist/gmail.generated.d.ts.map +1 -0
- package/dist/gmail.generated.js +21 -0
- package/dist/googleCalendar.generated.d.ts +83 -0
- package/dist/googleCalendar.generated.d.ts.map +1 -0
- package/dist/googleCalendar.generated.js +15 -0
- package/dist/googleDrive.generated.d.ts +210 -0
- package/dist/googleDrive.generated.d.ts.map +1 -0
- package/dist/googleDrive.generated.js +27 -0
- package/dist/googleDriveOauth.generated.d.ts +851 -0
- package/dist/googleDriveOauth.generated.d.ts.map +1 -0
- package/dist/googleDriveOauth.generated.js +84 -0
- package/dist/outlook.generated.d.ts +224 -0
- package/dist/outlook.generated.d.ts.map +1 -0
- package/dist/outlook.generated.js +24 -0
- package/dist/providers.generated.d.ts +117 -0
- package/dist/providers.generated.d.ts.map +1 -0
- package/dist/providers.generated.js +108 -0
- package/dist/salesforce.generated.d.ts +151 -0
- package/dist/salesforce.generated.d.ts.map +1 -0
- package/dist/salesforce.generated.js +24 -0
- package/dist/slack.generated.d.ts +290 -0
- package/dist/slack.generated.d.ts.map +1 -0
- package/dist/slack.generated.js +30 -0
- package/dist/triggers.generated.d.ts +107 -32
- package/dist/triggers.generated.d.ts.map +1 -1
- package/dist/triggers.generated.js +36 -24
- package/dist/workflow-connections-types.test.d.ts +2 -0
- package/dist/workflow-connections-types.test.d.ts.map +1 -0
- package/dist/workflow-types.test.d.ts +2 -0
- package/dist/workflow-types.test.d.ts.map +1 -0
- package/dist/workflow.d.ts +20 -16
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +14 -17
- package/docs/BUILD.md +83 -14
- package/docs/CONNECTIONS.md +129 -0
- package/package.json +1 -1
- package/src/box.generated.ts +187 -0
- package/src/calendar.generated.ts +1117 -0
- package/src/cli/build.test.ts +33 -0
- package/src/cli/build.ts +6 -5
- package/src/confluence.generated.ts +109 -0
- package/src/connection-actions.ts +2 -0
- package/src/connection-trigger-definitions.generated.ts +48 -0
- package/src/connections.test.ts +157 -0
- package/src/connections.ts +126 -0
- package/src/cursor.generated.ts +167 -0
- package/src/discord.generated.ts +318 -0
- package/src/gmail.generated.ts +205 -0
- package/src/googleCalendar.generated.ts +95 -0
- package/src/googleDrive.generated.ts +235 -0
- package/src/googleDriveOauth.generated.ts +980 -0
- package/src/outlook.generated.ts +249 -0
- package/src/providers.generated.ts +207 -0
- package/src/salesforce.generated.ts +170 -0
- package/src/slack.generated.ts +330 -0
- package/src/triggers.generated.ts +112 -32
- package/src/workflow-connections-types.test.ts +59 -0
- package/src/workflow-types.test.ts +144 -0
- package/src/workflow.test.ts +112 -2
- package/src/workflow.ts +58 -29
package/docs/BUILD.md
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# App build process
|
|
2
2
|
|
|
3
|
-
`notion-apps build` discovers
|
|
3
|
+
`notion-apps build` discovers capability modules and produces:
|
|
4
4
|
|
|
5
|
-
- `dist/worker.js`, an ESM bundle containing the app's
|
|
6
|
-
- `dist/manifest.json`,
|
|
5
|
+
- `dist/worker.js`, an ESM bundle containing the app's workflows and syncs.
|
|
6
|
+
- `dist/manifest.json`, the static capability and resource manifest.
|
|
7
|
+
- `dist/provisioning.json`, only when the app declares Notion-as-Code resources.
|
|
7
8
|
|
|
8
9
|
## Project convention
|
|
9
10
|
|
|
10
|
-
Each top-level TypeScript file under
|
|
11
|
-
|
|
11
|
+
Each top-level TypeScript file under a capability directory must default-export the
|
|
12
|
+
corresponding capability. The filename becomes its key:
|
|
13
|
+
|
|
14
|
+
| Directory | Default export |
|
|
15
|
+
| ------------------- | ------------------------ |
|
|
16
|
+
| `src/workflows/` | `createWorkflow(...)` |
|
|
17
|
+
| `src/syncs/` | `createSync(...)` |
|
|
18
|
+
| `src/customBlocks/` | `createCustomBlock(...)` |
|
|
12
19
|
|
|
13
20
|
```text
|
|
14
21
|
my-app/
|
|
@@ -23,19 +30,81 @@ my-app/
|
|
|
23
30
|
└── manifest.json
|
|
24
31
|
```
|
|
25
32
|
|
|
26
|
-
Files elsewhere under `src/` are ordinary modules and enter the
|
|
27
|
-
|
|
33
|
+
Files elsewhere under `src/` are ordinary modules and enter the build only when imported
|
|
34
|
+
by a capability. Capability discovery does not recurse into subdirectories.
|
|
28
35
|
|
|
29
36
|
## Pipeline
|
|
30
37
|
|
|
31
|
-
1. Discover top-level
|
|
32
|
-
2. Generate `.notion/entry.ts` with
|
|
38
|
+
1. Discover top-level files in the capability directories.
|
|
39
|
+
2. Generate `.notion/entry.ts` with workflow and sync imports and a dispatcher.
|
|
33
40
|
3. Bundle the app's code into `dist/worker.js`, leaving npm packages external.
|
|
34
|
-
4.
|
|
35
|
-
write `dist/manifest.json`.
|
|
41
|
+
4. Evaluate custom-block declarations separately, validate capability exports and
|
|
42
|
+
configuration, and write `dist/manifest.json`. Blocks do not enter `worker.js`.
|
|
43
|
+
5. Evaluate worker capabilities in a separate build-only metadata bundle to record
|
|
44
|
+
Notion-as-Code declarations, then emit `dist/provisioning.json` if there are any.
|
|
45
|
+
|
|
46
|
+
Capability modules must therefore be importable without secrets or network access.
|
|
47
|
+
Read required environment variables and make requests inside handlers or workflow
|
|
48
|
+
steps, not at module scope.
|
|
49
|
+
|
|
50
|
+
## Provisioning artifact and deployment
|
|
51
|
+
|
|
52
|
+
The optional provisioning artifact uses `$schema: "notion:apps-provisioning:v1"`,
|
|
53
|
+
`version: 1`, and an `intents` array. These declarations are build metadata, not
|
|
54
|
+
provisioning operations executed by the deployed Worker.
|
|
55
|
+
|
|
56
|
+
After a successful build, the artifact reflects the current declarations. If no
|
|
57
|
+
declarations remain, the build removes any previous `dist/provisioning.json`
|
|
58
|
+
rather than uploading stale intents or emitting an empty artifact. This also
|
|
59
|
+
works when rebuilding into a reused `dist/` directory. Removing the artifact does
|
|
60
|
+
not delete previously provisioned Notion resources or reset their cloud state.
|
|
61
|
+
Do not deploy the output of a failed build.
|
|
62
|
+
|
|
63
|
+
Build and coordination modes use the existing CLI arguments:
|
|
64
|
+
|
|
65
|
+
| Command | Build location | Deployment coordination |
|
|
66
|
+
| ------------------------------------- | ------------------------------------------------ | ----------------------------- |
|
|
67
|
+
| `ntn apps deploy` | Cloud sandbox, using the project's installed SDK | Server (`workersBuildWorker`) |
|
|
68
|
+
| `ntn apps deploy --local-build --yes` | Local `notion-apps build` | CLI, as on `main` |
|
|
69
|
+
|
|
70
|
+
Cloud builds do not require the SDK or Node.js on the invoking machine. The
|
|
71
|
+
uploaded project must declare its SDK dependency and a `build` script that invokes
|
|
72
|
+
`notion-apps build`; the cloud runner uses the existing `npm run build` or
|
|
73
|
+
`pnpm run build` command, not a separate SDK command. The CLI creates an App-linked
|
|
74
|
+
Worker using `workersCreateWorker` with `createApp: true`, or updates the existing
|
|
75
|
+
Worker, then uploads source and calls `workersBuildWorker` with the Worker ID.
|
|
76
|
+
For App-linked Workers, the build endpoint coordinates capability registration,
|
|
77
|
+
Notion-as-Code provisioning, and database attachment before reporting build success.
|
|
78
|
+
It returns the normal build result and run ID, not provisioning state. No separate
|
|
79
|
+
Apps deployment endpoint is required.
|
|
80
|
+
|
|
81
|
+
For App-linked Workers, the Notion-as-Code build phase prepares a separate
|
|
82
|
+
upload target, like the manifest target, for optional `dist/provisioning.json`.
|
|
83
|
+
The cloud runner uploads the file only if the build emits it; an upload failure
|
|
84
|
+
fails the build. The provisioning hooks read the JSON directly, not from the Worker
|
|
85
|
+
bundle. Provisioning JSON is limited to 5 MiB; a missing object means there are no
|
|
86
|
+
provisioning declarations, while other read errors or invalid JSON fail deployment.
|
|
87
|
+
|
|
88
|
+
This upload is a retained, deployment-scoped object in the existing Workers S3
|
|
89
|
+
bucket. The coordinator leaves it in storage after successful or failed deployment
|
|
90
|
+
attempts. It records build declarations, not the durable installation-owned
|
|
91
|
+
Notion-as-Code resource mappings and state.
|
|
92
|
+
Ordinary Worker deployment APIs, responses, and storage lifecycle are unchanged.
|
|
93
|
+
|
|
94
|
+
`--local-build` preserves the current CLI-coordinated setup. The CLI builds and
|
|
95
|
+
uploads the Worker bundle and manifest, uses the existing Notion-as-Code apply
|
|
96
|
+
flow and local state, and reconciles attachments. It reads the optional
|
|
97
|
+
`dist/provisioning.json` locally and does not upload it separately or invoke
|
|
98
|
+
the cloud build endpoint.
|
|
99
|
+
|
|
100
|
+
Resource bindings are not stored in SDK build output. Local deployments retain a
|
|
101
|
+
local state file and report `state_file`; cloud deployments keep installation-owned
|
|
102
|
+
resource mappings and state on the server. Cloud builds do not import local state
|
|
103
|
+
or return provisioning state to the CLI. Local and cloud state are independent:
|
|
104
|
+
switching between modes may recreate resources rather than reuse existing bindings.
|
|
36
105
|
|
|
37
|
-
|
|
38
|
-
|
|
106
|
+
Cloud failures never automatically retry locally. There is no rollback: code or
|
|
107
|
+
resources may already have changed when a deployment fails.
|
|
39
108
|
|
|
40
109
|
## Manifest
|
|
41
110
|
|
|
@@ -0,0 +1,129 @@
|
|
|
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 { connections, createWorkflow } from "@notionhq/apps/workflow";
|
|
7
|
+
import { triggers } from "@notionhq/apps/triggers";
|
|
8
|
+
|
|
9
|
+
export default createWorkflow({
|
|
10
|
+
name: "List work calendars",
|
|
11
|
+
description: "List calendars available through the work connection",
|
|
12
|
+
triggers: [triggers.notionPageCreated()],
|
|
13
|
+
connections: [connections.calendar({ key: "work" })],
|
|
14
|
+
handler: async (_event, context) => {
|
|
15
|
+
const calendars = await context.connections.calendar("work").listCalendars({});
|
|
16
|
+
console.log(calendars.accounts);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
An omitted key defaults to the provider type, so `connections.calendar()` is accessed through `context.connections.calendar()`. Keys must be unique, begin with a letter, and contain at most 128 letters, numbers, underscores, or hyphens. A workflow can declare up to 100 requirements.
|
|
22
|
+
|
|
23
|
+
## Trigger a workflow from a connection
|
|
24
|
+
|
|
25
|
+
Use a trigger callback to check connection keys against the workflow’s declared providers:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
export default createWorkflow({
|
|
29
|
+
name: "Support messages",
|
|
30
|
+
description: "Run when a message arrives in the configured support channel",
|
|
31
|
+
connections: [connections.slack({ key: "support" })],
|
|
32
|
+
triggers: ({ triggers }) => [triggers.slackMessage({ connectionKey: "support" })],
|
|
33
|
+
handler: async (event, context) => {
|
|
34
|
+
console.log(event);
|
|
35
|
+
const user = await context.connections
|
|
36
|
+
.slack("support")
|
|
37
|
+
.findUserByEmail({ email: "person@example.com" });
|
|
38
|
+
console.log(user);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
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 remain literal when you save a declaration in a variable, so the same check works with `const support = connections.slack({ key: "support" })`. Omitting the declaration key defaults to the provider name.
|
|
44
|
+
|
|
45
|
+
The callback runs once when `createWorkflow` 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.
|
|
46
|
+
|
|
47
|
+
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.
|
|
48
|
+
|
|
49
|
+
Calendar, 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. To bind a default connection such as `connections.calendar()`, use `triggers.calendarEventCreated({ connectionKey: "calendar" })`.
|
|
50
|
+
|
|
51
|
+
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.
|
|
52
|
+
|
|
53
|
+
## Use provider methods
|
|
54
|
+
|
|
55
|
+
Use the typed provider client to invoke a method:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const calendars = await context.connections.calendar().listCalendars({});
|
|
59
|
+
const user = await context.connections.slack("support").findUserByEmail({
|
|
60
|
+
email: "person@example.com",
|
|
61
|
+
});
|
|
62
|
+
console.log(user?.displayName);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
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.
|
|
66
|
+
|
|
67
|
+
The handler context exposes only providers declared in that workflow's
|
|
68
|
+
`connections` list. A Calendar-only declaration exposes `context.connections.calendar`
|
|
69
|
+
but not `context.connections.slack`; omitting connections exposes no provider
|
|
70
|
+
clients. Named keys still select a configured binding at runtime.
|
|
71
|
+
|
|
72
|
+
For a separate declaration array, let TypeScript infer its type or use
|
|
73
|
+
`satisfies readonly WorkflowConnection[]`. An explicit broad
|
|
74
|
+
`WorkflowConnection[]` annotation erases provider information and prevents this
|
|
75
|
+
narrowing. Reusable helpers can accept `WorkflowContext<typeof requirements>`.
|
|
76
|
+
|
|
77
|
+
## Supported providers and setup
|
|
78
|
+
|
|
79
|
+
The registry currently generates 73 methods across 12 providers: Calendar, 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.
|
|
80
|
+
|
|
81
|
+
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 only declares a provider and optional binding key; declaring a connection never grants permissions.
|
|
82
|
+
|
|
83
|
+
Providers outside the supported list are not currently available as workflow connections. Unsupported declarations receive an unavailable-provider error.
|
|
84
|
+
|
|
85
|
+
## Regenerate provider clients
|
|
86
|
+
|
|
87
|
+
From `apps-sdk`, with a compatible sibling `notion-next` checkout and its mise toolchain installed:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
pnpm exec tsx scripts/sync-connections.ts
|
|
91
|
+
pnpm exec tsx scripts/sync-connections.ts --check
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
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`:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
notion tool-core codegen-script-types --connections --path ../apps-sdk/src
|
|
98
|
+
notion tool-core codegen-script-types --connections --path ../apps-sdk/src --check
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### How generation works
|
|
102
|
+
|
|
103
|
+
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.
|
|
104
|
+
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, not excluded from the connection API, and without an explicit confirmation requirement. Workflows do not yet support human confirmation steps.
|
|
105
|
+
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.
|
|
106
|
+
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.
|
|
107
|
+
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.
|
|
108
|
+
6. It writes `<provider>.generated.ts` with types and thin client methods, plus `providers.generated.ts` with the declaration helpers and provider factories. The runtime transport stays in `connections.ts`.
|
|
109
|
+
|
|
110
|
+
### Updating the SDK after a Tool Core change
|
|
111
|
+
|
|
112
|
+
Use compatible checkouts of both repositories.
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
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.
|
|
116
|
+
3. In `apps-sdk`, run `pnpm run typecheck`, `pnpm run lint`, `pnpm test`, `pnpm run build:types`, and `pnpm run build:js`.
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
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.
|
|
120
|
+
|
|
121
|
+
`--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.
|
|
122
|
+
|
|
123
|
+
This does not require app developers to import server code or install Tool Core at runtime.
|
|
124
|
+
|
|
125
|
+
## Runtime and rollout
|
|
126
|
+
|
|
127
|
+
The runtime automatically connects each declared key to the account configured during workflow setup. For example, `context.connections.calendar("work")` uses the connection configured as `work`. App code does not manage connection IDs or credentials.
|
|
128
|
+
|
|
129
|
+
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.
|
package/package.json
CHANGED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Generated by notion tool-core codegen-script-types --connections. Do not edit.
|
|
2
|
+
import type { ConnectionActionInvoker } from "./connection-actions.js"
|
|
3
|
+
/**
|
|
4
|
+
* Script input for the "Find shared Box item" effect (`box.findSharedItem`),
|
|
5
|
+
* derived from its Tool Core definition's call_function input projection.
|
|
6
|
+
*
|
|
7
|
+
* Resolve a Box shared link to an item ID and type.
|
|
8
|
+
*/
|
|
9
|
+
export type FindSharedItemScriptInput = {
|
|
10
|
+
/**
|
|
11
|
+
* The full Box shared link URL.
|
|
12
|
+
*/
|
|
13
|
+
sharedLink: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Canonical Tool Core output for the "Find shared Box item" effect (`box.findSharedItem`).
|
|
18
|
+
* This is the definition's output schema; the effect's script surface may
|
|
19
|
+
* re-encode it before returning.
|
|
20
|
+
*/
|
|
21
|
+
export type FindSharedItemScriptOutput = {
|
|
22
|
+
itemId: string
|
|
23
|
+
/**
|
|
24
|
+
* One of: `file`, `folder`
|
|
25
|
+
*/
|
|
26
|
+
itemType: "file" | "folder"
|
|
27
|
+
name: string
|
|
28
|
+
size: number
|
|
29
|
+
modifiedAt: string
|
|
30
|
+
owner: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Script input for the "Load Box file" effect (`box.loadFile`),
|
|
35
|
+
* derived from its Tool Core definition's call_function input projection.
|
|
36
|
+
*
|
|
37
|
+
* Load a Box file by its file ID.
|
|
38
|
+
*/
|
|
39
|
+
export type LoadFileScriptInput = {
|
|
40
|
+
/**
|
|
41
|
+
* The Box file ID.
|
|
42
|
+
*/
|
|
43
|
+
fileId: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Canonical Tool Core output for the "Load Box file" effect (`box.loadFile`).
|
|
48
|
+
* This is the definition's output schema; the effect's script surface may
|
|
49
|
+
* re-encode it before returning.
|
|
50
|
+
*/
|
|
51
|
+
export type LoadFileScriptOutput = {
|
|
52
|
+
/**
|
|
53
|
+
* Always `box-file`
|
|
54
|
+
*/
|
|
55
|
+
type: "box-file"
|
|
56
|
+
title: string
|
|
57
|
+
blocks: Array<string>
|
|
58
|
+
fileId: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Script input for the "List Box folder" effect (`box.lsFolder`),
|
|
63
|
+
* derived from its Tool Core definition's call_function input projection.
|
|
64
|
+
*
|
|
65
|
+
* List files and subfolders in a Box folder.
|
|
66
|
+
*/
|
|
67
|
+
export type LsFolderScriptInput = {
|
|
68
|
+
/**
|
|
69
|
+
* The Box folder ID to list contents of.
|
|
70
|
+
*/
|
|
71
|
+
folderId: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Canonical Tool Core output for the "List Box folder" effect (`box.lsFolder`).
|
|
76
|
+
* This is the definition's output schema; the effect's script surface may
|
|
77
|
+
* re-encode it before returning.
|
|
78
|
+
*/
|
|
79
|
+
export type LsFolderScriptOutput = {
|
|
80
|
+
items: Array<{
|
|
81
|
+
id: string
|
|
82
|
+
/**
|
|
83
|
+
* One of: `file`, `folder`
|
|
84
|
+
*/
|
|
85
|
+
type: "file" | "folder"
|
|
86
|
+
name: string
|
|
87
|
+
size: number
|
|
88
|
+
modifiedAt: string
|
|
89
|
+
}>
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Script input for the "Search Box" effect (`box.search`),
|
|
94
|
+
* derived from its Tool Core definition's call_function input projection.
|
|
95
|
+
*
|
|
96
|
+
* Search Box via the configured connector.
|
|
97
|
+
*/
|
|
98
|
+
export type SearchScriptInput = {
|
|
99
|
+
/**
|
|
100
|
+
* A single, focused question to search for.
|
|
101
|
+
*/
|
|
102
|
+
question: string
|
|
103
|
+
/**
|
|
104
|
+
* Brief keywords capturing the core entities.
|
|
105
|
+
*/
|
|
106
|
+
keywords?: string
|
|
107
|
+
/**
|
|
108
|
+
* Optional time window. Use only "default", "all_time", a duration matching /^\d+[dwmy]$/ (for example, "7d", "2w", "3m", or "1y"), or a date in "YYYY-MM-DD" format. Do not use natural-language durations or combine units.
|
|
109
|
+
*/
|
|
110
|
+
lookback?: string
|
|
111
|
+
/**
|
|
112
|
+
* Optional list of Box folder IDs to scope the search to. Use findSharedItem or searchFolders to get folder IDs.
|
|
113
|
+
*/
|
|
114
|
+
folderIds?: Array<string>
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Canonical Tool Core output for the "Search Box" effect (`box.search`).
|
|
119
|
+
* This is the definition's output schema; the effect's script surface may
|
|
120
|
+
* re-encode it before returning.
|
|
121
|
+
*/
|
|
122
|
+
export type SearchScriptOutput = {
|
|
123
|
+
results: Array<{
|
|
124
|
+
id: string
|
|
125
|
+
title: string
|
|
126
|
+
path: string
|
|
127
|
+
text: string
|
|
128
|
+
lastEdited: string
|
|
129
|
+
isPrivate: boolean
|
|
130
|
+
pageId: string
|
|
131
|
+
fileType: string
|
|
132
|
+
fileId: string
|
|
133
|
+
}>
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Script input for the "Search Box folders" effect (`box.searchFolders`),
|
|
138
|
+
* derived from its Tool Core definition's call_function input projection.
|
|
139
|
+
*
|
|
140
|
+
* Search Box folders by name.
|
|
141
|
+
*/
|
|
142
|
+
export type SearchFoldersScriptInput = {
|
|
143
|
+
/**
|
|
144
|
+
* The search query for finding folders.
|
|
145
|
+
*/
|
|
146
|
+
question: string
|
|
147
|
+
/**
|
|
148
|
+
* Optional additional keywords to refine the folder search.
|
|
149
|
+
*/
|
|
150
|
+
keywords?: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Canonical Tool Core output for the "Search Box folders" effect (`box.searchFolders`).
|
|
155
|
+
* This is the definition's output schema; the effect's script surface may
|
|
156
|
+
* re-encode it before returning.
|
|
157
|
+
*/
|
|
158
|
+
export type SearchFoldersScriptOutput = {
|
|
159
|
+
results: Array<{
|
|
160
|
+
id: string
|
|
161
|
+
name: string
|
|
162
|
+
folderId: string
|
|
163
|
+
}>
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class BoxConnectionClient {
|
|
167
|
+
constructor(private readonly invoke: ConnectionActionInvoker) {}
|
|
168
|
+
findSharedItem(
|
|
169
|
+
args: FindSharedItemScriptInput,
|
|
170
|
+
): Promise<FindSharedItemScriptOutput> {
|
|
171
|
+
return this.invoke<FindSharedItemScriptOutput>("findSharedItem", args)
|
|
172
|
+
}
|
|
173
|
+
loadFile(args: LoadFileScriptInput): Promise<LoadFileScriptOutput> {
|
|
174
|
+
return this.invoke<LoadFileScriptOutput>("loadFile", args)
|
|
175
|
+
}
|
|
176
|
+
lsFolder(args: LsFolderScriptInput): Promise<LsFolderScriptOutput> {
|
|
177
|
+
return this.invoke<LsFolderScriptOutput>("lsFolder", args)
|
|
178
|
+
}
|
|
179
|
+
search(args: SearchScriptInput): Promise<SearchScriptOutput> {
|
|
180
|
+
return this.invoke<SearchScriptOutput>("search", args)
|
|
181
|
+
}
|
|
182
|
+
searchFolders(
|
|
183
|
+
args: SearchFoldersScriptInput,
|
|
184
|
+
): Promise<SearchFoldersScriptOutput> {
|
|
185
|
+
return this.invoke<SearchFoldersScriptOutput>("searchFolders", args)
|
|
186
|
+
}
|
|
187
|
+
}
|