@trigora/sdk 0.5.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -86,18 +86,21 @@ Use webhook triggers for hosted HTTP entrypoints.
86
86
  import { defineFlow } from '@trigora/sdk';
87
87
 
88
88
  export default defineFlow({
89
- id: 'ping',
90
- trigger: { type: 'webhook' },
89
+ id: 'stripe-webhook',
90
+ trigger: { type: 'webhook', route: '/hooks/stripe' },
91
91
  async run() {
92
92
  return 'pong';
93
93
  },
94
94
  });
95
95
  ```
96
96
 
97
+ `id` is the internal flow identifier used by the CLI. `route` is the optional public hosted webhook path.
98
+ When `route` is omitted, hosted ingress defaults to `/${id}`.
99
+
97
100
  You can also include an optional event name:
98
101
 
99
102
  ```ts
100
- trigger: { type: 'webhook', event: 'orders.created' }
103
+ trigger: { type: 'webhook', event: 'orders.created', route: '/hooks/orders' }
101
104
  ```
102
105
 
103
106
  ### Cron
@@ -116,6 +119,28 @@ export default defineFlow({
116
119
  });
117
120
  ```
118
121
 
122
+ ### Queue
123
+
124
+ Use queue triggers to consume workspace-scoped queue messages. Deploy auto-provisions and binds the named queue to the flow.
125
+
126
+ ```ts
127
+ import { defineFlow } from '@trigora/sdk';
128
+
129
+ export default defineFlow({
130
+ id: 'process-image',
131
+ trigger: { type: 'queue', queue: 'image-processing' },
132
+ async run(event, ctx) {
133
+ await ctx.log.info('Processing message', {
134
+ queue: event.queue,
135
+ messageId: event.messageId,
136
+ payload: event.payload,
137
+ });
138
+ },
139
+ });
140
+ ```
141
+
142
+ Locally, `trigora trigger` and `trigora dev` invoke queue flows with a synthetic `QueueFlowEvent` (`messageId` starts with `local_`). Hosted runs use the real message id.
143
+
119
144
  ## Return Types
120
145
 
121
146
  Return values are trigger-aware.
@@ -139,7 +164,7 @@ import { defineFlow } from '@trigora/sdk';
139
164
 
140
165
  export default defineFlow({
141
166
  id: 'status',
142
- trigger: { type: 'webhook' },
167
+ trigger: { type: 'webhook', route: '/status' },
143
168
  async run() {
144
169
  return {
145
170
  ok: true,
@@ -149,14 +174,15 @@ export default defineFlow({
149
174
  });
150
175
  ```
151
176
 
152
- ### Manual and cron flows
177
+ ### Manual, cron, and queue flows
153
178
 
154
- Manual and cron flows do not use return values. Their `run` functions are typed as `void`.
179
+ Manual, cron, and queue flows do not use return values. Their `run` functions are typed as `void`.
155
180
 
156
181
  This matches how Trigora uses them:
157
182
 
158
183
  - manual flows are invoked locally for testing and development
159
184
  - cron flows are background-style scheduled jobs
185
+ - queue flows consume workspace queue messages
160
186
  - webhook flows are request-response flows
161
187
 
162
188
  ## Event Shape
@@ -189,10 +215,19 @@ For webhook flows, request metadata may also be available on `event.request`, in
189
215
  Trigora includes a small helper for verifying Stripe webhook signatures:
190
216
 
191
217
  ```ts
218
+ import { defineFlow } from '@trigora/sdk';
192
219
  import { verifyStripeWebhook } from '@trigora/sdk/stripe';
193
220
 
194
- const stripeEvent = await verifyStripeWebhook(event, {
195
- secret: ctx.env.STRIPE_WEBHOOK_SECRET,
221
+ export default defineFlow({
222
+ id: 'stripe-webhook',
223
+ trigger: { type: 'webhook', route: '/hooks/stripe' },
224
+ async run(event, ctx) {
225
+ await verifyStripeWebhook(event, {
226
+ secret: ctx.env.STRIPE_WEBHOOK_SECRET,
227
+ });
228
+
229
+ return { ok: true };
230
+ },
196
231
  });
197
232
  ```
198
233
 
@@ -205,10 +240,19 @@ Production Stripe webhooks should verify signatures before trusting payloads.
205
240
  Trigora includes a small helper for verifying GitHub webhook signatures:
206
241
 
207
242
  ```ts
243
+ import { defineFlow } from '@trigora/sdk';
208
244
  import { verifyGitHubWebhook } from '@trigora/sdk/github';
209
245
 
210
- const githubEvent = await verifyGitHubWebhook(event, {
211
- secret: ctx.env.GITHUB_WEBHOOK_SECRET,
246
+ export default defineFlow({
247
+ id: 'github-webhook',
248
+ trigger: { type: 'webhook', route: '/hooks/github' },
249
+ async run(event, ctx) {
250
+ await verifyGitHubWebhook(event, {
251
+ secret: ctx.env.GITHUB_WEBHOOK_SECRET,
252
+ });
253
+
254
+ return { ok: true };
255
+ },
212
256
  });
213
257
  ```
214
258
 
@@ -1,20 +1,24 @@
1
- import type { CronEventPayload, CronFlowDefinition, FlowDefinition, FlowRunFn, JsonValue, ManualFlowDefinition, ManualTrigger, Trigger, WebhookTrigger, WebhookFlowDefinition, CronTrigger } from '@trigora/contracts';
1
+ import type { CronEventPayload, CronFlowDefinition, FlowDefinition, FlowRunFn, JsonValue, ManualFlowDefinition, ManualTrigger, QueueFlowDefinition, QueueTrigger, Trigger, WebhookTrigger, WebhookFlowDefinition, CronTrigger } from '@trigora/contracts';
2
2
  type DefineFlowInput<TPayload, TEnv extends Record<string, string>, TTrigger extends Trigger> = {
3
3
  id: string;
4
4
  trigger: TTrigger;
5
- run: TTrigger extends ManualTrigger ? FlowRunFn<TPayload, TEnv, ManualTrigger> : TTrigger extends WebhookTrigger ? FlowRunFn<TPayload, TEnv, WebhookTrigger> : TTrigger extends CronTrigger ? FlowRunFn<CronEventPayload, TEnv, CronTrigger> : never;
5
+ run: TTrigger extends ManualTrigger ? FlowRunFn<TPayload, TEnv, ManualTrigger> : TTrigger extends WebhookTrigger ? FlowRunFn<TPayload, TEnv, WebhookTrigger> : TTrigger extends CronTrigger ? FlowRunFn<CronEventPayload, TEnv, CronTrigger> : TTrigger extends QueueTrigger ? FlowRunFn<TPayload, TEnv, QueueTrigger> : never;
6
6
  };
7
- type DefineFlowOutput<TPayload, TEnv extends Record<string, string>, TTrigger extends Trigger> = TTrigger extends ManualTrigger ? ManualFlowDefinition<TPayload, TEnv> : TTrigger extends WebhookTrigger ? WebhookFlowDefinition<TPayload, TEnv> : TTrigger extends CronTrigger ? CronFlowDefinition<TEnv> : FlowDefinition<TPayload, TEnv, TTrigger>;
7
+ type DefineFlowOutput<TPayload, TEnv extends Record<string, string>, TTrigger extends Trigger> = TTrigger extends ManualTrigger ? ManualFlowDefinition<TPayload, TEnv> : TTrigger extends WebhookTrigger ? WebhookFlowDefinition<TPayload, TEnv> : TTrigger extends CronTrigger ? CronFlowDefinition<TEnv> : TTrigger extends QueueTrigger ? QueueFlowDefinition<TPayload, TEnv> : FlowDefinition<TPayload, TEnv, TTrigger>;
8
8
  /**
9
9
  * Define a Trigora flow.
10
10
  *
11
11
  * Flows are plain TypeScript modules with three core parts:
12
- * - `id`: the source identifier for the flow in your project
12
+ * - `id`: the internal identifier for the flow in your project
13
13
  * - `trigger`: how the flow is invoked
14
14
  * - `run`: the function that executes when the flow is triggered
15
15
  *
16
16
  * `run` receives the incoming `event` and a `ctx` object with logging and environment access.
17
17
  *
18
+ * For webhook flows, `trigger.route` controls the public hosted path and defaults to `/${id}`.
19
+ * This is separate from the flow `id`, which is still what the CLI uses for commands like
20
+ * `trigora deploy hello` or `trigora flows inspect hello`.
21
+ *
18
22
  * Webhook flows can return HTTP-friendly values:
19
23
  * - `Response`
20
24
  * - plain objects / arrays / numbers / booleans
@@ -26,8 +30,8 @@ type DefineFlowOutput<TPayload, TEnv extends Record<string, string>, TTrigger ex
26
30
  * @example
27
31
  * ```ts
28
32
  * export default defineFlow({
29
- * id: 'hello',
30
- * trigger: { type: 'webhook' },
33
+ * id: 'stripe-webhook',
34
+ * trigger: { type: 'webhook', route: '/hooks/stripe' },
31
35
  * async run(event, ctx) {
32
36
  * await ctx.log.info('Received event', event.payload);
33
37
  * return { ok: true };
@@ -39,4 +43,5 @@ export declare function defineFlow<TTrigger extends Trigger, TPayload = JsonValu
39
43
  export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: ManualFlowDefinition<TPayload, TEnv>): ManualFlowDefinition<TPayload, TEnv>;
40
44
  export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: WebhookFlowDefinition<TPayload, TEnv>): WebhookFlowDefinition<TPayload, TEnv>;
41
45
  export declare function defineFlow<TEnv extends Record<string, string> = Record<string, string>>(flow: CronFlowDefinition<TEnv>): CronFlowDefinition<TEnv>;
46
+ export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: QueueFlowDefinition<TPayload, TEnv>): QueueFlowDefinition<TPayload, TEnv>;
42
47
  export {};
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { defineFlow } from './defineFlow';
2
- export type { CronEventPayload, CronFlowEvent, FlowContext, FlowDefinition, FlowEvent, FlowRunFn, JsonValue, ManualFlowEvent, Trigger, WebhookFlowEvent, WebhookFlowResult, } from '@trigora/contracts';
2
+ export type { CronEventPayload, CronFlowEvent, FlowContext, FlowDefinition, FlowEvent, FlowRunFn, JsonValue, ManualFlowEvent, QueueFlowEvent, Trigger, WebhookFlowEvent, WebhookFlowResult, } from '@trigora/contracts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigora/sdk",
3
- "version": "0.5.0",
3
+ "version": "0.8.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/trigora-dev/trigora"
@@ -18,6 +18,7 @@
18
18
  "cli",
19
19
  "triggers",
20
20
  "cron",
21
+ "queues",
21
22
  "webhooks"
22
23
  ],
23
24
  "license": "MIT",
@@ -45,7 +46,7 @@
45
46
  "access": "public"
46
47
  },
47
48
  "dependencies": {
48
- "@trigora/contracts": "0.5.5"
49
+ "@trigora/contracts": "0.8.1"
49
50
  },
50
51
  "devDependencies": {
51
52
  "tsup": "^8.5.1"