@trigger.dev/sdk 3.3.17 → 4.0.0-v4-beta.0
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/commonjs/v3/ai.d.ts +23 -0
- package/dist/commonjs/v3/ai.js +50 -0
- package/dist/commonjs/v3/ai.js.map +1 -0
- package/dist/commonjs/v3/auth.d.ts +4 -3
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/hooks.d.ts +22 -0
- package/dist/commonjs/v3/hooks.js +65 -0
- package/dist/commonjs/v3/hooks.js.map +1 -0
- package/dist/commonjs/v3/index.d.ts +3 -1
- package/dist/commonjs/v3/index.js +4 -1
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/locals.d.ts +3 -0
- package/dist/commonjs/v3/locals.js +6 -0
- package/dist/commonjs/v3/locals.js.map +1 -0
- package/dist/commonjs/v3/queues.d.ts +61 -0
- package/dist/commonjs/v3/queues.js +137 -0
- package/dist/commonjs/v3/queues.js.map +1 -0
- package/dist/commonjs/v3/retry.js +10 -7
- package/dist/commonjs/v3/retry.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +40 -40
- package/dist/commonjs/v3/schedules/index.js +1 -1
- package/dist/commonjs/v3/schedules/index.js.map +1 -1
- package/dist/commonjs/v3/shared.d.ts +7 -6
- package/dist/commonjs/v3/shared.js +188 -176
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/tasks.d.ts +12 -0
- package/dist/commonjs/v3/tasks.js +11 -0
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/wait.d.ts +208 -3
- package/dist/commonjs/v3/wait.js +407 -7
- package/dist/commonjs/v3/wait.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +23 -0
- package/dist/esm/v3/ai.js +47 -0
- package/dist/esm/v3/ai.js.map +1 -0
- package/dist/esm/v3/auth.d.ts +4 -3
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/hooks.d.ts +22 -0
- package/dist/esm/v3/hooks.js +54 -0
- package/dist/esm/v3/hooks.js.map +1 -0
- package/dist/esm/v3/index.d.ts +3 -1
- package/dist/esm/v3/index.js +3 -1
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/locals.d.ts +3 -0
- package/dist/esm/v3/locals.js +3 -0
- package/dist/esm/v3/locals.js.map +1 -0
- package/dist/esm/v3/queues.d.ts +61 -0
- package/dist/esm/v3/queues.js +131 -0
- package/dist/esm/v3/queues.js.map +1 -0
- package/dist/esm/v3/retry.js +11 -8
- package/dist/esm/v3/retry.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +39 -39
- package/dist/esm/v3/schedules/index.js +2 -2
- package/dist/esm/v3/schedules/index.js.map +1 -1
- package/dist/esm/v3/shared.d.ts +7 -6
- package/dist/esm/v3/shared.js +189 -177
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/tasks.d.ts +12 -0
- package/dist/esm/v3/tasks.js +11 -0
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/wait.d.ts +208 -3
- package/dist/esm/v3/wait.js +406 -7
- package/dist/esm/v3/wait.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +36 -17
- package/dist/commonjs/apiClient.d.ts +0 -727
- package/dist/commonjs/apiClient.js +0 -692
- package/dist/commonjs/apiClient.js.map +0 -1
- package/dist/commonjs/concurrencyLimit.d.ts +0 -10
- package/dist/commonjs/concurrencyLimit.js +0 -17
- package/dist/commonjs/concurrencyLimit.js.map +0 -1
- package/dist/commonjs/errors.d.ts +0 -66
- package/dist/commonjs/errors.js +0 -109
- package/dist/commonjs/errors.js.map +0 -1
- package/dist/commonjs/httpEndpoint.d.ts +0 -87
- package/dist/commonjs/httpEndpoint.js +0 -130
- package/dist/commonjs/httpEndpoint.js.map +0 -1
- package/dist/commonjs/index.d.ts +0 -23
- package/dist/commonjs/index.js +0 -55
- package/dist/commonjs/index.js.map +0 -1
- package/dist/commonjs/integrations.d.ts +0 -11
- package/dist/commonjs/integrations.js +0 -3
- package/dist/commonjs/integrations.js.map +0 -1
- package/dist/commonjs/io.d.ts +0 -441
- package/dist/commonjs/io.js +0 -1165
- package/dist/commonjs/io.js.map +0 -1
- package/dist/commonjs/ioWithIntegrations.d.ts +0 -4
- package/dist/commonjs/ioWithIntegrations.js +0 -32
- package/dist/commonjs/ioWithIntegrations.js.map +0 -1
- package/dist/commonjs/job.d.ts +0 -96
- package/dist/commonjs/job.js +0 -210
- package/dist/commonjs/job.js.map +0 -1
- package/dist/commonjs/retry.d.ts +0 -20
- package/dist/commonjs/retry.js +0 -22
- package/dist/commonjs/retry.js.map +0 -1
- package/dist/commonjs/runLocalStorage.d.ts +0 -8
- package/dist/commonjs/runLocalStorage.js +0 -6
- package/dist/commonjs/runLocalStorage.js.map +0 -1
- package/dist/commonjs/security.d.ts +0 -18
- package/dist/commonjs/security.js +0 -41
- package/dist/commonjs/security.js.map +0 -1
- package/dist/commonjs/status.d.ts +0 -19
- package/dist/commonjs/status.js +0 -38
- package/dist/commonjs/status.js.map +0 -1
- package/dist/commonjs/store/keyValueStore.d.ts +0 -17
- package/dist/commonjs/store/keyValueStore.js +0 -138
- package/dist/commonjs/store/keyValueStore.js.map +0 -1
- package/dist/commonjs/store/keyValueStoreClient.d.ts +0 -19
- package/dist/commonjs/store/keyValueStoreClient.js +0 -65
- package/dist/commonjs/store/keyValueStoreClient.js.map +0 -1
- package/dist/commonjs/triggerClient.d.ts +0 -290
- package/dist/commonjs/triggerClient.js +0 -1366
- package/dist/commonjs/triggerClient.js.map +0 -1
- package/dist/commonjs/triggers/dynamic.d.ts +0 -56
- package/dist/commonjs/triggers/dynamic.js +0 -97
- package/dist/commonjs/triggers/dynamic.js.map +0 -1
- package/dist/commonjs/triggers/eventTrigger.d.ts +0 -58
- package/dist/commonjs/triggers/eventTrigger.js +0 -69
- package/dist/commonjs/triggers/eventTrigger.js.map +0 -1
- package/dist/commonjs/triggers/externalSource.d.ts +0 -148
- package/dist/commonjs/triggers/externalSource.js +0 -106
- package/dist/commonjs/triggers/externalSource.js.map +0 -1
- package/dist/commonjs/triggers/invokeTrigger.d.ts +0 -39
- package/dist/commonjs/triggers/invokeTrigger.js +0 -58
- package/dist/commonjs/triggers/invokeTrigger.js.map +0 -1
- package/dist/commonjs/triggers/notifications.d.ts +0 -111
- package/dist/commonjs/triggers/notifications.js +0 -101
- package/dist/commonjs/triggers/notifications.js.map +0 -1
- package/dist/commonjs/triggers/scheduled.d.ts +0 -145
- package/dist/commonjs/triggers/scheduled.js +0 -208
- package/dist/commonjs/triggers/scheduled.js.map +0 -1
- package/dist/commonjs/triggers/webhook.d.ts +0 -143
- package/dist/commonjs/triggers/webhook.js +0 -133
- package/dist/commonjs/triggers/webhook.js.map +0 -1
- package/dist/commonjs/typed-emitter.d.ts +0 -37
- package/dist/commonjs/typed-emitter.js +0 -3
- package/dist/commonjs/typed-emitter.js.map +0 -1
- package/dist/commonjs/types.d.ts +0 -204
- package/dist/commonjs/types.js +0 -23
- package/dist/commonjs/types.js.map +0 -1
- package/dist/commonjs/utils/formatSchemaErrors.d.ts +0 -3
- package/dist/commonjs/utils/formatSchemaErrors.js +0 -10
- package/dist/commonjs/utils/formatSchemaErrors.js.map +0 -1
- package/dist/commonjs/utils/typedAsyncLocalStorage.d.ts +0 -6
- package/dist/commonjs/utils/typedAsyncLocalStorage.js +0 -18
- package/dist/commonjs/utils/typedAsyncLocalStorage.js.map +0 -1
- package/dist/commonjs/utils.d.ts +0 -1
- package/dist/commonjs/utils.js +0 -11
- package/dist/commonjs/utils.js.map +0 -1
- package/dist/esm/apiClient.d.ts +0 -727
- package/dist/esm/apiClient.js +0 -687
- package/dist/esm/apiClient.js.map +0 -1
- package/dist/esm/concurrencyLimit.d.ts +0 -10
- package/dist/esm/concurrencyLimit.js +0 -13
- package/dist/esm/concurrencyLimit.js.map +0 -1
- package/dist/esm/errors.d.ts +0 -66
- package/dist/esm/errors.js +0 -95
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/httpEndpoint.d.ts +0 -87
- package/dist/esm/httpEndpoint.js +0 -125
- package/dist/esm/httpEndpoint.js.map +0 -1
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/index.js +0 -35
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/integrations.d.ts +0 -11
- package/dist/esm/integrations.js +0 -2
- package/dist/esm/integrations.js.map +0 -1
- package/dist/esm/io.d.ts +0 -441
- package/dist/esm/io.js +0 -1159
- package/dist/esm/io.js.map +0 -1
- package/dist/esm/ioWithIntegrations.d.ts +0 -4
- package/dist/esm/ioWithIntegrations.js +0 -29
- package/dist/esm/ioWithIntegrations.js.map +0 -1
- package/dist/esm/job.d.ts +0 -96
- package/dist/esm/job.js +0 -206
- package/dist/esm/job.js.map +0 -1
- package/dist/esm/retry.d.ts +0 -20
- package/dist/esm/retry.js +0 -19
- package/dist/esm/retry.js.map +0 -1
- package/dist/esm/runLocalStorage.d.ts +0 -8
- package/dist/esm/runLocalStorage.js +0 -3
- package/dist/esm/runLocalStorage.js.map +0 -1
- package/dist/esm/security.d.ts +0 -18
- package/dist/esm/security.js +0 -34
- package/dist/esm/security.js.map +0 -1
- package/dist/esm/status.d.ts +0 -19
- package/dist/esm/status.js +0 -34
- package/dist/esm/status.js.map +0 -1
- package/dist/esm/store/keyValueStore.d.ts +0 -17
- package/dist/esm/store/keyValueStore.js +0 -134
- package/dist/esm/store/keyValueStore.js.map +0 -1
- package/dist/esm/store/keyValueStoreClient.d.ts +0 -19
- package/dist/esm/store/keyValueStoreClient.js +0 -61
- package/dist/esm/store/keyValueStoreClient.js.map +0 -1
- package/dist/esm/triggerClient.d.ts +0 -288
- package/dist/esm/triggerClient.js +0 -1359
- package/dist/esm/triggerClient.js.map +0 -1
- package/dist/esm/triggers/dynamic.d.ts +0 -56
- package/dist/esm/triggers/dynamic.js +0 -93
- package/dist/esm/triggers/dynamic.js.map +0 -1
- package/dist/esm/triggers/eventTrigger.d.ts +0 -58
- package/dist/esm/triggers/eventTrigger.js +0 -64
- package/dist/esm/triggers/eventTrigger.js.map +0 -1
- package/dist/esm/triggers/externalSource.d.ts +0 -148
- package/dist/esm/triggers/externalSource.js +0 -100
- package/dist/esm/triggers/externalSource.js.map +0 -1
- package/dist/esm/triggers/invokeTrigger.d.ts +0 -39
- package/dist/esm/triggers/invokeTrigger.js +0 -53
- package/dist/esm/triggers/invokeTrigger.js.map +0 -1
- package/dist/esm/triggers/notifications.d.ts +0 -111
- package/dist/esm/triggers/notifications.js +0 -94
- package/dist/esm/triggers/notifications.js.map +0 -1
- package/dist/esm/triggers/scheduled.d.ts +0 -145
- package/dist/esm/triggers/scheduled.js +0 -197
- package/dist/esm/triggers/scheduled.js.map +0 -1
- package/dist/esm/triggers/webhook.d.ts +0 -143
- package/dist/esm/triggers/webhook.js +0 -128
- package/dist/esm/triggers/webhook.js.map +0 -1
- package/dist/esm/typed-emitter.d.ts +0 -37
- package/dist/esm/typed-emitter.js +0 -2
- package/dist/esm/typed-emitter.js.map +0 -1
- package/dist/esm/types.d.ts +0 -204
- package/dist/esm/types.js +0 -19
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils/formatSchemaErrors.d.ts +0 -3
- package/dist/esm/utils/formatSchemaErrors.js +0 -7
- package/dist/esm/utils/formatSchemaErrors.js.map +0 -1
- package/dist/esm/utils/typedAsyncLocalStorage.d.ts +0 -6
- package/dist/esm/utils/typedAsyncLocalStorage.js +0 -14
- package/dist/esm/utils/typedAsyncLocalStorage.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -1
- package/dist/esm/utils.js +0 -8
- package/dist/esm/utils.js.map +0 -1
package/dist/commonjs/io.d.ts
DELETED
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
import { CachedTask, ConnectionAuth, CronOptions, EventFilter, FetchPollOperation, FetchRequestInit, FetchRetryOptions, FetchTimeoutOptions, InitialStatusUpdate, IntervalOptions, RunTaskOptions, SendEvent, SendEventOptions, ServerTask, UpdateTriggerSourceBodyV2, UpdateWebhookBody } from "@trigger.dev/core";
|
|
2
|
-
import { LogLevel, Logger } from "@trigger.dev/core/logger";
|
|
3
|
-
import { ApiClient } from "./apiClient.js";
|
|
4
|
-
import { IntegrationTaskKey } from "./integrations.js";
|
|
5
|
-
import { TriggerStatus } from "./status.js";
|
|
6
|
-
import { TriggerClient } from "./triggerClient.js";
|
|
7
|
-
import { DynamicTrigger } from "./triggers/dynamic.js";
|
|
8
|
-
import { ExternalSource, ExternalSourceParams } from "./triggers/externalSource.js";
|
|
9
|
-
import { DynamicSchedule } from "./triggers/scheduled.js";
|
|
10
|
-
import { EventSpecification, TaskLogger, TriggerContext, WaitForEventResult } from "./types.js";
|
|
11
|
-
import { z } from "zod";
|
|
12
|
-
import { KeyValueStore } from "./store/keyValueStore.js";
|
|
13
|
-
export type IOTask = ServerTask;
|
|
14
|
-
export type IOOptions = {
|
|
15
|
-
id: string;
|
|
16
|
-
jobId: string;
|
|
17
|
-
apiClient: ApiClient;
|
|
18
|
-
client: TriggerClient;
|
|
19
|
-
context: TriggerContext;
|
|
20
|
-
timeOrigin: number;
|
|
21
|
-
logger?: Logger;
|
|
22
|
-
logLevel?: LogLevel;
|
|
23
|
-
jobLogger?: Logger;
|
|
24
|
-
jobLogLevel: LogLevel;
|
|
25
|
-
cachedTasks?: Array<CachedTask>;
|
|
26
|
-
cachedTasksCursor?: string;
|
|
27
|
-
yieldedExecutions?: Array<string>;
|
|
28
|
-
noopTasksSet?: string;
|
|
29
|
-
serverVersion?: string | null;
|
|
30
|
-
executionTimeout?: number;
|
|
31
|
-
};
|
|
32
|
-
type JsonPrimitive = string | number | boolean | null | undefined | Date | symbol;
|
|
33
|
-
type JsonArray = Json[];
|
|
34
|
-
type JsonRecord<T> = {
|
|
35
|
-
[Property in keyof T]: Json;
|
|
36
|
-
};
|
|
37
|
-
export type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
|
|
38
|
-
export type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
|
|
39
|
-
retryAt?: Date;
|
|
40
|
-
error?: Error;
|
|
41
|
-
jitter?: number;
|
|
42
|
-
skipRetrying?: boolean;
|
|
43
|
-
} | Error | undefined | void;
|
|
44
|
-
export type IOStats = {
|
|
45
|
-
initialCachedTasks: number;
|
|
46
|
-
lazyLoadedCachedTasks: number;
|
|
47
|
-
executedTasks: number;
|
|
48
|
-
cachedTaskHits: number;
|
|
49
|
-
cachedTaskMisses: number;
|
|
50
|
-
noopCachedTaskHits: number;
|
|
51
|
-
noopCachedTaskMisses: number;
|
|
52
|
-
};
|
|
53
|
-
export interface OutputSerializer {
|
|
54
|
-
serialize(value: any): string;
|
|
55
|
-
deserialize<T>(value: string): T;
|
|
56
|
-
}
|
|
57
|
-
export declare class JSONOutputSerializer implements OutputSerializer {
|
|
58
|
-
serialize(value: any): string;
|
|
59
|
-
deserialize(value?: string): any;
|
|
60
|
-
}
|
|
61
|
-
export type BackgroundFetchResponse<T> = {
|
|
62
|
-
status: number;
|
|
63
|
-
data: T;
|
|
64
|
-
headers: Record<string, string>;
|
|
65
|
-
};
|
|
66
|
-
export declare class IO {
|
|
67
|
-
#private;
|
|
68
|
-
private _id;
|
|
69
|
-
private _jobId;
|
|
70
|
-
private _apiClient;
|
|
71
|
-
private _triggerClient;
|
|
72
|
-
private _logger;
|
|
73
|
-
private _jobLogger?;
|
|
74
|
-
private _jobLogLevel;
|
|
75
|
-
private _cachedTasks;
|
|
76
|
-
private _taskStorage;
|
|
77
|
-
private _cachedTasksCursor?;
|
|
78
|
-
private _context;
|
|
79
|
-
private _yieldedExecutions;
|
|
80
|
-
private _noopTasksBloomFilter;
|
|
81
|
-
private _stats;
|
|
82
|
-
private _serverVersion;
|
|
83
|
-
private _timeOrigin;
|
|
84
|
-
private _executionTimeout?;
|
|
85
|
-
private _outputSerializer;
|
|
86
|
-
private _visitedCacheKeys;
|
|
87
|
-
private _envStore;
|
|
88
|
-
private _jobStore;
|
|
89
|
-
private _runStore;
|
|
90
|
-
get stats(): IOStats;
|
|
91
|
-
constructor(options: IOOptions);
|
|
92
|
-
/** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
|
|
93
|
-
get logger(): IOLogger;
|
|
94
|
-
/** `io.random()` is identical to `Math.random()` when called without options but ensures your random numbers are not regenerated on resume or retry. It will return a pseudo-random floating-point number between optional `min` (default: 0, inclusive) and `max` (default: 1, exclusive). Can optionally `round` to the nearest integer.
|
|
95
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
96
|
-
* @param min Sets the lower bound (inclusive). Can't be higher than `max`.
|
|
97
|
-
* @param max Sets the upper bound (exclusive). Can't be lower than `min`.
|
|
98
|
-
* @param round Controls rounding to the nearest integer. Any `max` integer will become inclusive when enabled. Rounding with floating-point bounds may cause unexpected skew and boundary inclusivity.
|
|
99
|
-
*/
|
|
100
|
-
random(cacheKey: string | any[], { min, max, round, }?: {
|
|
101
|
-
min?: number;
|
|
102
|
-
max?: number;
|
|
103
|
-
round?: boolean;
|
|
104
|
-
}): Promise<number>;
|
|
105
|
-
/** `io.wait()` waits for the specified amount of time before continuing the Job. Delays work even if you're on a serverless platform with timeouts, or if your server goes down. They utilize [resumability](https://trigger.dev/docs/documentation/concepts/resumability) to ensure that the Run can be resumed after the delay.
|
|
106
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
107
|
-
* @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
|
|
108
|
-
*/
|
|
109
|
-
wait(cacheKey: string | any[], seconds: number): Promise<void>;
|
|
110
|
-
waitForEvent<T extends z.ZodTypeAny = z.ZodTypeAny>(cacheKey: string | any[], event: {
|
|
111
|
-
name: string;
|
|
112
|
-
schema?: T;
|
|
113
|
-
filter?: EventFilter;
|
|
114
|
-
source?: string;
|
|
115
|
-
contextFilter?: EventFilter;
|
|
116
|
-
accountId?: string;
|
|
117
|
-
}, options?: {
|
|
118
|
-
timeoutInSeconds?: number;
|
|
119
|
-
}): Promise<WaitForEventResult<z.output<T>>>;
|
|
120
|
-
/** `io.waitForRequest()` allows you to pause the execution of a run until the url provided in the callback is POSTed to.
|
|
121
|
-
* This is useful for integrating with external services that require a callback URL to be provided, or if you want to be able to wait until an action is performed somewhere else in your system.
|
|
122
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
123
|
-
* @param callback A callback function that will provide the unique URL to POST to.
|
|
124
|
-
* @param options Options for the callback.
|
|
125
|
-
* @param options.timeoutInSeconds How long to wait for the request to be POSTed to the callback URL before timing out. Defaults to 1hr.
|
|
126
|
-
* @returns The POSTed request JSON body.
|
|
127
|
-
* @example
|
|
128
|
-
* ```ts
|
|
129
|
-
const result = await io.waitForRequest<{ message: string }>(
|
|
130
|
-
"wait-for-request",
|
|
131
|
-
async (url, task) => {
|
|
132
|
-
// Save the URL somewhere so you can POST to it later
|
|
133
|
-
// Or send it to an external service that will POST to it
|
|
134
|
-
},
|
|
135
|
-
{ timeoutInSeconds: 60 } // wait 60 seconds
|
|
136
|
-
);
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
waitForRequest<T extends Json<T> | unknown = unknown>(cacheKey: string | any[], callback: (url: string) => Promise<unknown>, options?: {
|
|
140
|
-
timeoutInSeconds?: number;
|
|
141
|
-
}): Promise<T>;
|
|
142
|
-
/** `io.createStatus()` allows you to set a status with associated data during the Run. Statuses can be used by your UI using the react package
|
|
143
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
144
|
-
* @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
|
|
145
|
-
* @returns a TriggerStatus object that you can call `update()` on, to update the status.
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* client.defineJob(
|
|
149
|
-
//...
|
|
150
|
-
run: async (payload, io, ctx) => {
|
|
151
|
-
const generatingImages = await io.createStatus("generating-images", {
|
|
152
|
-
label: "Generating Images",
|
|
153
|
-
state: "loading",
|
|
154
|
-
data: {
|
|
155
|
-
progress: 0.1,
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
//...do stuff
|
|
160
|
-
|
|
161
|
-
await generatingImages.update("completed-generation", {
|
|
162
|
-
label: "Generated images",
|
|
163
|
-
state: "success",
|
|
164
|
-
data: {
|
|
165
|
-
progress: 1.0,
|
|
166
|
-
urls: ["http://..."]
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
//...
|
|
171
|
-
});
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
createStatus(cacheKey: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
|
|
175
|
-
/** `io.backgroundFetch()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
|
|
176
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
177
|
-
* @param url The URL to fetch from.
|
|
178
|
-
* @param requestInit The options for the request
|
|
179
|
-
* @param retry The options for retrying the request if it fails
|
|
180
|
-
* An object where the key is a status code pattern and the value is a retrying strategy.
|
|
181
|
-
* Supported patterns are:
|
|
182
|
-
* - Specific status codes: 429
|
|
183
|
-
* - Ranges: 500-599
|
|
184
|
-
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
185
|
-
*/
|
|
186
|
-
backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, options?: {
|
|
187
|
-
retry?: FetchRetryOptions;
|
|
188
|
-
timeout?: FetchTimeoutOptions;
|
|
189
|
-
}): Promise<TResponseData>;
|
|
190
|
-
/** `io.backgroundPoll()` will fetch data from a URL on an interval. The actual `fetch` requests are performed on the Trigger.dev server, so you don't have to worry about serverless function timeouts.
|
|
191
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
192
|
-
* @param params The options for the background poll
|
|
193
|
-
* @param params.url The URL to fetch from.
|
|
194
|
-
* @param params.requestInit The options for the request, like headers and method
|
|
195
|
-
* @param params.responseFilter An [EventFilter](https://trigger.dev/docs/documentation/guides/event-filter) that allows you to specify when to stop polling.
|
|
196
|
-
* @param params.interval The interval in seconds to poll the URL in seconds. Defaults to 10 seconds which is the minimum.
|
|
197
|
-
* @param params.timeout The timeout in seconds for each request in seconds. Defaults to 10 minutes. Minimum is 60 seconds and max is 1 hour
|
|
198
|
-
* @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
|
|
199
|
-
* @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
|
|
200
|
-
* @param params.requestTimeout.durationInMs The duration in milliseconds to timeout the request
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```ts
|
|
204
|
-
* const result = await io.backgroundPoll<{ id: string; status: string; }>("poll", {
|
|
205
|
-
url: `http://localhost:3030/api/v1/runs/${run.id}`,
|
|
206
|
-
requestInit: {
|
|
207
|
-
headers: {
|
|
208
|
-
Accept: "application/json",
|
|
209
|
-
Authorization: redactString`Bearer ${process.env["TRIGGER_API_KEY"]!}`,
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
interval: 10,
|
|
213
|
-
timeout: 600,
|
|
214
|
-
responseFilter: {
|
|
215
|
-
status: [200],
|
|
216
|
-
body: {
|
|
217
|
-
status: ["SUCCESS"],
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
backgroundPoll<TResponseData>(cacheKey: string | any[], params: FetchPollOperation): Promise<TResponseData>;
|
|
224
|
-
/** `io.backgroundFetchResponse()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
|
|
225
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
226
|
-
* @param url The URL to fetch from.
|
|
227
|
-
* @param requestInit The options for the request
|
|
228
|
-
* @param retry The options for retrying the request if it fails
|
|
229
|
-
* An object where the key is a status code pattern and the value is a retrying strategy.
|
|
230
|
-
* Supported patterns are:
|
|
231
|
-
* - Specific status codes: 429
|
|
232
|
-
* - Ranges: 500-599
|
|
233
|
-
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
234
|
-
*/
|
|
235
|
-
backgroundFetchResponse<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, options?: {
|
|
236
|
-
retry?: FetchRetryOptions;
|
|
237
|
-
timeout?: FetchTimeoutOptions;
|
|
238
|
-
}): Promise<BackgroundFetchResponse<TResponseData>>;
|
|
239
|
-
/** `io.sendEvent()` allows you to send an event from inside a Job run. The sent event will trigger any Jobs that are listening for that event (based on the name).
|
|
240
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
241
|
-
* @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
|
|
242
|
-
* @param options Options for sending the event.
|
|
243
|
-
*/
|
|
244
|
-
sendEvent(cacheKey: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
|
|
245
|
-
payload: import("@trigger.dev/core").DeserializedJson;
|
|
246
|
-
name: string;
|
|
247
|
-
id: string;
|
|
248
|
-
timestamp: Date;
|
|
249
|
-
context?: import("@trigger.dev/core").DeserializedJson | undefined;
|
|
250
|
-
deliverAt?: Date | null | undefined;
|
|
251
|
-
deliveredAt?: Date | null | undefined;
|
|
252
|
-
cancelledAt?: Date | null | undefined;
|
|
253
|
-
}>;
|
|
254
|
-
/** `io.sendEvents()` allows you to send multiple events from inside a Job run. The sent events will trigger any Jobs that are listening for those events (based on the name).
|
|
255
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
256
|
-
* @param event The events to send. The event names must match the names of the events that your Jobs are listening for.
|
|
257
|
-
* @param options Options for sending the events.
|
|
258
|
-
*/
|
|
259
|
-
sendEvents(cacheKey: string | any[], events: SendEvent[], options?: SendEventOptions): Promise<{
|
|
260
|
-
payload: import("@trigger.dev/core").DeserializedJson;
|
|
261
|
-
name: string;
|
|
262
|
-
id: string;
|
|
263
|
-
timestamp: Date;
|
|
264
|
-
context?: import("@trigger.dev/core").DeserializedJson | undefined;
|
|
265
|
-
deliverAt?: Date | null | undefined;
|
|
266
|
-
deliveredAt?: Date | null | undefined;
|
|
267
|
-
cancelledAt?: Date | null | undefined;
|
|
268
|
-
}[]>;
|
|
269
|
-
getEvent(cacheKey: string | any[], id: string): Promise<{
|
|
270
|
-
name: string;
|
|
271
|
-
id: string;
|
|
272
|
-
updatedAt: Date;
|
|
273
|
-
runs: {
|
|
274
|
-
status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD" | "EXECUTING" | "WAITING_TO_CONTINUE" | "WAITING_TO_EXECUTE";
|
|
275
|
-
id: string;
|
|
276
|
-
startedAt?: Date | null | undefined;
|
|
277
|
-
completedAt?: Date | null | undefined;
|
|
278
|
-
}[];
|
|
279
|
-
createdAt: Date;
|
|
280
|
-
}>;
|
|
281
|
-
/** `io.cancelEvent()` allows you to cancel an event that was previously sent with `io.sendEvent()`. This will prevent any Jobs from running that are listening for that event if the event was sent with a delay
|
|
282
|
-
* @param cacheKey
|
|
283
|
-
* @param eventId
|
|
284
|
-
* @returns
|
|
285
|
-
*/
|
|
286
|
-
cancelEvent(cacheKey: string | any[], eventId: string): Promise<{
|
|
287
|
-
payload: import("@trigger.dev/core").DeserializedJson;
|
|
288
|
-
name: string;
|
|
289
|
-
id: string;
|
|
290
|
-
timestamp: Date;
|
|
291
|
-
context?: import("@trigger.dev/core").DeserializedJson | undefined;
|
|
292
|
-
deliverAt?: Date | null | undefined;
|
|
293
|
-
deliveredAt?: Date | null | undefined;
|
|
294
|
-
cancelledAt?: Date | null | undefined;
|
|
295
|
-
}>;
|
|
296
|
-
updateSource(cacheKey: string | any[], options: {
|
|
297
|
-
key: string;
|
|
298
|
-
} & UpdateTriggerSourceBodyV2): Promise<{
|
|
299
|
-
id: string;
|
|
300
|
-
key: string;
|
|
301
|
-
}>;
|
|
302
|
-
updateWebhook(cacheKey: string | any[], options: {
|
|
303
|
-
key: string;
|
|
304
|
-
} & UpdateWebhookBody): Promise<{
|
|
305
|
-
id: string;
|
|
306
|
-
key: string;
|
|
307
|
-
}>;
|
|
308
|
-
/** `io.registerInterval()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular interval.
|
|
309
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
310
|
-
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
311
|
-
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
312
|
-
* @param options The options for the interval.
|
|
313
|
-
* @returns A promise that has information about the interval.
|
|
314
|
-
* @deprecated Use `DynamicSchedule.register` instead.
|
|
315
|
-
*/
|
|
316
|
-
registerInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
|
|
317
|
-
id: string;
|
|
318
|
-
schedule: {
|
|
319
|
-
options: {
|
|
320
|
-
cron: string;
|
|
321
|
-
};
|
|
322
|
-
type: "cron";
|
|
323
|
-
metadata?: any;
|
|
324
|
-
accountId?: string | undefined;
|
|
325
|
-
} | {
|
|
326
|
-
options: {
|
|
327
|
-
seconds: number;
|
|
328
|
-
};
|
|
329
|
-
type: "interval";
|
|
330
|
-
metadata?: any;
|
|
331
|
-
accountId?: string | undefined;
|
|
332
|
-
};
|
|
333
|
-
active: boolean;
|
|
334
|
-
metadata?: any;
|
|
335
|
-
}>;
|
|
336
|
-
/** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
|
|
337
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
338
|
-
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
339
|
-
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
340
|
-
* @deprecated Use `DynamicSchedule.unregister` instead.
|
|
341
|
-
*/
|
|
342
|
-
unregisterInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
|
|
343
|
-
ok: boolean;
|
|
344
|
-
}>;
|
|
345
|
-
/** `io.registerCron()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular CRON schedule.
|
|
346
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
347
|
-
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
348
|
-
* @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
|
|
349
|
-
* @param options The options for the CRON schedule.
|
|
350
|
-
* @deprecated Use `DynamicSchedule.register` instead.
|
|
351
|
-
*/
|
|
352
|
-
registerCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
|
|
353
|
-
id: string;
|
|
354
|
-
schedule: {
|
|
355
|
-
options: {
|
|
356
|
-
cron: string;
|
|
357
|
-
};
|
|
358
|
-
type: "cron";
|
|
359
|
-
metadata?: any;
|
|
360
|
-
accountId?: string | undefined;
|
|
361
|
-
} | {
|
|
362
|
-
options: {
|
|
363
|
-
seconds: number;
|
|
364
|
-
};
|
|
365
|
-
type: "interval";
|
|
366
|
-
metadata?: any;
|
|
367
|
-
accountId?: string | undefined;
|
|
368
|
-
};
|
|
369
|
-
active: boolean;
|
|
370
|
-
metadata?: any;
|
|
371
|
-
}>;
|
|
372
|
-
/** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
|
|
373
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
374
|
-
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
375
|
-
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
376
|
-
* @deprecated Use `DynamicSchedule.unregister` instead.
|
|
377
|
-
*/
|
|
378
|
-
unregisterCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
|
|
379
|
-
ok: boolean;
|
|
380
|
-
}>;
|
|
381
|
-
/** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
|
|
382
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
383
|
-
* @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
|
|
384
|
-
* @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
|
|
385
|
-
* @param params The params for the trigger.
|
|
386
|
-
* @deprecated Use `DynamicTrigger.register` instead.
|
|
387
|
-
*/
|
|
388
|
-
registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(cacheKey: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
|
|
389
|
-
id: string;
|
|
390
|
-
key: string;
|
|
391
|
-
} | undefined>;
|
|
392
|
-
getAuth(cacheKey: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
|
|
393
|
-
parallel<T extends Json<T> | void, TItem>(cacheKey: string | any[], items: Array<TItem>, callback: (item: TItem, index: number) => Promise<T>, options?: Pick<RunTaskOptions, "name" | "properties">): Promise<Array<T>>;
|
|
394
|
-
/** `io.runTask()` allows you to run a [Task](https://trigger.dev/docs/documentation/concepts/tasks) from inside a Job run. A Task is a resumable unit of a Run that can be retried, resumed and is logged. [Integrations](https://trigger.dev/docs/integrations) use Tasks internally to perform their actions.
|
|
395
|
-
*
|
|
396
|
-
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
397
|
-
* @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
|
|
398
|
-
* @param options The options of how you'd like to run and log the Task.
|
|
399
|
-
* @param onError The callback that will be called when the Task fails. The callback receives the error, the Task and the IO as parameters. If you wish to retry then return an object with a `retryAt` property.
|
|
400
|
-
* @returns A Promise that resolves with the returned value of the callback.
|
|
401
|
-
*/
|
|
402
|
-
runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions & {
|
|
403
|
-
parseOutput?: (output: unknown) => T;
|
|
404
|
-
}, onError?: RunTaskErrorCallback): Promise<T>;
|
|
405
|
-
/**
|
|
406
|
-
* `io.yield()` allows you to yield execution of the current run and resume it in a new function execution. Similar to `io.wait()` but does not create a task and resumes execution immediately.
|
|
407
|
-
*/
|
|
408
|
-
yield(cacheKey: string): void;
|
|
409
|
-
/**
|
|
410
|
-
* `io.brb()` is an alias of `io.yield()`
|
|
411
|
-
*/
|
|
412
|
-
brb: (cacheKey: string) => void;
|
|
413
|
-
/** `io.try()` allows you to run Tasks and catch any errors that are thrown, it's similar to a normal `try/catch` block but works with [io.runTask()](https://trigger.dev/docs/sdk/io/runtask).
|
|
414
|
-
* A regular `try/catch` block on its own won't work as expected with Tasks. Internally `runTask()` throws some special errors to control flow execution. This is necessary to deal with resumability, serverless timeouts, and retrying Tasks.
|
|
415
|
-
* @param tryCallback The code you wish to run
|
|
416
|
-
* @param catchCallback Thhis will be called if the Task fails. The callback receives the error
|
|
417
|
-
* @returns A Promise that resolves with the returned value or the error
|
|
418
|
-
*/
|
|
419
|
-
try<TResult, TCatchResult>(tryCallback: () => Promise<TResult>, catchCallback: (error: unknown) => Promise<TCatchResult>): Promise<TResult | TCatchResult>;
|
|
420
|
-
get store(): {
|
|
421
|
-
env: KeyValueStore;
|
|
422
|
-
job: KeyValueStore;
|
|
423
|
-
run: KeyValueStore;
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
type CallbackFunction = (level: "DEBUG" | "INFO" | "WARN" | "ERROR" | "LOG", message: string, properties?: Record<string, any>) => Promise<void>;
|
|
427
|
-
export declare class IOLogger implements TaskLogger {
|
|
428
|
-
private callback;
|
|
429
|
-
constructor(callback: CallbackFunction);
|
|
430
|
-
/** Log: essential messages */
|
|
431
|
-
log(message: string, properties?: Record<string, any>): Promise<void>;
|
|
432
|
-
/** For debugging: the least important log level */
|
|
433
|
-
debug(message: string, properties?: Record<string, any>): Promise<void>;
|
|
434
|
-
/** Info: the second least important log level */
|
|
435
|
-
info(message: string, properties?: Record<string, any>): Promise<void>;
|
|
436
|
-
/** Warnings: the third most important log level */
|
|
437
|
-
warn(message: string, properties?: Record<string, any>): Promise<void>;
|
|
438
|
-
/** Error: The second most important log level */
|
|
439
|
-
error(message: string, properties?: Record<string, any>): Promise<void>;
|
|
440
|
-
}
|
|
441
|
-
export {};
|