@trigger.dev/sdk 2.0.0-next.4 → 2.0.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +184 -21
- package/dist/index.js +97 -64
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import * as zod from 'zod';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Represents different log levels.
|
|
6
|
+
* - `"log"`: Only essential messages.
|
|
7
|
+
* - `"error"`: Errors and essential messages.
|
|
8
|
+
* - `"warn"`: Warnings, Errors and essential messages.
|
|
9
|
+
* - `"info"`: Info, Warnings, Errors and essential messages.
|
|
10
|
+
* - `"debug"`: Everything.
|
|
11
|
+
*/
|
|
4
12
|
type LogLevel = "log" | "error" | "warn" | "info" | "debug";
|
|
5
13
|
declare class Logger {
|
|
6
14
|
#private;
|
|
7
15
|
constructor(name: string, level?: LogLevel, filteredKeys?: string[], jsonReplacer?: (key: string, value: unknown) => unknown);
|
|
8
16
|
filter(...keys: string[]): Logger;
|
|
17
|
+
static satisfiesLogLevel(logLevel: LogLevel, setLevel: LogLevel): boolean;
|
|
9
18
|
log(...args: any[]): void;
|
|
10
19
|
error(...args: any[]): void;
|
|
11
20
|
warn(...args: any[]): void;
|
|
@@ -733,17 +742,34 @@ declare const JobMetadataSchema: z.ZodObject<{
|
|
|
733
742
|
}>;
|
|
734
743
|
type JobMetadata = z.infer<typeof JobMetadataSchema>;
|
|
735
744
|
declare const RawEventSchema: z.ZodObject<{
|
|
736
|
-
|
|
745
|
+
/** The `name` property must exactly match any subscriptions you want to
|
|
746
|
+
trigger. */
|
|
737
747
|
name: z.ZodString;
|
|
738
|
-
|
|
748
|
+
/** The `payload` property will be sent to any matching Jobs and will appear
|
|
749
|
+
as the `payload` param of the `run()` function. You can leave this
|
|
750
|
+
parameter out if you just want to trigger a Job without any input data. */
|
|
739
751
|
payload: z.ZodAny;
|
|
752
|
+
/** The optional `context` property will be sent to any matching Jobs and will
|
|
753
|
+
be passed through as the `context.event.context` param of the `run()`
|
|
754
|
+
function. This is optional but can be useful if you want to pass through
|
|
755
|
+
some additional context to the Job. */
|
|
740
756
|
context: z.ZodOptional<z.ZodAny>;
|
|
741
|
-
|
|
757
|
+
/** The `id` property uniquely identify this particular event. If unset it
|
|
758
|
+
will be set automatically using `ulid`. */
|
|
759
|
+
id: z.ZodDefault<z.ZodString>;
|
|
760
|
+
/** This is optional, it defaults to the current timestamp. Usually you would
|
|
761
|
+
only set this if you have a timestamp that you wish to pass through, e.g.
|
|
762
|
+
you receive a timestamp from a service and you want the same timestamp to
|
|
763
|
+
be used in your Job. */
|
|
764
|
+
timestamp: z.ZodOptional<z.ZodDate>;
|
|
765
|
+
/** This is optional, it defaults to "trigger.dev". It can be useful to set
|
|
766
|
+
this as you can filter events using this in the `eventTrigger()`. */
|
|
767
|
+
source: z.ZodOptional<z.ZodString>;
|
|
742
768
|
}, "strip", z.ZodTypeAny, {
|
|
743
769
|
source?: string | undefined;
|
|
744
770
|
payload?: any;
|
|
745
771
|
context?: any;
|
|
746
|
-
timestamp?:
|
|
772
|
+
timestamp?: Date | undefined;
|
|
747
773
|
id: string;
|
|
748
774
|
name: string;
|
|
749
775
|
}, {
|
|
@@ -751,20 +777,30 @@ declare const RawEventSchema: z.ZodObject<{
|
|
|
751
777
|
source?: string | undefined;
|
|
752
778
|
payload?: any;
|
|
753
779
|
context?: any;
|
|
754
|
-
timestamp?:
|
|
780
|
+
timestamp?: Date | undefined;
|
|
755
781
|
name: string;
|
|
756
782
|
}>;
|
|
783
|
+
/** The event you wish to send to Trigger a Job */
|
|
757
784
|
type SendEvent = z.input<typeof RawEventSchema>;
|
|
785
|
+
/** Options to control the delivery of the event */
|
|
758
786
|
declare const SendEventOptionsSchema: z.ZodObject<{
|
|
759
|
-
|
|
787
|
+
/** An optional Date when you want the event to trigger Jobs. The event will
|
|
788
|
+
be sent to the platform immediately but won't be acted upon until the
|
|
789
|
+
specified time. */
|
|
790
|
+
deliverAt: z.ZodOptional<z.ZodDate>;
|
|
791
|
+
/** An optional number of seconds you want to wait for the event to trigger
|
|
792
|
+
any relevant Jobs. The event will be sent to the platform immediately but
|
|
793
|
+
won't be delivered until after the elapsed number of seconds. */
|
|
760
794
|
deliverAfter: z.ZodOptional<z.ZodNumber>;
|
|
795
|
+
/** This optional param will be used by Trigger.dev Connect, which
|
|
796
|
+
is coming soon. */
|
|
761
797
|
accountId: z.ZodOptional<z.ZodString>;
|
|
762
798
|
}, "strip", z.ZodTypeAny, {
|
|
763
|
-
deliverAt?:
|
|
799
|
+
deliverAt?: Date | undefined;
|
|
764
800
|
deliverAfter?: number | undefined;
|
|
765
801
|
accountId?: string | undefined;
|
|
766
802
|
}, {
|
|
767
|
-
deliverAt?:
|
|
803
|
+
deliverAt?: Date | undefined;
|
|
768
804
|
deliverAfter?: number | undefined;
|
|
769
805
|
accountId?: string | undefined;
|
|
770
806
|
}>;
|
|
@@ -1192,12 +1228,24 @@ declare const CreateRunBodySchema: z.ZodObject<{
|
|
|
1192
1228
|
preprocessRuns: boolean;
|
|
1193
1229
|
}>;
|
|
1194
1230
|
event: z.ZodObject<{
|
|
1231
|
+
/** The `id` of the event that was sent.
|
|
1232
|
+
*/
|
|
1195
1233
|
id: z.ZodString;
|
|
1234
|
+
/** The `name` of the event that was sent. */
|
|
1196
1235
|
name: z.ZodString;
|
|
1236
|
+
/** The `payload` of the event that was sent */
|
|
1197
1237
|
payload: z.ZodType<DeserializedJson, z.ZodTypeDef, DeserializedJson>;
|
|
1238
|
+
/** The `context` of the event that was sent. Is `undefined` if no context was
|
|
1239
|
+
set when sending the event. */
|
|
1198
1240
|
context: z.ZodNullable<z.ZodOptional<z.ZodType<DeserializedJson, z.ZodTypeDef, DeserializedJson>>>;
|
|
1241
|
+
/** The `timestamp` of the event that was sent */
|
|
1199
1242
|
timestamp: z.ZodDate;
|
|
1243
|
+
/** The timestamp when the event will be delivered to any matching Jobs. Is
|
|
1244
|
+
`undefined` if `deliverAt` or `deliverAfter` wasn't set when sending the
|
|
1245
|
+
event. */
|
|
1200
1246
|
deliverAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
1247
|
+
/** The timestamp when the event was delivered. Is `undefined` if `deliverAt`
|
|
1248
|
+
or `deliverAfter` were set when sending the event. */
|
|
1201
1249
|
deliveredAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
1202
1250
|
}, "strip", z.ZodTypeAny, {
|
|
1203
1251
|
context?: DeserializedJson | undefined;
|
|
@@ -1614,10 +1662,15 @@ declare const RunTaskOptionsSchema: z.ZodObject<{
|
|
|
1614
1662
|
style: "normal" | "minimal";
|
|
1615
1663
|
}>>;
|
|
1616
1664
|
retry: z.ZodOptional<z.ZodObject<{
|
|
1665
|
+
/** The maximum number of times to retry the request. */
|
|
1617
1666
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
1667
|
+
/** The exponential factor to use when calculating the next retry time. */
|
|
1618
1668
|
factor: z.ZodOptional<z.ZodNumber>;
|
|
1669
|
+
/** The minimum amount of time to wait before retrying the request. */
|
|
1619
1670
|
minTimeoutInMs: z.ZodOptional<z.ZodNumber>;
|
|
1671
|
+
/** The maximum amount of time to wait before retrying the request. */
|
|
1620
1672
|
maxTimeoutInMs: z.ZodOptional<z.ZodNumber>;
|
|
1673
|
+
/** Whether to randomize the retry time. */
|
|
1621
1674
|
randomize: z.ZodOptional<z.ZodBoolean>;
|
|
1622
1675
|
}, "strip", z.ZodTypeAny, {
|
|
1623
1676
|
limit?: number | undefined;
|
|
@@ -1946,10 +1999,15 @@ declare const RunTaskBodyInputSchema: z.ZodObject<z.extendShape<{
|
|
|
1946
1999
|
style: "normal" | "minimal";
|
|
1947
2000
|
}>>;
|
|
1948
2001
|
retry: z.ZodOptional<z.ZodObject<{
|
|
2002
|
+
/** The maximum number of times to retry the request. */
|
|
1949
2003
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
2004
|
+
/** The exponential factor to use when calculating the next retry time. */
|
|
1950
2005
|
factor: z.ZodOptional<z.ZodNumber>;
|
|
2006
|
+
/** The minimum amount of time to wait before retrying the request. */
|
|
1951
2007
|
minTimeoutInMs: z.ZodOptional<z.ZodNumber>;
|
|
2008
|
+
/** The maximum amount of time to wait before retrying the request. */
|
|
1952
2009
|
maxTimeoutInMs: z.ZodOptional<z.ZodNumber>;
|
|
2010
|
+
/** Whether to randomize the retry time. */
|
|
1953
2011
|
randomize: z.ZodOptional<z.ZodBoolean>;
|
|
1954
2012
|
}, "strip", z.ZodTypeAny, {
|
|
1955
2013
|
limit?: number | undefined;
|
|
@@ -2285,10 +2343,15 @@ declare const CompleteTaskBodyInputSchema: z.ZodObject<z.extendShape<Pick<z.exte
|
|
|
2285
2343
|
style: "normal" | "minimal";
|
|
2286
2344
|
}>>;
|
|
2287
2345
|
retry: z.ZodOptional<z.ZodObject<{
|
|
2346
|
+
/** The maximum number of times to retry the request. */
|
|
2288
2347
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
2348
|
+
/** The exponential factor to use when calculating the next retry time. */
|
|
2289
2349
|
factor: z.ZodOptional<z.ZodNumber>;
|
|
2350
|
+
/** The minimum amount of time to wait before retrying the request. */
|
|
2290
2351
|
minTimeoutInMs: z.ZodOptional<z.ZodNumber>;
|
|
2352
|
+
/** The maximum amount of time to wait before retrying the request. */
|
|
2291
2353
|
maxTimeoutInMs: z.ZodOptional<z.ZodNumber>;
|
|
2354
|
+
/** Whether to randomize the retry time. */
|
|
2292
2355
|
randomize: z.ZodOptional<z.ZodBoolean>;
|
|
2293
2356
|
}, "strip", z.ZodTypeAny, {
|
|
2294
2357
|
limit?: number | undefined;
|
|
@@ -3089,8 +3152,11 @@ declare const MissingConnectionResolvedNotificationPayloadSchema: z.ZodDiscrimin
|
|
|
3089
3152
|
}>]>;
|
|
3090
3153
|
type MissingConnectionResolvedNotificationPayload = z.infer<typeof MissingConnectionResolvedNotificationPayloadSchema>;
|
|
3091
3154
|
|
|
3155
|
+
/** The options for a fetch request */
|
|
3092
3156
|
declare const FetchRequestInitSchema: z.ZodObject<{
|
|
3157
|
+
/** The HTTP method to use for the request. */
|
|
3093
3158
|
method: z.ZodOptional<z.ZodString>;
|
|
3159
|
+
/** Any headers to send with the request. Note that you can use [redactString](https://trigger.dev/docs/sdk/redactString) to prevent sensitive information from being stored (e.g. in the logs), like API keys and tokens. */
|
|
3094
3160
|
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
3095
3161
|
__redactedString: z.ZodLiteral<true>;
|
|
3096
3162
|
strings: z.ZodArray<z.ZodString, "many">;
|
|
@@ -3104,6 +3170,7 @@ declare const FetchRequestInitSchema: z.ZodObject<{
|
|
|
3104
3170
|
strings: string[];
|
|
3105
3171
|
interpolations: string[];
|
|
3106
3172
|
}>]>>>;
|
|
3173
|
+
/** The body of the request. */
|
|
3107
3174
|
body: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<ArrayBuffer, z.ZodTypeDef, ArrayBuffer>]>>;
|
|
3108
3175
|
}, "strip", z.ZodTypeAny, {
|
|
3109
3176
|
method?: string | undefined;
|
|
@@ -3122,11 +3189,16 @@ declare const FetchRequestInitSchema: z.ZodObject<{
|
|
|
3122
3189
|
}> | undefined;
|
|
3123
3190
|
body?: string | ArrayBuffer | undefined;
|
|
3124
3191
|
}>;
|
|
3192
|
+
/** The options for a fetch request */
|
|
3125
3193
|
type FetchRequestInit = z.infer<typeof FetchRequestInitSchema>;
|
|
3126
3194
|
declare const FetchRetryOptionsSchema: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"strategy", [z.ZodObject<{
|
|
3195
|
+
/** The `headers` strategy retries the request using info from the response headers. */
|
|
3127
3196
|
strategy: z.ZodLiteral<"headers">;
|
|
3197
|
+
/** The header to use to determine the maximum number of times to retry the request. */
|
|
3128
3198
|
limitHeader: z.ZodString;
|
|
3199
|
+
/** The header to use to determine the number of remaining retries. */
|
|
3129
3200
|
remainingHeader: z.ZodString;
|
|
3201
|
+
/** The header to use to determine the time when the number of remaining retries will be reset. */
|
|
3130
3202
|
resetHeader: z.ZodString;
|
|
3131
3203
|
}, "strip", z.ZodTypeAny, {
|
|
3132
3204
|
strategy: "headers";
|
|
@@ -3145,6 +3217,7 @@ declare const FetchRetryOptionsSchema: z.ZodRecord<z.ZodString, z.ZodDiscriminat
|
|
|
3145
3217
|
maxTimeoutInMs: z.ZodOptional<z.ZodNumber>;
|
|
3146
3218
|
randomize: z.ZodOptional<z.ZodBoolean>;
|
|
3147
3219
|
}, {
|
|
3220
|
+
/** The `backoff` strategy retries the request with an exponential backoff. */
|
|
3148
3221
|
strategy: z.ZodLiteral<"backoff">;
|
|
3149
3222
|
}>, "strip", z.ZodTypeAny, {
|
|
3150
3223
|
limit?: number | undefined;
|
|
@@ -3161,8 +3234,17 @@ declare const FetchRetryOptionsSchema: z.ZodRecord<z.ZodString, z.ZodDiscriminat
|
|
|
3161
3234
|
randomize?: boolean | undefined;
|
|
3162
3235
|
strategy: "backoff";
|
|
3163
3236
|
}>]>>;
|
|
3237
|
+
/** An object where the key is a status code pattern and the value is a retrying strategy. Supported patterns are:
|
|
3238
|
+
- Specific status codes: 429
|
|
3239
|
+
- Ranges: 500-599
|
|
3240
|
+
- Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
3241
|
+
*/
|
|
3164
3242
|
type FetchRetryOptions = z.infer<typeof FetchRetryOptionsSchema>;
|
|
3165
3243
|
|
|
3244
|
+
type Prettify<T> = {
|
|
3245
|
+
[K in keyof T]: T[K];
|
|
3246
|
+
} & {};
|
|
3247
|
+
|
|
3166
3248
|
type ApiClientOptions = {
|
|
3167
3249
|
apiKey?: string;
|
|
3168
3250
|
apiUrl?: string;
|
|
@@ -3491,7 +3573,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration<Integration
|
|
|
3491
3573
|
source?: string | undefined;
|
|
3492
3574
|
payload?: any;
|
|
3493
3575
|
context?: any;
|
|
3494
|
-
timestamp?:
|
|
3576
|
+
timestamp?: Date | undefined;
|
|
3495
3577
|
name: string;
|
|
3496
3578
|
}[];
|
|
3497
3579
|
response?: {
|
|
@@ -3558,22 +3640,29 @@ declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExtern
|
|
|
3558
3640
|
}
|
|
3559
3641
|
|
|
3560
3642
|
type TriggerClientOptions = {
|
|
3643
|
+
/** The `id` property is used to uniquely identify the client.
|
|
3644
|
+
*/
|
|
3561
3645
|
id: string;
|
|
3562
|
-
|
|
3646
|
+
/** The `apiKey` property is the API Key for your Trigger.dev environment. We
|
|
3647
|
+
recommend using an environment variable to store your API Key. */
|
|
3563
3648
|
apiKey?: string;
|
|
3649
|
+
/** The `apiUrl` property is an optional property that specifies the API URL. You
|
|
3650
|
+
only need to specify this if you are not using Trigger.dev Cloud and are
|
|
3651
|
+
running your own Trigger.dev instance. */
|
|
3564
3652
|
apiUrl?: string;
|
|
3653
|
+
/** The `logLevel` property is an optional property that specifies the level of
|
|
3654
|
+
logging for the TriggerClient. The level is inherited by all Jobs that use this Client, unless they also specify a `logLevel`. */
|
|
3565
3655
|
logLevel?: LogLevel;
|
|
3656
|
+
/** Very verbose log messages, defaults to false. */
|
|
3657
|
+
verbose?: boolean;
|
|
3658
|
+
/** Default is unset and off. If set to true it will log to the server's console as well as the Trigger.dev platform */
|
|
3659
|
+
ioLogLocalEnabled?: boolean;
|
|
3566
3660
|
};
|
|
3567
|
-
|
|
3568
|
-
url: string;
|
|
3569
|
-
};
|
|
3661
|
+
/** 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). */
|
|
3570
3662
|
declare class TriggerClient {
|
|
3571
3663
|
#private;
|
|
3572
|
-
private _url;
|
|
3573
3664
|
id: string;
|
|
3574
|
-
|
|
3575
|
-
constructor(options: TriggerClientOptions);
|
|
3576
|
-
get url(): string;
|
|
3665
|
+
constructor(options: Prettify<TriggerClientOptions>);
|
|
3577
3666
|
handleRequest(request: Request): Promise<NormalizedResponse>;
|
|
3578
3667
|
attach(job: Job<Trigger<any>, any>): void;
|
|
3579
3668
|
attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
|
|
@@ -3614,6 +3703,8 @@ declare class TriggerClient {
|
|
|
3614
3703
|
type: "oauth2";
|
|
3615
3704
|
accessToken: string;
|
|
3616
3705
|
} | undefined>;
|
|
3706
|
+
/** 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()` from inside a `run()` function.
|
|
3707
|
+
*/
|
|
3617
3708
|
sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
|
|
3618
3709
|
context?: DeserializedJson | undefined;
|
|
3619
3710
|
deliverAt?: Date | null | undefined;
|
|
@@ -3772,6 +3863,8 @@ type IOOptions = {
|
|
|
3772
3863
|
context: TriggerContext;
|
|
3773
3864
|
logger?: Logger;
|
|
3774
3865
|
logLevel?: LogLevel;
|
|
3866
|
+
jobLogger?: Logger;
|
|
3867
|
+
jobLogLevel: LogLevel;
|
|
3775
3868
|
cachedTasks?: Array<CachedTask>;
|
|
3776
3869
|
};
|
|
3777
3870
|
declare class IO {
|
|
@@ -3780,13 +3873,36 @@ declare class IO {
|
|
|
3780
3873
|
private _apiClient;
|
|
3781
3874
|
private _triggerClient;
|
|
3782
3875
|
private _logger;
|
|
3876
|
+
private _jobLogger?;
|
|
3877
|
+
private _jobLogLevel;
|
|
3783
3878
|
private _cachedTasks;
|
|
3784
3879
|
private _taskStorage;
|
|
3785
3880
|
private _context;
|
|
3786
3881
|
constructor(options: IOOptions);
|
|
3882
|
+
/** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
|
|
3787
3883
|
get logger(): IOLogger;
|
|
3884
|
+
/** `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.
|
|
3885
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
3886
|
+
* @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
|
|
3887
|
+
*/
|
|
3788
3888
|
wait(key: string | any[], seconds: number): Promise<void>;
|
|
3889
|
+
/** `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.
|
|
3890
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
3891
|
+
* @param url The URL to fetch from.
|
|
3892
|
+
* @param requestInit The options for the request
|
|
3893
|
+
* @param retry The options for retrying the request if it fails
|
|
3894
|
+
* An object where the key is a status code pattern and the value is a retrying strategy.
|
|
3895
|
+
* Supported patterns are:
|
|
3896
|
+
* - Specific status codes: 429
|
|
3897
|
+
* - Ranges: 500-599
|
|
3898
|
+
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
3899
|
+
*/
|
|
3789
3900
|
backgroundFetch<TResponseData>(key: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
|
|
3901
|
+
/** `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).
|
|
3902
|
+
* @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
3903
|
+
* @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
|
|
3904
|
+
* @param options Options for sending the event.
|
|
3905
|
+
*/
|
|
3790
3906
|
sendEvent(key: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
|
|
3791
3907
|
context?: DeserializedJson | undefined;
|
|
3792
3908
|
deliverAt?: Date | null | undefined;
|
|
@@ -3856,13 +3972,19 @@ declare class IO {
|
|
|
3856
3972
|
} | undefined | void): Promise<TResult>;
|
|
3857
3973
|
try<TResult, TCatchResult>(tryCallback: () => Promise<TResult>, catchCallback: (error: unknown) => Promise<TCatchResult>): Promise<TResult | TCatchResult>;
|
|
3858
3974
|
}
|
|
3859
|
-
type CallbackFunction = (level: "DEBUG" | "INFO" | "WARN" | "ERROR", message: string, properties?: Record<string, any>) => Promise<void>;
|
|
3975
|
+
type CallbackFunction = (level: "DEBUG" | "INFO" | "WARN" | "ERROR" | "LOG", message: string, properties?: Record<string, any>) => Promise<void>;
|
|
3860
3976
|
declare class IOLogger implements TaskLogger {
|
|
3861
3977
|
private callback;
|
|
3862
3978
|
constructor(callback: CallbackFunction);
|
|
3979
|
+
/** Log: essential messages */
|
|
3980
|
+
log(message: string, properties?: Record<string, any>): Promise<void>;
|
|
3981
|
+
/** For debugging: the least important log level */
|
|
3863
3982
|
debug(message: string, properties?: Record<string, any>): Promise<void>;
|
|
3983
|
+
/** Info: the second least important log level */
|
|
3864
3984
|
info(message: string, properties?: Record<string, any>): Promise<void>;
|
|
3985
|
+
/** Warnings: the third most important log level */
|
|
3865
3986
|
warn(message: string, properties?: Record<string, any>): Promise<void>;
|
|
3987
|
+
/** Error: The second most important log level */
|
|
3866
3988
|
error(message: string, properties?: Record<string, any>): Promise<void>;
|
|
3867
3989
|
}
|
|
3868
3990
|
|
|
@@ -3916,28 +4038,69 @@ type ExtractIntegrations<TIntegrations extends Record<string, TriggerIntegration
|
|
|
3916
4038
|
type IOWithIntegrations<TIntegrations extends Record<string, TriggerIntegration<IntegrationClient<any, any>>>> = IO & ExtractIntegrations<TIntegrations>;
|
|
3917
4039
|
|
|
3918
4040
|
type JobOptions<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration<IntegrationClient<any, any>>> = {}> = {
|
|
4041
|
+
/** The `id` property is used to uniquely identify the Job. Only change this if you want to create a new Job. */
|
|
3919
4042
|
id: string;
|
|
4043
|
+
/** The `name` of the Job that you want to appear in the dashboard and logs. You can change this without creating a new Job. */
|
|
3920
4044
|
name: string;
|
|
4045
|
+
/** 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`. */
|
|
3921
4046
|
version: string;
|
|
4047
|
+
/** The `trigger` property is used to define when the Job should run. There are currently the following Trigger types:
|
|
4048
|
+
- [cronTrigger](https://trigger.dev/docs/sdk/crontrigger)
|
|
4049
|
+
- [intervalTrigger](https://trigger.dev/docs/sdk/intervaltrigger)
|
|
4050
|
+
- [eventTrigger](https://trigger.dev/docs/sdk/eventtrigger)
|
|
4051
|
+
- [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger)
|
|
4052
|
+
- [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule)
|
|
4053
|
+
- integration Triggers, like webhooks. See the [integrations](https://trigger.dev/docs/integrations) page for more information. */
|
|
3922
4054
|
trigger: TTrigger;
|
|
4055
|
+
/** The `logLevel` property is an optional property that specifies the level of
|
|
4056
|
+
logging for the Job. The level is inherited from the client if you omit this property. */
|
|
3923
4057
|
logLevel?: LogLevel;
|
|
4058
|
+
/** 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:
|
|
4059
|
+
```ts
|
|
4060
|
+
new Job(client, {
|
|
4061
|
+
//... other options
|
|
4062
|
+
integrations: {
|
|
4063
|
+
slack,
|
|
4064
|
+
gh: github,
|
|
4065
|
+
},
|
|
4066
|
+
run: async (payload, io, ctx) => {
|
|
4067
|
+
//slack is available on io.slack
|
|
4068
|
+
io.slack.postMessage(...);
|
|
4069
|
+
//github is available on io.gh
|
|
4070
|
+
io.gh.addIssueLabels(...);
|
|
4071
|
+
}
|
|
4072
|
+
});
|
|
4073
|
+
``` */
|
|
3924
4074
|
integrations?: TIntegrations;
|
|
4075
|
+
/** The `queue` property is used to specify a custom queue. If you use an Object and specify the `maxConcurrent` option, you can control how many simulataneous runs can happen. */
|
|
3925
4076
|
queue?: QueueOptions | string;
|
|
3926
4077
|
startPosition?: "initial" | "latest";
|
|
4078
|
+
/** The `enabled` property is used to enable or disable the Job. If you disable a Job, it will not run. */
|
|
3927
4079
|
enabled?: boolean;
|
|
3928
|
-
|
|
4080
|
+
/** This function gets called automatically when a Run is Triggered.
|
|
4081
|
+
* 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.
|
|
4082
|
+
* @param payload The payload of the event
|
|
4083
|
+
* @param io An object that contains the integrations that you specified in the `integrations` property and other useful functions like delays and running Tasks.
|
|
4084
|
+
* @param context An object that contains information about the Organization, Job, Run and more.
|
|
4085
|
+
*/
|
|
4086
|
+
run: (payload: TriggerEventType<TTrigger>, io: IOWithIntegrations<TIntegrations>, context: TriggerContext) => Promise<any>;
|
|
3929
4087
|
};
|
|
4088
|
+
/** 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. */
|
|
3930
4089
|
declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration<IntegrationClient<any, any>>> = {}> {
|
|
3931
4090
|
#private;
|
|
3932
4091
|
readonly options: JobOptions<TTrigger, TIntegrations>;
|
|
3933
4092
|
client: TriggerClient;
|
|
3934
|
-
constructor(
|
|
4093
|
+
constructor(
|
|
4094
|
+
/** An instance of [TriggerClient](/sdk/triggerclient) that is used to send events
|
|
4095
|
+
to the Trigger API. */
|
|
4096
|
+
client: TriggerClient, options: JobOptions<TTrigger, TIntegrations>);
|
|
3935
4097
|
get id(): string;
|
|
3936
4098
|
get enabled(): boolean;
|
|
3937
4099
|
get name(): string;
|
|
3938
4100
|
get trigger(): TTrigger;
|
|
3939
4101
|
get version(): string;
|
|
3940
4102
|
get integrations(): Record<string, IntegrationConfig>;
|
|
4103
|
+
get logLevel(): LogLevel | undefined;
|
|
3941
4104
|
toJSON(): JobMetadata;
|
|
3942
4105
|
}
|
|
3943
4106
|
|
|
@@ -4078,4 +4241,4 @@ declare function isTriggerError(err: unknown): err is ResumeWithTaskError | Retr
|
|
|
4078
4241
|
type Task = ServerTask;
|
|
4079
4242
|
declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
|
|
4080
4243
|
|
|
4081
|
-
export { AuthenticatedTask, ClientFactory, CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventFilter, EventSpecification, EventSpecificationExample, EventTrigger, EventTypeFromSpecification, ExternalSource, ExternalSourceParams, ExternalSourceTrigger, ExternalSourceTriggerOptions, HandlerEvent, HttpSourceEvent, IO, IOLogger, IOOptions, IOTask, IOWithIntegrations, IntegrationClient, IntervalTrigger, Job, JobOptions,
|
|
4244
|
+
export { AuthenticatedTask, ClientFactory, CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventFilter, EventSpecification, EventSpecificationExample, EventTrigger, EventTypeFromSpecification, ExternalSource, ExternalSourceParams, ExternalSourceTrigger, ExternalSourceTriggerOptions, HandlerEvent, HttpSourceEvent, IO, IOLogger, IOOptions, IOTask, IOWithIntegrations, IntegrationClient, IntervalTrigger, Job, JobOptions, Logger, MissingConnectionNotification, MissingConnectionResolvedNotification, NormalizedRequest, PreprocessResults, RedactString, Task, TaskLogger, Trigger, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerPreprocessContext, authenticatedTask, cronTrigger, eventTrigger, intervalTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString };
|