@trigger.dev/sdk 2.2.3 → 2.2.5

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, 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';
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;
@@ -77,6 +77,7 @@ declare class ApiClient {
77
77
  }>>>;
78
78
  operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
79
79
  callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
80
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
80
81
  idempotencyKey: z.ZodString;
81
82
  attempts: z.ZodNumber;
82
83
  forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
@@ -112,6 +113,7 @@ declare class ApiClient {
112
113
  } | null | undefined;
113
114
  operation?: string | null | undefined;
114
115
  callbackUrl?: string | null | undefined;
116
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
115
117
  forceYield?: boolean | null | undefined;
116
118
  }, {
117
119
  id: string;
@@ -145,6 +147,7 @@ declare class ApiClient {
145
147
  } | null | undefined;
146
148
  operation?: string | null | undefined;
147
149
  callbackUrl?: string | null | undefined;
150
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
148
151
  forceYield?: boolean | null | undefined;
149
152
  }>;
150
153
  cachedTasks: z.ZodOptional<z.ZodObject<{
@@ -225,6 +228,7 @@ declare class ApiClient {
225
228
  } | null | undefined;
226
229
  operation?: string | null | undefined;
227
230
  callbackUrl?: string | null | undefined;
231
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
228
232
  forceYield?: boolean | null | undefined;
229
233
  };
230
234
  cachedTasks?: {
@@ -271,6 +275,7 @@ declare class ApiClient {
271
275
  } | null | undefined;
272
276
  operation?: string | null | undefined;
273
277
  callbackUrl?: string | null | undefined;
278
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
274
279
  forceYield?: boolean | null | undefined;
275
280
  };
276
281
  cachedTasks?: {
@@ -337,6 +342,7 @@ declare class ApiClient {
337
342
  }>>>;
338
343
  operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
339
344
  callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
345
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
340
346
  idempotencyKey: z.ZodString;
341
347
  attempts: z.ZodNumber;
342
348
  forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
@@ -372,6 +378,7 @@ declare class ApiClient {
372
378
  } | null | undefined;
373
379
  operation?: string | null | undefined;
374
380
  callbackUrl?: string | null | undefined;
381
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
375
382
  forceYield?: boolean | null | undefined;
376
383
  }, {
377
384
  id: string;
@@ -405,9 +412,10 @@ declare class ApiClient {
405
412
  } | null | undefined;
406
413
  operation?: string | null | undefined;
407
414
  callbackUrl?: string | null | undefined;
415
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
408
416
  forceYield?: boolean | null | undefined;
409
417
  }>>>;
410
- completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
418
+ completeTask(runId: string, id: string, task: CompleteTaskBodyV2Input): Promise<{
411
419
  id: string;
412
420
  name: string;
413
421
  noop: boolean;
@@ -439,6 +447,7 @@ declare class ApiClient {
439
447
  } | null | undefined;
440
448
  operation?: string | null | undefined;
441
449
  callbackUrl?: string | null | undefined;
450
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
442
451
  forceYield?: boolean | null | undefined;
443
452
  }>;
444
453
  failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
@@ -473,6 +482,7 @@ declare class ApiClient {
473
482
  } | null | undefined;
474
483
  operation?: string | null | undefined;
475
484
  callbackUrl?: string | null | undefined;
485
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
476
486
  forceYield?: boolean | null | undefined;
477
487
  }>;
478
488
  sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
@@ -519,7 +529,7 @@ declare class ApiClient {
519
529
  state?: "loading" | "success" | "failure" | undefined;
520
530
  }>;
521
531
  updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
522
- 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>;
523
533
  registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
524
534
  id: string;
525
535
  schedule: {
@@ -631,6 +641,9 @@ declare class ApiClient {
631
641
  }[];
632
642
  nextCursor?: string | undefined;
633
643
  }>;
644
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
645
+ id: string;
646
+ }>;
634
647
  }
635
648
  type VersionedResponseBodyMap = {
636
649
  [key: string]: z.ZodTypeAny;
@@ -645,6 +658,23 @@ type VersionedResponseBody<TVersions extends VersionedResponseBodyMap, TUnversio
645
658
  body: z.infer<TUnversioned>;
646
659
  };
647
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
+ }>;
676
+ }
677
+
648
678
  interface TriggerContext {
649
679
  /** Job metadata */
650
680
  job: {
@@ -663,6 +693,12 @@ interface TriggerContext {
663
693
  id: string;
664
694
  title: string;
665
695
  };
696
+ /** Project metadata */
697
+ project: {
698
+ slug: string;
699
+ id: string;
700
+ name: string;
701
+ };
666
702
  /** Run metadata */
667
703
  run: {
668
704
  id: string;
@@ -729,20 +765,39 @@ type PreprocessResults = {
729
765
  properties: DisplayProperty[];
730
766
  };
731
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;
769
+ type VerifyResult = {
770
+ success: true;
771
+ } | {
772
+ success: false;
773
+ reason?: string;
774
+ };
732
775
  interface Trigger<TEventSpec extends EventSpecification<any>> {
733
776
  event: TEventSpec;
734
777
  toJSON(): TriggerMetadata;
735
778
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
736
779
  preprocessRuns: boolean;
780
+ verifyPayload: (payload: ReturnType<TEventSpec["parsePayload"]>) => Promise<VerifyResult>;
737
781
  }
738
782
  type TriggerPayload<TTrigger> = TTrigger extends Trigger<EventSpecification<infer TEvent>> ? TEvent : never;
739
- type EventSpecificationExample = {
783
+ declare const EventSpecificationExampleSchema: z.ZodObject<{
784
+ id: z.ZodString;
785
+ name: z.ZodString;
786
+ icon: z.ZodOptional<z.ZodString>;
787
+ payload: z.ZodAny;
788
+ }, "strip", z.ZodTypeAny, {
740
789
  id: string;
741
790
  name: string;
742
- icon?: string;
743
- payload: any;
744
- };
745
- interface EventSpecification<TEvent extends any> {
791
+ icon?: string | undefined;
792
+ payload?: any;
793
+ }, {
794
+ id: string;
795
+ name: string;
796
+ icon?: string | undefined;
797
+ payload?: any;
798
+ }>;
799
+ type EventSpecificationExample = z.infer<typeof EventSpecificationExampleSchema>;
800
+ interface EventSpecification<TEvent extends any, TInvoke extends any = TEvent> {
746
801
  name: string | string[];
747
802
  title: string;
748
803
  source: string;
@@ -752,6 +807,7 @@ interface EventSpecification<TEvent extends any> {
752
807
  examples?: Array<EventSpecificationExample>;
753
808
  filter?: EventFilter;
754
809
  parsePayload: (payload: unknown) => TEvent;
810
+ parseInvokePayload?: (payload: unknown) => TInvoke;
755
811
  runProperties?: (payload: TEvent) => DisplayProperty[];
756
812
  }
757
813
  type EventTypeFromSpecification<TEventSpec extends EventSpecification<any>> = TEventSpec extends EventSpecification<infer TEvent> ? TEvent : never;
@@ -772,6 +828,88 @@ type SchemaParser<T extends unknown = unknown> = {
772
828
  safeParse: (a: unknown) => SchemaParserResult<T>;
773
829
  };
774
830
 
831
+ type HttpEndpointOptions<TEventSpecification extends EventSpecification<any>> = {
832
+ id: string;
833
+ enabled?: boolean;
834
+ event: TEventSpecification;
835
+ respondWith?: RespondWith;
836
+ verify: VerifyCallback;
837
+ };
838
+ type RequestOptions = {
839
+ filter?: RequestFilter;
840
+ };
841
+ declare class HttpEndpoint<TEventSpecification extends EventSpecification<any>> {
842
+ private readonly options;
843
+ constructor(options: HttpEndpointOptions<TEventSpecification>);
844
+ get id(): string;
845
+ onRequest(options?: RequestOptions): HttpTrigger<EventSpecification<Request>>;
846
+ toJSON(): HttpEndpointMetadata;
847
+ }
848
+ type TriggerOptions$1<TEventSpecification extends EventSpecification<any>> = {
849
+ endpointId: string;
850
+ event: TEventSpecification;
851
+ filter?: EventFilter;
852
+ verify: VerifyCallback;
853
+ };
854
+ declare class HttpTrigger<TEventSpecification extends EventSpecification<any>> implements Trigger<TEventSpecification> {
855
+ private readonly options;
856
+ constructor(options: TriggerOptions$1<TEventSpecification>);
857
+ toJSON(): TriggerMetadata;
858
+ get event(): TEventSpecification;
859
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
860
+ get preprocessRuns(): boolean;
861
+ verifyPayload(payload: Request): Promise<VerifyResult>;
862
+ }
863
+ type RespondWith = {
864
+ /** Only Requests that match this filter will cause the `handler` function to run.
865
+ * For example, you can use this to only respond to `GET` Requests. */
866
+ filter?: RequestFilter;
867
+ /** If you set this to `true`, the Request that comes in won't go on to Trigger any Runs.
868
+ * This is useful if you want to Respond to the Request, but don't want to Trigger any Runs. */
869
+ skipTriggeringRuns?: boolean;
870
+ /** This is a function that's called when a Request comes in.
871
+ * It's passed the Request object, and expects you to return a Response object. */
872
+ handler: (request: Request, verify: () => Promise<VerifyResult>) => Promise<Response>;
873
+ };
874
+ type VerifyCallback = (request: Request) => Promise<VerifyResult>;
875
+ type EndpointOptions = {
876
+ /** Used to uniquely identify the HTTP Endpoint inside your Project. */
877
+ id: string;
878
+ enabled?: boolean;
879
+ /** Usually you would use the domain name of the service, e.g. `cal.com`. */
880
+ source: string;
881
+ /** An optional title, displayed in the dashboard. */
882
+ title?: string;
883
+ /** An optional icon name that's displayed in the dashboard.
884
+ * Lots of company names are supported, e.g. `github`, `twilio`.
885
+ * You can also reference the name of any [Tabler icon](https://tabler-icons.io/), e.g. `brand-google-maps`, `brand-twitch`. */
886
+ icon?: string;
887
+ /** Used to provide example payloads that are accepted by the job.
888
+ * This will be available in the dashboard and can be used to trigger test runs. */
889
+ examples?: EventSpecificationExample[];
890
+ /** Properties that are displayed in the dashboard. */
891
+ properties?: DisplayProperty[];
892
+ /** 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.
893
+
894
+ Only use this if you really need to Respond to the Request that comes in. Most of the time you don't. */
895
+ respondWith?: RespondWith;
896
+ /** This is compulsory, and is used to verify that the received webhook is authentic.
897
+ * It's a function that expects you to return a result object like:
898
+
899
+ In 90% of cases, you'll want to use the `verifyRequestSignature` helper function we provide.
900
+
901
+ @example
902
+ ```ts
903
+ //if it's valid
904
+ return { success: true }
905
+ //if it's invalid, reason is optional
906
+ return { success: false, reason: "No header" }
907
+ ```
908
+
909
+ */
910
+ verify: VerifyCallback;
911
+ };
912
+
775
913
  type HttpSourceEvent = {
776
914
  url: string;
777
915
  method: string;
@@ -876,6 +1014,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration, TParams ex
876
1014
  id?: string | undefined;
877
1015
  timestamp?: Date | undefined;
878
1016
  source?: string | undefined;
1017
+ payloadType?: "JSON" | "REQUEST" | undefined;
879
1018
  }[];
880
1019
  response?: {
881
1020
  status: number;
@@ -914,6 +1053,9 @@ declare class ExternalSourceTrigger<TEventSpecification extends EventSpecificati
914
1053
  toJSON(): TriggerMetadata;
915
1054
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
916
1055
  get preprocessRuns(): boolean;
1056
+ verifyPayload(payload: ReturnType<TEventSpecification["parsePayload"]>): Promise<{
1057
+ success: true;
1058
+ }>;
917
1059
  }
918
1060
  declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, key: K): {
919
1061
  result: Omit<T, K>;
@@ -966,6 +1108,9 @@ declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExtern
966
1108
  }): Promise<RegisterSourceEventV2>;
967
1109
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
968
1110
  get preprocessRuns(): boolean;
1111
+ verifyPayload(payload: ReturnType<TEventSpec["parsePayload"]>): Promise<{
1112
+ success: true;
1113
+ }>;
969
1114
  }
970
1115
 
971
1116
  type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
@@ -997,6 +1142,9 @@ declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
997
1142
  };
998
1143
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
999
1144
  get preprocessRuns(): boolean;
1145
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1146
+ success: true;
1147
+ }>;
1000
1148
  toJSON(): TriggerMetadata;
1001
1149
  }
1002
1150
  /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
@@ -1031,6 +1179,9 @@ declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
1031
1179
  };
1032
1180
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1033
1181
  get preprocessRuns(): boolean;
1182
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1183
+ success: true;
1184
+ }>;
1034
1185
  toJSON(): TriggerMetadata;
1035
1186
  }
1036
1187
  /** `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 +1248,9 @@ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
1097
1248
  }>;
1098
1249
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
1099
1250
  get preprocessRuns(): boolean;
1251
+ verifyPayload(payload: ReturnType<ScheduledEventSpecification["parsePayload"]>): Promise<{
1252
+ success: true;
1253
+ }>;
1100
1254
  toJSON(): TriggerMetadata;
1101
1255
  }
1102
1256
 
@@ -1131,10 +1285,17 @@ declare class TriggerClient {
1131
1285
  id: string;
1132
1286
  constructor(options: Prettify<TriggerClientOptions>);
1133
1287
  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>;
1288
+ 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
1289
  defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
1136
1290
  defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
1137
1291
  defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
1292
+ /**
1293
+ * 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.
1294
+ * @param options The Endpoint options
1295
+ * @returns An HTTP Endpoint, that can be used to create an HTTP Trigger.
1296
+ * @link https://trigger.dev/docs/documentation/concepts/http-endpoints
1297
+ */
1298
+ defineHttpEndpoint(options: EndpointOptions): HttpEndpoint<EventSpecification<Request, Request>>;
1138
1299
  attach(job: Job<Trigger<any>, any>): void;
1139
1300
  attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
1140
1301
  attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
@@ -1147,7 +1308,7 @@ declare class TriggerClient {
1147
1308
  }): void;
1148
1309
  attachDynamicSchedule(key: string): void;
1149
1310
  attachDynamicScheduleToJob(key: string, job: Job<Trigger<any>, any>): void;
1150
- registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
1311
+ registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2, idempotencyKey?: string): Promise<{
1151
1312
  id: string;
1152
1313
  options: {
1153
1314
  event: {
@@ -1337,27 +1498,13 @@ declare class TriggerClient {
1337
1498
  output?: any;
1338
1499
  };
1339
1500
  }>;
1501
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
1502
+ id: string;
1503
+ }>;
1340
1504
  authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
1341
1505
  apiKey(): string | undefined;
1342
1506
  }
1343
1507
 
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
1508
  type IOTask = ServerTask;
1362
1509
  type IOOptions = {
1363
1510
  id: string;
@@ -1397,6 +1544,14 @@ type IOStats = {
1397
1544
  noopCachedTaskHits: number;
1398
1545
  noopCachedTaskMisses: number;
1399
1546
  };
1547
+ interface OutputSerializer {
1548
+ serialize(value: any): string;
1549
+ deserialize<T>(value: string): T;
1550
+ }
1551
+ declare class JSONOutputSerializer implements OutputSerializer {
1552
+ serialize(value: any): string;
1553
+ deserialize(value?: string): any;
1554
+ }
1400
1555
  declare class IO {
1401
1556
  #private;
1402
1557
  private _id;
@@ -1415,15 +1570,50 @@ declare class IO {
1415
1570
  private _serverVersion;
1416
1571
  private _timeOrigin;
1417
1572
  private _executionTimeout?;
1573
+ private _outputSerializer;
1574
+ private _visitedCacheKeys;
1418
1575
  get stats(): IOStats;
1419
1576
  constructor(options: IOOptions);
1420
1577
  /** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
1421
1578
  get logger(): IOLogger;
1579
+ /** `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.
1580
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1581
+ * @param min Sets the lower bound (inclusive). Can't be higher than `max`.
1582
+ * @param max Sets the upper bound (exclusive). Can't be lower than `min`.
1583
+ * @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.
1584
+ */
1585
+ random(cacheKey: string | any[], { min, max, round, }?: {
1586
+ min?: number;
1587
+ max?: number;
1588
+ round?: boolean;
1589
+ }): Promise<number>;
1422
1590
  /** `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
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.
1424
1592
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
1425
1593
  */
1426
1594
  wait(cacheKey: string | any[], seconds: number): Promise<void>;
1595
+ /** `io.waitForRequest()` allows you to pause the execution of a run until the url provided in the callback is POSTed to.
1596
+ * 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
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1598
+ * @param callback A callback function that will provide the unique URL to POST to.
1599
+ * @param options Options for the callback.
1600
+ * @param options.timeoutInSeconds How long to wait for the request to be POSTed to the callback URL before timing out. Defaults to 1hr.
1601
+ * @returns The POSTed request JSON body.
1602
+ * @example
1603
+ * ```ts
1604
+ const result = await io.waitForRequest<{ message: string }>(
1605
+ "wait-for-request",
1606
+ async (url, task) => {
1607
+ // Save the URL somewhere so you can POST to it later
1608
+ // Or send it to an external service that will POST to it
1609
+ },
1610
+ { timeoutInSeconds: 60 } // wait 60 seconds
1611
+ );
1612
+ * ```
1613
+ */
1614
+ waitForRequest<T extends Json<T> | unknown = unknown>(cacheKey: string | any[], callback: (url: string) => Promise<unknown>, options?: {
1615
+ timeoutInSeconds?: number;
1616
+ }): Promise<T>;
1427
1617
  /** `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
1618
  * @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
1619
  * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
@@ -1468,7 +1658,7 @@ declare class IO {
1468
1658
  * - Ranges: 500-599
1469
1659
  * - Wildcards: 2xx, 3xx, 4xx, 5xx
1470
1660
  */
1471
- backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
1661
+ backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions, timeout?: FetchTimeoutOptions): Promise<TResponseData>;
1472
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).
1473
1663
  * @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
1664
  * @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
@@ -1610,6 +1800,7 @@ declare class IO {
1610
1800
  key: string;
1611
1801
  } | undefined>;
1612
1802
  getAuth(cacheKey: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
1803
+ 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
1804
  /** `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
1805
  *
1615
1806
  * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
@@ -1627,7 +1818,7 @@ declare class IO {
1627
1818
  * `io.brb()` is an alias of `io.yield()`
1628
1819
  */
1629
1820
  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).
1821
+ /** `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
1822
  * 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
1823
  * @param tryCallback The code you wish to run
1633
1824
  * @param catchCallback Thhis will be called if the Task fails. The callback receives the error
@@ -1660,7 +1851,7 @@ interface TriggerIntegration {
1660
1851
  type IOWithIntegrations<TIntegrations extends Record<string, TriggerIntegration>> = IO & TIntegrations;
1661
1852
  type IntegrationTaskKey = string | any[];
1662
1853
 
1663
- type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> = {
1854
+ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> = {
1664
1855
  /** The `id` property is used to uniquely identify the Job. Only change this if you want to create a new Job. */
1665
1856
  id: string;
1666
1857
  /** 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 +1897,19 @@ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations
1706
1897
  * @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
1898
  * @param context An object that contains information about the Organization, Job, Run and more.
1708
1899
  */
1709
- run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<any>;
1900
+ run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<TOutput>;
1710
1901
  };
1711
1902
  type JobPayload<TJob> = TJob extends Job<Trigger<EventSpecification<infer TEvent>>, any> ? TEvent : never;
1712
1903
  type JobIO<TJob> = TJob extends Job<any, infer TIntegrations> ? IOWithIntegrations<TIntegrations> : never;
1713
1904
  /** 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> = {}> {
1905
+ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> {
1715
1906
  #private;
1716
- readonly options: JobOptions<TTrigger, TIntegrations>;
1907
+ readonly options: JobOptions<TTrigger, TIntegrations, TOutput>;
1717
1908
  client: TriggerClient;
1718
1909
  constructor(
1719
1910
  /** An instance of [TriggerClient](/sdk/triggerclient) that is used to send events
1720
1911
  to the Trigger API. */
1721
- client: TriggerClient, options: JobOptions<TTrigger, TIntegrations>);
1912
+ client: TriggerClient, options: JobOptions<TTrigger, TIntegrations, TOutput>);
1722
1913
  get id(): string;
1723
1914
  get enabled(): boolean;
1724
1915
  get name(): string;
@@ -1727,6 +1918,19 @@ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegratio
1727
1918
  get logLevel(): LogLevel | undefined;
1728
1919
  get integrations(): Record<string, IntegrationConfig>;
1729
1920
  toJSON(): JobMetadata;
1921
+ invoke(cacheKey: string, payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
1922
+ id: string;
1923
+ }>;
1924
+ invoke(payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
1925
+ id: string;
1926
+ }>;
1927
+ invokeAndWaitForCompletion(cacheKey: string | string[], payload: TriggerInvokeType<TTrigger>, timeoutInSeconds?: number, // 1 hour
1928
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>): Promise<RunNotification<TOutput>>;
1929
+ batchInvokeAndWaitForCompletion(cacheKey: string | string[], batch: Array<{
1930
+ payload: TriggerInvokeType<TTrigger>;
1931
+ timeoutInSeconds?: number;
1932
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>;
1933
+ }>): Promise<Array<RunNotification<TOutput>>>;
1730
1934
  }
1731
1935
 
1732
1936
  type EventTriggerOptions<TEventSpecification extends EventSpecification<any>> = {
@@ -1742,6 +1946,9 @@ declare class EventTrigger<TEventSpecification extends EventSpecification<any>>
1742
1946
  get event(): TEventSpecification;
1743
1947
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
1744
1948
  get preprocessRuns(): boolean;
1949
+ verifyPayload(payload: ReturnType<TEventSpecification["parsePayload"]>): Promise<{
1950
+ success: true;
1951
+ }>;
1745
1952
  }
1746
1953
  /** Configuration options for an EventTrigger */
1747
1954
  type TriggerOptions<TEvent> = {
@@ -1828,6 +2035,9 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1828
2035
  };
1829
2036
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<MissingConnectionNotificationSpecification>, any>): void;
1830
2037
  get preprocessRuns(): boolean;
2038
+ verifyPayload(payload: ReturnType<MissingConnectionNotificationSpecification["parsePayload"]>): Promise<{
2039
+ success: true;
2040
+ }>;
1831
2041
  toJSON(): TriggerMetadata;
1832
2042
  }
1833
2043
  type MissingConnectionResolvedNotificationSpecification = EventSpecification<MissingConnectionResolvedNotificationPayload>;
@@ -1877,13 +2087,70 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1877
2087
  };
1878
2088
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<MissingConnectionResolvedNotificationSpecification>, any>): void;
1879
2089
  get preprocessRuns(): boolean;
2090
+ verifyPayload(payload: ReturnType<MissingConnectionResolvedNotificationSpecification["parsePayload"]>): Promise<{
2091
+ success: true;
2092
+ }>;
1880
2093
  toJSON(): TriggerMetadata;
1881
2094
  }
1882
2095
 
2096
+ /** Configuration options for an InvokeTrigger */
2097
+ type InvokeTriggerOptions<TSchema extends ZodType = z.ZodTypeAny> = {
2098
+ /** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
2099
+ * The default is `z.any()` which is `any`.
2100
+ * */
2101
+ schema?: TSchema;
2102
+ examples?: EventSpecificationExample[];
2103
+ };
2104
+ declare class InvokeTrigger<TSchema extends ZodType = z.ZodTypeAny> implements Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>> {
2105
+ #private;
2106
+ constructor(options: InvokeTriggerOptions<TSchema>);
2107
+ toJSON(): TriggerMetadata;
2108
+ get event(): {
2109
+ name: string;
2110
+ title: string;
2111
+ source: string;
2112
+ examples: {
2113
+ id: string;
2114
+ name: string;
2115
+ icon?: string | undefined;
2116
+ payload?: any;
2117
+ }[];
2118
+ icon: string;
2119
+ parsePayload: (rawPayload: unknown) => any;
2120
+ parseInvokePayload: (rawPayload: unknown) => any;
2121
+ };
2122
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<EventSpecification<ZodType<TSchema>>>, any>): void;
2123
+ get preprocessRuns(): boolean;
2124
+ verifyPayload(): Promise<{
2125
+ success: true;
2126
+ }>;
2127
+ }
2128
+ declare function invokeTrigger<TSchema extends ZodType = z.ZodTypeAny>(options?: InvokeTriggerOptions<TSchema>): Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>>;
2129
+
2130
+ /** Easily verify webhook payloads when they're using common signing methods. */
2131
+ declare function verifyRequestSignature({ request, headerName, secret, algorithm, }: {
2132
+ /** The web request that you want to verify. */
2133
+ request: Request;
2134
+ /** The name of the header that contains the signature. E.g. `X-Cal-Signature-256`. */
2135
+ headerName: string;
2136
+ /** The secret that you use to hash the payload. For HttpEndpoints this will usually originally
2137
+ come from the Trigger.dev dashboard and should be stored in an environment variable. */
2138
+ secret: string;
2139
+ /** The hashing algorithm that was used to create the signature. Currently only `sha256` is
2140
+ supported. */
2141
+ algorithm: "sha256";
2142
+ }): Promise<VerifyResult>;
2143
+ declare function verifyHmacSha256(headerValue: string, secret: string, body: string): boolean;
2144
+
1883
2145
  declare class ResumeWithTaskError {
1884
2146
  task: ServerTask;
1885
2147
  constructor(task: ServerTask);
1886
2148
  }
2149
+ declare class ResumeWithParallelTaskError {
2150
+ task: ServerTask;
2151
+ childErrors: Array<TriggerInternalError>;
2152
+ constructor(task: ServerTask, childErrors: Array<TriggerInternalError>);
2153
+ }
1887
2154
  declare class RetryWithTaskError {
1888
2155
  cause: ErrorWithStack;
1889
2156
  task: ServerTask;
@@ -1907,25 +2174,26 @@ declare class AutoYieldExecutionError {
1907
2174
  declare class AutoYieldWithCompletedTaskExecutionError {
1908
2175
  id: string;
1909
2176
  properties: DisplayProperty[] | undefined;
1910
- output: any;
1911
2177
  data: {
1912
2178
  location: string;
1913
2179
  timeRemaining: number;
1914
2180
  timeElapsed: number;
1915
2181
  };
1916
- constructor(id: string, properties: DisplayProperty[] | undefined, output: any, data: {
2182
+ output?: string | undefined;
2183
+ constructor(id: string, properties: DisplayProperty[] | undefined, data: {
1917
2184
  location: string;
1918
2185
  timeRemaining: number;
1919
2186
  timeElapsed: number;
1920
- });
2187
+ }, output?: string | undefined);
1921
2188
  }
2189
+ type TriggerInternalError = ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError | YieldExecutionError | AutoYieldExecutionError | AutoYieldWithCompletedTaskExecutionError | ResumeWithParallelTaskError;
1922
2190
  /** Use this function if you're using a `try/catch` block to catch errors.
1923
2191
  * It checks if a thrown error is a special internal error that you should ignore.
1924
2192
  * If this returns `true` then you must rethrow the error: `throw err;`
1925
2193
  * @param err The error to check
1926
2194
  * @returns `true` if the error is a Trigger Error, `false` otherwise.
1927
2195
  */
1928
- declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError | YieldExecutionError | AutoYieldExecutionError | AutoYieldWithCompletedTaskExecutionError;
2196
+ declare function isTriggerError(err: unknown): err is TriggerInternalError;
1929
2197
 
1930
2198
  declare const retry: {
1931
2199
  readonly standardBackoff: {
@@ -1942,4 +2210,4 @@ type Task = ServerTask;
1942
2210
  type SentEvent = ApiEventLog;
1943
2211
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1944
2212
 
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 };
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 };