@trigger.dev/sdk 0.0.0-isomorphic-sdk-20230918150523 → 0.0.0-node-18-20231010094401

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,5 +1,5 @@
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, DeserializedJson, IntervalOptions, CronOptions, ScheduledPayload, ServerTask, CachedTask, FetchRequestInit, FetchRetryOptions, RunTaskOptions, IntegrationMetadata, QueueOptions, IntegrationConfig, JobMetadata, MissingConnectionNotificationPayload, MissingConnectionResolvedNotificationPayload, ErrorWithStack, ApiEventLog, RedactString } from '@trigger.dev/core';
2
+ import { RunTaskBodyInput, CompleteTaskBodyInput, FailTaskBodyInput, SendEvent, SendEventOptions, StatusUpdate, UpdateTriggerSourceBodyV2, TriggerSource, RegisterTriggerBodyV2, RegisterSourceEventV2, ScheduleMetadata, GetRunOptionsWithTaskDetails, GetRunsOptions, LogLevel, RuntimeEnvironmentType, DisplayProperty, TriggerMetadata, EventFilter, Prettify, HandleTriggerSource, Logger, RegisterTriggerSource, SerializableJson, ConnectionAuth, NormalizedResponse, HttpSourceResponseMetadata, IntervalOptions, CronOptions, ScheduledPayload, DeserializedJson, ServerTask, CachedTask, InitialStatusUpdate, FetchRequestInit, FetchRetryOptions, RunTaskOptions, IntegrationMetadata, QueueOptions, IntegrationConfig, JobMetadata, MissingConnectionNotificationPayload, MissingConnectionResolvedNotificationPayload, ErrorWithStack, ApiEventLog, RedactString } from '@trigger.dev/core';
3
3
  export { ConnectionAuth, DisplayProperty, EventFilter, Logger, NormalizedRequest, OverridableRunTaskOptions, Prettify, RedactString, RegisteredOptionsDiff, RunTaskOptions, SourceEventOption } from '@trigger.dev/core';
4
4
  import * as zod from 'zod';
5
5
  import { z } from 'zod';
@@ -9,10 +9,332 @@ type ApiClientOptions = {
9
9
  apiUrl?: string;
10
10
  logLevel?: LogLevel;
11
11
  };
12
+ type EndpointRecord = {
13
+ id: string;
14
+ name: string;
15
+ url: string;
16
+ };
12
17
  declare class ApiClient {
13
18
  #private;
14
19
  constructor(options: ApiClientOptions);
15
- runTask(runId: string, task: RunTaskBodyInput): Promise<{
20
+ registerEndpoint(options: {
21
+ url: string;
22
+ name: string;
23
+ }): Promise<EndpointRecord>;
24
+ runTask(runId: string, task: RunTaskBodyInput, options?: {
25
+ cachedTasksCursor?: string;
26
+ }): Promise<VersionedResponseBody<{
27
+ "2023-09-29": z.ZodObject<{
28
+ task: z.ZodObject<{
29
+ id: z.ZodString;
30
+ name: z.ZodString;
31
+ icon: z.ZodNullable<z.ZodOptional<z.ZodString>>;
32
+ noop: z.ZodBoolean;
33
+ startedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
34
+ completedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
35
+ delayUntil: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
36
+ status: z.ZodEnum<["PENDING", "WAITING", "RUNNING", "COMPLETED", "ERRORED", "CANCELED"]>;
37
+ description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
38
+ params: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
39
+ properties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
40
+ label: z.ZodString;
41
+ text: z.ZodString;
42
+ url: z.ZodOptional<z.ZodString>;
43
+ }, "strip", z.ZodTypeAny, {
44
+ label: string;
45
+ text: string;
46
+ url?: string | undefined;
47
+ }, {
48
+ label: string;
49
+ text: string;
50
+ url?: string | undefined;
51
+ }>, "many">>>;
52
+ outputProperties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
53
+ label: z.ZodString;
54
+ text: z.ZodString;
55
+ url: z.ZodOptional<z.ZodString>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ label: string;
58
+ text: string;
59
+ url?: string | undefined;
60
+ }, {
61
+ label: string;
62
+ text: string;
63
+ url?: string | undefined;
64
+ }>, "many">>>;
65
+ output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
66
+ error: z.ZodNullable<z.ZodOptional<z.ZodString>>;
67
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
68
+ style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
69
+ style: z.ZodEnum<["normal", "minimal"]>;
70
+ variant: z.ZodOptional<z.ZodString>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ style: "normal" | "minimal";
73
+ variant?: string | undefined;
74
+ }, {
75
+ style: "normal" | "minimal";
76
+ variant?: string | undefined;
77
+ }>>>;
78
+ operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
79
+ callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
80
+ idempotencyKey: z.ZodString;
81
+ attempts: z.ZodNumber;
82
+ }, "strip", z.ZodTypeAny, {
83
+ id: string;
84
+ name: string;
85
+ noop: boolean;
86
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
87
+ idempotencyKey: string;
88
+ attempts: number;
89
+ icon?: string | null | undefined;
90
+ startedAt?: Date | null | undefined;
91
+ completedAt?: Date | null | undefined;
92
+ delayUntil?: Date | null | undefined;
93
+ description?: string | null | undefined;
94
+ params?: _trigger_dev_core.DeserializedJson | undefined;
95
+ properties?: {
96
+ label: string;
97
+ text: string;
98
+ url?: string | undefined;
99
+ }[] | null | undefined;
100
+ outputProperties?: {
101
+ label: string;
102
+ text: string;
103
+ url?: string | undefined;
104
+ }[] | null | undefined;
105
+ output?: _trigger_dev_core.DeserializedJson | undefined;
106
+ error?: string | null | undefined;
107
+ parentId?: string | null | undefined;
108
+ style?: {
109
+ style: "normal" | "minimal";
110
+ variant?: string | undefined;
111
+ } | null | undefined;
112
+ operation?: string | null | undefined;
113
+ callbackUrl?: string | null | undefined;
114
+ }, {
115
+ id: string;
116
+ name: string;
117
+ noop: boolean;
118
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
119
+ idempotencyKey: string;
120
+ attempts: number;
121
+ icon?: string | null | undefined;
122
+ startedAt?: Date | null | undefined;
123
+ completedAt?: Date | null | undefined;
124
+ delayUntil?: Date | null | undefined;
125
+ description?: string | null | undefined;
126
+ params?: _trigger_dev_core.DeserializedJson | undefined;
127
+ properties?: {
128
+ label: string;
129
+ text: string;
130
+ url?: string | undefined;
131
+ }[] | null | undefined;
132
+ outputProperties?: {
133
+ label: string;
134
+ text: string;
135
+ url?: string | undefined;
136
+ }[] | null | undefined;
137
+ output?: _trigger_dev_core.DeserializedJson | undefined;
138
+ error?: string | null | undefined;
139
+ parentId?: string | null | undefined;
140
+ style?: {
141
+ style: "normal" | "minimal";
142
+ variant?: string | undefined;
143
+ } | null | undefined;
144
+ operation?: string | null | undefined;
145
+ callbackUrl?: string | null | undefined;
146
+ }>;
147
+ cachedTasks: z.ZodOptional<z.ZodObject<{
148
+ tasks: z.ZodArray<z.ZodObject<{
149
+ id: z.ZodString;
150
+ idempotencyKey: z.ZodString;
151
+ status: z.ZodEnum<["PENDING", "WAITING", "RUNNING", "COMPLETED", "ERRORED", "CANCELED"]>;
152
+ noop: z.ZodDefault<z.ZodBoolean>;
153
+ output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
154
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
155
+ }, "strip", z.ZodTypeAny, {
156
+ id: string;
157
+ noop: boolean;
158
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
159
+ idempotencyKey: string;
160
+ output?: _trigger_dev_core.DeserializedJson | undefined;
161
+ parentId?: string | null | undefined;
162
+ }, {
163
+ id: string;
164
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
165
+ idempotencyKey: string;
166
+ noop?: boolean | undefined;
167
+ output?: _trigger_dev_core.DeserializedJson | undefined;
168
+ parentId?: string | null | undefined;
169
+ }>, "many">;
170
+ cursor: z.ZodOptional<z.ZodString>;
171
+ }, "strip", z.ZodTypeAny, {
172
+ tasks: {
173
+ id: string;
174
+ noop: boolean;
175
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
176
+ idempotencyKey: string;
177
+ output?: _trigger_dev_core.DeserializedJson | undefined;
178
+ parentId?: string | null | undefined;
179
+ }[];
180
+ cursor?: string | undefined;
181
+ }, {
182
+ tasks: {
183
+ id: string;
184
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
185
+ idempotencyKey: string;
186
+ noop?: boolean | undefined;
187
+ output?: _trigger_dev_core.DeserializedJson | undefined;
188
+ parentId?: string | null | undefined;
189
+ }[];
190
+ cursor?: string | undefined;
191
+ }>>;
192
+ }, "strip", z.ZodTypeAny, {
193
+ task: {
194
+ id: string;
195
+ name: string;
196
+ noop: boolean;
197
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
198
+ idempotencyKey: string;
199
+ attempts: number;
200
+ icon?: string | null | undefined;
201
+ startedAt?: Date | null | undefined;
202
+ completedAt?: Date | null | undefined;
203
+ delayUntil?: Date | null | undefined;
204
+ description?: string | null | undefined;
205
+ params?: _trigger_dev_core.DeserializedJson | undefined;
206
+ properties?: {
207
+ label: string;
208
+ text: string;
209
+ url?: string | undefined;
210
+ }[] | null | undefined;
211
+ outputProperties?: {
212
+ label: string;
213
+ text: string;
214
+ url?: string | undefined;
215
+ }[] | null | undefined;
216
+ output?: _trigger_dev_core.DeserializedJson | undefined;
217
+ error?: string | null | undefined;
218
+ parentId?: string | null | undefined;
219
+ style?: {
220
+ style: "normal" | "minimal";
221
+ variant?: string | undefined;
222
+ } | null | undefined;
223
+ operation?: string | null | undefined;
224
+ callbackUrl?: string | null | undefined;
225
+ };
226
+ cachedTasks?: {
227
+ tasks: {
228
+ id: string;
229
+ noop: boolean;
230
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
231
+ idempotencyKey: string;
232
+ output?: _trigger_dev_core.DeserializedJson | undefined;
233
+ parentId?: string | null | undefined;
234
+ }[];
235
+ cursor?: string | undefined;
236
+ } | undefined;
237
+ }, {
238
+ task: {
239
+ id: string;
240
+ name: string;
241
+ noop: boolean;
242
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
243
+ idempotencyKey: string;
244
+ attempts: number;
245
+ icon?: string | null | undefined;
246
+ startedAt?: Date | null | undefined;
247
+ completedAt?: Date | null | undefined;
248
+ delayUntil?: Date | null | undefined;
249
+ description?: string | null | undefined;
250
+ params?: _trigger_dev_core.DeserializedJson | undefined;
251
+ properties?: {
252
+ label: string;
253
+ text: string;
254
+ url?: string | undefined;
255
+ }[] | null | undefined;
256
+ outputProperties?: {
257
+ label: string;
258
+ text: string;
259
+ url?: string | undefined;
260
+ }[] | null | undefined;
261
+ output?: _trigger_dev_core.DeserializedJson | undefined;
262
+ error?: string | null | undefined;
263
+ parentId?: string | null | undefined;
264
+ style?: {
265
+ style: "normal" | "minimal";
266
+ variant?: string | undefined;
267
+ } | null | undefined;
268
+ operation?: string | null | undefined;
269
+ callbackUrl?: string | null | undefined;
270
+ };
271
+ cachedTasks?: {
272
+ tasks: {
273
+ id: string;
274
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
275
+ idempotencyKey: string;
276
+ noop?: boolean | undefined;
277
+ output?: _trigger_dev_core.DeserializedJson | undefined;
278
+ parentId?: string | null | undefined;
279
+ }[];
280
+ cursor?: string | undefined;
281
+ } | undefined;
282
+ }>;
283
+ }, z.ZodObject<{
284
+ id: z.ZodString;
285
+ name: z.ZodString;
286
+ icon: z.ZodNullable<z.ZodOptional<z.ZodString>>;
287
+ noop: z.ZodBoolean;
288
+ startedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
289
+ completedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
290
+ delayUntil: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
291
+ status: z.ZodEnum<["PENDING", "WAITING", "RUNNING", "COMPLETED", "ERRORED", "CANCELED"]>;
292
+ description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
293
+ params: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
294
+ properties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
295
+ label: z.ZodString;
296
+ text: z.ZodString;
297
+ url: z.ZodOptional<z.ZodString>;
298
+ }, "strip", z.ZodTypeAny, {
299
+ label: string;
300
+ text: string;
301
+ url?: string | undefined;
302
+ }, {
303
+ label: string;
304
+ text: string;
305
+ url?: string | undefined;
306
+ }>, "many">>>;
307
+ outputProperties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
308
+ label: z.ZodString;
309
+ text: z.ZodString;
310
+ url: z.ZodOptional<z.ZodString>;
311
+ }, "strip", z.ZodTypeAny, {
312
+ label: string;
313
+ text: string;
314
+ url?: string | undefined;
315
+ }, {
316
+ label: string;
317
+ text: string;
318
+ url?: string | undefined;
319
+ }>, "many">>>;
320
+ output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
321
+ error: z.ZodNullable<z.ZodOptional<z.ZodString>>;
322
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
323
+ style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
324
+ style: z.ZodEnum<["normal", "minimal"]>;
325
+ variant: z.ZodOptional<z.ZodString>;
326
+ }, "strip", z.ZodTypeAny, {
327
+ style: "normal" | "minimal";
328
+ variant?: string | undefined;
329
+ }, {
330
+ style: "normal" | "minimal";
331
+ variant?: string | undefined;
332
+ }>>>;
333
+ operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
334
+ callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
335
+ idempotencyKey: z.ZodString;
336
+ attempts: z.ZodNumber;
337
+ }, "strip", z.ZodTypeAny, {
16
338
  id: string;
17
339
  name: string;
18
340
  noop: boolean;
@@ -43,7 +365,40 @@ declare class ApiClient {
43
365
  variant?: string | undefined;
44
366
  } | null | undefined;
45
367
  operation?: string | null | undefined;
46
- }>;
368
+ callbackUrl?: string | null | undefined;
369
+ }, {
370
+ id: string;
371
+ name: string;
372
+ noop: boolean;
373
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
374
+ idempotencyKey: string;
375
+ attempts: number;
376
+ icon?: string | null | undefined;
377
+ startedAt?: Date | null | undefined;
378
+ completedAt?: Date | null | undefined;
379
+ delayUntil?: Date | null | undefined;
380
+ description?: string | null | undefined;
381
+ params?: _trigger_dev_core.DeserializedJson | undefined;
382
+ properties?: {
383
+ label: string;
384
+ text: string;
385
+ url?: string | undefined;
386
+ }[] | null | undefined;
387
+ outputProperties?: {
388
+ label: string;
389
+ text: string;
390
+ url?: string | undefined;
391
+ }[] | null | undefined;
392
+ output?: _trigger_dev_core.DeserializedJson | undefined;
393
+ error?: string | null | undefined;
394
+ parentId?: string | null | undefined;
395
+ style?: {
396
+ style: "normal" | "minimal";
397
+ variant?: string | undefined;
398
+ } | null | undefined;
399
+ operation?: string | null | undefined;
400
+ callbackUrl?: string | null | undefined;
401
+ }>>>;
47
402
  completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
48
403
  id: string;
49
404
  name: string;
@@ -75,6 +430,7 @@ declare class ApiClient {
75
430
  variant?: string | undefined;
76
431
  } | null | undefined;
77
432
  operation?: string | null | undefined;
433
+ callbackUrl?: string | null | undefined;
78
434
  }>;
79
435
  failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
80
436
  id: string;
@@ -107,6 +463,7 @@ declare class ApiClient {
107
463
  variant?: string | undefined;
108
464
  } | null | undefined;
109
465
  operation?: string | null | undefined;
466
+ callbackUrl?: string | null | undefined;
110
467
  }>;
111
468
  sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
112
469
  id: string;
@@ -136,6 +493,17 @@ declare class ApiClient {
136
493
  deliveredAt?: Date | null | undefined;
137
494
  cancelledAt?: Date | null | undefined;
138
495
  }>;
496
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
497
+ label: string;
498
+ key: string;
499
+ history: {
500
+ label?: string | undefined;
501
+ state?: "loading" | "success" | "failure" | undefined;
502
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
503
+ }[];
504
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
505
+ state?: "loading" | "success" | "failure" | undefined;
506
+ }>;
139
507
  updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
140
508
  registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2): Promise<RegisterSourceEventV2>;
141
509
  registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
@@ -145,12 +513,14 @@ declare class ApiClient {
145
513
  cron: string;
146
514
  };
147
515
  type: "cron";
516
+ accountId?: string | undefined;
148
517
  metadata?: any;
149
518
  } | {
150
519
  options: {
151
520
  seconds: number;
152
521
  };
153
522
  type: "interval";
523
+ accountId?: string | undefined;
154
524
  metadata?: any;
155
525
  };
156
526
  active: boolean;
@@ -160,7 +530,7 @@ declare class ApiClient {
160
530
  ok: boolean;
161
531
  }>;
162
532
  getAuth(client: string, id: string): Promise<{
163
- type: "oauth2";
533
+ type: "oauth2" | "apiKey";
164
534
  accessToken: string;
165
535
  scopes?: string[] | undefined;
166
536
  additionalFields?: Record<string, string> | undefined;
@@ -168,36 +538,98 @@ declare class ApiClient {
168
538
  getEvent(eventId: string): Promise<{
169
539
  id: string;
170
540
  name: string;
171
- createdAt: Date;
172
541
  updatedAt: Date;
173
542
  runs: {
174
543
  id: string;
175
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
544
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
176
545
  startedAt?: Date | null | undefined;
177
546
  completedAt?: Date | null | undefined;
178
547
  }[];
548
+ createdAt: Date;
179
549
  }>;
180
550
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
181
551
  id: string;
182
552
  startedAt: Date | null;
183
553
  completedAt: Date | null;
184
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
554
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
555
+ updatedAt: Date | null;
185
556
  tasks: _trigger_dev_core.RunTaskWithSubtasks[];
557
+ statuses: {
558
+ label: string;
559
+ key: string;
560
+ history: {
561
+ label?: string | undefined;
562
+ state?: "loading" | "success" | "failure" | undefined;
563
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
564
+ }[];
565
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
566
+ state?: "loading" | "success" | "failure" | undefined;
567
+ }[];
568
+ output?: any;
569
+ nextCursor?: string | undefined;
570
+ }>;
571
+ cancelRun(runId: string): Promise<{
572
+ id: string;
573
+ startedAt: Date | null;
574
+ completedAt: Date | null;
575
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
186
576
  updatedAt: Date | null;
577
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
578
+ statuses: {
579
+ label: string;
580
+ key: string;
581
+ history: {
582
+ label?: string | undefined;
583
+ state?: "loading" | "success" | "failure" | undefined;
584
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
585
+ }[];
586
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
587
+ state?: "loading" | "success" | "failure" | undefined;
588
+ }[];
187
589
  output?: any;
188
590
  nextCursor?: string | undefined;
189
591
  }>;
592
+ getRunStatuses(runId: string): Promise<{
593
+ statuses: {
594
+ label: string;
595
+ key: string;
596
+ history: {
597
+ label?: string | undefined;
598
+ state?: "loading" | "success" | "failure" | undefined;
599
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
600
+ }[];
601
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
602
+ state?: "loading" | "success" | "failure" | undefined;
603
+ }[];
604
+ run: {
605
+ id: string;
606
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
607
+ output?: any;
608
+ };
609
+ }>;
190
610
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
191
611
  runs: {
192
612
  id: string;
193
613
  startedAt: Date | null;
194
614
  completedAt: Date | null;
195
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
615
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
196
616
  updatedAt: Date | null;
197
617
  }[];
198
618
  nextCursor?: string | undefined;
199
619
  }>;
200
620
  }
621
+ type VersionedResponseBodyMap = {
622
+ [key: string]: z.ZodTypeAny;
623
+ };
624
+ type VersionedResponseBody<TVersions extends VersionedResponseBodyMap, TUnversioned extends z.ZodTypeAny> = {
625
+ [TVersion in keyof TVersions]: {
626
+ version: TVersion;
627
+ body: z.infer<TVersions[TVersion]>;
628
+ };
629
+ }[keyof TVersions] | {
630
+ version: "unversioned";
631
+ body: z.infer<TUnversioned>;
632
+ };
201
633
 
202
634
  interface TriggerContext {
203
635
  /** Job metadata */
@@ -309,6 +741,22 @@ interface EventSpecification<TEvent extends any> {
309
741
  runProperties?: (payload: TEvent) => DisplayProperty[];
310
742
  }
311
743
  type EventTypeFromSpecification<TEventSpec extends EventSpecification<any>> = TEventSpec extends EventSpecification<infer TEvent> ? TEvent : never;
744
+ type SchemaParserIssue = {
745
+ path: PropertyKey[];
746
+ message: string;
747
+ };
748
+ type SchemaParserResult<T> = {
749
+ success: true;
750
+ data: T;
751
+ } | {
752
+ success: false;
753
+ error: {
754
+ issues: SchemaParserIssue[];
755
+ };
756
+ };
757
+ type SchemaParser<T extends unknown = unknown> = {
758
+ safeParse: (a: unknown) => SchemaParserResult<T>;
759
+ };
312
760
 
313
761
  type HttpSourceEvent = {
314
762
  url: string;
@@ -393,8 +841,8 @@ type FilterFunction<TParams extends any, TTriggerOptionDefinitions extends Recor
393
841
  type ExternalSourceOptions<TChannel extends ChannelNames, TIntegration extends TriggerIntegration, TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
394
842
  id: string;
395
843
  version: string;
396
- schema: z.Schema<TParams>;
397
- optionSchema?: z.Schema<TTriggerOptionDefinitions>;
844
+ schema: SchemaParser<TParams>;
845
+ optionSchema?: SchemaParser<TTriggerOptionDefinitions>;
398
846
  integration: TIntegration;
399
847
  register: RegisterFunction<TIntegration, TParams, TChannel, TTriggerOptionDefinitions>;
400
848
  filter?: FilterFunction<TParams, TTriggerOptionDefinitions>;
@@ -438,9 +886,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration, TParams ex
438
886
  get id(): string;
439
887
  get version(): string;
440
888
  }
441
- type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams & {
442
- filter?: EventFilter;
443
- } : never;
889
+ type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams : never;
444
890
  type ExternalSourceTriggerOptions<TEventSpecification extends EventSpecification<any>, TEventSource extends ExternalSource<any, any, any>, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
445
891
  event: TEventSpecification;
446
892
  source: TEventSource;
@@ -471,7 +917,7 @@ type DynamicTriggerOptions<TEventSpec extends EventSpecification<any>, TExternal
471
917
  * ```ts
472
918
  * import { events } from "@trigger.dev/github";
473
919
  *
474
- * const dynamicOnIssueOpened = new DynamicTrigger(client, {
920
+ * const dynamicOnIssueOpened = client.defineDynamicTrigger({
475
921
  id: "github-issue-opened",
476
922
  event: events.onIssueOpened,
477
923
  source: github.sources.repo,
@@ -492,16 +938,154 @@ declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExtern
492
938
  toJSON(): TriggerMetadata;
493
939
  get id(): string;
494
940
  get event(): TEventSpec;
495
- registeredTriggerForParams(params: ExternalSourceParams<TExternalSource>): RegisterTriggerBodyV2;
496
941
  /** Use this method to register a new configuration with the DynamicTrigger.
497
942
  * @param key The key for the configuration. This will be used to identify the configuration when it is triggered.
498
943
  * @param params The params for the configuration.
944
+ * @param options Options for the configuration.
945
+ * @param options.accountId The accountId to associate with the configuration.
946
+ * @param options.filter The filter to use for the configuration.
947
+ *
499
948
  */
500
- register(key: string, params: ExternalSourceParams<TExternalSource>): Promise<RegisterSourceEventV2>;
949
+ register(key: string, params: ExternalSourceParams<TExternalSource>, options?: {
950
+ accountId?: string;
951
+ filter?: EventFilter;
952
+ }): Promise<RegisterSourceEventV2>;
501
953
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
502
954
  get preprocessRuns(): boolean;
503
955
  }
504
956
 
957
+ type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
958
+ declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
959
+ private options;
960
+ constructor(options: IntervalOptions);
961
+ get event(): {
962
+ name: string;
963
+ title: string;
964
+ source: string;
965
+ icon: string;
966
+ examples: {
967
+ id: string;
968
+ name: string;
969
+ icon: string;
970
+ payload: {
971
+ ts: string;
972
+ lastTimestamp: string;
973
+ };
974
+ }[];
975
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
976
+ ts: Date;
977
+ lastTimestamp?: Date | undefined;
978
+ };
979
+ properties: {
980
+ label: string;
981
+ text: string;
982
+ }[];
983
+ };
984
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
985
+ get preprocessRuns(): boolean;
986
+ toJSON(): TriggerMetadata;
987
+ }
988
+ /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
989
+ * @param options An object containing options about the interval.
990
+ */
991
+ declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
992
+ declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
993
+ private options;
994
+ constructor(options: CronOptions);
995
+ get event(): {
996
+ name: string;
997
+ title: string;
998
+ source: string;
999
+ icon: string;
1000
+ examples: {
1001
+ id: string;
1002
+ name: string;
1003
+ icon: string;
1004
+ payload: {
1005
+ ts: string;
1006
+ lastTimestamp: string;
1007
+ };
1008
+ }[];
1009
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
1010
+ ts: Date;
1011
+ lastTimestamp?: Date | undefined;
1012
+ };
1013
+ properties: {
1014
+ label: string;
1015
+ text: string;
1016
+ }[];
1017
+ };
1018
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1019
+ get preprocessRuns(): boolean;
1020
+ toJSON(): TriggerMetadata;
1021
+ }
1022
+ /** `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.
1023
+ * @param options An object containing options about the CRON schedule.
1024
+ */
1025
+ declare function cronTrigger(options: CronOptions): CronTrigger;
1026
+ /** DynamicSchedule options
1027
+ * @param id Used to uniquely identify a DynamicSchedule
1028
+ */
1029
+ type DynamicIntervalOptions = {
1030
+ id: string;
1031
+ };
1032
+ /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
1033
+ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
1034
+ private client;
1035
+ private options;
1036
+ /**
1037
+ * @param client The `TriggerClient` instance to use for registering the trigger.
1038
+ * @param options The options for the schedule.
1039
+ */
1040
+ constructor(client: TriggerClient, options: DynamicIntervalOptions);
1041
+ get id(): string;
1042
+ get event(): {
1043
+ name: string;
1044
+ title: string;
1045
+ source: string;
1046
+ icon: string;
1047
+ examples: {
1048
+ id: string;
1049
+ name: string;
1050
+ icon: string;
1051
+ payload: {
1052
+ ts: string;
1053
+ lastTimestamp: string;
1054
+ };
1055
+ }[];
1056
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
1057
+ ts: Date;
1058
+ lastTimestamp?: Date | undefined;
1059
+ };
1060
+ };
1061
+ register(key: string, metadata: ScheduleMetadata): Promise<{
1062
+ id: string;
1063
+ schedule: {
1064
+ options: {
1065
+ cron: string;
1066
+ };
1067
+ type: "cron";
1068
+ accountId?: string | undefined;
1069
+ metadata?: any;
1070
+ } | {
1071
+ options: {
1072
+ seconds: number;
1073
+ };
1074
+ type: "interval";
1075
+ accountId?: string | undefined;
1076
+ metadata?: any;
1077
+ };
1078
+ active: boolean;
1079
+ metadata?: any;
1080
+ }>;
1081
+ unregister(key: string): Promise<{
1082
+ ok: boolean;
1083
+ }>;
1084
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1085
+ get preprocessRuns(): boolean;
1086
+ toJSON(): TriggerMetadata;
1087
+ }
1088
+
505
1089
  type TriggerClientOptions = {
506
1090
  /** The `id` property is used to uniquely identify the client.
507
1091
  */
@@ -521,12 +1105,22 @@ type TriggerClientOptions = {
521
1105
  /** Default is unset and off. If set to true it will log to the server's console as well as the Trigger.dev platform */
522
1106
  ioLogLocalEnabled?: boolean;
523
1107
  };
1108
+ type AuthResolverResult = {
1109
+ type: "apiKey" | "oauth";
1110
+ token: string;
1111
+ additionalFields?: Record<string, string>;
1112
+ };
1113
+ type TriggerAuthResolver = (ctx: TriggerContext, integration: TriggerIntegration) => Promise<AuthResolverResult | void | undefined>;
524
1114
  /** 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). */
525
1115
  declare class TriggerClient {
526
1116
  #private;
527
1117
  id: string;
528
1118
  constructor(options: Prettify<TriggerClientOptions>);
529
1119
  handleRequest(request: Request): Promise<NormalizedResponse>;
1120
+ defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
1121
+ defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
1122
+ defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
1123
+ defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
530
1124
  attach(job: Job<Trigger<any>, any>): void;
531
1125
  attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
532
1126
  attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
@@ -537,7 +1131,8 @@ declare class TriggerClient {
537
1131
  params: any;
538
1132
  options?: Record<string, string[]>;
539
1133
  }): void;
540
- attachDynamicSchedule(key: string, job: Job<Trigger<any>, any>): void;
1134
+ attachDynamicSchedule(key: string): void;
1135
+ attachDynamicScheduleToJob(key: string, job: Job<Trigger<any>, any>): void;
541
1136
  registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
542
1137
  id: string;
543
1138
  options: {
@@ -570,12 +1165,12 @@ declare class TriggerClient {
570
1165
  dynamicTriggerId?: string | undefined;
571
1166
  }>;
572
1167
  getAuth(id: string): Promise<{
573
- type: "oauth2";
1168
+ type: "oauth2" | "apiKey";
574
1169
  accessToken: string;
575
1170
  scopes?: string[] | undefined;
576
1171
  additionalFields?: Record<string, string> | undefined;
577
1172
  } | undefined>;
578
- /** 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.
1173
+ /** 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.
579
1174
  * @param event The event to send.
580
1175
  * @param options Options for sending the event.
581
1176
  * @returns A promise that resolves to the event details
@@ -608,6 +1203,17 @@ declare class TriggerClient {
608
1203
  deliveredAt?: Date | null | undefined;
609
1204
  cancelledAt?: Date | null | undefined;
610
1205
  }>;
1206
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
1207
+ label: string;
1208
+ key: string;
1209
+ history: {
1210
+ label?: string | undefined;
1211
+ state?: "loading" | "success" | "failure" | undefined;
1212
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1213
+ }[];
1214
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1215
+ state?: "loading" | "success" | "failure" | undefined;
1216
+ }>;
611
1217
  registerSchedule(id: string, key: string, schedule: ScheduleMetadata): Promise<{
612
1218
  id: string;
613
1219
  schedule: {
@@ -615,12 +1221,14 @@ declare class TriggerClient {
615
1221
  cron: string;
616
1222
  };
617
1223
  type: "cron";
1224
+ accountId?: string | undefined;
618
1225
  metadata?: any;
619
1226
  } | {
620
1227
  options: {
621
1228
  seconds: number;
622
1229
  };
623
1230
  type: "interval";
1231
+ accountId?: string | undefined;
624
1232
  metadata?: any;
625
1233
  };
626
1234
  active: boolean;
@@ -632,22 +1240,54 @@ declare class TriggerClient {
632
1240
  getEvent(eventId: string): Promise<{
633
1241
  id: string;
634
1242
  name: string;
635
- createdAt: Date;
636
1243
  updatedAt: Date;
637
1244
  runs: {
638
1245
  id: string;
639
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1246
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
640
1247
  startedAt?: Date | null | undefined;
641
1248
  completedAt?: Date | null | undefined;
642
1249
  }[];
1250
+ createdAt: Date;
643
1251
  }>;
644
1252
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
645
1253
  id: string;
646
1254
  startedAt: Date | null;
647
1255
  completedAt: Date | null;
648
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1256
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
1257
+ updatedAt: Date | null;
649
1258
  tasks: _trigger_dev_core.RunTaskWithSubtasks[];
1259
+ statuses: {
1260
+ label: string;
1261
+ key: string;
1262
+ history: {
1263
+ label?: string | undefined;
1264
+ state?: "loading" | "success" | "failure" | undefined;
1265
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1266
+ }[];
1267
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1268
+ state?: "loading" | "success" | "failure" | undefined;
1269
+ }[];
1270
+ output?: any;
1271
+ nextCursor?: string | undefined;
1272
+ }>;
1273
+ cancelRun(runId: string): Promise<{
1274
+ id: string;
1275
+ startedAt: Date | null;
1276
+ completedAt: Date | null;
1277
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
650
1278
  updatedAt: Date | null;
1279
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
1280
+ statuses: {
1281
+ label: string;
1282
+ key: string;
1283
+ history: {
1284
+ label?: string | undefined;
1285
+ state?: "loading" | "success" | "failure" | undefined;
1286
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1287
+ }[];
1288
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1289
+ state?: "loading" | "success" | "failure" | undefined;
1290
+ }[];
651
1291
  output?: any;
652
1292
  nextCursor?: string | undefined;
653
1293
  }>;
@@ -656,144 +1296,48 @@ declare class TriggerClient {
656
1296
  id: string;
657
1297
  startedAt: Date | null;
658
1298
  completedAt: Date | null;
659
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1299
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
660
1300
  updatedAt: Date | null;
661
1301
  }[];
662
1302
  nextCursor?: string | undefined;
663
1303
  }>;
664
- authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
665
- apiKey(): string | undefined;
666
- defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
667
- }
668
-
669
- type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
670
- declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
671
- private options;
672
- constructor(options: IntervalOptions);
673
- get event(): {
674
- name: string;
675
- title: string;
676
- source: string;
677
- icon: string;
678
- examples: {
679
- id: string;
680
- name: string;
681
- icon: string;
682
- payload: {
683
- ts: string;
684
- lastTimestamp: string;
685
- };
686
- }[];
687
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
688
- ts: Date;
689
- lastTimestamp?: Date | undefined;
690
- };
691
- properties: {
1304
+ getRunStatuses(runId: string): Promise<{
1305
+ statuses: {
692
1306
  label: string;
693
- text: string;
1307
+ key: string;
1308
+ history: {
1309
+ label?: string | undefined;
1310
+ state?: "loading" | "success" | "failure" | undefined;
1311
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1312
+ }[];
1313
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1314
+ state?: "loading" | "success" | "failure" | undefined;
694
1315
  }[];
695
- };
696
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
697
- get preprocessRuns(): boolean;
698
- toJSON(): TriggerMetadata;
699
- }
700
- /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
701
- * @param options An object containing options about the interval.
702
- */
703
- declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
704
- declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
705
- private options;
706
- constructor(options: CronOptions);
707
- get event(): {
708
- name: string;
709
- title: string;
710
- source: string;
711
- icon: string;
712
- examples: {
1316
+ run: {
713
1317
  id: string;
714
- name: string;
715
- icon: string;
716
- payload: {
717
- ts: string;
718
- lastTimestamp: string;
719
- };
720
- }[];
721
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
722
- ts: Date;
723
- lastTimestamp?: Date | undefined;
1318
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
1319
+ output?: any;
724
1320
  };
725
- properties: {
726
- label: string;
727
- text: string;
728
- }[];
729
- };
730
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
731
- get preprocessRuns(): boolean;
732
- toJSON(): TriggerMetadata;
1321
+ }>;
1322
+ authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
1323
+ apiKey(): string | undefined;
733
1324
  }
734
- /** `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.
735
- * @param options An object containing options about the CRON schedule.
736
- */
737
- declare function cronTrigger(options: CronOptions): CronTrigger;
738
- /** DynamicSchedule options
739
- * @param id Used to uniquely identify a DynamicSchedule
740
- */
741
- type DynamicIntervalOptions = {
742
- id: string;
743
- };
744
- /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
745
- declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
746
- private client;
747
- private options;
748
- /**
749
- * @param client The `TriggerClient` instance to use for registering the trigger.
750
- * @param options The options for the schedule.
751
- */
752
- constructor(client: TriggerClient, options: DynamicIntervalOptions);
753
- get id(): string;
754
- get event(): {
755
- name: string;
756
- title: string;
757
- source: string;
758
- icon: string;
759
- examples: {
760
- id: string;
761
- name: string;
762
- icon: string;
763
- payload: {
764
- ts: string;
765
- lastTimestamp: string;
766
- };
1325
+
1326
+ declare class TriggerStatus {
1327
+ private id;
1328
+ private io;
1329
+ constructor(id: string, io: IO);
1330
+ update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
1331
+ label: string;
1332
+ key: string;
1333
+ history: {
1334
+ label?: string | undefined;
1335
+ state?: "loading" | "success" | "failure" | undefined;
1336
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
767
1337
  }[];
768
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
769
- ts: Date;
770
- lastTimestamp?: Date | undefined;
771
- };
772
- };
773
- register(key: string, metadata: ScheduleMetadata): Promise<{
774
- id: string;
775
- schedule: {
776
- options: {
777
- cron: string;
778
- };
779
- type: "cron";
780
- metadata?: any;
781
- } | {
782
- options: {
783
- seconds: number;
784
- };
785
- type: "interval";
786
- metadata?: any;
787
- };
788
- active: boolean;
789
- metadata?: any;
790
- }>;
791
- unregister(key: string): Promise<{
792
- ok: boolean;
1338
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1339
+ state?: "loading" | "success" | "failure" | undefined;
793
1340
  }>;
794
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
795
- get preprocessRuns(): boolean;
796
- toJSON(): TriggerMetadata;
797
1341
  }
798
1342
 
799
1343
  type IOTask = ServerTask;
@@ -807,6 +1351,10 @@ type IOOptions = {
807
1351
  jobLogger?: Logger;
808
1352
  jobLogLevel: LogLevel;
809
1353
  cachedTasks?: Array<CachedTask>;
1354
+ cachedTasksCursor?: string;
1355
+ yieldedExecutions?: Array<string>;
1356
+ noopTasksSet?: string;
1357
+ serverVersion?: string | null;
810
1358
  };
811
1359
  type JsonPrimitive = string | number | boolean | null | undefined | Date | symbol;
812
1360
  type JsonArray = Json[];
@@ -815,10 +1363,20 @@ type JsonRecord<T> = {
815
1363
  };
816
1364
  type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
817
1365
  type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
818
- retryAt: Date;
1366
+ retryAt?: Date;
819
1367
  error?: Error;
820
1368
  jitter?: number;
1369
+ skipRetrying?: boolean;
821
1370
  } | Error | undefined | void;
1371
+ type IOStats = {
1372
+ initialCachedTasks: number;
1373
+ lazyLoadedCachedTasks: number;
1374
+ executedTasks: number;
1375
+ cachedTaskHits: number;
1376
+ cachedTaskMisses: number;
1377
+ noopCachedTaskHits: number;
1378
+ noopCachedTaskMisses: number;
1379
+ };
822
1380
  declare class IO {
823
1381
  #private;
824
1382
  private _id;
@@ -829,7 +1387,13 @@ declare class IO {
829
1387
  private _jobLogLevel;
830
1388
  private _cachedTasks;
831
1389
  private _taskStorage;
1390
+ private _cachedTasksCursor?;
832
1391
  private _context;
1392
+ private _yieldedExecutions;
1393
+ private _noopTasksBloomFilter;
1394
+ private _stats;
1395
+ private _serverVersion;
1396
+ get stats(): IOStats;
833
1397
  constructor(options: IOOptions);
834
1398
  /** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
835
1399
  get logger(): IOLogger;
@@ -838,6 +1402,39 @@ declare class IO {
838
1402
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
839
1403
  */
840
1404
  wait(key: string | any[], seconds: number): Promise<void>;
1405
+ /** `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
1406
+ * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1407
+ * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
1408
+ * @returns a TriggerStatus object that you can call `update()` on, to update the status.
1409
+ * @example
1410
+ * ```ts
1411
+ * client.defineJob(
1412
+ //...
1413
+ run: async (payload, io, ctx) => {
1414
+ const generatingImages = await io.createStatus("generating-images", {
1415
+ label: "Generating Images",
1416
+ state: "loading",
1417
+ data: {
1418
+ progress: 0.1,
1419
+ },
1420
+ });
1421
+
1422
+ //...do stuff
1423
+
1424
+ await generatingImages.update("completed-generation", {
1425
+ label: "Generated images",
1426
+ state: "success",
1427
+ data: {
1428
+ progress: 1.0,
1429
+ urls: ["http://..."]
1430
+ },
1431
+ });
1432
+
1433
+ //...
1434
+ });
1435
+ * ```
1436
+ */
1437
+ createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
841
1438
  /** `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.
842
1439
  * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
843
1440
  * @param url The URL to fetch from.
@@ -872,14 +1469,14 @@ declare class IO {
872
1469
  getEvent(key: string | any[], id: string): Promise<{
873
1470
  id: string;
874
1471
  name: string;
875
- createdAt: Date;
876
1472
  updatedAt: Date;
877
1473
  runs: {
878
1474
  id: string;
879
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1475
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
880
1476
  startedAt?: Date | null | undefined;
881
1477
  completedAt?: Date | null | undefined;
882
1478
  }[];
1479
+ createdAt: Date;
883
1480
  }>;
884
1481
  /** `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
885
1482
  * @param key
@@ -912,6 +1509,7 @@ declare class IO {
912
1509
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
913
1510
  * @param options The options for the interval.
914
1511
  * @returns A promise that has information about the interval.
1512
+ * @deprecated Use `DynamicSchedule.register` instead.
915
1513
  */
916
1514
  registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
917
1515
  id: string;
@@ -920,12 +1518,14 @@ declare class IO {
920
1518
  cron: string;
921
1519
  };
922
1520
  type: "cron";
1521
+ accountId?: string | undefined;
923
1522
  metadata?: any;
924
1523
  } | {
925
1524
  options: {
926
1525
  seconds: number;
927
1526
  };
928
1527
  type: "interval";
1528
+ accountId?: string | undefined;
929
1529
  metadata?: any;
930
1530
  };
931
1531
  active: boolean;
@@ -935,6 +1535,7 @@ declare class IO {
935
1535
  * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
936
1536
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
937
1537
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1538
+ * @deprecated Use `DynamicSchedule.unregister` instead.
938
1539
  */
939
1540
  unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
940
1541
  ok: boolean;
@@ -944,6 +1545,7 @@ declare class IO {
944
1545
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
945
1546
  * @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
946
1547
  * @param options The options for the CRON schedule.
1548
+ * @deprecated Use `DynamicSchedule.register` instead.
947
1549
  */
948
1550
  registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
949
1551
  id: string;
@@ -952,12 +1554,14 @@ declare class IO {
952
1554
  cron: string;
953
1555
  };
954
1556
  type: "cron";
1557
+ accountId?: string | undefined;
955
1558
  metadata?: any;
956
1559
  } | {
957
1560
  options: {
958
1561
  seconds: number;
959
1562
  };
960
1563
  type: "interval";
1564
+ accountId?: string | undefined;
961
1565
  metadata?: any;
962
1566
  };
963
1567
  active: boolean;
@@ -967,6 +1571,7 @@ declare class IO {
967
1571
  * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
968
1572
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
969
1573
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1574
+ * @deprecated Use `DynamicSchedule.unregister` instead.
970
1575
  */
971
1576
  unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
972
1577
  ok: boolean;
@@ -976,6 +1581,7 @@ declare class IO {
976
1581
  * @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
977
1582
  * @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
978
1583
  * @param params The params for the trigger.
1584
+ * @deprecated Use `DynamicTrigger.register` instead.
979
1585
  */
980
1586
  registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
981
1587
  id: string;
@@ -991,6 +1597,14 @@ declare class IO {
991
1597
  * @returns A Promise that resolves with the returned value of the callback.
992
1598
  */
993
1599
  runTask<T extends Json<T> | void>(key: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
1600
+ /**
1601
+ * `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.
1602
+ */
1603
+ yield(key: string): void;
1604
+ /**
1605
+ * `io.brb()` is an alias of `io.yield()`
1606
+ */
1607
+ brb: (key: string) => void;
994
1608
  /** `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).
995
1609
  * 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.
996
1610
  * @param tryCallback The code you wish to run
@@ -1088,8 +1702,8 @@ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegratio
1088
1702
  get name(): string;
1089
1703
  get trigger(): TTrigger;
1090
1704
  get version(): string;
1091
- get integrations(): Record<string, IntegrationConfig>;
1092
1705
  get logLevel(): LogLevel | undefined;
1706
+ get integrations(): Record<string, IntegrationConfig>;
1093
1707
  toJSON(): JobMetadata;
1094
1708
  }
1095
1709
 
@@ -1114,7 +1728,7 @@ type TriggerOptions<TEvent> = {
1114
1728
  /** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
1115
1729
  * The default is `z.any()` which is `any`.
1116
1730
  * */
1117
- schema?: z.Schema<TEvent>;
1731
+ schema?: SchemaParser<TEvent>;
1118
1732
  /** You can use this to filter events based on the source. */
1119
1733
  source?: string;
1120
1734
  /** Used to filter which events trigger the Job
@@ -1165,8 +1779,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1165
1779
  id: string;
1166
1780
  scopes: string[];
1167
1781
  title: string;
1168
- createdAt: Date;
1169
1782
  updatedAt: Date;
1783
+ createdAt: Date;
1170
1784
  };
1171
1785
  authorizationUrl: string;
1172
1786
  } | {
@@ -1180,8 +1794,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1180
1794
  id: string;
1181
1795
  scopes: string[];
1182
1796
  title: string;
1183
- createdAt: Date;
1184
1797
  updatedAt: Date;
1798
+ createdAt: Date;
1185
1799
  };
1186
1800
  authorizationUrl: string;
1187
1801
  };
@@ -1210,8 +1824,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1210
1824
  id: string;
1211
1825
  scopes: string[];
1212
1826
  title: string;
1213
- createdAt: Date;
1214
1827
  updatedAt: Date;
1828
+ createdAt: Date;
1215
1829
  integrationIdentifier: string;
1216
1830
  integrationAuthMethod: string;
1217
1831
  };
@@ -1227,8 +1841,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1227
1841
  id: string;
1228
1842
  scopes: string[];
1229
1843
  title: string;
1230
- createdAt: Date;
1231
1844
  updatedAt: Date;
1845
+ createdAt: Date;
1232
1846
  integrationIdentifier: string;
1233
1847
  integrationAuthMethod: string;
1234
1848
  };
@@ -1281,4 +1895,4 @@ type Task = ServerTask;
1281
1895
  type SentEvent = ApiEventLog;
1282
1896
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1283
1897
 
1284
- 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 };
1898
+ export { AuthResolverResult, CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventSpecification, EventSpecificationExample, EventTrigger, EventTypeFromSpecification, ExternalSource, ExternalSourceParams, ExternalSourceTrigger, ExternalSourceTriggerOptions, HandlerEvent, HttpSourceEvent, IO, IOLogger, IOOptions, IOStats, IOTask, IOWithIntegrations, IntegrationTaskKey, IntervalTrigger, Job, JobIO, JobOptions, JobPayload, Json, MissingConnectionNotification, MissingConnectionResolvedNotification, PreprocessResults, RunTaskErrorCallback, SchemaParser, SchemaParserIssue, SchemaParserResult, SentEvent, Task, TaskLogger, Trigger, TriggerAuthResolver, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerOptionRecord, TriggerPayload, TriggerPreprocessContext, cronTrigger, eventTrigger, intervalTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry };