@trigger.dev/sdk 2.0.0-next.2 → 2.0.0-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -25
- package/dist/index.d.ts +1332 -949
- package/dist/index.js +419 -156
- package/dist/index.js.map +1 -1
- package/package.json +20 -19
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
9
|
var __export = (target, all) => {
|
|
@@ -16,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
}
|
|
17
19
|
return to;
|
|
18
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
19
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
26
|
var __accessCheck = (obj, member, msg) => {
|
|
21
27
|
if (!member.has(obj))
|
|
@@ -112,6 +118,9 @@ var Job = class {
|
|
|
112
118
|
return acc;
|
|
113
119
|
}, {});
|
|
114
120
|
}
|
|
121
|
+
get logLevel() {
|
|
122
|
+
return this.options.logLevel;
|
|
123
|
+
}
|
|
115
124
|
toJSON() {
|
|
116
125
|
const internal = this.options.__internal;
|
|
117
126
|
return {
|
|
@@ -145,9 +154,10 @@ var logLevels = [
|
|
|
145
154
|
"info",
|
|
146
155
|
"debug"
|
|
147
156
|
];
|
|
148
|
-
var _name, _level, _filteredKeys, _jsonReplacer;
|
|
157
|
+
var _name, _level, _filteredKeys, _jsonReplacer, _structuredLog, structuredLog_fn;
|
|
149
158
|
var _Logger = class {
|
|
150
159
|
constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
|
|
160
|
+
__privateAdd(this, _structuredLog);
|
|
151
161
|
__privateAdd(this, _name, void 0);
|
|
152
162
|
__privateAdd(this, _level, void 0);
|
|
153
163
|
__privateAdd(this, _filteredKeys, []);
|
|
@@ -160,36 +170,33 @@ var _Logger = class {
|
|
|
160
170
|
filter(...keys) {
|
|
161
171
|
return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
|
|
162
172
|
}
|
|
163
|
-
|
|
173
|
+
static satisfiesLogLevel(logLevel, setLevel) {
|
|
174
|
+
return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
|
|
175
|
+
}
|
|
176
|
+
log(message, ...args) {
|
|
164
177
|
if (__privateGet(this, _level) < 0)
|
|
165
178
|
return;
|
|
166
|
-
|
|
179
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.log, message, ...args);
|
|
167
180
|
}
|
|
168
|
-
error(...args) {
|
|
181
|
+
error(message, ...args) {
|
|
169
182
|
if (__privateGet(this, _level) < 1)
|
|
170
183
|
return;
|
|
171
|
-
|
|
184
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.error, message, ...args);
|
|
172
185
|
}
|
|
173
|
-
warn(...args) {
|
|
186
|
+
warn(message, ...args) {
|
|
174
187
|
if (__privateGet(this, _level) < 2)
|
|
175
188
|
return;
|
|
176
|
-
|
|
189
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.warn, message, ...args);
|
|
177
190
|
}
|
|
178
|
-
info(...args) {
|
|
191
|
+
info(message, ...args) {
|
|
179
192
|
if (__privateGet(this, _level) < 3)
|
|
180
193
|
return;
|
|
181
|
-
|
|
194
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.info, message, ...args);
|
|
182
195
|
}
|
|
183
196
|
debug(message, ...args) {
|
|
184
197
|
if (__privateGet(this, _level) < 4)
|
|
185
198
|
return;
|
|
186
|
-
|
|
187
|
-
timestamp: new Date(),
|
|
188
|
-
name: __privateGet(this, _name),
|
|
189
|
-
message,
|
|
190
|
-
args: structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys))
|
|
191
|
-
};
|
|
192
|
-
console.debug(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
|
|
199
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.debug, message, ...args);
|
|
193
200
|
}
|
|
194
201
|
};
|
|
195
202
|
var Logger = _Logger;
|
|
@@ -198,6 +205,16 @@ _name = new WeakMap();
|
|
|
198
205
|
_level = new WeakMap();
|
|
199
206
|
_filteredKeys = new WeakMap();
|
|
200
207
|
_jsonReplacer = new WeakMap();
|
|
208
|
+
_structuredLog = new WeakSet();
|
|
209
|
+
structuredLog_fn = /* @__PURE__ */ __name(function(loggerFunction, message, ...args) {
|
|
210
|
+
const structuredLog = {
|
|
211
|
+
...structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys)),
|
|
212
|
+
timestamp: new Date(),
|
|
213
|
+
name: __privateGet(this, _name),
|
|
214
|
+
message
|
|
215
|
+
};
|
|
216
|
+
loggerFunction(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
|
|
217
|
+
}, "#structuredLog");
|
|
201
218
|
function createReplacer(replacer) {
|
|
202
219
|
return (key, value) => {
|
|
203
220
|
if (typeof value === "bigint") {
|
|
@@ -225,19 +242,6 @@ function safeJsonClone(obj) {
|
|
|
225
242
|
}
|
|
226
243
|
}
|
|
227
244
|
__name(safeJsonClone, "safeJsonClone");
|
|
228
|
-
function formattedDateTime() {
|
|
229
|
-
const date = new Date();
|
|
230
|
-
const hours = date.getHours();
|
|
231
|
-
const minutes = date.getMinutes();
|
|
232
|
-
const seconds = date.getSeconds();
|
|
233
|
-
const milliseconds = date.getMilliseconds();
|
|
234
|
-
const formattedHours = hours < 10 ? `0${hours}` : hours;
|
|
235
|
-
const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes;
|
|
236
|
-
const formattedSeconds = seconds < 10 ? `0${seconds}` : seconds;
|
|
237
|
-
const formattedMilliseconds = milliseconds < 10 ? `00${milliseconds}` : milliseconds < 100 ? `0${milliseconds}` : milliseconds;
|
|
238
|
-
return `${formattedHours}:${formattedMinutes}:${formattedSeconds}.${formattedMilliseconds}`;
|
|
239
|
-
}
|
|
240
|
-
__name(formattedDateTime, "formattedDateTime");
|
|
241
245
|
function structureArgs(args, filteredKeys = []) {
|
|
242
246
|
if (args.length === 0) {
|
|
243
247
|
return;
|
|
@@ -405,7 +409,8 @@ var TaskStatusSchema = import_zod7.z.enum([
|
|
|
405
409
|
"WAITING",
|
|
406
410
|
"RUNNING",
|
|
407
411
|
"COMPLETED",
|
|
408
|
-
"ERRORED"
|
|
412
|
+
"ERRORED",
|
|
413
|
+
"CANCELED"
|
|
409
414
|
]);
|
|
410
415
|
var TaskSchema = import_zod7.z.object({
|
|
411
416
|
id: import_zod7.z.string(),
|
|
@@ -418,6 +423,7 @@ var TaskSchema = import_zod7.z.object({
|
|
|
418
423
|
status: TaskStatusSchema,
|
|
419
424
|
description: import_zod7.z.string().optional().nullable(),
|
|
420
425
|
properties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
|
|
426
|
+
outputProperties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
|
|
421
427
|
params: DeserializedJsonSchema.optional().nullable(),
|
|
422
428
|
output: DeserializedJsonSchema.optional().nullable(),
|
|
423
429
|
error: import_zod7.z.string().optional().nullable(),
|
|
@@ -589,14 +595,22 @@ var SourceMetadataSchema = import_zod9.z.object({
|
|
|
589
595
|
integration: IntegrationConfigSchema,
|
|
590
596
|
key: import_zod9.z.string(),
|
|
591
597
|
params: import_zod9.z.any(),
|
|
592
|
-
events: import_zod9.z.array(import_zod9.z.string())
|
|
598
|
+
events: import_zod9.z.array(import_zod9.z.string()),
|
|
599
|
+
registerSourceJob: import_zod9.z.object({
|
|
600
|
+
id: import_zod9.z.string(),
|
|
601
|
+
version: import_zod9.z.string()
|
|
602
|
+
}).optional()
|
|
593
603
|
});
|
|
594
604
|
var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
|
|
595
605
|
id: import_zod9.z.string(),
|
|
596
606
|
jobs: import_zod9.z.array(JobMetadataSchema.pick({
|
|
597
607
|
id: true,
|
|
598
608
|
version: true
|
|
599
|
-
}))
|
|
609
|
+
})),
|
|
610
|
+
registerSourceJob: import_zod9.z.object({
|
|
611
|
+
id: import_zod9.z.string(),
|
|
612
|
+
version: import_zod9.z.string()
|
|
613
|
+
}).optional()
|
|
600
614
|
});
|
|
601
615
|
var IndexEndpointResponseSchema = import_zod9.z.object({
|
|
602
616
|
jobs: import_zod9.z.array(JobMetadataSchema),
|
|
@@ -605,12 +619,12 @@ var IndexEndpointResponseSchema = import_zod9.z.object({
|
|
|
605
619
|
dynamicSchedules: import_zod9.z.array(RegisterDynamicSchedulePayloadSchema)
|
|
606
620
|
});
|
|
607
621
|
var RawEventSchema = import_zod9.z.object({
|
|
608
|
-
id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
|
|
609
622
|
name: import_zod9.z.string(),
|
|
610
|
-
source: import_zod9.z.string().optional(),
|
|
611
623
|
payload: import_zod9.z.any(),
|
|
612
624
|
context: import_zod9.z.any().optional(),
|
|
613
|
-
|
|
625
|
+
id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
|
|
626
|
+
timestamp: import_zod9.z.coerce.date().optional(),
|
|
627
|
+
source: import_zod9.z.string().optional()
|
|
614
628
|
});
|
|
615
629
|
var ApiEventLogSchema = import_zod9.z.object({
|
|
616
630
|
id: import_zod9.z.string(),
|
|
@@ -622,7 +636,7 @@ var ApiEventLogSchema = import_zod9.z.object({
|
|
|
622
636
|
deliveredAt: import_zod9.z.coerce.date().optional().nullable()
|
|
623
637
|
});
|
|
624
638
|
var SendEventOptionsSchema = import_zod9.z.object({
|
|
625
|
-
deliverAt: import_zod9.z.
|
|
639
|
+
deliverAt: import_zod9.z.coerce.date().optional(),
|
|
626
640
|
deliverAfter: import_zod9.z.number().int().optional(),
|
|
627
641
|
accountId: import_zod9.z.string().optional()
|
|
628
642
|
});
|
|
@@ -639,6 +653,10 @@ var RuntimeEnvironmentTypeSchema = import_zod9.z.enum([
|
|
|
639
653
|
"DEVELOPMENT",
|
|
640
654
|
"PREVIEW"
|
|
641
655
|
]);
|
|
656
|
+
var RunSourceContextSchema = import_zod9.z.object({
|
|
657
|
+
id: import_zod9.z.string(),
|
|
658
|
+
metadata: import_zod9.z.any()
|
|
659
|
+
});
|
|
642
660
|
var RunJobBodySchema = import_zod9.z.object({
|
|
643
661
|
event: ApiEventLogSchema,
|
|
644
662
|
job: import_zod9.z.object({
|
|
@@ -648,6 +666,7 @@ var RunJobBodySchema = import_zod9.z.object({
|
|
|
648
666
|
run: import_zod9.z.object({
|
|
649
667
|
id: import_zod9.z.string(),
|
|
650
668
|
isTest: import_zod9.z.boolean(),
|
|
669
|
+
isRetry: import_zod9.z.boolean().default(false),
|
|
651
670
|
startedAt: import_zod9.z.coerce.date()
|
|
652
671
|
}),
|
|
653
672
|
environment: import_zod9.z.object({
|
|
@@ -664,6 +683,7 @@ var RunJobBodySchema = import_zod9.z.object({
|
|
|
664
683
|
id: import_zod9.z.string(),
|
|
665
684
|
metadata: import_zod9.z.any()
|
|
666
685
|
}).optional(),
|
|
686
|
+
source: RunSourceContextSchema.optional(),
|
|
667
687
|
tasks: import_zod9.z.array(CachedTaskSchema).optional(),
|
|
668
688
|
connections: import_zod9.z.record(ConnectionAuthSchema).optional()
|
|
669
689
|
});
|
|
@@ -682,6 +702,10 @@ var RunJobRetryWithTaskSchema = import_zod9.z.object({
|
|
|
682
702
|
error: ErrorWithStackSchema,
|
|
683
703
|
retryAt: import_zod9.z.coerce.date()
|
|
684
704
|
});
|
|
705
|
+
var RunJobCanceledWithTaskSchema = import_zod9.z.object({
|
|
706
|
+
status: import_zod9.z.literal("CANCELED"),
|
|
707
|
+
task: TaskSchema
|
|
708
|
+
});
|
|
685
709
|
var RunJobSuccessSchema = import_zod9.z.object({
|
|
686
710
|
status: import_zod9.z.literal("SUCCESS"),
|
|
687
711
|
output: DeserializedJsonSchema.optional()
|
|
@@ -690,6 +714,7 @@ var RunJobResponseSchema = import_zod9.z.discriminatedUnion("status", [
|
|
|
690
714
|
RunJobErrorSchema,
|
|
691
715
|
RunJobResumeWithTaskSchema,
|
|
692
716
|
RunJobRetryWithTaskSchema,
|
|
717
|
+
RunJobCanceledWithTaskSchema,
|
|
693
718
|
RunJobSuccessSchema
|
|
694
719
|
]);
|
|
695
720
|
var PreprocessRunBodySchema = import_zod9.z.object({
|
|
@@ -768,21 +793,21 @@ var RetryOptionsSchema = import_zod9.z.object({
|
|
|
768
793
|
});
|
|
769
794
|
var RunTaskOptionsSchema = import_zod9.z.object({
|
|
770
795
|
name: import_zod9.z.string(),
|
|
796
|
+
delayUntil: import_zod9.z.coerce.date().optional(),
|
|
797
|
+
retry: RetryOptionsSchema.optional(),
|
|
771
798
|
icon: import_zod9.z.string().optional(),
|
|
772
799
|
displayKey: import_zod9.z.string().optional(),
|
|
773
|
-
noop: import_zod9.z.boolean().default(false),
|
|
774
|
-
operation: import_zod9.z.enum([
|
|
775
|
-
"fetch"
|
|
776
|
-
]).optional(),
|
|
777
|
-
delayUntil: import_zod9.z.coerce.date().optional(),
|
|
778
800
|
description: import_zod9.z.string().optional(),
|
|
779
801
|
properties: import_zod9.z.array(DisplayPropertySchema).optional(),
|
|
780
802
|
params: import_zod9.z.any(),
|
|
781
|
-
trigger: TriggerMetadataSchema.optional(),
|
|
782
|
-
redact: RedactSchema.optional(),
|
|
783
|
-
connectionKey: import_zod9.z.string().optional(),
|
|
784
803
|
style: StyleSchema.optional(),
|
|
785
|
-
|
|
804
|
+
connectionKey: import_zod9.z.string().optional(),
|
|
805
|
+
operation: import_zod9.z.enum([
|
|
806
|
+
"fetch"
|
|
807
|
+
]).optional(),
|
|
808
|
+
noop: import_zod9.z.boolean().default(false),
|
|
809
|
+
redact: RedactSchema.optional(),
|
|
810
|
+
trigger: TriggerMetadataSchema.optional()
|
|
786
811
|
});
|
|
787
812
|
var RunTaskBodyInputSchema = RunTaskOptionsSchema.extend({
|
|
788
813
|
idempotencyKey: import_zod9.z.string(),
|
|
@@ -824,7 +849,8 @@ var RegisterTriggerBodySchema = import_zod9.z.object({
|
|
|
824
849
|
var InitializeTriggerBodySchema = import_zod9.z.object({
|
|
825
850
|
id: import_zod9.z.string(),
|
|
826
851
|
params: import_zod9.z.any(),
|
|
827
|
-
accountId: import_zod9.z.string().optional()
|
|
852
|
+
accountId: import_zod9.z.string().optional(),
|
|
853
|
+
metadata: import_zod9.z.any().optional()
|
|
828
854
|
});
|
|
829
855
|
var RegisterCommonScheduleBodySchema = import_zod9.z.object({
|
|
830
856
|
id: import_zod9.z.string(),
|
|
@@ -942,25 +968,88 @@ var FetchOperationSchema = import_zod11.z.object({
|
|
|
942
968
|
retry: import_zod11.z.record(FetchRetryStrategySchema).optional()
|
|
943
969
|
});
|
|
944
970
|
|
|
971
|
+
// ../internal/src/schemas/events.ts
|
|
972
|
+
var import_zod13 = require("zod");
|
|
973
|
+
|
|
974
|
+
// ../internal/src/schemas/runs.ts
|
|
975
|
+
var import_zod12 = require("zod");
|
|
976
|
+
var RunStatusSchema = import_zod12.z.union([
|
|
977
|
+
import_zod12.z.literal("PENDING"),
|
|
978
|
+
import_zod12.z.literal("QUEUED"),
|
|
979
|
+
import_zod12.z.literal("WAITING_ON_CONNECTIONS"),
|
|
980
|
+
import_zod12.z.literal("PREPROCESSING"),
|
|
981
|
+
import_zod12.z.literal("STARTED"),
|
|
982
|
+
import_zod12.z.literal("SUCCESS"),
|
|
983
|
+
import_zod12.z.literal("FAILURE"),
|
|
984
|
+
import_zod12.z.literal("TIMED_OUT"),
|
|
985
|
+
import_zod12.z.literal("ABORTED"),
|
|
986
|
+
import_zod12.z.literal("CANCELED")
|
|
987
|
+
]);
|
|
988
|
+
var RunTaskSchema = import_zod12.z.object({
|
|
989
|
+
id: import_zod12.z.string(),
|
|
990
|
+
displayKey: import_zod12.z.string().nullable(),
|
|
991
|
+
status: TaskStatusSchema,
|
|
992
|
+
name: import_zod12.z.string(),
|
|
993
|
+
icon: import_zod12.z.string().nullable(),
|
|
994
|
+
startedAt: import_zod12.z.coerce.date().nullable(),
|
|
995
|
+
completedAt: import_zod12.z.coerce.date().nullable()
|
|
996
|
+
});
|
|
997
|
+
var GetRunOptionsSchema = import_zod12.z.object({
|
|
998
|
+
subtasks: import_zod12.z.boolean().optional(),
|
|
999
|
+
cursor: import_zod12.z.string().optional(),
|
|
1000
|
+
take: import_zod12.z.number().optional()
|
|
1001
|
+
});
|
|
1002
|
+
var GetRunOptionsWithTaskDetailsSchema = GetRunOptionsSchema.extend({
|
|
1003
|
+
taskdetails: import_zod12.z.boolean().optional()
|
|
1004
|
+
});
|
|
1005
|
+
var RunSchema = import_zod12.z.object({
|
|
1006
|
+
id: import_zod12.z.string(),
|
|
1007
|
+
status: RunStatusSchema,
|
|
1008
|
+
startedAt: import_zod12.z.coerce.date().nullable(),
|
|
1009
|
+
updatedAt: import_zod12.z.coerce.date().nullable(),
|
|
1010
|
+
completedAt: import_zod12.z.coerce.date().nullable()
|
|
1011
|
+
});
|
|
1012
|
+
var GetRunSchema = RunSchema.extend({
|
|
1013
|
+
output: import_zod12.z.any().optional(),
|
|
1014
|
+
tasks: import_zod12.z.array(RunTaskSchema),
|
|
1015
|
+
nextCursor: import_zod12.z.string().optional()
|
|
1016
|
+
});
|
|
1017
|
+
var GetRunsOptionsSchema = import_zod12.z.object({
|
|
1018
|
+
cursor: import_zod12.z.string().optional(),
|
|
1019
|
+
take: import_zod12.z.number().optional()
|
|
1020
|
+
});
|
|
1021
|
+
var GetRunsSchema = import_zod12.z.object({
|
|
1022
|
+
runs: RunSchema.array(),
|
|
1023
|
+
nextCursor: import_zod12.z.string().optional()
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
// ../internal/src/schemas/events.ts
|
|
1027
|
+
var GetEventSchema = import_zod13.z.object({
|
|
1028
|
+
id: import_zod13.z.string(),
|
|
1029
|
+
name: import_zod13.z.string(),
|
|
1030
|
+
createdAt: import_zod13.z.coerce.date(),
|
|
1031
|
+
updatedAt: import_zod13.z.coerce.date(),
|
|
1032
|
+
runs: import_zod13.z.array(import_zod13.z.object({
|
|
1033
|
+
id: import_zod13.z.string(),
|
|
1034
|
+
status: RunStatusSchema,
|
|
1035
|
+
startedAt: import_zod13.z.coerce.date().optional().nullable(),
|
|
1036
|
+
completedAt: import_zod13.z.coerce.date().optional().nullable()
|
|
1037
|
+
}))
|
|
1038
|
+
});
|
|
1039
|
+
|
|
945
1040
|
// ../internal/src/utils.ts
|
|
946
|
-
function deepMergeFilters(
|
|
947
|
-
const result = {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
if (other.hasOwnProperty(key)) {
|
|
952
|
-
const otherValue = other[key];
|
|
953
|
-
if (typeof otherValue === "object" && !Array.isArray(otherValue) && otherValue !== null) {
|
|
1041
|
+
function deepMergeFilters(...filters) {
|
|
1042
|
+
const result = {};
|
|
1043
|
+
for (const filter of filters) {
|
|
1044
|
+
for (const key in filter) {
|
|
1045
|
+
if (filter.hasOwnProperty(key)) {
|
|
954
1046
|
const filterValue = filter[key];
|
|
955
|
-
|
|
956
|
-
|
|
1047
|
+
const existingValue = result[key];
|
|
1048
|
+
if (existingValue && typeof existingValue === "object" && typeof filterValue === "object" && !Array.isArray(existingValue) && !Array.isArray(filterValue) && existingValue !== null && filterValue !== null) {
|
|
1049
|
+
result[key] = deepMergeFilters(existingValue, filterValue);
|
|
957
1050
|
} else {
|
|
958
|
-
result[key] =
|
|
959
|
-
...other[key]
|
|
960
|
-
};
|
|
1051
|
+
result[key] = filterValue;
|
|
961
1052
|
}
|
|
962
|
-
} else {
|
|
963
|
-
result[key] = other[key];
|
|
964
1053
|
}
|
|
965
1054
|
}
|
|
966
1055
|
}
|
|
@@ -1000,8 +1089,22 @@ var currentDate = {
|
|
|
1000
1089
|
}
|
|
1001
1090
|
};
|
|
1002
1091
|
|
|
1092
|
+
// ../internal/src/searchParams.ts
|
|
1093
|
+
function urlWithSearchParams(url, params) {
|
|
1094
|
+
if (!params) {
|
|
1095
|
+
return url;
|
|
1096
|
+
}
|
|
1097
|
+
const urlObj = new URL(url);
|
|
1098
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1099
|
+
urlObj.searchParams.append(key, String(value));
|
|
1100
|
+
}
|
|
1101
|
+
return urlObj.toString();
|
|
1102
|
+
}
|
|
1103
|
+
__name(urlWithSearchParams, "urlWithSearchParams");
|
|
1104
|
+
|
|
1003
1105
|
// src/apiClient.ts
|
|
1004
|
-
var
|
|
1106
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
1107
|
+
var import_zod14 = require("zod");
|
|
1005
1108
|
var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
|
|
1006
1109
|
var ApiClient = class {
|
|
1007
1110
|
constructor(options) {
|
|
@@ -1019,7 +1122,7 @@ var ApiClient = class {
|
|
|
1019
1122
|
url: options.url,
|
|
1020
1123
|
name: options.name
|
|
1021
1124
|
});
|
|
1022
|
-
const response = await
|
|
1125
|
+
const response = await (0, import_node_fetch.default)(`${__privateGet(this, _apiUrl)}/api/v1/endpoints`, {
|
|
1023
1126
|
method: "POST",
|
|
1024
1127
|
headers: {
|
|
1025
1128
|
"Content-Type": "application/json",
|
|
@@ -1170,8 +1273,8 @@ var ApiClient = class {
|
|
|
1170
1273
|
__privateGet(this, _logger).debug("unregistering schedule", {
|
|
1171
1274
|
id
|
|
1172
1275
|
});
|
|
1173
|
-
const response = await zodfetch(
|
|
1174
|
-
ok:
|
|
1276
|
+
const response = await zodfetch(import_zod14.z.object({
|
|
1277
|
+
ok: import_zod14.z.boolean()
|
|
1175
1278
|
}), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
|
|
1176
1279
|
method: "DELETE",
|
|
1177
1280
|
headers: {
|
|
@@ -1197,6 +1300,42 @@ var ApiClient = class {
|
|
|
1197
1300
|
});
|
|
1198
1301
|
return response;
|
|
1199
1302
|
}
|
|
1303
|
+
async getEvent(eventId) {
|
|
1304
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1305
|
+
__privateGet(this, _logger).debug("Getting Event", {
|
|
1306
|
+
eventId
|
|
1307
|
+
});
|
|
1308
|
+
return await zodfetch(GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
|
|
1309
|
+
method: "GET",
|
|
1310
|
+
headers: {
|
|
1311
|
+
Authorization: `Bearer ${apiKey}`
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
async getRun(runId, options) {
|
|
1316
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1317
|
+
__privateGet(this, _logger).debug("Getting Run", {
|
|
1318
|
+
runId
|
|
1319
|
+
});
|
|
1320
|
+
return await zodfetch(GetRunSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
|
|
1321
|
+
method: "GET",
|
|
1322
|
+
headers: {
|
|
1323
|
+
Authorization: `Bearer ${apiKey}`
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
async getRuns(jobSlug, options) {
|
|
1328
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1329
|
+
__privateGet(this, _logger).debug("Getting Runs", {
|
|
1330
|
+
jobSlug
|
|
1331
|
+
});
|
|
1332
|
+
return await zodfetch(GetRunsSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
|
|
1333
|
+
method: "GET",
|
|
1334
|
+
headers: {
|
|
1335
|
+
Authorization: `Bearer ${apiKey}`
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1200
1339
|
};
|
|
1201
1340
|
__name(ApiClient, "ApiClient");
|
|
1202
1341
|
_apiUrl = new WeakMap();
|
|
@@ -1233,7 +1372,7 @@ function getApiKey(key) {
|
|
|
1233
1372
|
}
|
|
1234
1373
|
__name(getApiKey, "getApiKey");
|
|
1235
1374
|
async function zodfetch(schema, url, requestInit, options) {
|
|
1236
|
-
const response = await
|
|
1375
|
+
const response = await (0, import_node_fetch.default)(url, requestInit);
|
|
1237
1376
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
1238
1377
|
return;
|
|
1239
1378
|
}
|
|
@@ -1264,8 +1403,14 @@ var RetryWithTaskError = class {
|
|
|
1264
1403
|
}
|
|
1265
1404
|
};
|
|
1266
1405
|
__name(RetryWithTaskError, "RetryWithTaskError");
|
|
1406
|
+
var CanceledWithTaskError = class {
|
|
1407
|
+
constructor(task) {
|
|
1408
|
+
this.task = task;
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
__name(CanceledWithTaskError, "CanceledWithTaskError");
|
|
1267
1412
|
function isTriggerError(err) {
|
|
1268
|
-
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError;
|
|
1413
|
+
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError;
|
|
1269
1414
|
}
|
|
1270
1415
|
__name(isTriggerError, "isTriggerError");
|
|
1271
1416
|
|
|
@@ -1288,6 +1433,15 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1288
1433
|
const ioConnection = {
|
|
1289
1434
|
client
|
|
1290
1435
|
};
|
|
1436
|
+
ioConnection.runTask = async (key, callback, options) => {
|
|
1437
|
+
return await io.runTask(key, {
|
|
1438
|
+
name: "Task",
|
|
1439
|
+
icon: integration.metadata.id,
|
|
1440
|
+
...options
|
|
1441
|
+
}, async (ioTask) => {
|
|
1442
|
+
return await callback(client, ioTask, io);
|
|
1443
|
+
});
|
|
1444
|
+
};
|
|
1291
1445
|
if (integration.client.tasks) {
|
|
1292
1446
|
const tasks = integration.client.tasks;
|
|
1293
1447
|
Object.keys(tasks).forEach((taskName) => {
|
|
@@ -1329,6 +1483,8 @@ var IO = class {
|
|
|
1329
1483
|
this._triggerClient = options.client;
|
|
1330
1484
|
this._logger = options.logger ?? new Logger("trigger.dev", options.logLevel);
|
|
1331
1485
|
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
1486
|
+
this._jobLogger = options.jobLogger;
|
|
1487
|
+
this._jobLogLevel = options.jobLogLevel;
|
|
1332
1488
|
if (options.cachedTasks) {
|
|
1333
1489
|
options.cachedTasks.forEach((task) => {
|
|
1334
1490
|
this._cachedTasks.set(task.id, task);
|
|
@@ -1339,45 +1495,57 @@ var IO = class {
|
|
|
1339
1495
|
}
|
|
1340
1496
|
get logger() {
|
|
1341
1497
|
return new IOLogger(async (level, message, data) => {
|
|
1498
|
+
let logLevel = "info";
|
|
1342
1499
|
switch (level) {
|
|
1500
|
+
case "LOG": {
|
|
1501
|
+
this._jobLogger?.log(message, data);
|
|
1502
|
+
logLevel = "log";
|
|
1503
|
+
break;
|
|
1504
|
+
}
|
|
1343
1505
|
case "DEBUG": {
|
|
1344
|
-
this.
|
|
1506
|
+
this._jobLogger?.debug(message, data);
|
|
1507
|
+
logLevel = "debug";
|
|
1345
1508
|
break;
|
|
1346
1509
|
}
|
|
1347
1510
|
case "INFO": {
|
|
1348
|
-
this.
|
|
1511
|
+
this._jobLogger?.info(message, data);
|
|
1512
|
+
logLevel = "info";
|
|
1349
1513
|
break;
|
|
1350
1514
|
}
|
|
1351
1515
|
case "WARN": {
|
|
1352
|
-
this.
|
|
1516
|
+
this._jobLogger?.warn(message, data);
|
|
1517
|
+
logLevel = "warn";
|
|
1353
1518
|
break;
|
|
1354
1519
|
}
|
|
1355
1520
|
case "ERROR": {
|
|
1356
|
-
this.
|
|
1521
|
+
this._jobLogger?.error(message, data);
|
|
1522
|
+
logLevel = "error";
|
|
1357
1523
|
break;
|
|
1358
1524
|
}
|
|
1359
1525
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
style:
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1526
|
+
if (Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
|
|
1527
|
+
await this.runTask([
|
|
1528
|
+
message,
|
|
1529
|
+
level
|
|
1530
|
+
], {
|
|
1531
|
+
name: "log",
|
|
1532
|
+
icon: "log",
|
|
1533
|
+
description: message,
|
|
1534
|
+
params: data,
|
|
1535
|
+
properties: [
|
|
1536
|
+
{
|
|
1537
|
+
label: "Level",
|
|
1538
|
+
text: level
|
|
1539
|
+
}
|
|
1540
|
+
],
|
|
1541
|
+
style: {
|
|
1542
|
+
style: "minimal",
|
|
1543
|
+
variant: level.toLowerCase()
|
|
1544
|
+
},
|
|
1545
|
+
noop: true
|
|
1546
|
+
}, async (task) => {
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1381
1549
|
});
|
|
1382
1550
|
}
|
|
1383
1551
|
async wait(key, seconds) {
|
|
@@ -1432,7 +1600,19 @@ var IO = class {
|
|
|
1432
1600
|
params: {
|
|
1433
1601
|
event,
|
|
1434
1602
|
options
|
|
1435
|
-
}
|
|
1603
|
+
},
|
|
1604
|
+
properties: [
|
|
1605
|
+
{
|
|
1606
|
+
label: "name",
|
|
1607
|
+
text: event.name
|
|
1608
|
+
},
|
|
1609
|
+
...event?.id ? [
|
|
1610
|
+
{
|
|
1611
|
+
label: "ID",
|
|
1612
|
+
text: event.id
|
|
1613
|
+
}
|
|
1614
|
+
] : []
|
|
1615
|
+
]
|
|
1436
1616
|
}, async (task) => {
|
|
1437
1617
|
return await this._triggerClient.sendEvent(event, options);
|
|
1438
1618
|
});
|
|
@@ -1440,13 +1620,14 @@ var IO = class {
|
|
|
1440
1620
|
async updateSource(key, options) {
|
|
1441
1621
|
return this.runTask(key, {
|
|
1442
1622
|
name: "Update Source",
|
|
1443
|
-
description:
|
|
1623
|
+
description: "Update Source",
|
|
1444
1624
|
properties: [
|
|
1445
1625
|
{
|
|
1446
1626
|
label: "key",
|
|
1447
1627
|
text: options.key
|
|
1448
1628
|
}
|
|
1449
1629
|
],
|
|
1630
|
+
params: options,
|
|
1450
1631
|
redact: {
|
|
1451
1632
|
paths: [
|
|
1452
1633
|
"secret"
|
|
@@ -1619,6 +1800,13 @@ var IO = class {
|
|
|
1619
1800
|
...options,
|
|
1620
1801
|
parentId
|
|
1621
1802
|
});
|
|
1803
|
+
if (task.status === "CANCELED") {
|
|
1804
|
+
this._logger.debug("Task canceled", {
|
|
1805
|
+
idempotencyKey,
|
|
1806
|
+
task
|
|
1807
|
+
});
|
|
1808
|
+
throw new CanceledWithTaskError(task);
|
|
1809
|
+
}
|
|
1622
1810
|
if (task.status === "COMPLETED") {
|
|
1623
1811
|
this._logger.debug("Using task output", {
|
|
1624
1812
|
idempotencyKey,
|
|
@@ -1655,21 +1843,36 @@ var IO = class {
|
|
|
1655
1843
|
idempotencyKey,
|
|
1656
1844
|
task
|
|
1657
1845
|
});
|
|
1658
|
-
await this._apiClient.completeTask(this._id, task.id, {
|
|
1659
|
-
output: result ?? void 0
|
|
1846
|
+
const completedTask = await this._apiClient.completeTask(this._id, task.id, {
|
|
1847
|
+
output: result ?? void 0,
|
|
1848
|
+
properties: task.outputProperties ?? void 0
|
|
1660
1849
|
});
|
|
1850
|
+
if (completedTask.status === "CANCELED") {
|
|
1851
|
+
throw new CanceledWithTaskError(completedTask);
|
|
1852
|
+
}
|
|
1661
1853
|
return result;
|
|
1662
1854
|
} catch (error) {
|
|
1663
1855
|
if (isTriggerError(error)) {
|
|
1664
1856
|
throw error;
|
|
1665
1857
|
}
|
|
1666
1858
|
if (onError) {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1859
|
+
try {
|
|
1860
|
+
const onErrorResult = onError(error, task, this);
|
|
1861
|
+
if (onErrorResult) {
|
|
1862
|
+
if (onErrorResult instanceof Error) {
|
|
1863
|
+
error = onErrorResult;
|
|
1864
|
+
} else {
|
|
1865
|
+
const parsedError2 = ErrorWithStackSchema.safeParse(onErrorResult.error);
|
|
1866
|
+
throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
|
|
1867
|
+
message: "Unknown error"
|
|
1868
|
+
}, task, onErrorResult.retryAt);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
} catch (innerError) {
|
|
1872
|
+
if (isTriggerError(innerError)) {
|
|
1873
|
+
throw innerError;
|
|
1874
|
+
}
|
|
1875
|
+
error = innerError;
|
|
1673
1876
|
}
|
|
1674
1877
|
}
|
|
1675
1878
|
const parsedError = ErrorWithStackSchema.safeParse(error);
|
|
@@ -1752,6 +1955,9 @@ var IOLogger = class {
|
|
|
1752
1955
|
constructor(callback) {
|
|
1753
1956
|
this.callback = callback;
|
|
1754
1957
|
}
|
|
1958
|
+
log(message, properties) {
|
|
1959
|
+
return this.callback("LOG", message, properties);
|
|
1960
|
+
}
|
|
1755
1961
|
debug(message, properties) {
|
|
1756
1962
|
return this.callback("DEBUG", message, properties);
|
|
1757
1963
|
}
|
|
@@ -1824,7 +2030,7 @@ var registerSourceEvent = {
|
|
|
1824
2030
|
icon: "register-source",
|
|
1825
2031
|
parsePayload: RegisterSourceEventSchema.parse
|
|
1826
2032
|
};
|
|
1827
|
-
var _options3, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _client,
|
|
2033
|
+
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;
|
|
1828
2034
|
var TriggerClient = class {
|
|
1829
2035
|
constructor(options) {
|
|
1830
2036
|
__privateAdd(this, _preprocessRun);
|
|
@@ -1840,36 +2046,54 @@ var TriggerClient = class {
|
|
|
1840
2046
|
__privateAdd(this, _jobMetadataByDynamicTriggers, {});
|
|
1841
2047
|
__privateAdd(this, _registeredSchedules, {});
|
|
1842
2048
|
__privateAdd(this, _client, void 0);
|
|
1843
|
-
__privateAdd(this,
|
|
2049
|
+
__privateAdd(this, _internalLogger, void 0);
|
|
1844
2050
|
this.id = options.id;
|
|
1845
|
-
this._url = buildClientUrl(options.url);
|
|
1846
2051
|
__privateSet(this, _options3, options);
|
|
1847
2052
|
__privateSet(this, _client, new ApiClient(__privateGet(this, _options3)));
|
|
1848
|
-
__privateSet(this,
|
|
1849
|
-
}
|
|
1850
|
-
get url() {
|
|
1851
|
-
return `${this._url}${this.path ? `${this.path.startsWith("/") ? "" : "/"}${this.path}` : ""}`;
|
|
2053
|
+
__privateSet(this, _internalLogger, new Logger("trigger.dev", __privateGet(this, _options3).verbose ? "debug" : "log"));
|
|
1852
2054
|
}
|
|
1853
2055
|
async handleRequest(request) {
|
|
1854
|
-
__privateGet(this,
|
|
2056
|
+
__privateGet(this, _internalLogger).debug("handling request", {
|
|
1855
2057
|
url: request.url,
|
|
1856
2058
|
headers: Object.fromEntries(request.headers.entries()),
|
|
1857
2059
|
method: request.method
|
|
1858
2060
|
});
|
|
1859
2061
|
const apiKey = request.headers.get("x-trigger-api-key");
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
2062
|
+
const authorization = this.authorized(apiKey);
|
|
2063
|
+
switch (authorization) {
|
|
2064
|
+
case "authorized": {
|
|
2065
|
+
break;
|
|
2066
|
+
}
|
|
2067
|
+
case "missing-client": {
|
|
2068
|
+
return {
|
|
2069
|
+
status: 401,
|
|
2070
|
+
body: {
|
|
2071
|
+
message: "Unauthorized: client missing apiKey"
|
|
2072
|
+
}
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
case "missing-header": {
|
|
2076
|
+
return {
|
|
2077
|
+
status: 401,
|
|
2078
|
+
body: {
|
|
2079
|
+
message: "Unauthorized: missing x-trigger-api-key header"
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
case "unauthorized": {
|
|
2084
|
+
return {
|
|
2085
|
+
status: 401,
|
|
2086
|
+
body: {
|
|
2087
|
+
message: `Forbidden: client apiKey mismatch: Make sure you are using the correct API Key for your environment`
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
1867
2091
|
}
|
|
1868
2092
|
if (request.method !== "POST") {
|
|
1869
2093
|
return {
|
|
1870
2094
|
status: 405,
|
|
1871
2095
|
body: {
|
|
1872
|
-
message: "Method not allowed"
|
|
2096
|
+
message: "Method not allowed (only POST is allowed)"
|
|
1873
2097
|
}
|
|
1874
2098
|
};
|
|
1875
2099
|
}
|
|
@@ -1890,7 +2114,7 @@ var TriggerClient = class {
|
|
|
1890
2114
|
status: 200,
|
|
1891
2115
|
body: {
|
|
1892
2116
|
ok: false,
|
|
1893
|
-
|
|
2117
|
+
error: "Missing endpoint ID"
|
|
1894
2118
|
}
|
|
1895
2119
|
};
|
|
1896
2120
|
}
|
|
@@ -1899,7 +2123,7 @@ var TriggerClient = class {
|
|
|
1899
2123
|
status: 200,
|
|
1900
2124
|
body: {
|
|
1901
2125
|
ok: false,
|
|
1902
|
-
|
|
2126
|
+
error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
|
|
1903
2127
|
}
|
|
1904
2128
|
};
|
|
1905
2129
|
}
|
|
@@ -1932,7 +2156,11 @@ var TriggerClient = class {
|
|
|
1932
2156
|
sources: Object.values(__privateGet(this, _registeredSources)),
|
|
1933
2157
|
dynamicTriggers: Object.values(__privateGet(this, _registeredDynamicTriggers)).map((trigger) => ({
|
|
1934
2158
|
id: trigger.id,
|
|
1935
|
-
jobs: __privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] ?? []
|
|
2159
|
+
jobs: __privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] ?? [],
|
|
2160
|
+
registerSourceJob: {
|
|
2161
|
+
id: dynamicTriggerRegisterSourceJobId(trigger.id),
|
|
2162
|
+
version: trigger.source.version
|
|
2163
|
+
}
|
|
1936
2164
|
})),
|
|
1937
2165
|
dynamicSchedules: Object.entries(__privateGet(this, _registeredSchedules)).map(([id, jobs]) => ({
|
|
1938
2166
|
id,
|
|
@@ -2034,11 +2262,19 @@ var TriggerClient = class {
|
|
|
2034
2262
|
}
|
|
2035
2263
|
};
|
|
2036
2264
|
}
|
|
2037
|
-
const
|
|
2265
|
+
const sourceRequestNeedsBody = headers.data["x-ts-http-method"] !== "GET";
|
|
2266
|
+
const sourceRequestInit = {
|
|
2038
2267
|
method: headers.data["x-ts-http-method"],
|
|
2039
2268
|
headers: headers.data["x-ts-http-headers"],
|
|
2040
|
-
body:
|
|
2041
|
-
}
|
|
2269
|
+
body: sourceRequestNeedsBody ? request.body : void 0
|
|
2270
|
+
};
|
|
2271
|
+
if (sourceRequestNeedsBody) {
|
|
2272
|
+
try {
|
|
2273
|
+
sourceRequestInit.duplex = "half";
|
|
2274
|
+
} catch (error) {
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
const sourceRequest = new Request(headers.data["x-ts-http-url"], sourceRequestInit);
|
|
2042
2278
|
const key = headers.data["x-ts-key"];
|
|
2043
2279
|
const dynamicId = headers.data["x-ts-dynamic-id"];
|
|
2044
2280
|
const secret = headers.data["x-ts-secret"];
|
|
@@ -2078,7 +2314,7 @@ var TriggerClient = class {
|
|
|
2078
2314
|
attachDynamicTrigger(trigger) {
|
|
2079
2315
|
__privateGet(this, _registeredDynamicTriggers)[trigger.id] = trigger;
|
|
2080
2316
|
new Job(this, {
|
|
2081
|
-
id:
|
|
2317
|
+
id: dynamicTriggerRegisterSourceJobId(trigger.id),
|
|
2082
2318
|
name: `Register dynamic trigger ${trigger.id}`,
|
|
2083
2319
|
version: trigger.source.version,
|
|
2084
2320
|
trigger: new EventTrigger({
|
|
@@ -2115,7 +2351,7 @@ var TriggerClient = class {
|
|
|
2115
2351
|
}
|
|
2116
2352
|
attachSource(options) {
|
|
2117
2353
|
__privateGet(this, _registeredHttpSourceHandlers)[options.key] = async (s, r) => {
|
|
2118
|
-
return await options.source.handle(s, r, __privateGet(this,
|
|
2354
|
+
return await options.source.handle(s, r, __privateGet(this, _internalLogger));
|
|
2119
2355
|
};
|
|
2120
2356
|
let registeredSource = __privateGet(this, _registeredSources)[options.key];
|
|
2121
2357
|
if (!registeredSource) {
|
|
@@ -2128,6 +2364,10 @@ var TriggerClient = class {
|
|
|
2128
2364
|
id: options.source.integration.id,
|
|
2129
2365
|
metadata: options.source.integration.metadata,
|
|
2130
2366
|
authSource: options.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
|
|
2367
|
+
},
|
|
2368
|
+
registerSourceJob: {
|
|
2369
|
+
id: options.key,
|
|
2370
|
+
version: options.source.version
|
|
2131
2371
|
}
|
|
2132
2372
|
};
|
|
2133
2373
|
}
|
|
@@ -2194,16 +2434,31 @@ var TriggerClient = class {
|
|
|
2194
2434
|
async unregisterSchedule(id, key) {
|
|
2195
2435
|
return __privateGet(this, _client).unregisterSchedule(this.id, id, key);
|
|
2196
2436
|
}
|
|
2437
|
+
async getEvent(eventId) {
|
|
2438
|
+
return __privateGet(this, _client).getEvent(eventId);
|
|
2439
|
+
}
|
|
2440
|
+
async getRun(runId, options) {
|
|
2441
|
+
return __privateGet(this, _client).getRun(runId, options);
|
|
2442
|
+
}
|
|
2443
|
+
async getRuns(jobSlug, options) {
|
|
2444
|
+
return __privateGet(this, _client).getRuns(jobSlug, options);
|
|
2445
|
+
}
|
|
2197
2446
|
authorized(apiKey) {
|
|
2447
|
+
if (typeof apiKey !== "string") {
|
|
2448
|
+
return "missing-header";
|
|
2449
|
+
}
|
|
2198
2450
|
const localApiKey = __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
2199
2451
|
if (!localApiKey) {
|
|
2200
|
-
return
|
|
2452
|
+
return "missing-client";
|
|
2201
2453
|
}
|
|
2202
|
-
return apiKey === localApiKey;
|
|
2454
|
+
return apiKey === localApiKey ? "authorized" : "unauthorized";
|
|
2203
2455
|
}
|
|
2204
2456
|
apiKey() {
|
|
2205
2457
|
return __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
2206
2458
|
}
|
|
2459
|
+
defineJob(options) {
|
|
2460
|
+
return new Job(this, options);
|
|
2461
|
+
}
|
|
2207
2462
|
};
|
|
2208
2463
|
__name(TriggerClient, "TriggerClient");
|
|
2209
2464
|
_options3 = new WeakMap();
|
|
@@ -2214,7 +2469,7 @@ _registeredDynamicTriggers = new WeakMap();
|
|
|
2214
2469
|
_jobMetadataByDynamicTriggers = new WeakMap();
|
|
2215
2470
|
_registeredSchedules = new WeakMap();
|
|
2216
2471
|
_client = new WeakMap();
|
|
2217
|
-
|
|
2472
|
+
_internalLogger = new WeakMap();
|
|
2218
2473
|
_preprocessRun = new WeakSet();
|
|
2219
2474
|
preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
2220
2475
|
const context = __privateMethod(this, _createPreprocessRunContext, createPreprocessRunContext_fn).call(this, body);
|
|
@@ -2227,7 +2482,7 @@ preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
|
2227
2482
|
}, "#preprocessRun");
|
|
2228
2483
|
_executeJob = new WeakSet();
|
|
2229
2484
|
executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
2230
|
-
__privateGet(this,
|
|
2485
|
+
__privateGet(this, _internalLogger).debug("executing job", {
|
|
2231
2486
|
execution: body1,
|
|
2232
2487
|
job: job1.toJSON()
|
|
2233
2488
|
});
|
|
@@ -2236,9 +2491,11 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
|
2236
2491
|
id: body1.run.id,
|
|
2237
2492
|
cachedTasks: body1.tasks,
|
|
2238
2493
|
apiClient: __privateGet(this, _client),
|
|
2239
|
-
logger: __privateGet(this,
|
|
2494
|
+
logger: __privateGet(this, _internalLogger),
|
|
2240
2495
|
client: this,
|
|
2241
|
-
context
|
|
2496
|
+
context,
|
|
2497
|
+
jobLogLevel: job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info",
|
|
2498
|
+
jobLogger: __privateGet(this, _options3).ioLogLocalEnabled ? new Logger(job1.id, job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info") : void 0
|
|
2242
2499
|
});
|
|
2243
2500
|
const ioWithConnections = createIOWithIntegrations(io, body1.connections, job1.options.integrations);
|
|
2244
2501
|
try {
|
|
@@ -2262,6 +2519,12 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
|
2262
2519
|
retryAt: error.retryAt
|
|
2263
2520
|
};
|
|
2264
2521
|
}
|
|
2522
|
+
if (error instanceof CanceledWithTaskError) {
|
|
2523
|
+
return {
|
|
2524
|
+
status: "CANCELED",
|
|
2525
|
+
task: error.task
|
|
2526
|
+
};
|
|
2527
|
+
}
|
|
2265
2528
|
if (error instanceof RetryWithTaskError) {
|
|
2266
2529
|
const errorWithStack2 = ErrorWithStackSchema.safeParse(error.cause);
|
|
2267
2530
|
if (errorWithStack2.success) {
|
|
@@ -2296,7 +2559,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
|
2296
2559
|
}, "#executeJob");
|
|
2297
2560
|
_createRunContext = new WeakSet();
|
|
2298
2561
|
createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
2299
|
-
const { event, organization, environment, job, run } = execution;
|
|
2562
|
+
const { event, organization, environment, job, run, source } = execution;
|
|
2300
2563
|
return {
|
|
2301
2564
|
event: {
|
|
2302
2565
|
id: event.id,
|
|
@@ -2308,7 +2571,8 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
|
2308
2571
|
environment,
|
|
2309
2572
|
job,
|
|
2310
2573
|
run,
|
|
2311
|
-
account: execution.account
|
|
2574
|
+
account: execution.account,
|
|
2575
|
+
source
|
|
2312
2576
|
};
|
|
2313
2577
|
}, "#createRunContext");
|
|
2314
2578
|
_createPreprocessRunContext = new WeakSet();
|
|
@@ -2330,13 +2594,13 @@ createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(body2) {
|
|
|
2330
2594
|
}, "#createPreprocessRunContext");
|
|
2331
2595
|
_handleHttpSourceRequest = new WeakSet();
|
|
2332
2596
|
handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourceRequest) {
|
|
2333
|
-
__privateGet(this,
|
|
2597
|
+
__privateGet(this, _internalLogger).debug("Handling HTTP source request", {
|
|
2334
2598
|
source
|
|
2335
2599
|
});
|
|
2336
2600
|
if (source.dynamicId) {
|
|
2337
2601
|
const dynamicTrigger = __privateGet(this, _registeredDynamicTriggers)[source.dynamicId];
|
|
2338
2602
|
if (!dynamicTrigger) {
|
|
2339
|
-
__privateGet(this,
|
|
2603
|
+
__privateGet(this, _internalLogger).debug("No dynamic trigger registered for HTTP source", {
|
|
2340
2604
|
source
|
|
2341
2605
|
});
|
|
2342
2606
|
return {
|
|
@@ -2349,7 +2613,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2349
2613
|
events: []
|
|
2350
2614
|
};
|
|
2351
2615
|
}
|
|
2352
|
-
const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this,
|
|
2616
|
+
const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this, _internalLogger));
|
|
2353
2617
|
if (!results2) {
|
|
2354
2618
|
return {
|
|
2355
2619
|
events: [],
|
|
@@ -2373,7 +2637,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2373
2637
|
}
|
|
2374
2638
|
const handler = __privateGet(this, _registeredHttpSourceHandlers)[source.key];
|
|
2375
2639
|
if (!handler) {
|
|
2376
|
-
__privateGet(this,
|
|
2640
|
+
__privateGet(this, _internalLogger).debug("No handler registered for HTTP source", {
|
|
2377
2641
|
source
|
|
2378
2642
|
});
|
|
2379
2643
|
return {
|
|
@@ -2408,20 +2672,10 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2408
2672
|
}
|
|
2409
2673
|
};
|
|
2410
2674
|
}, "#handleHttpSourceRequest");
|
|
2411
|
-
function
|
|
2412
|
-
|
|
2413
|
-
const host = process.env.TRIGGER_CLIENT_HOST ?? process.env.HOST ?? process.env.HOSTNAME ?? process.env.NOW_URL ?? process.env.VERCEL_URL;
|
|
2414
|
-
if (host) {
|
|
2415
|
-
return "https://" + host;
|
|
2416
|
-
}
|
|
2417
|
-
throw new Error("Could not determine the url for this TriggerClient. Please set the TRIGGER_CLIENT_HOST environment variable or pass in the `url` option to the TriggerClient constructor.");
|
|
2418
|
-
}
|
|
2419
|
-
if (!url.startsWith("http")) {
|
|
2420
|
-
return "https://" + url;
|
|
2421
|
-
}
|
|
2422
|
-
return url;
|
|
2675
|
+
function dynamicTriggerRegisterSourceJobId(id) {
|
|
2676
|
+
return `register-dynamic-trigger-${id}`;
|
|
2423
2677
|
}
|
|
2424
|
-
__name(
|
|
2678
|
+
__name(dynamicTriggerRegisterSourceJobId, "dynamicTriggerRegisterSourceJobId");
|
|
2425
2679
|
|
|
2426
2680
|
// src/integrations.ts
|
|
2427
2681
|
function authenticatedTask(options) {
|
|
@@ -2445,7 +2699,7 @@ var ExternalSource = class {
|
|
|
2445
2699
|
}, logger);
|
|
2446
2700
|
}
|
|
2447
2701
|
filter(params) {
|
|
2448
|
-
return this.options.filter(params);
|
|
2702
|
+
return this.options.filter?.(params) ?? {};
|
|
2449
2703
|
}
|
|
2450
2704
|
properties(params) {
|
|
2451
2705
|
return this.options.properties?.(params) ?? [];
|
|
@@ -2503,7 +2757,7 @@ var ExternalSourceTrigger = class {
|
|
|
2503
2757
|
title: "External Source",
|
|
2504
2758
|
rule: {
|
|
2505
2759
|
event: this.event.name,
|
|
2506
|
-
payload: deepMergeFilters(this.options.source.filter(this.options.params), this.event.filter ?? {}),
|
|
2760
|
+
payload: deepMergeFilters(this.options.source.filter(this.options.params), this.event.filter ?? {}, this.options.params.filter ?? {}),
|
|
2507
2761
|
source: this.event.source
|
|
2508
2762
|
},
|
|
2509
2763
|
properties: this.options.source.properties(this.options.params)
|
|
@@ -2560,6 +2814,7 @@ var DynamicTrigger = class {
|
|
|
2560
2814
|
return __privateGet(this, _options4).event;
|
|
2561
2815
|
}
|
|
2562
2816
|
registeredTriggerForParams(params) {
|
|
2817
|
+
const key = slugifyId(this.source.key(params));
|
|
2563
2818
|
return {
|
|
2564
2819
|
rule: {
|
|
2565
2820
|
event: this.event.name,
|
|
@@ -2567,7 +2822,7 @@ var DynamicTrigger = class {
|
|
|
2567
2822
|
payload: deepMergeFilters(this.source.filter(params), this.event.filter ?? {})
|
|
2568
2823
|
},
|
|
2569
2824
|
source: {
|
|
2570
|
-
key
|
|
2825
|
+
key,
|
|
2571
2826
|
channel: this.source.channel,
|
|
2572
2827
|
params,
|
|
2573
2828
|
events: [
|
|
@@ -2588,7 +2843,7 @@ var DynamicTrigger = class {
|
|
|
2588
2843
|
triggerClient.attachJobToDynamicTrigger(job, this);
|
|
2589
2844
|
}
|
|
2590
2845
|
get preprocessRuns() {
|
|
2591
|
-
return
|
|
2846
|
+
return true;
|
|
2592
2847
|
}
|
|
2593
2848
|
};
|
|
2594
2849
|
__name(DynamicTrigger, "DynamicTrigger");
|
|
@@ -2596,6 +2851,7 @@ _client2 = new WeakMap();
|
|
|
2596
2851
|
_options4 = new WeakMap();
|
|
2597
2852
|
|
|
2598
2853
|
// src/triggers/scheduled.ts
|
|
2854
|
+
var import_cronstrue = __toESM(require("cronstrue"));
|
|
2599
2855
|
var examples = [
|
|
2600
2856
|
{
|
|
2601
2857
|
id: "now",
|
|
@@ -2654,6 +2910,9 @@ var CronTrigger = class {
|
|
|
2654
2910
|
this.options = options;
|
|
2655
2911
|
}
|
|
2656
2912
|
get event() {
|
|
2913
|
+
const humanReadable = import_cronstrue.default.toString(this.options.cron, {
|
|
2914
|
+
throwExceptionOnParseError: false
|
|
2915
|
+
});
|
|
2657
2916
|
return {
|
|
2658
2917
|
name: "trigger.scheduled",
|
|
2659
2918
|
title: "Cron Schedule",
|
|
@@ -2663,8 +2922,12 @@ var CronTrigger = class {
|
|
|
2663
2922
|
parsePayload: ScheduledPayloadSchema.parse,
|
|
2664
2923
|
properties: [
|
|
2665
2924
|
{
|
|
2666
|
-
label: "
|
|
2925
|
+
label: "cron",
|
|
2667
2926
|
text: this.options.cron
|
|
2927
|
+
},
|
|
2928
|
+
{
|
|
2929
|
+
label: "Schedule",
|
|
2930
|
+
text: humanReadable
|
|
2668
2931
|
}
|
|
2669
2932
|
]
|
|
2670
2933
|
};
|