@trigora/sdk 0.4.0 → 0.6.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
@@ -139,7 +142,7 @@ import { defineFlow } from '@trigora/sdk';
139
142
 
140
143
  export default defineFlow({
141
144
  id: 'status',
142
- trigger: { type: 'webhook' },
145
+ trigger: { type: 'webhook', route: '/status' },
143
146
  async run() {
144
147
  return {
145
148
  ok: true,
@@ -189,10 +192,19 @@ For webhook flows, request metadata may also be available on `event.request`, in
189
192
  Trigora includes a small helper for verifying Stripe webhook signatures:
190
193
 
191
194
  ```ts
195
+ import { defineFlow } from '@trigora/sdk';
192
196
  import { verifyStripeWebhook } from '@trigora/sdk/stripe';
193
197
 
194
- const stripeEvent = await verifyStripeWebhook(event, {
195
- secret: ctx.env.STRIPE_WEBHOOK_SECRET,
198
+ export default defineFlow({
199
+ id: 'stripe-webhook',
200
+ trigger: { type: 'webhook', route: '/hooks/stripe' },
201
+ async run(event, ctx) {
202
+ await verifyStripeWebhook(event, {
203
+ secret: ctx.env.STRIPE_WEBHOOK_SECRET,
204
+ });
205
+
206
+ return { ok: true };
207
+ },
196
208
  });
197
209
  ```
198
210
 
@@ -205,10 +217,19 @@ Production Stripe webhooks should verify signatures before trusting payloads.
205
217
  Trigora includes a small helper for verifying GitHub webhook signatures:
206
218
 
207
219
  ```ts
220
+ import { defineFlow } from '@trigora/sdk';
208
221
  import { verifyGitHubWebhook } from '@trigora/sdk/github';
209
222
 
210
- const githubEvent = await verifyGitHubWebhook(event, {
211
- secret: ctx.env.GITHUB_WEBHOOK_SECRET,
223
+ export default defineFlow({
224
+ id: 'github-webhook',
225
+ trigger: { type: 'webhook', route: '/hooks/github' },
226
+ async run(event, ctx) {
227
+ await verifyGitHubWebhook(event, {
228
+ secret: ctx.env.GITHUB_WEBHOOK_SECRET,
229
+ });
230
+
231
+ return { ok: true };
232
+ },
212
233
  });
213
234
  ```
214
235
 
@@ -1,14 +1,24 @@
1
- import type { CronFlowDefinition, JsonValue, ManualFlowDefinition, WebhookFlowDefinition } from '@trigora/contracts';
1
+ import type { CronEventPayload, CronFlowDefinition, FlowDefinition, FlowRunFn, JsonValue, ManualFlowDefinition, ManualTrigger, Trigger, WebhookTrigger, WebhookFlowDefinition, CronTrigger } from '@trigora/contracts';
2
+ type DefineFlowInput<TPayload, TEnv extends Record<string, string>, TTrigger extends Trigger> = {
3
+ id: string;
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;
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>;
2
8
  /**
3
9
  * Define a Trigora flow.
4
10
  *
5
11
  * Flows are plain TypeScript modules with three core parts:
6
- * - `id`: the source identifier for the flow in your project
12
+ * - `id`: the internal identifier for the flow in your project
7
13
  * - `trigger`: how the flow is invoked
8
14
  * - `run`: the function that executes when the flow is triggered
9
15
  *
10
16
  * `run` receives the incoming `event` and a `ctx` object with logging and environment access.
11
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
+ *
12
22
  * Webhook flows can return HTTP-friendly values:
13
23
  * - `Response`
14
24
  * - plain objects / arrays / numbers / booleans
@@ -20,8 +30,8 @@ import type { CronFlowDefinition, JsonValue, ManualFlowDefinition, WebhookFlowDe
20
30
  * @example
21
31
  * ```ts
22
32
  * export default defineFlow({
23
- * id: 'hello',
24
- * trigger: { type: 'webhook' },
33
+ * id: 'stripe-webhook',
34
+ * trigger: { type: 'webhook', route: '/hooks/stripe' },
25
35
  * async run(event, ctx) {
26
36
  * await ctx.log.info('Received event', event.payload);
27
37
  * return { ok: true };
@@ -29,6 +39,8 @@ import type { CronFlowDefinition, JsonValue, ManualFlowDefinition, WebhookFlowDe
29
39
  * });
30
40
  * ```
31
41
  */
42
+ export declare function defineFlow<TTrigger extends Trigger, TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: DefineFlowInput<TPayload, TEnv, TTrigger>): DefineFlowOutput<TPayload, TEnv, TTrigger>;
32
43
  export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: ManualFlowDefinition<TPayload, TEnv>): ManualFlowDefinition<TPayload, TEnv>;
33
44
  export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: WebhookFlowDefinition<TPayload, TEnv>): WebhookFlowDefinition<TPayload, TEnv>;
34
- export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: CronFlowDefinition<TPayload, TEnv>): CronFlowDefinition<TPayload, TEnv>;
45
+ export declare function defineFlow<TEnv extends Record<string, string> = Record<string, string>>(flow: CronFlowDefinition<TEnv>): CronFlowDefinition<TEnv>;
46
+ export {};
package/dist/github.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { FlowEvent } from '@trigora/contracts';
1
+ import type { WebhookFlowEvent } from '@trigora/contracts';
2
2
  export type VerifyGitHubWebhookOptions = {
3
3
  secret: string | undefined;
4
4
  };
5
5
  export declare class GitHubWebhookVerificationError extends Error {
6
6
  name: string;
7
7
  }
8
- export declare function verifyGitHubWebhook<T = unknown>(event: FlowEvent, options: VerifyGitHubWebhookOptions): Promise<T>;
8
+ export declare function verifyGitHubWebhook<T = unknown>(event: WebhookFlowEvent, options: VerifyGitHubWebhookOptions): Promise<T>;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { defineFlow } from './defineFlow';
2
- export type { FlowContext, FlowDefinition, FlowEvent, FlowRunFn, JsonValue, Trigger, WebhookFlowResult, } from '@trigora/contracts';
2
+ export type { CronEventPayload, CronFlowEvent, FlowContext, FlowDefinition, FlowEvent, FlowRunFn, JsonValue, ManualFlowEvent, Trigger, WebhookFlowEvent, WebhookFlowResult, } from '@trigora/contracts';
package/dist/stripe.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FlowEvent } from '@trigora/contracts';
1
+ import type { WebhookFlowEvent } from '@trigora/contracts';
2
2
  export type VerifyStripeWebhookOptions = {
3
3
  secret: string | undefined;
4
4
  toleranceSeconds?: number;
@@ -6,4 +6,4 @@ export type VerifyStripeWebhookOptions = {
6
6
  export declare class StripeWebhookVerificationError extends Error {
7
7
  name: string;
8
8
  }
9
- export declare function verifyStripeWebhook<T = unknown>(event: FlowEvent, options: VerifyStripeWebhookOptions): Promise<T>;
9
+ export declare function verifyStripeWebhook<T = unknown>(event: WebhookFlowEvent, options: VerifyStripeWebhookOptions): Promise<T>;
@@ -1,4 +1,4 @@
1
- import type { FlowEvent } from '@trigora/contracts';
1
+ import type { WebhookFlowEvent } from '@trigora/contracts';
2
2
  export declare function encodeUtf8(value: string): Uint8Array;
3
3
  export declare function toArrayBuffer(bytes: Uint8Array): ArrayBuffer;
4
4
  export declare function bytesToHex(bytes: Uint8Array): string;
@@ -6,7 +6,7 @@ export declare function getHeaderCaseInsensitive(headers: Record<string, string>
6
6
  export declare function isHexString(value: string): boolean;
7
7
  export declare function timingSafeEqualStrings(left: string, right: string): boolean;
8
8
  export declare function computeHmacSha256Hex(secret: string, signedPayload: string): Promise<string>;
9
- export declare function requireWebhookRequestParts(event: FlowEvent, providerName: string): {
9
+ export declare function requireWebhookRequestParts(event: WebhookFlowEvent, providerName: string): {
10
10
  headers: Record<string, string>;
11
11
  rawBody: string;
12
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigora/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/trigora-dev/trigora"
@@ -45,7 +45,7 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@trigora/contracts": "0.4.1"
48
+ "@trigora/contracts": "0.6.5"
49
49
  },
50
50
  "devDependencies": {
51
51
  "tsup": "^8.5.1"