@trigger.dev/sdk 0.0.0-background-tasks-20230906212613 → 0.0.0-beta-20240327133444

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.d.ts CHANGED
@@ -1,8 +1,39 @@
1
1
  import * as _trigger_dev_core from '@trigger.dev/core';
2
- import { RunTaskBodyInput, CompleteTaskBodyInput, FailTaskBodyInput, SendEvent, SendEventOptions, UpdateTriggerSourceBodyV2, TriggerSource, RegisterTriggerBodyV2, RegisterSourceEventV2, ScheduleMetadata, GetRunOptionsWithTaskDetails, GetRunsOptions, LogLevel, RuntimeEnvironmentType, DisplayProperty, TriggerMetadata, EventFilter, Prettify, HandleTriggerSource, Logger, RegisterTriggerSource, SerializableJson, ConnectionAuth, NormalizedResponse, HttpSourceResponseMetadata, BackgroundTaskMetadata, DeserializedJson, IntervalOptions, CronOptions, ScheduledPayload, ServerTask, CachedTask, FetchRequestInit, FetchRetryOptions, RunTaskOptions, IntegrationMetadata, QueueOptions, IntegrationConfig, JobMetadata, MissingConnectionNotificationPayload, MissingConnectionResolvedNotificationPayload, ErrorWithStack, ApiEventLog, RedactString } from '@trigger.dev/core';
3
- export { ConnectionAuth, DisplayProperty, EventFilter, Logger, NormalizedRequest, OverridableRunTaskOptions, Prettify, RedactString, RegisteredOptionsDiff, RunTaskOptions, SourceEventOption } from '@trigger.dev/core';
2
+ import { AsyncMap, KeyValueStoreResponseBody, RunTaskBodyInput, CompleteTaskBodyV2Input, FailTaskBodyInput, SendEvent, SendEventOptions, StatusUpdate, UpdateTriggerSourceBodyV2, TriggerSource, UpdateWebhookBody, RegisterTriggerBodyV2, RegisterSourceEventV2, ScheduleMetadata, GetRunOptionsWithTaskDetails, GetRunsOptions, InvokeOptions, EphemeralEventDispatcherRequestBody, RuntimeEnvironmentType, DisplayProperty, TriggerMetadata, EventFilter, SuccessfulRunNotification, FailedRunNotification, HttpEndpointMetadata, RequestFilter, Prettify, HandleTriggerSource, RegisterTriggerSource, SerializableJson, ConnectionAuth, NormalizedResponse, HttpSourceResponseMetadata, IntervalOptions, CronOptions, ScheduledPayload, RegisterWebhookSource, DeserializedJson, ServerTask, CachedTask, InitialStatusUpdate, FetchRequestInit, FetchRetryOptions, FetchTimeoutOptions, FetchPollOperation, RunTaskOptions, IntegrationMetadata, IntegrationConfig, JobMetadata, RunNotification, MissingConnectionNotificationPayload, MissingConnectionResolvedNotificationPayload, ErrorWithStack, ApiEventLog, RedactString } from '@trigger.dev/core';
3
+ export { ConnectionAuth, DisplayProperty, EventFilter, NormalizedRequest, OverridableRunTaskOptions, Prettify, RedactString, RegisteredOptionsDiff, RunTaskOptions, SourceEventOption } from '@trigger.dev/core';
4
+ import { LogLevel, Logger } from '@trigger.dev/core-backend';
5
+ export { Logger } from '@trigger.dev/core-backend';
4
6
  import * as zod from 'zod';
5
- import { z } from 'zod';
7
+ import { z, ZodType, TypeOf } from 'zod';
8
+ import { Buffer } from 'buffer';
9
+ import { BinaryToTextEncoding, BinaryLike, KeyObject } from 'crypto';
10
+
11
+ type ConcurrencyLimitOptions = {
12
+ id: string;
13
+ limit: number;
14
+ };
15
+ declare class ConcurrencyLimit {
16
+ private options;
17
+ constructor(options: ConcurrencyLimitOptions);
18
+ get id(): string;
19
+ get limit(): number;
20
+ }
21
+
22
+ type QueryKeyValueStoreFunction = (action: "DELETE" | "GET" | "HAS" | "SET", data: {
23
+ key: string;
24
+ value?: string;
25
+ }) => Promise<KeyValueStoreResponseBody>;
26
+ declare class KeyValueStoreClient implements AsyncMap {
27
+ #private;
28
+ private queryStore;
29
+ private type;
30
+ private namespace;
31
+ constructor(queryStore: QueryKeyValueStoreFunction, type?: string | null, namespace?: string);
32
+ delete(key: string): Promise<boolean>;
33
+ get<T extends Json<T>>(key: string): Promise<T | undefined>;
34
+ has(key: string): Promise<boolean>;
35
+ set<T extends Json<T>>(key: string, value: T): Promise<T>;
36
+ }
6
37
 
7
38
  type ApiClientOptions = {
8
39
  apiKey?: string;
@@ -21,7 +52,358 @@ declare class ApiClient {
21
52
  url: string;
22
53
  name: string;
23
54
  }): Promise<EndpointRecord>;
24
- runTask(runId: string, task: RunTaskBodyInput): Promise<{
55
+ runTask(runId: string, task: RunTaskBodyInput, options?: {
56
+ cachedTasksCursor?: string;
57
+ }): Promise<VersionedResponseBody<{
58
+ "2023-09-29": z.ZodObject<{
59
+ task: z.ZodObject<{
60
+ id: z.ZodString;
61
+ name: z.ZodString;
62
+ icon: z.ZodNullable<z.ZodOptional<z.ZodString>>;
63
+ noop: z.ZodBoolean;
64
+ startedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
65
+ completedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
66
+ delayUntil: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
67
+ status: z.ZodEnum<["PENDING", "WAITING", "RUNNING", "COMPLETED", "ERRORED", "CANCELED"]>;
68
+ description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
69
+ params: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
70
+ properties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
71
+ label: z.ZodString;
72
+ text: z.ZodString;
73
+ url: z.ZodOptional<z.ZodString>;
74
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
75
+ }, "strip", z.ZodTypeAny, {
76
+ label: string;
77
+ text: string;
78
+ url?: string | undefined;
79
+ imageUrl?: string[] | undefined;
80
+ }, {
81
+ label: string;
82
+ text: string;
83
+ url?: string | undefined;
84
+ imageUrl?: string[] | undefined;
85
+ }>, "many">>>;
86
+ outputProperties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
87
+ label: z.ZodString;
88
+ text: z.ZodString;
89
+ url: z.ZodOptional<z.ZodString>;
90
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
91
+ }, "strip", z.ZodTypeAny, {
92
+ label: string;
93
+ text: string;
94
+ url?: string | undefined;
95
+ imageUrl?: string[] | undefined;
96
+ }, {
97
+ label: string;
98
+ text: string;
99
+ url?: string | undefined;
100
+ imageUrl?: string[] | undefined;
101
+ }>, "many">>>;
102
+ output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
103
+ context: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
104
+ error: z.ZodNullable<z.ZodOptional<z.ZodString>>;
105
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
106
+ style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
107
+ style: z.ZodEnum<["normal", "minimal"]>;
108
+ variant: z.ZodOptional<z.ZodString>;
109
+ }, "strip", z.ZodTypeAny, {
110
+ style: "normal" | "minimal";
111
+ variant?: string | undefined;
112
+ }, {
113
+ style: "normal" | "minimal";
114
+ variant?: string | undefined;
115
+ }>>>;
116
+ operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
117
+ callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
118
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
119
+ idempotencyKey: z.ZodString;
120
+ attempts: z.ZodNumber;
121
+ forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
122
+ }, "strip", z.ZodTypeAny, {
123
+ id: string;
124
+ name: string;
125
+ noop: boolean;
126
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
127
+ idempotencyKey: string;
128
+ attempts: number;
129
+ icon?: string | null | undefined;
130
+ startedAt?: Date | null | undefined;
131
+ completedAt?: Date | null | undefined;
132
+ delayUntil?: Date | null | undefined;
133
+ description?: string | null | undefined;
134
+ params?: _trigger_dev_core.DeserializedJson | undefined;
135
+ properties?: {
136
+ label: string;
137
+ text: string;
138
+ url?: string | undefined;
139
+ imageUrl?: string[] | undefined;
140
+ }[] | null | undefined;
141
+ outputProperties?: {
142
+ label: string;
143
+ text: string;
144
+ url?: string | undefined;
145
+ imageUrl?: string[] | undefined;
146
+ }[] | null | undefined;
147
+ output?: _trigger_dev_core.DeserializedJson | undefined;
148
+ context?: _trigger_dev_core.DeserializedJson | undefined;
149
+ error?: string | null | undefined;
150
+ parentId?: string | null | undefined;
151
+ style?: {
152
+ style: "normal" | "minimal";
153
+ variant?: string | undefined;
154
+ } | null | undefined;
155
+ operation?: string | null | undefined;
156
+ callbackUrl?: string | null | undefined;
157
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
158
+ forceYield?: boolean | null | undefined;
159
+ }, {
160
+ id: string;
161
+ name: string;
162
+ noop: boolean;
163
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
164
+ idempotencyKey: string;
165
+ attempts: number;
166
+ icon?: string | null | undefined;
167
+ startedAt?: Date | null | undefined;
168
+ completedAt?: Date | null | undefined;
169
+ delayUntil?: Date | null | undefined;
170
+ description?: string | null | undefined;
171
+ params?: _trigger_dev_core.DeserializedJson | undefined;
172
+ properties?: {
173
+ label: string;
174
+ text: string;
175
+ url?: string | undefined;
176
+ imageUrl?: string[] | undefined;
177
+ }[] | null | undefined;
178
+ outputProperties?: {
179
+ label: string;
180
+ text: string;
181
+ url?: string | undefined;
182
+ imageUrl?: string[] | undefined;
183
+ }[] | null | undefined;
184
+ output?: _trigger_dev_core.DeserializedJson | undefined;
185
+ context?: _trigger_dev_core.DeserializedJson | undefined;
186
+ error?: string | null | undefined;
187
+ parentId?: string | null | undefined;
188
+ style?: {
189
+ style: "normal" | "minimal";
190
+ variant?: string | undefined;
191
+ } | null | undefined;
192
+ operation?: string | null | undefined;
193
+ callbackUrl?: string | null | undefined;
194
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
195
+ forceYield?: boolean | null | undefined;
196
+ }>;
197
+ cachedTasks: z.ZodOptional<z.ZodObject<{
198
+ tasks: z.ZodArray<z.ZodObject<{
199
+ id: z.ZodString;
200
+ idempotencyKey: z.ZodString;
201
+ status: z.ZodEnum<["PENDING", "WAITING", "RUNNING", "COMPLETED", "ERRORED", "CANCELED"]>;
202
+ noop: z.ZodDefault<z.ZodBoolean>;
203
+ output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
204
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
205
+ }, "strip", z.ZodTypeAny, {
206
+ id: string;
207
+ noop: boolean;
208
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
209
+ idempotencyKey: string;
210
+ output?: _trigger_dev_core.DeserializedJson | undefined;
211
+ parentId?: string | null | undefined;
212
+ }, {
213
+ id: string;
214
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
215
+ idempotencyKey: string;
216
+ noop?: boolean | undefined;
217
+ output?: _trigger_dev_core.DeserializedJson | undefined;
218
+ parentId?: string | null | undefined;
219
+ }>, "many">;
220
+ cursor: z.ZodOptional<z.ZodString>;
221
+ }, "strip", z.ZodTypeAny, {
222
+ tasks: {
223
+ id: string;
224
+ noop: boolean;
225
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
226
+ idempotencyKey: string;
227
+ output?: _trigger_dev_core.DeserializedJson | undefined;
228
+ parentId?: string | null | undefined;
229
+ }[];
230
+ cursor?: string | undefined;
231
+ }, {
232
+ tasks: {
233
+ id: string;
234
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
235
+ idempotencyKey: string;
236
+ noop?: boolean | undefined;
237
+ output?: _trigger_dev_core.DeserializedJson | undefined;
238
+ parentId?: string | null | undefined;
239
+ }[];
240
+ cursor?: string | undefined;
241
+ }>>;
242
+ }, "strip", z.ZodTypeAny, {
243
+ task: {
244
+ id: string;
245
+ name: string;
246
+ noop: boolean;
247
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
248
+ idempotencyKey: string;
249
+ attempts: number;
250
+ icon?: string | null | undefined;
251
+ startedAt?: Date | null | undefined;
252
+ completedAt?: Date | null | undefined;
253
+ delayUntil?: Date | null | undefined;
254
+ description?: string | null | undefined;
255
+ params?: _trigger_dev_core.DeserializedJson | undefined;
256
+ properties?: {
257
+ label: string;
258
+ text: string;
259
+ url?: string | undefined;
260
+ imageUrl?: string[] | undefined;
261
+ }[] | null | undefined;
262
+ outputProperties?: {
263
+ label: string;
264
+ text: string;
265
+ url?: string | undefined;
266
+ imageUrl?: string[] | undefined;
267
+ }[] | null | undefined;
268
+ output?: _trigger_dev_core.DeserializedJson | undefined;
269
+ context?: _trigger_dev_core.DeserializedJson | undefined;
270
+ error?: string | null | undefined;
271
+ parentId?: string | null | undefined;
272
+ style?: {
273
+ style: "normal" | "minimal";
274
+ variant?: string | undefined;
275
+ } | null | undefined;
276
+ operation?: string | null | undefined;
277
+ callbackUrl?: string | null | undefined;
278
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
279
+ forceYield?: boolean | null | undefined;
280
+ };
281
+ cachedTasks?: {
282
+ tasks: {
283
+ id: string;
284
+ noop: boolean;
285
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
286
+ idempotencyKey: string;
287
+ output?: _trigger_dev_core.DeserializedJson | undefined;
288
+ parentId?: string | null | undefined;
289
+ }[];
290
+ cursor?: string | undefined;
291
+ } | undefined;
292
+ }, {
293
+ task: {
294
+ id: string;
295
+ name: string;
296
+ noop: boolean;
297
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
298
+ idempotencyKey: string;
299
+ attempts: number;
300
+ icon?: string | null | undefined;
301
+ startedAt?: Date | null | undefined;
302
+ completedAt?: Date | null | undefined;
303
+ delayUntil?: Date | null | undefined;
304
+ description?: string | null | undefined;
305
+ params?: _trigger_dev_core.DeserializedJson | undefined;
306
+ properties?: {
307
+ label: string;
308
+ text: string;
309
+ url?: string | undefined;
310
+ imageUrl?: string[] | undefined;
311
+ }[] | null | undefined;
312
+ outputProperties?: {
313
+ label: string;
314
+ text: string;
315
+ url?: string | undefined;
316
+ imageUrl?: string[] | undefined;
317
+ }[] | null | undefined;
318
+ output?: _trigger_dev_core.DeserializedJson | undefined;
319
+ context?: _trigger_dev_core.DeserializedJson | undefined;
320
+ error?: string | null | undefined;
321
+ parentId?: string | null | undefined;
322
+ style?: {
323
+ style: "normal" | "minimal";
324
+ variant?: string | undefined;
325
+ } | null | undefined;
326
+ operation?: string | null | undefined;
327
+ callbackUrl?: string | null | undefined;
328
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
329
+ forceYield?: boolean | null | undefined;
330
+ };
331
+ cachedTasks?: {
332
+ tasks: {
333
+ id: string;
334
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
335
+ idempotencyKey: string;
336
+ noop?: boolean | undefined;
337
+ output?: _trigger_dev_core.DeserializedJson | undefined;
338
+ parentId?: string | null | undefined;
339
+ }[];
340
+ cursor?: string | undefined;
341
+ } | undefined;
342
+ }>;
343
+ }, z.ZodObject<{
344
+ id: z.ZodString;
345
+ name: z.ZodString;
346
+ icon: z.ZodNullable<z.ZodOptional<z.ZodString>>;
347
+ noop: z.ZodBoolean;
348
+ startedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
349
+ completedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
350
+ delayUntil: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
351
+ status: z.ZodEnum<["PENDING", "WAITING", "RUNNING", "COMPLETED", "ERRORED", "CANCELED"]>;
352
+ description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
353
+ params: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
354
+ properties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
355
+ label: z.ZodString;
356
+ text: z.ZodString;
357
+ url: z.ZodOptional<z.ZodString>;
358
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
359
+ }, "strip", z.ZodTypeAny, {
360
+ label: string;
361
+ text: string;
362
+ url?: string | undefined;
363
+ imageUrl?: string[] | undefined;
364
+ }, {
365
+ label: string;
366
+ text: string;
367
+ url?: string | undefined;
368
+ imageUrl?: string[] | undefined;
369
+ }>, "many">>>;
370
+ outputProperties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
371
+ label: z.ZodString;
372
+ text: z.ZodString;
373
+ url: z.ZodOptional<z.ZodString>;
374
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
375
+ }, "strip", z.ZodTypeAny, {
376
+ label: string;
377
+ text: string;
378
+ url?: string | undefined;
379
+ imageUrl?: string[] | undefined;
380
+ }, {
381
+ label: string;
382
+ text: string;
383
+ url?: string | undefined;
384
+ imageUrl?: string[] | undefined;
385
+ }>, "many">>>;
386
+ output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
387
+ context: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
388
+ error: z.ZodNullable<z.ZodOptional<z.ZodString>>;
389
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
390
+ style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
391
+ style: z.ZodEnum<["normal", "minimal"]>;
392
+ variant: z.ZodOptional<z.ZodString>;
393
+ }, "strip", z.ZodTypeAny, {
394
+ style: "normal" | "minimal";
395
+ variant?: string | undefined;
396
+ }, {
397
+ style: "normal" | "minimal";
398
+ variant?: string | undefined;
399
+ }>>>;
400
+ operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
401
+ callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
402
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
403
+ idempotencyKey: z.ZodString;
404
+ attempts: z.ZodNumber;
405
+ forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
406
+ }, "strip", z.ZodTypeAny, {
25
407
  id: string;
26
408
  name: string;
27
409
  noop: boolean;
@@ -38,13 +420,16 @@ declare class ApiClient {
38
420
  label: string;
39
421
  text: string;
40
422
  url?: string | undefined;
423
+ imageUrl?: string[] | undefined;
41
424
  }[] | null | undefined;
42
425
  outputProperties?: {
43
426
  label: string;
44
427
  text: string;
45
428
  url?: string | undefined;
429
+ imageUrl?: string[] | undefined;
46
430
  }[] | null | undefined;
47
431
  output?: _trigger_dev_core.DeserializedJson | undefined;
432
+ context?: _trigger_dev_core.DeserializedJson | undefined;
48
433
  error?: string | null | undefined;
49
434
  parentId?: string | null | undefined;
50
435
  style?: {
@@ -52,8 +437,48 @@ declare class ApiClient {
52
437
  variant?: string | undefined;
53
438
  } | null | undefined;
54
439
  operation?: string | null | undefined;
55
- }>;
56
- completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
440
+ callbackUrl?: string | null | undefined;
441
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
442
+ forceYield?: boolean | null | undefined;
443
+ }, {
444
+ id: string;
445
+ name: string;
446
+ noop: boolean;
447
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
448
+ idempotencyKey: string;
449
+ attempts: number;
450
+ icon?: string | null | undefined;
451
+ startedAt?: Date | null | undefined;
452
+ completedAt?: Date | null | undefined;
453
+ delayUntil?: Date | null | undefined;
454
+ description?: string | null | undefined;
455
+ params?: _trigger_dev_core.DeserializedJson | undefined;
456
+ properties?: {
457
+ label: string;
458
+ text: string;
459
+ url?: string | undefined;
460
+ imageUrl?: string[] | undefined;
461
+ }[] | null | undefined;
462
+ outputProperties?: {
463
+ label: string;
464
+ text: string;
465
+ url?: string | undefined;
466
+ imageUrl?: string[] | undefined;
467
+ }[] | null | undefined;
468
+ output?: _trigger_dev_core.DeserializedJson | undefined;
469
+ context?: _trigger_dev_core.DeserializedJson | undefined;
470
+ error?: string | null | undefined;
471
+ parentId?: string | null | undefined;
472
+ style?: {
473
+ style: "normal" | "minimal";
474
+ variant?: string | undefined;
475
+ } | null | undefined;
476
+ operation?: string | null | undefined;
477
+ callbackUrl?: string | null | undefined;
478
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
479
+ forceYield?: boolean | null | undefined;
480
+ }>>>;
481
+ completeTask(runId: string, id: string, task: CompleteTaskBodyV2Input): Promise<{
57
482
  id: string;
58
483
  name: string;
59
484
  noop: boolean;
@@ -70,13 +495,16 @@ declare class ApiClient {
70
495
  label: string;
71
496
  text: string;
72
497
  url?: string | undefined;
498
+ imageUrl?: string[] | undefined;
73
499
  }[] | null | undefined;
74
500
  outputProperties?: {
75
501
  label: string;
76
502
  text: string;
77
503
  url?: string | undefined;
504
+ imageUrl?: string[] | undefined;
78
505
  }[] | null | undefined;
79
506
  output?: _trigger_dev_core.DeserializedJson | undefined;
507
+ context?: _trigger_dev_core.DeserializedJson | undefined;
80
508
  error?: string | null | undefined;
81
509
  parentId?: string | null | undefined;
82
510
  style?: {
@@ -84,6 +512,9 @@ declare class ApiClient {
84
512
  variant?: string | undefined;
85
513
  } | null | undefined;
86
514
  operation?: string | null | undefined;
515
+ callbackUrl?: string | null | undefined;
516
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
517
+ forceYield?: boolean | null | undefined;
87
518
  }>;
88
519
  failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
89
520
  id: string;
@@ -102,13 +533,16 @@ declare class ApiClient {
102
533
  label: string;
103
534
  text: string;
104
535
  url?: string | undefined;
536
+ imageUrl?: string[] | undefined;
105
537
  }[] | null | undefined;
106
538
  outputProperties?: {
107
539
  label: string;
108
540
  text: string;
109
541
  url?: string | undefined;
542
+ imageUrl?: string[] | undefined;
110
543
  }[] | null | undefined;
111
544
  output?: _trigger_dev_core.DeserializedJson | undefined;
545
+ context?: _trigger_dev_core.DeserializedJson | undefined;
112
546
  error?: string | null | undefined;
113
547
  parentId?: string | null | undefined;
114
548
  style?: {
@@ -116,6 +550,9 @@ declare class ApiClient {
116
550
  variant?: string | undefined;
117
551
  } | null | undefined;
118
552
  operation?: string | null | undefined;
553
+ callbackUrl?: string | null | undefined;
554
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
555
+ forceYield?: boolean | null | undefined;
119
556
  }>;
120
557
  sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
121
558
  id: string;
@@ -131,6 +568,20 @@ declare class ApiClient {
131
568
  deliveredAt?: Date | null | undefined;
132
569
  cancelledAt?: Date | null | undefined;
133
570
  }>;
571
+ sendEvents(events: SendEvent[], options?: SendEventOptions): Promise<{
572
+ id: string;
573
+ name: string;
574
+ payload: ((string | number | boolean | {
575
+ [key: string]: _trigger_dev_core.DeserializedJson;
576
+ } | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
577
+ [key: string]: _trigger_dev_core.DeserializedJson;
578
+ } | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
579
+ timestamp: Date;
580
+ context?: _trigger_dev_core.DeserializedJson | undefined;
581
+ deliverAt?: Date | null | undefined;
582
+ deliveredAt?: Date | null | undefined;
583
+ cancelledAt?: Date | null | undefined;
584
+ }[]>;
134
585
  cancelEvent(eventId: string): Promise<{
135
586
  id: string;
136
587
  name: string;
@@ -145,8 +596,24 @@ declare class ApiClient {
145
596
  deliveredAt?: Date | null | undefined;
146
597
  cancelledAt?: Date | null | undefined;
147
598
  }>;
599
+ cancelRunsForEvent(eventId: string): Promise<{
600
+ cancelledRunIds: string[];
601
+ failedToCancelRunIds: string[];
602
+ }>;
603
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
604
+ label: string;
605
+ key: string;
606
+ history: {
607
+ label?: string | undefined;
608
+ state?: "loading" | "success" | "failure" | undefined;
609
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
610
+ }[];
611
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
612
+ state?: "loading" | "success" | "failure" | undefined;
613
+ }>;
148
614
  updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
149
- registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2): Promise<RegisterSourceEventV2>;
615
+ updateWebhook(key: string, webhookData: UpdateWebhookBody): Promise<TriggerSource>;
616
+ registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2, idempotencyKey?: string): Promise<RegisterSourceEventV2>;
150
617
  registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
151
618
  id: string;
152
619
  schedule: {
@@ -154,12 +621,14 @@ declare class ApiClient {
154
621
  cron: string;
155
622
  };
156
623
  type: "cron";
624
+ accountId?: string | undefined;
157
625
  metadata?: any;
158
626
  } | {
159
627
  options: {
160
628
  seconds: number;
161
629
  };
162
630
  type: "interval";
631
+ accountId?: string | undefined;
163
632
  metadata?: any;
164
633
  };
165
634
  active: boolean;
@@ -169,7 +638,7 @@ declare class ApiClient {
169
638
  ok: boolean;
170
639
  }>;
171
640
  getAuth(client: string, id: string): Promise<{
172
- type: "oauth2";
641
+ type: "oauth2" | "apiKey";
173
642
  accessToken: string;
174
643
  scopes?: string[] | undefined;
175
644
  additionalFields?: Record<string, string> | undefined;
@@ -177,35 +646,167 @@ declare class ApiClient {
177
646
  getEvent(eventId: string): Promise<{
178
647
  id: string;
179
648
  name: string;
180
- createdAt: Date;
181
649
  updatedAt: Date;
182
650
  runs: {
183
651
  id: string;
184
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
652
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
185
653
  startedAt?: Date | null | undefined;
186
654
  completedAt?: Date | null | undefined;
187
655
  }[];
656
+ createdAt: Date;
188
657
  }>;
189
658
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
190
659
  id: string;
191
660
  startedAt: Date | null;
192
661
  completedAt: Date | null;
193
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
662
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
663
+ updatedAt: Date | null;
194
664
  tasks: _trigger_dev_core.RunTaskWithSubtasks[];
665
+ statuses: {
666
+ label: string;
667
+ key: string;
668
+ history: {
669
+ label?: string | undefined;
670
+ state?: "loading" | "success" | "failure" | undefined;
671
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
672
+ }[];
673
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
674
+ state?: "loading" | "success" | "failure" | undefined;
675
+ }[];
676
+ output?: any;
677
+ nextCursor?: string | undefined;
678
+ }>;
679
+ cancelRun(runId: string): Promise<{
680
+ id: string;
681
+ startedAt: Date | null;
682
+ completedAt: Date | null;
683
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
195
684
  updatedAt: Date | null;
685
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
686
+ statuses: {
687
+ label: string;
688
+ key: string;
689
+ history: {
690
+ label?: string | undefined;
691
+ state?: "loading" | "success" | "failure" | undefined;
692
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
693
+ }[];
694
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
695
+ state?: "loading" | "success" | "failure" | undefined;
696
+ }[];
196
697
  output?: any;
197
698
  nextCursor?: string | undefined;
198
699
  }>;
700
+ getRunStatuses(runId: string): Promise<{
701
+ statuses: {
702
+ label: string;
703
+ key: string;
704
+ history: {
705
+ label?: string | undefined;
706
+ state?: "loading" | "success" | "failure" | undefined;
707
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
708
+ }[];
709
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
710
+ state?: "loading" | "success" | "failure" | undefined;
711
+ }[];
712
+ run: {
713
+ id: string;
714
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
715
+ output?: any;
716
+ };
717
+ }>;
199
718
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
200
719
  runs: {
201
720
  id: string;
202
721
  startedAt: Date | null;
203
722
  completedAt: Date | null;
204
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
723
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
205
724
  updatedAt: Date | null;
206
725
  }[];
207
726
  nextCursor?: string | undefined;
208
727
  }>;
728
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
729
+ id: string;
730
+ }>;
731
+ cancelRunsForJob(jobId: string): Promise<{
732
+ cancelledRunIds: string[];
733
+ failedToCancelRunIds: string[];
734
+ }>;
735
+ createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
736
+ id: string;
737
+ }>;
738
+ get store(): KeyValueStoreClient;
739
+ }
740
+ type VersionedResponseBodyMap = {
741
+ [key: string]: z.ZodTypeAny;
742
+ };
743
+ type VersionedResponseBody<TVersions extends VersionedResponseBodyMap, TUnversioned extends z.ZodTypeAny> = {
744
+ [TVersion in keyof TVersions]: {
745
+ version: TVersion;
746
+ body: z.infer<TVersions[TVersion]>;
747
+ };
748
+ }[keyof TVersions] | {
749
+ version: "unversioned";
750
+ body: z.infer<TUnversioned>;
751
+ };
752
+
753
+ declare class TriggerStatus {
754
+ private id;
755
+ private io;
756
+ constructor(id: string, io: IO);
757
+ update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
758
+ label: string;
759
+ key: string;
760
+ history: {
761
+ label?: string | undefined;
762
+ state?: "loading" | "success" | "failure" | undefined;
763
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
764
+ }[];
765
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
766
+ state?: "loading" | "success" | "failure" | undefined;
767
+ }>;
768
+ }
769
+
770
+ type EventMap = {
771
+ [key: string]: (...args: any[]) => void
772
+ }
773
+
774
+ /**
775
+ * Type-safe event emitter.
776
+ *
777
+ * Use it like this:
778
+ *
779
+ * ```typescript
780
+ * type MyEvents = {
781
+ * error: (error: Error) => void;
782
+ * message: (from: string, content: string) => void;
783
+ * }
784
+ *
785
+ * const myEmitter = new EventEmitter() as TypedEmitter<MyEvents>;
786
+ *
787
+ * myEmitter.emit("error", "x") // <- Will catch this type error;
788
+ * ```
789
+ */
790
+ interface TypedEventEmitter<Events extends EventMap> {
791
+ addListener<E extends keyof Events> (event: E, listener: Events[E]): this
792
+ on<E extends keyof Events> (event: E, listener: Events[E]): this
793
+ once<E extends keyof Events> (event: E, listener: Events[E]): this
794
+ prependListener<E extends keyof Events> (event: E, listener: Events[E]): this
795
+ prependOnceListener<E extends keyof Events> (event: E, listener: Events[E]): this
796
+
797
+ off<E extends keyof Events>(event: E, listener: Events[E]): this
798
+ removeAllListeners<E extends keyof Events> (event?: E): this
799
+ removeListener<E extends keyof Events> (event: E, listener: Events[E]): this
800
+
801
+ emit<E extends keyof Events> (event: E, ...args: Parameters<Events[E]>): boolean
802
+ // The sloppy `eventNames()` return type is to mitigate type incompatibilities - see #5
803
+ eventNames (): (keyof Events | string | symbol)[]
804
+ rawListeners<E extends keyof Events> (event: E): Events[E][]
805
+ listeners<E extends keyof Events> (event: E): Events[E][]
806
+ listenerCount<E extends keyof Events> (event: E): number
807
+
808
+ getMaxListeners (): number
809
+ setMaxListeners (maxListeners: number): this
209
810
  }
210
811
 
211
812
  interface TriggerContext {
@@ -226,6 +827,12 @@ interface TriggerContext {
226
827
  id: string;
227
828
  title: string;
228
829
  };
830
+ /** Project metadata */
831
+ project: {
832
+ slug: string;
833
+ id: string;
834
+ name: string;
835
+ };
229
836
  /** Run metadata */
230
837
  run: {
231
838
  id: string;
@@ -292,20 +899,45 @@ type PreprocessResults = {
292
899
  properties: DisplayProperty[];
293
900
  };
294
901
  type TriggerEventType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? ReturnType<TEventSpec["parsePayload"]> : never;
902
+ type TriggerInvokeType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<EventSpecification<any, infer TInvoke>> ? TInvoke : any;
903
+ type VerifyResult = {
904
+ success: true;
905
+ } | {
906
+ success: false;
907
+ reason?: string;
908
+ };
295
909
  interface Trigger<TEventSpec extends EventSpecification<any>> {
296
910
  event: TEventSpec;
297
911
  toJSON(): TriggerMetadata;
298
912
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
299
913
  preprocessRuns: boolean;
914
+ verifyPayload: (payload: ReturnType<TEventSpec["parsePayload"]>) => Promise<VerifyResult>;
300
915
  }
301
916
  type TriggerPayload<TTrigger> = TTrigger extends Trigger<EventSpecification<infer TEvent>> ? TEvent : never;
302
- type EventSpecificationExample = {
917
+ declare const EventSpecificationExampleSchema: z.ZodObject<{
918
+ id: z.ZodString;
919
+ name: z.ZodString;
920
+ icon: z.ZodOptional<z.ZodString>;
921
+ payload: z.ZodAny;
922
+ }, "strip", z.ZodTypeAny, {
923
+ id: string;
924
+ name: string;
925
+ icon?: string | undefined;
926
+ payload?: any;
927
+ }, {
928
+ id: string;
929
+ name: string;
930
+ icon?: string | undefined;
931
+ payload?: any;
932
+ }>;
933
+ type EventSpecificationExample = z.infer<typeof EventSpecificationExampleSchema>;
934
+ type TypedEventSpecificationExample<TEvent> = {
303
935
  id: string;
304
936
  name: string;
305
937
  icon?: string;
306
- payload: any;
938
+ payload: TEvent;
307
939
  };
308
- interface EventSpecification<TEvent extends any> {
940
+ interface EventSpecification<TEvent extends any, TInvoke extends any = TEvent> {
309
941
  name: string | string[];
310
942
  title: string;
311
943
  source: string;
@@ -315,9 +947,163 @@ interface EventSpecification<TEvent extends any> {
315
947
  examples?: Array<EventSpecificationExample>;
316
948
  filter?: EventFilter;
317
949
  parsePayload: (payload: unknown) => TEvent;
950
+ parseInvokePayload?: (payload: unknown) => TInvoke;
318
951
  runProperties?: (payload: TEvent) => DisplayProperty[];
319
952
  }
320
953
  type EventTypeFromSpecification<TEventSpec extends EventSpecification<any>> = TEventSpec extends EventSpecification<infer TEvent> ? TEvent : never;
954
+ type SchemaParserIssue = {
955
+ path: PropertyKey[];
956
+ message: string;
957
+ };
958
+ type SchemaParserResult<T> = {
959
+ success: true;
960
+ data: T;
961
+ } | {
962
+ success: false;
963
+ error: {
964
+ issues: SchemaParserIssue[];
965
+ };
966
+ };
967
+ type SchemaParser<T extends unknown = unknown> = {
968
+ safeParse: (a: unknown) => SchemaParserResult<T>;
969
+ };
970
+ type WaitForEventResult<TEvent> = {
971
+ id: string;
972
+ name: string;
973
+ source: string;
974
+ payload: TEvent;
975
+ timestamp: Date;
976
+ context?: any;
977
+ accountId?: string;
978
+ };
979
+ declare function waitForEventSchema(schema: z.ZodTypeAny): z.ZodObject<{
980
+ id: z.ZodString;
981
+ name: z.ZodString;
982
+ source: z.ZodString;
983
+ payload: z.ZodTypeAny;
984
+ timestamp: z.ZodDate;
985
+ context: z.ZodOptional<z.ZodAny>;
986
+ accountId: z.ZodOptional<z.ZodString>;
987
+ }, "strip", z.ZodTypeAny, {
988
+ id: string;
989
+ name: string;
990
+ timestamp: Date;
991
+ source: string;
992
+ payload?: any;
993
+ context?: any;
994
+ accountId?: string | undefined;
995
+ }, {
996
+ id: string;
997
+ name: string;
998
+ timestamp: Date;
999
+ source: string;
1000
+ payload?: any;
1001
+ context?: any;
1002
+ accountId?: string | undefined;
1003
+ }>;
1004
+ type NotificationEvents = {
1005
+ runSucceeeded: (notification: SuccessfulRunNotification<any>) => void;
1006
+ runFailed: (notification: FailedRunNotification) => void;
1007
+ };
1008
+ type NotificationsEventEmitter = TypedEventEmitter<NotificationEvents>;
1009
+
1010
+ type HttpEndpointOptions<TEventSpecification extends EventSpecification<any>> = {
1011
+ id: string;
1012
+ enabled?: boolean;
1013
+ event: TEventSpecification;
1014
+ respondWith?: RespondWith;
1015
+ verify: VerifyCallback;
1016
+ };
1017
+ type RequestOptions = {
1018
+ filter?: RequestFilter;
1019
+ };
1020
+ declare class HttpEndpoint<TEventSpecification extends EventSpecification<any>> {
1021
+ private readonly options;
1022
+ constructor(options: HttpEndpointOptions<TEventSpecification>);
1023
+ get id(): string;
1024
+ onRequest(options?: RequestOptions): HttpTrigger<EventSpecification<Request>>;
1025
+ toJSON(): HttpEndpointMetadata;
1026
+ }
1027
+ type TriggerOptions$1<TEventSpecification extends EventSpecification<any>> = {
1028
+ endpointId: string;
1029
+ event: TEventSpecification;
1030
+ filter?: EventFilter;
1031
+ verify: VerifyCallback;
1032
+ };
1033
+ declare class HttpTrigger<TEventSpecification extends EventSpecification<any>> implements Trigger<TEventSpecification> {
1034
+ private readonly options;
1035
+ constructor(options: TriggerOptions$1<TEventSpecification>);
1036
+ toJSON(): TriggerMetadata;
1037
+ get event(): TEventSpecification;
1038
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
1039
+ get preprocessRuns(): boolean;
1040
+ verifyPayload(payload: Request): Promise<VerifyResult>;
1041
+ }
1042
+ type RespondWith = {
1043
+ /** Only Requests that match this filter will cause the `handler` function to run.
1044
+ * For example, you can use this to only respond to `GET` Requests. */
1045
+ filter?: RequestFilter;
1046
+ /** If you set this to `true`, the Request that comes in won't go on to Trigger any Runs.
1047
+ * This is useful if you want to Respond to the Request, but don't want to Trigger any Runs. */
1048
+ skipTriggeringRuns?: boolean;
1049
+ /** This is a function that's called when a Request comes in.
1050
+ * It's passed the Request object, and expects you to return a Response object. */
1051
+ handler: (request: Request, verify: () => Promise<VerifyResult>) => Promise<Response>;
1052
+ };
1053
+ type VerifyCallback = (request: Request) => Promise<VerifyResult>;
1054
+ type EndpointOptions = {
1055
+ /** Used to uniquely identify the HTTP Endpoint inside your Project. */
1056
+ id: string;
1057
+ enabled?: boolean;
1058
+ /** Usually you would use the domain name of the service, e.g. `cal.com`. */
1059
+ source: string;
1060
+ /** An optional title, displayed in the dashboard. */
1061
+ title?: string;
1062
+ /** An optional icon name that's displayed in the dashboard.
1063
+ * Lots of company names are supported, e.g. `github`, `twilio`.
1064
+ * You can also reference the name of any [Tabler icon](https://tabler-icons.io/), e.g. `brand-google-maps`, `brand-twitch`. */
1065
+ icon?: string;
1066
+ /** Used to provide example payloads that are accepted by the job.
1067
+ * This will be available in the dashboard and can be used to trigger test runs. */
1068
+ examples?: EventSpecificationExample[];
1069
+ /** Properties that are displayed in the dashboard. */
1070
+ properties?: DisplayProperty[];
1071
+ /** This optional object allows you to immediately Respond to a Request. This is useful for some APIs where they do a `GET` Request when the webhook is first setup and expect a specific Response.
1072
+
1073
+ Only use this if you really need to Respond to the Request that comes in. Most of the time you don't. */
1074
+ respondWith?: RespondWith;
1075
+ /** This is compulsory, and is used to verify that the received webhook is authentic.
1076
+ * It's a function that expects you to return a result object like:
1077
+
1078
+ In 90% of cases, you'll want to use the `verifyRequestSignature` helper function we provide.
1079
+
1080
+ @example
1081
+ ```ts
1082
+ //if it's valid
1083
+ return { success: true }
1084
+ //if it's invalid, reason is optional
1085
+ return { success: false, reason: "No header" }
1086
+ ```
1087
+
1088
+ */
1089
+ verify: VerifyCallback;
1090
+ };
1091
+
1092
+ declare class KeyValueStore {
1093
+ #private;
1094
+ private apiClient;
1095
+ private type;
1096
+ private namespace;
1097
+ constructor(apiClient: ApiClient, type?: string | null, namespace?: string);
1098
+ delete(cacheKey: string | any[], key: string): Promise<boolean>;
1099
+ delete(key: string): Promise<boolean>;
1100
+ get<T extends Json<T> = any>(cacheKey: string | any[], key: string): Promise<T | undefined>;
1101
+ get<T extends Json<T> = any>(key: string): Promise<T | undefined>;
1102
+ has(cacheKey: string | any[], key: string): Promise<boolean>;
1103
+ has(key: string): Promise<boolean>;
1104
+ set<T extends Json<T>>(cacheKey: string | any[], key: string, value: T): Promise<T>;
1105
+ set<T extends Json<T>>(key: string, value: T): Promise<T>;
1106
+ }
321
1107
 
322
1108
  type HttpSourceEvent = {
323
1109
  url: string;
@@ -363,7 +1149,7 @@ type TriggerOptionsRecordWithEvent<TValue, TTriggerOptionDefinitions extends Rec
363
1149
  type TriggerOptionRecord<TValue, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
364
1150
  [K in keyof TTriggerOptionDefinitions]: TValue;
365
1151
  };
366
- type RegisterFunctionEvent<TChannel extends ChannelNames, TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
1152
+ type RegisterFunctionEvent$1<TChannel extends ChannelNames, TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
367
1153
  options: TriggerOptionDiffs<TTriggerOptionDefinitions>;
368
1154
  source: {
369
1155
  active: boolean;
@@ -378,14 +1164,14 @@ type RegisterSourceEvent<TTriggerOptionDefinitions extends Record<string, string
378
1164
  dynamicTriggerId?: string;
379
1165
  options: TriggerOptionDiffs<TTriggerOptionDefinitions>;
380
1166
  };
381
- type RegisterFunctionOutput<TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
1167
+ type RegisterFunctionOutput$1<TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
382
1168
  secret?: string;
383
1169
  data?: SerializableJson;
384
1170
  options: TriggerOptionsRecordWithEvent<string[], TTriggerOptionDefinitions>;
385
1171
  };
386
- type RegisterFunction<TIntegration extends TriggerIntegration, TParams extends any, TChannel extends ChannelNames, TTriggerOptionDefinitions extends Record<string, string[]> = any> = (event: RegisterFunctionEvent<TChannel, TParams, TTriggerOptionDefinitions>, io: IOWithIntegrations<{
1172
+ type RegisterFunction$1<TIntegration extends TriggerIntegration, TParams extends any, TChannel extends ChannelNames, TTriggerOptionDefinitions extends Record<string, string[]> = any> = (event: RegisterFunctionEvent$1<TChannel, TParams, TTriggerOptionDefinitions>, io: IOWithIntegrations<{
387
1173
  integration: TIntegration;
388
- }>, ctx: TriggerContext) => Promise<RegisterFunctionOutput<TTriggerOptionDefinitions> | undefined>;
1174
+ }>, ctx: TriggerContext) => Promise<RegisterFunctionOutput$1<TTriggerOptionDefinitions> | undefined>;
389
1175
  type HandlerEvent<TChannel extends ChannelNames, TParams extends any = any> = {
390
1176
  rawEvent: ExternalSourceChannelMap[TChannel]["event"];
391
1177
  source: Prettify<Omit<HandleTriggerSource, "params"> & {
@@ -397,18 +1183,18 @@ type HandlerFunction<TChannel extends ChannelNames, TParams extends any, TTrigge
397
1183
  response?: NormalizedResponse;
398
1184
  metadata?: HttpSourceResponseMetadata;
399
1185
  } | void>;
400
- type KeyFunction<TParams extends any> = (params: TParams) => string;
401
- type FilterFunction<TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = (params: TParams, options?: TTriggerOptionDefinitions) => EventFilter;
1186
+ type KeyFunction$1<TParams extends any> = (params: TParams) => string;
1187
+ type FilterFunction$1<TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = (params: TParams, options?: TTriggerOptionDefinitions) => EventFilter;
402
1188
  type ExternalSourceOptions<TChannel extends ChannelNames, TIntegration extends TriggerIntegration, TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
403
1189
  id: string;
404
1190
  version: string;
405
- schema: z.Schema<TParams>;
406
- optionSchema?: z.Schema<TTriggerOptionDefinitions>;
1191
+ schema: SchemaParser<TParams>;
1192
+ optionSchema?: SchemaParser<TTriggerOptionDefinitions>;
407
1193
  integration: TIntegration;
408
- register: RegisterFunction<TIntegration, TParams, TChannel, TTriggerOptionDefinitions>;
409
- filter?: FilterFunction<TParams, TTriggerOptionDefinitions>;
1194
+ register: RegisterFunction$1<TIntegration, TParams, TChannel, TTriggerOptionDefinitions>;
1195
+ filter?: FilterFunction$1<TParams, TTriggerOptionDefinitions>;
410
1196
  handler: HandlerFunction<TChannel, TParams, TIntegration>;
411
- key: KeyFunction<TParams>;
1197
+ key: KeyFunction$1<TParams>;
412
1198
  properties?: (params: TParams) => DisplayProperty[];
413
1199
  };
414
1200
  declare class ExternalSource<TIntegration extends TriggerIntegration, TParams extends any, TChannel extends ChannelNames = ChannelNames, TTriggerOptionDefinitions extends Record<string, string[]> = any> {
@@ -423,6 +1209,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration, TParams ex
423
1209
  id?: string | undefined;
424
1210
  timestamp?: Date | undefined;
425
1211
  source?: string | undefined;
1212
+ payloadType?: "JSON" | "REQUEST" | undefined;
426
1213
  }[];
427
1214
  response?: {
428
1215
  status: number;
@@ -433,7 +1220,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration, TParams ex
433
1220
  }>;
434
1221
  filter(params: TParams, options?: TTriggerOptionDefinitions): EventFilter;
435
1222
  properties(params: TParams): DisplayProperty[];
436
- register(params: TParams, registerEvent: RegisterSourceEvent<TTriggerOptionDefinitions>, io: IO, ctx: TriggerContext): Promise<RegisterFunctionOutput<TTriggerOptionDefinitions> | undefined>;
1223
+ register(params: TParams, registerEvent: RegisterSourceEvent<TTriggerOptionDefinitions>, io: IO, ctx: TriggerContext): Promise<RegisterFunctionOutput$1<TTriggerOptionDefinitions> | undefined>;
437
1224
  key(params: TParams): string;
438
1225
  get integration(): TIntegration;
439
1226
  get integrationConfig(): {
@@ -447,9 +1234,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration, TParams ex
447
1234
  get id(): string;
448
1235
  get version(): string;
449
1236
  }
450
- type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams & {
451
- filter?: EventFilter;
452
- } : never;
1237
+ type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams : never;
453
1238
  type ExternalSourceTriggerOptions<TEventSpecification extends EventSpecification<any>, TEventSource extends ExternalSource<any, any, any>, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
454
1239
  event: TEventSpecification;
455
1240
  source: TEventSource;
@@ -463,6 +1248,9 @@ declare class ExternalSourceTrigger<TEventSpecification extends EventSpecificati
463
1248
  toJSON(): TriggerMetadata;
464
1249
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
465
1250
  get preprocessRuns(): boolean;
1251
+ verifyPayload(payload: ReturnType<TEventSpecification["parsePayload"]>): Promise<{
1252
+ success: true;
1253
+ }>;
466
1254
  }
467
1255
  declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, key: K): {
468
1256
  result: Omit<T, K>;
@@ -480,7 +1268,7 @@ type DynamicTriggerOptions<TEventSpec extends EventSpecification<any>, TExternal
480
1268
  * ```ts
481
1269
  * import { events } from "@trigger.dev/github";
482
1270
  *
483
- * const dynamicOnIssueOpened = new DynamicTrigger(client, {
1271
+ * const dynamicOnIssueOpened = client.defineDynamicTrigger({
484
1272
  id: "github-issue-opened",
485
1273
  event: events.onIssueOpened,
486
1274
  source: github.sources.repo,
@@ -501,84 +1289,365 @@ declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExtern
501
1289
  toJSON(): TriggerMetadata;
502
1290
  get id(): string;
503
1291
  get event(): TEventSpec;
504
- registeredTriggerForParams(params: ExternalSourceParams<TExternalSource>): RegisterTriggerBodyV2;
505
1292
  /** Use this method to register a new configuration with the DynamicTrigger.
506
1293
  * @param key The key for the configuration. This will be used to identify the configuration when it is triggered.
507
1294
  * @param params The params for the configuration.
1295
+ * @param options Options for the configuration.
1296
+ * @param options.accountId The accountId to associate with the configuration.
1297
+ * @param options.filter The filter to use for the configuration.
1298
+ *
508
1299
  */
509
- register(key: string, params: ExternalSourceParams<TExternalSource>): Promise<RegisterSourceEventV2>;
1300
+ register(key: string, params: ExternalSourceParams<TExternalSource>, options?: {
1301
+ accountId?: string;
1302
+ filter?: EventFilter;
1303
+ }): Promise<RegisterSourceEventV2>;
510
1304
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
511
1305
  get preprocessRuns(): boolean;
1306
+ verifyPayload(payload: ReturnType<TEventSpec["parsePayload"]>): Promise<{
1307
+ success: true;
1308
+ }>;
512
1309
  }
513
1310
 
514
- type BackgroundTaskOptions<TPayload = any> = {
515
- id: string;
516
- name: string;
517
- version: string;
518
- schema?: z.Schema<TPayload>;
519
- logLevel?: LogLevel;
520
- cpu?: 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128;
521
- memory?: 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768;
522
- concurrency?: number;
523
- secrets?: {
524
- [key: string]: string;
1311
+ type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
1312
+ declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
1313
+ private options;
1314
+ constructor(options: IntervalOptions);
1315
+ get event(): {
1316
+ name: string;
1317
+ title: string;
1318
+ source: string;
1319
+ icon: string;
1320
+ examples: {
1321
+ id: string;
1322
+ name: string;
1323
+ icon: string;
1324
+ payload: {
1325
+ ts: string;
1326
+ lastTimestamp: string;
1327
+ };
1328
+ }[];
1329
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
1330
+ ts: Date;
1331
+ lastTimestamp?: Date | undefined;
1332
+ };
1333
+ properties: {
1334
+ label: string;
1335
+ text: string;
1336
+ }[];
525
1337
  };
526
- enabled?: boolean;
527
- run: (payload: TPayload) => Promise<any>;
528
- };
529
- declare class BackgroundTask<TPayload = any> {
530
- #private;
531
- readonly options: BackgroundTaskOptions<TPayload>;
532
- client: TriggerClient;
533
- constructor(client: TriggerClient, options: BackgroundTaskOptions<TPayload>);
534
- get id(): string;
535
- get enabled(): boolean;
536
- get name(): string;
537
- get schema(): z.ZodType<TPayload, z.ZodTypeDef, TPayload> | undefined;
538
- get version(): string;
539
- get logLevel(): LogLevel | undefined;
540
- invoke(key: string, payload: TPayload): Promise<any>;
541
- toJSON(): BackgroundTaskMetadata;
1338
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1339
+ get preprocessRuns(): boolean;
1340
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1341
+ success: true;
1342
+ }>;
1343
+ toJSON(): TriggerMetadata;
542
1344
  }
543
-
544
- type TriggerClientOptions = {
545
- /** The `id` property is used to uniquely identify the client.
546
- */
547
- id: string;
548
- /** The `apiKey` property is the API Key for your Trigger.dev environment. We
549
- recommend using an environment variable to store your API Key. */
550
- apiKey?: string;
551
- /** The `apiUrl` property is an optional property that specifies the API URL. You
552
- only need to specify this if you are not using Trigger.dev Cloud and are
553
- running your own Trigger.dev instance. */
554
- apiUrl?: string;
555
- /** The `logLevel` property is an optional property that specifies the level of
556
- logging for the TriggerClient. The level is inherited by all Jobs that use this Client, unless they also specify a `logLevel`. */
557
- logLevel?: LogLevel;
558
- /** Very verbose log messages, defaults to false. */
559
- verbose?: boolean;
560
- /** Default is unset and off. If set to true it will log to the server's console as well as the Trigger.dev platform */
561
- ioLogLocalEnabled?: boolean;
562
- };
563
- /** A [TriggerClient](https://trigger.dev/docs/documentation/concepts/client-adaptors) is used to connect to a specific [Project](https://trigger.dev/docs/documentation/concepts/projects) by using an [API Key](https://trigger.dev/docs/documentation/concepts/environments-apikeys). */
564
- declare class TriggerClient {
565
- #private;
566
- id: string;
567
- constructor(options: Prettify<TriggerClientOptions>);
568
- handleRequest(request: Request): Promise<NormalizedResponse>;
569
- attach(job: Job<Trigger<any>, any>): void;
570
- attachBackgroundTask(task: BackgroundTask<any>): void;
571
- attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
572
- attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
573
- attachSource(options: {
1345
+ /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
1346
+ * @param options An object containing options about the interval.
1347
+ */
1348
+ declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
1349
+ declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
1350
+ private options;
1351
+ constructor(options: CronOptions);
1352
+ get event(): {
1353
+ name: string;
1354
+ title: string;
1355
+ source: string;
1356
+ icon: string;
1357
+ examples: {
1358
+ id: string;
1359
+ name: string;
1360
+ icon: string;
1361
+ payload: {
1362
+ ts: string;
1363
+ lastTimestamp: string;
1364
+ };
1365
+ }[];
1366
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
1367
+ ts: Date;
1368
+ lastTimestamp?: Date | undefined;
1369
+ };
1370
+ properties: {
1371
+ label: string;
1372
+ text: string;
1373
+ }[];
1374
+ };
1375
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1376
+ get preprocessRuns(): boolean;
1377
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1378
+ success: true;
1379
+ }>;
1380
+ toJSON(): TriggerMetadata;
1381
+ }
1382
+ /** `cronTrigger()` is set as a [Job's trigger](https://trigger.dev/docs/sdk/job) to trigger a Job on a recurring schedule using a CRON expression.
1383
+ * @param options An object containing options about the CRON schedule.
1384
+ */
1385
+ declare function cronTrigger(options: CronOptions): CronTrigger;
1386
+ /** DynamicSchedule options
1387
+ * @param id Used to uniquely identify a DynamicSchedule
1388
+ */
1389
+ type DynamicIntervalOptions = {
1390
+ id: string;
1391
+ };
1392
+ /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
1393
+ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
1394
+ private client;
1395
+ private options;
1396
+ /**
1397
+ * @param client The `TriggerClient` instance to use for registering the trigger.
1398
+ * @param options The options for the schedule.
1399
+ */
1400
+ constructor(client: TriggerClient, options: DynamicIntervalOptions);
1401
+ get id(): string;
1402
+ get event(): {
1403
+ name: string;
1404
+ title: string;
1405
+ source: string;
1406
+ icon: string;
1407
+ examples: {
1408
+ id: string;
1409
+ name: string;
1410
+ icon: string;
1411
+ payload: {
1412
+ ts: string;
1413
+ lastTimestamp: string;
1414
+ };
1415
+ }[];
1416
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
1417
+ ts: Date;
1418
+ lastTimestamp?: Date | undefined;
1419
+ };
1420
+ };
1421
+ register(key: string, metadata: ScheduleMetadata): Promise<{
1422
+ id: string;
1423
+ schedule: {
1424
+ options: {
1425
+ cron: string;
1426
+ };
1427
+ type: "cron";
1428
+ accountId?: string | undefined;
1429
+ metadata?: any;
1430
+ } | {
1431
+ options: {
1432
+ seconds: number;
1433
+ };
1434
+ type: "interval";
1435
+ accountId?: string | undefined;
1436
+ metadata?: any;
1437
+ };
1438
+ active: boolean;
1439
+ metadata?: any;
1440
+ }>;
1441
+ unregister(key: string): Promise<{
1442
+ ok: boolean;
1443
+ }>;
1444
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1445
+ get preprocessRuns(): boolean;
1446
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1447
+ success: true;
1448
+ }>;
1449
+ toJSON(): TriggerMetadata;
1450
+ }
1451
+
1452
+ type WebhookCRUDContext<TParams extends any, TConfig extends Record<string, string[]>> = {
1453
+ active: boolean;
1454
+ params: TParams;
1455
+ config: {
1456
+ current: Partial<TConfig>;
1457
+ desired: TConfig;
1458
+ };
1459
+ url: string;
1460
+ secret: string;
1461
+ };
1462
+ type WebhookCRUDFunction<TIntegration extends TriggerIntegration, TParams extends any, TConfig extends Record<string, string[]>> = (options: {
1463
+ io: IOWithIntegrations<{
1464
+ integration: TIntegration;
1465
+ }>;
1466
+ ctx: WebhookCRUDContext<TParams, TConfig>;
1467
+ }) => Promise<any>;
1468
+ interface WebhookCRUD<TIntegration extends TriggerIntegration, TParams extends any, TConfig extends Record<string, string[]>> {
1469
+ create: WebhookCRUDFunction<TIntegration, TParams, TConfig>;
1470
+ read?: WebhookCRUDFunction<TIntegration, TParams, TConfig>;
1471
+ update?: WebhookCRUDFunction<TIntegration, TParams, TConfig>;
1472
+ delete: WebhookCRUDFunction<TIntegration, TParams, TConfig>;
1473
+ }
1474
+ type WebhookConfig<TConfigKeys extends string> = {
1475
+ [K in TConfigKeys]: string[];
1476
+ };
1477
+ type RegisterFunctionEvent<TParams extends any, TConfig extends Record<string, string[]>> = {
1478
+ source: {
1479
+ active: boolean;
1480
+ data?: any;
1481
+ secret: string;
1482
+ url: string;
1483
+ };
1484
+ params: TParams;
1485
+ config: TConfig;
1486
+ };
1487
+ type WebhookRegisterEvent<TConfig extends Record<string, string[]>> = {
1488
+ id: string;
1489
+ source: RegisterWebhookSource;
1490
+ dynamicTriggerId?: string;
1491
+ config: TConfig;
1492
+ };
1493
+ type RegisterFunctionOutput<TConfig extends Record<string, string[]>> = {
1494
+ secret?: string;
1495
+ data?: SerializableJson;
1496
+ config: TConfig;
1497
+ };
1498
+ type RegisterFunction<TIntegration extends TriggerIntegration, TParams extends any, TConfig extends Record<string, string[]>> = (event: RegisterFunctionEvent<TParams, TConfig>, io: IOWithIntegrations<{
1499
+ integration: TIntegration;
1500
+ }>, ctx: TriggerContext) => Promise<RegisterFunctionOutput<TConfig> | undefined>;
1501
+ type WebhookHandlerEvent<TParams extends any = any> = {
1502
+ rawEvent: Request;
1503
+ source: Prettify<Omit<HandleTriggerSource, "params"> & {
1504
+ params: TParams;
1505
+ }>;
1506
+ };
1507
+ type WebhookDeliveryContext = {
1508
+ key: string;
1509
+ secret: string;
1510
+ params: any;
1511
+ };
1512
+ type EventGenerator<TParams extends any, TConfig extends Record<string, string[]>, TIntegration extends TriggerIntegration> = (options: {
1513
+ request: Request;
1514
+ client: TriggerClient;
1515
+ ctx: WebhookDeliveryContext;
1516
+ }) => Promise<any>;
1517
+ type KeyFunction<TParams extends any> = (params: TParams) => string;
1518
+ type FilterFunction<TParams extends any, TConfig extends Record<string, string[]>> = (params: TParams, config?: TConfig) => EventFilter;
1519
+ type WebhookOptions<TIntegration extends TriggerIntegration, TParams extends any, TConfig extends Record<string, string[]>> = {
1520
+ id: string;
1521
+ version: string;
1522
+ integration: TIntegration;
1523
+ schemas: {
1524
+ params: SchemaParser<TParams>;
1525
+ config?: SchemaParser<TConfig>;
1526
+ };
1527
+ key: KeyFunction<TParams>;
1528
+ crud: WebhookCRUD<TIntegration, TParams, TConfig>;
1529
+ filter?: FilterFunction<TParams, TConfig>;
1530
+ register?: RegisterFunction<TIntegration, TParams, TConfig>;
1531
+ verify?: (options: {
1532
+ request: Request;
1533
+ client: TriggerClient;
1534
+ ctx: WebhookDeliveryContext;
1535
+ }) => Promise<VerifyResult>;
1536
+ generateEvents: EventGenerator<TParams, TConfig, TIntegration>;
1537
+ properties?: (params: TParams) => DisplayProperty[];
1538
+ };
1539
+ declare class WebhookSource<TIntegration extends TriggerIntegration, TParams extends any = any, TConfig extends Record<string, string[]> = Record<string, string[]>> {
1540
+ #private;
1541
+ private options;
1542
+ constructor(options: WebhookOptions<TIntegration, TParams, TConfig>);
1543
+ generateEvents(request: Request, client: TriggerClient, ctx: WebhookDeliveryContext): Promise<any>;
1544
+ filter(params: TParams, config?: TConfig): EventFilter;
1545
+ properties(params: TParams): DisplayProperty[];
1546
+ get crud(): WebhookCRUD<TIntegration, TParams, TConfig>;
1547
+ register(params: TParams, registerEvent: WebhookRegisterEvent<TConfig>, io: IO, ctx: TriggerContext): Promise<RegisterFunctionOutput<TConfig> | undefined>;
1548
+ verify(request: Request, client: TriggerClient, ctx: WebhookDeliveryContext): Promise<VerifyResult>;
1549
+ key(params: TParams): string;
1550
+ get integration(): TIntegration;
1551
+ get integrationConfig(): {
1552
+ id: string;
1553
+ metadata: {
1554
+ id: string;
1555
+ name: string;
1556
+ instructions?: string | undefined;
1557
+ };
1558
+ };
1559
+ get id(): string;
1560
+ get version(): string;
1561
+ }
1562
+ type GetWebhookParams<TWebhook extends WebhookSource<any, any, any>> = TWebhook extends WebhookSource<any, infer TParams, any> ? TParams : never;
1563
+ type GetWebhookConfig<TWebhook extends WebhookSource<any, any, any>> = TWebhook extends WebhookSource<any, any, infer TConfig> ? TConfig : never;
1564
+ type WebhookTriggerOptions<TEventSpecification extends EventSpecification<any>, TEventSource extends WebhookSource<any, any, any>, TConfig extends Record<string, string[]> = Record<string, string[]>> = {
1565
+ event: TEventSpecification;
1566
+ source: TEventSource;
1567
+ params: GetWebhookParams<TEventSource>;
1568
+ config: TConfig;
1569
+ };
1570
+ declare class WebhookTrigger<TEventSpecification extends EventSpecification<any>, TEventSource extends WebhookSource<any, any, any>> implements Trigger<TEventSpecification> {
1571
+ private options;
1572
+ constructor(options: WebhookTriggerOptions<TEventSpecification, TEventSource>);
1573
+ get event(): TEventSpecification;
1574
+ get source(): TEventSource;
1575
+ get key(): string;
1576
+ toJSON(): TriggerMetadata;
1577
+ filter(eventFilter: EventFilter): WebhookTrigger<Omit<TEventSpecification, "filter"> & {
1578
+ filter: EventFilter;
1579
+ }, TEventSource>;
1580
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
1581
+ get preprocessRuns(): boolean;
1582
+ verifyPayload(payload: ReturnType<TEventSpecification["parsePayload"]>): Promise<{
1583
+ success: true;
1584
+ }>;
1585
+ }
1586
+
1587
+ type TriggerClientOptions = {
1588
+ /** The `id` property is used to uniquely identify the client.
1589
+ */
1590
+ id: string;
1591
+ /** The `apiKey` property is the API Key for your Trigger.dev environment. We
1592
+ recommend using an environment variable to store your API Key. */
1593
+ apiKey?: string;
1594
+ /** The `apiUrl` property is an optional property that specifies the API URL. You
1595
+ only need to specify this if you are not using Trigger.dev Cloud and are
1596
+ running your own Trigger.dev instance. */
1597
+ apiUrl?: string;
1598
+ /** The `logLevel` property is an optional property that specifies the level of
1599
+ logging for the TriggerClient. The level is inherited by all Jobs that use this Client, unless they also specify a `logLevel`. */
1600
+ logLevel?: LogLevel;
1601
+ /** Very verbose log messages, defaults to false. */
1602
+ verbose?: boolean;
1603
+ /** Default is unset and off. If set to true it will log to the server's console as well as the Trigger.dev platform */
1604
+ ioLogLocalEnabled?: boolean;
1605
+ };
1606
+ type AuthResolverResult = {
1607
+ type: "apiKey" | "oauth";
1608
+ token: string;
1609
+ additionalFields?: Record<string, string>;
1610
+ };
1611
+ type TriggerAuthResolver = (ctx: TriggerContext, integration: TriggerIntegration) => Promise<AuthResolverResult | void | undefined>;
1612
+ /** A [TriggerClient](https://trigger.dev/docs/documentation/concepts/client-adaptors) is used to connect to a specific [Project](https://trigger.dev/docs/documentation/concepts/projects) by using an [API Key](https://trigger.dev/docs/documentation/concepts/environments-apikeys). */
1613
+ declare class TriggerClient {
1614
+ #private;
1615
+ id: string;
1616
+ constructor(options: Prettify<TriggerClientOptions>);
1617
+ on: <E extends keyof NotificationEvents>(event: E, listener: NotificationEvents[E]) => NotificationsEventEmitter;
1618
+ handleRequest(request: Request, timeOrigin?: number): Promise<NormalizedResponse>;
1619
+ defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any>(options: JobOptions<TTrigger, TIntegrations, TOutput>): Job<TTrigger, TIntegrations, TOutput>;
1620
+ defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
1621
+ defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
1622
+ defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
1623
+ /**
1624
+ * An [HTTP endpoint](https://trigger.dev/docs/documentation/concepts/http-endpoints) allows you to create a [HTTP Trigger](https://trigger.dev/docs/documentation/concepts/triggers/http), which means you can trigger your Jobs from any webhooks.
1625
+ * @param options The Endpoint options
1626
+ * @returns An HTTP Endpoint, that can be used to create an HTTP Trigger.
1627
+ * @link https://trigger.dev/docs/documentation/concepts/http-endpoints
1628
+ */
1629
+ defineHttpEndpoint(options: EndpointOptions, suppressWarnings?: boolean): HttpEndpoint<EventSpecification<Request, Request>>;
1630
+ defineConcurrencyLimit(options: ConcurrencyLimitOptions): ConcurrencyLimit;
1631
+ attach(job: Job<Trigger<any>, any>): void;
1632
+ attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
1633
+ attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
1634
+ attachSource(options: {
574
1635
  key: string;
575
1636
  source: ExternalSource<any, any>;
576
1637
  event: EventSpecification<any>;
577
1638
  params: any;
578
1639
  options?: Record<string, string[]>;
579
1640
  }): void;
580
- attachDynamicSchedule(key: string, job: Job<Trigger<any>, any>): void;
581
- registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
1641
+ attachDynamicSchedule(key: string): void;
1642
+ attachDynamicScheduleToJob(key: string, job: Job<Trigger<any>, any>): void;
1643
+ attachWebhook<TIntegration extends TriggerIntegration, TParams extends any, TConfig extends Record<string, string[]>>(options: {
1644
+ key: string;
1645
+ source: WebhookSource<TIntegration, TParams, TConfig>;
1646
+ event: EventSpecification<any>;
1647
+ params: any;
1648
+ config: TConfig;
1649
+ }): void;
1650
+ registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2, idempotencyKey?: string): Promise<{
582
1651
  id: string;
583
1652
  options: {
584
1653
  event: {
@@ -610,12 +1679,12 @@ declare class TriggerClient {
610
1679
  dynamicTriggerId?: string | undefined;
611
1680
  }>;
612
1681
  getAuth(id: string): Promise<{
613
- type: "oauth2";
1682
+ type: "oauth2" | "apiKey";
614
1683
  accessToken: string;
615
1684
  scopes?: string[] | undefined;
616
1685
  additionalFields?: Record<string, string> | undefined;
617
1686
  } | undefined>;
618
- /** You can call this function from anywhere in your code to send an event. The other way to send an event is by using [`io.sendEvent()`](https://trigger.dev/docs/sdk/io/sendevent) from inside a `run()` function.
1687
+ /** You can call this function from anywhere in your backend to send an event. The other way to send an event is by using [`io.sendEvent()`](https://trigger.dev/docs/sdk/io/sendevent) from inside a `run()` function.
619
1688
  * @param event The event to send.
620
1689
  * @param options Options for sending the event.
621
1690
  * @returns A promise that resolves to the event details
@@ -634,6 +1703,25 @@ declare class TriggerClient {
634
1703
  deliveredAt?: Date | null | undefined;
635
1704
  cancelledAt?: Date | null | undefined;
636
1705
  }>;
1706
+ /** You can call this function from anywhere in your backend to send multiple events. The other way to send multiple events is by using [`io.sendEvents()`](https://trigger.dev/docs/sdk/io/sendevents) from inside a `run()` function.
1707
+ * @param events The events to send.
1708
+ * @param options Options for sending the events.
1709
+ * @returns A promise that resolves to an array of event details
1710
+ */
1711
+ sendEvents(events: SendEvent[], options?: SendEventOptions): Promise<{
1712
+ id: string;
1713
+ name: string;
1714
+ payload: ((string | number | boolean | {
1715
+ [key: string]: DeserializedJson;
1716
+ } | DeserializedJson[]) & (string | number | boolean | {
1717
+ [key: string]: DeserializedJson;
1718
+ } | DeserializedJson[] | undefined)) | null;
1719
+ timestamp: Date;
1720
+ context?: DeserializedJson | undefined;
1721
+ deliverAt?: Date | null | undefined;
1722
+ deliveredAt?: Date | null | undefined;
1723
+ cancelledAt?: Date | null | undefined;
1724
+ }[]>;
637
1725
  cancelEvent(eventId: string): Promise<{
638
1726
  id: string;
639
1727
  name: string;
@@ -648,6 +1736,21 @@ declare class TriggerClient {
648
1736
  deliveredAt?: Date | null | undefined;
649
1737
  cancelledAt?: Date | null | undefined;
650
1738
  }>;
1739
+ cancelRunsForEvent(eventId: string): Promise<{
1740
+ cancelledRunIds: string[];
1741
+ failedToCancelRunIds: string[];
1742
+ }>;
1743
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
1744
+ label: string;
1745
+ key: string;
1746
+ history: {
1747
+ label?: string | undefined;
1748
+ state?: "loading" | "success" | "failure" | undefined;
1749
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1750
+ }[];
1751
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1752
+ state?: "loading" | "success" | "failure" | undefined;
1753
+ }>;
651
1754
  registerSchedule(id: string, key: string, schedule: ScheduleMetadata): Promise<{
652
1755
  id: string;
653
1756
  schedule: {
@@ -655,12 +1758,14 @@ declare class TriggerClient {
655
1758
  cron: string;
656
1759
  };
657
1760
  type: "cron";
1761
+ accountId?: string | undefined;
658
1762
  metadata?: any;
659
1763
  } | {
660
1764
  options: {
661
1765
  seconds: number;
662
1766
  };
663
1767
  type: "interval";
1768
+ accountId?: string | undefined;
664
1769
  metadata?: any;
665
1770
  };
666
1771
  active: boolean;
@@ -672,22 +1777,54 @@ declare class TriggerClient {
672
1777
  getEvent(eventId: string): Promise<{
673
1778
  id: string;
674
1779
  name: string;
675
- createdAt: Date;
676
1780
  updatedAt: Date;
677
1781
  runs: {
678
1782
  id: string;
679
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1783
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
680
1784
  startedAt?: Date | null | undefined;
681
1785
  completedAt?: Date | null | undefined;
682
1786
  }[];
1787
+ createdAt: Date;
683
1788
  }>;
684
1789
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
685
1790
  id: string;
686
1791
  startedAt: Date | null;
687
1792
  completedAt: Date | null;
688
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1793
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
1794
+ updatedAt: Date | null;
689
1795
  tasks: _trigger_dev_core.RunTaskWithSubtasks[];
1796
+ statuses: {
1797
+ label: string;
1798
+ key: string;
1799
+ history: {
1800
+ label?: string | undefined;
1801
+ state?: "loading" | "success" | "failure" | undefined;
1802
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1803
+ }[];
1804
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1805
+ state?: "loading" | "success" | "failure" | undefined;
1806
+ }[];
1807
+ output?: any;
1808
+ nextCursor?: string | undefined;
1809
+ }>;
1810
+ cancelRun(runId: string): Promise<{
1811
+ id: string;
1812
+ startedAt: Date | null;
1813
+ completedAt: Date | null;
1814
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
690
1815
  updatedAt: Date | null;
1816
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
1817
+ statuses: {
1818
+ label: string;
1819
+ key: string;
1820
+ history: {
1821
+ label?: string | undefined;
1822
+ state?: "loading" | "success" | "failure" | undefined;
1823
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1824
+ }[];
1825
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1826
+ state?: "loading" | "success" | "failure" | undefined;
1827
+ }[];
691
1828
  output?: any;
692
1829
  nextCursor?: string | undefined;
693
1830
  }>;
@@ -696,158 +1833,64 @@ declare class TriggerClient {
696
1833
  id: string;
697
1834
  startedAt: Date | null;
698
1835
  completedAt: Date | null;
699
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1836
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
700
1837
  updatedAt: Date | null;
701
1838
  }[];
702
1839
  nextCursor?: string | undefined;
703
1840
  }>;
704
- authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
705
- apiKey(): string | undefined;
706
- defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
707
- defineBackgroundTask<TPayload = any>(options: BackgroundTaskOptions<TPayload>): BackgroundTask<TPayload>;
708
- }
709
-
710
- type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
711
- declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
712
- private options;
713
- constructor(options: IntervalOptions);
714
- get event(): {
715
- name: string;
716
- title: string;
717
- source: string;
718
- icon: string;
719
- examples: {
720
- id: string;
721
- name: string;
722
- icon: string;
723
- payload: {
724
- ts: string;
725
- lastTimestamp: string;
726
- };
727
- }[];
728
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
729
- ts: Date;
730
- lastTimestamp?: Date | undefined;
731
- };
732
- properties: {
733
- label: string;
734
- text: string;
735
- }[];
736
- };
737
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
738
- get preprocessRuns(): boolean;
739
- toJSON(): TriggerMetadata;
740
- }
741
- /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
742
- * @param options An object containing options about the interval.
743
- */
744
- declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
745
- declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
746
- private options;
747
- constructor(options: CronOptions);
748
- get event(): {
749
- name: string;
750
- title: string;
751
- source: string;
752
- icon: string;
753
- examples: {
754
- id: string;
755
- name: string;
756
- icon: string;
757
- payload: {
758
- ts: string;
759
- lastTimestamp: string;
760
- };
761
- }[];
762
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
763
- ts: Date;
764
- lastTimestamp?: Date | undefined;
765
- };
766
- properties: {
1841
+ getRunStatuses(runId: string): Promise<{
1842
+ statuses: {
767
1843
  label: string;
768
- text: string;
1844
+ key: string;
1845
+ history: {
1846
+ label?: string | undefined;
1847
+ state?: "loading" | "success" | "failure" | undefined;
1848
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1849
+ }[];
1850
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1851
+ state?: "loading" | "success" | "failure" | undefined;
769
1852
  }[];
770
- };
771
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
772
- get preprocessRuns(): boolean;
773
- toJSON(): TriggerMetadata;
774
- }
775
- /** `cronTrigger()` is set as a [Job's trigger](https://trigger.dev/docs/sdk/job) to trigger a Job on a recurring schedule using a CRON expression.
776
- * @param options An object containing options about the CRON schedule.
777
- */
778
- declare function cronTrigger(options: CronOptions): CronTrigger;
779
- /** DynamicSchedule options
780
- * @param id Used to uniquely identify a DynamicSchedule
781
- */
782
- type DynamicIntervalOptions = {
783
- id: string;
784
- };
785
- /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
786
- declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
787
- private client;
788
- private options;
789
- /**
790
- * @param client The `TriggerClient` instance to use for registering the trigger.
791
- * @param options The options for the schedule.
792
- */
793
- constructor(client: TriggerClient, options: DynamicIntervalOptions);
794
- get id(): string;
795
- get event(): {
796
- name: string;
797
- title: string;
798
- source: string;
799
- icon: string;
800
- examples: {
1853
+ run: {
801
1854
  id: string;
802
- name: string;
803
- icon: string;
804
- payload: {
805
- ts: string;
806
- lastTimestamp: string;
807
- };
808
- }[];
809
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
810
- ts: Date;
811
- lastTimestamp?: Date | undefined;
1855
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
1856
+ output?: any;
812
1857
  };
813
- };
814
- register(key: string, metadata: ScheduleMetadata): Promise<{
1858
+ }>;
1859
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
815
1860
  id: string;
816
- schedule: {
817
- options: {
818
- cron: string;
819
- };
820
- type: "cron";
821
- metadata?: any;
822
- } | {
823
- options: {
824
- seconds: number;
825
- };
826
- type: "interval";
827
- metadata?: any;
828
- };
829
- active: boolean;
830
- metadata?: any;
831
1861
  }>;
832
- unregister(key: string): Promise<{
833
- ok: boolean;
1862
+ cancelRunsForJob(jobId: string): Promise<{
1863
+ cancelledRunIds: string[];
1864
+ failedToCancelRunIds: string[];
834
1865
  }>;
835
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
836
- get preprocessRuns(): boolean;
837
- toJSON(): TriggerMetadata;
1866
+ createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
1867
+ id: string;
1868
+ }>;
1869
+ get store(): {
1870
+ env: KeyValueStore;
1871
+ };
1872
+ authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
1873
+ apiKey(): string | undefined;
838
1874
  }
839
1875
 
840
1876
  type IOTask = ServerTask;
841
1877
  type IOOptions = {
842
1878
  id: string;
1879
+ jobId: string;
843
1880
  apiClient: ApiClient;
844
1881
  client: TriggerClient;
845
1882
  context: TriggerContext;
1883
+ timeOrigin: number;
846
1884
  logger?: Logger;
847
1885
  logLevel?: LogLevel;
848
1886
  jobLogger?: Logger;
849
1887
  jobLogLevel: LogLevel;
850
1888
  cachedTasks?: Array<CachedTask>;
1889
+ cachedTasksCursor?: string;
1890
+ yieldedExecutions?: Array<string>;
1891
+ noopTasksSet?: string;
1892
+ serverVersion?: string | null;
1893
+ executionTimeout?: number;
851
1894
  };
852
1895
  type JsonPrimitive = string | number | boolean | null | undefined | Date | symbol;
853
1896
  type JsonArray = Json[];
@@ -856,13 +1899,37 @@ type JsonRecord<T> = {
856
1899
  };
857
1900
  type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
858
1901
  type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
859
- retryAt: Date;
1902
+ retryAt?: Date;
860
1903
  error?: Error;
861
1904
  jitter?: number;
1905
+ skipRetrying?: boolean;
862
1906
  } | Error | undefined | void;
1907
+ type IOStats = {
1908
+ initialCachedTasks: number;
1909
+ lazyLoadedCachedTasks: number;
1910
+ executedTasks: number;
1911
+ cachedTaskHits: number;
1912
+ cachedTaskMisses: number;
1913
+ noopCachedTaskHits: number;
1914
+ noopCachedTaskMisses: number;
1915
+ };
1916
+ interface OutputSerializer {
1917
+ serialize(value: any): string;
1918
+ deserialize<T>(value: string): T;
1919
+ }
1920
+ declare class JSONOutputSerializer implements OutputSerializer {
1921
+ serialize(value: any): string;
1922
+ deserialize(value?: string): any;
1923
+ }
1924
+ type BackgroundFetchResponse<T> = {
1925
+ status: number;
1926
+ data: T;
1927
+ headers: Record<string, string>;
1928
+ };
863
1929
  declare class IO {
864
1930
  #private;
865
1931
  private _id;
1932
+ private _jobId;
866
1933
  private _apiClient;
867
1934
  private _triggerClient;
868
1935
  private _logger;
@@ -870,17 +1937,155 @@ declare class IO {
870
1937
  private _jobLogLevel;
871
1938
  private _cachedTasks;
872
1939
  private _taskStorage;
1940
+ private _cachedTasksCursor?;
873
1941
  private _context;
1942
+ private _yieldedExecutions;
1943
+ private _noopTasksBloomFilter;
1944
+ private _stats;
1945
+ private _serverVersion;
1946
+ private _timeOrigin;
1947
+ private _executionTimeout?;
1948
+ private _outputSerializer;
1949
+ private _visitedCacheKeys;
1950
+ private _envStore;
1951
+ private _jobStore;
1952
+ private _runStore;
1953
+ get stats(): IOStats;
874
1954
  constructor(options: IOOptions);
875
1955
  /** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
876
1956
  get logger(): IOLogger;
1957
+ /** `io.random()` is identical to `Math.random()` when called without options but ensures your random numbers are not regenerated on resume or retry. It will return a pseudo-random floating-point number between optional `min` (default: 0, inclusive) and `max` (default: 1, exclusive). Can optionally `round` to the nearest integer.
1958
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1959
+ * @param min Sets the lower bound (inclusive). Can't be higher than `max`.
1960
+ * @param max Sets the upper bound (exclusive). Can't be lower than `min`.
1961
+ * @param round Controls rounding to the nearest integer. Any `max` integer will become inclusive when enabled. Rounding with floating-point bounds may cause unexpected skew and boundary inclusivity.
1962
+ */
1963
+ random(cacheKey: string | any[], { min, max, round, }?: {
1964
+ min?: number;
1965
+ max?: number;
1966
+ round?: boolean;
1967
+ }): Promise<number>;
877
1968
  /** `io.wait()` waits for the specified amount of time before continuing the Job. Delays work even if you're on a serverless platform with timeouts, or if your server goes down. They utilize [resumability](https://trigger.dev/docs/documentation/concepts/resumability) to ensure that the Run can be resumed after the delay.
878
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1969
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
879
1970
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
880
1971
  */
881
- wait(key: string | any[], seconds: number): Promise<void>;
1972
+ wait(cacheKey: string | any[], seconds: number): Promise<void>;
1973
+ waitForEvent<T extends z.ZodTypeAny = z.ZodTypeAny>(cacheKey: string | any[], event: {
1974
+ name: string;
1975
+ schema?: T;
1976
+ filter?: EventFilter;
1977
+ source?: string;
1978
+ contextFilter?: EventFilter;
1979
+ accountId?: string;
1980
+ }, options?: {
1981
+ timeoutInSeconds?: number;
1982
+ }): Promise<WaitForEventResult<z.output<T>>>;
1983
+ /** `io.waitForRequest()` allows you to pause the execution of a run until the url provided in the callback is POSTed to.
1984
+ * This is useful for integrating with external services that require a callback URL to be provided, or if you want to be able to wait until an action is performed somewhere else in your system.
1985
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1986
+ * @param callback A callback function that will provide the unique URL to POST to.
1987
+ * @param options Options for the callback.
1988
+ * @param options.timeoutInSeconds How long to wait for the request to be POSTed to the callback URL before timing out. Defaults to 1hr.
1989
+ * @returns The POSTed request JSON body.
1990
+ * @example
1991
+ * ```ts
1992
+ const result = await io.waitForRequest<{ message: string }>(
1993
+ "wait-for-request",
1994
+ async (url, task) => {
1995
+ // Save the URL somewhere so you can POST to it later
1996
+ // Or send it to an external service that will POST to it
1997
+ },
1998
+ { timeoutInSeconds: 60 } // wait 60 seconds
1999
+ );
2000
+ * ```
2001
+ */
2002
+ waitForRequest<T extends Json<T> | unknown = unknown>(cacheKey: string | any[], callback: (url: string) => Promise<unknown>, options?: {
2003
+ timeoutInSeconds?: number;
2004
+ }): Promise<T>;
2005
+ /** `io.createStatus()` allows you to set a status with associated data during the Run. Statuses can be used by your UI using the react package
2006
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2007
+ * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
2008
+ * @returns a TriggerStatus object that you can call `update()` on, to update the status.
2009
+ * @example
2010
+ * ```ts
2011
+ * client.defineJob(
2012
+ //...
2013
+ run: async (payload, io, ctx) => {
2014
+ const generatingImages = await io.createStatus("generating-images", {
2015
+ label: "Generating Images",
2016
+ state: "loading",
2017
+ data: {
2018
+ progress: 0.1,
2019
+ },
2020
+ });
2021
+
2022
+ //...do stuff
2023
+
2024
+ await generatingImages.update("completed-generation", {
2025
+ label: "Generated images",
2026
+ state: "success",
2027
+ data: {
2028
+ progress: 1.0,
2029
+ urls: ["http://..."]
2030
+ },
2031
+ });
2032
+
2033
+ //...
2034
+ });
2035
+ * ```
2036
+ */
2037
+ createStatus(cacheKey: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
882
2038
  /** `io.backgroundFetch()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
883
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2039
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2040
+ * @param url The URL to fetch from.
2041
+ * @param requestInit The options for the request
2042
+ * @param retry The options for retrying the request if it fails
2043
+ * An object where the key is a status code pattern and the value is a retrying strategy.
2044
+ * Supported patterns are:
2045
+ * - Specific status codes: 429
2046
+ * - Ranges: 500-599
2047
+ * - Wildcards: 2xx, 3xx, 4xx, 5xx
2048
+ */
2049
+ backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, options?: {
2050
+ retry?: FetchRetryOptions;
2051
+ timeout?: FetchTimeoutOptions;
2052
+ }): Promise<TResponseData>;
2053
+ /** `io.backgroundPoll()` will fetch data from a URL on an interval. The actual `fetch` requests are performed on the Trigger.dev server, so you don't have to worry about serverless function timeouts.
2054
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2055
+ * @param params The options for the background poll
2056
+ * @param params.url The URL to fetch from.
2057
+ * @param params.requestInit The options for the request, like headers and method
2058
+ * @param params.responseFilter An [EventFilter](https://trigger.dev/docs/documentation/guides/event-filter) that allows you to specify when to stop polling.
2059
+ * @param params.interval The interval in seconds to poll the URL in seconds. Defaults to 10 seconds which is the minimum.
2060
+ * @param params.timeout The timeout in seconds for each request in seconds. Defaults to 10 minutes. Minimum is 60 seconds and max is 1 hour
2061
+ * @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
2062
+ * @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
2063
+ * @param params.requestTimeout.durationInMs The duration in milliseconds to timeout the request
2064
+ *
2065
+ * @example
2066
+ * ```ts
2067
+ * const result = await io.backgroundPoll<{ id: string; status: string; }>("poll", {
2068
+ url: `http://localhost:3030/api/v1/runs/${run.id}`,
2069
+ requestInit: {
2070
+ headers: {
2071
+ Accept: "application/json",
2072
+ Authorization: redactString`Bearer ${process.env["TRIGGER_API_KEY"]!}`,
2073
+ },
2074
+ },
2075
+ interval: 10,
2076
+ timeout: 600,
2077
+ responseFilter: {
2078
+ status: [200],
2079
+ body: {
2080
+ status: ["SUCCESS"],
2081
+ },
2082
+ },
2083
+ });
2084
+ * ```
2085
+ */
2086
+ backgroundPoll<TResponseData>(cacheKey: string | any[], params: FetchPollOperation): Promise<TResponseData>;
2087
+ /** `io.backgroundFetchResponse()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
2088
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
884
2089
  * @param url The URL to fetch from.
885
2090
  * @param requestInit The options for the request
886
2091
  * @param retry The options for retrying the request if it fails
@@ -890,13 +2095,16 @@ declare class IO {
890
2095
  * - Ranges: 500-599
891
2096
  * - Wildcards: 2xx, 3xx, 4xx, 5xx
892
2097
  */
893
- backgroundFetch<TResponseData>(key: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
894
- /** `io.sendEvent()` allows you to send an event from inside a Job run. The sent even will trigger any Jobs that are listening for that event (based on the name).
895
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2098
+ backgroundFetchResponse<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, options?: {
2099
+ retry?: FetchRetryOptions;
2100
+ timeout?: FetchTimeoutOptions;
2101
+ }): Promise<BackgroundFetchResponse<TResponseData>>;
2102
+ /** `io.sendEvent()` allows you to send an event from inside a Job run. The sent event will trigger any Jobs that are listening for that event (based on the name).
2103
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
896
2104
  * @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
897
2105
  * @param options Options for sending the event.
898
2106
  */
899
- sendEvent(key: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
2107
+ sendEvent(cacheKey: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
900
2108
  id: string;
901
2109
  name: string;
902
2110
  payload: ((string | number | boolean | {
@@ -910,24 +2118,43 @@ declare class IO {
910
2118
  deliveredAt?: Date | null | undefined;
911
2119
  cancelledAt?: Date | null | undefined;
912
2120
  }>;
913
- getEvent(key: string | any[], id: string): Promise<{
2121
+ /** `io.sendEvents()` allows you to send multiple events from inside a Job run. The sent events will trigger any Jobs that are listening for those events (based on the name).
2122
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2123
+ * @param event The events to send. The event names must match the names of the events that your Jobs are listening for.
2124
+ * @param options Options for sending the events.
2125
+ */
2126
+ sendEvents(cacheKey: string | any[], events: SendEvent[], options?: SendEventOptions): Promise<{
2127
+ id: string;
2128
+ name: string;
2129
+ payload: ((string | number | boolean | {
2130
+ [key: string]: _trigger_dev_core.DeserializedJson;
2131
+ } | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
2132
+ [key: string]: _trigger_dev_core.DeserializedJson;
2133
+ } | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
2134
+ timestamp: Date;
2135
+ context?: _trigger_dev_core.DeserializedJson | undefined;
2136
+ deliverAt?: Date | null | undefined;
2137
+ deliveredAt?: Date | null | undefined;
2138
+ cancelledAt?: Date | null | undefined;
2139
+ }[]>;
2140
+ getEvent(cacheKey: string | any[], id: string): Promise<{
914
2141
  id: string;
915
2142
  name: string;
916
- createdAt: Date;
917
2143
  updatedAt: Date;
918
2144
  runs: {
919
2145
  id: string;
920
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
2146
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
921
2147
  startedAt?: Date | null | undefined;
922
2148
  completedAt?: Date | null | undefined;
923
2149
  }[];
2150
+ createdAt: Date;
924
2151
  }>;
925
2152
  /** `io.cancelEvent()` allows you to cancel an event that was previously sent with `io.sendEvent()`. This will prevent any Jobs from running that are listening for that event if the event was sent with a delay
926
- * @param key
2153
+ * @param cacheKey
927
2154
  * @param eventId
928
2155
  * @returns
929
2156
  */
930
- cancelEvent(key: string | any[], eventId: string): Promise<{
2157
+ cancelEvent(cacheKey: string | any[], eventId: string): Promise<{
931
2158
  id: string;
932
2159
  name: string;
933
2160
  payload: ((string | number | boolean | {
@@ -941,104 +2168,135 @@ declare class IO {
941
2168
  deliveredAt?: Date | null | undefined;
942
2169
  cancelledAt?: Date | null | undefined;
943
2170
  }>;
944
- updateSource(key: string | any[], options: {
2171
+ updateSource(cacheKey: string | any[], options: {
945
2172
  key: string;
946
2173
  } & UpdateTriggerSourceBodyV2): Promise<{
947
2174
  id: string;
948
2175
  key: string;
949
2176
  }>;
2177
+ updateWebhook(cacheKey: string | any[], options: {
2178
+ key: string;
2179
+ } & UpdateWebhookBody): Promise<{
2180
+ id: string;
2181
+ key: string;
2182
+ }>;
950
2183
  /** `io.registerInterval()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular interval.
951
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2184
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
952
2185
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
953
2186
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
954
2187
  * @param options The options for the interval.
955
2188
  * @returns A promise that has information about the interval.
2189
+ * @deprecated Use `DynamicSchedule.register` instead.
956
2190
  */
957
- registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
2191
+ registerInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
958
2192
  id: string;
959
2193
  schedule: {
960
2194
  options: {
961
2195
  cron: string;
962
2196
  };
963
2197
  type: "cron";
2198
+ accountId?: string | undefined;
964
2199
  metadata?: any;
965
2200
  } | {
966
2201
  options: {
967
2202
  seconds: number;
968
2203
  };
969
2204
  type: "interval";
2205
+ accountId?: string | undefined;
970
2206
  metadata?: any;
971
2207
  };
972
2208
  active: boolean;
973
2209
  metadata?: any;
974
2210
  }>;
975
2211
  /** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
976
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2212
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
977
2213
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
978
2214
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
2215
+ * @deprecated Use `DynamicSchedule.unregister` instead.
979
2216
  */
980
- unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
2217
+ unregisterInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
981
2218
  ok: boolean;
982
2219
  }>;
983
2220
  /** `io.registerCron()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular CRON schedule.
984
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2221
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
985
2222
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
986
2223
  * @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
987
2224
  * @param options The options for the CRON schedule.
2225
+ * @deprecated Use `DynamicSchedule.register` instead.
988
2226
  */
989
- registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
2227
+ registerCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
990
2228
  id: string;
991
2229
  schedule: {
992
2230
  options: {
993
2231
  cron: string;
994
2232
  };
995
2233
  type: "cron";
2234
+ accountId?: string | undefined;
996
2235
  metadata?: any;
997
2236
  } | {
998
2237
  options: {
999
2238
  seconds: number;
1000
2239
  };
1001
2240
  type: "interval";
2241
+ accountId?: string | undefined;
1002
2242
  metadata?: any;
1003
2243
  };
1004
2244
  active: boolean;
1005
2245
  metadata?: any;
1006
2246
  }>;
1007
2247
  /** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
1008
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2248
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1009
2249
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
1010
2250
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
2251
+ * @deprecated Use `DynamicSchedule.unregister` instead.
1011
2252
  */
1012
- unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
2253
+ unregisterCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1013
2254
  ok: boolean;
1014
2255
  }>;
1015
2256
  /** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
1016
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2257
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1017
2258
  * @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
1018
2259
  * @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
1019
2260
  * @param params The params for the trigger.
2261
+ * @deprecated Use `DynamicTrigger.register` instead.
1020
2262
  */
1021
- registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
2263
+ registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(cacheKey: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
1022
2264
  id: string;
1023
2265
  key: string;
1024
2266
  } | undefined>;
1025
- getAuth(key: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
2267
+ getAuth(cacheKey: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
2268
+ parallel<T extends Json<T> | void, TItem>(cacheKey: string | any[], items: Array<TItem>, callback: (item: TItem, index: number) => Promise<T>, options?: Pick<RunTaskOptions, "name" | "properties">): Promise<Array<T>>;
1026
2269
  /** `io.runTask()` allows you to run a [Task](https://trigger.dev/docs/documentation/concepts/tasks) from inside a Job run. A Task is a resumable unit of a Run that can be retried, resumed and is logged. [Integrations](https://trigger.dev/docs/integrations) use Tasks internally to perform their actions.
1027
2270
  *
1028
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
2271
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1029
2272
  * @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
1030
2273
  * @param options The options of how you'd like to run and log the Task.
1031
2274
  * @param onError The callback that will be called when the Task fails. The callback receives the error, the Task and the IO as parameters. If you wish to retry then return an object with a `retryAt` property.
1032
2275
  * @returns A Promise that resolves with the returned value of the callback.
1033
2276
  */
1034
- runTask<T extends Json<T> | void>(key: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
1035
- /** `io.try()` allows you to run Tasks and catch any errors that are thrown, it's similar to a normal `try/catch` block but works with [io.runTask()](/sdk/io/runtask).
2277
+ runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions & {
2278
+ parseOutput?: (output: unknown) => T;
2279
+ }, onError?: RunTaskErrorCallback): Promise<T>;
2280
+ /**
2281
+ * `io.yield()` allows you to yield execution of the current run and resume it in a new function execution. Similar to `io.wait()` but does not create a task and resumes execution immediately.
2282
+ */
2283
+ yield(cacheKey: string): void;
2284
+ /**
2285
+ * `io.brb()` is an alias of `io.yield()`
2286
+ */
2287
+ brb: (cacheKey: string) => void;
2288
+ /** `io.try()` allows you to run Tasks and catch any errors that are thrown, it's similar to a normal `try/catch` block but works with [io.runTask()](https://trigger.dev/docs/sdk/io/runtask).
1036
2289
  * A regular `try/catch` block on its own won't work as expected with Tasks. Internally `runTask()` throws some special errors to control flow execution. This is necessary to deal with resumability, serverless timeouts, and retrying Tasks.
1037
2290
  * @param tryCallback The code you wish to run
1038
2291
  * @param catchCallback Thhis will be called if the Task fails. The callback receives the error
1039
2292
  * @returns A Promise that resolves with the returned value or the error
1040
2293
  */
1041
2294
  try<TResult, TCatchResult>(tryCallback: () => Promise<TResult>, catchCallback: (error: unknown) => Promise<TCatchResult>): Promise<TResult | TCatchResult>;
2295
+ get store(): {
2296
+ env: KeyValueStore;
2297
+ job: KeyValueStore;
2298
+ run: KeyValueStore;
2299
+ };
1042
2300
  }
1043
2301
  type CallbackFunction = (level: "DEBUG" | "INFO" | "WARN" | "ERROR" | "LOG", message: string, properties?: Record<string, any>) => Promise<void>;
1044
2302
  declare class IOLogger implements TaskLogger {
@@ -1065,7 +2323,7 @@ interface TriggerIntegration {
1065
2323
  type IOWithIntegrations<TIntegrations extends Record<string, TriggerIntegration>> = IO & TIntegrations;
1066
2324
  type IntegrationTaskKey = string | any[];
1067
2325
 
1068
- type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> = {
2326
+ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> = {
1069
2327
  /** The `id` property is used to uniquely identify the Job. Only change this if you want to create a new Job. */
1070
2328
  id: string;
1071
2329
  /** The `name` of the Job that you want to appear in the dashboard and logs. You can change this without creating a new Job. */
@@ -1100,9 +2358,15 @@ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations
1100
2358
  });
1101
2359
  ``` */
1102
2360
  integrations?: TIntegrations;
1103
- /** @deprecated This property is deprecated and no longer effects the execution of the Job
1104
- * */
1105
- queue?: QueueOptions | string;
2361
+ /**
2362
+ * The `concurrencyLimit` property is used to limit the number of concurrent run executions of a job.
2363
+ * Can be a number which represents the limit or a `ConcurrencyLimit` instance which can be used to
2364
+ * group together multiple jobs to share the same concurrency limit.
2365
+ *
2366
+ * If undefined the job will be limited only by the server's global concurrency limit, or if you are using the
2367
+ * Trigger.dev Cloud service, the concurrency limit of your plan.
2368
+ */
2369
+ concurrencyLimit?: number | ConcurrencyLimit;
1106
2370
  /** The `enabled` property is used to enable or disable the Job. If you disable a Job, it will not run. */
1107
2371
  enabled?: boolean;
1108
2372
  /** This function gets called automatically when a Run is Triggered.
@@ -1111,27 +2375,43 @@ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations
1111
2375
  * @param io An object that contains the integrations that you specified in the `integrations` property and other useful functions like delays and running Tasks.
1112
2376
  * @param context An object that contains information about the Organization, Job, Run and more.
1113
2377
  */
1114
- run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<any>;
2378
+ run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<TOutput>;
2379
+ onSuccess?: (notification: SuccessfulRunNotification<TOutput, TriggerEventType<TTrigger>>) => void;
2380
+ onFailure?: (notification: FailedRunNotification<TriggerEventType<TTrigger>>) => void;
1115
2381
  };
1116
2382
  type JobPayload<TJob> = TJob extends Job<Trigger<EventSpecification<infer TEvent>>, any> ? TEvent : never;
1117
2383
  type JobIO<TJob> = TJob extends Job<any, infer TIntegrations> ? IOWithIntegrations<TIntegrations> : never;
1118
2384
  /** A [Job](https://trigger.dev/docs/documentation/concepts/jobs) is used to define the [Trigger](https://trigger.dev/docs/documentation/concepts/triggers), metadata, and what happens when it runs. */
1119
- declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> {
2385
+ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> {
1120
2386
  #private;
1121
- readonly options: JobOptions<TTrigger, TIntegrations>;
1122
- client: TriggerClient;
1123
- constructor(
1124
- /** An instance of [TriggerClient](/sdk/triggerclient) that is used to send events
1125
- to the Trigger API. */
1126
- client: TriggerClient, options: JobOptions<TTrigger, TIntegrations>);
2387
+ readonly options: JobOptions<TTrigger, TIntegrations, TOutput>;
2388
+ client?: TriggerClient;
2389
+ constructor(options: JobOptions<TTrigger, TIntegrations, TOutput>);
2390
+ /**
2391
+ * Attaches the job to a client. This is called automatically when you define a job using `client.defineJob()`.
2392
+ */
2393
+ attachToClient(client: TriggerClient): this;
1127
2394
  get id(): string;
1128
2395
  get enabled(): boolean;
1129
2396
  get name(): string;
1130
2397
  get trigger(): TTrigger;
1131
2398
  get version(): string;
1132
- get integrations(): Record<string, IntegrationConfig>;
1133
2399
  get logLevel(): LogLevel | undefined;
2400
+ get integrations(): Record<string, IntegrationConfig>;
1134
2401
  toJSON(): JobMetadata;
2402
+ invoke(cacheKey: string, payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
2403
+ id: string;
2404
+ }>;
2405
+ invoke(payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
2406
+ id: string;
2407
+ }>;
2408
+ invokeAndWaitForCompletion(cacheKey: string | string[], payload: TriggerInvokeType<TTrigger>, timeoutInSeconds?: number, // 1 hour
2409
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>): Promise<RunNotification<TOutput>>;
2410
+ batchInvokeAndWaitForCompletion(cacheKey: string | string[], batch: Array<{
2411
+ payload: TriggerInvokeType<TTrigger>;
2412
+ timeoutInSeconds?: number;
2413
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>;
2414
+ }>): Promise<Array<RunNotification<TOutput>>>;
1135
2415
  }
1136
2416
 
1137
2417
  type EventTriggerOptions<TEventSpecification extends EventSpecification<any>> = {
@@ -1139,6 +2419,7 @@ type EventTriggerOptions<TEventSpecification extends EventSpecification<any>> =
1139
2419
  name?: string | string[];
1140
2420
  source?: string;
1141
2421
  filter?: EventFilter;
2422
+ verify?: EventTypeFromSpecification<TEventSpecification> extends Request ? VerifyCallback : never;
1142
2423
  };
1143
2424
  declare class EventTrigger<TEventSpecification extends EventSpecification<any>> implements Trigger<TEventSpecification> {
1144
2425
  #private;
@@ -1147,6 +2428,7 @@ declare class EventTrigger<TEventSpecification extends EventSpecification<any>>
1147
2428
  get event(): TEventSpecification;
1148
2429
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
1149
2430
  get preprocessRuns(): boolean;
2431
+ verifyPayload(payload: ReturnType<TEventSpecification["parsePayload"]>): Promise<VerifyResult>;
1150
2432
  }
1151
2433
  /** Configuration options for an EventTrigger */
1152
2434
  type TriggerOptions<TEvent> = {
@@ -1155,7 +2437,7 @@ type TriggerOptions<TEvent> = {
1155
2437
  /** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
1156
2438
  * The default is `z.any()` which is `any`.
1157
2439
  * */
1158
- schema?: z.Schema<TEvent>;
2440
+ schema?: SchemaParser<TEvent>;
1159
2441
  /** You can use this to filter events based on the source. */
1160
2442
  source?: string;
1161
2443
  /** Used to filter which events trigger the Job
@@ -1206,8 +2488,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1206
2488
  id: string;
1207
2489
  scopes: string[];
1208
2490
  title: string;
1209
- createdAt: Date;
1210
2491
  updatedAt: Date;
2492
+ createdAt: Date;
1211
2493
  };
1212
2494
  authorizationUrl: string;
1213
2495
  } | {
@@ -1221,8 +2503,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1221
2503
  id: string;
1222
2504
  scopes: string[];
1223
2505
  title: string;
1224
- createdAt: Date;
1225
2506
  updatedAt: Date;
2507
+ createdAt: Date;
1226
2508
  };
1227
2509
  authorizationUrl: string;
1228
2510
  };
@@ -1233,6 +2515,9 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1233
2515
  };
1234
2516
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<MissingConnectionNotificationSpecification>, any>): void;
1235
2517
  get preprocessRuns(): boolean;
2518
+ verifyPayload(payload: ReturnType<MissingConnectionNotificationSpecification["parsePayload"]>): Promise<{
2519
+ success: true;
2520
+ }>;
1236
2521
  toJSON(): TriggerMetadata;
1237
2522
  }
1238
2523
  type MissingConnectionResolvedNotificationSpecification = EventSpecification<MissingConnectionResolvedNotificationPayload>;
@@ -1251,8 +2536,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1251
2536
  id: string;
1252
2537
  scopes: string[];
1253
2538
  title: string;
1254
- createdAt: Date;
1255
2539
  updatedAt: Date;
2540
+ createdAt: Date;
1256
2541
  integrationIdentifier: string;
1257
2542
  integrationAuthMethod: string;
1258
2543
  };
@@ -1268,8 +2553,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1268
2553
  id: string;
1269
2554
  scopes: string[];
1270
2555
  title: string;
1271
- createdAt: Date;
1272
2556
  updatedAt: Date;
2557
+ createdAt: Date;
1273
2558
  integrationIdentifier: string;
1274
2559
  integrationAuthMethod: string;
1275
2560
  };
@@ -1282,13 +2567,74 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1282
2567
  };
1283
2568
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<MissingConnectionResolvedNotificationSpecification>, any>): void;
1284
2569
  get preprocessRuns(): boolean;
2570
+ verifyPayload(payload: ReturnType<MissingConnectionResolvedNotificationSpecification["parsePayload"]>): Promise<{
2571
+ success: true;
2572
+ }>;
1285
2573
  toJSON(): TriggerMetadata;
1286
2574
  }
1287
2575
 
2576
+ /** Configuration options for an InvokeTrigger */
2577
+ type InvokeTriggerOptions<TSchema extends ZodType = z.ZodTypeAny> = {
2578
+ /** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
2579
+ * The default is `z.any()` which is `any`.
2580
+ * */
2581
+ schema?: TSchema;
2582
+ examples?: EventSpecificationExample[];
2583
+ };
2584
+ declare class InvokeTrigger<TSchema extends ZodType = z.ZodTypeAny> implements Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>> {
2585
+ #private;
2586
+ constructor(options: InvokeTriggerOptions<TSchema>);
2587
+ toJSON(): TriggerMetadata;
2588
+ get event(): {
2589
+ name: string;
2590
+ title: string;
2591
+ source: string;
2592
+ examples: {
2593
+ id: string;
2594
+ name: string;
2595
+ icon?: string | undefined;
2596
+ payload?: any;
2597
+ }[];
2598
+ icon: string;
2599
+ parsePayload: (rawPayload: unknown) => any;
2600
+ parseInvokePayload: (rawPayload: unknown) => any;
2601
+ };
2602
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<EventSpecification<ZodType<TSchema>>>, any>): void;
2603
+ get preprocessRuns(): boolean;
2604
+ verifyPayload(): Promise<{
2605
+ success: true;
2606
+ }>;
2607
+ }
2608
+ declare function invokeTrigger<TSchema extends ZodType = z.ZodTypeAny>(options?: InvokeTriggerOptions<TSchema>): Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>>;
2609
+
2610
+ declare function slugifyId(input: string): string;
2611
+
2612
+ /** Easily verify webhook payloads when they're using common signing methods. */
2613
+ declare function verifyRequestSignature({ request, headerName, headerEncoding, secret, algorithm, }: {
2614
+ /** The web request that you want to verify. */
2615
+ request: Request;
2616
+ /** The name of the header that contains the signature. E.g. `X-Cal-Signature-256`. */
2617
+ headerName: string;
2618
+ /** The header encoding. Defaults to `hex`. */
2619
+ headerEncoding?: BinaryToTextEncoding;
2620
+ /** The secret that you use to hash the payload. For HttpEndpoints this will usually originally
2621
+ come from the Trigger.dev dashboard and should be stored in an environment variable. */
2622
+ secret: BinaryLike | KeyObject;
2623
+ /** The hashing algorithm that was used to create the signature. Currently only `sha256` is
2624
+ supported. */
2625
+ algorithm: "sha256";
2626
+ }): Promise<VerifyResult>;
2627
+ declare function verifyHmacSha256(headerValue: string, headerEncoding: BinaryToTextEncoding, secret: BinaryLike | KeyObject, body: string): boolean;
2628
+
1288
2629
  declare class ResumeWithTaskError {
1289
2630
  task: ServerTask;
1290
2631
  constructor(task: ServerTask);
1291
2632
  }
2633
+ declare class ResumeWithParallelTaskError {
2634
+ task: ServerTask;
2635
+ childErrors: Array<TriggerInternalError>;
2636
+ constructor(task: ServerTask, childErrors: Array<TriggerInternalError>);
2637
+ }
1292
2638
  declare class RetryWithTaskError {
1293
2639
  cause: ErrorWithStack;
1294
2640
  task: ServerTask;
@@ -1299,13 +2645,39 @@ declare class CanceledWithTaskError {
1299
2645
  task: ServerTask;
1300
2646
  constructor(task: ServerTask);
1301
2647
  }
2648
+ declare class YieldExecutionError {
2649
+ key: string;
2650
+ constructor(key: string);
2651
+ }
2652
+ declare class AutoYieldExecutionError {
2653
+ location: string;
2654
+ timeRemaining: number;
2655
+ timeElapsed: number;
2656
+ constructor(location: string, timeRemaining: number, timeElapsed: number);
2657
+ }
2658
+ declare class AutoYieldWithCompletedTaskExecutionError {
2659
+ id: string;
2660
+ properties: DisplayProperty[] | undefined;
2661
+ data: {
2662
+ location: string;
2663
+ timeRemaining: number;
2664
+ timeElapsed: number;
2665
+ };
2666
+ output?: string | undefined;
2667
+ constructor(id: string, properties: DisplayProperty[] | undefined, data: {
2668
+ location: string;
2669
+ timeRemaining: number;
2670
+ timeElapsed: number;
2671
+ }, output?: string | undefined);
2672
+ }
2673
+ type TriggerInternalError = ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError | YieldExecutionError | AutoYieldExecutionError | AutoYieldWithCompletedTaskExecutionError | ResumeWithParallelTaskError;
1302
2674
  /** Use this function if you're using a `try/catch` block to catch errors.
1303
2675
  * It checks if a thrown error is a special internal error that you should ignore.
1304
2676
  * If this returns `true` then you must rethrow the error: `throw err;`
1305
2677
  * @param err The error to check
1306
2678
  * @returns `true` if the error is a Trigger Error, `false` otherwise.
1307
2679
  */
1308
- declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError;
2680
+ declare function isTriggerError(err: unknown): err is TriggerInternalError;
1309
2681
 
1310
2682
  declare const retry: {
1311
2683
  readonly standardBackoff: {
@@ -1315,6 +2687,13 @@ declare const retry: {
1315
2687
  readonly maxTimeoutInMs: 30000;
1316
2688
  readonly randomize: true;
1317
2689
  };
2690
+ readonly exponentialBackoff: {
2691
+ readonly limit: 8;
2692
+ readonly factor: 2;
2693
+ readonly minTimeoutInMs: 1000;
2694
+ readonly maxTimeoutInMs: 30000;
2695
+ readonly randomize: true;
2696
+ };
1318
2697
  };
1319
2698
 
1320
2699
  type Task = ServerTask;
@@ -1322,4 +2701,4 @@ type Task = ServerTask;
1322
2701
  type SentEvent = ApiEventLog;
1323
2702
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1324
2703
 
1325
- export { CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventSpecification, EventSpecificationExample, EventTrigger, EventTypeFromSpecification, ExternalSource, ExternalSourceParams, ExternalSourceTrigger, ExternalSourceTriggerOptions, HandlerEvent, HttpSourceEvent, IO, IOLogger, IOOptions, IOTask, IOWithIntegrations, IntegrationTaskKey, IntervalTrigger, Job, JobIO, JobOptions, JobPayload, Json, MissingConnectionNotification, MissingConnectionResolvedNotification, PreprocessResults, RunTaskErrorCallback, SentEvent, Task, TaskLogger, Trigger, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerOptionRecord, TriggerPayload, TriggerPreprocessContext, cronTrigger, eventTrigger, intervalTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry };
2704
+ export { type AuthResolverResult, type BackgroundFetchResponse, CronTrigger, type DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, type DynamicTriggerOptions, type EventSpecification, type EventSpecificationExample, EventSpecificationExampleSchema, EventTrigger, type EventTypeFromSpecification, ExternalSource, type ExternalSourceParams, ExternalSourceTrigger, type ExternalSourceTriggerOptions, type GetWebhookConfig, type GetWebhookParams, type HandlerEvent, type HttpSourceEvent, IO, IOLogger, type IOOptions, type IOStats, type IOTask, type IOWithIntegrations, type IntegrationTaskKey, IntervalTrigger, InvokeTrigger, JSONOutputSerializer, Job, type JobIO, type JobOptions, type JobPayload, type Json, MissingConnectionNotification, MissingConnectionResolvedNotification, type NotificationEvents, type NotificationsEventEmitter, type OutputSerializer, type PreprocessResults, type RunTaskErrorCallback, type SchemaParser, type SchemaParserIssue, type SchemaParserResult, type SentEvent, type Task, type TaskLogger, type Trigger, type TriggerAuthResolver, TriggerClient, type TriggerClientOptions, type TriggerContext, type TriggerEventType, type TriggerIntegration, type TriggerInvokeType, type TriggerOptionRecord, type TriggerPayload, type TriggerPreprocessContext, type TypedEventSpecificationExample, type VerifyResult, type WaitForEventResult, type WebhookConfig, type WebhookDeliveryContext, type WebhookHandlerEvent, WebhookSource, WebhookTrigger, type WebhookTriggerOptions, cronTrigger, eventTrigger, intervalTrigger, invokeTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry, slugifyId, verifyHmacSha256, verifyRequestSignature, waitForEventSchema };