@trigger.dev/sdk 3.0.0-beta.46 → 3.0.0-beta.48

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.
@@ -1,5 +1,5 @@
1
- import { RetryOptions, FetchRetryOptions, ListProjectRunsQueryParams, CursorPagePromise, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RescheduleRunRequestBody, RetrieveRunResponse, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
2
- export { ApiClientConfiguration, ApiError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, ImportEnvironmentVariablesParams, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, ResolveEnvironmentVariablesFunction, ResolveEnvironmentVariablesParams, ResolveEnvironmentVariablesResult, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
1
+ import { RetryOptions, FetchRetryOptions, ListProjectRunsQueryParams, ApiRequestOptions, CursorPagePromise, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RescheduleRunRequestBody, RetrieveRunResponse, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
2
+ export { AbortTaskRunError, ApiClientConfiguration, ApiError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, ImportEnvironmentVariablesParams, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, ResolveEnvironmentVariablesFunction, ResolveEnvironmentVariablesParams, ResolveEnvironmentVariablesResult, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
3
3
  import { HttpHandler } from 'msw';
4
4
 
5
5
  type CacheMetadata = {
@@ -61,18 +61,18 @@ declare const runs: {
61
61
  reschedule: typeof rescheduleRun;
62
62
  poll: typeof poll;
63
63
  };
64
- declare function listRuns(projectRef: string, params?: ListProjectRunsQueryParams): CursorPagePromise<typeof ListRunResponseItem>;
65
- declare function listRuns(params?: ListRunsQueryParams): CursorPagePromise<typeof ListRunResponseItem>;
66
- declare function retrieveRun<TRunId extends RunHandle<any> | string>(runId: TRunId): ApiPromise<RetrieveRunResult<TRunId>>;
67
- declare function replayRun(runId: string): ApiPromise<ReplayRunResponse>;
68
- declare function cancelRun(runId: string): ApiPromise<CanceledRunResponse>;
69
- declare function rescheduleRun(runId: string, body: RescheduleRunRequestBody): ApiPromise<RetrieveRunResponse>;
64
+ declare function listRuns(projectRef: string, params?: ListProjectRunsQueryParams, requestOptions?: ApiRequestOptions): CursorPagePromise<typeof ListRunResponseItem>;
65
+ declare function listRuns(params?: ListRunsQueryParams, requestOptions?: ApiRequestOptions): CursorPagePromise<typeof ListRunResponseItem>;
66
+ declare function retrieveRun<TRunId extends RunHandle<any> | string>(runId: TRunId, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveRunResult<TRunId>>;
67
+ declare function replayRun(runId: string, requestOptions?: ApiRequestOptions): ApiPromise<ReplayRunResponse>;
68
+ declare function cancelRun(runId: string, requestOptions?: ApiRequestOptions): ApiPromise<CanceledRunResponse>;
69
+ declare function rescheduleRun(runId: string, body: RescheduleRunRequestBody, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveRunResponse>;
70
70
  type PollOptions = {
71
71
  pollIntervalMs?: number;
72
72
  };
73
73
  declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHandle, options?: {
74
74
  pollIntervalMs?: number;
75
- }): Promise<(TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
75
+ }, requestOptions?: ApiRequestOptions): Promise<(TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
76
76
  status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
77
77
  id: string;
78
78
  isTest: boolean;
@@ -270,6 +270,55 @@ declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHa
270
270
  output?: TRunHandle | undefined;
271
271
  })[K]; } : never>;
272
272
 
273
+ declare const idempotencyKeys: {
274
+ create: typeof createIdempotencyKey;
275
+ };
276
+ declare const __brand: unique symbol;
277
+ type Brand<B> = {
278
+ [__brand]: B;
279
+ };
280
+ type Branded<T, B> = T & Brand<B>;
281
+ type IdempotencyKey = Branded<string, "IdempotencyKey">;
282
+ declare function isIdempotencyKey(value: string | string[] | IdempotencyKey): value is IdempotencyKey;
283
+ /**
284
+ * Creates a deterministic idempotency key based on the provided key material.
285
+ *
286
+ * If running inside a task, the task run ID is automatically included in the key material, giving you a unique key per task run.
287
+ * This ensures that a given child task is only triggered once per task run, even if the parent task is retried.
288
+ *
289
+ * @param {string | string[]} key The key material to create the idempotency key from.
290
+ * @param {object} [options] Additional options.
291
+ * @param {"run" | "attempt" | "global"} [options.scope="run"] The scope of the idempotency key.
292
+ *
293
+ * @returns {Promise<IdempotencyKey>} The idempotency key as a branded string.
294
+ *
295
+ * @example
296
+ *
297
+ * ```typescript
298
+ * import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
299
+ *
300
+ * export const myTask = task({
301
+ * id: "my-task",
302
+ * run: async (payload: any) => {
303
+ * const idempotencyKey = await idempotencyKeys.create("my-task-key");
304
+ *
305
+ * // Use the idempotency key when triggering child tasks
306
+ * await childTask.triggerAndWait(payload, { idempotencyKey });
307
+ * }
308
+ * });
309
+ * ```
310
+ *
311
+ * You can also use the `scope` parameter to create a key that is unique per task run, task run attempts (retries of the same run), or globally:
312
+ *
313
+ * ```typescript
314
+ * await idempotencyKeys.create("my-task-key", { scope: "attempt" }); // Creates a key that is unique per task run attempt
315
+ * await idempotencyKeys.create("my-task-key", { scope: "global" }); // Skips including the task run ID
316
+ * ```
317
+ */
318
+ declare function createIdempotencyKey(key: string | string[], options?: {
319
+ scope?: "run" | "attempt" | "global";
320
+ }): Promise<IdempotencyKey>;
321
+
273
322
  type Context = TaskRunContext;
274
323
  type RequireOne<T, K extends keyof T> = {
275
324
  [X in Exclude<keyof T, K>]?: T[X];
@@ -519,7 +568,52 @@ type TaskOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, i
519
568
  type TaskBatchOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? BatchRunHandle<TOutput> : never;
520
569
  type TaskIdentifier<TTask extends AnyTask> = TTask extends Task<infer TIdentifier, any, any> ? TIdentifier : never;
521
570
  type TaskRunOptions = {
522
- idempotencyKey?: string;
571
+ /**
572
+ * A unique key that can be used to ensure that a task is only triggered once per key.
573
+ *
574
+ * You can use `idempotencyKeys.create` to create an idempotency key first, and then pass it to the task options.
575
+ *
576
+ * @example
577
+ *
578
+ * ```typescript
579
+ * import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
580
+ *
581
+ * export const myTask = task({
582
+ * id: "my-task",
583
+ * run: async (payload: any) => {
584
+ * // scoped to the task run by default
585
+ * const idempotencyKey = await idempotencyKeys.create("my-task-key");
586
+ *
587
+ * // Use the idempotency key when triggering child tasks
588
+ * await childTask.triggerAndWait(payload, { idempotencyKey });
589
+ *
590
+ * // scoped globally, does not include the task run ID
591
+ * const globalIdempotencyKey = await idempotencyKeys.create("my-task-key", { scope: "global" });
592
+ *
593
+ * await childTask.triggerAndWait(payload, { idempotencyKey: globalIdempotencyKey });
594
+ *
595
+ * // You can also pass a string directly, which is the same as a global idempotency key
596
+ * await childTask.triggerAndWait(payload, { idempotencyKey: "my-very-unique-key" });
597
+ * }
598
+ * });
599
+ * ```
600
+ *
601
+ * When triggering a task inside another task, we automatically inject the run ID into the key material.
602
+ *
603
+ * If you are triggering a task from your backend, ensure you include some sufficiently unique key material to prevent collisions.
604
+ *
605
+ * @example
606
+ *
607
+ * ```typescript
608
+ * import { idempotencyKeys, tasks } from "@trigger.dev/sdk/v3";
609
+ *
610
+ * // Somewhere in your backend
611
+ * const idempotencyKey = await idempotenceKeys.create(["my-task-trigger", "user-123"]);
612
+ * await tasks.trigger("my-task", { foo: "bar" }, { idempotencyKey });
613
+ * ```
614
+ *
615
+ */
616
+ idempotencyKey?: IdempotencyKey | string | string[];
523
617
  maxAttempts?: number;
524
618
  queue?: TaskRunConcurrencyOptions;
525
619
  concurrencyKey?: string;
@@ -571,7 +665,8 @@ type Prettify<T> = {
571
665
  *
572
666
  * @returns {RunHandle} An object with the `id` of the run. Can be used to retrieve the completed run output in a typesafe manner.
573
667
  */
574
- declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions): Promise<TaskOutputHandle<TTask>>;
668
+ declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): Promise<TaskOutputHandle<TTask>>;
669
+ declare function triggerAndWait<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): Promise<TaskRunResult<TaskOutput<TTask>>>;
575
670
  /**
576
671
  * Trigger a task by its identifier with the given payload and poll until the run is completed.
577
672
  *
@@ -587,8 +682,8 @@ declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, paylo
587
682
  *
588
683
  * @returns {Run} The completed run, either successful or failed.
589
684
  */
590
- declare function triggerAndPoll<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions & PollOptions): Promise<RetrieveRunResult<TaskOutputHandle<TTask>>>;
591
- declare function batchTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>): Promise<TaskBatchOutputHandle<TTask>>;
685
+ declare function triggerAndPoll<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions & PollOptions, requestOptions?: ApiRequestOptions): Promise<RetrieveRunResult<TaskOutputHandle<TTask>>>;
686
+ declare function batchTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>, requestOptions?: ApiRequestOptions): Promise<TaskBatchOutputHandle<TTask>>;
592
687
 
593
688
  /** Creates a task that can be triggered
594
689
  * @param options - Task options
@@ -613,6 +708,7 @@ declare const tasks: {
613
708
  trigger: typeof trigger;
614
709
  triggerAndPoll: typeof triggerAndPoll;
615
710
  batchTrigger: typeof batchTrigger;
711
+ triggerAndWait: typeof triggerAndWait;
616
712
  };
617
713
 
618
714
  type WaitOptions = {
@@ -727,13 +823,13 @@ declare function task<TIdentifier extends string, TOutput, TInitOutput extends I
727
823
  * @param options.deduplicationKey - An optional deduplication key for the schedule
728
824
  * @returns The created schedule
729
825
  */
730
- declare function create$1(options: CreateScheduleOptions): ApiPromise<ScheduleObject>;
826
+ declare function create$1(options: CreateScheduleOptions, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
731
827
  /**
732
828
  * Retrieves a schedule
733
829
  * @param scheduleId - The ID of the schedule to retrieve
734
830
  * @returns The retrieved schedule
735
831
  */
736
- declare function retrieve$1(scheduleId: string): ApiPromise<ScheduleObject>;
832
+ declare function retrieve$1(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
737
833
  /**
738
834
  * Updates a schedule
739
835
  * @param scheduleId - The ID of the schedule to update
@@ -744,22 +840,22 @@ declare function retrieve$1(scheduleId: string): ApiPromise<ScheduleObject>;
744
840
  * @param options.externalId - An optional external identifier for the schedule
745
841
  * @returns The updated schedule
746
842
  */
747
- declare function update$1(scheduleId: string, options: UpdateScheduleOptions): ApiPromise<ScheduleObject>;
843
+ declare function update$1(scheduleId: string, options: UpdateScheduleOptions, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
748
844
  /**
749
845
  * Deletes a schedule
750
846
  * @param scheduleId - The ID of the schedule to delete
751
847
  */
752
- declare function del$1(scheduleId: string): ApiPromise<DeletedScheduleObject>;
848
+ declare function del$1(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<DeletedScheduleObject>;
753
849
  /**
754
850
  * Deactivates a schedule
755
851
  * @param scheduleId - The ID of the schedule to deactivate
756
852
  */
757
- declare function deactivate(scheduleId: string): ApiPromise<ScheduleObject>;
853
+ declare function deactivate(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
758
854
  /**
759
855
  * Activates a schedule
760
856
  * @param scheduleId - The ID of the schedule to activate
761
857
  */
762
- declare function activate(scheduleId: string): ApiPromise<ScheduleObject>;
858
+ declare function activate(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
763
859
  /**
764
860
  * Lists schedules
765
861
  * @param options - The list options
@@ -767,7 +863,7 @@ declare function activate(scheduleId: string): ApiPromise<ScheduleObject>;
767
863
  * @param options.perPage - The number of schedules per page
768
864
  * @returns The list of schedules
769
865
  */
770
- declare function list$1(options?: ListScheduleOptions): OffsetLimitPagePromise<typeof ScheduleObject>;
866
+ declare function list$1(options?: ListScheduleOptions, requestOptions?: ApiRequestOptions): OffsetLimitPagePromise<typeof ScheduleObject>;
771
867
  /**
772
868
  * Lists the possible timezones we support
773
869
  * @param excludeUtc - By default "UTC" is included and is first. If true, "UTC" will be excluded.
@@ -786,18 +882,18 @@ declare namespace index {
786
882
  export { index_activate as activate, create$1 as create, index_deactivate as deactivate, del$1 as del, list$1 as list, retrieve$1 as retrieve, index_task as task, index_timezones as timezones, update$1 as update };
787
883
  }
788
884
 
789
- declare function upload(projectRef: string, slug: string, params: ImportEnvironmentVariablesParams): ApiPromise<EnvironmentVariableResponseBody>;
790
- declare function upload(params: ImportEnvironmentVariablesParams): ApiPromise<EnvironmentVariableResponseBody>;
791
- declare function list(projectRef: string, slug: string): ApiPromise<EnvironmentVariables>;
792
- declare function list(): ApiPromise<EnvironmentVariables>;
793
- declare function create(projectRef: string, slug: string, params: CreateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
794
- declare function create(params: CreateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
795
- declare function retrieve(projectRef: string, slug: string, name: string): ApiPromise<EnvironmentVariableValue>;
796
- declare function retrieve(name: string): ApiPromise<EnvironmentVariableValue>;
797
- declare function del(projectRef: string, slug: string, name: string): ApiPromise<EnvironmentVariableResponseBody>;
798
- declare function del(name: string): ApiPromise<EnvironmentVariableResponseBody>;
799
- declare function update(projectRef: string, slug: string, name: string, params: UpdateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
800
- declare function update(name: string, params: UpdateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
885
+ declare function upload(projectRef: string, slug: string, params: ImportEnvironmentVariablesParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
886
+ declare function upload(params: ImportEnvironmentVariablesParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
887
+ declare function list(projectRef: string, slug: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariables>;
888
+ declare function list(requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariables>;
889
+ declare function create(projectRef: string, slug: string, params: CreateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
890
+ declare function create(params: CreateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
891
+ declare function retrieve(projectRef: string, slug: string, name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableValue>;
892
+ declare function retrieve(name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableValue>;
893
+ declare function del(projectRef: string, slug: string, name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
894
+ declare function del(name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
895
+ declare function update(projectRef: string, slug: string, name: string, params: UpdateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
896
+ declare function update(name: string, params: UpdateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
801
897
 
802
898
  declare const envvars_CreateEnvironmentVariableParams: typeof CreateEnvironmentVariableParams;
803
899
  declare const envvars_ImportEnvironmentVariablesParams: typeof ImportEnvironmentVariablesParams;
@@ -830,4 +926,4 @@ declare namespace envvars {
830
926
  */
831
927
  declare function configure(options: ApiClientConfiguration): void;
832
928
 
833
- export { type BatchItem, type BatchResult, type BatchRunHandle, type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type ComputeUsage, type Context, type CurrentUsage, type Eventually, InMemoryCache, type Queue, type RunHandle, type Task, type TaskIdentifier, type TaskOptions, type TaskOutput, type TaskPayload, type TaskRunOptions, type TaskRunResult, type WaitOptions, configure, createCache, envvars, queue, retry, runs, index as schedules, task$1 as task, tasks, usage, wait };
929
+ export { type BatchItem, type BatchResult, type BatchRunHandle, type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type ComputeUsage, type Context, type CurrentUsage, type Eventually, type IdempotencyKey, InMemoryCache, type Queue, type RunHandle, type Task, type TaskIdentifier, type TaskOptions, type TaskOutput, type TaskPayload, type TaskRunOptions, type TaskRunResult, type WaitOptions, configure, createCache, envvars, idempotencyKeys, isIdempotencyKey, queue, retry, runs, index as schedules, task$1 as task, tasks, usage, wait };
@@ -1,5 +1,5 @@
1
- import { RetryOptions, FetchRetryOptions, ListProjectRunsQueryParams, CursorPagePromise, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RescheduleRunRequestBody, RetrieveRunResponse, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
2
- export { ApiClientConfiguration, ApiError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, ImportEnvironmentVariablesParams, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, ResolveEnvironmentVariablesFunction, ResolveEnvironmentVariablesParams, ResolveEnvironmentVariablesResult, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
1
+ import { RetryOptions, FetchRetryOptions, ListProjectRunsQueryParams, ApiRequestOptions, CursorPagePromise, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RescheduleRunRequestBody, RetrieveRunResponse, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
2
+ export { AbortTaskRunError, ApiClientConfiguration, ApiError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, ImportEnvironmentVariablesParams, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, ResolveEnvironmentVariablesFunction, ResolveEnvironmentVariablesParams, ResolveEnvironmentVariablesResult, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
3
3
  import { HttpHandler } from 'msw';
4
4
 
5
5
  type CacheMetadata = {
@@ -61,18 +61,18 @@ declare const runs: {
61
61
  reschedule: typeof rescheduleRun;
62
62
  poll: typeof poll;
63
63
  };
64
- declare function listRuns(projectRef: string, params?: ListProjectRunsQueryParams): CursorPagePromise<typeof ListRunResponseItem>;
65
- declare function listRuns(params?: ListRunsQueryParams): CursorPagePromise<typeof ListRunResponseItem>;
66
- declare function retrieveRun<TRunId extends RunHandle<any> | string>(runId: TRunId): ApiPromise<RetrieveRunResult<TRunId>>;
67
- declare function replayRun(runId: string): ApiPromise<ReplayRunResponse>;
68
- declare function cancelRun(runId: string): ApiPromise<CanceledRunResponse>;
69
- declare function rescheduleRun(runId: string, body: RescheduleRunRequestBody): ApiPromise<RetrieveRunResponse>;
64
+ declare function listRuns(projectRef: string, params?: ListProjectRunsQueryParams, requestOptions?: ApiRequestOptions): CursorPagePromise<typeof ListRunResponseItem>;
65
+ declare function listRuns(params?: ListRunsQueryParams, requestOptions?: ApiRequestOptions): CursorPagePromise<typeof ListRunResponseItem>;
66
+ declare function retrieveRun<TRunId extends RunHandle<any> | string>(runId: TRunId, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveRunResult<TRunId>>;
67
+ declare function replayRun(runId: string, requestOptions?: ApiRequestOptions): ApiPromise<ReplayRunResponse>;
68
+ declare function cancelRun(runId: string, requestOptions?: ApiRequestOptions): ApiPromise<CanceledRunResponse>;
69
+ declare function rescheduleRun(runId: string, body: RescheduleRunRequestBody, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveRunResponse>;
70
70
  type PollOptions = {
71
71
  pollIntervalMs?: number;
72
72
  };
73
73
  declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHandle, options?: {
74
74
  pollIntervalMs?: number;
75
- }): Promise<(TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
75
+ }, requestOptions?: ApiRequestOptions): Promise<(TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
76
76
  status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
77
77
  id: string;
78
78
  isTest: boolean;
@@ -270,6 +270,55 @@ declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHa
270
270
  output?: TRunHandle | undefined;
271
271
  })[K]; } : never>;
272
272
 
273
+ declare const idempotencyKeys: {
274
+ create: typeof createIdempotencyKey;
275
+ };
276
+ declare const __brand: unique symbol;
277
+ type Brand<B> = {
278
+ [__brand]: B;
279
+ };
280
+ type Branded<T, B> = T & Brand<B>;
281
+ type IdempotencyKey = Branded<string, "IdempotencyKey">;
282
+ declare function isIdempotencyKey(value: string | string[] | IdempotencyKey): value is IdempotencyKey;
283
+ /**
284
+ * Creates a deterministic idempotency key based on the provided key material.
285
+ *
286
+ * If running inside a task, the task run ID is automatically included in the key material, giving you a unique key per task run.
287
+ * This ensures that a given child task is only triggered once per task run, even if the parent task is retried.
288
+ *
289
+ * @param {string | string[]} key The key material to create the idempotency key from.
290
+ * @param {object} [options] Additional options.
291
+ * @param {"run" | "attempt" | "global"} [options.scope="run"] The scope of the idempotency key.
292
+ *
293
+ * @returns {Promise<IdempotencyKey>} The idempotency key as a branded string.
294
+ *
295
+ * @example
296
+ *
297
+ * ```typescript
298
+ * import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
299
+ *
300
+ * export const myTask = task({
301
+ * id: "my-task",
302
+ * run: async (payload: any) => {
303
+ * const idempotencyKey = await idempotencyKeys.create("my-task-key");
304
+ *
305
+ * // Use the idempotency key when triggering child tasks
306
+ * await childTask.triggerAndWait(payload, { idempotencyKey });
307
+ * }
308
+ * });
309
+ * ```
310
+ *
311
+ * You can also use the `scope` parameter to create a key that is unique per task run, task run attempts (retries of the same run), or globally:
312
+ *
313
+ * ```typescript
314
+ * await idempotencyKeys.create("my-task-key", { scope: "attempt" }); // Creates a key that is unique per task run attempt
315
+ * await idempotencyKeys.create("my-task-key", { scope: "global" }); // Skips including the task run ID
316
+ * ```
317
+ */
318
+ declare function createIdempotencyKey(key: string | string[], options?: {
319
+ scope?: "run" | "attempt" | "global";
320
+ }): Promise<IdempotencyKey>;
321
+
273
322
  type Context = TaskRunContext;
274
323
  type RequireOne<T, K extends keyof T> = {
275
324
  [X in Exclude<keyof T, K>]?: T[X];
@@ -519,7 +568,52 @@ type TaskOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, i
519
568
  type TaskBatchOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? BatchRunHandle<TOutput> : never;
520
569
  type TaskIdentifier<TTask extends AnyTask> = TTask extends Task<infer TIdentifier, any, any> ? TIdentifier : never;
521
570
  type TaskRunOptions = {
522
- idempotencyKey?: string;
571
+ /**
572
+ * A unique key that can be used to ensure that a task is only triggered once per key.
573
+ *
574
+ * You can use `idempotencyKeys.create` to create an idempotency key first, and then pass it to the task options.
575
+ *
576
+ * @example
577
+ *
578
+ * ```typescript
579
+ * import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
580
+ *
581
+ * export const myTask = task({
582
+ * id: "my-task",
583
+ * run: async (payload: any) => {
584
+ * // scoped to the task run by default
585
+ * const idempotencyKey = await idempotencyKeys.create("my-task-key");
586
+ *
587
+ * // Use the idempotency key when triggering child tasks
588
+ * await childTask.triggerAndWait(payload, { idempotencyKey });
589
+ *
590
+ * // scoped globally, does not include the task run ID
591
+ * const globalIdempotencyKey = await idempotencyKeys.create("my-task-key", { scope: "global" });
592
+ *
593
+ * await childTask.triggerAndWait(payload, { idempotencyKey: globalIdempotencyKey });
594
+ *
595
+ * // You can also pass a string directly, which is the same as a global idempotency key
596
+ * await childTask.triggerAndWait(payload, { idempotencyKey: "my-very-unique-key" });
597
+ * }
598
+ * });
599
+ * ```
600
+ *
601
+ * When triggering a task inside another task, we automatically inject the run ID into the key material.
602
+ *
603
+ * If you are triggering a task from your backend, ensure you include some sufficiently unique key material to prevent collisions.
604
+ *
605
+ * @example
606
+ *
607
+ * ```typescript
608
+ * import { idempotencyKeys, tasks } from "@trigger.dev/sdk/v3";
609
+ *
610
+ * // Somewhere in your backend
611
+ * const idempotencyKey = await idempotenceKeys.create(["my-task-trigger", "user-123"]);
612
+ * await tasks.trigger("my-task", { foo: "bar" }, { idempotencyKey });
613
+ * ```
614
+ *
615
+ */
616
+ idempotencyKey?: IdempotencyKey | string | string[];
523
617
  maxAttempts?: number;
524
618
  queue?: TaskRunConcurrencyOptions;
525
619
  concurrencyKey?: string;
@@ -571,7 +665,8 @@ type Prettify<T> = {
571
665
  *
572
666
  * @returns {RunHandle} An object with the `id` of the run. Can be used to retrieve the completed run output in a typesafe manner.
573
667
  */
574
- declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions): Promise<TaskOutputHandle<TTask>>;
668
+ declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): Promise<TaskOutputHandle<TTask>>;
669
+ declare function triggerAndWait<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): Promise<TaskRunResult<TaskOutput<TTask>>>;
575
670
  /**
576
671
  * Trigger a task by its identifier with the given payload and poll until the run is completed.
577
672
  *
@@ -587,8 +682,8 @@ declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, paylo
587
682
  *
588
683
  * @returns {Run} The completed run, either successful or failed.
589
684
  */
590
- declare function triggerAndPoll<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions & PollOptions): Promise<RetrieveRunResult<TaskOutputHandle<TTask>>>;
591
- declare function batchTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>): Promise<TaskBatchOutputHandle<TTask>>;
685
+ declare function triggerAndPoll<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions & PollOptions, requestOptions?: ApiRequestOptions): Promise<RetrieveRunResult<TaskOutputHandle<TTask>>>;
686
+ declare function batchTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>, requestOptions?: ApiRequestOptions): Promise<TaskBatchOutputHandle<TTask>>;
592
687
 
593
688
  /** Creates a task that can be triggered
594
689
  * @param options - Task options
@@ -613,6 +708,7 @@ declare const tasks: {
613
708
  trigger: typeof trigger;
614
709
  triggerAndPoll: typeof triggerAndPoll;
615
710
  batchTrigger: typeof batchTrigger;
711
+ triggerAndWait: typeof triggerAndWait;
616
712
  };
617
713
 
618
714
  type WaitOptions = {
@@ -727,13 +823,13 @@ declare function task<TIdentifier extends string, TOutput, TInitOutput extends I
727
823
  * @param options.deduplicationKey - An optional deduplication key for the schedule
728
824
  * @returns The created schedule
729
825
  */
730
- declare function create$1(options: CreateScheduleOptions): ApiPromise<ScheduleObject>;
826
+ declare function create$1(options: CreateScheduleOptions, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
731
827
  /**
732
828
  * Retrieves a schedule
733
829
  * @param scheduleId - The ID of the schedule to retrieve
734
830
  * @returns The retrieved schedule
735
831
  */
736
- declare function retrieve$1(scheduleId: string): ApiPromise<ScheduleObject>;
832
+ declare function retrieve$1(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
737
833
  /**
738
834
  * Updates a schedule
739
835
  * @param scheduleId - The ID of the schedule to update
@@ -744,22 +840,22 @@ declare function retrieve$1(scheduleId: string): ApiPromise<ScheduleObject>;
744
840
  * @param options.externalId - An optional external identifier for the schedule
745
841
  * @returns The updated schedule
746
842
  */
747
- declare function update$1(scheduleId: string, options: UpdateScheduleOptions): ApiPromise<ScheduleObject>;
843
+ declare function update$1(scheduleId: string, options: UpdateScheduleOptions, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
748
844
  /**
749
845
  * Deletes a schedule
750
846
  * @param scheduleId - The ID of the schedule to delete
751
847
  */
752
- declare function del$1(scheduleId: string): ApiPromise<DeletedScheduleObject>;
848
+ declare function del$1(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<DeletedScheduleObject>;
753
849
  /**
754
850
  * Deactivates a schedule
755
851
  * @param scheduleId - The ID of the schedule to deactivate
756
852
  */
757
- declare function deactivate(scheduleId: string): ApiPromise<ScheduleObject>;
853
+ declare function deactivate(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
758
854
  /**
759
855
  * Activates a schedule
760
856
  * @param scheduleId - The ID of the schedule to activate
761
857
  */
762
- declare function activate(scheduleId: string): ApiPromise<ScheduleObject>;
858
+ declare function activate(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
763
859
  /**
764
860
  * Lists schedules
765
861
  * @param options - The list options
@@ -767,7 +863,7 @@ declare function activate(scheduleId: string): ApiPromise<ScheduleObject>;
767
863
  * @param options.perPage - The number of schedules per page
768
864
  * @returns The list of schedules
769
865
  */
770
- declare function list$1(options?: ListScheduleOptions): OffsetLimitPagePromise<typeof ScheduleObject>;
866
+ declare function list$1(options?: ListScheduleOptions, requestOptions?: ApiRequestOptions): OffsetLimitPagePromise<typeof ScheduleObject>;
771
867
  /**
772
868
  * Lists the possible timezones we support
773
869
  * @param excludeUtc - By default "UTC" is included and is first. If true, "UTC" will be excluded.
@@ -786,18 +882,18 @@ declare namespace index {
786
882
  export { index_activate as activate, create$1 as create, index_deactivate as deactivate, del$1 as del, list$1 as list, retrieve$1 as retrieve, index_task as task, index_timezones as timezones, update$1 as update };
787
883
  }
788
884
 
789
- declare function upload(projectRef: string, slug: string, params: ImportEnvironmentVariablesParams): ApiPromise<EnvironmentVariableResponseBody>;
790
- declare function upload(params: ImportEnvironmentVariablesParams): ApiPromise<EnvironmentVariableResponseBody>;
791
- declare function list(projectRef: string, slug: string): ApiPromise<EnvironmentVariables>;
792
- declare function list(): ApiPromise<EnvironmentVariables>;
793
- declare function create(projectRef: string, slug: string, params: CreateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
794
- declare function create(params: CreateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
795
- declare function retrieve(projectRef: string, slug: string, name: string): ApiPromise<EnvironmentVariableValue>;
796
- declare function retrieve(name: string): ApiPromise<EnvironmentVariableValue>;
797
- declare function del(projectRef: string, slug: string, name: string): ApiPromise<EnvironmentVariableResponseBody>;
798
- declare function del(name: string): ApiPromise<EnvironmentVariableResponseBody>;
799
- declare function update(projectRef: string, slug: string, name: string, params: UpdateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
800
- declare function update(name: string, params: UpdateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
885
+ declare function upload(projectRef: string, slug: string, params: ImportEnvironmentVariablesParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
886
+ declare function upload(params: ImportEnvironmentVariablesParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
887
+ declare function list(projectRef: string, slug: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariables>;
888
+ declare function list(requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariables>;
889
+ declare function create(projectRef: string, slug: string, params: CreateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
890
+ declare function create(params: CreateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
891
+ declare function retrieve(projectRef: string, slug: string, name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableValue>;
892
+ declare function retrieve(name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableValue>;
893
+ declare function del(projectRef: string, slug: string, name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
894
+ declare function del(name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
895
+ declare function update(projectRef: string, slug: string, name: string, params: UpdateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
896
+ declare function update(name: string, params: UpdateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
801
897
 
802
898
  declare const envvars_CreateEnvironmentVariableParams: typeof CreateEnvironmentVariableParams;
803
899
  declare const envvars_ImportEnvironmentVariablesParams: typeof ImportEnvironmentVariablesParams;
@@ -830,4 +926,4 @@ declare namespace envvars {
830
926
  */
831
927
  declare function configure(options: ApiClientConfiguration): void;
832
928
 
833
- export { type BatchItem, type BatchResult, type BatchRunHandle, type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type ComputeUsage, type Context, type CurrentUsage, type Eventually, InMemoryCache, type Queue, type RunHandle, type Task, type TaskIdentifier, type TaskOptions, type TaskOutput, type TaskPayload, type TaskRunOptions, type TaskRunResult, type WaitOptions, configure, createCache, envvars, queue, retry, runs, index as schedules, task$1 as task, tasks, usage, wait };
929
+ export { type BatchItem, type BatchResult, type BatchRunHandle, type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type ComputeUsage, type Context, type CurrentUsage, type Eventually, type IdempotencyKey, InMemoryCache, type Queue, type RunHandle, type Task, type TaskIdentifier, type TaskOptions, type TaskOutput, type TaskPayload, type TaskRunOptions, type TaskRunResult, type WaitOptions, configure, createCache, envvars, idempotencyKeys, isIdempotencyKey, queue, retry, runs, index as schedules, task$1 as task, tasks, usage, wait };