@trigger.dev/sdk 0.2.11 → 0.2.12
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 +50 -2
- package/dist/index.js +290 -154
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -213,10 +213,19 @@ var ManualWebhookSourceSchema = import_zod5.z.object({
|
|
|
213
213
|
}),
|
|
214
214
|
event: import_zod5.z.string()
|
|
215
215
|
});
|
|
216
|
-
var
|
|
216
|
+
var SlackBlockInteractionSourceSchema = import_zod5.z.object({
|
|
217
|
+
type: import_zod5.z.literal("block_action"),
|
|
217
218
|
blockId: import_zod5.z.string(),
|
|
218
219
|
actionIds: import_zod5.z.array(import_zod5.z.string())
|
|
219
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
|
+
]);
|
|
220
229
|
|
|
221
230
|
// ../common-schemas/src/triggers.ts
|
|
222
231
|
var import_zod6 = require("zod");
|
|
@@ -224,7 +233,8 @@ var CustomEventTriggerSchema = import_zod6.z.object({
|
|
|
224
233
|
type: import_zod6.z.literal("CUSTOM_EVENT"),
|
|
225
234
|
service: import_zod6.z.literal("trigger"),
|
|
226
235
|
name: import_zod6.z.string(),
|
|
227
|
-
filter: EventFilterSchema
|
|
236
|
+
filter: EventFilterSchema,
|
|
237
|
+
schema: JsonSchema.optional()
|
|
228
238
|
});
|
|
229
239
|
var WebhookEventTriggerSchema = import_zod6.z.object({
|
|
230
240
|
type: import_zod6.z.literal("WEBHOOK"),
|
|
@@ -232,7 +242,8 @@ var WebhookEventTriggerSchema = import_zod6.z.object({
|
|
|
232
242
|
name: import_zod6.z.string(),
|
|
233
243
|
filter: EventFilterSchema,
|
|
234
244
|
source: JsonSchema.optional(),
|
|
235
|
-
manualRegistration: import_zod6.z.boolean().default(false)
|
|
245
|
+
manualRegistration: import_zod6.z.boolean().default(false),
|
|
246
|
+
schema: JsonSchema.optional()
|
|
236
247
|
});
|
|
237
248
|
var HttpEventTriggerSchema = import_zod6.z.object({
|
|
238
249
|
type: import_zod6.z.literal("HTTP_ENDPOINT"),
|
|
@@ -314,8 +325,31 @@ var FetchResponseSchema = import_zod7.z.object({
|
|
|
314
325
|
body: import_zod7.z.any().optional()
|
|
315
326
|
});
|
|
316
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
|
+
|
|
317
350
|
// src/events.ts
|
|
318
351
|
var import_slug = __toESM(require("slug"));
|
|
352
|
+
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
|
319
353
|
function customEvent(options) {
|
|
320
354
|
return {
|
|
321
355
|
metadata: {
|
|
@@ -327,7 +361,8 @@ function customEvent(options) {
|
|
|
327
361
|
options.name
|
|
328
362
|
],
|
|
329
363
|
payload: options.filter ?? {}
|
|
330
|
-
}
|
|
364
|
+
},
|
|
365
|
+
schema: (0, import_zod_to_json_schema.default)(options.schema)
|
|
331
366
|
},
|
|
332
367
|
schema: options.schema
|
|
333
368
|
};
|
|
@@ -366,7 +401,8 @@ function webhookEvent(options) {
|
|
|
366
401
|
},
|
|
367
402
|
event: options.eventName
|
|
368
403
|
},
|
|
369
|
-
manualRegistration: true
|
|
404
|
+
manualRegistration: true,
|
|
405
|
+
schema: (0, import_zod_to_json_schema.default)(options.schema)
|
|
370
406
|
},
|
|
371
407
|
schema: options.schema
|
|
372
408
|
};
|
|
@@ -374,228 +410,262 @@ function webhookEvent(options) {
|
|
|
374
410
|
__name(webhookEvent, "webhookEvent");
|
|
375
411
|
|
|
376
412
|
// ../internal-bridge/src/schemas/host.ts
|
|
377
|
-
var
|
|
413
|
+
var import_zod9 = require("zod");
|
|
378
414
|
var HostRPCSchema = {
|
|
379
415
|
TRIGGER_WORKFLOW: {
|
|
380
|
-
request:
|
|
381
|
-
id:
|
|
382
|
-
trigger:
|
|
416
|
+
request: import_zod9.z.object({
|
|
417
|
+
id: import_zod9.z.string(),
|
|
418
|
+
trigger: import_zod9.z.object({
|
|
383
419
|
input: JsonSchema.default({}),
|
|
384
420
|
context: JsonSchema.default({})
|
|
385
421
|
}),
|
|
386
|
-
meta:
|
|
387
|
-
environment:
|
|
388
|
-
workflowId:
|
|
389
|
-
organizationId:
|
|
390
|
-
apiKey:
|
|
391
|
-
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()
|
|
392
429
|
})
|
|
393
430
|
}),
|
|
394
|
-
response:
|
|
431
|
+
response: import_zod9.z.boolean()
|
|
395
432
|
},
|
|
396
433
|
RESOLVE_REQUEST: {
|
|
397
|
-
request:
|
|
398
|
-
id:
|
|
399
|
-
key:
|
|
434
|
+
request: import_zod9.z.object({
|
|
435
|
+
id: import_zod9.z.string(),
|
|
436
|
+
key: import_zod9.z.string(),
|
|
400
437
|
output: JsonSchema.default({}),
|
|
401
|
-
meta:
|
|
402
|
-
environment:
|
|
403
|
-
workflowId:
|
|
404
|
-
organizationId:
|
|
405
|
-
apiKey:
|
|
406
|
-
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()
|
|
407
444
|
})
|
|
408
445
|
}),
|
|
409
|
-
response:
|
|
446
|
+
response: import_zod9.z.boolean()
|
|
410
447
|
},
|
|
411
448
|
RESOLVE_DELAY: {
|
|
412
|
-
request:
|
|
413
|
-
id:
|
|
414
|
-
key:
|
|
415
|
-
meta:
|
|
416
|
-
environment:
|
|
417
|
-
workflowId:
|
|
418
|
-
organizationId:
|
|
419
|
-
apiKey:
|
|
420
|
-
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()
|
|
421
458
|
})
|
|
422
459
|
}),
|
|
423
|
-
response:
|
|
460
|
+
response: import_zod9.z.boolean()
|
|
424
461
|
},
|
|
425
462
|
REJECT_REQUEST: {
|
|
426
|
-
request:
|
|
427
|
-
id:
|
|
428
|
-
key:
|
|
463
|
+
request: import_zod9.z.object({
|
|
464
|
+
id: import_zod9.z.string(),
|
|
465
|
+
key: import_zod9.z.string(),
|
|
429
466
|
error: JsonSchema.default({}),
|
|
430
|
-
meta:
|
|
431
|
-
environment:
|
|
432
|
-
workflowId:
|
|
433
|
-
organizationId:
|
|
434
|
-
apiKey:
|
|
435
|
-
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()
|
|
436
473
|
})
|
|
437
474
|
}),
|
|
438
|
-
response:
|
|
475
|
+
response: import_zod9.z.boolean()
|
|
439
476
|
},
|
|
440
477
|
RESOLVE_FETCH_REQUEST: {
|
|
441
|
-
request:
|
|
442
|
-
id:
|
|
443
|
-
key:
|
|
478
|
+
request: import_zod9.z.object({
|
|
479
|
+
id: import_zod9.z.string(),
|
|
480
|
+
key: import_zod9.z.string(),
|
|
444
481
|
output: FetchOutputSchema,
|
|
445
|
-
meta:
|
|
446
|
-
environment:
|
|
447
|
-
workflowId:
|
|
448
|
-
organizationId:
|
|
449
|
-
apiKey:
|
|
450
|
-
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()
|
|
451
488
|
})
|
|
452
489
|
}),
|
|
453
|
-
response:
|
|
490
|
+
response: import_zod9.z.boolean()
|
|
454
491
|
},
|
|
455
492
|
REJECT_FETCH_REQUEST: {
|
|
456
|
-
request:
|
|
457
|
-
id:
|
|
458
|
-
key:
|
|
493
|
+
request: import_zod9.z.object({
|
|
494
|
+
id: import_zod9.z.string(),
|
|
495
|
+
key: import_zod9.z.string(),
|
|
459
496
|
error: JsonSchema.default({}),
|
|
460
|
-
meta:
|
|
461
|
-
environment:
|
|
462
|
-
workflowId:
|
|
463
|
-
organizationId:
|
|
464
|
-
apiKey:
|
|
465
|
-
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()
|
|
466
518
|
})
|
|
467
519
|
}),
|
|
468
|
-
response:
|
|
520
|
+
response: import_zod9.z.boolean()
|
|
469
521
|
}
|
|
470
522
|
};
|
|
471
523
|
|
|
472
524
|
// ../internal-bridge/src/schemas/server.ts
|
|
473
|
-
var
|
|
525
|
+
var import_zod10 = require("zod");
|
|
474
526
|
var ServerRPCSchema = {
|
|
475
527
|
INITIALIZE_DELAY: {
|
|
476
|
-
request:
|
|
477
|
-
runId:
|
|
478
|
-
key:
|
|
528
|
+
request: import_zod10.z.object({
|
|
529
|
+
runId: import_zod10.z.string(),
|
|
530
|
+
key: import_zod10.z.string(),
|
|
479
531
|
wait: WaitSchema,
|
|
480
|
-
timestamp:
|
|
532
|
+
timestamp: import_zod10.z.string()
|
|
481
533
|
}),
|
|
482
|
-
response:
|
|
534
|
+
response: import_zod10.z.boolean()
|
|
483
535
|
},
|
|
484
536
|
SEND_REQUEST: {
|
|
485
|
-
request:
|
|
486
|
-
runId:
|
|
487
|
-
key:
|
|
488
|
-
request:
|
|
489
|
-
service:
|
|
490
|
-
endpoint:
|
|
491
|
-
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()
|
|
492
544
|
}),
|
|
493
|
-
timestamp:
|
|
545
|
+
timestamp: import_zod10.z.string()
|
|
494
546
|
}),
|
|
495
|
-
response:
|
|
547
|
+
response: import_zod10.z.boolean()
|
|
496
548
|
},
|
|
497
549
|
SEND_FETCH: {
|
|
498
|
-
request:
|
|
499
|
-
runId:
|
|
500
|
-
key:
|
|
550
|
+
request: import_zod10.z.object({
|
|
551
|
+
runId: import_zod10.z.string(),
|
|
552
|
+
key: import_zod10.z.string(),
|
|
501
553
|
fetch: FetchRequestSchema,
|
|
502
|
-
timestamp:
|
|
554
|
+
timestamp: import_zod10.z.string()
|
|
503
555
|
}),
|
|
504
|
-
response:
|
|
556
|
+
response: import_zod10.z.boolean()
|
|
505
557
|
},
|
|
506
558
|
SEND_LOG: {
|
|
507
|
-
request:
|
|
508
|
-
runId:
|
|
509
|
-
key:
|
|
510
|
-
log:
|
|
511
|
-
message:
|
|
512
|
-
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([
|
|
513
565
|
"DEBUG",
|
|
514
566
|
"INFO",
|
|
515
567
|
"WARN",
|
|
516
568
|
"ERROR"
|
|
517
569
|
]),
|
|
518
|
-
properties:
|
|
570
|
+
properties: import_zod10.z.string().optional()
|
|
519
571
|
}),
|
|
520
|
-
timestamp:
|
|
572
|
+
timestamp: import_zod10.z.string()
|
|
521
573
|
}),
|
|
522
|
-
response:
|
|
574
|
+
response: import_zod10.z.boolean()
|
|
523
575
|
},
|
|
524
576
|
SEND_EVENT: {
|
|
525
|
-
request:
|
|
526
|
-
runId:
|
|
527
|
-
key:
|
|
577
|
+
request: import_zod10.z.object({
|
|
578
|
+
runId: import_zod10.z.string(),
|
|
579
|
+
key: import_zod10.z.string(),
|
|
528
580
|
event: CustomEventSchema,
|
|
529
|
-
timestamp:
|
|
581
|
+
timestamp: import_zod10.z.string()
|
|
530
582
|
}),
|
|
531
|
-
response:
|
|
583
|
+
response: import_zod10.z.boolean()
|
|
532
584
|
},
|
|
533
585
|
INITIALIZE_HOST: {
|
|
534
|
-
request:
|
|
535
|
-
apiKey:
|
|
536
|
-
workflowId:
|
|
537
|
-
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(),
|
|
538
590
|
trigger: TriggerMetadataSchema,
|
|
539
|
-
packageVersion:
|
|
540
|
-
packageName:
|
|
541
|
-
triggerTTL:
|
|
591
|
+
packageVersion: import_zod10.z.string(),
|
|
592
|
+
packageName: import_zod10.z.string(),
|
|
593
|
+
triggerTTL: import_zod10.z.number().optional()
|
|
542
594
|
}),
|
|
543
|
-
response:
|
|
544
|
-
|
|
545
|
-
type:
|
|
595
|
+
response: import_zod10.z.discriminatedUnion("type", [
|
|
596
|
+
import_zod10.z.object({
|
|
597
|
+
type: import_zod10.z.literal("success")
|
|
546
598
|
}),
|
|
547
|
-
|
|
548
|
-
type:
|
|
549
|
-
message:
|
|
599
|
+
import_zod10.z.object({
|
|
600
|
+
type: import_zod10.z.literal("error"),
|
|
601
|
+
message: import_zod10.z.string()
|
|
550
602
|
})
|
|
551
603
|
]).nullable()
|
|
552
604
|
},
|
|
553
605
|
START_WORKFLOW_RUN: {
|
|
554
|
-
request:
|
|
555
|
-
runId:
|
|
556
|
-
timestamp:
|
|
606
|
+
request: import_zod10.z.object({
|
|
607
|
+
runId: import_zod10.z.string(),
|
|
608
|
+
timestamp: import_zod10.z.string()
|
|
557
609
|
}),
|
|
558
|
-
response:
|
|
610
|
+
response: import_zod10.z.boolean()
|
|
559
611
|
},
|
|
560
612
|
COMPLETE_WORKFLOW_RUN: {
|
|
561
|
-
request:
|
|
562
|
-
runId:
|
|
563
|
-
output:
|
|
564
|
-
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()
|
|
565
617
|
}),
|
|
566
|
-
response:
|
|
618
|
+
response: import_zod10.z.boolean()
|
|
567
619
|
},
|
|
568
620
|
SEND_WORKFLOW_ERROR: {
|
|
569
|
-
request:
|
|
570
|
-
runId:
|
|
571
|
-
error:
|
|
572
|
-
name:
|
|
573
|
-
message:
|
|
574
|
-
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()
|
|
575
627
|
}),
|
|
576
|
-
timestamp:
|
|
628
|
+
timestamp: import_zod10.z.string()
|
|
577
629
|
}),
|
|
578
|
-
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()
|
|
579
649
|
}
|
|
580
650
|
};
|
|
581
651
|
|
|
582
652
|
// ../internal-bridge/src/schemas/common.ts
|
|
583
|
-
var
|
|
584
|
-
var MESSAGE_META =
|
|
585
|
-
data:
|
|
586
|
-
id:
|
|
587
|
-
type:
|
|
588
|
-
|
|
589
|
-
|
|
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")
|
|
590
660
|
])
|
|
591
661
|
});
|
|
592
|
-
var TriggerEnvironmentSchema =
|
|
662
|
+
var TriggerEnvironmentSchema = import_zod11.z.enum([
|
|
593
663
|
"live",
|
|
594
664
|
"development"
|
|
595
665
|
]);
|
|
596
666
|
|
|
597
667
|
// ../internal-bridge/src/zodRPC.ts
|
|
598
|
-
var
|
|
668
|
+
var import_zod12 = require("zod");
|
|
599
669
|
var import_node_crypto = require("crypto");
|
|
600
670
|
|
|
601
671
|
// ../internal-bridge/src/logger.ts
|
|
@@ -659,11 +729,11 @@ function formattedDateTime() {
|
|
|
659
729
|
__name(formattedDateTime, "formattedDateTime");
|
|
660
730
|
|
|
661
731
|
// ../internal-bridge/src/zodRPC.ts
|
|
662
|
-
var RPCMessageSchema =
|
|
663
|
-
id:
|
|
664
|
-
methodName:
|
|
665
|
-
data:
|
|
666
|
-
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([
|
|
667
737
|
"CALL",
|
|
668
738
|
"RESPONSE"
|
|
669
739
|
])
|
|
@@ -743,7 +813,7 @@ onCall_fn = /* @__PURE__ */ __name(async function(message) {
|
|
|
743
813
|
try {
|
|
744
814
|
await __privateMethod(this, _handleCall, handleCall_fn).call(this, message);
|
|
745
815
|
} catch (callError) {
|
|
746
|
-
if (callError instanceof
|
|
816
|
+
if (callError instanceof import_zod12.ZodError) {
|
|
747
817
|
__privateGet(this, _logger).error(`[ZodRPC] Received invalid call:
|
|
748
818
|
${JSON.stringify(message)}: `, callError.errors);
|
|
749
819
|
} else {
|
|
@@ -757,7 +827,7 @@ onResponse_fn = /* @__PURE__ */ __name(async function(message1) {
|
|
|
757
827
|
try {
|
|
758
828
|
await __privateMethod(this, _handleResponse, handleResponse_fn).call(this, message1);
|
|
759
829
|
} catch (callError) {
|
|
760
|
-
if (callError instanceof
|
|
830
|
+
if (callError instanceof import_zod12.ZodError) {
|
|
761
831
|
__privateGet(this, _logger).error(`[ZodRPC] Received invalid response
|
|
762
832
|
|
|
763
833
|
${JSON.stringify(message1)}: `, callError.flatten());
|
|
@@ -833,11 +903,11 @@ __name(packageResponse, "packageResponse");
|
|
|
833
903
|
// src/client.ts
|
|
834
904
|
var import_uuid2 = require("uuid");
|
|
835
905
|
var import_ws = require("ws");
|
|
836
|
-
var
|
|
906
|
+
var import_zod13 = require("zod");
|
|
837
907
|
|
|
838
908
|
// package.json
|
|
839
909
|
var name = "@trigger.dev/sdk";
|
|
840
|
-
var version = "0.2.
|
|
910
|
+
var version = "0.2.12";
|
|
841
911
|
|
|
842
912
|
// src/connection.ts
|
|
843
913
|
var import_uuid = require("uuid");
|
|
@@ -1095,7 +1165,7 @@ var zodErrorMessageOptions = {
|
|
|
1095
1165
|
error: " \u{1F525} "
|
|
1096
1166
|
}
|
|
1097
1167
|
};
|
|
1098
|
-
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;
|
|
1099
1169
|
var TriggerClient = class {
|
|
1100
1170
|
constructor(trigger, options) {
|
|
1101
1171
|
__privateAdd(this, _initializeConnection);
|
|
@@ -1115,6 +1185,7 @@ var TriggerClient = class {
|
|
|
1115
1185
|
__privateAdd(this, _responseCompleteCallbacks, /* @__PURE__ */ new Map());
|
|
1116
1186
|
__privateAdd(this, _waitForCallbacks, /* @__PURE__ */ new Map());
|
|
1117
1187
|
__privateAdd(this, _fetchCallbacks, /* @__PURE__ */ new Map());
|
|
1188
|
+
__privateAdd(this, _runOnceCallbacks, /* @__PURE__ */ new Map());
|
|
1118
1189
|
__privateSet(this, _trigger, trigger);
|
|
1119
1190
|
__privateSet(this, _options, options);
|
|
1120
1191
|
const apiKey = __privateGet(this, _options).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
@@ -1153,6 +1224,7 @@ _closedByUser = new WeakMap();
|
|
|
1153
1224
|
_responseCompleteCallbacks = new WeakMap();
|
|
1154
1225
|
_waitForCallbacks = new WeakMap();
|
|
1155
1226
|
_fetchCallbacks = new WeakMap();
|
|
1227
|
+
_runOnceCallbacks = new WeakMap();
|
|
1156
1228
|
_initializeConnection = new WeakSet();
|
|
1157
1229
|
initializeConnection_fn = /* @__PURE__ */ __name(async function(instanceId) {
|
|
1158
1230
|
const id = instanceId ?? (0, import_uuid2.v4)();
|
|
@@ -1222,6 +1294,17 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1222
1294
|
resolve();
|
|
1223
1295
|
return true;
|
|
1224
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
|
+
},
|
|
1225
1308
|
RESOLVE_REQUEST: async (data) => {
|
|
1226
1309
|
__privateGet(this, _logger3).debug("Handling RESOLVE_REQUEST", data);
|
|
1227
1310
|
const requestCallbacks = __privateGet(this, _responseCompleteCallbacks).get(messageKey(data.meta.runId, data.key));
|
|
@@ -1304,7 +1387,7 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1304
1387
|
status: response.status,
|
|
1305
1388
|
ok: response.ok,
|
|
1306
1389
|
headers: response.headers,
|
|
1307
|
-
body: response.body ? (options.responseSchema ??
|
|
1390
|
+
body: response.body ? (options.responseSchema ?? import_zod13.z.any()).parse(response.body) : void 0
|
|
1308
1391
|
};
|
|
1309
1392
|
}, "fetchFunction");
|
|
1310
1393
|
const ctx = {
|
|
@@ -1374,6 +1457,56 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1374
1457
|
await result;
|
|
1375
1458
|
return;
|
|
1376
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
|
+
},
|
|
1377
1510
|
fetch: fetchFunction
|
|
1378
1511
|
};
|
|
1379
1512
|
const eventData = parsedEventData.data;
|
|
@@ -1407,7 +1540,10 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1407
1540
|
timestamp: String(highPrecisionTimestamp())
|
|
1408
1541
|
});
|
|
1409
1542
|
},
|
|
1410
|
-
fetch: fetchFunction
|
|
1543
|
+
fetch: fetchFunction,
|
|
1544
|
+
workflowId: data.meta.workflowId,
|
|
1545
|
+
appOrigin: data.meta.appOrigin,
|
|
1546
|
+
id: data.id
|
|
1411
1547
|
}, () => {
|
|
1412
1548
|
__privateGet(this, _logger3).debug("Running trigger...");
|
|
1413
1549
|
serverRPC.send("START_WORKFLOW_RUN", {
|
|
@@ -1430,9 +1566,9 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1430
1566
|
stackTrace: error2.stack
|
|
1431
1567
|
};
|
|
1432
1568
|
}
|
|
1433
|
-
const parsedError =
|
|
1434
|
-
name:
|
|
1435
|
-
message:
|
|
1569
|
+
const parsedError = import_zod13.z.object({
|
|
1570
|
+
name: import_zod13.z.string(),
|
|
1571
|
+
message: import_zod13.z.string()
|
|
1436
1572
|
}).passthrough().safeParse(error2);
|
|
1437
1573
|
if (parsedError.success) {
|
|
1438
1574
|
return parsedError.data;
|