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

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
@@ -55,16 +55,16 @@ __export(src_exports, {
55
55
  Job: () => Job,
56
56
  MissingConnectionNotification: () => MissingConnectionNotification,
57
57
  MissingConnectionResolvedNotification: () => MissingConnectionResolvedNotification,
58
- ResumeWithTask: () => ResumeWithTask,
59
58
  TriggerClient: () => TriggerClient,
60
59
  authenticatedTask: () => authenticatedTask,
61
60
  cronTrigger: () => cronTrigger,
62
61
  eventTrigger: () => eventTrigger,
63
62
  intervalTrigger: () => intervalTrigger,
63
+ isTriggerError: () => isTriggerError,
64
64
  missingConnectionNotification: () => missingConnectionNotification,
65
65
  missingConnectionResolvedNotification: () => missingConnectionResolvedNotification,
66
66
  omit: () => omit,
67
- secureString: () => secureString
67
+ redactString: () => redactString
68
68
  });
69
69
  module.exports = __toCommonJS(src_exports);
70
70
 
@@ -104,12 +104,11 @@ var Job = class {
104
104
  get integrations() {
105
105
  return Object.keys(this.options.integrations ?? {}).reduce((acc, key) => {
106
106
  const integration = this.options.integrations[key];
107
- if (!integration.client.usesLocalAuth) {
108
- acc[key] = {
109
- id: integration.id,
110
- metadata: integration.metadata
111
- };
112
- }
107
+ acc[key] = {
108
+ id: integration.id,
109
+ metadata: integration.metadata,
110
+ authSource: integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
111
+ };
113
112
  return acc;
114
113
  }, {});
115
114
  }
@@ -146,18 +145,20 @@ var logLevels = [
146
145
  "info",
147
146
  "debug"
148
147
  ];
149
- var _name, _level, _filteredKeys;
148
+ var _name, _level, _filteredKeys, _jsonReplacer;
150
149
  var _Logger = class {
151
- constructor(name, level = "info", filteredKeys = []) {
150
+ constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
152
151
  __privateAdd(this, _name, void 0);
153
152
  __privateAdd(this, _level, void 0);
154
153
  __privateAdd(this, _filteredKeys, []);
154
+ __privateAdd(this, _jsonReplacer, void 0);
155
155
  __privateSet(this, _name, name);
156
156
  __privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
157
157
  __privateSet(this, _filteredKeys, filteredKeys);
158
+ __privateSet(this, _jsonReplacer, jsonReplacer);
158
159
  }
159
160
  filter(...keys) {
160
- return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys);
161
+ return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
161
162
  }
162
163
  log(...args) {
163
164
  if (__privateGet(this, _level) < 0)
@@ -188,7 +189,7 @@ var _Logger = class {
188
189
  message,
189
190
  args: structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys))
190
191
  };
191
- console.debug(JSON.stringify(structuredLog, bigIntReplacer));
192
+ console.debug(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
192
193
  }
193
194
  };
194
195
  var Logger = _Logger;
@@ -196,6 +197,19 @@ __name(Logger, "Logger");
196
197
  _name = new WeakMap();
197
198
  _level = new WeakMap();
198
199
  _filteredKeys = new WeakMap();
200
+ _jsonReplacer = new WeakMap();
201
+ function createReplacer(replacer) {
202
+ return (key, value) => {
203
+ if (typeof value === "bigint") {
204
+ return value.toString();
205
+ }
206
+ if (replacer) {
207
+ return replacer(key, value);
208
+ }
209
+ return value;
210
+ };
211
+ }
212
+ __name(createReplacer, "createReplacer");
199
213
  function bigIntReplacer(_key, value) {
200
214
  if (typeof value === "bigint") {
201
215
  return value.toString();
@@ -254,129 +268,100 @@ __name(filterKeys, "filterKeys");
254
268
 
255
269
  // ../internal/src/schemas/api.ts
256
270
  var import_ulid = require("ulid");
257
- var import_zod8 = require("zod");
271
+ var import_zod9 = require("zod");
258
272
 
259
- // ../internal/src/schemas/integrations.ts
273
+ // ../internal/src/schemas/errors.ts
260
274
  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
275
+ var ErrorWithStackSchema = import_zod.z.object({
276
+ message: import_zod.z.string(),
277
+ name: import_zod.z.string().optional(),
278
+ stack: import_zod.z.string().optional()
277
279
  });
278
280
 
279
- // ../internal/src/schemas/properties.ts
281
+ // ../internal/src/schemas/eventFilter.ts
280
282
  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"
283
+ var EventMatcherSchema = import_zod2.z.union([
284
+ import_zod2.z.array(import_zod2.z.string()),
285
+ import_zod2.z.array(import_zod2.z.number()),
286
+ import_zod2.z.array(import_zod2.z.boolean())
287
+ ]);
288
+ var EventFilterSchema = import_zod2.z.lazy(() => import_zod2.z.record(import_zod2.z.union([
289
+ EventMatcherSchema,
290
+ EventFilterSchema
291
+ ])));
292
+ var EventRuleSchema = import_zod2.z.object({
293
+ event: import_zod2.z.string(),
294
+ source: import_zod2.z.string(),
295
+ payload: EventFilterSchema.optional(),
296
+ context: EventFilterSchema.optional()
297
+ });
298
+
299
+ // ../internal/src/schemas/integrations.ts
300
+ var import_zod3 = require("zod");
301
+ var ConnectionAuthSchema = import_zod3.z.object({
302
+ type: import_zod3.z.enum([
303
+ "oauth2"
291
304
  ]),
292
- variant: import_zod2.z.string().optional()
305
+ accessToken: import_zod3.z.string(),
306
+ scopes: import_zod3.z.array(import_zod3.z.string()).optional(),
307
+ additionalFields: import_zod3.z.record(import_zod3.z.string()).optional()
308
+ });
309
+ var IntegrationMetadataSchema = import_zod3.z.object({
310
+ id: import_zod3.z.string(),
311
+ name: import_zod3.z.string(),
312
+ instructions: import_zod3.z.string().optional()
313
+ });
314
+ var IntegrationConfigSchema = import_zod3.z.object({
315
+ id: import_zod3.z.string(),
316
+ metadata: IntegrationMetadataSchema,
317
+ authSource: import_zod3.z.enum([
318
+ "HOSTED",
319
+ "LOCAL"
320
+ ])
293
321
  });
294
322
 
295
323
  // ../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()
324
+ var import_zod4 = require("zod");
325
+ var LiteralSchema = import_zod4.z.union([
326
+ import_zod4.z.string(),
327
+ import_zod4.z.number(),
328
+ import_zod4.z.boolean(),
329
+ import_zod4.z.null()
302
330
  ]);
303
- var DeserializedJsonSchema = import_zod3.z.lazy(() => import_zod3.z.union([
331
+ var DeserializedJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
304
332
  LiteralSchema,
305
- import_zod3.z.array(DeserializedJsonSchema),
306
- import_zod3.z.record(DeserializedJsonSchema)
333
+ import_zod4.z.array(DeserializedJsonSchema),
334
+ import_zod4.z.record(DeserializedJsonSchema)
307
335
  ]));
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()
336
+ var SerializableSchema = import_zod4.z.union([
337
+ import_zod4.z.string(),
338
+ import_zod4.z.number(),
339
+ import_zod4.z.boolean(),
340
+ import_zod4.z.null(),
341
+ import_zod4.z.date(),
342
+ import_zod4.z.undefined(),
343
+ import_zod4.z.symbol()
316
344
  ]);
317
- var SerializableJsonSchema = import_zod3.z.lazy(() => import_zod3.z.union([
345
+ var SerializableJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
318
346
  SerializableSchema,
319
- import_zod3.z.array(SerializableJsonSchema),
320
- import_zod3.z.record(SerializableJsonSchema)
347
+ import_zod4.z.array(SerializableJsonSchema),
348
+ import_zod4.z.record(SerializableJsonSchema)
321
349
  ]));
322
350
 
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
351
+ // ../internal/src/schemas/properties.ts
365
352
  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()
353
+ var DisplayPropertySchema = import_zod5.z.object({
354
+ label: import_zod5.z.string(),
355
+ text: import_zod5.z.string(),
356
+ url: import_zod5.z.string().optional()
357
+ });
358
+ var DisplayPropertiesSchema = import_zod5.z.array(DisplayPropertySchema);
359
+ var StyleSchema = import_zod5.z.object({
360
+ style: import_zod5.z.enum([
361
+ "normal",
362
+ "minimal"
363
+ ]),
364
+ variant: import_zod5.z.string().optional()
380
365
  });
381
366
 
382
367
  // ../internal/src/schemas/schedules.ts
@@ -413,310 +398,395 @@ var RegisterDynamicSchedulePayloadSchema = import_zod6.z.object({
413
398
  }))
414
399
  });
415
400
 
416
- // ../internal/src/schemas/triggers.ts
417
- var EventSpecificationSchema = import_zod7.z.object({
401
+ // ../internal/src/schemas/tasks.ts
402
+ var import_zod7 = require("zod");
403
+ var TaskStatusSchema = import_zod7.z.enum([
404
+ "PENDING",
405
+ "WAITING",
406
+ "RUNNING",
407
+ "COMPLETED",
408
+ "ERRORED"
409
+ ]);
410
+ var TaskSchema = import_zod7.z.object({
411
+ id: import_zod7.z.string(),
418
412
  name: import_zod7.z.string(),
419
- title: import_zod7.z.string(),
420
- source: import_zod7.z.string(),
421
- icon: import_zod7.z.string(),
413
+ icon: import_zod7.z.string().optional().nullable(),
414
+ noop: import_zod7.z.boolean(),
415
+ startedAt: import_zod7.z.coerce.date().optional().nullable(),
416
+ completedAt: import_zod7.z.coerce.date().optional().nullable(),
417
+ delayUntil: import_zod7.z.coerce.date().optional().nullable(),
418
+ status: TaskStatusSchema,
419
+ description: import_zod7.z.string().optional().nullable(),
420
+ properties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
421
+ params: DeserializedJsonSchema.optional().nullable(),
422
+ output: DeserializedJsonSchema.optional().nullable(),
423
+ error: import_zod7.z.string().optional().nullable(),
424
+ parentId: import_zod7.z.string().optional().nullable(),
425
+ style: StyleSchema.optional().nullable(),
426
+ operation: import_zod7.z.string().optional().nullable()
427
+ });
428
+ var ServerTaskSchema = TaskSchema.extend({
429
+ idempotencyKey: import_zod7.z.string(),
430
+ attempts: import_zod7.z.number()
431
+ });
432
+ var CachedTaskSchema = import_zod7.z.object({
433
+ id: import_zod7.z.string(),
434
+ idempotencyKey: import_zod7.z.string(),
435
+ status: TaskStatusSchema,
436
+ noop: import_zod7.z.boolean().default(false),
437
+ output: DeserializedJsonSchema.optional().nullable(),
438
+ parentId: import_zod7.z.string().optional().nullable()
439
+ });
440
+
441
+ // ../internal/src/schemas/triggers.ts
442
+ var import_zod8 = require("zod");
443
+ var EventExampleSchema = import_zod8.z.object({
444
+ id: import_zod8.z.string(),
445
+ icon: import_zod8.z.string().optional(),
446
+ name: import_zod8.z.string(),
447
+ payload: import_zod8.z.any()
448
+ });
449
+ var EventSpecificationSchema = import_zod8.z.object({
450
+ name: import_zod8.z.string(),
451
+ title: import_zod8.z.string(),
452
+ source: import_zod8.z.string(),
453
+ icon: import_zod8.z.string(),
422
454
  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(),
455
+ properties: import_zod8.z.array(DisplayPropertySchema).optional(),
456
+ schema: import_zod8.z.any().optional(),
457
+ examples: import_zod8.z.array(EventExampleSchema).optional()
458
+ });
459
+ var DynamicTriggerMetadataSchema = import_zod8.z.object({
460
+ type: import_zod8.z.literal("dynamic"),
461
+ id: import_zod8.z.string()
462
+ });
463
+ var StaticTriggerMetadataSchema = import_zod8.z.object({
464
+ type: import_zod8.z.literal("static"),
465
+ title: import_zod8.z.string(),
466
+ properties: import_zod8.z.array(DisplayPropertySchema).optional(),
435
467
  rule: EventRuleSchema
436
468
  });
437
- var ScheduledTriggerMetadataSchema = import_zod7.z.object({
438
- type: import_zod7.z.literal("scheduled"),
469
+ var ScheduledTriggerMetadataSchema = import_zod8.z.object({
470
+ type: import_zod8.z.literal("scheduled"),
439
471
  schedule: ScheduleMetadataSchema
440
472
  });
441
- var TriggerMetadataSchema = import_zod7.z.discriminatedUnion("type", [
473
+ var TriggerMetadataSchema = import_zod8.z.discriminatedUnion("type", [
442
474
  DynamicTriggerMetadataSchema,
443
475
  StaticTriggerMetadataSchema,
444
476
  ScheduledTriggerMetadataSchema
445
477
  ]);
446
478
 
447
479
  // ../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(),
480
+ var UpdateTriggerSourceBodySchema = import_zod9.z.object({
481
+ registeredEvents: import_zod9.z.array(import_zod9.z.string()),
482
+ secret: import_zod9.z.string().optional(),
451
483
  data: SerializableJsonSchema.optional()
452
484
  });
453
485
  var HttpEventSourceSchema = UpdateTriggerSourceBodySchema.extend({
454
- id: import_zod8.z.string(),
455
- active: import_zod8.z.boolean(),
456
- url: import_zod8.z.string().url()
486
+ id: import_zod9.z.string(),
487
+ active: import_zod9.z.boolean(),
488
+ url: import_zod9.z.string().url()
457
489
  });
458
- var RegisterHTTPTriggerSourceBodySchema = import_zod8.z.object({
459
- type: import_zod8.z.literal("HTTP"),
460
- url: import_zod8.z.string().url()
490
+ var RegisterHTTPTriggerSourceBodySchema = import_zod9.z.object({
491
+ type: import_zod9.z.literal("HTTP"),
492
+ url: import_zod9.z.string().url()
461
493
  });
462
- var RegisterSMTPTriggerSourceBodySchema = import_zod8.z.object({
463
- type: import_zod8.z.literal("SMTP")
494
+ var RegisterSMTPTriggerSourceBodySchema = import_zod9.z.object({
495
+ type: import_zod9.z.literal("SMTP")
464
496
  });
465
- var RegisterSQSTriggerSourceBodySchema = import_zod8.z.object({
466
- type: import_zod8.z.literal("SQS")
497
+ var RegisterSQSTriggerSourceBodySchema = import_zod9.z.object({
498
+ type: import_zod9.z.literal("SQS")
467
499
  });
468
- var RegisterSourceChannelBodySchema = import_zod8.z.discriminatedUnion("type", [
500
+ var RegisterSourceChannelBodySchema = import_zod9.z.discriminatedUnion("type", [
469
501
  RegisterHTTPTriggerSourceBodySchema,
470
502
  RegisterSMTPTriggerSourceBodySchema,
471
503
  RegisterSQSTriggerSourceBodySchema
472
504
  ]);
473
505
  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(),
506
+ var RegisterTriggerSourceSchema = import_zod9.z.object({
507
+ key: import_zod9.z.string(),
508
+ params: import_zod9.z.any(),
509
+ active: import_zod9.z.boolean(),
510
+ secret: import_zod9.z.string(),
479
511
  data: DeserializedJsonSchema.optional(),
480
512
  channel: RegisterSourceChannelBodySchema,
481
- clientId: import_zod8.z.string().optional()
513
+ clientId: import_zod9.z.string().optional()
482
514
  });
483
- var RegisterSourceEventSchema = import_zod8.z.object({
484
- id: import_zod8.z.string(),
515
+ var RegisterSourceEventSchema = import_zod9.z.object({
516
+ id: import_zod9.z.string(),
485
517
  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(),
518
+ events: import_zod9.z.array(import_zod9.z.string()),
519
+ missingEvents: import_zod9.z.array(import_zod9.z.string()),
520
+ orphanedEvents: import_zod9.z.array(import_zod9.z.string()),
521
+ dynamicTriggerId: import_zod9.z.string().optional()
522
+ });
523
+ var TriggerSourceSchema = import_zod9.z.object({
524
+ id: import_zod9.z.string(),
525
+ key: import_zod9.z.string()
526
+ });
527
+ var HandleTriggerSourceSchema = import_zod9.z.object({
528
+ key: import_zod9.z.string(),
529
+ secret: import_zod9.z.string(),
530
+ data: import_zod9.z.any(),
531
+ params: import_zod9.z.any()
532
+ });
533
+ var HttpSourceRequestSchema = import_zod9.z.object({
534
+ url: import_zod9.z.string().url(),
535
+ method: import_zod9.z.string(),
536
+ headers: import_zod9.z.record(import_zod9.z.string()),
537
+ rawBody: import_zod9.z.instanceof(Buffer).optional().nullable()
538
+ });
539
+ var HttpSourceRequestHeadersSchema = import_zod9.z.object({
540
+ "x-ts-key": import_zod9.z.string(),
541
+ "x-ts-dynamic-id": import_zod9.z.string().optional(),
542
+ "x-ts-secret": import_zod9.z.string(),
543
+ "x-ts-data": import_zod9.z.string().transform((s) => JSON.parse(s)),
544
+ "x-ts-params": import_zod9.z.string().transform((s) => JSON.parse(s)),
545
+ "x-ts-http-url": import_zod9.z.string(),
546
+ "x-ts-http-method": import_zod9.z.string(),
547
+ "x-ts-http-headers": import_zod9.z.string().transform((s) => import_zod9.z.record(import_zod9.z.string()).parse(JSON.parse(s)))
548
+ });
549
+ var PongSuccessResponseSchema = import_zod9.z.object({
550
+ ok: import_zod9.z.literal(true)
551
+ });
552
+ var PongErrorResponseSchema = import_zod9.z.object({
553
+ ok: import_zod9.z.literal(false),
554
+ error: import_zod9.z.string()
555
+ });
556
+ var PongResponseSchema = import_zod9.z.discriminatedUnion("ok", [
557
+ PongSuccessResponseSchema,
558
+ PongErrorResponseSchema
559
+ ]);
560
+ var QueueOptionsSchema = import_zod9.z.object({
561
+ name: import_zod9.z.string(),
562
+ maxConcurrent: import_zod9.z.number().optional()
563
+ });
564
+ var JobMetadataSchema = import_zod9.z.object({
565
+ id: import_zod9.z.string(),
566
+ name: import_zod9.z.string(),
567
+ version: import_zod9.z.string(),
528
568
  event: EventSpecificationSchema,
529
569
  trigger: TriggerMetadataSchema,
530
- integrations: import_zod8.z.record(IntegrationConfigSchema),
531
- internal: import_zod8.z.boolean().default(false),
532
- queue: import_zod8.z.union([
570
+ integrations: import_zod9.z.record(IntegrationConfigSchema),
571
+ internal: import_zod9.z.boolean().default(false),
572
+ queue: import_zod9.z.union([
533
573
  QueueOptionsSchema,
534
- import_zod8.z.string()
574
+ import_zod9.z.string()
535
575
  ]).optional(),
536
- startPosition: import_zod8.z.enum([
576
+ startPosition: import_zod9.z.enum([
537
577
  "initial",
538
578
  "latest"
539
579
  ]),
540
- enabled: import_zod8.z.boolean(),
541
- preprocessRuns: import_zod8.z.boolean()
580
+ enabled: import_zod9.z.boolean(),
581
+ preprocessRuns: import_zod9.z.boolean()
542
582
  });
543
- var SourceMetadataSchema = import_zod8.z.object({
544
- channel: import_zod8.z.enum([
583
+ var SourceMetadataSchema = import_zod9.z.object({
584
+ channel: import_zod9.z.enum([
545
585
  "HTTP",
546
586
  "SQS",
547
587
  "SMTP"
548
588
  ]),
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({
589
+ integration: IntegrationConfigSchema,
590
+ key: import_zod9.z.string(),
591
+ params: import_zod9.z.any(),
592
+ events: import_zod9.z.array(import_zod9.z.string())
593
+ });
594
+ var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
595
+ id: import_zod9.z.string(),
596
+ jobs: import_zod9.z.array(JobMetadataSchema.pick({
557
597
  id: true,
558
598
  version: true
559
599
  }))
560
600
  });
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(),
601
+ var IndexEndpointResponseSchema = import_zod9.z.object({
602
+ jobs: import_zod9.z.array(JobMetadataSchema),
603
+ sources: import_zod9.z.array(SourceMetadataSchema),
604
+ dynamicTriggers: import_zod9.z.array(DynamicTriggerEndpointMetadataSchema),
605
+ dynamicSchedules: import_zod9.z.array(RegisterDynamicSchedulePayloadSchema)
606
+ });
607
+ var RawEventSchema = import_zod9.z.object({
608
+ id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
609
+ name: import_zod9.z.string(),
610
+ source: import_zod9.z.string().optional(),
611
+ payload: import_zod9.z.any(),
612
+ context: import_zod9.z.any().optional(),
613
+ timestamp: import_zod9.z.string().datetime().optional()
614
+ });
615
+ var ApiEventLogSchema = import_zod9.z.object({
616
+ id: import_zod9.z.string(),
617
+ name: import_zod9.z.string(),
578
618
  payload: DeserializedJsonSchema,
579
619
  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()
620
+ timestamp: import_zod9.z.coerce.date(),
621
+ deliverAt: import_zod9.z.coerce.date().optional().nullable(),
622
+ deliveredAt: import_zod9.z.coerce.date().optional().nullable()
583
623
  });
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()
624
+ var SendEventOptionsSchema = import_zod9.z.object({
625
+ deliverAt: import_zod9.z.string().datetime().optional(),
626
+ deliverAfter: import_zod9.z.number().int().optional(),
627
+ accountId: import_zod9.z.string().optional()
588
628
  });
589
- var SendEventBodySchema = import_zod8.z.object({
629
+ var SendEventBodySchema = import_zod9.z.object({
590
630
  event: RawEventSchema,
591
631
  options: SendEventOptionsSchema.optional()
592
632
  });
593
- var DeliverEventResponseSchema = import_zod8.z.object({
594
- deliveredAt: import_zod8.z.string().datetime()
633
+ var DeliverEventResponseSchema = import_zod9.z.object({
634
+ deliveredAt: import_zod9.z.string().datetime()
595
635
  });
596
- var RuntimeEnvironmentTypeSchema = import_zod8.z.enum([
636
+ var RuntimeEnvironmentTypeSchema = import_zod9.z.enum([
597
637
  "PRODUCTION",
598
638
  "STAGING",
599
639
  "DEVELOPMENT",
600
640
  "PREVIEW"
601
641
  ]);
602
- var RunJobBodySchema = import_zod8.z.object({
642
+ var RunJobBodySchema = import_zod9.z.object({
603
643
  event: ApiEventLogSchema,
604
- job: import_zod8.z.object({
605
- id: import_zod8.z.string(),
606
- version: import_zod8.z.string()
644
+ job: import_zod9.z.object({
645
+ id: import_zod9.z.string(),
646
+ version: import_zod9.z.string()
607
647
  }),
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()
648
+ run: import_zod9.z.object({
649
+ id: import_zod9.z.string(),
650
+ isTest: import_zod9.z.boolean(),
651
+ startedAt: import_zod9.z.coerce.date()
612
652
  }),
613
- environment: import_zod8.z.object({
614
- id: import_zod8.z.string(),
615
- slug: import_zod8.z.string(),
653
+ environment: import_zod9.z.object({
654
+ id: import_zod9.z.string(),
655
+ slug: import_zod9.z.string(),
616
656
  type: RuntimeEnvironmentTypeSchema
617
657
  }),
618
- organization: import_zod8.z.object({
619
- id: import_zod8.z.string(),
620
- title: import_zod8.z.string(),
621
- slug: import_zod8.z.string()
658
+ organization: import_zod9.z.object({
659
+ id: import_zod9.z.string(),
660
+ title: import_zod9.z.string(),
661
+ slug: import_zod9.z.string()
622
662
  }),
623
- account: import_zod8.z.object({
624
- id: import_zod8.z.string(),
625
- metadata: import_zod8.z.any()
663
+ account: import_zod9.z.object({
664
+ id: import_zod9.z.string(),
665
+ metadata: import_zod9.z.any()
626
666
  }).optional(),
627
- tasks: import_zod8.z.array(CachedTaskSchema).optional(),
628
- connections: import_zod8.z.record(ConnectionAuthSchema).optional()
667
+ tasks: import_zod9.z.array(CachedTaskSchema).optional(),
668
+ connections: import_zod9.z.record(ConnectionAuthSchema).optional()
629
669
  });
630
- var RunJobResponseSchema = import_zod8.z.object({
631
- executionId: import_zod8.z.string(),
632
- completed: import_zod8.z.boolean(),
633
- output: DeserializedJsonSchema.optional(),
670
+ var RunJobErrorSchema = import_zod9.z.object({
671
+ status: import_zod9.z.literal("ERROR"),
672
+ error: ErrorWithStackSchema,
634
673
  task: TaskSchema.optional()
635
674
  });
636
- var PreprocessRunBodySchema = import_zod8.z.object({
675
+ var RunJobResumeWithTaskSchema = import_zod9.z.object({
676
+ status: import_zod9.z.literal("RESUME_WITH_TASK"),
677
+ task: TaskSchema
678
+ });
679
+ var RunJobRetryWithTaskSchema = import_zod9.z.object({
680
+ status: import_zod9.z.literal("RETRY_WITH_TASK"),
681
+ task: TaskSchema,
682
+ error: ErrorWithStackSchema,
683
+ retryAt: import_zod9.z.coerce.date()
684
+ });
685
+ var RunJobSuccessSchema = import_zod9.z.object({
686
+ status: import_zod9.z.literal("SUCCESS"),
687
+ output: DeserializedJsonSchema.optional()
688
+ });
689
+ var RunJobResponseSchema = import_zod9.z.discriminatedUnion("status", [
690
+ RunJobErrorSchema,
691
+ RunJobResumeWithTaskSchema,
692
+ RunJobRetryWithTaskSchema,
693
+ RunJobSuccessSchema
694
+ ]);
695
+ var PreprocessRunBodySchema = import_zod9.z.object({
637
696
  event: ApiEventLogSchema,
638
- job: import_zod8.z.object({
639
- id: import_zod8.z.string(),
640
- version: import_zod8.z.string()
697
+ job: import_zod9.z.object({
698
+ id: import_zod9.z.string(),
699
+ version: import_zod9.z.string()
641
700
  }),
642
- run: import_zod8.z.object({
643
- id: import_zod8.z.string(),
644
- isTest: import_zod8.z.boolean()
701
+ run: import_zod9.z.object({
702
+ id: import_zod9.z.string(),
703
+ isTest: import_zod9.z.boolean()
645
704
  }),
646
- environment: import_zod8.z.object({
647
- id: import_zod8.z.string(),
648
- slug: import_zod8.z.string(),
705
+ environment: import_zod9.z.object({
706
+ id: import_zod9.z.string(),
707
+ slug: import_zod9.z.string(),
649
708
  type: RuntimeEnvironmentTypeSchema
650
709
  }),
651
- organization: import_zod8.z.object({
652
- id: import_zod8.z.string(),
653
- title: import_zod8.z.string(),
654
- slug: import_zod8.z.string()
710
+ organization: import_zod9.z.object({
711
+ id: import_zod9.z.string(),
712
+ title: import_zod9.z.string(),
713
+ slug: import_zod9.z.string()
655
714
  }),
656
- account: import_zod8.z.object({
657
- id: import_zod8.z.string(),
658
- metadata: import_zod8.z.any()
715
+ account: import_zod9.z.object({
716
+ id: import_zod9.z.string(),
717
+ metadata: import_zod9.z.any()
659
718
  }).optional()
660
719
  });
661
- var PreprocessRunResponseSchema = import_zod8.z.object({
662
- abort: import_zod8.z.boolean(),
663
- properties: import_zod8.z.array(DisplayPropertySchema).optional()
720
+ var PreprocessRunResponseSchema = import_zod9.z.object({
721
+ abort: import_zod9.z.boolean(),
722
+ properties: import_zod9.z.array(DisplayPropertySchema).optional()
664
723
  });
665
- var CreateRunBodySchema = import_zod8.z.object({
666
- client: import_zod8.z.string(),
724
+ var CreateRunBodySchema = import_zod9.z.object({
725
+ client: import_zod9.z.string(),
667
726
  job: JobMetadataSchema,
668
727
  event: ApiEventLogSchema,
669
- properties: import_zod8.z.array(DisplayPropertySchema).optional()
728
+ properties: import_zod9.z.array(DisplayPropertySchema).optional()
670
729
  });
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()
730
+ var CreateRunResponseOkSchema = import_zod9.z.object({
731
+ ok: import_zod9.z.literal(true),
732
+ data: import_zod9.z.object({
733
+ id: import_zod9.z.string()
675
734
  })
676
735
  });
677
- var CreateRunResponseErrorSchema = import_zod8.z.object({
678
- ok: import_zod8.z.literal(false),
679
- error: import_zod8.z.string()
736
+ var CreateRunResponseErrorSchema = import_zod9.z.object({
737
+ ok: import_zod9.z.literal(false),
738
+ error: import_zod9.z.string()
680
739
  });
681
- var CreateRunResponseBodySchema = import_zod8.z.discriminatedUnion("ok", [
740
+ var CreateRunResponseBodySchema = import_zod9.z.discriminatedUnion("ok", [
682
741
  CreateRunResponseOkSchema,
683
742
  CreateRunResponseErrorSchema
684
743
  ]);
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())
744
+ var RedactStringSchema = import_zod9.z.object({
745
+ __redactedString: import_zod9.z.literal(true),
746
+ strings: import_zod9.z.array(import_zod9.z.string()),
747
+ interpolations: import_zod9.z.array(import_zod9.z.string())
689
748
  });
690
- var LogMessageSchema = import_zod8.z.object({
691
- level: import_zod8.z.enum([
749
+ var LogMessageSchema = import_zod9.z.object({
750
+ level: import_zod9.z.enum([
692
751
  "DEBUG",
693
752
  "INFO",
694
753
  "WARN",
695
754
  "ERROR"
696
755
  ]),
697
- message: import_zod8.z.string(),
756
+ message: import_zod9.z.string(),
698
757
  data: SerializableJsonSchema.optional()
699
758
  });
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(),
759
+ var RedactSchema = import_zod9.z.object({
760
+ paths: import_zod9.z.array(import_zod9.z.string())
761
+ });
762
+ var RetryOptionsSchema = import_zod9.z.object({
763
+ limit: import_zod9.z.number().optional(),
764
+ factor: import_zod9.z.number().optional(),
765
+ minTimeoutInMs: import_zod9.z.number().optional(),
766
+ maxTimeoutInMs: import_zod9.z.number().optional(),
767
+ randomize: import_zod9.z.boolean().optional()
768
+ });
769
+ var RunTaskOptionsSchema = import_zod9.z.object({
770
+ name: import_zod9.z.string(),
771
+ icon: import_zod9.z.string().optional(),
772
+ 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
+ description: import_zod9.z.string().optional(),
779
+ properties: import_zod9.z.array(DisplayPropertySchema).optional(),
780
+ params: import_zod9.z.any(),
712
781
  trigger: TriggerMetadataSchema.optional(),
713
782
  redact: RedactSchema.optional(),
714
- connectionKey: import_zod8.z.string().optional(),
715
- style: StyleSchema.optional()
783
+ connectionKey: import_zod9.z.string().optional(),
784
+ style: StyleSchema.optional(),
785
+ retry: RetryOptionsSchema.optional()
716
786
  });
717
787
  var RunTaskBodyInputSchema = RunTaskOptionsSchema.extend({
718
- idempotencyKey: import_zod8.z.string(),
719
- parentId: import_zod8.z.string().optional()
788
+ idempotencyKey: import_zod9.z.string(),
789
+ parentId: import_zod9.z.string().optional()
720
790
  });
721
791
  var RunTaskBodyOutputSchema = RunTaskBodyInputSchema.extend({
722
792
  params: DeserializedJsonSchema.optional().nullable()
@@ -728,64 +798,58 @@ var CompleteTaskBodyInputSchema = RunTaskBodyInputSchema.pick({
728
798
  }).extend({
729
799
  output: SerializableJsonSchema.optional().transform((v) => v ? DeserializedJsonSchema.parse(JSON.parse(JSON.stringify(v))) : {})
730
800
  });
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()
801
+ var FailTaskBodyInputSchema = import_zod9.z.object({
802
+ error: ErrorWithStackSchema
737
803
  });
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()
804
+ var NormalizedRequestSchema = import_zod9.z.object({
805
+ headers: import_zod9.z.record(import_zod9.z.string()),
806
+ method: import_zod9.z.string(),
807
+ query: import_zod9.z.record(import_zod9.z.string()),
808
+ url: import_zod9.z.string(),
809
+ body: import_zod9.z.any()
742
810
  });
743
- var HttpSourceResponseSchema = import_zod8.z.object({
811
+ var NormalizedResponseSchema = import_zod9.z.object({
812
+ status: import_zod9.z.number(),
813
+ body: import_zod9.z.any(),
814
+ headers: import_zod9.z.record(import_zod9.z.string()).optional()
815
+ });
816
+ var HttpSourceResponseSchema = import_zod9.z.object({
744
817
  response: NormalizedResponseSchema,
745
- events: import_zod8.z.array(RawEventSchema)
818
+ events: import_zod9.z.array(RawEventSchema)
746
819
  });
747
- var RegisterTriggerBodySchema = import_zod8.z.object({
820
+ var RegisterTriggerBodySchema = import_zod9.z.object({
748
821
  rule: EventRuleSchema,
749
822
  source: SourceMetadataSchema
750
823
  });
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()
824
+ var InitializeTriggerBodySchema = import_zod9.z.object({
825
+ id: import_zod9.z.string(),
826
+ params: import_zod9.z.any(),
827
+ accountId: import_zod9.z.string().optional()
755
828
  });
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()
829
+ var RegisterCommonScheduleBodySchema = import_zod9.z.object({
830
+ id: import_zod9.z.string(),
831
+ metadata: import_zod9.z.any(),
832
+ accountId: import_zod9.z.string().optional()
760
833
  });
761
834
  var RegisterIntervalScheduleBodySchema = RegisterCommonScheduleBodySchema.merge(IntervalMetadataSchema);
762
835
  var InitializeCronScheduleBodySchema = RegisterCommonScheduleBodySchema.merge(CronMetadataSchema);
763
- var RegisterScheduleBodySchema = import_zod8.z.discriminatedUnion("type", [
836
+ var RegisterScheduleBodySchema = import_zod9.z.discriminatedUnion("type", [
764
837
  RegisterIntervalScheduleBodySchema,
765
838
  InitializeCronScheduleBodySchema
766
839
  ]);
767
- var RegisterScheduleResponseBodySchema = import_zod8.z.object({
768
- id: import_zod8.z.string(),
840
+ var RegisterScheduleResponseBodySchema = import_zod9.z.object({
841
+ id: import_zod9.z.string(),
769
842
  schedule: ScheduleMetadataSchema,
770
- metadata: import_zod8.z.any(),
771
- active: import_zod8.z.boolean()
843
+ metadata: import_zod9.z.any(),
844
+ active: import_zod9.z.boolean()
772
845
  });
773
- var CreateExternalConnectionBodySchema = import_zod8.z.object({
774
- accessToken: import_zod8.z.string(),
775
- type: import_zod8.z.enum([
846
+ var CreateExternalConnectionBodySchema = import_zod9.z.object({
847
+ accessToken: import_zod9.z.string(),
848
+ type: import_zod9.z.enum([
776
849
  "oauth2"
777
850
  ]),
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()
851
+ scopes: import_zod9.z.array(import_zod9.z.string()).optional(),
852
+ metadata: import_zod9.z.any()
789
853
  });
790
854
 
791
855
  // ../internal/src/schemas/notifications.ts
@@ -799,9 +863,7 @@ var CommonMissingConnectionNotificationPayloadSchema = import_zod10.z.object({
799
863
  title: import_zod10.z.string(),
800
864
  scopes: import_zod10.z.array(import_zod10.z.string()),
801
865
  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()
866
+ updatedAt: import_zod10.z.coerce.date()
805
867
  }),
806
868
  authorizationUrl: import_zod10.z.string()
807
869
  });
@@ -847,6 +909,39 @@ var MissingConnectionResolvedNotificationPayloadSchema = import_zod10.z.discrimi
847
909
  MissingExternalConnectionResolvedNotificationPayloadSchema
848
910
  ]);
849
911
 
912
+ // ../internal/src/schemas/fetch.ts
913
+ var import_zod11 = require("zod");
914
+ var FetchRetryHeadersStrategySchema = import_zod11.z.object({
915
+ strategy: import_zod11.z.literal("headers"),
916
+ limitHeader: import_zod11.z.string(),
917
+ remainingHeader: import_zod11.z.string(),
918
+ resetHeader: import_zod11.z.string()
919
+ });
920
+ var FetchRetryBackoffStrategySchema = RetryOptionsSchema.extend({
921
+ strategy: import_zod11.z.literal("backoff")
922
+ });
923
+ var FetchRetryStrategySchema = import_zod11.z.discriminatedUnion("strategy", [
924
+ FetchRetryHeadersStrategySchema,
925
+ FetchRetryBackoffStrategySchema
926
+ ]);
927
+ var FetchRequestInitSchema = import_zod11.z.object({
928
+ method: import_zod11.z.string().optional(),
929
+ headers: import_zod11.z.record(import_zod11.z.union([
930
+ import_zod11.z.string(),
931
+ RedactStringSchema
932
+ ])).optional(),
933
+ body: import_zod11.z.union([
934
+ import_zod11.z.string(),
935
+ import_zod11.z.instanceof(ArrayBuffer)
936
+ ]).optional()
937
+ });
938
+ var FetchRetryOptionsSchema = import_zod11.z.record(FetchRetryStrategySchema);
939
+ var FetchOperationSchema = import_zod11.z.object({
940
+ url: import_zod11.z.string(),
941
+ requestInit: FetchRequestInitSchema.optional(),
942
+ retry: import_zod11.z.record(FetchRetryStrategySchema).optional()
943
+ });
944
+
850
945
  // ../internal/src/utils.ts
851
946
  function deepMergeFilters(filter, other) {
852
947
  const result = {
@@ -873,8 +968,40 @@ function deepMergeFilters(filter, other) {
873
968
  }
874
969
  __name(deepMergeFilters, "deepMergeFilters");
875
970
 
971
+ // ../internal/src/retry.ts
972
+ var DEFAULT_RETRY_OPTIONS = {
973
+ limit: 5,
974
+ factor: 1.8,
975
+ minTimeoutInMs: 1e3,
976
+ maxTimeoutInMs: 6e4,
977
+ randomize: true
978
+ };
979
+ function calculateRetryAt(retryOptions, attempts) {
980
+ const options = {
981
+ ...DEFAULT_RETRY_OPTIONS,
982
+ ...retryOptions
983
+ };
984
+ const retryCount = attempts + 1;
985
+ if (retryCount >= options.limit) {
986
+ return;
987
+ }
988
+ const random = options.randomize ? Math.random() + 1 : 1;
989
+ let timeoutInMs = Math.round(random * Math.max(options.minTimeoutInMs, 1) * Math.pow(options.factor, Math.max(attempts - 1, 0)));
990
+ timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);
991
+ return new Date(Date.now() + timeoutInMs);
992
+ }
993
+ __name(calculateRetryAt, "calculateRetryAt");
994
+
995
+ // ../internal/src/replacements.ts
996
+ var currentDate = {
997
+ marker: "__CURRENT_DATE__",
998
+ replace({ data: { now } }) {
999
+ return now.toISOString();
1000
+ }
1001
+ };
1002
+
876
1003
  // src/apiClient.ts
877
- var import_zod11 = require("zod");
1004
+ var import_zod12 = require("zod");
878
1005
  var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
879
1006
  var ApiClient = class {
880
1007
  constructor(options) {
@@ -955,6 +1082,22 @@ var ApiClient = class {
955
1082
  body: JSON.stringify(task)
956
1083
  });
957
1084
  }
1085
+ async failTask(runId, id, body) {
1086
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
1087
+ __privateGet(this, _logger).debug("Fail Task", {
1088
+ id,
1089
+ runId,
1090
+ body
1091
+ });
1092
+ return await zodfetch(ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/fail`, {
1093
+ method: "POST",
1094
+ headers: {
1095
+ "Content-Type": "application/json",
1096
+ Authorization: `Bearer ${apiKey}`
1097
+ },
1098
+ body: JSON.stringify(body)
1099
+ });
1100
+ }
958
1101
  async sendEvent(event, options = {}) {
959
1102
  const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
960
1103
  __privateGet(this, _logger).debug("Sending event", {
@@ -1027,8 +1170,8 @@ var ApiClient = class {
1027
1170
  __privateGet(this, _logger).debug("unregistering schedule", {
1028
1171
  id
1029
1172
  });
1030
- const response = await zodfetch(import_zod11.z.object({
1031
- ok: import_zod11.z.boolean()
1173
+ const response = await zodfetch(import_zod12.z.object({
1174
+ ok: import_zod12.z.boolean()
1032
1175
  }), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
1033
1176
  method: "DELETE",
1034
1177
  headers: {
@@ -1106,6 +1249,26 @@ async function zodfetch(schema, url, requestInit, options) {
1106
1249
  }
1107
1250
  __name(zodfetch, "zodfetch");
1108
1251
 
1252
+ // src/errors.ts
1253
+ var ResumeWithTaskError = class {
1254
+ constructor(task) {
1255
+ this.task = task;
1256
+ }
1257
+ };
1258
+ __name(ResumeWithTaskError, "ResumeWithTaskError");
1259
+ var RetryWithTaskError = class {
1260
+ constructor(cause, task, retryAt) {
1261
+ this.cause = cause;
1262
+ this.task = task;
1263
+ this.retryAt = retryAt;
1264
+ }
1265
+ };
1266
+ __name(RetryWithTaskError, "RetryWithTaskError");
1267
+ function isTriggerError(err) {
1268
+ return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError;
1269
+ }
1270
+ __name(isTriggerError, "isTriggerError");
1271
+
1109
1272
  // src/io.ts
1110
1273
  var import_node_async_hooks = require("async_hooks");
1111
1274
  var import_node_crypto = require("crypto");
@@ -1116,11 +1279,12 @@ function createIOWithIntegrations(io, auths, integrations) {
1116
1279
  return io;
1117
1280
  }
1118
1281
  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;
1282
+ let auth = auths?.[connectionKey];
1283
+ const client = integration.client.usesLocalAuth ? integration.client.client : auth ? integration.client.clientFactory?.(auth) : void 0;
1121
1284
  if (!client) {
1122
1285
  return acc;
1123
1286
  }
1287
+ auth = integration.client.usesLocalAuth ? integration.client.auth : auth;
1124
1288
  const ioConnection = {
1125
1289
  client
1126
1290
  };
@@ -1132,8 +1296,8 @@ function createIOWithIntegrations(io, auths, integrations) {
1132
1296
  const options = authenticatedTask2.init(params);
1133
1297
  options.connectionKey = connectionKey;
1134
1298
  return await io.runTask(key, options, async (ioTask) => {
1135
- return authenticatedTask2.run(params, client, ioTask, io);
1136
- });
1299
+ return authenticatedTask2.run(params, client, ioTask, io, auth);
1300
+ }, authenticatedTask2.onError);
1137
1301
  };
1138
1302
  });
1139
1303
  }
@@ -1156,12 +1320,6 @@ function createIOWithIntegrations(io, auths, integrations) {
1156
1320
  __name(createIOWithIntegrations, "createIOWithIntegrations");
1157
1321
 
1158
1322
  // src/io.ts
1159
- var ResumeWithTask = class {
1160
- constructor(task) {
1161
- this.task = task;
1162
- }
1163
- };
1164
- __name(ResumeWithTask, "ResumeWithTask");
1165
1323
  var _addToCachedTasks, addToCachedTasks_fn;
1166
1324
  var IO = class {
1167
1325
  constructor(options) {
@@ -1237,6 +1395,37 @@ var IO = class {
1237
1395
  }, async (task) => {
1238
1396
  });
1239
1397
  }
1398
+ async backgroundFetch(key, url, requestInit, retry) {
1399
+ const urlObject = new URL(url);
1400
+ return await this.runTask(key, {
1401
+ name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
1402
+ params: {
1403
+ url,
1404
+ requestInit,
1405
+ retry
1406
+ },
1407
+ operation: "fetch",
1408
+ icon: "background",
1409
+ noop: false,
1410
+ properties: [
1411
+ {
1412
+ label: "url",
1413
+ text: url,
1414
+ url
1415
+ },
1416
+ {
1417
+ label: "method",
1418
+ text: requestInit?.method ?? "GET"
1419
+ },
1420
+ {
1421
+ label: "background",
1422
+ text: "true"
1423
+ }
1424
+ ]
1425
+ }, async (task) => {
1426
+ return task.output;
1427
+ });
1428
+ }
1240
1429
  async sendEvent(key, event, options) {
1241
1430
  return await this.runTask(key, {
1242
1431
  name: "sendEvent",
@@ -1401,7 +1590,7 @@ var IO = class {
1401
1590
  return await this._triggerClient.getAuth(clientId);
1402
1591
  });
1403
1592
  }
1404
- async runTask(key, options, callback) {
1593
+ async runTask(key, options, callback, onError) {
1405
1594
  const parentId = this._taskStorage.getStore()?.taskId;
1406
1595
  if (parentId) {
1407
1596
  this._logger.debug("Using parent task", {
@@ -1450,7 +1639,14 @@ var IO = class {
1450
1639
  idempotencyKey,
1451
1640
  task
1452
1641
  });
1453
- throw new ResumeWithTask(task);
1642
+ throw new ResumeWithTaskError(task);
1643
+ }
1644
+ if (task.status === "RUNNING" && typeof task.operation === "string") {
1645
+ this._logger.debug("Task running operation", {
1646
+ idempotencyKey,
1647
+ task
1648
+ });
1649
+ throw new ResumeWithTaskError(task);
1454
1650
  }
1455
1651
  const executeTask = /* @__PURE__ */ __name(async () => {
1456
1652
  try {
@@ -1464,6 +1660,39 @@ var IO = class {
1464
1660
  });
1465
1661
  return result;
1466
1662
  } catch (error) {
1663
+ if (isTriggerError(error)) {
1664
+ throw error;
1665
+ }
1666
+ if (onError) {
1667
+ const onErrorResult = onError(error, task, this);
1668
+ 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);
1673
+ }
1674
+ }
1675
+ const parsedError = ErrorWithStackSchema.safeParse(error);
1676
+ if (options.retry) {
1677
+ const retryAt = calculateRetryAt(options.retry, task.attempts - 1);
1678
+ if (retryAt) {
1679
+ throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
1680
+ message: "Unknown error"
1681
+ }, task, retryAt);
1682
+ }
1683
+ }
1684
+ if (parsedError.success) {
1685
+ await this._apiClient.failTask(this._id, task.id, {
1686
+ error: parsedError.data
1687
+ });
1688
+ } else {
1689
+ await this._apiClient.failTask(this._id, task.id, {
1690
+ error: {
1691
+ message: JSON.stringify(error),
1692
+ name: "Unknown Error"
1693
+ }
1694
+ });
1695
+ }
1467
1696
  throw error;
1468
1697
  }
1469
1698
  }, "executeTask");
@@ -1471,6 +1700,16 @@ var IO = class {
1471
1700
  taskId: task.id
1472
1701
  }, executeTask);
1473
1702
  }
1703
+ async try(tryCallback, catchCallback) {
1704
+ try {
1705
+ return await tryCallback();
1706
+ } catch (error) {
1707
+ if (isTriggerError(error)) {
1708
+ throw error;
1709
+ }
1710
+ return await catchCallback(error);
1711
+ }
1712
+ }
1474
1713
  };
1475
1714
  __name(IO, "IO");
1476
1715
  _addToCachedTasks = new WeakSet();
@@ -1559,7 +1798,7 @@ __name(EventTrigger, "EventTrigger");
1559
1798
  _options2 = new WeakMap();
1560
1799
  function eventTrigger(options) {
1561
1800
  return new EventTrigger({
1562
- name: "Event Trigger",
1801
+ name: options.name,
1563
1802
  filter: options.filter,
1564
1803
  event: {
1565
1804
  name: options.name,
@@ -1645,14 +1884,33 @@ var TriggerClient = class {
1645
1884
  }
1646
1885
  switch (action) {
1647
1886
  case "PING": {
1887
+ const endpointId = request.headers.get("x-trigger-endpoint-id");
1888
+ if (!endpointId) {
1889
+ return {
1890
+ status: 200,
1891
+ body: {
1892
+ ok: false,
1893
+ message: "Missing endpoint ID"
1894
+ }
1895
+ };
1896
+ }
1897
+ if (this.id !== endpointId) {
1898
+ return {
1899
+ status: 200,
1900
+ body: {
1901
+ ok: false,
1902
+ message: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
1903
+ }
1904
+ };
1905
+ }
1648
1906
  return {
1649
1907
  status: 200,
1650
1908
  body: {
1651
- message: "PONG"
1909
+ ok: true
1652
1910
  }
1653
1911
  };
1654
1912
  }
1655
- case "GET_ENDPOINT_DATA": {
1913
+ case "INDEX_ENDPOINT": {
1656
1914
  const jobId = request.headers.get("x-trigger-job-id");
1657
1915
  if (jobId) {
1658
1916
  const job = __privateGet(this, _registeredJobs)[jobId];
@@ -1686,15 +1944,6 @@ var TriggerClient = class {
1686
1944
  body
1687
1945
  };
1688
1946
  }
1689
- case "INITIALIZE": {
1690
- await this.listen();
1691
- return {
1692
- status: 200,
1693
- body: {
1694
- message: "Initialized"
1695
- }
1696
- };
1697
- }
1698
1947
  case "INITIALIZE_TRIGGER": {
1699
1948
  const json = await request.json();
1700
1949
  const body = InitializeTriggerBodySchema.safeParse(json);
@@ -1741,20 +1990,9 @@ var TriggerClient = class {
1741
1990
  };
1742
1991
  }
1743
1992
  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
1993
  return {
1751
1994
  status: 200,
1752
- body: {
1753
- completed: results.completed,
1754
- output: results.output,
1755
- executionId: execution.data.run.id,
1756
- task: results.task
1757
- }
1995
+ body: results
1758
1996
  };
1759
1997
  }
1760
1998
  case "PREPROCESS_RUN": {
@@ -1886,7 +2124,11 @@ var TriggerClient = class {
1886
2124
  key: options.key,
1887
2125
  params: options.params,
1888
2126
  events: [],
1889
- clientId: !options.source.integration.usesLocalAuth ? options.source.integration.id : void 0
2127
+ integration: {
2128
+ id: options.source.integration.id,
2129
+ metadata: options.source.integration.metadata,
2130
+ authSource: options.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
2131
+ }
1890
2132
  };
1891
2133
  }
1892
2134
  registeredSource.events = Array.from(/* @__PURE__ */ new Set([
@@ -1962,12 +2204,6 @@ var TriggerClient = class {
1962
2204
  apiKey() {
1963
2205
  return __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
1964
2206
  }
1965
- async listen() {
1966
- await __privateGet(this, _client).registerEndpoint({
1967
- url: this.url,
1968
- name: this.id
1969
- });
1970
- }
1971
2207
  };
1972
2208
  __name(TriggerClient, "TriggerClient");
1973
2209
  _options3 = new WeakMap();
@@ -2008,32 +2244,50 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2008
2244
  try {
2009
2245
  const output = await job1.options.run(job1.trigger.event.parsePayload(body1.event.payload ?? {}), ioWithConnections, context);
2010
2246
  return {
2011
- completed: true,
2247
+ status: "SUCCESS",
2012
2248
  output
2013
2249
  };
2014
2250
  } catch (error) {
2015
- if (error instanceof ResumeWithTask) {
2251
+ if (error instanceof ResumeWithTaskError) {
2016
2252
  return {
2017
- completed: false,
2253
+ status: "RESUME_WITH_TASK",
2018
2254
  task: error.task
2019
2255
  };
2020
2256
  }
2021
- const errorWithStack = ErrorWithStackSchema.safeParse(error);
2022
- if (errorWithStack.success) {
2257
+ if (error instanceof RetryWithTaskError) {
2023
2258
  return {
2024
- completed: true,
2025
- error: errorWithStack.data
2259
+ status: "RETRY_WITH_TASK",
2260
+ task: error.task,
2261
+ error: error.cause,
2262
+ retryAt: error.retryAt
2026
2263
  };
2027
2264
  }
2028
- const errorWithMessage = ErrorWithMessage.safeParse(error);
2029
- if (errorWithMessage.success) {
2265
+ if (error instanceof RetryWithTaskError) {
2266
+ const errorWithStack2 = ErrorWithStackSchema.safeParse(error.cause);
2267
+ if (errorWithStack2.success) {
2268
+ return {
2269
+ status: "ERROR",
2270
+ error: errorWithStack2.data,
2271
+ task: error.task
2272
+ };
2273
+ }
2030
2274
  return {
2031
- completed: true,
2032
- error: errorWithMessage.data
2275
+ status: "ERROR",
2276
+ error: {
2277
+ message: "Unknown error"
2278
+ },
2279
+ task: error.task
2280
+ };
2281
+ }
2282
+ const errorWithStack = ErrorWithStackSchema.safeParse(error);
2283
+ if (errorWithStack.success) {
2284
+ return {
2285
+ status: "ERROR",
2286
+ error: errorWithStack.data
2033
2287
  };
2034
2288
  }
2035
2289
  return {
2036
- completed: true,
2290
+ status: "ERROR",
2037
2291
  error: {
2038
2292
  message: "Unknown error"
2039
2293
  }
@@ -2319,7 +2573,11 @@ var DynamicTrigger = class {
2319
2573
  events: [
2320
2574
  this.event.name
2321
2575
  ],
2322
- clientId: !this.source.integration.usesLocalAuth ? this.source.integration.id : void 0
2576
+ integration: {
2577
+ id: this.source.integration.id,
2578
+ metadata: this.source.integration.metadata,
2579
+ authSource: this.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
2580
+ }
2323
2581
  }
2324
2582
  };
2325
2583
  }
@@ -2338,6 +2596,17 @@ _client2 = new WeakMap();
2338
2596
  _options4 = new WeakMap();
2339
2597
 
2340
2598
  // src/triggers/scheduled.ts
2599
+ var examples = [
2600
+ {
2601
+ id: "now",
2602
+ name: "Now",
2603
+ icon: "clock",
2604
+ payload: {
2605
+ ts: currentDate.marker,
2606
+ lastTimestamp: currentDate.marker
2607
+ }
2608
+ }
2609
+ ];
2341
2610
  var IntervalTrigger = class {
2342
2611
  constructor(options) {
2343
2612
  this.options = options;
@@ -2348,6 +2617,7 @@ var IntervalTrigger = class {
2348
2617
  title: "Schedule",
2349
2618
  source: "trigger.dev",
2350
2619
  icon: "schedule-interval",
2620
+ examples,
2351
2621
  parsePayload: ScheduledPayloadSchema.parse,
2352
2622
  properties: [
2353
2623
  {
@@ -2389,6 +2659,7 @@ var CronTrigger = class {
2389
2659
  title: "Cron Schedule",
2390
2660
  source: "trigger.dev",
2391
2661
  icon: "schedule-cron",
2662
+ examples,
2392
2663
  parsePayload: ScheduledPayloadSchema.parse,
2393
2664
  properties: [
2394
2665
  {
@@ -2434,6 +2705,7 @@ var DynamicSchedule = class {
2434
2705
  title: "Dynamic Schedule",
2435
2706
  source: "trigger.dev",
2436
2707
  icon: "schedule-dynamic",
2708
+ examples,
2437
2709
  parsePayload: ScheduledPayloadSchema.parse
2438
2710
  };
2439
2711
  }
@@ -2555,14 +2827,14 @@ var MissingConnectionResolvedNotification = class {
2555
2827
  __name(MissingConnectionResolvedNotification, "MissingConnectionResolvedNotification");
2556
2828
 
2557
2829
  // src/index.ts
2558
- function secureString(strings, ...interpolations) {
2830
+ function redactString(strings, ...interpolations) {
2559
2831
  return {
2560
- __secureString: true,
2832
+ __redactedString: true,
2561
2833
  strings: strings.raw,
2562
2834
  interpolations
2563
2835
  };
2564
2836
  }
2565
- __name(secureString, "secureString");
2837
+ __name(redactString, "redactString");
2566
2838
  // Annotate the CommonJS export names for ESM import in node:
2567
2839
  0 && (module.exports = {
2568
2840
  CronTrigger,
@@ -2577,15 +2849,15 @@ __name(secureString, "secureString");
2577
2849
  Job,
2578
2850
  MissingConnectionNotification,
2579
2851
  MissingConnectionResolvedNotification,
2580
- ResumeWithTask,
2581
2852
  TriggerClient,
2582
2853
  authenticatedTask,
2583
2854
  cronTrigger,
2584
2855
  eventTrigger,
2585
2856
  intervalTrigger,
2857
+ isTriggerError,
2586
2858
  missingConnectionNotification,
2587
2859
  missingConnectionResolvedNotification,
2588
2860
  omit,
2589
- secureString
2861
+ redactString
2590
2862
  });
2591
2863
  //# sourceMappingURL=index.js.map