@trigger.dev/sdk 2.2.4 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,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, EphemeralEventDispatcherRequestBody, LogLevel, RuntimeEnvironmentType, DisplayProperty, TriggerMetadata, EventFilter, HttpEndpointMetadata, RequestFilter, Prettify, HandleTriggerSource, Logger, RegisterTriggerSource, SerializableJson, ConnectionAuth, NormalizedResponse, HttpSourceResponseMetadata, IntervalOptions, CronOptions, ScheduledPayload, DeserializedJson, ServerTask, CachedTask, InitialStatusUpdate, FetchRequestInit, FetchRetryOptions, FetchTimeoutOptions, FetchPollOperation, 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 } from 'zod';
5
+ import { z, ZodType, TypeOf } from 'zod';
6
6
 
7
7
  type ApiClientOptions = {
8
8
  apiKey?: string;
@@ -40,29 +40,36 @@ declare class ApiClient {
40
40
  label: z.ZodString;
41
41
  text: z.ZodString;
42
42
  url: z.ZodOptional<z.ZodString>;
43
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
43
44
  }, "strip", z.ZodTypeAny, {
44
45
  label: string;
45
46
  text: string;
46
47
  url?: string | undefined;
48
+ imageUrl?: string[] | undefined;
47
49
  }, {
48
50
  label: string;
49
51
  text: string;
50
52
  url?: string | undefined;
53
+ imageUrl?: string[] | undefined;
51
54
  }>, "many">>>;
52
55
  outputProperties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
53
56
  label: z.ZodString;
54
57
  text: z.ZodString;
55
58
  url: z.ZodOptional<z.ZodString>;
59
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
56
60
  }, "strip", z.ZodTypeAny, {
57
61
  label: string;
58
62
  text: string;
59
63
  url?: string | undefined;
64
+ imageUrl?: string[] | undefined;
60
65
  }, {
61
66
  label: string;
62
67
  text: string;
63
68
  url?: string | undefined;
69
+ imageUrl?: string[] | undefined;
64
70
  }>, "many">>>;
65
71
  output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
72
+ context: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
66
73
  error: z.ZodNullable<z.ZodOptional<z.ZodString>>;
67
74
  parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
68
75
  style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
@@ -77,6 +84,7 @@ declare class ApiClient {
77
84
  }>>>;
78
85
  operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
79
86
  callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
87
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
80
88
  idempotencyKey: z.ZodString;
81
89
  attempts: z.ZodNumber;
82
90
  forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
@@ -97,13 +105,16 @@ declare class ApiClient {
97
105
  label: string;
98
106
  text: string;
99
107
  url?: string | undefined;
108
+ imageUrl?: string[] | undefined;
100
109
  }[] | null | undefined;
101
110
  outputProperties?: {
102
111
  label: string;
103
112
  text: string;
104
113
  url?: string | undefined;
114
+ imageUrl?: string[] | undefined;
105
115
  }[] | null | undefined;
106
116
  output?: _trigger_dev_core.DeserializedJson | undefined;
117
+ context?: _trigger_dev_core.DeserializedJson | undefined;
107
118
  error?: string | null | undefined;
108
119
  parentId?: string | null | undefined;
109
120
  style?: {
@@ -112,6 +123,7 @@ declare class ApiClient {
112
123
  } | null | undefined;
113
124
  operation?: string | null | undefined;
114
125
  callbackUrl?: string | null | undefined;
126
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
115
127
  forceYield?: boolean | null | undefined;
116
128
  }, {
117
129
  id: string;
@@ -130,13 +142,16 @@ declare class ApiClient {
130
142
  label: string;
131
143
  text: string;
132
144
  url?: string | undefined;
145
+ imageUrl?: string[] | undefined;
133
146
  }[] | null | undefined;
134
147
  outputProperties?: {
135
148
  label: string;
136
149
  text: string;
137
150
  url?: string | undefined;
151
+ imageUrl?: string[] | undefined;
138
152
  }[] | null | undefined;
139
153
  output?: _trigger_dev_core.DeserializedJson | undefined;
154
+ context?: _trigger_dev_core.DeserializedJson | undefined;
140
155
  error?: string | null | undefined;
141
156
  parentId?: string | null | undefined;
142
157
  style?: {
@@ -145,6 +160,7 @@ declare class ApiClient {
145
160
  } | null | undefined;
146
161
  operation?: string | null | undefined;
147
162
  callbackUrl?: string | null | undefined;
163
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
148
164
  forceYield?: boolean | null | undefined;
149
165
  }>;
150
166
  cachedTasks: z.ZodOptional<z.ZodObject<{
@@ -210,13 +226,16 @@ declare class ApiClient {
210
226
  label: string;
211
227
  text: string;
212
228
  url?: string | undefined;
229
+ imageUrl?: string[] | undefined;
213
230
  }[] | null | undefined;
214
231
  outputProperties?: {
215
232
  label: string;
216
233
  text: string;
217
234
  url?: string | undefined;
235
+ imageUrl?: string[] | undefined;
218
236
  }[] | null | undefined;
219
237
  output?: _trigger_dev_core.DeserializedJson | undefined;
238
+ context?: _trigger_dev_core.DeserializedJson | undefined;
220
239
  error?: string | null | undefined;
221
240
  parentId?: string | null | undefined;
222
241
  style?: {
@@ -225,6 +244,7 @@ declare class ApiClient {
225
244
  } | null | undefined;
226
245
  operation?: string | null | undefined;
227
246
  callbackUrl?: string | null | undefined;
247
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
228
248
  forceYield?: boolean | null | undefined;
229
249
  };
230
250
  cachedTasks?: {
@@ -256,13 +276,16 @@ declare class ApiClient {
256
276
  label: string;
257
277
  text: string;
258
278
  url?: string | undefined;
279
+ imageUrl?: string[] | undefined;
259
280
  }[] | null | undefined;
260
281
  outputProperties?: {
261
282
  label: string;
262
283
  text: string;
263
284
  url?: string | undefined;
285
+ imageUrl?: string[] | undefined;
264
286
  }[] | null | undefined;
265
287
  output?: _trigger_dev_core.DeserializedJson | undefined;
288
+ context?: _trigger_dev_core.DeserializedJson | undefined;
266
289
  error?: string | null | undefined;
267
290
  parentId?: string | null | undefined;
268
291
  style?: {
@@ -271,6 +294,7 @@ declare class ApiClient {
271
294
  } | null | undefined;
272
295
  operation?: string | null | undefined;
273
296
  callbackUrl?: string | null | undefined;
297
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
274
298
  forceYield?: boolean | null | undefined;
275
299
  };
276
300
  cachedTasks?: {
@@ -300,29 +324,36 @@ declare class ApiClient {
300
324
  label: z.ZodString;
301
325
  text: z.ZodString;
302
326
  url: z.ZodOptional<z.ZodString>;
327
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
303
328
  }, "strip", z.ZodTypeAny, {
304
329
  label: string;
305
330
  text: string;
306
331
  url?: string | undefined;
332
+ imageUrl?: string[] | undefined;
307
333
  }, {
308
334
  label: string;
309
335
  text: string;
310
336
  url?: string | undefined;
337
+ imageUrl?: string[] | undefined;
311
338
  }>, "many">>>;
312
339
  outputProperties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
313
340
  label: z.ZodString;
314
341
  text: z.ZodString;
315
342
  url: z.ZodOptional<z.ZodString>;
343
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
316
344
  }, "strip", z.ZodTypeAny, {
317
345
  label: string;
318
346
  text: string;
319
347
  url?: string | undefined;
348
+ imageUrl?: string[] | undefined;
320
349
  }, {
321
350
  label: string;
322
351
  text: string;
323
352
  url?: string | undefined;
353
+ imageUrl?: string[] | undefined;
324
354
  }>, "many">>>;
325
355
  output: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
356
+ context: z.ZodNullable<z.ZodOptional<z.ZodType<_trigger_dev_core.DeserializedJson, z.ZodTypeDef, _trigger_dev_core.DeserializedJson>>>;
326
357
  error: z.ZodNullable<z.ZodOptional<z.ZodString>>;
327
358
  parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
328
359
  style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
@@ -337,6 +368,7 @@ declare class ApiClient {
337
368
  }>>>;
338
369
  operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
339
370
  callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
371
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
340
372
  idempotencyKey: z.ZodString;
341
373
  attempts: z.ZodNumber;
342
374
  forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
@@ -357,13 +389,16 @@ declare class ApiClient {
357
389
  label: string;
358
390
  text: string;
359
391
  url?: string | undefined;
392
+ imageUrl?: string[] | undefined;
360
393
  }[] | null | undefined;
361
394
  outputProperties?: {
362
395
  label: string;
363
396
  text: string;
364
397
  url?: string | undefined;
398
+ imageUrl?: string[] | undefined;
365
399
  }[] | null | undefined;
366
400
  output?: _trigger_dev_core.DeserializedJson | undefined;
401
+ context?: _trigger_dev_core.DeserializedJson | undefined;
367
402
  error?: string | null | undefined;
368
403
  parentId?: string | null | undefined;
369
404
  style?: {
@@ -372,6 +407,7 @@ declare class ApiClient {
372
407
  } | null | undefined;
373
408
  operation?: string | null | undefined;
374
409
  callbackUrl?: string | null | undefined;
410
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
375
411
  forceYield?: boolean | null | undefined;
376
412
  }, {
377
413
  id: string;
@@ -390,13 +426,16 @@ declare class ApiClient {
390
426
  label: string;
391
427
  text: string;
392
428
  url?: string | undefined;
429
+ imageUrl?: string[] | undefined;
393
430
  }[] | null | undefined;
394
431
  outputProperties?: {
395
432
  label: string;
396
433
  text: string;
397
434
  url?: string | undefined;
435
+ imageUrl?: string[] | undefined;
398
436
  }[] | null | undefined;
399
437
  output?: _trigger_dev_core.DeserializedJson | undefined;
438
+ context?: _trigger_dev_core.DeserializedJson | undefined;
400
439
  error?: string | null | undefined;
401
440
  parentId?: string | null | undefined;
402
441
  style?: {
@@ -405,9 +444,10 @@ declare class ApiClient {
405
444
  } | null | undefined;
406
445
  operation?: string | null | undefined;
407
446
  callbackUrl?: string | null | undefined;
447
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
408
448
  forceYield?: boolean | null | undefined;
409
449
  }>>>;
410
- completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
450
+ completeTask(runId: string, id: string, task: CompleteTaskBodyV2Input): Promise<{
411
451
  id: string;
412
452
  name: string;
413
453
  noop: boolean;
@@ -424,13 +464,16 @@ declare class ApiClient {
424
464
  label: string;
425
465
  text: string;
426
466
  url?: string | undefined;
467
+ imageUrl?: string[] | undefined;
427
468
  }[] | null | undefined;
428
469
  outputProperties?: {
429
470
  label: string;
430
471
  text: string;
431
472
  url?: string | undefined;
473
+ imageUrl?: string[] | undefined;
432
474
  }[] | null | undefined;
433
475
  output?: _trigger_dev_core.DeserializedJson | undefined;
476
+ context?: _trigger_dev_core.DeserializedJson | undefined;
434
477
  error?: string | null | undefined;
435
478
  parentId?: string | null | undefined;
436
479
  style?: {
@@ -439,6 +482,7 @@ declare class ApiClient {
439
482
  } | null | undefined;
440
483
  operation?: string | null | undefined;
441
484
  callbackUrl?: string | null | undefined;
485
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
442
486
  forceYield?: boolean | null | undefined;
443
487
  }>;
444
488
  failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
@@ -458,13 +502,16 @@ declare class ApiClient {
458
502
  label: string;
459
503
  text: string;
460
504
  url?: string | undefined;
505
+ imageUrl?: string[] | undefined;
461
506
  }[] | null | undefined;
462
507
  outputProperties?: {
463
508
  label: string;
464
509
  text: string;
465
510
  url?: string | undefined;
511
+ imageUrl?: string[] | undefined;
466
512
  }[] | null | undefined;
467
513
  output?: _trigger_dev_core.DeserializedJson | undefined;
514
+ context?: _trigger_dev_core.DeserializedJson | undefined;
468
515
  error?: string | null | undefined;
469
516
  parentId?: string | null | undefined;
470
517
  style?: {
@@ -473,6 +520,7 @@ declare class ApiClient {
473
520
  } | null | undefined;
474
521
  operation?: string | null | undefined;
475
522
  callbackUrl?: string | null | undefined;
523
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
476
524
  forceYield?: boolean | null | undefined;
477
525
  }>;
478
526
  sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
@@ -489,6 +537,20 @@ declare class ApiClient {
489
537
  deliveredAt?: Date | null | undefined;
490
538
  cancelledAt?: Date | null | undefined;
491
539
  }>;
540
+ sendEvents(events: SendEvent[], options?: SendEventOptions): Promise<{
541
+ id: string;
542
+ name: string;
543
+ payload: ((string | number | boolean | {
544
+ [key: string]: _trigger_dev_core.DeserializedJson;
545
+ } | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
546
+ [key: string]: _trigger_dev_core.DeserializedJson;
547
+ } | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
548
+ timestamp: Date;
549
+ context?: _trigger_dev_core.DeserializedJson | undefined;
550
+ deliverAt?: Date | null | undefined;
551
+ deliveredAt?: Date | null | undefined;
552
+ cancelledAt?: Date | null | undefined;
553
+ }[]>;
492
554
  cancelEvent(eventId: string): Promise<{
493
555
  id: string;
494
556
  name: string;
@@ -631,6 +693,12 @@ declare class ApiClient {
631
693
  }[];
632
694
  nextCursor?: string | undefined;
633
695
  }>;
696
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
697
+ id: string;
698
+ }>;
699
+ createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
700
+ id: string;
701
+ }>;
634
702
  }
635
703
  type VersionedResponseBodyMap = {
636
704
  [key: string]: z.ZodTypeAny;
@@ -645,6 +713,23 @@ type VersionedResponseBody<TVersions extends VersionedResponseBodyMap, TUnversio
645
713
  body: z.infer<TUnversioned>;
646
714
  };
647
715
 
716
+ declare class TriggerStatus {
717
+ private id;
718
+ private io;
719
+ constructor(id: string, io: IO);
720
+ update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
721
+ label: string;
722
+ key: string;
723
+ history: {
724
+ label?: string | undefined;
725
+ state?: "loading" | "success" | "failure" | undefined;
726
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
727
+ }[];
728
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
729
+ state?: "loading" | "success" | "failure" | undefined;
730
+ }>;
731
+ }
732
+
648
733
  interface TriggerContext {
649
734
  /** Job metadata */
650
735
  job: {
@@ -663,6 +748,12 @@ interface TriggerContext {
663
748
  id: string;
664
749
  title: string;
665
750
  };
751
+ /** Project metadata */
752
+ project: {
753
+ slug: string;
754
+ id: string;
755
+ name: string;
756
+ };
666
757
  /** Run metadata */
667
758
  run: {
668
759
  id: string;
@@ -729,20 +820,39 @@ type PreprocessResults = {
729
820
  properties: DisplayProperty[];
730
821
  };
731
822
  type TriggerEventType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? ReturnType<TEventSpec["parsePayload"]> : never;
823
+ type TriggerInvokeType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? TEventSpec["parseInvokePayload"] extends (payload: unknown) => infer TInvoke ? TInvoke : any : never;
824
+ type VerifyResult = {
825
+ success: true;
826
+ } | {
827
+ success: false;
828
+ reason?: string;
829
+ };
732
830
  interface Trigger<TEventSpec extends EventSpecification<any>> {
733
831
  event: TEventSpec;
734
832
  toJSON(): TriggerMetadata;
735
833
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
736
834
  preprocessRuns: boolean;
835
+ verifyPayload: (payload: ReturnType<TEventSpec["parsePayload"]>) => Promise<VerifyResult>;
737
836
  }
738
837
  type TriggerPayload<TTrigger> = TTrigger extends Trigger<EventSpecification<infer TEvent>> ? TEvent : never;
739
- type EventSpecificationExample = {
838
+ declare const EventSpecificationExampleSchema: z.ZodObject<{
839
+ id: z.ZodString;
840
+ name: z.ZodString;
841
+ icon: z.ZodOptional<z.ZodString>;
842
+ payload: z.ZodAny;
843
+ }, "strip", z.ZodTypeAny, {
740
844
  id: string;
741
845
  name: string;
742
- icon?: string;
743
- payload: any;
744
- };
745
- interface EventSpecification<TEvent extends any> {
846
+ icon?: string | undefined;
847
+ payload?: any;
848
+ }, {
849
+ id: string;
850
+ name: string;
851
+ icon?: string | undefined;
852
+ payload?: any;
853
+ }>;
854
+ type EventSpecificationExample = z.infer<typeof EventSpecificationExampleSchema>;
855
+ interface EventSpecification<TEvent extends any, TInvoke extends any = TEvent> {
746
856
  name: string | string[];
747
857
  title: string;
748
858
  source: string;
@@ -752,6 +862,7 @@ interface EventSpecification<TEvent extends any> {
752
862
  examples?: Array<EventSpecificationExample>;
753
863
  filter?: EventFilter;
754
864
  parsePayload: (payload: unknown) => TEvent;
865
+ parseInvokePayload?: (payload: unknown) => TInvoke;
755
866
  runProperties?: (payload: TEvent) => DisplayProperty[];
756
867
  }
757
868
  type EventTypeFromSpecification<TEventSpec extends EventSpecification<any>> = TEventSpec extends EventSpecification<infer TEvent> ? TEvent : never;
@@ -771,6 +882,122 @@ type SchemaParserResult<T> = {
771
882
  type SchemaParser<T extends unknown = unknown> = {
772
883
  safeParse: (a: unknown) => SchemaParserResult<T>;
773
884
  };
885
+ type WaitForEventResult<TEvent> = {
886
+ id: string;
887
+ name: string;
888
+ source: string;
889
+ payload: TEvent;
890
+ timestamp: Date;
891
+ context?: any;
892
+ accountId?: string;
893
+ };
894
+ declare function waitForEventSchema(schema: z.ZodTypeAny): z.ZodObject<{
895
+ id: z.ZodString;
896
+ name: z.ZodString;
897
+ source: z.ZodString;
898
+ payload: z.ZodTypeAny;
899
+ timestamp: z.ZodDate;
900
+ context: z.ZodOptional<z.ZodAny>;
901
+ accountId: z.ZodOptional<z.ZodString>;
902
+ }, "strip", z.ZodTypeAny, {
903
+ id: string;
904
+ name: string;
905
+ timestamp: Date;
906
+ source: string;
907
+ payload?: any;
908
+ context?: any;
909
+ accountId?: string | undefined;
910
+ }, {
911
+ id: string;
912
+ name: string;
913
+ timestamp: Date;
914
+ source: string;
915
+ payload?: any;
916
+ context?: any;
917
+ accountId?: string | undefined;
918
+ }>;
919
+
920
+ type HttpEndpointOptions<TEventSpecification extends EventSpecification<any>> = {
921
+ id: string;
922
+ enabled?: boolean;
923
+ event: TEventSpecification;
924
+ respondWith?: RespondWith;
925
+ verify: VerifyCallback;
926
+ };
927
+ type RequestOptions = {
928
+ filter?: RequestFilter;
929
+ };
930
+ declare class HttpEndpoint<TEventSpecification extends EventSpecification<any>> {
931
+ private readonly options;
932
+ constructor(options: HttpEndpointOptions<TEventSpecification>);
933
+ get id(): string;
934
+ onRequest(options?: RequestOptions): HttpTrigger<EventSpecification<Request>>;
935
+ toJSON(): HttpEndpointMetadata;
936
+ }
937
+ type TriggerOptions$1<TEventSpecification extends EventSpecification<any>> = {
938
+ endpointId: string;
939
+ event: TEventSpecification;
940
+ filter?: EventFilter;
941
+ verify: VerifyCallback;
942
+ };
943
+ declare class HttpTrigger<TEventSpecification extends EventSpecification<any>> implements Trigger<TEventSpecification> {
944
+ private readonly options;
945
+ constructor(options: TriggerOptions$1<TEventSpecification>);
946
+ toJSON(): TriggerMetadata;
947
+ get event(): TEventSpecification;
948
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
949
+ get preprocessRuns(): boolean;
950
+ verifyPayload(payload: Request): Promise<VerifyResult>;
951
+ }
952
+ type RespondWith = {
953
+ /** Only Requests that match this filter will cause the `handler` function to run.
954
+ * For example, you can use this to only respond to `GET` Requests. */
955
+ filter?: RequestFilter;
956
+ /** If you set this to `true`, the Request that comes in won't go on to Trigger any Runs.
957
+ * This is useful if you want to Respond to the Request, but don't want to Trigger any Runs. */
958
+ skipTriggeringRuns?: boolean;
959
+ /** This is a function that's called when a Request comes in.
960
+ * It's passed the Request object, and expects you to return a Response object. */
961
+ handler: (request: Request, verify: () => Promise<VerifyResult>) => Promise<Response>;
962
+ };
963
+ type VerifyCallback = (request: Request) => Promise<VerifyResult>;
964
+ type EndpointOptions = {
965
+ /** Used to uniquely identify the HTTP Endpoint inside your Project. */
966
+ id: string;
967
+ enabled?: boolean;
968
+ /** Usually you would use the domain name of the service, e.g. `cal.com`. */
969
+ source: string;
970
+ /** An optional title, displayed in the dashboard. */
971
+ title?: string;
972
+ /** An optional icon name that's displayed in the dashboard.
973
+ * Lots of company names are supported, e.g. `github`, `twilio`.
974
+ * You can also reference the name of any [Tabler icon](https://tabler-icons.io/), e.g. `brand-google-maps`, `brand-twitch`. */
975
+ icon?: string;
976
+ /** Used to provide example payloads that are accepted by the job.
977
+ * This will be available in the dashboard and can be used to trigger test runs. */
978
+ examples?: EventSpecificationExample[];
979
+ /** Properties that are displayed in the dashboard. */
980
+ properties?: DisplayProperty[];
981
+ /** This optional object allows you to immediately Respond to a Request. This is useful for some APIs where they do a `GET` Request when the webhook is first setup and expect a specific Response.
982
+
983
+ Only use this if you really need to Respond to the Request that comes in. Most of the time you don't. */
984
+ respondWith?: RespondWith;
985
+ /** This is compulsory, and is used to verify that the received webhook is authentic.
986
+ * It's a function that expects you to return a result object like:
987
+
988
+ In 90% of cases, you'll want to use the `verifyRequestSignature` helper function we provide.
989
+
990
+ @example
991
+ ```ts
992
+ //if it's valid
993
+ return { success: true }
994
+ //if it's invalid, reason is optional
995
+ return { success: false, reason: "No header" }
996
+ ```
997
+
998
+ */
999
+ verify: VerifyCallback;
1000
+ };
774
1001
 
775
1002
  type HttpSourceEvent = {
776
1003
  url: string;
@@ -876,6 +1103,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration, TParams ex
876
1103
  id?: string | undefined;
877
1104
  timestamp?: Date | undefined;
878
1105
  source?: string | undefined;
1106
+ payloadType?: "JSON" | "REQUEST" | undefined;
879
1107
  }[];
880
1108
  response?: {
881
1109
  status: number;
@@ -914,6 +1142,9 @@ declare class ExternalSourceTrigger<TEventSpecification extends EventSpecificati
914
1142
  toJSON(): TriggerMetadata;
915
1143
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
916
1144
  get preprocessRuns(): boolean;
1145
+ verifyPayload(payload: ReturnType<TEventSpecification["parsePayload"]>): Promise<{
1146
+ success: true;
1147
+ }>;
917
1148
  }
918
1149
  declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, key: K): {
919
1150
  result: Omit<T, K>;
@@ -966,6 +1197,9 @@ declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExtern
966
1197
  }): Promise<RegisterSourceEventV2>;
967
1198
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
968
1199
  get preprocessRuns(): boolean;
1200
+ verifyPayload(payload: ReturnType<TEventSpec["parsePayload"]>): Promise<{
1201
+ success: true;
1202
+ }>;
969
1203
  }
970
1204
 
971
1205
  type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
@@ -997,6 +1231,9 @@ declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
997
1231
  };
998
1232
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
999
1233
  get preprocessRuns(): boolean;
1234
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1235
+ success: true;
1236
+ }>;
1000
1237
  toJSON(): TriggerMetadata;
1001
1238
  }
1002
1239
  /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
@@ -1031,6 +1268,9 @@ declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
1031
1268
  };
1032
1269
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1033
1270
  get preprocessRuns(): boolean;
1271
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1272
+ success: true;
1273
+ }>;
1034
1274
  toJSON(): TriggerMetadata;
1035
1275
  }
1036
1276
  /** `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.
@@ -1097,6 +1337,9 @@ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
1097
1337
  }>;
1098
1338
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1099
1339
  get preprocessRuns(): boolean;
1340
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1341
+ success: true;
1342
+ }>;
1100
1343
  toJSON(): TriggerMetadata;
1101
1344
  }
1102
1345
 
@@ -1131,10 +1374,17 @@ declare class TriggerClient {
1131
1374
  id: string;
1132
1375
  constructor(options: Prettify<TriggerClientOptions>);
1133
1376
  handleRequest(request: Request, timeOrigin?: number): Promise<NormalizedResponse>;
1134
- defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
1377
+ defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any>(options: JobOptions<TTrigger, TIntegrations, TOutput>): Job<TTrigger, TIntegrations, TOutput>;
1135
1378
  defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
1136
1379
  defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
1137
1380
  defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
1381
+ /**
1382
+ * An [HTTP endpoint](https://trigger.dev/docs/documentation/concepts/http-endpoints) allows you to create a [HTTP Trigger](https://trigger.dev/docs/documentation/concepts/triggers/http), which means you can trigger your Jobs from any webhooks.
1383
+ * @param options The Endpoint options
1384
+ * @returns An HTTP Endpoint, that can be used to create an HTTP Trigger.
1385
+ * @link https://trigger.dev/docs/documentation/concepts/http-endpoints
1386
+ */
1387
+ defineHttpEndpoint(options: EndpointOptions): HttpEndpoint<EventSpecification<Request, Request>>;
1138
1388
  attach(job: Job<Trigger<any>, any>): void;
1139
1389
  attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
1140
1390
  attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
@@ -1203,6 +1453,25 @@ declare class TriggerClient {
1203
1453
  deliveredAt?: Date | null | undefined;
1204
1454
  cancelledAt?: Date | null | undefined;
1205
1455
  }>;
1456
+ /** You can call this function from anywhere in your backend to send multiple events. The other way to send multiple events is by using [`io.sendEvents()`](https://trigger.dev/docs/sdk/io/sendevents) from inside a `run()` function.
1457
+ * @param events The events to send.
1458
+ * @param options Options for sending the events.
1459
+ * @returns A promise that resolves to an array of event details
1460
+ */
1461
+ sendEvents(events: SendEvent[], options?: SendEventOptions): Promise<{
1462
+ id: string;
1463
+ name: string;
1464
+ payload: ((string | number | boolean | {
1465
+ [key: string]: DeserializedJson;
1466
+ } | DeserializedJson[]) & (string | number | boolean | {
1467
+ [key: string]: DeserializedJson;
1468
+ } | DeserializedJson[] | undefined)) | null;
1469
+ timestamp: Date;
1470
+ context?: DeserializedJson | undefined;
1471
+ deliverAt?: Date | null | undefined;
1472
+ deliveredAt?: Date | null | undefined;
1473
+ cancelledAt?: Date | null | undefined;
1474
+ }[]>;
1206
1475
  cancelEvent(eventId: string): Promise<{
1207
1476
  id: string;
1208
1477
  name: string;
@@ -1337,27 +1606,16 @@ declare class TriggerClient {
1337
1606
  output?: any;
1338
1607
  };
1339
1608
  }>;
1609
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
1610
+ id: string;
1611
+ }>;
1612
+ createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
1613
+ id: string;
1614
+ }>;
1340
1615
  authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
1341
1616
  apiKey(): string | undefined;
1342
1617
  }
1343
1618
 
1344
- declare class TriggerStatus {
1345
- private id;
1346
- private io;
1347
- constructor(id: string, io: IO);
1348
- update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
1349
- label: string;
1350
- key: string;
1351
- history: {
1352
- label?: string | undefined;
1353
- state?: "loading" | "success" | "failure" | undefined;
1354
- data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1355
- }[];
1356
- data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1357
- state?: "loading" | "success" | "failure" | undefined;
1358
- }>;
1359
- }
1360
-
1361
1619
  type IOTask = ServerTask;
1362
1620
  type IOOptions = {
1363
1621
  id: string;
@@ -1397,6 +1655,19 @@ type IOStats = {
1397
1655
  noopCachedTaskHits: number;
1398
1656
  noopCachedTaskMisses: number;
1399
1657
  };
1658
+ interface OutputSerializer {
1659
+ serialize(value: any): string;
1660
+ deserialize<T>(value: string): T;
1661
+ }
1662
+ declare class JSONOutputSerializer implements OutputSerializer {
1663
+ serialize(value: any): string;
1664
+ deserialize(value?: string): any;
1665
+ }
1666
+ type BackgroundFetchResponse<T> = {
1667
+ status: number;
1668
+ data: T;
1669
+ headers: Record<string, string>;
1670
+ };
1400
1671
  declare class IO {
1401
1672
  #private;
1402
1673
  private _id;
@@ -1415,15 +1686,60 @@ declare class IO {
1415
1686
  private _serverVersion;
1416
1687
  private _timeOrigin;
1417
1688
  private _executionTimeout?;
1689
+ private _outputSerializer;
1690
+ private _visitedCacheKeys;
1418
1691
  get stats(): IOStats;
1419
1692
  constructor(options: IOOptions);
1420
1693
  /** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
1421
1694
  get logger(): IOLogger;
1695
+ /** `io.random()` is identical to `Math.random()` when called without options but ensures your random numbers are not regenerated on resume or retry. It will return a pseudo-random floating-point number between optional `min` (default: 0, inclusive) and `max` (default: 1, exclusive). Can optionally `round` to the nearest integer.
1696
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1697
+ * @param min Sets the lower bound (inclusive). Can't be higher than `max`.
1698
+ * @param max Sets the upper bound (exclusive). Can't be lower than `min`.
1699
+ * @param round Controls rounding to the nearest integer. Any `max` integer will become inclusive when enabled. Rounding with floating-point bounds may cause unexpected skew and boundary inclusivity.
1700
+ */
1701
+ random(cacheKey: string | any[], { min, max, round, }?: {
1702
+ min?: number;
1703
+ max?: number;
1704
+ round?: boolean;
1705
+ }): Promise<number>;
1422
1706
  /** `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.
1423
1707
  * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1424
1708
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
1425
1709
  */
1426
1710
  wait(cacheKey: string | any[], seconds: number): Promise<void>;
1711
+ waitForEvent<T extends z.ZodTypeAny = z.ZodTypeAny>(cacheKey: string | any[], event: {
1712
+ name: string;
1713
+ schema?: T;
1714
+ filter?: EventFilter;
1715
+ source?: string;
1716
+ contextFilter?: EventFilter;
1717
+ accountId?: string;
1718
+ }, options?: {
1719
+ timeoutInSeconds?: number;
1720
+ }): Promise<WaitForEventResult<z.output<T>>>;
1721
+ /** `io.waitForRequest()` allows you to pause the execution of a run until the url provided in the callback is POSTed to.
1722
+ * This is useful for integrating with external services that require a callback URL to be provided, or if you want to be able to wait until an action is performed somewhere else in your system.
1723
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1724
+ * @param callback A callback function that will provide the unique URL to POST to.
1725
+ * @param options Options for the callback.
1726
+ * @param options.timeoutInSeconds How long to wait for the request to be POSTed to the callback URL before timing out. Defaults to 1hr.
1727
+ * @returns The POSTed request JSON body.
1728
+ * @example
1729
+ * ```ts
1730
+ const result = await io.waitForRequest<{ message: string }>(
1731
+ "wait-for-request",
1732
+ async (url, task) => {
1733
+ // Save the URL somewhere so you can POST to it later
1734
+ // Or send it to an external service that will POST to it
1735
+ },
1736
+ { timeoutInSeconds: 60 } // wait 60 seconds
1737
+ );
1738
+ * ```
1739
+ */
1740
+ waitForRequest<T extends Json<T> | unknown = unknown>(cacheKey: string | any[], callback: (url: string) => Promise<unknown>, options?: {
1741
+ timeoutInSeconds?: number;
1742
+ }): Promise<T>;
1427
1743
  /** `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
1428
1744
  * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1429
1745
  * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
@@ -1468,8 +1784,60 @@ declare class IO {
1468
1784
  * - Ranges: 500-599
1469
1785
  * - Wildcards: 2xx, 3xx, 4xx, 5xx
1470
1786
  */
1471
- backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
1472
- /** `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).
1787
+ backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, options?: {
1788
+ retry?: FetchRetryOptions;
1789
+ timeout?: FetchTimeoutOptions;
1790
+ }): Promise<TResponseData>;
1791
+ /** `io.backgroundPoll()` will fetch data from a URL on an interval. The actual `fetch` requests are performed on the Trigger.dev server, so you don't have to worry about serverless function timeouts.
1792
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1793
+ * @param params The options for the background poll
1794
+ * @param params.url The URL to fetch from.
1795
+ * @param params.requestInit The options for the request, like headers and method
1796
+ * @param params.responseFilter An [EventFilter](https://trigger.dev/docs/documentation/guides/event-filter) that allows you to specify when to stop polling.
1797
+ * @param params.interval The interval in seconds to poll the URL in seconds. Defaults to 10 seconds which is the minimum.
1798
+ * @param params.timeout The timeout in seconds for each request in seconds. Defaults to 10 minutes. Minimum is 60 seconds and max is 1 hour
1799
+ * @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
1800
+ * @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
1801
+ * @param params.requestTimeout.durationInMs The duration in milliseconds to timeout the request
1802
+ *
1803
+ * @example
1804
+ * ```ts
1805
+ * const result = await io.backgroundPoll<{ id: string; status: string; }>("poll", {
1806
+ url: `http://localhost:3030/api/v1/runs/${run.id}`,
1807
+ requestInit: {
1808
+ headers: {
1809
+ Accept: "application/json",
1810
+ Authorization: redactString`Bearer ${process.env["TRIGGER_API_KEY"]!}`,
1811
+ },
1812
+ },
1813
+ interval: 10,
1814
+ timeout: 600,
1815
+ responseFilter: {
1816
+ status: [200],
1817
+ body: {
1818
+ status: ["SUCCESS"],
1819
+ },
1820
+ },
1821
+ });
1822
+ * ```
1823
+ */
1824
+ backgroundPoll<TResponseData>(cacheKey: string | any[], params: FetchPollOperation): Promise<TResponseData>;
1825
+ /** `io.backgroundFetchResponse()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
1826
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1827
+ * @param url The URL to fetch from.
1828
+ * @param requestInit The options for the request
1829
+ * @param retry The options for retrying the request if it fails
1830
+ * An object where the key is a status code pattern and the value is a retrying strategy.
1831
+ * Supported patterns are:
1832
+ * - Specific status codes: 429
1833
+ * - Ranges: 500-599
1834
+ * - Wildcards: 2xx, 3xx, 4xx, 5xx
1835
+ */
1836
+ backgroundFetchResponse<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, options?: {
1837
+ retry?: FetchRetryOptions;
1838
+ timeout?: FetchTimeoutOptions;
1839
+ }): Promise<BackgroundFetchResponse<TResponseData>>;
1840
+ /** `io.sendEvent()` allows you to send an event from inside a Job run. The sent event will trigger any Jobs that are listening for that event (based on the name).
1473
1841
  * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1474
1842
  * @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
1475
1843
  * @param options Options for sending the event.
@@ -1488,6 +1856,25 @@ declare class IO {
1488
1856
  deliveredAt?: Date | null | undefined;
1489
1857
  cancelledAt?: Date | null | undefined;
1490
1858
  }>;
1859
+ /** `io.sendEvents()` allows you to send multiple events from inside a Job run. The sent events will trigger any Jobs that are listening for those events (based on the name).
1860
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1861
+ * @param event The events to send. The event names must match the names of the events that your Jobs are listening for.
1862
+ * @param options Options for sending the events.
1863
+ */
1864
+ sendEvents(cacheKey: string | any[], events: SendEvent[], options?: SendEventOptions): Promise<{
1865
+ id: string;
1866
+ name: string;
1867
+ payload: ((string | number | boolean | {
1868
+ [key: string]: _trigger_dev_core.DeserializedJson;
1869
+ } | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
1870
+ [key: string]: _trigger_dev_core.DeserializedJson;
1871
+ } | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
1872
+ timestamp: Date;
1873
+ context?: _trigger_dev_core.DeserializedJson | undefined;
1874
+ deliverAt?: Date | null | undefined;
1875
+ deliveredAt?: Date | null | undefined;
1876
+ cancelledAt?: Date | null | undefined;
1877
+ }[]>;
1491
1878
  getEvent(cacheKey: string | any[], id: string): Promise<{
1492
1879
  id: string;
1493
1880
  name: string;
@@ -1610,6 +1997,7 @@ declare class IO {
1610
1997
  key: string;
1611
1998
  } | undefined>;
1612
1999
  getAuth(cacheKey: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
2000
+ 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>>;
1613
2001
  /** `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.
1614
2002
  *
1615
2003
  * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
@@ -1618,7 +2006,9 @@ declare class IO {
1618
2006
  * @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.
1619
2007
  * @returns A Promise that resolves with the returned value of the callback.
1620
2008
  */
1621
- runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
2009
+ runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions & {
2010
+ parseOutput?: (output: unknown) => T;
2011
+ }, onError?: RunTaskErrorCallback): Promise<T>;
1622
2012
  /**
1623
2013
  * `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.
1624
2014
  */
@@ -1627,7 +2017,7 @@ declare class IO {
1627
2017
  * `io.brb()` is an alias of `io.yield()`
1628
2018
  */
1629
2019
  brb: (cacheKey: string) => void;
1630
- /** `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).
2020
+ /** `io.try()` allows you to run Tasks and catch any errors that are thrown, it's similar to a normal `try/catch` block but works with [io.runTask()](https://trigger.dev/docs/sdk/io/runtask).
1631
2021
  * 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.
1632
2022
  * @param tryCallback The code you wish to run
1633
2023
  * @param catchCallback Thhis will be called if the Task fails. The callback receives the error
@@ -1660,7 +2050,7 @@ interface TriggerIntegration {
1660
2050
  type IOWithIntegrations<TIntegrations extends Record<string, TriggerIntegration>> = IO & TIntegrations;
1661
2051
  type IntegrationTaskKey = string | any[];
1662
2052
 
1663
- type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> = {
2053
+ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> = {
1664
2054
  /** The `id` property is used to uniquely identify the Job. Only change this if you want to create a new Job. */
1665
2055
  id: string;
1666
2056
  /** The `name` of the Job that you want to appear in the dashboard and logs. You can change this without creating a new Job. */
@@ -1706,19 +2096,19 @@ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations
1706
2096
  * @param io An object that contains the integrations that you specified in the `integrations` property and other useful functions like delays and running Tasks.
1707
2097
  * @param context An object that contains information about the Organization, Job, Run and more.
1708
2098
  */
1709
- run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<any>;
2099
+ run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<TOutput>;
1710
2100
  };
1711
2101
  type JobPayload<TJob> = TJob extends Job<Trigger<EventSpecification<infer TEvent>>, any> ? TEvent : never;
1712
2102
  type JobIO<TJob> = TJob extends Job<any, infer TIntegrations> ? IOWithIntegrations<TIntegrations> : never;
1713
2103
  /** 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. */
1714
- declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> {
2104
+ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> {
1715
2105
  #private;
1716
- readonly options: JobOptions<TTrigger, TIntegrations>;
2106
+ readonly options: JobOptions<TTrigger, TIntegrations, TOutput>;
1717
2107
  client: TriggerClient;
1718
2108
  constructor(
1719
2109
  /** An instance of [TriggerClient](/sdk/triggerclient) that is used to send events
1720
2110
  to the Trigger API. */
1721
- client: TriggerClient, options: JobOptions<TTrigger, TIntegrations>);
2111
+ client: TriggerClient, options: JobOptions<TTrigger, TIntegrations, TOutput>);
1722
2112
  get id(): string;
1723
2113
  get enabled(): boolean;
1724
2114
  get name(): string;
@@ -1727,6 +2117,19 @@ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegratio
1727
2117
  get logLevel(): LogLevel | undefined;
1728
2118
  get integrations(): Record<string, IntegrationConfig>;
1729
2119
  toJSON(): JobMetadata;
2120
+ invoke(cacheKey: string, payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
2121
+ id: string;
2122
+ }>;
2123
+ invoke(payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
2124
+ id: string;
2125
+ }>;
2126
+ invokeAndWaitForCompletion(cacheKey: string | string[], payload: TriggerInvokeType<TTrigger>, timeoutInSeconds?: number, // 1 hour
2127
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>): Promise<RunNotification<TOutput>>;
2128
+ batchInvokeAndWaitForCompletion(cacheKey: string | string[], batch: Array<{
2129
+ payload: TriggerInvokeType<TTrigger>;
2130
+ timeoutInSeconds?: number;
2131
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>;
2132
+ }>): Promise<Array<RunNotification<TOutput>>>;
1730
2133
  }
1731
2134
 
1732
2135
  type EventTriggerOptions<TEventSpecification extends EventSpecification<any>> = {
@@ -1742,6 +2145,9 @@ declare class EventTrigger<TEventSpecification extends EventSpecification<any>>
1742
2145
  get event(): TEventSpecification;
1743
2146
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
1744
2147
  get preprocessRuns(): boolean;
2148
+ verifyPayload(payload: ReturnType<TEventSpecification["parsePayload"]>): Promise<{
2149
+ success: true;
2150
+ }>;
1745
2151
  }
1746
2152
  /** Configuration options for an EventTrigger */
1747
2153
  type TriggerOptions<TEvent> = {
@@ -1828,6 +2234,9 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1828
2234
  };
1829
2235
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<MissingConnectionNotificationSpecification>, any>): void;
1830
2236
  get preprocessRuns(): boolean;
2237
+ verifyPayload(payload: ReturnType<MissingConnectionNotificationSpecification["parsePayload"]>): Promise<{
2238
+ success: true;
2239
+ }>;
1831
2240
  toJSON(): TriggerMetadata;
1832
2241
  }
1833
2242
  type MissingConnectionResolvedNotificationSpecification = EventSpecification<MissingConnectionResolvedNotificationPayload>;
@@ -1877,13 +2286,70 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1877
2286
  };
1878
2287
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<MissingConnectionResolvedNotificationSpecification>, any>): void;
1879
2288
  get preprocessRuns(): boolean;
2289
+ verifyPayload(payload: ReturnType<MissingConnectionResolvedNotificationSpecification["parsePayload"]>): Promise<{
2290
+ success: true;
2291
+ }>;
2292
+ toJSON(): TriggerMetadata;
2293
+ }
2294
+
2295
+ /** Configuration options for an InvokeTrigger */
2296
+ type InvokeTriggerOptions<TSchema extends ZodType = z.ZodTypeAny> = {
2297
+ /** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
2298
+ * The default is `z.any()` which is `any`.
2299
+ * */
2300
+ schema?: TSchema;
2301
+ examples?: EventSpecificationExample[];
2302
+ };
2303
+ declare class InvokeTrigger<TSchema extends ZodType = z.ZodTypeAny> implements Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>> {
2304
+ #private;
2305
+ constructor(options: InvokeTriggerOptions<TSchema>);
1880
2306
  toJSON(): TriggerMetadata;
2307
+ get event(): {
2308
+ name: string;
2309
+ title: string;
2310
+ source: string;
2311
+ examples: {
2312
+ id: string;
2313
+ name: string;
2314
+ icon?: string | undefined;
2315
+ payload?: any;
2316
+ }[];
2317
+ icon: string;
2318
+ parsePayload: (rawPayload: unknown) => any;
2319
+ parseInvokePayload: (rawPayload: unknown) => any;
2320
+ };
2321
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<EventSpecification<ZodType<TSchema>>>, any>): void;
2322
+ get preprocessRuns(): boolean;
2323
+ verifyPayload(): Promise<{
2324
+ success: true;
2325
+ }>;
1881
2326
  }
2327
+ declare function invokeTrigger<TSchema extends ZodType = z.ZodTypeAny>(options?: InvokeTriggerOptions<TSchema>): Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>>;
2328
+
2329
+ /** Easily verify webhook payloads when they're using common signing methods. */
2330
+ declare function verifyRequestSignature({ request, headerName, secret, algorithm, }: {
2331
+ /** The web request that you want to verify. */
2332
+ request: Request;
2333
+ /** The name of the header that contains the signature. E.g. `X-Cal-Signature-256`. */
2334
+ headerName: string;
2335
+ /** The secret that you use to hash the payload. For HttpEndpoints this will usually originally
2336
+ come from the Trigger.dev dashboard and should be stored in an environment variable. */
2337
+ secret: string;
2338
+ /** The hashing algorithm that was used to create the signature. Currently only `sha256` is
2339
+ supported. */
2340
+ algorithm: "sha256";
2341
+ }): Promise<VerifyResult>;
2342
+ declare function verifyHmacSha256(headerValue: string, secret: string, body: string): boolean;
1882
2343
 
1883
2344
  declare class ResumeWithTaskError {
1884
2345
  task: ServerTask;
1885
2346
  constructor(task: ServerTask);
1886
2347
  }
2348
+ declare class ResumeWithParallelTaskError {
2349
+ task: ServerTask;
2350
+ childErrors: Array<TriggerInternalError>;
2351
+ constructor(task: ServerTask, childErrors: Array<TriggerInternalError>);
2352
+ }
1887
2353
  declare class RetryWithTaskError {
1888
2354
  cause: ErrorWithStack;
1889
2355
  task: ServerTask;
@@ -1907,25 +2373,26 @@ declare class AutoYieldExecutionError {
1907
2373
  declare class AutoYieldWithCompletedTaskExecutionError {
1908
2374
  id: string;
1909
2375
  properties: DisplayProperty[] | undefined;
1910
- output: any;
1911
2376
  data: {
1912
2377
  location: string;
1913
2378
  timeRemaining: number;
1914
2379
  timeElapsed: number;
1915
2380
  };
1916
- constructor(id: string, properties: DisplayProperty[] | undefined, output: any, data: {
2381
+ output?: string | undefined;
2382
+ constructor(id: string, properties: DisplayProperty[] | undefined, data: {
1917
2383
  location: string;
1918
2384
  timeRemaining: number;
1919
2385
  timeElapsed: number;
1920
- });
2386
+ }, output?: string | undefined);
1921
2387
  }
2388
+ type TriggerInternalError = ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError | YieldExecutionError | AutoYieldExecutionError | AutoYieldWithCompletedTaskExecutionError | ResumeWithParallelTaskError;
1922
2389
  /** Use this function if you're using a `try/catch` block to catch errors.
1923
2390
  * It checks if a thrown error is a special internal error that you should ignore.
1924
2391
  * If this returns `true` then you must rethrow the error: `throw err;`
1925
2392
  * @param err The error to check
1926
2393
  * @returns `true` if the error is a Trigger Error, `false` otherwise.
1927
2394
  */
1928
- declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError | YieldExecutionError | AutoYieldExecutionError | AutoYieldWithCompletedTaskExecutionError;
2395
+ declare function isTriggerError(err: unknown): err is TriggerInternalError;
1929
2396
 
1930
2397
  declare const retry: {
1931
2398
  readonly standardBackoff: {
@@ -1935,6 +2402,13 @@ declare const retry: {
1935
2402
  readonly maxTimeoutInMs: 30000;
1936
2403
  readonly randomize: true;
1937
2404
  };
2405
+ readonly exponentialBackoff: {
2406
+ readonly limit: 8;
2407
+ readonly factor: 2;
2408
+ readonly minTimeoutInMs: 1000;
2409
+ readonly maxTimeoutInMs: 30000;
2410
+ readonly randomize: true;
2411
+ };
1938
2412
  };
1939
2413
 
1940
2414
  type Task = ServerTask;
@@ -1942,4 +2416,4 @@ type Task = ServerTask;
1942
2416
  type SentEvent = ApiEventLog;
1943
2417
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1944
2418
 
1945
- 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 };
2419
+ export { AuthResolverResult, BackgroundFetchResponse, CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventSpecification, EventSpecificationExample, EventSpecificationExampleSchema, 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, VerifyResult, WaitForEventResult, cronTrigger, eventTrigger, intervalTrigger, invokeTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry, verifyHmacSha256, verifyRequestSignature, waitForEventSchema };