@trigora/sdk 0.1.3 → 0.2.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
@@ -1,8 +1,8 @@
1
1
  # @trigora/sdk
2
2
 
3
- Define flows for Trigora.
3
+ Flow authoring for Trigora.
4
4
 
5
- ---
5
+ `@trigora/sdk` is the package most Trigora users write against directly. It provides `defineFlow` plus the shared runtime types needed to author flows with good TypeScript ergonomics.
6
6
 
7
7
  ## Install
8
8
 
@@ -10,7 +10,11 @@ Define flows for Trigora.
10
10
  npm install @trigora/sdk
11
11
  ```
12
12
 
13
- ---
13
+ Most projects will install the CLI alongside it:
14
+
15
+ ```bash
16
+ npm install trigora @trigora/sdk
17
+ ```
14
18
 
15
19
  ## Basic Usage
16
20
 
@@ -21,51 +25,201 @@ export default defineFlow({
21
25
  id: 'hello',
22
26
  trigger: { type: 'manual' },
23
27
  async run(event, ctx) {
24
- await ctx.log.info('Hello');
28
+ await ctx.log.info('Hello from Trigora', {
29
+ payload: event.payload,
30
+ });
31
+ },
32
+ });
33
+ ```
34
+
35
+ ## What `defineFlow` Gives You
36
+
37
+ `defineFlow` helps with:
38
+
39
+ - typed flow definitions
40
+ - typed trigger variants
41
+ - typed event payload access
42
+ - typed runtime context
43
+ - trigger-aware return types
44
+ - compile-time validation of trigger shape
45
+
46
+ The trigger typing is strict. If you mix properties from different trigger kinds, TypeScript will flag it.
47
+
48
+ For example, this is invalid:
49
+
50
+ ```ts
51
+ import { defineFlow } from '@trigora/sdk';
52
+
53
+ export default defineFlow({
54
+ id: 'broken',
55
+ trigger: {
56
+ type: 'webhook',
57
+ cron: '* * * * *',
58
+ },
59
+ async run() {
60
+ return 'nope';
25
61
  },
26
62
  });
27
63
  ```
28
64
 
29
- ---
65
+ ## Trigger Types
66
+
67
+ ### Manual
30
68
 
31
- ## Flow Structure
69
+ Use manual triggers for local invocation and testing.
32
70
 
33
71
  ```ts
34
- defineFlow({
35
- id: string,
72
+ import { defineFlow } from '@trigora/sdk';
73
+
74
+ export default defineFlow({
75
+ id: 'hello',
36
76
  trigger: { type: 'manual' },
37
- run: async (event, ctx) => {}
38
- })
77
+ async run(event, ctx) {
78
+ await ctx.log.info('Triggered manually', {
79
+ payload: event.payload,
80
+ });
81
+ },
82
+ });
83
+ ```
84
+
85
+ ### Webhook
86
+
87
+ Use webhook triggers for hosted HTTP entrypoints.
88
+
89
+ ```ts
90
+ import { defineFlow } from '@trigora/sdk';
91
+
92
+ export default defineFlow({
93
+ id: 'ping',
94
+ trigger: { type: 'webhook' },
95
+ async run() {
96
+ return 'pong';
97
+ },
98
+ });
99
+ ```
100
+
101
+ You can also include an optional event name:
102
+
103
+ ```ts
104
+ trigger: { type: 'webhook', event: 'orders.created' }
39
105
  ```
40
106
 
41
- ---
107
+ ### Cron
42
108
 
43
- ## Event
109
+ Use cron triggers for scheduled work.
44
110
 
45
111
  ```ts
46
- {
112
+ import { defineFlow } from '@trigora/sdk';
113
+
114
+ export default defineFlow({
115
+ id: 'nightly-sync',
116
+ trigger: { type: 'cron', cron: '0 2 * * *' },
117
+ async run(event, ctx) {
118
+ await ctx.log.info('Nightly sync started', {
119
+ payload: event.payload,
120
+ });
121
+ },
122
+ });
123
+ ```
124
+
125
+ ## Return Types
126
+
127
+ Return values are trigger-aware.
128
+
129
+ ### Webhook flows
130
+
131
+ Webhook flows can return HTTP-friendly values directly from `run`.
132
+
133
+ Supported return values:
134
+
135
+ - `Response`
136
+ - plain objects, arrays, numbers, and booleans
137
+ - `string`
138
+ - `null`
139
+ - `undefined`
140
+
141
+ Example:
142
+
143
+ ```ts
144
+ import { defineFlow } from '@trigora/sdk';
145
+
146
+ export default defineFlow({
147
+ id: 'status',
148
+ trigger: { type: 'webhook' },
149
+ async run() {
150
+ return {
151
+ ok: true,
152
+ service: 'trigora',
153
+ };
154
+ },
155
+ });
156
+ ```
157
+
158
+ ### Manual and cron flows
159
+
160
+ Manual and cron flows do not use return values. Their `run` functions are typed as `void`.
161
+
162
+ This matches how Trigora uses them:
163
+
164
+ - manual flows are invoked locally for testing and development
165
+ - cron flows are background-style scheduled jobs
166
+ - webhook flows are request-response flows
167
+
168
+ ## Event Shape
169
+
170
+ Flows receive an event object:
171
+
172
+ ```ts
173
+ type FlowEvent<TPayload = unknown> = {
47
174
  id: string;
48
175
  type: string;
49
176
  timestamp: string;
50
- payload: unknown;
51
- }
177
+ payload: TPayload;
178
+ };
52
179
  ```
53
180
 
54
- ---
181
+ In local CLI runs, the payload comes from your JSON payload file when one is provided.
55
182
 
56
183
  ## Context
57
184
 
185
+ Flows receive a context object with logging and environment access:
186
+
58
187
  ```ts
59
- ctx.log.info()
60
- ctx.log.warn()
61
- ctx.log.error()
188
+ ctx.log.info('message')
189
+ ctx.log.warn('message')
190
+ ctx.log.error('message')
62
191
 
63
192
  ctx.env
64
193
  ```
65
194
 
66
- ---
195
+ The exact exported type is `FlowContext<TEnv>`.
196
+
197
+ ## Exported Types
198
+
199
+ `@trigora/sdk` re-exports the main flow authoring types from `@trigora/contracts`:
200
+
201
+ - `FlowContext`
202
+ - `FlowDefinition`
203
+ - `FlowEvent`
204
+ - `FlowRunFn`
205
+ - `JsonValue`
206
+ - `Trigger`
207
+ - `WebhookFlowResult`
208
+
209
+ That means most flow authors can stay entirely within `@trigora/sdk`.
210
+
211
+ ## Typical Workflow
212
+
213
+ 1. Define a flow with `defineFlow`
214
+ 2. Run it locally with `trigora trigger` or `trigora dev`
215
+ 3. Deploy webhook flows with `trigora deploy`
216
+ 4. Manage hosted flows with `trigora flows`
217
+
218
+ ## Related Packages
219
+
220
+ - `trigora` - CLI for local development and hosted deploys
221
+ - `@trigora/contracts` - shared public types used by the SDK, CLI, and API consumers
67
222
 
68
- ## Notes
223
+ ## License
69
224
 
70
- - flows are plain TypeScript modules
71
- - no framework required
225
+ MIT
@@ -1,2 +1,32 @@
1
- import type { FlowDefinition } from '@trigora/contracts';
2
- export declare function defineFlow<TPayload = unknown, TEnv extends Record<string, string> = Record<string, string>>(flow: FlowDefinition<TPayload, TEnv>): FlowDefinition<TPayload, TEnv>;
1
+ import type { FlowDefinition, Trigger } from '@trigora/contracts';
2
+ /**
3
+ * Define a Trigora flow.
4
+ *
5
+ * Flows are plain TypeScript modules with three core parts:
6
+ * - `id`: the source identifier for the flow in your project
7
+ * - `trigger`: how the flow is invoked
8
+ * - `run`: the function that executes when the flow is triggered
9
+ *
10
+ * `run` receives the incoming `event` and a `ctx` object with logging and environment access.
11
+ *
12
+ * Webhook flows can return HTTP-friendly values:
13
+ * - `Response`
14
+ * - plain objects / arrays / numbers / booleans
15
+ * - `string`
16
+ * - `null` or `undefined`
17
+ *
18
+ * Other trigger types generally do not need to return anything meaningful.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * export default defineFlow({
23
+ * id: 'hello',
24
+ * trigger: { type: 'webhook' },
25
+ * async run(event, ctx) {
26
+ * await ctx.log.info('Received event', { payload: event.payload });
27
+ * return { ok: true };
28
+ * },
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function defineFlow<TPayload = unknown, TEnv extends Record<string, string> = Record<string, string>, TTrigger extends Trigger = Trigger>(flow: FlowDefinition<TPayload, TEnv, TTrigger>): FlowDefinition<TPayload, TEnv, TTrigger>;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { defineFlow } from './defineFlow';
2
- export type { FlowContext, FlowDefinition, FlowEvent, FlowRunFn, Trigger, } from '@trigora/contracts';
2
+ export type { FlowContext, FlowDefinition, FlowEvent, FlowRunFn, JsonValue, Trigger, WebhookFlowResult, } from '@trigora/contracts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigora/sdk",
3
- "version": "0.1.3",
3
+ "version": "0.2.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.1.0"
40
+ "@trigora/contracts": "0.2.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "tsup": "^8.5.1"