@trigger.dev/sdk 2.0.0-next.0 → 2.0.0-next.10

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))
@@ -55,16 +61,16 @@ __export(src_exports, {
55
61
  Job: () => Job,
56
62
  MissingConnectionNotification: () => MissingConnectionNotification,
57
63
  MissingConnectionResolvedNotification: () => MissingConnectionResolvedNotification,
58
- ResumeWithTask: () => ResumeWithTask,
59
64
  TriggerClient: () => TriggerClient,
60
65
  authenticatedTask: () => authenticatedTask,
61
66
  cronTrigger: () => cronTrigger,
62
67
  eventTrigger: () => eventTrigger,
63
68
  intervalTrigger: () => intervalTrigger,
69
+ isTriggerError: () => isTriggerError,
64
70
  missingConnectionNotification: () => missingConnectionNotification,
65
71
  missingConnectionResolvedNotification: () => missingConnectionResolvedNotification,
66
72
  omit: () => omit,
67
- secureString: () => secureString
73
+ redactString: () => redactString
68
74
  });
69
75
  module.exports = __toCommonJS(src_exports);
70
76
 
@@ -104,15 +110,17 @@ var Job = class {
104
110
  get integrations() {
105
111
  return Object.keys(this.options.integrations ?? {}).reduce((acc, key) => {
106
112
  const integration = this.options.integrations[key];
107
- if (!integration.client.usesLocalAuth) {
108
- acc[key] = {
109
- id: integration.id,
110
- metadata: integration.metadata
111
- };
112
- }
113
+ acc[key] = {
114
+ id: integration.id,
115
+ metadata: integration.metadata,
116
+ authSource: integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
117
+ };
113
118
  return acc;
114
119
  }, {});
115
120
  }
121
+ get logLevel() {
122
+ return this.options.logLevel;
123
+ }
116
124
  toJSON() {
117
125
  const internal = this.options.__internal;
118
126
  return {
@@ -146,18 +154,23 @@ var logLevels = [
146
154
  "info",
147
155
  "debug"
148
156
  ];
149
- var _name, _level, _filteredKeys;
157
+ var _name, _level, _filteredKeys, _jsonReplacer;
150
158
  var _Logger = class {
151
- constructor(name, level = "info", filteredKeys = []) {
159
+ constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
152
160
  __privateAdd(this, _name, void 0);
153
161
  __privateAdd(this, _level, void 0);
154
162
  __privateAdd(this, _filteredKeys, []);
163
+ __privateAdd(this, _jsonReplacer, void 0);
155
164
  __privateSet(this, _name, name);
156
165
  __privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
157
166
  __privateSet(this, _filteredKeys, filteredKeys);
167
+ __privateSet(this, _jsonReplacer, jsonReplacer);
158
168
  }
159
169
  filter(...keys) {
160
- return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys);
170
+ return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
171
+ }
172
+ static satisfiesLogLevel(logLevel, setLevel) {
173
+ return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
161
174
  }
162
175
  log(...args) {
163
176
  if (__privateGet(this, _level) < 0)
@@ -188,7 +201,7 @@ var _Logger = class {
188
201
  message,
189
202
  args: structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys))
190
203
  };
191
- console.debug(JSON.stringify(structuredLog, bigIntReplacer));
204
+ console.debug(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
192
205
  }
193
206
  };
194
207
  var Logger = _Logger;
@@ -196,6 +209,19 @@ __name(Logger, "Logger");
196
209
  _name = new WeakMap();
197
210
  _level = new WeakMap();
198
211
  _filteredKeys = new WeakMap();
212
+ _jsonReplacer = new WeakMap();
213
+ function createReplacer(replacer) {
214
+ return (key, value) => {
215
+ if (typeof value === "bigint") {
216
+ return value.toString();
217
+ }
218
+ if (replacer) {
219
+ return replacer(key, value);
220
+ }
221
+ return value;
222
+ };
223
+ }
224
+ __name(createReplacer, "createReplacer");
199
225
  function bigIntReplacer(_key, value) {
200
226
  if (typeof value === "bigint") {
201
227
  return value.toString();
@@ -254,129 +280,100 @@ __name(filterKeys, "filterKeys");
254
280
 
255
281
  // ../internal/src/schemas/api.ts
256
282
  var import_ulid = require("ulid");
257
- var import_zod8 = require("zod");
283
+ var import_zod9 = require("zod");
258
284
 
259
- // ../internal/src/schemas/integrations.ts
285
+ // ../internal/src/schemas/errors.ts
260
286
  var import_zod = require("zod");
261
- var ConnectionAuthSchema = import_zod.z.object({
262
- type: import_zod.z.enum([
263
- "oauth2"
264
- ]),
265
- accessToken: import_zod.z.string(),
266
- scopes: import_zod.z.array(import_zod.z.string()).optional(),
267
- additionalFields: import_zod.z.record(import_zod.z.string()).optional()
268
- });
269
- var IntegrationMetadataSchema = import_zod.z.object({
270
- key: import_zod.z.string(),
271
- title: import_zod.z.string(),
272
- icon: import_zod.z.string()
273
- });
274
- var IntegrationConfigSchema = import_zod.z.object({
275
- id: import_zod.z.string(),
276
- metadata: IntegrationMetadataSchema
287
+ var ErrorWithStackSchema = import_zod.z.object({
288
+ message: import_zod.z.string(),
289
+ name: import_zod.z.string().optional(),
290
+ stack: import_zod.z.string().optional()
277
291
  });
278
292
 
279
- // ../internal/src/schemas/properties.ts
293
+ // ../internal/src/schemas/eventFilter.ts
280
294
  var import_zod2 = require("zod");
281
- var DisplayPropertySchema = import_zod2.z.object({
282
- label: import_zod2.z.string(),
283
- text: import_zod2.z.string(),
284
- url: import_zod2.z.string().optional()
285
- });
286
- var DisplayPropertiesSchema = import_zod2.z.array(DisplayPropertySchema);
287
- var StyleSchema = import_zod2.z.object({
288
- style: import_zod2.z.enum([
289
- "normal",
290
- "minimal"
295
+ var EventMatcherSchema = import_zod2.z.union([
296
+ import_zod2.z.array(import_zod2.z.string()),
297
+ import_zod2.z.array(import_zod2.z.number()),
298
+ import_zod2.z.array(import_zod2.z.boolean())
299
+ ]);
300
+ var EventFilterSchema = import_zod2.z.lazy(() => import_zod2.z.record(import_zod2.z.union([
301
+ EventMatcherSchema,
302
+ EventFilterSchema
303
+ ])));
304
+ var EventRuleSchema = import_zod2.z.object({
305
+ event: import_zod2.z.string(),
306
+ source: import_zod2.z.string(),
307
+ payload: EventFilterSchema.optional(),
308
+ context: EventFilterSchema.optional()
309
+ });
310
+
311
+ // ../internal/src/schemas/integrations.ts
312
+ var import_zod3 = require("zod");
313
+ var ConnectionAuthSchema = import_zod3.z.object({
314
+ type: import_zod3.z.enum([
315
+ "oauth2"
291
316
  ]),
292
- variant: import_zod2.z.string().optional()
317
+ accessToken: import_zod3.z.string(),
318
+ scopes: import_zod3.z.array(import_zod3.z.string()).optional(),
319
+ additionalFields: import_zod3.z.record(import_zod3.z.string()).optional()
320
+ });
321
+ var IntegrationMetadataSchema = import_zod3.z.object({
322
+ id: import_zod3.z.string(),
323
+ name: import_zod3.z.string(),
324
+ instructions: import_zod3.z.string().optional()
325
+ });
326
+ var IntegrationConfigSchema = import_zod3.z.object({
327
+ id: import_zod3.z.string(),
328
+ metadata: IntegrationMetadataSchema,
329
+ authSource: import_zod3.z.enum([
330
+ "HOSTED",
331
+ "LOCAL"
332
+ ])
293
333
  });
294
334
 
295
335
  // ../internal/src/schemas/json.ts
296
- var import_zod3 = require("zod");
297
- var LiteralSchema = import_zod3.z.union([
298
- import_zod3.z.string(),
299
- import_zod3.z.number(),
300
- import_zod3.z.boolean(),
301
- import_zod3.z.null()
336
+ var import_zod4 = require("zod");
337
+ var LiteralSchema = import_zod4.z.union([
338
+ import_zod4.z.string(),
339
+ import_zod4.z.number(),
340
+ import_zod4.z.boolean(),
341
+ import_zod4.z.null()
302
342
  ]);
303
- var DeserializedJsonSchema = import_zod3.z.lazy(() => import_zod3.z.union([
343
+ var DeserializedJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
304
344
  LiteralSchema,
305
- import_zod3.z.array(DeserializedJsonSchema),
306
- import_zod3.z.record(DeserializedJsonSchema)
345
+ import_zod4.z.array(DeserializedJsonSchema),
346
+ import_zod4.z.record(DeserializedJsonSchema)
307
347
  ]));
308
- var SerializableSchema = import_zod3.z.union([
309
- import_zod3.z.string(),
310
- import_zod3.z.number(),
311
- import_zod3.z.boolean(),
312
- import_zod3.z.null(),
313
- import_zod3.z.date(),
314
- import_zod3.z.undefined(),
315
- import_zod3.z.symbol()
348
+ var SerializableSchema = import_zod4.z.union([
349
+ import_zod4.z.string(),
350
+ import_zod4.z.number(),
351
+ import_zod4.z.boolean(),
352
+ import_zod4.z.null(),
353
+ import_zod4.z.date(),
354
+ import_zod4.z.undefined(),
355
+ import_zod4.z.symbol()
316
356
  ]);
317
- var SerializableJsonSchema = import_zod3.z.lazy(() => import_zod3.z.union([
357
+ var SerializableJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
318
358
  SerializableSchema,
319
- import_zod3.z.array(SerializableJsonSchema),
320
- import_zod3.z.record(SerializableJsonSchema)
359
+ import_zod4.z.array(SerializableJsonSchema),
360
+ import_zod4.z.record(SerializableJsonSchema)
321
361
  ]));
322
362
 
323
- // ../internal/src/schemas/tasks.ts
324
- var import_zod4 = require("zod");
325
- var TaskStatusSchema = import_zod4.z.enum([
326
- "PENDING",
327
- "WAITING",
328
- "RUNNING",
329
- "COMPLETED",
330
- "ERRORED"
331
- ]);
332
- var TaskSchema = import_zod4.z.object({
333
- id: import_zod4.z.string(),
334
- name: import_zod4.z.string(),
335
- icon: import_zod4.z.string().optional().nullable(),
336
- noop: import_zod4.z.boolean(),
337
- startedAt: import_zod4.z.coerce.date().optional().nullable(),
338
- completedAt: import_zod4.z.coerce.date().optional().nullable(),
339
- delayUntil: import_zod4.z.coerce.date().optional().nullable(),
340
- status: TaskStatusSchema,
341
- description: import_zod4.z.string().optional().nullable(),
342
- properties: import_zod4.z.array(DisplayPropertySchema).optional().nullable(),
343
- params: DeserializedJsonSchema.optional().nullable(),
344
- output: DeserializedJsonSchema.optional().nullable(),
345
- error: import_zod4.z.string().optional().nullable(),
346
- parentId: import_zod4.z.string().optional().nullable(),
347
- style: StyleSchema.optional().nullable()
348
- });
349
- var ServerTaskSchema = TaskSchema.extend({
350
- idempotencyKey: import_zod4.z.string()
351
- });
352
- var CachedTaskSchema = import_zod4.z.object({
353
- id: import_zod4.z.string(),
354
- idempotencyKey: import_zod4.z.string(),
355
- status: TaskStatusSchema,
356
- noop: import_zod4.z.boolean().default(false),
357
- output: DeserializedJsonSchema.optional().nullable(),
358
- parentId: import_zod4.z.string().optional().nullable()
359
- });
360
-
361
- // ../internal/src/schemas/triggers.ts
362
- var import_zod7 = require("zod");
363
-
364
- // ../internal/src/schemas/eventFilter.ts
363
+ // ../internal/src/schemas/properties.ts
365
364
  var import_zod5 = require("zod");
366
- var EventMatcherSchema = import_zod5.z.union([
367
- import_zod5.z.array(import_zod5.z.string()),
368
- import_zod5.z.array(import_zod5.z.number()),
369
- import_zod5.z.array(import_zod5.z.boolean())
370
- ]);
371
- var EventFilterSchema = import_zod5.z.lazy(() => import_zod5.z.record(import_zod5.z.union([
372
- EventMatcherSchema,
373
- EventFilterSchema
374
- ])));
375
- var EventRuleSchema = import_zod5.z.object({
376
- event: import_zod5.z.string(),
377
- source: import_zod5.z.string(),
378
- payload: EventFilterSchema.optional(),
379
- context: EventFilterSchema.optional()
365
+ var DisplayPropertySchema = import_zod5.z.object({
366
+ label: import_zod5.z.string(),
367
+ text: import_zod5.z.string(),
368
+ url: import_zod5.z.string().optional()
369
+ });
370
+ var DisplayPropertiesSchema = import_zod5.z.array(DisplayPropertySchema);
371
+ var StyleSchema = import_zod5.z.object({
372
+ style: import_zod5.z.enum([
373
+ "normal",
374
+ "minimal"
375
+ ]),
376
+ variant: import_zod5.z.string().optional()
380
377
  });
381
378
 
382
379
  // ../internal/src/schemas/schedules.ts
@@ -413,310 +410,400 @@ var RegisterDynamicSchedulePayloadSchema = import_zod6.z.object({
413
410
  }))
414
411
  });
415
412
 
416
- // ../internal/src/schemas/triggers.ts
417
- var EventSpecificationSchema = import_zod7.z.object({
413
+ // ../internal/src/schemas/tasks.ts
414
+ var import_zod7 = require("zod");
415
+ var TaskStatusSchema = import_zod7.z.enum([
416
+ "PENDING",
417
+ "WAITING",
418
+ "RUNNING",
419
+ "COMPLETED",
420
+ "ERRORED"
421
+ ]);
422
+ var TaskSchema = import_zod7.z.object({
423
+ id: import_zod7.z.string(),
418
424
  name: import_zod7.z.string(),
419
- title: import_zod7.z.string(),
420
- source: import_zod7.z.string(),
421
- icon: import_zod7.z.string(),
425
+ icon: import_zod7.z.string().optional().nullable(),
426
+ noop: import_zod7.z.boolean(),
427
+ startedAt: import_zod7.z.coerce.date().optional().nullable(),
428
+ completedAt: import_zod7.z.coerce.date().optional().nullable(),
429
+ delayUntil: import_zod7.z.coerce.date().optional().nullable(),
430
+ status: TaskStatusSchema,
431
+ description: import_zod7.z.string().optional().nullable(),
432
+ properties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
433
+ params: DeserializedJsonSchema.optional().nullable(),
434
+ output: DeserializedJsonSchema.optional().nullable(),
435
+ error: import_zod7.z.string().optional().nullable(),
436
+ parentId: import_zod7.z.string().optional().nullable(),
437
+ style: StyleSchema.optional().nullable(),
438
+ operation: import_zod7.z.string().optional().nullable()
439
+ });
440
+ var ServerTaskSchema = TaskSchema.extend({
441
+ idempotencyKey: import_zod7.z.string(),
442
+ attempts: import_zod7.z.number()
443
+ });
444
+ var CachedTaskSchema = import_zod7.z.object({
445
+ id: import_zod7.z.string(),
446
+ idempotencyKey: import_zod7.z.string(),
447
+ status: TaskStatusSchema,
448
+ noop: import_zod7.z.boolean().default(false),
449
+ output: DeserializedJsonSchema.optional().nullable(),
450
+ parentId: import_zod7.z.string().optional().nullable()
451
+ });
452
+
453
+ // ../internal/src/schemas/triggers.ts
454
+ var import_zod8 = require("zod");
455
+ var EventExampleSchema = import_zod8.z.object({
456
+ id: import_zod8.z.string(),
457
+ icon: import_zod8.z.string().optional(),
458
+ name: import_zod8.z.string(),
459
+ payload: import_zod8.z.any()
460
+ });
461
+ var EventSpecificationSchema = import_zod8.z.object({
462
+ name: import_zod8.z.string(),
463
+ title: import_zod8.z.string(),
464
+ source: import_zod8.z.string(),
465
+ icon: import_zod8.z.string(),
422
466
  filter: EventFilterSchema.optional(),
423
- properties: import_zod7.z.array(DisplayPropertySchema).optional(),
424
- schema: import_zod7.z.any().optional(),
425
- examples: import_zod7.z.array(import_zod7.z.any()).optional()
426
- });
427
- var DynamicTriggerMetadataSchema = import_zod7.z.object({
428
- type: import_zod7.z.literal("dynamic"),
429
- id: import_zod7.z.string()
430
- });
431
- var StaticTriggerMetadataSchema = import_zod7.z.object({
432
- type: import_zod7.z.literal("static"),
433
- title: import_zod7.z.string(),
434
- properties: import_zod7.z.array(DisplayPropertySchema).optional(),
467
+ properties: import_zod8.z.array(DisplayPropertySchema).optional(),
468
+ schema: import_zod8.z.any().optional(),
469
+ examples: import_zod8.z.array(EventExampleSchema).optional()
470
+ });
471
+ var DynamicTriggerMetadataSchema = import_zod8.z.object({
472
+ type: import_zod8.z.literal("dynamic"),
473
+ id: import_zod8.z.string()
474
+ });
475
+ var StaticTriggerMetadataSchema = import_zod8.z.object({
476
+ type: import_zod8.z.literal("static"),
477
+ title: import_zod8.z.string(),
478
+ properties: import_zod8.z.array(DisplayPropertySchema).optional(),
435
479
  rule: EventRuleSchema
436
480
  });
437
- var ScheduledTriggerMetadataSchema = import_zod7.z.object({
438
- type: import_zod7.z.literal("scheduled"),
481
+ var ScheduledTriggerMetadataSchema = import_zod8.z.object({
482
+ type: import_zod8.z.literal("scheduled"),
439
483
  schedule: ScheduleMetadataSchema
440
484
  });
441
- var TriggerMetadataSchema = import_zod7.z.discriminatedUnion("type", [
485
+ var TriggerMetadataSchema = import_zod8.z.discriminatedUnion("type", [
442
486
  DynamicTriggerMetadataSchema,
443
487
  StaticTriggerMetadataSchema,
444
488
  ScheduledTriggerMetadataSchema
445
489
  ]);
446
490
 
447
491
  // ../internal/src/schemas/api.ts
448
- var UpdateTriggerSourceBodySchema = import_zod8.z.object({
449
- registeredEvents: import_zod8.z.array(import_zod8.z.string()),
450
- secret: import_zod8.z.string().optional(),
492
+ var UpdateTriggerSourceBodySchema = import_zod9.z.object({
493
+ registeredEvents: import_zod9.z.array(import_zod9.z.string()),
494
+ secret: import_zod9.z.string().optional(),
451
495
  data: SerializableJsonSchema.optional()
452
496
  });
453
497
  var HttpEventSourceSchema = UpdateTriggerSourceBodySchema.extend({
454
- id: import_zod8.z.string(),
455
- active: import_zod8.z.boolean(),
456
- url: import_zod8.z.string().url()
498
+ id: import_zod9.z.string(),
499
+ active: import_zod9.z.boolean(),
500
+ url: import_zod9.z.string().url()
457
501
  });
458
- var RegisterHTTPTriggerSourceBodySchema = import_zod8.z.object({
459
- type: import_zod8.z.literal("HTTP"),
460
- url: import_zod8.z.string().url()
502
+ var RegisterHTTPTriggerSourceBodySchema = import_zod9.z.object({
503
+ type: import_zod9.z.literal("HTTP"),
504
+ url: import_zod9.z.string().url()
461
505
  });
462
- var RegisterSMTPTriggerSourceBodySchema = import_zod8.z.object({
463
- type: import_zod8.z.literal("SMTP")
506
+ var RegisterSMTPTriggerSourceBodySchema = import_zod9.z.object({
507
+ type: import_zod9.z.literal("SMTP")
464
508
  });
465
- var RegisterSQSTriggerSourceBodySchema = import_zod8.z.object({
466
- type: import_zod8.z.literal("SQS")
509
+ var RegisterSQSTriggerSourceBodySchema = import_zod9.z.object({
510
+ type: import_zod9.z.literal("SQS")
467
511
  });
468
- var RegisterSourceChannelBodySchema = import_zod8.z.discriminatedUnion("type", [
512
+ var RegisterSourceChannelBodySchema = import_zod9.z.discriminatedUnion("type", [
469
513
  RegisterHTTPTriggerSourceBodySchema,
470
514
  RegisterSMTPTriggerSourceBodySchema,
471
515
  RegisterSQSTriggerSourceBodySchema
472
516
  ]);
473
517
  var REGISTER_SOURCE_EVENT = "dev.trigger.source.register";
474
- var RegisterTriggerSourceSchema = import_zod8.z.object({
475
- key: import_zod8.z.string(),
476
- params: import_zod8.z.any(),
477
- active: import_zod8.z.boolean(),
478
- secret: import_zod8.z.string(),
518
+ var RegisterTriggerSourceSchema = import_zod9.z.object({
519
+ key: import_zod9.z.string(),
520
+ params: import_zod9.z.any(),
521
+ active: import_zod9.z.boolean(),
522
+ secret: import_zod9.z.string(),
479
523
  data: DeserializedJsonSchema.optional(),
480
524
  channel: RegisterSourceChannelBodySchema,
481
- clientId: import_zod8.z.string().optional()
525
+ clientId: import_zod9.z.string().optional()
482
526
  });
483
- var RegisterSourceEventSchema = import_zod8.z.object({
484
- id: import_zod8.z.string(),
527
+ var RegisterSourceEventSchema = import_zod9.z.object({
528
+ id: import_zod9.z.string(),
485
529
  source: RegisterTriggerSourceSchema,
486
- events: import_zod8.z.array(import_zod8.z.string()),
487
- missingEvents: import_zod8.z.array(import_zod8.z.string()),
488
- orphanedEvents: import_zod8.z.array(import_zod8.z.string()),
489
- dynamicTriggerId: import_zod8.z.string().optional()
490
- });
491
- var TriggerSourceSchema = import_zod8.z.object({
492
- id: import_zod8.z.string(),
493
- key: import_zod8.z.string()
494
- });
495
- var HandleTriggerSourceSchema = import_zod8.z.object({
496
- key: import_zod8.z.string(),
497
- secret: import_zod8.z.string(),
498
- data: import_zod8.z.any(),
499
- params: import_zod8.z.any()
500
- });
501
- var HttpSourceRequestSchema = import_zod8.z.object({
502
- url: import_zod8.z.string().url(),
503
- method: import_zod8.z.string(),
504
- headers: import_zod8.z.record(import_zod8.z.string()),
505
- rawBody: import_zod8.z.instanceof(Buffer).optional().nullable()
506
- });
507
- var HttpSourceRequestHeadersSchema = import_zod8.z.object({
508
- "x-ts-key": import_zod8.z.string(),
509
- "x-ts-dynamic-id": import_zod8.z.string().optional(),
510
- "x-ts-secret": import_zod8.z.string(),
511
- "x-ts-data": import_zod8.z.string().transform((s) => JSON.parse(s)),
512
- "x-ts-params": import_zod8.z.string().transform((s) => JSON.parse(s)),
513
- "x-ts-http-url": import_zod8.z.string(),
514
- "x-ts-http-method": import_zod8.z.string(),
515
- "x-ts-http-headers": import_zod8.z.string().transform((s) => import_zod8.z.record(import_zod8.z.string()).parse(JSON.parse(s)))
516
- });
517
- var PongResponseSchema = import_zod8.z.object({
518
- message: import_zod8.z.literal("PONG")
519
- });
520
- var QueueOptionsSchema = import_zod8.z.object({
521
- name: import_zod8.z.string(),
522
- maxConcurrent: import_zod8.z.number().optional()
523
- });
524
- var JobMetadataSchema = import_zod8.z.object({
525
- id: import_zod8.z.string(),
526
- name: import_zod8.z.string(),
527
- version: import_zod8.z.string(),
530
+ events: import_zod9.z.array(import_zod9.z.string()),
531
+ missingEvents: import_zod9.z.array(import_zod9.z.string()),
532
+ orphanedEvents: import_zod9.z.array(import_zod9.z.string()),
533
+ dynamicTriggerId: import_zod9.z.string().optional()
534
+ });
535
+ var TriggerSourceSchema = import_zod9.z.object({
536
+ id: import_zod9.z.string(),
537
+ key: import_zod9.z.string()
538
+ });
539
+ var HandleTriggerSourceSchema = import_zod9.z.object({
540
+ key: import_zod9.z.string(),
541
+ secret: import_zod9.z.string(),
542
+ data: import_zod9.z.any(),
543
+ params: import_zod9.z.any()
544
+ });
545
+ var HttpSourceRequestSchema = import_zod9.z.object({
546
+ url: import_zod9.z.string().url(),
547
+ method: import_zod9.z.string(),
548
+ headers: import_zod9.z.record(import_zod9.z.string()),
549
+ rawBody: import_zod9.z.instanceof(Buffer).optional().nullable()
550
+ });
551
+ var HttpSourceRequestHeadersSchema = import_zod9.z.object({
552
+ "x-ts-key": import_zod9.z.string(),
553
+ "x-ts-dynamic-id": import_zod9.z.string().optional(),
554
+ "x-ts-secret": import_zod9.z.string(),
555
+ "x-ts-data": import_zod9.z.string().transform((s) => JSON.parse(s)),
556
+ "x-ts-params": import_zod9.z.string().transform((s) => JSON.parse(s)),
557
+ "x-ts-http-url": import_zod9.z.string(),
558
+ "x-ts-http-method": import_zod9.z.string(),
559
+ "x-ts-http-headers": import_zod9.z.string().transform((s) => import_zod9.z.record(import_zod9.z.string()).parse(JSON.parse(s)))
560
+ });
561
+ var PongSuccessResponseSchema = import_zod9.z.object({
562
+ ok: import_zod9.z.literal(true)
563
+ });
564
+ var PongErrorResponseSchema = import_zod9.z.object({
565
+ ok: import_zod9.z.literal(false),
566
+ error: import_zod9.z.string()
567
+ });
568
+ var PongResponseSchema = import_zod9.z.discriminatedUnion("ok", [
569
+ PongSuccessResponseSchema,
570
+ PongErrorResponseSchema
571
+ ]);
572
+ var QueueOptionsSchema = import_zod9.z.object({
573
+ name: import_zod9.z.string(),
574
+ maxConcurrent: import_zod9.z.number().optional()
575
+ });
576
+ var JobMetadataSchema = import_zod9.z.object({
577
+ id: import_zod9.z.string(),
578
+ name: import_zod9.z.string(),
579
+ version: import_zod9.z.string(),
528
580
  event: EventSpecificationSchema,
529
581
  trigger: TriggerMetadataSchema,
530
- integrations: import_zod8.z.record(IntegrationConfigSchema),
531
- internal: import_zod8.z.boolean().default(false),
532
- queue: import_zod8.z.union([
582
+ integrations: import_zod9.z.record(IntegrationConfigSchema),
583
+ internal: import_zod9.z.boolean().default(false),
584
+ queue: import_zod9.z.union([
533
585
  QueueOptionsSchema,
534
- import_zod8.z.string()
586
+ import_zod9.z.string()
535
587
  ]).optional(),
536
- startPosition: import_zod8.z.enum([
588
+ startPosition: import_zod9.z.enum([
537
589
  "initial",
538
590
  "latest"
539
591
  ]),
540
- enabled: import_zod8.z.boolean(),
541
- preprocessRuns: import_zod8.z.boolean()
592
+ enabled: import_zod9.z.boolean(),
593
+ preprocessRuns: import_zod9.z.boolean()
542
594
  });
543
- var SourceMetadataSchema = import_zod8.z.object({
544
- channel: import_zod8.z.enum([
595
+ var SourceMetadataSchema = import_zod9.z.object({
596
+ channel: import_zod9.z.enum([
545
597
  "HTTP",
546
598
  "SQS",
547
599
  "SMTP"
548
600
  ]),
549
- key: import_zod8.z.string(),
550
- params: import_zod8.z.any(),
551
- events: import_zod8.z.array(import_zod8.z.string()),
552
- clientId: import_zod8.z.string().optional()
553
- });
554
- var DynamicTriggerEndpointMetadataSchema = import_zod8.z.object({
555
- id: import_zod8.z.string(),
556
- jobs: import_zod8.z.array(JobMetadataSchema.pick({
601
+ integration: IntegrationConfigSchema,
602
+ key: import_zod9.z.string(),
603
+ params: import_zod9.z.any(),
604
+ events: import_zod9.z.array(import_zod9.z.string())
605
+ });
606
+ var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
607
+ id: import_zod9.z.string(),
608
+ jobs: import_zod9.z.array(JobMetadataSchema.pick({
557
609
  id: true,
558
610
  version: true
559
611
  }))
560
612
  });
561
- var GetEndpointDataResponseSchema = import_zod8.z.object({
562
- jobs: import_zod8.z.array(JobMetadataSchema),
563
- sources: import_zod8.z.array(SourceMetadataSchema),
564
- dynamicTriggers: import_zod8.z.array(DynamicTriggerEndpointMetadataSchema),
565
- dynamicSchedules: import_zod8.z.array(RegisterDynamicSchedulePayloadSchema)
566
- });
567
- var RawEventSchema = import_zod8.z.object({
568
- id: import_zod8.z.string().default(() => (0, import_ulid.ulid)()),
569
- name: import_zod8.z.string(),
570
- source: import_zod8.z.string().optional(),
571
- payload: import_zod8.z.any(),
572
- context: import_zod8.z.any().optional(),
573
- timestamp: import_zod8.z.string().datetime().optional()
574
- });
575
- var ApiEventLogSchema = import_zod8.z.object({
576
- id: import_zod8.z.string(),
577
- name: import_zod8.z.string(),
613
+ var IndexEndpointResponseSchema = import_zod9.z.object({
614
+ jobs: import_zod9.z.array(JobMetadataSchema),
615
+ sources: import_zod9.z.array(SourceMetadataSchema),
616
+ dynamicTriggers: import_zod9.z.array(DynamicTriggerEndpointMetadataSchema),
617
+ dynamicSchedules: import_zod9.z.array(RegisterDynamicSchedulePayloadSchema)
618
+ });
619
+ var RawEventSchema = import_zod9.z.object({
620
+ name: import_zod9.z.string(),
621
+ payload: import_zod9.z.any(),
622
+ context: import_zod9.z.any().optional(),
623
+ id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
624
+ timestamp: import_zod9.z.coerce.date().optional(),
625
+ source: import_zod9.z.string().optional()
626
+ });
627
+ var ApiEventLogSchema = import_zod9.z.object({
628
+ id: import_zod9.z.string(),
629
+ name: import_zod9.z.string(),
578
630
  payload: DeserializedJsonSchema,
579
631
  context: DeserializedJsonSchema.optional().nullable(),
580
- timestamp: import_zod8.z.coerce.date(),
581
- deliverAt: import_zod8.z.coerce.date().optional().nullable(),
582
- deliveredAt: import_zod8.z.coerce.date().optional().nullable()
632
+ timestamp: import_zod9.z.coerce.date(),
633
+ deliverAt: import_zod9.z.coerce.date().optional().nullable(),
634
+ deliveredAt: import_zod9.z.coerce.date().optional().nullable()
583
635
  });
584
- var SendEventOptionsSchema = import_zod8.z.object({
585
- deliverAt: import_zod8.z.string().datetime().optional(),
586
- deliverAfter: import_zod8.z.number().int().optional(),
587
- accountId: import_zod8.z.string().optional()
636
+ var SendEventOptionsSchema = import_zod9.z.object({
637
+ deliverAt: import_zod9.z.coerce.date().optional(),
638
+ deliverAfter: import_zod9.z.number().int().optional(),
639
+ accountId: import_zod9.z.string().optional()
588
640
  });
589
- var SendEventBodySchema = import_zod8.z.object({
641
+ var SendEventBodySchema = import_zod9.z.object({
590
642
  event: RawEventSchema,
591
643
  options: SendEventOptionsSchema.optional()
592
644
  });
593
- var DeliverEventResponseSchema = import_zod8.z.object({
594
- deliveredAt: import_zod8.z.string().datetime()
645
+ var DeliverEventResponseSchema = import_zod9.z.object({
646
+ deliveredAt: import_zod9.z.string().datetime()
595
647
  });
596
- var RuntimeEnvironmentTypeSchema = import_zod8.z.enum([
648
+ var RuntimeEnvironmentTypeSchema = import_zod9.z.enum([
597
649
  "PRODUCTION",
598
650
  "STAGING",
599
651
  "DEVELOPMENT",
600
652
  "PREVIEW"
601
653
  ]);
602
- var RunJobBodySchema = import_zod8.z.object({
654
+ var RunSourceContextSchema = import_zod9.z.object({
655
+ id: import_zod9.z.string(),
656
+ metadata: import_zod9.z.any()
657
+ });
658
+ var RunJobBodySchema = import_zod9.z.object({
603
659
  event: ApiEventLogSchema,
604
- job: import_zod8.z.object({
605
- id: import_zod8.z.string(),
606
- version: import_zod8.z.string()
660
+ job: import_zod9.z.object({
661
+ id: import_zod9.z.string(),
662
+ version: import_zod9.z.string()
607
663
  }),
608
- run: import_zod8.z.object({
609
- id: import_zod8.z.string(),
610
- isTest: import_zod8.z.boolean(),
611
- startedAt: import_zod8.z.coerce.date()
664
+ run: import_zod9.z.object({
665
+ id: import_zod9.z.string(),
666
+ isTest: import_zod9.z.boolean(),
667
+ startedAt: import_zod9.z.coerce.date()
612
668
  }),
613
- environment: import_zod8.z.object({
614
- id: import_zod8.z.string(),
615
- slug: import_zod8.z.string(),
669
+ environment: import_zod9.z.object({
670
+ id: import_zod9.z.string(),
671
+ slug: import_zod9.z.string(),
616
672
  type: RuntimeEnvironmentTypeSchema
617
673
  }),
618
- organization: import_zod8.z.object({
619
- id: import_zod8.z.string(),
620
- title: import_zod8.z.string(),
621
- slug: import_zod8.z.string()
674
+ organization: import_zod9.z.object({
675
+ id: import_zod9.z.string(),
676
+ title: import_zod9.z.string(),
677
+ slug: import_zod9.z.string()
622
678
  }),
623
- account: import_zod8.z.object({
624
- id: import_zod8.z.string(),
625
- metadata: import_zod8.z.any()
679
+ account: import_zod9.z.object({
680
+ id: import_zod9.z.string(),
681
+ metadata: import_zod9.z.any()
626
682
  }).optional(),
627
- tasks: import_zod8.z.array(CachedTaskSchema).optional(),
628
- connections: import_zod8.z.record(ConnectionAuthSchema).optional()
683
+ source: RunSourceContextSchema.optional(),
684
+ tasks: import_zod9.z.array(CachedTaskSchema).optional(),
685
+ connections: import_zod9.z.record(ConnectionAuthSchema).optional()
629
686
  });
630
- var RunJobResponseSchema = import_zod8.z.object({
631
- executionId: import_zod8.z.string(),
632
- completed: import_zod8.z.boolean(),
633
- output: DeserializedJsonSchema.optional(),
687
+ var RunJobErrorSchema = import_zod9.z.object({
688
+ status: import_zod9.z.literal("ERROR"),
689
+ error: ErrorWithStackSchema,
634
690
  task: TaskSchema.optional()
635
691
  });
636
- var PreprocessRunBodySchema = import_zod8.z.object({
692
+ var RunJobResumeWithTaskSchema = import_zod9.z.object({
693
+ status: import_zod9.z.literal("RESUME_WITH_TASK"),
694
+ task: TaskSchema
695
+ });
696
+ var RunJobRetryWithTaskSchema = import_zod9.z.object({
697
+ status: import_zod9.z.literal("RETRY_WITH_TASK"),
698
+ task: TaskSchema,
699
+ error: ErrorWithStackSchema,
700
+ retryAt: import_zod9.z.coerce.date()
701
+ });
702
+ var RunJobSuccessSchema = import_zod9.z.object({
703
+ status: import_zod9.z.literal("SUCCESS"),
704
+ output: DeserializedJsonSchema.optional()
705
+ });
706
+ var RunJobResponseSchema = import_zod9.z.discriminatedUnion("status", [
707
+ RunJobErrorSchema,
708
+ RunJobResumeWithTaskSchema,
709
+ RunJobRetryWithTaskSchema,
710
+ RunJobSuccessSchema
711
+ ]);
712
+ var PreprocessRunBodySchema = import_zod9.z.object({
637
713
  event: ApiEventLogSchema,
638
- job: import_zod8.z.object({
639
- id: import_zod8.z.string(),
640
- version: import_zod8.z.string()
714
+ job: import_zod9.z.object({
715
+ id: import_zod9.z.string(),
716
+ version: import_zod9.z.string()
641
717
  }),
642
- run: import_zod8.z.object({
643
- id: import_zod8.z.string(),
644
- isTest: import_zod8.z.boolean()
718
+ run: import_zod9.z.object({
719
+ id: import_zod9.z.string(),
720
+ isTest: import_zod9.z.boolean()
645
721
  }),
646
- environment: import_zod8.z.object({
647
- id: import_zod8.z.string(),
648
- slug: import_zod8.z.string(),
722
+ environment: import_zod9.z.object({
723
+ id: import_zod9.z.string(),
724
+ slug: import_zod9.z.string(),
649
725
  type: RuntimeEnvironmentTypeSchema
650
726
  }),
651
- organization: import_zod8.z.object({
652
- id: import_zod8.z.string(),
653
- title: import_zod8.z.string(),
654
- slug: import_zod8.z.string()
727
+ organization: import_zod9.z.object({
728
+ id: import_zod9.z.string(),
729
+ title: import_zod9.z.string(),
730
+ slug: import_zod9.z.string()
655
731
  }),
656
- account: import_zod8.z.object({
657
- id: import_zod8.z.string(),
658
- metadata: import_zod8.z.any()
732
+ account: import_zod9.z.object({
733
+ id: import_zod9.z.string(),
734
+ metadata: import_zod9.z.any()
659
735
  }).optional()
660
736
  });
661
- var PreprocessRunResponseSchema = import_zod8.z.object({
662
- abort: import_zod8.z.boolean(),
663
- properties: import_zod8.z.array(DisplayPropertySchema).optional()
737
+ var PreprocessRunResponseSchema = import_zod9.z.object({
738
+ abort: import_zod9.z.boolean(),
739
+ properties: import_zod9.z.array(DisplayPropertySchema).optional()
664
740
  });
665
- var CreateRunBodySchema = import_zod8.z.object({
666
- client: import_zod8.z.string(),
741
+ var CreateRunBodySchema = import_zod9.z.object({
742
+ client: import_zod9.z.string(),
667
743
  job: JobMetadataSchema,
668
744
  event: ApiEventLogSchema,
669
- properties: import_zod8.z.array(DisplayPropertySchema).optional()
745
+ properties: import_zod9.z.array(DisplayPropertySchema).optional()
670
746
  });
671
- var CreateRunResponseOkSchema = import_zod8.z.object({
672
- ok: import_zod8.z.literal(true),
673
- data: import_zod8.z.object({
674
- id: import_zod8.z.string()
747
+ var CreateRunResponseOkSchema = import_zod9.z.object({
748
+ ok: import_zod9.z.literal(true),
749
+ data: import_zod9.z.object({
750
+ id: import_zod9.z.string()
675
751
  })
676
752
  });
677
- var CreateRunResponseErrorSchema = import_zod8.z.object({
678
- ok: import_zod8.z.literal(false),
679
- error: import_zod8.z.string()
753
+ var CreateRunResponseErrorSchema = import_zod9.z.object({
754
+ ok: import_zod9.z.literal(false),
755
+ error: import_zod9.z.string()
680
756
  });
681
- var CreateRunResponseBodySchema = import_zod8.z.discriminatedUnion("ok", [
757
+ var CreateRunResponseBodySchema = import_zod9.z.discriminatedUnion("ok", [
682
758
  CreateRunResponseOkSchema,
683
759
  CreateRunResponseErrorSchema
684
760
  ]);
685
- var SecureStringSchema = import_zod8.z.object({
686
- __secureString: import_zod8.z.literal(true),
687
- strings: import_zod8.z.array(import_zod8.z.string()),
688
- interpolations: import_zod8.z.array(import_zod8.z.string())
761
+ var RedactStringSchema = import_zod9.z.object({
762
+ __redactedString: import_zod9.z.literal(true),
763
+ strings: import_zod9.z.array(import_zod9.z.string()),
764
+ interpolations: import_zod9.z.array(import_zod9.z.string())
689
765
  });
690
- var LogMessageSchema = import_zod8.z.object({
691
- level: import_zod8.z.enum([
766
+ var LogMessageSchema = import_zod9.z.object({
767
+ level: import_zod9.z.enum([
692
768
  "DEBUG",
693
769
  "INFO",
694
770
  "WARN",
695
771
  "ERROR"
696
772
  ]),
697
- message: import_zod8.z.string(),
773
+ message: import_zod9.z.string(),
698
774
  data: SerializableJsonSchema.optional()
699
775
  });
700
- var RedactSchema = import_zod8.z.object({
701
- paths: import_zod8.z.array(import_zod8.z.string())
702
- });
703
- var RunTaskOptionsSchema = import_zod8.z.object({
704
- name: import_zod8.z.string(),
705
- icon: import_zod8.z.string().optional(),
706
- displayKey: import_zod8.z.string().optional(),
707
- noop: import_zod8.z.boolean().default(false),
708
- delayUntil: import_zod8.z.coerce.date().optional(),
709
- description: import_zod8.z.string().optional(),
710
- properties: import_zod8.z.array(DisplayPropertySchema).optional(),
711
- params: SerializableJsonSchema.optional(),
712
- trigger: TriggerMetadataSchema.optional(),
776
+ var RedactSchema = import_zod9.z.object({
777
+ paths: import_zod9.z.array(import_zod9.z.string())
778
+ });
779
+ var RetryOptionsSchema = import_zod9.z.object({
780
+ limit: import_zod9.z.number().optional(),
781
+ factor: import_zod9.z.number().optional(),
782
+ minTimeoutInMs: import_zod9.z.number().optional(),
783
+ maxTimeoutInMs: import_zod9.z.number().optional(),
784
+ randomize: import_zod9.z.boolean().optional()
785
+ });
786
+ var RunTaskOptionsSchema = import_zod9.z.object({
787
+ name: import_zod9.z.string(),
788
+ delayUntil: import_zod9.z.coerce.date().optional(),
789
+ retry: RetryOptionsSchema.optional(),
790
+ icon: import_zod9.z.string().optional(),
791
+ displayKey: import_zod9.z.string().optional(),
792
+ description: import_zod9.z.string().optional(),
793
+ properties: import_zod9.z.array(DisplayPropertySchema).optional(),
794
+ params: import_zod9.z.any(),
795
+ style: StyleSchema.optional(),
796
+ connectionKey: import_zod9.z.string().optional(),
797
+ operation: import_zod9.z.enum([
798
+ "fetch"
799
+ ]).optional(),
800
+ noop: import_zod9.z.boolean().default(false),
713
801
  redact: RedactSchema.optional(),
714
- connectionKey: import_zod8.z.string().optional(),
715
- style: StyleSchema.optional()
802
+ trigger: TriggerMetadataSchema.optional()
716
803
  });
717
804
  var RunTaskBodyInputSchema = RunTaskOptionsSchema.extend({
718
- idempotencyKey: import_zod8.z.string(),
719
- parentId: import_zod8.z.string().optional()
805
+ idempotencyKey: import_zod9.z.string(),
806
+ parentId: import_zod9.z.string().optional()
720
807
  });
721
808
  var RunTaskBodyOutputSchema = RunTaskBodyInputSchema.extend({
722
809
  params: DeserializedJsonSchema.optional().nullable()
@@ -728,64 +815,59 @@ var CompleteTaskBodyInputSchema = RunTaskBodyInputSchema.pick({
728
815
  }).extend({
729
816
  output: SerializableJsonSchema.optional().transform((v) => v ? DeserializedJsonSchema.parse(JSON.parse(JSON.stringify(v))) : {})
730
817
  });
731
- var NormalizedRequestSchema = import_zod8.z.object({
732
- headers: import_zod8.z.record(import_zod8.z.string()),
733
- method: import_zod8.z.string(),
734
- query: import_zod8.z.record(import_zod8.z.string()),
735
- url: import_zod8.z.string(),
736
- body: import_zod8.z.any()
818
+ var FailTaskBodyInputSchema = import_zod9.z.object({
819
+ error: ErrorWithStackSchema
820
+ });
821
+ var NormalizedRequestSchema = import_zod9.z.object({
822
+ headers: import_zod9.z.record(import_zod9.z.string()),
823
+ method: import_zod9.z.string(),
824
+ query: import_zod9.z.record(import_zod9.z.string()),
825
+ url: import_zod9.z.string(),
826
+ body: import_zod9.z.any()
737
827
  });
738
- var NormalizedResponseSchema = import_zod8.z.object({
739
- status: import_zod8.z.number(),
740
- body: import_zod8.z.any(),
741
- headers: import_zod8.z.record(import_zod8.z.string()).optional()
828
+ var NormalizedResponseSchema = import_zod9.z.object({
829
+ status: import_zod9.z.number(),
830
+ body: import_zod9.z.any(),
831
+ headers: import_zod9.z.record(import_zod9.z.string()).optional()
742
832
  });
743
- var HttpSourceResponseSchema = import_zod8.z.object({
833
+ var HttpSourceResponseSchema = import_zod9.z.object({
744
834
  response: NormalizedResponseSchema,
745
- events: import_zod8.z.array(RawEventSchema)
835
+ events: import_zod9.z.array(RawEventSchema)
746
836
  });
747
- var RegisterTriggerBodySchema = import_zod8.z.object({
837
+ var RegisterTriggerBodySchema = import_zod9.z.object({
748
838
  rule: EventRuleSchema,
749
839
  source: SourceMetadataSchema
750
840
  });
751
- var InitializeTriggerBodySchema = import_zod8.z.object({
752
- id: import_zod8.z.string(),
753
- params: import_zod8.z.any(),
754
- accountId: import_zod8.z.string().optional()
841
+ var InitializeTriggerBodySchema = import_zod9.z.object({
842
+ id: import_zod9.z.string(),
843
+ params: import_zod9.z.any(),
844
+ accountId: import_zod9.z.string().optional(),
845
+ metadata: import_zod9.z.any().optional()
755
846
  });
756
- var RegisterCommonScheduleBodySchema = import_zod8.z.object({
757
- id: import_zod8.z.string(),
758
- metadata: import_zod8.z.any(),
759
- accountId: import_zod8.z.string().optional()
847
+ var RegisterCommonScheduleBodySchema = import_zod9.z.object({
848
+ id: import_zod9.z.string(),
849
+ metadata: import_zod9.z.any(),
850
+ accountId: import_zod9.z.string().optional()
760
851
  });
761
852
  var RegisterIntervalScheduleBodySchema = RegisterCommonScheduleBodySchema.merge(IntervalMetadataSchema);
762
853
  var InitializeCronScheduleBodySchema = RegisterCommonScheduleBodySchema.merge(CronMetadataSchema);
763
- var RegisterScheduleBodySchema = import_zod8.z.discriminatedUnion("type", [
854
+ var RegisterScheduleBodySchema = import_zod9.z.discriminatedUnion("type", [
764
855
  RegisterIntervalScheduleBodySchema,
765
856
  InitializeCronScheduleBodySchema
766
857
  ]);
767
- var RegisterScheduleResponseBodySchema = import_zod8.z.object({
768
- id: import_zod8.z.string(),
858
+ var RegisterScheduleResponseBodySchema = import_zod9.z.object({
859
+ id: import_zod9.z.string(),
769
860
  schedule: ScheduleMetadataSchema,
770
- metadata: import_zod8.z.any(),
771
- active: import_zod8.z.boolean()
861
+ metadata: import_zod9.z.any(),
862
+ active: import_zod9.z.boolean()
772
863
  });
773
- var CreateExternalConnectionBodySchema = import_zod8.z.object({
774
- accessToken: import_zod8.z.string(),
775
- type: import_zod8.z.enum([
864
+ var CreateExternalConnectionBodySchema = import_zod9.z.object({
865
+ accessToken: import_zod9.z.string(),
866
+ type: import_zod9.z.enum([
776
867
  "oauth2"
777
868
  ]),
778
- scopes: import_zod8.z.array(import_zod8.z.string()).optional(),
779
- metadata: import_zod8.z.any()
780
- });
781
-
782
- // ../internal/src/schemas/errors.ts
783
- var import_zod9 = require("zod");
784
- var ErrorWithMessage = import_zod9.z.object({
785
- message: import_zod9.z.string()
786
- });
787
- var ErrorWithStackSchema = ErrorWithMessage.extend({
788
- stack: import_zod9.z.string().optional()
869
+ scopes: import_zod9.z.array(import_zod9.z.string()).optional(),
870
+ metadata: import_zod9.z.any()
789
871
  });
790
872
 
791
873
  // ../internal/src/schemas/notifications.ts
@@ -799,9 +881,7 @@ var CommonMissingConnectionNotificationPayloadSchema = import_zod10.z.object({
799
881
  title: import_zod10.z.string(),
800
882
  scopes: import_zod10.z.array(import_zod10.z.string()),
801
883
  createdAt: import_zod10.z.coerce.date(),
802
- updatedAt: import_zod10.z.coerce.date(),
803
- integrationIdentifier: import_zod10.z.string(),
804
- integrationAuthMethod: import_zod10.z.string()
884
+ updatedAt: import_zod10.z.coerce.date()
805
885
  }),
806
886
  authorizationUrl: import_zod10.z.string()
807
887
  });
@@ -847,6 +927,39 @@ var MissingConnectionResolvedNotificationPayloadSchema = import_zod10.z.discrimi
847
927
  MissingExternalConnectionResolvedNotificationPayloadSchema
848
928
  ]);
849
929
 
930
+ // ../internal/src/schemas/fetch.ts
931
+ var import_zod11 = require("zod");
932
+ var FetchRetryHeadersStrategySchema = import_zod11.z.object({
933
+ strategy: import_zod11.z.literal("headers"),
934
+ limitHeader: import_zod11.z.string(),
935
+ remainingHeader: import_zod11.z.string(),
936
+ resetHeader: import_zod11.z.string()
937
+ });
938
+ var FetchRetryBackoffStrategySchema = RetryOptionsSchema.extend({
939
+ strategy: import_zod11.z.literal("backoff")
940
+ });
941
+ var FetchRetryStrategySchema = import_zod11.z.discriminatedUnion("strategy", [
942
+ FetchRetryHeadersStrategySchema,
943
+ FetchRetryBackoffStrategySchema
944
+ ]);
945
+ var FetchRequestInitSchema = import_zod11.z.object({
946
+ method: import_zod11.z.string().optional(),
947
+ headers: import_zod11.z.record(import_zod11.z.union([
948
+ import_zod11.z.string(),
949
+ RedactStringSchema
950
+ ])).optional(),
951
+ body: import_zod11.z.union([
952
+ import_zod11.z.string(),
953
+ import_zod11.z.instanceof(ArrayBuffer)
954
+ ]).optional()
955
+ });
956
+ var FetchRetryOptionsSchema = import_zod11.z.record(FetchRetryStrategySchema);
957
+ var FetchOperationSchema = import_zod11.z.object({
958
+ url: import_zod11.z.string(),
959
+ requestInit: FetchRequestInitSchema.optional(),
960
+ retry: import_zod11.z.record(FetchRetryStrategySchema).optional()
961
+ });
962
+
850
963
  // ../internal/src/utils.ts
851
964
  function deepMergeFilters(filter, other) {
852
965
  const result = {
@@ -873,8 +986,40 @@ function deepMergeFilters(filter, other) {
873
986
  }
874
987
  __name(deepMergeFilters, "deepMergeFilters");
875
988
 
989
+ // ../internal/src/retry.ts
990
+ var DEFAULT_RETRY_OPTIONS = {
991
+ limit: 5,
992
+ factor: 1.8,
993
+ minTimeoutInMs: 1e3,
994
+ maxTimeoutInMs: 6e4,
995
+ randomize: true
996
+ };
997
+ function calculateRetryAt(retryOptions, attempts) {
998
+ const options = {
999
+ ...DEFAULT_RETRY_OPTIONS,
1000
+ ...retryOptions
1001
+ };
1002
+ const retryCount = attempts + 1;
1003
+ if (retryCount >= options.limit) {
1004
+ return;
1005
+ }
1006
+ const random = options.randomize ? Math.random() + 1 : 1;
1007
+ let timeoutInMs = Math.round(random * Math.max(options.minTimeoutInMs, 1) * Math.pow(options.factor, Math.max(attempts - 1, 0)));
1008
+ timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);
1009
+ return new Date(Date.now() + timeoutInMs);
1010
+ }
1011
+ __name(calculateRetryAt, "calculateRetryAt");
1012
+
1013
+ // ../internal/src/replacements.ts
1014
+ var currentDate = {
1015
+ marker: "__CURRENT_DATE__",
1016
+ replace({ data: { now } }) {
1017
+ return now.toISOString();
1018
+ }
1019
+ };
1020
+
876
1021
  // src/apiClient.ts
877
- var import_zod11 = require("zod");
1022
+ var import_zod12 = require("zod");
878
1023
  var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
879
1024
  var ApiClient = class {
880
1025
  constructor(options) {
@@ -955,6 +1100,22 @@ var ApiClient = class {
955
1100
  body: JSON.stringify(task)
956
1101
  });
957
1102
  }
1103
+ async failTask(runId, id, body) {
1104
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
1105
+ __privateGet(this, _logger).debug("Fail Task", {
1106
+ id,
1107
+ runId,
1108
+ body
1109
+ });
1110
+ return await zodfetch(ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/fail`, {
1111
+ method: "POST",
1112
+ headers: {
1113
+ "Content-Type": "application/json",
1114
+ Authorization: `Bearer ${apiKey}`
1115
+ },
1116
+ body: JSON.stringify(body)
1117
+ });
1118
+ }
958
1119
  async sendEvent(event, options = {}) {
959
1120
  const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
960
1121
  __privateGet(this, _logger).debug("Sending event", {
@@ -1027,8 +1188,8 @@ var ApiClient = class {
1027
1188
  __privateGet(this, _logger).debug("unregistering schedule", {
1028
1189
  id
1029
1190
  });
1030
- const response = await zodfetch(import_zod11.z.object({
1031
- ok: import_zod11.z.boolean()
1191
+ const response = await zodfetch(import_zod12.z.object({
1192
+ ok: import_zod12.z.boolean()
1032
1193
  }), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
1033
1194
  method: "DELETE",
1034
1195
  headers: {
@@ -1106,6 +1267,26 @@ async function zodfetch(schema, url, requestInit, options) {
1106
1267
  }
1107
1268
  __name(zodfetch, "zodfetch");
1108
1269
 
1270
+ // src/errors.ts
1271
+ var ResumeWithTaskError = class {
1272
+ constructor(task) {
1273
+ this.task = task;
1274
+ }
1275
+ };
1276
+ __name(ResumeWithTaskError, "ResumeWithTaskError");
1277
+ var RetryWithTaskError = class {
1278
+ constructor(cause, task, retryAt) {
1279
+ this.cause = cause;
1280
+ this.task = task;
1281
+ this.retryAt = retryAt;
1282
+ }
1283
+ };
1284
+ __name(RetryWithTaskError, "RetryWithTaskError");
1285
+ function isTriggerError(err) {
1286
+ return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError;
1287
+ }
1288
+ __name(isTriggerError, "isTriggerError");
1289
+
1109
1290
  // src/io.ts
1110
1291
  var import_node_async_hooks = require("async_hooks");
1111
1292
  var import_node_crypto = require("crypto");
@@ -1116,11 +1297,12 @@ function createIOWithIntegrations(io, auths, integrations) {
1116
1297
  return io;
1117
1298
  }
1118
1299
  const connections = Object.entries(integrations).reduce((acc, [connectionKey, integration]) => {
1119
- const connection = auths?.[connectionKey];
1120
- const client = "client" in integration.client ? integration.client.client : connection ? integration.client.clientFactory?.(connection) : void 0;
1300
+ let auth = auths?.[connectionKey];
1301
+ const client = integration.client.usesLocalAuth ? integration.client.client : auth ? integration.client.clientFactory?.(auth) : void 0;
1121
1302
  if (!client) {
1122
1303
  return acc;
1123
1304
  }
1305
+ auth = integration.client.usesLocalAuth ? integration.client.auth : auth;
1124
1306
  const ioConnection = {
1125
1307
  client
1126
1308
  };
@@ -1132,8 +1314,8 @@ function createIOWithIntegrations(io, auths, integrations) {
1132
1314
  const options = authenticatedTask2.init(params);
1133
1315
  options.connectionKey = connectionKey;
1134
1316
  return await io.runTask(key, options, async (ioTask) => {
1135
- return authenticatedTask2.run(params, client, ioTask, io);
1136
- });
1317
+ return authenticatedTask2.run(params, client, ioTask, io, auth);
1318
+ }, authenticatedTask2.onError);
1137
1319
  };
1138
1320
  });
1139
1321
  }
@@ -1156,12 +1338,6 @@ function createIOWithIntegrations(io, auths, integrations) {
1156
1338
  __name(createIOWithIntegrations, "createIOWithIntegrations");
1157
1339
 
1158
1340
  // src/io.ts
1159
- var ResumeWithTask = class {
1160
- constructor(task) {
1161
- this.task = task;
1162
- }
1163
- };
1164
- __name(ResumeWithTask, "ResumeWithTask");
1165
1341
  var _addToCachedTasks, addToCachedTasks_fn;
1166
1342
  var IO = class {
1167
1343
  constructor(options) {
@@ -1171,6 +1347,8 @@ var IO = class {
1171
1347
  this._triggerClient = options.client;
1172
1348
  this._logger = options.logger ?? new Logger("trigger.dev", options.logLevel);
1173
1349
  this._cachedTasks = /* @__PURE__ */ new Map();
1350
+ this._jobLogger = options.jobLogger;
1351
+ this._jobLogLevel = options.jobLogLevel;
1174
1352
  if (options.cachedTasks) {
1175
1353
  options.cachedTasks.forEach((task) => {
1176
1354
  this._cachedTasks.set(task.id, task);
@@ -1181,45 +1359,57 @@ var IO = class {
1181
1359
  }
1182
1360
  get logger() {
1183
1361
  return new IOLogger(async (level, message, data) => {
1362
+ let logLevel = "info";
1184
1363
  switch (level) {
1364
+ case "LOG": {
1365
+ this._jobLogger?.log(message, data);
1366
+ logLevel = "log";
1367
+ break;
1368
+ }
1185
1369
  case "DEBUG": {
1186
- this._logger.debug(message, data);
1370
+ this._jobLogger?.debug(message, data);
1371
+ logLevel = "debug";
1187
1372
  break;
1188
1373
  }
1189
1374
  case "INFO": {
1190
- this._logger.info(message, data);
1375
+ this._jobLogger?.info(message, data);
1376
+ logLevel = "info";
1191
1377
  break;
1192
1378
  }
1193
1379
  case "WARN": {
1194
- this._logger.warn(message, data);
1380
+ this._jobLogger?.warn(message, data);
1381
+ logLevel = "warn";
1195
1382
  break;
1196
1383
  }
1197
1384
  case "ERROR": {
1198
- this._logger.error(message, data);
1385
+ this._jobLogger?.error(message, data);
1386
+ logLevel = "error";
1199
1387
  break;
1200
1388
  }
1201
1389
  }
1202
- await this.runTask([
1203
- message,
1204
- level
1205
- ], {
1206
- name: "log",
1207
- icon: "log",
1208
- description: message,
1209
- params: data,
1210
- properties: [
1211
- {
1212
- label: "Level",
1213
- text: level
1214
- }
1215
- ],
1216
- style: {
1217
- style: "minimal",
1218
- variant: level.toLowerCase()
1219
- },
1220
- noop: true
1221
- }, async (task) => {
1222
- });
1390
+ if (Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
1391
+ await this.runTask([
1392
+ message,
1393
+ level
1394
+ ], {
1395
+ name: "log",
1396
+ icon: "log",
1397
+ description: message,
1398
+ params: data,
1399
+ properties: [
1400
+ {
1401
+ label: "Level",
1402
+ text: level
1403
+ }
1404
+ ],
1405
+ style: {
1406
+ style: "minimal",
1407
+ variant: level.toLowerCase()
1408
+ },
1409
+ noop: true
1410
+ }, async (task) => {
1411
+ });
1412
+ }
1223
1413
  });
1224
1414
  }
1225
1415
  async wait(key, seconds) {
@@ -1237,13 +1427,56 @@ var IO = class {
1237
1427
  }, async (task) => {
1238
1428
  });
1239
1429
  }
1430
+ async backgroundFetch(key, url, requestInit, retry) {
1431
+ const urlObject = new URL(url);
1432
+ return await this.runTask(key, {
1433
+ name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
1434
+ params: {
1435
+ url,
1436
+ requestInit,
1437
+ retry
1438
+ },
1439
+ operation: "fetch",
1440
+ icon: "background",
1441
+ noop: false,
1442
+ properties: [
1443
+ {
1444
+ label: "url",
1445
+ text: url,
1446
+ url
1447
+ },
1448
+ {
1449
+ label: "method",
1450
+ text: requestInit?.method ?? "GET"
1451
+ },
1452
+ {
1453
+ label: "background",
1454
+ text: "true"
1455
+ }
1456
+ ]
1457
+ }, async (task) => {
1458
+ return task.output;
1459
+ });
1460
+ }
1240
1461
  async sendEvent(key, event, options) {
1241
1462
  return await this.runTask(key, {
1242
1463
  name: "sendEvent",
1243
1464
  params: {
1244
1465
  event,
1245
1466
  options
1246
- }
1467
+ },
1468
+ properties: [
1469
+ {
1470
+ label: "name",
1471
+ text: event.name
1472
+ },
1473
+ ...event?.id ? [
1474
+ {
1475
+ label: "ID",
1476
+ text: event.id
1477
+ }
1478
+ ] : []
1479
+ ]
1247
1480
  }, async (task) => {
1248
1481
  return await this._triggerClient.sendEvent(event, options);
1249
1482
  });
@@ -1401,7 +1634,7 @@ var IO = class {
1401
1634
  return await this._triggerClient.getAuth(clientId);
1402
1635
  });
1403
1636
  }
1404
- async runTask(key, options, callback) {
1637
+ async runTask(key, options, callback, onError) {
1405
1638
  const parentId = this._taskStorage.getStore()?.taskId;
1406
1639
  if (parentId) {
1407
1640
  this._logger.debug("Using parent task", {
@@ -1450,7 +1683,14 @@ var IO = class {
1450
1683
  idempotencyKey,
1451
1684
  task
1452
1685
  });
1453
- throw new ResumeWithTask(task);
1686
+ throw new ResumeWithTaskError(task);
1687
+ }
1688
+ if (task.status === "RUNNING" && typeof task.operation === "string") {
1689
+ this._logger.debug("Task running operation", {
1690
+ idempotencyKey,
1691
+ task
1692
+ });
1693
+ throw new ResumeWithTaskError(task);
1454
1694
  }
1455
1695
  const executeTask = /* @__PURE__ */ __name(async () => {
1456
1696
  try {
@@ -1464,6 +1704,39 @@ var IO = class {
1464
1704
  });
1465
1705
  return result;
1466
1706
  } catch (error) {
1707
+ if (isTriggerError(error)) {
1708
+ throw error;
1709
+ }
1710
+ if (onError) {
1711
+ const onErrorResult = onError(error, task, this);
1712
+ if (onErrorResult) {
1713
+ const parsedError2 = ErrorWithStackSchema.safeParse(onErrorResult.error);
1714
+ throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
1715
+ message: "Unknown error"
1716
+ }, task, onErrorResult.retryAt);
1717
+ }
1718
+ }
1719
+ const parsedError = ErrorWithStackSchema.safeParse(error);
1720
+ if (options.retry) {
1721
+ const retryAt = calculateRetryAt(options.retry, task.attempts - 1);
1722
+ if (retryAt) {
1723
+ throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
1724
+ message: "Unknown error"
1725
+ }, task, retryAt);
1726
+ }
1727
+ }
1728
+ if (parsedError.success) {
1729
+ await this._apiClient.failTask(this._id, task.id, {
1730
+ error: parsedError.data
1731
+ });
1732
+ } else {
1733
+ await this._apiClient.failTask(this._id, task.id, {
1734
+ error: {
1735
+ message: JSON.stringify(error),
1736
+ name: "Unknown Error"
1737
+ }
1738
+ });
1739
+ }
1467
1740
  throw error;
1468
1741
  }
1469
1742
  }, "executeTask");
@@ -1471,6 +1744,16 @@ var IO = class {
1471
1744
  taskId: task.id
1472
1745
  }, executeTask);
1473
1746
  }
1747
+ async try(tryCallback, catchCallback) {
1748
+ try {
1749
+ return await tryCallback();
1750
+ } catch (error) {
1751
+ if (isTriggerError(error)) {
1752
+ throw error;
1753
+ }
1754
+ return await catchCallback(error);
1755
+ }
1756
+ }
1474
1757
  };
1475
1758
  __name(IO, "IO");
1476
1759
  _addToCachedTasks = new WeakSet();
@@ -1513,6 +1796,9 @@ var IOLogger = class {
1513
1796
  constructor(callback) {
1514
1797
  this.callback = callback;
1515
1798
  }
1799
+ log(message, properties) {
1800
+ return this.callback("LOG", message, properties);
1801
+ }
1516
1802
  debug(message, properties) {
1517
1803
  return this.callback("DEBUG", message, properties);
1518
1804
  }
@@ -1559,7 +1845,7 @@ __name(EventTrigger, "EventTrigger");
1559
1845
  _options2 = new WeakMap();
1560
1846
  function eventTrigger(options) {
1561
1847
  return new EventTrigger({
1562
- name: "Event Trigger",
1848
+ name: options.name,
1563
1849
  filter: options.filter,
1564
1850
  event: {
1565
1851
  name: options.name,
@@ -1585,7 +1871,7 @@ var registerSourceEvent = {
1585
1871
  icon: "register-source",
1586
1872
  parsePayload: RegisterSourceEventSchema.parse
1587
1873
  };
1588
- 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;
1874
+ 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;
1589
1875
  var TriggerClient = class {
1590
1876
  constructor(options) {
1591
1877
  __privateAdd(this, _preprocessRun);
@@ -1601,36 +1887,54 @@ var TriggerClient = class {
1601
1887
  __privateAdd(this, _jobMetadataByDynamicTriggers, {});
1602
1888
  __privateAdd(this, _registeredSchedules, {});
1603
1889
  __privateAdd(this, _client, void 0);
1604
- __privateAdd(this, _logger2, void 0);
1890
+ __privateAdd(this, _internalLogger, void 0);
1605
1891
  this.id = options.id;
1606
- this._url = buildClientUrl(options.url);
1607
1892
  __privateSet(this, _options3, options);
1608
1893
  __privateSet(this, _client, new ApiClient(__privateGet(this, _options3)));
1609
- __privateSet(this, _logger2, new Logger("trigger.dev", __privateGet(this, _options3).logLevel));
1610
- }
1611
- get url() {
1612
- return `${this._url}${this.path ? `${this.path.startsWith("/") ? "" : "/"}${this.path}` : ""}`;
1894
+ __privateSet(this, _internalLogger, new Logger("trigger.dev", __privateGet(this, _options3).verbose ? "debug" : "log"));
1613
1895
  }
1614
1896
  async handleRequest(request) {
1615
- __privateGet(this, _logger2).debug("handling request", {
1897
+ __privateGet(this, _internalLogger).debug("handling request", {
1616
1898
  url: request.url,
1617
1899
  headers: Object.fromEntries(request.headers.entries()),
1618
1900
  method: request.method
1619
1901
  });
1620
1902
  const apiKey = request.headers.get("x-trigger-api-key");
1621
- if (!this.authorized(apiKey)) {
1622
- return {
1623
- status: 401,
1624
- body: {
1625
- message: "Unauthorized"
1626
- }
1627
- };
1903
+ const authorization = this.authorized(apiKey);
1904
+ switch (authorization) {
1905
+ case "authorized": {
1906
+ break;
1907
+ }
1908
+ case "missing-client": {
1909
+ return {
1910
+ status: 401,
1911
+ body: {
1912
+ message: "Unauthorized: client missing apiKey"
1913
+ }
1914
+ };
1915
+ }
1916
+ case "missing-header": {
1917
+ return {
1918
+ status: 401,
1919
+ body: {
1920
+ message: "Unauthorized: missing x-trigger-api-key header"
1921
+ }
1922
+ };
1923
+ }
1924
+ case "unauthorized": {
1925
+ return {
1926
+ status: 401,
1927
+ body: {
1928
+ message: `Forbidden: client apiKey mismatch: Expected ${__privateGet(this, _options3).apiKey}, got ${apiKey}`
1929
+ }
1930
+ };
1931
+ }
1628
1932
  }
1629
1933
  if (request.method !== "POST") {
1630
1934
  return {
1631
1935
  status: 405,
1632
1936
  body: {
1633
- message: "Method not allowed"
1937
+ message: "Method not allowed (only POST is allowed)"
1634
1938
  }
1635
1939
  };
1636
1940
  }
@@ -1645,14 +1949,33 @@ var TriggerClient = class {
1645
1949
  }
1646
1950
  switch (action) {
1647
1951
  case "PING": {
1952
+ const endpointId = request.headers.get("x-trigger-endpoint-id");
1953
+ if (!endpointId) {
1954
+ return {
1955
+ status: 200,
1956
+ body: {
1957
+ ok: false,
1958
+ error: "Missing endpoint ID"
1959
+ }
1960
+ };
1961
+ }
1962
+ if (this.id !== endpointId) {
1963
+ return {
1964
+ status: 200,
1965
+ body: {
1966
+ ok: false,
1967
+ error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
1968
+ }
1969
+ };
1970
+ }
1648
1971
  return {
1649
1972
  status: 200,
1650
1973
  body: {
1651
- message: "PONG"
1974
+ ok: true
1652
1975
  }
1653
1976
  };
1654
1977
  }
1655
- case "GET_ENDPOINT_DATA": {
1978
+ case "INDEX_ENDPOINT": {
1656
1979
  const jobId = request.headers.get("x-trigger-job-id");
1657
1980
  if (jobId) {
1658
1981
  const job = __privateGet(this, _registeredJobs)[jobId];
@@ -1686,15 +2009,6 @@ var TriggerClient = class {
1686
2009
  body
1687
2010
  };
1688
2011
  }
1689
- case "INITIALIZE": {
1690
- await this.listen();
1691
- return {
1692
- status: 200,
1693
- body: {
1694
- message: "Initialized"
1695
- }
1696
- };
1697
- }
1698
2012
  case "INITIALIZE_TRIGGER": {
1699
2013
  const json = await request.json();
1700
2014
  const body = InitializeTriggerBodySchema.safeParse(json);
@@ -1741,20 +2055,9 @@ var TriggerClient = class {
1741
2055
  };
1742
2056
  }
1743
2057
  const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job);
1744
- if (results.error) {
1745
- return {
1746
- status: 500,
1747
- body: results.error
1748
- };
1749
- }
1750
2058
  return {
1751
2059
  status: 200,
1752
- body: {
1753
- completed: results.completed,
1754
- output: results.output,
1755
- executionId: execution.data.run.id,
1756
- task: results.task
1757
- }
2060
+ body: results
1758
2061
  };
1759
2062
  }
1760
2063
  case "PREPROCESS_RUN": {
@@ -1877,7 +2180,7 @@ var TriggerClient = class {
1877
2180
  }
1878
2181
  attachSource(options) {
1879
2182
  __privateGet(this, _registeredHttpSourceHandlers)[options.key] = async (s, r) => {
1880
- return await options.source.handle(s, r, __privateGet(this, _logger2));
2183
+ return await options.source.handle(s, r, __privateGet(this, _internalLogger));
1881
2184
  };
1882
2185
  let registeredSource = __privateGet(this, _registeredSources)[options.key];
1883
2186
  if (!registeredSource) {
@@ -1886,7 +2189,11 @@ var TriggerClient = class {
1886
2189
  key: options.key,
1887
2190
  params: options.params,
1888
2191
  events: [],
1889
- clientId: !options.source.integration.usesLocalAuth ? options.source.integration.id : void 0
2192
+ integration: {
2193
+ id: options.source.integration.id,
2194
+ metadata: options.source.integration.metadata,
2195
+ authSource: options.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
2196
+ }
1890
2197
  };
1891
2198
  }
1892
2199
  registeredSource.events = Array.from(/* @__PURE__ */ new Set([
@@ -1953,21 +2260,18 @@ var TriggerClient = class {
1953
2260
  return __privateGet(this, _client).unregisterSchedule(this.id, id, key);
1954
2261
  }
1955
2262
  authorized(apiKey) {
2263
+ if (typeof apiKey !== "string") {
2264
+ return "missing-header";
2265
+ }
1956
2266
  const localApiKey = __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
1957
2267
  if (!localApiKey) {
1958
- return false;
2268
+ return "missing-client";
1959
2269
  }
1960
- return apiKey === localApiKey;
2270
+ return apiKey === localApiKey ? "authorized" : "unauthorized";
1961
2271
  }
1962
2272
  apiKey() {
1963
2273
  return __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
1964
2274
  }
1965
- async listen() {
1966
- await __privateGet(this, _client).registerEndpoint({
1967
- url: this.url,
1968
- name: this.id
1969
- });
1970
- }
1971
2275
  };
1972
2276
  __name(TriggerClient, "TriggerClient");
1973
2277
  _options3 = new WeakMap();
@@ -1978,7 +2282,7 @@ _registeredDynamicTriggers = new WeakMap();
1978
2282
  _jobMetadataByDynamicTriggers = new WeakMap();
1979
2283
  _registeredSchedules = new WeakMap();
1980
2284
  _client = new WeakMap();
1981
- _logger2 = new WeakMap();
2285
+ _internalLogger = new WeakMap();
1982
2286
  _preprocessRun = new WeakSet();
1983
2287
  preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
1984
2288
  const context = __privateMethod(this, _createPreprocessRunContext, createPreprocessRunContext_fn).call(this, body);
@@ -1991,7 +2295,7 @@ preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
1991
2295
  }, "#preprocessRun");
1992
2296
  _executeJob = new WeakSet();
1993
2297
  executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
1994
- __privateGet(this, _logger2).debug("executing job", {
2298
+ __privateGet(this, _internalLogger).debug("executing job", {
1995
2299
  execution: body1,
1996
2300
  job: job1.toJSON()
1997
2301
  });
@@ -2000,40 +2304,60 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2000
2304
  id: body1.run.id,
2001
2305
  cachedTasks: body1.tasks,
2002
2306
  apiClient: __privateGet(this, _client),
2003
- logger: __privateGet(this, _logger2),
2307
+ logger: __privateGet(this, _internalLogger),
2004
2308
  client: this,
2005
- context
2309
+ context,
2310
+ jobLogLevel: job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info",
2311
+ jobLogger: __privateGet(this, _options3).ioLogLocalEnabled ? new Logger(job1.id, job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info") : void 0
2006
2312
  });
2007
2313
  const ioWithConnections = createIOWithIntegrations(io, body1.connections, job1.options.integrations);
2008
2314
  try {
2009
2315
  const output = await job1.options.run(job1.trigger.event.parsePayload(body1.event.payload ?? {}), ioWithConnections, context);
2010
2316
  return {
2011
- completed: true,
2317
+ status: "SUCCESS",
2012
2318
  output
2013
2319
  };
2014
2320
  } catch (error) {
2015
- if (error instanceof ResumeWithTask) {
2321
+ if (error instanceof ResumeWithTaskError) {
2016
2322
  return {
2017
- completed: false,
2323
+ status: "RESUME_WITH_TASK",
2018
2324
  task: error.task
2019
2325
  };
2020
2326
  }
2021
- const errorWithStack = ErrorWithStackSchema.safeParse(error);
2022
- if (errorWithStack.success) {
2327
+ if (error instanceof RetryWithTaskError) {
2023
2328
  return {
2024
- completed: true,
2025
- error: errorWithStack.data
2329
+ status: "RETRY_WITH_TASK",
2330
+ task: error.task,
2331
+ error: error.cause,
2332
+ retryAt: error.retryAt
2026
2333
  };
2027
2334
  }
2028
- const errorWithMessage = ErrorWithMessage.safeParse(error);
2029
- if (errorWithMessage.success) {
2335
+ if (error instanceof RetryWithTaskError) {
2336
+ const errorWithStack2 = ErrorWithStackSchema.safeParse(error.cause);
2337
+ if (errorWithStack2.success) {
2338
+ return {
2339
+ status: "ERROR",
2340
+ error: errorWithStack2.data,
2341
+ task: error.task
2342
+ };
2343
+ }
2030
2344
  return {
2031
- completed: true,
2032
- error: errorWithMessage.data
2345
+ status: "ERROR",
2346
+ error: {
2347
+ message: "Unknown error"
2348
+ },
2349
+ task: error.task
2350
+ };
2351
+ }
2352
+ const errorWithStack = ErrorWithStackSchema.safeParse(error);
2353
+ if (errorWithStack.success) {
2354
+ return {
2355
+ status: "ERROR",
2356
+ error: errorWithStack.data
2033
2357
  };
2034
2358
  }
2035
2359
  return {
2036
- completed: true,
2360
+ status: "ERROR",
2037
2361
  error: {
2038
2362
  message: "Unknown error"
2039
2363
  }
@@ -2042,7 +2366,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2042
2366
  }, "#executeJob");
2043
2367
  _createRunContext = new WeakSet();
2044
2368
  createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
2045
- const { event, organization, environment, job, run } = execution;
2369
+ const { event, organization, environment, job, run, source } = execution;
2046
2370
  return {
2047
2371
  event: {
2048
2372
  id: event.id,
@@ -2054,7 +2378,8 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
2054
2378
  environment,
2055
2379
  job,
2056
2380
  run,
2057
- account: execution.account
2381
+ account: execution.account,
2382
+ source
2058
2383
  };
2059
2384
  }, "#createRunContext");
2060
2385
  _createPreprocessRunContext = new WeakSet();
@@ -2076,13 +2401,13 @@ createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(body2) {
2076
2401
  }, "#createPreprocessRunContext");
2077
2402
  _handleHttpSourceRequest = new WeakSet();
2078
2403
  handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourceRequest) {
2079
- __privateGet(this, _logger2).debug("Handling HTTP source request", {
2404
+ __privateGet(this, _internalLogger).debug("Handling HTTP source request", {
2080
2405
  source
2081
2406
  });
2082
2407
  if (source.dynamicId) {
2083
2408
  const dynamicTrigger = __privateGet(this, _registeredDynamicTriggers)[source.dynamicId];
2084
2409
  if (!dynamicTrigger) {
2085
- __privateGet(this, _logger2).debug("No dynamic trigger registered for HTTP source", {
2410
+ __privateGet(this, _internalLogger).debug("No dynamic trigger registered for HTTP source", {
2086
2411
  source
2087
2412
  });
2088
2413
  return {
@@ -2095,7 +2420,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
2095
2420
  events: []
2096
2421
  };
2097
2422
  }
2098
- const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this, _logger2));
2423
+ const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this, _internalLogger));
2099
2424
  if (!results2) {
2100
2425
  return {
2101
2426
  events: [],
@@ -2119,7 +2444,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
2119
2444
  }
2120
2445
  const handler = __privateGet(this, _registeredHttpSourceHandlers)[source.key];
2121
2446
  if (!handler) {
2122
- __privateGet(this, _logger2).debug("No handler registered for HTTP source", {
2447
+ __privateGet(this, _internalLogger).debug("No handler registered for HTTP source", {
2123
2448
  source
2124
2449
  });
2125
2450
  return {
@@ -2154,20 +2479,6 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
2154
2479
  }
2155
2480
  };
2156
2481
  }, "#handleHttpSourceRequest");
2157
- function buildClientUrl(url) {
2158
- if (!url) {
2159
- const host = process.env.TRIGGER_CLIENT_HOST ?? process.env.HOST ?? process.env.HOSTNAME ?? process.env.NOW_URL ?? process.env.VERCEL_URL;
2160
- if (host) {
2161
- return "https://" + host;
2162
- }
2163
- 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.");
2164
- }
2165
- if (!url.startsWith("http")) {
2166
- return "https://" + url;
2167
- }
2168
- return url;
2169
- }
2170
- __name(buildClientUrl, "buildClientUrl");
2171
2482
 
2172
2483
  // src/integrations.ts
2173
2484
  function authenticatedTask(options) {
@@ -2319,7 +2630,11 @@ var DynamicTrigger = class {
2319
2630
  events: [
2320
2631
  this.event.name
2321
2632
  ],
2322
- clientId: !this.source.integration.usesLocalAuth ? this.source.integration.id : void 0
2633
+ integration: {
2634
+ id: this.source.integration.id,
2635
+ metadata: this.source.integration.metadata,
2636
+ authSource: this.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
2637
+ }
2323
2638
  }
2324
2639
  };
2325
2640
  }
@@ -2330,7 +2645,7 @@ var DynamicTrigger = class {
2330
2645
  triggerClient.attachJobToDynamicTrigger(job, this);
2331
2646
  }
2332
2647
  get preprocessRuns() {
2333
- return false;
2648
+ return true;
2334
2649
  }
2335
2650
  };
2336
2651
  __name(DynamicTrigger, "DynamicTrigger");
@@ -2338,6 +2653,18 @@ _client2 = new WeakMap();
2338
2653
  _options4 = new WeakMap();
2339
2654
 
2340
2655
  // src/triggers/scheduled.ts
2656
+ var import_cronstrue = __toESM(require("cronstrue"));
2657
+ var examples = [
2658
+ {
2659
+ id: "now",
2660
+ name: "Now",
2661
+ icon: "clock",
2662
+ payload: {
2663
+ ts: currentDate.marker,
2664
+ lastTimestamp: currentDate.marker
2665
+ }
2666
+ }
2667
+ ];
2341
2668
  var IntervalTrigger = class {
2342
2669
  constructor(options) {
2343
2670
  this.options = options;
@@ -2348,6 +2675,7 @@ var IntervalTrigger = class {
2348
2675
  title: "Schedule",
2349
2676
  source: "trigger.dev",
2350
2677
  icon: "schedule-interval",
2678
+ examples,
2351
2679
  parsePayload: ScheduledPayloadSchema.parse,
2352
2680
  properties: [
2353
2681
  {
@@ -2384,16 +2712,24 @@ var CronTrigger = class {
2384
2712
  this.options = options;
2385
2713
  }
2386
2714
  get event() {
2715
+ const humanReadable = import_cronstrue.default.toString(this.options.cron, {
2716
+ throwExceptionOnParseError: false
2717
+ });
2387
2718
  return {
2388
2719
  name: "trigger.scheduled",
2389
2720
  title: "Cron Schedule",
2390
2721
  source: "trigger.dev",
2391
2722
  icon: "schedule-cron",
2723
+ examples,
2392
2724
  parsePayload: ScheduledPayloadSchema.parse,
2393
2725
  properties: [
2394
2726
  {
2395
- label: "Expression",
2727
+ label: "cron",
2396
2728
  text: this.options.cron
2729
+ },
2730
+ {
2731
+ label: "Schedule",
2732
+ text: humanReadable
2397
2733
  }
2398
2734
  ]
2399
2735
  };
@@ -2434,6 +2770,7 @@ var DynamicSchedule = class {
2434
2770
  title: "Dynamic Schedule",
2435
2771
  source: "trigger.dev",
2436
2772
  icon: "schedule-dynamic",
2773
+ examples,
2437
2774
  parsePayload: ScheduledPayloadSchema.parse
2438
2775
  };
2439
2776
  }
@@ -2555,14 +2892,14 @@ var MissingConnectionResolvedNotification = class {
2555
2892
  __name(MissingConnectionResolvedNotification, "MissingConnectionResolvedNotification");
2556
2893
 
2557
2894
  // src/index.ts
2558
- function secureString(strings, ...interpolations) {
2895
+ function redactString(strings, ...interpolations) {
2559
2896
  return {
2560
- __secureString: true,
2897
+ __redactedString: true,
2561
2898
  strings: strings.raw,
2562
2899
  interpolations
2563
2900
  };
2564
2901
  }
2565
- __name(secureString, "secureString");
2902
+ __name(redactString, "redactString");
2566
2903
  // Annotate the CommonJS export names for ESM import in node:
2567
2904
  0 && (module.exports = {
2568
2905
  CronTrigger,
@@ -2577,15 +2914,15 @@ __name(secureString, "secureString");
2577
2914
  Job,
2578
2915
  MissingConnectionNotification,
2579
2916
  MissingConnectionResolvedNotification,
2580
- ResumeWithTask,
2581
2917
  TriggerClient,
2582
2918
  authenticatedTask,
2583
2919
  cronTrigger,
2584
2920
  eventTrigger,
2585
2921
  intervalTrigger,
2922
+ isTriggerError,
2586
2923
  missingConnectionNotification,
2587
2924
  missingConnectionResolvedNotification,
2588
2925
  omit,
2589
- secureString
2926
+ redactString
2590
2927
  });
2591
2928
  //# sourceMappingURL=index.js.map