@trigger.dev/sdk 2.1.9 → 2.2.1
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 +68 -29
- package/dist/index.js +178 -67
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
package/dist/index.js
CHANGED
|
@@ -155,7 +155,6 @@ var import_core7 = require("@trigger.dev/core");
|
|
|
155
155
|
|
|
156
156
|
// src/apiClient.ts
|
|
157
157
|
var import_core = require("@trigger.dev/core");
|
|
158
|
-
var import_node_fetch = __toESM(require("node-fetch"));
|
|
159
158
|
var import_zod = require("zod");
|
|
160
159
|
var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
|
|
161
160
|
var ApiClient = class {
|
|
@@ -174,7 +173,7 @@ var ApiClient = class {
|
|
|
174
173
|
url: options.url,
|
|
175
174
|
name: options.name
|
|
176
175
|
});
|
|
177
|
-
const response = await (
|
|
176
|
+
const response = await fetch(`${__privateGet(this, _apiUrl)}/api/v1/endpoints`, {
|
|
178
177
|
method: "POST",
|
|
179
178
|
headers: {
|
|
180
179
|
"Content-Type": "application/json",
|
|
@@ -467,7 +466,7 @@ function getApiKey(key) {
|
|
|
467
466
|
}
|
|
468
467
|
__name(getApiKey, "getApiKey");
|
|
469
468
|
async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options) {
|
|
470
|
-
const response = await (
|
|
469
|
+
const response = await fetch(url, requestInit);
|
|
471
470
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
472
471
|
return;
|
|
473
472
|
}
|
|
@@ -479,25 +478,25 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
|
|
|
479
478
|
throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
|
|
480
479
|
}
|
|
481
480
|
const jsonBody = await response.json();
|
|
482
|
-
const
|
|
483
|
-
if (!
|
|
481
|
+
const version2 = response.headers.get("trigger-version");
|
|
482
|
+
if (!version2) {
|
|
484
483
|
return {
|
|
485
484
|
version: "unversioned",
|
|
486
485
|
body: unversionedSchema.parse(jsonBody)
|
|
487
486
|
};
|
|
488
487
|
}
|
|
489
|
-
const versionedSchema = versionedSchemaMap[
|
|
488
|
+
const versionedSchema = versionedSchemaMap[version2];
|
|
490
489
|
if (!versionedSchema) {
|
|
491
|
-
throw new Error(`Unknown version ${
|
|
490
|
+
throw new Error(`Unknown version ${version2}`);
|
|
492
491
|
}
|
|
493
492
|
return {
|
|
494
|
-
version,
|
|
493
|
+
version: version2,
|
|
495
494
|
body: versionedSchema.parse(jsonBody)
|
|
496
495
|
};
|
|
497
496
|
}
|
|
498
497
|
__name(zodfetchWithVersions, "zodfetchWithVersions");
|
|
499
498
|
async function zodfetch(schema, url, requestInit, options) {
|
|
500
|
-
const response = await (
|
|
499
|
+
const response = await fetch(url, requestInit);
|
|
501
500
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
502
501
|
return;
|
|
503
502
|
}
|
|
@@ -540,6 +539,23 @@ var YieldExecutionError = class {
|
|
|
540
539
|
}
|
|
541
540
|
};
|
|
542
541
|
__name(YieldExecutionError, "YieldExecutionError");
|
|
542
|
+
var AutoYieldExecutionError = class {
|
|
543
|
+
constructor(location, timeRemaining, timeElapsed) {
|
|
544
|
+
this.location = location;
|
|
545
|
+
this.timeRemaining = timeRemaining;
|
|
546
|
+
this.timeElapsed = timeElapsed;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
__name(AutoYieldExecutionError, "AutoYieldExecutionError");
|
|
550
|
+
var AutoYieldWithCompletedTaskExecutionError = class {
|
|
551
|
+
constructor(id, properties, output, data) {
|
|
552
|
+
this.id = id;
|
|
553
|
+
this.properties = properties;
|
|
554
|
+
this.output = output;
|
|
555
|
+
this.data = data;
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
__name(AutoYieldWithCompletedTaskExecutionError, "AutoYieldWithCompletedTaskExecutionError");
|
|
543
559
|
var ParsedPayloadSchemaError = class {
|
|
544
560
|
constructor(schemaErrors) {
|
|
545
561
|
this.schemaErrors = schemaErrors;
|
|
@@ -547,7 +563,7 @@ var ParsedPayloadSchemaError = class {
|
|
|
547
563
|
};
|
|
548
564
|
__name(ParsedPayloadSchemaError, "ParsedPayloadSchemaError");
|
|
549
565
|
function isTriggerError(err) {
|
|
550
|
-
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError;
|
|
566
|
+
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError || err instanceof AutoYieldExecutionError || err instanceof AutoYieldWithCompletedTaskExecutionError;
|
|
551
567
|
}
|
|
552
568
|
__name(isTriggerError, "isTriggerError");
|
|
553
569
|
|
|
@@ -603,10 +619,14 @@ var TriggerStatus = class {
|
|
|
603
619
|
__name(TriggerStatus, "TriggerStatus");
|
|
604
620
|
|
|
605
621
|
// src/io.ts
|
|
606
|
-
var _addToCachedTasks, addToCachedTasks_fn;
|
|
622
|
+
var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _forceYield, forceYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
|
|
607
623
|
var IO = class {
|
|
608
624
|
constructor(options) {
|
|
609
625
|
__privateAdd(this, _addToCachedTasks);
|
|
626
|
+
__privateAdd(this, _detectAutoYield);
|
|
627
|
+
__privateAdd(this, _forceYield);
|
|
628
|
+
__privateAdd(this, _getTimeElapsed);
|
|
629
|
+
__privateAdd(this, _getRemainingTimeInMillis);
|
|
610
630
|
__publicField(this, "brb", this.yield.bind(this));
|
|
611
631
|
this._id = options.id;
|
|
612
632
|
this._apiClient = options.apiClient;
|
|
@@ -615,6 +635,8 @@ var IO = class {
|
|
|
615
635
|
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
616
636
|
this._jobLogger = options.jobLogger;
|
|
617
637
|
this._jobLogLevel = options.jobLogLevel;
|
|
638
|
+
this._timeOrigin = options.timeOrigin;
|
|
639
|
+
this._executionTimeout = options.executionTimeout;
|
|
618
640
|
this._stats = {
|
|
619
641
|
initialCachedTasks: 0,
|
|
620
642
|
lazyLoadedCachedTasks: 0,
|
|
@@ -703,8 +725,8 @@ var IO = class {
|
|
|
703
725
|
}
|
|
704
726
|
});
|
|
705
727
|
}
|
|
706
|
-
async wait(
|
|
707
|
-
return await this.runTask(
|
|
728
|
+
async wait(cacheKey, seconds) {
|
|
729
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
708
730
|
}, {
|
|
709
731
|
name: "wait",
|
|
710
732
|
icon: "clock",
|
|
@@ -718,15 +740,15 @@ var IO = class {
|
|
|
718
740
|
}
|
|
719
741
|
});
|
|
720
742
|
}
|
|
721
|
-
async createStatus(
|
|
722
|
-
const id = typeof
|
|
743
|
+
async createStatus(cacheKey, initialStatus) {
|
|
744
|
+
const id = typeof cacheKey === "string" ? cacheKey : cacheKey.join("-");
|
|
723
745
|
const status = new TriggerStatus(id, this);
|
|
724
|
-
await status.update(
|
|
746
|
+
await status.update(cacheKey, initialStatus);
|
|
725
747
|
return status;
|
|
726
748
|
}
|
|
727
|
-
async backgroundFetch(
|
|
749
|
+
async backgroundFetch(cacheKey, url, requestInit, retry2) {
|
|
728
750
|
const urlObject = new URL(url);
|
|
729
|
-
return await this.runTask(
|
|
751
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
730
752
|
return task.output;
|
|
731
753
|
}, {
|
|
732
754
|
name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
|
|
@@ -755,8 +777,8 @@ var IO = class {
|
|
|
755
777
|
]
|
|
756
778
|
});
|
|
757
779
|
}
|
|
758
|
-
async sendEvent(
|
|
759
|
-
return await this.runTask(
|
|
780
|
+
async sendEvent(cacheKey, event, options) {
|
|
781
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
760
782
|
return await this._triggerClient.sendEvent(event, options);
|
|
761
783
|
}, {
|
|
762
784
|
name: "sendEvent",
|
|
@@ -778,8 +800,8 @@ var IO = class {
|
|
|
778
800
|
]
|
|
779
801
|
});
|
|
780
802
|
}
|
|
781
|
-
async getEvent(
|
|
782
|
-
return await this.runTask(
|
|
803
|
+
async getEvent(cacheKey, id) {
|
|
804
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
783
805
|
return await this._triggerClient.getEvent(id);
|
|
784
806
|
}, {
|
|
785
807
|
name: "getEvent",
|
|
@@ -794,8 +816,8 @@ var IO = class {
|
|
|
794
816
|
]
|
|
795
817
|
});
|
|
796
818
|
}
|
|
797
|
-
async cancelEvent(
|
|
798
|
-
return await this.runTask(
|
|
819
|
+
async cancelEvent(cacheKey, eventId) {
|
|
820
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
799
821
|
return await this._triggerClient.cancelEvent(eventId);
|
|
800
822
|
}, {
|
|
801
823
|
name: "cancelEvent",
|
|
@@ -810,8 +832,8 @@ var IO = class {
|
|
|
810
832
|
]
|
|
811
833
|
});
|
|
812
834
|
}
|
|
813
|
-
async updateSource(
|
|
814
|
-
return this.runTask(
|
|
835
|
+
async updateSource(cacheKey, options) {
|
|
836
|
+
return this.runTask(cacheKey, async (task) => {
|
|
815
837
|
return await this._apiClient.updateSource(this._triggerClient.id, options.key, options);
|
|
816
838
|
}, {
|
|
817
839
|
name: "Update Source",
|
|
@@ -830,8 +852,8 @@ var IO = class {
|
|
|
830
852
|
}
|
|
831
853
|
});
|
|
832
854
|
}
|
|
833
|
-
async registerInterval(
|
|
834
|
-
return await this.runTask(
|
|
855
|
+
async registerInterval(cacheKey, dynamicSchedule, id, options) {
|
|
856
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
835
857
|
return dynamicSchedule.register(id, {
|
|
836
858
|
type: "interval",
|
|
837
859
|
options
|
|
@@ -855,8 +877,8 @@ var IO = class {
|
|
|
855
877
|
params: options
|
|
856
878
|
});
|
|
857
879
|
}
|
|
858
|
-
async unregisterInterval(
|
|
859
|
-
return await this.runTask(
|
|
880
|
+
async unregisterInterval(cacheKey, dynamicSchedule, id) {
|
|
881
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
860
882
|
return dynamicSchedule.unregister(id);
|
|
861
883
|
}, {
|
|
862
884
|
name: "unregister-interval",
|
|
@@ -872,8 +894,8 @@ var IO = class {
|
|
|
872
894
|
]
|
|
873
895
|
});
|
|
874
896
|
}
|
|
875
|
-
async registerCron(
|
|
876
|
-
return await this.runTask(
|
|
897
|
+
async registerCron(cacheKey, dynamicSchedule, id, options) {
|
|
898
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
877
899
|
return dynamicSchedule.register(id, {
|
|
878
900
|
type: "cron",
|
|
879
901
|
options
|
|
@@ -897,8 +919,8 @@ var IO = class {
|
|
|
897
919
|
params: options
|
|
898
920
|
});
|
|
899
921
|
}
|
|
900
|
-
async unregisterCron(
|
|
901
|
-
return await this.runTask(
|
|
922
|
+
async unregisterCron(cacheKey, dynamicSchedule, id) {
|
|
923
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
902
924
|
return dynamicSchedule.unregister(id);
|
|
903
925
|
}, {
|
|
904
926
|
name: "unregister-cron",
|
|
@@ -914,8 +936,8 @@ var IO = class {
|
|
|
914
936
|
]
|
|
915
937
|
});
|
|
916
938
|
}
|
|
917
|
-
async registerTrigger(
|
|
918
|
-
return await this.runTask(
|
|
939
|
+
async registerTrigger(cacheKey, trigger, id, params) {
|
|
940
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
919
941
|
const registration = await this.runTask("register-source", async (subtask1) => {
|
|
920
942
|
return trigger.register(id, params);
|
|
921
943
|
}, {
|
|
@@ -940,29 +962,30 @@ var IO = class {
|
|
|
940
962
|
params
|
|
941
963
|
});
|
|
942
964
|
}
|
|
943
|
-
async getAuth(
|
|
965
|
+
async getAuth(cacheKey, clientId) {
|
|
944
966
|
if (!clientId) {
|
|
945
967
|
return;
|
|
946
968
|
}
|
|
947
|
-
return this.runTask(
|
|
969
|
+
return this.runTask(cacheKey, async (task) => {
|
|
948
970
|
return await this._triggerClient.getAuth(clientId);
|
|
949
971
|
}, {
|
|
950
972
|
name: "get-auth"
|
|
951
973
|
});
|
|
952
974
|
}
|
|
953
|
-
async runTask(
|
|
975
|
+
async runTask(cacheKey, callback, options, onError) {
|
|
976
|
+
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
|
|
954
977
|
const parentId = this._taskStorage.getStore()?.taskId;
|
|
955
978
|
if (parentId) {
|
|
956
979
|
this._logger.debug("Using parent task", {
|
|
957
980
|
parentId,
|
|
958
|
-
|
|
981
|
+
cacheKey,
|
|
959
982
|
options
|
|
960
983
|
});
|
|
961
984
|
}
|
|
962
985
|
const idempotencyKey = await generateIdempotencyKey([
|
|
963
986
|
this._id,
|
|
964
987
|
parentId ?? "",
|
|
965
|
-
|
|
988
|
+
cacheKey
|
|
966
989
|
].flat());
|
|
967
990
|
const cachedTask = this._cachedTasks.get(idempotencyKey);
|
|
968
991
|
if (cachedTask && cachedTask.status === "COMPLETED") {
|
|
@@ -983,7 +1006,7 @@ var IO = class {
|
|
|
983
1006
|
}
|
|
984
1007
|
const response = await this._apiClient.runTask(this._id, {
|
|
985
1008
|
idempotencyKey,
|
|
986
|
-
displayKey: typeof
|
|
1009
|
+
displayKey: typeof cacheKey === "string" ? cacheKey : void 0,
|
|
987
1010
|
noop: false,
|
|
988
1011
|
...options ?? {},
|
|
989
1012
|
parentId
|
|
@@ -991,6 +1014,12 @@ var IO = class {
|
|
|
991
1014
|
cachedTasksCursor: this._cachedTasksCursor
|
|
992
1015
|
});
|
|
993
1016
|
const task = response.version === import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
|
|
1017
|
+
if (task.forceYield) {
|
|
1018
|
+
this._logger.debug("Forcing yield after run task", {
|
|
1019
|
+
idempotencyKey
|
|
1020
|
+
});
|
|
1021
|
+
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_run_task");
|
|
1022
|
+
}
|
|
994
1023
|
if (response.version === import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
|
|
995
1024
|
this._cachedTasksCursor = response.body.cachedTasks?.cursor;
|
|
996
1025
|
for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
|
|
@@ -1032,6 +1061,7 @@ var IO = class {
|
|
|
1032
1061
|
});
|
|
1033
1062
|
throw new Error(task.error ?? task?.output ? JSON.stringify(task.output) : "Task errored");
|
|
1034
1063
|
}
|
|
1064
|
+
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_execute_task", 1500);
|
|
1035
1065
|
const executeTask = /* @__PURE__ */ __name(async () => {
|
|
1036
1066
|
try {
|
|
1037
1067
|
const result = await callback(task, this);
|
|
@@ -1047,14 +1077,22 @@ var IO = class {
|
|
|
1047
1077
|
idempotencyKey,
|
|
1048
1078
|
task
|
|
1049
1079
|
});
|
|
1080
|
+
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_complete_task", 500, task, output);
|
|
1050
1081
|
const completedTask = await this._apiClient.completeTask(this._id, task.id, {
|
|
1051
1082
|
output: output ?? void 0,
|
|
1052
1083
|
properties: task.outputProperties ?? void 0
|
|
1053
1084
|
});
|
|
1085
|
+
if (completedTask.forceYield) {
|
|
1086
|
+
this._logger.debug("Forcing yield after task completed", {
|
|
1087
|
+
idempotencyKey
|
|
1088
|
+
});
|
|
1089
|
+
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_complete_task");
|
|
1090
|
+
}
|
|
1054
1091
|
this._stats.executedTasks++;
|
|
1055
1092
|
if (completedTask.status === "CANCELED") {
|
|
1056
1093
|
throw new CanceledWithTaskError(completedTask);
|
|
1057
1094
|
}
|
|
1095
|
+
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "after_complete_task", 500);
|
|
1058
1096
|
return output;
|
|
1059
1097
|
} catch (error) {
|
|
1060
1098
|
if (isTriggerError(error)) {
|
|
@@ -1131,15 +1169,15 @@ var IO = class {
|
|
|
1131
1169
|
taskId: task.id
|
|
1132
1170
|
}, executeTask);
|
|
1133
1171
|
}
|
|
1134
|
-
yield(
|
|
1172
|
+
yield(cacheKey) {
|
|
1135
1173
|
if (!(0, import_core3.supportsFeature)("yieldExecution", this._serverVersion)) {
|
|
1136
1174
|
console.warn("[trigger.dev] io.yield() is not support by the version of the Trigger.dev server you are using, you will need to upgrade your self-hosted Trigger.dev instance.");
|
|
1137
1175
|
return;
|
|
1138
1176
|
}
|
|
1139
|
-
if (this._yieldedExecutions.includes(
|
|
1177
|
+
if (this._yieldedExecutions.includes(cacheKey)) {
|
|
1140
1178
|
return;
|
|
1141
1179
|
}
|
|
1142
|
-
throw new YieldExecutionError(
|
|
1180
|
+
throw new YieldExecutionError(cacheKey);
|
|
1143
1181
|
}
|
|
1144
1182
|
async try(tryCallback, catchCallback) {
|
|
1145
1183
|
try {
|
|
@@ -1157,6 +1195,39 @@ _addToCachedTasks = new WeakSet();
|
|
|
1157
1195
|
addToCachedTasks_fn = /* @__PURE__ */ __name(function(task) {
|
|
1158
1196
|
this._cachedTasks.set(task.idempotencyKey, task);
|
|
1159
1197
|
}, "#addToCachedTasks");
|
|
1198
|
+
_detectAutoYield = new WeakSet();
|
|
1199
|
+
detectAutoYield_fn = /* @__PURE__ */ __name(function(location, threshold = 1500, task1, output) {
|
|
1200
|
+
const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
|
|
1201
|
+
if (timeRemaining && timeRemaining < threshold) {
|
|
1202
|
+
if (task1) {
|
|
1203
|
+
throw new AutoYieldWithCompletedTaskExecutionError(task1.id, task1.outputProperties ?? [], output, {
|
|
1204
|
+
location,
|
|
1205
|
+
timeRemaining,
|
|
1206
|
+
timeElapsed: __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this)
|
|
1207
|
+
});
|
|
1208
|
+
} else {
|
|
1209
|
+
throw new AutoYieldExecutionError(location, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}, "#detectAutoYield");
|
|
1213
|
+
_forceYield = new WeakSet();
|
|
1214
|
+
forceYield_fn = /* @__PURE__ */ __name(function(location1) {
|
|
1215
|
+
const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
|
|
1216
|
+
if (timeRemaining) {
|
|
1217
|
+
throw new AutoYieldExecutionError(location1, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
|
|
1218
|
+
}
|
|
1219
|
+
}, "#forceYield");
|
|
1220
|
+
_getTimeElapsed = new WeakSet();
|
|
1221
|
+
getTimeElapsed_fn = /* @__PURE__ */ __name(function() {
|
|
1222
|
+
return performance.now() - this._timeOrigin;
|
|
1223
|
+
}, "#getTimeElapsed");
|
|
1224
|
+
_getRemainingTimeInMillis = new WeakSet();
|
|
1225
|
+
getRemainingTimeInMillis_fn = /* @__PURE__ */ __name(function() {
|
|
1226
|
+
if (this._executionTimeout) {
|
|
1227
|
+
return this._executionTimeout - (performance.now() - this._timeOrigin);
|
|
1228
|
+
}
|
|
1229
|
+
return void 0;
|
|
1230
|
+
}, "#getRemainingTimeInMillis");
|
|
1160
1231
|
async function generateIdempotencyKey(keyMaterial) {
|
|
1161
1232
|
const keys = keyMaterial.map((key2) => {
|
|
1162
1233
|
if (typeof key2 === "string") {
|
|
@@ -1607,6 +1678,9 @@ var DynamicSchedule = class {
|
|
|
1607
1678
|
};
|
|
1608
1679
|
__name(DynamicSchedule, "DynamicSchedule");
|
|
1609
1680
|
|
|
1681
|
+
// package.json
|
|
1682
|
+
var version = "2.2.1";
|
|
1683
|
+
|
|
1610
1684
|
// src/triggerClient.ts
|
|
1611
1685
|
var registerSourceEvent = {
|
|
1612
1686
|
name: import_core7.REGISTER_SOURCE_EVENT_V2,
|
|
@@ -1615,7 +1689,7 @@ var registerSourceEvent = {
|
|
|
1615
1689
|
icon: "register-source",
|
|
1616
1690
|
parsePayload: import_core7.RegisterSourceEventSchemaV2.parse
|
|
1617
1691
|
};
|
|
1618
|
-
var _options4, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _authResolvers, _client2, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn, _resolveConnections, resolveConnections_fn, _resolveConnection, resolveConnection_fn, _buildJobsIndex, buildJobsIndex_fn, _buildJobIndex, buildJobIndex_fn, _buildJobIntegrations, buildJobIntegrations_fn, _buildJobIntegration, buildJobIntegration_fn, _logIOStats, logIOStats_fn, _standardResponseHeaders,
|
|
1692
|
+
var _options4, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _authResolvers, _client2, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn, _resolveConnections, resolveConnections_fn, _resolveConnection, resolveConnection_fn, _buildJobsIndex, buildJobsIndex_fn, _buildJobIndex, buildJobIndex_fn, _buildJobIntegrations, buildJobIntegrations_fn, _buildJobIntegration, buildJobIntegration_fn, _logIOStats, logIOStats_fn, _standardResponseHeaders, standardResponseHeaders_fn;
|
|
1619
1693
|
var TriggerClient = class {
|
|
1620
1694
|
constructor(options) {
|
|
1621
1695
|
__privateAdd(this, _preprocessRun);
|
|
@@ -1649,7 +1723,7 @@ var TriggerClient = class {
|
|
|
1649
1723
|
"noopTasksSet"
|
|
1650
1724
|
]));
|
|
1651
1725
|
}
|
|
1652
|
-
async handleRequest(request) {
|
|
1726
|
+
async handleRequest(request, timeOrigin = performance.now()) {
|
|
1653
1727
|
__privateGet(this, _internalLogger).debug("handling request", {
|
|
1654
1728
|
url: request.url,
|
|
1655
1729
|
headers: Object.fromEntries(request.headers.entries()),
|
|
@@ -1668,7 +1742,7 @@ var TriggerClient = class {
|
|
|
1668
1742
|
body: {
|
|
1669
1743
|
message: "Unauthorized: client missing apiKey"
|
|
1670
1744
|
},
|
|
1671
|
-
headers:
|
|
1745
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1672
1746
|
};
|
|
1673
1747
|
}
|
|
1674
1748
|
case "missing-header": {
|
|
@@ -1677,7 +1751,7 @@ var TriggerClient = class {
|
|
|
1677
1751
|
body: {
|
|
1678
1752
|
message: "Unauthorized: missing x-trigger-api-key header"
|
|
1679
1753
|
},
|
|
1680
|
-
headers:
|
|
1754
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1681
1755
|
};
|
|
1682
1756
|
}
|
|
1683
1757
|
case "unauthorized": {
|
|
@@ -1686,7 +1760,7 @@ var TriggerClient = class {
|
|
|
1686
1760
|
body: {
|
|
1687
1761
|
message: `Forbidden: client apiKey mismatch: Make sure you are using the correct API Key for your environment`
|
|
1688
1762
|
},
|
|
1689
|
-
headers:
|
|
1763
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1690
1764
|
};
|
|
1691
1765
|
}
|
|
1692
1766
|
}
|
|
@@ -1696,7 +1770,7 @@ var TriggerClient = class {
|
|
|
1696
1770
|
body: {
|
|
1697
1771
|
message: "Method not allowed (only POST is allowed)"
|
|
1698
1772
|
},
|
|
1699
|
-
headers:
|
|
1773
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1700
1774
|
};
|
|
1701
1775
|
}
|
|
1702
1776
|
const action = request.headers.get("x-trigger-action");
|
|
@@ -1706,7 +1780,7 @@ var TriggerClient = class {
|
|
|
1706
1780
|
body: {
|
|
1707
1781
|
message: "Missing x-trigger-action header"
|
|
1708
1782
|
},
|
|
1709
|
-
headers:
|
|
1783
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1710
1784
|
};
|
|
1711
1785
|
}
|
|
1712
1786
|
switch (action) {
|
|
@@ -1719,7 +1793,7 @@ var TriggerClient = class {
|
|
|
1719
1793
|
ok: false,
|
|
1720
1794
|
error: "Missing endpoint ID"
|
|
1721
1795
|
},
|
|
1722
|
-
headers:
|
|
1796
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1723
1797
|
};
|
|
1724
1798
|
}
|
|
1725
1799
|
if (this.id !== endpointId) {
|
|
@@ -1729,7 +1803,7 @@ var TriggerClient = class {
|
|
|
1729
1803
|
ok: false,
|
|
1730
1804
|
error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
|
|
1731
1805
|
},
|
|
1732
|
-
headers:
|
|
1806
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1733
1807
|
};
|
|
1734
1808
|
}
|
|
1735
1809
|
return {
|
|
@@ -1737,7 +1811,7 @@ var TriggerClient = class {
|
|
|
1737
1811
|
body: {
|
|
1738
1812
|
ok: true
|
|
1739
1813
|
},
|
|
1740
|
-
headers:
|
|
1814
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1741
1815
|
};
|
|
1742
1816
|
}
|
|
1743
1817
|
case "INDEX_ENDPOINT": {
|
|
@@ -1760,7 +1834,7 @@ var TriggerClient = class {
|
|
|
1760
1834
|
return {
|
|
1761
1835
|
status: 200,
|
|
1762
1836
|
body,
|
|
1763
|
-
headers:
|
|
1837
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1764
1838
|
};
|
|
1765
1839
|
}
|
|
1766
1840
|
case "INITIALIZE_TRIGGER": {
|
|
@@ -1786,7 +1860,7 @@ var TriggerClient = class {
|
|
|
1786
1860
|
return {
|
|
1787
1861
|
status: 200,
|
|
1788
1862
|
body: dynamicTrigger.registeredTriggerForParams(body.data.params),
|
|
1789
|
-
headers:
|
|
1863
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1790
1864
|
};
|
|
1791
1865
|
}
|
|
1792
1866
|
case "EXECUTE_JOB": {
|
|
@@ -1809,11 +1883,11 @@ var TriggerClient = class {
|
|
|
1809
1883
|
}
|
|
1810
1884
|
};
|
|
1811
1885
|
}
|
|
1812
|
-
const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job, triggerVersion);
|
|
1886
|
+
const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job, timeOrigin, triggerVersion);
|
|
1813
1887
|
return {
|
|
1814
1888
|
status: 200,
|
|
1815
1889
|
body: results,
|
|
1816
|
-
headers:
|
|
1890
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1817
1891
|
};
|
|
1818
1892
|
}
|
|
1819
1893
|
case "PREPROCESS_RUN": {
|
|
@@ -1843,7 +1917,7 @@ var TriggerClient = class {
|
|
|
1843
1917
|
abort: results.abort,
|
|
1844
1918
|
properties: results.properties
|
|
1845
1919
|
},
|
|
1846
|
-
headers:
|
|
1920
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1847
1921
|
};
|
|
1848
1922
|
}
|
|
1849
1923
|
case "DELIVER_HTTP_SOURCE_REQUEST": {
|
|
@@ -1893,7 +1967,7 @@ var TriggerClient = class {
|
|
|
1893
1967
|
response,
|
|
1894
1968
|
metadata
|
|
1895
1969
|
},
|
|
1896
|
-
headers:
|
|
1970
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1897
1971
|
};
|
|
1898
1972
|
}
|
|
1899
1973
|
case "VALIDATE": {
|
|
@@ -1903,7 +1977,19 @@ var TriggerClient = class {
|
|
|
1903
1977
|
ok: true,
|
|
1904
1978
|
endpointId: this.id
|
|
1905
1979
|
},
|
|
1906
|
-
headers:
|
|
1980
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
case "PROBE_EXECUTION_TIMEOUT": {
|
|
1984
|
+
const json = await request.json();
|
|
1985
|
+
const timeout = json?.timeout ?? 15 * 60 * 1e3;
|
|
1986
|
+
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
1987
|
+
return {
|
|
1988
|
+
status: 200,
|
|
1989
|
+
body: {
|
|
1990
|
+
ok: true
|
|
1991
|
+
},
|
|
1992
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1907
1993
|
};
|
|
1908
1994
|
}
|
|
1909
1995
|
}
|
|
@@ -1912,7 +1998,7 @@ var TriggerClient = class {
|
|
|
1912
1998
|
body: {
|
|
1913
1999
|
message: "Method not allowed"
|
|
1914
2000
|
},
|
|
1915
|
-
headers:
|
|
2001
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1916
2002
|
};
|
|
1917
2003
|
}
|
|
1918
2004
|
defineJob(options) {
|
|
@@ -2114,7 +2200,7 @@ preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
|
2114
2200
|
};
|
|
2115
2201
|
}, "#preprocessRun");
|
|
2116
2202
|
_executeJob = new WeakSet();
|
|
2117
|
-
executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, triggerVersion) {
|
|
2203
|
+
executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, triggerVersion) {
|
|
2118
2204
|
__privateGet(this, _internalLogger).debug("executing job", {
|
|
2119
2205
|
execution: body1,
|
|
2120
2206
|
job: job1.id,
|
|
@@ -2134,7 +2220,9 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, triggerVersio
|
|
|
2134
2220
|
context,
|
|
2135
2221
|
jobLogLevel: job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info",
|
|
2136
2222
|
jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new import_core7.Logger(job1.id, job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info") : void 0,
|
|
2137
|
-
serverVersion: triggerVersion
|
|
2223
|
+
serverVersion: triggerVersion,
|
|
2224
|
+
timeOrigin,
|
|
2225
|
+
executionTimeout: body1.runChunkExecutionLimit
|
|
2138
2226
|
});
|
|
2139
2227
|
const resolvedConnections = await __privateMethod(this, _resolveConnections, resolveConnections_fn).call(this, context, job1.options.integrations, body1.connections);
|
|
2140
2228
|
if (!resolvedConnections.ok) {
|
|
@@ -2162,6 +2250,27 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, triggerVersio
|
|
|
2162
2250
|
if (__privateGet(this, _options4).verbose) {
|
|
2163
2251
|
__privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
|
|
2164
2252
|
}
|
|
2253
|
+
if (error instanceof AutoYieldExecutionError) {
|
|
2254
|
+
return {
|
|
2255
|
+
status: "AUTO_YIELD_EXECUTION",
|
|
2256
|
+
location: error.location,
|
|
2257
|
+
timeRemaining: error.timeRemaining,
|
|
2258
|
+
timeElapsed: error.timeElapsed,
|
|
2259
|
+
limit: body1.runChunkExecutionLimit
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
if (error instanceof AutoYieldWithCompletedTaskExecutionError) {
|
|
2263
|
+
return {
|
|
2264
|
+
status: "AUTO_YIELD_EXECUTION_WITH_COMPLETED_TASK",
|
|
2265
|
+
id: error.id,
|
|
2266
|
+
properties: error.properties,
|
|
2267
|
+
output: error.output,
|
|
2268
|
+
data: {
|
|
2269
|
+
...error.data,
|
|
2270
|
+
limit: body1.runChunkExecutionLimit
|
|
2271
|
+
}
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2165
2274
|
if (error instanceof YieldExecutionError) {
|
|
2166
2275
|
return {
|
|
2167
2276
|
status: "YIELD_EXECUTION",
|
|
@@ -2498,9 +2607,11 @@ logIOStats_fn = /* @__PURE__ */ __name(function(stats) {
|
|
|
2498
2607
|
});
|
|
2499
2608
|
}, "#logIOStats");
|
|
2500
2609
|
_standardResponseHeaders = new WeakSet();
|
|
2501
|
-
|
|
2610
|
+
standardResponseHeaders_fn = /* @__PURE__ */ __name(function(start) {
|
|
2502
2611
|
return {
|
|
2503
|
-
"Trigger-Version": import_core7.API_VERSIONS.LAZY_LOADED_CACHED_TASKS
|
|
2612
|
+
"Trigger-Version": import_core7.API_VERSIONS.LAZY_LOADED_CACHED_TASKS,
|
|
2613
|
+
"Trigger-SDK-Version": version,
|
|
2614
|
+
"X-Trigger-Request-Timing": `dur=${performance.now() - start / 1e3}`
|
|
2504
2615
|
};
|
|
2505
2616
|
}, "#standardResponseHeaders");
|
|
2506
2617
|
function dynamicTriggerRegisterSourceJobId(id) {
|