@trigger.dev/sdk 0.2.21 → 0.2.22-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 +8 -0
- package/dist/index.js +465 -218
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -348,12 +348,28 @@ var ResolveRunOnceOuputSchema = import_zod8.z.object({
|
|
|
348
348
|
output: SerializableJsonSchema.optional()
|
|
349
349
|
});
|
|
350
350
|
|
|
351
|
-
// src/
|
|
351
|
+
// ../common-schemas/src/kv.ts
|
|
352
352
|
var import_zod9 = require("zod");
|
|
353
|
+
var KVGetSchema = import_zod9.z.object({
|
|
354
|
+
key: import_zod9.z.string(),
|
|
355
|
+
namespace: import_zod9.z.string()
|
|
356
|
+
});
|
|
357
|
+
var KVDeleteSchema = import_zod9.z.object({
|
|
358
|
+
key: import_zod9.z.string(),
|
|
359
|
+
namespace: import_zod9.z.string()
|
|
360
|
+
});
|
|
361
|
+
var KVSetSchema = import_zod9.z.object({
|
|
362
|
+
key: import_zod9.z.string(),
|
|
363
|
+
namespace: import_zod9.z.string(),
|
|
364
|
+
value: SerializableJsonSchema
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// src/events.ts
|
|
368
|
+
var import_zod10 = require("zod");
|
|
353
369
|
var import_slug = __toESM(require("slug"));
|
|
354
370
|
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
|
355
371
|
function customEvent(options) {
|
|
356
|
-
const schema = options.schema ??
|
|
372
|
+
const schema = options.schema ?? import_zod10.z.any();
|
|
357
373
|
return {
|
|
358
374
|
metadata: {
|
|
359
375
|
type: "CUSTOM_EVENT",
|
|
@@ -384,7 +400,7 @@ function scheduleEvent(options) {
|
|
|
384
400
|
}
|
|
385
401
|
__name(scheduleEvent, "scheduleEvent");
|
|
386
402
|
function webhookEvent(options) {
|
|
387
|
-
const schema = options.schema ??
|
|
403
|
+
const schema = options.schema ?? import_zod10.z.any();
|
|
388
404
|
return {
|
|
389
405
|
metadata: {
|
|
390
406
|
type: "WEBHOOK",
|
|
@@ -414,301 +430,378 @@ function webhookEvent(options) {
|
|
|
414
430
|
__name(webhookEvent, "webhookEvent");
|
|
415
431
|
|
|
416
432
|
// ../internal-bridge/src/schemas/host.ts
|
|
417
|
-
var
|
|
433
|
+
var import_zod11 = require("zod");
|
|
418
434
|
var HostRPCSchema = {
|
|
419
435
|
TRIGGER_WORKFLOW: {
|
|
420
|
-
request:
|
|
421
|
-
id:
|
|
422
|
-
trigger:
|
|
436
|
+
request: import_zod11.z.object({
|
|
437
|
+
id: import_zod11.z.string(),
|
|
438
|
+
trigger: import_zod11.z.object({
|
|
423
439
|
input: JsonSchema.default({}),
|
|
424
440
|
context: JsonSchema.default({})
|
|
425
441
|
}),
|
|
426
|
-
meta:
|
|
427
|
-
environment:
|
|
428
|
-
workflowId:
|
|
429
|
-
organizationId:
|
|
430
|
-
apiKey:
|
|
431
|
-
isTest:
|
|
432
|
-
appOrigin:
|
|
433
|
-
attempt:
|
|
442
|
+
meta: import_zod11.z.object({
|
|
443
|
+
environment: import_zod11.z.string(),
|
|
444
|
+
workflowId: import_zod11.z.string(),
|
|
445
|
+
organizationId: import_zod11.z.string(),
|
|
446
|
+
apiKey: import_zod11.z.string(),
|
|
447
|
+
isTest: import_zod11.z.boolean().default(false),
|
|
448
|
+
appOrigin: import_zod11.z.string(),
|
|
449
|
+
attempt: import_zod11.z.number().optional()
|
|
434
450
|
})
|
|
435
451
|
}),
|
|
436
|
-
response:
|
|
452
|
+
response: import_zod11.z.boolean()
|
|
437
453
|
},
|
|
438
454
|
RESOLVE_REQUEST: {
|
|
439
|
-
request:
|
|
440
|
-
id:
|
|
441
|
-
key:
|
|
455
|
+
request: import_zod11.z.object({
|
|
456
|
+
id: import_zod11.z.string(),
|
|
457
|
+
key: import_zod11.z.string(),
|
|
442
458
|
output: JsonSchema.default({}),
|
|
443
|
-
meta:
|
|
444
|
-
environment:
|
|
445
|
-
workflowId:
|
|
446
|
-
organizationId:
|
|
447
|
-
apiKey:
|
|
448
|
-
runId:
|
|
459
|
+
meta: import_zod11.z.object({
|
|
460
|
+
environment: import_zod11.z.string(),
|
|
461
|
+
workflowId: import_zod11.z.string(),
|
|
462
|
+
organizationId: import_zod11.z.string(),
|
|
463
|
+
apiKey: import_zod11.z.string(),
|
|
464
|
+
runId: import_zod11.z.string()
|
|
449
465
|
})
|
|
450
466
|
}),
|
|
451
|
-
response:
|
|
467
|
+
response: import_zod11.z.boolean()
|
|
452
468
|
},
|
|
453
469
|
RESOLVE_DELAY: {
|
|
454
|
-
request:
|
|
455
|
-
id:
|
|
456
|
-
key:
|
|
457
|
-
meta:
|
|
458
|
-
environment:
|
|
459
|
-
workflowId:
|
|
460
|
-
organizationId:
|
|
461
|
-
apiKey:
|
|
462
|
-
runId:
|
|
470
|
+
request: import_zod11.z.object({
|
|
471
|
+
id: import_zod11.z.string(),
|
|
472
|
+
key: import_zod11.z.string(),
|
|
473
|
+
meta: import_zod11.z.object({
|
|
474
|
+
environment: import_zod11.z.string(),
|
|
475
|
+
workflowId: import_zod11.z.string(),
|
|
476
|
+
organizationId: import_zod11.z.string(),
|
|
477
|
+
apiKey: import_zod11.z.string(),
|
|
478
|
+
runId: import_zod11.z.string()
|
|
463
479
|
})
|
|
464
480
|
}),
|
|
465
|
-
response:
|
|
481
|
+
response: import_zod11.z.boolean()
|
|
466
482
|
},
|
|
467
483
|
REJECT_REQUEST: {
|
|
468
|
-
request:
|
|
469
|
-
id:
|
|
470
|
-
key:
|
|
484
|
+
request: import_zod11.z.object({
|
|
485
|
+
id: import_zod11.z.string(),
|
|
486
|
+
key: import_zod11.z.string(),
|
|
471
487
|
error: JsonSchema.default({}),
|
|
472
|
-
meta:
|
|
473
|
-
environment:
|
|
474
|
-
workflowId:
|
|
475
|
-
organizationId:
|
|
476
|
-
apiKey:
|
|
477
|
-
runId:
|
|
488
|
+
meta: import_zod11.z.object({
|
|
489
|
+
environment: import_zod11.z.string(),
|
|
490
|
+
workflowId: import_zod11.z.string(),
|
|
491
|
+
organizationId: import_zod11.z.string(),
|
|
492
|
+
apiKey: import_zod11.z.string(),
|
|
493
|
+
runId: import_zod11.z.string()
|
|
478
494
|
})
|
|
479
495
|
}),
|
|
480
|
-
response:
|
|
496
|
+
response: import_zod11.z.boolean()
|
|
481
497
|
},
|
|
482
498
|
RESOLVE_FETCH_REQUEST: {
|
|
483
|
-
request:
|
|
484
|
-
id:
|
|
485
|
-
key:
|
|
499
|
+
request: import_zod11.z.object({
|
|
500
|
+
id: import_zod11.z.string(),
|
|
501
|
+
key: import_zod11.z.string(),
|
|
486
502
|
output: FetchOutputSchema,
|
|
487
|
-
meta:
|
|
488
|
-
environment:
|
|
489
|
-
workflowId:
|
|
490
|
-
organizationId:
|
|
491
|
-
apiKey:
|
|
492
|
-
runId:
|
|
503
|
+
meta: import_zod11.z.object({
|
|
504
|
+
environment: import_zod11.z.string(),
|
|
505
|
+
workflowId: import_zod11.z.string(),
|
|
506
|
+
organizationId: import_zod11.z.string(),
|
|
507
|
+
apiKey: import_zod11.z.string(),
|
|
508
|
+
runId: import_zod11.z.string()
|
|
493
509
|
})
|
|
494
510
|
}),
|
|
495
|
-
response:
|
|
511
|
+
response: import_zod11.z.boolean()
|
|
496
512
|
},
|
|
497
513
|
REJECT_FETCH_REQUEST: {
|
|
498
|
-
request:
|
|
499
|
-
id:
|
|
500
|
-
key:
|
|
514
|
+
request: import_zod11.z.object({
|
|
515
|
+
id: import_zod11.z.string(),
|
|
516
|
+
key: import_zod11.z.string(),
|
|
501
517
|
error: JsonSchema.default({}),
|
|
502
|
-
meta:
|
|
503
|
-
environment:
|
|
504
|
-
workflowId:
|
|
505
|
-
organizationId:
|
|
506
|
-
apiKey:
|
|
507
|
-
runId:
|
|
518
|
+
meta: import_zod11.z.object({
|
|
519
|
+
environment: import_zod11.z.string(),
|
|
520
|
+
workflowId: import_zod11.z.string(),
|
|
521
|
+
organizationId: import_zod11.z.string(),
|
|
522
|
+
apiKey: import_zod11.z.string(),
|
|
523
|
+
runId: import_zod11.z.string()
|
|
508
524
|
})
|
|
509
525
|
}),
|
|
510
|
-
response:
|
|
526
|
+
response: import_zod11.z.boolean()
|
|
511
527
|
},
|
|
512
528
|
RESOLVE_RUN_ONCE: {
|
|
513
|
-
request:
|
|
514
|
-
id:
|
|
515
|
-
key:
|
|
529
|
+
request: import_zod11.z.object({
|
|
530
|
+
id: import_zod11.z.string(),
|
|
531
|
+
key: import_zod11.z.string(),
|
|
516
532
|
output: ResolveRunOnceOuputSchema,
|
|
517
|
-
meta:
|
|
518
|
-
environment:
|
|
519
|
-
workflowId:
|
|
520
|
-
organizationId:
|
|
521
|
-
apiKey:
|
|
522
|
-
runId:
|
|
533
|
+
meta: import_zod11.z.object({
|
|
534
|
+
environment: import_zod11.z.string(),
|
|
535
|
+
workflowId: import_zod11.z.string(),
|
|
536
|
+
organizationId: import_zod11.z.string(),
|
|
537
|
+
apiKey: import_zod11.z.string(),
|
|
538
|
+
runId: import_zod11.z.string()
|
|
539
|
+
})
|
|
540
|
+
}),
|
|
541
|
+
response: import_zod11.z.boolean()
|
|
542
|
+
},
|
|
543
|
+
RESOLVE_KV_GET: {
|
|
544
|
+
request: import_zod11.z.object({
|
|
545
|
+
key: import_zod11.z.string(),
|
|
546
|
+
output: SerializableJsonSchema,
|
|
547
|
+
meta: import_zod11.z.object({
|
|
548
|
+
environment: import_zod11.z.string(),
|
|
549
|
+
workflowId: import_zod11.z.string(),
|
|
550
|
+
organizationId: import_zod11.z.string(),
|
|
551
|
+
apiKey: import_zod11.z.string(),
|
|
552
|
+
runId: import_zod11.z.string()
|
|
553
|
+
})
|
|
554
|
+
}),
|
|
555
|
+
response: import_zod11.z.boolean()
|
|
556
|
+
},
|
|
557
|
+
RESOLVE_KV_SET: {
|
|
558
|
+
request: import_zod11.z.object({
|
|
559
|
+
key: import_zod11.z.string(),
|
|
560
|
+
meta: import_zod11.z.object({
|
|
561
|
+
environment: import_zod11.z.string(),
|
|
562
|
+
workflowId: import_zod11.z.string(),
|
|
563
|
+
organizationId: import_zod11.z.string(),
|
|
564
|
+
apiKey: import_zod11.z.string(),
|
|
565
|
+
runId: import_zod11.z.string()
|
|
523
566
|
})
|
|
524
567
|
}),
|
|
525
|
-
response:
|
|
568
|
+
response: import_zod11.z.boolean()
|
|
569
|
+
},
|
|
570
|
+
RESOLVE_KV_DELETE: {
|
|
571
|
+
request: import_zod11.z.object({
|
|
572
|
+
key: import_zod11.z.string(),
|
|
573
|
+
meta: import_zod11.z.object({
|
|
574
|
+
environment: import_zod11.z.string(),
|
|
575
|
+
workflowId: import_zod11.z.string(),
|
|
576
|
+
organizationId: import_zod11.z.string(),
|
|
577
|
+
apiKey: import_zod11.z.string(),
|
|
578
|
+
runId: import_zod11.z.string()
|
|
579
|
+
})
|
|
580
|
+
}),
|
|
581
|
+
response: import_zod11.z.boolean()
|
|
526
582
|
}
|
|
527
583
|
};
|
|
528
584
|
|
|
529
585
|
// ../internal-bridge/src/schemas/server.ts
|
|
530
|
-
var
|
|
586
|
+
var import_zod12 = require("zod");
|
|
531
587
|
var ServerRPCSchema = {
|
|
532
588
|
INITIALIZE_DELAY: {
|
|
533
|
-
request:
|
|
534
|
-
runId:
|
|
535
|
-
key:
|
|
589
|
+
request: import_zod12.z.object({
|
|
590
|
+
runId: import_zod12.z.string(),
|
|
591
|
+
key: import_zod12.z.string(),
|
|
536
592
|
wait: WaitSchema,
|
|
537
|
-
timestamp:
|
|
593
|
+
timestamp: import_zod12.z.string()
|
|
538
594
|
}),
|
|
539
|
-
response:
|
|
595
|
+
response: import_zod12.z.boolean()
|
|
540
596
|
},
|
|
541
597
|
SEND_REQUEST: {
|
|
542
|
-
request:
|
|
543
|
-
runId:
|
|
544
|
-
key:
|
|
545
|
-
request:
|
|
546
|
-
service:
|
|
547
|
-
endpoint:
|
|
548
|
-
params:
|
|
549
|
-
version:
|
|
598
|
+
request: import_zod12.z.object({
|
|
599
|
+
runId: import_zod12.z.string(),
|
|
600
|
+
key: import_zod12.z.string(),
|
|
601
|
+
request: import_zod12.z.object({
|
|
602
|
+
service: import_zod12.z.string(),
|
|
603
|
+
endpoint: import_zod12.z.string(),
|
|
604
|
+
params: import_zod12.z.any(),
|
|
605
|
+
version: import_zod12.z.string().optional()
|
|
550
606
|
}),
|
|
551
|
-
timestamp:
|
|
607
|
+
timestamp: import_zod12.z.string()
|
|
552
608
|
}),
|
|
553
|
-
response:
|
|
609
|
+
response: import_zod12.z.boolean()
|
|
554
610
|
},
|
|
555
611
|
SEND_FETCH: {
|
|
556
|
-
request:
|
|
557
|
-
runId:
|
|
558
|
-
key:
|
|
612
|
+
request: import_zod12.z.object({
|
|
613
|
+
runId: import_zod12.z.string(),
|
|
614
|
+
key: import_zod12.z.string(),
|
|
559
615
|
fetch: FetchRequestSchema,
|
|
560
|
-
timestamp:
|
|
616
|
+
timestamp: import_zod12.z.string()
|
|
561
617
|
}),
|
|
562
|
-
response:
|
|
618
|
+
response: import_zod12.z.boolean()
|
|
563
619
|
},
|
|
564
620
|
SEND_LOG: {
|
|
565
|
-
request:
|
|
566
|
-
runId:
|
|
567
|
-
key:
|
|
568
|
-
log:
|
|
569
|
-
message:
|
|
570
|
-
level:
|
|
621
|
+
request: import_zod12.z.object({
|
|
622
|
+
runId: import_zod12.z.string(),
|
|
623
|
+
key: import_zod12.z.string(),
|
|
624
|
+
log: import_zod12.z.object({
|
|
625
|
+
message: import_zod12.z.string(),
|
|
626
|
+
level: import_zod12.z.enum([
|
|
571
627
|
"DEBUG",
|
|
572
628
|
"INFO",
|
|
573
629
|
"WARN",
|
|
574
630
|
"ERROR"
|
|
575
631
|
]),
|
|
576
|
-
properties:
|
|
632
|
+
properties: import_zod12.z.string().optional()
|
|
577
633
|
}),
|
|
578
|
-
timestamp:
|
|
634
|
+
timestamp: import_zod12.z.string()
|
|
579
635
|
}),
|
|
580
|
-
response:
|
|
636
|
+
response: import_zod12.z.boolean()
|
|
581
637
|
},
|
|
582
638
|
SEND_EVENT: {
|
|
583
|
-
request:
|
|
584
|
-
runId:
|
|
585
|
-
key:
|
|
639
|
+
request: import_zod12.z.object({
|
|
640
|
+
runId: import_zod12.z.string(),
|
|
641
|
+
key: import_zod12.z.string(),
|
|
586
642
|
event: CustomEventSchema,
|
|
587
|
-
timestamp:
|
|
643
|
+
timestamp: import_zod12.z.string()
|
|
588
644
|
}),
|
|
589
|
-
response:
|
|
645
|
+
response: import_zod12.z.boolean()
|
|
590
646
|
},
|
|
591
647
|
INITIALIZE_HOST: {
|
|
592
|
-
request:
|
|
593
|
-
apiKey:
|
|
594
|
-
workflowId:
|
|
595
|
-
workflowName:
|
|
648
|
+
request: import_zod12.z.object({
|
|
649
|
+
apiKey: import_zod12.z.string(),
|
|
650
|
+
workflowId: import_zod12.z.string(),
|
|
651
|
+
workflowName: import_zod12.z.string(),
|
|
596
652
|
trigger: TriggerMetadataSchema,
|
|
597
|
-
packageVersion:
|
|
598
|
-
packageName:
|
|
599
|
-
triggerTTL:
|
|
653
|
+
packageVersion: import_zod12.z.string(),
|
|
654
|
+
packageName: import_zod12.z.string(),
|
|
655
|
+
triggerTTL: import_zod12.z.number().optional()
|
|
600
656
|
}),
|
|
601
|
-
response:
|
|
602
|
-
|
|
603
|
-
type:
|
|
657
|
+
response: import_zod12.z.discriminatedUnion("type", [
|
|
658
|
+
import_zod12.z.object({
|
|
659
|
+
type: import_zod12.z.literal("success")
|
|
604
660
|
}),
|
|
605
|
-
|
|
606
|
-
type:
|
|
607
|
-
message:
|
|
661
|
+
import_zod12.z.object({
|
|
662
|
+
type: import_zod12.z.literal("error"),
|
|
663
|
+
message: import_zod12.z.string()
|
|
608
664
|
})
|
|
609
665
|
]).nullable()
|
|
610
666
|
},
|
|
611
667
|
INITIALIZE_HOST_V2: {
|
|
612
|
-
request:
|
|
613
|
-
apiKey:
|
|
614
|
-
workflowId:
|
|
615
|
-
workflowName:
|
|
668
|
+
request: import_zod12.z.object({
|
|
669
|
+
apiKey: import_zod12.z.string(),
|
|
670
|
+
workflowId: import_zod12.z.string(),
|
|
671
|
+
workflowName: import_zod12.z.string(),
|
|
616
672
|
trigger: TriggerMetadataSchema,
|
|
617
|
-
packageVersion:
|
|
618
|
-
packageName:
|
|
619
|
-
triggerTTL:
|
|
673
|
+
packageVersion: import_zod12.z.string(),
|
|
674
|
+
packageName: import_zod12.z.string(),
|
|
675
|
+
triggerTTL: import_zod12.z.number().optional(),
|
|
620
676
|
metadata: SerializableJsonSchema.optional()
|
|
621
677
|
}),
|
|
622
|
-
response:
|
|
623
|
-
|
|
624
|
-
type:
|
|
625
|
-
data:
|
|
626
|
-
workflow:
|
|
627
|
-
id:
|
|
628
|
-
slug:
|
|
678
|
+
response: import_zod12.z.discriminatedUnion("type", [
|
|
679
|
+
import_zod12.z.object({
|
|
680
|
+
type: import_zod12.z.literal("success"),
|
|
681
|
+
data: import_zod12.z.object({
|
|
682
|
+
workflow: import_zod12.z.object({
|
|
683
|
+
id: import_zod12.z.string(),
|
|
684
|
+
slug: import_zod12.z.string()
|
|
629
685
|
}),
|
|
630
|
-
environment:
|
|
631
|
-
id:
|
|
632
|
-
slug:
|
|
686
|
+
environment: import_zod12.z.object({
|
|
687
|
+
id: import_zod12.z.string(),
|
|
688
|
+
slug: import_zod12.z.string()
|
|
633
689
|
}),
|
|
634
|
-
organization:
|
|
635
|
-
id:
|
|
636
|
-
slug:
|
|
690
|
+
organization: import_zod12.z.object({
|
|
691
|
+
id: import_zod12.z.string(),
|
|
692
|
+
slug: import_zod12.z.string()
|
|
637
693
|
}),
|
|
638
|
-
isNew:
|
|
639
|
-
url:
|
|
694
|
+
isNew: import_zod12.z.boolean(),
|
|
695
|
+
url: import_zod12.z.string()
|
|
640
696
|
})
|
|
641
697
|
}),
|
|
642
|
-
|
|
643
|
-
type:
|
|
644
|
-
message:
|
|
698
|
+
import_zod12.z.object({
|
|
699
|
+
type: import_zod12.z.literal("error"),
|
|
700
|
+
message: import_zod12.z.string()
|
|
645
701
|
})
|
|
646
702
|
]).nullable()
|
|
647
703
|
},
|
|
648
704
|
START_WORKFLOW_RUN: {
|
|
649
|
-
request:
|
|
650
|
-
runId:
|
|
651
|
-
timestamp:
|
|
705
|
+
request: import_zod12.z.object({
|
|
706
|
+
runId: import_zod12.z.string(),
|
|
707
|
+
timestamp: import_zod12.z.string()
|
|
652
708
|
}),
|
|
653
|
-
response:
|
|
709
|
+
response: import_zod12.z.boolean()
|
|
654
710
|
},
|
|
655
711
|
COMPLETE_WORKFLOW_RUN: {
|
|
656
|
-
request:
|
|
657
|
-
runId:
|
|
658
|
-
output:
|
|
659
|
-
timestamp:
|
|
712
|
+
request: import_zod12.z.object({
|
|
713
|
+
runId: import_zod12.z.string(),
|
|
714
|
+
output: import_zod12.z.string().optional(),
|
|
715
|
+
timestamp: import_zod12.z.string()
|
|
660
716
|
}),
|
|
661
|
-
response:
|
|
717
|
+
response: import_zod12.z.boolean()
|
|
662
718
|
},
|
|
663
719
|
SEND_WORKFLOW_ERROR: {
|
|
664
|
-
request:
|
|
665
|
-
runId:
|
|
666
|
-
error:
|
|
667
|
-
name:
|
|
668
|
-
message:
|
|
669
|
-
stackTrace:
|
|
720
|
+
request: import_zod12.z.object({
|
|
721
|
+
runId: import_zod12.z.string(),
|
|
722
|
+
error: import_zod12.z.object({
|
|
723
|
+
name: import_zod12.z.string(),
|
|
724
|
+
message: import_zod12.z.string(),
|
|
725
|
+
stackTrace: import_zod12.z.string().optional()
|
|
670
726
|
}),
|
|
671
|
-
timestamp:
|
|
727
|
+
timestamp: import_zod12.z.string()
|
|
672
728
|
}),
|
|
673
|
-
response:
|
|
729
|
+
response: import_zod12.z.boolean()
|
|
674
730
|
},
|
|
675
731
|
INITIALIZE_RUN_ONCE: {
|
|
676
|
-
request:
|
|
677
|
-
runId:
|
|
678
|
-
key:
|
|
679
|
-
timestamp:
|
|
732
|
+
request: import_zod12.z.object({
|
|
733
|
+
runId: import_zod12.z.string(),
|
|
734
|
+
key: import_zod12.z.string(),
|
|
735
|
+
timestamp: import_zod12.z.string(),
|
|
680
736
|
runOnce: InitializeRunOnceSchema
|
|
681
737
|
}),
|
|
682
|
-
response:
|
|
738
|
+
response: import_zod12.z.boolean()
|
|
683
739
|
},
|
|
684
740
|
COMPLETE_RUN_ONCE: {
|
|
685
|
-
request:
|
|
686
|
-
runId:
|
|
687
|
-
key:
|
|
688
|
-
timestamp:
|
|
741
|
+
request: import_zod12.z.object({
|
|
742
|
+
runId: import_zod12.z.string(),
|
|
743
|
+
key: import_zod12.z.string(),
|
|
744
|
+
timestamp: import_zod12.z.string(),
|
|
689
745
|
runOnce: CompleteRunOnceSchema
|
|
690
746
|
}),
|
|
691
|
-
response:
|
|
747
|
+
response: import_zod12.z.boolean()
|
|
748
|
+
},
|
|
749
|
+
SEND_KV_GET: {
|
|
750
|
+
request: import_zod12.z.object({
|
|
751
|
+
runId: import_zod12.z.string(),
|
|
752
|
+
key: import_zod12.z.string(),
|
|
753
|
+
timestamp: import_zod12.z.string(),
|
|
754
|
+
get: import_zod12.z.object({
|
|
755
|
+
namespace: import_zod12.z.string(),
|
|
756
|
+
key: import_zod12.z.string()
|
|
757
|
+
})
|
|
758
|
+
}),
|
|
759
|
+
response: import_zod12.z.boolean()
|
|
760
|
+
},
|
|
761
|
+
SEND_KV_SET: {
|
|
762
|
+
request: import_zod12.z.object({
|
|
763
|
+
runId: import_zod12.z.string(),
|
|
764
|
+
key: import_zod12.z.string(),
|
|
765
|
+
timestamp: import_zod12.z.string(),
|
|
766
|
+
set: import_zod12.z.object({
|
|
767
|
+
namespace: import_zod12.z.string(),
|
|
768
|
+
key: import_zod12.z.string(),
|
|
769
|
+
value: SerializableJsonSchema
|
|
770
|
+
})
|
|
771
|
+
}),
|
|
772
|
+
response: import_zod12.z.boolean()
|
|
773
|
+
},
|
|
774
|
+
SEND_KV_DELETE: {
|
|
775
|
+
request: import_zod12.z.object({
|
|
776
|
+
runId: import_zod12.z.string(),
|
|
777
|
+
key: import_zod12.z.string(),
|
|
778
|
+
timestamp: import_zod12.z.string(),
|
|
779
|
+
delete: import_zod12.z.object({
|
|
780
|
+
namespace: import_zod12.z.string(),
|
|
781
|
+
key: import_zod12.z.string()
|
|
782
|
+
})
|
|
783
|
+
}),
|
|
784
|
+
response: import_zod12.z.boolean()
|
|
692
785
|
}
|
|
693
786
|
};
|
|
694
787
|
|
|
695
788
|
// ../internal-bridge/src/schemas/common.ts
|
|
696
|
-
var
|
|
697
|
-
var MESSAGE_META =
|
|
698
|
-
data:
|
|
699
|
-
id:
|
|
700
|
-
type:
|
|
701
|
-
|
|
702
|
-
|
|
789
|
+
var import_zod13 = require("zod");
|
|
790
|
+
var MESSAGE_META = import_zod13.z.object({
|
|
791
|
+
data: import_zod13.z.any(),
|
|
792
|
+
id: import_zod13.z.string(),
|
|
793
|
+
type: import_zod13.z.union([
|
|
794
|
+
import_zod13.z.literal("ACK"),
|
|
795
|
+
import_zod13.z.literal("MESSAGE")
|
|
703
796
|
])
|
|
704
797
|
});
|
|
705
|
-
var TriggerEnvironmentSchema =
|
|
798
|
+
var TriggerEnvironmentSchema = import_zod13.z.enum([
|
|
706
799
|
"live",
|
|
707
800
|
"development"
|
|
708
801
|
]);
|
|
709
802
|
|
|
710
803
|
// ../internal-bridge/src/zodRPC.ts
|
|
711
|
-
var
|
|
804
|
+
var import_zod14 = require("zod");
|
|
712
805
|
var import_node_crypto = require("crypto");
|
|
713
806
|
|
|
714
807
|
// ../internal-bridge/src/logger.ts
|
|
@@ -814,11 +907,11 @@ function formattedDateTime() {
|
|
|
814
907
|
__name(formattedDateTime, "formattedDateTime");
|
|
815
908
|
|
|
816
909
|
// ../internal-bridge/src/zodRPC.ts
|
|
817
|
-
var RPCMessageSchema =
|
|
818
|
-
id:
|
|
819
|
-
methodName:
|
|
820
|
-
data:
|
|
821
|
-
kind:
|
|
910
|
+
var RPCMessageSchema = import_zod14.z.object({
|
|
911
|
+
id: import_zod14.z.string(),
|
|
912
|
+
methodName: import_zod14.z.string(),
|
|
913
|
+
data: import_zod14.z.any(),
|
|
914
|
+
kind: import_zod14.z.enum([
|
|
822
915
|
"CALL",
|
|
823
916
|
"RESPONSE"
|
|
824
917
|
])
|
|
@@ -898,7 +991,7 @@ onCall_fn = /* @__PURE__ */ __name(async function(message) {
|
|
|
898
991
|
try {
|
|
899
992
|
await __privateMethod(this, _handleCall, handleCall_fn).call(this, message);
|
|
900
993
|
} catch (callError) {
|
|
901
|
-
if (callError instanceof
|
|
994
|
+
if (callError instanceof import_zod14.ZodError) {
|
|
902
995
|
__privateGet(this, _logger).error(`[ZodRPC] Received invalid call:
|
|
903
996
|
${JSON.stringify(message)}: `, callError.errors);
|
|
904
997
|
} else {
|
|
@@ -912,7 +1005,7 @@ onResponse_fn = /* @__PURE__ */ __name(async function(message1) {
|
|
|
912
1005
|
try {
|
|
913
1006
|
await __privateMethod(this, _handleResponse, handleResponse_fn).call(this, message1);
|
|
914
1007
|
} catch (callError) {
|
|
915
|
-
if (callError instanceof
|
|
1008
|
+
if (callError instanceof import_zod14.ZodError) {
|
|
916
1009
|
__privateGet(this, _logger).error(`[ZodRPC] Received invalid response
|
|
917
1010
|
|
|
918
1011
|
${JSON.stringify(message1)}: `, callError.flatten());
|
|
@@ -988,11 +1081,11 @@ __name(packageResponse, "packageResponse");
|
|
|
988
1081
|
// src/client.ts
|
|
989
1082
|
var import_uuid2 = require("uuid");
|
|
990
1083
|
var import_ws = require("ws");
|
|
991
|
-
var
|
|
1084
|
+
var import_zod15 = require("zod");
|
|
992
1085
|
|
|
993
1086
|
// package.json
|
|
994
1087
|
var name = "@trigger.dev/sdk";
|
|
995
|
-
var version = "0.2.
|
|
1088
|
+
var version = "0.2.22-next.0";
|
|
996
1089
|
|
|
997
1090
|
// src/connection.ts
|
|
998
1091
|
var import_uuid = require("uuid");
|
|
@@ -1176,7 +1269,7 @@ startPingInterval_fn = /* @__PURE__ */ __name(function() {
|
|
|
1176
1269
|
__privateGet(this, _logger2).error(err);
|
|
1177
1270
|
}
|
|
1178
1271
|
if (lastSuccessfulPing.getTime() < new Date().getTime() - __privateGet(this, _closeUnresponsiveConnectionTimeoutMs)) {
|
|
1179
|
-
__privateGet(this, _logger2).error("No pong received in last three minutes, closing connection to
|
|
1272
|
+
__privateGet(this, _logger2).error("No pong received in last three minutes, closing connection to Trigger.dev and retrying...");
|
|
1180
1273
|
if (__privateGet(this, _pingIntervalHandle)) {
|
|
1181
1274
|
clearInterval(__privateGet(this, _pingIntervalHandle));
|
|
1182
1275
|
__privateSet(this, _pingIntervalHandle, void 0);
|
|
@@ -1245,17 +1338,54 @@ __name(ContextLogger, "ContextLogger");
|
|
|
1245
1338
|
|
|
1246
1339
|
// src/client.ts
|
|
1247
1340
|
var import_zod_error = require("zod-error");
|
|
1248
|
-
var import_terminal_link = __toESM(require("terminal-link"));
|
|
1249
|
-
var import_chalk = __toESM(require("chalk"));
|
|
1250
|
-
var import_git_repo_info = __toESM(require("git-repo-info"));
|
|
1251
|
-
var import_git_remote_origin_url = __toESM(require("git-remote-origin-url"));
|
|
1252
1341
|
var import_promises = require("fs/promises");
|
|
1342
|
+
|
|
1343
|
+
// src/keyValueStorage.ts
|
|
1344
|
+
var ContextKeyValueStorage = class {
|
|
1345
|
+
constructor(namespace, onGet, onSet, onDelete) {
|
|
1346
|
+
this.namespace = namespace;
|
|
1347
|
+
this.onGet = onGet;
|
|
1348
|
+
this.onSet = onSet;
|
|
1349
|
+
this.onDelete = onDelete;
|
|
1350
|
+
this.getCount = 0;
|
|
1351
|
+
this.setCount = 0;
|
|
1352
|
+
this.deleteCount = 0;
|
|
1353
|
+
}
|
|
1354
|
+
get(key) {
|
|
1355
|
+
const operation = {
|
|
1356
|
+
key,
|
|
1357
|
+
namespace: this.namespace,
|
|
1358
|
+
idempotencyKey: `get:${this.namespace}:${key}:${this.getCount++}`
|
|
1359
|
+
};
|
|
1360
|
+
return this.onGet(operation);
|
|
1361
|
+
}
|
|
1362
|
+
set(key, value) {
|
|
1363
|
+
const operation = {
|
|
1364
|
+
key,
|
|
1365
|
+
namespace: this.namespace,
|
|
1366
|
+
idempotencyKey: `set:${this.namespace}:${key}:${this.setCount++}`,
|
|
1367
|
+
value
|
|
1368
|
+
};
|
|
1369
|
+
return this.onSet(operation);
|
|
1370
|
+
}
|
|
1371
|
+
delete(key) {
|
|
1372
|
+
const operation = {
|
|
1373
|
+
key,
|
|
1374
|
+
namespace: this.namespace,
|
|
1375
|
+
idempotencyKey: `delete:${this.namespace}:${key}:${this.deleteCount++}`
|
|
1376
|
+
};
|
|
1377
|
+
return this.onDelete(operation);
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
__name(ContextKeyValueStorage, "ContextKeyValueStorage");
|
|
1381
|
+
|
|
1382
|
+
// src/client.ts
|
|
1253
1383
|
var zodErrorMessageOptions = {
|
|
1254
1384
|
delimiter: {
|
|
1255
1385
|
error: " \u{1F525} "
|
|
1256
1386
|
}
|
|
1257
1387
|
};
|
|
1258
|
-
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;
|
|
1388
|
+
var _trigger, _options, _connection2, _serverRPC, _apiKey, _endpoint, _isConnected, _retryIntervalMs, _logger3, _closedByUser, _registerResponse, _responseCompleteCallbacks, _waitForCallbacks, _fetchCallbacks, _runOnceCallbacks, _kvGetCallbacks, _kvSetCallbacks, _kvDeleteCallbacks, _initializeConnection, initializeConnection_fn, _initializeRPC, initializeRPC_fn, _initializeHost, initializeHost_fn, _send, send_fn;
|
|
1259
1389
|
var TriggerClient = class {
|
|
1260
1390
|
constructor(trigger, options) {
|
|
1261
1391
|
__privateAdd(this, _initializeConnection);
|
|
@@ -1277,6 +1407,9 @@ var TriggerClient = class {
|
|
|
1277
1407
|
__privateAdd(this, _waitForCallbacks, /* @__PURE__ */ new Map());
|
|
1278
1408
|
__privateAdd(this, _fetchCallbacks, /* @__PURE__ */ new Map());
|
|
1279
1409
|
__privateAdd(this, _runOnceCallbacks, /* @__PURE__ */ new Map());
|
|
1410
|
+
__privateAdd(this, _kvGetCallbacks, /* @__PURE__ */ new Map());
|
|
1411
|
+
__privateAdd(this, _kvSetCallbacks, /* @__PURE__ */ new Map());
|
|
1412
|
+
__privateAdd(this, _kvDeleteCallbacks, /* @__PURE__ */ new Map());
|
|
1280
1413
|
__privateSet(this, _trigger, trigger);
|
|
1281
1414
|
__privateSet(this, _options, options);
|
|
1282
1415
|
const apiKey = __privateGet(this, _options).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
@@ -1295,12 +1428,13 @@ var TriggerClient = class {
|
|
|
1295
1428
|
await __privateMethod(this, _initializeConnection, initializeConnection_fn).call(this, instanceId);
|
|
1296
1429
|
__privateMethod(this, _initializeRPC, initializeRPC_fn).call(this);
|
|
1297
1430
|
await __privateMethod(this, _initializeHost, initializeHost_fn).call(this);
|
|
1431
|
+
const terminalLink = (await import("terminal-link")).default;
|
|
1298
1432
|
if (__privateGet(this, _registerResponse)?.isNew) {
|
|
1299
|
-
__privateGet(this, _logger3).logClean(`\u{1F389} Successfully registered "${__privateGet(this, _trigger).name}" to trigger.dev \u{1F449} ${(
|
|
1433
|
+
__privateGet(this, _logger3).logClean(`\u{1F389} Successfully registered "${__privateGet(this, _trigger).name}" to trigger.dev \u{1F449} ${terminalLink("View on dashboard", __privateGet(this, _registerResponse).url, {
|
|
1300
1434
|
fallback: (text, url) => `${text}: (${url})`
|
|
1301
1435
|
})}. Listening for events...`);
|
|
1302
1436
|
} else {
|
|
1303
|
-
__privateGet(this, _logger3).log(`\u2728 Connected and listening for events \u{1F449} ${(
|
|
1437
|
+
__privateGet(this, _logger3).log(`\u2728 Connected and listening for events \u{1F449} ${terminalLink("View on dashboard", __privateGet(this, _registerResponse).url, {
|
|
1304
1438
|
fallback: (text, url) => `${text}: (${url})`
|
|
1305
1439
|
})}`);
|
|
1306
1440
|
}
|
|
@@ -1334,6 +1468,9 @@ _responseCompleteCallbacks = new WeakMap();
|
|
|
1334
1468
|
_waitForCallbacks = new WeakMap();
|
|
1335
1469
|
_fetchCallbacks = new WeakMap();
|
|
1336
1470
|
_runOnceCallbacks = new WeakMap();
|
|
1471
|
+
_kvGetCallbacks = new WeakMap();
|
|
1472
|
+
_kvSetCallbacks = new WeakMap();
|
|
1473
|
+
_kvDeleteCallbacks = new WeakMap();
|
|
1337
1474
|
_initializeConnection = new WeakSet();
|
|
1338
1475
|
initializeConnection_fn = /* @__PURE__ */ __name(async function(instanceId) {
|
|
1339
1476
|
const id = instanceId ?? (0, import_uuid2.v4)();
|
|
@@ -1356,7 +1493,8 @@ initializeConnection_fn = /* @__PURE__ */ __name(async function(instanceId) {
|
|
|
1356
1493
|
__privateSet(this, _closedByUser, false);
|
|
1357
1494
|
return;
|
|
1358
1495
|
}
|
|
1359
|
-
|
|
1496
|
+
const chalk = (await import("chalk")).default;
|
|
1497
|
+
__privateGet(this, _logger3).error(`${chalk.red("error")} Could not connect to trigger.dev${reason ? `: ${reason}` : `(code ${code})`}`);
|
|
1360
1498
|
if (!__privateGet(this, _isConnected))
|
|
1361
1499
|
return;
|
|
1362
1500
|
__privateGet(this, _logger3).log("\u{1F50C} Reconnecting to trigger.dev...");
|
|
@@ -1455,6 +1593,39 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1455
1593
|
reject(data.error);
|
|
1456
1594
|
return true;
|
|
1457
1595
|
},
|
|
1596
|
+
RESOLVE_KV_GET: async (data) => {
|
|
1597
|
+
__privateGet(this, _logger3).debug("Handling RESOLVE_KV_GET", data);
|
|
1598
|
+
const getCallbacks = __privateGet(this, _kvGetCallbacks).get(messageKey(data.meta.runId, data.key));
|
|
1599
|
+
if (!getCallbacks) {
|
|
1600
|
+
__privateGet(this, _logger3).debug(`Could not find kvGet callbacks for request ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
|
|
1601
|
+
return true;
|
|
1602
|
+
}
|
|
1603
|
+
const { resolve } = getCallbacks;
|
|
1604
|
+
resolve(data.output);
|
|
1605
|
+
return true;
|
|
1606
|
+
},
|
|
1607
|
+
RESOLVE_KV_SET: async (data) => {
|
|
1608
|
+
__privateGet(this, _logger3).debug("Handling RESOLVE_KV_SET", data);
|
|
1609
|
+
const setCallbacks = __privateGet(this, _kvSetCallbacks).get(messageKey(data.meta.runId, data.key));
|
|
1610
|
+
if (!setCallbacks) {
|
|
1611
|
+
__privateGet(this, _logger3).debug(`Could not find kvSet callbacks for request ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
|
|
1612
|
+
return true;
|
|
1613
|
+
}
|
|
1614
|
+
const { resolve } = setCallbacks;
|
|
1615
|
+
resolve();
|
|
1616
|
+
return true;
|
|
1617
|
+
},
|
|
1618
|
+
RESOLVE_KV_DELETE: async (data) => {
|
|
1619
|
+
__privateGet(this, _logger3).debug("Handling RESOLVE_KV_DELETE", data);
|
|
1620
|
+
const deleteCallbacks = __privateGet(this, _kvDeleteCallbacks).get(messageKey(data.meta.runId, data.key));
|
|
1621
|
+
if (!deleteCallbacks) {
|
|
1622
|
+
__privateGet(this, _logger3).debug(`Could not find kvDelete callbacks for request ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
|
|
1623
|
+
return true;
|
|
1624
|
+
}
|
|
1625
|
+
const { resolve } = deleteCallbacks;
|
|
1626
|
+
resolve();
|
|
1627
|
+
return true;
|
|
1628
|
+
},
|
|
1458
1629
|
TRIGGER_WORKFLOW: async (data) => {
|
|
1459
1630
|
__privateGet(this, _logger3).debug("Handling TRIGGER_WORKFLOW", data);
|
|
1460
1631
|
const parsedEventData = __privateGet(this, _options).on.schema.safeParse(data.trigger.input);
|
|
@@ -1493,15 +1664,76 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1493
1664
|
status: response.status,
|
|
1494
1665
|
ok: response.ok,
|
|
1495
1666
|
headers: response.headers,
|
|
1496
|
-
body: response.body ? (options.responseSchema ??
|
|
1667
|
+
body: response.body ? (options.responseSchema ?? import_zod15.z.any()).parse(response.body) : void 0
|
|
1497
1668
|
};
|
|
1498
1669
|
}, "fetchFunction");
|
|
1670
|
+
const kvGetFunction = /* @__PURE__ */ __name(async (op) => {
|
|
1671
|
+
const result = new Promise((resolve, reject) => {
|
|
1672
|
+
__privateGet(this, _kvGetCallbacks).set(messageKey(data.id, op.idempotencyKey), {
|
|
1673
|
+
resolve,
|
|
1674
|
+
reject
|
|
1675
|
+
});
|
|
1676
|
+
});
|
|
1677
|
+
await serverRPC.send("SEND_KV_GET", {
|
|
1678
|
+
runId: data.id,
|
|
1679
|
+
key: op.idempotencyKey,
|
|
1680
|
+
get: {
|
|
1681
|
+
namespace: op.namespace,
|
|
1682
|
+
key: op.key
|
|
1683
|
+
},
|
|
1684
|
+
timestamp: String(highPrecisionTimestamp())
|
|
1685
|
+
});
|
|
1686
|
+
const output = await result;
|
|
1687
|
+
return output;
|
|
1688
|
+
}, "kvGetFunction");
|
|
1689
|
+
const kvSetFunction = /* @__PURE__ */ __name(async (op) => {
|
|
1690
|
+
const result = new Promise((resolve, reject) => {
|
|
1691
|
+
__privateGet(this, _kvSetCallbacks).set(messageKey(data.id, op.idempotencyKey), {
|
|
1692
|
+
resolve,
|
|
1693
|
+
reject
|
|
1694
|
+
});
|
|
1695
|
+
});
|
|
1696
|
+
await serverRPC.send("SEND_KV_SET", {
|
|
1697
|
+
runId: data.id,
|
|
1698
|
+
key: op.idempotencyKey,
|
|
1699
|
+
set: {
|
|
1700
|
+
namespace: op.namespace,
|
|
1701
|
+
key: op.key,
|
|
1702
|
+
value: op.value
|
|
1703
|
+
},
|
|
1704
|
+
timestamp: String(highPrecisionTimestamp())
|
|
1705
|
+
});
|
|
1706
|
+
await result;
|
|
1707
|
+
return;
|
|
1708
|
+
}, "kvSetFunction");
|
|
1709
|
+
const kvDeleteFunction = /* @__PURE__ */ __name(async (op) => {
|
|
1710
|
+
const result = new Promise((resolve, reject) => {
|
|
1711
|
+
__privateGet(this, _kvDeleteCallbacks).set(messageKey(data.id, op.idempotencyKey), {
|
|
1712
|
+
resolve,
|
|
1713
|
+
reject
|
|
1714
|
+
});
|
|
1715
|
+
});
|
|
1716
|
+
await serverRPC.send("SEND_KV_DELETE", {
|
|
1717
|
+
runId: data.id,
|
|
1718
|
+
key: op.idempotencyKey,
|
|
1719
|
+
delete: {
|
|
1720
|
+
namespace: op.namespace,
|
|
1721
|
+
key: op.key
|
|
1722
|
+
},
|
|
1723
|
+
timestamp: String(highPrecisionTimestamp())
|
|
1724
|
+
});
|
|
1725
|
+
await result;
|
|
1726
|
+
return;
|
|
1727
|
+
}, "kvDeleteFunction");
|
|
1499
1728
|
const ctx = {
|
|
1500
1729
|
id: data.id,
|
|
1501
1730
|
environment: data.meta.environment,
|
|
1502
1731
|
apiKey: data.meta.apiKey,
|
|
1503
1732
|
organizationId: data.meta.organizationId,
|
|
1504
1733
|
isTest: data.meta.isTest,
|
|
1734
|
+
kv: new ContextKeyValueStorage(`workflow:${data.meta.workflowId}`, kvGetFunction, kvSetFunction, kvDeleteFunction),
|
|
1735
|
+
globalKv: new ContextKeyValueStorage(`org:${data.meta.organizationId}`, kvGetFunction, kvSetFunction, kvDeleteFunction),
|
|
1736
|
+
runKv: new ContextKeyValueStorage(`run:${data.id}`, kvGetFunction, kvSetFunction, kvDeleteFunction),
|
|
1505
1737
|
logger: new ContextLogger(async (level, message, properties) => {
|
|
1506
1738
|
await serverRPC.send("SEND_LOG", {
|
|
1507
1739
|
runId: data.id,
|
|
@@ -1617,6 +1849,7 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1617
1849
|
};
|
|
1618
1850
|
const eventData = parsedEventData.data;
|
|
1619
1851
|
__privateGet(this, _logger3).debug("Parsed event data", eventData);
|
|
1852
|
+
const terminalLink = (await import("terminal-link")).default;
|
|
1620
1853
|
triggerRunLocalStorage.run({
|
|
1621
1854
|
performRequest: async (key, options) => {
|
|
1622
1855
|
const result = new Promise((resolve, reject) => {
|
|
@@ -1657,7 +1890,7 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1657
1890
|
}, () => {
|
|
1658
1891
|
__privateGet(this, _logger3).debug("Running trigger...");
|
|
1659
1892
|
if (typeof data.meta.attempt === "number" && data.meta.attempt === 0) {
|
|
1660
|
-
__privateGet(this, _logger3).log(`Run ${data.id} started \u{1F449} ${(
|
|
1893
|
+
__privateGet(this, _logger3).log(`Run ${data.id} started \u{1F449} ${terminalLink("View on dashboard", `${__privateGet(this, _registerResponse).url}/runs/${data.id}`, {
|
|
1661
1894
|
fallback: (text, url) => `${text}: (${url})`
|
|
1662
1895
|
})}`);
|
|
1663
1896
|
}
|
|
@@ -1666,7 +1899,7 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1666
1899
|
timestamp: String(highPrecisionTimestamp())
|
|
1667
1900
|
}).then(() => {
|
|
1668
1901
|
return __privateGet(this, _trigger).options.run(eventData, ctx).then((output) => {
|
|
1669
|
-
__privateGet(this, _logger3).log(`Run ${data.id} complete \u{1F449} ${(
|
|
1902
|
+
__privateGet(this, _logger3).log(`Run ${data.id} complete \u{1F449} ${terminalLink("View on dashboard", `${__privateGet(this, _registerResponse).url}/runs/${data.id}`, {
|
|
1670
1903
|
fallback: (text, url) => `${text}: (${url})`
|
|
1671
1904
|
})}`);
|
|
1672
1905
|
return serverRPC.send("COMPLETE_WORKFLOW_RUN", {
|
|
@@ -1683,9 +1916,9 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1683
1916
|
stackTrace: error2.stack
|
|
1684
1917
|
};
|
|
1685
1918
|
}
|
|
1686
|
-
const parsedError =
|
|
1687
|
-
name:
|
|
1688
|
-
message:
|
|
1919
|
+
const parsedError = import_zod15.z.object({
|
|
1920
|
+
name: import_zod15.z.string(),
|
|
1921
|
+
message: import_zod15.z.string()
|
|
1689
1922
|
}).passthrough().safeParse(error2);
|
|
1690
1923
|
if (parsedError.success) {
|
|
1691
1924
|
return parsedError.data;
|
|
@@ -1725,7 +1958,7 @@ initializeHost_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1725
1958
|
if (!__privateGet(this, _serverRPC)) {
|
|
1726
1959
|
throw new Error("Cannot initialize host without an RPC connection");
|
|
1727
1960
|
}
|
|
1728
|
-
const repoInfo = safeGetRepoInfo();
|
|
1961
|
+
const repoInfo = await safeGetRepoInfo();
|
|
1729
1962
|
const remoteUrl = repoInfo ? await getRemoteUrl(repoInfo.commonGitDir) : void 0;
|
|
1730
1963
|
const packageMetadata = await getTriggerPackageEnvVars(process.env);
|
|
1731
1964
|
const response = await __privateMethod(this, _send, send_fn).call(this, "INITIALIZE_HOST_V2", {
|
|
@@ -1745,7 +1978,8 @@ initializeHost_fn = /* @__PURE__ */ __name(async function() {
|
|
|
1745
1978
|
commitMessage: repoInfo.commitMessage,
|
|
1746
1979
|
origin: remoteUrl
|
|
1747
1980
|
} : void 0,
|
|
1748
|
-
packageMetadata
|
|
1981
|
+
packageMetadata,
|
|
1982
|
+
env: gatherEnvVars(process.env)
|
|
1749
1983
|
}
|
|
1750
1984
|
});
|
|
1751
1985
|
if (!response) {
|
|
@@ -1805,7 +2039,8 @@ async function getTriggerPackageEnvVars(env) {
|
|
|
1805
2039
|
__name(getTriggerPackageEnvVars, "getTriggerPackageEnvVars");
|
|
1806
2040
|
async function getRemoteUrl(cwd) {
|
|
1807
2041
|
try {
|
|
1808
|
-
|
|
2042
|
+
const gitRemoteOriginUrl = (await import("git-remote-origin-url")).default;
|
|
2043
|
+
return await gitRemoteOriginUrl({
|
|
1809
2044
|
cwd
|
|
1810
2045
|
});
|
|
1811
2046
|
} catch (err) {
|
|
@@ -1813,18 +2048,28 @@ async function getRemoteUrl(cwd) {
|
|
|
1813
2048
|
}
|
|
1814
2049
|
}
|
|
1815
2050
|
__name(getRemoteUrl, "getRemoteUrl");
|
|
1816
|
-
function safeGetRepoInfo() {
|
|
2051
|
+
async function safeGetRepoInfo() {
|
|
1817
2052
|
try {
|
|
1818
|
-
|
|
2053
|
+
const gitRepoInfo = (await import("git-repo-info")).default;
|
|
2054
|
+
return gitRepoInfo();
|
|
1819
2055
|
} catch (err) {
|
|
1820
2056
|
return;
|
|
1821
2057
|
}
|
|
1822
2058
|
}
|
|
1823
2059
|
__name(safeGetRepoInfo, "safeGetRepoInfo");
|
|
2060
|
+
function gatherEnvVars(env) {
|
|
2061
|
+
if (!env) {
|
|
2062
|
+
return {};
|
|
2063
|
+
}
|
|
2064
|
+
const envVars = Object.entries(env).filter(([key]) => key.startsWith("TRIGGER_") && key !== "TRIGGER_API_KEY").map(([key, value]) => [
|
|
2065
|
+
key.replace("TRIGGER_", ""),
|
|
2066
|
+
`${value}`
|
|
2067
|
+
]);
|
|
2068
|
+
return Object.fromEntries(envVars);
|
|
2069
|
+
}
|
|
2070
|
+
__name(gatherEnvVars, "gatherEnvVars");
|
|
1824
2071
|
|
|
1825
2072
|
// src/trigger/index.ts
|
|
1826
|
-
var import_chalk2 = __toESM(require("chalk"));
|
|
1827
|
-
var import_terminal_link2 = __toESM(require("terminal-link"));
|
|
1828
2073
|
var _client, _getApiKey, getApiKey_fn;
|
|
1829
2074
|
var Trigger = class {
|
|
1830
2075
|
constructor(options) {
|
|
@@ -1834,15 +2079,17 @@ var Trigger = class {
|
|
|
1834
2079
|
}
|
|
1835
2080
|
async listen() {
|
|
1836
2081
|
const apiKey = __privateMethod(this, _getApiKey, getApiKey_fn).call(this);
|
|
2082
|
+
const chalk = (await import("chalk")).default;
|
|
2083
|
+
const terminalLink = (await import("terminal-link")).default;
|
|
1837
2084
|
if (apiKey.status === "invalid") {
|
|
1838
|
-
console.log(`${
|
|
2085
|
+
console.log(`${chalk.red("Trigger.dev error")}: ${chalk.bold(this.id)} is has an invalid API key ("${chalk.italic(apiKey.apiKey)}"), please set the TRIGGER_API_KEY environment variable or pass the apiKey option to a valid value. ${terminalLink("Get your API key here", "https://app.trigger.dev", {
|
|
1839
2086
|
fallback(text, url) {
|
|
1840
2087
|
return `${text} \u{1F449} ${url}`;
|
|
1841
2088
|
}
|
|
1842
2089
|
})}`);
|
|
1843
2090
|
return;
|
|
1844
2091
|
} else if (apiKey.status === "missing") {
|
|
1845
|
-
console.log(`${
|
|
2092
|
+
console.log(`${chalk.red("Trigger.dev error")}: ${chalk.bold(this.id)} is missing an API key, please set the TRIGGER_API_KEY environment variable or pass the apiKey option to the Trigger constructor. ${terminalLink("Get your API key here", "https://app.trigger.dev", {
|
|
1846
2093
|
fallback(text, url) {
|
|
1847
2094
|
return `${text} \u{1F449} ${url}`;
|
|
1848
2095
|
}
|