@trigger.dev/sdk 0.0.0-dev-20231004120419 → 0.0.0-invoke-trigger-20231103104037

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,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, 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,8 +77,10 @@ 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;
83
+ forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
82
84
  }, "strip", z.ZodTypeAny, {
83
85
  id: string;
84
86
  name: string;
@@ -111,6 +113,8 @@ declare class ApiClient {
111
113
  } | null | undefined;
112
114
  operation?: string | null | undefined;
113
115
  callbackUrl?: string | null | undefined;
116
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
117
+ forceYield?: boolean | null | undefined;
114
118
  }, {
115
119
  id: string;
116
120
  name: string;
@@ -143,6 +147,8 @@ declare class ApiClient {
143
147
  } | null | undefined;
144
148
  operation?: string | null | undefined;
145
149
  callbackUrl?: string | null | undefined;
150
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
151
+ forceYield?: boolean | null | undefined;
146
152
  }>;
147
153
  cachedTasks: z.ZodOptional<z.ZodObject<{
148
154
  tasks: z.ZodArray<z.ZodObject<{
@@ -222,6 +228,8 @@ declare class ApiClient {
222
228
  } | null | undefined;
223
229
  operation?: string | null | undefined;
224
230
  callbackUrl?: string | null | undefined;
231
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
232
+ forceYield?: boolean | null | undefined;
225
233
  };
226
234
  cachedTasks?: {
227
235
  tasks: {
@@ -267,6 +275,8 @@ declare class ApiClient {
267
275
  } | null | undefined;
268
276
  operation?: string | null | undefined;
269
277
  callbackUrl?: string | null | undefined;
278
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
279
+ forceYield?: boolean | null | undefined;
270
280
  };
271
281
  cachedTasks?: {
272
282
  tasks: {
@@ -332,8 +342,10 @@ declare class ApiClient {
332
342
  }>>>;
333
343
  operation: z.ZodNullable<z.ZodOptional<z.ZodString>>;
334
344
  callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
345
+ childExecutionMode: z.ZodNullable<z.ZodOptional<z.ZodEnum<["SEQUENTIAL", "PARALLEL"]>>>;
335
346
  idempotencyKey: z.ZodString;
336
347
  attempts: z.ZodNumber;
348
+ forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
337
349
  }, "strip", z.ZodTypeAny, {
338
350
  id: string;
339
351
  name: string;
@@ -366,6 +378,8 @@ declare class ApiClient {
366
378
  } | null | undefined;
367
379
  operation?: string | null | undefined;
368
380
  callbackUrl?: string | null | undefined;
381
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
382
+ forceYield?: boolean | null | undefined;
369
383
  }, {
370
384
  id: string;
371
385
  name: string;
@@ -398,8 +412,10 @@ declare class ApiClient {
398
412
  } | null | undefined;
399
413
  operation?: string | null | undefined;
400
414
  callbackUrl?: string | null | undefined;
415
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
416
+ forceYield?: boolean | null | undefined;
401
417
  }>>>;
402
- completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
418
+ completeTask(runId: string, id: string, task: CompleteTaskBodyV2Input): Promise<{
403
419
  id: string;
404
420
  name: string;
405
421
  noop: boolean;
@@ -431,6 +447,8 @@ declare class ApiClient {
431
447
  } | null | undefined;
432
448
  operation?: string | null | undefined;
433
449
  callbackUrl?: string | null | undefined;
450
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
451
+ forceYield?: boolean | null | undefined;
434
452
  }>;
435
453
  failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
436
454
  id: string;
@@ -464,6 +482,8 @@ declare class ApiClient {
464
482
  } | null | undefined;
465
483
  operation?: string | null | undefined;
466
484
  callbackUrl?: string | null | undefined;
485
+ childExecutionMode?: "SEQUENTIAL" | "PARALLEL" | null | undefined;
486
+ forceYield?: boolean | null | undefined;
467
487
  }>;
468
488
  sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
469
489
  id: string;
@@ -493,6 +513,10 @@ declare class ApiClient {
493
513
  deliveredAt?: Date | null | undefined;
494
514
  cancelledAt?: Date | null | undefined;
495
515
  }>;
516
+ cancelRunsForEvent(eventId: string): Promise<{
517
+ cancelledRunIds: string[];
518
+ failedToCancelRunIds: string[];
519
+ }>;
496
520
  updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
497
521
  label: string;
498
522
  key: string;
@@ -505,7 +529,7 @@ declare class ApiClient {
505
529
  state?: "loading" | "success" | "failure" | undefined;
506
530
  }>;
507
531
  updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
508
- 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>;
509
533
  registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
510
534
  id: string;
511
535
  schedule: {
@@ -568,6 +592,27 @@ declare class ApiClient {
568
592
  output?: any;
569
593
  nextCursor?: string | undefined;
570
594
  }>;
595
+ cancelRun(runId: string): Promise<{
596
+ id: string;
597
+ startedAt: Date | null;
598
+ completedAt: Date | null;
599
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
600
+ updatedAt: Date | null;
601
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
602
+ statuses: {
603
+ label: string;
604
+ key: string;
605
+ history: {
606
+ label?: string | undefined;
607
+ state?: "loading" | "success" | "failure" | undefined;
608
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
609
+ }[];
610
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
611
+ state?: "loading" | "success" | "failure" | undefined;
612
+ }[];
613
+ output?: any;
614
+ nextCursor?: string | undefined;
615
+ }>;
571
616
  getRunStatuses(runId: string): Promise<{
572
617
  statuses: {
573
618
  label: string;
@@ -596,6 +641,9 @@ declare class ApiClient {
596
641
  }[];
597
642
  nextCursor?: string | undefined;
598
643
  }>;
644
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
645
+ id: string;
646
+ }>;
599
647
  }
600
648
  type VersionedResponseBodyMap = {
601
649
  [key: string]: z.ZodTypeAny;
@@ -610,6 +658,23 @@ type VersionedResponseBody<TVersions extends VersionedResponseBodyMap, TUnversio
610
658
  body: z.infer<TUnversioned>;
611
659
  };
612
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
+
613
678
  interface TriggerContext {
614
679
  /** Job metadata */
615
680
  job: {
@@ -628,6 +693,12 @@ interface TriggerContext {
628
693
  id: string;
629
694
  title: string;
630
695
  };
696
+ /** Project metadata */
697
+ project: {
698
+ slug: string;
699
+ id: string;
700
+ name: string;
701
+ };
631
702
  /** Run metadata */
632
703
  run: {
633
704
  id: string;
@@ -694,6 +765,7 @@ type PreprocessResults = {
694
765
  properties: DisplayProperty[];
695
766
  };
696
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;
697
769
  interface Trigger<TEventSpec extends EventSpecification<any>> {
698
770
  event: TEventSpec;
699
771
  toJSON(): TriggerMetadata;
@@ -707,7 +779,7 @@ type EventSpecificationExample = {
707
779
  icon?: string;
708
780
  payload: any;
709
781
  };
710
- interface EventSpecification<TEvent extends any> {
782
+ interface EventSpecification<TEvent extends any, TInvoke extends any = TEvent> {
711
783
  name: string | string[];
712
784
  title: string;
713
785
  source: string;
@@ -717,6 +789,7 @@ interface EventSpecification<TEvent extends any> {
717
789
  examples?: Array<EventSpecificationExample>;
718
790
  filter?: EventFilter;
719
791
  parsePayload: (payload: unknown) => TEvent;
792
+ parseInvokePayload?: (payload: unknown) => TInvoke;
720
793
  runProperties?: (payload: TEvent) => DisplayProperty[];
721
794
  }
722
795
  type EventTypeFromSpecification<TEventSpec extends EventSpecification<any>> = TEventSpec extends EventSpecification<infer TEvent> ? TEvent : never;
@@ -1095,8 +1168,8 @@ declare class TriggerClient {
1095
1168
  #private;
1096
1169
  id: string;
1097
1170
  constructor(options: Prettify<TriggerClientOptions>);
1098
- handleRequest(request: Request): Promise<NormalizedResponse>;
1099
- defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
1171
+ handleRequest(request: Request, timeOrigin?: number): Promise<NormalizedResponse>;
1172
+ defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any>(options: JobOptions<TTrigger, TIntegrations, TOutput>): Job<TTrigger, TIntegrations, TOutput>;
1100
1173
  defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
1101
1174
  defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
1102
1175
  defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
@@ -1112,7 +1185,7 @@ declare class TriggerClient {
1112
1185
  }): void;
1113
1186
  attachDynamicSchedule(key: string): void;
1114
1187
  attachDynamicScheduleToJob(key: string, job: Job<Trigger<any>, any>): void;
1115
- registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
1188
+ registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2, idempotencyKey?: string): Promise<{
1116
1189
  id: string;
1117
1190
  options: {
1118
1191
  event: {
@@ -1182,6 +1255,10 @@ declare class TriggerClient {
1182
1255
  deliveredAt?: Date | null | undefined;
1183
1256
  cancelledAt?: Date | null | undefined;
1184
1257
  }>;
1258
+ cancelRunsForEvent(eventId: string): Promise<{
1259
+ cancelledRunIds: string[];
1260
+ failedToCancelRunIds: string[];
1261
+ }>;
1185
1262
  updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
1186
1263
  label: string;
1187
1264
  key: string;
@@ -1249,6 +1326,27 @@ declare class TriggerClient {
1249
1326
  output?: any;
1250
1327
  nextCursor?: string | undefined;
1251
1328
  }>;
1329
+ cancelRun(runId: string): Promise<{
1330
+ id: string;
1331
+ startedAt: Date | null;
1332
+ completedAt: Date | null;
1333
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
1334
+ updatedAt: Date | null;
1335
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
1336
+ statuses: {
1337
+ label: string;
1338
+ key: string;
1339
+ history: {
1340
+ label?: string | undefined;
1341
+ state?: "loading" | "success" | "failure" | undefined;
1342
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1343
+ }[];
1344
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1345
+ state?: "loading" | "success" | "failure" | undefined;
1346
+ }[];
1347
+ output?: any;
1348
+ nextCursor?: string | undefined;
1349
+ }>;
1252
1350
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
1253
1351
  runs: {
1254
1352
  id: string;
@@ -1277,33 +1375,20 @@ declare class TriggerClient {
1277
1375
  output?: any;
1278
1376
  };
1279
1377
  }>;
1378
+ invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
1379
+ id: string;
1380
+ }>;
1280
1381
  authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
1281
1382
  apiKey(): string | undefined;
1282
1383
  }
1283
1384
 
1284
- declare class TriggerStatus {
1285
- private id;
1286
- private io;
1287
- constructor(id: string, io: IO);
1288
- update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
1289
- label: string;
1290
- key: string;
1291
- history: {
1292
- label?: string | undefined;
1293
- state?: "loading" | "success" | "failure" | undefined;
1294
- data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1295
- }[];
1296
- data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
1297
- state?: "loading" | "success" | "failure" | undefined;
1298
- }>;
1299
- }
1300
-
1301
1385
  type IOTask = ServerTask;
1302
1386
  type IOOptions = {
1303
1387
  id: string;
1304
1388
  apiClient: ApiClient;
1305
1389
  client: TriggerClient;
1306
1390
  context: TriggerContext;
1391
+ timeOrigin: number;
1307
1392
  logger?: Logger;
1308
1393
  logLevel?: LogLevel;
1309
1394
  jobLogger?: Logger;
@@ -1313,6 +1398,7 @@ type IOOptions = {
1313
1398
  yieldedExecutions?: Array<string>;
1314
1399
  noopTasksSet?: string;
1315
1400
  serverVersion?: string | null;
1401
+ executionTimeout?: number;
1316
1402
  };
1317
1403
  type JsonPrimitive = string | number | boolean | null | undefined | Date | symbol;
1318
1404
  type JsonArray = Json[];
@@ -1335,6 +1421,14 @@ type IOStats = {
1335
1421
  noopCachedTaskHits: number;
1336
1422
  noopCachedTaskMisses: number;
1337
1423
  };
1424
+ interface OutputSerializer {
1425
+ serialize(value: any): string;
1426
+ deserialize<T>(value: string): T;
1427
+ }
1428
+ declare class JSONOutputSerializer implements OutputSerializer {
1429
+ serialize(value: any): string;
1430
+ deserialize(value?: string): any;
1431
+ }
1338
1432
  declare class IO {
1339
1433
  #private;
1340
1434
  private _id;
@@ -1351,17 +1445,21 @@ declare class IO {
1351
1445
  private _noopTasksBloomFilter;
1352
1446
  private _stats;
1353
1447
  private _serverVersion;
1448
+ private _timeOrigin;
1449
+ private _executionTimeout?;
1450
+ private _outputSerializer;
1451
+ private _visitedCacheKeys;
1354
1452
  get stats(): IOStats;
1355
1453
  constructor(options: IOOptions);
1356
1454
  /** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
1357
1455
  get logger(): IOLogger;
1358
1456
  /** `io.wait()` waits for the specified amount of time before continuing the Job. Delays work even if you're on a serverless platform with timeouts, or if your server goes down. They utilize [resumability](https://trigger.dev/docs/documentation/concepts/resumability) to ensure that the Run can be resumed after the delay.
1359
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1457
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1360
1458
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
1361
1459
  */
1362
- wait(key: string | any[], seconds: number): Promise<void>;
1460
+ wait(cacheKey: string | any[], seconds: number): Promise<void>;
1363
1461
  /** `io.createStatus()` allows you to set a status with associated data during the Run. Statuses can be used by your UI using the react package
1364
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1462
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1365
1463
  * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
1366
1464
  * @returns a TriggerStatus object that you can call `update()` on, to update the status.
1367
1465
  * @example
@@ -1392,9 +1490,9 @@ declare class IO {
1392
1490
  });
1393
1491
  * ```
1394
1492
  */
1395
- createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
1493
+ createStatus(cacheKey: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
1396
1494
  /** `io.backgroundFetch()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
1397
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1495
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1398
1496
  * @param url The URL to fetch from.
1399
1497
  * @param requestInit The options for the request
1400
1498
  * @param retry The options for retrying the request if it fails
@@ -1404,13 +1502,13 @@ declare class IO {
1404
1502
  * - Ranges: 500-599
1405
1503
  * - Wildcards: 2xx, 3xx, 4xx, 5xx
1406
1504
  */
1407
- backgroundFetch<TResponseData>(key: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
1505
+ backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions, timeout?: FetchTimeoutOptions): Promise<TResponseData>;
1408
1506
  /** `io.sendEvent()` allows you to send an event from inside a Job run. The sent even will trigger any Jobs that are listening for that event (based on the name).
1409
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1507
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1410
1508
  * @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
1411
1509
  * @param options Options for sending the event.
1412
1510
  */
1413
- sendEvent(key: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
1511
+ sendEvent(cacheKey: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
1414
1512
  id: string;
1415
1513
  name: string;
1416
1514
  payload: ((string | number | boolean | {
@@ -1424,7 +1522,7 @@ declare class IO {
1424
1522
  deliveredAt?: Date | null | undefined;
1425
1523
  cancelledAt?: Date | null | undefined;
1426
1524
  }>;
1427
- getEvent(key: string | any[], id: string): Promise<{
1525
+ getEvent(cacheKey: string | any[], id: string): Promise<{
1428
1526
  id: string;
1429
1527
  name: string;
1430
1528
  updatedAt: Date;
@@ -1437,11 +1535,11 @@ declare class IO {
1437
1535
  createdAt: Date;
1438
1536
  }>;
1439
1537
  /** `io.cancelEvent()` allows you to cancel an event that was previously sent with `io.sendEvent()`. This will prevent any Jobs from running that are listening for that event if the event was sent with a delay
1440
- * @param key
1538
+ * @param cacheKey
1441
1539
  * @param eventId
1442
1540
  * @returns
1443
1541
  */
1444
- cancelEvent(key: string | any[], eventId: string): Promise<{
1542
+ cancelEvent(cacheKey: string | any[], eventId: string): Promise<{
1445
1543
  id: string;
1446
1544
  name: string;
1447
1545
  payload: ((string | number | boolean | {
@@ -1455,21 +1553,21 @@ declare class IO {
1455
1553
  deliveredAt?: Date | null | undefined;
1456
1554
  cancelledAt?: Date | null | undefined;
1457
1555
  }>;
1458
- updateSource(key: string | any[], options: {
1556
+ updateSource(cacheKey: string | any[], options: {
1459
1557
  key: string;
1460
1558
  } & UpdateTriggerSourceBodyV2): Promise<{
1461
1559
  id: string;
1462
1560
  key: string;
1463
1561
  }>;
1464
1562
  /** `io.registerInterval()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular interval.
1465
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1563
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1466
1564
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
1467
1565
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1468
1566
  * @param options The options for the interval.
1469
1567
  * @returns A promise that has information about the interval.
1470
1568
  * @deprecated Use `DynamicSchedule.register` instead.
1471
1569
  */
1472
- registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
1570
+ registerInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
1473
1571
  id: string;
1474
1572
  schedule: {
1475
1573
  options: {
@@ -1490,22 +1588,22 @@ declare class IO {
1490
1588
  metadata?: any;
1491
1589
  }>;
1492
1590
  /** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
1493
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1591
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1494
1592
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
1495
1593
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1496
1594
  * @deprecated Use `DynamicSchedule.unregister` instead.
1497
1595
  */
1498
- unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1596
+ unregisterInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1499
1597
  ok: boolean;
1500
1598
  }>;
1501
1599
  /** `io.registerCron()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular CRON schedule.
1502
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1600
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1503
1601
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
1504
1602
  * @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
1505
1603
  * @param options The options for the CRON schedule.
1506
1604
  * @deprecated Use `DynamicSchedule.register` instead.
1507
1605
  */
1508
- registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
1606
+ registerCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
1509
1607
  id: string;
1510
1608
  schedule: {
1511
1609
  options: {
@@ -1526,43 +1624,44 @@ declare class IO {
1526
1624
  metadata?: any;
1527
1625
  }>;
1528
1626
  /** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
1529
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1627
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1530
1628
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
1531
1629
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1532
1630
  * @deprecated Use `DynamicSchedule.unregister` instead.
1533
1631
  */
1534
- unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1632
+ unregisterCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1535
1633
  ok: boolean;
1536
1634
  }>;
1537
1635
  /** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
1538
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1636
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1539
1637
  * @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
1540
1638
  * @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
1541
1639
  * @param params The params for the trigger.
1542
1640
  * @deprecated Use `DynamicTrigger.register` instead.
1543
1641
  */
1544
- registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
1642
+ registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(cacheKey: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
1545
1643
  id: string;
1546
1644
  key: string;
1547
1645
  } | undefined>;
1548
- getAuth(key: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
1646
+ getAuth(cacheKey: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
1647
+ parallel<T extends Json<T> | void, TItem>(cacheKey: string | any[], items: Array<TItem>, callback: (item: TItem, index: number) => Promise<T>, options?: Pick<RunTaskOptions, "name" | "properties">): Promise<Array<T>>;
1549
1648
  /** `io.runTask()` allows you to run a [Task](https://trigger.dev/docs/documentation/concepts/tasks) from inside a Job run. A Task is a resumable unit of a Run that can be retried, resumed and is logged. [Integrations](https://trigger.dev/docs/integrations) use Tasks internally to perform their actions.
1550
1649
  *
1551
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1650
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1552
1651
  * @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
1553
1652
  * @param options The options of how you'd like to run and log the Task.
1554
1653
  * @param onError The callback that will be called when the Task fails. The callback receives the error, the Task and the IO as parameters. If you wish to retry then return an object with a `retryAt` property.
1555
1654
  * @returns A Promise that resolves with the returned value of the callback.
1556
1655
  */
1557
- runTask<T extends Json<T> | void>(key: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
1656
+ runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
1558
1657
  /**
1559
1658
  * `io.yield()` allows you to yield execution of the current run and resume it in a new function execution. Similar to `io.wait()` but does not create a task and resumes execution immediately.
1560
1659
  */
1561
- yield(key: string): void;
1660
+ yield(cacheKey: string): void;
1562
1661
  /**
1563
1662
  * `io.brb()` is an alias of `io.yield()`
1564
1663
  */
1565
- brb: (key: string) => void;
1664
+ brb: (cacheKey: string) => void;
1566
1665
  /** `io.try()` allows you to run Tasks and catch any errors that are thrown, it's similar to a normal `try/catch` block but works with [io.runTask()](/sdk/io/runtask).
1567
1666
  * A regular `try/catch` block on its own won't work as expected with Tasks. Internally `runTask()` throws some special errors to control flow execution. This is necessary to deal with resumability, serverless timeouts, and retrying Tasks.
1568
1667
  * @param tryCallback The code you wish to run
@@ -1596,7 +1695,7 @@ interface TriggerIntegration {
1596
1695
  type IOWithIntegrations<TIntegrations extends Record<string, TriggerIntegration>> = IO & TIntegrations;
1597
1696
  type IntegrationTaskKey = string | any[];
1598
1697
 
1599
- type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> = {
1698
+ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> = {
1600
1699
  /** The `id` property is used to uniquely identify the Job. Only change this if you want to create a new Job. */
1601
1700
  id: string;
1602
1701
  /** The `name` of the Job that you want to appear in the dashboard and logs. You can change this without creating a new Job. */
@@ -1642,19 +1741,19 @@ type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations
1642
1741
  * @param io An object that contains the integrations that you specified in the `integrations` property and other useful functions like delays and running Tasks.
1643
1742
  * @param context An object that contains information about the Organization, Job, Run and more.
1644
1743
  */
1645
- run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<any>;
1744
+ run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<TOutput>;
1646
1745
  };
1647
1746
  type JobPayload<TJob> = TJob extends Job<Trigger<EventSpecification<infer TEvent>>, any> ? TEvent : never;
1648
1747
  type JobIO<TJob> = TJob extends Job<any, infer TIntegrations> ? IOWithIntegrations<TIntegrations> : never;
1649
1748
  /** A [Job](https://trigger.dev/docs/documentation/concepts/jobs) is used to define the [Trigger](https://trigger.dev/docs/documentation/concepts/triggers), metadata, and what happens when it runs. */
1650
- declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> {
1749
+ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}, TOutput extends any = any> {
1651
1750
  #private;
1652
- readonly options: JobOptions<TTrigger, TIntegrations>;
1751
+ readonly options: JobOptions<TTrigger, TIntegrations, TOutput>;
1653
1752
  client: TriggerClient;
1654
1753
  constructor(
1655
1754
  /** An instance of [TriggerClient](/sdk/triggerclient) that is used to send events
1656
1755
  to the Trigger API. */
1657
- client: TriggerClient, options: JobOptions<TTrigger, TIntegrations>);
1756
+ client: TriggerClient, options: JobOptions<TTrigger, TIntegrations, TOutput>);
1658
1757
  get id(): string;
1659
1758
  get enabled(): boolean;
1660
1759
  get name(): string;
@@ -1663,6 +1762,19 @@ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegratio
1663
1762
  get logLevel(): LogLevel | undefined;
1664
1763
  get integrations(): Record<string, IntegrationConfig>;
1665
1764
  toJSON(): JobMetadata;
1765
+ invoke(cacheKey: string, payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
1766
+ id: string;
1767
+ }>;
1768
+ invoke(payload: TriggerInvokeType<TTrigger>, options?: InvokeOptions): Promise<{
1769
+ id: string;
1770
+ }>;
1771
+ invokeAndWaitForCompletion(cacheKey: string | string[], payload: TriggerInvokeType<TTrigger>, timeoutInSeconds?: number, // 1 hour
1772
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>): Promise<RunNotification<TOutput>>;
1773
+ batchInvokeAndWaitForCompletion(cacheKey: string | string[], batch: Array<{
1774
+ payload: TriggerInvokeType<TTrigger>;
1775
+ timeoutInSeconds?: number;
1776
+ options?: Prettify<Pick<InvokeOptions, "accountId" | "context">>;
1777
+ }>): Promise<Array<RunNotification<TOutput>>>;
1666
1778
  }
1667
1779
 
1668
1780
  type EventTriggerOptions<TEventSpecification extends EventSpecification<any>> = {
@@ -1816,10 +1928,41 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1816
1928
  toJSON(): TriggerMetadata;
1817
1929
  }
1818
1930
 
1931
+ /** Configuration options for an InvokeTrigger */
1932
+ type InvokeTriggerOptions<TSchema extends ZodType = z.ZodTypeAny> = {
1933
+ /** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
1934
+ * The default is `z.any()` which is `any`.
1935
+ * */
1936
+ schema?: TSchema;
1937
+ examples?: EventSpecificationExample[];
1938
+ };
1939
+ declare class InvokeTrigger<TSchema extends ZodType = z.ZodTypeAny> implements Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>> {
1940
+ #private;
1941
+ constructor(options: InvokeTriggerOptions<TSchema>);
1942
+ toJSON(): TriggerMetadata;
1943
+ get event(): {
1944
+ name: string;
1945
+ title: string;
1946
+ source: string;
1947
+ examples: EventSpecificationExample[];
1948
+ icon: string;
1949
+ parsePayload: (rawPayload: unknown) => any;
1950
+ parseInvokePayload: (rawPayload: unknown) => any;
1951
+ };
1952
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<EventSpecification<ZodType<TSchema>>>, any>): void;
1953
+ get preprocessRuns(): boolean;
1954
+ }
1955
+ declare function invokeTrigger<TSchema extends ZodType = z.ZodTypeAny>(options?: InvokeTriggerOptions<TSchema>): Trigger<EventSpecification<TypeOf<TSchema>, z.input<TSchema>>>;
1956
+
1819
1957
  declare class ResumeWithTaskError {
1820
1958
  task: ServerTask;
1821
1959
  constructor(task: ServerTask);
1822
1960
  }
1961
+ declare class ResumeWithParallelTaskError {
1962
+ task: ServerTask;
1963
+ childErrors: Array<TriggerInternalError>;
1964
+ constructor(task: ServerTask, childErrors: Array<TriggerInternalError>);
1965
+ }
1823
1966
  declare class RetryWithTaskError {
1824
1967
  cause: ErrorWithStack;
1825
1968
  task: ServerTask;
@@ -1830,13 +1973,39 @@ declare class CanceledWithTaskError {
1830
1973
  task: ServerTask;
1831
1974
  constructor(task: ServerTask);
1832
1975
  }
1976
+ declare class YieldExecutionError {
1977
+ key: string;
1978
+ constructor(key: string);
1979
+ }
1980
+ declare class AutoYieldExecutionError {
1981
+ location: string;
1982
+ timeRemaining: number;
1983
+ timeElapsed: number;
1984
+ constructor(location: string, timeRemaining: number, timeElapsed: number);
1985
+ }
1986
+ declare class AutoYieldWithCompletedTaskExecutionError {
1987
+ id: string;
1988
+ properties: DisplayProperty[] | undefined;
1989
+ data: {
1990
+ location: string;
1991
+ timeRemaining: number;
1992
+ timeElapsed: number;
1993
+ };
1994
+ output?: string | undefined;
1995
+ constructor(id: string, properties: DisplayProperty[] | undefined, data: {
1996
+ location: string;
1997
+ timeRemaining: number;
1998
+ timeElapsed: number;
1999
+ }, output?: string | undefined);
2000
+ }
2001
+ type TriggerInternalError = ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError | YieldExecutionError | AutoYieldExecutionError | AutoYieldWithCompletedTaskExecutionError | ResumeWithParallelTaskError;
1833
2002
  /** Use this function if you're using a `try/catch` block to catch errors.
1834
2003
  * It checks if a thrown error is a special internal error that you should ignore.
1835
2004
  * If this returns `true` then you must rethrow the error: `throw err;`
1836
2005
  * @param err The error to check
1837
2006
  * @returns `true` if the error is a Trigger Error, `false` otherwise.
1838
2007
  */
1839
- declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError;
2008
+ declare function isTriggerError(err: unknown): err is TriggerInternalError;
1840
2009
 
1841
2010
  declare const retry: {
1842
2011
  readonly standardBackoff: {
@@ -1853,4 +2022,4 @@ type Task = ServerTask;
1853
2022
  type SentEvent = ApiEventLog;
1854
2023
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1855
2024
 
1856
- 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 };
2025
+ export { AuthResolverResult, CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventSpecification, EventSpecificationExample, EventTrigger, EventTypeFromSpecification, ExternalSource, ExternalSourceParams, ExternalSourceTrigger, ExternalSourceTriggerOptions, HandlerEvent, HttpSourceEvent, IO, IOLogger, IOOptions, IOStats, IOTask, IOWithIntegrations, IntegrationTaskKey, IntervalTrigger, InvokeTrigger, JSONOutputSerializer, Job, JobIO, JobOptions, JobPayload, Json, MissingConnectionNotification, MissingConnectionResolvedNotification, OutputSerializer, PreprocessResults, RunTaskErrorCallback, SchemaParser, SchemaParserIssue, SchemaParserResult, SentEvent, Task, TaskLogger, Trigger, TriggerAuthResolver, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerInvokeType, TriggerOptionRecord, TriggerPayload, TriggerPreprocessContext, cronTrigger, eventTrigger, intervalTrigger, invokeTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry };