@trigger.dev/sdk 0.0.0-background-tasks-20230906212613
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/index.d.ts +1325 -0
- package/dist/index.js +2275 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1325 @@
|
|
|
1
|
+
import * as _trigger_dev_core from '@trigger.dev/core';
|
|
2
|
+
import { RunTaskBodyInput, CompleteTaskBodyInput, FailTaskBodyInput, SendEvent, SendEventOptions, UpdateTriggerSourceBodyV2, TriggerSource, RegisterTriggerBodyV2, RegisterSourceEventV2, ScheduleMetadata, GetRunOptionsWithTaskDetails, GetRunsOptions, LogLevel, RuntimeEnvironmentType, DisplayProperty, TriggerMetadata, EventFilter, Prettify, HandleTriggerSource, Logger, RegisterTriggerSource, SerializableJson, ConnectionAuth, NormalizedResponse, HttpSourceResponseMetadata, BackgroundTaskMetadata, DeserializedJson, IntervalOptions, CronOptions, ScheduledPayload, ServerTask, CachedTask, FetchRequestInit, FetchRetryOptions, RunTaskOptions, IntegrationMetadata, QueueOptions, IntegrationConfig, JobMetadata, MissingConnectionNotificationPayload, MissingConnectionResolvedNotificationPayload, ErrorWithStack, ApiEventLog, RedactString } from '@trigger.dev/core';
|
|
3
|
+
export { ConnectionAuth, DisplayProperty, EventFilter, Logger, NormalizedRequest, OverridableRunTaskOptions, Prettify, RedactString, RegisteredOptionsDiff, RunTaskOptions, SourceEventOption } from '@trigger.dev/core';
|
|
4
|
+
import * as zod from 'zod';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
type ApiClientOptions = {
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
apiUrl?: string;
|
|
10
|
+
logLevel?: LogLevel;
|
|
11
|
+
};
|
|
12
|
+
type EndpointRecord = {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
url: string;
|
|
16
|
+
};
|
|
17
|
+
declare class ApiClient {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(options: ApiClientOptions);
|
|
20
|
+
registerEndpoint(options: {
|
|
21
|
+
url: string;
|
|
22
|
+
name: string;
|
|
23
|
+
}): Promise<EndpointRecord>;
|
|
24
|
+
runTask(runId: string, task: RunTaskBodyInput): Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
noop: boolean;
|
|
28
|
+
status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
|
|
29
|
+
idempotencyKey: string;
|
|
30
|
+
attempts: number;
|
|
31
|
+
icon?: string | null | undefined;
|
|
32
|
+
startedAt?: Date | null | undefined;
|
|
33
|
+
completedAt?: Date | null | undefined;
|
|
34
|
+
delayUntil?: Date | null | undefined;
|
|
35
|
+
description?: string | null | undefined;
|
|
36
|
+
params?: _trigger_dev_core.DeserializedJson | undefined;
|
|
37
|
+
properties?: {
|
|
38
|
+
label: string;
|
|
39
|
+
text: string;
|
|
40
|
+
url?: string | undefined;
|
|
41
|
+
}[] | null | undefined;
|
|
42
|
+
outputProperties?: {
|
|
43
|
+
label: string;
|
|
44
|
+
text: string;
|
|
45
|
+
url?: string | undefined;
|
|
46
|
+
}[] | null | undefined;
|
|
47
|
+
output?: _trigger_dev_core.DeserializedJson | undefined;
|
|
48
|
+
error?: string | null | undefined;
|
|
49
|
+
parentId?: string | null | undefined;
|
|
50
|
+
style?: {
|
|
51
|
+
style: "normal" | "minimal";
|
|
52
|
+
variant?: string | undefined;
|
|
53
|
+
} | null | undefined;
|
|
54
|
+
operation?: string | null | undefined;
|
|
55
|
+
}>;
|
|
56
|
+
completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
|
|
57
|
+
id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
noop: boolean;
|
|
60
|
+
status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
|
|
61
|
+
idempotencyKey: string;
|
|
62
|
+
attempts: number;
|
|
63
|
+
icon?: string | null | undefined;
|
|
64
|
+
startedAt?: Date | null | undefined;
|
|
65
|
+
completedAt?: Date | null | undefined;
|
|
66
|
+
delayUntil?: Date | null | undefined;
|
|
67
|
+
description?: string | null | undefined;
|
|
68
|
+
params?: _trigger_dev_core.DeserializedJson | undefined;
|
|
69
|
+
properties?: {
|
|
70
|
+
label: string;
|
|
71
|
+
text: string;
|
|
72
|
+
url?: string | undefined;
|
|
73
|
+
}[] | null | undefined;
|
|
74
|
+
outputProperties?: {
|
|
75
|
+
label: string;
|
|
76
|
+
text: string;
|
|
77
|
+
url?: string | undefined;
|
|
78
|
+
}[] | null | undefined;
|
|
79
|
+
output?: _trigger_dev_core.DeserializedJson | undefined;
|
|
80
|
+
error?: string | null | undefined;
|
|
81
|
+
parentId?: string | null | undefined;
|
|
82
|
+
style?: {
|
|
83
|
+
style: "normal" | "minimal";
|
|
84
|
+
variant?: string | undefined;
|
|
85
|
+
} | null | undefined;
|
|
86
|
+
operation?: string | null | undefined;
|
|
87
|
+
}>;
|
|
88
|
+
failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
|
|
89
|
+
id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
noop: boolean;
|
|
92
|
+
status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
|
|
93
|
+
idempotencyKey: string;
|
|
94
|
+
attempts: number;
|
|
95
|
+
icon?: string | null | undefined;
|
|
96
|
+
startedAt?: Date | null | undefined;
|
|
97
|
+
completedAt?: Date | null | undefined;
|
|
98
|
+
delayUntil?: Date | null | undefined;
|
|
99
|
+
description?: string | null | undefined;
|
|
100
|
+
params?: _trigger_dev_core.DeserializedJson | undefined;
|
|
101
|
+
properties?: {
|
|
102
|
+
label: string;
|
|
103
|
+
text: string;
|
|
104
|
+
url?: string | undefined;
|
|
105
|
+
}[] | null | undefined;
|
|
106
|
+
outputProperties?: {
|
|
107
|
+
label: string;
|
|
108
|
+
text: string;
|
|
109
|
+
url?: string | undefined;
|
|
110
|
+
}[] | null | undefined;
|
|
111
|
+
output?: _trigger_dev_core.DeserializedJson | undefined;
|
|
112
|
+
error?: string | null | undefined;
|
|
113
|
+
parentId?: string | null | undefined;
|
|
114
|
+
style?: {
|
|
115
|
+
style: "normal" | "minimal";
|
|
116
|
+
variant?: string | undefined;
|
|
117
|
+
} | null | undefined;
|
|
118
|
+
operation?: string | null | undefined;
|
|
119
|
+
}>;
|
|
120
|
+
sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
|
|
121
|
+
id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
payload: ((string | number | boolean | {
|
|
124
|
+
[key: string]: _trigger_dev_core.DeserializedJson;
|
|
125
|
+
} | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
|
|
126
|
+
[key: string]: _trigger_dev_core.DeserializedJson;
|
|
127
|
+
} | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
|
|
128
|
+
timestamp: Date;
|
|
129
|
+
context?: _trigger_dev_core.DeserializedJson | undefined;
|
|
130
|
+
deliverAt?: Date | null | undefined;
|
|
131
|
+
deliveredAt?: Date | null | undefined;
|
|
132
|
+
cancelledAt?: Date | null | undefined;
|
|
133
|
+
}>;
|
|
134
|
+
cancelEvent(eventId: string): Promise<{
|
|
135
|
+
id: string;
|
|
136
|
+
name: string;
|
|
137
|
+
payload: ((string | number | boolean | {
|
|
138
|
+
[key: string]: _trigger_dev_core.DeserializedJson;
|
|
139
|
+
} | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
|
|
140
|
+
[key: string]: _trigger_dev_core.DeserializedJson;
|
|
141
|
+
} | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
|
|
142
|
+
timestamp: Date;
|
|
143
|
+
context?: _trigger_dev_core.DeserializedJson | undefined;
|
|
144
|
+
deliverAt?: Date | null | undefined;
|
|
145
|
+
deliveredAt?: Date | null | undefined;
|
|
146
|
+
cancelledAt?: Date | null | undefined;
|
|
147
|
+
}>;
|
|
148
|
+
updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
|
|
149
|
+
registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2): Promise<RegisterSourceEventV2>;
|
|
150
|
+
registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
|
|
151
|
+
id: string;
|
|
152
|
+
schedule: {
|
|
153
|
+
options: {
|
|
154
|
+
cron: string;
|
|
155
|
+
};
|
|
156
|
+
type: "cron";
|
|
157
|
+
metadata?: any;
|
|
158
|
+
} | {
|
|
159
|
+
options: {
|
|
160
|
+
seconds: number;
|
|
161
|
+
};
|
|
162
|
+
type: "interval";
|
|
163
|
+
metadata?: any;
|
|
164
|
+
};
|
|
165
|
+
active: boolean;
|
|
166
|
+
metadata?: any;
|
|
167
|
+
}>;
|
|
168
|
+
unregisterSchedule(client: string, id: string, key: string): Promise<{
|
|
169
|
+
ok: boolean;
|
|
170
|
+
}>;
|
|
171
|
+
getAuth(client: string, id: string): Promise<{
|
|
172
|
+
type: "oauth2";
|
|
173
|
+
accessToken: string;
|
|
174
|
+
scopes?: string[] | undefined;
|
|
175
|
+
additionalFields?: Record<string, string> | undefined;
|
|
176
|
+
} | undefined>;
|
|
177
|
+
getEvent(eventId: string): Promise<{
|
|
178
|
+
id: string;
|
|
179
|
+
name: string;
|
|
180
|
+
createdAt: Date;
|
|
181
|
+
updatedAt: Date;
|
|
182
|
+
runs: {
|
|
183
|
+
id: string;
|
|
184
|
+
status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
|
|
185
|
+
startedAt?: Date | null | undefined;
|
|
186
|
+
completedAt?: Date | null | undefined;
|
|
187
|
+
}[];
|
|
188
|
+
}>;
|
|
189
|
+
getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
|
|
190
|
+
id: string;
|
|
191
|
+
startedAt: Date | null;
|
|
192
|
+
completedAt: Date | null;
|
|
193
|
+
status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
|
|
194
|
+
tasks: _trigger_dev_core.RunTaskWithSubtasks[];
|
|
195
|
+
updatedAt: Date | null;
|
|
196
|
+
output?: any;
|
|
197
|
+
nextCursor?: string | undefined;
|
|
198
|
+
}>;
|
|
199
|
+
getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
|
|
200
|
+
runs: {
|
|
201
|
+
id: string;
|
|
202
|
+
startedAt: Date | null;
|
|
203
|
+
completedAt: Date | null;
|
|
204
|
+
status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
|
|
205
|
+
updatedAt: Date | null;
|
|
206
|
+
}[];
|
|
207
|
+
nextCursor?: string | undefined;
|
|
208
|
+
}>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
interface TriggerContext {
|
|
212
|
+
/** Job metadata */
|
|
213
|
+
job: {
|
|
214
|
+
id: string;
|
|
215
|
+
version: string;
|
|
216
|
+
};
|
|
217
|
+
/** Environment metadata */
|
|
218
|
+
environment: {
|
|
219
|
+
slug: string;
|
|
220
|
+
id: string;
|
|
221
|
+
type: RuntimeEnvironmentType;
|
|
222
|
+
};
|
|
223
|
+
/** Organization metadata */
|
|
224
|
+
organization: {
|
|
225
|
+
slug: string;
|
|
226
|
+
id: string;
|
|
227
|
+
title: string;
|
|
228
|
+
};
|
|
229
|
+
/** Run metadata */
|
|
230
|
+
run: {
|
|
231
|
+
id: string;
|
|
232
|
+
isTest: boolean;
|
|
233
|
+
startedAt: Date;
|
|
234
|
+
isRetry: boolean;
|
|
235
|
+
};
|
|
236
|
+
/** Event metadata */
|
|
237
|
+
event: {
|
|
238
|
+
id: string;
|
|
239
|
+
name: string;
|
|
240
|
+
context: any;
|
|
241
|
+
timestamp: Date;
|
|
242
|
+
};
|
|
243
|
+
/** Source metadata */
|
|
244
|
+
source?: {
|
|
245
|
+
id: string;
|
|
246
|
+
metadata?: any;
|
|
247
|
+
};
|
|
248
|
+
/** Account metadata */
|
|
249
|
+
account?: {
|
|
250
|
+
id: string;
|
|
251
|
+
metadata?: any;
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
interface TriggerPreprocessContext {
|
|
255
|
+
job: {
|
|
256
|
+
id: string;
|
|
257
|
+
version: string;
|
|
258
|
+
};
|
|
259
|
+
environment: {
|
|
260
|
+
slug: string;
|
|
261
|
+
id: string;
|
|
262
|
+
type: RuntimeEnvironmentType;
|
|
263
|
+
};
|
|
264
|
+
organization: {
|
|
265
|
+
slug: string;
|
|
266
|
+
id: string;
|
|
267
|
+
title: string;
|
|
268
|
+
};
|
|
269
|
+
run: {
|
|
270
|
+
id: string;
|
|
271
|
+
isTest: boolean;
|
|
272
|
+
};
|
|
273
|
+
event: {
|
|
274
|
+
id: string;
|
|
275
|
+
name: string;
|
|
276
|
+
context: any;
|
|
277
|
+
timestamp: Date;
|
|
278
|
+
};
|
|
279
|
+
account?: {
|
|
280
|
+
id: string;
|
|
281
|
+
metadata?: any;
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
interface TaskLogger {
|
|
285
|
+
debug(message: string, properties?: Record<string, any>): Promise<void>;
|
|
286
|
+
info(message: string, properties?: Record<string, any>): Promise<void>;
|
|
287
|
+
warn(message: string, properties?: Record<string, any>): Promise<void>;
|
|
288
|
+
error(message: string, properties?: Record<string, any>): Promise<void>;
|
|
289
|
+
}
|
|
290
|
+
type PreprocessResults = {
|
|
291
|
+
abort: boolean;
|
|
292
|
+
properties: DisplayProperty[];
|
|
293
|
+
};
|
|
294
|
+
type TriggerEventType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? ReturnType<TEventSpec["parsePayload"]> : never;
|
|
295
|
+
interface Trigger<TEventSpec extends EventSpecification<any>> {
|
|
296
|
+
event: TEventSpec;
|
|
297
|
+
toJSON(): TriggerMetadata;
|
|
298
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
|
|
299
|
+
preprocessRuns: boolean;
|
|
300
|
+
}
|
|
301
|
+
type TriggerPayload<TTrigger> = TTrigger extends Trigger<EventSpecification<infer TEvent>> ? TEvent : never;
|
|
302
|
+
type EventSpecificationExample = {
|
|
303
|
+
id: string;
|
|
304
|
+
name: string;
|
|
305
|
+
icon?: string;
|
|
306
|
+
payload: any;
|
|
307
|
+
};
|
|
308
|
+
interface EventSpecification<TEvent extends any> {
|
|
309
|
+
name: string | string[];
|
|
310
|
+
title: string;
|
|
311
|
+
source: string;
|
|
312
|
+
icon: string;
|
|
313
|
+
properties?: DisplayProperty[];
|
|
314
|
+
schema?: any;
|
|
315
|
+
examples?: Array<EventSpecificationExample>;
|
|
316
|
+
filter?: EventFilter;
|
|
317
|
+
parsePayload: (payload: unknown) => TEvent;
|
|
318
|
+
runProperties?: (payload: TEvent) => DisplayProperty[];
|
|
319
|
+
}
|
|
320
|
+
type EventTypeFromSpecification<TEventSpec extends EventSpecification<any>> = TEventSpec extends EventSpecification<infer TEvent> ? TEvent : never;
|
|
321
|
+
|
|
322
|
+
type HttpSourceEvent = {
|
|
323
|
+
url: string;
|
|
324
|
+
method: string;
|
|
325
|
+
headers: Record<string, string>;
|
|
326
|
+
rawBody?: Buffer | null;
|
|
327
|
+
};
|
|
328
|
+
type SmtpSourceEvent = {
|
|
329
|
+
from: string;
|
|
330
|
+
to: string;
|
|
331
|
+
subject: string;
|
|
332
|
+
body: string;
|
|
333
|
+
};
|
|
334
|
+
type SqsSourceEvent = {
|
|
335
|
+
body: string;
|
|
336
|
+
};
|
|
337
|
+
type ExternalSourceChannelMap = {
|
|
338
|
+
HTTP: {
|
|
339
|
+
event: Request;
|
|
340
|
+
register: {
|
|
341
|
+
url: string;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
SMTP: {
|
|
345
|
+
event: SmtpSourceEvent;
|
|
346
|
+
register: {};
|
|
347
|
+
};
|
|
348
|
+
SQS: {
|
|
349
|
+
event: SqsSourceEvent;
|
|
350
|
+
register: {};
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
type ChannelNames = keyof ExternalSourceChannelMap;
|
|
354
|
+
type TriggerOptionDiff = {
|
|
355
|
+
desired: string[];
|
|
356
|
+
missing: string[];
|
|
357
|
+
orphaned: string[];
|
|
358
|
+
};
|
|
359
|
+
type TriggerOptionDiffs<TTriggerOptionDefinitions extends Record<string, string[]> = any> = TriggerOptionsRecordWithEvent<TriggerOptionDiff, TTriggerOptionDefinitions>;
|
|
360
|
+
type TriggerOptionsRecordWithEvent<TValue, TTriggerOptionDefinitions extends Record<string, string[]>> = {
|
|
361
|
+
event: TValue;
|
|
362
|
+
} & TriggerOptionRecord<TValue, TTriggerOptionDefinitions>;
|
|
363
|
+
type TriggerOptionRecord<TValue, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
|
|
364
|
+
[K in keyof TTriggerOptionDefinitions]: TValue;
|
|
365
|
+
};
|
|
366
|
+
type RegisterFunctionEvent<TChannel extends ChannelNames, TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
|
|
367
|
+
options: TriggerOptionDiffs<TTriggerOptionDefinitions>;
|
|
368
|
+
source: {
|
|
369
|
+
active: boolean;
|
|
370
|
+
data?: any;
|
|
371
|
+
secret: string;
|
|
372
|
+
} & ExternalSourceChannelMap[TChannel]["register"];
|
|
373
|
+
params: TParams;
|
|
374
|
+
};
|
|
375
|
+
type RegisterSourceEvent<TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
|
|
376
|
+
id: string;
|
|
377
|
+
source: RegisterTriggerSource;
|
|
378
|
+
dynamicTriggerId?: string;
|
|
379
|
+
options: TriggerOptionDiffs<TTriggerOptionDefinitions>;
|
|
380
|
+
};
|
|
381
|
+
type RegisterFunctionOutput<TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
|
|
382
|
+
secret?: string;
|
|
383
|
+
data?: SerializableJson;
|
|
384
|
+
options: TriggerOptionsRecordWithEvent<string[], TTriggerOptionDefinitions>;
|
|
385
|
+
};
|
|
386
|
+
type RegisterFunction<TIntegration extends TriggerIntegration, TParams extends any, TChannel extends ChannelNames, TTriggerOptionDefinitions extends Record<string, string[]> = any> = (event: RegisterFunctionEvent<TChannel, TParams, TTriggerOptionDefinitions>, io: IOWithIntegrations<{
|
|
387
|
+
integration: TIntegration;
|
|
388
|
+
}>, ctx: TriggerContext) => Promise<RegisterFunctionOutput<TTriggerOptionDefinitions> | undefined>;
|
|
389
|
+
type HandlerEvent<TChannel extends ChannelNames, TParams extends any = any> = {
|
|
390
|
+
rawEvent: ExternalSourceChannelMap[TChannel]["event"];
|
|
391
|
+
source: Prettify<Omit<HandleTriggerSource, "params"> & {
|
|
392
|
+
params: TParams;
|
|
393
|
+
}>;
|
|
394
|
+
};
|
|
395
|
+
type HandlerFunction<TChannel extends ChannelNames, TParams extends any, TTriggerIntegration extends TriggerIntegration> = (event: HandlerEvent<TChannel, TParams>, logger: Logger, integration: TTriggerIntegration, auth?: ConnectionAuth) => Promise<{
|
|
396
|
+
events: SendEvent[];
|
|
397
|
+
response?: NormalizedResponse;
|
|
398
|
+
metadata?: HttpSourceResponseMetadata;
|
|
399
|
+
} | void>;
|
|
400
|
+
type KeyFunction<TParams extends any> = (params: TParams) => string;
|
|
401
|
+
type FilterFunction<TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = (params: TParams, options?: TTriggerOptionDefinitions) => EventFilter;
|
|
402
|
+
type ExternalSourceOptions<TChannel extends ChannelNames, TIntegration extends TriggerIntegration, TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
|
|
403
|
+
id: string;
|
|
404
|
+
version: string;
|
|
405
|
+
schema: z.Schema<TParams>;
|
|
406
|
+
optionSchema?: z.Schema<TTriggerOptionDefinitions>;
|
|
407
|
+
integration: TIntegration;
|
|
408
|
+
register: RegisterFunction<TIntegration, TParams, TChannel, TTriggerOptionDefinitions>;
|
|
409
|
+
filter?: FilterFunction<TParams, TTriggerOptionDefinitions>;
|
|
410
|
+
handler: HandlerFunction<TChannel, TParams, TIntegration>;
|
|
411
|
+
key: KeyFunction<TParams>;
|
|
412
|
+
properties?: (params: TParams) => DisplayProperty[];
|
|
413
|
+
};
|
|
414
|
+
declare class ExternalSource<TIntegration extends TriggerIntegration, TParams extends any, TChannel extends ChannelNames = ChannelNames, TTriggerOptionDefinitions extends Record<string, string[]> = any> {
|
|
415
|
+
private options;
|
|
416
|
+
channel: TChannel;
|
|
417
|
+
constructor(channel: TChannel, options: ExternalSourceOptions<TChannel, TIntegration, TParams, TTriggerOptionDefinitions>);
|
|
418
|
+
handle(source: HandleTriggerSource, rawEvent: ExternalSourceChannelMap[TChannel]["event"], logger: Logger): Promise<void | {
|
|
419
|
+
events: {
|
|
420
|
+
name: string;
|
|
421
|
+
payload?: any;
|
|
422
|
+
context?: any;
|
|
423
|
+
id?: string | undefined;
|
|
424
|
+
timestamp?: Date | undefined;
|
|
425
|
+
source?: string | undefined;
|
|
426
|
+
}[];
|
|
427
|
+
response?: {
|
|
428
|
+
status: number;
|
|
429
|
+
body?: any;
|
|
430
|
+
headers?: Record<string, string> | undefined;
|
|
431
|
+
} | undefined;
|
|
432
|
+
metadata?: _trigger_dev_core.DeserializedJson | undefined;
|
|
433
|
+
}>;
|
|
434
|
+
filter(params: TParams, options?: TTriggerOptionDefinitions): EventFilter;
|
|
435
|
+
properties(params: TParams): DisplayProperty[];
|
|
436
|
+
register(params: TParams, registerEvent: RegisterSourceEvent<TTriggerOptionDefinitions>, io: IO, ctx: TriggerContext): Promise<RegisterFunctionOutput<TTriggerOptionDefinitions> | undefined>;
|
|
437
|
+
key(params: TParams): string;
|
|
438
|
+
get integration(): TIntegration;
|
|
439
|
+
get integrationConfig(): {
|
|
440
|
+
id: string;
|
|
441
|
+
metadata: {
|
|
442
|
+
id: string;
|
|
443
|
+
name: string;
|
|
444
|
+
instructions?: string | undefined;
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
get id(): string;
|
|
448
|
+
get version(): string;
|
|
449
|
+
}
|
|
450
|
+
type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams & {
|
|
451
|
+
filter?: EventFilter;
|
|
452
|
+
} : never;
|
|
453
|
+
type ExternalSourceTriggerOptions<TEventSpecification extends EventSpecification<any>, TEventSource extends ExternalSource<any, any, any>, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
|
|
454
|
+
event: TEventSpecification;
|
|
455
|
+
source: TEventSource;
|
|
456
|
+
params: ExternalSourceParams<TEventSource>;
|
|
457
|
+
options: TriggerOptionRecord<string[], TTriggerOptionDefinitions>;
|
|
458
|
+
};
|
|
459
|
+
declare class ExternalSourceTrigger<TEventSpecification extends EventSpecification<any>, TEventSource extends ExternalSource<any, any, any>> implements Trigger<TEventSpecification> {
|
|
460
|
+
private options;
|
|
461
|
+
constructor(options: ExternalSourceTriggerOptions<TEventSpecification, TEventSource>);
|
|
462
|
+
get event(): TEventSpecification;
|
|
463
|
+
toJSON(): TriggerMetadata;
|
|
464
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
|
|
465
|
+
get preprocessRuns(): boolean;
|
|
466
|
+
}
|
|
467
|
+
declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, key: K): {
|
|
468
|
+
result: Omit<T, K>;
|
|
469
|
+
ommited: T[K];
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
/** Options for a DynamicTrigger */
|
|
473
|
+
type DynamicTriggerOptions<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>> = {
|
|
474
|
+
/** Used to uniquely identify a DynamicTrigger */
|
|
475
|
+
id: string;
|
|
476
|
+
/** An event from an [Integration](https://trigger.dev/docs/integrations) package that you want to attach to the DynamicTrigger. The event types will come through to the payload in your Job's run. */
|
|
477
|
+
event: TEventSpec;
|
|
478
|
+
/** An external source fron an [Integration](https://trigger.dev/docs/integrations) package
|
|
479
|
+
* @example
|
|
480
|
+
* ```ts
|
|
481
|
+
* import { events } from "@trigger.dev/github";
|
|
482
|
+
*
|
|
483
|
+
* const dynamicOnIssueOpened = new DynamicTrigger(client, {
|
|
484
|
+
id: "github-issue-opened",
|
|
485
|
+
event: events.onIssueOpened,
|
|
486
|
+
source: github.sources.repo,
|
|
487
|
+
});
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
source: TExternalSource;
|
|
491
|
+
};
|
|
492
|
+
/** `DynamicTrigger` allows you to define a trigger that can be configured dynamically at runtime. */
|
|
493
|
+
declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>> implements Trigger<TEventSpec> {
|
|
494
|
+
#private;
|
|
495
|
+
source: TExternalSource;
|
|
496
|
+
/** `DynamicTrigger` allows you to define a trigger that can be configured dynamically at runtime.
|
|
497
|
+
* @param client The `TriggerClient` instance to use for registering the trigger.
|
|
498
|
+
* @param options The options for the dynamic trigger.
|
|
499
|
+
* */
|
|
500
|
+
constructor(client: TriggerClient, options: DynamicTriggerOptions<TEventSpec, TExternalSource>);
|
|
501
|
+
toJSON(): TriggerMetadata;
|
|
502
|
+
get id(): string;
|
|
503
|
+
get event(): TEventSpec;
|
|
504
|
+
registeredTriggerForParams(params: ExternalSourceParams<TExternalSource>): RegisterTriggerBodyV2;
|
|
505
|
+
/** Use this method to register a new configuration with the DynamicTrigger.
|
|
506
|
+
* @param key The key for the configuration. This will be used to identify the configuration when it is triggered.
|
|
507
|
+
* @param params The params for the configuration.
|
|
508
|
+
*/
|
|
509
|
+
register(key: string, params: ExternalSourceParams<TExternalSource>): Promise<RegisterSourceEventV2>;
|
|
510
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
|
|
511
|
+
get preprocessRuns(): boolean;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
type BackgroundTaskOptions<TPayload = any> = {
|
|
515
|
+
id: string;
|
|
516
|
+
name: string;
|
|
517
|
+
version: string;
|
|
518
|
+
schema?: z.Schema<TPayload>;
|
|
519
|
+
logLevel?: LogLevel;
|
|
520
|
+
cpu?: 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128;
|
|
521
|
+
memory?: 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768;
|
|
522
|
+
concurrency?: number;
|
|
523
|
+
secrets?: {
|
|
524
|
+
[key: string]: string;
|
|
525
|
+
};
|
|
526
|
+
enabled?: boolean;
|
|
527
|
+
run: (payload: TPayload) => Promise<any>;
|
|
528
|
+
};
|
|
529
|
+
declare class BackgroundTask<TPayload = any> {
|
|
530
|
+
#private;
|
|
531
|
+
readonly options: BackgroundTaskOptions<TPayload>;
|
|
532
|
+
client: TriggerClient;
|
|
533
|
+
constructor(client: TriggerClient, options: BackgroundTaskOptions<TPayload>);
|
|
534
|
+
get id(): string;
|
|
535
|
+
get enabled(): boolean;
|
|
536
|
+
get name(): string;
|
|
537
|
+
get schema(): z.ZodType<TPayload, z.ZodTypeDef, TPayload> | undefined;
|
|
538
|
+
get version(): string;
|
|
539
|
+
get logLevel(): LogLevel | undefined;
|
|
540
|
+
invoke(key: string, payload: TPayload): Promise<any>;
|
|
541
|
+
toJSON(): BackgroundTaskMetadata;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
type TriggerClientOptions = {
|
|
545
|
+
/** The `id` property is used to uniquely identify the client.
|
|
546
|
+
*/
|
|
547
|
+
id: string;
|
|
548
|
+
/** The `apiKey` property is the API Key for your Trigger.dev environment. We
|
|
549
|
+
recommend using an environment variable to store your API Key. */
|
|
550
|
+
apiKey?: string;
|
|
551
|
+
/** The `apiUrl` property is an optional property that specifies the API URL. You
|
|
552
|
+
only need to specify this if you are not using Trigger.dev Cloud and are
|
|
553
|
+
running your own Trigger.dev instance. */
|
|
554
|
+
apiUrl?: string;
|
|
555
|
+
/** The `logLevel` property is an optional property that specifies the level of
|
|
556
|
+
logging for the TriggerClient. The level is inherited by all Jobs that use this Client, unless they also specify a `logLevel`. */
|
|
557
|
+
logLevel?: LogLevel;
|
|
558
|
+
/** Very verbose log messages, defaults to false. */
|
|
559
|
+
verbose?: boolean;
|
|
560
|
+
/** Default is unset and off. If set to true it will log to the server's console as well as the Trigger.dev platform */
|
|
561
|
+
ioLogLocalEnabled?: boolean;
|
|
562
|
+
};
|
|
563
|
+
/** A [TriggerClient](https://trigger.dev/docs/documentation/concepts/client-adaptors) is used to connect to a specific [Project](https://trigger.dev/docs/documentation/concepts/projects) by using an [API Key](https://trigger.dev/docs/documentation/concepts/environments-apikeys). */
|
|
564
|
+
declare class TriggerClient {
|
|
565
|
+
#private;
|
|
566
|
+
id: string;
|
|
567
|
+
constructor(options: Prettify<TriggerClientOptions>);
|
|
568
|
+
handleRequest(request: Request): Promise<NormalizedResponse>;
|
|
569
|
+
attach(job: Job<Trigger<any>, any>): void;
|
|
570
|
+
attachBackgroundTask(task: BackgroundTask<any>): void;
|
|
571
|
+
attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
|
|
572
|
+
attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
|
|
573
|
+
attachSource(options: {
|
|
574
|
+
key: string;
|
|
575
|
+
source: ExternalSource<any, any>;
|
|
576
|
+
event: EventSpecification<any>;
|
|
577
|
+
params: any;
|
|
578
|
+
options?: Record<string, string[]>;
|
|
579
|
+
}): void;
|
|
580
|
+
attachDynamicSchedule(key: string, job: Job<Trigger<any>, any>): void;
|
|
581
|
+
registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
|
|
582
|
+
id: string;
|
|
583
|
+
options: {
|
|
584
|
+
event: {
|
|
585
|
+
desired: string[];
|
|
586
|
+
missing: string[];
|
|
587
|
+
orphaned: string[];
|
|
588
|
+
};
|
|
589
|
+
} & Record<string, {
|
|
590
|
+
desired: string[];
|
|
591
|
+
missing: string[];
|
|
592
|
+
orphaned: string[];
|
|
593
|
+
}>;
|
|
594
|
+
source: {
|
|
595
|
+
key: string;
|
|
596
|
+
secret: string;
|
|
597
|
+
active: boolean;
|
|
598
|
+
channel: {
|
|
599
|
+
url: string;
|
|
600
|
+
type: "HTTP";
|
|
601
|
+
} | {
|
|
602
|
+
type: "SMTP";
|
|
603
|
+
} | {
|
|
604
|
+
type: "SQS";
|
|
605
|
+
};
|
|
606
|
+
params?: any;
|
|
607
|
+
data?: DeserializedJson | undefined;
|
|
608
|
+
clientId?: string | undefined;
|
|
609
|
+
};
|
|
610
|
+
dynamicTriggerId?: string | undefined;
|
|
611
|
+
}>;
|
|
612
|
+
getAuth(id: string): Promise<{
|
|
613
|
+
type: "oauth2";
|
|
614
|
+
accessToken: string;
|
|
615
|
+
scopes?: string[] | undefined;
|
|
616
|
+
additionalFields?: Record<string, string> | undefined;
|
|
617
|
+
} | undefined>;
|
|
618
|
+
/** You can call this function from anywhere in your code to send an event. The other way to send an event is by using [`io.sendEvent()`](https://trigger.dev/docs/sdk/io/sendevent) from inside a `run()` function.
|
|
619
|
+
* @param event The event to send.
|
|
620
|
+
* @param options Options for sending the event.
|
|
621
|
+
* @returns A promise that resolves to the event details
|
|
622
|
+
*/
|
|
623
|
+
sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
|
|
624
|
+
id: string;
|
|
625
|
+
name: string;
|
|
626
|
+
payload: ((string | number | boolean | {
|
|
627
|
+
[key: string]: DeserializedJson;
|
|
628
|
+
} | DeserializedJson[]) & (string | number | boolean | {
|
|
629
|
+
[key: string]: DeserializedJson;
|
|
630
|
+
} | DeserializedJson[] | undefined)) | null;
|
|
631
|
+
timestamp: Date;
|
|
632
|
+
context?: DeserializedJson | undefined;
|
|
633
|
+
deliverAt?: Date | null | undefined;
|
|
634
|
+
deliveredAt?: Date | null | undefined;
|
|
635
|
+
cancelledAt?: Date | null | undefined;
|
|
636
|
+
}>;
|
|
637
|
+
cancelEvent(eventId: string): Promise<{
|
|
638
|
+
id: string;
|
|
639
|
+
name: string;
|
|
640
|
+
payload: ((string | number | boolean | {
|
|
641
|
+
[key: string]: DeserializedJson;
|
|
642
|
+
} | DeserializedJson[]) & (string | number | boolean | {
|
|
643
|
+
[key: string]: DeserializedJson;
|
|
644
|
+
} | DeserializedJson[] | undefined)) | null;
|
|
645
|
+
timestamp: Date;
|
|
646
|
+
context?: DeserializedJson | undefined;
|
|
647
|
+
deliverAt?: Date | null | undefined;
|
|
648
|
+
deliveredAt?: Date | null | undefined;
|
|
649
|
+
cancelledAt?: Date | null | undefined;
|
|
650
|
+
}>;
|
|
651
|
+
registerSchedule(id: string, key: string, schedule: ScheduleMetadata): Promise<{
|
|
652
|
+
id: string;
|
|
653
|
+
schedule: {
|
|
654
|
+
options: {
|
|
655
|
+
cron: string;
|
|
656
|
+
};
|
|
657
|
+
type: "cron";
|
|
658
|
+
metadata?: any;
|
|
659
|
+
} | {
|
|
660
|
+
options: {
|
|
661
|
+
seconds: number;
|
|
662
|
+
};
|
|
663
|
+
type: "interval";
|
|
664
|
+
metadata?: any;
|
|
665
|
+
};
|
|
666
|
+
active: boolean;
|
|
667
|
+
metadata?: any;
|
|
668
|
+
}>;
|
|
669
|
+
unregisterSchedule(id: string, key: string): Promise<{
|
|
670
|
+
ok: boolean;
|
|
671
|
+
}>;
|
|
672
|
+
getEvent(eventId: string): Promise<{
|
|
673
|
+
id: string;
|
|
674
|
+
name: string;
|
|
675
|
+
createdAt: Date;
|
|
676
|
+
updatedAt: Date;
|
|
677
|
+
runs: {
|
|
678
|
+
id: string;
|
|
679
|
+
status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
|
|
680
|
+
startedAt?: Date | null | undefined;
|
|
681
|
+
completedAt?: Date | null | undefined;
|
|
682
|
+
}[];
|
|
683
|
+
}>;
|
|
684
|
+
getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
|
|
685
|
+
id: string;
|
|
686
|
+
startedAt: Date | null;
|
|
687
|
+
completedAt: Date | null;
|
|
688
|
+
status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
|
|
689
|
+
tasks: _trigger_dev_core.RunTaskWithSubtasks[];
|
|
690
|
+
updatedAt: Date | null;
|
|
691
|
+
output?: any;
|
|
692
|
+
nextCursor?: string | undefined;
|
|
693
|
+
}>;
|
|
694
|
+
getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
|
|
695
|
+
runs: {
|
|
696
|
+
id: string;
|
|
697
|
+
startedAt: Date | null;
|
|
698
|
+
completedAt: Date | null;
|
|
699
|
+
status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
|
|
700
|
+
updatedAt: Date | null;
|
|
701
|
+
}[];
|
|
702
|
+
nextCursor?: string | undefined;
|
|
703
|
+
}>;
|
|
704
|
+
authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
|
|
705
|
+
apiKey(): string | undefined;
|
|
706
|
+
defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
|
|
707
|
+
defineBackgroundTask<TPayload = any>(options: BackgroundTaskOptions<TPayload>): BackgroundTask<TPayload>;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
|
|
711
|
+
declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
|
|
712
|
+
private options;
|
|
713
|
+
constructor(options: IntervalOptions);
|
|
714
|
+
get event(): {
|
|
715
|
+
name: string;
|
|
716
|
+
title: string;
|
|
717
|
+
source: string;
|
|
718
|
+
icon: string;
|
|
719
|
+
examples: {
|
|
720
|
+
id: string;
|
|
721
|
+
name: string;
|
|
722
|
+
icon: string;
|
|
723
|
+
payload: {
|
|
724
|
+
ts: string;
|
|
725
|
+
lastTimestamp: string;
|
|
726
|
+
};
|
|
727
|
+
}[];
|
|
728
|
+
parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
|
|
729
|
+
ts: Date;
|
|
730
|
+
lastTimestamp?: Date | undefined;
|
|
731
|
+
};
|
|
732
|
+
properties: {
|
|
733
|
+
label: string;
|
|
734
|
+
text: string;
|
|
735
|
+
}[];
|
|
736
|
+
};
|
|
737
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
|
|
738
|
+
get preprocessRuns(): boolean;
|
|
739
|
+
toJSON(): TriggerMetadata;
|
|
740
|
+
}
|
|
741
|
+
/** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
|
|
742
|
+
* @param options An object containing options about the interval.
|
|
743
|
+
*/
|
|
744
|
+
declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
|
|
745
|
+
declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
|
|
746
|
+
private options;
|
|
747
|
+
constructor(options: CronOptions);
|
|
748
|
+
get event(): {
|
|
749
|
+
name: string;
|
|
750
|
+
title: string;
|
|
751
|
+
source: string;
|
|
752
|
+
icon: string;
|
|
753
|
+
examples: {
|
|
754
|
+
id: string;
|
|
755
|
+
name: string;
|
|
756
|
+
icon: string;
|
|
757
|
+
payload: {
|
|
758
|
+
ts: string;
|
|
759
|
+
lastTimestamp: string;
|
|
760
|
+
};
|
|
761
|
+
}[];
|
|
762
|
+
parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
|
|
763
|
+
ts: Date;
|
|
764
|
+
lastTimestamp?: Date | undefined;
|
|
765
|
+
};
|
|
766
|
+
properties: {
|
|
767
|
+
label: string;
|
|
768
|
+
text: string;
|
|
769
|
+
}[];
|
|
770
|
+
};
|
|
771
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
|
|
772
|
+
get preprocessRuns(): boolean;
|
|
773
|
+
toJSON(): TriggerMetadata;
|
|
774
|
+
}
|
|
775
|
+
/** `cronTrigger()` is set as a [Job's trigger](https://trigger.dev/docs/sdk/job) to trigger a Job on a recurring schedule using a CRON expression.
|
|
776
|
+
* @param options An object containing options about the CRON schedule.
|
|
777
|
+
*/
|
|
778
|
+
declare function cronTrigger(options: CronOptions): CronTrigger;
|
|
779
|
+
/** DynamicSchedule options
|
|
780
|
+
* @param id Used to uniquely identify a DynamicSchedule
|
|
781
|
+
*/
|
|
782
|
+
type DynamicIntervalOptions = {
|
|
783
|
+
id: string;
|
|
784
|
+
};
|
|
785
|
+
/** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
|
|
786
|
+
declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
|
|
787
|
+
private client;
|
|
788
|
+
private options;
|
|
789
|
+
/**
|
|
790
|
+
* @param client The `TriggerClient` instance to use for registering the trigger.
|
|
791
|
+
* @param options The options for the schedule.
|
|
792
|
+
*/
|
|
793
|
+
constructor(client: TriggerClient, options: DynamicIntervalOptions);
|
|
794
|
+
get id(): string;
|
|
795
|
+
get event(): {
|
|
796
|
+
name: string;
|
|
797
|
+
title: string;
|
|
798
|
+
source: string;
|
|
799
|
+
icon: string;
|
|
800
|
+
examples: {
|
|
801
|
+
id: string;
|
|
802
|
+
name: string;
|
|
803
|
+
icon: string;
|
|
804
|
+
payload: {
|
|
805
|
+
ts: string;
|
|
806
|
+
lastTimestamp: string;
|
|
807
|
+
};
|
|
808
|
+
}[];
|
|
809
|
+
parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
|
|
810
|
+
ts: Date;
|
|
811
|
+
lastTimestamp?: Date | undefined;
|
|
812
|
+
};
|
|
813
|
+
};
|
|
814
|
+
register(key: string, metadata: ScheduleMetadata): Promise<{
|
|
815
|
+
id: string;
|
|
816
|
+
schedule: {
|
|
817
|
+
options: {
|
|
818
|
+
cron: string;
|
|
819
|
+
};
|
|
820
|
+
type: "cron";
|
|
821
|
+
metadata?: any;
|
|
822
|
+
} | {
|
|
823
|
+
options: {
|
|
824
|
+
seconds: number;
|
|
825
|
+
};
|
|
826
|
+
type: "interval";
|
|
827
|
+
metadata?: any;
|
|
828
|
+
};
|
|
829
|
+
active: boolean;
|
|
830
|
+
metadata?: any;
|
|
831
|
+
}>;
|
|
832
|
+
unregister(key: string): Promise<{
|
|
833
|
+
ok: boolean;
|
|
834
|
+
}>;
|
|
835
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
|
|
836
|
+
get preprocessRuns(): boolean;
|
|
837
|
+
toJSON(): TriggerMetadata;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
type IOTask = ServerTask;
|
|
841
|
+
type IOOptions = {
|
|
842
|
+
id: string;
|
|
843
|
+
apiClient: ApiClient;
|
|
844
|
+
client: TriggerClient;
|
|
845
|
+
context: TriggerContext;
|
|
846
|
+
logger?: Logger;
|
|
847
|
+
logLevel?: LogLevel;
|
|
848
|
+
jobLogger?: Logger;
|
|
849
|
+
jobLogLevel: LogLevel;
|
|
850
|
+
cachedTasks?: Array<CachedTask>;
|
|
851
|
+
};
|
|
852
|
+
type JsonPrimitive = string | number | boolean | null | undefined | Date | symbol;
|
|
853
|
+
type JsonArray = Json[];
|
|
854
|
+
type JsonRecord<T> = {
|
|
855
|
+
[Property in keyof T]: Json;
|
|
856
|
+
};
|
|
857
|
+
type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
|
|
858
|
+
type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
|
|
859
|
+
retryAt: Date;
|
|
860
|
+
error?: Error;
|
|
861
|
+
jitter?: number;
|
|
862
|
+
} | Error | undefined | void;
|
|
863
|
+
declare class IO {
|
|
864
|
+
#private;
|
|
865
|
+
private _id;
|
|
866
|
+
private _apiClient;
|
|
867
|
+
private _triggerClient;
|
|
868
|
+
private _logger;
|
|
869
|
+
private _jobLogger?;
|
|
870
|
+
private _jobLogLevel;
|
|
871
|
+
private _cachedTasks;
|
|
872
|
+
private _taskStorage;
|
|
873
|
+
private _context;
|
|
874
|
+
constructor(options: IOOptions);
|
|
875
|
+
/** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
|
|
876
|
+
get logger(): IOLogger;
|
|
877
|
+
/** `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.
|
|
878
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
879
|
+
* @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
|
|
880
|
+
*/
|
|
881
|
+
wait(key: string | any[], seconds: number): Promise<void>;
|
|
882
|
+
/** `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.
|
|
883
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
884
|
+
* @param url The URL to fetch from.
|
|
885
|
+
* @param requestInit The options for the request
|
|
886
|
+
* @param retry The options for retrying the request if it fails
|
|
887
|
+
* An object where the key is a status code pattern and the value is a retrying strategy.
|
|
888
|
+
* Supported patterns are:
|
|
889
|
+
* - Specific status codes: 429
|
|
890
|
+
* - Ranges: 500-599
|
|
891
|
+
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
892
|
+
*/
|
|
893
|
+
backgroundFetch<TResponseData>(key: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
|
|
894
|
+
/** `io.sendEvent()` allows you to send an event from inside a Job run. The sent even will trigger any Jobs that are listening for that event (based on the name).
|
|
895
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
896
|
+
* @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
|
|
897
|
+
* @param options Options for sending the event.
|
|
898
|
+
*/
|
|
899
|
+
sendEvent(key: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
|
|
900
|
+
id: string;
|
|
901
|
+
name: string;
|
|
902
|
+
payload: ((string | number | boolean | {
|
|
903
|
+
[key: string]: _trigger_dev_core.DeserializedJson;
|
|
904
|
+
} | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
|
|
905
|
+
[key: string]: _trigger_dev_core.DeserializedJson;
|
|
906
|
+
} | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
|
|
907
|
+
timestamp: Date;
|
|
908
|
+
context?: _trigger_dev_core.DeserializedJson | undefined;
|
|
909
|
+
deliverAt?: Date | null | undefined;
|
|
910
|
+
deliveredAt?: Date | null | undefined;
|
|
911
|
+
cancelledAt?: Date | null | undefined;
|
|
912
|
+
}>;
|
|
913
|
+
getEvent(key: string | any[], id: string): Promise<{
|
|
914
|
+
id: string;
|
|
915
|
+
name: string;
|
|
916
|
+
createdAt: Date;
|
|
917
|
+
updatedAt: Date;
|
|
918
|
+
runs: {
|
|
919
|
+
id: string;
|
|
920
|
+
status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
|
|
921
|
+
startedAt?: Date | null | undefined;
|
|
922
|
+
completedAt?: Date | null | undefined;
|
|
923
|
+
}[];
|
|
924
|
+
}>;
|
|
925
|
+
/** `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
|
|
926
|
+
* @param key
|
|
927
|
+
* @param eventId
|
|
928
|
+
* @returns
|
|
929
|
+
*/
|
|
930
|
+
cancelEvent(key: string | any[], eventId: string): Promise<{
|
|
931
|
+
id: string;
|
|
932
|
+
name: string;
|
|
933
|
+
payload: ((string | number | boolean | {
|
|
934
|
+
[key: string]: _trigger_dev_core.DeserializedJson;
|
|
935
|
+
} | _trigger_dev_core.DeserializedJson[]) & (string | number | boolean | {
|
|
936
|
+
[key: string]: _trigger_dev_core.DeserializedJson;
|
|
937
|
+
} | _trigger_dev_core.DeserializedJson[] | undefined)) | null;
|
|
938
|
+
timestamp: Date;
|
|
939
|
+
context?: _trigger_dev_core.DeserializedJson | undefined;
|
|
940
|
+
deliverAt?: Date | null | undefined;
|
|
941
|
+
deliveredAt?: Date | null | undefined;
|
|
942
|
+
cancelledAt?: Date | null | undefined;
|
|
943
|
+
}>;
|
|
944
|
+
updateSource(key: string | any[], options: {
|
|
945
|
+
key: string;
|
|
946
|
+
} & UpdateTriggerSourceBodyV2): Promise<{
|
|
947
|
+
id: string;
|
|
948
|
+
key: string;
|
|
949
|
+
}>;
|
|
950
|
+
/** `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.
|
|
951
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
952
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
953
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
954
|
+
* @param options The options for the interval.
|
|
955
|
+
* @returns A promise that has information about the interval.
|
|
956
|
+
*/
|
|
957
|
+
registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
|
|
958
|
+
id: string;
|
|
959
|
+
schedule: {
|
|
960
|
+
options: {
|
|
961
|
+
cron: string;
|
|
962
|
+
};
|
|
963
|
+
type: "cron";
|
|
964
|
+
metadata?: any;
|
|
965
|
+
} | {
|
|
966
|
+
options: {
|
|
967
|
+
seconds: number;
|
|
968
|
+
};
|
|
969
|
+
type: "interval";
|
|
970
|
+
metadata?: any;
|
|
971
|
+
};
|
|
972
|
+
active: boolean;
|
|
973
|
+
metadata?: any;
|
|
974
|
+
}>;
|
|
975
|
+
/** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
|
|
976
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
977
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
978
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
979
|
+
*/
|
|
980
|
+
unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
|
|
981
|
+
ok: boolean;
|
|
982
|
+
}>;
|
|
983
|
+
/** `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.
|
|
984
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
985
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
986
|
+
* @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
|
|
987
|
+
* @param options The options for the CRON schedule.
|
|
988
|
+
*/
|
|
989
|
+
registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
|
|
990
|
+
id: string;
|
|
991
|
+
schedule: {
|
|
992
|
+
options: {
|
|
993
|
+
cron: string;
|
|
994
|
+
};
|
|
995
|
+
type: "cron";
|
|
996
|
+
metadata?: any;
|
|
997
|
+
} | {
|
|
998
|
+
options: {
|
|
999
|
+
seconds: number;
|
|
1000
|
+
};
|
|
1001
|
+
type: "interval";
|
|
1002
|
+
metadata?: any;
|
|
1003
|
+
};
|
|
1004
|
+
active: boolean;
|
|
1005
|
+
metadata?: any;
|
|
1006
|
+
}>;
|
|
1007
|
+
/** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
|
|
1008
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1009
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
1010
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1011
|
+
*/
|
|
1012
|
+
unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
|
|
1013
|
+
ok: boolean;
|
|
1014
|
+
}>;
|
|
1015
|
+
/** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
|
|
1016
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1017
|
+
* @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
|
|
1018
|
+
* @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
|
|
1019
|
+
* @param params The params for the trigger.
|
|
1020
|
+
*/
|
|
1021
|
+
registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
|
|
1022
|
+
id: string;
|
|
1023
|
+
key: string;
|
|
1024
|
+
} | undefined>;
|
|
1025
|
+
getAuth(key: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
|
|
1026
|
+
/** `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.
|
|
1027
|
+
*
|
|
1028
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1029
|
+
* @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
|
|
1030
|
+
* @param options The options of how you'd like to run and log the Task.
|
|
1031
|
+
* @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.
|
|
1032
|
+
* @returns A Promise that resolves with the returned value of the callback.
|
|
1033
|
+
*/
|
|
1034
|
+
runTask<T extends Json<T> | void>(key: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
|
|
1035
|
+
/** `io.try()` allows you to run Tasks and catch any errors that are thrown, it's similar to a normal `try/catch` block but works with [io.runTask()](/sdk/io/runtask).
|
|
1036
|
+
* 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.
|
|
1037
|
+
* @param tryCallback The code you wish to run
|
|
1038
|
+
* @param catchCallback Thhis will be called if the Task fails. The callback receives the error
|
|
1039
|
+
* @returns A Promise that resolves with the returned value or the error
|
|
1040
|
+
*/
|
|
1041
|
+
try<TResult, TCatchResult>(tryCallback: () => Promise<TResult>, catchCallback: (error: unknown) => Promise<TCatchResult>): Promise<TResult | TCatchResult>;
|
|
1042
|
+
}
|
|
1043
|
+
type CallbackFunction = (level: "DEBUG" | "INFO" | "WARN" | "ERROR" | "LOG", message: string, properties?: Record<string, any>) => Promise<void>;
|
|
1044
|
+
declare class IOLogger implements TaskLogger {
|
|
1045
|
+
private callback;
|
|
1046
|
+
constructor(callback: CallbackFunction);
|
|
1047
|
+
/** Log: essential messages */
|
|
1048
|
+
log(message: string, properties?: Record<string, any>): Promise<void>;
|
|
1049
|
+
/** For debugging: the least important log level */
|
|
1050
|
+
debug(message: string, properties?: Record<string, any>): Promise<void>;
|
|
1051
|
+
/** Info: the second least important log level */
|
|
1052
|
+
info(message: string, properties?: Record<string, any>): Promise<void>;
|
|
1053
|
+
/** Warnings: the third most important log level */
|
|
1054
|
+
warn(message: string, properties?: Record<string, any>): Promise<void>;
|
|
1055
|
+
/** Error: The second most important log level */
|
|
1056
|
+
error(message: string, properties?: Record<string, any>): Promise<void>;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
interface TriggerIntegration {
|
|
1060
|
+
id: string;
|
|
1061
|
+
metadata: IntegrationMetadata;
|
|
1062
|
+
authSource: "LOCAL" | "HOSTED";
|
|
1063
|
+
cloneForRun: (io: IO, connectionKey: string, auth?: ConnectionAuth) => TriggerIntegration;
|
|
1064
|
+
}
|
|
1065
|
+
type IOWithIntegrations<TIntegrations extends Record<string, TriggerIntegration>> = IO & TIntegrations;
|
|
1066
|
+
type IntegrationTaskKey = string | any[];
|
|
1067
|
+
|
|
1068
|
+
type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> = {
|
|
1069
|
+
/** The `id` property is used to uniquely identify the Job. Only change this if you want to create a new Job. */
|
|
1070
|
+
id: string;
|
|
1071
|
+
/** The `name` of the Job that you want to appear in the dashboard and logs. You can change this without creating a new Job. */
|
|
1072
|
+
name: string;
|
|
1073
|
+
/** The `version` property is used to version your Job. A new version will be created if you change this property. We recommend using [semantic versioning](https://www.baeldung.com/cs/semantic-versioning), e.g. `1.0.3`. */
|
|
1074
|
+
version: string;
|
|
1075
|
+
/** The `trigger` property is used to define when the Job should run. There are currently the following Trigger types:
|
|
1076
|
+
- [cronTrigger](https://trigger.dev/docs/sdk/crontrigger)
|
|
1077
|
+
- [intervalTrigger](https://trigger.dev/docs/sdk/intervaltrigger)
|
|
1078
|
+
- [eventTrigger](https://trigger.dev/docs/sdk/eventtrigger)
|
|
1079
|
+
- [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger)
|
|
1080
|
+
- [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule)
|
|
1081
|
+
- integration Triggers, like webhooks. See the [integrations](https://trigger.dev/docs/integrations) page for more information. */
|
|
1082
|
+
trigger: TTrigger;
|
|
1083
|
+
/** The `logLevel` property is an optional property that specifies the level of
|
|
1084
|
+
logging for the Job. The level is inherited from the client if you omit this property. */
|
|
1085
|
+
logLevel?: LogLevel;
|
|
1086
|
+
/** Imports the specified integrations into the Job. The integrations will be available on the `io` object in the `run()` function with the same name as the key. For example:
|
|
1087
|
+
```ts
|
|
1088
|
+
client.defineJob({
|
|
1089
|
+
//... other options
|
|
1090
|
+
integrations: {
|
|
1091
|
+
slack,
|
|
1092
|
+
gh: github,
|
|
1093
|
+
},
|
|
1094
|
+
run: async (payload, io, ctx) => {
|
|
1095
|
+
//slack is available on io.slack
|
|
1096
|
+
io.slack.postMessage(...);
|
|
1097
|
+
//github is available on io.gh
|
|
1098
|
+
io.gh.addIssueLabels(...);
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
``` */
|
|
1102
|
+
integrations?: TIntegrations;
|
|
1103
|
+
/** @deprecated This property is deprecated and no longer effects the execution of the Job
|
|
1104
|
+
* */
|
|
1105
|
+
queue?: QueueOptions | string;
|
|
1106
|
+
/** The `enabled` property is used to enable or disable the Job. If you disable a Job, it will not run. */
|
|
1107
|
+
enabled?: boolean;
|
|
1108
|
+
/** This function gets called automatically when a Run is Triggered.
|
|
1109
|
+
* This is where you put the code you want to run for a Job. You can use normal code in here and you can also use Tasks. You can return a value from this function and it will be sent back to the Trigger API.
|
|
1110
|
+
* @param payload The payload of the event
|
|
1111
|
+
* @param io An object that contains the integrations that you specified in the `integrations` property and other useful functions like delays and running Tasks.
|
|
1112
|
+
* @param context An object that contains information about the Organization, Job, Run and more.
|
|
1113
|
+
*/
|
|
1114
|
+
run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<any>;
|
|
1115
|
+
};
|
|
1116
|
+
type JobPayload<TJob> = TJob extends Job<Trigger<EventSpecification<infer TEvent>>, any> ? TEvent : never;
|
|
1117
|
+
type JobIO<TJob> = TJob extends Job<any, infer TIntegrations> ? IOWithIntegrations<TIntegrations> : never;
|
|
1118
|
+
/** A [Job](https://trigger.dev/docs/documentation/concepts/jobs) is used to define the [Trigger](https://trigger.dev/docs/documentation/concepts/triggers), metadata, and what happens when it runs. */
|
|
1119
|
+
declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}> {
|
|
1120
|
+
#private;
|
|
1121
|
+
readonly options: JobOptions<TTrigger, TIntegrations>;
|
|
1122
|
+
client: TriggerClient;
|
|
1123
|
+
constructor(
|
|
1124
|
+
/** An instance of [TriggerClient](/sdk/triggerclient) that is used to send events
|
|
1125
|
+
to the Trigger API. */
|
|
1126
|
+
client: TriggerClient, options: JobOptions<TTrigger, TIntegrations>);
|
|
1127
|
+
get id(): string;
|
|
1128
|
+
get enabled(): boolean;
|
|
1129
|
+
get name(): string;
|
|
1130
|
+
get trigger(): TTrigger;
|
|
1131
|
+
get version(): string;
|
|
1132
|
+
get integrations(): Record<string, IntegrationConfig>;
|
|
1133
|
+
get logLevel(): LogLevel | undefined;
|
|
1134
|
+
toJSON(): JobMetadata;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
type EventTriggerOptions<TEventSpecification extends EventSpecification<any>> = {
|
|
1138
|
+
event: TEventSpecification;
|
|
1139
|
+
name?: string | string[];
|
|
1140
|
+
source?: string;
|
|
1141
|
+
filter?: EventFilter;
|
|
1142
|
+
};
|
|
1143
|
+
declare class EventTrigger<TEventSpecification extends EventSpecification<any>> implements Trigger<TEventSpecification> {
|
|
1144
|
+
#private;
|
|
1145
|
+
constructor(options: EventTriggerOptions<TEventSpecification>);
|
|
1146
|
+
toJSON(): TriggerMetadata;
|
|
1147
|
+
get event(): TEventSpecification;
|
|
1148
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void;
|
|
1149
|
+
get preprocessRuns(): boolean;
|
|
1150
|
+
}
|
|
1151
|
+
/** Configuration options for an EventTrigger */
|
|
1152
|
+
type TriggerOptions<TEvent> = {
|
|
1153
|
+
/** The name of the event you are subscribing to. Must be an exact match (case sensitive). To trigger on multiple possible events, pass in an array of event names */
|
|
1154
|
+
name: string | string[];
|
|
1155
|
+
/** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
|
|
1156
|
+
* The default is `z.any()` which is `any`.
|
|
1157
|
+
* */
|
|
1158
|
+
schema?: z.Schema<TEvent>;
|
|
1159
|
+
/** You can use this to filter events based on the source. */
|
|
1160
|
+
source?: string;
|
|
1161
|
+
/** Used to filter which events trigger the Job
|
|
1162
|
+
* @example
|
|
1163
|
+
* filter:
|
|
1164
|
+
* ```ts
|
|
1165
|
+
* {
|
|
1166
|
+
* name: ["John", "Jane"],
|
|
1167
|
+
* age: [18, 21]
|
|
1168
|
+
* }
|
|
1169
|
+
* ```
|
|
1170
|
+
*
|
|
1171
|
+
* This filter would match against an event with the following data:
|
|
1172
|
+
* ```json
|
|
1173
|
+
* {
|
|
1174
|
+
* "name": "Jane",
|
|
1175
|
+
* "age": 18,
|
|
1176
|
+
* "location": "San Francisco"
|
|
1177
|
+
* }
|
|
1178
|
+
* ```
|
|
1179
|
+
*/
|
|
1180
|
+
filter?: EventFilter;
|
|
1181
|
+
examples?: EventSpecificationExample[];
|
|
1182
|
+
};
|
|
1183
|
+
/** `eventTrigger()` is set as a [Job's trigger](https://trigger.dev/docs/sdk/job) to subscribe to an event a Job from [a sent event](https://trigger.dev/docs/sdk/triggerclient/instancemethods/sendevent)
|
|
1184
|
+
* @param options options for the EventTrigger
|
|
1185
|
+
*/
|
|
1186
|
+
declare function eventTrigger<TEvent extends any = any>(options: TriggerOptions<TEvent>): Trigger<EventSpecification<TEvent>>;
|
|
1187
|
+
|
|
1188
|
+
declare function missingConnectionNotification(integrations: Array<TriggerIntegration>): MissingConnectionNotification;
|
|
1189
|
+
declare function missingConnectionResolvedNotification(integrations: Array<TriggerIntegration>): MissingConnectionResolvedNotification;
|
|
1190
|
+
type MissingConnectionNotificationSpecification = EventSpecification<MissingConnectionNotificationPayload>;
|
|
1191
|
+
type MissingConnectionNotificationOptions = {
|
|
1192
|
+
integrations: Array<TriggerIntegration>;
|
|
1193
|
+
};
|
|
1194
|
+
declare class MissingConnectionNotification implements Trigger<MissingConnectionNotificationSpecification> {
|
|
1195
|
+
private options;
|
|
1196
|
+
constructor(options: MissingConnectionNotificationOptions);
|
|
1197
|
+
get event(): {
|
|
1198
|
+
name: string;
|
|
1199
|
+
title: string;
|
|
1200
|
+
source: string;
|
|
1201
|
+
icon: string;
|
|
1202
|
+
parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
|
|
1203
|
+
id: string;
|
|
1204
|
+
type: "DEVELOPER";
|
|
1205
|
+
client: {
|
|
1206
|
+
id: string;
|
|
1207
|
+
scopes: string[];
|
|
1208
|
+
title: string;
|
|
1209
|
+
createdAt: Date;
|
|
1210
|
+
updatedAt: Date;
|
|
1211
|
+
};
|
|
1212
|
+
authorizationUrl: string;
|
|
1213
|
+
} | {
|
|
1214
|
+
id: string;
|
|
1215
|
+
type: "EXTERNAL";
|
|
1216
|
+
account: {
|
|
1217
|
+
id: string;
|
|
1218
|
+
metadata?: any;
|
|
1219
|
+
};
|
|
1220
|
+
client: {
|
|
1221
|
+
id: string;
|
|
1222
|
+
scopes: string[];
|
|
1223
|
+
title: string;
|
|
1224
|
+
createdAt: Date;
|
|
1225
|
+
updatedAt: Date;
|
|
1226
|
+
};
|
|
1227
|
+
authorizationUrl: string;
|
|
1228
|
+
};
|
|
1229
|
+
properties: {
|
|
1230
|
+
label: string;
|
|
1231
|
+
text: string;
|
|
1232
|
+
}[];
|
|
1233
|
+
};
|
|
1234
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<MissingConnectionNotificationSpecification>, any>): void;
|
|
1235
|
+
get preprocessRuns(): boolean;
|
|
1236
|
+
toJSON(): TriggerMetadata;
|
|
1237
|
+
}
|
|
1238
|
+
type MissingConnectionResolvedNotificationSpecification = EventSpecification<MissingConnectionResolvedNotificationPayload>;
|
|
1239
|
+
declare class MissingConnectionResolvedNotification implements Trigger<MissingConnectionResolvedNotificationSpecification> {
|
|
1240
|
+
private options;
|
|
1241
|
+
constructor(options: MissingConnectionNotificationOptions);
|
|
1242
|
+
get event(): {
|
|
1243
|
+
name: string;
|
|
1244
|
+
title: string;
|
|
1245
|
+
source: string;
|
|
1246
|
+
icon: string;
|
|
1247
|
+
parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
|
|
1248
|
+
id: string;
|
|
1249
|
+
type: "DEVELOPER";
|
|
1250
|
+
client: {
|
|
1251
|
+
id: string;
|
|
1252
|
+
scopes: string[];
|
|
1253
|
+
title: string;
|
|
1254
|
+
createdAt: Date;
|
|
1255
|
+
updatedAt: Date;
|
|
1256
|
+
integrationIdentifier: string;
|
|
1257
|
+
integrationAuthMethod: string;
|
|
1258
|
+
};
|
|
1259
|
+
expiresAt: Date;
|
|
1260
|
+
} | {
|
|
1261
|
+
id: string;
|
|
1262
|
+
type: "EXTERNAL";
|
|
1263
|
+
account: {
|
|
1264
|
+
id: string;
|
|
1265
|
+
metadata?: any;
|
|
1266
|
+
};
|
|
1267
|
+
client: {
|
|
1268
|
+
id: string;
|
|
1269
|
+
scopes: string[];
|
|
1270
|
+
title: string;
|
|
1271
|
+
createdAt: Date;
|
|
1272
|
+
updatedAt: Date;
|
|
1273
|
+
integrationIdentifier: string;
|
|
1274
|
+
integrationAuthMethod: string;
|
|
1275
|
+
};
|
|
1276
|
+
expiresAt: Date;
|
|
1277
|
+
};
|
|
1278
|
+
properties: {
|
|
1279
|
+
label: string;
|
|
1280
|
+
text: string;
|
|
1281
|
+
}[];
|
|
1282
|
+
};
|
|
1283
|
+
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<MissingConnectionResolvedNotificationSpecification>, any>): void;
|
|
1284
|
+
get preprocessRuns(): boolean;
|
|
1285
|
+
toJSON(): TriggerMetadata;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
declare class ResumeWithTaskError {
|
|
1289
|
+
task: ServerTask;
|
|
1290
|
+
constructor(task: ServerTask);
|
|
1291
|
+
}
|
|
1292
|
+
declare class RetryWithTaskError {
|
|
1293
|
+
cause: ErrorWithStack;
|
|
1294
|
+
task: ServerTask;
|
|
1295
|
+
retryAt: Date;
|
|
1296
|
+
constructor(cause: ErrorWithStack, task: ServerTask, retryAt: Date);
|
|
1297
|
+
}
|
|
1298
|
+
declare class CanceledWithTaskError {
|
|
1299
|
+
task: ServerTask;
|
|
1300
|
+
constructor(task: ServerTask);
|
|
1301
|
+
}
|
|
1302
|
+
/** Use this function if you're using a `try/catch` block to catch errors.
|
|
1303
|
+
* It checks if a thrown error is a special internal error that you should ignore.
|
|
1304
|
+
* If this returns `true` then you must rethrow the error: `throw err;`
|
|
1305
|
+
* @param err The error to check
|
|
1306
|
+
* @returns `true` if the error is a Trigger Error, `false` otherwise.
|
|
1307
|
+
*/
|
|
1308
|
+
declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError;
|
|
1309
|
+
|
|
1310
|
+
declare const retry: {
|
|
1311
|
+
readonly standardBackoff: {
|
|
1312
|
+
readonly limit: 8;
|
|
1313
|
+
readonly factor: 1.8;
|
|
1314
|
+
readonly minTimeoutInMs: 500;
|
|
1315
|
+
readonly maxTimeoutInMs: 30000;
|
|
1316
|
+
readonly randomize: true;
|
|
1317
|
+
};
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
type Task = ServerTask;
|
|
1321
|
+
|
|
1322
|
+
type SentEvent = ApiEventLog;
|
|
1323
|
+
declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
|
|
1324
|
+
|
|
1325
|
+
export { CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventSpecification, EventSpecificationExample, EventTrigger, EventTypeFromSpecification, ExternalSource, ExternalSourceParams, ExternalSourceTrigger, ExternalSourceTriggerOptions, HandlerEvent, HttpSourceEvent, IO, IOLogger, IOOptions, IOTask, IOWithIntegrations, IntegrationTaskKey, IntervalTrigger, Job, JobIO, JobOptions, JobPayload, Json, MissingConnectionNotification, MissingConnectionResolvedNotification, PreprocessResults, RunTaskErrorCallback, SentEvent, Task, TaskLogger, Trigger, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerOptionRecord, TriggerPayload, TriggerPreprocessContext, cronTrigger, eventTrigger, intervalTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry };
|