@trigora/sdk 0.2.0 → 0.3.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 +19 -12
- package/dist/defineFlow.d.ts +5 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,9 +25,7 @@ export default defineFlow({
|
|
|
25
25
|
id: 'hello',
|
|
26
26
|
trigger: { type: 'manual' },
|
|
27
27
|
async run(event, ctx) {
|
|
28
|
-
await ctx.log.info('Hello from Trigora',
|
|
29
|
-
payload: event.payload,
|
|
30
|
-
});
|
|
28
|
+
await ctx.log.info('Hello from Trigora', event.payload);
|
|
31
29
|
},
|
|
32
30
|
});
|
|
33
31
|
```
|
|
@@ -75,9 +73,7 @@ export default defineFlow({
|
|
|
75
73
|
id: 'hello',
|
|
76
74
|
trigger: { type: 'manual' },
|
|
77
75
|
async run(event, ctx) {
|
|
78
|
-
await ctx.log.info('Triggered manually',
|
|
79
|
-
payload: event.payload,
|
|
80
|
-
});
|
|
76
|
+
await ctx.log.info('Triggered manually', event.payload);
|
|
81
77
|
},
|
|
82
78
|
});
|
|
83
79
|
```
|
|
@@ -115,9 +111,7 @@ export default defineFlow({
|
|
|
115
111
|
id: 'nightly-sync',
|
|
116
112
|
trigger: { type: 'cron', cron: '0 2 * * *' },
|
|
117
113
|
async run(event, ctx) {
|
|
118
|
-
await ctx.log.info('Nightly sync started',
|
|
119
|
-
payload: event.payload,
|
|
120
|
-
});
|
|
114
|
+
await ctx.log.info('Nightly sync started', event.payload);
|
|
121
115
|
},
|
|
122
116
|
});
|
|
123
117
|
```
|
|
@@ -170,15 +164,25 @@ This matches how Trigora uses them:
|
|
|
170
164
|
Flows receive an event object:
|
|
171
165
|
|
|
172
166
|
```ts
|
|
173
|
-
type FlowEvent<TPayload =
|
|
167
|
+
type FlowEvent<TPayload = JsonValue> = {
|
|
174
168
|
id: string;
|
|
175
169
|
type: string;
|
|
176
170
|
timestamp: string;
|
|
177
171
|
payload: TPayload;
|
|
172
|
+
request?: {
|
|
173
|
+
headers: Record<string, string>;
|
|
174
|
+
method: string;
|
|
175
|
+
url: string;
|
|
176
|
+
rawBody: string;
|
|
177
|
+
};
|
|
178
178
|
};
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
In local
|
|
181
|
+
In local manual runs, the payload comes from your JSON payload file when one is provided. In local webhook dev and deployed webhook flows, the payload is the parsed JSON request body.
|
|
182
|
+
|
|
183
|
+
If you do not provide your own payload type, `event.payload` defaults to `JsonValue`.
|
|
184
|
+
|
|
185
|
+
For webhook flows, request metadata may also be available on `event.request`, including headers, method, URL, and the raw request body. `event.request.rawBody` is useful when you want to verify webhook signatures yourself.
|
|
182
186
|
|
|
183
187
|
## Context
|
|
184
188
|
|
|
@@ -211,7 +215,10 @@ That means most flow authors can stay entirely within `@trigora/sdk`.
|
|
|
211
215
|
## Typical Workflow
|
|
212
216
|
|
|
213
217
|
1. Define a flow with `defineFlow`
|
|
214
|
-
2. Run it locally with
|
|
218
|
+
2. Run it locally with:
|
|
219
|
+
- `trigora trigger hello --payload payload.json` for one-off runs
|
|
220
|
+
- `trigora dev hello --payload payload.json` for manual or payload watch mode
|
|
221
|
+
- `trigora dev stripe-checkout` for a local webhook server
|
|
215
222
|
3. Deploy webhook flows with `trigora deploy`
|
|
216
223
|
4. Manage hosted flows with `trigora flows`
|
|
217
224
|
|
package/dist/defineFlow.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CronFlowDefinition, JsonValue, ManualFlowDefinition, WebhookFlowDefinition } from '@trigora/contracts';
|
|
2
2
|
/**
|
|
3
3
|
* Define a Trigora flow.
|
|
4
4
|
*
|
|
@@ -23,10 +23,12 @@ import type { FlowDefinition, Trigger } from '@trigora/contracts';
|
|
|
23
23
|
* id: 'hello',
|
|
24
24
|
* trigger: { type: 'webhook' },
|
|
25
25
|
* async run(event, ctx) {
|
|
26
|
-
* await ctx.log.info('Received event',
|
|
26
|
+
* await ctx.log.info('Received event', event.payload);
|
|
27
27
|
* return { ok: true };
|
|
28
28
|
* },
|
|
29
29
|
* });
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
export declare function defineFlow<TPayload =
|
|
32
|
+
export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: ManualFlowDefinition<TPayload, TEnv>): ManualFlowDefinition<TPayload, TEnv>;
|
|
33
|
+
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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trigora/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/trigora-dev/trigora"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@trigora/contracts": "0.
|
|
40
|
+
"@trigora/contracts": "0.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"tsup": "^8.5.1"
|