@trigger.dev/sdk 2.0.0 → 2.0.1

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
@@ -146,935 +146,13 @@ validate_fn = /* @__PURE__ */ __name(function() {
146
146
  }
147
147
  }, "#validate");
148
148
 
149
- // ../core/src/logger.ts
150
- var logLevels = [
151
- "log",
152
- "error",
153
- "warn",
154
- "info",
155
- "debug"
156
- ];
157
- var _name, _level, _filteredKeys, _jsonReplacer, _structuredLog, structuredLog_fn;
158
- var _Logger = class {
159
- constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
160
- __privateAdd(this, _structuredLog);
161
- __privateAdd(this, _name, void 0);
162
- __privateAdd(this, _level, void 0);
163
- __privateAdd(this, _filteredKeys, []);
164
- __privateAdd(this, _jsonReplacer, void 0);
165
- __privateSet(this, _name, name);
166
- __privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
167
- __privateSet(this, _filteredKeys, filteredKeys);
168
- __privateSet(this, _jsonReplacer, jsonReplacer);
169
- }
170
- filter(...keys) {
171
- return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
172
- }
173
- static satisfiesLogLevel(logLevel, setLevel) {
174
- return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
175
- }
176
- log(message, ...args) {
177
- if (__privateGet(this, _level) < 0)
178
- return;
179
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.log, message, ...args);
180
- }
181
- error(message, ...args) {
182
- if (__privateGet(this, _level) < 1)
183
- return;
184
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.error, message, ...args);
185
- }
186
- warn(message, ...args) {
187
- if (__privateGet(this, _level) < 2)
188
- return;
189
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.warn, message, ...args);
190
- }
191
- info(message, ...args) {
192
- if (__privateGet(this, _level) < 3)
193
- return;
194
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.info, message, ...args);
195
- }
196
- debug(message, ...args) {
197
- if (__privateGet(this, _level) < 4)
198
- return;
199
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.debug, message, ...args);
200
- }
201
- };
202
- var Logger = _Logger;
203
- __name(Logger, "Logger");
204
- _name = new WeakMap();
205
- _level = new WeakMap();
206
- _filteredKeys = new WeakMap();
207
- _jsonReplacer = new WeakMap();
208
- _structuredLog = new WeakSet();
209
- structuredLog_fn = /* @__PURE__ */ __name(function(loggerFunction, message, ...args) {
210
- const structuredLog = {
211
- ...structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys)),
212
- timestamp: new Date(),
213
- name: __privateGet(this, _name),
214
- message
215
- };
216
- loggerFunction(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
217
- }, "#structuredLog");
218
- function createReplacer(replacer) {
219
- return (key, value) => {
220
- if (typeof value === "bigint") {
221
- return value.toString();
222
- }
223
- if (replacer) {
224
- return replacer(key, value);
225
- }
226
- return value;
227
- };
228
- }
229
- __name(createReplacer, "createReplacer");
230
- function bigIntReplacer(_key, value) {
231
- if (typeof value === "bigint") {
232
- return value.toString();
233
- }
234
- return value;
235
- }
236
- __name(bigIntReplacer, "bigIntReplacer");
237
- function safeJsonClone(obj) {
238
- try {
239
- return JSON.parse(JSON.stringify(obj, bigIntReplacer));
240
- } catch (e) {
241
- return obj;
242
- }
243
- }
244
- __name(safeJsonClone, "safeJsonClone");
245
- function structureArgs(args, filteredKeys = []) {
246
- if (args.length === 0) {
247
- return;
248
- }
249
- if (args.length === 1 && typeof args[0] === "object") {
250
- return filterKeys(JSON.parse(JSON.stringify(args[0], bigIntReplacer)), filteredKeys);
251
- }
252
- return args;
253
- }
254
- __name(structureArgs, "structureArgs");
255
- function filterKeys(obj, keys) {
256
- if (typeof obj !== "object" || obj === null) {
257
- return obj;
258
- }
259
- if (Array.isArray(obj)) {
260
- return obj.map((item) => filterKeys(item, keys));
261
- }
262
- const filteredObj = {};
263
- for (const [key, value] of Object.entries(obj)) {
264
- if (keys.includes(key)) {
265
- continue;
266
- }
267
- filteredObj[key] = filterKeys(value, keys);
268
- }
269
- return filteredObj;
270
- }
271
- __name(filterKeys, "filterKeys");
272
-
273
- // ../core/src/schemas/api.ts
274
- var import_ulid = require("ulid");
275
- var import_zod9 = require("zod");
276
-
277
- // ../core/src/schemas/errors.ts
278
- var import_zod = require("zod");
279
- var ErrorWithStackSchema = import_zod.z.object({
280
- message: import_zod.z.string(),
281
- name: import_zod.z.string().optional(),
282
- stack: import_zod.z.string().optional()
283
- });
284
-
285
- // ../core/src/schemas/eventFilter.ts
286
- var import_zod2 = require("zod");
287
- var EventMatcherSchema = import_zod2.z.union([
288
- import_zod2.z.array(import_zod2.z.string()),
289
- import_zod2.z.array(import_zod2.z.number()),
290
- import_zod2.z.array(import_zod2.z.boolean())
291
- ]);
292
- var EventFilterSchema = import_zod2.z.lazy(() => import_zod2.z.record(import_zod2.z.union([
293
- EventMatcherSchema,
294
- EventFilterSchema
295
- ])));
296
- var EventRuleSchema = import_zod2.z.object({
297
- event: import_zod2.z.string().or(import_zod2.z.array(import_zod2.z.string())),
298
- source: import_zod2.z.string(),
299
- payload: EventFilterSchema.optional(),
300
- context: EventFilterSchema.optional()
301
- });
302
-
303
- // ../core/src/schemas/integrations.ts
304
- var import_zod3 = require("zod");
305
- var ConnectionAuthSchema = import_zod3.z.object({
306
- type: import_zod3.z.enum([
307
- "oauth2"
308
- ]),
309
- accessToken: import_zod3.z.string(),
310
- scopes: import_zod3.z.array(import_zod3.z.string()).optional(),
311
- additionalFields: import_zod3.z.record(import_zod3.z.string()).optional()
312
- });
313
- var IntegrationMetadataSchema = import_zod3.z.object({
314
- id: import_zod3.z.string(),
315
- name: import_zod3.z.string(),
316
- instructions: import_zod3.z.string().optional()
317
- });
318
- var IntegrationConfigSchema = import_zod3.z.object({
319
- id: import_zod3.z.string(),
320
- metadata: IntegrationMetadataSchema,
321
- authSource: import_zod3.z.enum([
322
- "HOSTED",
323
- "LOCAL"
324
- ])
325
- });
326
-
327
- // ../core/src/schemas/json.ts
328
- var import_zod4 = require("zod");
329
- var LiteralSchema = import_zod4.z.union([
330
- import_zod4.z.string(),
331
- import_zod4.z.number(),
332
- import_zod4.z.boolean(),
333
- import_zod4.z.null()
334
- ]);
335
- var DeserializedJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
336
- LiteralSchema,
337
- import_zod4.z.array(DeserializedJsonSchema),
338
- import_zod4.z.record(DeserializedJsonSchema)
339
- ]));
340
- var SerializableSchema = import_zod4.z.union([
341
- import_zod4.z.string(),
342
- import_zod4.z.number(),
343
- import_zod4.z.boolean(),
344
- import_zod4.z.null(),
345
- import_zod4.z.date(),
346
- import_zod4.z.undefined(),
347
- import_zod4.z.symbol()
348
- ]);
349
- var SerializableJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
350
- SerializableSchema,
351
- import_zod4.z.array(SerializableJsonSchema),
352
- import_zod4.z.record(SerializableJsonSchema)
353
- ]));
354
-
355
- // ../core/src/schemas/properties.ts
356
- var import_zod5 = require("zod");
357
- var DisplayPropertySchema = import_zod5.z.object({
358
- label: import_zod5.z.string(),
359
- text: import_zod5.z.string(),
360
- url: import_zod5.z.string().optional()
361
- });
362
- var DisplayPropertiesSchema = import_zod5.z.array(DisplayPropertySchema);
363
- var StyleSchema = import_zod5.z.object({
364
- style: import_zod5.z.enum([
365
- "normal",
366
- "minimal"
367
- ]),
368
- variant: import_zod5.z.string().optional()
369
- });
370
-
371
- // ../core/src/schemas/schedules.ts
372
- var import_zod6 = require("zod");
373
- var ScheduledPayloadSchema = import_zod6.z.object({
374
- ts: import_zod6.z.coerce.date(),
375
- lastTimestamp: import_zod6.z.coerce.date().optional()
376
- });
377
- var IntervalOptionsSchema = import_zod6.z.object({
378
- seconds: import_zod6.z.number().int().positive().min(60).max(86400)
379
- });
380
- var CronOptionsSchema = import_zod6.z.object({
381
- cron: import_zod6.z.string()
382
- });
383
- var CronMetadataSchema = import_zod6.z.object({
384
- type: import_zod6.z.literal("cron"),
385
- options: CronOptionsSchema,
386
- metadata: import_zod6.z.any()
387
- });
388
- var IntervalMetadataSchema = import_zod6.z.object({
389
- type: import_zod6.z.literal("interval"),
390
- options: IntervalOptionsSchema,
391
- metadata: import_zod6.z.any()
392
- });
393
- var ScheduleMetadataSchema = import_zod6.z.discriminatedUnion("type", [
394
- IntervalMetadataSchema,
395
- CronMetadataSchema
396
- ]);
397
- var RegisterDynamicSchedulePayloadSchema = import_zod6.z.object({
398
- id: import_zod6.z.string(),
399
- jobs: import_zod6.z.array(import_zod6.z.object({
400
- id: import_zod6.z.string(),
401
- version: import_zod6.z.string()
402
- }))
403
- });
404
-
405
- // ../core/src/schemas/tasks.ts
406
- var import_zod7 = require("zod");
407
- var TaskStatusSchema = import_zod7.z.enum([
408
- "PENDING",
409
- "WAITING",
410
- "RUNNING",
411
- "COMPLETED",
412
- "ERRORED",
413
- "CANCELED"
414
- ]);
415
- var TaskSchema = import_zod7.z.object({
416
- id: import_zod7.z.string(),
417
- name: import_zod7.z.string(),
418
- icon: import_zod7.z.string().optional().nullable(),
419
- noop: import_zod7.z.boolean(),
420
- startedAt: import_zod7.z.coerce.date().optional().nullable(),
421
- completedAt: import_zod7.z.coerce.date().optional().nullable(),
422
- delayUntil: import_zod7.z.coerce.date().optional().nullable(),
423
- status: TaskStatusSchema,
424
- description: import_zod7.z.string().optional().nullable(),
425
- properties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
426
- outputProperties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
427
- params: DeserializedJsonSchema.optional().nullable(),
428
- output: DeserializedJsonSchema.optional().nullable(),
429
- error: import_zod7.z.string().optional().nullable(),
430
- parentId: import_zod7.z.string().optional().nullable(),
431
- style: StyleSchema.optional().nullable(),
432
- operation: import_zod7.z.string().optional().nullable()
433
- });
434
- var ServerTaskSchema = TaskSchema.extend({
435
- idempotencyKey: import_zod7.z.string(),
436
- attempts: import_zod7.z.number()
437
- });
438
- var CachedTaskSchema = import_zod7.z.object({
439
- id: import_zod7.z.string(),
440
- idempotencyKey: import_zod7.z.string(),
441
- status: TaskStatusSchema,
442
- noop: import_zod7.z.boolean().default(false),
443
- output: DeserializedJsonSchema.optional().nullable(),
444
- parentId: import_zod7.z.string().optional().nullable()
445
- });
446
-
447
- // ../core/src/schemas/triggers.ts
448
- var import_zod8 = require("zod");
449
- var EventExampleSchema = import_zod8.z.object({
450
- id: import_zod8.z.string(),
451
- icon: import_zod8.z.string().optional(),
452
- name: import_zod8.z.string(),
453
- payload: import_zod8.z.any()
454
- });
455
- var EventSpecificationSchema = import_zod8.z.object({
456
- name: import_zod8.z.string().or(import_zod8.z.array(import_zod8.z.string())),
457
- title: import_zod8.z.string(),
458
- source: import_zod8.z.string(),
459
- icon: import_zod8.z.string(),
460
- filter: EventFilterSchema.optional(),
461
- properties: import_zod8.z.array(DisplayPropertySchema).optional(),
462
- schema: import_zod8.z.any().optional(),
463
- examples: import_zod8.z.array(EventExampleSchema).optional()
464
- });
465
- var DynamicTriggerMetadataSchema = import_zod8.z.object({
466
- type: import_zod8.z.literal("dynamic"),
467
- id: import_zod8.z.string()
468
- });
469
- var StaticTriggerMetadataSchema = import_zod8.z.object({
470
- type: import_zod8.z.literal("static"),
471
- title: import_zod8.z.union([
472
- import_zod8.z.string(),
473
- import_zod8.z.array(import_zod8.z.string())
474
- ]),
475
- properties: import_zod8.z.array(DisplayPropertySchema).optional(),
476
- rule: EventRuleSchema
477
- });
478
- var ScheduledTriggerMetadataSchema = import_zod8.z.object({
479
- type: import_zod8.z.literal("scheduled"),
480
- schedule: ScheduleMetadataSchema
481
- });
482
- var TriggerMetadataSchema = import_zod8.z.discriminatedUnion("type", [
483
- DynamicTriggerMetadataSchema,
484
- StaticTriggerMetadataSchema,
485
- ScheduledTriggerMetadataSchema
486
- ]);
487
-
488
- // ../core/src/schemas/api.ts
489
- var UpdateTriggerSourceBodySchema = import_zod9.z.object({
490
- registeredEvents: import_zod9.z.array(import_zod9.z.string()),
491
- secret: import_zod9.z.string().optional(),
492
- data: SerializableJsonSchema.optional()
493
- });
494
- var HttpEventSourceSchema = UpdateTriggerSourceBodySchema.extend({
495
- id: import_zod9.z.string(),
496
- active: import_zod9.z.boolean(),
497
- url: import_zod9.z.string().url()
498
- });
499
- var RegisterHTTPTriggerSourceBodySchema = import_zod9.z.object({
500
- type: import_zod9.z.literal("HTTP"),
501
- url: import_zod9.z.string().url()
502
- });
503
- var RegisterSMTPTriggerSourceBodySchema = import_zod9.z.object({
504
- type: import_zod9.z.literal("SMTP")
505
- });
506
- var RegisterSQSTriggerSourceBodySchema = import_zod9.z.object({
507
- type: import_zod9.z.literal("SQS")
508
- });
509
- var RegisterSourceChannelBodySchema = import_zod9.z.discriminatedUnion("type", [
510
- RegisterHTTPTriggerSourceBodySchema,
511
- RegisterSMTPTriggerSourceBodySchema,
512
- RegisterSQSTriggerSourceBodySchema
513
- ]);
514
- var REGISTER_SOURCE_EVENT = "dev.trigger.source.register";
515
- var RegisterTriggerSourceSchema = import_zod9.z.object({
516
- key: import_zod9.z.string(),
517
- params: import_zod9.z.any(),
518
- active: import_zod9.z.boolean(),
519
- secret: import_zod9.z.string(),
520
- data: DeserializedJsonSchema.optional(),
521
- channel: RegisterSourceChannelBodySchema,
522
- clientId: import_zod9.z.string().optional()
523
- });
524
- var RegisterSourceEventSchema = import_zod9.z.object({
525
- id: import_zod9.z.string(),
526
- source: RegisterTriggerSourceSchema,
527
- events: import_zod9.z.array(import_zod9.z.string()),
528
- missingEvents: import_zod9.z.array(import_zod9.z.string()),
529
- orphanedEvents: import_zod9.z.array(import_zod9.z.string()),
530
- dynamicTriggerId: import_zod9.z.string().optional()
531
- });
532
- var TriggerSourceSchema = import_zod9.z.object({
533
- id: import_zod9.z.string(),
534
- key: import_zod9.z.string()
535
- });
536
- var HandleTriggerSourceSchema = import_zod9.z.object({
537
- key: import_zod9.z.string(),
538
- secret: import_zod9.z.string(),
539
- data: import_zod9.z.any(),
540
- params: import_zod9.z.any()
541
- });
542
- var HttpSourceRequestSchema = import_zod9.z.object({
543
- url: import_zod9.z.string().url(),
544
- method: import_zod9.z.string(),
545
- headers: import_zod9.z.record(import_zod9.z.string()),
546
- rawBody: import_zod9.z.instanceof(Buffer).optional().nullable()
547
- });
548
- var HttpSourceRequestHeadersSchema = import_zod9.z.object({
549
- "x-ts-key": import_zod9.z.string(),
550
- "x-ts-dynamic-id": import_zod9.z.string().optional(),
551
- "x-ts-secret": import_zod9.z.string(),
552
- "x-ts-data": import_zod9.z.string().transform((s) => JSON.parse(s)),
553
- "x-ts-params": import_zod9.z.string().transform((s) => JSON.parse(s)),
554
- "x-ts-http-url": import_zod9.z.string(),
555
- "x-ts-http-method": import_zod9.z.string(),
556
- "x-ts-http-headers": import_zod9.z.string().transform((s) => import_zod9.z.record(import_zod9.z.string()).parse(JSON.parse(s)))
557
- });
558
- var PongSuccessResponseSchema = import_zod9.z.object({
559
- ok: import_zod9.z.literal(true)
560
- });
561
- var PongErrorResponseSchema = import_zod9.z.object({
562
- ok: import_zod9.z.literal(false),
563
- error: import_zod9.z.string()
564
- });
565
- var PongResponseSchema = import_zod9.z.discriminatedUnion("ok", [
566
- PongSuccessResponseSchema,
567
- PongErrorResponseSchema
568
- ]);
569
- var QueueOptionsSchema = import_zod9.z.object({
570
- name: import_zod9.z.string(),
571
- maxConcurrent: import_zod9.z.number().optional()
572
- });
573
- var JobMetadataSchema = import_zod9.z.object({
574
- id: import_zod9.z.string(),
575
- name: import_zod9.z.string(),
576
- version: import_zod9.z.string(),
577
- event: EventSpecificationSchema,
578
- trigger: TriggerMetadataSchema,
579
- integrations: import_zod9.z.record(IntegrationConfigSchema),
580
- internal: import_zod9.z.boolean().default(false),
581
- queue: import_zod9.z.union([
582
- QueueOptionsSchema,
583
- import_zod9.z.string()
584
- ]).optional(),
585
- startPosition: import_zod9.z.enum([
586
- "initial",
587
- "latest"
588
- ]),
589
- enabled: import_zod9.z.boolean(),
590
- preprocessRuns: import_zod9.z.boolean()
591
- });
592
- var SourceMetadataSchema = import_zod9.z.object({
593
- channel: import_zod9.z.enum([
594
- "HTTP",
595
- "SQS",
596
- "SMTP"
597
- ]),
598
- integration: IntegrationConfigSchema,
599
- key: import_zod9.z.string(),
600
- params: import_zod9.z.any(),
601
- events: import_zod9.z.array(import_zod9.z.string()),
602
- registerSourceJob: import_zod9.z.object({
603
- id: import_zod9.z.string(),
604
- version: import_zod9.z.string()
605
- }).optional()
606
- });
607
- var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
608
- id: import_zod9.z.string(),
609
- jobs: import_zod9.z.array(JobMetadataSchema.pick({
610
- id: true,
611
- version: true
612
- })),
613
- registerSourceJob: import_zod9.z.object({
614
- id: import_zod9.z.string(),
615
- version: import_zod9.z.string()
616
- }).optional()
617
- });
618
- var IndexEndpointResponseSchema = import_zod9.z.object({
619
- jobs: import_zod9.z.array(JobMetadataSchema),
620
- sources: import_zod9.z.array(SourceMetadataSchema),
621
- dynamicTriggers: import_zod9.z.array(DynamicTriggerEndpointMetadataSchema),
622
- dynamicSchedules: import_zod9.z.array(RegisterDynamicSchedulePayloadSchema)
623
- });
624
- var RawEventSchema = import_zod9.z.object({
625
- name: import_zod9.z.string(),
626
- payload: import_zod9.z.any(),
627
- context: import_zod9.z.any().optional(),
628
- id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
629
- timestamp: import_zod9.z.coerce.date().optional(),
630
- source: import_zod9.z.string().optional()
631
- });
632
- var ApiEventLogSchema = import_zod9.z.object({
633
- id: import_zod9.z.string(),
634
- name: import_zod9.z.string(),
635
- payload: DeserializedJsonSchema,
636
- context: DeserializedJsonSchema.optional().nullable(),
637
- timestamp: import_zod9.z.coerce.date(),
638
- deliverAt: import_zod9.z.coerce.date().optional().nullable(),
639
- deliveredAt: import_zod9.z.coerce.date().optional().nullable()
640
- });
641
- var SendEventOptionsSchema = import_zod9.z.object({
642
- deliverAt: import_zod9.z.coerce.date().optional(),
643
- deliverAfter: import_zod9.z.number().int().optional(),
644
- accountId: import_zod9.z.string().optional()
645
- });
646
- var SendEventBodySchema = import_zod9.z.object({
647
- event: RawEventSchema,
648
- options: SendEventOptionsSchema.optional()
649
- });
650
- var DeliverEventResponseSchema = import_zod9.z.object({
651
- deliveredAt: import_zod9.z.string().datetime()
652
- });
653
- var RuntimeEnvironmentTypeSchema = import_zod9.z.enum([
654
- "PRODUCTION",
655
- "STAGING",
656
- "DEVELOPMENT",
657
- "PREVIEW"
658
- ]);
659
- var RunSourceContextSchema = import_zod9.z.object({
660
- id: import_zod9.z.string(),
661
- metadata: import_zod9.z.any()
662
- });
663
- var RunJobBodySchema = import_zod9.z.object({
664
- event: ApiEventLogSchema,
665
- job: import_zod9.z.object({
666
- id: import_zod9.z.string(),
667
- version: import_zod9.z.string()
668
- }),
669
- run: import_zod9.z.object({
670
- id: import_zod9.z.string(),
671
- isTest: import_zod9.z.boolean(),
672
- isRetry: import_zod9.z.boolean().default(false),
673
- startedAt: import_zod9.z.coerce.date()
674
- }),
675
- environment: import_zod9.z.object({
676
- id: import_zod9.z.string(),
677
- slug: import_zod9.z.string(),
678
- type: RuntimeEnvironmentTypeSchema
679
- }),
680
- organization: import_zod9.z.object({
681
- id: import_zod9.z.string(),
682
- title: import_zod9.z.string(),
683
- slug: import_zod9.z.string()
684
- }),
685
- account: import_zod9.z.object({
686
- id: import_zod9.z.string(),
687
- metadata: import_zod9.z.any()
688
- }).optional(),
689
- source: RunSourceContextSchema.optional(),
690
- tasks: import_zod9.z.array(CachedTaskSchema).optional(),
691
- connections: import_zod9.z.record(ConnectionAuthSchema).optional()
692
- });
693
- var RunJobErrorSchema = import_zod9.z.object({
694
- status: import_zod9.z.literal("ERROR"),
695
- error: ErrorWithStackSchema,
696
- task: TaskSchema.optional()
697
- });
698
- var RunJobResumeWithTaskSchema = import_zod9.z.object({
699
- status: import_zod9.z.literal("RESUME_WITH_TASK"),
700
- task: TaskSchema
701
- });
702
- var RunJobRetryWithTaskSchema = import_zod9.z.object({
703
- status: import_zod9.z.literal("RETRY_WITH_TASK"),
704
- task: TaskSchema,
705
- error: ErrorWithStackSchema,
706
- retryAt: import_zod9.z.coerce.date()
707
- });
708
- var RunJobCanceledWithTaskSchema = import_zod9.z.object({
709
- status: import_zod9.z.literal("CANCELED"),
710
- task: TaskSchema
711
- });
712
- var RunJobSuccessSchema = import_zod9.z.object({
713
- status: import_zod9.z.literal("SUCCESS"),
714
- output: DeserializedJsonSchema.optional()
715
- });
716
- var RunJobResponseSchema = import_zod9.z.discriminatedUnion("status", [
717
- RunJobErrorSchema,
718
- RunJobResumeWithTaskSchema,
719
- RunJobRetryWithTaskSchema,
720
- RunJobCanceledWithTaskSchema,
721
- RunJobSuccessSchema
722
- ]);
723
- var PreprocessRunBodySchema = import_zod9.z.object({
724
- event: ApiEventLogSchema,
725
- job: import_zod9.z.object({
726
- id: import_zod9.z.string(),
727
- version: import_zod9.z.string()
728
- }),
729
- run: import_zod9.z.object({
730
- id: import_zod9.z.string(),
731
- isTest: import_zod9.z.boolean()
732
- }),
733
- environment: import_zod9.z.object({
734
- id: import_zod9.z.string(),
735
- slug: import_zod9.z.string(),
736
- type: RuntimeEnvironmentTypeSchema
737
- }),
738
- organization: import_zod9.z.object({
739
- id: import_zod9.z.string(),
740
- title: import_zod9.z.string(),
741
- slug: import_zod9.z.string()
742
- }),
743
- account: import_zod9.z.object({
744
- id: import_zod9.z.string(),
745
- metadata: import_zod9.z.any()
746
- }).optional()
747
- });
748
- var PreprocessRunResponseSchema = import_zod9.z.object({
749
- abort: import_zod9.z.boolean(),
750
- properties: import_zod9.z.array(DisplayPropertySchema).optional()
751
- });
752
- var CreateRunBodySchema = import_zod9.z.object({
753
- client: import_zod9.z.string(),
754
- job: JobMetadataSchema,
755
- event: ApiEventLogSchema,
756
- properties: import_zod9.z.array(DisplayPropertySchema).optional()
757
- });
758
- var CreateRunResponseOkSchema = import_zod9.z.object({
759
- ok: import_zod9.z.literal(true),
760
- data: import_zod9.z.object({
761
- id: import_zod9.z.string()
762
- })
763
- });
764
- var CreateRunResponseErrorSchema = import_zod9.z.object({
765
- ok: import_zod9.z.literal(false),
766
- error: import_zod9.z.string()
767
- });
768
- var CreateRunResponseBodySchema = import_zod9.z.discriminatedUnion("ok", [
769
- CreateRunResponseOkSchema,
770
- CreateRunResponseErrorSchema
771
- ]);
772
- var RedactStringSchema = import_zod9.z.object({
773
- __redactedString: import_zod9.z.literal(true),
774
- strings: import_zod9.z.array(import_zod9.z.string()),
775
- interpolations: import_zod9.z.array(import_zod9.z.string())
776
- });
777
- var LogMessageSchema = import_zod9.z.object({
778
- level: import_zod9.z.enum([
779
- "DEBUG",
780
- "INFO",
781
- "WARN",
782
- "ERROR"
783
- ]),
784
- message: import_zod9.z.string(),
785
- data: SerializableJsonSchema.optional()
786
- });
787
- var RedactSchema = import_zod9.z.object({
788
- paths: import_zod9.z.array(import_zod9.z.string())
789
- });
790
- var RetryOptionsSchema = import_zod9.z.object({
791
- limit: import_zod9.z.number().optional(),
792
- factor: import_zod9.z.number().optional(),
793
- minTimeoutInMs: import_zod9.z.number().optional(),
794
- maxTimeoutInMs: import_zod9.z.number().optional(),
795
- randomize: import_zod9.z.boolean().optional()
796
- });
797
- var RunTaskOptionsSchema = import_zod9.z.object({
798
- name: import_zod9.z.string(),
799
- delayUntil: import_zod9.z.coerce.date().optional(),
800
- retry: RetryOptionsSchema.optional(),
801
- icon: import_zod9.z.string().optional(),
802
- displayKey: import_zod9.z.string().optional(),
803
- description: import_zod9.z.string().optional(),
804
- properties: import_zod9.z.array(DisplayPropertySchema).optional(),
805
- params: import_zod9.z.any(),
806
- style: StyleSchema.optional(),
807
- connectionKey: import_zod9.z.string().optional(),
808
- operation: import_zod9.z.enum([
809
- "fetch"
810
- ]).optional(),
811
- noop: import_zod9.z.boolean().default(false),
812
- redact: RedactSchema.optional(),
813
- trigger: TriggerMetadataSchema.optional()
814
- });
815
- var RunTaskBodyInputSchema = RunTaskOptionsSchema.extend({
816
- idempotencyKey: import_zod9.z.string(),
817
- parentId: import_zod9.z.string().optional()
818
- });
819
- var RunTaskBodyOutputSchema = RunTaskBodyInputSchema.extend({
820
- params: DeserializedJsonSchema.optional().nullable()
821
- });
822
- var CompleteTaskBodyInputSchema = RunTaskBodyInputSchema.pick({
823
- properties: true,
824
- description: true,
825
- params: true
826
- }).extend({
827
- output: SerializableJsonSchema.optional().transform((v) => v ? DeserializedJsonSchema.parse(JSON.parse(JSON.stringify(v))) : {})
828
- });
829
- var FailTaskBodyInputSchema = import_zod9.z.object({
830
- error: ErrorWithStackSchema
831
- });
832
- var NormalizedRequestSchema = import_zod9.z.object({
833
- headers: import_zod9.z.record(import_zod9.z.string()),
834
- method: import_zod9.z.string(),
835
- query: import_zod9.z.record(import_zod9.z.string()),
836
- url: import_zod9.z.string(),
837
- body: import_zod9.z.any()
838
- });
839
- var NormalizedResponseSchema = import_zod9.z.object({
840
- status: import_zod9.z.number(),
841
- body: import_zod9.z.any(),
842
- headers: import_zod9.z.record(import_zod9.z.string()).optional()
843
- });
844
- var HttpSourceResponseSchema = import_zod9.z.object({
845
- response: NormalizedResponseSchema,
846
- events: import_zod9.z.array(RawEventSchema)
847
- });
848
- var RegisterTriggerBodySchema = import_zod9.z.object({
849
- rule: EventRuleSchema,
850
- source: SourceMetadataSchema
851
- });
852
- var InitializeTriggerBodySchema = import_zod9.z.object({
853
- id: import_zod9.z.string(),
854
- params: import_zod9.z.any(),
855
- accountId: import_zod9.z.string().optional(),
856
- metadata: import_zod9.z.any().optional()
857
- });
858
- var RegisterCommonScheduleBodySchema = import_zod9.z.object({
859
- id: import_zod9.z.string(),
860
- metadata: import_zod9.z.any(),
861
- accountId: import_zod9.z.string().optional()
862
- });
863
- var RegisterIntervalScheduleBodySchema = RegisterCommonScheduleBodySchema.merge(IntervalMetadataSchema);
864
- var InitializeCronScheduleBodySchema = RegisterCommonScheduleBodySchema.merge(CronMetadataSchema);
865
- var RegisterScheduleBodySchema = import_zod9.z.discriminatedUnion("type", [
866
- RegisterIntervalScheduleBodySchema,
867
- InitializeCronScheduleBodySchema
868
- ]);
869
- var RegisterScheduleResponseBodySchema = import_zod9.z.object({
870
- id: import_zod9.z.string(),
871
- schedule: ScheduleMetadataSchema,
872
- metadata: import_zod9.z.any(),
873
- active: import_zod9.z.boolean()
874
- });
875
- var CreateExternalConnectionBodySchema = import_zod9.z.object({
876
- accessToken: import_zod9.z.string(),
877
- type: import_zod9.z.enum([
878
- "oauth2"
879
- ]),
880
- scopes: import_zod9.z.array(import_zod9.z.string()).optional(),
881
- metadata: import_zod9.z.any()
882
- });
883
-
884
- // ../core/src/schemas/notifications.ts
885
- var import_zod10 = require("zod");
886
- var MISSING_CONNECTION_NOTIFICATION = "dev.trigger.notifications.missingConnection";
887
- var MISSING_CONNECTION_RESOLVED_NOTIFICATION = "dev.trigger.notifications.missingConnectionResolved";
888
- var CommonMissingConnectionNotificationPayloadSchema = import_zod10.z.object({
889
- id: import_zod10.z.string(),
890
- client: import_zod10.z.object({
891
- id: import_zod10.z.string(),
892
- title: import_zod10.z.string(),
893
- scopes: import_zod10.z.array(import_zod10.z.string()),
894
- createdAt: import_zod10.z.coerce.date(),
895
- updatedAt: import_zod10.z.coerce.date()
896
- }),
897
- authorizationUrl: import_zod10.z.string()
898
- });
899
- var MissingDeveloperConnectionNotificationPayloadSchema = CommonMissingConnectionNotificationPayloadSchema.extend({
900
- type: import_zod10.z.literal("DEVELOPER")
901
- });
902
- var MissingExternalConnectionNotificationPayloadSchema = CommonMissingConnectionNotificationPayloadSchema.extend({
903
- type: import_zod10.z.literal("EXTERNAL"),
904
- account: import_zod10.z.object({
905
- id: import_zod10.z.string(),
906
- metadata: import_zod10.z.any()
907
- })
908
- });
909
- var MissingConnectionNotificationPayloadSchema = import_zod10.z.discriminatedUnion("type", [
910
- MissingDeveloperConnectionNotificationPayloadSchema,
911
- MissingExternalConnectionNotificationPayloadSchema
912
- ]);
913
- var CommonMissingConnectionNotificationResolvedPayloadSchema = import_zod10.z.object({
914
- id: import_zod10.z.string(),
915
- client: import_zod10.z.object({
916
- id: import_zod10.z.string(),
917
- title: import_zod10.z.string(),
918
- scopes: import_zod10.z.array(import_zod10.z.string()),
919
- createdAt: import_zod10.z.coerce.date(),
920
- updatedAt: import_zod10.z.coerce.date(),
921
- integrationIdentifier: import_zod10.z.string(),
922
- integrationAuthMethod: import_zod10.z.string()
923
- }),
924
- expiresAt: import_zod10.z.coerce.date()
925
- });
926
- var MissingDeveloperConnectionResolvedNotificationPayloadSchema = CommonMissingConnectionNotificationResolvedPayloadSchema.extend({
927
- type: import_zod10.z.literal("DEVELOPER")
928
- });
929
- var MissingExternalConnectionResolvedNotificationPayloadSchema = CommonMissingConnectionNotificationResolvedPayloadSchema.extend({
930
- type: import_zod10.z.literal("EXTERNAL"),
931
- account: import_zod10.z.object({
932
- id: import_zod10.z.string(),
933
- metadata: import_zod10.z.any()
934
- })
935
- });
936
- var MissingConnectionResolvedNotificationPayloadSchema = import_zod10.z.discriminatedUnion("type", [
937
- MissingDeveloperConnectionResolvedNotificationPayloadSchema,
938
- MissingExternalConnectionResolvedNotificationPayloadSchema
939
- ]);
940
-
941
- // ../core/src/schemas/events.ts
942
- var import_zod12 = require("zod");
943
-
944
- // ../core/src/schemas/runs.ts
945
- var import_zod11 = require("zod");
946
- var RunStatusSchema = import_zod11.z.union([
947
- import_zod11.z.literal("PENDING"),
948
- import_zod11.z.literal("QUEUED"),
949
- import_zod11.z.literal("WAITING_ON_CONNECTIONS"),
950
- import_zod11.z.literal("PREPROCESSING"),
951
- import_zod11.z.literal("STARTED"),
952
- import_zod11.z.literal("SUCCESS"),
953
- import_zod11.z.literal("FAILURE"),
954
- import_zod11.z.literal("TIMED_OUT"),
955
- import_zod11.z.literal("ABORTED"),
956
- import_zod11.z.literal("CANCELED")
957
- ]);
958
- var RunTaskSchema = import_zod11.z.object({
959
- id: import_zod11.z.string(),
960
- displayKey: import_zod11.z.string().nullable(),
961
- status: TaskStatusSchema,
962
- name: import_zod11.z.string(),
963
- icon: import_zod11.z.string().nullable(),
964
- startedAt: import_zod11.z.coerce.date().nullable(),
965
- completedAt: import_zod11.z.coerce.date().nullable()
966
- });
967
- var GetRunOptionsSchema = import_zod11.z.object({
968
- subtasks: import_zod11.z.boolean().optional(),
969
- cursor: import_zod11.z.string().optional(),
970
- take: import_zod11.z.number().optional()
971
- });
972
- var GetRunOptionsWithTaskDetailsSchema = GetRunOptionsSchema.extend({
973
- taskdetails: import_zod11.z.boolean().optional()
974
- });
975
- var RunSchema = import_zod11.z.object({
976
- id: import_zod11.z.string(),
977
- status: RunStatusSchema,
978
- startedAt: import_zod11.z.coerce.date().nullable(),
979
- updatedAt: import_zod11.z.coerce.date().nullable(),
980
- completedAt: import_zod11.z.coerce.date().nullable()
981
- });
982
- var GetRunSchema = RunSchema.extend({
983
- output: import_zod11.z.any().optional(),
984
- tasks: import_zod11.z.array(RunTaskSchema),
985
- nextCursor: import_zod11.z.string().optional()
986
- });
987
- var GetRunsOptionsSchema = import_zod11.z.object({
988
- cursor: import_zod11.z.string().optional(),
989
- take: import_zod11.z.number().optional()
990
- });
991
- var GetRunsSchema = import_zod11.z.object({
992
- runs: RunSchema.array(),
993
- nextCursor: import_zod11.z.string().optional()
994
- });
995
-
996
- // ../core/src/schemas/events.ts
997
- var GetEventSchema = import_zod12.z.object({
998
- id: import_zod12.z.string(),
999
- name: import_zod12.z.string(),
1000
- createdAt: import_zod12.z.coerce.date(),
1001
- updatedAt: import_zod12.z.coerce.date(),
1002
- runs: import_zod12.z.array(import_zod12.z.object({
1003
- id: import_zod12.z.string(),
1004
- status: RunStatusSchema,
1005
- startedAt: import_zod12.z.coerce.date().optional().nullable(),
1006
- completedAt: import_zod12.z.coerce.date().optional().nullable()
1007
- }))
1008
- });
1009
-
1010
- // ../core/src/utils.ts
1011
- function deepMergeFilters(...filters) {
1012
- const result = {};
1013
- for (const filter of filters) {
1014
- for (const key in filter) {
1015
- if (filter.hasOwnProperty(key)) {
1016
- const filterValue = filter[key];
1017
- const existingValue = result[key];
1018
- if (existingValue && typeof existingValue === "object" && typeof filterValue === "object" && !Array.isArray(existingValue) && !Array.isArray(filterValue) && existingValue !== null && filterValue !== null) {
1019
- result[key] = deepMergeFilters(existingValue, filterValue);
1020
- } else {
1021
- result[key] = filterValue;
1022
- }
1023
- }
1024
- }
1025
- }
1026
- return result;
1027
- }
1028
- __name(deepMergeFilters, "deepMergeFilters");
1029
-
1030
- // ../core/src/retry.ts
1031
- var DEFAULT_RETRY_OPTIONS = {
1032
- limit: 5,
1033
- factor: 1.8,
1034
- minTimeoutInMs: 1e3,
1035
- maxTimeoutInMs: 6e4,
1036
- randomize: true
1037
- };
1038
- function calculateRetryAt(retryOptions, attempts) {
1039
- const options = {
1040
- ...DEFAULT_RETRY_OPTIONS,
1041
- ...retryOptions
1042
- };
1043
- const retryCount = attempts + 1;
1044
- if (retryCount >= options.limit) {
1045
- return;
1046
- }
1047
- const random = options.randomize ? Math.random() + 1 : 1;
1048
- let timeoutInMs = Math.round(random * Math.max(options.minTimeoutInMs, 1) * Math.pow(options.factor, Math.max(attempts - 1, 0)));
1049
- timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);
1050
- return new Date(Date.now() + timeoutInMs);
1051
- }
1052
- __name(calculateRetryAt, "calculateRetryAt");
1053
-
1054
- // ../core/src/replacements.ts
1055
- var currentDate = {
1056
- marker: "__CURRENT_DATE__",
1057
- replace({ data: { now } }) {
1058
- return now.toISOString();
1059
- }
1060
- };
1061
-
1062
- // ../core/src/searchParams.ts
1063
- function urlWithSearchParams(url, params) {
1064
- if (!params) {
1065
- return url;
1066
- }
1067
- const urlObj = new URL(url);
1068
- for (const [key, value] of Object.entries(params)) {
1069
- urlObj.searchParams.append(key, String(value));
1070
- }
1071
- return urlObj.toString();
1072
- }
1073
- __name(urlWithSearchParams, "urlWithSearchParams");
149
+ // src/triggerClient.ts
150
+ var import_core5 = require("@trigger.dev/core");
1074
151
 
1075
152
  // src/apiClient.ts
153
+ var import_core = require("@trigger.dev/core");
1076
154
  var import_node_fetch = __toESM(require("node-fetch"));
1077
- var import_zod13 = require("zod");
155
+ var import_zod = require("zod");
1078
156
  var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
1079
157
  var ApiClient = class {
1080
158
  constructor(options) {
@@ -1084,7 +162,7 @@ var ApiClient = class {
1084
162
  __privateAdd(this, _logger, void 0);
1085
163
  __privateSet(this, _options, options);
1086
164
  __privateSet(this, _apiUrl, __privateGet(this, _options).apiUrl ?? process.env.TRIGGER_API_URL ?? "https://api.trigger.dev");
1087
- __privateSet(this, _logger, new Logger("trigger.dev", __privateGet(this, _options).logLevel));
165
+ __privateSet(this, _logger, new import_core.Logger("trigger.dev", __privateGet(this, _options).logLevel));
1088
166
  }
1089
167
  async registerEndpoint(options) {
1090
168
  const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
@@ -1117,7 +195,7 @@ var ApiClient = class {
1117
195
  __privateGet(this, _logger).debug("Creating run", {
1118
196
  params
1119
197
  });
1120
- return await zodfetch(CreateRunResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/runs`, {
198
+ return await zodfetch(import_core.CreateRunResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/runs`, {
1121
199
  method: "POST",
1122
200
  headers: {
1123
201
  "Content-Type": "application/json",
@@ -1131,7 +209,7 @@ var ApiClient = class {
1131
209
  __privateGet(this, _logger).debug("Running Task", {
1132
210
  task
1133
211
  });
1134
- return await zodfetch(ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks`, {
212
+ return await zodfetch(import_core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks`, {
1135
213
  method: "POST",
1136
214
  headers: {
1137
215
  "Content-Type": "application/json",
@@ -1146,7 +224,7 @@ var ApiClient = class {
1146
224
  __privateGet(this, _logger).debug("Complete Task", {
1147
225
  task
1148
226
  });
1149
- return await zodfetch(ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/complete`, {
227
+ return await zodfetch(import_core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/complete`, {
1150
228
  method: "POST",
1151
229
  headers: {
1152
230
  "Content-Type": "application/json",
@@ -1162,7 +240,7 @@ var ApiClient = class {
1162
240
  runId,
1163
241
  body
1164
242
  });
1165
- return await zodfetch(ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/fail`, {
243
+ return await zodfetch(import_core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/fail`, {
1166
244
  method: "POST",
1167
245
  headers: {
1168
246
  "Content-Type": "application/json",
@@ -1176,7 +254,7 @@ var ApiClient = class {
1176
254
  __privateGet(this, _logger).debug("Sending event", {
1177
255
  event
1178
256
  });
1179
- return await zodfetch(ApiEventLogSchema, `${__privateGet(this, _apiUrl)}/api/v1/events`, {
257
+ return await zodfetch(import_core.ApiEventLogSchema, `${__privateGet(this, _apiUrl)}/api/v1/events`, {
1180
258
  method: "POST",
1181
259
  headers: {
1182
260
  "Content-Type": "application/json",
@@ -1193,7 +271,7 @@ var ApiClient = class {
1193
271
  __privateGet(this, _logger).debug("activating http source", {
1194
272
  source
1195
273
  });
1196
- const response = await zodfetch(TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/sources/${key}`, {
274
+ const response = await zodfetch(import_core.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/sources/${key}`, {
1197
275
  method: "PUT",
1198
276
  headers: {
1199
277
  "Content-Type": "application/json",
@@ -1209,7 +287,7 @@ var ApiClient = class {
1209
287
  id,
1210
288
  payload
1211
289
  });
1212
- const response = await zodfetch(RegisterSourceEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/triggers/${id}/registrations/${key}`, {
290
+ const response = await zodfetch(import_core.RegisterSourceEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/triggers/${id}/registrations/${key}`, {
1213
291
  method: "PUT",
1214
292
  headers: {
1215
293
  "Content-Type": "application/json",
@@ -1225,7 +303,7 @@ var ApiClient = class {
1225
303
  id,
1226
304
  payload
1227
305
  });
1228
- const response = await zodfetch(RegisterScheduleResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations`, {
306
+ const response = await zodfetch(import_core.RegisterScheduleResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations`, {
1229
307
  method: "POST",
1230
308
  headers: {
1231
309
  "Content-Type": "application/json",
@@ -1243,8 +321,8 @@ var ApiClient = class {
1243
321
  __privateGet(this, _logger).debug("unregistering schedule", {
1244
322
  id
1245
323
  });
1246
- const response = await zodfetch(import_zod13.z.object({
1247
- ok: import_zod13.z.boolean()
324
+ const response = await zodfetch(import_zod.z.object({
325
+ ok: import_zod.z.boolean()
1248
326
  }), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
1249
327
  method: "DELETE",
1250
328
  headers: {
@@ -1259,7 +337,7 @@ var ApiClient = class {
1259
337
  __privateGet(this, _logger).debug("getting auth", {
1260
338
  id
1261
339
  });
1262
- const response = await zodfetch(ConnectionAuthSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/auth/${id}`, {
340
+ const response = await zodfetch(import_core.ConnectionAuthSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/auth/${id}`, {
1263
341
  method: "GET",
1264
342
  headers: {
1265
343
  Accept: "application/json",
@@ -1275,7 +353,7 @@ var ApiClient = class {
1275
353
  __privateGet(this, _logger).debug("Getting Event", {
1276
354
  eventId
1277
355
  });
1278
- return await zodfetch(GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
356
+ return await zodfetch(import_core.GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
1279
357
  method: "GET",
1280
358
  headers: {
1281
359
  Authorization: `Bearer ${apiKey}`
@@ -1287,7 +365,7 @@ var ApiClient = class {
1287
365
  __privateGet(this, _logger).debug("Getting Run", {
1288
366
  runId
1289
367
  });
1290
- return await zodfetch(GetRunSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
368
+ return await zodfetch(import_core.GetRunSchema, (0, import_core.urlWithSearchParams)(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
1291
369
  method: "GET",
1292
370
  headers: {
1293
371
  Authorization: `Bearer ${apiKey}`
@@ -1299,7 +377,7 @@ var ApiClient = class {
1299
377
  __privateGet(this, _logger).debug("Getting Runs", {
1300
378
  jobSlug
1301
379
  });
1302
- return await zodfetch(GetRunsSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
380
+ return await zodfetch(import_core.GetRunsSchema, (0, import_core.urlWithSearchParams)(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
1303
381
  method: "GET",
1304
382
  headers: {
1305
383
  Authorization: `Bearer ${apiKey}`
@@ -1385,6 +463,7 @@ function isTriggerError(err) {
1385
463
  __name(isTriggerError, "isTriggerError");
1386
464
 
1387
465
  // src/io.ts
466
+ var import_core3 = require("@trigger.dev/core");
1388
467
  var import_node_async_hooks = require("async_hooks");
1389
468
  var import_node_crypto = require("crypto");
1390
469
 
@@ -1450,6 +529,9 @@ function createIOWithIntegrations(io, auths, integrations) {
1450
529
  }
1451
530
  __name(createIOWithIntegrations, "createIOWithIntegrations");
1452
531
 
532
+ // src/retry.ts
533
+ var import_core2 = require("@trigger.dev/core");
534
+
1453
535
  // src/io.ts
1454
536
  var _addToCachedTasks, addToCachedTasks_fn;
1455
537
  var IO = class {
@@ -1458,7 +540,7 @@ var IO = class {
1458
540
  this._id = options.id;
1459
541
  this._apiClient = options.apiClient;
1460
542
  this._triggerClient = options.client;
1461
- this._logger = options.logger ?? new Logger("trigger.dev", options.logLevel);
543
+ this._logger = options.logger ?? new import_core3.Logger("trigger.dev", options.logLevel);
1462
544
  this._cachedTasks = /* @__PURE__ */ new Map();
1463
545
  this._jobLogger = options.jobLogger;
1464
546
  this._jobLogLevel = options.jobLogLevel;
@@ -1500,7 +582,7 @@ var IO = class {
1500
582
  break;
1501
583
  }
1502
584
  }
1503
- if (Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
585
+ if (import_core3.Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
1504
586
  await this.runTask([
1505
587
  message,
1506
588
  level
@@ -1839,7 +921,7 @@ var IO = class {
1839
921
  if (onErrorResult instanceof Error) {
1840
922
  error = onErrorResult;
1841
923
  } else {
1842
- const parsedError2 = ErrorWithStackSchema.safeParse(onErrorResult.error);
924
+ const parsedError2 = import_core3.ErrorWithStackSchema.safeParse(onErrorResult.error);
1843
925
  throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
1844
926
  message: "Unknown error"
1845
927
  }, task, onErrorResult.retryAt);
@@ -1852,9 +934,9 @@ var IO = class {
1852
934
  error = innerError;
1853
935
  }
1854
936
  }
1855
- const parsedError = ErrorWithStackSchema.safeParse(error);
937
+ const parsedError = import_core3.ErrorWithStackSchema.safeParse(error);
1856
938
  if (options.retry) {
1857
- const retryAt = calculateRetryAt(options.retry, task.attempts - 1);
939
+ const retryAt = (0, import_core2.calculateRetryAt)(options.retry, task.attempts - 1);
1858
940
  if (retryAt) {
1859
941
  throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
1860
942
  message: "Unknown error"
@@ -1951,6 +1033,7 @@ var IOLogger = class {
1951
1033
  __name(IOLogger, "IOLogger");
1952
1034
 
1953
1035
  // src/triggers/eventTrigger.ts
1036
+ var import_core4 = require("@trigger.dev/core");
1954
1037
  var _options2;
1955
1038
  var EventTrigger = class {
1956
1039
  constructor(options) {
@@ -1964,7 +1047,7 @@ var EventTrigger = class {
1964
1047
  rule: {
1965
1048
  event: __privateGet(this, _options2).name ?? __privateGet(this, _options2).event.name,
1966
1049
  source: __privateGet(this, _options2).source ?? "trigger.dev",
1967
- payload: deepMergeFilters(__privateGet(this, _options2).filter ?? {}, __privateGet(this, _options2).event.filter ?? {})
1050
+ payload: (0, import_core4.deepMergeFilters)(__privateGet(this, _options2).filter ?? {}, __privateGet(this, _options2).event.filter ?? {})
1968
1051
  }
1969
1052
  };
1970
1053
  }
@@ -2002,11 +1085,11 @@ __name(eventTrigger, "eventTrigger");
2002
1085
 
2003
1086
  // src/triggerClient.ts
2004
1087
  var registerSourceEvent = {
2005
- name: REGISTER_SOURCE_EVENT,
1088
+ name: import_core5.REGISTER_SOURCE_EVENT,
2006
1089
  title: "Register Source",
2007
1090
  source: "internal",
2008
1091
  icon: "register-source",
2009
- parsePayload: RegisterSourceEventSchema.parse
1092
+ parsePayload: import_core5.RegisterSourceEventSchema.parse
2010
1093
  };
2011
1094
  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;
2012
1095
  var TriggerClient = class {
@@ -2028,7 +1111,7 @@ var TriggerClient = class {
2028
1111
  this.id = options.id;
2029
1112
  __privateSet(this, _options3, options);
2030
1113
  __privateSet(this, _client, new ApiClient(__privateGet(this, _options3)));
2031
- __privateSet(this, _internalLogger, new Logger("trigger.dev", __privateGet(this, _options3).verbose ? "debug" : "log"));
1114
+ __privateSet(this, _internalLogger, new import_core5.Logger("trigger.dev", __privateGet(this, _options3).verbose ? "debug" : "log"));
2032
1115
  }
2033
1116
  async handleRequest(request) {
2034
1117
  __privateGet(this, _internalLogger).debug("handling request", {
@@ -2152,7 +1235,7 @@ var TriggerClient = class {
2152
1235
  }
2153
1236
  case "INITIALIZE_TRIGGER": {
2154
1237
  const json = await request.json();
2155
- const body = InitializeTriggerBodySchema.safeParse(json);
1238
+ const body = import_core5.InitializeTriggerBodySchema.safeParse(json);
2156
1239
  if (!body.success) {
2157
1240
  return {
2158
1241
  status: 400,
@@ -2177,7 +1260,7 @@ var TriggerClient = class {
2177
1260
  }
2178
1261
  case "EXECUTE_JOB": {
2179
1262
  const json = await request.json();
2180
- const execution = RunJobBodySchema.safeParse(json);
1263
+ const execution = import_core5.RunJobBodySchema.safeParse(json);
2181
1264
  if (!execution.success) {
2182
1265
  return {
2183
1266
  status: 400,
@@ -2203,7 +1286,7 @@ var TriggerClient = class {
2203
1286
  }
2204
1287
  case "PREPROCESS_RUN": {
2205
1288
  const json = await request.json();
2206
- const body = PreprocessRunBodySchema.safeParse(json);
1289
+ const body = import_core5.PreprocessRunBodySchema.safeParse(json);
2207
1290
  if (!body.success) {
2208
1291
  return {
2209
1292
  status: 400,
@@ -2231,7 +1314,7 @@ var TriggerClient = class {
2231
1314
  };
2232
1315
  }
2233
1316
  case "DELIVER_HTTP_SOURCE_REQUEST": {
2234
- const headers = HttpSourceRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
1317
+ const headers = import_core5.HttpSourceRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
2235
1318
  if (!headers.success) {
2236
1319
  return {
2237
1320
  status: 400,
@@ -2475,7 +1558,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2475
1558
  client: this,
2476
1559
  context,
2477
1560
  jobLogLevel: job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info",
2478
- jobLogger: __privateGet(this, _options3).ioLogLocalEnabled ? new Logger(job1.id, job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info") : void 0
1561
+ jobLogger: __privateGet(this, _options3).ioLogLocalEnabled ? new import_core5.Logger(job1.id, job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info") : void 0
2479
1562
  });
2480
1563
  const ioWithConnections = createIOWithIntegrations(io, body1.connections, job1.options.integrations);
2481
1564
  try {
@@ -2506,7 +1589,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2506
1589
  };
2507
1590
  }
2508
1591
  if (error instanceof RetryWithTaskError) {
2509
- const errorWithStack2 = ErrorWithStackSchema.safeParse(error.cause);
1592
+ const errorWithStack2 = import_core5.ErrorWithStackSchema.safeParse(error.cause);
2510
1593
  if (errorWithStack2.success) {
2511
1594
  return {
2512
1595
  status: "ERROR",
@@ -2522,7 +1605,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2522
1605
  task: error.task
2523
1606
  };
2524
1607
  }
2525
- const errorWithStack = ErrorWithStackSchema.safeParse(error);
1608
+ const errorWithStack = import_core5.ErrorWithStackSchema.safeParse(error);
2526
1609
  if (errorWithStack.success) {
2527
1610
  return {
2528
1611
  status: "ERROR",
@@ -2664,6 +1747,7 @@ function authenticatedTask(options) {
2664
1747
  __name(authenticatedTask, "authenticatedTask");
2665
1748
 
2666
1749
  // src/triggers/externalSource.ts
1750
+ var import_core6 = require("@trigger.dev/core");
2667
1751
  var ExternalSource = class {
2668
1752
  constructor(channel, options) {
2669
1753
  this.options = options;
@@ -2737,7 +1821,7 @@ var ExternalSourceTrigger = class {
2737
1821
  title: "External Source",
2738
1822
  rule: {
2739
1823
  event: this.event.name,
2740
- payload: deepMergeFilters(this.options.source.filter(this.options.params), this.event.filter ?? {}, this.options.params.filter ?? {}),
1824
+ payload: (0, import_core6.deepMergeFilters)(this.options.source.filter(this.options.params), this.event.filter ?? {}, this.options.params.filter ?? {}),
2741
1825
  source: this.event.source
2742
1826
  },
2743
1827
  properties: this.options.source.properties(this.options.params)
@@ -2771,6 +1855,7 @@ function omit(obj, key) {
2771
1855
  __name(omit, "omit");
2772
1856
 
2773
1857
  // src/triggers/dynamic.ts
1858
+ var import_core7 = require("@trigger.dev/core");
2774
1859
  var _client2, _options4;
2775
1860
  var DynamicTrigger = class {
2776
1861
  constructor(client, options) {
@@ -2799,7 +1884,7 @@ var DynamicTrigger = class {
2799
1884
  rule: {
2800
1885
  event: this.event.name,
2801
1886
  source: this.event.source,
2802
- payload: deepMergeFilters(this.source.filter(params), this.event.filter ?? {})
1887
+ payload: (0, import_core7.deepMergeFilters)(this.source.filter(params), this.event.filter ?? {})
2803
1888
  },
2804
1889
  source: {
2805
1890
  key,
@@ -2831,6 +1916,7 @@ _client2 = new WeakMap();
2831
1916
  _options4 = new WeakMap();
2832
1917
 
2833
1918
  // src/triggers/scheduled.ts
1919
+ var import_core8 = require("@trigger.dev/core");
2834
1920
  var import_cronstrue = __toESM(require("cronstrue"));
2835
1921
  var examples = [
2836
1922
  {
@@ -2838,8 +1924,8 @@ var examples = [
2838
1924
  name: "Now",
2839
1925
  icon: "clock",
2840
1926
  payload: {
2841
- ts: currentDate.marker,
2842
- lastTimestamp: currentDate.marker
1927
+ ts: import_core8.currentDate.marker,
1928
+ lastTimestamp: import_core8.currentDate.marker
2843
1929
  }
2844
1930
  }
2845
1931
  ];
@@ -2854,7 +1940,7 @@ var IntervalTrigger = class {
2854
1940
  source: "trigger.dev",
2855
1941
  icon: "schedule-interval",
2856
1942
  examples,
2857
- parsePayload: ScheduledPayloadSchema.parse,
1943
+ parsePayload: import_core8.ScheduledPayloadSchema.parse,
2858
1944
  properties: [
2859
1945
  {
2860
1946
  label: "Interval",
@@ -2899,7 +1985,7 @@ var CronTrigger = class {
2899
1985
  source: "trigger.dev",
2900
1986
  icon: "schedule-cron",
2901
1987
  examples,
2902
- parsePayload: ScheduledPayloadSchema.parse,
1988
+ parsePayload: import_core8.ScheduledPayloadSchema.parse,
2903
1989
  properties: [
2904
1990
  {
2905
1991
  label: "cron",
@@ -2949,7 +2035,7 @@ var DynamicSchedule = class {
2949
2035
  source: "trigger.dev",
2950
2036
  icon: "schedule-dynamic",
2951
2037
  examples,
2952
- parsePayload: ScheduledPayloadSchema.parse
2038
+ parsePayload: import_core8.ScheduledPayloadSchema.parse
2953
2039
  };
2954
2040
  }
2955
2041
  async register(key, metadata) {
@@ -2974,6 +2060,7 @@ var DynamicSchedule = class {
2974
2060
  __name(DynamicSchedule, "DynamicSchedule");
2975
2061
 
2976
2062
  // src/triggers/notifications.ts
2063
+ var import_core9 = require("@trigger.dev/core");
2977
2064
  function missingConnectionNotification(integrations) {
2978
2065
  return new MissingConnectionNotification({
2979
2066
  integrations
@@ -2992,11 +2079,11 @@ var MissingConnectionNotification = class {
2992
2079
  }
2993
2080
  get event() {
2994
2081
  return {
2995
- name: MISSING_CONNECTION_NOTIFICATION,
2082
+ name: import_core9.MISSING_CONNECTION_NOTIFICATION,
2996
2083
  title: "Missing Connection Notification",
2997
2084
  source: "trigger.dev",
2998
2085
  icon: "connection-alert",
2999
- parsePayload: MissingConnectionNotificationPayloadSchema.parse,
2086
+ parsePayload: import_core9.MissingConnectionNotificationPayloadSchema.parse,
3000
2087
  properties: [
3001
2088
  {
3002
2089
  label: "Integrations",
@@ -3033,11 +2120,11 @@ var MissingConnectionResolvedNotification = class {
3033
2120
  }
3034
2121
  get event() {
3035
2122
  return {
3036
- name: MISSING_CONNECTION_RESOLVED_NOTIFICATION,
2123
+ name: import_core9.MISSING_CONNECTION_RESOLVED_NOTIFICATION,
3037
2124
  title: "Missing Connection Resolved Notification",
3038
2125
  source: "trigger.dev",
3039
2126
  icon: "connection-alert",
3040
- parsePayload: MissingConnectionResolvedNotificationPayloadSchema.parse,
2127
+ parsePayload: import_core9.MissingConnectionResolvedNotificationPayloadSchema.parse,
3041
2128
  properties: [
3042
2129
  {
3043
2130
  label: "Integrations",