@trigger.dev/sdk 4.8.5 → 4.8.7
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/commonjs/v3/ai.d.ts +34 -8
- package/dist/commonjs/v3/ai.js +304 -168
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/auth.d.ts +4 -4
- package/dist/commonjs/v3/auth.js +21 -75
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/chat-client.d.ts +1 -1
- package/dist/commonjs/v3/chat.d.ts +1 -1
- package/dist/commonjs/v3/prompt.js +6 -8
- package/dist/commonjs/v3/prompt.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +5 -1
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/sessions.js +10 -7
- package/dist/commonjs/v3/sessions.js.map +1 -1
- package/dist/commonjs/v3/shared.d.ts +2 -2
- package/dist/commonjs/v3/shared.js +16 -15
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/steeringContext.d.ts +35 -10
- package/dist/commonjs/v3/steeringContext.js +86 -14
- package/dist/commonjs/v3/steeringContext.js.map +1 -1
- package/dist/commonjs/v3/streams.js +10 -8
- package/dist/commonjs/v3/streams.js.map +1 -1
- package/dist/commonjs/v3/tasks.d.ts +2 -2
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/test/mock-chat-agent.js +24 -13
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/commonjs/v3/toolOutputJson.d.ts +17 -0
- package/dist/commonjs/v3/toolOutputJson.js +241 -0
- package/dist/commonjs/v3/toolOutputJson.js.map +1 -0
- package/dist/commonjs/v3/webhooks.d.ts +8 -2
- package/dist/commonjs/v3/webhooks.js +20 -11
- package/dist/commonjs/v3/webhooks.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +34 -8
- package/dist/esm/v3/ai.js +306 -171
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/auth.d.ts +4 -4
- package/dist/esm/v3/auth.js +22 -76
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/chat-client.d.ts +1 -1
- package/dist/esm/v3/chat.d.ts +1 -1
- package/dist/esm/v3/prompt.js +6 -8
- package/dist/esm/v3/prompt.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +5 -1
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/sessions.js +10 -7
- package/dist/esm/v3/sessions.js.map +1 -1
- package/dist/esm/v3/shared.d.ts +2 -2
- package/dist/esm/v3/shared.js +16 -15
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/steeringContext.d.ts +35 -10
- package/dist/esm/v3/steeringContext.js +85 -14
- package/dist/esm/v3/steeringContext.js.map +1 -1
- package/dist/esm/v3/streams.js +10 -8
- package/dist/esm/v3/streams.js.map +1 -1
- package/dist/esm/v3/tasks.d.ts +2 -2
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/test/mock-chat-agent.js +25 -14
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/esm/v3/toolOutputJson.d.ts +17 -0
- package/dist/esm/v3/toolOutputJson.js +238 -0
- package/dist/esm/v3/toolOutputJson.js.map +1 -0
- package/dist/esm/v3/webhooks.d.ts +8 -2
- package/dist/esm/v3/webhooks.js +20 -11
- package/dist/esm/v3/webhooks.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai/observability.mdx +25 -19
- package/docs/ai/prompts.mdx +25 -19
- package/docs/ai-chat/actions.mdx +1 -1
- package/docs/ai-chat/anatomy.mdx +1 -1
- package/docs/ai-chat/backend.mdx +24 -24
- package/docs/ai-chat/background-injection.mdx +5 -5
- package/docs/ai-chat/chat-local.mdx +2 -2
- package/docs/ai-chat/compaction.mdx +47 -18
- package/docs/ai-chat/custom-agents.mdx +4 -4
- package/docs/ai-chat/error-handling.mdx +4 -4
- package/docs/ai-chat/fast-starts.mdx +8 -7
- package/docs/ai-chat/frontend.mdx +6 -2
- package/docs/ai-chat/lifecycle-hooks.mdx +11 -11
- package/docs/ai-chat/migrating-from-a-route-handler.mdx +4 -4
- package/docs/ai-chat/migrating-from-hydrate-messages.mdx +1 -1
- package/docs/ai-chat/overview.mdx +1 -1
- package/docs/ai-chat/patterns/branching-conversations.mdx +1 -1
- package/docs/ai-chat/patterns/database-persistence.mdx +2 -2
- package/docs/ai-chat/patterns/human-in-the-loop.mdx +1 -1
- package/docs/ai-chat/patterns/native-compaction.mdx +29 -9
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +1 -1
- package/docs/ai-chat/patterns/redacting-telemetry.mdx +2 -2
- package/docs/ai-chat/patterns/skills.mdx +2 -2
- package/docs/ai-chat/patterns/sub-agents.mdx +1 -1
- package/docs/ai-chat/patterns/tool-result-auditing.mdx +1 -1
- package/docs/ai-chat/patterns/trusted-edge-signals.mdx +2 -2
- package/docs/ai-chat/patterns/version-upgrades.mdx +2 -2
- package/docs/ai-chat/pending-messages.mdx +5 -5
- package/docs/ai-chat/prompt-caching.mdx +7 -7
- package/docs/ai-chat/quick-start.mdx +2 -2
- package/docs/ai-chat/testing.mdx +9 -9
- package/docs/ai-chat/tools.mdx +9 -5
- package/docs/ai-chat/transcript-storage.mdx +2 -2
- package/docs/ai-chat/types.mdx +10 -3
- package/docs/apikeys.mdx +2 -1
- package/docs/cli-login-commands.mdx +12 -0
- package/docs/concurrency.mdx +40 -0
- package/docs/database-connections.mdx +1 -1
- package/docs/deploy-environment-variables.mdx +84 -2
- package/docs/deployment/trusted-publishing.mdx +4 -0
- package/docs/errors-retrying.mdx +25 -18
- package/docs/github-actions.mdx +1 -1
- package/docs/github-integration.mdx +32 -1
- package/docs/how-it-works.mdx +4 -2
- package/docs/introduction.mdx +1 -1
- package/docs/mcp-introduction.mdx +7 -1
- package/docs/mcp-remote.mdx +90 -0
- package/docs/oidc/azure.mdx +81 -0
- package/docs/oidc/databricks.mdx +99 -0
- package/docs/oidc/doppler.mdx +60 -0
- package/docs/oidc/gcp.mdx +109 -0
- package/docs/oidc/hugging-face.mdx +90 -0
- package/docs/oidc/openrouter.mdx +91 -0
- package/docs/oidc/snowflake.mdx +91 -0
- package/docs/oidc/vault.mdx +71 -0
- package/docs/oidc.mdx +2 -0
- package/docs/runs/metadata.mdx +1 -1
- package/docs/self-hosting/docker.mdx +2 -0
- package/docs/self-hosting/env/webapp.mdx +4 -1
- package/docs/self-hosting/kubernetes.mdx +2 -0
- package/docs/tasks/schemaTask.mdx +26 -13
- package/docs/tasks/streams.mdx +2 -2
- package/docs/troubleshooting.mdx +7 -0
- package/docs/webhooks/channels.mdx +6 -6
- package/docs/webhooks/connect.mdx +9 -75
- package/docs/webhooks/custom-providers.mdx +87 -0
- package/docs/webhooks/deliveries.mdx +7 -7
- package/docs/webhooks/filters.mdx +2 -2
- package/docs/webhooks/how-it-works.mdx +58 -0
- package/docs/webhooks/human-in-the-loop.mdx +3 -3
- package/docs/webhooks/linear.mdx +5 -3
- package/docs/webhooks/overview.mdx +20 -71
- package/docs/webhooks/own-handler.mdx +62 -0
- package/docs/webhooks/pricing-and-limits.mdx +13 -0
- package/docs/webhooks/providers/attio.mdx +38 -0
- package/docs/webhooks/providers/autumn.mdx +40 -0
- package/docs/webhooks/providers/cal-com.mdx +41 -0
- package/docs/webhooks/providers/calendly.mdx +41 -0
- package/docs/webhooks/providers/clerk.mdx +40 -0
- package/docs/webhooks/providers/discord.mdx +45 -0
- package/docs/webhooks/providers/docusign.mdx +41 -0
- package/docs/webhooks/providers/elevenlabs.mdx +41 -0
- package/docs/webhooks/providers/firecrawl.mdx +54 -0
- package/docs/webhooks/providers/github.mdx +46 -0
- package/docs/webhooks/providers/gitlab.mdx +41 -0
- package/docs/webhooks/providers/granola.mdx +44 -0
- package/docs/webhooks/providers/hookdeck.mdx +98 -0
- package/docs/webhooks/providers/infisical.mdx +41 -0
- package/docs/webhooks/providers/jira.mdx +41 -0
- package/docs/webhooks/providers/langfuse.mdx +40 -0
- package/docs/webhooks/providers/linear.mdx +45 -0
- package/docs/webhooks/providers/loops.mdx +40 -0
- package/docs/webhooks/providers/metronome.mdx +42 -0
- package/docs/webhooks/providers/mux.mdx +40 -0
- package/docs/webhooks/providers/openai.mdx +40 -0
- package/docs/webhooks/providers/pagerduty.mdx +40 -0
- package/docs/webhooks/providers/plain.mdx +41 -0
- package/docs/webhooks/providers/planetscale.mdx +40 -0
- package/docs/webhooks/providers/recall-ai.mdx +54 -0
- package/docs/webhooks/providers/replicate.mdx +41 -0
- package/docs/webhooks/providers/resend.mdx +44 -0
- package/docs/webhooks/providers/retell.mdx +41 -0
- package/docs/webhooks/providers/sentry.mdx +41 -0
- package/docs/webhooks/providers/shopify.mdx +49 -0
- package/docs/webhooks/providers/slack.mdx +48 -0
- package/docs/webhooks/providers/square.mdx +40 -0
- package/docs/webhooks/providers/stripe.mdx +86 -0
- package/docs/webhooks/providers/supabase.mdx +41 -0
- package/docs/webhooks/providers/tailscale.mdx +43 -0
- package/docs/webhooks/providers/typeform.mdx +42 -0
- package/docs/webhooks/providers/vapi.mdx +47 -0
- package/docs/webhooks/providers/vercel.mdx +40 -0
- package/docs/webhooks/providers/whatsapp.mdx +45 -0
- package/docs/webhooks/providers/workos.mdx +41 -0
- package/docs/webhooks/providers/zendesk.mdx +41 -0
- package/docs/webhooks/providers.mdx +53 -0
- package/docs/webhooks/quick-start.mdx +131 -0
- package/docs/webhooks/session-routing.mdx +6 -6
- package/docs/webhooks/signing-secrets.mdx +80 -0
- package/docs/webhooks/slack.mdx +11 -2
- package/docs/webhooks/verification.mdx +139 -0
- package/docs/webhooks/waiters.mdx +2 -2
- package/docs/webhooks/webhook-tasks.mdx +46 -0
- package/package.json +4 -5
- package/docs/migrating-from-v3.mdx +0 -332
- package/docs/webhooks/public-beta.mdx +0 -70
- package/docs/webhooks/sources.mdx +0 -252
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Migrating from v3"
|
|
3
|
-
description: "What's new in v4, how to migrate, and breaking changes."
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
import NodeVersions from "/snippets/node-versions.mdx";
|
|
7
|
-
import MigrateV4UsingAi from "/snippets/migrate-v4-using-ai.mdx";
|
|
8
|
-
|
|
9
|
-
<Warning>
|
|
10
|
-
**Trigger.dev v3 has been retired**
|
|
11
|
-
|
|
12
|
-
Trigger.dev v3 is end of life. v4 is stable, fully supported, and recommended for all users.
|
|
13
|
-
|
|
14
|
-
- On Trigger.dev Cloud, v3 has been shut down: v3 triggers and deploys no longer run.
|
|
15
|
-
- If you self-host, 4.5.0 is the last version we officially support for running v3. Stay on 4.5.0 or upgrade to v4; 4.5.1 and later reject v3 triggers, batch triggers, and deploys with an upgrade message.
|
|
16
|
-
|
|
17
|
-
**What you need to do:** Migrate to v4. The migration takes about 2 minutes; follow the steps below. If you have questions or need help, [contact us](https://trigger.dev/contact) or reach out in our [Discord](https://trigger.dev/discord).
|
|
18
|
-
|
|
19
|
-
</Warning>
|
|
20
|
-
|
|
21
|
-
## What's new in v4?
|
|
22
|
-
|
|
23
|
-
| Feature | Description |
|
|
24
|
-
| :------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
-
| [Wait for token](/wait-for-token) | Create and wait for tokens to be completed, enabling approval workflows and waiting for arbitrary external conditions. |
|
|
26
|
-
| Wait idempotency | Skip waits if the same idempotency key is used again when using [wait for](/wait-for#wait-idempotency), [wait until](/wait-until#wait-idempotency), or [wait for token](/wait-for-token#wait-idempotency). |
|
|
27
|
-
| [Priority](/runs/priority) | Specify a priority when triggering a task. |
|
|
28
|
-
| [Global lifecycle hooks](/tasks/overview#global-lifecycle-hooks) | Register global lifecycle hooks that are executed for all runs, regardless of the task. |
|
|
29
|
-
| [onWait and onResume](/tasks/overview#onwait-and-onresume-functions) | Run code when a run is paused or resumed because of a wait. |
|
|
30
|
-
| [onComplete](/tasks/overview#oncomplete-function) | Run code when a run completes, regardless of whether it succeeded or failed. |
|
|
31
|
-
| [onCancel](/tasks/overview#oncancel-function) | Run code when a run is cancelled. |
|
|
32
|
-
| [Hidden tasks](/hidden-tasks) | Create tasks that are not exported from your trigger files but can still be executed. |
|
|
33
|
-
| [Middleware & locals](#middleware-and-locals) | The middleware system runs at the top level, executing before and after all lifecycle hooks. The locals API allows sharing data between middleware and hooks. |
|
|
34
|
-
| [useWaitToken](/realtime/react-hooks/use-wait-token) | Use the useWaitToken hook to complete a wait token from a React component. |
|
|
35
|
-
| [Task-backed AI tools](/tasks/schemaTask#task-backed-ai-tools) | Use `schemaTask` with AI SDK `tool()` and `ai.toolExecute()` (legacy `ai.tool` is deprecated). |
|
|
36
|
-
|
|
37
|
-
## Node.js support
|
|
38
|
-
|
|
39
|
-
<NodeVersions />
|
|
40
|
-
|
|
41
|
-
## How to migrate to v4
|
|
42
|
-
|
|
43
|
-
First read the deprecations and breaking changes sections below.
|
|
44
|
-
|
|
45
|
-
We recommend the following steps to migrate to v4:
|
|
46
|
-
|
|
47
|
-
1. Install the v4 package.
|
|
48
|
-
2. Run the `trigger dev` CLI command and test your tasks locally, fixing any breaking changes.
|
|
49
|
-
3. Deploy to the staging environment and test your tasks in staging, fixing any breaking changes. (this step is optional, but highly recommended)
|
|
50
|
-
4. Once you've verified that v4 is working as expected, you should deploy your application backend with the updated v4 package.
|
|
51
|
-
5. Once you've deployed your application backend, you should deploy your tasks to the production environment.
|
|
52
|
-
|
|
53
|
-
Note that between steps 4 and 5, runs triggered with the v4 package will continue using v3, and only new runs triggered after step 5 is complete will use v4.
|
|
54
|
-
|
|
55
|
-
<Warning>
|
|
56
|
-
Once v4 is activated in your environment, there will be a period of time where old runs will
|
|
57
|
-
continue to execute using v3, while new runs will use v4. Because these engines use completely
|
|
58
|
-
different underlying queues and concurrency models, it's possible you may have up to double the
|
|
59
|
-
amount of concurrently executing runs. Once the runs drain from the old run engine, the
|
|
60
|
-
concurrency will return to normal.
|
|
61
|
-
</Warning>
|
|
62
|
-
|
|
63
|
-
<Note>
|
|
64
|
-
When migrating from v3 to v4, our infrastructure IPs may change. If you use IP allowlisting (e.g. for databases or APIs), [update your allowlists](https://trigger.dev/changelog/static-ips) with the current static IPs before or immediately after switching to v4 to avoid connectivity issues or downtime.
|
|
65
|
-
</Note>
|
|
66
|
-
|
|
67
|
-
## Migrate using AI
|
|
68
|
-
|
|
69
|
-
Use the prompt in the accordion below to help you migrate your v3 tasks to v4. The prompt gives good results when using Claude 4 Sonnet. You’ll need a relatively large token limit.
|
|
70
|
-
|
|
71
|
-
<MigrateV4UsingAi />
|
|
72
|
-
|
|
73
|
-
## Installation
|
|
74
|
-
|
|
75
|
-
To opt-in to using v4, you will need to update your dependencies to the latest version:
|
|
76
|
-
|
|
77
|
-
<CodeGroup>
|
|
78
|
-
|
|
79
|
-
```bash npx
|
|
80
|
-
npx trigger.dev@latest update
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
```bash yarn
|
|
84
|
-
yarn dlx trigger.dev@latest update
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
```bash pnpm
|
|
88
|
-
pnpm dlx trigger.dev@latest update
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
</CodeGroup>
|
|
92
|
-
|
|
93
|
-
This command should update all of your `@trigger.dev/*` packages to a `4.x` version.
|
|
94
|
-
|
|
95
|
-
## Deprecations
|
|
96
|
-
|
|
97
|
-
We've deprecated the following APIs:
|
|
98
|
-
|
|
99
|
-
### @trigger.dev/sdk/v3
|
|
100
|
-
|
|
101
|
-
We've deprecated the `@trigger.dev/sdk/v3` import path and moved to a new path:
|
|
102
|
-
|
|
103
|
-
```ts
|
|
104
|
-
// This still works, but will be removed in a future version
|
|
105
|
-
import { task } from "@trigger.dev/sdk/v3";
|
|
106
|
-
|
|
107
|
-
// This is the new path
|
|
108
|
-
import { task } from "@trigger.dev/sdk";
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### `handleError` and `init`
|
|
112
|
-
|
|
113
|
-
We've renamed the `handleError` hook to `catchError` to better reflect that it can catch and react to errors. `handleError` will be removed in a future version.
|
|
114
|
-
|
|
115
|
-
`init` was previously used to initialize data used in the run function:
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
import { task } from "@trigger.dev/sdk";
|
|
119
|
-
|
|
120
|
-
const myTask = task({
|
|
121
|
-
init: async () => {
|
|
122
|
-
return {
|
|
123
|
-
myClient: new MyClient(),
|
|
124
|
-
};
|
|
125
|
-
},
|
|
126
|
-
run: async (payload: any, { ctx, init }) => {
|
|
127
|
-
const client = init.myClient;
|
|
128
|
-
await client.doSomething();
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
This has now been deprecated in favor of the `locals` API and middleware. See the [Improved middleware and locals](/tasks/overview#middleware-and-locals-functions) section for more details.
|
|
134
|
-
|
|
135
|
-
### toolTask
|
|
136
|
-
|
|
137
|
-
We've deprecated the `toolTask` function, which created both a Trigger.dev task and a tool compatible with the Vercel [AI SDK](https://vercel.com/docs/ai-sdk):
|
|
138
|
-
|
|
139
|
-
```ts
|
|
140
|
-
import { toolTask, schemaTask } from "@trigger.dev/sdk";
|
|
141
|
-
import { z } from "zod";
|
|
142
|
-
import { generateText } from "ai";
|
|
143
|
-
|
|
144
|
-
const myToolTask = toolTask({
|
|
145
|
-
id: "my-tool-task",
|
|
146
|
-
run: async (payload: any, { ctx }) => {},
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
export const myAiTask = schemaTask({
|
|
150
|
-
id: "my-ai-task",
|
|
151
|
-
schema: z.object({
|
|
152
|
-
text: z.string(),
|
|
153
|
-
}),
|
|
154
|
-
run: async (payload, { ctx }) => {
|
|
155
|
-
const { text } = await generateText({
|
|
156
|
-
prompt: payload.text,
|
|
157
|
-
model: openai("gpt-4o"),
|
|
158
|
-
tools: {
|
|
159
|
-
myToolTask,
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
We've replaced the `toolTask` function with `schemaTask` plus AI SDK `tool()` and `ai.toolExecute()` (the older `ai.tool()` wrapper is deprecated). See [Task-backed AI tools](/tasks/schemaTask#task-backed-ai-tools).
|
|
167
|
-
|
|
168
|
-
## Breaking changes
|
|
169
|
-
|
|
170
|
-
### Queue changes
|
|
171
|
-
|
|
172
|
-
Previously, it was possible to specify a queue name of a queue that did not exist, along with a concurrency limit. The queue would then be created "on-demand" with the specified concurrency limit. If the queue did exist, the concurrency limit of the queue would be updated to the specified value:
|
|
173
|
-
|
|
174
|
-
```ts
|
|
175
|
-
await myTask.trigger({ foo: "bar" }, { queue: { name: "my-queue", concurrencyLimit: 10 } });
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
This is no longer possible, and queues must now be defined ahead of time using the `queue` function:
|
|
179
|
-
|
|
180
|
-
```ts
|
|
181
|
-
import { queue } from "@trigger.dev/sdk";
|
|
182
|
-
|
|
183
|
-
const myQueue = queue({
|
|
184
|
-
name: "my-queue",
|
|
185
|
-
concurrencyLimit: 10,
|
|
186
|
-
});
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
Now when you trigger a task, you can only specify the queue by name:
|
|
190
|
-
|
|
191
|
-
```ts
|
|
192
|
-
await myTask.trigger({ foo: "bar" }, { queue: "my-queue" });
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
Or you can set the queue on the task:
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
import { queue, task } from "@trigger.dev/sdk";
|
|
199
|
-
|
|
200
|
-
const myQueue = queue({
|
|
201
|
-
name: "my-queue",
|
|
202
|
-
concurrencyLimit: 10,
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
export const myTask = task({
|
|
206
|
-
id: "my-task",
|
|
207
|
-
queue: myQueue,
|
|
208
|
-
run: async (payload: any, { ctx }) => {},
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// You can optionally specify the queue directly on the task
|
|
212
|
-
export const myTask2 = task({
|
|
213
|
-
id: "my-task-2",
|
|
214
|
-
queue: {
|
|
215
|
-
name: "my-queue-2",
|
|
216
|
-
concurrencyLimit: 50,
|
|
217
|
-
},
|
|
218
|
-
run: async (payload: any, { ctx }) => {},
|
|
219
|
-
});
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Now you can trigger these tasks without having to specify the queue name in the trigger options:
|
|
223
|
-
|
|
224
|
-
```ts
|
|
225
|
-
await myTask.trigger({ foo: "bar" }); // Will use the queue defined on the task
|
|
226
|
-
await myTask2.trigger({ foo: "bar" }); // Will use the queue defined on the task
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
If you're using `concurrencyKey` you can specify the `queue` and `concurrencyKey` like this:
|
|
230
|
-
|
|
231
|
-
```ts
|
|
232
|
-
const handle = await generatePullRequest.trigger(data, {
|
|
233
|
-
queue: "paid-users",
|
|
234
|
-
concurrencyKey: data.userId,
|
|
235
|
-
});
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
For each unique value of `concurrencyKey`, a new queue will be created using the `concurrencyLimit` from the queue. This allows you to have a queue per user.
|
|
239
|
-
|
|
240
|
-
### Lifecycle hooks
|
|
241
|
-
|
|
242
|
-
We've changed the function signatures of the lifecycle hooks to be more consistent and easier to use, by unifying all the parameters into a single object that can be destructured.
|
|
243
|
-
|
|
244
|
-
Previously, hooks received a payload as the first argument and then an additional object as the second argument:
|
|
245
|
-
|
|
246
|
-
```ts
|
|
247
|
-
import { task } from "@trigger.dev/sdk";
|
|
248
|
-
|
|
249
|
-
export const myTask = task({
|
|
250
|
-
id: "my-task",
|
|
251
|
-
onStart: (payload, { ctx }) => {},
|
|
252
|
-
run: async (payload, { ctx }) => {},
|
|
253
|
-
});
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
Now, all the parameters are passed in a single object:
|
|
257
|
-
|
|
258
|
-
```ts
|
|
259
|
-
import { task } from "@trigger.dev/sdk";
|
|
260
|
-
|
|
261
|
-
export const myTask = task({
|
|
262
|
-
id: "my-task",
|
|
263
|
-
onStart: ({ payload, ctx }) => {},
|
|
264
|
-
// The run function still uses separate parameters
|
|
265
|
-
run: async (payload, { ctx }) => {},
|
|
266
|
-
});
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
This is true for all the lifecycle hooks:
|
|
270
|
-
|
|
271
|
-
```ts
|
|
272
|
-
import { task } from "@trigger.dev/sdk";
|
|
273
|
-
|
|
274
|
-
export const myTask = task({
|
|
275
|
-
id: "my-task",
|
|
276
|
-
onStart: ({ payload, ctx, task }) => {},
|
|
277
|
-
onSuccess: ({ payload, ctx, task, output }) => {},
|
|
278
|
-
onFailure: ({ payload, ctx, task, error }) => {},
|
|
279
|
-
onWait: ({ payload, ctx, task, wait }) => {},
|
|
280
|
-
onResume: ({ payload, ctx, task, wait }) => {},
|
|
281
|
-
onComplete: ({ payload, ctx, task, result }) => {},
|
|
282
|
-
catchError: ({ payload, ctx, task, error, retry, retryAt, retryDelayInMs }) => {},
|
|
283
|
-
run: async (payload, { ctx }) => {},
|
|
284
|
-
});
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
### Context changes
|
|
288
|
-
|
|
289
|
-
We've made a few small changes to the `ctx` object:
|
|
290
|
-
|
|
291
|
-
- `ctx.attempt.id` and `ctx.attempt.status` have been removed. `ctx.attempt.number` is still available.
|
|
292
|
-
- `ctx.task.exportName` has been removed (since we no longer require tasks to be exported to be triggered).
|
|
293
|
-
|
|
294
|
-
### BatchTrigger changes
|
|
295
|
-
|
|
296
|
-
The `batchTrigger` function no longer returns a `runs` list directly. In v3, you could access the runs directly from the batch handle:
|
|
297
|
-
|
|
298
|
-
```ts
|
|
299
|
-
// In v3
|
|
300
|
-
const batchHandle = await tasks.batchTrigger([
|
|
301
|
-
[myTask, { foo: "bar" }],
|
|
302
|
-
[myOtherTask, { baz: "qux" }],
|
|
303
|
-
]);
|
|
304
|
-
|
|
305
|
-
// You could access runs directly
|
|
306
|
-
console.log(batchHandle.runs);
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
In v4, you now need to use the `batch.retrieve()` method to get the batch with its runs:
|
|
310
|
-
|
|
311
|
-
```ts
|
|
312
|
-
// In v4
|
|
313
|
-
const batchHandle = await tasks.batchTrigger([
|
|
314
|
-
[myTask, { foo: "bar" }],
|
|
315
|
-
[myOtherTask, { baz: "qux" }],
|
|
316
|
-
]);
|
|
317
|
-
|
|
318
|
-
// Now you need to retrieve the batch to get the runs
|
|
319
|
-
const batch = await batch.retrieve(batchHandle.batchId);
|
|
320
|
-
console.log(batch.runs);
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
### OpenTelemetry
|
|
324
|
-
|
|
325
|
-
We are now using newer versions of the OpenTelemetry packages. This means that if you're using custom exporters you may need to update the packages:
|
|
326
|
-
|
|
327
|
-
| Package | Previous Version | New Version | Change Type |
|
|
328
|
-
| ----------------------------------------- | ---------------- | ----------- | ------------ |
|
|
329
|
-
| `@opentelemetry/api-logs` | 0.52.1 | 0.203.0 | Major update |
|
|
330
|
-
| `@opentelemetry/exporter-logs-otlp-http` | 0.52.1 | 0.203.0 | Major update |
|
|
331
|
-
| `@opentelemetry/exporter-trace-otlp-http` | 0.52.1 | 0.203.0 | Major update |
|
|
332
|
-
| `@opentelemetry/instrumentation` | 0.52.1 | 0.203.0 | Major update |
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Webhooks public beta"
|
|
3
|
-
description: "Webhooks are available to every organization in the normal Trigger.dev release. Install the packages, see what may change before general availability, and send feedback."
|
|
4
|
-
sidebarTitle: "Public beta"
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
**Webhooks are in public beta: every organization can use them, and they ship in the normal Trigger.dev release.** Endpoints you declare sync when you deploy or run `trigger dev`, and they show up on each environment's **Webhooks** page.
|
|
8
|
-
|
|
9
|
-
## What public beta means
|
|
10
|
-
|
|
11
|
-
- The API may still change before general availability. We announce changes in the [changelog](https://trigger.dev/changelog).
|
|
12
|
-
- Webhooks are open source, so they work self-hosted too. See [Self-hosting webhooks](/self-hosting/env/webapp#webhooks) to turn them on.
|
|
13
|
-
|
|
14
|
-
## Install the packages
|
|
15
|
-
|
|
16
|
-
Webhooks are in `@trigger.dev/sdk` 4.8.1 and later. Install the SDK and the CLI from `@latest`:
|
|
17
|
-
|
|
18
|
-
<CodeGroup>
|
|
19
|
-
|
|
20
|
-
```bash npm
|
|
21
|
-
npm i @trigger.dev/sdk@latest
|
|
22
|
-
npm i -D trigger.dev@latest
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
```bash pnpm
|
|
26
|
-
pnpm add @trigger.dev/sdk@latest
|
|
27
|
-
pnpm add -D trigger.dev@latest
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
```bash bun
|
|
31
|
-
bun add @trigger.dev/sdk@latest
|
|
32
|
-
bun add -D trigger.dev@latest
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
</CodeGroup>
|
|
36
|
-
|
|
37
|
-
Add the connector packages if you're building Slack or Linear agents:
|
|
38
|
-
|
|
39
|
-
<CodeGroup>
|
|
40
|
-
|
|
41
|
-
```bash npm
|
|
42
|
-
npm i @trigger.dev/slack@latest @trigger.dev/linear@latest
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
```bash pnpm
|
|
46
|
-
pnpm add @trigger.dev/slack@latest @trigger.dev/linear@latest
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
```bash bun
|
|
50
|
-
bun add @trigger.dev/slack@latest @trigger.dev/linear@latest
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
</CodeGroup>
|
|
54
|
-
|
|
55
|
-
The webhook tools in the [MCP server](/mcp-introduction) come with the CLI, so a current `trigger.dev` install has them.
|
|
56
|
-
|
|
57
|
-
## Moving from a private beta build
|
|
58
|
-
|
|
59
|
-
If you installed from the `webhooks` npm tag, switch every Trigger.dev package to `@latest`, including `@trigger.dev/build` if your project has it. Versions like `4.8.0-webhooks.20261020092920` are older than 4.8.1. You can also remove any minimum release age exemption you added for the beta builds, and reinstall the MCP server without `--tag webhooks`.
|
|
60
|
-
|
|
61
|
-
## Get started
|
|
62
|
-
|
|
63
|
-
- [Overview](/webhooks/overview): endpoints, sources, and what can subscribe.
|
|
64
|
-
- [Connect a provider](/webhooks/connect): register the URL and signing secret, then check that events arrive.
|
|
65
|
-
- [Slack agents](/webhooks/slack) and [Linear agents](/webhooks/linear): turn a `chat.agent` into an agent that lives in Slack or Linear.
|
|
66
|
-
- [Deliveries and endpoints](/webhooks/deliveries): inspect payloads, replay deliveries, and see the runs each one started.
|
|
67
|
-
|
|
68
|
-
## Feedback
|
|
69
|
-
|
|
70
|
-
Send bugs, questions and ideas to [eric@trigger.dev](mailto:eric@trigger.dev). Delivery ids (`whd_...`) and run ids help us find what happened.
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Sources and verification"
|
|
3
|
-
description: "Choose an endpoint's source, configure verification, and type the event its subscribers receive."
|
|
4
|
-
sidebarTitle: "Sources & verification"
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
An endpoint's `source` defines how Trigger.dev verifies requests and types the event every subscriber receives. Choose a named provider source or supply a verification configuration with `webhooks.custom()`.
|
|
8
|
-
|
|
9
|
-
## Presets
|
|
10
|
-
|
|
11
|
-
Presets supply the verification configuration, and most also carry the provider's part of the endpoint's [setup prompt](/webhooks/connect#set-it-up-with-an-ai-agent). Set the endpoint's signing secret or public key as described in [Connect a provider](/webhooks/connect).
|
|
12
|
-
|
|
13
|
-
<CodeGroup>
|
|
14
|
-
|
|
15
|
-
```ts /trigger/stripe.ts
|
|
16
|
-
import { webhook, webhooks } from "@trigger.dev/sdk";
|
|
17
|
-
|
|
18
|
-
export const stripe = webhooks.endpoint.define({ id: "stripe", source: webhooks.stripe() });
|
|
19
|
-
|
|
20
|
-
export const stripeEvents = webhook({
|
|
21
|
-
id: "stripe-events",
|
|
22
|
-
endpoint: stripe,
|
|
23
|
-
onEvent: async ({ event }) => {
|
|
24
|
-
if (event.type === "payment_intent.succeeded") {
|
|
25
|
-
console.log(event.id);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
```ts /trigger/github.ts
|
|
32
|
-
import { webhook, webhooks } from "@trigger.dev/sdk";
|
|
33
|
-
|
|
34
|
-
export const github = webhooks.endpoint.define({ id: "github", source: webhooks.github() });
|
|
35
|
-
|
|
36
|
-
export const githubEvents = webhook({
|
|
37
|
-
id: "github-events",
|
|
38
|
-
endpoint: github,
|
|
39
|
-
onEvent: async ({ headers }) => {
|
|
40
|
-
// GitHub puts the event type in a header
|
|
41
|
-
console.log(headers.get("x-github-event"));
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
```ts /trigger/svix.ts
|
|
47
|
-
import { webhook, webhooks } from "@trigger.dev/sdk";
|
|
48
|
-
|
|
49
|
-
export const svix = webhooks.endpoint.define({ id: "svix", source: webhooks.svix() });
|
|
50
|
-
|
|
51
|
-
export const svixEvents = webhook({
|
|
52
|
-
id: "svix-events",
|
|
53
|
-
endpoint: svix,
|
|
54
|
-
onEvent: async ({ event }) => {
|
|
55
|
-
console.log(event);
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
```ts /trigger/composio.ts
|
|
61
|
-
import { webhook, webhooks } from "@trigger.dev/sdk";
|
|
62
|
-
|
|
63
|
-
export const composio = webhooks.endpoint.define({ id: "composio", source: webhooks.standardWebhooks() });
|
|
64
|
-
|
|
65
|
-
export const composioEvents = webhook({
|
|
66
|
-
id: "composio-events",
|
|
67
|
-
endpoint: composio,
|
|
68
|
-
onEvent: async ({ event }) => {
|
|
69
|
-
console.log(event);
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
</CodeGroup>
|
|
75
|
-
|
|
76
|
-
The available presets are `stripe()`, `github()`, `svix()`, `standardWebhooks()`, `square()`, and `discord()`.
|
|
77
|
-
|
|
78
|
-
### Svix and Standard Webhooks
|
|
79
|
-
|
|
80
|
-
`svix()` and `standardWebhooks()` use HMAC-SHA256 over `id.timestamp.body` with a base64-encoded `whsec_` secret. Their header names differ:
|
|
81
|
-
|
|
82
|
-
| Source | Headers |
|
|
83
|
-
| --- | --- |
|
|
84
|
-
| `svix()` | `svix-id`, `svix-timestamp`, `svix-signature` |
|
|
85
|
-
| `standardWebhooks()` | `webhook-id`, `webhook-timestamp`, `webhook-signature` |
|
|
86
|
-
|
|
87
|
-
Named sources such as `webhooks.clerk()` and `webhooks.composio()` select the corresponding configuration.
|
|
88
|
-
|
|
89
|
-
## Named providers
|
|
90
|
-
|
|
91
|
-
Each function below returns a source with its provider's verification configuration. Call it through `webhooks`, for example `webhooks.calCom()`.
|
|
92
|
-
|
|
93
|
-
| Verification | Source functions |
|
|
94
|
-
| --- | --- |
|
|
95
|
-
| Svix | `clerk()`, `resend()`, `brex()`, `autumn()` |
|
|
96
|
-
| Standard Webhooks | `openai()`, `replicate()`, `recallai()`, `composio()`, `loops()`, `granola()` |
|
|
97
|
-
| HMAC-SHA256 with `X-Hub-Signature-256` | `whatsapp()` |
|
|
98
|
-
| Shared secret in `X-Gitlab-Token` | `gitlab()` |
|
|
99
|
-
| Shared secret as `Authorization: Bearer` | `supabase()` |
|
|
100
|
-
| Hookdeck relay (HMAC-SHA256 with `X-Hookdeck-Signature`) | `hookdeck()` |
|
|
101
|
-
| Provider-specific HMAC | `calendly()`, `calCom()`, `sentry()`, `pagerduty()`, `vercel()`, `linear()`, `notion()`, `typeform()`, `docusign()`, `jira()`, `intercom()`, `zendesk()`, `attio()`, `workos()`, `elevenlabs()`, `vapi()`, `retell()`, `shopify()`, `metronome()`, `mux()`, `tailscale()`, `langfuse()`, `infisical()`, `planetscale()`, `plain()`, `firecrawl()` |
|
|
102
|
-
|
|
103
|
-
Provider IDs containing a hyphen use a camel case function name: the `cal-com` provider is `webhooks.calCom()`.
|
|
104
|
-
|
|
105
|
-
Supabase database webhooks aren't signed, so `supabase()` checks a shared secret instead. Generate the endpoint's secret on Trigger.dev, then add an `Authorization` header with the value `Bearer <secret>` under the webhook's HTTP Headers in Supabase.
|
|
106
|
-
|
|
107
|
-
Slack also ships as a chat channel in `@trigger.dev/slack`.
|
|
108
|
-
|
|
109
|
-
For a complete project built on `resend()`, see the [Resend email agent example](https://github.com/triggerdotdev/examples/tree/main/resend-slack-email-agent). It drafts replies to a Resend inbox and waits for your approval in Slack before sending them.
|
|
110
|
-
|
|
111
|
-
### Hookdeck
|
|
112
|
-
|
|
113
|
-
`hookdeck()` verifies requests that a [Hookdeck](https://hookdeck.com) connection forwards to the endpoint. Hookdeck forwards the original provider's body unchanged, so pass that provider's event type:
|
|
114
|
-
|
|
115
|
-
```ts /trigger/stripe-via-hookdeck.ts
|
|
116
|
-
import type Stripe from "stripe";
|
|
117
|
-
import { webhook, webhooks } from "@trigger.dev/sdk";
|
|
118
|
-
|
|
119
|
-
export const stripeViaHookdeck = webhooks.endpoint.define({
|
|
120
|
-
id: "stripe-via-hookdeck",
|
|
121
|
-
source: webhooks.hookdeck<Stripe.Event>(),
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
export const paymentSucceeded = webhook({
|
|
125
|
-
id: "payment-succeeded",
|
|
126
|
-
endpoint: stripeViaHookdeck,
|
|
127
|
-
filter: "event.type == 'payment_intent.succeeded'",
|
|
128
|
-
onEvent: async ({ event }) => {
|
|
129
|
-
console.log(event.id);
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Use the endpoint URL as the connection's HTTP destination, keep the destination's authentication on Hookdeck Signature (the default for new destinations), and store the Hookdeck project's signing secret from **Settings > Secrets** as the endpoint's signing secret.
|
|
135
|
-
|
|
136
|
-
- **Secret rotation:** when you roll the signing secret in Hookdeck with an expiry, Hookdeck also signs each request with the previous secret in `X-Hookdeck-Signature-2`, so deliveries keep verifying until you store the new secret.
|
|
137
|
-
- **Deduplication:** retries dedupe on `X-Hookdeck-Eventid`, which is the same on every attempt of a Hookdeck event.
|
|
138
|
-
- **Custom header prefix:** if you changed the header prefix in the Hookdeck project's settings, pass it with `webhooks.hookdeck({ headerPrefix: "x-acme" })`. The prefix renames the event id header; the signature headers keep the `X-Hookdeck-` name.
|
|
139
|
-
|
|
140
|
-
## Endpoint validation
|
|
141
|
-
|
|
142
|
-
Some sources also define a response for the provider's endpoint-validation request. These requests don't create deliveries or task runs.
|
|
143
|
-
|
|
144
|
-
`discord()` answers a verified `{ type: 0 }` PING with HTTP `204` and no body. It also returns `204` for accepted events and `401` for invalid signatures. Set the Discord application's public key as the endpoint's verification credential.
|
|
145
|
-
|
|
146
|
-
Slack's `url_verification` challenge is handled the same way by `@trigger.dev/slack`.
|
|
147
|
-
|
|
148
|
-
`whatsapp()` answers Meta's GET verification request when `hub.mode` is `subscribe` and `hub.verify_token` matches the endpoint's verify token. It returns `hub.challenge` as text. The verify token is separate from the App Secret used to verify event signatures; see [Verify a WhatsApp endpoint URL](/webhooks/connect#verify-a-whatsapp-endpoint-url). Endpoints without GET verification return `405` to GET requests.
|
|
149
|
-
|
|
150
|
-
## Custom providers
|
|
151
|
-
|
|
152
|
-
`webhooks.custom()` accepts a verification configuration. This source verifies an HMAC-SHA256 signature over the raw body in `x-webhook-signature` and uses the event's `id` for deduplication:
|
|
153
|
-
|
|
154
|
-
```ts /trigger/internal.ts
|
|
155
|
-
import { webhook, webhooks } from "@trigger.dev/sdk";
|
|
156
|
-
|
|
157
|
-
export const internal = webhooks.endpoint.define({
|
|
158
|
-
id: "internal",
|
|
159
|
-
source: webhooks.custom<{ id: string; message: string }>(
|
|
160
|
-
{
|
|
161
|
-
scheme: "hmac",
|
|
162
|
-
algorithm: "sha256",
|
|
163
|
-
encoding: "hex",
|
|
164
|
-
signatureHeader: "x-webhook-signature",
|
|
165
|
-
signingString: "raw",
|
|
166
|
-
idempotencyField: { from: "body", name: "id" },
|
|
167
|
-
},
|
|
168
|
-
{ setupPrompt: "Add the URL under Settings > Webhooks in the admin app and paste the secret there." }
|
|
169
|
-
),
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
export const internalEvents = webhook({
|
|
173
|
-
id: "internal-events",
|
|
174
|
-
endpoint: internal,
|
|
175
|
-
onEvent: async ({ event }) => {
|
|
176
|
-
console.log(event.message);
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
The optional `setupPrompt` is the provider-specific part of the endpoint's [setup prompt](/webhooks/connect#set-it-up-with-an-ai-agent): where the provider's webhook settings are and how to register a URL there. Trigger.dev adds the URL, the subscribers' filters and the signing secret steps around it.
|
|
182
|
-
|
|
183
|
-
### Form-encoded bodies
|
|
184
|
-
|
|
185
|
-
A verified body sent as `application/x-www-form-urlencoded` reaches subscribers as an object of its fields, so filters, `chat.event` keys and waiter `match` paths read form fields the way they read JSON fields. A repeated field becomes an array of its values. Slack slash commands and other providers that post forms work this way.
|
|
186
|
-
|
|
187
|
-
By default an accepted request gets a `200` with a small JSON receipt. Some providers show the response body to the user who triggered the request, so pass `response: { acceptedBody: "empty" }` to answer with an empty `200` instead:
|
|
188
|
-
|
|
189
|
-
```ts /trigger/forms.ts
|
|
190
|
-
import { webhook, webhooks } from "@trigger.dev/sdk";
|
|
191
|
-
|
|
192
|
-
export const forms = webhooks.endpoint.define({
|
|
193
|
-
id: "forms",
|
|
194
|
-
source: webhooks.custom<{ command: string; text: string; user_id: string }>(
|
|
195
|
-
{ scheme: "url-secret", placement: "query", paramName: "token" },
|
|
196
|
-
{ response: { acceptedBody: "empty" } }
|
|
197
|
-
),
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
export const commands = webhook({
|
|
201
|
-
id: "commands",
|
|
202
|
-
endpoint: forms,
|
|
203
|
-
filter: "event.command == '/deploy'",
|
|
204
|
-
onEvent: async ({ event }) => {
|
|
205
|
-
console.log(event.user_id, event.text);
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## Typing the event
|
|
211
|
-
|
|
212
|
-
Stripe and GitHub sources provide default event shapes; other sources default to `unknown`. Pass an event type to the source function for typed handler parameters and autocomplete. This example uses `Stripe.Event` from the `stripe` package, which must be installed in your project:
|
|
213
|
-
|
|
214
|
-
```ts /trigger/stripe.ts
|
|
215
|
-
import type Stripe from "stripe";
|
|
216
|
-
import { webhook, webhooks } from "@trigger.dev/sdk";
|
|
217
|
-
|
|
218
|
-
export const stripe = webhooks.endpoint.define({ id: "stripe", source: webhooks.stripe<Stripe.Event>() });
|
|
219
|
-
|
|
220
|
-
export const stripeEvents = webhook({
|
|
221
|
-
id: "stripe-events",
|
|
222
|
-
endpoint: stripe,
|
|
223
|
-
onEvent: async ({ event }) => {
|
|
224
|
-
console.log(event.type, event.id);
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
For `webhooks.custom<T>()`, pass your own event type as `T`. The endpoint's event type flows to every subscriber: `webhook()` handlers, `chat.event` keys and filters, and [waiter](/webhooks/waiters) `match` paths are all checked against it.
|
|
230
|
-
|
|
231
|
-
<Note>
|
|
232
|
-
Event types are compile-time annotations. Signature verification doesn't validate the body against
|
|
233
|
-
a TypeScript type. Validate `event` inside `onEvent` if your handler needs runtime schema checks.
|
|
234
|
-
</Note>
|
|
235
|
-
|
|
236
|
-
## Verification schemes
|
|
237
|
-
|
|
238
|
-
Requests must pass verification before they reach any subscriber. Sources can check a signature or credential, enforce a timestamp tolerance, and derive an idempotency key for [deduplication](/webhooks/deliveries#deduplication). Verification failures return the source's rejected HTTP status (`400` by default).
|
|
239
|
-
|
|
240
|
-
Custom sources support these schemes:
|
|
241
|
-
|
|
242
|
-
| Scheme | Verification |
|
|
243
|
-
| --- | --- |
|
|
244
|
-
| `hmac` | Computes an HMAC over the raw body or a signing template and compares it with a request header. |
|
|
245
|
-
| `shared-secret` | Compares a static token supplied in a header, bearer token, basic authentication, or request body. |
|
|
246
|
-
| `url-secret` | Compares a token in a URL query parameter. Hosted endpoints don't support path placement. |
|
|
247
|
-
| `asymmetric` | Verifies an Ed25519, ECDSA (P-256 with SHA-256, P-384 with SHA-384), or RSA-SHA256 signature using the provider's public key. Set `prehash: "sha256"` when the provider signs a SHA-256 digest of the signing string instead of the string itself. |
|
|
248
|
-
|
|
249
|
-
<Warning>
|
|
250
|
-
Query parameters can appear in access logs, proxies, and traces. Prefer a header-based scheme when
|
|
251
|
-
the provider supports one.
|
|
252
|
-
</Warning>
|