@cloudwerk/trigger 0.0.1
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/LICENSE +21 -0
- package/dist/index.d.ts +966 -0
- package/dist/index.js +1130 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +193 -0
- package/dist/testing.js +181 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-w3ZeMXZ9.d.ts +510 -0
- package/package.json +40 -0
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @cloudwerk/trigger - Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Core types for event-driven triggers in Cloudwerk.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Type that can be either a value or a Promise of that value.
|
|
8
|
+
* Used throughout the trigger package for async-friendly APIs.
|
|
9
|
+
*/
|
|
10
|
+
type Awaitable<T> = T | Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Batch configuration for queue and R2 triggers.
|
|
13
|
+
*/
|
|
14
|
+
interface BatchConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Maximum number of events to deliver in a batch.
|
|
17
|
+
* @default 10
|
|
18
|
+
*/
|
|
19
|
+
size?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Maximum time to wait for a batch to fill.
|
|
22
|
+
* Supports duration strings like '5s', '30s'.
|
|
23
|
+
* @default '5s'
|
|
24
|
+
*/
|
|
25
|
+
timeout?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Retry configuration for triggers.
|
|
29
|
+
*/
|
|
30
|
+
interface RetryConfig {
|
|
31
|
+
/**
|
|
32
|
+
* Maximum number of retry attempts.
|
|
33
|
+
* @default 3
|
|
34
|
+
*/
|
|
35
|
+
maxAttempts?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Delay between retries. Supports duration strings like '30s', '1m'.
|
|
38
|
+
* @default '1m'
|
|
39
|
+
*/
|
|
40
|
+
delay?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Backoff strategy for retries.
|
|
43
|
+
* - 'linear': Fixed delay between retries
|
|
44
|
+
* - 'exponential': Delay doubles with each retry
|
|
45
|
+
* @default 'linear'
|
|
46
|
+
*/
|
|
47
|
+
backoff?: 'linear' | 'exponential';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Result of webhook signature verification.
|
|
51
|
+
*/
|
|
52
|
+
interface WebhookVerificationResult {
|
|
53
|
+
/** Whether the signature is valid */
|
|
54
|
+
valid: boolean;
|
|
55
|
+
/** Error message if verification failed */
|
|
56
|
+
error?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Webhook signature verifier function.
|
|
60
|
+
*
|
|
61
|
+
* @param request - The incoming request
|
|
62
|
+
* @param rawBody - The raw request body as ArrayBuffer
|
|
63
|
+
* @returns Verification result
|
|
64
|
+
*/
|
|
65
|
+
type WebhookVerifier = (request: Request, rawBody: ArrayBuffer) => Awaitable<WebhookVerificationResult>;
|
|
66
|
+
/**
|
|
67
|
+
* R2 event types that can trigger a handler.
|
|
68
|
+
*/
|
|
69
|
+
type R2EventType = 'object-create' | 'object-delete';
|
|
70
|
+
/**
|
|
71
|
+
* D1 event types that can trigger a handler.
|
|
72
|
+
*/
|
|
73
|
+
type D1EventType = 'insert' | 'update' | 'delete';
|
|
74
|
+
/**
|
|
75
|
+
* Queue trigger source configuration.
|
|
76
|
+
*/
|
|
77
|
+
interface QueueTriggerSource {
|
|
78
|
+
type: 'queue';
|
|
79
|
+
/** Name of the queue to consume from */
|
|
80
|
+
queue: string;
|
|
81
|
+
/** Batch configuration */
|
|
82
|
+
batch?: BatchConfig;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Scheduled (cron) trigger source configuration.
|
|
86
|
+
*/
|
|
87
|
+
interface ScheduledTriggerSource {
|
|
88
|
+
type: 'scheduled';
|
|
89
|
+
/** Cron expression (e.g., '0 0 * * *' for daily at midnight) */
|
|
90
|
+
cron: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* R2 bucket trigger source configuration.
|
|
94
|
+
*/
|
|
95
|
+
interface R2TriggerSource {
|
|
96
|
+
type: 'r2';
|
|
97
|
+
/** Name of the R2 bucket */
|
|
98
|
+
bucket: string;
|
|
99
|
+
/** Event types to trigger on */
|
|
100
|
+
events: R2EventType[];
|
|
101
|
+
/** Optional prefix filter */
|
|
102
|
+
prefix?: string;
|
|
103
|
+
/** Optional suffix filter */
|
|
104
|
+
suffix?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Webhook trigger source configuration.
|
|
108
|
+
*/
|
|
109
|
+
interface WebhookTriggerSource {
|
|
110
|
+
type: 'webhook';
|
|
111
|
+
/** URL path for the webhook (e.g., '/webhooks/stripe') */
|
|
112
|
+
path: string;
|
|
113
|
+
/** Optional signature verifier */
|
|
114
|
+
verify?: WebhookVerifier;
|
|
115
|
+
/** HTTP methods to accept (default: ['POST']) */
|
|
116
|
+
methods?: ('POST' | 'PUT' | 'PATCH')[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Email trigger source configuration.
|
|
120
|
+
*/
|
|
121
|
+
interface EmailTriggerSource {
|
|
122
|
+
type: 'email';
|
|
123
|
+
/** Email address pattern to match */
|
|
124
|
+
address: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* D1 database trigger source configuration.
|
|
128
|
+
*/
|
|
129
|
+
interface D1TriggerSource {
|
|
130
|
+
type: 'd1';
|
|
131
|
+
/** Name of the D1 database binding */
|
|
132
|
+
database: string;
|
|
133
|
+
/** Table to watch */
|
|
134
|
+
table: string;
|
|
135
|
+
/** Event types to trigger on */
|
|
136
|
+
events: D1EventType[];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Tail trigger source configuration (for consuming logs from other workers).
|
|
140
|
+
*/
|
|
141
|
+
interface TailTriggerSource {
|
|
142
|
+
type: 'tail';
|
|
143
|
+
/** Worker names to consume logs from */
|
|
144
|
+
consumers: string[];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Union of all trigger source types.
|
|
148
|
+
*/
|
|
149
|
+
type TriggerSource = QueueTriggerSource | ScheduledTriggerSource | R2TriggerSource | WebhookTriggerSource | EmailTriggerSource | D1TriggerSource | TailTriggerSource;
|
|
150
|
+
/**
|
|
151
|
+
* Scheduled event passed to cron trigger handlers.
|
|
152
|
+
*/
|
|
153
|
+
interface ScheduledEvent {
|
|
154
|
+
/** The cron expression that triggered this event */
|
|
155
|
+
cron: string;
|
|
156
|
+
/** Unix timestamp (milliseconds) when the event was scheduled */
|
|
157
|
+
scheduledTime: number;
|
|
158
|
+
/**
|
|
159
|
+
* Prevent automatic retry on failure.
|
|
160
|
+
* Call this if the error is not recoverable.
|
|
161
|
+
*/
|
|
162
|
+
noRetry(): void;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Single message in a queue batch.
|
|
166
|
+
*/
|
|
167
|
+
interface QueueMessage<T = unknown> {
|
|
168
|
+
/** Unique message ID */
|
|
169
|
+
readonly id: string;
|
|
170
|
+
/** Message payload */
|
|
171
|
+
readonly body: T;
|
|
172
|
+
/** When the message was sent */
|
|
173
|
+
readonly timestamp: Date;
|
|
174
|
+
/** Number of delivery attempts */
|
|
175
|
+
readonly attempts: number;
|
|
176
|
+
/** Acknowledge successful processing */
|
|
177
|
+
ack(): void;
|
|
178
|
+
/** Request retry with optional delay */
|
|
179
|
+
retry(options?: {
|
|
180
|
+
delaySeconds?: number;
|
|
181
|
+
}): void;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Queue batch event passed to queue trigger handlers.
|
|
185
|
+
*/
|
|
186
|
+
interface QueueBatchEvent<T = unknown> {
|
|
187
|
+
/** Array of messages in the batch */
|
|
188
|
+
messages: QueueMessage<T>[];
|
|
189
|
+
/** Name of the queue */
|
|
190
|
+
queue: string;
|
|
191
|
+
/** Acknowledge all messages in the batch */
|
|
192
|
+
ackAll(): void;
|
|
193
|
+
/** Retry all messages in the batch */
|
|
194
|
+
retryAll(): void;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* R2 object event passed to R2 trigger handlers.
|
|
198
|
+
*/
|
|
199
|
+
interface R2Event {
|
|
200
|
+
/** Type of event */
|
|
201
|
+
type: 'object-create' | 'object-delete';
|
|
202
|
+
/** Name of the R2 bucket */
|
|
203
|
+
bucket: string;
|
|
204
|
+
/** Object key (path) */
|
|
205
|
+
key: string;
|
|
206
|
+
/** ETag of the object (for create events) */
|
|
207
|
+
etag?: string;
|
|
208
|
+
/** Size in bytes (for create events) */
|
|
209
|
+
size?: number;
|
|
210
|
+
/** Upload timestamp (for create events) */
|
|
211
|
+
uploadedAt?: Date;
|
|
212
|
+
/** Account ID */
|
|
213
|
+
account: string;
|
|
214
|
+
/** Event ID for deduplication */
|
|
215
|
+
eventId: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Webhook event passed to webhook trigger handlers.
|
|
219
|
+
*/
|
|
220
|
+
interface WebhookEvent<T = unknown> {
|
|
221
|
+
/** Parsed payload (JSON) */
|
|
222
|
+
payload: T;
|
|
223
|
+
/** Request headers */
|
|
224
|
+
headers: Headers;
|
|
225
|
+
/** Signature header value (if present) */
|
|
226
|
+
signature: string | null;
|
|
227
|
+
/** Raw request body for manual verification */
|
|
228
|
+
rawBody: ArrayBuffer;
|
|
229
|
+
/** Whether signature verification passed */
|
|
230
|
+
verified: boolean;
|
|
231
|
+
/** HTTP method used */
|
|
232
|
+
method: string;
|
|
233
|
+
/** URL path */
|
|
234
|
+
path: string;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Email event passed to email trigger handlers.
|
|
238
|
+
*/
|
|
239
|
+
interface EmailEvent {
|
|
240
|
+
/** Sender email address */
|
|
241
|
+
from: string;
|
|
242
|
+
/** Recipient email address */
|
|
243
|
+
to: string;
|
|
244
|
+
/** Email subject */
|
|
245
|
+
subject: string;
|
|
246
|
+
/** Raw email as a stream */
|
|
247
|
+
rawEmail: ReadableStream;
|
|
248
|
+
/** Parse the email body as text */
|
|
249
|
+
text(): Promise<string>;
|
|
250
|
+
/** Parse the email body as HTML */
|
|
251
|
+
html(): Promise<string | null>;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* D1 change event passed to D1 trigger handlers.
|
|
255
|
+
*/
|
|
256
|
+
interface D1Event {
|
|
257
|
+
/** Type of database operation */
|
|
258
|
+
type: 'insert' | 'update' | 'delete';
|
|
259
|
+
/** Database name */
|
|
260
|
+
database: string;
|
|
261
|
+
/** Table name */
|
|
262
|
+
table: string;
|
|
263
|
+
/** Primary key values of the affected row */
|
|
264
|
+
primaryKey: Record<string, unknown>;
|
|
265
|
+
/** New values (for insert/update) */
|
|
266
|
+
newValues?: Record<string, unknown>;
|
|
267
|
+
/** Old values (for update/delete) */
|
|
268
|
+
oldValues?: Record<string, unknown>;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Tail event passed to tail trigger handlers.
|
|
272
|
+
*/
|
|
273
|
+
interface TailEvent {
|
|
274
|
+
/** Array of log entries */
|
|
275
|
+
logs: TailLogEntry[];
|
|
276
|
+
/** Worker that produced the logs */
|
|
277
|
+
worker: string;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Single log entry in a tail event.
|
|
281
|
+
*/
|
|
282
|
+
interface TailLogEntry {
|
|
283
|
+
/** Log level */
|
|
284
|
+
level: 'log' | 'debug' | 'info' | 'warn' | 'error';
|
|
285
|
+
/** Log message */
|
|
286
|
+
message: string;
|
|
287
|
+
/** Timestamp */
|
|
288
|
+
timestamp: Date;
|
|
289
|
+
/** Additional data */
|
|
290
|
+
data?: unknown;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Infer the event type from a trigger source.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* type Event = InferEventType<{ type: 'scheduled'; cron: '0 0 * * *' }>
|
|
298
|
+
* // Event = ScheduledEvent
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
type InferEventType<TSource extends TriggerSource> = TSource extends ScheduledTriggerSource ? ScheduledEvent : TSource extends QueueTriggerSource ? QueueBatchEvent : TSource extends R2TriggerSource ? R2Event : TSource extends WebhookTriggerSource ? WebhookEvent : TSource extends EmailTriggerSource ? EmailEvent : TSource extends D1TriggerSource ? D1Event : TSource extends TailTriggerSource ? TailEvent : never;
|
|
302
|
+
/**
|
|
303
|
+
* Context passed to trigger handlers.
|
|
304
|
+
*/
|
|
305
|
+
interface TriggerContext {
|
|
306
|
+
/**
|
|
307
|
+
* Unique trace ID for this trigger execution.
|
|
308
|
+
* Propagated through trigger chains for observability.
|
|
309
|
+
*/
|
|
310
|
+
traceId: string;
|
|
311
|
+
/**
|
|
312
|
+
* Extend the lifetime of the trigger execution.
|
|
313
|
+
* Use for background tasks that should complete after the handler returns.
|
|
314
|
+
*/
|
|
315
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
316
|
+
/**
|
|
317
|
+
* Allow the request to pass through on exception.
|
|
318
|
+
* Only applicable for certain trigger types.
|
|
319
|
+
*/
|
|
320
|
+
passThroughOnException(): void;
|
|
321
|
+
/**
|
|
322
|
+
* Access to Cloudflare bindings (D1, KV, R2, etc.).
|
|
323
|
+
*/
|
|
324
|
+
env: Record<string, unknown>;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Trigger handler function signature.
|
|
328
|
+
*/
|
|
329
|
+
type TriggerHandler<TEvent> = (event: TEvent, ctx: TriggerContext) => Awaitable<void>;
|
|
330
|
+
/**
|
|
331
|
+
* Error handler function signature.
|
|
332
|
+
*/
|
|
333
|
+
type TriggerErrorHandler<TEvent> = (error: Error, event: TEvent, ctx: TriggerContext) => Awaitable<void>;
|
|
334
|
+
/**
|
|
335
|
+
* Configuration for defining a trigger.
|
|
336
|
+
*
|
|
337
|
+
* @typeParam TSource - The trigger source type
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```typescript
|
|
341
|
+
* // Scheduled trigger
|
|
342
|
+
* defineTrigger({
|
|
343
|
+
* source: { type: 'scheduled', cron: '0 0 * * *' },
|
|
344
|
+
* async handle(event, ctx) {
|
|
345
|
+
* console.log(`Running at ${event.scheduledTime}`)
|
|
346
|
+
* }
|
|
347
|
+
* })
|
|
348
|
+
*
|
|
349
|
+
* // R2 trigger
|
|
350
|
+
* defineTrigger({
|
|
351
|
+
* source: { type: 'r2', bucket: 'uploads', events: ['object-create'] },
|
|
352
|
+
* async handle(event, ctx) {
|
|
353
|
+
* console.log(`New file: ${event.key}`)
|
|
354
|
+
* }
|
|
355
|
+
* })
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
interface TriggerConfig<TSource extends TriggerSource> {
|
|
359
|
+
/**
|
|
360
|
+
* Optional trigger name override.
|
|
361
|
+
* By default, derived from the filename.
|
|
362
|
+
*/
|
|
363
|
+
name?: string;
|
|
364
|
+
/**
|
|
365
|
+
* The event source configuration.
|
|
366
|
+
*/
|
|
367
|
+
source: TSource;
|
|
368
|
+
/**
|
|
369
|
+
* Retry configuration for failed executions.
|
|
370
|
+
*/
|
|
371
|
+
retry?: RetryConfig;
|
|
372
|
+
/**
|
|
373
|
+
* Execution timeout in milliseconds.
|
|
374
|
+
* @default 30000 (30 seconds)
|
|
375
|
+
*/
|
|
376
|
+
timeout?: number;
|
|
377
|
+
/**
|
|
378
|
+
* The trigger handler function.
|
|
379
|
+
*/
|
|
380
|
+
handle: TriggerHandler<InferEventType<TSource>>;
|
|
381
|
+
/**
|
|
382
|
+
* Optional error handler for logging/reporting failures.
|
|
383
|
+
*/
|
|
384
|
+
onError?: TriggerErrorHandler<InferEventType<TSource>>;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* A defined trigger, returned by defineTrigger().
|
|
388
|
+
*
|
|
389
|
+
* @typeParam TSource - The trigger source type
|
|
390
|
+
*/
|
|
391
|
+
interface TriggerDefinition<TSource extends TriggerSource = TriggerSource> {
|
|
392
|
+
/** Internal marker identifying this as a trigger definition */
|
|
393
|
+
readonly __brand: 'cloudwerk-trigger';
|
|
394
|
+
/** Trigger name (derived from filename or explicitly set) */
|
|
395
|
+
readonly name: string | undefined;
|
|
396
|
+
/** The event source configuration */
|
|
397
|
+
readonly source: TSource;
|
|
398
|
+
/** Retry configuration */
|
|
399
|
+
readonly retry: RetryConfig;
|
|
400
|
+
/** Execution timeout in milliseconds */
|
|
401
|
+
readonly timeout: number;
|
|
402
|
+
/** The trigger handler function */
|
|
403
|
+
readonly handle: TriggerHandler<InferEventType<TSource>>;
|
|
404
|
+
/** Optional error handler */
|
|
405
|
+
readonly onError: TriggerErrorHandler<InferEventType<TSource>> | undefined;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* A scanned trigger file from the app/triggers/ directory.
|
|
409
|
+
*/
|
|
410
|
+
interface ScannedTrigger {
|
|
411
|
+
/** Relative path from app/triggers/ (e.g., 'daily-cleanup.ts') */
|
|
412
|
+
relativePath: string;
|
|
413
|
+
/** Absolute filesystem path */
|
|
414
|
+
absolutePath: string;
|
|
415
|
+
/** File name without extension (e.g., 'daily-cleanup') */
|
|
416
|
+
name: string;
|
|
417
|
+
/** File extension (e.g., '.ts') */
|
|
418
|
+
extension: string;
|
|
419
|
+
/** If this is in a fan-out subdirectory, the group name */
|
|
420
|
+
fanOutGroup?: string;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Result of scanning the app/triggers/ directory.
|
|
424
|
+
*/
|
|
425
|
+
interface TriggerScanResult {
|
|
426
|
+
/** All discovered trigger files */
|
|
427
|
+
triggers: ScannedTrigger[];
|
|
428
|
+
/** Fan-out groups detected (directory name -> trigger names) */
|
|
429
|
+
fanOutGroups: Map<string, string[]>;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* A compiled trigger entry in the manifest.
|
|
433
|
+
*/
|
|
434
|
+
interface TriggerEntry {
|
|
435
|
+
/** Trigger name derived from filename (e.g., 'dailyCleanup') */
|
|
436
|
+
name: string;
|
|
437
|
+
/** Binding name for wrangler.toml (e.g., 'DAILY_CLEANUP_TRIGGER') */
|
|
438
|
+
bindingName: string;
|
|
439
|
+
/** Relative path to the trigger definition file */
|
|
440
|
+
filePath: string;
|
|
441
|
+
/** Absolute path to the trigger definition file */
|
|
442
|
+
absolutePath: string;
|
|
443
|
+
/** Trigger source configuration */
|
|
444
|
+
source: TriggerSource;
|
|
445
|
+
/** Whether onError handler is defined */
|
|
446
|
+
hasOnError: boolean;
|
|
447
|
+
/** Retry configuration */
|
|
448
|
+
retry?: RetryConfig;
|
|
449
|
+
/** Execution timeout */
|
|
450
|
+
timeout?: number;
|
|
451
|
+
/** Fan-out group name (if part of a fan-out) */
|
|
452
|
+
fanOutGroup?: string;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Error codes for trigger validation.
|
|
456
|
+
*/
|
|
457
|
+
type TriggerErrorCode = 'NO_HANDLER' | 'INVALID_SOURCE' | 'DUPLICATE_NAME' | 'INVALID_CRON' | 'INVALID_WEBHOOK_PATH' | 'INVALID_CONFIG' | 'INVALID_NAME' | 'MISSING_SOURCE';
|
|
458
|
+
/**
|
|
459
|
+
* Warning codes for trigger validation.
|
|
460
|
+
*/
|
|
461
|
+
type TriggerWarningCode = 'NO_ERROR_HANDLER' | 'DUPLICATE_CRON' | 'SHORT_TIMEOUT' | 'MISSING_RETRY' | 'WEBHOOK_NO_VERIFY';
|
|
462
|
+
/**
|
|
463
|
+
* Validation error for a trigger definition.
|
|
464
|
+
*/
|
|
465
|
+
interface TriggerValidationError {
|
|
466
|
+
/** Trigger file path */
|
|
467
|
+
file: string;
|
|
468
|
+
/** Error message */
|
|
469
|
+
message: string;
|
|
470
|
+
/** Error code for programmatic handling */
|
|
471
|
+
code: TriggerErrorCode;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Validation warning for a trigger definition.
|
|
475
|
+
*/
|
|
476
|
+
interface TriggerValidationWarning {
|
|
477
|
+
/** Trigger file path */
|
|
478
|
+
file: string;
|
|
479
|
+
/** Warning message */
|
|
480
|
+
message: string;
|
|
481
|
+
/** Warning code */
|
|
482
|
+
code: TriggerWarningCode;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Complete trigger manifest generated during build.
|
|
486
|
+
*/
|
|
487
|
+
interface TriggerManifest {
|
|
488
|
+
/** All compiled trigger entries */
|
|
489
|
+
triggers: TriggerEntry[];
|
|
490
|
+
/** Scheduled triggers grouped by cron expression */
|
|
491
|
+
scheduled: Map<string, TriggerEntry[]>;
|
|
492
|
+
/** Queue triggers grouped by queue name */
|
|
493
|
+
queues: Map<string, TriggerEntry[]>;
|
|
494
|
+
/** R2 triggers grouped by bucket name */
|
|
495
|
+
r2: Map<string, TriggerEntry[]>;
|
|
496
|
+
/** Webhook triggers mapped by path */
|
|
497
|
+
webhooks: Map<string, TriggerEntry>;
|
|
498
|
+
/** Email triggers mapped by address pattern */
|
|
499
|
+
emails: Map<string, TriggerEntry>;
|
|
500
|
+
/** Validation errors (trigger won't be registered) */
|
|
501
|
+
errors: TriggerValidationError[];
|
|
502
|
+
/** Validation warnings (trigger will be registered with warning) */
|
|
503
|
+
warnings: TriggerValidationWarning[];
|
|
504
|
+
/** When the manifest was generated */
|
|
505
|
+
generatedAt: Date;
|
|
506
|
+
/** Root directory of the app */
|
|
507
|
+
rootDir: string;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export type { Awaitable as A, BatchConfig as B, WebhookTriggerSource as C, D1Event as D, EmailEvent as E, WebhookVerificationResult as F, InferEventType as I, QueueBatchEvent as Q, R2Event as R, ScannedTrigger as S, TriggerSource as T, WebhookVerifier as W, TriggerConfig as a, TriggerDefinition as b, TriggerContext as c, D1EventType as d, D1TriggerSource as e, EmailTriggerSource as f, QueueMessage as g, QueueTriggerSource as h, R2EventType as i, R2TriggerSource as j, RetryConfig as k, ScheduledEvent as l, ScheduledTriggerSource as m, TailEvent as n, TailLogEntry as o, TailTriggerSource as p, TriggerEntry as q, TriggerErrorCode as r, TriggerErrorHandler as s, TriggerHandler as t, TriggerManifest as u, TriggerScanResult as v, TriggerValidationError as w, TriggerValidationWarning as x, TriggerWarningCode as y, WebhookEvent as z };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloudwerk/trigger",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Event-driven triggers for Cloudwerk (scheduled, queue, R2, webhooks)",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/squirrelsoft-dev/cloudwerk.git",
|
|
8
|
+
"directory": "packages/trigger"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./testing": {
|
|
17
|
+
"types": "./dist/testing.d.ts",
|
|
18
|
+
"import": "./dist/testing.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@cloudwerk/core": "0.12.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.4.0",
|
|
29
|
+
"vitest": "^1.0.0",
|
|
30
|
+
"tsup": "^8.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"typescript": "^5.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"test": "vitest --run",
|
|
38
|
+
"test:watch": "vitest"
|
|
39
|
+
}
|
|
40
|
+
}
|