@trigger.dev/sdk 2.2.0 → 2.2.2

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
@@ -79,6 +79,7 @@ declare class ApiClient {
79
79
  callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
80
80
  idempotencyKey: z.ZodString;
81
81
  attempts: z.ZodNumber;
82
+ forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
82
83
  }, "strip", z.ZodTypeAny, {
83
84
  id: string;
84
85
  name: string;
@@ -111,6 +112,7 @@ declare class ApiClient {
111
112
  } | null | undefined;
112
113
  operation?: string | null | undefined;
113
114
  callbackUrl?: string | null | undefined;
115
+ forceYield?: boolean | null | undefined;
114
116
  }, {
115
117
  id: string;
116
118
  name: string;
@@ -143,6 +145,7 @@ declare class ApiClient {
143
145
  } | null | undefined;
144
146
  operation?: string | null | undefined;
145
147
  callbackUrl?: string | null | undefined;
148
+ forceYield?: boolean | null | undefined;
146
149
  }>;
147
150
  cachedTasks: z.ZodOptional<z.ZodObject<{
148
151
  tasks: z.ZodArray<z.ZodObject<{
@@ -222,6 +225,7 @@ declare class ApiClient {
222
225
  } | null | undefined;
223
226
  operation?: string | null | undefined;
224
227
  callbackUrl?: string | null | undefined;
228
+ forceYield?: boolean | null | undefined;
225
229
  };
226
230
  cachedTasks?: {
227
231
  tasks: {
@@ -267,6 +271,7 @@ declare class ApiClient {
267
271
  } | null | undefined;
268
272
  operation?: string | null | undefined;
269
273
  callbackUrl?: string | null | undefined;
274
+ forceYield?: boolean | null | undefined;
270
275
  };
271
276
  cachedTasks?: {
272
277
  tasks: {
@@ -334,6 +339,7 @@ declare class ApiClient {
334
339
  callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
335
340
  idempotencyKey: z.ZodString;
336
341
  attempts: z.ZodNumber;
342
+ forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
337
343
  }, "strip", z.ZodTypeAny, {
338
344
  id: string;
339
345
  name: string;
@@ -366,6 +372,7 @@ declare class ApiClient {
366
372
  } | null | undefined;
367
373
  operation?: string | null | undefined;
368
374
  callbackUrl?: string | null | undefined;
375
+ forceYield?: boolean | null | undefined;
369
376
  }, {
370
377
  id: string;
371
378
  name: string;
@@ -398,6 +405,7 @@ declare class ApiClient {
398
405
  } | null | undefined;
399
406
  operation?: string | null | undefined;
400
407
  callbackUrl?: string | null | undefined;
408
+ forceYield?: boolean | null | undefined;
401
409
  }>>>;
402
410
  completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
403
411
  id: string;
@@ -431,6 +439,7 @@ declare class ApiClient {
431
439
  } | null | undefined;
432
440
  operation?: string | null | undefined;
433
441
  callbackUrl?: string | null | undefined;
442
+ forceYield?: boolean | null | undefined;
434
443
  }>;
435
444
  failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
436
445
  id: string;
@@ -464,6 +473,7 @@ declare class ApiClient {
464
473
  } | null | undefined;
465
474
  operation?: string | null | undefined;
466
475
  callbackUrl?: string | null | undefined;
476
+ forceYield?: boolean | null | undefined;
467
477
  }>;
468
478
  sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
469
479
  id: string;
@@ -1116,7 +1126,7 @@ declare class TriggerClient {
1116
1126
  #private;
1117
1127
  id: string;
1118
1128
  constructor(options: Prettify<TriggerClientOptions>);
1119
- handleRequest(request: Request): Promise<NormalizedResponse>;
1129
+ handleRequest(request: Request, timeOrigin?: number): Promise<NormalizedResponse>;
1120
1130
  defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
1121
1131
  defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
1122
1132
  defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
@@ -1346,6 +1356,7 @@ type IOOptions = {
1346
1356
  apiClient: ApiClient;
1347
1357
  client: TriggerClient;
1348
1358
  context: TriggerContext;
1359
+ timeOrigin: number;
1349
1360
  logger?: Logger;
1350
1361
  logLevel?: LogLevel;
1351
1362
  jobLogger?: Logger;
@@ -1355,6 +1366,7 @@ type IOOptions = {
1355
1366
  yieldedExecutions?: Array<string>;
1356
1367
  noopTasksSet?: string;
1357
1368
  serverVersion?: string | null;
1369
+ executionTimeout?: number;
1358
1370
  };
1359
1371
  type JsonPrimitive = string | number | boolean | null | undefined | Date | symbol;
1360
1372
  type JsonArray = Json[];
@@ -1393,17 +1405,19 @@ declare class IO {
1393
1405
  private _noopTasksBloomFilter;
1394
1406
  private _stats;
1395
1407
  private _serverVersion;
1408
+ private _timeOrigin;
1409
+ private _executionTimeout?;
1396
1410
  get stats(): IOStats;
1397
1411
  constructor(options: IOOptions);
1398
1412
  /** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
1399
1413
  get logger(): IOLogger;
1400
1414
  /** `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.
1401
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1415
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1402
1416
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
1403
1417
  */
1404
- wait(key: string | any[], seconds: number): Promise<void>;
1418
+ wait(cacheKey: string | any[], seconds: number): Promise<void>;
1405
1419
  /** `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
1406
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1420
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1407
1421
  * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
1408
1422
  * @returns a TriggerStatus object that you can call `update()` on, to update the status.
1409
1423
  * @example
@@ -1434,9 +1448,9 @@ declare class IO {
1434
1448
  });
1435
1449
  * ```
1436
1450
  */
1437
- createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
1451
+ createStatus(cacheKey: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
1438
1452
  /** `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.
1439
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1453
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1440
1454
  * @param url The URL to fetch from.
1441
1455
  * @param requestInit The options for the request
1442
1456
  * @param retry The options for retrying the request if it fails
@@ -1446,13 +1460,13 @@ declare class IO {
1446
1460
  * - Ranges: 500-599
1447
1461
  * - Wildcards: 2xx, 3xx, 4xx, 5xx
1448
1462
  */
1449
- backgroundFetch<TResponseData>(key: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
1463
+ backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
1450
1464
  /** `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).
1451
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1465
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1452
1466
  * @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
1453
1467
  * @param options Options for sending the event.
1454
1468
  */
1455
- sendEvent(key: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
1469
+ sendEvent(cacheKey: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
1456
1470
  id: string;
1457
1471
  name: string;
1458
1472
  payload: ((string | number | boolean | {
@@ -1466,7 +1480,7 @@ declare class IO {
1466
1480
  deliveredAt?: Date | null | undefined;
1467
1481
  cancelledAt?: Date | null | undefined;
1468
1482
  }>;
1469
- getEvent(key: string | any[], id: string): Promise<{
1483
+ getEvent(cacheKey: string | any[], id: string): Promise<{
1470
1484
  id: string;
1471
1485
  name: string;
1472
1486
  updatedAt: Date;
@@ -1479,11 +1493,11 @@ declare class IO {
1479
1493
  createdAt: Date;
1480
1494
  }>;
1481
1495
  /** `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
1482
- * @param key
1496
+ * @param cacheKey
1483
1497
  * @param eventId
1484
1498
  * @returns
1485
1499
  */
1486
- cancelEvent(key: string | any[], eventId: string): Promise<{
1500
+ cancelEvent(cacheKey: string | any[], eventId: string): Promise<{
1487
1501
  id: string;
1488
1502
  name: string;
1489
1503
  payload: ((string | number | boolean | {
@@ -1497,21 +1511,21 @@ declare class IO {
1497
1511
  deliveredAt?: Date | null | undefined;
1498
1512
  cancelledAt?: Date | null | undefined;
1499
1513
  }>;
1500
- updateSource(key: string | any[], options: {
1514
+ updateSource(cacheKey: string | any[], options: {
1501
1515
  key: string;
1502
1516
  } & UpdateTriggerSourceBodyV2): Promise<{
1503
1517
  id: string;
1504
1518
  key: string;
1505
1519
  }>;
1506
1520
  /** `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.
1507
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1521
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1508
1522
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
1509
1523
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1510
1524
  * @param options The options for the interval.
1511
1525
  * @returns A promise that has information about the interval.
1512
1526
  * @deprecated Use `DynamicSchedule.register` instead.
1513
1527
  */
1514
- registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
1528
+ registerInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
1515
1529
  id: string;
1516
1530
  schedule: {
1517
1531
  options: {
@@ -1532,22 +1546,22 @@ declare class IO {
1532
1546
  metadata?: any;
1533
1547
  }>;
1534
1548
  /** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
1535
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1549
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1536
1550
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
1537
1551
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1538
1552
  * @deprecated Use `DynamicSchedule.unregister` instead.
1539
1553
  */
1540
- unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1554
+ unregisterInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1541
1555
  ok: boolean;
1542
1556
  }>;
1543
1557
  /** `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.
1544
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1558
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1545
1559
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
1546
1560
  * @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
1547
1561
  * @param options The options for the CRON schedule.
1548
1562
  * @deprecated Use `DynamicSchedule.register` instead.
1549
1563
  */
1550
- registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
1564
+ registerCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
1551
1565
  id: string;
1552
1566
  schedule: {
1553
1567
  options: {
@@ -1568,43 +1582,43 @@ declare class IO {
1568
1582
  metadata?: any;
1569
1583
  }>;
1570
1584
  /** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
1571
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1585
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1572
1586
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
1573
1587
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1574
1588
  * @deprecated Use `DynamicSchedule.unregister` instead.
1575
1589
  */
1576
- unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1590
+ unregisterCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
1577
1591
  ok: boolean;
1578
1592
  }>;
1579
1593
  /** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
1580
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1594
+ * @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
1595
  * @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
1582
1596
  * @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
1583
1597
  * @param params The params for the trigger.
1584
1598
  * @deprecated Use `DynamicTrigger.register` instead.
1585
1599
  */
1586
- registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
1600
+ registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(cacheKey: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
1587
1601
  id: string;
1588
1602
  key: string;
1589
1603
  } | undefined>;
1590
- getAuth(key: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
1604
+ getAuth(cacheKey: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
1591
1605
  /** `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.
1592
1606
  *
1593
- * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1607
+ * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
1594
1608
  * @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
1595
1609
  * @param options The options of how you'd like to run and log the Task.
1596
1610
  * @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.
1597
1611
  * @returns A Promise that resolves with the returned value of the callback.
1598
1612
  */
1599
- runTask<T extends Json<T> | void>(key: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
1613
+ runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
1600
1614
  /**
1601
1615
  * `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.
1602
1616
  */
1603
- yield(key: string): void;
1617
+ yield(cacheKey: string): void;
1604
1618
  /**
1605
1619
  * `io.brb()` is an alias of `io.yield()`
1606
1620
  */
1607
- brb: (key: string) => void;
1621
+ brb: (cacheKey: string) => void;
1608
1622
  /** `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).
1609
1623
  * 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.
1610
1624
  * @param tryCallback The code you wish to run
@@ -1872,13 +1886,38 @@ declare class CanceledWithTaskError {
1872
1886
  task: ServerTask;
1873
1887
  constructor(task: ServerTask);
1874
1888
  }
1889
+ declare class YieldExecutionError {
1890
+ key: string;
1891
+ constructor(key: string);
1892
+ }
1893
+ declare class AutoYieldExecutionError {
1894
+ location: string;
1895
+ timeRemaining: number;
1896
+ timeElapsed: number;
1897
+ constructor(location: string, timeRemaining: number, timeElapsed: number);
1898
+ }
1899
+ declare class AutoYieldWithCompletedTaskExecutionError {
1900
+ id: string;
1901
+ properties: DisplayProperty[] | undefined;
1902
+ output: any;
1903
+ data: {
1904
+ location: string;
1905
+ timeRemaining: number;
1906
+ timeElapsed: number;
1907
+ };
1908
+ constructor(id: string, properties: DisplayProperty[] | undefined, output: any, data: {
1909
+ location: string;
1910
+ timeRemaining: number;
1911
+ timeElapsed: number;
1912
+ });
1913
+ }
1875
1914
  /** Use this function if you're using a `try/catch` block to catch errors.
1876
1915
  * It checks if a thrown error is a special internal error that you should ignore.
1877
1916
  * If this returns `true` then you must rethrow the error: `throw err;`
1878
1917
  * @param err The error to check
1879
1918
  * @returns `true` if the error is a Trigger Error, `false` otherwise.
1880
1919
  */
1881
- declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError;
1920
+ declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError | YieldExecutionError | AutoYieldExecutionError | AutoYieldWithCompletedTaskExecutionError;
1882
1921
 
1883
1922
  declare const retry: {
1884
1923
  readonly standardBackoff: {