@trigger.dev/sdk 2.0.0-next.2 → 2.0.0-next.20

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.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
- log(...args) {
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
- console.log(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
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
- console.error(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
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
- console.warn(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
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
- console.info(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
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
- const structuredLog = {
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
- timestamp: import_zod9.z.string().datetime().optional()
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.string().datetime().optional(),
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
- retry: RetryOptionsSchema.optional()
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,6 +968,75 @@ 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
1041
  function deepMergeFilters(filter, other) {
947
1042
  const result = {
@@ -1000,8 +1095,22 @@ var currentDate = {
1000
1095
  }
1001
1096
  };
1002
1097
 
1098
+ // ../internal/src/searchParams.ts
1099
+ function urlWithSearchParams(url, params) {
1100
+ if (!params) {
1101
+ return url;
1102
+ }
1103
+ const urlObj = new URL(url);
1104
+ for (const [key, value] of Object.entries(params)) {
1105
+ urlObj.searchParams.append(key, String(value));
1106
+ }
1107
+ return urlObj.toString();
1108
+ }
1109
+ __name(urlWithSearchParams, "urlWithSearchParams");
1110
+
1003
1111
  // src/apiClient.ts
1004
- var import_zod12 = require("zod");
1112
+ var import_node_fetch = __toESM(require("node-fetch"));
1113
+ var import_zod14 = require("zod");
1005
1114
  var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
1006
1115
  var ApiClient = class {
1007
1116
  constructor(options) {
@@ -1019,7 +1128,7 @@ var ApiClient = class {
1019
1128
  url: options.url,
1020
1129
  name: options.name
1021
1130
  });
1022
- const response = await fetch(`${__privateGet(this, _apiUrl)}/api/v1/endpoints`, {
1131
+ const response = await (0, import_node_fetch.default)(`${__privateGet(this, _apiUrl)}/api/v1/endpoints`, {
1023
1132
  method: "POST",
1024
1133
  headers: {
1025
1134
  "Content-Type": "application/json",
@@ -1170,8 +1279,8 @@ var ApiClient = class {
1170
1279
  __privateGet(this, _logger).debug("unregistering schedule", {
1171
1280
  id
1172
1281
  });
1173
- const response = await zodfetch(import_zod12.z.object({
1174
- ok: import_zod12.z.boolean()
1282
+ const response = await zodfetch(import_zod14.z.object({
1283
+ ok: import_zod14.z.boolean()
1175
1284
  }), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
1176
1285
  method: "DELETE",
1177
1286
  headers: {
@@ -1197,6 +1306,42 @@ var ApiClient = class {
1197
1306
  });
1198
1307
  return response;
1199
1308
  }
1309
+ async getEvent(eventId) {
1310
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
1311
+ __privateGet(this, _logger).debug("Getting Event", {
1312
+ eventId
1313
+ });
1314
+ return await zodfetch(GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
1315
+ method: "GET",
1316
+ headers: {
1317
+ Authorization: `Bearer ${apiKey}`
1318
+ }
1319
+ });
1320
+ }
1321
+ async getRun(runId, options) {
1322
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
1323
+ __privateGet(this, _logger).debug("Getting Run", {
1324
+ runId
1325
+ });
1326
+ return await zodfetch(GetRunSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
1327
+ method: "GET",
1328
+ headers: {
1329
+ Authorization: `Bearer ${apiKey}`
1330
+ }
1331
+ });
1332
+ }
1333
+ async getRuns(jobSlug, options) {
1334
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
1335
+ __privateGet(this, _logger).debug("Getting Runs", {
1336
+ jobSlug
1337
+ });
1338
+ return await zodfetch(GetRunsSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
1339
+ method: "GET",
1340
+ headers: {
1341
+ Authorization: `Bearer ${apiKey}`
1342
+ }
1343
+ });
1344
+ }
1200
1345
  };
1201
1346
  __name(ApiClient, "ApiClient");
1202
1347
  _apiUrl = new WeakMap();
@@ -1233,7 +1378,7 @@ function getApiKey(key) {
1233
1378
  }
1234
1379
  __name(getApiKey, "getApiKey");
1235
1380
  async function zodfetch(schema, url, requestInit, options) {
1236
- const response = await fetch(url, requestInit);
1381
+ const response = await (0, import_node_fetch.default)(url, requestInit);
1237
1382
  if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
1238
1383
  return;
1239
1384
  }
@@ -1264,8 +1409,14 @@ var RetryWithTaskError = class {
1264
1409
  }
1265
1410
  };
1266
1411
  __name(RetryWithTaskError, "RetryWithTaskError");
1412
+ var CanceledWithTaskError = class {
1413
+ constructor(task) {
1414
+ this.task = task;
1415
+ }
1416
+ };
1417
+ __name(CanceledWithTaskError, "CanceledWithTaskError");
1267
1418
  function isTriggerError(err) {
1268
- return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError;
1419
+ return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError;
1269
1420
  }
1270
1421
  __name(isTriggerError, "isTriggerError");
1271
1422
 
@@ -1288,6 +1439,15 @@ function createIOWithIntegrations(io, auths, integrations) {
1288
1439
  const ioConnection = {
1289
1440
  client
1290
1441
  };
1442
+ ioConnection.runTask = async (key, callback, options) => {
1443
+ return await io.runTask(key, {
1444
+ name: "Task",
1445
+ icon: integration.metadata.id,
1446
+ ...options
1447
+ }, async (ioTask) => {
1448
+ return await callback(client, ioTask, io);
1449
+ });
1450
+ };
1291
1451
  if (integration.client.tasks) {
1292
1452
  const tasks = integration.client.tasks;
1293
1453
  Object.keys(tasks).forEach((taskName) => {
@@ -1329,6 +1489,8 @@ var IO = class {
1329
1489
  this._triggerClient = options.client;
1330
1490
  this._logger = options.logger ?? new Logger("trigger.dev", options.logLevel);
1331
1491
  this._cachedTasks = /* @__PURE__ */ new Map();
1492
+ this._jobLogger = options.jobLogger;
1493
+ this._jobLogLevel = options.jobLogLevel;
1332
1494
  if (options.cachedTasks) {
1333
1495
  options.cachedTasks.forEach((task) => {
1334
1496
  this._cachedTasks.set(task.id, task);
@@ -1339,45 +1501,57 @@ var IO = class {
1339
1501
  }
1340
1502
  get logger() {
1341
1503
  return new IOLogger(async (level, message, data) => {
1504
+ let logLevel = "info";
1342
1505
  switch (level) {
1506
+ case "LOG": {
1507
+ this._jobLogger?.log(message, data);
1508
+ logLevel = "log";
1509
+ break;
1510
+ }
1343
1511
  case "DEBUG": {
1344
- this._logger.debug(message, data);
1512
+ this._jobLogger?.debug(message, data);
1513
+ logLevel = "debug";
1345
1514
  break;
1346
1515
  }
1347
1516
  case "INFO": {
1348
- this._logger.info(message, data);
1517
+ this._jobLogger?.info(message, data);
1518
+ logLevel = "info";
1349
1519
  break;
1350
1520
  }
1351
1521
  case "WARN": {
1352
- this._logger.warn(message, data);
1522
+ this._jobLogger?.warn(message, data);
1523
+ logLevel = "warn";
1353
1524
  break;
1354
1525
  }
1355
1526
  case "ERROR": {
1356
- this._logger.error(message, data);
1527
+ this._jobLogger?.error(message, data);
1528
+ logLevel = "error";
1357
1529
  break;
1358
1530
  }
1359
1531
  }
1360
- await this.runTask([
1361
- message,
1362
- level
1363
- ], {
1364
- name: "log",
1365
- icon: "log",
1366
- description: message,
1367
- params: data,
1368
- properties: [
1369
- {
1370
- label: "Level",
1371
- text: level
1372
- }
1373
- ],
1374
- style: {
1375
- style: "minimal",
1376
- variant: level.toLowerCase()
1377
- },
1378
- noop: true
1379
- }, async (task) => {
1380
- });
1532
+ if (Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
1533
+ await this.runTask([
1534
+ message,
1535
+ level
1536
+ ], {
1537
+ name: "log",
1538
+ icon: "log",
1539
+ description: message,
1540
+ params: data,
1541
+ properties: [
1542
+ {
1543
+ label: "Level",
1544
+ text: level
1545
+ }
1546
+ ],
1547
+ style: {
1548
+ style: "minimal",
1549
+ variant: level.toLowerCase()
1550
+ },
1551
+ noop: true
1552
+ }, async (task) => {
1553
+ });
1554
+ }
1381
1555
  });
1382
1556
  }
1383
1557
  async wait(key, seconds) {
@@ -1432,7 +1606,19 @@ var IO = class {
1432
1606
  params: {
1433
1607
  event,
1434
1608
  options
1435
- }
1609
+ },
1610
+ properties: [
1611
+ {
1612
+ label: "name",
1613
+ text: event.name
1614
+ },
1615
+ ...event?.id ? [
1616
+ {
1617
+ label: "ID",
1618
+ text: event.id
1619
+ }
1620
+ ] : []
1621
+ ]
1436
1622
  }, async (task) => {
1437
1623
  return await this._triggerClient.sendEvent(event, options);
1438
1624
  });
@@ -1440,13 +1626,14 @@ var IO = class {
1440
1626
  async updateSource(key, options) {
1441
1627
  return this.runTask(key, {
1442
1628
  name: "Update Source",
1443
- description: `Update Source ${options.key}`,
1629
+ description: "Update Source",
1444
1630
  properties: [
1445
1631
  {
1446
1632
  label: "key",
1447
1633
  text: options.key
1448
1634
  }
1449
1635
  ],
1636
+ params: options,
1450
1637
  redact: {
1451
1638
  paths: [
1452
1639
  "secret"
@@ -1619,6 +1806,13 @@ var IO = class {
1619
1806
  ...options,
1620
1807
  parentId
1621
1808
  });
1809
+ if (task.status === "CANCELED") {
1810
+ this._logger.debug("Task canceled", {
1811
+ idempotencyKey,
1812
+ task
1813
+ });
1814
+ throw new CanceledWithTaskError(task);
1815
+ }
1622
1816
  if (task.status === "COMPLETED") {
1623
1817
  this._logger.debug("Using task output", {
1624
1818
  idempotencyKey,
@@ -1655,9 +1849,13 @@ var IO = class {
1655
1849
  idempotencyKey,
1656
1850
  task
1657
1851
  });
1658
- await this._apiClient.completeTask(this._id, task.id, {
1659
- output: result ?? void 0
1852
+ const completedTask = await this._apiClient.completeTask(this._id, task.id, {
1853
+ output: result ?? void 0,
1854
+ properties: task.outputProperties ?? void 0
1660
1855
  });
1856
+ if (completedTask.status === "CANCELED") {
1857
+ throw new CanceledWithTaskError(completedTask);
1858
+ }
1661
1859
  return result;
1662
1860
  } catch (error) {
1663
1861
  if (isTriggerError(error)) {
@@ -1666,10 +1864,14 @@ var IO = class {
1666
1864
  if (onError) {
1667
1865
  const onErrorResult = onError(error, task, this);
1668
1866
  if (onErrorResult) {
1669
- const parsedError2 = ErrorWithStackSchema.safeParse(onErrorResult.error);
1670
- throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
1671
- message: "Unknown error"
1672
- }, task, onErrorResult.retryAt);
1867
+ if (onErrorResult instanceof Error) {
1868
+ error = onErrorResult;
1869
+ } else {
1870
+ const parsedError2 = ErrorWithStackSchema.safeParse(onErrorResult.error);
1871
+ throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
1872
+ message: "Unknown error"
1873
+ }, task, onErrorResult.retryAt);
1874
+ }
1673
1875
  }
1674
1876
  }
1675
1877
  const parsedError = ErrorWithStackSchema.safeParse(error);
@@ -1752,6 +1954,9 @@ var IOLogger = class {
1752
1954
  constructor(callback) {
1753
1955
  this.callback = callback;
1754
1956
  }
1957
+ log(message, properties) {
1958
+ return this.callback("LOG", message, properties);
1959
+ }
1755
1960
  debug(message, properties) {
1756
1961
  return this.callback("DEBUG", message, properties);
1757
1962
  }
@@ -1824,7 +2029,7 @@ var registerSourceEvent = {
1824
2029
  icon: "register-source",
1825
2030
  parsePayload: RegisterSourceEventSchema.parse
1826
2031
  };
1827
- var _options3, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _client, _logger2, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn;
2032
+ 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
2033
  var TriggerClient = class {
1829
2034
  constructor(options) {
1830
2035
  __privateAdd(this, _preprocessRun);
@@ -1840,36 +2045,54 @@ var TriggerClient = class {
1840
2045
  __privateAdd(this, _jobMetadataByDynamicTriggers, {});
1841
2046
  __privateAdd(this, _registeredSchedules, {});
1842
2047
  __privateAdd(this, _client, void 0);
1843
- __privateAdd(this, _logger2, void 0);
2048
+ __privateAdd(this, _internalLogger, void 0);
1844
2049
  this.id = options.id;
1845
- this._url = buildClientUrl(options.url);
1846
2050
  __privateSet(this, _options3, options);
1847
2051
  __privateSet(this, _client, new ApiClient(__privateGet(this, _options3)));
1848
- __privateSet(this, _logger2, new Logger("trigger.dev", __privateGet(this, _options3).logLevel));
1849
- }
1850
- get url() {
1851
- return `${this._url}${this.path ? `${this.path.startsWith("/") ? "" : "/"}${this.path}` : ""}`;
2052
+ __privateSet(this, _internalLogger, new Logger("trigger.dev", __privateGet(this, _options3).verbose ? "debug" : "log"));
1852
2053
  }
1853
2054
  async handleRequest(request) {
1854
- __privateGet(this, _logger2).debug("handling request", {
2055
+ __privateGet(this, _internalLogger).debug("handling request", {
1855
2056
  url: request.url,
1856
2057
  headers: Object.fromEntries(request.headers.entries()),
1857
2058
  method: request.method
1858
2059
  });
1859
2060
  const apiKey = request.headers.get("x-trigger-api-key");
1860
- if (!this.authorized(apiKey)) {
1861
- return {
1862
- status: 401,
1863
- body: {
1864
- message: "Unauthorized"
1865
- }
1866
- };
2061
+ const authorization = this.authorized(apiKey);
2062
+ switch (authorization) {
2063
+ case "authorized": {
2064
+ break;
2065
+ }
2066
+ case "missing-client": {
2067
+ return {
2068
+ status: 401,
2069
+ body: {
2070
+ message: "Unauthorized: client missing apiKey"
2071
+ }
2072
+ };
2073
+ }
2074
+ case "missing-header": {
2075
+ return {
2076
+ status: 401,
2077
+ body: {
2078
+ message: "Unauthorized: missing x-trigger-api-key header"
2079
+ }
2080
+ };
2081
+ }
2082
+ case "unauthorized": {
2083
+ return {
2084
+ status: 401,
2085
+ body: {
2086
+ message: `Forbidden: client apiKey mismatch: Make sure you are using the correct API Key for your environment`
2087
+ }
2088
+ };
2089
+ }
1867
2090
  }
1868
2091
  if (request.method !== "POST") {
1869
2092
  return {
1870
2093
  status: 405,
1871
2094
  body: {
1872
- message: "Method not allowed"
2095
+ message: "Method not allowed (only POST is allowed)"
1873
2096
  }
1874
2097
  };
1875
2098
  }
@@ -1890,7 +2113,7 @@ var TriggerClient = class {
1890
2113
  status: 200,
1891
2114
  body: {
1892
2115
  ok: false,
1893
- message: "Missing endpoint ID"
2116
+ error: "Missing endpoint ID"
1894
2117
  }
1895
2118
  };
1896
2119
  }
@@ -1899,7 +2122,7 @@ var TriggerClient = class {
1899
2122
  status: 200,
1900
2123
  body: {
1901
2124
  ok: false,
1902
- message: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
2125
+ error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
1903
2126
  }
1904
2127
  };
1905
2128
  }
@@ -1932,7 +2155,11 @@ var TriggerClient = class {
1932
2155
  sources: Object.values(__privateGet(this, _registeredSources)),
1933
2156
  dynamicTriggers: Object.values(__privateGet(this, _registeredDynamicTriggers)).map((trigger) => ({
1934
2157
  id: trigger.id,
1935
- jobs: __privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] ?? []
2158
+ jobs: __privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] ?? [],
2159
+ registerSourceJob: {
2160
+ id: dynamicTriggerRegisterSourceJobId(trigger.id),
2161
+ version: trigger.source.version
2162
+ }
1936
2163
  })),
1937
2164
  dynamicSchedules: Object.entries(__privateGet(this, _registeredSchedules)).map(([id, jobs]) => ({
1938
2165
  id,
@@ -2034,11 +2261,19 @@ var TriggerClient = class {
2034
2261
  }
2035
2262
  };
2036
2263
  }
2037
- const sourceRequest = new Request(headers.data["x-ts-http-url"], {
2264
+ const sourceRequestNeedsBody = headers.data["x-ts-http-method"] !== "GET";
2265
+ const sourceRequestInit = {
2038
2266
  method: headers.data["x-ts-http-method"],
2039
2267
  headers: headers.data["x-ts-http-headers"],
2040
- body: headers.data["x-ts-http-method"] !== "GET" ? request.body : void 0
2041
- });
2268
+ body: sourceRequestNeedsBody ? request.body : void 0
2269
+ };
2270
+ if (sourceRequestNeedsBody) {
2271
+ try {
2272
+ sourceRequestInit.duplex = "half";
2273
+ } catch (error) {
2274
+ }
2275
+ }
2276
+ const sourceRequest = new Request(headers.data["x-ts-http-url"], sourceRequestInit);
2042
2277
  const key = headers.data["x-ts-key"];
2043
2278
  const dynamicId = headers.data["x-ts-dynamic-id"];
2044
2279
  const secret = headers.data["x-ts-secret"];
@@ -2078,7 +2313,7 @@ var TriggerClient = class {
2078
2313
  attachDynamicTrigger(trigger) {
2079
2314
  __privateGet(this, _registeredDynamicTriggers)[trigger.id] = trigger;
2080
2315
  new Job(this, {
2081
- id: `register-dynamic-trigger-${trigger.id}`,
2316
+ id: dynamicTriggerRegisterSourceJobId(trigger.id),
2082
2317
  name: `Register dynamic trigger ${trigger.id}`,
2083
2318
  version: trigger.source.version,
2084
2319
  trigger: new EventTrigger({
@@ -2115,7 +2350,7 @@ var TriggerClient = class {
2115
2350
  }
2116
2351
  attachSource(options) {
2117
2352
  __privateGet(this, _registeredHttpSourceHandlers)[options.key] = async (s, r) => {
2118
- return await options.source.handle(s, r, __privateGet(this, _logger2));
2353
+ return await options.source.handle(s, r, __privateGet(this, _internalLogger));
2119
2354
  };
2120
2355
  let registeredSource = __privateGet(this, _registeredSources)[options.key];
2121
2356
  if (!registeredSource) {
@@ -2128,6 +2363,10 @@ var TriggerClient = class {
2128
2363
  id: options.source.integration.id,
2129
2364
  metadata: options.source.integration.metadata,
2130
2365
  authSource: options.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
2366
+ },
2367
+ registerSourceJob: {
2368
+ id: options.key,
2369
+ version: options.source.version
2131
2370
  }
2132
2371
  };
2133
2372
  }
@@ -2194,16 +2433,31 @@ var TriggerClient = class {
2194
2433
  async unregisterSchedule(id, key) {
2195
2434
  return __privateGet(this, _client).unregisterSchedule(this.id, id, key);
2196
2435
  }
2436
+ async getEvent(eventId) {
2437
+ return __privateGet(this, _client).getEvent(eventId);
2438
+ }
2439
+ async getRun(runId, options) {
2440
+ return __privateGet(this, _client).getRun(runId, options);
2441
+ }
2442
+ async getRuns(jobSlug, options) {
2443
+ return __privateGet(this, _client).getRuns(jobSlug, options);
2444
+ }
2197
2445
  authorized(apiKey) {
2446
+ if (typeof apiKey !== "string") {
2447
+ return "missing-header";
2448
+ }
2198
2449
  const localApiKey = __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
2199
2450
  if (!localApiKey) {
2200
- return false;
2451
+ return "missing-client";
2201
2452
  }
2202
- return apiKey === localApiKey;
2453
+ return apiKey === localApiKey ? "authorized" : "unauthorized";
2203
2454
  }
2204
2455
  apiKey() {
2205
2456
  return __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
2206
2457
  }
2458
+ defineJob(options) {
2459
+ return new Job(this, options);
2460
+ }
2207
2461
  };
2208
2462
  __name(TriggerClient, "TriggerClient");
2209
2463
  _options3 = new WeakMap();
@@ -2214,7 +2468,7 @@ _registeredDynamicTriggers = new WeakMap();
2214
2468
  _jobMetadataByDynamicTriggers = new WeakMap();
2215
2469
  _registeredSchedules = new WeakMap();
2216
2470
  _client = new WeakMap();
2217
- _logger2 = new WeakMap();
2471
+ _internalLogger = new WeakMap();
2218
2472
  _preprocessRun = new WeakSet();
2219
2473
  preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
2220
2474
  const context = __privateMethod(this, _createPreprocessRunContext, createPreprocessRunContext_fn).call(this, body);
@@ -2227,7 +2481,7 @@ preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
2227
2481
  }, "#preprocessRun");
2228
2482
  _executeJob = new WeakSet();
2229
2483
  executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2230
- __privateGet(this, _logger2).debug("executing job", {
2484
+ __privateGet(this, _internalLogger).debug("executing job", {
2231
2485
  execution: body1,
2232
2486
  job: job1.toJSON()
2233
2487
  });
@@ -2236,9 +2490,11 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2236
2490
  id: body1.run.id,
2237
2491
  cachedTasks: body1.tasks,
2238
2492
  apiClient: __privateGet(this, _client),
2239
- logger: __privateGet(this, _logger2),
2493
+ logger: __privateGet(this, _internalLogger),
2240
2494
  client: this,
2241
- context
2495
+ context,
2496
+ jobLogLevel: job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info",
2497
+ jobLogger: __privateGet(this, _options3).ioLogLocalEnabled ? new Logger(job1.id, job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info") : void 0
2242
2498
  });
2243
2499
  const ioWithConnections = createIOWithIntegrations(io, body1.connections, job1.options.integrations);
2244
2500
  try {
@@ -2262,6 +2518,12 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2262
2518
  retryAt: error.retryAt
2263
2519
  };
2264
2520
  }
2521
+ if (error instanceof CanceledWithTaskError) {
2522
+ return {
2523
+ status: "CANCELED",
2524
+ task: error.task
2525
+ };
2526
+ }
2265
2527
  if (error instanceof RetryWithTaskError) {
2266
2528
  const errorWithStack2 = ErrorWithStackSchema.safeParse(error.cause);
2267
2529
  if (errorWithStack2.success) {
@@ -2296,7 +2558,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2296
2558
  }, "#executeJob");
2297
2559
  _createRunContext = new WeakSet();
2298
2560
  createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
2299
- const { event, organization, environment, job, run } = execution;
2561
+ const { event, organization, environment, job, run, source } = execution;
2300
2562
  return {
2301
2563
  event: {
2302
2564
  id: event.id,
@@ -2308,7 +2570,8 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
2308
2570
  environment,
2309
2571
  job,
2310
2572
  run,
2311
- account: execution.account
2573
+ account: execution.account,
2574
+ source
2312
2575
  };
2313
2576
  }, "#createRunContext");
2314
2577
  _createPreprocessRunContext = new WeakSet();
@@ -2330,13 +2593,13 @@ createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(body2) {
2330
2593
  }, "#createPreprocessRunContext");
2331
2594
  _handleHttpSourceRequest = new WeakSet();
2332
2595
  handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourceRequest) {
2333
- __privateGet(this, _logger2).debug("Handling HTTP source request", {
2596
+ __privateGet(this, _internalLogger).debug("Handling HTTP source request", {
2334
2597
  source
2335
2598
  });
2336
2599
  if (source.dynamicId) {
2337
2600
  const dynamicTrigger = __privateGet(this, _registeredDynamicTriggers)[source.dynamicId];
2338
2601
  if (!dynamicTrigger) {
2339
- __privateGet(this, _logger2).debug("No dynamic trigger registered for HTTP source", {
2602
+ __privateGet(this, _internalLogger).debug("No dynamic trigger registered for HTTP source", {
2340
2603
  source
2341
2604
  });
2342
2605
  return {
@@ -2349,7 +2612,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
2349
2612
  events: []
2350
2613
  };
2351
2614
  }
2352
- const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this, _logger2));
2615
+ const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this, _internalLogger));
2353
2616
  if (!results2) {
2354
2617
  return {
2355
2618
  events: [],
@@ -2373,7 +2636,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
2373
2636
  }
2374
2637
  const handler = __privateGet(this, _registeredHttpSourceHandlers)[source.key];
2375
2638
  if (!handler) {
2376
- __privateGet(this, _logger2).debug("No handler registered for HTTP source", {
2639
+ __privateGet(this, _internalLogger).debug("No handler registered for HTTP source", {
2377
2640
  source
2378
2641
  });
2379
2642
  return {
@@ -2408,20 +2671,10 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
2408
2671
  }
2409
2672
  };
2410
2673
  }, "#handleHttpSourceRequest");
2411
- function buildClientUrl(url) {
2412
- if (!url) {
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;
2674
+ function dynamicTriggerRegisterSourceJobId(id) {
2675
+ return `register-dynamic-trigger-${id}`;
2423
2676
  }
2424
- __name(buildClientUrl, "buildClientUrl");
2677
+ __name(dynamicTriggerRegisterSourceJobId, "dynamicTriggerRegisterSourceJobId");
2425
2678
 
2426
2679
  // src/integrations.ts
2427
2680
  function authenticatedTask(options) {
@@ -2445,7 +2698,7 @@ var ExternalSource = class {
2445
2698
  }, logger);
2446
2699
  }
2447
2700
  filter(params) {
2448
- return this.options.filter(params);
2701
+ return this.options.filter?.(params) ?? {};
2449
2702
  }
2450
2703
  properties(params) {
2451
2704
  return this.options.properties?.(params) ?? [];
@@ -2560,6 +2813,7 @@ var DynamicTrigger = class {
2560
2813
  return __privateGet(this, _options4).event;
2561
2814
  }
2562
2815
  registeredTriggerForParams(params) {
2816
+ const key = slugifyId(this.source.key(params));
2563
2817
  return {
2564
2818
  rule: {
2565
2819
  event: this.event.name,
@@ -2567,7 +2821,7 @@ var DynamicTrigger = class {
2567
2821
  payload: deepMergeFilters(this.source.filter(params), this.event.filter ?? {})
2568
2822
  },
2569
2823
  source: {
2570
- key: slugifyId(this.source.key(params)),
2824
+ key,
2571
2825
  channel: this.source.channel,
2572
2826
  params,
2573
2827
  events: [
@@ -2588,7 +2842,7 @@ var DynamicTrigger = class {
2588
2842
  triggerClient.attachJobToDynamicTrigger(job, this);
2589
2843
  }
2590
2844
  get preprocessRuns() {
2591
- return false;
2845
+ return true;
2592
2846
  }
2593
2847
  };
2594
2848
  __name(DynamicTrigger, "DynamicTrigger");
@@ -2596,6 +2850,7 @@ _client2 = new WeakMap();
2596
2850
  _options4 = new WeakMap();
2597
2851
 
2598
2852
  // src/triggers/scheduled.ts
2853
+ var import_cronstrue = __toESM(require("cronstrue"));
2599
2854
  var examples = [
2600
2855
  {
2601
2856
  id: "now",
@@ -2654,6 +2909,9 @@ var CronTrigger = class {
2654
2909
  this.options = options;
2655
2910
  }
2656
2911
  get event() {
2912
+ const humanReadable = import_cronstrue.default.toString(this.options.cron, {
2913
+ throwExceptionOnParseError: false
2914
+ });
2657
2915
  return {
2658
2916
  name: "trigger.scheduled",
2659
2917
  title: "Cron Schedule",
@@ -2663,8 +2921,12 @@ var CronTrigger = class {
2663
2921
  parsePayload: ScheduledPayloadSchema.parse,
2664
2922
  properties: [
2665
2923
  {
2666
- label: "Expression",
2924
+ label: "cron",
2667
2925
  text: this.options.cron
2926
+ },
2927
+ {
2928
+ label: "Schedule",
2929
+ text: humanReadable
2668
2930
  }
2669
2931
  ]
2670
2932
  };