@trigger.dev/core 0.0.5

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 ADDED
@@ -0,0 +1,1260 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __accessCheck = (obj, member, msg) => {
21
+ if (!member.has(obj))
22
+ throw TypeError("Cannot " + msg);
23
+ };
24
+ var __privateGet = (obj, member, getter) => {
25
+ __accessCheck(obj, member, "read from private field");
26
+ return getter ? getter.call(obj) : member.get(obj);
27
+ };
28
+ var __privateAdd = (obj, member, value) => {
29
+ if (member.has(obj))
30
+ throw TypeError("Cannot add the same private member more than once");
31
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
32
+ };
33
+ var __privateSet = (obj, member, value, setter) => {
34
+ __accessCheck(obj, member, "write to private field");
35
+ setter ? setter.call(obj, value) : member.set(obj, value);
36
+ return value;
37
+ };
38
+ var __privateMethod = (obj, member, method) => {
39
+ __accessCheck(obj, member, "access private method");
40
+ return method;
41
+ };
42
+
43
+ // src/index.ts
44
+ var src_exports = {};
45
+ __export(src_exports, {
46
+ ApiEventLogSchema: () => ApiEventLogSchema,
47
+ CachedTaskSchema: () => CachedTaskSchema,
48
+ CommonMissingConnectionNotificationPayloadSchema: () => CommonMissingConnectionNotificationPayloadSchema,
49
+ CommonMissingConnectionNotificationResolvedPayloadSchema: () => CommonMissingConnectionNotificationResolvedPayloadSchema,
50
+ CompleteTaskBodyInputSchema: () => CompleteTaskBodyInputSchema,
51
+ ConnectionAuthSchema: () => ConnectionAuthSchema,
52
+ CreateExternalConnectionBodySchema: () => CreateExternalConnectionBodySchema,
53
+ CreateRunBodySchema: () => CreateRunBodySchema,
54
+ CreateRunResponseBodySchema: () => CreateRunResponseBodySchema,
55
+ CronMetadataSchema: () => CronMetadataSchema,
56
+ CronOptionsSchema: () => CronOptionsSchema,
57
+ DeliverEventResponseSchema: () => DeliverEventResponseSchema,
58
+ DeserializedJsonSchema: () => DeserializedJsonSchema,
59
+ DisplayPropertiesSchema: () => DisplayPropertiesSchema,
60
+ DisplayPropertySchema: () => DisplayPropertySchema,
61
+ DynamicTriggerEndpointMetadataSchema: () => DynamicTriggerEndpointMetadataSchema,
62
+ DynamicTriggerMetadataSchema: () => DynamicTriggerMetadataSchema,
63
+ ErrorWithStackSchema: () => ErrorWithStackSchema,
64
+ EventExampleSchema: () => EventExampleSchema,
65
+ EventFilterSchema: () => EventFilterSchema,
66
+ EventRuleSchema: () => EventRuleSchema,
67
+ EventSpecificationSchema: () => EventSpecificationSchema,
68
+ FailTaskBodyInputSchema: () => FailTaskBodyInputSchema,
69
+ FetchOperationSchema: () => FetchOperationSchema,
70
+ FetchRequestInitSchema: () => FetchRequestInitSchema,
71
+ FetchRetryBackoffStrategySchema: () => FetchRetryBackoffStrategySchema,
72
+ FetchRetryHeadersStrategySchema: () => FetchRetryHeadersStrategySchema,
73
+ FetchRetryOptionsSchema: () => FetchRetryOptionsSchema,
74
+ FetchRetryStrategySchema: () => FetchRetryStrategySchema,
75
+ GetEventSchema: () => GetEventSchema,
76
+ GetRunSchema: () => GetRunSchema,
77
+ GetRunsSchema: () => GetRunsSchema,
78
+ HandleTriggerSourceSchema: () => HandleTriggerSourceSchema,
79
+ HttpEventSourceSchema: () => HttpEventSourceSchema,
80
+ HttpSourceRequestHeadersSchema: () => HttpSourceRequestHeadersSchema,
81
+ HttpSourceRequestSchema: () => HttpSourceRequestSchema,
82
+ HttpSourceResponseSchema: () => HttpSourceResponseSchema,
83
+ IndexEndpointResponseSchema: () => IndexEndpointResponseSchema,
84
+ InitializeCronScheduleBodySchema: () => InitializeCronScheduleBodySchema,
85
+ InitializeTriggerBodySchema: () => InitializeTriggerBodySchema,
86
+ IntegrationConfigSchema: () => IntegrationConfigSchema,
87
+ IntegrationMetadataSchema: () => IntegrationMetadataSchema,
88
+ IntervalMetadataSchema: () => IntervalMetadataSchema,
89
+ IntervalOptionsSchema: () => IntervalOptionsSchema,
90
+ JobMetadataSchema: () => JobMetadataSchema,
91
+ LogMessageSchema: () => LogMessageSchema,
92
+ Logger: () => Logger,
93
+ MISSING_CONNECTION_NOTIFICATION: () => MISSING_CONNECTION_NOTIFICATION,
94
+ MISSING_CONNECTION_RESOLVED_NOTIFICATION: () => MISSING_CONNECTION_RESOLVED_NOTIFICATION,
95
+ MissingConnectionNotificationPayloadSchema: () => MissingConnectionNotificationPayloadSchema,
96
+ MissingConnectionResolvedNotificationPayloadSchema: () => MissingConnectionResolvedNotificationPayloadSchema,
97
+ MissingDeveloperConnectionNotificationPayloadSchema: () => MissingDeveloperConnectionNotificationPayloadSchema,
98
+ MissingDeveloperConnectionResolvedNotificationPayloadSchema: () => MissingDeveloperConnectionResolvedNotificationPayloadSchema,
99
+ MissingExternalConnectionNotificationPayloadSchema: () => MissingExternalConnectionNotificationPayloadSchema,
100
+ MissingExternalConnectionResolvedNotificationPayloadSchema: () => MissingExternalConnectionResolvedNotificationPayloadSchema,
101
+ NormalizedRequestSchema: () => NormalizedRequestSchema,
102
+ NormalizedResponseSchema: () => NormalizedResponseSchema,
103
+ PongErrorResponseSchema: () => PongErrorResponseSchema,
104
+ PongResponseSchema: () => PongResponseSchema,
105
+ PongSuccessResponseSchema: () => PongSuccessResponseSchema,
106
+ PreprocessRunBodySchema: () => PreprocessRunBodySchema,
107
+ PreprocessRunResponseSchema: () => PreprocessRunResponseSchema,
108
+ QueueOptionsSchema: () => QueueOptionsSchema,
109
+ REGISTER_SOURCE_EVENT: () => REGISTER_SOURCE_EVENT,
110
+ RawEventSchema: () => RawEventSchema,
111
+ RedactSchema: () => RedactSchema,
112
+ RedactStringSchema: () => RedactStringSchema,
113
+ RegisterDynamicSchedulePayloadSchema: () => RegisterDynamicSchedulePayloadSchema,
114
+ RegisterHTTPTriggerSourceBodySchema: () => RegisterHTTPTriggerSourceBodySchema,
115
+ RegisterIntervalScheduleBodySchema: () => RegisterIntervalScheduleBodySchema,
116
+ RegisterSMTPTriggerSourceBodySchema: () => RegisterSMTPTriggerSourceBodySchema,
117
+ RegisterSQSTriggerSourceBodySchema: () => RegisterSQSTriggerSourceBodySchema,
118
+ RegisterScheduleBodySchema: () => RegisterScheduleBodySchema,
119
+ RegisterScheduleResponseBodySchema: () => RegisterScheduleResponseBodySchema,
120
+ RegisterSourceChannelBodySchema: () => RegisterSourceChannelBodySchema,
121
+ RegisterSourceEventSchema: () => RegisterSourceEventSchema,
122
+ RegisterTriggerBodySchema: () => RegisterTriggerBodySchema,
123
+ RegisterTriggerSourceSchema: () => RegisterTriggerSourceSchema,
124
+ RetryOptionsSchema: () => RetryOptionsSchema,
125
+ RunJobBodySchema: () => RunJobBodySchema,
126
+ RunJobCanceledWithTaskSchema: () => RunJobCanceledWithTaskSchema,
127
+ RunJobErrorSchema: () => RunJobErrorSchema,
128
+ RunJobResponseSchema: () => RunJobResponseSchema,
129
+ RunJobResumeWithTaskSchema: () => RunJobResumeWithTaskSchema,
130
+ RunJobRetryWithTaskSchema: () => RunJobRetryWithTaskSchema,
131
+ RunJobSuccessSchema: () => RunJobSuccessSchema,
132
+ RunSourceContextSchema: () => RunSourceContextSchema,
133
+ RunStatusSchema: () => RunStatusSchema,
134
+ RunTaskBodyInputSchema: () => RunTaskBodyInputSchema,
135
+ RunTaskBodyOutputSchema: () => RunTaskBodyOutputSchema,
136
+ RunTaskOptionsSchema: () => RunTaskOptionsSchema,
137
+ RunTaskSchema: () => RunTaskSchema,
138
+ RuntimeEnvironmentTypeSchema: () => RuntimeEnvironmentTypeSchema,
139
+ SCHEDULED_EVENT: () => SCHEDULED_EVENT,
140
+ ScheduleMetadataSchema: () => ScheduleMetadataSchema,
141
+ ScheduledPayloadSchema: () => ScheduledPayloadSchema,
142
+ ScheduledTriggerMetadataSchema: () => ScheduledTriggerMetadataSchema,
143
+ SendEventBodySchema: () => SendEventBodySchema,
144
+ SendEventOptionsSchema: () => SendEventOptionsSchema,
145
+ SerializableJsonSchema: () => SerializableJsonSchema,
146
+ ServerTaskSchema: () => ServerTaskSchema,
147
+ SourceMetadataSchema: () => SourceMetadataSchema,
148
+ StaticTriggerMetadataSchema: () => StaticTriggerMetadataSchema,
149
+ StyleSchema: () => StyleSchema,
150
+ TaskSchema: () => TaskSchema,
151
+ TaskStatusSchema: () => TaskStatusSchema,
152
+ TriggerMetadataSchema: () => TriggerMetadataSchema,
153
+ TriggerSourceSchema: () => TriggerSourceSchema,
154
+ UpdateTriggerSourceBodySchema: () => UpdateTriggerSourceBodySchema,
155
+ calculateRetryAt: () => calculateRetryAt,
156
+ currentDate: () => currentDate,
157
+ currentTimestampMilliseconds: () => currentTimestampMilliseconds,
158
+ currentTimestampSeconds: () => currentTimestampSeconds,
159
+ deepMergeFilters: () => deepMergeFilters,
160
+ replacements: () => replacements,
161
+ urlWithSearchParams: () => urlWithSearchParams
162
+ });
163
+ module.exports = __toCommonJS(src_exports);
164
+
165
+ // src/logger.ts
166
+ var logLevels = [
167
+ "log",
168
+ "error",
169
+ "warn",
170
+ "info",
171
+ "debug"
172
+ ];
173
+ var _name, _level, _filteredKeys, _jsonReplacer, _structuredLog, structuredLog_fn;
174
+ var _Logger = class _Logger {
175
+ constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
176
+ __privateAdd(this, _structuredLog);
177
+ __privateAdd(this, _name, void 0);
178
+ __privateAdd(this, _level, void 0);
179
+ __privateAdd(this, _filteredKeys, []);
180
+ __privateAdd(this, _jsonReplacer, void 0);
181
+ __privateSet(this, _name, name);
182
+ __privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
183
+ __privateSet(this, _filteredKeys, filteredKeys);
184
+ __privateSet(this, _jsonReplacer, jsonReplacer);
185
+ }
186
+ // Return a new Logger instance with the same name and a new log level
187
+ // but filter out the keys from the log messages (at any level)
188
+ filter(...keys) {
189
+ return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
190
+ }
191
+ static satisfiesLogLevel(logLevel, setLevel) {
192
+ return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
193
+ }
194
+ log(message, ...args) {
195
+ if (__privateGet(this, _level) < 0)
196
+ return;
197
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.log, message, ...args);
198
+ }
199
+ error(message, ...args) {
200
+ if (__privateGet(this, _level) < 1)
201
+ return;
202
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.error, message, ...args);
203
+ }
204
+ warn(message, ...args) {
205
+ if (__privateGet(this, _level) < 2)
206
+ return;
207
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.warn, message, ...args);
208
+ }
209
+ info(message, ...args) {
210
+ if (__privateGet(this, _level) < 3)
211
+ return;
212
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.info, message, ...args);
213
+ }
214
+ debug(message, ...args) {
215
+ if (__privateGet(this, _level) < 4)
216
+ return;
217
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.debug, message, ...args);
218
+ }
219
+ };
220
+ _name = new WeakMap();
221
+ _level = new WeakMap();
222
+ _filteredKeys = new WeakMap();
223
+ _jsonReplacer = new WeakMap();
224
+ _structuredLog = new WeakSet();
225
+ structuredLog_fn = /* @__PURE__ */ __name(function(loggerFunction, message, ...args) {
226
+ const structuredLog = {
227
+ ...structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys)),
228
+ timestamp: /* @__PURE__ */ new Date(),
229
+ name: __privateGet(this, _name),
230
+ message
231
+ };
232
+ loggerFunction(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
233
+ }, "#structuredLog");
234
+ __name(_Logger, "Logger");
235
+ var Logger = _Logger;
236
+ function createReplacer(replacer) {
237
+ return (key, value) => {
238
+ if (typeof value === "bigint") {
239
+ return value.toString();
240
+ }
241
+ if (replacer) {
242
+ return replacer(key, value);
243
+ }
244
+ return value;
245
+ };
246
+ }
247
+ __name(createReplacer, "createReplacer");
248
+ function bigIntReplacer(_key, value) {
249
+ if (typeof value === "bigint") {
250
+ return value.toString();
251
+ }
252
+ return value;
253
+ }
254
+ __name(bigIntReplacer, "bigIntReplacer");
255
+ function safeJsonClone(obj) {
256
+ try {
257
+ return JSON.parse(JSON.stringify(obj, bigIntReplacer));
258
+ } catch (e) {
259
+ return obj;
260
+ }
261
+ }
262
+ __name(safeJsonClone, "safeJsonClone");
263
+ function structureArgs(args, filteredKeys = []) {
264
+ if (args.length === 0) {
265
+ return;
266
+ }
267
+ if (args.length === 1 && typeof args[0] === "object") {
268
+ return filterKeys(JSON.parse(JSON.stringify(args[0], bigIntReplacer)), filteredKeys);
269
+ }
270
+ return args;
271
+ }
272
+ __name(structureArgs, "structureArgs");
273
+ function filterKeys(obj, keys) {
274
+ if (typeof obj !== "object" || obj === null) {
275
+ return obj;
276
+ }
277
+ if (Array.isArray(obj)) {
278
+ return obj.map((item) => filterKeys(item, keys));
279
+ }
280
+ const filteredObj = {};
281
+ for (const [key, value] of Object.entries(obj)) {
282
+ if (keys.includes(key)) {
283
+ continue;
284
+ }
285
+ filteredObj[key] = filterKeys(value, keys);
286
+ }
287
+ return filteredObj;
288
+ }
289
+ __name(filterKeys, "filterKeys");
290
+
291
+ // src/schemas/api.ts
292
+ var import_ulid = require("ulid");
293
+ var import_zod9 = require("zod");
294
+
295
+ // src/schemas/errors.ts
296
+ var import_zod = require("zod");
297
+ var ErrorWithStackSchema = import_zod.z.object({
298
+ message: import_zod.z.string(),
299
+ name: import_zod.z.string().optional(),
300
+ stack: import_zod.z.string().optional()
301
+ });
302
+
303
+ // src/schemas/eventFilter.ts
304
+ var import_zod2 = require("zod");
305
+ var EventMatcherSchema = import_zod2.z.union([
306
+ /** Match against a string */
307
+ import_zod2.z.array(import_zod2.z.string()),
308
+ /** Match against a number */
309
+ import_zod2.z.array(import_zod2.z.number()),
310
+ /** Match against a boolean */
311
+ import_zod2.z.array(import_zod2.z.boolean())
312
+ ]);
313
+ var EventFilterSchema = import_zod2.z.lazy(() => import_zod2.z.record(import_zod2.z.union([
314
+ EventMatcherSchema,
315
+ EventFilterSchema
316
+ ])));
317
+ var EventRuleSchema = import_zod2.z.object({
318
+ event: import_zod2.z.string().or(import_zod2.z.array(import_zod2.z.string())),
319
+ source: import_zod2.z.string(),
320
+ payload: EventFilterSchema.optional(),
321
+ context: EventFilterSchema.optional()
322
+ });
323
+
324
+ // src/schemas/integrations.ts
325
+ var import_zod3 = require("zod");
326
+ var ConnectionAuthSchema = import_zod3.z.object({
327
+ type: import_zod3.z.enum([
328
+ "oauth2"
329
+ ]),
330
+ accessToken: import_zod3.z.string(),
331
+ scopes: import_zod3.z.array(import_zod3.z.string()).optional(),
332
+ additionalFields: import_zod3.z.record(import_zod3.z.string()).optional()
333
+ });
334
+ var IntegrationMetadataSchema = import_zod3.z.object({
335
+ id: import_zod3.z.string(),
336
+ name: import_zod3.z.string(),
337
+ instructions: import_zod3.z.string().optional()
338
+ });
339
+ var IntegrationConfigSchema = import_zod3.z.object({
340
+ id: import_zod3.z.string(),
341
+ metadata: IntegrationMetadataSchema,
342
+ authSource: import_zod3.z.enum([
343
+ "HOSTED",
344
+ "LOCAL"
345
+ ])
346
+ });
347
+
348
+ // src/schemas/json.ts
349
+ var import_zod4 = require("zod");
350
+ var LiteralSchema = import_zod4.z.union([
351
+ import_zod4.z.string(),
352
+ import_zod4.z.number(),
353
+ import_zod4.z.boolean(),
354
+ import_zod4.z.null()
355
+ ]);
356
+ var DeserializedJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
357
+ LiteralSchema,
358
+ import_zod4.z.array(DeserializedJsonSchema),
359
+ import_zod4.z.record(DeserializedJsonSchema)
360
+ ]));
361
+ var SerializableSchema = import_zod4.z.union([
362
+ import_zod4.z.string(),
363
+ import_zod4.z.number(),
364
+ import_zod4.z.boolean(),
365
+ import_zod4.z.null(),
366
+ import_zod4.z.date(),
367
+ import_zod4.z.undefined(),
368
+ import_zod4.z.symbol()
369
+ ]);
370
+ var SerializableJsonSchema = import_zod4.z.lazy(() => import_zod4.z.union([
371
+ SerializableSchema,
372
+ import_zod4.z.array(SerializableJsonSchema),
373
+ import_zod4.z.record(SerializableJsonSchema)
374
+ ]));
375
+
376
+ // src/schemas/properties.ts
377
+ var import_zod5 = require("zod");
378
+ var DisplayPropertySchema = import_zod5.z.object({
379
+ /** The label for the property */
380
+ label: import_zod5.z.string(),
381
+ /** The value of the property */
382
+ text: import_zod5.z.string(),
383
+ /** The URL to link to when the property is clicked */
384
+ url: import_zod5.z.string().optional()
385
+ });
386
+ var DisplayPropertiesSchema = import_zod5.z.array(DisplayPropertySchema);
387
+ var StyleSchema = import_zod5.z.object({
388
+ /** The style, `normal` or `minimal` */
389
+ style: import_zod5.z.enum([
390
+ "normal",
391
+ "minimal"
392
+ ]),
393
+ /** A variant of the style. */
394
+ variant: import_zod5.z.string().optional()
395
+ });
396
+
397
+ // src/schemas/schedules.ts
398
+ var import_zod6 = require("zod");
399
+ var SCHEDULED_EVENT = "dev.trigger.scheduled";
400
+ var ScheduledPayloadSchema = import_zod6.z.object({
401
+ ts: import_zod6.z.coerce.date(),
402
+ lastTimestamp: import_zod6.z.coerce.date().optional()
403
+ });
404
+ var IntervalOptionsSchema = import_zod6.z.object({
405
+ /** The number of seconds for the interval. Min = 60, Max = 86400 (1 day) */
406
+ seconds: import_zod6.z.number().int().positive().min(60).max(86400)
407
+ });
408
+ var CronOptionsSchema = import_zod6.z.object({
409
+ /** A CRON expression that defines the schedule. A useful tool when writing CRON
410
+ expressions is [crontab guru](https://crontab.guru). Note that the timezone
411
+ used is UTC. */
412
+ cron: import_zod6.z.string()
413
+ });
414
+ var CronMetadataSchema = import_zod6.z.object({
415
+ type: import_zod6.z.literal("cron"),
416
+ options: CronOptionsSchema,
417
+ metadata: import_zod6.z.any()
418
+ });
419
+ var IntervalMetadataSchema = import_zod6.z.object({
420
+ /** An interval reoccurs at the specified number of seconds */
421
+ type: import_zod6.z.literal("interval"),
422
+ /** An object containing options about the interval. */
423
+ options: IntervalOptionsSchema,
424
+ /** Any additional metadata about the schedule. */
425
+ metadata: import_zod6.z.any()
426
+ });
427
+ var ScheduleMetadataSchema = import_zod6.z.discriminatedUnion("type", [
428
+ IntervalMetadataSchema,
429
+ CronMetadataSchema
430
+ ]);
431
+ var RegisterDynamicSchedulePayloadSchema = import_zod6.z.object({
432
+ id: import_zod6.z.string(),
433
+ jobs: import_zod6.z.array(import_zod6.z.object({
434
+ id: import_zod6.z.string(),
435
+ version: import_zod6.z.string()
436
+ }))
437
+ });
438
+
439
+ // src/schemas/tasks.ts
440
+ var import_zod7 = require("zod");
441
+ var TaskStatusSchema = import_zod7.z.enum([
442
+ "PENDING",
443
+ "WAITING",
444
+ "RUNNING",
445
+ "COMPLETED",
446
+ "ERRORED",
447
+ "CANCELED"
448
+ ]);
449
+ var TaskSchema = import_zod7.z.object({
450
+ id: import_zod7.z.string(),
451
+ name: import_zod7.z.string(),
452
+ icon: import_zod7.z.string().optional().nullable(),
453
+ noop: import_zod7.z.boolean(),
454
+ startedAt: import_zod7.z.coerce.date().optional().nullable(),
455
+ completedAt: import_zod7.z.coerce.date().optional().nullable(),
456
+ delayUntil: import_zod7.z.coerce.date().optional().nullable(),
457
+ status: TaskStatusSchema,
458
+ description: import_zod7.z.string().optional().nullable(),
459
+ properties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
460
+ outputProperties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
461
+ params: DeserializedJsonSchema.optional().nullable(),
462
+ output: DeserializedJsonSchema.optional().nullable(),
463
+ error: import_zod7.z.string().optional().nullable(),
464
+ parentId: import_zod7.z.string().optional().nullable(),
465
+ style: StyleSchema.optional().nullable(),
466
+ operation: import_zod7.z.string().optional().nullable()
467
+ });
468
+ var ServerTaskSchema = TaskSchema.extend({
469
+ idempotencyKey: import_zod7.z.string(),
470
+ attempts: import_zod7.z.number()
471
+ });
472
+ var CachedTaskSchema = import_zod7.z.object({
473
+ id: import_zod7.z.string(),
474
+ idempotencyKey: import_zod7.z.string(),
475
+ status: TaskStatusSchema,
476
+ noop: import_zod7.z.boolean().default(false),
477
+ output: DeserializedJsonSchema.optional().nullable(),
478
+ parentId: import_zod7.z.string().optional().nullable()
479
+ });
480
+
481
+ // src/schemas/triggers.ts
482
+ var import_zod8 = require("zod");
483
+ var EventExampleSchema = import_zod8.z.object({
484
+ id: import_zod8.z.string(),
485
+ icon: import_zod8.z.string().optional(),
486
+ name: import_zod8.z.string(),
487
+ payload: import_zod8.z.any()
488
+ });
489
+ var EventSpecificationSchema = import_zod8.z.object({
490
+ name: import_zod8.z.string().or(import_zod8.z.array(import_zod8.z.string())),
491
+ title: import_zod8.z.string(),
492
+ source: import_zod8.z.string(),
493
+ icon: import_zod8.z.string(),
494
+ filter: EventFilterSchema.optional(),
495
+ properties: import_zod8.z.array(DisplayPropertySchema).optional(),
496
+ schema: import_zod8.z.any().optional(),
497
+ examples: import_zod8.z.array(EventExampleSchema).optional()
498
+ });
499
+ var DynamicTriggerMetadataSchema = import_zod8.z.object({
500
+ type: import_zod8.z.literal("dynamic"),
501
+ id: import_zod8.z.string()
502
+ });
503
+ var StaticTriggerMetadataSchema = import_zod8.z.object({
504
+ type: import_zod8.z.literal("static"),
505
+ title: import_zod8.z.union([
506
+ import_zod8.z.string(),
507
+ import_zod8.z.array(import_zod8.z.string())
508
+ ]),
509
+ properties: import_zod8.z.array(DisplayPropertySchema).optional(),
510
+ rule: EventRuleSchema
511
+ });
512
+ var ScheduledTriggerMetadataSchema = import_zod8.z.object({
513
+ type: import_zod8.z.literal("scheduled"),
514
+ schedule: ScheduleMetadataSchema
515
+ });
516
+ var TriggerMetadataSchema = import_zod8.z.discriminatedUnion("type", [
517
+ DynamicTriggerMetadataSchema,
518
+ StaticTriggerMetadataSchema,
519
+ ScheduledTriggerMetadataSchema
520
+ ]);
521
+
522
+ // src/schemas/api.ts
523
+ var UpdateTriggerSourceBodySchema = import_zod9.z.object({
524
+ registeredEvents: import_zod9.z.array(import_zod9.z.string()),
525
+ secret: import_zod9.z.string().optional(),
526
+ data: SerializableJsonSchema.optional()
527
+ });
528
+ var HttpEventSourceSchema = UpdateTriggerSourceBodySchema.extend({
529
+ id: import_zod9.z.string(),
530
+ active: import_zod9.z.boolean(),
531
+ url: import_zod9.z.string().url()
532
+ });
533
+ var RegisterHTTPTriggerSourceBodySchema = import_zod9.z.object({
534
+ type: import_zod9.z.literal("HTTP"),
535
+ url: import_zod9.z.string().url()
536
+ });
537
+ var RegisterSMTPTriggerSourceBodySchema = import_zod9.z.object({
538
+ type: import_zod9.z.literal("SMTP")
539
+ });
540
+ var RegisterSQSTriggerSourceBodySchema = import_zod9.z.object({
541
+ type: import_zod9.z.literal("SQS")
542
+ });
543
+ var RegisterSourceChannelBodySchema = import_zod9.z.discriminatedUnion("type", [
544
+ RegisterHTTPTriggerSourceBodySchema,
545
+ RegisterSMTPTriggerSourceBodySchema,
546
+ RegisterSQSTriggerSourceBodySchema
547
+ ]);
548
+ var REGISTER_SOURCE_EVENT = "dev.trigger.source.register";
549
+ var RegisterTriggerSourceSchema = import_zod9.z.object({
550
+ key: import_zod9.z.string(),
551
+ params: import_zod9.z.any(),
552
+ active: import_zod9.z.boolean(),
553
+ secret: import_zod9.z.string(),
554
+ data: DeserializedJsonSchema.optional(),
555
+ channel: RegisterSourceChannelBodySchema,
556
+ clientId: import_zod9.z.string().optional()
557
+ });
558
+ var RegisterSourceEventSchema = import_zod9.z.object({
559
+ /** The id of the source */
560
+ id: import_zod9.z.string(),
561
+ source: RegisterTriggerSourceSchema,
562
+ events: import_zod9.z.array(import_zod9.z.string()),
563
+ missingEvents: import_zod9.z.array(import_zod9.z.string()),
564
+ orphanedEvents: import_zod9.z.array(import_zod9.z.string()),
565
+ dynamicTriggerId: import_zod9.z.string().optional()
566
+ });
567
+ var TriggerSourceSchema = import_zod9.z.object({
568
+ id: import_zod9.z.string(),
569
+ key: import_zod9.z.string()
570
+ });
571
+ var HandleTriggerSourceSchema = import_zod9.z.object({
572
+ key: import_zod9.z.string(),
573
+ secret: import_zod9.z.string(),
574
+ data: import_zod9.z.any(),
575
+ params: import_zod9.z.any()
576
+ });
577
+ var HttpSourceRequestSchema = import_zod9.z.object({
578
+ url: import_zod9.z.string().url(),
579
+ method: import_zod9.z.string(),
580
+ headers: import_zod9.z.record(import_zod9.z.string()),
581
+ rawBody: import_zod9.z.instanceof(Buffer).optional().nullable()
582
+ });
583
+ var HttpSourceRequestHeadersSchema = import_zod9.z.object({
584
+ "x-ts-key": import_zod9.z.string(),
585
+ "x-ts-dynamic-id": import_zod9.z.string().optional(),
586
+ "x-ts-secret": import_zod9.z.string(),
587
+ "x-ts-data": import_zod9.z.string().transform((s) => JSON.parse(s)),
588
+ "x-ts-params": import_zod9.z.string().transform((s) => JSON.parse(s)),
589
+ "x-ts-http-url": import_zod9.z.string(),
590
+ "x-ts-http-method": import_zod9.z.string(),
591
+ "x-ts-http-headers": import_zod9.z.string().transform((s) => import_zod9.z.record(import_zod9.z.string()).parse(JSON.parse(s)))
592
+ });
593
+ var PongSuccessResponseSchema = import_zod9.z.object({
594
+ ok: import_zod9.z.literal(true)
595
+ });
596
+ var PongErrorResponseSchema = import_zod9.z.object({
597
+ ok: import_zod9.z.literal(false),
598
+ error: import_zod9.z.string()
599
+ });
600
+ var PongResponseSchema = import_zod9.z.discriminatedUnion("ok", [
601
+ PongSuccessResponseSchema,
602
+ PongErrorResponseSchema
603
+ ]);
604
+ var QueueOptionsSchema = import_zod9.z.object({
605
+ name: import_zod9.z.string(),
606
+ maxConcurrent: import_zod9.z.number().optional()
607
+ });
608
+ var JobMetadataSchema = import_zod9.z.object({
609
+ id: import_zod9.z.string(),
610
+ name: import_zod9.z.string(),
611
+ version: import_zod9.z.string(),
612
+ event: EventSpecificationSchema,
613
+ trigger: TriggerMetadataSchema,
614
+ integrations: import_zod9.z.record(IntegrationConfigSchema),
615
+ internal: import_zod9.z.boolean().default(false),
616
+ queue: import_zod9.z.union([
617
+ QueueOptionsSchema,
618
+ import_zod9.z.string()
619
+ ]).optional(),
620
+ startPosition: import_zod9.z.enum([
621
+ "initial",
622
+ "latest"
623
+ ]),
624
+ enabled: import_zod9.z.boolean(),
625
+ preprocessRuns: import_zod9.z.boolean()
626
+ });
627
+ var SourceMetadataSchema = import_zod9.z.object({
628
+ channel: import_zod9.z.enum([
629
+ "HTTP",
630
+ "SQS",
631
+ "SMTP"
632
+ ]),
633
+ integration: IntegrationConfigSchema,
634
+ key: import_zod9.z.string(),
635
+ params: import_zod9.z.any(),
636
+ events: import_zod9.z.array(import_zod9.z.string()),
637
+ registerSourceJob: import_zod9.z.object({
638
+ id: import_zod9.z.string(),
639
+ version: import_zod9.z.string()
640
+ }).optional()
641
+ });
642
+ var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
643
+ id: import_zod9.z.string(),
644
+ jobs: import_zod9.z.array(JobMetadataSchema.pick({
645
+ id: true,
646
+ version: true
647
+ })),
648
+ registerSourceJob: import_zod9.z.object({
649
+ id: import_zod9.z.string(),
650
+ version: import_zod9.z.string()
651
+ }).optional()
652
+ });
653
+ var IndexEndpointResponseSchema = import_zod9.z.object({
654
+ jobs: import_zod9.z.array(JobMetadataSchema),
655
+ sources: import_zod9.z.array(SourceMetadataSchema),
656
+ dynamicTriggers: import_zod9.z.array(DynamicTriggerEndpointMetadataSchema),
657
+ dynamicSchedules: import_zod9.z.array(RegisterDynamicSchedulePayloadSchema)
658
+ });
659
+ var RawEventSchema = import_zod9.z.object({
660
+ /** The `name` property must exactly match any subscriptions you want to
661
+ trigger. */
662
+ name: import_zod9.z.string(),
663
+ /** The `payload` property will be sent to any matching Jobs and will appear
664
+ as the `payload` param of the `run()` function. You can leave this
665
+ parameter out if you just want to trigger a Job without any input data. */
666
+ payload: import_zod9.z.any(),
667
+ /** The optional `context` property will be sent to any matching Jobs and will
668
+ be passed through as the `context.event.context` param of the `run()`
669
+ function. This is optional but can be useful if you want to pass through
670
+ some additional context to the Job. */
671
+ context: import_zod9.z.any().optional(),
672
+ /** The `id` property uniquely identify this particular event. If unset it
673
+ will be set automatically using `ulid`. */
674
+ id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
675
+ /** This is optional, it defaults to the current timestamp. Usually you would
676
+ only set this if you have a timestamp that you wish to pass through, e.g.
677
+ you receive a timestamp from a service and you want the same timestamp to
678
+ be used in your Job. */
679
+ timestamp: import_zod9.z.coerce.date().optional(),
680
+ /** This is optional, it defaults to "trigger.dev". It can be useful to set
681
+ this as you can filter events using this in the `eventTrigger()`. */
682
+ source: import_zod9.z.string().optional()
683
+ });
684
+ var ApiEventLogSchema = import_zod9.z.object({
685
+ /** The `id` of the event that was sent.
686
+ */
687
+ id: import_zod9.z.string(),
688
+ /** The `name` of the event that was sent. */
689
+ name: import_zod9.z.string(),
690
+ /** The `payload` of the event that was sent */
691
+ payload: DeserializedJsonSchema,
692
+ /** The `context` of the event that was sent. Is `undefined` if no context was
693
+ set when sending the event. */
694
+ context: DeserializedJsonSchema.optional().nullable(),
695
+ /** The `timestamp` of the event that was sent */
696
+ timestamp: import_zod9.z.coerce.date(),
697
+ /** The timestamp when the event will be delivered to any matching Jobs. Is
698
+ `undefined` if `deliverAt` or `deliverAfter` wasn't set when sending the
699
+ event. */
700
+ deliverAt: import_zod9.z.coerce.date().optional().nullable(),
701
+ /** The timestamp when the event was delivered. Is `undefined` if `deliverAt`
702
+ or `deliverAfter` were set when sending the event. */
703
+ deliveredAt: import_zod9.z.coerce.date().optional().nullable()
704
+ });
705
+ var SendEventOptionsSchema = import_zod9.z.object({
706
+ /** An optional Date when you want the event to trigger Jobs. The event will
707
+ be sent to the platform immediately but won't be acted upon until the
708
+ specified time. */
709
+ deliverAt: import_zod9.z.coerce.date().optional(),
710
+ /** An optional number of seconds you want to wait for the event to trigger
711
+ any relevant Jobs. The event will be sent to the platform immediately but
712
+ won't be delivered until after the elapsed number of seconds. */
713
+ deliverAfter: import_zod9.z.number().int().optional(),
714
+ /** This optional param will be used by Trigger.dev Connect, which
715
+ is coming soon. */
716
+ accountId: import_zod9.z.string().optional()
717
+ });
718
+ var SendEventBodySchema = import_zod9.z.object({
719
+ event: RawEventSchema,
720
+ options: SendEventOptionsSchema.optional()
721
+ });
722
+ var DeliverEventResponseSchema = import_zod9.z.object({
723
+ deliveredAt: import_zod9.z.string().datetime()
724
+ });
725
+ var RuntimeEnvironmentTypeSchema = import_zod9.z.enum([
726
+ "PRODUCTION",
727
+ "STAGING",
728
+ "DEVELOPMENT",
729
+ "PREVIEW"
730
+ ]);
731
+ var RunSourceContextSchema = import_zod9.z.object({
732
+ id: import_zod9.z.string(),
733
+ metadata: import_zod9.z.any()
734
+ });
735
+ var RunJobBodySchema = import_zod9.z.object({
736
+ event: ApiEventLogSchema,
737
+ job: import_zod9.z.object({
738
+ id: import_zod9.z.string(),
739
+ version: import_zod9.z.string()
740
+ }),
741
+ run: import_zod9.z.object({
742
+ id: import_zod9.z.string(),
743
+ isTest: import_zod9.z.boolean(),
744
+ isRetry: import_zod9.z.boolean().default(false),
745
+ startedAt: import_zod9.z.coerce.date()
746
+ }),
747
+ environment: import_zod9.z.object({
748
+ id: import_zod9.z.string(),
749
+ slug: import_zod9.z.string(),
750
+ type: RuntimeEnvironmentTypeSchema
751
+ }),
752
+ organization: import_zod9.z.object({
753
+ id: import_zod9.z.string(),
754
+ title: import_zod9.z.string(),
755
+ slug: import_zod9.z.string()
756
+ }),
757
+ account: import_zod9.z.object({
758
+ id: import_zod9.z.string(),
759
+ metadata: import_zod9.z.any()
760
+ }).optional(),
761
+ source: RunSourceContextSchema.optional(),
762
+ tasks: import_zod9.z.array(CachedTaskSchema).optional(),
763
+ connections: import_zod9.z.record(ConnectionAuthSchema).optional()
764
+ });
765
+ var RunJobErrorSchema = import_zod9.z.object({
766
+ status: import_zod9.z.literal("ERROR"),
767
+ error: ErrorWithStackSchema,
768
+ task: TaskSchema.optional()
769
+ });
770
+ var RunJobResumeWithTaskSchema = import_zod9.z.object({
771
+ status: import_zod9.z.literal("RESUME_WITH_TASK"),
772
+ task: TaskSchema
773
+ });
774
+ var RunJobRetryWithTaskSchema = import_zod9.z.object({
775
+ status: import_zod9.z.literal("RETRY_WITH_TASK"),
776
+ task: TaskSchema,
777
+ error: ErrorWithStackSchema,
778
+ retryAt: import_zod9.z.coerce.date()
779
+ });
780
+ var RunJobCanceledWithTaskSchema = import_zod9.z.object({
781
+ status: import_zod9.z.literal("CANCELED"),
782
+ task: TaskSchema
783
+ });
784
+ var RunJobSuccessSchema = import_zod9.z.object({
785
+ status: import_zod9.z.literal("SUCCESS"),
786
+ output: DeserializedJsonSchema.optional()
787
+ });
788
+ var RunJobResponseSchema = import_zod9.z.discriminatedUnion("status", [
789
+ RunJobErrorSchema,
790
+ RunJobResumeWithTaskSchema,
791
+ RunJobRetryWithTaskSchema,
792
+ RunJobCanceledWithTaskSchema,
793
+ RunJobSuccessSchema
794
+ ]);
795
+ var PreprocessRunBodySchema = import_zod9.z.object({
796
+ event: ApiEventLogSchema,
797
+ job: import_zod9.z.object({
798
+ id: import_zod9.z.string(),
799
+ version: import_zod9.z.string()
800
+ }),
801
+ run: import_zod9.z.object({
802
+ id: import_zod9.z.string(),
803
+ isTest: import_zod9.z.boolean()
804
+ }),
805
+ environment: import_zod9.z.object({
806
+ id: import_zod9.z.string(),
807
+ slug: import_zod9.z.string(),
808
+ type: RuntimeEnvironmentTypeSchema
809
+ }),
810
+ organization: import_zod9.z.object({
811
+ id: import_zod9.z.string(),
812
+ title: import_zod9.z.string(),
813
+ slug: import_zod9.z.string()
814
+ }),
815
+ account: import_zod9.z.object({
816
+ id: import_zod9.z.string(),
817
+ metadata: import_zod9.z.any()
818
+ }).optional()
819
+ });
820
+ var PreprocessRunResponseSchema = import_zod9.z.object({
821
+ abort: import_zod9.z.boolean(),
822
+ properties: import_zod9.z.array(DisplayPropertySchema).optional()
823
+ });
824
+ var CreateRunBodySchema = import_zod9.z.object({
825
+ client: import_zod9.z.string(),
826
+ job: JobMetadataSchema,
827
+ event: ApiEventLogSchema,
828
+ properties: import_zod9.z.array(DisplayPropertySchema).optional()
829
+ });
830
+ var CreateRunResponseOkSchema = import_zod9.z.object({
831
+ ok: import_zod9.z.literal(true),
832
+ data: import_zod9.z.object({
833
+ id: import_zod9.z.string()
834
+ })
835
+ });
836
+ var CreateRunResponseErrorSchema = import_zod9.z.object({
837
+ ok: import_zod9.z.literal(false),
838
+ error: import_zod9.z.string()
839
+ });
840
+ var CreateRunResponseBodySchema = import_zod9.z.discriminatedUnion("ok", [
841
+ CreateRunResponseOkSchema,
842
+ CreateRunResponseErrorSchema
843
+ ]);
844
+ var RedactStringSchema = import_zod9.z.object({
845
+ __redactedString: import_zod9.z.literal(true),
846
+ strings: import_zod9.z.array(import_zod9.z.string()),
847
+ interpolations: import_zod9.z.array(import_zod9.z.string())
848
+ });
849
+ var LogMessageSchema = import_zod9.z.object({
850
+ level: import_zod9.z.enum([
851
+ "DEBUG",
852
+ "INFO",
853
+ "WARN",
854
+ "ERROR"
855
+ ]),
856
+ message: import_zod9.z.string(),
857
+ data: SerializableJsonSchema.optional()
858
+ });
859
+ var RedactSchema = import_zod9.z.object({
860
+ paths: import_zod9.z.array(import_zod9.z.string())
861
+ });
862
+ var RetryOptionsSchema = import_zod9.z.object({
863
+ /** The maximum number of times to retry the request. */
864
+ limit: import_zod9.z.number().optional(),
865
+ /** The exponential factor to use when calculating the next retry time. */
866
+ factor: import_zod9.z.number().optional(),
867
+ /** The minimum amount of time to wait before retrying the request. */
868
+ minTimeoutInMs: import_zod9.z.number().optional(),
869
+ /** The maximum amount of time to wait before retrying the request. */
870
+ maxTimeoutInMs: import_zod9.z.number().optional(),
871
+ /** Whether to randomize the retry time. */
872
+ randomize: import_zod9.z.boolean().optional()
873
+ });
874
+ var RunTaskOptionsSchema = import_zod9.z.object({
875
+ /** The name of the Task is required. This is displayed on the Task in the logs. */
876
+ name: import_zod9.z.string(),
877
+ /** The Task will wait and only start at the specified Date */
878
+ delayUntil: import_zod9.z.coerce.date().optional(),
879
+ /** Retry options */
880
+ retry: RetryOptionsSchema.optional(),
881
+ /** The icon for the Task, it will appear in the logs.
882
+ * You can use the name of a company in lowercase, e.g. "github".
883
+ * Or any icon name that [Font Awesome](https://fontawesome.com/icons) supports. */
884
+ icon: import_zod9.z.string().optional(),
885
+ /** The key for the Task that you want to appear in the logs */
886
+ displayKey: import_zod9.z.string().optional(),
887
+ /** A description of the Task */
888
+ description: import_zod9.z.string().optional(),
889
+ /** Properties that are displayed in the logs */
890
+ properties: import_zod9.z.array(DisplayPropertySchema).optional(),
891
+ /** The input params to the Task, will be displayed in the logs */
892
+ params: import_zod9.z.any(),
893
+ /** The style of the log entry. */
894
+ style: StyleSchema.optional(),
895
+ /** Allows you to link the Integration connection in the logs. This is handled automatically in integrations. */
896
+ connectionKey: import_zod9.z.string().optional(),
897
+ /** An operation you want to perform on the Trigger.dev platform, current only "fetch" is supported. If you wish to `fetch` use [`io.backgroundFetch()`](https://trigger.dev/docs/sdk/io/backgroundfetch) instead. */
898
+ operation: import_zod9.z.enum([
899
+ "fetch"
900
+ ]).optional(),
901
+ /** A No Operation means that the code won't be executed. This is used internally to implement features like [io.wait()](https://trigger.dev/docs/sdk/io/wait). */
902
+ noop: import_zod9.z.boolean().default(false),
903
+ redact: RedactSchema.optional(),
904
+ trigger: TriggerMetadataSchema.optional()
905
+ });
906
+ var RunTaskBodyInputSchema = RunTaskOptionsSchema.extend({
907
+ idempotencyKey: import_zod9.z.string(),
908
+ parentId: import_zod9.z.string().optional()
909
+ });
910
+ var RunTaskBodyOutputSchema = RunTaskBodyInputSchema.extend({
911
+ params: DeserializedJsonSchema.optional().nullable()
912
+ });
913
+ var CompleteTaskBodyInputSchema = RunTaskBodyInputSchema.pick({
914
+ properties: true,
915
+ description: true,
916
+ params: true
917
+ }).extend({
918
+ output: SerializableJsonSchema.optional().transform((v) => v ? DeserializedJsonSchema.parse(JSON.parse(JSON.stringify(v))) : {})
919
+ });
920
+ var FailTaskBodyInputSchema = import_zod9.z.object({
921
+ error: ErrorWithStackSchema
922
+ });
923
+ var NormalizedRequestSchema = import_zod9.z.object({
924
+ headers: import_zod9.z.record(import_zod9.z.string()),
925
+ method: import_zod9.z.string(),
926
+ query: import_zod9.z.record(import_zod9.z.string()),
927
+ url: import_zod9.z.string(),
928
+ body: import_zod9.z.any()
929
+ });
930
+ var NormalizedResponseSchema = import_zod9.z.object({
931
+ status: import_zod9.z.number(),
932
+ body: import_zod9.z.any(),
933
+ headers: import_zod9.z.record(import_zod9.z.string()).optional()
934
+ });
935
+ var HttpSourceResponseSchema = import_zod9.z.object({
936
+ response: NormalizedResponseSchema,
937
+ events: import_zod9.z.array(RawEventSchema)
938
+ });
939
+ var RegisterTriggerBodySchema = import_zod9.z.object({
940
+ rule: EventRuleSchema,
941
+ source: SourceMetadataSchema
942
+ });
943
+ var InitializeTriggerBodySchema = import_zod9.z.object({
944
+ id: import_zod9.z.string(),
945
+ params: import_zod9.z.any(),
946
+ accountId: import_zod9.z.string().optional(),
947
+ metadata: import_zod9.z.any().optional()
948
+ });
949
+ var RegisterCommonScheduleBodySchema = import_zod9.z.object({
950
+ /** A unique id for the schedule. This is used to identify and unregister the schedule later. */
951
+ id: import_zod9.z.string(),
952
+ /** Any additional metadata about the schedule. */
953
+ metadata: import_zod9.z.any(),
954
+ /** This will be used by the Trigger.dev Connect feature, which is coming soon. */
955
+ accountId: import_zod9.z.string().optional()
956
+ });
957
+ var RegisterIntervalScheduleBodySchema = RegisterCommonScheduleBodySchema.merge(IntervalMetadataSchema);
958
+ var InitializeCronScheduleBodySchema = RegisterCommonScheduleBodySchema.merge(CronMetadataSchema);
959
+ var RegisterScheduleBodySchema = import_zod9.z.discriminatedUnion("type", [
960
+ RegisterIntervalScheduleBodySchema,
961
+ InitializeCronScheduleBodySchema
962
+ ]);
963
+ var RegisterScheduleResponseBodySchema = import_zod9.z.object({
964
+ id: import_zod9.z.string(),
965
+ schedule: ScheduleMetadataSchema,
966
+ metadata: import_zod9.z.any(),
967
+ active: import_zod9.z.boolean()
968
+ });
969
+ var CreateExternalConnectionBodySchema = import_zod9.z.object({
970
+ accessToken: import_zod9.z.string(),
971
+ type: import_zod9.z.enum([
972
+ "oauth2"
973
+ ]),
974
+ scopes: import_zod9.z.array(import_zod9.z.string()).optional(),
975
+ metadata: import_zod9.z.any()
976
+ });
977
+
978
+ // src/schemas/notifications.ts
979
+ var import_zod10 = require("zod");
980
+ var MISSING_CONNECTION_NOTIFICATION = "dev.trigger.notifications.missingConnection";
981
+ var MISSING_CONNECTION_RESOLVED_NOTIFICATION = "dev.trigger.notifications.missingConnectionResolved";
982
+ var CommonMissingConnectionNotificationPayloadSchema = import_zod10.z.object({
983
+ id: import_zod10.z.string(),
984
+ client: import_zod10.z.object({
985
+ id: import_zod10.z.string(),
986
+ title: import_zod10.z.string(),
987
+ scopes: import_zod10.z.array(import_zod10.z.string()),
988
+ createdAt: import_zod10.z.coerce.date(),
989
+ updatedAt: import_zod10.z.coerce.date()
990
+ }),
991
+ authorizationUrl: import_zod10.z.string()
992
+ });
993
+ var MissingDeveloperConnectionNotificationPayloadSchema = CommonMissingConnectionNotificationPayloadSchema.extend({
994
+ type: import_zod10.z.literal("DEVELOPER")
995
+ });
996
+ var MissingExternalConnectionNotificationPayloadSchema = CommonMissingConnectionNotificationPayloadSchema.extend({
997
+ type: import_zod10.z.literal("EXTERNAL"),
998
+ account: import_zod10.z.object({
999
+ id: import_zod10.z.string(),
1000
+ metadata: import_zod10.z.any()
1001
+ })
1002
+ });
1003
+ var MissingConnectionNotificationPayloadSchema = import_zod10.z.discriminatedUnion("type", [
1004
+ MissingDeveloperConnectionNotificationPayloadSchema,
1005
+ MissingExternalConnectionNotificationPayloadSchema
1006
+ ]);
1007
+ var CommonMissingConnectionNotificationResolvedPayloadSchema = import_zod10.z.object({
1008
+ id: import_zod10.z.string(),
1009
+ client: import_zod10.z.object({
1010
+ id: import_zod10.z.string(),
1011
+ title: import_zod10.z.string(),
1012
+ scopes: import_zod10.z.array(import_zod10.z.string()),
1013
+ createdAt: import_zod10.z.coerce.date(),
1014
+ updatedAt: import_zod10.z.coerce.date(),
1015
+ integrationIdentifier: import_zod10.z.string(),
1016
+ integrationAuthMethod: import_zod10.z.string()
1017
+ }),
1018
+ expiresAt: import_zod10.z.coerce.date()
1019
+ });
1020
+ var MissingDeveloperConnectionResolvedNotificationPayloadSchema = CommonMissingConnectionNotificationResolvedPayloadSchema.extend({
1021
+ type: import_zod10.z.literal("DEVELOPER")
1022
+ });
1023
+ var MissingExternalConnectionResolvedNotificationPayloadSchema = CommonMissingConnectionNotificationResolvedPayloadSchema.extend({
1024
+ type: import_zod10.z.literal("EXTERNAL"),
1025
+ account: import_zod10.z.object({
1026
+ id: import_zod10.z.string(),
1027
+ metadata: import_zod10.z.any()
1028
+ })
1029
+ });
1030
+ var MissingConnectionResolvedNotificationPayloadSchema = import_zod10.z.discriminatedUnion("type", [
1031
+ MissingDeveloperConnectionResolvedNotificationPayloadSchema,
1032
+ MissingExternalConnectionResolvedNotificationPayloadSchema
1033
+ ]);
1034
+
1035
+ // src/schemas/fetch.ts
1036
+ var import_zod11 = require("zod");
1037
+ var FetchRetryHeadersStrategySchema = import_zod11.z.object({
1038
+ /** The `headers` strategy retries the request using info from the response headers. */
1039
+ strategy: import_zod11.z.literal("headers"),
1040
+ /** The header to use to determine the maximum number of times to retry the request. */
1041
+ limitHeader: import_zod11.z.string(),
1042
+ /** The header to use to determine the number of remaining retries. */
1043
+ remainingHeader: import_zod11.z.string(),
1044
+ /** The header to use to determine the time when the number of remaining retries will be reset. */
1045
+ resetHeader: import_zod11.z.string()
1046
+ });
1047
+ var FetchRetryBackoffStrategySchema = RetryOptionsSchema.extend({
1048
+ /** The `backoff` strategy retries the request with an exponential backoff. */
1049
+ strategy: import_zod11.z.literal("backoff")
1050
+ });
1051
+ var FetchRetryStrategySchema = import_zod11.z.discriminatedUnion("strategy", [
1052
+ FetchRetryHeadersStrategySchema,
1053
+ FetchRetryBackoffStrategySchema
1054
+ ]);
1055
+ var FetchRequestInitSchema = import_zod11.z.object({
1056
+ /** The HTTP method to use for the request. */
1057
+ method: import_zod11.z.string().optional(),
1058
+ /** Any headers to send with the request. Note that you can use [redactString](https://trigger.dev/docs/sdk/redactString) to prevent sensitive information from being stored (e.g. in the logs), like API keys and tokens. */
1059
+ headers: import_zod11.z.record(import_zod11.z.union([
1060
+ import_zod11.z.string(),
1061
+ RedactStringSchema
1062
+ ])).optional(),
1063
+ /** The body of the request. */
1064
+ body: import_zod11.z.union([
1065
+ import_zod11.z.string(),
1066
+ import_zod11.z.instanceof(ArrayBuffer)
1067
+ ]).optional()
1068
+ });
1069
+ var FetchRetryOptionsSchema = import_zod11.z.record(FetchRetryStrategySchema);
1070
+ var FetchOperationSchema = import_zod11.z.object({
1071
+ url: import_zod11.z.string(),
1072
+ requestInit: FetchRequestInitSchema.optional(),
1073
+ retry: import_zod11.z.record(FetchRetryStrategySchema).optional()
1074
+ });
1075
+
1076
+ // src/schemas/events.ts
1077
+ var import_zod13 = require("zod");
1078
+
1079
+ // src/schemas/runs.ts
1080
+ var import_zod12 = require("zod");
1081
+ var RunStatusSchema = import_zod12.z.union([
1082
+ import_zod12.z.literal("PENDING"),
1083
+ import_zod12.z.literal("QUEUED"),
1084
+ import_zod12.z.literal("WAITING_ON_CONNECTIONS"),
1085
+ import_zod12.z.literal("PREPROCESSING"),
1086
+ import_zod12.z.literal("STARTED"),
1087
+ import_zod12.z.literal("SUCCESS"),
1088
+ import_zod12.z.literal("FAILURE"),
1089
+ import_zod12.z.literal("TIMED_OUT"),
1090
+ import_zod12.z.literal("ABORTED"),
1091
+ import_zod12.z.literal("CANCELED")
1092
+ ]);
1093
+ var RunTaskSchema = import_zod12.z.object({
1094
+ /** The Task id */
1095
+ id: import_zod12.z.string(),
1096
+ /** The key that you defined when creating the Task, the first param in any task. */
1097
+ displayKey: import_zod12.z.string().nullable(),
1098
+ /** The Task status */
1099
+ status: TaskStatusSchema,
1100
+ /** The name of the Task */
1101
+ name: import_zod12.z.string(),
1102
+ /** The icon of the Task, a string.
1103
+ * For integrations, this will be a lowercase name of the company.
1104
+ * Can be used with the [@trigger.dev/companyicons](https://www.npmjs.com/package/@trigger.dev/companyicons) package to display an svg. */
1105
+ icon: import_zod12.z.string().nullable(),
1106
+ /** When the task started */
1107
+ startedAt: import_zod12.z.coerce.date().nullable(),
1108
+ /** When the task completed */
1109
+ completedAt: import_zod12.z.coerce.date().nullable()
1110
+ });
1111
+ var GetRunOptionsSchema = import_zod12.z.object({
1112
+ /** Return subtasks, which appear in a `subtasks` array on a task. @default false */
1113
+ subtasks: import_zod12.z.boolean().optional(),
1114
+ /** You can use this to get more tasks, if there are more than are returned in a single batch @default undefined */
1115
+ cursor: import_zod12.z.string().optional(),
1116
+ /** How many tasks you want to return in one go, max 50. @default 20 */
1117
+ take: import_zod12.z.number().optional()
1118
+ });
1119
+ var GetRunOptionsWithTaskDetailsSchema = GetRunOptionsSchema.extend({
1120
+ /** If `true`, it returns the `params` and `output` of all tasks. @default false */
1121
+ taskdetails: import_zod12.z.boolean().optional()
1122
+ });
1123
+ var RunSchema = import_zod12.z.object({
1124
+ /** The Run id */
1125
+ id: import_zod12.z.string(),
1126
+ /** The Run status */
1127
+ status: RunStatusSchema,
1128
+ /** When the run started */
1129
+ startedAt: import_zod12.z.coerce.date().nullable(),
1130
+ /** When the run was last updated */
1131
+ updatedAt: import_zod12.z.coerce.date().nullable(),
1132
+ /** When the run was completed */
1133
+ completedAt: import_zod12.z.coerce.date().nullable()
1134
+ });
1135
+ var GetRunSchema = RunSchema.extend({
1136
+ /** The output of the run */
1137
+ output: import_zod12.z.any().optional(),
1138
+ /** The tasks from the run */
1139
+ tasks: import_zod12.z.array(RunTaskSchema),
1140
+ /** If there are more tasks, you can use this to get them */
1141
+ nextCursor: import_zod12.z.string().optional()
1142
+ });
1143
+ var GetRunsOptionsSchema = import_zod12.z.object({
1144
+ /** You can use this to get more tasks, if there are more than are returned in a single batch @default undefined */
1145
+ cursor: import_zod12.z.string().optional(),
1146
+ /** How many runs you want to return in one go, max 50. @default 20 */
1147
+ take: import_zod12.z.number().optional()
1148
+ });
1149
+ var GetRunsSchema = import_zod12.z.object({
1150
+ /** The runs from the query */
1151
+ runs: RunSchema.array(),
1152
+ /** If there are more runs, you can use this to get them */
1153
+ nextCursor: import_zod12.z.string().optional()
1154
+ });
1155
+
1156
+ // src/schemas/events.ts
1157
+ var GetEventSchema = import_zod13.z.object({
1158
+ /** The event id */
1159
+ id: import_zod13.z.string(),
1160
+ /** The event name */
1161
+ name: import_zod13.z.string(),
1162
+ /** When the event was created */
1163
+ createdAt: import_zod13.z.coerce.date(),
1164
+ /** When the event was last updated */
1165
+ updatedAt: import_zod13.z.coerce.date(),
1166
+ /** The runs that were triggered by the event */
1167
+ runs: import_zod13.z.array(import_zod13.z.object({
1168
+ /** The Run id */
1169
+ id: import_zod13.z.string(),
1170
+ /** The Run status */
1171
+ status: RunStatusSchema,
1172
+ /** When the run started */
1173
+ startedAt: import_zod13.z.coerce.date().optional().nullable(),
1174
+ /** When the run completed */
1175
+ completedAt: import_zod13.z.coerce.date().optional().nullable()
1176
+ }))
1177
+ });
1178
+
1179
+ // src/utils.ts
1180
+ function deepMergeFilters(...filters) {
1181
+ const result = {};
1182
+ for (const filter of filters) {
1183
+ for (const key in filter) {
1184
+ if (filter.hasOwnProperty(key)) {
1185
+ const filterValue = filter[key];
1186
+ const existingValue = result[key];
1187
+ if (existingValue && typeof existingValue === "object" && typeof filterValue === "object" && !Array.isArray(existingValue) && !Array.isArray(filterValue) && existingValue !== null && filterValue !== null) {
1188
+ result[key] = deepMergeFilters(existingValue, filterValue);
1189
+ } else {
1190
+ result[key] = filterValue;
1191
+ }
1192
+ }
1193
+ }
1194
+ }
1195
+ return result;
1196
+ }
1197
+ __name(deepMergeFilters, "deepMergeFilters");
1198
+
1199
+ // src/retry.ts
1200
+ var DEFAULT_RETRY_OPTIONS = {
1201
+ limit: 5,
1202
+ factor: 1.8,
1203
+ minTimeoutInMs: 1e3,
1204
+ maxTimeoutInMs: 6e4,
1205
+ randomize: true
1206
+ };
1207
+ function calculateRetryAt(retryOptions, attempts) {
1208
+ const options = {
1209
+ ...DEFAULT_RETRY_OPTIONS,
1210
+ ...retryOptions
1211
+ };
1212
+ const retryCount = attempts + 1;
1213
+ if (retryCount >= options.limit) {
1214
+ return;
1215
+ }
1216
+ const random = options.randomize ? Math.random() + 1 : 1;
1217
+ let timeoutInMs = Math.round(random * Math.max(options.minTimeoutInMs, 1) * Math.pow(options.factor, Math.max(attempts - 1, 0)));
1218
+ timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);
1219
+ return new Date(Date.now() + timeoutInMs);
1220
+ }
1221
+ __name(calculateRetryAt, "calculateRetryAt");
1222
+
1223
+ // src/replacements.ts
1224
+ var currentDate = {
1225
+ marker: "__CURRENT_DATE__",
1226
+ replace({ data: { now } }) {
1227
+ return now.toISOString();
1228
+ }
1229
+ };
1230
+ var currentTimestampMilliseconds = {
1231
+ marker: "__CURRENT_TIMESTAMP_MS__",
1232
+ replace({ data: { now } }) {
1233
+ return now.getTime();
1234
+ }
1235
+ };
1236
+ var currentTimestampSeconds = {
1237
+ marker: "__CURRENT_TIMESTAMP_S__",
1238
+ replace({ data: { now } }) {
1239
+ return now.getTime() / 1e3;
1240
+ }
1241
+ };
1242
+ var replacements = [
1243
+ currentDate,
1244
+ currentTimestampMilliseconds,
1245
+ currentTimestampSeconds
1246
+ ];
1247
+
1248
+ // src/searchParams.ts
1249
+ function urlWithSearchParams(url, params) {
1250
+ if (!params) {
1251
+ return url;
1252
+ }
1253
+ const urlObj = new URL(url);
1254
+ for (const [key, value] of Object.entries(params)) {
1255
+ urlObj.searchParams.append(key, String(value));
1256
+ }
1257
+ return urlObj.toString();
1258
+ }
1259
+ __name(urlWithSearchParams, "urlWithSearchParams");
1260
+ //# sourceMappingURL=index.js.map