@trigger.dev/sdk 0.2.10 → 0.2.12-next.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/LICENSE +25 -201
- package/dist/index.d.ts +145 -0
- package/dist/index.js +338 -156
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -131,13 +131,47 @@ var CustomEventSchema = import_zod5.z.object({
|
|
|
131
131
|
name: import_zod5.z.string(),
|
|
132
132
|
payload: JsonSchema,
|
|
133
133
|
context: JsonSchema.optional(),
|
|
134
|
-
timestamp: import_zod5.z.string().datetime().optional()
|
|
134
|
+
timestamp: import_zod5.z.string().datetime().optional(),
|
|
135
|
+
delay: import_zod5.z.union([
|
|
136
|
+
import_zod5.z.object({
|
|
137
|
+
seconds: import_zod5.z.number().int()
|
|
138
|
+
}),
|
|
139
|
+
import_zod5.z.object({
|
|
140
|
+
minutes: import_zod5.z.number().int()
|
|
141
|
+
}),
|
|
142
|
+
import_zod5.z.object({
|
|
143
|
+
hours: import_zod5.z.number().int()
|
|
144
|
+
}),
|
|
145
|
+
import_zod5.z.object({
|
|
146
|
+
days: import_zod5.z.number().int()
|
|
147
|
+
}),
|
|
148
|
+
import_zod5.z.object({
|
|
149
|
+
until: import_zod5.z.string().datetime()
|
|
150
|
+
})
|
|
151
|
+
]).optional()
|
|
135
152
|
});
|
|
136
153
|
var SerializableCustomEventSchema = import_zod5.z.object({
|
|
137
154
|
name: import_zod5.z.string(),
|
|
138
155
|
payload: SerializableJsonSchema,
|
|
139
156
|
context: SerializableJsonSchema.optional(),
|
|
140
|
-
timestamp: import_zod5.z.string().datetime().optional()
|
|
157
|
+
timestamp: import_zod5.z.string().datetime().optional(),
|
|
158
|
+
delay: import_zod5.z.union([
|
|
159
|
+
import_zod5.z.object({
|
|
160
|
+
seconds: import_zod5.z.number().int()
|
|
161
|
+
}),
|
|
162
|
+
import_zod5.z.object({
|
|
163
|
+
minutes: import_zod5.z.number().int()
|
|
164
|
+
}),
|
|
165
|
+
import_zod5.z.object({
|
|
166
|
+
hours: import_zod5.z.number().int()
|
|
167
|
+
}),
|
|
168
|
+
import_zod5.z.object({
|
|
169
|
+
days: import_zod5.z.number().int()
|
|
170
|
+
}),
|
|
171
|
+
import_zod5.z.object({
|
|
172
|
+
until: import_zod5.z.date()
|
|
173
|
+
})
|
|
174
|
+
]).optional()
|
|
141
175
|
});
|
|
142
176
|
var EventMatcherSchema = import_zod5.z.union([
|
|
143
177
|
import_zod5.z.array(import_zod5.z.string()),
|
|
@@ -179,6 +213,19 @@ var ManualWebhookSourceSchema = import_zod5.z.object({
|
|
|
179
213
|
}),
|
|
180
214
|
event: import_zod5.z.string()
|
|
181
215
|
});
|
|
216
|
+
var SlackBlockInteractionSourceSchema = import_zod5.z.object({
|
|
217
|
+
type: import_zod5.z.literal("block_action"),
|
|
218
|
+
blockId: import_zod5.z.string(),
|
|
219
|
+
actionIds: import_zod5.z.array(import_zod5.z.string())
|
|
220
|
+
});
|
|
221
|
+
var SlackViewSubmissionInteractionSourceSchema = import_zod5.z.object({
|
|
222
|
+
type: import_zod5.z.literal("view_submission"),
|
|
223
|
+
callbackIds: import_zod5.z.array(import_zod5.z.string())
|
|
224
|
+
});
|
|
225
|
+
var SlackInteractionSourceSchema = import_zod5.z.discriminatedUnion("type", [
|
|
226
|
+
SlackBlockInteractionSourceSchema,
|
|
227
|
+
SlackViewSubmissionInteractionSourceSchema
|
|
228
|
+
]);
|
|
182
229
|
|
|
183
230
|
// ../common-schemas/src/triggers.ts
|
|
184
231
|
var import_zod6 = require("zod");
|
|
@@ -186,7 +233,8 @@ var CustomEventTriggerSchema = import_zod6.z.object({
|
|
|
186
233
|
type: import_zod6.z.literal("CUSTOM_EVENT"),
|
|
187
234
|
service: import_zod6.z.literal("trigger"),
|
|
188
235
|
name: import_zod6.z.string(),
|
|
189
|
-
filter: EventFilterSchema
|
|
236
|
+
filter: EventFilterSchema,
|
|
237
|
+
schema: JsonSchema.optional()
|
|
190
238
|
});
|
|
191
239
|
var WebhookEventTriggerSchema = import_zod6.z.object({
|
|
192
240
|
type: import_zod6.z.literal("WEBHOOK"),
|
|
@@ -194,7 +242,8 @@ var WebhookEventTriggerSchema = import_zod6.z.object({
|
|
|
194
242
|
name: import_zod6.z.string(),
|
|
195
243
|
filter: EventFilterSchema,
|
|
196
244
|
source: JsonSchema.optional(),
|
|
197
|
-
manualRegistration: import_zod6.z.boolean().default(false)
|
|
245
|
+
manualRegistration: import_zod6.z.boolean().default(false),
|
|
246
|
+
schema: JsonSchema.optional()
|
|
198
247
|
});
|
|
199
248
|
var HttpEventTriggerSchema = import_zod6.z.object({
|
|
200
249
|
type: import_zod6.z.literal("HTTP_ENDPOINT"),
|
|
@@ -208,11 +257,19 @@ var ScheduledEventTriggerSchema = import_zod6.z.object({
|
|
|
208
257
|
name: import_zod6.z.string(),
|
|
209
258
|
source: ScheduleSourceSchema
|
|
210
259
|
});
|
|
260
|
+
var SlackInteractionTriggerSchema = import_zod6.z.object({
|
|
261
|
+
type: import_zod6.z.literal("SLACK_INTERACTION"),
|
|
262
|
+
service: import_zod6.z.literal("slack"),
|
|
263
|
+
name: import_zod6.z.string(),
|
|
264
|
+
filter: EventFilterSchema,
|
|
265
|
+
source: SlackInteractionSourceSchema
|
|
266
|
+
});
|
|
211
267
|
var TriggerMetadataSchema = import_zod6.z.discriminatedUnion("type", [
|
|
212
268
|
CustomEventTriggerSchema,
|
|
213
269
|
WebhookEventTriggerSchema,
|
|
214
270
|
HttpEventTriggerSchema,
|
|
215
|
-
ScheduledEventTriggerSchema
|
|
271
|
+
ScheduledEventTriggerSchema,
|
|
272
|
+
SlackInteractionTriggerSchema
|
|
216
273
|
]);
|
|
217
274
|
|
|
218
275
|
// ../common-schemas/src/fetch.ts
|
|
@@ -268,8 +325,31 @@ var FetchResponseSchema = import_zod7.z.object({
|
|
|
268
325
|
body: import_zod7.z.any().optional()
|
|
269
326
|
});
|
|
270
327
|
|
|
328
|
+
// ../common-schemas/src/runOnce.ts
|
|
329
|
+
var import_zod8 = require("zod");
|
|
330
|
+
var InitializeRunOnceSchema = import_zod8.z.object({
|
|
331
|
+
type: import_zod8.z.enum([
|
|
332
|
+
"REMOTE",
|
|
333
|
+
"LOCAL_ONLY"
|
|
334
|
+
])
|
|
335
|
+
});
|
|
336
|
+
var CompleteRunOnceSchema = import_zod8.z.object({
|
|
337
|
+
type: import_zod8.z.enum([
|
|
338
|
+
"REMOTE",
|
|
339
|
+
"LOCAL_ONLY"
|
|
340
|
+
]),
|
|
341
|
+
idempotencyKey: import_zod8.z.string(),
|
|
342
|
+
output: import_zod8.z.string().optional()
|
|
343
|
+
});
|
|
344
|
+
var ResolveRunOnceOuputSchema = import_zod8.z.object({
|
|
345
|
+
idempotencyKey: import_zod8.z.string(),
|
|
346
|
+
hasRun: import_zod8.z.boolean(),
|
|
347
|
+
output: SerializableJsonSchema.optional()
|
|
348
|
+
});
|
|
349
|
+
|
|
271
350
|
// src/events.ts
|
|
272
351
|
var import_slug = __toESM(require("slug"));
|
|
352
|
+
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
|
273
353
|
function customEvent(options) {
|
|
274
354
|
return {
|
|
275
355
|
metadata: {
|
|
@@ -281,7 +361,8 @@ function customEvent(options) {
|
|
|
281
361
|
options.name
|
|
282
362
|
],
|
|
283
363
|
payload: options.filter ?? {}
|
|
284
|
-
}
|
|
364
|
+
},
|
|
365
|
+
schema: (0, import_zod_to_json_schema.default)(options.schema)
|
|
285
366
|
},
|
|
286
367
|
schema: options.schema
|
|
287
368
|
};
|
|
@@ -320,7 +401,8 @@ function webhookEvent(options) {
|
|
|
320
401
|
},
|
|
321
402
|
event: options.eventName
|
|
322
403
|
},
|
|
323
|
-
manualRegistration: true
|
|
404
|
+
manualRegistration: true,
|
|
405
|
+
schema: (0, import_zod_to_json_schema.default)(options.schema)
|
|
324
406
|
},
|
|
325
407
|
schema: options.schema
|
|
326
408
|
};
|
|
@@ -328,228 +410,262 @@ function webhookEvent(options) {
|
|
|
328
410
|
__name(webhookEvent, "webhookEvent");
|
|
329
411
|
|
|
330
412
|
// ../internal-bridge/src/schemas/host.ts
|
|
331
|
-
var
|
|
413
|
+
var import_zod9 = require("zod");
|
|
332
414
|
var HostRPCSchema = {
|
|
333
415
|
TRIGGER_WORKFLOW: {
|
|
334
|
-
request:
|
|
335
|
-
id:
|
|
336
|
-
trigger:
|
|
416
|
+
request: import_zod9.z.object({
|
|
417
|
+
id: import_zod9.z.string(),
|
|
418
|
+
trigger: import_zod9.z.object({
|
|
337
419
|
input: JsonSchema.default({}),
|
|
338
420
|
context: JsonSchema.default({})
|
|
339
421
|
}),
|
|
340
|
-
meta:
|
|
341
|
-
environment:
|
|
342
|
-
workflowId:
|
|
343
|
-
organizationId:
|
|
344
|
-
apiKey:
|
|
345
|
-
isTest:
|
|
422
|
+
meta: import_zod9.z.object({
|
|
423
|
+
environment: import_zod9.z.string(),
|
|
424
|
+
workflowId: import_zod9.z.string(),
|
|
425
|
+
organizationId: import_zod9.z.string(),
|
|
426
|
+
apiKey: import_zod9.z.string(),
|
|
427
|
+
isTest: import_zod9.z.boolean().default(false),
|
|
428
|
+
appOrigin: import_zod9.z.string()
|
|
346
429
|
})
|
|
347
430
|
}),
|
|
348
|
-
response:
|
|
431
|
+
response: import_zod9.z.boolean()
|
|
349
432
|
},
|
|
350
433
|
RESOLVE_REQUEST: {
|
|
351
|
-
request:
|
|
352
|
-
id:
|
|
353
|
-
key:
|
|
434
|
+
request: import_zod9.z.object({
|
|
435
|
+
id: import_zod9.z.string(),
|
|
436
|
+
key: import_zod9.z.string(),
|
|
354
437
|
output: JsonSchema.default({}),
|
|
355
|
-
meta:
|
|
356
|
-
environment:
|
|
357
|
-
workflowId:
|
|
358
|
-
organizationId:
|
|
359
|
-
apiKey:
|
|
360
|
-
runId:
|
|
438
|
+
meta: import_zod9.z.object({
|
|
439
|
+
environment: import_zod9.z.string(),
|
|
440
|
+
workflowId: import_zod9.z.string(),
|
|
441
|
+
organizationId: import_zod9.z.string(),
|
|
442
|
+
apiKey: import_zod9.z.string(),
|
|
443
|
+
runId: import_zod9.z.string()
|
|
361
444
|
})
|
|
362
445
|
}),
|
|
363
|
-
response:
|
|
446
|
+
response: import_zod9.z.boolean()
|
|
364
447
|
},
|
|
365
448
|
RESOLVE_DELAY: {
|
|
366
|
-
request:
|
|
367
|
-
id:
|
|
368
|
-
key:
|
|
369
|
-
meta:
|
|
370
|
-
environment:
|
|
371
|
-
workflowId:
|
|
372
|
-
organizationId:
|
|
373
|
-
apiKey:
|
|
374
|
-
runId:
|
|
449
|
+
request: import_zod9.z.object({
|
|
450
|
+
id: import_zod9.z.string(),
|
|
451
|
+
key: import_zod9.z.string(),
|
|
452
|
+
meta: import_zod9.z.object({
|
|
453
|
+
environment: import_zod9.z.string(),
|
|
454
|
+
workflowId: import_zod9.z.string(),
|
|
455
|
+
organizationId: import_zod9.z.string(),
|
|
456
|
+
apiKey: import_zod9.z.string(),
|
|
457
|
+
runId: import_zod9.z.string()
|
|
375
458
|
})
|
|
376
459
|
}),
|
|
377
|
-
response:
|
|
460
|
+
response: import_zod9.z.boolean()
|
|
378
461
|
},
|
|
379
462
|
REJECT_REQUEST: {
|
|
380
|
-
request:
|
|
381
|
-
id:
|
|
382
|
-
key:
|
|
463
|
+
request: import_zod9.z.object({
|
|
464
|
+
id: import_zod9.z.string(),
|
|
465
|
+
key: import_zod9.z.string(),
|
|
383
466
|
error: JsonSchema.default({}),
|
|
384
|
-
meta:
|
|
385
|
-
environment:
|
|
386
|
-
workflowId:
|
|
387
|
-
organizationId:
|
|
388
|
-
apiKey:
|
|
389
|
-
runId:
|
|
467
|
+
meta: import_zod9.z.object({
|
|
468
|
+
environment: import_zod9.z.string(),
|
|
469
|
+
workflowId: import_zod9.z.string(),
|
|
470
|
+
organizationId: import_zod9.z.string(),
|
|
471
|
+
apiKey: import_zod9.z.string(),
|
|
472
|
+
runId: import_zod9.z.string()
|
|
390
473
|
})
|
|
391
474
|
}),
|
|
392
|
-
response:
|
|
475
|
+
response: import_zod9.z.boolean()
|
|
393
476
|
},
|
|
394
477
|
RESOLVE_FETCH_REQUEST: {
|
|
395
|
-
request:
|
|
396
|
-
id:
|
|
397
|
-
key:
|
|
478
|
+
request: import_zod9.z.object({
|
|
479
|
+
id: import_zod9.z.string(),
|
|
480
|
+
key: import_zod9.z.string(),
|
|
398
481
|
output: FetchOutputSchema,
|
|
399
|
-
meta:
|
|
400
|
-
environment:
|
|
401
|
-
workflowId:
|
|
402
|
-
organizationId:
|
|
403
|
-
apiKey:
|
|
404
|
-
runId:
|
|
482
|
+
meta: import_zod9.z.object({
|
|
483
|
+
environment: import_zod9.z.string(),
|
|
484
|
+
workflowId: import_zod9.z.string(),
|
|
485
|
+
organizationId: import_zod9.z.string(),
|
|
486
|
+
apiKey: import_zod9.z.string(),
|
|
487
|
+
runId: import_zod9.z.string()
|
|
405
488
|
})
|
|
406
489
|
}),
|
|
407
|
-
response:
|
|
490
|
+
response: import_zod9.z.boolean()
|
|
408
491
|
},
|
|
409
492
|
REJECT_FETCH_REQUEST: {
|
|
410
|
-
request:
|
|
411
|
-
id:
|
|
412
|
-
key:
|
|
493
|
+
request: import_zod9.z.object({
|
|
494
|
+
id: import_zod9.z.string(),
|
|
495
|
+
key: import_zod9.z.string(),
|
|
413
496
|
error: JsonSchema.default({}),
|
|
414
|
-
meta:
|
|
415
|
-
environment:
|
|
416
|
-
workflowId:
|
|
417
|
-
organizationId:
|
|
418
|
-
apiKey:
|
|
419
|
-
runId:
|
|
497
|
+
meta: import_zod9.z.object({
|
|
498
|
+
environment: import_zod9.z.string(),
|
|
499
|
+
workflowId: import_zod9.z.string(),
|
|
500
|
+
organizationId: import_zod9.z.string(),
|
|
501
|
+
apiKey: import_zod9.z.string(),
|
|
502
|
+
runId: import_zod9.z.string()
|
|
503
|
+
})
|
|
504
|
+
}),
|
|
505
|
+
response: import_zod9.z.boolean()
|
|
506
|
+
},
|
|
507
|
+
RESOLVE_RUN_ONCE: {
|
|
508
|
+
request: import_zod9.z.object({
|
|
509
|
+
id: import_zod9.z.string(),
|
|
510
|
+
key: import_zod9.z.string(),
|
|
511
|
+
output: ResolveRunOnceOuputSchema,
|
|
512
|
+
meta: import_zod9.z.object({
|
|
513
|
+
environment: import_zod9.z.string(),
|
|
514
|
+
workflowId: import_zod9.z.string(),
|
|
515
|
+
organizationId: import_zod9.z.string(),
|
|
516
|
+
apiKey: import_zod9.z.string(),
|
|
517
|
+
runId: import_zod9.z.string()
|
|
420
518
|
})
|
|
421
519
|
}),
|
|
422
|
-
response:
|
|
520
|
+
response: import_zod9.z.boolean()
|
|
423
521
|
}
|
|
424
522
|
};
|
|
425
523
|
|
|
426
524
|
// ../internal-bridge/src/schemas/server.ts
|
|
427
|
-
var
|
|
525
|
+
var import_zod10 = require("zod");
|
|
428
526
|
var ServerRPCSchema = {
|
|
429
527
|
INITIALIZE_DELAY: {
|
|
430
|
-
request:
|
|
431
|
-
runId:
|
|
432
|
-
key:
|
|
528
|
+
request: import_zod10.z.object({
|
|
529
|
+
runId: import_zod10.z.string(),
|
|
530
|
+
key: import_zod10.z.string(),
|
|
433
531
|
wait: WaitSchema,
|
|
434
|
-
timestamp:
|
|
532
|
+
timestamp: import_zod10.z.string()
|
|
435
533
|
}),
|
|
436
|
-
response:
|
|
534
|
+
response: import_zod10.z.boolean()
|
|
437
535
|
},
|
|
438
536
|
SEND_REQUEST: {
|
|
439
|
-
request:
|
|
440
|
-
runId:
|
|
441
|
-
key:
|
|
442
|
-
request:
|
|
443
|
-
service:
|
|
444
|
-
endpoint:
|
|
445
|
-
params:
|
|
537
|
+
request: import_zod10.z.object({
|
|
538
|
+
runId: import_zod10.z.string(),
|
|
539
|
+
key: import_zod10.z.string(),
|
|
540
|
+
request: import_zod10.z.object({
|
|
541
|
+
service: import_zod10.z.string(),
|
|
542
|
+
endpoint: import_zod10.z.string(),
|
|
543
|
+
params: import_zod10.z.any()
|
|
446
544
|
}),
|
|
447
|
-
timestamp:
|
|
545
|
+
timestamp: import_zod10.z.string()
|
|
448
546
|
}),
|
|
449
|
-
response:
|
|
547
|
+
response: import_zod10.z.boolean()
|
|
450
548
|
},
|
|
451
549
|
SEND_FETCH: {
|
|
452
|
-
request:
|
|
453
|
-
runId:
|
|
454
|
-
key:
|
|
550
|
+
request: import_zod10.z.object({
|
|
551
|
+
runId: import_zod10.z.string(),
|
|
552
|
+
key: import_zod10.z.string(),
|
|
455
553
|
fetch: FetchRequestSchema,
|
|
456
|
-
timestamp:
|
|
554
|
+
timestamp: import_zod10.z.string()
|
|
457
555
|
}),
|
|
458
|
-
response:
|
|
556
|
+
response: import_zod10.z.boolean()
|
|
459
557
|
},
|
|
460
558
|
SEND_LOG: {
|
|
461
|
-
request:
|
|
462
|
-
runId:
|
|
463
|
-
key:
|
|
464
|
-
log:
|
|
465
|
-
message:
|
|
466
|
-
level:
|
|
559
|
+
request: import_zod10.z.object({
|
|
560
|
+
runId: import_zod10.z.string(),
|
|
561
|
+
key: import_zod10.z.string(),
|
|
562
|
+
log: import_zod10.z.object({
|
|
563
|
+
message: import_zod10.z.string(),
|
|
564
|
+
level: import_zod10.z.enum([
|
|
467
565
|
"DEBUG",
|
|
468
566
|
"INFO",
|
|
469
567
|
"WARN",
|
|
470
568
|
"ERROR"
|
|
471
569
|
]),
|
|
472
|
-
properties:
|
|
570
|
+
properties: import_zod10.z.string().optional()
|
|
473
571
|
}),
|
|
474
|
-
timestamp:
|
|
572
|
+
timestamp: import_zod10.z.string()
|
|
475
573
|
}),
|
|
476
|
-
response:
|
|
574
|
+
response: import_zod10.z.boolean()
|
|
477
575
|
},
|
|
478
576
|
SEND_EVENT: {
|
|
479
|
-
request:
|
|
480
|
-
runId:
|
|
481
|
-
key:
|
|
577
|
+
request: import_zod10.z.object({
|
|
578
|
+
runId: import_zod10.z.string(),
|
|
579
|
+
key: import_zod10.z.string(),
|
|
482
580
|
event: CustomEventSchema,
|
|
483
|
-
timestamp:
|
|
581
|
+
timestamp: import_zod10.z.string()
|
|
484
582
|
}),
|
|
485
|
-
response:
|
|
583
|
+
response: import_zod10.z.boolean()
|
|
486
584
|
},
|
|
487
585
|
INITIALIZE_HOST: {
|
|
488
|
-
request:
|
|
489
|
-
apiKey:
|
|
490
|
-
workflowId:
|
|
491
|
-
workflowName:
|
|
586
|
+
request: import_zod10.z.object({
|
|
587
|
+
apiKey: import_zod10.z.string(),
|
|
588
|
+
workflowId: import_zod10.z.string(),
|
|
589
|
+
workflowName: import_zod10.z.string(),
|
|
492
590
|
trigger: TriggerMetadataSchema,
|
|
493
|
-
packageVersion:
|
|
494
|
-
packageName:
|
|
495
|
-
triggerTTL:
|
|
591
|
+
packageVersion: import_zod10.z.string(),
|
|
592
|
+
packageName: import_zod10.z.string(),
|
|
593
|
+
triggerTTL: import_zod10.z.number().optional()
|
|
496
594
|
}),
|
|
497
|
-
response:
|
|
498
|
-
|
|
499
|
-
type:
|
|
595
|
+
response: import_zod10.z.discriminatedUnion("type", [
|
|
596
|
+
import_zod10.z.object({
|
|
597
|
+
type: import_zod10.z.literal("success")
|
|
500
598
|
}),
|
|
501
|
-
|
|
502
|
-
type:
|
|
503
|
-
message:
|
|
599
|
+
import_zod10.z.object({
|
|
600
|
+
type: import_zod10.z.literal("error"),
|
|
601
|
+
message: import_zod10.z.string()
|
|
504
602
|
})
|
|
505
603
|
]).nullable()
|
|
506
604
|
},
|
|
507
605
|
START_WORKFLOW_RUN: {
|
|
508
|
-
request:
|
|
509
|
-
runId:
|
|
510
|
-
timestamp:
|
|
606
|
+
request: import_zod10.z.object({
|
|
607
|
+
runId: import_zod10.z.string(),
|
|
608
|
+
timestamp: import_zod10.z.string()
|
|
511
609
|
}),
|
|
512
|
-
response:
|
|
610
|
+
response: import_zod10.z.boolean()
|
|
513
611
|
},
|
|
514
612
|
COMPLETE_WORKFLOW_RUN: {
|
|
515
|
-
request:
|
|
516
|
-
runId:
|
|
517
|
-
output:
|
|
518
|
-
timestamp:
|
|
613
|
+
request: import_zod10.z.object({
|
|
614
|
+
runId: import_zod10.z.string(),
|
|
615
|
+
output: import_zod10.z.string().optional(),
|
|
616
|
+
timestamp: import_zod10.z.string()
|
|
519
617
|
}),
|
|
520
|
-
response:
|
|
618
|
+
response: import_zod10.z.boolean()
|
|
521
619
|
},
|
|
522
620
|
SEND_WORKFLOW_ERROR: {
|
|
523
|
-
request:
|
|
524
|
-
runId:
|
|
525
|
-
error:
|
|
526
|
-
name:
|
|
527
|
-
message:
|
|
528
|
-
stackTrace:
|
|
621
|
+
request: import_zod10.z.object({
|
|
622
|
+
runId: import_zod10.z.string(),
|
|
623
|
+
error: import_zod10.z.object({
|
|
624
|
+
name: import_zod10.z.string(),
|
|
625
|
+
message: import_zod10.z.string(),
|
|
626
|
+
stackTrace: import_zod10.z.string().optional()
|
|
529
627
|
}),
|
|
530
|
-
timestamp:
|
|
628
|
+
timestamp: import_zod10.z.string()
|
|
531
629
|
}),
|
|
532
|
-
response:
|
|
630
|
+
response: import_zod10.z.boolean()
|
|
631
|
+
},
|
|
632
|
+
INITIALIZE_RUN_ONCE: {
|
|
633
|
+
request: import_zod10.z.object({
|
|
634
|
+
runId: import_zod10.z.string(),
|
|
635
|
+
key: import_zod10.z.string(),
|
|
636
|
+
timestamp: import_zod10.z.string(),
|
|
637
|
+
runOnce: InitializeRunOnceSchema
|
|
638
|
+
}),
|
|
639
|
+
response: import_zod10.z.boolean()
|
|
640
|
+
},
|
|
641
|
+
COMPLETE_RUN_ONCE: {
|
|
642
|
+
request: import_zod10.z.object({
|
|
643
|
+
runId: import_zod10.z.string(),
|
|
644
|
+
key: import_zod10.z.string(),
|
|
645
|
+
timestamp: import_zod10.z.string(),
|
|
646
|
+
runOnce: CompleteRunOnceSchema
|
|
647
|
+
}),
|
|
648
|
+
response: import_zod10.z.boolean()
|
|
533
649
|
}
|
|
534
650
|
};
|
|
535
651
|
|
|
536
652
|
// ../internal-bridge/src/schemas/common.ts
|
|
537
|
-
var
|
|
538
|
-
var MESSAGE_META =
|
|
539
|
-
data:
|
|
540
|
-
id:
|
|
541
|
-
type:
|
|
542
|
-
|
|
543
|
-
|
|
653
|
+
var import_zod11 = require("zod");
|
|
654
|
+
var MESSAGE_META = import_zod11.z.object({
|
|
655
|
+
data: import_zod11.z.any(),
|
|
656
|
+
id: import_zod11.z.string(),
|
|
657
|
+
type: import_zod11.z.union([
|
|
658
|
+
import_zod11.z.literal("ACK"),
|
|
659
|
+
import_zod11.z.literal("MESSAGE")
|
|
544
660
|
])
|
|
545
661
|
});
|
|
546
|
-
var TriggerEnvironmentSchema =
|
|
662
|
+
var TriggerEnvironmentSchema = import_zod11.z.enum([
|
|
547
663
|
"live",
|
|
548
664
|
"development"
|
|
549
665
|
]);
|
|
550
666
|
|
|
551
667
|
// ../internal-bridge/src/zodRPC.ts
|
|
552
|
-
var
|
|
668
|
+
var import_zod12 = require("zod");
|
|
553
669
|
var import_node_crypto = require("crypto");
|
|
554
670
|
|
|
555
671
|
// ../internal-bridge/src/logger.ts
|
|
@@ -613,11 +729,11 @@ function formattedDateTime() {
|
|
|
613
729
|
__name(formattedDateTime, "formattedDateTime");
|
|
614
730
|
|
|
615
731
|
// ../internal-bridge/src/zodRPC.ts
|
|
616
|
-
var RPCMessageSchema =
|
|
617
|
-
id:
|
|
618
|
-
methodName:
|
|
619
|
-
data:
|
|
620
|
-
kind:
|
|
732
|
+
var RPCMessageSchema = import_zod12.z.object({
|
|
733
|
+
id: import_zod12.z.string(),
|
|
734
|
+
methodName: import_zod12.z.string(),
|
|
735
|
+
data: import_zod12.z.any(),
|
|
736
|
+
kind: import_zod12.z.enum([
|
|
621
737
|
"CALL",
|
|
622
738
|
"RESPONSE"
|
|
623
739
|
])
|
|
@@ -697,7 +813,7 @@ onCall_fn = /* @__PURE__ */ __name(async function(message) {
|
|
|
697
813
|
try {
|
|
698
814
|
await __privateMethod(this, _handleCall, handleCall_fn).call(this, message);
|
|
699
815
|
} catch (callError) {
|
|
700
|
-
if (callError instanceof
|
|
816
|
+
if (callError instanceof import_zod12.ZodError) {
|
|
701
817
|
__privateGet(this, _logger).error(`[ZodRPC] Received invalid call:
|
|
702
818
|
${JSON.stringify(message)}: `, callError.errors);
|
|
703
819
|
} else {
|
|
@@ -711,7 +827,7 @@ onResponse_fn = /* @__PURE__ */ __name(async function(message1) {
|
|
|
711
827
|
try {
|
|
712
828
|
await __privateMethod(this, _handleResponse, handleResponse_fn).call(this, message1);
|
|
713
829
|
} catch (callError) {
|
|
714
|
-
if (callError instanceof
|
|
830
|
+
if (callError instanceof import_zod12.ZodError) {
|
|
715
831
|
__privateGet(this, _logger).error(`[ZodRPC] Received invalid response
|
|
716
832
|
|
|
717
833
|
${JSON.stringify(message1)}: `, callError.flatten());
|
|
@@ -787,11 +903,11 @@ __name(packageResponse, "packageResponse");
|
|
|
787
903
|
// src/client.ts
|
|
788
904
|
var import_uuid2 = require("uuid");
|
|
789
905
|
var import_ws = require("ws");
|
|
790
|
-
var
|
|
906
|
+
var import_zod13 = require("zod");
|
|
791
907
|
|
|
792
908
|
// package.json
|
|
793
909
|
var name = "@trigger.dev/sdk";
|
|
794
|
-
var version = "0.2.
|
|
910
|
+
var version = "0.2.12-next.0";
|
|
795
911
|
|
|
796
912
|
// src/connection.ts
|
|
797
913
|
var import_uuid = require("uuid");
|
|
@@ -1049,7 +1165,7 @@ var zodErrorMessageOptions = {
|
|
|
1049
1165
|
error: " \u{1F525} "
|
|
1050
1166
|
}
|
|
1051
1167
|
};
|
|
1052
|
-
var _trigger, _options, _connection2, _serverRPC, _apiKey, _endpoint, _isConnected, _retryIntervalMs, _logger3, _closedByUser, _responseCompleteCallbacks, _waitForCallbacks, _fetchCallbacks, _initializeConnection, initializeConnection_fn, _initializeRPC, initializeRPC_fn, _initializeHost, initializeHost_fn, _send, send_fn;
|
|
1168
|
+
var _trigger, _options, _connection2, _serverRPC, _apiKey, _endpoint, _isConnected, _retryIntervalMs, _logger3, _closedByUser, _responseCompleteCallbacks, _waitForCallbacks, _fetchCallbacks, _runOnceCallbacks, _initializeConnection, initializeConnection_fn, _initializeRPC, initializeRPC_fn, _initializeHost, initializeHost_fn, _send, send_fn;
|
|
1053
1169
|
var TriggerClient = class {
|
|
1054
1170
|
constructor(trigger, options) {
|
|
1055
1171
|
__privateAdd(this, _initializeConnection);
|
|
@@ -1069,6 +1185,7 @@ var TriggerClient = class {
|
|
|
1069
1185
|
__privateAdd(this, _responseCompleteCallbacks, /* @__PURE__ */ new Map());
|
|
1070
1186
|
__privateAdd(this, _waitForCallbacks, /* @__PURE__ */ new Map());
|
|
1071
1187
|
__privateAdd(this, _fetchCallbacks, /* @__PURE__ */ new Map());
|
|
1188
|
+
__privateAdd(this, _runOnceCallbacks, /* @__PURE__ */ new Map());
|
|
1072
1189
|
__privateSet(this, _trigger, trigger);
|
|
1073
1190
|
__privateSet(this, _options, options);
|
|
1074
1191
|
const apiKey = __privateGet(this, _options).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
@@ -1107,6 +1224,7 @@ _closedByUser = new WeakMap();
|
|
|
1107
1224
|
_responseCompleteCallbacks = new WeakMap();
|
|
1108
1225
|
_waitForCallbacks = new WeakMap();
|
|
1109
1226
|
_fetchCallbacks = new WeakMap();
|
|
1227
|
+
_runOnceCallbacks = new WeakMap();
|
|
1110
1228
|
_initializeConnection = new WeakSet();
|
|
1111
1229
|
initializeConnection_fn = /* @__PURE__ */ __name(async function(instanceId) {
|
|
1112
1230
|
const id = instanceId ?? (0, import_uuid2.v4)();
|
|
@@ -1176,6 +1294,17 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1176
1294
|
resolve();
|
|
1177
1295
|
return true;
|
|
1178
1296
|
},
|
|
1297
|
+
RESOLVE_RUN_ONCE: async (data) => {
|
|
1298
|
+
__privateGet(this, _logger3).debug("Handling RESOLVE_RUN_ONCE", data);
|
|
1299
|
+
const runOnceCallbacks = __privateGet(this, _runOnceCallbacks).get(messageKey(data.meta.runId, data.key));
|
|
1300
|
+
if (!runOnceCallbacks) {
|
|
1301
|
+
__privateGet(this, _logger3).debug(`Could not find runOnce callbacks for request ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
|
|
1302
|
+
return true;
|
|
1303
|
+
}
|
|
1304
|
+
const { resolve } = runOnceCallbacks;
|
|
1305
|
+
resolve(data.output);
|
|
1306
|
+
return true;
|
|
1307
|
+
},
|
|
1179
1308
|
RESOLVE_REQUEST: async (data) => {
|
|
1180
1309
|
__privateGet(this, _logger3).debug("Handling RESOLVE_REQUEST", data);
|
|
1181
1310
|
const requestCallbacks = __privateGet(this, _responseCompleteCallbacks).get(messageKey(data.meta.runId, data.key));
|
|
@@ -1258,7 +1387,7 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1258
1387
|
status: response.status,
|
|
1259
1388
|
ok: response.ok,
|
|
1260
1389
|
headers: response.headers,
|
|
1261
|
-
body: response.body ? (options.responseSchema ??
|
|
1390
|
+
body: response.body ? (options.responseSchema ?? import_zod13.z.any()).parse(response.body) : void 0
|
|
1262
1391
|
};
|
|
1263
1392
|
}, "fetchFunction");
|
|
1264
1393
|
const ctx = {
|
|
@@ -1328,6 +1457,56 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1328
1457
|
await result;
|
|
1329
1458
|
return;
|
|
1330
1459
|
},
|
|
1460
|
+
runOnce: async (key, callback) => {
|
|
1461
|
+
const result = new Promise((resolve, reject) => {
|
|
1462
|
+
__privateGet(this, _runOnceCallbacks).set(messageKey(data.id, key), {
|
|
1463
|
+
resolve,
|
|
1464
|
+
reject
|
|
1465
|
+
});
|
|
1466
|
+
});
|
|
1467
|
+
await serverRPC.send("INITIALIZE_RUN_ONCE", {
|
|
1468
|
+
runId: data.id,
|
|
1469
|
+
key,
|
|
1470
|
+
runOnce: {
|
|
1471
|
+
type: "REMOTE"
|
|
1472
|
+
},
|
|
1473
|
+
timestamp: String(highPrecisionTimestamp())
|
|
1474
|
+
});
|
|
1475
|
+
const { idempotencyKey, hasRun, output } = await result;
|
|
1476
|
+
if (hasRun) {
|
|
1477
|
+
return output;
|
|
1478
|
+
}
|
|
1479
|
+
const callbackResult = await callback(idempotencyKey);
|
|
1480
|
+
await serverRPC.send("COMPLETE_RUN_ONCE", {
|
|
1481
|
+
runId: data.id,
|
|
1482
|
+
key,
|
|
1483
|
+
runOnce: {
|
|
1484
|
+
type: "REMOTE",
|
|
1485
|
+
idempotencyKey,
|
|
1486
|
+
output: callbackResult ? JSON.stringify(callbackResult) : void 0
|
|
1487
|
+
},
|
|
1488
|
+
timestamp: String(highPrecisionTimestamp())
|
|
1489
|
+
});
|
|
1490
|
+
return callbackResult;
|
|
1491
|
+
},
|
|
1492
|
+
runOnceLocalOnly: async (key, callback) => {
|
|
1493
|
+
const result = new Promise((resolve, reject) => {
|
|
1494
|
+
__privateGet(this, _runOnceCallbacks).set(messageKey(data.id, key), {
|
|
1495
|
+
resolve,
|
|
1496
|
+
reject
|
|
1497
|
+
});
|
|
1498
|
+
});
|
|
1499
|
+
await serverRPC.send("INITIALIZE_RUN_ONCE", {
|
|
1500
|
+
runId: data.id,
|
|
1501
|
+
key,
|
|
1502
|
+
runOnce: {
|
|
1503
|
+
type: "LOCAL_ONLY"
|
|
1504
|
+
},
|
|
1505
|
+
timestamp: String(highPrecisionTimestamp())
|
|
1506
|
+
});
|
|
1507
|
+
const { idempotencyKey } = await result;
|
|
1508
|
+
return callback(idempotencyKey);
|
|
1509
|
+
},
|
|
1331
1510
|
fetch: fetchFunction
|
|
1332
1511
|
};
|
|
1333
1512
|
const eventData = parsedEventData.data;
|
|
@@ -1361,7 +1540,10 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1361
1540
|
timestamp: String(highPrecisionTimestamp())
|
|
1362
1541
|
});
|
|
1363
1542
|
},
|
|
1364
|
-
fetch: fetchFunction
|
|
1543
|
+
fetch: fetchFunction,
|
|
1544
|
+
workflowId: data.meta.workflowId,
|
|
1545
|
+
appOrigin: data.meta.appOrigin,
|
|
1546
|
+
id: data.id
|
|
1365
1547
|
}, () => {
|
|
1366
1548
|
__privateGet(this, _logger3).debug("Running trigger...");
|
|
1367
1549
|
serverRPC.send("START_WORKFLOW_RUN", {
|
|
@@ -1384,9 +1566,9 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1384
1566
|
stackTrace: error2.stack
|
|
1385
1567
|
};
|
|
1386
1568
|
}
|
|
1387
|
-
const parsedError =
|
|
1388
|
-
name:
|
|
1389
|
-
message:
|
|
1569
|
+
const parsedError = import_zod13.z.object({
|
|
1570
|
+
name: import_zod13.z.string(),
|
|
1571
|
+
message: import_zod13.z.string()
|
|
1390
1572
|
}).passthrough().safeParse(error2);
|
|
1391
1573
|
if (parsedError.success) {
|
|
1392
1574
|
return parsedError.data;
|