@trigger.dev/sdk 2.0.13 → 2.1.0-beta.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 +106 -103
- package/dist/index.js +153 -166
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -62,7 +62,6 @@ __export(src_exports, {
|
|
|
62
62
|
MissingConnectionNotification: () => MissingConnectionNotification,
|
|
63
63
|
MissingConnectionResolvedNotification: () => MissingConnectionResolvedNotification,
|
|
64
64
|
TriggerClient: () => TriggerClient,
|
|
65
|
-
authenticatedTask: () => authenticatedTask,
|
|
66
65
|
cronTrigger: () => cronTrigger,
|
|
67
66
|
eventTrigger: () => eventTrigger,
|
|
68
67
|
intervalTrigger: () => intervalTrigger,
|
|
@@ -70,7 +69,8 @@ __export(src_exports, {
|
|
|
70
69
|
missingConnectionNotification: () => missingConnectionNotification,
|
|
71
70
|
missingConnectionResolvedNotification: () => missingConnectionResolvedNotification,
|
|
72
71
|
omit: () => omit,
|
|
73
|
-
redactString: () => redactString
|
|
72
|
+
redactString: () => redactString,
|
|
73
|
+
retry: () => retry
|
|
74
74
|
});
|
|
75
75
|
module.exports = __toCommonJS(src_exports);
|
|
76
76
|
|
|
@@ -113,7 +113,7 @@ var Job = class {
|
|
|
113
113
|
acc[key] = {
|
|
114
114
|
id: integration.id,
|
|
115
115
|
metadata: integration.metadata,
|
|
116
|
-
authSource: integration.
|
|
116
|
+
authSource: integration.authSource
|
|
117
117
|
};
|
|
118
118
|
return acc;
|
|
119
119
|
}, {});
|
|
@@ -269,7 +269,7 @@ var ApiClient = class {
|
|
|
269
269
|
__privateGet(this, _logger).debug("activating http source", {
|
|
270
270
|
source
|
|
271
271
|
});
|
|
272
|
-
const response = await zodfetch(import_core.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/
|
|
272
|
+
const response = await zodfetch(import_core.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v2/${client}/sources/${key}`, {
|
|
273
273
|
method: "PUT",
|
|
274
274
|
headers: {
|
|
275
275
|
"Content-Type": "application/json",
|
|
@@ -285,7 +285,7 @@ var ApiClient = class {
|
|
|
285
285
|
id,
|
|
286
286
|
payload
|
|
287
287
|
});
|
|
288
|
-
const response = await zodfetch(import_core.
|
|
288
|
+
const response = await zodfetch(import_core.RegisterSourceEventSchemaV2, `${__privateGet(this, _apiUrl)}/api/v2/${client}/triggers/${id}/registrations/${key}`, {
|
|
289
289
|
method: "PUT",
|
|
290
290
|
headers: {
|
|
291
291
|
"Content-Type": "application/json",
|
|
@@ -465,70 +465,17 @@ var import_core3 = require("@trigger.dev/core");
|
|
|
465
465
|
var import_node_async_hooks = require("async_hooks");
|
|
466
466
|
var import_node_crypto = require("crypto");
|
|
467
467
|
|
|
468
|
-
// src/ioWithIntegrations.ts
|
|
469
|
-
function createIOWithIntegrations(io, auths, integrations) {
|
|
470
|
-
if (!integrations) {
|
|
471
|
-
return io;
|
|
472
|
-
}
|
|
473
|
-
const connections = Object.entries(integrations).reduce((acc, [connectionKey, integration]) => {
|
|
474
|
-
let auth = auths?.[connectionKey];
|
|
475
|
-
const client = integration.client.usesLocalAuth ? integration.client.client : auth ? integration.client.clientFactory?.(auth) : void 0;
|
|
476
|
-
if (!client) {
|
|
477
|
-
return acc;
|
|
478
|
-
}
|
|
479
|
-
auth = integration.client.usesLocalAuth ? integration.client.auth : auth;
|
|
480
|
-
const ioConnection = {
|
|
481
|
-
client
|
|
482
|
-
};
|
|
483
|
-
ioConnection.runTask = async (key, callback, options) => {
|
|
484
|
-
return await io.runTask(key, {
|
|
485
|
-
name: "Task",
|
|
486
|
-
icon: integration.metadata.id,
|
|
487
|
-
retry: {
|
|
488
|
-
limit: 10,
|
|
489
|
-
minTimeoutInMs: 1e3,
|
|
490
|
-
maxTimeoutInMs: 3e4,
|
|
491
|
-
factor: 2,
|
|
492
|
-
randomize: true
|
|
493
|
-
},
|
|
494
|
-
...options
|
|
495
|
-
}, async (ioTask) => {
|
|
496
|
-
return await callback(client, ioTask, io);
|
|
497
|
-
});
|
|
498
|
-
};
|
|
499
|
-
if (integration.client.tasks) {
|
|
500
|
-
const tasks = integration.client.tasks;
|
|
501
|
-
Object.keys(tasks).forEach((taskName) => {
|
|
502
|
-
const authenticatedTask2 = tasks[taskName];
|
|
503
|
-
ioConnection[taskName] = async (key, params) => {
|
|
504
|
-
const options = authenticatedTask2.init(params);
|
|
505
|
-
options.connectionKey = connectionKey;
|
|
506
|
-
return await io.runTask(key, options, async (ioTask) => {
|
|
507
|
-
return authenticatedTask2.run(params, client, ioTask, io, auth);
|
|
508
|
-
}, authenticatedTask2.onError);
|
|
509
|
-
};
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
acc[connectionKey] = ioConnection;
|
|
513
|
-
return acc;
|
|
514
|
-
}, {});
|
|
515
|
-
return new Proxy(io, {
|
|
516
|
-
get(target, prop, receiver) {
|
|
517
|
-
if (prop === "__io") {
|
|
518
|
-
return io;
|
|
519
|
-
}
|
|
520
|
-
if (prop in connections) {
|
|
521
|
-
return connections[prop];
|
|
522
|
-
}
|
|
523
|
-
const value = Reflect.get(target, prop, receiver);
|
|
524
|
-
return typeof value == "function" ? value.bind(target) : value;
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
529
|
-
|
|
530
468
|
// src/retry.ts
|
|
531
469
|
var import_core2 = require("@trigger.dev/core");
|
|
470
|
+
var retry = {
|
|
471
|
+
standardBackoff: {
|
|
472
|
+
limit: 8,
|
|
473
|
+
factor: 1.8,
|
|
474
|
+
minTimeoutInMs: 500,
|
|
475
|
+
maxTimeoutInMs: 3e4,
|
|
476
|
+
randomize: true
|
|
477
|
+
}
|
|
478
|
+
};
|
|
532
479
|
|
|
533
480
|
// src/io.ts
|
|
534
481
|
var _addToCachedTasks, addToCachedTasks_fn;
|
|
@@ -584,7 +531,8 @@ var IO = class {
|
|
|
584
531
|
await this.runTask([
|
|
585
532
|
message,
|
|
586
533
|
level
|
|
587
|
-
], {
|
|
534
|
+
], async (task) => {
|
|
535
|
+
}, {
|
|
588
536
|
name: "log",
|
|
589
537
|
icon: "log",
|
|
590
538
|
description: message,
|
|
@@ -600,13 +548,13 @@ var IO = class {
|
|
|
600
548
|
variant: level.toLowerCase()
|
|
601
549
|
},
|
|
602
550
|
noop: true
|
|
603
|
-
}, async (task) => {
|
|
604
551
|
});
|
|
605
552
|
}
|
|
606
553
|
});
|
|
607
554
|
}
|
|
608
555
|
async wait(key, seconds) {
|
|
609
|
-
return await this.runTask(key, {
|
|
556
|
+
return await this.runTask(key, async (task) => {
|
|
557
|
+
}, {
|
|
610
558
|
name: "wait",
|
|
611
559
|
icon: "clock",
|
|
612
560
|
params: {
|
|
@@ -617,17 +565,18 @@ var IO = class {
|
|
|
617
565
|
style: {
|
|
618
566
|
style: "minimal"
|
|
619
567
|
}
|
|
620
|
-
}, async (task) => {
|
|
621
568
|
});
|
|
622
569
|
}
|
|
623
|
-
async backgroundFetch(key, url, requestInit,
|
|
570
|
+
async backgroundFetch(key, url, requestInit, retry2) {
|
|
624
571
|
const urlObject = new URL(url);
|
|
625
|
-
return await this.runTask(key, {
|
|
572
|
+
return await this.runTask(key, async (task) => {
|
|
573
|
+
return task.output;
|
|
574
|
+
}, {
|
|
626
575
|
name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
|
|
627
576
|
params: {
|
|
628
577
|
url,
|
|
629
578
|
requestInit,
|
|
630
|
-
retry
|
|
579
|
+
retry: retry2
|
|
631
580
|
},
|
|
632
581
|
operation: "fetch",
|
|
633
582
|
icon: "background",
|
|
@@ -647,12 +596,12 @@ var IO = class {
|
|
|
647
596
|
text: "true"
|
|
648
597
|
}
|
|
649
598
|
]
|
|
650
|
-
}, async (task) => {
|
|
651
|
-
return task.output;
|
|
652
599
|
});
|
|
653
600
|
}
|
|
654
601
|
async sendEvent(key, event, options) {
|
|
655
|
-
return await this.runTask(key, {
|
|
602
|
+
return await this.runTask(key, async (task) => {
|
|
603
|
+
return await this._triggerClient.sendEvent(event, options);
|
|
604
|
+
}, {
|
|
656
605
|
name: "sendEvent",
|
|
657
606
|
params: {
|
|
658
607
|
event,
|
|
@@ -670,12 +619,12 @@ var IO = class {
|
|
|
670
619
|
}
|
|
671
620
|
] : []
|
|
672
621
|
]
|
|
673
|
-
}, async (task) => {
|
|
674
|
-
return await this._triggerClient.sendEvent(event, options);
|
|
675
622
|
});
|
|
676
623
|
}
|
|
677
624
|
async getEvent(key, id) {
|
|
678
|
-
return await this.runTask(key, {
|
|
625
|
+
return await this.runTask(key, async (task) => {
|
|
626
|
+
return await this._triggerClient.getEvent(id);
|
|
627
|
+
}, {
|
|
679
628
|
name: "getEvent",
|
|
680
629
|
params: {
|
|
681
630
|
id
|
|
@@ -686,12 +635,12 @@ var IO = class {
|
|
|
686
635
|
text: id
|
|
687
636
|
}
|
|
688
637
|
]
|
|
689
|
-
}, async (task) => {
|
|
690
|
-
return await this._triggerClient.getEvent(id);
|
|
691
638
|
});
|
|
692
639
|
}
|
|
693
640
|
async cancelEvent(key, eventId) {
|
|
694
|
-
return await this.runTask(key, {
|
|
641
|
+
return await this.runTask(key, async (task) => {
|
|
642
|
+
return await this._triggerClient.cancelEvent(eventId);
|
|
643
|
+
}, {
|
|
695
644
|
name: "cancelEvent",
|
|
696
645
|
params: {
|
|
697
646
|
eventId
|
|
@@ -702,12 +651,12 @@ var IO = class {
|
|
|
702
651
|
text: eventId
|
|
703
652
|
}
|
|
704
653
|
]
|
|
705
|
-
}, async (task) => {
|
|
706
|
-
return await this._triggerClient.cancelEvent(eventId);
|
|
707
654
|
});
|
|
708
655
|
}
|
|
709
656
|
async updateSource(key, options) {
|
|
710
|
-
return this.runTask(key, {
|
|
657
|
+
return this.runTask(key, async (task) => {
|
|
658
|
+
return await this._apiClient.updateSource(this._triggerClient.id, options.key, options);
|
|
659
|
+
}, {
|
|
711
660
|
name: "Update Source",
|
|
712
661
|
description: "Update Source",
|
|
713
662
|
properties: [
|
|
@@ -722,12 +671,15 @@ var IO = class {
|
|
|
722
671
|
"secret"
|
|
723
672
|
]
|
|
724
673
|
}
|
|
725
|
-
}, async (task) => {
|
|
726
|
-
return await this._apiClient.updateSource(this._triggerClient.id, options.key, options);
|
|
727
674
|
});
|
|
728
675
|
}
|
|
729
676
|
async registerInterval(key, dynamicSchedule, id, options) {
|
|
730
|
-
return await this.runTask(key, {
|
|
677
|
+
return await this.runTask(key, async (task) => {
|
|
678
|
+
return dynamicSchedule.register(id, {
|
|
679
|
+
type: "interval",
|
|
680
|
+
options
|
|
681
|
+
});
|
|
682
|
+
}, {
|
|
731
683
|
name: "register-interval",
|
|
732
684
|
properties: [
|
|
733
685
|
{
|
|
@@ -744,15 +696,12 @@ var IO = class {
|
|
|
744
696
|
}
|
|
745
697
|
],
|
|
746
698
|
params: options
|
|
747
|
-
}, async (task) => {
|
|
748
|
-
return dynamicSchedule.register(id, {
|
|
749
|
-
type: "interval",
|
|
750
|
-
options
|
|
751
|
-
});
|
|
752
699
|
});
|
|
753
700
|
}
|
|
754
701
|
async unregisterInterval(key, dynamicSchedule, id) {
|
|
755
|
-
return await this.runTask(key, {
|
|
702
|
+
return await this.runTask(key, async (task) => {
|
|
703
|
+
return dynamicSchedule.unregister(id);
|
|
704
|
+
}, {
|
|
756
705
|
name: "unregister-interval",
|
|
757
706
|
properties: [
|
|
758
707
|
{
|
|
@@ -764,12 +713,15 @@ var IO = class {
|
|
|
764
713
|
text: id
|
|
765
714
|
}
|
|
766
715
|
]
|
|
767
|
-
}, async (task) => {
|
|
768
|
-
return dynamicSchedule.unregister(id);
|
|
769
716
|
});
|
|
770
717
|
}
|
|
771
718
|
async registerCron(key, dynamicSchedule, id, options) {
|
|
772
|
-
return await this.runTask(key, {
|
|
719
|
+
return await this.runTask(key, async (task) => {
|
|
720
|
+
return dynamicSchedule.register(id, {
|
|
721
|
+
type: "cron",
|
|
722
|
+
options
|
|
723
|
+
});
|
|
724
|
+
}, {
|
|
773
725
|
name: "register-cron",
|
|
774
726
|
properties: [
|
|
775
727
|
{
|
|
@@ -786,15 +738,12 @@ var IO = class {
|
|
|
786
738
|
}
|
|
787
739
|
],
|
|
788
740
|
params: options
|
|
789
|
-
}, async (task) => {
|
|
790
|
-
return dynamicSchedule.register(id, {
|
|
791
|
-
type: "cron",
|
|
792
|
-
options
|
|
793
|
-
});
|
|
794
741
|
});
|
|
795
742
|
}
|
|
796
743
|
async unregisterCron(key, dynamicSchedule, id) {
|
|
797
|
-
return await this.runTask(key, {
|
|
744
|
+
return await this.runTask(key, async (task) => {
|
|
745
|
+
return dynamicSchedule.unregister(id);
|
|
746
|
+
}, {
|
|
798
747
|
name: "unregister-cron",
|
|
799
748
|
properties: [
|
|
800
749
|
{
|
|
@@ -806,12 +755,20 @@ var IO = class {
|
|
|
806
755
|
text: id
|
|
807
756
|
}
|
|
808
757
|
]
|
|
809
|
-
}, async (task) => {
|
|
810
|
-
return dynamicSchedule.unregister(id);
|
|
811
758
|
});
|
|
812
759
|
}
|
|
813
760
|
async registerTrigger(key, trigger, id, params) {
|
|
814
|
-
return await this.runTask(key, {
|
|
761
|
+
return await this.runTask(key, async (task) => {
|
|
762
|
+
const registration = await this.runTask("register-source", async (subtask1) => {
|
|
763
|
+
return trigger.register(id, params);
|
|
764
|
+
}, {
|
|
765
|
+
name: "register-source"
|
|
766
|
+
});
|
|
767
|
+
return {
|
|
768
|
+
id: registration.id,
|
|
769
|
+
key: registration.source.key
|
|
770
|
+
};
|
|
771
|
+
}, {
|
|
815
772
|
name: "register-trigger",
|
|
816
773
|
properties: [
|
|
817
774
|
{
|
|
@@ -824,43 +781,19 @@ var IO = class {
|
|
|
824
781
|
}
|
|
825
782
|
],
|
|
826
783
|
params
|
|
827
|
-
}, async (task) => {
|
|
828
|
-
const registration = await this.runTask("register-source", {
|
|
829
|
-
name: "register-source"
|
|
830
|
-
}, async (subtask1) => {
|
|
831
|
-
return trigger.register(id, params);
|
|
832
|
-
});
|
|
833
|
-
const connection = await this.getAuth("get-auth", registration.source.clientId);
|
|
834
|
-
const io = createIOWithIntegrations(
|
|
835
|
-
this,
|
|
836
|
-
{
|
|
837
|
-
integration: connection
|
|
838
|
-
},
|
|
839
|
-
{
|
|
840
|
-
integration: trigger.source.integration
|
|
841
|
-
}
|
|
842
|
-
);
|
|
843
|
-
const updates = await trigger.source.register(params, registration, io, this._context);
|
|
844
|
-
if (!updates) {
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
return await this.updateSource("update-source", {
|
|
848
|
-
key: registration.source.key,
|
|
849
|
-
...updates
|
|
850
|
-
});
|
|
851
784
|
});
|
|
852
785
|
}
|
|
853
786
|
async getAuth(key, clientId) {
|
|
854
787
|
if (!clientId) {
|
|
855
788
|
return;
|
|
856
789
|
}
|
|
857
|
-
return this.runTask(key, {
|
|
858
|
-
name: "get-auth"
|
|
859
|
-
}, async (task) => {
|
|
790
|
+
return this.runTask(key, async (task) => {
|
|
860
791
|
return await this._triggerClient.getAuth(clientId);
|
|
792
|
+
}, {
|
|
793
|
+
name: "get-auth"
|
|
861
794
|
});
|
|
862
795
|
}
|
|
863
|
-
async runTask(key,
|
|
796
|
+
async runTask(key, callback, options, onError) {
|
|
864
797
|
const parentId = this._taskStorage.getStore()?.taskId;
|
|
865
798
|
if (parentId) {
|
|
866
799
|
this._logger.debug("Using parent task", {
|
|
@@ -886,7 +819,7 @@ var IO = class {
|
|
|
886
819
|
idempotencyKey,
|
|
887
820
|
displayKey: typeof key === "string" ? key : void 0,
|
|
888
821
|
noop: false,
|
|
889
|
-
...options,
|
|
822
|
+
...options ?? {},
|
|
890
823
|
parentId
|
|
891
824
|
});
|
|
892
825
|
if (task.status === "CANCELED") {
|
|
@@ -966,7 +899,7 @@ var IO = class {
|
|
|
966
899
|
}
|
|
967
900
|
}
|
|
968
901
|
const parsedError = import_core3.ErrorWithStackSchema.safeParse(error);
|
|
969
|
-
if (options
|
|
902
|
+
if (options?.retry) {
|
|
970
903
|
const retryAt = (0, import_core2.calculateRetryAt)(options.retry, task.attempts - 1);
|
|
971
904
|
if (retryAt) {
|
|
972
905
|
throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
|
|
@@ -1063,6 +996,35 @@ var IOLogger = class {
|
|
|
1063
996
|
};
|
|
1064
997
|
__name(IOLogger, "IOLogger");
|
|
1065
998
|
|
|
999
|
+
// src/ioWithIntegrations.ts
|
|
1000
|
+
function createIOWithIntegrations(io, auths, integrations) {
|
|
1001
|
+
if (!integrations) {
|
|
1002
|
+
return io;
|
|
1003
|
+
}
|
|
1004
|
+
const connections = Object.entries(integrations).reduce((acc, [connectionKey, integration]) => {
|
|
1005
|
+
let auth = auths?.[connectionKey];
|
|
1006
|
+
acc[connectionKey] = {
|
|
1007
|
+
integration,
|
|
1008
|
+
auth
|
|
1009
|
+
};
|
|
1010
|
+
return acc;
|
|
1011
|
+
}, {});
|
|
1012
|
+
return new Proxy(io, {
|
|
1013
|
+
get(target, prop, receiver) {
|
|
1014
|
+
if (prop === "__io") {
|
|
1015
|
+
return io;
|
|
1016
|
+
}
|
|
1017
|
+
if (typeof prop === "string" && prop in connections) {
|
|
1018
|
+
const { integration, auth } = connections[prop];
|
|
1019
|
+
return integration.cloneForRun(io, prop, auth);
|
|
1020
|
+
}
|
|
1021
|
+
const value = Reflect.get(target, prop, receiver);
|
|
1022
|
+
return typeof value == "function" ? value.bind(target) : value;
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
1027
|
+
|
|
1066
1028
|
// src/triggers/eventTrigger.ts
|
|
1067
1029
|
var import_core4 = require("@trigger.dev/core");
|
|
1068
1030
|
var _options2;
|
|
@@ -1116,11 +1078,11 @@ __name(eventTrigger, "eventTrigger");
|
|
|
1116
1078
|
|
|
1117
1079
|
// src/triggerClient.ts
|
|
1118
1080
|
var registerSourceEvent = {
|
|
1119
|
-
name: import_core5.
|
|
1081
|
+
name: import_core5.REGISTER_SOURCE_EVENT_V2,
|
|
1120
1082
|
title: "Register Source",
|
|
1121
1083
|
source: "internal",
|
|
1122
1084
|
icon: "register-source",
|
|
1123
|
-
parsePayload: import_core5.
|
|
1085
|
+
parsePayload: import_core5.RegisterSourceEventSchemaV2.parse
|
|
1124
1086
|
};
|
|
1125
1087
|
var _options3, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _client, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn;
|
|
1126
1088
|
var TriggerClient = class {
|
|
@@ -1372,19 +1334,24 @@ var TriggerClient = class {
|
|
|
1372
1334
|
const secret = headers.data["x-ts-secret"];
|
|
1373
1335
|
const params = headers.data["x-ts-params"];
|
|
1374
1336
|
const data = headers.data["x-ts-data"];
|
|
1337
|
+
const auth = headers.data["x-ts-auth"];
|
|
1338
|
+
const inputMetadata = headers.data["x-ts-metadata"];
|
|
1375
1339
|
const source = {
|
|
1376
1340
|
key,
|
|
1377
1341
|
dynamicId,
|
|
1378
1342
|
secret,
|
|
1379
1343
|
params,
|
|
1380
|
-
data
|
|
1344
|
+
data,
|
|
1345
|
+
auth,
|
|
1346
|
+
metadata: inputMetadata
|
|
1381
1347
|
};
|
|
1382
|
-
const { response, events } = await __privateMethod(this, _handleHttpSourceRequest, handleHttpSourceRequest_fn).call(this, source, sourceRequest);
|
|
1348
|
+
const { response, events, metadata } = await __privateMethod(this, _handleHttpSourceRequest, handleHttpSourceRequest_fn).call(this, source, sourceRequest);
|
|
1383
1349
|
return {
|
|
1384
1350
|
status: 200,
|
|
1385
1351
|
body: {
|
|
1386
1352
|
events,
|
|
1387
|
-
response
|
|
1353
|
+
response,
|
|
1354
|
+
metadata
|
|
1388
1355
|
}
|
|
1389
1356
|
};
|
|
1390
1357
|
}
|
|
@@ -1454,14 +1421,15 @@ var TriggerClient = class {
|
|
|
1454
1421
|
let registeredSource = __privateGet(this, _registeredSources)[options.key];
|
|
1455
1422
|
if (!registeredSource) {
|
|
1456
1423
|
registeredSource = {
|
|
1424
|
+
version: "2",
|
|
1457
1425
|
channel: options.source.channel,
|
|
1458
1426
|
key: options.key,
|
|
1459
1427
|
params: options.params,
|
|
1460
|
-
|
|
1428
|
+
options: {},
|
|
1461
1429
|
integration: {
|
|
1462
1430
|
id: options.source.integration.id,
|
|
1463
1431
|
metadata: options.source.integration.metadata,
|
|
1464
|
-
authSource: options.source.integration.
|
|
1432
|
+
authSource: options.source.integration.authSource
|
|
1465
1433
|
},
|
|
1466
1434
|
registerSourceJob: {
|
|
1467
1435
|
id: options.key,
|
|
@@ -1469,12 +1437,12 @@ var TriggerClient = class {
|
|
|
1469
1437
|
}
|
|
1470
1438
|
};
|
|
1471
1439
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
...typeof options.event.name === "string" ? [
|
|
1440
|
+
const newOptions = deepMergeOptions({
|
|
1441
|
+
event: typeof options.event.name === "string" ? [
|
|
1475
1442
|
options.event.name
|
|
1476
1443
|
] : options.event.name
|
|
1477
|
-
|
|
1444
|
+
}, options.options ?? {});
|
|
1445
|
+
registeredSource.options = deepMergeOptions(registeredSource.options, newOptions);
|
|
1478
1446
|
__privateGet(this, _registeredSources)[options.key] = registeredSource;
|
|
1479
1447
|
new Job(this, {
|
|
1480
1448
|
id: options.key,
|
|
@@ -1730,7 +1698,8 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
1730
1698
|
body: {
|
|
1731
1699
|
ok: true
|
|
1732
1700
|
}
|
|
1733
|
-
}
|
|
1701
|
+
},
|
|
1702
|
+
metadata: results2.metadata
|
|
1734
1703
|
};
|
|
1735
1704
|
}
|
|
1736
1705
|
const handler = __privateGet(this, _registeredHttpSourceHandlers)[source.key];
|
|
@@ -1767,19 +1736,33 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
1767
1736
|
body: {
|
|
1768
1737
|
ok: true
|
|
1769
1738
|
}
|
|
1770
|
-
}
|
|
1739
|
+
},
|
|
1740
|
+
metadata: results.metadata
|
|
1771
1741
|
};
|
|
1772
1742
|
}, "#handleHttpSourceRequest");
|
|
1773
1743
|
function dynamicTriggerRegisterSourceJobId(id) {
|
|
1774
1744
|
return `register-dynamic-trigger-${id}`;
|
|
1775
1745
|
}
|
|
1776
1746
|
__name(dynamicTriggerRegisterSourceJobId, "dynamicTriggerRegisterSourceJobId");
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1747
|
+
function deepMergeOptions(obj1, obj2) {
|
|
1748
|
+
const mergedOptions = {
|
|
1749
|
+
...obj1
|
|
1750
|
+
};
|
|
1751
|
+
for (const key in obj2) {
|
|
1752
|
+
if (obj2.hasOwnProperty(key)) {
|
|
1753
|
+
if (key in mergedOptions) {
|
|
1754
|
+
mergedOptions[key] = [
|
|
1755
|
+
...mergedOptions[key],
|
|
1756
|
+
...obj2[key]
|
|
1757
|
+
];
|
|
1758
|
+
} else {
|
|
1759
|
+
mergedOptions[key] = obj2[key];
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
return mergedOptions;
|
|
1781
1764
|
}
|
|
1782
|
-
__name(
|
|
1765
|
+
__name(deepMergeOptions, "deepMergeOptions");
|
|
1783
1766
|
|
|
1784
1767
|
// src/triggers/externalSource.ts
|
|
1785
1768
|
var import_core6 = require("@trigger.dev/core");
|
|
@@ -1795,10 +1778,10 @@ var ExternalSource = class {
|
|
|
1795
1778
|
params: source.params
|
|
1796
1779
|
},
|
|
1797
1780
|
rawEvent
|
|
1798
|
-
}, logger);
|
|
1781
|
+
}, logger, this.options.integration);
|
|
1799
1782
|
}
|
|
1800
|
-
filter(params) {
|
|
1801
|
-
return this.options.filter?.(params) ?? {};
|
|
1783
|
+
filter(params, options) {
|
|
1784
|
+
return this.options.filter?.(params, options) ?? {};
|
|
1802
1785
|
}
|
|
1803
1786
|
properties(params) {
|
|
1804
1787
|
return this.options.properties?.(params) ?? [];
|
|
@@ -1856,7 +1839,7 @@ var ExternalSourceTrigger = class {
|
|
|
1856
1839
|
title: "External Source",
|
|
1857
1840
|
rule: {
|
|
1858
1841
|
event: this.event.name,
|
|
1859
|
-
payload: (0, import_core6.deepMergeFilters)(this.options.source.filter(this.options.params), this.event.filter ?? {}, this.options.params.filter ?? {}),
|
|
1842
|
+
payload: (0, import_core6.deepMergeFilters)(this.options.source.filter(this.options.params, this.options.options), this.event.filter ?? {}, this.options.params.filter ?? {}),
|
|
1860
1843
|
source: this.event.source
|
|
1861
1844
|
},
|
|
1862
1845
|
properties: this.options.source.properties(this.options.params)
|
|
@@ -1867,7 +1850,8 @@ var ExternalSourceTrigger = class {
|
|
|
1867
1850
|
key: slugifyId(this.options.source.key(this.options.params)),
|
|
1868
1851
|
source: this.options.source,
|
|
1869
1852
|
event: this.options.event,
|
|
1870
|
-
params: this.options.params
|
|
1853
|
+
params: this.options.params,
|
|
1854
|
+
options: this.options.options
|
|
1871
1855
|
});
|
|
1872
1856
|
}
|
|
1873
1857
|
get preprocessRuns() {
|
|
@@ -1922,16 +1906,19 @@ var DynamicTrigger = class {
|
|
|
1922
1906
|
payload: (0, import_core7.deepMergeFilters)(this.source.filter(params), this.event.filter ?? {})
|
|
1923
1907
|
},
|
|
1924
1908
|
source: {
|
|
1909
|
+
version: "2",
|
|
1925
1910
|
key,
|
|
1926
1911
|
channel: this.source.channel,
|
|
1927
1912
|
params,
|
|
1928
|
-
|
|
1929
|
-
this.event.name
|
|
1930
|
-
|
|
1913
|
+
options: {
|
|
1914
|
+
event: typeof this.event.name === "string" ? [
|
|
1915
|
+
this.event.name
|
|
1916
|
+
] : this.event.name
|
|
1917
|
+
},
|
|
1931
1918
|
integration: {
|
|
1932
1919
|
id: this.source.integration.id,
|
|
1933
1920
|
metadata: this.source.integration.metadata,
|
|
1934
|
-
authSource: this.source.integration.
|
|
1921
|
+
authSource: this.source.integration.authSource
|
|
1935
1922
|
}
|
|
1936
1923
|
}
|
|
1937
1924
|
};
|
|
@@ -2215,7 +2202,6 @@ __name(redactString, "redactString");
|
|
|
2215
2202
|
MissingConnectionNotification,
|
|
2216
2203
|
MissingConnectionResolvedNotification,
|
|
2217
2204
|
TriggerClient,
|
|
2218
|
-
authenticatedTask,
|
|
2219
2205
|
cronTrigger,
|
|
2220
2206
|
eventTrigger,
|
|
2221
2207
|
intervalTrigger,
|
|
@@ -2223,6 +2209,7 @@ __name(redactString, "redactString");
|
|
|
2223
2209
|
missingConnectionNotification,
|
|
2224
2210
|
missingConnectionResolvedNotification,
|
|
2225
2211
|
omit,
|
|
2226
|
-
redactString
|
|
2212
|
+
redactString,
|
|
2213
|
+
retry
|
|
2227
2214
|
});
|
|
2228
2215
|
//# sourceMappingURL=index.js.map
|