@trigger.dev/sdk 0.2.15-next.0 → 0.2.16-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/dist/index.d.ts +3 -3
- package/dist/index.js +241 -182
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -348,9 +348,11 @@ var ResolveRunOnceOuputSchema = import_zod8.z.object({
|
|
|
348
348
|
});
|
|
349
349
|
|
|
350
350
|
// src/events.ts
|
|
351
|
+
var import_zod9 = require("zod");
|
|
351
352
|
var import_slug = __toESM(require("slug"));
|
|
352
353
|
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
|
353
354
|
function customEvent(options) {
|
|
355
|
+
const schema = options.schema ?? import_zod9.z.any();
|
|
354
356
|
return {
|
|
355
357
|
metadata: {
|
|
356
358
|
type: "CUSTOM_EVENT",
|
|
@@ -362,9 +364,9 @@ function customEvent(options) {
|
|
|
362
364
|
],
|
|
363
365
|
payload: options.filter ?? {}
|
|
364
366
|
},
|
|
365
|
-
schema: (0, import_zod_to_json_schema.default)(
|
|
367
|
+
schema: (0, import_zod_to_json_schema.default)(schema)
|
|
366
368
|
},
|
|
367
|
-
schema
|
|
369
|
+
schema
|
|
368
370
|
};
|
|
369
371
|
}
|
|
370
372
|
__name(customEvent, "customEvent");
|
|
@@ -381,6 +383,7 @@ function scheduleEvent(options) {
|
|
|
381
383
|
}
|
|
382
384
|
__name(scheduleEvent, "scheduleEvent");
|
|
383
385
|
function webhookEvent(options) {
|
|
386
|
+
const schema = options.schema ?? import_zod9.z.any();
|
|
384
387
|
return {
|
|
385
388
|
metadata: {
|
|
386
389
|
type: "WEBHOOK",
|
|
@@ -402,7 +405,7 @@ function webhookEvent(options) {
|
|
|
402
405
|
event: options.eventName
|
|
403
406
|
},
|
|
404
407
|
manualRegistration: true,
|
|
405
|
-
schema: (0, import_zod_to_json_schema.default)(
|
|
408
|
+
schema: (0, import_zod_to_json_schema.default)(schema)
|
|
406
409
|
},
|
|
407
410
|
schema: options.schema
|
|
408
411
|
};
|
|
@@ -410,263 +413,299 @@ function webhookEvent(options) {
|
|
|
410
413
|
__name(webhookEvent, "webhookEvent");
|
|
411
414
|
|
|
412
415
|
// ../internal-bridge/src/schemas/host.ts
|
|
413
|
-
var
|
|
416
|
+
var import_zod10 = require("zod");
|
|
414
417
|
var HostRPCSchema = {
|
|
415
418
|
TRIGGER_WORKFLOW: {
|
|
416
|
-
request:
|
|
417
|
-
id:
|
|
418
|
-
trigger:
|
|
419
|
+
request: import_zod10.z.object({
|
|
420
|
+
id: import_zod10.z.string(),
|
|
421
|
+
trigger: import_zod10.z.object({
|
|
419
422
|
input: JsonSchema.default({}),
|
|
420
423
|
context: JsonSchema.default({})
|
|
421
424
|
}),
|
|
422
|
-
meta:
|
|
423
|
-
environment:
|
|
424
|
-
workflowId:
|
|
425
|
-
organizationId:
|
|
426
|
-
apiKey:
|
|
427
|
-
isTest:
|
|
428
|
-
appOrigin:
|
|
425
|
+
meta: import_zod10.z.object({
|
|
426
|
+
environment: import_zod10.z.string(),
|
|
427
|
+
workflowId: import_zod10.z.string(),
|
|
428
|
+
organizationId: import_zod10.z.string(),
|
|
429
|
+
apiKey: import_zod10.z.string(),
|
|
430
|
+
isTest: import_zod10.z.boolean().default(false),
|
|
431
|
+
appOrigin: import_zod10.z.string()
|
|
429
432
|
})
|
|
430
433
|
}),
|
|
431
|
-
response:
|
|
434
|
+
response: import_zod10.z.boolean()
|
|
432
435
|
},
|
|
433
436
|
RESOLVE_REQUEST: {
|
|
434
|
-
request:
|
|
435
|
-
id:
|
|
436
|
-
key:
|
|
437
|
+
request: import_zod10.z.object({
|
|
438
|
+
id: import_zod10.z.string(),
|
|
439
|
+
key: import_zod10.z.string(),
|
|
437
440
|
output: JsonSchema.default({}),
|
|
438
|
-
meta:
|
|
439
|
-
environment:
|
|
440
|
-
workflowId:
|
|
441
|
-
organizationId:
|
|
442
|
-
apiKey:
|
|
443
|
-
runId:
|
|
441
|
+
meta: import_zod10.z.object({
|
|
442
|
+
environment: import_zod10.z.string(),
|
|
443
|
+
workflowId: import_zod10.z.string(),
|
|
444
|
+
organizationId: import_zod10.z.string(),
|
|
445
|
+
apiKey: import_zod10.z.string(),
|
|
446
|
+
runId: import_zod10.z.string()
|
|
444
447
|
})
|
|
445
448
|
}),
|
|
446
|
-
response:
|
|
449
|
+
response: import_zod10.z.boolean()
|
|
447
450
|
},
|
|
448
451
|
RESOLVE_DELAY: {
|
|
449
|
-
request:
|
|
450
|
-
id:
|
|
451
|
-
key:
|
|
452
|
-
meta:
|
|
453
|
-
environment:
|
|
454
|
-
workflowId:
|
|
455
|
-
organizationId:
|
|
456
|
-
apiKey:
|
|
457
|
-
runId:
|
|
452
|
+
request: import_zod10.z.object({
|
|
453
|
+
id: import_zod10.z.string(),
|
|
454
|
+
key: import_zod10.z.string(),
|
|
455
|
+
meta: import_zod10.z.object({
|
|
456
|
+
environment: import_zod10.z.string(),
|
|
457
|
+
workflowId: import_zod10.z.string(),
|
|
458
|
+
organizationId: import_zod10.z.string(),
|
|
459
|
+
apiKey: import_zod10.z.string(),
|
|
460
|
+
runId: import_zod10.z.string()
|
|
458
461
|
})
|
|
459
462
|
}),
|
|
460
|
-
response:
|
|
463
|
+
response: import_zod10.z.boolean()
|
|
461
464
|
},
|
|
462
465
|
REJECT_REQUEST: {
|
|
463
|
-
request:
|
|
464
|
-
id:
|
|
465
|
-
key:
|
|
466
|
+
request: import_zod10.z.object({
|
|
467
|
+
id: import_zod10.z.string(),
|
|
468
|
+
key: import_zod10.z.string(),
|
|
466
469
|
error: JsonSchema.default({}),
|
|
467
|
-
meta:
|
|
468
|
-
environment:
|
|
469
|
-
workflowId:
|
|
470
|
-
organizationId:
|
|
471
|
-
apiKey:
|
|
472
|
-
runId:
|
|
470
|
+
meta: import_zod10.z.object({
|
|
471
|
+
environment: import_zod10.z.string(),
|
|
472
|
+
workflowId: import_zod10.z.string(),
|
|
473
|
+
organizationId: import_zod10.z.string(),
|
|
474
|
+
apiKey: import_zod10.z.string(),
|
|
475
|
+
runId: import_zod10.z.string()
|
|
473
476
|
})
|
|
474
477
|
}),
|
|
475
|
-
response:
|
|
478
|
+
response: import_zod10.z.boolean()
|
|
476
479
|
},
|
|
477
480
|
RESOLVE_FETCH_REQUEST: {
|
|
478
|
-
request:
|
|
479
|
-
id:
|
|
480
|
-
key:
|
|
481
|
+
request: import_zod10.z.object({
|
|
482
|
+
id: import_zod10.z.string(),
|
|
483
|
+
key: import_zod10.z.string(),
|
|
481
484
|
output: FetchOutputSchema,
|
|
482
|
-
meta:
|
|
483
|
-
environment:
|
|
484
|
-
workflowId:
|
|
485
|
-
organizationId:
|
|
486
|
-
apiKey:
|
|
487
|
-
runId:
|
|
485
|
+
meta: import_zod10.z.object({
|
|
486
|
+
environment: import_zod10.z.string(),
|
|
487
|
+
workflowId: import_zod10.z.string(),
|
|
488
|
+
organizationId: import_zod10.z.string(),
|
|
489
|
+
apiKey: import_zod10.z.string(),
|
|
490
|
+
runId: import_zod10.z.string()
|
|
488
491
|
})
|
|
489
492
|
}),
|
|
490
|
-
response:
|
|
493
|
+
response: import_zod10.z.boolean()
|
|
491
494
|
},
|
|
492
495
|
REJECT_FETCH_REQUEST: {
|
|
493
|
-
request:
|
|
494
|
-
id:
|
|
495
|
-
key:
|
|
496
|
+
request: import_zod10.z.object({
|
|
497
|
+
id: import_zod10.z.string(),
|
|
498
|
+
key: import_zod10.z.string(),
|
|
496
499
|
error: JsonSchema.default({}),
|
|
497
|
-
meta:
|
|
498
|
-
environment:
|
|
499
|
-
workflowId:
|
|
500
|
-
organizationId:
|
|
501
|
-
apiKey:
|
|
502
|
-
runId:
|
|
500
|
+
meta: import_zod10.z.object({
|
|
501
|
+
environment: import_zod10.z.string(),
|
|
502
|
+
workflowId: import_zod10.z.string(),
|
|
503
|
+
organizationId: import_zod10.z.string(),
|
|
504
|
+
apiKey: import_zod10.z.string(),
|
|
505
|
+
runId: import_zod10.z.string()
|
|
503
506
|
})
|
|
504
507
|
}),
|
|
505
|
-
response:
|
|
508
|
+
response: import_zod10.z.boolean()
|
|
506
509
|
},
|
|
507
510
|
RESOLVE_RUN_ONCE: {
|
|
508
|
-
request:
|
|
509
|
-
id:
|
|
510
|
-
key:
|
|
511
|
+
request: import_zod10.z.object({
|
|
512
|
+
id: import_zod10.z.string(),
|
|
513
|
+
key: import_zod10.z.string(),
|
|
511
514
|
output: ResolveRunOnceOuputSchema,
|
|
512
|
-
meta:
|
|
513
|
-
environment:
|
|
514
|
-
workflowId:
|
|
515
|
-
organizationId:
|
|
516
|
-
apiKey:
|
|
517
|
-
runId:
|
|
515
|
+
meta: import_zod10.z.object({
|
|
516
|
+
environment: import_zod10.z.string(),
|
|
517
|
+
workflowId: import_zod10.z.string(),
|
|
518
|
+
organizationId: import_zod10.z.string(),
|
|
519
|
+
apiKey: import_zod10.z.string(),
|
|
520
|
+
runId: import_zod10.z.string()
|
|
518
521
|
})
|
|
519
522
|
}),
|
|
520
|
-
response:
|
|
523
|
+
response: import_zod10.z.boolean()
|
|
521
524
|
}
|
|
522
525
|
};
|
|
523
526
|
|
|
524
527
|
// ../internal-bridge/src/schemas/server.ts
|
|
525
|
-
var
|
|
528
|
+
var import_zod11 = require("zod");
|
|
526
529
|
var ServerRPCSchema = {
|
|
527
530
|
INITIALIZE_DELAY: {
|
|
528
|
-
request:
|
|
529
|
-
runId:
|
|
530
|
-
key:
|
|
531
|
+
request: import_zod11.z.object({
|
|
532
|
+
runId: import_zod11.z.string(),
|
|
533
|
+
key: import_zod11.z.string(),
|
|
531
534
|
wait: WaitSchema,
|
|
532
|
-
timestamp:
|
|
535
|
+
timestamp: import_zod11.z.string()
|
|
533
536
|
}),
|
|
534
|
-
response:
|
|
537
|
+
response: import_zod11.z.boolean()
|
|
535
538
|
},
|
|
536
539
|
SEND_REQUEST: {
|
|
537
|
-
request:
|
|
538
|
-
runId:
|
|
539
|
-
key:
|
|
540
|
-
request:
|
|
541
|
-
service:
|
|
542
|
-
endpoint:
|
|
543
|
-
params:
|
|
544
|
-
version:
|
|
540
|
+
request: import_zod11.z.object({
|
|
541
|
+
runId: import_zod11.z.string(),
|
|
542
|
+
key: import_zod11.z.string(),
|
|
543
|
+
request: import_zod11.z.object({
|
|
544
|
+
service: import_zod11.z.string(),
|
|
545
|
+
endpoint: import_zod11.z.string(),
|
|
546
|
+
params: import_zod11.z.any(),
|
|
547
|
+
version: import_zod11.z.string().optional()
|
|
545
548
|
}),
|
|
546
|
-
timestamp:
|
|
549
|
+
timestamp: import_zod11.z.string()
|
|
547
550
|
}),
|
|
548
|
-
response:
|
|
551
|
+
response: import_zod11.z.boolean()
|
|
549
552
|
},
|
|
550
553
|
SEND_FETCH: {
|
|
551
|
-
request:
|
|
552
|
-
runId:
|
|
553
|
-
key:
|
|
554
|
+
request: import_zod11.z.object({
|
|
555
|
+
runId: import_zod11.z.string(),
|
|
556
|
+
key: import_zod11.z.string(),
|
|
554
557
|
fetch: FetchRequestSchema,
|
|
555
|
-
timestamp:
|
|
558
|
+
timestamp: import_zod11.z.string()
|
|
556
559
|
}),
|
|
557
|
-
response:
|
|
560
|
+
response: import_zod11.z.boolean()
|
|
558
561
|
},
|
|
559
562
|
SEND_LOG: {
|
|
560
|
-
request:
|
|
561
|
-
runId:
|
|
562
|
-
key:
|
|
563
|
-
log:
|
|
564
|
-
message:
|
|
565
|
-
level:
|
|
563
|
+
request: import_zod11.z.object({
|
|
564
|
+
runId: import_zod11.z.string(),
|
|
565
|
+
key: import_zod11.z.string(),
|
|
566
|
+
log: import_zod11.z.object({
|
|
567
|
+
message: import_zod11.z.string(),
|
|
568
|
+
level: import_zod11.z.enum([
|
|
566
569
|
"DEBUG",
|
|
567
570
|
"INFO",
|
|
568
571
|
"WARN",
|
|
569
572
|
"ERROR"
|
|
570
573
|
]),
|
|
571
|
-
properties:
|
|
574
|
+
properties: import_zod11.z.string().optional()
|
|
572
575
|
}),
|
|
573
|
-
timestamp:
|
|
576
|
+
timestamp: import_zod11.z.string()
|
|
574
577
|
}),
|
|
575
|
-
response:
|
|
578
|
+
response: import_zod11.z.boolean()
|
|
576
579
|
},
|
|
577
580
|
SEND_EVENT: {
|
|
578
|
-
request:
|
|
579
|
-
runId:
|
|
580
|
-
key:
|
|
581
|
+
request: import_zod11.z.object({
|
|
582
|
+
runId: import_zod11.z.string(),
|
|
583
|
+
key: import_zod11.z.string(),
|
|
581
584
|
event: CustomEventSchema,
|
|
582
|
-
timestamp:
|
|
585
|
+
timestamp: import_zod11.z.string()
|
|
583
586
|
}),
|
|
584
|
-
response:
|
|
587
|
+
response: import_zod11.z.boolean()
|
|
585
588
|
},
|
|
586
589
|
INITIALIZE_HOST: {
|
|
587
|
-
request:
|
|
588
|
-
apiKey:
|
|
589
|
-
workflowId:
|
|
590
|
-
workflowName:
|
|
590
|
+
request: import_zod11.z.object({
|
|
591
|
+
apiKey: import_zod11.z.string(),
|
|
592
|
+
workflowId: import_zod11.z.string(),
|
|
593
|
+
workflowName: import_zod11.z.string(),
|
|
594
|
+
trigger: TriggerMetadataSchema,
|
|
595
|
+
packageVersion: import_zod11.z.string(),
|
|
596
|
+
packageName: import_zod11.z.string(),
|
|
597
|
+
triggerTTL: import_zod11.z.number().optional()
|
|
598
|
+
}),
|
|
599
|
+
response: import_zod11.z.discriminatedUnion("type", [
|
|
600
|
+
import_zod11.z.object({
|
|
601
|
+
type: import_zod11.z.literal("success")
|
|
602
|
+
}),
|
|
603
|
+
import_zod11.z.object({
|
|
604
|
+
type: import_zod11.z.literal("error"),
|
|
605
|
+
message: import_zod11.z.string()
|
|
606
|
+
})
|
|
607
|
+
]).nullable()
|
|
608
|
+
},
|
|
609
|
+
INITIALIZE_HOST_V2: {
|
|
610
|
+
request: import_zod11.z.object({
|
|
611
|
+
apiKey: import_zod11.z.string(),
|
|
612
|
+
workflowId: import_zod11.z.string(),
|
|
613
|
+
workflowName: import_zod11.z.string(),
|
|
591
614
|
trigger: TriggerMetadataSchema,
|
|
592
|
-
packageVersion:
|
|
593
|
-
packageName:
|
|
594
|
-
triggerTTL:
|
|
615
|
+
packageVersion: import_zod11.z.string(),
|
|
616
|
+
packageName: import_zod11.z.string(),
|
|
617
|
+
triggerTTL: import_zod11.z.number().optional()
|
|
595
618
|
}),
|
|
596
|
-
response:
|
|
597
|
-
|
|
598
|
-
type:
|
|
619
|
+
response: import_zod11.z.discriminatedUnion("type", [
|
|
620
|
+
import_zod11.z.object({
|
|
621
|
+
type: import_zod11.z.literal("success"),
|
|
622
|
+
data: import_zod11.z.object({
|
|
623
|
+
workflow: import_zod11.z.object({
|
|
624
|
+
id: import_zod11.z.string(),
|
|
625
|
+
slug: import_zod11.z.string()
|
|
626
|
+
}),
|
|
627
|
+
environment: import_zod11.z.object({
|
|
628
|
+
id: import_zod11.z.string(),
|
|
629
|
+
slug: import_zod11.z.string()
|
|
630
|
+
}),
|
|
631
|
+
organization: import_zod11.z.object({
|
|
632
|
+
id: import_zod11.z.string(),
|
|
633
|
+
slug: import_zod11.z.string()
|
|
634
|
+
}),
|
|
635
|
+
isNew: import_zod11.z.boolean(),
|
|
636
|
+
url: import_zod11.z.string()
|
|
637
|
+
})
|
|
599
638
|
}),
|
|
600
|
-
|
|
601
|
-
type:
|
|
602
|
-
message:
|
|
639
|
+
import_zod11.z.object({
|
|
640
|
+
type: import_zod11.z.literal("error"),
|
|
641
|
+
message: import_zod11.z.string()
|
|
603
642
|
})
|
|
604
643
|
]).nullable()
|
|
605
644
|
},
|
|
606
645
|
START_WORKFLOW_RUN: {
|
|
607
|
-
request:
|
|
608
|
-
runId:
|
|
609
|
-
timestamp:
|
|
646
|
+
request: import_zod11.z.object({
|
|
647
|
+
runId: import_zod11.z.string(),
|
|
648
|
+
timestamp: import_zod11.z.string()
|
|
610
649
|
}),
|
|
611
|
-
response:
|
|
650
|
+
response: import_zod11.z.boolean()
|
|
612
651
|
},
|
|
613
652
|
COMPLETE_WORKFLOW_RUN: {
|
|
614
|
-
request:
|
|
615
|
-
runId:
|
|
616
|
-
output:
|
|
617
|
-
timestamp:
|
|
653
|
+
request: import_zod11.z.object({
|
|
654
|
+
runId: import_zod11.z.string(),
|
|
655
|
+
output: import_zod11.z.string().optional(),
|
|
656
|
+
timestamp: import_zod11.z.string()
|
|
618
657
|
}),
|
|
619
|
-
response:
|
|
658
|
+
response: import_zod11.z.boolean()
|
|
620
659
|
},
|
|
621
660
|
SEND_WORKFLOW_ERROR: {
|
|
622
|
-
request:
|
|
623
|
-
runId:
|
|
624
|
-
error:
|
|
625
|
-
name:
|
|
626
|
-
message:
|
|
627
|
-
stackTrace:
|
|
661
|
+
request: import_zod11.z.object({
|
|
662
|
+
runId: import_zod11.z.string(),
|
|
663
|
+
error: import_zod11.z.object({
|
|
664
|
+
name: import_zod11.z.string(),
|
|
665
|
+
message: import_zod11.z.string(),
|
|
666
|
+
stackTrace: import_zod11.z.string().optional()
|
|
628
667
|
}),
|
|
629
|
-
timestamp:
|
|
668
|
+
timestamp: import_zod11.z.string()
|
|
630
669
|
}),
|
|
631
|
-
response:
|
|
670
|
+
response: import_zod11.z.boolean()
|
|
632
671
|
},
|
|
633
672
|
INITIALIZE_RUN_ONCE: {
|
|
634
|
-
request:
|
|
635
|
-
runId:
|
|
636
|
-
key:
|
|
637
|
-
timestamp:
|
|
673
|
+
request: import_zod11.z.object({
|
|
674
|
+
runId: import_zod11.z.string(),
|
|
675
|
+
key: import_zod11.z.string(),
|
|
676
|
+
timestamp: import_zod11.z.string(),
|
|
638
677
|
runOnce: InitializeRunOnceSchema
|
|
639
678
|
}),
|
|
640
|
-
response:
|
|
679
|
+
response: import_zod11.z.boolean()
|
|
641
680
|
},
|
|
642
681
|
COMPLETE_RUN_ONCE: {
|
|
643
|
-
request:
|
|
644
|
-
runId:
|
|
645
|
-
key:
|
|
646
|
-
timestamp:
|
|
682
|
+
request: import_zod11.z.object({
|
|
683
|
+
runId: import_zod11.z.string(),
|
|
684
|
+
key: import_zod11.z.string(),
|
|
685
|
+
timestamp: import_zod11.z.string(),
|
|
647
686
|
runOnce: CompleteRunOnceSchema
|
|
648
687
|
}),
|
|
649
|
-
response:
|
|
688
|
+
response: import_zod11.z.boolean()
|
|
650
689
|
}
|
|
651
690
|
};
|
|
652
691
|
|
|
653
692
|
// ../internal-bridge/src/schemas/common.ts
|
|
654
|
-
var
|
|
655
|
-
var MESSAGE_META =
|
|
656
|
-
data:
|
|
657
|
-
id:
|
|
658
|
-
type:
|
|
659
|
-
|
|
660
|
-
|
|
693
|
+
var import_zod12 = require("zod");
|
|
694
|
+
var MESSAGE_META = import_zod12.z.object({
|
|
695
|
+
data: import_zod12.z.any(),
|
|
696
|
+
id: import_zod12.z.string(),
|
|
697
|
+
type: import_zod12.z.union([
|
|
698
|
+
import_zod12.z.literal("ACK"),
|
|
699
|
+
import_zod12.z.literal("MESSAGE")
|
|
661
700
|
])
|
|
662
701
|
});
|
|
663
|
-
var TriggerEnvironmentSchema =
|
|
702
|
+
var TriggerEnvironmentSchema = import_zod12.z.enum([
|
|
664
703
|
"live",
|
|
665
704
|
"development"
|
|
666
705
|
]);
|
|
667
706
|
|
|
668
707
|
// ../internal-bridge/src/zodRPC.ts
|
|
669
|
-
var
|
|
708
|
+
var import_zod13 = require("zod");
|
|
670
709
|
var import_node_crypto = require("crypto");
|
|
671
710
|
|
|
672
711
|
// ../internal-bridge/src/logger.ts
|
|
@@ -704,6 +743,11 @@ var Logger = class {
|
|
|
704
743
|
...__privateMethod(this, _formatTags, formatTags_fn).call(this)
|
|
705
744
|
]);
|
|
706
745
|
}
|
|
746
|
+
logClean(...args) {
|
|
747
|
+
if (__privateGet(this, _level) < 1)
|
|
748
|
+
return;
|
|
749
|
+
console.log(`${__privateMethod(this, _formatName, formatName_fn).call(this)} `, ...args);
|
|
750
|
+
}
|
|
707
751
|
error(...args) {
|
|
708
752
|
if (__privateGet(this, _level) < 2)
|
|
709
753
|
return;
|
|
@@ -767,11 +811,11 @@ function formattedDateTime() {
|
|
|
767
811
|
__name(formattedDateTime, "formattedDateTime");
|
|
768
812
|
|
|
769
813
|
// ../internal-bridge/src/zodRPC.ts
|
|
770
|
-
var RPCMessageSchema =
|
|
771
|
-
id:
|
|
772
|
-
methodName:
|
|
773
|
-
data:
|
|
774
|
-
kind:
|
|
814
|
+
var RPCMessageSchema = import_zod13.z.object({
|
|
815
|
+
id: import_zod13.z.string(),
|
|
816
|
+
methodName: import_zod13.z.string(),
|
|
817
|
+
data: import_zod13.z.any(),
|
|
818
|
+
kind: import_zod13.z.enum([
|
|
775
819
|
"CALL",
|
|
776
820
|
"RESPONSE"
|
|
777
821
|
])
|
|
@@ -851,7 +895,7 @@ onCall_fn = /* @__PURE__ */ __name(async function(message) {
|
|
|
851
895
|
try {
|
|
852
896
|
await __privateMethod(this, _handleCall, handleCall_fn).call(this, message);
|
|
853
897
|
} catch (callError) {
|
|
854
|
-
if (callError instanceof
|
|
898
|
+
if (callError instanceof import_zod13.ZodError) {
|
|
855
899
|
__privateGet(this, _logger).error(`[ZodRPC] Received invalid call:
|
|
856
900
|
${JSON.stringify(message)}: `, callError.errors);
|
|
857
901
|
} else {
|
|
@@ -865,7 +909,7 @@ onResponse_fn = /* @__PURE__ */ __name(async function(message1) {
|
|
|
865
909
|
try {
|
|
866
910
|
await __privateMethod(this, _handleResponse, handleResponse_fn).call(this, message1);
|
|
867
911
|
} catch (callError) {
|
|
868
|
-
if (callError instanceof
|
|
912
|
+
if (callError instanceof import_zod13.ZodError) {
|
|
869
913
|
__privateGet(this, _logger).error(`[ZodRPC] Received invalid response
|
|
870
914
|
|
|
871
915
|
${JSON.stringify(message1)}: `, callError.flatten());
|
|
@@ -941,11 +985,11 @@ __name(packageResponse, "packageResponse");
|
|
|
941
985
|
// src/client.ts
|
|
942
986
|
var import_uuid2 = require("uuid");
|
|
943
987
|
var import_ws = require("ws");
|
|
944
|
-
var
|
|
988
|
+
var import_zod14 = require("zod");
|
|
945
989
|
|
|
946
990
|
// package.json
|
|
947
991
|
var name = "@trigger.dev/sdk";
|
|
948
|
-
var version = "0.2.
|
|
992
|
+
var version = "0.2.16-next.0";
|
|
949
993
|
|
|
950
994
|
// src/connection.ts
|
|
951
995
|
var import_uuid = require("uuid");
|
|
@@ -1198,12 +1242,13 @@ __name(ContextLogger, "ContextLogger");
|
|
|
1198
1242
|
|
|
1199
1243
|
// src/client.ts
|
|
1200
1244
|
var import_zod_error = require("zod-error");
|
|
1245
|
+
var import_terminal_link = __toESM(require("terminal-link"));
|
|
1201
1246
|
var zodErrorMessageOptions = {
|
|
1202
1247
|
delimiter: {
|
|
1203
1248
|
error: " \u{1F525} "
|
|
1204
1249
|
}
|
|
1205
1250
|
};
|
|
1206
|
-
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;
|
|
1251
|
+
var _trigger, _options, _connection2, _serverRPC, _apiKey, _endpoint, _isConnected, _retryIntervalMs, _logger3, _closedByUser, _registerResponse, _responseCompleteCallbacks, _waitForCallbacks, _fetchCallbacks, _runOnceCallbacks, _initializeConnection, initializeConnection_fn, _initializeRPC, initializeRPC_fn, _initializeHost, initializeHost_fn, _send, send_fn;
|
|
1207
1252
|
var TriggerClient = class {
|
|
1208
1253
|
constructor(trigger, options) {
|
|
1209
1254
|
__privateAdd(this, _initializeConnection);
|
|
@@ -1220,6 +1265,7 @@ var TriggerClient = class {
|
|
|
1220
1265
|
__privateAdd(this, _retryIntervalMs, 3e3);
|
|
1221
1266
|
__privateAdd(this, _logger3, void 0);
|
|
1222
1267
|
__privateAdd(this, _closedByUser, false);
|
|
1268
|
+
__privateAdd(this, _registerResponse, void 0);
|
|
1223
1269
|
__privateAdd(this, _responseCompleteCallbacks, /* @__PURE__ */ new Map());
|
|
1224
1270
|
__privateAdd(this, _waitForCallbacks, /* @__PURE__ */ new Map());
|
|
1225
1271
|
__privateAdd(this, _fetchCallbacks, /* @__PURE__ */ new Map());
|
|
@@ -1242,7 +1288,15 @@ var TriggerClient = class {
|
|
|
1242
1288
|
await __privateMethod(this, _initializeConnection, initializeConnection_fn).call(this, instanceId);
|
|
1243
1289
|
__privateMethod(this, _initializeRPC, initializeRPC_fn).call(this);
|
|
1244
1290
|
await __privateMethod(this, _initializeHost, initializeHost_fn).call(this);
|
|
1245
|
-
__privateGet(this,
|
|
1291
|
+
if (__privateGet(this, _registerResponse)?.isNew) {
|
|
1292
|
+
__privateGet(this, _logger3).logClean(`\u{1F389} Successfully registered "${__privateGet(this, _trigger).name}" to trigger.dev \u{1F449} ${(0, import_terminal_link.default)("View on dashboard", __privateGet(this, _registerResponse).url, {
|
|
1293
|
+
fallback: (text, url) => `${text}: (${url})`
|
|
1294
|
+
})}. Listening for events...`);
|
|
1295
|
+
} else {
|
|
1296
|
+
__privateGet(this, _logger3).log(`\u2728 Connected and listening for events \u{1F449} ${(0, import_terminal_link.default)("View on dashboard", __privateGet(this, _registerResponse).url, {
|
|
1297
|
+
fallback: (text, url) => `${text}: (${url})`
|
|
1298
|
+
})}`);
|
|
1299
|
+
}
|
|
1246
1300
|
} catch (error) {
|
|
1247
1301
|
__privateGet(this, _logger3).log(`\u{1F6A9} Could not connect to trigger.dev`);
|
|
1248
1302
|
this.close();
|
|
@@ -1268,6 +1322,7 @@ _isConnected = new WeakMap();
|
|
|
1268
1322
|
_retryIntervalMs = new WeakMap();
|
|
1269
1323
|
_logger3 = new WeakMap();
|
|
1270
1324
|
_closedByUser = new WeakMap();
|
|
1325
|
+
_registerResponse = new WeakMap();
|
|
1271
1326
|
_responseCompleteCallbacks = new WeakMap();
|
|
1272
1327
|
_waitForCallbacks = new WeakMap();
|
|
1273
1328
|
_fetchCallbacks = new WeakMap();
|
|
@@ -1434,7 +1489,7 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1434
1489
|
status: response.status,
|
|
1435
1490
|
ok: response.ok,
|
|
1436
1491
|
headers: response.headers,
|
|
1437
|
-
body: response.body ? (options.responseSchema ??
|
|
1492
|
+
body: response.body ? (options.responseSchema ?? import_zod14.z.any()).parse(response.body) : void 0
|
|
1438
1493
|
};
|
|
1439
1494
|
}, "fetchFunction");
|
|
1440
1495
|
const ctx = {
|
|
@@ -1602,7 +1657,9 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1602
1657
|
timestamp: String(highPrecisionTimestamp())
|
|
1603
1658
|
}).then(() => {
|
|
1604
1659
|
return __privateGet(this, _trigger).options.run(eventData, ctx).then((output) => {
|
|
1605
|
-
__privateGet(this, _logger3).log(`Run ${data.id} complete \u{
|
|
1660
|
+
__privateGet(this, _logger3).log(`Run ${data.id} complete \u{1F449} ${(0, import_terminal_link.default)("View on dashboard", `${__privateGet(this, _registerResponse).url}/runs/${data.id}`, {
|
|
1661
|
+
fallback: (text, url) => `${text}: (${url})`
|
|
1662
|
+
})}`);
|
|
1606
1663
|
return serverRPC.send("COMPLETE_WORKFLOW_RUN", {
|
|
1607
1664
|
runId: data.id,
|
|
1608
1665
|
output: JSON.stringify(output),
|
|
@@ -1617,9 +1674,9 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1617
1674
|
stackTrace: error2.stack
|
|
1618
1675
|
};
|
|
1619
1676
|
}
|
|
1620
|
-
const parsedError =
|
|
1621
|
-
name:
|
|
1622
|
-
message:
|
|
1677
|
+
const parsedError = import_zod14.z.object({
|
|
1678
|
+
name: import_zod14.z.string(),
|
|
1679
|
+
message: import_zod14.z.string()
|
|
1623
1680
|
}).passthrough().safeParse(error2);
|
|
1624
1681
|
if (parsedError.success) {
|
|
1625
1682
|
return parsedError.data;
|
|
@@ -1659,7 +1716,7 @@ initializeHost_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1659
1716
|
if (!__privateGet(this, _serverRPC)) {
|
|
1660
1717
|
throw new Error("Cannot initialize host without an RPC connection");
|
|
1661
1718
|
}
|
|
1662
|
-
const response = await __privateMethod(this, _send, send_fn).call(this, "
|
|
1719
|
+
const response = await __privateMethod(this, _send, send_fn).call(this, "INITIALIZE_HOST_V2", {
|
|
1663
1720
|
apiKey: __privateGet(this, _apiKey),
|
|
1664
1721
|
workflowId: __privateGet(this, _trigger).id,
|
|
1665
1722
|
workflowName: __privateGet(this, _trigger).name,
|
|
@@ -1668,9 +1725,13 @@ initializeHost_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1668
1725
|
packageName: name,
|
|
1669
1726
|
triggerTTL: __privateGet(this, _options).triggerTTL
|
|
1670
1727
|
});
|
|
1728
|
+
if (!response) {
|
|
1729
|
+
throw new Error("Could not initialize workflow with server");
|
|
1730
|
+
}
|
|
1671
1731
|
if (response?.type === "error") {
|
|
1672
1732
|
throw new Error(response.message);
|
|
1673
1733
|
}
|
|
1734
|
+
__privateSet(this, _registerResponse, response.data);
|
|
1674
1735
|
__privateGet(this, _logger3).debug("Successfully initialized workflow with server");
|
|
1675
1736
|
}, "#initializeHost");
|
|
1676
1737
|
_send = new WeakSet();
|
|
@@ -1731,20 +1792,18 @@ _client = new WeakMap();
|
|
|
1731
1792
|
|
|
1732
1793
|
// src/customEvents.ts
|
|
1733
1794
|
var import_node_fetch = __toESM(require("node-fetch"));
|
|
1734
|
-
|
|
1735
|
-
function sendEvent(id, event) {
|
|
1795
|
+
function sendEvent(idOrKey, event) {
|
|
1736
1796
|
const triggerRun = triggerRunLocalStorage.getStore();
|
|
1737
1797
|
if (!triggerRun) {
|
|
1738
|
-
return sendEventFetch(event);
|
|
1798
|
+
return sendEventFetch(idOrKey, event);
|
|
1739
1799
|
}
|
|
1740
|
-
return triggerRun.sendEvent(
|
|
1800
|
+
return triggerRun.sendEvent(idOrKey, event);
|
|
1741
1801
|
}
|
|
1742
1802
|
__name(sendEvent, "sendEvent");
|
|
1743
|
-
async function sendEventFetch(event) {
|
|
1803
|
+
async function sendEventFetch(id, event) {
|
|
1744
1804
|
if (!process.env.TRIGGER_API_KEY) {
|
|
1745
1805
|
throw new Error(`There was a problem sending a custom event: the TRIGGER_API_KEY environment variable is not set`);
|
|
1746
1806
|
}
|
|
1747
|
-
const id = (0, import_ulid.ulid)();
|
|
1748
1807
|
const baseUrl = process.env.TRIGGER_API_URL || "https://app.trigger.dev";
|
|
1749
1808
|
const url = `${baseUrl}/api/v1/events`;
|
|
1750
1809
|
const response = await (0, import_node_fetch.default)(url, {
|