@trigger.dev/sdk 0.0.0-cliframeworks-20230929110149 → 0.0.0-invoke-trigger-20231103104037

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,7 +1,8 @@
1
1
  import * as _trigger_dev_core 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';
2
+ import { RunTaskBodyInput, CompleteTaskBodyV2Input, FailTaskBodyInput, SendEvent, SendEventOptions, StatusUpdate, UpdateTriggerSourceBodyV2, TriggerSource, RegisterTriggerBodyV2, RegisterSourceEventV2, ScheduleMetadata, GetRunOptionsWithTaskDetails, GetRunsOptions, InvokeOptions, LogLevel, RuntimeEnvironmentType, DisplayProperty, TriggerMetadata, EventFilter, Prettify, HandleTriggerSource, Logger, RegisterTriggerSource, SerializableJson, ConnectionAuth, NormalizedResponse, HttpSourceResponseMetadata, IntervalOptions, CronOptions, ScheduledPayload, DeserializedJson, ServerTask, CachedTask, InitialStatusUpdate, FetchRequestInit, FetchRetryOptions, FetchTimeoutOptions, RunTaskOptions, IntegrationMetadata, QueueOptions, IntegrationConfig, JobMetadata, RunNotification, 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
+ import { z, ZodType, TypeOf } from 'zod';
5
6
 
6
7
  type ApiClientOptions = {
7
8
  apiKey?: string;
@@ -20,7 +21,332 @@ declare class ApiClient {
20
21
  url: string;
21
22
  name: string;
22
23
  }): Promise<EndpointRecord>;
23
- runTask(runId: string, task: RunTaskBodyInput): Promise<{
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
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
81
+ idempotencyKey: z.ZodString;
82
+ attempts: z.ZodNumber;
83
+ forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ id: string;
86
+ name: string;
87
+ noop: boolean;
88
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
89
+ idempotencyKey: string;
90
+ attempts: number;
91
+ icon?: string | null | undefined;
92
+ startedAt?: Date | null | undefined;
93
+ completedAt?: Date | null | undefined;
94
+ delayUntil?: Date | null | undefined;
95
+ description?: string | null | undefined;
96
+ params?: _trigger_dev_core.DeserializedJson | undefined;
97
+ properties?: {
98
+ label: string;
99
+ text: string;
100
+ url?: string | undefined;
101
+ }[] | null | undefined;
102
+ outputProperties?: {
103
+ label: string;
104
+ text: string;
105
+ url?: string | undefined;
106
+ }[] | null | undefined;
107
+ output?: _trigger_dev_core.DeserializedJson | undefined;
108
+ error?: string | null | undefined;
109
+ parentId?: string | null | undefined;
110
+ style?: {
111
+ style: "normal" | "minimal";
112
+ variant?: string | undefined;
113
+ } | null | undefined;
114
+ operation?: string | null | undefined;
115
+ callbackUrl?: string | null | undefined;
116
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
117
+ forceYield?: boolean | null | undefined;
118
+ }, {
119
+ id: string;
120
+ name: string;
121
+ noop: boolean;
122
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
123
+ idempotencyKey: string;
124
+ attempts: number;
125
+ icon?: string | null | undefined;
126
+ startedAt?: Date | null | undefined;
127
+ completedAt?: Date | null | undefined;
128
+ delayUntil?: Date | null | undefined;
129
+ description?: string | null | undefined;
130
+ params?: _trigger_dev_core.DeserializedJson | undefined;
131
+ properties?: {
132
+ label: string;
133
+ text: string;
134
+ url?: string | undefined;
135
+ }[] | null | undefined;
136
+ outputProperties?: {
137
+ label: string;
138
+ text: string;
139
+ url?: string | undefined;
140
+ }[] | null | undefined;
141
+ output?: _trigger_dev_core.DeserializedJson | undefined;
142
+ error?: string | null | undefined;
143
+ parentId?: string | null | undefined;
144
+ style?: {
145
+ style: "normal" | "minimal";
146
+ variant?: string | undefined;
147
+ } | null | undefined;
148
+ operation?: string | null | undefined;
149
+ callbackUrl?: string | null | undefined;
150
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
151
+ forceYield?: boolean | null | undefined;
152
+ }>;
153
+ cachedTasks: z.ZodOptional<z.ZodObject<{
154
+ tasks: z.ZodArray<z.ZodObject<{
155
+ id: z.ZodString;
156
+ idempotencyKey: z.ZodString;
157
+ status: z.ZodEnum<["PENDING", "WAITING", "RUNNING", "COMPLETED", "ERRORED", "CANCELED"]>;
158
+ noop: z.ZodDefault<z.ZodBoolean>;
159
+ output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
160
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
161
+ }, "strip", z.ZodTypeAny, {
162
+ id: string;
163
+ noop: boolean;
164
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
165
+ idempotencyKey: string;
166
+ output?: _trigger_dev_core.DeserializedJson | undefined;
167
+ parentId?: string | null | undefined;
168
+ }, {
169
+ id: string;
170
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
171
+ idempotencyKey: string;
172
+ noop?: boolean | undefined;
173
+ output?: _trigger_dev_core.DeserializedJson | undefined;
174
+ parentId?: string | null | undefined;
175
+ }>, "many">;
176
+ cursor: z.ZodOptional<z.ZodString>;
177
+ }, "strip", z.ZodTypeAny, {
178
+ tasks: {
179
+ id: string;
180
+ noop: boolean;
181
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
182
+ idempotencyKey: string;
183
+ output?: _trigger_dev_core.DeserializedJson | undefined;
184
+ parentId?: string | null | undefined;
185
+ }[];
186
+ cursor?: string | undefined;
187
+ }, {
188
+ tasks: {
189
+ id: string;
190
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
191
+ idempotencyKey: string;
192
+ noop?: boolean | undefined;
193
+ output?: _trigger_dev_core.DeserializedJson | undefined;
194
+ parentId?: string | null | undefined;
195
+ }[];
196
+ cursor?: string | undefined;
197
+ }>>;
198
+ }, "strip", z.ZodTypeAny, {
199
+ task: {
200
+ id: string;
201
+ name: string;
202
+ noop: boolean;
203
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
204
+ idempotencyKey: string;
205
+ attempts: number;
206
+ icon?: string | null | undefined;
207
+ startedAt?: Date | null | undefined;
208
+ completedAt?: Date | null | undefined;
209
+ delayUntil?: Date | null | undefined;
210
+ description?: string | null | undefined;
211
+ params?: _trigger_dev_core.DeserializedJson | undefined;
212
+ properties?: {
213
+ label: string;
214
+ text: string;
215
+ url?: string | undefined;
216
+ }[] | null | undefined;
217
+ outputProperties?: {
218
+ label: string;
219
+ text: string;
220
+ url?: string | undefined;
221
+ }[] | null | undefined;
222
+ output?: _trigger_dev_core.DeserializedJson | undefined;
223
+ error?: string | null | undefined;
224
+ parentId?: string | null | undefined;
225
+ style?: {
226
+ style: "normal" | "minimal";
227
+ variant?: string | undefined;
228
+ } | null | undefined;
229
+ operation?: string | null | undefined;
230
+ callbackUrl?: string | null | undefined;
231
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
232
+ forceYield?: boolean | null | undefined;
233
+ };
234
+ cachedTasks?: {
235
+ tasks: {
236
+ id: string;
237
+ noop: boolean;
238
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
239
+ idempotencyKey: string;
240
+ output?: _trigger_dev_core.DeserializedJson | undefined;
241
+ parentId?: string | null | undefined;
242
+ }[];
243
+ cursor?: string | undefined;
244
+ } | undefined;
245
+ }, {
246
+ task: {
247
+ id: string;
248
+ name: string;
249
+ noop: boolean;
250
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
251
+ idempotencyKey: string;
252
+ attempts: number;
253
+ icon?: string | null | undefined;
254
+ startedAt?: Date | null | undefined;
255
+ completedAt?: Date | null | undefined;
256
+ delayUntil?: Date | null | undefined;
257
+ description?: string | null | undefined;
258
+ params?: _trigger_dev_core.DeserializedJson | undefined;
259
+ properties?: {
260
+ label: string;
261
+ text: string;
262
+ url?: string | undefined;
263
+ }[] | null | undefined;
264
+ outputProperties?: {
265
+ label: string;
266
+ text: string;
267
+ url?: string | undefined;
268
+ }[] | null | undefined;
269
+ output?: _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
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
285
+ idempotencyKey: string;
286
+ noop?: boolean | undefined;
287
+ output?: _trigger_dev_core.DeserializedJson | undefined;
288
+ parentId?: string | null | undefined;
289
+ }[];
290
+ cursor?: string | undefined;
291
+ } | undefined;
292
+ }>;
293
+ }, z.ZodObject<{
294
+ id: z.ZodString;
295
+ name: z.ZodString;
296
+ icon: z.ZodNullable<z.ZodOptional<z.ZodString>>;
297
+ noop: z.ZodBoolean;
298
+ startedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
299
+ completedAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
300
+ delayUntil: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
301
+ status: z.ZodEnum<["PENDING", "WAITING", "RUNNING", "COMPLETED", "ERRORED", "CANCELED"]>;
302
+ description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
303
+ params: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
304
+ properties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
305
+ label: z.ZodString;
306
+ text: z.ZodString;
307
+ url: z.ZodOptional<z.ZodString>;
308
+ }, "strip", z.ZodTypeAny, {
309
+ label: string;
310
+ text: string;
311
+ url?: string | undefined;
312
+ }, {
313
+ label: string;
314
+ text: string;
315
+ url?: string | undefined;
316
+ }>, "many">>>;
317
+ outputProperties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
318
+ label: z.ZodString;
319
+ text: z.ZodString;
320
+ url: z.ZodOptional<z.ZodString>;
321
+ }, "strip", z.ZodTypeAny, {
322
+ label: string;
323
+ text: string;
324
+ url?: string | undefined;
325
+ }, {
326
+ label: string;
327
+ text: string;
328
+ url?: string | undefined;
329
+ }>, "many">>>;
330
+ output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
331
+ error: z.ZodNullable<z.ZodOptional<z.ZodString>>;
332
+ parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
333
+ style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
334
+ style: z.ZodEnum<["normal", "minimal"]>;
335
+ variant: z.ZodOptional<z.ZodString>;
336
+ }, "strip", z.ZodTypeAny, {
337
+ style: "normal" | "minimal";
338
+ variant?: string | undefined;
339
+ }, {
340
+ style: "normal" | "minimal";
341
+ variant?: string | undefined;
342
+ }>>>;
343
+ operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
344
+ callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
345
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
346
+ idempotencyKey: z.ZodString;
347
+ attempts: z.ZodNumber;
348
+ forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
349
+ }, "strip", z.ZodTypeAny, {
24
350
  id: string;
25
351
  name: string;
26
352
  noop: boolean;
@@ -51,8 +377,45 @@ declare class ApiClient {
51
377
  variant?: string | undefined;
52
378
  } | null | undefined;
53
379
  operation?: string | null | undefined;
54
- }>;
55
- completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
380
+ callbackUrl?: string | null | undefined;
381
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
382
+ forceYield?: boolean | null | undefined;
383
+ }, {
384
+ id: string;
385
+ name: string;
386
+ noop: boolean;
387
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
388
+ idempotencyKey: string;
389
+ attempts: number;
390
+ icon?: string | null | undefined;
391
+ startedAt?: Date | null | undefined;
392
+ completedAt?: Date | null | undefined;
393
+ delayUntil?: Date | null | undefined;
394
+ description?: string | null | undefined;
395
+ params?: _trigger_dev_core.DeserializedJson | undefined;
396
+ properties?: {
397
+ label: string;
398
+ text: string;
399
+ url?: string | undefined;
400
+ }[] | null | undefined;
401
+ outputProperties?: {
402
+ label: string;
403
+ text: string;
404
+ url?: string | undefined;
405
+ }[] | null | undefined;
406
+ output?: _trigger_dev_core.DeserializedJson | undefined;
407
+ error?: string | null | undefined;
408
+ parentId?: string | null | undefined;
409
+ style?: {
410
+ style: "normal" | "minimal";
411
+ variant?: string | undefined;
412
+ } | null | undefined;
413
+ operation?: string | null | undefined;
414
+ callbackUrl?: string | null | undefined;
415
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
416
+ forceYield?: boolean | null | undefined;
417
+ }>>>;
418
+ completeTask(runId: string, id: string, task: CompleteTaskBodyV2Input): Promise<{
56
419
  id: string;
57
420
  name: string;
58
421
  noop: boolean;
@@ -83,6 +446,9 @@ declare class ApiClient {
83
446
  variant?: string | undefined;
84
447
  } | null | undefined;
85
448
  operation?: string | null | undefined;
449
+ callbackUrl?: string | null | undefined;
450
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
451
+ forceYield?: boolean | null | undefined;
86
452
  }>;
87
453
  failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
88
454
  id: string;
@@ -115,6 +481,9 @@ declare class ApiClient {
115
481
  variant?: string | undefined;
116
482
  } | null | undefined;
117
483
  operation?: string | null | undefined;
484
+ callbackUrl?: string | null | undefined;
485
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
486
+ forceYield?: boolean | null | undefined;
118
487
  }>;
119
488
  sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
120
489
  id: string;
@@ -144,6 +513,10 @@ declare class ApiClient {
144
513
  deliveredAt?: Date | null | undefined;
145
514
  cancelledAt?: Date | null | undefined;
146
515
  }>;
516
+ cancelRunsForEvent(eventId: string): Promise<{
517
+ cancelledRunIds: string[];
518
+ failedToCancelRunIds: string[];
519
+ }>;
147
520
  updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
148
521
  label: string;
149
522
  key: string;
@@ -156,7 +529,7 @@ declare class ApiClient {
156
529
  state?: "loading" | "success" | "failure" | undefined;
157
530
  }>;
158
531
  updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
159
- registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2): Promise<RegisterSourceEventV2>;
532
+ registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2, idempotencyKey?: string): Promise<RegisterSourceEventV2>;
160
533
  registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
161
534
  id: string;
162
535
  schedule: {
@@ -205,8 +578,28 @@ declare class ApiClient {
205
578
  status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
206
579
  updatedAt: Date | null;
207
580
  tasks: _trigger_dev_core.RunTaskWithSubtasks[];
581
+ statuses: {
582
+ label: string;
583
+ key: string;
584
+ history: {
585
+ label?: string | undefined;
586
+ state?: "loading" | "success" | "failure" | undefined;
587
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
588
+ }[];
589
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
590
+ state?: "loading" | "success" | "failure" | undefined;
591
+ }[];
208
592
  output?: any;
209
- statuses?: {
593
+ nextCursor?: string | undefined;
594
+ }>;
595
+ cancelRun(runId: string): Promise<{
596
+ id: string;
597
+ startedAt: Date | null;
598
+ completedAt: Date | null;
599
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
600
+ updatedAt: Date | null;
601
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
602
+ statuses: {
210
603
  label: string;
211
604
  key: string;
212
605
  history: {
@@ -216,7 +609,8 @@ declare class ApiClient {
216
609
  }[];
217
610
  data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
218
611
  state?: "loading" | "success" | "failure" | undefined;
219
- }[] | undefined;
612
+ }[];
613
+ output?: any;
220
614
  nextCursor?: string | undefined;
221
615
  }>;
222
616
  getRunStatuses(runId: string): Promise<{
@@ -247,6 +641,38 @@ declare class ApiClient {
247
641
  }[];
248
642
  nextCursor?: string | undefined;
249
643
  }>;
644
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
645
+ id: string;
646
+ }>;
647
+ }
648
+ type VersionedResponseBodyMap = {
649
+ [key: string]: z.ZodTypeAny;
650
+ };
651
+ type VersionedResponseBody<TVersions extends VersionedResponseBodyMap, TUnversioned extends z.ZodTypeAny> = {
652
+ [TVersion in keyof TVersions]: {
653
+ version: TVersion;
654
+ body: z.infer<TVersions[TVersion]>;
655
+ };
656
+ }[keyof TVersions] | {
657
+ version: "unversioned";
658
+ body: z.infer<TUnversioned>;
659
+ };
660
+
661
+ declare class TriggerStatus {
662
+ private id;
663
+ private io;
664
+ constructor(id: string, io: IO);
665
+ update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
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
+ }>;
250
676
  }
251
677
 
252
678
  interface TriggerContext {
@@ -267,6 +693,12 @@ interface TriggerContext {
267
693
  id: string;
268
694
  title: string;
269
695
  };
696
+ /** Project metadata */
697
+ project: {
698
+ slug: string;
699
+ id: string;
700
+ name: string;
701
+ };
270
702
  /** Run metadata */
271
703
  run: {
272
704
  id: string;
@@ -333,6 +765,7 @@ type PreprocessResults = {
333
765
  properties: DisplayProperty[];
334
766
  };
335
767
  type TriggerEventType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? ReturnType<TEventSpec["parsePayload"]> : never;
768
+ type TriggerInvokeType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? TEventSpec["parseInvokePayload"] extends (payload: unknown) => infer TInvoke ? TInvoke : any : never;
336
769
  interface Trigger<TEventSpec extends EventSpecification<any>> {
337
770
  event: TEventSpec;
338
771
  toJSON(): TriggerMetadata;
@@ -346,7 +779,7 @@ type EventSpecificationExample = {
346
779
  icon?: string;
347
780
  payload: any;
348
781
  };
349
- interface EventSpecification<TEvent extends any> {
782
+ interface EventSpecification<TEvent extends any, TInvoke extends any = TEvent> {
350
783
  name: string | string[];
351
784
  title: string;
352
785
  source: string;
@@ -356,6 +789,7 @@ interface EventSpecification<TEvent extends any> {
356
789
  examples?: Array<EventSpecificationExample>;
357
790
  filter?: EventFilter;
358
791
  parsePayload: (payload: unknown) => TEvent;
792
+ parseInvokePayload?: (payload: unknown) => TInvoke;
359
793
  runProperties?: (payload: TEvent) => DisplayProperty[];
360
794
  }
361
795
  type EventTypeFromSpecification<TEventSpec extends EventSpecification<any>> = TEventSpec extends EventSpecification<infer TEvent> ? TEvent : never;
@@ -734,8 +1168,8 @@ declare class TriggerClient {
734
1168
  #private;
735
1169
  id: string;
736
1170
  constructor(options: Prettify<TriggerClientOptions>);
737
- handleRequest(request: Request): Promise<NormalizedResponse>;
738
- defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
1171
+ handleRequest(request: Request, timeOrigin?: number): Promise<NormalizedResponse>;
1172
+ defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any>(options: JobOptions<TTrigger, TIntegrations, TOutput>): Job<TTrigger, TIntegrations, TOutput>;
739
1173
  defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
740
1174
  defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
741
1175
  defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
@@ -751,7 +1185,7 @@ declare class TriggerClient {
751
1185
  }): void;
752
1186
  attachDynamicSchedule(key: string): void;
753
1187
  attachDynamicScheduleToJob(key: string, job: Job<Trigger<any>, any>): void;
754
- registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
1188
+ registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2, idempotencyKey?: string): Promise<{
755
1189
  id: string;
756
1190
  options: {
757
1191
  event: {
@@ -788,7 +1222,7 @@ declare class TriggerClient {
788
1222
  scopes?: string[] | undefined;
789
1223
  additionalFields?: Record<string, string> | undefined;
790
1224
  } | undefined>;
791
- /** 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.
1225
+ /** 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.
792
1226
  * @param event The event to send.
793
1227
  * @param options Options for sending the event.
794
1228
  * @returns A promise that resolves to the event details
@@ -821,6 +1255,10 @@ declare class TriggerClient {
821
1255
  deliveredAt?: Date | null | undefined;
822
1256
  cancelledAt?: Date | null | undefined;
823
1257
  }>;
1258
+ cancelRunsForEvent(eventId: string): Promise<{
1259
+ cancelledRunIds: string[];
1260
+ failedToCancelRunIds: string[];
1261
+ }>;
824
1262
  updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
825
1263
  label: string;
826
1264
  key: string;
@@ -874,8 +1312,28 @@ declare class TriggerClient {
874
1312
  status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
875
1313
  updatedAt: Date | null;
876
1314
  tasks: _trigger_dev_core.RunTaskWithSubtasks[];
1315
+ statuses: {
1316
+ label: string;
1317
+ key: string;
1318
+ history: {
1319
+ label?: string | undefined;
1320
+ state?: "loading" | "success" | "failure" | undefined;
1321
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1322
+ }[];
1323
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1324
+ state?: "loading" | "success" | "failure" | undefined;
1325
+ }[];
877
1326
  output?: any;
878
- statuses?: {
1327
+ nextCursor?: string | undefined;
1328
+ }>;
1329
+ cancelRun(runId: string): Promise<{
1330
+ id: string;
1331
+ startedAt: Date | null;
1332
+ completedAt: Date | null;
1333
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
1334
+ updatedAt: Date | null;
1335
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
1336
+ statuses: {
879
1337
  label: string;
880
1338
  key: string;
881
1339
  history: {
@@ -885,7 +1343,8 @@ declare class TriggerClient {
885
1343
  }[];
886
1344
  data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
887
1345
  state?: "loading" | "success" | "failure" | undefined;
888
- }[] | undefined;
1346
+ }[];
1347
+ output?: any;
889
1348
  nextCursor?: string | undefined;
890
1349
  }>;
891
1350
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
@@ -916,38 +1375,30 @@ declare class TriggerClient {
916
1375
  output?: any;
917
1376
  };
918
1377
  }>;
1378
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
1379
+ id: string;
1380
+ }>;
919
1381
  authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
920
1382
  apiKey(): string | undefined;
921
1383
  }
922
1384
 
923
- declare class TriggerStatus {
924
- private id;
925
- private io;
926
- constructor(id: string, io: IO);
927
- update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
928
- label: string;
929
- key: string;
930
- history: {
931
- label?: string | undefined;
932
- state?: "loading" | "success" | "failure" | undefined;
933
- data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
934
- }[];
935
- data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
936
- state?: "loading" | "success" | "failure" | undefined;
937
- }>;
938
- }
939
-
940
1385
  type IOTask = ServerTask;
941
1386
  type IOOptions = {
942
1387
  id: string;
943
1388
  apiClient: ApiClient;
944
1389
  client: TriggerClient;
945
1390
  context: TriggerContext;
1391
+ timeOrigin: number;
946
1392
  logger?: Logger;
947
1393
  logLevel?: LogLevel;
948
1394
  jobLogger?: Logger;
949
1395
  jobLogLevel: LogLevel;
950
1396
  cachedTasks?: Array<CachedTask>;
1397
+ cachedTasksCursor?: string;
1398
+ yieldedExecutions?: Array<string>;
1399
+ noopTasksSet?: string;
1400
+ serverVersion?: string | null;
1401
+ executionTimeout?: number;
951
1402
  };
952
1403
  type JsonPrimitive = string | number | boolean | null | undefined | Date | symbol;
953
1404
  type JsonArray = Json[];
@@ -961,6 +1412,23 @@ type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
961
1412
  jitter?: number;
962
1413
  skipRetrying?: boolean;
963
1414
  } | Error | undefined | void;
1415
+ type IOStats = {
1416
+ initialCachedTasks: number;
1417
+ lazyLoadedCachedTasks: number;
1418
+ executedTasks: number;
1419
+ cachedTaskHits: number;
1420
+ cachedTaskMisses: number;
1421
+ noopCachedTaskHits: number;
1422
+ noopCachedTaskMisses: number;
1423
+ };
1424
+ interface OutputSerializer {
1425
+ serialize(value: any): string;
1426
+ deserialize<T>(value: string): T;
1427
+ }
1428
+ declare class JSONOutputSerializer implements OutputSerializer {
1429
+ serialize(value: any): string;
1430
+ deserialize(value?: string): any;
1431
+ }
964
1432
  declare class IO {
965
1433
  #private;
966
1434
  private _id;
@@ -971,17 +1439,27 @@ declare class IO {
971
1439
  private _jobLogLevel;
972
1440
  private _cachedTasks;
973
1441
  private _taskStorage;
1442
+ private _cachedTasksCursor?;
974
1443
  private _context;
1444
+ private _yieldedExecutions;
1445
+ private _noopTasksBloomFilter;
1446
+ private _stats;
1447
+ private _serverVersion;
1448
+ private _timeOrigin;
1449
+ private _executionTimeout?;
1450
+ private _outputSerializer;
1451
+ private _visitedCacheKeys;
1452
+ get stats(): IOStats;
975
1453
  constructor(options: IOOptions);
976
1454
  /** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
977
1455
  get logger(): IOLogger;
978
1456
  /** `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.
979
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1457
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
980
1458
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
981
1459
  */
982
- wait(key: string | any[], seconds: number): Promise<void>;
1460
+ wait(cacheKey: string | any[], seconds: number): Promise<void>;
983
1461
  /** `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
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.
1462
+ * @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
1463
  * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
986
1464
  * @returns a TriggerStatus object that you can call `update()` on, to update the status.
987
1465
  * @example
@@ -1012,9 +1490,9 @@ declare class IO {
1012
1490
  });
1013
1491
  * ```
1014
1492
  */
1015
- createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
1493
+ createStatus(cacheKey: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
1016
1494
  /** `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.
1017
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1495
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1018
1496
  * @param url The URL to fetch from.
1019
1497
  * @param requestInit The options for the request
1020
1498
  * @param retry The options for retrying the request if it fails
@@ -1024,13 +1502,13 @@ declare class IO {
1024
1502
  * - Ranges: 500-599
1025
1503
  * - Wildcards: 2xx, 3xx, 4xx, 5xx
1026
1504
  */
1027
- backgroundFetch<TResponseData>(key: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
1505
+ backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions, timeout?: FetchTimeoutOptions): Promise<TResponseData>;
1028
1506
  /** `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).
1029
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1507
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1030
1508
  * @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
1031
1509
  * @param options Options for sending the event.
1032
1510
  */
1033
- sendEvent(key: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
1511
+ sendEvent(cacheKey: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
1034
1512
  id: string;
1035
1513
  name: string;
1036
1514
  payload: ((string | number | boolean | {
@@ -1044,7 +1522,7 @@ declare class IO {
1044
1522
  deliveredAt?: Date | null | undefined;
1045
1523
  cancelledAt?: Date | null | undefined;
1046
1524
  }>;
1047
- getEvent(key: string | any[], id: string): Promise<{
1525
+ getEvent(cacheKey: string | any[], id: string): Promise<{
1048
1526
  id: string;
1049
1527
  name: string;
1050
1528
  updatedAt: Date;
@@ -1057,11 +1535,11 @@ declare class IO {
1057
1535
  createdAt: Date;
1058
1536
  }>;
1059
1537
  /** `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
1060
- * @param key
1538
+ * @param cacheKey
1061
1539
  * @param eventId
1062
1540
  * @returns
1063
1541
  */
1064
- cancelEvent(key: string | any[], eventId: string): Promise<{
1542
+ cancelEvent(cacheKey: string | any[], eventId: string): Promise<{
1065
1543
  id: string;
1066
1544
  name: string;
1067
1545
  payload: ((string | number | boolean | {
@@ -1075,21 +1553,21 @@ declare class IO {
1075
1553
  deliveredAt?: Date | null | undefined;
1076
1554
  cancelledAt?: Date | null | undefined;
1077
1555
  }>;
1078
- updateSource(key: string | any[], options: {
1556
+ updateSource(cacheKey: string | any[], options: {
1079
1557
  key: string;
1080
1558
  } & UpdateTriggerSourceBodyV2): Promise<{
1081
1559
  id: string;
1082
1560
  key: string;
1083
1561
  }>;
1084
1562
  /** `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.
1085
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1563
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1086
1564
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
1087
1565
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1088
1566
  * @param options The options for the interval.
1089
1567
  * @returns A promise that has information about the interval.
1090
1568
  * @deprecated Use `DynamicSchedule.register` instead.
1091
1569
  */
1092
- registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
1570
+ registerInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
1093
1571
  id: string;
1094
1572
  schedule: {
1095
1573
  options: {
@@ -1110,22 +1588,22 @@ declare class IO {
1110
1588
  metadata?: any;
1111
1589
  }>;
1112
1590
  /** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
1113
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1591
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1114
1592
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
1115
1593
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1116
1594
  * @deprecated Use `DynamicSchedule.unregister` instead.
1117
1595
  */
1118
- unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1596
+ unregisterInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1119
1597
  ok: boolean;
1120
1598
  }>;
1121
1599
  /** `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.
1122
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1600
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1123
1601
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
1124
1602
  * @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
1125
1603
  * @param options The options for the CRON schedule.
1126
1604
  * @deprecated Use `DynamicSchedule.register` instead.
1127
1605
  */
1128
- registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
1606
+ registerCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
1129
1607
  id: string;
1130
1608
  schedule: {
1131
1609
  options: {
@@ -1146,35 +1624,44 @@ declare class IO {
1146
1624
  metadata?: any;
1147
1625
  }>;
1148
1626
  /** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
1149
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1627
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1150
1628
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
1151
1629
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1152
1630
  * @deprecated Use `DynamicSchedule.unregister` instead.
1153
1631
  */
1154
- unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1632
+ unregisterCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1155
1633
  ok: boolean;
1156
1634
  }>;
1157
1635
  /** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
1158
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1636
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1159
1637
  * @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
1160
1638
  * @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
1161
1639
  * @param params The params for the trigger.
1162
1640
  * @deprecated Use `DynamicTrigger.register` instead.
1163
1641
  */
1164
- registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
1642
+ registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(cacheKey: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
1165
1643
  id: string;
1166
1644
  key: string;
1167
1645
  } | undefined>;
1168
- getAuth(key: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
1646
+ getAuth(cacheKey: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
1647
+ 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>>;
1169
1648
  /** `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.
1170
1649
  *
1171
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1650
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1172
1651
  * @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
1173
1652
  * @param options The options of how you'd like to run and log the Task.
1174
1653
  * @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.
1175
1654
  * @returns A Promise that resolves with the returned value of the callback.
1176
1655
  */
1177
- runTask<T extends Json<T> | void>(key: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
1656
+ runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
1657
+ /**
1658
+ * `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.
1659
+ */
1660
+ yield(cacheKey: string): void;
1661
+ /**
1662
+ * `io.brb()` is an alias of `io.yield()`
1663
+ */
1664
+ brb: (cacheKey: string) => void;
1178
1665
  /** `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).
1179
1666
  * 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.
1180
1667
  * @param tryCallback The code you wish to run
@@ -1208,7 +1695,7 @@ interface TriggerIntegration {
1208
1695
  type IOWithIntegrations<TIntegrations extends Record<string, TriggerIntegration>> = IO & TIntegrations;
1209
1696
  type IntegrationTaskKey = string | any[];
1210
1697
 
1211
- type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> = {
1698
+ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> = {
1212
1699
  /** The `id` property is used to uniquely identify the Job. Only change this if you want to create a new Job. */
1213
1700
  id: string;
1214
1701
  /** The `name` of the Job that you want to appear in the dashboard and logs. You can change this without creating a new Job. */
@@ -1254,19 +1741,19 @@ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations
1254
1741
  * @param io An object that contains the integrations that you specified in the `integrations` property and other useful functions like delays and running Tasks.
1255
1742
  * @param context An object that contains information about the Organization, Job, Run and more.
1256
1743
  */
1257
- run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<any>;
1744
+ run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<TOutput>;
1258
1745
  };
1259
1746
  type JobPayload<TJob> = TJob extends Job<Trigger<EventSpecification<infer TEvent>>, any> ? TEvent : never;
1260
1747
  type JobIO<TJob> = TJob extends Job<any, infer TIntegrations> ? IOWithIntegrations<TIntegrations> : never;
1261
1748
  /** 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. */
1262
- declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> {
1749
+ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> {
1263
1750
  #private;
1264
- readonly options: JobOptions<TTrigger, TIntegrations>;
1751
+ readonly options: JobOptions<TTrigger, TIntegrations, TOutput>;
1265
1752
  client: TriggerClient;
1266
1753
  constructor(
1267
1754
  /** An instance of [TriggerClient](/sdk/triggerclient) that is used to send events
1268
1755
  to the Trigger API. */
1269
- client: TriggerClient, options: JobOptions<TTrigger, TIntegrations>);
1756
+ client: TriggerClient, options: JobOptions<TTrigger, TIntegrations, TOutput>);
1270
1757
  get id(): string;
1271
1758
  get enabled(): boolean;
1272
1759
  get name(): string;
@@ -1275,6 +1762,19 @@ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegratio
1275
1762
  get logLevel(): LogLevel | undefined;
1276
1763
  get integrations(): Record<string, IntegrationConfig>;
1277
1764
  toJSON(): JobMetadata;
1765
+ invoke(cacheKey: string, payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
1766
+ id: string;
1767
+ }>;
1768
+ invoke(payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
1769
+ id: string;
1770
+ }>;
1771
+ invokeAndWaitForCompletion(cacheKey: string | string[], payload: TriggerInvokeType<TTrigger>, timeoutInSeconds?: number, // 1 hour
1772
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>): Promise<RunNotification<TOutput>>;
1773
+ batchInvokeAndWaitForCompletion(cacheKey: string | string[], batch: Array<{
1774
+ payload: TriggerInvokeType<TTrigger>;
1775
+ timeoutInSeconds?: number;
1776
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>;
1777
+ }>): Promise<Array<RunNotification<TOutput>>>;
1278
1778
  }
1279
1779
 
1280
1780
  type EventTriggerOptions<TEventSpecification extends EventSpecification<any>> = {
@@ -1428,10 +1928,41 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1428
1928
  toJSON(): TriggerMetadata;
1429
1929
  }
1430
1930
 
1931
+ /** Configuration options for an InvokeTrigger */
1932
+ type InvokeTriggerOptions<TSchema extends ZodType = z.ZodTypeAny> = {
1933
+ /** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
1934
+ * The default is `z.any()` which is `any`.
1935
+ * */
1936
+ schema?: TSchema;
1937
+ examples?: EventSpecificationExample[];
1938
+ };
1939
+ declare class InvokeTrigger<TSchema extends ZodType = z.ZodTypeAny> implements Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>> {
1940
+ #private;
1941
+ constructor(options: InvokeTriggerOptions<TSchema>);
1942
+ toJSON(): TriggerMetadata;
1943
+ get event(): {
1944
+ name: string;
1945
+ title: string;
1946
+ source: string;
1947
+ examples: EventSpecificationExample[];
1948
+ icon: string;
1949
+ parsePayload: (rawPayload: unknown) => any;
1950
+ parseInvokePayload: (rawPayload: unknown) => any;
1951
+ };
1952
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<EventSpecification<ZodType<TSchema>>>, any>): void;
1953
+ get preprocessRuns(): boolean;
1954
+ }
1955
+ declare function invokeTrigger<TSchema extends ZodType = z.ZodTypeAny>(options?: InvokeTriggerOptions<TSchema>): Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>>;
1956
+
1431
1957
  declare class ResumeWithTaskError {
1432
1958
  task: ServerTask;
1433
1959
  constructor(task: ServerTask);
1434
1960
  }
1961
+ declare class ResumeWithParallelTaskError {
1962
+ task: ServerTask;
1963
+ childErrors: Array<TriggerInternalError>;
1964
+ constructor(task: ServerTask, childErrors: Array<TriggerInternalError>);
1965
+ }
1435
1966
  declare class RetryWithTaskError {
1436
1967
  cause: ErrorWithStack;
1437
1968
  task: ServerTask;
@@ -1442,13 +1973,39 @@ declare class CanceledWithTaskError {
1442
1973
  task: ServerTask;
1443
1974
  constructor(task: ServerTask);
1444
1975
  }
1976
+ declare class YieldExecutionError {
1977
+ key: string;
1978
+ constructor(key: string);
1979
+ }
1980
+ declare class AutoYieldExecutionError {
1981
+ location: string;
1982
+ timeRemaining: number;
1983
+ timeElapsed: number;
1984
+ constructor(location: string, timeRemaining: number, timeElapsed: number);
1985
+ }
1986
+ declare class AutoYieldWithCompletedTaskExecutionError {
1987
+ id: string;
1988
+ properties: DisplayProperty[] | undefined;
1989
+ data: {
1990
+ location: string;
1991
+ timeRemaining: number;
1992
+ timeElapsed: number;
1993
+ };
1994
+ output?: string | undefined;
1995
+ constructor(id: string, properties: DisplayProperty[] | undefined, data: {
1996
+ location: string;
1997
+ timeRemaining: number;
1998
+ timeElapsed: number;
1999
+ }, output?: string | undefined);
2000
+ }
2001
+ type TriggerInternalError = ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError | YieldExecutionError | AutoYieldExecutionError | AutoYieldWithCompletedTaskExecutionError | ResumeWithParallelTaskError;
1445
2002
  /** Use this function if you're using a `try/catch` block to catch errors.
1446
2003
  * It checks if a thrown error is a special internal error that you should ignore.
1447
2004
  * If this returns `true` then you must rethrow the error: `throw err;`
1448
2005
  * @param err The error to check
1449
2006
  * @returns `true` if the error is a Trigger Error, `false` otherwise.
1450
2007
  */
1451
- declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError;
2008
+ declare function isTriggerError(err: unknown): err is TriggerInternalError;
1452
2009
 
1453
2010
  declare const retry: {
1454
2011
  readonly standardBackoff: {
@@ -1465,4 +2022,4 @@ type Task = ServerTask;
1465
2022
  type SentEvent = ApiEventLog;
1466
2023
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1467
2024
 
1468
- export { AuthResolverResult, 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, 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 };
2025
+ 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, InvokeTrigger, JSONOutputSerializer, Job, JobIO, JobOptions, JobPayload, Json, MissingConnectionNotification, MissingConnectionResolvedNotification, OutputSerializer, PreprocessResults, RunTaskErrorCallback, SchemaParser, SchemaParserIssue, SchemaParserResult, SentEvent, Task, TaskLogger, Trigger, TriggerAuthResolver, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerInvokeType, TriggerOptionRecord, TriggerPayload, TriggerPreprocessContext, cronTrigger, eventTrigger, intervalTrigger, invokeTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry };