@trigger.dev/sdk 2.2.5 → 2.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _trigger_dev_core from '@trigger.dev/core';
2
- import { RunTaskBodyInput, CompleteTaskBodyV2Input, FailTaskBodyInput, SendEvent, SendEventOptions, StatusUpdate, UpdateTriggerSourceBodyV2, TriggerSource, RegisterTriggerBodyV2, RegisterSourceEventV2, ScheduleMetadata, GetRunOptionsWithTaskDetails, GetRunsOptions, InvokeOptions, 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, RunTaskOptions, IntegrationMetadata, QueueOptions, IntegrationConfig, JobMetadata, RunNotification, 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, SuccessfulRunNotification, FailedRunNotification, 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
5
  import { z, ZodType, TypeOf } from 'zod';
@@ -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<{
@@ -98,13 +105,16 @@ declare class ApiClient {
98
105
  label: string;
99
106
  text: string;
100
107
  url?: string | undefined;
108
+ imageUrl?: string[] | undefined;
101
109
  }[] | null | undefined;
102
110
  outputProperties?: {
103
111
  label: string;
104
112
  text: string;
105
113
  url?: string | undefined;
114
+ imageUrl?: string[] | undefined;
106
115
  }[] | null | undefined;
107
116
  output?: _trigger_dev_core.DeserializedJson | undefined;
117
+ context?: _trigger_dev_core.DeserializedJson | undefined;
108
118
  error?: string | null | undefined;
109
119
  parentId?: string | null | undefined;
110
120
  style?: {
@@ -132,13 +142,16 @@ declare class ApiClient {
132
142
  label: string;
133
143
  text: string;
134
144
  url?: string | undefined;
145
+ imageUrl?: string[] | undefined;
135
146
  }[] | null | undefined;
136
147
  outputProperties?: {
137
148
  label: string;
138
149
  text: string;
139
150
  url?: string | undefined;
151
+ imageUrl?: string[] | undefined;
140
152
  }[] | null | undefined;
141
153
  output?: _trigger_dev_core.DeserializedJson | undefined;
154
+ context?: _trigger_dev_core.DeserializedJson | undefined;
142
155
  error?: string | null | undefined;
143
156
  parentId?: string | null | undefined;
144
157
  style?: {
@@ -213,13 +226,16 @@ declare class ApiClient {
213
226
  label: string;
214
227
  text: string;
215
228
  url?: string | undefined;
229
+ imageUrl?: string[] | undefined;
216
230
  }[] | null | undefined;
217
231
  outputProperties?: {
218
232
  label: string;
219
233
  text: string;
220
234
  url?: string | undefined;
235
+ imageUrl?: string[] | undefined;
221
236
  }[] | null | undefined;
222
237
  output?: _trigger_dev_core.DeserializedJson | undefined;
238
+ context?: _trigger_dev_core.DeserializedJson | undefined;
223
239
  error?: string | null | undefined;
224
240
  parentId?: string | null | undefined;
225
241
  style?: {
@@ -260,13 +276,16 @@ declare class ApiClient {
260
276
  label: string;
261
277
  text: string;
262
278
  url?: string | undefined;
279
+ imageUrl?: string[] | undefined;
263
280
  }[] | null | undefined;
264
281
  outputProperties?: {
265
282
  label: string;
266
283
  text: string;
267
284
  url?: string | undefined;
285
+ imageUrl?: string[] | undefined;
268
286
  }[] | null | undefined;
269
287
  output?: _trigger_dev_core.DeserializedJson | undefined;
288
+ context?: _trigger_dev_core.DeserializedJson | undefined;
270
289
  error?: string | null | undefined;
271
290
  parentId?: string | null | undefined;
272
291
  style?: {
@@ -305,29 +324,36 @@ declare class ApiClient {
305
324
  label: z.ZodString;
306
325
  text: z.ZodString;
307
326
  url: z.ZodOptional<z.ZodString>;
327
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
308
328
  }, "strip", z.ZodTypeAny, {
309
329
  label: string;
310
330
  text: string;
311
331
  url?: string | undefined;
332
+ imageUrl?: string[] | undefined;
312
333
  }, {
313
334
  label: string;
314
335
  text: string;
315
336
  url?: string | undefined;
337
+ imageUrl?: string[] | undefined;
316
338
  }>, "many">>>;
317
339
  outputProperties: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
318
340
  label: z.ZodString;
319
341
  text: z.ZodString;
320
342
  url: z.ZodOptional<z.ZodString>;
343
+ imageUrl: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
321
344
  }, "strip", z.ZodTypeAny, {
322
345
  label: string;
323
346
  text: string;
324
347
  url?: string | undefined;
348
+ imageUrl?: string[] | undefined;
325
349
  }, {
326
350
  label: string;
327
351
  text: string;
328
352
  url?: string | undefined;
353
+ imageUrl?: string[] | undefined;
329
354
  }>, "many">>>;
330
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>>>;
331
357
  error: z.ZodNullable<z.ZodOptional<z.ZodString>>;
332
358
  parentId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
333
359
  style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
@@ -363,13 +389,16 @@ declare class ApiClient {
363
389
  label: string;
364
390
  text: string;
365
391
  url?: string | undefined;
392
+ imageUrl?: string[] | undefined;
366
393
  }[] | null | undefined;
367
394
  outputProperties?: {
368
395
  label: string;
369
396
  text: string;
370
397
  url?: string | undefined;
398
+ imageUrl?: string[] | undefined;
371
399
  }[] | null | undefined;
372
400
  output?: _trigger_dev_core.DeserializedJson | undefined;
401
+ context?: _trigger_dev_core.DeserializedJson | undefined;
373
402
  error?: string | null | undefined;
374
403
  parentId?: string | null | undefined;
375
404
  style?: {
@@ -397,13 +426,16 @@ declare class ApiClient {
397
426
  label: string;
398
427
  text: string;
399
428
  url?: string | undefined;
429
+ imageUrl?: string[] | undefined;
400
430
  }[] | null | undefined;
401
431
  outputProperties?: {
402
432
  label: string;
403
433
  text: string;
404
434
  url?: string | undefined;
435
+ imageUrl?: string[] | undefined;
405
436
  }[] | null | undefined;
406
437
  output?: _trigger_dev_core.DeserializedJson | undefined;
438
+ context?: _trigger_dev_core.DeserializedJson | undefined;
407
439
  error?: string | null | undefined;
408
440
  parentId?: string | null | undefined;
409
441
  style?: {
@@ -432,13 +464,16 @@ declare class ApiClient {
432
464
  label: string;
433
465
  text: string;
434
466
  url?: string | undefined;
467
+ imageUrl?: string[] | undefined;
435
468
  }[] | null | undefined;
436
469
  outputProperties?: {
437
470
  label: string;
438
471
  text: string;
439
472
  url?: string | undefined;
473
+ imageUrl?: string[] | undefined;
440
474
  }[] | null | undefined;
441
475
  output?: _trigger_dev_core.DeserializedJson | undefined;
476
+ context?: _trigger_dev_core.DeserializedJson | undefined;
442
477
  error?: string | null | undefined;
443
478
  parentId?: string | null | undefined;
444
479
  style?: {
@@ -467,13 +502,16 @@ declare class ApiClient {
467
502
  label: string;
468
503
  text: string;
469
504
  url?: string | undefined;
505
+ imageUrl?: string[] | undefined;
470
506
  }[] | null | undefined;
471
507
  outputProperties?: {
472
508
  label: string;
473
509
  text: string;
474
510
  url?: string | undefined;
511
+ imageUrl?: string[] | undefined;
475
512
  }[] | null | undefined;
476
513
  output?: _trigger_dev_core.DeserializedJson | undefined;
514
+ context?: _trigger_dev_core.DeserializedJson | undefined;
477
515
  error?: string | null | undefined;
478
516
  parentId?: string | null | undefined;
479
517
  style?: {
@@ -499,6 +537,20 @@ declare class ApiClient {
499
537
  deliveredAt?: Date | null | undefined;
500
538
  cancelledAt?: Date | null | undefined;
501
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
+ }[]>;
502
554
  cancelEvent(eventId: string): Promise<{
503
555
  id: string;
504
556
  name: string;
@@ -644,6 +696,9 @@ declare class ApiClient {
644
696
  invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
645
697
  id: string;
646
698
  }>;
699
+ createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
700
+ id: string;
701
+ }>;
647
702
  }
648
703
  type VersionedResponseBodyMap = {
649
704
  [key: string]: z.ZodTypeAny;
@@ -675,6 +730,48 @@ declare class TriggerStatus {
675
730
  }>;
676
731
  }
677
732
 
733
+ type EventMap = {
734
+ [key: string]: (...args: any[]) => void
735
+ }
736
+
737
+ /**
738
+ * Type-safe event emitter.
739
+ *
740
+ * Use it like this:
741
+ *
742
+ * ```typescript
743
+ * type MyEvents = {
744
+ * error: (error: Error) => void;
745
+ * message: (from: string, content: string) => void;
746
+ * }
747
+ *
748
+ * const myEmitter = new EventEmitter() as TypedEmitter<MyEvents>;
749
+ *
750
+ * myEmitter.emit("error", "x") // <- Will catch this type error;
751
+ * ```
752
+ */
753
+ interface TypedEventEmitter<Events extends EventMap> {
754
+ addListener<E extends keyof Events> (event: E, listener: Events[E]): this
755
+ on<E extends keyof Events> (event: E, listener: Events[E]): this
756
+ once<E extends keyof Events> (event: E, listener: Events[E]): this
757
+ prependListener<E extends keyof Events> (event: E, listener: Events[E]): this
758
+ prependOnceListener<E extends keyof Events> (event: E, listener: Events[E]): this
759
+
760
+ off<E extends keyof Events>(event: E, listener: Events[E]): this
761
+ removeAllListeners<E extends keyof Events> (event?: E): this
762
+ removeListener<E extends keyof Events> (event: E, listener: Events[E]): this
763
+
764
+ emit<E extends keyof Events> (event: E, ...args: Parameters<Events[E]>): boolean
765
+ // The sloppy `eventNames()` return type is to mitigate type incompatibilities - see #5
766
+ eventNames (): (keyof Events | string | symbol)[]
767
+ rawListeners<E extends keyof Events> (event: E): Events[E][]
768
+ listeners<E extends keyof Events> (event: E): Events[E][]
769
+ listenerCount<E extends keyof Events> (event: E): number
770
+
771
+ getMaxListeners (): number
772
+ setMaxListeners (maxListeners: number): this
773
+ }
774
+
678
775
  interface TriggerContext {
679
776
  /** Job metadata */
680
777
  job: {
@@ -827,6 +924,45 @@ type SchemaParserResult<T> = {
827
924
  type SchemaParser<T extends unknown = unknown> = {
828
925
  safeParse: (a: unknown) => SchemaParserResult<T>;
829
926
  };
927
+ type WaitForEventResult<TEvent> = {
928
+ id: string;
929
+ name: string;
930
+ source: string;
931
+ payload: TEvent;
932
+ timestamp: Date;
933
+ context?: any;
934
+ accountId?: string;
935
+ };
936
+ declare function waitForEventSchema(schema: z.ZodTypeAny): z.ZodObject<{
937
+ id: z.ZodString;
938
+ name: z.ZodString;
939
+ source: z.ZodString;
940
+ payload: z.ZodTypeAny;
941
+ timestamp: z.ZodDate;
942
+ context: z.ZodOptional<z.ZodAny>;
943
+ accountId: z.ZodOptional<z.ZodString>;
944
+ }, "strip", z.ZodTypeAny, {
945
+ id: string;
946
+ name: string;
947
+ timestamp: Date;
948
+ source: string;
949
+ payload?: any;
950
+ context?: any;
951
+ accountId?: string | undefined;
952
+ }, {
953
+ id: string;
954
+ name: string;
955
+ timestamp: Date;
956
+ source: string;
957
+ payload?: any;
958
+ context?: any;
959
+ accountId?: string | undefined;
960
+ }>;
961
+ type NotificationEvents = {
962
+ runSucceeeded: (notification: SuccessfulRunNotification<any>) => void;
963
+ runFailed: (notification: FailedRunNotification) => void;
964
+ };
965
+ type NotificationsEventEmitter = TypedEventEmitter<NotificationEvents>;
830
966
 
831
967
  type HttpEndpointOptions<TEventSpecification extends EventSpecification<any>> = {
832
968
  id: string;
@@ -1284,6 +1420,7 @@ declare class TriggerClient {
1284
1420
  #private;
1285
1421
  id: string;
1286
1422
  constructor(options: Prettify<TriggerClientOptions>);
1423
+ on: <E extends keyof NotificationEvents>(event: E, listener: NotificationEvents[E]) => NotificationsEventEmitter;
1287
1424
  handleRequest(request: Request, timeOrigin?: number): Promise<NormalizedResponse>;
1288
1425
  defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any>(options: JobOptions<TTrigger, TIntegrations, TOutput>): Job<TTrigger, TIntegrations, TOutput>;
1289
1426
  defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
@@ -1364,6 +1501,25 @@ declare class TriggerClient {
1364
1501
  deliveredAt?: Date | null | undefined;
1365
1502
  cancelledAt?: Date | null | undefined;
1366
1503
  }>;
1504
+ /** 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.
1505
+ * @param events The events to send.
1506
+ * @param options Options for sending the events.
1507
+ * @returns A promise that resolves to an array of event details
1508
+ */
1509
+ sendEvents(events: SendEvent[], options?: SendEventOptions): Promise<{
1510
+ id: string;
1511
+ name: string;
1512
+ payload: ((string | number | boolean | {
1513
+ [key: string]: DeserializedJson;
1514
+ } | DeserializedJson[]) & (string | number | boolean | {
1515
+ [key: string]: DeserializedJson;
1516
+ } | DeserializedJson[] | undefined)) | null;
1517
+ timestamp: Date;
1518
+ context?: DeserializedJson | undefined;
1519
+ deliverAt?: Date | null | undefined;
1520
+ deliveredAt?: Date | null | undefined;
1521
+ cancelledAt?: Date | null | undefined;
1522
+ }[]>;
1367
1523
  cancelEvent(eventId: string): Promise<{
1368
1524
  id: string;
1369
1525
  name: string;
@@ -1501,6 +1657,9 @@ declare class TriggerClient {
1501
1657
  invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
1502
1658
  id: string;
1503
1659
  }>;
1660
+ createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
1661
+ id: string;
1662
+ }>;
1504
1663
  authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
1505
1664
  apiKey(): string | undefined;
1506
1665
  }
@@ -1552,6 +1711,11 @@ declare class JSONOutputSerializer implements OutputSerializer {
1552
1711
  serialize(value: any): string;
1553
1712
  deserialize(value?: string): any;
1554
1713
  }
1714
+ type BackgroundFetchResponse<T> = {
1715
+ status: number;
1716
+ data: T;
1717
+ headers: Record<string, string>;
1718
+ };
1555
1719
  declare class IO {
1556
1720
  #private;
1557
1721
  private _id;
@@ -1592,6 +1756,16 @@ declare class IO {
1592
1756
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
1593
1757
  */
1594
1758
  wait(cacheKey: string | any[], seconds: number): Promise<void>;
1759
+ waitForEvent<T extends z.ZodTypeAny = z.ZodTypeAny>(cacheKey: string | any[], event: {
1760
+ name: string;
1761
+ schema?: T;
1762
+ filter?: EventFilter;
1763
+ source?: string;
1764
+ contextFilter?: EventFilter;
1765
+ accountId?: string;
1766
+ }, options?: {
1767
+ timeoutInSeconds?: number;
1768
+ }): Promise<WaitForEventResult<z.output<T>>>;
1595
1769
  /** `io.waitForRequest()` allows you to pause the execution of a run until the url provided in the callback is POSTed to.
1596
1770
  * 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.
1597
1771
  * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
@@ -1658,8 +1832,60 @@ declare class IO {
1658
1832
  * - Ranges: 500-599
1659
1833
  * - Wildcards: 2xx, 3xx, 4xx, 5xx
1660
1834
  */
1661
- backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions, timeout?: FetchTimeoutOptions): Promise<TResponseData>;
1662
- /** `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).
1835
+ backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, options?: {
1836
+ retry?: FetchRetryOptions;
1837
+ timeout?: FetchTimeoutOptions;
1838
+ }): Promise<TResponseData>;
1839
+ /** `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.
1840
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1841
+ * @param params The options for the background poll
1842
+ * @param params.url The URL to fetch from.
1843
+ * @param params.requestInit The options for the request, like headers and method
1844
+ * @param params.responseFilter An [EventFilter](https://trigger.dev/docs/documentation/guides/event-filter) that allows you to specify when to stop polling.
1845
+ * @param params.interval The interval in seconds to poll the URL in seconds. Defaults to 10 seconds which is the minimum.
1846
+ * @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
1847
+ * @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
1848
+ * @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
1849
+ * @param params.requestTimeout.durationInMs The duration in milliseconds to timeout the request
1850
+ *
1851
+ * @example
1852
+ * ```ts
1853
+ * const result = await io.backgroundPoll<{ id: string; status: string; }>("poll", {
1854
+ url: `http://localhost:3030/api/v1/runs/${run.id}`,
1855
+ requestInit: {
1856
+ headers: {
1857
+ Accept: "application/json",
1858
+ Authorization: redactString`Bearer ${process.env["TRIGGER_API_KEY"]!}`,
1859
+ },
1860
+ },
1861
+ interval: 10,
1862
+ timeout: 600,
1863
+ responseFilter: {
1864
+ status: [200],
1865
+ body: {
1866
+ status: ["SUCCESS"],
1867
+ },
1868
+ },
1869
+ });
1870
+ * ```
1871
+ */
1872
+ backgroundPoll<TResponseData>(cacheKey: string | any[], params: FetchPollOperation): Promise<TResponseData>;
1873
+ /** `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.
1874
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1875
+ * @param url The URL to fetch from.
1876
+ * @param requestInit The options for the request
1877
+ * @param retry The options for retrying the request if it fails
1878
+ * An object where the key is a status code pattern and the value is a retrying strategy.
1879
+ * Supported patterns are:
1880
+ * - Specific status codes: 429
1881
+ * - Ranges: 500-599
1882
+ * - Wildcards: 2xx, 3xx, 4xx, 5xx
1883
+ */
1884
+ backgroundFetchResponse<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, options?: {
1885
+ retry?: FetchRetryOptions;
1886
+ timeout?: FetchTimeoutOptions;
1887
+ }): Promise<BackgroundFetchResponse<TResponseData>>;
1888
+ /** `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).
1663
1889
  * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1664
1890
  * @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
1665
1891
  * @param options Options for sending the event.
@@ -1678,6 +1904,25 @@ declare class IO {
1678
1904
  deliveredAt?: Date | null | undefined;
1679
1905
  cancelledAt?: Date | null | undefined;
1680
1906
  }>;
1907
+ /** `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).
1908
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1909
+ * @param event The events to send. The event names must match the names of the events that your Jobs are listening for.
1910
+ * @param options Options for sending the events.
1911
+ */
1912
+ sendEvents(cacheKey: string | any[], events: SendEvent[], options?: SendEventOptions): Promise<{
1913
+ id: string;
1914
+ name: string;
1915
+ payload: ((string | number | boolean | {
1916
+ [key: string]: _trigger_dev_core.DeserializedJson;
1917
+ } | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
1918
+ [key: string]: _trigger_dev_core.DeserializedJson;
1919
+ } | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
1920
+ timestamp: Date;
1921
+ context?: _trigger_dev_core.DeserializedJson | undefined;
1922
+ deliverAt?: Date | null | undefined;
1923
+ deliveredAt?: Date | null | undefined;
1924
+ cancelledAt?: Date | null | undefined;
1925
+ }[]>;
1681
1926
  getEvent(cacheKey: string | any[], id: string): Promise<{
1682
1927
  id: string;
1683
1928
  name: string;
@@ -1809,7 +2054,9 @@ declare class IO {
1809
2054
  * @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.
1810
2055
  * @returns A Promise that resolves with the returned value of the callback.
1811
2056
  */
1812
- runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
2057
+ runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions & {
2058
+ parseOutput?: (output: unknown) => T;
2059
+ }, onError?: RunTaskErrorCallback): Promise<T>;
1813
2060
  /**
1814
2061
  * `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.
1815
2062
  */
@@ -1898,6 +2145,8 @@ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations
1898
2145
  * @param context An object that contains information about the Organization, Job, Run and more.
1899
2146
  */
1900
2147
  run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<TOutput>;
2148
+ onSuccess?: (notification: SuccessfulRunNotification<TOutput, TriggerEventType<TTrigger>>) => void;
2149
+ onFailure?: (notification: FailedRunNotification<TriggerEventType<TTrigger>>) => void;
1901
2150
  };
1902
2151
  type JobPayload<TJob> = TJob extends Job<Trigger<EventSpecification<infer TEvent>>, any> ? TEvent : never;
1903
2152
  type JobIO<TJob> = TJob extends Job<any, infer TIntegrations> ? IOWithIntegrations<TIntegrations> : never;
@@ -2203,6 +2452,13 @@ declare const retry: {
2203
2452
  readonly maxTimeoutInMs: 30000;
2204
2453
  readonly randomize: true;
2205
2454
  };
2455
+ readonly exponentialBackoff: {
2456
+ readonly limit: 8;
2457
+ readonly factor: 2;
2458
+ readonly minTimeoutInMs: 1000;
2459
+ readonly maxTimeoutInMs: 30000;
2460
+ readonly randomize: true;
2461
+ };
2206
2462
  };
2207
2463
 
2208
2464
  type Task = ServerTask;
@@ -2210,4 +2466,4 @@ type Task = ServerTask;
2210
2466
  type SentEvent = ApiEventLog;
2211
2467
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
2212
2468
 
2213
- export { AuthResolverResult, 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, cronTrigger, eventTrigger, intervalTrigger, invokeTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry, verifyHmacSha256, verifyRequestSignature };
2469
+ 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, NotificationEvents, NotificationsEventEmitter, 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 };