@trigger.dev/sdk 3.0.0-beta.5 → 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.
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +221 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +221 -69
- package/dist/index.mjs.map +1 -1
- package/dist/v3/index.d.mts +960 -81
- package/dist/v3/index.d.ts +960 -81
- package/dist/v3/index.js +1395 -388
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +1347 -390
- package/dist/v3/index.mjs.map +1 -1
- package/package.json +5 -12
package/dist/v3/index.d.mts
CHANGED
|
@@ -1,7 +1,443 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { HandleErrorArgs, HandleErrorFunction, LogLevel, RetryOptions, ProjectConfig as TriggerConfig, 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, RunTags, 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
|
+
type CacheMetadata = {
|
|
6
|
+
createdTime: number;
|
|
7
|
+
ttl?: number | null;
|
|
8
|
+
};
|
|
9
|
+
type CacheEntry<Value = unknown> = {
|
|
10
|
+
metadata: CacheMetadata;
|
|
11
|
+
value: Value;
|
|
12
|
+
};
|
|
13
|
+
type Eventually<Value> = Value | null | undefined | Promise<Value | null | undefined>;
|
|
14
|
+
type CacheStore<Value = any> = {
|
|
15
|
+
name?: string;
|
|
16
|
+
get: (key: string) => Eventually<CacheEntry<Value>>;
|
|
17
|
+
set: (key: string, value: CacheEntry<Value>) => unknown | Promise<unknown>;
|
|
18
|
+
delete: (key: string) => unknown | Promise<unknown>;
|
|
19
|
+
};
|
|
20
|
+
type CacheFunction = <Value>(cacheKey: string, fn: () => Promise<Value> | Value) => Promise<Value> | Value;
|
|
21
|
+
declare class InMemoryCache<Value = any> {
|
|
22
|
+
private _cache;
|
|
23
|
+
get(key: string): Eventually<CacheEntry<Value>>;
|
|
24
|
+
set(key: string, value: CacheEntry<Value>): unknown;
|
|
25
|
+
delete(key: string): unknown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a cache function that uses the provided store to cache values. Using InMemoryCache is safe because each task run is isolated.
|
|
29
|
+
* @param store
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
declare function createCache(store: CacheStore): CacheFunction;
|
|
33
|
+
|
|
34
|
+
declare function onThrow<T>(fn: (options: {
|
|
35
|
+
attempt: number;
|
|
36
|
+
maxAttempts: number;
|
|
37
|
+
}) => Promise<T>, options: RetryOptions): Promise<T>;
|
|
38
|
+
interface RetryFetchRequestInit extends RequestInit {
|
|
39
|
+
retry?: FetchRetryOptions;
|
|
40
|
+
timeoutInMs?: number;
|
|
41
|
+
}
|
|
42
|
+
declare function retryFetch(input: RequestInfo | URL, init?: RetryFetchRequestInit | undefined): Promise<Response>;
|
|
43
|
+
declare const retry: {
|
|
44
|
+
onThrow: typeof onThrow;
|
|
45
|
+
fetch: typeof retryFetch;
|
|
46
|
+
interceptFetch: (...handlers: Array<HttpHandler>) => {
|
|
47
|
+
run: <T>(fn: (...args: any[]) => Promise<T>) => Promise<T>;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type RetrieveRunResult<TRunId> = Prettify<TRunId extends RunHandle<infer TOutput> ? Omit<RetrieveRunResponse, "output"> & {
|
|
52
|
+
output?: TOutput;
|
|
53
|
+
} : TRunId extends Task<string, any, infer TTaskOutput> ? Omit<RetrieveRunResponse, "output"> & {
|
|
54
|
+
output?: TTaskOutput;
|
|
55
|
+
} : TRunId extends string ? RetrieveRunResponse : never>;
|
|
56
|
+
declare const runs: {
|
|
57
|
+
replay: typeof replayRun;
|
|
58
|
+
cancel: typeof cancelRun;
|
|
59
|
+
retrieve: typeof retrieveRun;
|
|
60
|
+
list: typeof listRuns;
|
|
61
|
+
reschedule: typeof rescheduleRun;
|
|
62
|
+
poll: typeof poll;
|
|
63
|
+
};
|
|
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
|
+
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>>;
|
|
68
|
+
declare function replayRun(runId: string, requestOptions?: ApiRequestOptions): ApiPromise<ReplayRunResponse>;
|
|
69
|
+
declare function cancelRun(runId: string, requestOptions?: ApiRequestOptions): ApiPromise<CanceledRunResponse>;
|
|
70
|
+
declare function rescheduleRun(runId: string, body: RescheduleRunRequestBody, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveRunResponse>;
|
|
71
|
+
type PollOptions = {
|
|
72
|
+
pollIntervalMs?: number;
|
|
73
|
+
};
|
|
74
|
+
declare function poll<TRunId extends RunHandle<any> | AnyTask | string>(runId: RunId<TRunId>, options?: {
|
|
75
|
+
pollIntervalMs?: number;
|
|
76
|
+
}, requestOptions?: ApiRequestOptions): Promise<(TRunId extends RunHandle<infer TOutput> ? Omit<{
|
|
77
|
+
status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
|
|
78
|
+
id: string;
|
|
79
|
+
tags: string[];
|
|
80
|
+
isTest: boolean;
|
|
81
|
+
createdAt: Date;
|
|
82
|
+
durationMs: number;
|
|
83
|
+
costInCents: number;
|
|
84
|
+
baseCostInCents: number;
|
|
85
|
+
attempts: ({
|
|
86
|
+
status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
|
|
87
|
+
id: string;
|
|
88
|
+
createdAt: Date;
|
|
89
|
+
updatedAt: Date;
|
|
90
|
+
startedAt?: Date | undefined;
|
|
91
|
+
completedAt?: Date | undefined;
|
|
92
|
+
error?: {
|
|
93
|
+
message: string;
|
|
94
|
+
name?: string | undefined;
|
|
95
|
+
stackTrace?: string | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
} | undefined)[];
|
|
98
|
+
updatedAt: Date;
|
|
99
|
+
taskIdentifier: string;
|
|
100
|
+
isQueued: boolean;
|
|
101
|
+
isExecuting: boolean;
|
|
102
|
+
isCompleted: boolean;
|
|
103
|
+
isSuccess: boolean;
|
|
104
|
+
isFailed: boolean;
|
|
105
|
+
isCancelled: boolean;
|
|
106
|
+
payload?: any;
|
|
107
|
+
payloadPresignedUrl?: string | undefined;
|
|
108
|
+
output?: any;
|
|
109
|
+
outputPresignedUrl?: string | undefined;
|
|
110
|
+
schedule?: {
|
|
111
|
+
id: string;
|
|
112
|
+
generator: {
|
|
113
|
+
type: "CRON";
|
|
114
|
+
expression: string;
|
|
115
|
+
description: string;
|
|
116
|
+
};
|
|
117
|
+
externalId?: string | undefined;
|
|
118
|
+
deduplicationKey?: string | undefined;
|
|
119
|
+
} | undefined;
|
|
120
|
+
idempotencyKey?: string | undefined;
|
|
121
|
+
version?: string | undefined;
|
|
122
|
+
startedAt?: Date | undefined;
|
|
123
|
+
finishedAt?: Date | undefined;
|
|
124
|
+
delayedUntil?: Date | undefined;
|
|
125
|
+
ttl?: string | undefined;
|
|
126
|
+
expiredAt?: Date | undefined;
|
|
127
|
+
}, "output"> & {
|
|
128
|
+
output?: TOutput | undefined;
|
|
129
|
+
} : TRunId extends Task<string, any, infer TTaskOutput> ? Omit<{
|
|
130
|
+
status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
|
|
131
|
+
id: string;
|
|
132
|
+
tags: string[];
|
|
133
|
+
isTest: boolean;
|
|
134
|
+
createdAt: Date;
|
|
135
|
+
durationMs: number;
|
|
136
|
+
costInCents: number;
|
|
137
|
+
baseCostInCents: number;
|
|
138
|
+
attempts: ({
|
|
139
|
+
status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
|
|
140
|
+
id: string;
|
|
141
|
+
createdAt: Date;
|
|
142
|
+
updatedAt: Date;
|
|
143
|
+
startedAt?: Date | undefined;
|
|
144
|
+
completedAt?: Date | undefined;
|
|
145
|
+
error?: {
|
|
146
|
+
message: string;
|
|
147
|
+
name?: string | undefined;
|
|
148
|
+
stackTrace?: string | undefined;
|
|
149
|
+
} | undefined;
|
|
150
|
+
} | undefined)[];
|
|
151
|
+
updatedAt: Date;
|
|
152
|
+
taskIdentifier: string;
|
|
153
|
+
isQueued: boolean;
|
|
154
|
+
isExecuting: boolean;
|
|
155
|
+
isCompleted: boolean;
|
|
156
|
+
isSuccess: boolean;
|
|
157
|
+
isFailed: boolean;
|
|
158
|
+
isCancelled: boolean;
|
|
159
|
+
payload?: any;
|
|
160
|
+
payloadPresignedUrl?: string | undefined;
|
|
161
|
+
output?: any;
|
|
162
|
+
outputPresignedUrl?: string | undefined;
|
|
163
|
+
schedule?: {
|
|
164
|
+
id: string;
|
|
165
|
+
generator: {
|
|
166
|
+
type: "CRON";
|
|
167
|
+
expression: string;
|
|
168
|
+
description: string;
|
|
169
|
+
};
|
|
170
|
+
externalId?: string | undefined;
|
|
171
|
+
deduplicationKey?: string | undefined;
|
|
172
|
+
} | undefined;
|
|
173
|
+
idempotencyKey?: string | undefined;
|
|
174
|
+
version?: string | undefined;
|
|
175
|
+
startedAt?: Date | undefined;
|
|
176
|
+
finishedAt?: Date | undefined;
|
|
177
|
+
delayedUntil?: Date | undefined;
|
|
178
|
+
ttl?: string | undefined;
|
|
179
|
+
expiredAt?: Date | undefined;
|
|
180
|
+
}, "output"> & {
|
|
181
|
+
output?: TTaskOutput | undefined;
|
|
182
|
+
} : TRunId extends string ? {
|
|
183
|
+
status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
|
|
184
|
+
id: string;
|
|
185
|
+
tags: string[];
|
|
186
|
+
isTest: boolean;
|
|
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;
|
|
242
|
+
attempts: ({
|
|
243
|
+
status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
|
|
244
|
+
id: string;
|
|
245
|
+
createdAt: Date;
|
|
246
|
+
updatedAt: Date;
|
|
247
|
+
startedAt?: Date | undefined;
|
|
248
|
+
completedAt?: Date | undefined;
|
|
249
|
+
error?: {
|
|
250
|
+
message: string;
|
|
251
|
+
name?: string | undefined;
|
|
252
|
+
stackTrace?: string | undefined;
|
|
253
|
+
} | undefined;
|
|
254
|
+
} | undefined)[];
|
|
255
|
+
updatedAt: Date;
|
|
256
|
+
taskIdentifier: string;
|
|
257
|
+
isQueued: boolean;
|
|
258
|
+
isExecuting: boolean;
|
|
259
|
+
isCompleted: boolean;
|
|
260
|
+
isSuccess: boolean;
|
|
261
|
+
isFailed: boolean;
|
|
262
|
+
isCancelled: boolean;
|
|
263
|
+
payload?: any;
|
|
264
|
+
payloadPresignedUrl?: string | undefined;
|
|
265
|
+
output?: any;
|
|
266
|
+
outputPresignedUrl?: string | undefined;
|
|
267
|
+
schedule?: {
|
|
268
|
+
id: string;
|
|
269
|
+
generator: {
|
|
270
|
+
type: "CRON";
|
|
271
|
+
expression: string;
|
|
272
|
+
description: string;
|
|
273
|
+
};
|
|
274
|
+
externalId?: string | undefined;
|
|
275
|
+
deduplicationKey?: string | undefined;
|
|
276
|
+
} | undefined;
|
|
277
|
+
idempotencyKey?: string | undefined;
|
|
278
|
+
version?: string | undefined;
|
|
279
|
+
startedAt?: Date | undefined;
|
|
280
|
+
finishedAt?: Date | undefined;
|
|
281
|
+
delayedUntil?: Date | undefined;
|
|
282
|
+
ttl?: string | undefined;
|
|
283
|
+
expiredAt?: Date | undefined;
|
|
284
|
+
}, "output"> & {
|
|
285
|
+
output?: TOutput | undefined;
|
|
286
|
+
} : TRunId extends Task<string, any, infer TTaskOutput> ? Omit<{
|
|
287
|
+
status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
|
|
288
|
+
id: string;
|
|
289
|
+
tags: string[];
|
|
290
|
+
isTest: boolean;
|
|
291
|
+
createdAt: Date;
|
|
292
|
+
durationMs: number;
|
|
293
|
+
costInCents: number;
|
|
294
|
+
baseCostInCents: number;
|
|
295
|
+
attempts: ({
|
|
296
|
+
status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
|
|
297
|
+
id: string;
|
|
298
|
+
createdAt: Date;
|
|
299
|
+
updatedAt: Date;
|
|
300
|
+
startedAt?: Date | undefined;
|
|
301
|
+
completedAt?: Date | undefined;
|
|
302
|
+
error?: {
|
|
303
|
+
message: string;
|
|
304
|
+
name?: string | undefined;
|
|
305
|
+
stackTrace?: string | undefined;
|
|
306
|
+
} | undefined;
|
|
307
|
+
} | undefined)[];
|
|
308
|
+
updatedAt: Date;
|
|
309
|
+
taskIdentifier: string;
|
|
310
|
+
isQueued: boolean;
|
|
311
|
+
isExecuting: boolean;
|
|
312
|
+
isCompleted: boolean;
|
|
313
|
+
isSuccess: boolean;
|
|
314
|
+
isFailed: boolean;
|
|
315
|
+
isCancelled: boolean;
|
|
316
|
+
payload?: any;
|
|
317
|
+
payloadPresignedUrl?: string | undefined;
|
|
318
|
+
output?: any;
|
|
319
|
+
outputPresignedUrl?: string | undefined;
|
|
320
|
+
schedule?: {
|
|
321
|
+
id: string;
|
|
322
|
+
generator: {
|
|
323
|
+
type: "CRON";
|
|
324
|
+
expression: string;
|
|
325
|
+
description: string;
|
|
326
|
+
};
|
|
327
|
+
externalId?: string | undefined;
|
|
328
|
+
deduplicationKey?: string | undefined;
|
|
329
|
+
} | undefined;
|
|
330
|
+
idempotencyKey?: string | undefined;
|
|
331
|
+
version?: string | undefined;
|
|
332
|
+
startedAt?: Date | undefined;
|
|
333
|
+
finishedAt?: Date | undefined;
|
|
334
|
+
delayedUntil?: Date | undefined;
|
|
335
|
+
ttl?: string | undefined;
|
|
336
|
+
expiredAt?: Date | undefined;
|
|
337
|
+
}, "output"> & {
|
|
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>;
|
|
391
|
+
|
|
392
|
+
declare const idempotencyKeys: {
|
|
393
|
+
create: typeof createIdempotencyKey;
|
|
394
|
+
};
|
|
395
|
+
declare const __brand: unique symbol;
|
|
396
|
+
type Brand<B> = {
|
|
397
|
+
[__brand]: B;
|
|
398
|
+
};
|
|
399
|
+
type Branded<T, B> = T & Brand<B>;
|
|
400
|
+
type IdempotencyKey = Branded<string, "IdempotencyKey">;
|
|
401
|
+
declare function isIdempotencyKey(value: string | string[] | IdempotencyKey): value is IdempotencyKey;
|
|
402
|
+
/**
|
|
403
|
+
* Creates a deterministic idempotency key based on the provided key material.
|
|
404
|
+
*
|
|
405
|
+
* If running inside a task, the task run ID is automatically included in the key material, giving you a unique key per task run.
|
|
406
|
+
* This ensures that a given child task is only triggered once per task run, even if the parent task is retried.
|
|
407
|
+
*
|
|
408
|
+
* @param {string | string[]} key The key material to create the idempotency key from.
|
|
409
|
+
* @param {object} [options] Additional options.
|
|
410
|
+
* @param {"run" | "attempt" | "global"} [options.scope="run"] The scope of the idempotency key.
|
|
411
|
+
*
|
|
412
|
+
* @returns {Promise<IdempotencyKey>} The idempotency key as a branded string.
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
*
|
|
416
|
+
* ```typescript
|
|
417
|
+
* import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
|
|
418
|
+
*
|
|
419
|
+
* export const myTask = task({
|
|
420
|
+
* id: "my-task",
|
|
421
|
+
* run: async (payload: any) => {
|
|
422
|
+
* const idempotencyKey = await idempotencyKeys.create("my-task-key");
|
|
423
|
+
*
|
|
424
|
+
* // Use the idempotency key when triggering child tasks
|
|
425
|
+
* await childTask.triggerAndWait(payload, { idempotencyKey });
|
|
426
|
+
* }
|
|
427
|
+
* });
|
|
428
|
+
* ```
|
|
429
|
+
*
|
|
430
|
+
* 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:
|
|
431
|
+
*
|
|
432
|
+
* ```typescript
|
|
433
|
+
* await idempotencyKeys.create("my-task-key", { scope: "attempt" }); // Creates a key that is unique per task run attempt
|
|
434
|
+
* await idempotencyKeys.create("my-task-key", { scope: "global" }); // Skips including the task run ID
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
declare function createIdempotencyKey(key: string | string[], options?: {
|
|
438
|
+
scope?: "run" | "attempt" | "global";
|
|
439
|
+
}): Promise<IdempotencyKey>;
|
|
440
|
+
|
|
5
441
|
type Context = TaskRunContext;
|
|
6
442
|
type RequireOne<T, K extends keyof T> = {
|
|
7
443
|
[X in Exclude<keyof T, K>]?: T[X];
|
|
@@ -9,9 +445,12 @@ type RequireOne<T, K extends keyof T> = {
|
|
|
9
445
|
[P in K]-?: T[P];
|
|
10
446
|
};
|
|
11
447
|
type Queue = RequireOne<QueueOptions, "name">;
|
|
12
|
-
|
|
448
|
+
declare function queue(options: {
|
|
449
|
+
name: string;
|
|
450
|
+
} & QueueOptions): Queue;
|
|
451
|
+
type TaskOptions<TIdentifier extends string, TPayload = void, TOutput = unknown, TInitOutput extends InitOutput = any> = {
|
|
13
452
|
/** An id for your task. This must be unique inside your project and not change between versions. */
|
|
14
|
-
id:
|
|
453
|
+
id: TIdentifier;
|
|
15
454
|
/** The retry settings when an uncaught error is thrown.
|
|
16
455
|
*
|
|
17
456
|
* If omitted it will use the values in your `trigger.config.ts` file.
|
|
@@ -79,6 +518,7 @@ type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any>
|
|
|
79
518
|
* - 1
|
|
80
519
|
* - 2
|
|
81
520
|
* - 4
|
|
521
|
+
* @deprecated use preset instead
|
|
82
522
|
*/
|
|
83
523
|
cpu?: MachineCpu;
|
|
84
524
|
/** In GBs of RAM. The default is 1.
|
|
@@ -90,8 +530,11 @@ type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any>
|
|
|
90
530
|
* - 2
|
|
91
531
|
* - 4
|
|
92
532
|
* - 8
|
|
533
|
+
* * @deprecated use preset instead
|
|
93
534
|
*/
|
|
94
535
|
memory?: MachineMemory;
|
|
536
|
+
/** Preset to use for the machine. Defaults to small-1x */
|
|
537
|
+
preset?: "micro" | "small-1x" | "small-2x" | "medium-1x" | "medium-2x" | "large-1x" | "large-2x";
|
|
95
538
|
};
|
|
96
539
|
/** This gets called when a task is triggered. It's where you put the code you want to execute.
|
|
97
540
|
*
|
|
@@ -99,19 +542,64 @@ type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any>
|
|
|
99
542
|
* @param params - Metadata about the run.
|
|
100
543
|
*/
|
|
101
544
|
run: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<TOutput>;
|
|
545
|
+
/**
|
|
546
|
+
* init is called before the run function is called. It's useful for setting up any global state.
|
|
547
|
+
*/
|
|
102
548
|
init?: (payload: TPayload, params: InitFnParams) => Promise<TInitOutput>;
|
|
103
|
-
|
|
549
|
+
/**
|
|
550
|
+
* cleanup is called after the run function has completed.
|
|
551
|
+
*/
|
|
104
552
|
cleanup?: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<void>;
|
|
553
|
+
/**
|
|
554
|
+
* handleError is called when the run function throws an error. It can be used to modify the error or return new retry options.
|
|
555
|
+
*/
|
|
556
|
+
handleError?: (payload: TPayload, error: unknown, params: HandleErrorFnParams<TInitOutput>) => HandleErrorResult;
|
|
557
|
+
/**
|
|
558
|
+
* middleware allows you to run code "around" the run function. This can be useful for logging, metrics, or other cross-cutting concerns.
|
|
559
|
+
*
|
|
560
|
+
* When writing middleware, you should always call `next()` to continue the execution of the task:
|
|
561
|
+
*
|
|
562
|
+
* ```ts
|
|
563
|
+
* export const middlewareTask = task({
|
|
564
|
+
* id: "middleware-task",
|
|
565
|
+
* middleware: async (payload, { ctx, next }) => {
|
|
566
|
+
* console.log("Before run");
|
|
567
|
+
* await next();
|
|
568
|
+
* console.log("After run");
|
|
569
|
+
* },
|
|
570
|
+
* run: async (payload, { ctx }) => {}
|
|
571
|
+
* });
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
105
574
|
middleware?: (payload: TPayload, params: MiddlewareFnParams) => Promise<void>;
|
|
106
|
-
|
|
575
|
+
/**
|
|
576
|
+
* onStart is called the first time a task is executed in a run (not before every retry)
|
|
577
|
+
*/
|
|
578
|
+
onStart?: (payload: TPayload, params: StartFnParams) => Promise<void>;
|
|
579
|
+
/**
|
|
580
|
+
* onSuccess is called after the run function has successfully completed.
|
|
581
|
+
*/
|
|
582
|
+
onSuccess?: (payload: TPayload, output: TOutput, params: SuccessFnParams<TInitOutput>) => Promise<void>;
|
|
583
|
+
/**
|
|
584
|
+
* onFailure is called after a task run has failed (meaning the run function threw an error and won't be retried anymore)
|
|
585
|
+
*/
|
|
586
|
+
onFailure?: (payload: TPayload, error: unknown, params: FailureFnParams<TInitOutput>) => Promise<void>;
|
|
107
587
|
};
|
|
108
|
-
|
|
109
|
-
|
|
588
|
+
declare const __output: unique symbol;
|
|
589
|
+
type BrandOutput<B> = {
|
|
590
|
+
[__output]: B;
|
|
110
591
|
};
|
|
111
|
-
type
|
|
592
|
+
type BrandedOutput<T, B> = T & BrandOutput<B>;
|
|
593
|
+
type RunHandle<TOutput> = BrandedOutput<{
|
|
594
|
+
id: string;
|
|
595
|
+
}, TOutput>;
|
|
596
|
+
/**
|
|
597
|
+
* A BatchRunHandle can be used to retrieve the runs of a batch trigger in a typesafe manner.
|
|
598
|
+
*/
|
|
599
|
+
type BatchRunHandle<TOutput> = BrandedOutput<{
|
|
112
600
|
batchId: string;
|
|
113
|
-
runs:
|
|
114
|
-
}
|
|
601
|
+
runs: Array<RunHandle<TOutput>>;
|
|
602
|
+
}, TOutput>;
|
|
115
603
|
type TaskRunResult<TOutput = any> = {
|
|
116
604
|
ok: true;
|
|
117
605
|
id: string;
|
|
@@ -119,48 +607,257 @@ type TaskRunResult<TOutput = any> = {
|
|
|
119
607
|
} | {
|
|
120
608
|
ok: false;
|
|
121
609
|
id: string;
|
|
122
|
-
error:
|
|
610
|
+
error: unknown;
|
|
123
611
|
};
|
|
124
612
|
type BatchResult<TOutput = any> = {
|
|
125
613
|
id: string;
|
|
126
614
|
runs: TaskRunResult<TOutput>[];
|
|
127
615
|
};
|
|
128
|
-
type
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
items: {
|
|
135
|
-
payload: TInput;
|
|
136
|
-
options?: TaskRunOptions;
|
|
137
|
-
}[];
|
|
138
|
-
batchOptions?: BatchRunOptions;
|
|
139
|
-
}) => Promise<InvokeBatchHandle>;
|
|
140
|
-
triggerAndWait: (params: {
|
|
141
|
-
payload: TInput;
|
|
142
|
-
options?: TaskRunOptions;
|
|
143
|
-
}) => Promise<TOutput>;
|
|
144
|
-
batchTriggerAndWait: (params: {
|
|
145
|
-
items: {
|
|
146
|
-
payload: TInput;
|
|
147
|
-
options?: TaskRunOptions;
|
|
148
|
-
}[];
|
|
149
|
-
batchOptions?: BatchRunOptions;
|
|
150
|
-
}) => Promise<BatchResult<TOutput>>;
|
|
616
|
+
type BatchItem<TInput> = TInput extends void ? {
|
|
617
|
+
payload?: TInput;
|
|
618
|
+
options?: TaskRunOptions;
|
|
619
|
+
} : {
|
|
620
|
+
payload: TInput;
|
|
621
|
+
options?: TaskRunOptions;
|
|
151
622
|
};
|
|
623
|
+
interface Task<TIdentifier extends string, TInput = void, TOutput = any> {
|
|
624
|
+
/**
|
|
625
|
+
* The id of the task.
|
|
626
|
+
*/
|
|
627
|
+
id: TIdentifier;
|
|
628
|
+
/**
|
|
629
|
+
* Trigger a task with the given payload, and continue without waiting for the result. If you want to wait for the result, use `triggerAndWait`. Returns the id of the triggered task run.
|
|
630
|
+
* @param payload
|
|
631
|
+
* @param options
|
|
632
|
+
* @returns RunHandle
|
|
633
|
+
* - `id` - The id of the triggered task run.
|
|
634
|
+
*/
|
|
635
|
+
trigger: (payload: TInput, options?: TaskRunOptions) => Promise<RunHandle<TOutput>>;
|
|
636
|
+
/**
|
|
637
|
+
* Batch trigger multiple task runs with the given payloads, and continue without waiting for the results. If you want to wait for the results, use `batchTriggerAndWait`. Returns the id of the triggered batch.
|
|
638
|
+
* @param items
|
|
639
|
+
* @returns InvokeBatchHandle
|
|
640
|
+
* - `batchId` - The id of the triggered batch.
|
|
641
|
+
* - `runs` - The ids of the triggered task runs.
|
|
642
|
+
*/
|
|
643
|
+
batchTrigger: (items: Array<BatchItem<TInput>>) => Promise<BatchRunHandle<TOutput>>;
|
|
644
|
+
/**
|
|
645
|
+
* Trigger a task with the given payload, and wait for the result. Returns the result of the task run
|
|
646
|
+
* @param payload
|
|
647
|
+
* @param options - Options for the task run
|
|
648
|
+
* @returns TaskRunResult
|
|
649
|
+
* @example
|
|
650
|
+
* ```
|
|
651
|
+
* const result = await task.triggerAndWait({ foo: "bar" });
|
|
652
|
+
*
|
|
653
|
+
* if (result.ok) {
|
|
654
|
+
* console.log(result.output);
|
|
655
|
+
* } else {
|
|
656
|
+
* console.error(result.error);
|
|
657
|
+
* }
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
triggerAndWait: (payload: TInput, options?: TaskRunOptions) => Promise<TaskRunResult<TOutput>>;
|
|
661
|
+
/**
|
|
662
|
+
* Batch trigger multiple task runs with the given payloads, and wait for the results. Returns the results of the task runs.
|
|
663
|
+
* @param items
|
|
664
|
+
* @returns BatchResult
|
|
665
|
+
* @example
|
|
666
|
+
* ```
|
|
667
|
+
* const result = await task.batchTriggerAndWait([
|
|
668
|
+
* { payload: { foo: "bar" } },
|
|
669
|
+
* { payload: { foo: "baz" } },
|
|
670
|
+
* ]);
|
|
671
|
+
*
|
|
672
|
+
* for (const run of result.runs) {
|
|
673
|
+
* if (run.ok) {
|
|
674
|
+
* console.log(run.output);
|
|
675
|
+
* } else {
|
|
676
|
+
* console.error(run.error);
|
|
677
|
+
* }
|
|
678
|
+
* }
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
batchTriggerAndWait: (items: Array<BatchItem<TInput>>) => Promise<BatchResult<TOutput>>;
|
|
682
|
+
}
|
|
683
|
+
type AnyTask = Task<string, any, any>;
|
|
684
|
+
type TaskPayload<TTask extends AnyTask> = TTask extends Task<string, infer TInput, any> ? TInput : never;
|
|
685
|
+
type TaskOutput<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? TOutput : never;
|
|
686
|
+
type TaskIdentifier<TTask extends AnyTask> = TTask extends Task<infer TIdentifier, any, any> ? TIdentifier : never;
|
|
152
687
|
type TaskRunOptions = {
|
|
153
|
-
|
|
688
|
+
/**
|
|
689
|
+
* A unique key that can be used to ensure that a task is only triggered once per key.
|
|
690
|
+
*
|
|
691
|
+
* You can use `idempotencyKeys.create` to create an idempotency key first, and then pass it to the task options.
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
*
|
|
695
|
+
* ```typescript
|
|
696
|
+
* import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
|
|
697
|
+
*
|
|
698
|
+
* export const myTask = task({
|
|
699
|
+
* id: "my-task",
|
|
700
|
+
* run: async (payload: any) => {
|
|
701
|
+
* // scoped to the task run by default
|
|
702
|
+
* const idempotencyKey = await idempotencyKeys.create("my-task-key");
|
|
703
|
+
*
|
|
704
|
+
* // Use the idempotency key when triggering child tasks
|
|
705
|
+
* await childTask.triggerAndWait(payload, { idempotencyKey });
|
|
706
|
+
*
|
|
707
|
+
* // scoped globally, does not include the task run ID
|
|
708
|
+
* const globalIdempotencyKey = await idempotencyKeys.create("my-task-key", { scope: "global" });
|
|
709
|
+
*
|
|
710
|
+
* await childTask.triggerAndWait(payload, { idempotencyKey: globalIdempotencyKey });
|
|
711
|
+
*
|
|
712
|
+
* // You can also pass a string directly, which is the same as a global idempotency key
|
|
713
|
+
* await childTask.triggerAndWait(payload, { idempotencyKey: "my-very-unique-key" });
|
|
714
|
+
* }
|
|
715
|
+
* });
|
|
716
|
+
* ```
|
|
717
|
+
*
|
|
718
|
+
* When triggering a task inside another task, we automatically inject the run ID into the key material.
|
|
719
|
+
*
|
|
720
|
+
* If you are triggering a task from your backend, ensure you include some sufficiently unique key material to prevent collisions.
|
|
721
|
+
*
|
|
722
|
+
* @example
|
|
723
|
+
*
|
|
724
|
+
* ```typescript
|
|
725
|
+
* import { idempotencyKeys, tasks } from "@trigger.dev/sdk/v3";
|
|
726
|
+
*
|
|
727
|
+
* // Somewhere in your backend
|
|
728
|
+
* const idempotencyKey = await idempotenceKeys.create(["my-task-trigger", "user-123"]);
|
|
729
|
+
* await tasks.trigger("my-task", { foo: "bar" }, { idempotencyKey });
|
|
730
|
+
* ```
|
|
731
|
+
*
|
|
732
|
+
*/
|
|
733
|
+
idempotencyKey?: IdempotencyKey | string | string[];
|
|
154
734
|
maxAttempts?: number;
|
|
155
|
-
startAt?: Date;
|
|
156
|
-
startAfter?: number;
|
|
157
735
|
queue?: TaskRunConcurrencyOptions;
|
|
158
736
|
concurrencyKey?: string;
|
|
737
|
+
/**
|
|
738
|
+
* The delay before the task is executed. This can be a string like "1h" or a Date object.
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
741
|
+
* "1h" - 1 hour
|
|
742
|
+
* "30d" - 30 days
|
|
743
|
+
* "15m" - 15 minutes
|
|
744
|
+
* "2w" - 2 weeks
|
|
745
|
+
* "60s" - 60 seconds
|
|
746
|
+
* new Date("2025-01-01T00:00:00Z")
|
|
747
|
+
*/
|
|
748
|
+
delay?: string | Date;
|
|
749
|
+
/**
|
|
750
|
+
* Set a time-to-live for this run. If the run is not executed within this time, it will be removed from the queue and never execute.
|
|
751
|
+
*
|
|
752
|
+
* @example
|
|
753
|
+
*
|
|
754
|
+
* ```ts
|
|
755
|
+
* await myTask.trigger({ foo: "bar" }, { ttl: "1h" });
|
|
756
|
+
* await myTask.trigger({ foo: "bar" }, { ttl: 60 * 60 }); // 1 hour
|
|
757
|
+
* ```
|
|
758
|
+
*
|
|
759
|
+
* The minimum value is 1 second. Setting the `ttl` to `0` will disable the TTL and the run will never expire.
|
|
760
|
+
*
|
|
761
|
+
* **Note:** Runs in development have a default `ttl` of 10 minutes. You can override this by setting the `ttl` option.
|
|
762
|
+
*/
|
|
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;
|
|
159
778
|
};
|
|
160
779
|
type TaskRunConcurrencyOptions = Queue;
|
|
161
|
-
type
|
|
162
|
-
|
|
163
|
-
};
|
|
780
|
+
type Prettify<T> = {
|
|
781
|
+
[K in keyof T]: T[K];
|
|
782
|
+
} & {};
|
|
783
|
+
/**
|
|
784
|
+
* Trigger a task by its identifier with the given payload. Returns a typesafe `RunHandle`.
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
*
|
|
788
|
+
* ```ts
|
|
789
|
+
* import { tasks, runs } from "@trigger.dev/sdk/v3";
|
|
790
|
+
* import type { myTask } from "./myTasks"; // Import just the type of the task
|
|
791
|
+
*
|
|
792
|
+
* const handle = await tasks.trigger<typeof myTask>("my-task", { foo: "bar" }); // The id and payload are fully typesafe
|
|
793
|
+
* const run = await runs.retrieve(handle);
|
|
794
|
+
* console.log(run.output) // The output is also fully typed
|
|
795
|
+
* ```
|
|
796
|
+
*
|
|
797
|
+
* @returns {RunHandle} An object with the `id` of the run. Can be used to retrieve the completed run output in a typesafe manner.
|
|
798
|
+
*/
|
|
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
|
+
*/
|
|
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>>>;
|
|
844
|
+
/**
|
|
845
|
+
* Trigger a task by its identifier with the given payload and poll until the run is completed.
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
*
|
|
849
|
+
* ```ts
|
|
850
|
+
* import { tasks, runs } from "@trigger.dev/sdk/v3";
|
|
851
|
+
* import type { myTask } from "./myTasks"; // Import just the type of the task
|
|
852
|
+
*
|
|
853
|
+
* const run = await tasks.triggerAndPoll<typeof myTask>("my-task", { foo: "bar" }); // The id and payload are fully typesafe
|
|
854
|
+
* console.log(run.output) // The output is also fully typed
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @returns {Run} The completed run, either successful or failed.
|
|
858
|
+
*/
|
|
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>>>;
|
|
164
861
|
|
|
165
862
|
/** Creates a task that can be triggered
|
|
166
863
|
* @param options - Task options
|
|
@@ -180,7 +877,14 @@ type BatchRunOptions = TaskRunOptions & {
|
|
|
180
877
|
*
|
|
181
878
|
* @returns A task that can be triggered
|
|
182
879
|
*/
|
|
183
|
-
declare function task<TInput, TOutput =
|
|
880
|
+
declare function task$1<TIdentifier extends string, TInput = void, TOutput = unknown, TInitOutput extends InitOutput = any>(options: TaskOptions<TIdentifier, TInput, TOutput, TInitOutput>): Task<TIdentifier, TInput, TOutput>;
|
|
881
|
+
declare const tasks: {
|
|
882
|
+
trigger: typeof trigger;
|
|
883
|
+
triggerAndPoll: typeof triggerAndPoll;
|
|
884
|
+
batchTrigger: typeof batchTrigger;
|
|
885
|
+
triggerAndWait: typeof triggerAndWait;
|
|
886
|
+
batchTriggerAndWait: typeof batchTriggerAndWait;
|
|
887
|
+
};
|
|
184
888
|
|
|
185
889
|
type WaitOptions = {
|
|
186
890
|
seconds: number;
|
|
@@ -205,50 +909,225 @@ declare const wait: {
|
|
|
205
909
|
}) => Promise<void>;
|
|
206
910
|
};
|
|
207
911
|
|
|
208
|
-
type
|
|
209
|
-
|
|
210
|
-
|
|
912
|
+
type ComputeUsage = {
|
|
913
|
+
costInCents: number;
|
|
914
|
+
durationMs: number;
|
|
211
915
|
};
|
|
212
|
-
type
|
|
213
|
-
|
|
214
|
-
|
|
916
|
+
type CurrentUsage = {
|
|
917
|
+
compute: {
|
|
918
|
+
attempt: ComputeUsage;
|
|
919
|
+
total: ComputeUsage;
|
|
920
|
+
};
|
|
921
|
+
baseCostInCents: number;
|
|
922
|
+
totalCostInCents: number;
|
|
215
923
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
924
|
+
declare const usage: {
|
|
925
|
+
/**
|
|
926
|
+
* Get the current running usage of this task run.
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
*
|
|
930
|
+
* ```typescript
|
|
931
|
+
* import { usage, task } from "@trigger.dev/sdk/v3";
|
|
932
|
+
*
|
|
933
|
+
* export const myTask = task({
|
|
934
|
+
* id: "my-task",
|
|
935
|
+
* run: async (payload, { ctx }) => {
|
|
936
|
+
* // ... Do a bunch of work
|
|
937
|
+
*
|
|
938
|
+
* const currentUsage = usage.getCurrent();
|
|
939
|
+
*
|
|
940
|
+
* // You have access to the current compute cost and duration up to this point
|
|
941
|
+
* console.log("Current attempt compute cost and duration", {
|
|
942
|
+
* cost: currentUsage.compute.attempt.costInCents,
|
|
943
|
+
* duration: currentUsage.compute.attempt.durationMs,
|
|
944
|
+
* });
|
|
945
|
+
*
|
|
946
|
+
* // You also can see the total compute cost and duration up to this point in the run, across all attempts
|
|
947
|
+
* console.log("Current total compute cost and duration", {
|
|
948
|
+
* cost: currentUsage.compute.total.costInCents,
|
|
949
|
+
* duration: currentUsage.compute.total.durationMs,
|
|
950
|
+
* });
|
|
951
|
+
*
|
|
952
|
+
* // You can see the base cost of the run, which is the cost of the run before any compute costs
|
|
953
|
+
* console.log("Total cost", {
|
|
954
|
+
* cost: currentUsage.totalCostInCents,
|
|
955
|
+
* baseCost: currentUsage.baseCostInCents,
|
|
956
|
+
* });
|
|
957
|
+
* },
|
|
958
|
+
* });
|
|
959
|
+
* ```
|
|
960
|
+
*/
|
|
961
|
+
getCurrent: () => CurrentUsage;
|
|
962
|
+
/**
|
|
963
|
+
* Measure the cost and duration of a function.
|
|
964
|
+
*
|
|
965
|
+
* @example
|
|
966
|
+
*
|
|
967
|
+
* ```typescript
|
|
968
|
+
* import { usage } from "@trigger.dev/sdk/v3";
|
|
969
|
+
*
|
|
970
|
+
* export const myTask = task({
|
|
971
|
+
* id: "my-task",
|
|
972
|
+
* run: async (payload, { ctx }) => {
|
|
973
|
+
* const { result, compute } = await usage.measure(async () => {
|
|
974
|
+
* // Do some work
|
|
975
|
+
* return "result";
|
|
976
|
+
* });
|
|
977
|
+
*
|
|
978
|
+
* console.log("Result", result);
|
|
979
|
+
* console.log("Cost and duration", { cost: compute.costInCents, duration: compute.durationMs });
|
|
980
|
+
* },
|
|
981
|
+
* });
|
|
982
|
+
* ```
|
|
983
|
+
*/
|
|
984
|
+
measure: <T>(cb: () => Promise<T>) => Promise<{
|
|
985
|
+
result: T;
|
|
986
|
+
compute: ComputeUsage;
|
|
987
|
+
}>;
|
|
222
988
|
};
|
|
223
|
-
|
|
224
|
-
declare
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
989
|
+
|
|
990
|
+
declare const tags: {
|
|
991
|
+
add: typeof addTags;
|
|
992
|
+
};
|
|
993
|
+
declare function addTags(tags: RunTags, requestOptions?: ApiRequestOptions): Promise<void>;
|
|
994
|
+
|
|
995
|
+
type ScheduleOptions<TIdentifier extends string, TOutput, TInitOutput extends InitOutput> = TaskOptions<TIdentifier, ScheduledTaskPayload, TOutput, TInitOutput> & {
|
|
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.
|
|
997
|
+
*
|
|
998
|
+
* 1. Pass a CRON pattern string
|
|
999
|
+
* ```ts
|
|
1000
|
+
* "0 0 * * *"
|
|
1001
|
+
* ```
|
|
1002
|
+
*
|
|
1003
|
+
* 2. Or an object with a pattern and an optional timezone (default is "UTC")
|
|
1004
|
+
* ```ts
|
|
1005
|
+
* {
|
|
1006
|
+
* pattern: "0 0 * * *",
|
|
1007
|
+
* timezone: "America/Los_Angeles"
|
|
1008
|
+
* }
|
|
1009
|
+
* ```
|
|
1010
|
+
*
|
|
1011
|
+
* @link https://trigger.dev/docs/v3/tasks-scheduled
|
|
1012
|
+
*/
|
|
1013
|
+
cron?: string | {
|
|
1014
|
+
pattern: string;
|
|
1015
|
+
timezone?: string;
|
|
1016
|
+
};
|
|
1017
|
+
};
|
|
1018
|
+
declare function task<TIdentifier extends string, TOutput, TInitOutput extends InitOutput>(params: ScheduleOptions<TIdentifier, TOutput, TInitOutput>): Task<TIdentifier, ScheduledTaskPayload, TOutput>;
|
|
230
1019
|
/**
|
|
231
|
-
*
|
|
232
|
-
* @param
|
|
233
|
-
* @
|
|
1020
|
+
* Creates a new schedule
|
|
1021
|
+
* @param options
|
|
1022
|
+
* @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
|
|
1023
|
+
* @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
|
|
1024
|
+
* @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
|
|
1025
|
+
* @param options.externalId - An optional external identifier for the schedule
|
|
1026
|
+
* @param options.deduplicationKey - An optional deduplication key for the schedule
|
|
1027
|
+
* @returns The created schedule
|
|
234
1028
|
*/
|
|
235
|
-
declare function
|
|
1029
|
+
declare function create$1(options: CreateScheduleOptions, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Retrieves a schedule
|
|
1032
|
+
* @param scheduleId - The ID of the schedule to retrieve
|
|
1033
|
+
* @returns The retrieved schedule
|
|
1034
|
+
*/
|
|
1035
|
+
declare function retrieve$1(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
|
|
1036
|
+
/**
|
|
1037
|
+
* Updates a schedule
|
|
1038
|
+
* @param scheduleId - The ID of the schedule to update
|
|
1039
|
+
* @param options - The updated schedule options
|
|
1040
|
+
* @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
|
|
1041
|
+
* @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
|
|
1042
|
+
* @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
|
|
1043
|
+
* @param options.externalId - An optional external identifier for the schedule
|
|
1044
|
+
* @returns The updated schedule
|
|
1045
|
+
*/
|
|
1046
|
+
declare function update$1(scheduleId: string, options: UpdateScheduleOptions, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Deletes a schedule
|
|
1049
|
+
* @param scheduleId - The ID of the schedule to delete
|
|
1050
|
+
*/
|
|
1051
|
+
declare function del$1(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<DeletedScheduleObject>;
|
|
1052
|
+
/**
|
|
1053
|
+
* Deactivates a schedule
|
|
1054
|
+
* @param scheduleId - The ID of the schedule to deactivate
|
|
1055
|
+
*/
|
|
1056
|
+
declare function deactivate(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
|
|
1057
|
+
/**
|
|
1058
|
+
* Activates a schedule
|
|
1059
|
+
* @param scheduleId - The ID of the schedule to activate
|
|
1060
|
+
*/
|
|
1061
|
+
declare function activate(scheduleId: string, requestOptions?: ApiRequestOptions): ApiPromise<ScheduleObject>;
|
|
1062
|
+
/**
|
|
1063
|
+
* Lists schedules
|
|
1064
|
+
* @param options - The list options
|
|
1065
|
+
* @param options.page - The page number
|
|
1066
|
+
* @param options.perPage - The number of schedules per page
|
|
1067
|
+
* @returns The list of schedules
|
|
1068
|
+
*/
|
|
1069
|
+
declare function list$1(options?: ListScheduleOptions, requestOptions?: ApiRequestOptions): OffsetLimitPagePromise<typeof ScheduleObject>;
|
|
1070
|
+
/**
|
|
1071
|
+
* Lists the possible timezones we support
|
|
1072
|
+
* @param excludeUtc - By default "UTC" is included and is first. If true, "UTC" will be excluded.
|
|
1073
|
+
*/
|
|
1074
|
+
declare function timezones(options?: {
|
|
1075
|
+
excludeUtc?: boolean;
|
|
1076
|
+
}): ApiPromise<{
|
|
1077
|
+
timezones: string[];
|
|
1078
|
+
}>;
|
|
236
1079
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
1080
|
+
type index_ScheduleOptions<TIdentifier extends string, TOutput, TInitOutput extends InitOutput> = ScheduleOptions<TIdentifier, TOutput, TInitOutput>;
|
|
1081
|
+
declare const index_activate: typeof activate;
|
|
1082
|
+
declare const index_deactivate: typeof deactivate;
|
|
1083
|
+
declare const index_task: typeof task;
|
|
1084
|
+
declare const index_timezones: typeof timezones;
|
|
1085
|
+
declare namespace index {
|
|
1086
|
+
export { type index_ScheduleOptions as ScheduleOptions, 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 };
|
|
244
1087
|
}
|
|
245
|
-
declare function retryFetch(input: RequestInfo | URL, init?: RetryFetchRequestInit | undefined): Promise<Response>;
|
|
246
|
-
declare const retry: {
|
|
247
|
-
onThrow: typeof onThrow;
|
|
248
|
-
fetch: typeof retryFetch;
|
|
249
|
-
interceptFetch: (...handlers: Array<HttpHandler>) => {
|
|
250
|
-
run: <T>(fn: (...args: any[]) => Promise<T>) => Promise<T>;
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
1088
|
|
|
254
|
-
|
|
1089
|
+
declare function upload(projectRef: string, slug: string, params: ImportEnvironmentVariablesParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
|
|
1090
|
+
declare function upload(params: ImportEnvironmentVariablesParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
|
|
1091
|
+
declare function list(projectRef: string, slug: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariables>;
|
|
1092
|
+
declare function list(requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariables>;
|
|
1093
|
+
declare function create(projectRef: string, slug: string, params: CreateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
|
|
1094
|
+
declare function create(params: CreateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
|
|
1095
|
+
declare function retrieve(projectRef: string, slug: string, name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableValue>;
|
|
1096
|
+
declare function retrieve(name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableValue>;
|
|
1097
|
+
declare function del(projectRef: string, slug: string, name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
|
|
1098
|
+
declare function del(name: string, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
|
|
1099
|
+
declare function update(projectRef: string, slug: string, name: string, params: UpdateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
|
|
1100
|
+
declare function update(name: string, params: UpdateEnvironmentVariableParams, requestOptions?: ApiRequestOptions): ApiPromise<EnvironmentVariableResponseBody>;
|
|
1101
|
+
|
|
1102
|
+
declare const envvars_CreateEnvironmentVariableParams: typeof CreateEnvironmentVariableParams;
|
|
1103
|
+
declare const envvars_ImportEnvironmentVariablesParams: typeof ImportEnvironmentVariablesParams;
|
|
1104
|
+
declare const envvars_create: typeof create;
|
|
1105
|
+
declare const envvars_del: typeof del;
|
|
1106
|
+
declare const envvars_list: typeof list;
|
|
1107
|
+
declare const envvars_retrieve: typeof retrieve;
|
|
1108
|
+
declare const envvars_update: typeof update;
|
|
1109
|
+
declare const envvars_upload: typeof upload;
|
|
1110
|
+
declare namespace envvars {
|
|
1111
|
+
export { envvars_CreateEnvironmentVariableParams as CreateEnvironmentVariableParams, envvars_ImportEnvironmentVariablesParams as ImportEnvironmentVariablesParams, envvars_create as create, envvars_del as del, envvars_list as list, envvars_retrieve as retrieve, envvars_update as update, envvars_upload as upload };
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* Register the global API client configuration. Alternatively, you can set the `TRIGGER_SECRET_KEY` and `TRIGGER_API_URL` environment variables.
|
|
1116
|
+
* @param options The API client configuration.
|
|
1117
|
+
* @param options.baseURL The base URL of the Trigger API. (default: `https://api.trigger.dev`)
|
|
1118
|
+
* @param options.secretKey The secret key to authenticate with the Trigger API. (default: `process.env.TRIGGER_SECRET_KEY`) This can be found in your Trigger.dev project "API Keys" settings.
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
*
|
|
1122
|
+
* ```typescript
|
|
1123
|
+
* import { configure } from "@trigger.dev/sdk/v3";
|
|
1124
|
+
*
|
|
1125
|
+
* configure({
|
|
1126
|
+
* baseURL: "https://api.trigger.dev",
|
|
1127
|
+
* secretKey: "tr_dev_1234567890"
|
|
1128
|
+
* });
|
|
1129
|
+
* ```
|
|
1130
|
+
*/
|
|
1131
|
+
declare function configure(options: ApiClientConfiguration): void;
|
|
1132
|
+
|
|
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 };
|