@trigger.dev/sdk 3.0.0-beta.50 → 3.0.0-beta.51

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,4 +1,4 @@
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';
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, RunTags, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
2
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
 
@@ -48,11 +48,11 @@ declare const retry: {
48
48
  };
49
49
  };
50
50
 
51
- type RetrieveRunResult<TOutput> = Prettify<TOutput extends RunHandle<infer THandleOutput> ? Omit<RetrieveRunResponse, "output"> & {
52
- output?: THandleOutput;
53
- } : Omit<RetrieveRunResponse, "output"> & {
51
+ type RetrieveRunResult<TRunId> = Prettify<TRunId extends RunHandle<infer TOutput> ? Omit<RetrieveRunResponse, "output"> & {
54
52
  output?: TOutput;
55
- }>;
53
+ } : TRunId extends Task<string, any, infer TTaskOutput> ? Omit<RetrieveRunResponse, "output"> & {
54
+ output?: TTaskOutput;
55
+ } : TRunId extends string ? RetrieveRunResponse : never>;
56
56
  declare const runs: {
57
57
  replay: typeof replayRun;
58
58
  cancel: typeof cancelRun;
@@ -63,20 +63,25 @@ declare const runs: {
63
63
  };
64
64
  declare function listRuns(projectRef: string, params?: ListProjectRunsQueryParams, requestOptions?: ApiRequestOptions): CursorPagePromise<typeof ListRunResponseItem>;
65
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>>;
66
+ type RunId<TRunId> = TRunId extends RunHandle<any> ? TRunId : TRunId extends AnyTask ? string : TRunId extends string ? TRunId : never;
67
+ declare function retrieveRun<TRunId extends RunHandle<any> | AnyTask | string>(runId: RunId<TRunId>, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveRunResult<TRunId>>;
67
68
  declare function replayRun(runId: string, requestOptions?: ApiRequestOptions): ApiPromise<ReplayRunResponse>;
68
69
  declare function cancelRun(runId: string, requestOptions?: ApiRequestOptions): ApiPromise<CanceledRunResponse>;
69
70
  declare function rescheduleRun(runId: string, body: RescheduleRunRequestBody, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveRunResponse>;
70
71
  type PollOptions = {
71
72
  pollIntervalMs?: number;
72
73
  };
73
- declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHandle, options?: {
74
+ declare function poll<TRunId extends RunHandle<any> | AnyTask | string>(runId: RunId<TRunId>, options?: {
74
75
  pollIntervalMs?: number;
75
- }, requestOptions?: ApiRequestOptions): Promise<(TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
76
+ }, requestOptions?: ApiRequestOptions): Promise<(TRunId extends RunHandle<infer TOutput> ? Omit<{
76
77
  status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
77
78
  id: string;
79
+ tags: string[];
78
80
  isTest: boolean;
79
81
  createdAt: Date;
82
+ durationMs: number;
83
+ costInCents: number;
84
+ baseCostInCents: number;
80
85
  attempts: ({
81
86
  status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
82
87
  id: string;
@@ -120,12 +125,16 @@ declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHa
120
125
  ttl?: string | undefined;
121
126
  expiredAt?: Date | undefined;
122
127
  }, "output"> & {
123
- output?: THandleOutput | undefined;
124
- } : Omit<{
128
+ output?: TOutput | undefined;
129
+ } : TRunId extends Task<string, any, infer TTaskOutput> ? Omit<{
125
130
  status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
126
131
  id: string;
132
+ tags: string[];
127
133
  isTest: boolean;
128
134
  createdAt: Date;
135
+ durationMs: number;
136
+ costInCents: number;
137
+ baseCostInCents: number;
129
138
  attempts: ({
130
139
  status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
131
140
  id: string;
@@ -169,12 +178,67 @@ declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHa
169
178
  ttl?: string | undefined;
170
179
  expiredAt?: Date | undefined;
171
180
  }, "output"> & {
172
- output?: TRunHandle | undefined;
173
- }) extends infer T ? { [K in keyof T]: (TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
181
+ output?: TTaskOutput | undefined;
182
+ } : TRunId extends string ? {
174
183
  status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
175
184
  id: string;
185
+ tags: string[];
176
186
  isTest: boolean;
177
187
  createdAt: Date;
188
+ durationMs: number;
189
+ costInCents: number;
190
+ baseCostInCents: number;
191
+ attempts: ({
192
+ status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
193
+ id: string;
194
+ createdAt: Date;
195
+ updatedAt: Date;
196
+ startedAt?: Date | undefined;
197
+ completedAt?: Date | undefined;
198
+ error?: {
199
+ message: string;
200
+ name?: string | undefined;
201
+ stackTrace?: string | undefined;
202
+ } | undefined;
203
+ } | undefined)[];
204
+ updatedAt: Date;
205
+ taskIdentifier: string;
206
+ isQueued: boolean;
207
+ isExecuting: boolean;
208
+ isCompleted: boolean;
209
+ isSuccess: boolean;
210
+ isFailed: boolean;
211
+ isCancelled: boolean;
212
+ payload?: any;
213
+ payloadPresignedUrl?: string | undefined;
214
+ output?: any;
215
+ outputPresignedUrl?: string | undefined;
216
+ schedule?: {
217
+ id: string;
218
+ generator: {
219
+ type: "CRON";
220
+ expression: string;
221
+ description: string;
222
+ };
223
+ externalId?: string | undefined;
224
+ deduplicationKey?: string | undefined;
225
+ } | undefined;
226
+ idempotencyKey?: string | undefined;
227
+ version?: string | undefined;
228
+ startedAt?: Date | undefined;
229
+ finishedAt?: Date | undefined;
230
+ delayedUntil?: Date | undefined;
231
+ ttl?: string | undefined;
232
+ expiredAt?: Date | undefined;
233
+ } : never) extends infer T ? { [K in keyof T]: (TRunId extends RunHandle<infer TOutput> ? Omit<{
234
+ status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
235
+ id: string;
236
+ tags: string[];
237
+ isTest: boolean;
238
+ createdAt: Date;
239
+ durationMs: number;
240
+ costInCents: number;
241
+ baseCostInCents: number;
178
242
  attempts: ({
179
243
  status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
180
244
  id: string;
@@ -218,12 +282,16 @@ declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHa
218
282
  ttl?: string | undefined;
219
283
  expiredAt?: Date | undefined;
220
284
  }, "output"> & {
221
- output?: THandleOutput | undefined;
222
- } : Omit<{
285
+ output?: TOutput | undefined;
286
+ } : TRunId extends Task<string, any, infer TTaskOutput> ? Omit<{
223
287
  status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
224
288
  id: string;
289
+ tags: string[];
225
290
  isTest: boolean;
226
291
  createdAt: Date;
292
+ durationMs: number;
293
+ costInCents: number;
294
+ baseCostInCents: number;
227
295
  attempts: ({
228
296
  status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
229
297
  id: string;
@@ -267,8 +335,59 @@ declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHa
267
335
  ttl?: string | undefined;
268
336
  expiredAt?: Date | undefined;
269
337
  }, "output"> & {
270
- output?: TRunHandle | undefined;
271
- })[K]; } : never>;
338
+ output?: TTaskOutput | undefined;
339
+ } : TRunId extends string ? {
340
+ status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
341
+ id: string;
342
+ tags: string[];
343
+ isTest: boolean;
344
+ createdAt: Date;
345
+ durationMs: number;
346
+ costInCents: number;
347
+ baseCostInCents: number;
348
+ attempts: ({
349
+ status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
350
+ id: string;
351
+ createdAt: Date;
352
+ updatedAt: Date;
353
+ startedAt?: Date | undefined;
354
+ completedAt?: Date | undefined;
355
+ error?: {
356
+ message: string;
357
+ name?: string | undefined;
358
+ stackTrace?: string | undefined;
359
+ } | undefined;
360
+ } | undefined)[];
361
+ updatedAt: Date;
362
+ taskIdentifier: string;
363
+ isQueued: boolean;
364
+ isExecuting: boolean;
365
+ isCompleted: boolean;
366
+ isSuccess: boolean;
367
+ isFailed: boolean;
368
+ isCancelled: boolean;
369
+ payload?: any;
370
+ payloadPresignedUrl?: string | undefined;
371
+ output?: any;
372
+ outputPresignedUrl?: string | undefined;
373
+ schedule?: {
374
+ id: string;
375
+ generator: {
376
+ type: "CRON";
377
+ expression: string;
378
+ description: string;
379
+ };
380
+ externalId?: string | undefined;
381
+ deduplicationKey?: string | undefined;
382
+ } | undefined;
383
+ idempotencyKey?: string | undefined;
384
+ version?: string | undefined;
385
+ startedAt?: Date | undefined;
386
+ finishedAt?: Date | undefined;
387
+ delayedUntil?: Date | undefined;
388
+ ttl?: string | undefined;
389
+ expiredAt?: Date | undefined;
390
+ } : never)[K]; } : never>;
272
391
 
273
392
  declare const idempotencyKeys: {
274
393
  create: typeof createIdempotencyKey;
@@ -564,8 +683,6 @@ interface Task<TIdentifier extends string, TInput = void, TOutput = any> {
564
683
  type AnyTask = Task<string, any, any>;
565
684
  type TaskPayload<TTask extends AnyTask> = TTask extends Task<string, infer TInput, any> ? TInput : never;
566
685
  type TaskOutput<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? TOutput : never;
567
- type TaskOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? RunHandle<TOutput> : never;
568
- type TaskBatchOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? BatchRunHandle<TOutput> : never;
569
686
  type TaskIdentifier<TTask extends AnyTask> = TTask extends Task<infer TIdentifier, any, any> ? TIdentifier : never;
570
687
  type TaskRunOptions = {
571
688
  /**
@@ -644,6 +761,20 @@ type TaskRunOptions = {
644
761
  * **Note:** Runs in development have a default `ttl` of 10 minutes. You can override this by setting the `ttl` option.
645
762
  */
646
763
  ttl?: string | number;
764
+ /**
765
+ * Tags to attach to the run. Tags can be used to filter runs in the dashboard and using the SDK.
766
+ *
767
+ * You can set up to 3 tags per run, they must be less than 64 characters each.
768
+ *
769
+ * We recommend prefixing tags with a namespace using an underscore or colon, like `user_1234567` or `org:9876543`.
770
+ *
771
+ * @example
772
+ *
773
+ * ```ts
774
+ * await myTask.trigger({ foo: "bar" }, { tags: ["user:1234567", "org:9876543"] });
775
+ * ```
776
+ */
777
+ tags?: RunTags;
647
778
  };
648
779
  type TaskRunConcurrencyOptions = Queue;
649
780
  type Prettify<T> = {
@@ -665,8 +796,51 @@ type Prettify<T> = {
665
796
  *
666
797
  * @returns {RunHandle} An object with the `id` of the run. Can be used to retrieve the completed run output in a typesafe manner.
667
798
  */
668
- declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): Promise<TaskOutputHandle<TTask>>;
799
+ declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): Promise<RunHandle<TaskOutput<TTask>>>;
800
+ /**
801
+ * Trigger a task with the given payload, and wait for the result. Returns the result of the task run
802
+ * @param id - The id of the task to trigger
803
+ * @param payload
804
+ * @param options - Options for the task run
805
+ * @returns TaskRunResult
806
+ * @example
807
+ * ```ts
808
+ * import { tasks } from "@trigger.dev/sdk/v3";
809
+ * const result = await tasks.triggerAndWait("my-task", { foo: "bar" });
810
+ *
811
+ * if (result.ok) {
812
+ * console.log(result.output);
813
+ * } else {
814
+ * console.error(result.error);
815
+ * }
816
+ * ```
817
+ */
669
818
  declare function triggerAndWait<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): Promise<TaskRunResult<TaskOutput<TTask>>>;
819
+ /**
820
+ * Batch trigger multiple task runs with the given payloads, and wait for the results. Returns the results of the task runs.
821
+ * @param id - The id of the task to trigger
822
+ * @param items
823
+ * @returns BatchResult
824
+ * @example
825
+ *
826
+ * ```ts
827
+ * import { tasks } from "@trigger.dev/sdk/v3";
828
+ *
829
+ * const result = await tasks.batchTriggerAndWait("my-task", [
830
+ * { payload: { foo: "bar" } },
831
+ * { payload: { foo: "baz" } },
832
+ * ]);
833
+ *
834
+ * for (const run of result.runs) {
835
+ * if (run.ok) {
836
+ * console.log(run.output);
837
+ * } else {
838
+ * console.error(run.error);
839
+ * }
840
+ * }
841
+ * ```
842
+ */
843
+ declare function batchTriggerAndWait<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>, requestOptions?: ApiRequestOptions): Promise<BatchResult<TaskOutput<TTask>>>;
670
844
  /**
671
845
  * Trigger a task by its identifier with the given payload and poll until the run is completed.
672
846
  *
@@ -682,8 +856,8 @@ declare function triggerAndWait<TTask extends AnyTask>(id: TaskIdentifier<TTask>
682
856
  *
683
857
  * @returns {Run} The completed run, either successful or failed.
684
858
  */
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>>;
859
+ declare function triggerAndPoll<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions & PollOptions, requestOptions?: ApiRequestOptions): Promise<RetrieveRunResult<RunHandle<TaskOutput<TTask>>>>;
860
+ declare function batchTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>, requestOptions?: ApiRequestOptions): Promise<BatchRunHandle<TaskOutput<TTask>>>;
687
861
 
688
862
  /** Creates a task that can be triggered
689
863
  * @param options - Task options
@@ -709,6 +883,7 @@ declare const tasks: {
709
883
  triggerAndPoll: typeof triggerAndPoll;
710
884
  batchTrigger: typeof batchTrigger;
711
885
  triggerAndWait: typeof triggerAndWait;
886
+ batchTriggerAndWait: typeof batchTriggerAndWait;
712
887
  };
713
888
 
714
889
  type WaitOptions = {
@@ -812,6 +987,11 @@ declare const usage: {
812
987
  }>;
813
988
  };
814
989
 
990
+ declare const tags: {
991
+ add: typeof addTags;
992
+ };
993
+ declare function addTags(tags: RunTags, requestOptions?: ApiRequestOptions): Promise<void>;
994
+
815
995
  type ScheduleOptions<TIdentifier extends string, TOutput, TInitOutput extends InitOutput> = TaskOptions<TIdentifier, ScheduledTaskPayload, TOutput, TInitOutput> & {
816
996
  /** You can optionally specify a CRON schedule on your task. You can also dynamically add a schedule in the dashboard or using the SDK functions.
817
997
  *
@@ -950,4 +1130,4 @@ declare namespace envvars {
950
1130
  */
951
1131
  declare function configure(options: ApiClientConfiguration): void;
952
1132
 
953
- 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 };
1133
+ export { type AnyTask, 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, tags, task$1 as task, tasks, usage, wait };