@trigger.dev/sdk 2.0.0-next.8 → 2.0.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/README.md +2 -2
- package/dist/index.d.ts +1043 -932
- package/dist/index.js +299 -121
- package/dist/index.js.map +1 -1
- package/package.json +20 -19
package/dist/index.js
CHANGED
|
@@ -146,7 +146,7 @@ validate_fn = /* @__PURE__ */ __name(function() {
|
|
|
146
146
|
}
|
|
147
147
|
}, "#validate");
|
|
148
148
|
|
|
149
|
-
// ../
|
|
149
|
+
// ../core/src/logger.ts
|
|
150
150
|
var logLevels = [
|
|
151
151
|
"log",
|
|
152
152
|
"error",
|
|
@@ -154,9 +154,10 @@ var logLevels = [
|
|
|
154
154
|
"info",
|
|
155
155
|
"debug"
|
|
156
156
|
];
|
|
157
|
-
var _name, _level, _filteredKeys, _jsonReplacer;
|
|
157
|
+
var _name, _level, _filteredKeys, _jsonReplacer, _structuredLog, structuredLog_fn;
|
|
158
158
|
var _Logger = class {
|
|
159
159
|
constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
|
|
160
|
+
__privateAdd(this, _structuredLog);
|
|
160
161
|
__privateAdd(this, _name, void 0);
|
|
161
162
|
__privateAdd(this, _level, void 0);
|
|
162
163
|
__privateAdd(this, _filteredKeys, []);
|
|
@@ -172,36 +173,30 @@ var _Logger = class {
|
|
|
172
173
|
static satisfiesLogLevel(logLevel, setLevel) {
|
|
173
174
|
return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
|
|
174
175
|
}
|
|
175
|
-
log(...args) {
|
|
176
|
+
log(message, ...args) {
|
|
176
177
|
if (__privateGet(this, _level) < 0)
|
|
177
178
|
return;
|
|
178
|
-
|
|
179
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.log, message, ...args);
|
|
179
180
|
}
|
|
180
|
-
error(...args) {
|
|
181
|
+
error(message, ...args) {
|
|
181
182
|
if (__privateGet(this, _level) < 1)
|
|
182
183
|
return;
|
|
183
|
-
|
|
184
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.error, message, ...args);
|
|
184
185
|
}
|
|
185
|
-
warn(...args) {
|
|
186
|
+
warn(message, ...args) {
|
|
186
187
|
if (__privateGet(this, _level) < 2)
|
|
187
188
|
return;
|
|
188
|
-
|
|
189
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.warn, message, ...args);
|
|
189
190
|
}
|
|
190
|
-
info(...args) {
|
|
191
|
+
info(message, ...args) {
|
|
191
192
|
if (__privateGet(this, _level) < 3)
|
|
192
193
|
return;
|
|
193
|
-
|
|
194
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.info, message, ...args);
|
|
194
195
|
}
|
|
195
196
|
debug(message, ...args) {
|
|
196
197
|
if (__privateGet(this, _level) < 4)
|
|
197
198
|
return;
|
|
198
|
-
|
|
199
|
-
timestamp: new Date(),
|
|
200
|
-
name: __privateGet(this, _name),
|
|
201
|
-
message,
|
|
202
|
-
args: structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys))
|
|
203
|
-
};
|
|
204
|
-
console.debug(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
|
|
199
|
+
__privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.debug, message, ...args);
|
|
205
200
|
}
|
|
206
201
|
};
|
|
207
202
|
var Logger = _Logger;
|
|
@@ -210,6 +205,16 @@ _name = new WeakMap();
|
|
|
210
205
|
_level = new WeakMap();
|
|
211
206
|
_filteredKeys = new WeakMap();
|
|
212
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");
|
|
213
218
|
function createReplacer(replacer) {
|
|
214
219
|
return (key, value) => {
|
|
215
220
|
if (typeof value === "bigint") {
|
|
@@ -237,19 +242,6 @@ function safeJsonClone(obj) {
|
|
|
237
242
|
}
|
|
238
243
|
}
|
|
239
244
|
__name(safeJsonClone, "safeJsonClone");
|
|
240
|
-
function formattedDateTime() {
|
|
241
|
-
const date = new Date();
|
|
242
|
-
const hours = date.getHours();
|
|
243
|
-
const minutes = date.getMinutes();
|
|
244
|
-
const seconds = date.getSeconds();
|
|
245
|
-
const milliseconds = date.getMilliseconds();
|
|
246
|
-
const formattedHours = hours < 10 ? `0${hours}` : hours;
|
|
247
|
-
const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes;
|
|
248
|
-
const formattedSeconds = seconds < 10 ? `0${seconds}` : seconds;
|
|
249
|
-
const formattedMilliseconds = milliseconds < 10 ? `00${milliseconds}` : milliseconds < 100 ? `0${milliseconds}` : milliseconds;
|
|
250
|
-
return `${formattedHours}:${formattedMinutes}:${formattedSeconds}.${formattedMilliseconds}`;
|
|
251
|
-
}
|
|
252
|
-
__name(formattedDateTime, "formattedDateTime");
|
|
253
245
|
function structureArgs(args, filteredKeys = []) {
|
|
254
246
|
if (args.length === 0) {
|
|
255
247
|
return;
|
|
@@ -278,11 +270,11 @@ function filterKeys(obj, keys) {
|
|
|
278
270
|
}
|
|
279
271
|
__name(filterKeys, "filterKeys");
|
|
280
272
|
|
|
281
|
-
// ../
|
|
273
|
+
// ../core/src/schemas/api.ts
|
|
282
274
|
var import_ulid = require("ulid");
|
|
283
275
|
var import_zod9 = require("zod");
|
|
284
276
|
|
|
285
|
-
// ../
|
|
277
|
+
// ../core/src/schemas/errors.ts
|
|
286
278
|
var import_zod = require("zod");
|
|
287
279
|
var ErrorWithStackSchema = import_zod.z.object({
|
|
288
280
|
message: import_zod.z.string(),
|
|
@@ -290,7 +282,7 @@ var ErrorWithStackSchema = import_zod.z.object({
|
|
|
290
282
|
stack: import_zod.z.string().optional()
|
|
291
283
|
});
|
|
292
284
|
|
|
293
|
-
// ../
|
|
285
|
+
// ../core/src/schemas/eventFilter.ts
|
|
294
286
|
var import_zod2 = require("zod");
|
|
295
287
|
var EventMatcherSchema = import_zod2.z.union([
|
|
296
288
|
import_zod2.z.array(import_zod2.z.string()),
|
|
@@ -302,13 +294,13 @@ var EventFilterSchema = import_zod2.z.lazy(() => import_zod2.z.record(import_zod
|
|
|
302
294
|
EventFilterSchema
|
|
303
295
|
])));
|
|
304
296
|
var EventRuleSchema = import_zod2.z.object({
|
|
305
|
-
event: import_zod2.z.string(),
|
|
297
|
+
event: import_zod2.z.string().or(import_zod2.z.array(import_zod2.z.string())),
|
|
306
298
|
source: import_zod2.z.string(),
|
|
307
299
|
payload: EventFilterSchema.optional(),
|
|
308
300
|
context: EventFilterSchema.optional()
|
|
309
301
|
});
|
|
310
302
|
|
|
311
|
-
// ../
|
|
303
|
+
// ../core/src/schemas/integrations.ts
|
|
312
304
|
var import_zod3 = require("zod");
|
|
313
305
|
var ConnectionAuthSchema = import_zod3.z.object({
|
|
314
306
|
type: import_zod3.z.enum([
|
|
@@ -332,7 +324,7 @@ var IntegrationConfigSchema = import_zod3.z.object({
|
|
|
332
324
|
])
|
|
333
325
|
});
|
|
334
326
|
|
|
335
|
-
// ../
|
|
327
|
+
// ../core/src/schemas/json.ts
|
|
336
328
|
var import_zod4 = require("zod");
|
|
337
329
|
var LiteralSchema = import_zod4.z.union([
|
|
338
330
|
import_zod4.z.string(),
|
|
@@ -360,7 +352,7 @@ var SerializableJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
|
|
|
360
352
|
import_zod4.z.record(SerializableJsonSchema)
|
|
361
353
|
]));
|
|
362
354
|
|
|
363
|
-
// ../
|
|
355
|
+
// ../core/src/schemas/properties.ts
|
|
364
356
|
var import_zod5 = require("zod");
|
|
365
357
|
var DisplayPropertySchema = import_zod5.z.object({
|
|
366
358
|
label: import_zod5.z.string(),
|
|
@@ -376,7 +368,7 @@ var StyleSchema = import_zod5.z.object({
|
|
|
376
368
|
variant: import_zod5.z.string().optional()
|
|
377
369
|
});
|
|
378
370
|
|
|
379
|
-
// ../
|
|
371
|
+
// ../core/src/schemas/schedules.ts
|
|
380
372
|
var import_zod6 = require("zod");
|
|
381
373
|
var ScheduledPayloadSchema = import_zod6.z.object({
|
|
382
374
|
ts: import_zod6.z.coerce.date(),
|
|
@@ -410,14 +402,15 @@ var RegisterDynamicSchedulePayloadSchema = import_zod6.z.object({
|
|
|
410
402
|
}))
|
|
411
403
|
});
|
|
412
404
|
|
|
413
|
-
// ../
|
|
405
|
+
// ../core/src/schemas/tasks.ts
|
|
414
406
|
var import_zod7 = require("zod");
|
|
415
407
|
var TaskStatusSchema = import_zod7.z.enum([
|
|
416
408
|
"PENDING",
|
|
417
409
|
"WAITING",
|
|
418
410
|
"RUNNING",
|
|
419
411
|
"COMPLETED",
|
|
420
|
-
"ERRORED"
|
|
412
|
+
"ERRORED",
|
|
413
|
+
"CANCELED"
|
|
421
414
|
]);
|
|
422
415
|
var TaskSchema = import_zod7.z.object({
|
|
423
416
|
id: import_zod7.z.string(),
|
|
@@ -430,6 +423,7 @@ var TaskSchema = import_zod7.z.object({
|
|
|
430
423
|
status: TaskStatusSchema,
|
|
431
424
|
description: import_zod7.z.string().optional().nullable(),
|
|
432
425
|
properties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
|
|
426
|
+
outputProperties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
|
|
433
427
|
params: DeserializedJsonSchema.optional().nullable(),
|
|
434
428
|
output: DeserializedJsonSchema.optional().nullable(),
|
|
435
429
|
error: import_zod7.z.string().optional().nullable(),
|
|
@@ -450,7 +444,7 @@ var CachedTaskSchema = import_zod7.z.object({
|
|
|
450
444
|
parentId: import_zod7.z.string().optional().nullable()
|
|
451
445
|
});
|
|
452
446
|
|
|
453
|
-
// ../
|
|
447
|
+
// ../core/src/schemas/triggers.ts
|
|
454
448
|
var import_zod8 = require("zod");
|
|
455
449
|
var EventExampleSchema = import_zod8.z.object({
|
|
456
450
|
id: import_zod8.z.string(),
|
|
@@ -459,7 +453,7 @@ var EventExampleSchema = import_zod8.z.object({
|
|
|
459
453
|
payload: import_zod8.z.any()
|
|
460
454
|
});
|
|
461
455
|
var EventSpecificationSchema = import_zod8.z.object({
|
|
462
|
-
name: import_zod8.z.string(),
|
|
456
|
+
name: import_zod8.z.string().or(import_zod8.z.array(import_zod8.z.string())),
|
|
463
457
|
title: import_zod8.z.string(),
|
|
464
458
|
source: import_zod8.z.string(),
|
|
465
459
|
icon: import_zod8.z.string(),
|
|
@@ -474,7 +468,10 @@ var DynamicTriggerMetadataSchema = import_zod8.z.object({
|
|
|
474
468
|
});
|
|
475
469
|
var StaticTriggerMetadataSchema = import_zod8.z.object({
|
|
476
470
|
type: import_zod8.z.literal("static"),
|
|
477
|
-
title: import_zod8.z.
|
|
471
|
+
title: import_zod8.z.union([
|
|
472
|
+
import_zod8.z.string(),
|
|
473
|
+
import_zod8.z.array(import_zod8.z.string())
|
|
474
|
+
]),
|
|
478
475
|
properties: import_zod8.z.array(DisplayPropertySchema).optional(),
|
|
479
476
|
rule: EventRuleSchema
|
|
480
477
|
});
|
|
@@ -488,7 +485,7 @@ var TriggerMetadataSchema = import_zod8.z.discriminatedUnion("type", [
|
|
|
488
485
|
ScheduledTriggerMetadataSchema
|
|
489
486
|
]);
|
|
490
487
|
|
|
491
|
-
// ../
|
|
488
|
+
// ../core/src/schemas/api.ts
|
|
492
489
|
var UpdateTriggerSourceBodySchema = import_zod9.z.object({
|
|
493
490
|
registeredEvents: import_zod9.z.array(import_zod9.z.string()),
|
|
494
491
|
secret: import_zod9.z.string().optional(),
|
|
@@ -601,14 +598,22 @@ var SourceMetadataSchema = import_zod9.z.object({
|
|
|
601
598
|
integration: IntegrationConfigSchema,
|
|
602
599
|
key: import_zod9.z.string(),
|
|
603
600
|
params: import_zod9.z.any(),
|
|
604
|
-
events: import_zod9.z.array(import_zod9.z.string())
|
|
601
|
+
events: import_zod9.z.array(import_zod9.z.string()),
|
|
602
|
+
registerSourceJob: import_zod9.z.object({
|
|
603
|
+
id: import_zod9.z.string(),
|
|
604
|
+
version: import_zod9.z.string()
|
|
605
|
+
}).optional()
|
|
605
606
|
});
|
|
606
607
|
var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
|
|
607
608
|
id: import_zod9.z.string(),
|
|
608
609
|
jobs: import_zod9.z.array(JobMetadataSchema.pick({
|
|
609
610
|
id: true,
|
|
610
611
|
version: true
|
|
611
|
-
}))
|
|
612
|
+
})),
|
|
613
|
+
registerSourceJob: import_zod9.z.object({
|
|
614
|
+
id: import_zod9.z.string(),
|
|
615
|
+
version: import_zod9.z.string()
|
|
616
|
+
}).optional()
|
|
612
617
|
});
|
|
613
618
|
var IndexEndpointResponseSchema = import_zod9.z.object({
|
|
614
619
|
jobs: import_zod9.z.array(JobMetadataSchema),
|
|
@@ -664,6 +669,7 @@ var RunJobBodySchema = import_zod9.z.object({
|
|
|
664
669
|
run: import_zod9.z.object({
|
|
665
670
|
id: import_zod9.z.string(),
|
|
666
671
|
isTest: import_zod9.z.boolean(),
|
|
672
|
+
isRetry: import_zod9.z.boolean().default(false),
|
|
667
673
|
startedAt: import_zod9.z.coerce.date()
|
|
668
674
|
}),
|
|
669
675
|
environment: import_zod9.z.object({
|
|
@@ -699,6 +705,10 @@ var RunJobRetryWithTaskSchema = import_zod9.z.object({
|
|
|
699
705
|
error: ErrorWithStackSchema,
|
|
700
706
|
retryAt: import_zod9.z.coerce.date()
|
|
701
707
|
});
|
|
708
|
+
var RunJobCanceledWithTaskSchema = import_zod9.z.object({
|
|
709
|
+
status: import_zod9.z.literal("CANCELED"),
|
|
710
|
+
task: TaskSchema
|
|
711
|
+
});
|
|
702
712
|
var RunJobSuccessSchema = import_zod9.z.object({
|
|
703
713
|
status: import_zod9.z.literal("SUCCESS"),
|
|
704
714
|
output: DeserializedJsonSchema.optional()
|
|
@@ -707,6 +717,7 @@ var RunJobResponseSchema = import_zod9.z.discriminatedUnion("status", [
|
|
|
707
717
|
RunJobErrorSchema,
|
|
708
718
|
RunJobResumeWithTaskSchema,
|
|
709
719
|
RunJobRetryWithTaskSchema,
|
|
720
|
+
RunJobCanceledWithTaskSchema,
|
|
710
721
|
RunJobSuccessSchema
|
|
711
722
|
]);
|
|
712
723
|
var PreprocessRunBodySchema = import_zod9.z.object({
|
|
@@ -870,7 +881,7 @@ var CreateExternalConnectionBodySchema = import_zod9.z.object({
|
|
|
870
881
|
metadata: import_zod9.z.any()
|
|
871
882
|
});
|
|
872
883
|
|
|
873
|
-
// ../
|
|
884
|
+
// ../core/src/schemas/notifications.ts
|
|
874
885
|
var import_zod10 = require("zod");
|
|
875
886
|
var MISSING_CONNECTION_NOTIFICATION = "dev.trigger.notifications.missingConnection";
|
|
876
887
|
var MISSING_CONNECTION_RESOLVED_NOTIFICATION = "dev.trigger.notifications.missingConnectionResolved";
|
|
@@ -927,58 +938,88 @@ var MissingConnectionResolvedNotificationPayloadSchema = import_zod10.z.discrimi
|
|
|
927
938
|
MissingExternalConnectionResolvedNotificationPayloadSchema
|
|
928
939
|
]);
|
|
929
940
|
|
|
930
|
-
// ../
|
|
941
|
+
// ../core/src/schemas/events.ts
|
|
942
|
+
var import_zod12 = require("zod");
|
|
943
|
+
|
|
944
|
+
// ../core/src/schemas/runs.ts
|
|
931
945
|
var import_zod11 = require("zod");
|
|
932
|
-
var
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
FetchRetryBackoffStrategySchema
|
|
946
|
+
var RunStatusSchema = import_zod11.z.union([
|
|
947
|
+
import_zod11.z.literal("PENDING"),
|
|
948
|
+
import_zod11.z.literal("QUEUED"),
|
|
949
|
+
import_zod11.z.literal("WAITING_ON_CONNECTIONS"),
|
|
950
|
+
import_zod11.z.literal("PREPROCESSING"),
|
|
951
|
+
import_zod11.z.literal("STARTED"),
|
|
952
|
+
import_zod11.z.literal("SUCCESS"),
|
|
953
|
+
import_zod11.z.literal("FAILURE"),
|
|
954
|
+
import_zod11.z.literal("TIMED_OUT"),
|
|
955
|
+
import_zod11.z.literal("ABORTED"),
|
|
956
|
+
import_zod11.z.literal("CANCELED")
|
|
944
957
|
]);
|
|
945
|
-
var
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
958
|
+
var RunTaskSchema = import_zod11.z.object({
|
|
959
|
+
id: import_zod11.z.string(),
|
|
960
|
+
displayKey: import_zod11.z.string().nullable(),
|
|
961
|
+
status: TaskStatusSchema,
|
|
962
|
+
name: import_zod11.z.string(),
|
|
963
|
+
icon: import_zod11.z.string().nullable(),
|
|
964
|
+
startedAt: import_zod11.z.coerce.date().nullable(),
|
|
965
|
+
completedAt: import_zod11.z.coerce.date().nullable()
|
|
966
|
+
});
|
|
967
|
+
var GetRunOptionsSchema = import_zod11.z.object({
|
|
968
|
+
subtasks: import_zod11.z.boolean().optional(),
|
|
969
|
+
cursor: import_zod11.z.string().optional(),
|
|
970
|
+
take: import_zod11.z.number().optional()
|
|
971
|
+
});
|
|
972
|
+
var GetRunOptionsWithTaskDetailsSchema = GetRunOptionsSchema.extend({
|
|
973
|
+
taskdetails: import_zod11.z.boolean().optional()
|
|
974
|
+
});
|
|
975
|
+
var RunSchema = import_zod11.z.object({
|
|
976
|
+
id: import_zod11.z.string(),
|
|
977
|
+
status: RunStatusSchema,
|
|
978
|
+
startedAt: import_zod11.z.coerce.date().nullable(),
|
|
979
|
+
updatedAt: import_zod11.z.coerce.date().nullable(),
|
|
980
|
+
completedAt: import_zod11.z.coerce.date().nullable()
|
|
981
|
+
});
|
|
982
|
+
var GetRunSchema = RunSchema.extend({
|
|
983
|
+
output: import_zod11.z.any().optional(),
|
|
984
|
+
tasks: import_zod11.z.array(RunTaskSchema),
|
|
985
|
+
nextCursor: import_zod11.z.string().optional()
|
|
986
|
+
});
|
|
987
|
+
var GetRunsOptionsSchema = import_zod11.z.object({
|
|
988
|
+
cursor: import_zod11.z.string().optional(),
|
|
989
|
+
take: import_zod11.z.number().optional()
|
|
990
|
+
});
|
|
991
|
+
var GetRunsSchema = import_zod11.z.object({
|
|
992
|
+
runs: RunSchema.array(),
|
|
993
|
+
nextCursor: import_zod11.z.string().optional()
|
|
961
994
|
});
|
|
962
995
|
|
|
963
|
-
// ../
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
996
|
+
// ../core/src/schemas/events.ts
|
|
997
|
+
var GetEventSchema = import_zod12.z.object({
|
|
998
|
+
id: import_zod12.z.string(),
|
|
999
|
+
name: import_zod12.z.string(),
|
|
1000
|
+
createdAt: import_zod12.z.coerce.date(),
|
|
1001
|
+
updatedAt: import_zod12.z.coerce.date(),
|
|
1002
|
+
runs: import_zod12.z.array(import_zod12.z.object({
|
|
1003
|
+
id: import_zod12.z.string(),
|
|
1004
|
+
status: RunStatusSchema,
|
|
1005
|
+
startedAt: import_zod12.z.coerce.date().optional().nullable(),
|
|
1006
|
+
completedAt: import_zod12.z.coerce.date().optional().nullable()
|
|
1007
|
+
}))
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
// ../core/src/utils.ts
|
|
1011
|
+
function deepMergeFilters(...filters) {
|
|
1012
|
+
const result = {};
|
|
1013
|
+
for (const filter of filters) {
|
|
1014
|
+
for (const key in filter) {
|
|
1015
|
+
if (filter.hasOwnProperty(key)) {
|
|
972
1016
|
const filterValue = filter[key];
|
|
973
|
-
|
|
974
|
-
|
|
1017
|
+
const existingValue = result[key];
|
|
1018
|
+
if (existingValue && typeof existingValue === "object" && typeof filterValue === "object" && !Array.isArray(existingValue) && !Array.isArray(filterValue) && existingValue !== null && filterValue !== null) {
|
|
1019
|
+
result[key] = deepMergeFilters(existingValue, filterValue);
|
|
975
1020
|
} else {
|
|
976
|
-
result[key] =
|
|
977
|
-
...other[key]
|
|
978
|
-
};
|
|
1021
|
+
result[key] = filterValue;
|
|
979
1022
|
}
|
|
980
|
-
} else {
|
|
981
|
-
result[key] = other[key];
|
|
982
1023
|
}
|
|
983
1024
|
}
|
|
984
1025
|
}
|
|
@@ -986,7 +1027,7 @@ function deepMergeFilters(filter, other) {
|
|
|
986
1027
|
}
|
|
987
1028
|
__name(deepMergeFilters, "deepMergeFilters");
|
|
988
1029
|
|
|
989
|
-
// ../
|
|
1030
|
+
// ../core/src/retry.ts
|
|
990
1031
|
var DEFAULT_RETRY_OPTIONS = {
|
|
991
1032
|
limit: 5,
|
|
992
1033
|
factor: 1.8,
|
|
@@ -1010,7 +1051,7 @@ function calculateRetryAt(retryOptions, attempts) {
|
|
|
1010
1051
|
}
|
|
1011
1052
|
__name(calculateRetryAt, "calculateRetryAt");
|
|
1012
1053
|
|
|
1013
|
-
// ../
|
|
1054
|
+
// ../core/src/replacements.ts
|
|
1014
1055
|
var currentDate = {
|
|
1015
1056
|
marker: "__CURRENT_DATE__",
|
|
1016
1057
|
replace({ data: { now } }) {
|
|
@@ -1018,8 +1059,22 @@ var currentDate = {
|
|
|
1018
1059
|
}
|
|
1019
1060
|
};
|
|
1020
1061
|
|
|
1062
|
+
// ../core/src/searchParams.ts
|
|
1063
|
+
function urlWithSearchParams(url, params) {
|
|
1064
|
+
if (!params) {
|
|
1065
|
+
return url;
|
|
1066
|
+
}
|
|
1067
|
+
const urlObj = new URL(url);
|
|
1068
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1069
|
+
urlObj.searchParams.append(key, String(value));
|
|
1070
|
+
}
|
|
1071
|
+
return urlObj.toString();
|
|
1072
|
+
}
|
|
1073
|
+
__name(urlWithSearchParams, "urlWithSearchParams");
|
|
1074
|
+
|
|
1021
1075
|
// src/apiClient.ts
|
|
1022
|
-
var
|
|
1076
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
1077
|
+
var import_zod13 = require("zod");
|
|
1023
1078
|
var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
|
|
1024
1079
|
var ApiClient = class {
|
|
1025
1080
|
constructor(options) {
|
|
@@ -1037,7 +1092,7 @@ var ApiClient = class {
|
|
|
1037
1092
|
url: options.url,
|
|
1038
1093
|
name: options.name
|
|
1039
1094
|
});
|
|
1040
|
-
const response = await
|
|
1095
|
+
const response = await (0, import_node_fetch.default)(`${__privateGet(this, _apiUrl)}/api/v1/endpoints`, {
|
|
1041
1096
|
method: "POST",
|
|
1042
1097
|
headers: {
|
|
1043
1098
|
"Content-Type": "application/json",
|
|
@@ -1188,8 +1243,8 @@ var ApiClient = class {
|
|
|
1188
1243
|
__privateGet(this, _logger).debug("unregistering schedule", {
|
|
1189
1244
|
id
|
|
1190
1245
|
});
|
|
1191
|
-
const response = await zodfetch(
|
|
1192
|
-
ok:
|
|
1246
|
+
const response = await zodfetch(import_zod13.z.object({
|
|
1247
|
+
ok: import_zod13.z.boolean()
|
|
1193
1248
|
}), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
|
|
1194
1249
|
method: "DELETE",
|
|
1195
1250
|
headers: {
|
|
@@ -1215,6 +1270,42 @@ var ApiClient = class {
|
|
|
1215
1270
|
});
|
|
1216
1271
|
return response;
|
|
1217
1272
|
}
|
|
1273
|
+
async getEvent(eventId) {
|
|
1274
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1275
|
+
__privateGet(this, _logger).debug("Getting Event", {
|
|
1276
|
+
eventId
|
|
1277
|
+
});
|
|
1278
|
+
return await zodfetch(GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
|
|
1279
|
+
method: "GET",
|
|
1280
|
+
headers: {
|
|
1281
|
+
Authorization: `Bearer ${apiKey}`
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
async getRun(runId, options) {
|
|
1286
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1287
|
+
__privateGet(this, _logger).debug("Getting Run", {
|
|
1288
|
+
runId
|
|
1289
|
+
});
|
|
1290
|
+
return await zodfetch(GetRunSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
|
|
1291
|
+
method: "GET",
|
|
1292
|
+
headers: {
|
|
1293
|
+
Authorization: `Bearer ${apiKey}`
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
async getRuns(jobSlug, options) {
|
|
1298
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1299
|
+
__privateGet(this, _logger).debug("Getting Runs", {
|
|
1300
|
+
jobSlug
|
|
1301
|
+
});
|
|
1302
|
+
return await zodfetch(GetRunsSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
|
|
1303
|
+
method: "GET",
|
|
1304
|
+
headers: {
|
|
1305
|
+
Authorization: `Bearer ${apiKey}`
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1218
1309
|
};
|
|
1219
1310
|
__name(ApiClient, "ApiClient");
|
|
1220
1311
|
_apiUrl = new WeakMap();
|
|
@@ -1251,7 +1342,7 @@ function getApiKey(key) {
|
|
|
1251
1342
|
}
|
|
1252
1343
|
__name(getApiKey, "getApiKey");
|
|
1253
1344
|
async function zodfetch(schema, url, requestInit, options) {
|
|
1254
|
-
const response = await
|
|
1345
|
+
const response = await (0, import_node_fetch.default)(url, requestInit);
|
|
1255
1346
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
1256
1347
|
return;
|
|
1257
1348
|
}
|
|
@@ -1282,8 +1373,14 @@ var RetryWithTaskError = class {
|
|
|
1282
1373
|
}
|
|
1283
1374
|
};
|
|
1284
1375
|
__name(RetryWithTaskError, "RetryWithTaskError");
|
|
1376
|
+
var CanceledWithTaskError = class {
|
|
1377
|
+
constructor(task) {
|
|
1378
|
+
this.task = task;
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
__name(CanceledWithTaskError, "CanceledWithTaskError");
|
|
1285
1382
|
function isTriggerError(err) {
|
|
1286
|
-
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError;
|
|
1383
|
+
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError;
|
|
1287
1384
|
}
|
|
1288
1385
|
__name(isTriggerError, "isTriggerError");
|
|
1289
1386
|
|
|
@@ -1306,6 +1403,22 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1306
1403
|
const ioConnection = {
|
|
1307
1404
|
client
|
|
1308
1405
|
};
|
|
1406
|
+
ioConnection.runTask = async (key, callback, options) => {
|
|
1407
|
+
return await io.runTask(key, {
|
|
1408
|
+
name: "Task",
|
|
1409
|
+
icon: integration.metadata.id,
|
|
1410
|
+
retry: {
|
|
1411
|
+
limit: 10,
|
|
1412
|
+
minTimeoutInMs: 1e3,
|
|
1413
|
+
maxTimeoutInMs: 3e4,
|
|
1414
|
+
factor: 2,
|
|
1415
|
+
randomize: true
|
|
1416
|
+
},
|
|
1417
|
+
...options
|
|
1418
|
+
}, async (ioTask) => {
|
|
1419
|
+
return await callback(client, ioTask, io);
|
|
1420
|
+
});
|
|
1421
|
+
};
|
|
1309
1422
|
if (integration.client.tasks) {
|
|
1310
1423
|
const tasks = integration.client.tasks;
|
|
1311
1424
|
Object.keys(tasks).forEach((taskName) => {
|
|
@@ -1484,13 +1597,14 @@ var IO = class {
|
|
|
1484
1597
|
async updateSource(key, options) {
|
|
1485
1598
|
return this.runTask(key, {
|
|
1486
1599
|
name: "Update Source",
|
|
1487
|
-
description:
|
|
1600
|
+
description: "Update Source",
|
|
1488
1601
|
properties: [
|
|
1489
1602
|
{
|
|
1490
1603
|
label: "key",
|
|
1491
1604
|
text: options.key
|
|
1492
1605
|
}
|
|
1493
1606
|
],
|
|
1607
|
+
params: options,
|
|
1494
1608
|
redact: {
|
|
1495
1609
|
paths: [
|
|
1496
1610
|
"secret"
|
|
@@ -1663,6 +1777,13 @@ var IO = class {
|
|
|
1663
1777
|
...options,
|
|
1664
1778
|
parentId
|
|
1665
1779
|
});
|
|
1780
|
+
if (task.status === "CANCELED") {
|
|
1781
|
+
this._logger.debug("Task canceled", {
|
|
1782
|
+
idempotencyKey,
|
|
1783
|
+
task
|
|
1784
|
+
});
|
|
1785
|
+
throw new CanceledWithTaskError(task);
|
|
1786
|
+
}
|
|
1666
1787
|
if (task.status === "COMPLETED") {
|
|
1667
1788
|
this._logger.debug("Using task output", {
|
|
1668
1789
|
idempotencyKey,
|
|
@@ -1699,21 +1820,36 @@ var IO = class {
|
|
|
1699
1820
|
idempotencyKey,
|
|
1700
1821
|
task
|
|
1701
1822
|
});
|
|
1702
|
-
await this._apiClient.completeTask(this._id, task.id, {
|
|
1703
|
-
output: result ?? void 0
|
|
1823
|
+
const completedTask = await this._apiClient.completeTask(this._id, task.id, {
|
|
1824
|
+
output: result ?? void 0,
|
|
1825
|
+
properties: task.outputProperties ?? void 0
|
|
1704
1826
|
});
|
|
1827
|
+
if (completedTask.status === "CANCELED") {
|
|
1828
|
+
throw new CanceledWithTaskError(completedTask);
|
|
1829
|
+
}
|
|
1705
1830
|
return result;
|
|
1706
1831
|
} catch (error) {
|
|
1707
1832
|
if (isTriggerError(error)) {
|
|
1708
1833
|
throw error;
|
|
1709
1834
|
}
|
|
1710
1835
|
if (onError) {
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1836
|
+
try {
|
|
1837
|
+
const onErrorResult = onError(error, task, this);
|
|
1838
|
+
if (onErrorResult) {
|
|
1839
|
+
if (onErrorResult instanceof Error) {
|
|
1840
|
+
error = onErrorResult;
|
|
1841
|
+
} else {
|
|
1842
|
+
const parsedError2 = ErrorWithStackSchema.safeParse(onErrorResult.error);
|
|
1843
|
+
throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
|
|
1844
|
+
message: "Unknown error"
|
|
1845
|
+
}, task, onErrorResult.retryAt);
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
} catch (innerError) {
|
|
1849
|
+
if (isTriggerError(innerError)) {
|
|
1850
|
+
throw innerError;
|
|
1851
|
+
}
|
|
1852
|
+
error = innerError;
|
|
1717
1853
|
}
|
|
1718
1854
|
}
|
|
1719
1855
|
const parsedError = ErrorWithStackSchema.safeParse(error);
|
|
@@ -1852,6 +1988,7 @@ function eventTrigger(options) {
|
|
|
1852
1988
|
title: "Event",
|
|
1853
1989
|
source: options.source ?? "trigger.dev",
|
|
1854
1990
|
icon: "custom-event",
|
|
1991
|
+
examples: options.examples,
|
|
1855
1992
|
parsePayload: (rawPayload) => {
|
|
1856
1993
|
if (options.schema) {
|
|
1857
1994
|
return options.schema.parse(rawPayload);
|
|
@@ -1925,7 +2062,7 @@ var TriggerClient = class {
|
|
|
1925
2062
|
return {
|
|
1926
2063
|
status: 401,
|
|
1927
2064
|
body: {
|
|
1928
|
-
message: `Forbidden: client apiKey mismatch:
|
|
2065
|
+
message: `Forbidden: client apiKey mismatch: Make sure you are using the correct API Key for your environment`
|
|
1929
2066
|
}
|
|
1930
2067
|
};
|
|
1931
2068
|
}
|
|
@@ -1997,7 +2134,11 @@ var TriggerClient = class {
|
|
|
1997
2134
|
sources: Object.values(__privateGet(this, _registeredSources)),
|
|
1998
2135
|
dynamicTriggers: Object.values(__privateGet(this, _registeredDynamicTriggers)).map((trigger) => ({
|
|
1999
2136
|
id: trigger.id,
|
|
2000
|
-
jobs: __privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] ?? []
|
|
2137
|
+
jobs: __privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] ?? [],
|
|
2138
|
+
registerSourceJob: {
|
|
2139
|
+
id: dynamicTriggerRegisterSourceJobId(trigger.id),
|
|
2140
|
+
version: trigger.source.version
|
|
2141
|
+
}
|
|
2001
2142
|
})),
|
|
2002
2143
|
dynamicSchedules: Object.entries(__privateGet(this, _registeredSchedules)).map(([id, jobs]) => ({
|
|
2003
2144
|
id,
|
|
@@ -2099,11 +2240,19 @@ var TriggerClient = class {
|
|
|
2099
2240
|
}
|
|
2100
2241
|
};
|
|
2101
2242
|
}
|
|
2102
|
-
const
|
|
2243
|
+
const sourceRequestNeedsBody = headers.data["x-ts-http-method"] !== "GET";
|
|
2244
|
+
const sourceRequestInit = {
|
|
2103
2245
|
method: headers.data["x-ts-http-method"],
|
|
2104
2246
|
headers: headers.data["x-ts-http-headers"],
|
|
2105
|
-
body:
|
|
2106
|
-
}
|
|
2247
|
+
body: sourceRequestNeedsBody ? request.body : void 0
|
|
2248
|
+
};
|
|
2249
|
+
if (sourceRequestNeedsBody) {
|
|
2250
|
+
try {
|
|
2251
|
+
sourceRequestInit.duplex = "half";
|
|
2252
|
+
} catch (error) {
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
const sourceRequest = new Request(headers.data["x-ts-http-url"], sourceRequestInit);
|
|
2107
2256
|
const key = headers.data["x-ts-key"];
|
|
2108
2257
|
const dynamicId = headers.data["x-ts-dynamic-id"];
|
|
2109
2258
|
const secret = headers.data["x-ts-secret"];
|
|
@@ -2143,7 +2292,7 @@ var TriggerClient = class {
|
|
|
2143
2292
|
attachDynamicTrigger(trigger) {
|
|
2144
2293
|
__privateGet(this, _registeredDynamicTriggers)[trigger.id] = trigger;
|
|
2145
2294
|
new Job(this, {
|
|
2146
|
-
id:
|
|
2295
|
+
id: dynamicTriggerRegisterSourceJobId(trigger.id),
|
|
2147
2296
|
name: `Register dynamic trigger ${trigger.id}`,
|
|
2148
2297
|
version: trigger.source.version,
|
|
2149
2298
|
trigger: new EventTrigger({
|
|
@@ -2193,12 +2342,18 @@ var TriggerClient = class {
|
|
|
2193
2342
|
id: options.source.integration.id,
|
|
2194
2343
|
metadata: options.source.integration.metadata,
|
|
2195
2344
|
authSource: options.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
|
|
2345
|
+
},
|
|
2346
|
+
registerSourceJob: {
|
|
2347
|
+
id: options.key,
|
|
2348
|
+
version: options.source.version
|
|
2196
2349
|
}
|
|
2197
2350
|
};
|
|
2198
2351
|
}
|
|
2199
2352
|
registeredSource.events = Array.from(/* @__PURE__ */ new Set([
|
|
2200
2353
|
...registeredSource.events,
|
|
2201
|
-
options.event.name
|
|
2354
|
+
...typeof options.event.name === "string" ? [
|
|
2355
|
+
options.event.name
|
|
2356
|
+
] : options.event.name
|
|
2202
2357
|
]));
|
|
2203
2358
|
__privateGet(this, _registeredSources)[options.key] = registeredSource;
|
|
2204
2359
|
new Job(this, {
|
|
@@ -2259,6 +2414,15 @@ var TriggerClient = class {
|
|
|
2259
2414
|
async unregisterSchedule(id, key) {
|
|
2260
2415
|
return __privateGet(this, _client).unregisterSchedule(this.id, id, key);
|
|
2261
2416
|
}
|
|
2417
|
+
async getEvent(eventId) {
|
|
2418
|
+
return __privateGet(this, _client).getEvent(eventId);
|
|
2419
|
+
}
|
|
2420
|
+
async getRun(runId, options) {
|
|
2421
|
+
return __privateGet(this, _client).getRun(runId, options);
|
|
2422
|
+
}
|
|
2423
|
+
async getRuns(jobSlug, options) {
|
|
2424
|
+
return __privateGet(this, _client).getRuns(jobSlug, options);
|
|
2425
|
+
}
|
|
2262
2426
|
authorized(apiKey) {
|
|
2263
2427
|
if (typeof apiKey !== "string") {
|
|
2264
2428
|
return "missing-header";
|
|
@@ -2272,6 +2436,9 @@ var TriggerClient = class {
|
|
|
2272
2436
|
apiKey() {
|
|
2273
2437
|
return __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
2274
2438
|
}
|
|
2439
|
+
defineJob(options) {
|
|
2440
|
+
return new Job(this, options);
|
|
2441
|
+
}
|
|
2275
2442
|
};
|
|
2276
2443
|
__name(TriggerClient, "TriggerClient");
|
|
2277
2444
|
_options3 = new WeakMap();
|
|
@@ -2332,6 +2499,12 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
|
2332
2499
|
retryAt: error.retryAt
|
|
2333
2500
|
};
|
|
2334
2501
|
}
|
|
2502
|
+
if (error instanceof CanceledWithTaskError) {
|
|
2503
|
+
return {
|
|
2504
|
+
status: "CANCELED",
|
|
2505
|
+
task: error.task
|
|
2506
|
+
};
|
|
2507
|
+
}
|
|
2335
2508
|
if (error instanceof RetryWithTaskError) {
|
|
2336
2509
|
const errorWithStack2 = ErrorWithStackSchema.safeParse(error.cause);
|
|
2337
2510
|
if (errorWithStack2.success) {
|
|
@@ -2479,6 +2652,10 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2479
2652
|
}
|
|
2480
2653
|
};
|
|
2481
2654
|
}, "#handleHttpSourceRequest");
|
|
2655
|
+
function dynamicTriggerRegisterSourceJobId(id) {
|
|
2656
|
+
return `register-dynamic-trigger-${id}`;
|
|
2657
|
+
}
|
|
2658
|
+
__name(dynamicTriggerRegisterSourceJobId, "dynamicTriggerRegisterSourceJobId");
|
|
2482
2659
|
|
|
2483
2660
|
// src/integrations.ts
|
|
2484
2661
|
function authenticatedTask(options) {
|
|
@@ -2502,7 +2679,7 @@ var ExternalSource = class {
|
|
|
2502
2679
|
}, logger);
|
|
2503
2680
|
}
|
|
2504
2681
|
filter(params) {
|
|
2505
|
-
return this.options.filter(params);
|
|
2682
|
+
return this.options.filter?.(params) ?? {};
|
|
2506
2683
|
}
|
|
2507
2684
|
properties(params) {
|
|
2508
2685
|
return this.options.properties?.(params) ?? [];
|
|
@@ -2560,7 +2737,7 @@ var ExternalSourceTrigger = class {
|
|
|
2560
2737
|
title: "External Source",
|
|
2561
2738
|
rule: {
|
|
2562
2739
|
event: this.event.name,
|
|
2563
|
-
payload: deepMergeFilters(this.options.source.filter(this.options.params), this.event.filter ?? {}),
|
|
2740
|
+
payload: deepMergeFilters(this.options.source.filter(this.options.params), this.event.filter ?? {}, this.options.params.filter ?? {}),
|
|
2564
2741
|
source: this.event.source
|
|
2565
2742
|
},
|
|
2566
2743
|
properties: this.options.source.properties(this.options.params)
|
|
@@ -2617,6 +2794,7 @@ var DynamicTrigger = class {
|
|
|
2617
2794
|
return __privateGet(this, _options4).event;
|
|
2618
2795
|
}
|
|
2619
2796
|
registeredTriggerForParams(params) {
|
|
2797
|
+
const key = slugifyId(this.source.key(params));
|
|
2620
2798
|
return {
|
|
2621
2799
|
rule: {
|
|
2622
2800
|
event: this.event.name,
|
|
@@ -2624,12 +2802,12 @@ var DynamicTrigger = class {
|
|
|
2624
2802
|
payload: deepMergeFilters(this.source.filter(params), this.event.filter ?? {})
|
|
2625
2803
|
},
|
|
2626
2804
|
source: {
|
|
2627
|
-
key
|
|
2805
|
+
key,
|
|
2628
2806
|
channel: this.source.channel,
|
|
2629
2807
|
params,
|
|
2630
|
-
events: [
|
|
2808
|
+
events: typeof this.event.name === "string" ? [
|
|
2631
2809
|
this.event.name
|
|
2632
|
-
],
|
|
2810
|
+
] : this.event.name,
|
|
2633
2811
|
integration: {
|
|
2634
2812
|
id: this.source.integration.id,
|
|
2635
2813
|
metadata: this.source.integration.metadata,
|