@trigger.dev/sdk 2.1.3 → 2.1.4

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 CHANGED
@@ -1,8 +1,7 @@
1
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, DeserializedJson, IntervalOptions, CronOptions, ScheduledPayload, ServerTask, CachedTask, FetchRequestInit, FetchRetryOptions, RunTaskOptions, IntegrationMetadata, QueueOptions, IntegrationConfig, JobMetadata, MissingConnectionNotificationPayload, MissingConnectionResolvedNotificationPayload, ErrorWithStack, ApiEventLog, RedactString } from '@trigger.dev/core';
2
+ import { RunTaskBodyInput, CompleteTaskBodyInput, FailTaskBodyInput, SendEvent, SendEventOptions, StatusUpdate, UpdateTriggerSourceBodyV2, TriggerSource, RegisterTriggerBodyV2, RegisterSourceEventV2, ScheduleMetadata, GetRunOptionsWithTaskDetails, GetRunsOptions, LogLevel, RuntimeEnvironmentType, DisplayProperty, TriggerMetadata, EventFilter, Prettify, HandleTriggerSource, Logger, RegisterTriggerSource, SerializableJson, ConnectionAuth, NormalizedResponse, HttpSourceResponseMetadata, IntervalOptions, CronOptions, ScheduledPayload, DeserializedJson, ServerTask, CachedTask, InitialStatusUpdate, FetchRequestInit, FetchRetryOptions, RunTaskOptions, IntegrationMetadata, QueueOptions, IntegrationConfig, JobMetadata, MissingConnectionNotificationPayload, MissingConnectionResolvedNotificationPayload, ErrorWithStack, ApiEventLog, RedactString } from '@trigger.dev/core';
3
3
  export { ConnectionAuth, DisplayProperty, EventFilter, Logger, NormalizedRequest, OverridableRunTaskOptions, Prettify, RedactString, RegisteredOptionsDiff, RunTaskOptions, SourceEventOption } from '@trigger.dev/core';
4
4
  import * as zod from 'zod';
5
- import { z } from 'zod';
6
5
 
7
6
  type ApiClientOptions = {
8
7
  apiKey?: string;
@@ -145,6 +144,17 @@ declare class ApiClient {
145
144
  deliveredAt?: Date | null | undefined;
146
145
  cancelledAt?: Date | null | undefined;
147
146
  }>;
147
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
148
+ label: string;
149
+ key: string;
150
+ history: {
151
+ label?: string | undefined;
152
+ state?: "loading" | "success" | "failure" | undefined;
153
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
154
+ }[];
155
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
156
+ state?: "loading" | "success" | "failure" | undefined;
157
+ }>;
148
158
  updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
149
159
  registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2): Promise<RegisterSourceEventV2>;
150
160
  registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
@@ -154,12 +164,14 @@ declare class ApiClient {
154
164
  cron: string;
155
165
  };
156
166
  type: "cron";
167
+ accountId?: string | undefined;
157
168
  metadata?: any;
158
169
  } | {
159
170
  options: {
160
171
  seconds: number;
161
172
  };
162
173
  type: "interval";
174
+ accountId?: string | undefined;
163
175
  metadata?: any;
164
176
  };
165
177
  active: boolean;
@@ -169,7 +181,7 @@ declare class ApiClient {
169
181
  ok: boolean;
170
182
  }>;
171
183
  getAuth(client: string, id: string): Promise<{
172
- type: "oauth2";
184
+ type: "oauth2" | "apiKey";
173
185
  accessToken: string;
174
186
  scopes?: string[] | undefined;
175
187
  additionalFields?: Record<string, string> | undefined;
@@ -177,31 +189,60 @@ declare class ApiClient {
177
189
  getEvent(eventId: string): Promise<{
178
190
  id: string;
179
191
  name: string;
180
- createdAt: Date;
181
192
  updatedAt: Date;
182
193
  runs: {
183
194
  id: string;
184
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
195
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
185
196
  startedAt?: Date | null | undefined;
186
197
  completedAt?: Date | null | undefined;
187
198
  }[];
199
+ createdAt: Date;
188
200
  }>;
189
201
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
190
202
  id: string;
191
203
  startedAt: Date | null;
192
204
  completedAt: Date | null;
193
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
194
- tasks: _trigger_dev_core.RunTaskWithSubtasks[];
205
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
195
206
  updatedAt: Date | null;
207
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
196
208
  output?: any;
209
+ statuses?: {
210
+ label: string;
211
+ key: string;
212
+ history: {
213
+ label?: string | undefined;
214
+ state?: "loading" | "success" | "failure" | undefined;
215
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
216
+ }[];
217
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
218
+ state?: "loading" | "success" | "failure" | undefined;
219
+ }[] | undefined;
197
220
  nextCursor?: string | undefined;
198
221
  }>;
222
+ getRunStatuses(runId: string): Promise<{
223
+ statuses: {
224
+ label: string;
225
+ key: string;
226
+ history: {
227
+ label?: string | undefined;
228
+ state?: "loading" | "success" | "failure" | undefined;
229
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
230
+ }[];
231
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
232
+ state?: "loading" | "success" | "failure" | undefined;
233
+ }[];
234
+ run: {
235
+ id: string;
236
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
237
+ output?: any;
238
+ };
239
+ }>;
199
240
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
200
241
  runs: {
201
242
  id: string;
202
243
  startedAt: Date | null;
203
244
  completedAt: Date | null;
204
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
245
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
205
246
  updatedAt: Date | null;
206
247
  }[];
207
248
  nextCursor?: string | undefined;
@@ -318,6 +359,22 @@ interface EventSpecification<TEvent extends any> {
318
359
  runProperties?: (payload: TEvent) => DisplayProperty[];
319
360
  }
320
361
  type EventTypeFromSpecification<TEventSpec extends EventSpecification<any>> = TEventSpec extends EventSpecification<infer TEvent> ? TEvent : never;
362
+ type SchemaParserIssue = {
363
+ path: PropertyKey[];
364
+ message: string;
365
+ };
366
+ type SchemaParserResult<T> = {
367
+ success: true;
368
+ data: T;
369
+ } | {
370
+ success: false;
371
+ error: {
372
+ issues: SchemaParserIssue[];
373
+ };
374
+ };
375
+ type SchemaParser<T extends unknown = unknown> = {
376
+ safeParse: (a: unknown) => SchemaParserResult<T>;
377
+ };
321
378
 
322
379
  type HttpSourceEvent = {
323
380
  url: string;
@@ -402,8 +459,8 @@ type FilterFunction<TParams extends any, TTriggerOptionDefinitions extends Recor
402
459
  type ExternalSourceOptions<TChannel extends ChannelNames, TIntegration extends TriggerIntegration, TParams extends any, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
403
460
  id: string;
404
461
  version: string;
405
- schema: z.Schema<TParams>;
406
- optionSchema?: z.Schema<TTriggerOptionDefinitions>;
462
+ schema: SchemaParser<TParams>;
463
+ optionSchema?: SchemaParser<TTriggerOptionDefinitions>;
407
464
  integration: TIntegration;
408
465
  register: RegisterFunction<TIntegration, TParams, TChannel, TTriggerOptionDefinitions>;
409
466
  filter?: FilterFunction<TParams, TTriggerOptionDefinitions>;
@@ -447,9 +504,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration, TParams ex
447
504
  get id(): string;
448
505
  get version(): string;
449
506
  }
450
- type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams & {
451
- filter?: EventFilter;
452
- } : never;
507
+ type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams : never;
453
508
  type ExternalSourceTriggerOptions<TEventSpecification extends EventSpecification<any>, TEventSource extends ExternalSource<any, any, any>, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
454
509
  event: TEventSpecification;
455
510
  source: TEventSource;
@@ -480,7 +535,7 @@ type DynamicTriggerOptions<TEventSpec extends EventSpecification<any>, TExternal
480
535
  * ```ts
481
536
  * import { events } from "@trigger.dev/github";
482
537
  *
483
- * const dynamicOnIssueOpened = new DynamicTrigger(client, {
538
+ * const dynamicOnIssueOpened = client.defineDynamicTrigger({
484
539
  id: "github-issue-opened",
485
540
  event: events.onIssueOpened,
486
541
  source: github.sources.repo,
@@ -501,16 +556,154 @@ declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExtern
501
556
  toJSON(): TriggerMetadata;
502
557
  get id(): string;
503
558
  get event(): TEventSpec;
504
- registeredTriggerForParams(params: ExternalSourceParams<TExternalSource>): RegisterTriggerBodyV2;
505
559
  /** Use this method to register a new configuration with the DynamicTrigger.
506
560
  * @param key The key for the configuration. This will be used to identify the configuration when it is triggered.
507
561
  * @param params The params for the configuration.
562
+ * @param options Options for the configuration.
563
+ * @param options.accountId The accountId to associate with the configuration.
564
+ * @param options.filter The filter to use for the configuration.
565
+ *
508
566
  */
509
- register(key: string, params: ExternalSourceParams<TExternalSource>): Promise<RegisterSourceEventV2>;
567
+ register(key: string, params: ExternalSourceParams<TExternalSource>, options?: {
568
+ accountId?: string;
569
+ filter?: EventFilter;
570
+ }): Promise<RegisterSourceEventV2>;
510
571
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
511
572
  get preprocessRuns(): boolean;
512
573
  }
513
574
 
575
+ type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
576
+ declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
577
+ private options;
578
+ constructor(options: IntervalOptions);
579
+ get event(): {
580
+ name: string;
581
+ title: string;
582
+ source: string;
583
+ icon: string;
584
+ examples: {
585
+ id: string;
586
+ name: string;
587
+ icon: string;
588
+ payload: {
589
+ ts: string;
590
+ lastTimestamp: string;
591
+ };
592
+ }[];
593
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
594
+ ts: Date;
595
+ lastTimestamp?: Date | undefined;
596
+ };
597
+ properties: {
598
+ label: string;
599
+ text: string;
600
+ }[];
601
+ };
602
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
603
+ get preprocessRuns(): boolean;
604
+ toJSON(): TriggerMetadata;
605
+ }
606
+ /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
607
+ * @param options An object containing options about the interval.
608
+ */
609
+ declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
610
+ declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
611
+ private options;
612
+ constructor(options: CronOptions);
613
+ get event(): {
614
+ name: string;
615
+ title: string;
616
+ source: string;
617
+ icon: string;
618
+ examples: {
619
+ id: string;
620
+ name: string;
621
+ icon: string;
622
+ payload: {
623
+ ts: string;
624
+ lastTimestamp: string;
625
+ };
626
+ }[];
627
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
628
+ ts: Date;
629
+ lastTimestamp?: Date | undefined;
630
+ };
631
+ properties: {
632
+ label: string;
633
+ text: string;
634
+ }[];
635
+ };
636
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
637
+ get preprocessRuns(): boolean;
638
+ toJSON(): TriggerMetadata;
639
+ }
640
+ /** `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.
641
+ * @param options An object containing options about the CRON schedule.
642
+ */
643
+ declare function cronTrigger(options: CronOptions): CronTrigger;
644
+ /** DynamicSchedule options
645
+ * @param id Used to uniquely identify a DynamicSchedule
646
+ */
647
+ type DynamicIntervalOptions = {
648
+ id: string;
649
+ };
650
+ /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
651
+ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
652
+ private client;
653
+ private options;
654
+ /**
655
+ * @param client The `TriggerClient` instance to use for registering the trigger.
656
+ * @param options The options for the schedule.
657
+ */
658
+ constructor(client: TriggerClient, options: DynamicIntervalOptions);
659
+ get id(): string;
660
+ get event(): {
661
+ name: string;
662
+ title: string;
663
+ source: string;
664
+ icon: string;
665
+ examples: {
666
+ id: string;
667
+ name: string;
668
+ icon: string;
669
+ payload: {
670
+ ts: string;
671
+ lastTimestamp: string;
672
+ };
673
+ }[];
674
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
675
+ ts: Date;
676
+ lastTimestamp?: Date | undefined;
677
+ };
678
+ };
679
+ register(key: string, metadata: ScheduleMetadata): Promise<{
680
+ id: string;
681
+ schedule: {
682
+ options: {
683
+ cron: string;
684
+ };
685
+ type: "cron";
686
+ accountId?: string | undefined;
687
+ metadata?: any;
688
+ } | {
689
+ options: {
690
+ seconds: number;
691
+ };
692
+ type: "interval";
693
+ accountId?: string | undefined;
694
+ metadata?: any;
695
+ };
696
+ active: boolean;
697
+ metadata?: any;
698
+ }>;
699
+ unregister(key: string): Promise<{
700
+ ok: boolean;
701
+ }>;
702
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
703
+ get preprocessRuns(): boolean;
704
+ toJSON(): TriggerMetadata;
705
+ }
706
+
514
707
  type TriggerClientOptions = {
515
708
  /** The `id` property is used to uniquely identify the client.
516
709
  */
@@ -530,12 +723,22 @@ type TriggerClientOptions = {
530
723
  /** Default is unset and off. If set to true it will log to the server's console as well as the Trigger.dev platform */
531
724
  ioLogLocalEnabled?: boolean;
532
725
  };
726
+ type AuthResolverResult = {
727
+ type: "apiKey" | "oauth";
728
+ token: string;
729
+ additionalFields?: Record<string, string>;
730
+ };
731
+ type TriggerAuthResolver = (ctx: TriggerContext, integration: TriggerIntegration) => Promise<AuthResolverResult | void | undefined>;
533
732
  /** 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). */
534
733
  declare class TriggerClient {
535
734
  #private;
536
735
  id: string;
537
736
  constructor(options: Prettify<TriggerClientOptions>);
538
737
  handleRequest(request: Request): Promise<NormalizedResponse>;
738
+ defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
739
+ defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
740
+ defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
741
+ defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
539
742
  attach(job: Job<Trigger<any>, any>): void;
540
743
  attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
541
744
  attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
@@ -546,7 +749,8 @@ declare class TriggerClient {
546
749
  params: any;
547
750
  options?: Record<string, string[]>;
548
751
  }): void;
549
- attachDynamicSchedule(key: string, job: Job<Trigger<any>, any>): void;
752
+ attachDynamicSchedule(key: string): void;
753
+ attachDynamicScheduleToJob(key: string, job: Job<Trigger<any>, any>): void;
550
754
  registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
551
755
  id: string;
552
756
  options: {
@@ -579,7 +783,7 @@ declare class TriggerClient {
579
783
  dynamicTriggerId?: string | undefined;
580
784
  }>;
581
785
  getAuth(id: string): Promise<{
582
- type: "oauth2";
786
+ type: "oauth2" | "apiKey";
583
787
  accessToken: string;
584
788
  scopes?: string[] | undefined;
585
789
  additionalFields?: Record<string, string> | undefined;
@@ -617,6 +821,17 @@ declare class TriggerClient {
617
821
  deliveredAt?: Date | null | undefined;
618
822
  cancelledAt?: Date | null | undefined;
619
823
  }>;
824
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
825
+ label: string;
826
+ key: string;
827
+ history: {
828
+ label?: string | undefined;
829
+ state?: "loading" | "success" | "failure" | undefined;
830
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
831
+ }[];
832
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
833
+ state?: "loading" | "success" | "failure" | undefined;
834
+ }>;
620
835
  registerSchedule(id: string, key: string, schedule: ScheduleMetadata): Promise<{
621
836
  id: string;
622
837
  schedule: {
@@ -624,12 +839,14 @@ declare class TriggerClient {
624
839
  cron: string;
625
840
  };
626
841
  type: "cron";
842
+ accountId?: string | undefined;
627
843
  metadata?: any;
628
844
  } | {
629
845
  options: {
630
846
  seconds: number;
631
847
  };
632
848
  type: "interval";
849
+ accountId?: string | undefined;
633
850
  metadata?: any;
634
851
  };
635
852
  active: boolean;
@@ -641,23 +858,34 @@ declare class TriggerClient {
641
858
  getEvent(eventId: string): Promise<{
642
859
  id: string;
643
860
  name: string;
644
- createdAt: Date;
645
861
  updatedAt: Date;
646
862
  runs: {
647
863
  id: string;
648
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
864
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
649
865
  startedAt?: Date | null | undefined;
650
866
  completedAt?: Date | null | undefined;
651
867
  }[];
868
+ createdAt: Date;
652
869
  }>;
653
870
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
654
871
  id: string;
655
872
  startedAt: Date | null;
656
873
  completedAt: Date | null;
657
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
658
- tasks: _trigger_dev_core.RunTaskWithSubtasks[];
874
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
659
875
  updatedAt: Date | null;
876
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
660
877
  output?: any;
878
+ statuses?: {
879
+ label: string;
880
+ key: string;
881
+ history: {
882
+ label?: string | undefined;
883
+ state?: "loading" | "success" | "failure" | undefined;
884
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
885
+ }[];
886
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
887
+ state?: "loading" | "success" | "failure" | undefined;
888
+ }[] | undefined;
661
889
  nextCursor?: string | undefined;
662
890
  }>;
663
891
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
@@ -665,144 +893,48 @@ declare class TriggerClient {
665
893
  id: string;
666
894
  startedAt: Date | null;
667
895
  completedAt: Date | null;
668
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
896
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
669
897
  updatedAt: Date | null;
670
898
  }[];
671
899
  nextCursor?: string | undefined;
672
900
  }>;
673
- authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
674
- apiKey(): string | undefined;
675
- defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
676
- }
677
-
678
- type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
679
- declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
680
- private options;
681
- constructor(options: IntervalOptions);
682
- get event(): {
683
- name: string;
684
- title: string;
685
- source: string;
686
- icon: string;
687
- examples: {
688
- id: string;
689
- name: string;
690
- icon: string;
691
- payload: {
692
- ts: string;
693
- lastTimestamp: string;
694
- };
695
- }[];
696
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
697
- ts: Date;
698
- lastTimestamp?: Date | undefined;
699
- };
700
- properties: {
901
+ getRunStatuses(runId: string): Promise<{
902
+ statuses: {
701
903
  label: string;
702
- text: string;
904
+ key: string;
905
+ history: {
906
+ label?: string | undefined;
907
+ state?: "loading" | "success" | "failure" | undefined;
908
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
909
+ }[];
910
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
911
+ state?: "loading" | "success" | "failure" | undefined;
703
912
  }[];
704
- };
705
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
706
- get preprocessRuns(): boolean;
707
- toJSON(): TriggerMetadata;
708
- }
709
- /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
710
- * @param options An object containing options about the interval.
711
- */
712
- declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
713
- declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
714
- private options;
715
- constructor(options: CronOptions);
716
- get event(): {
717
- name: string;
718
- title: string;
719
- source: string;
720
- icon: string;
721
- examples: {
913
+ run: {
722
914
  id: string;
723
- name: string;
724
- icon: string;
725
- payload: {
726
- ts: string;
727
- lastTimestamp: string;
728
- };
729
- }[];
730
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
731
- ts: Date;
732
- lastTimestamp?: Date | undefined;
915
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
916
+ output?: any;
733
917
  };
734
- properties: {
735
- label: string;
736
- text: string;
737
- }[];
738
- };
739
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
740
- get preprocessRuns(): boolean;
741
- toJSON(): TriggerMetadata;
918
+ }>;
919
+ authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
920
+ apiKey(): string | undefined;
742
921
  }
743
- /** `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.
744
- * @param options An object containing options about the CRON schedule.
745
- */
746
- declare function cronTrigger(options: CronOptions): CronTrigger;
747
- /** DynamicSchedule options
748
- * @param id Used to uniquely identify a DynamicSchedule
749
- */
750
- type DynamicIntervalOptions = {
751
- id: string;
752
- };
753
- /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
754
- declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
755
- private client;
756
- private options;
757
- /**
758
- * @param client The `TriggerClient` instance to use for registering the trigger.
759
- * @param options The options for the schedule.
760
- */
761
- constructor(client: TriggerClient, options: DynamicIntervalOptions);
762
- get id(): string;
763
- get event(): {
764
- name: string;
765
- title: string;
766
- source: string;
767
- icon: string;
768
- examples: {
769
- id: string;
770
- name: string;
771
- icon: string;
772
- payload: {
773
- ts: string;
774
- lastTimestamp: string;
775
- };
922
+
923
+ declare class TriggerStatus {
924
+ private id;
925
+ private io;
926
+ constructor(id: string, io: IO);
927
+ update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
928
+ label: string;
929
+ key: string;
930
+ history: {
931
+ label?: string | undefined;
932
+ state?: "loading" | "success" | "failure" | undefined;
933
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
776
934
  }[];
777
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
778
- ts: Date;
779
- lastTimestamp?: Date | undefined;
780
- };
781
- };
782
- register(key: string, metadata: ScheduleMetadata): Promise<{
783
- id: string;
784
- schedule: {
785
- options: {
786
- cron: string;
787
- };
788
- type: "cron";
789
- metadata?: any;
790
- } | {
791
- options: {
792
- seconds: number;
793
- };
794
- type: "interval";
795
- metadata?: any;
796
- };
797
- active: boolean;
798
- metadata?: any;
799
- }>;
800
- unregister(key: string): Promise<{
801
- ok: boolean;
935
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
936
+ state?: "loading" | "success" | "failure" | undefined;
802
937
  }>;
803
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
804
- get preprocessRuns(): boolean;
805
- toJSON(): TriggerMetadata;
806
938
  }
807
939
 
808
940
  type IOTask = ServerTask;
@@ -824,9 +956,10 @@ type JsonRecord<T> = {
824
956
  };
825
957
  type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
826
958
  type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
827
- retryAt: Date;
959
+ retryAt?: Date;
828
960
  error?: Error;
829
961
  jitter?: number;
962
+ skipRetrying?: boolean;
830
963
  } | Error | undefined | void;
831
964
  declare class IO {
832
965
  #private;
@@ -847,6 +980,39 @@ declare class IO {
847
980
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
848
981
  */
849
982
  wait(key: string | any[], seconds: number): Promise<void>;
983
+ /** `io.createStatus()` allows you to set a status with associated data during the Run. Statuses can be used by your UI using the react package
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 initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
986
+ * @returns a TriggerStatus object that you can call `update()` on, to update the status.
987
+ * @example
988
+ * ```ts
989
+ * client.defineJob(
990
+ //...
991
+ run: async (payload, io, ctx) => {
992
+ const generatingImages = await io.createStatus("generating-images", {
993
+ label: "Generating Images",
994
+ state: "loading",
995
+ data: {
996
+ progress: 0.1,
997
+ },
998
+ });
999
+
1000
+ //...do stuff
1001
+
1002
+ await generatingImages.update("completed-generation", {
1003
+ label: "Generated images",
1004
+ state: "success",
1005
+ data: {
1006
+ progress: 1.0,
1007
+ urls: ["http://..."]
1008
+ },
1009
+ });
1010
+
1011
+ //...
1012
+ });
1013
+ * ```
1014
+ */
1015
+ createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
850
1016
  /** `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.
851
1017
  * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
852
1018
  * @param url The URL to fetch from.
@@ -881,14 +1047,14 @@ declare class IO {
881
1047
  getEvent(key: string | any[], id: string): Promise<{
882
1048
  id: string;
883
1049
  name: string;
884
- createdAt: Date;
885
1050
  updatedAt: Date;
886
1051
  runs: {
887
1052
  id: string;
888
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1053
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH" | "INVALID_PAYLOAD";
889
1054
  startedAt?: Date | null | undefined;
890
1055
  completedAt?: Date | null | undefined;
891
1056
  }[];
1057
+ createdAt: Date;
892
1058
  }>;
893
1059
  /** `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
894
1060
  * @param key
@@ -921,6 +1087,7 @@ declare class IO {
921
1087
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
922
1088
  * @param options The options for the interval.
923
1089
  * @returns A promise that has information about the interval.
1090
+ * @deprecated Use `DynamicSchedule.register` instead.
924
1091
  */
925
1092
  registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
926
1093
  id: string;
@@ -929,12 +1096,14 @@ declare class IO {
929
1096
  cron: string;
930
1097
  };
931
1098
  type: "cron";
1099
+ accountId?: string | undefined;
932
1100
  metadata?: any;
933
1101
  } | {
934
1102
  options: {
935
1103
  seconds: number;
936
1104
  };
937
1105
  type: "interval";
1106
+ accountId?: string | undefined;
938
1107
  metadata?: any;
939
1108
  };
940
1109
  active: boolean;
@@ -944,6 +1113,7 @@ declare class IO {
944
1113
  * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
945
1114
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
946
1115
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1116
+ * @deprecated Use `DynamicSchedule.unregister` instead.
947
1117
  */
948
1118
  unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
949
1119
  ok: boolean;
@@ -953,6 +1123,7 @@ declare class IO {
953
1123
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
954
1124
  * @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
955
1125
  * @param options The options for the CRON schedule.
1126
+ * @deprecated Use `DynamicSchedule.register` instead.
956
1127
  */
957
1128
  registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
958
1129
  id: string;
@@ -961,12 +1132,14 @@ declare class IO {
961
1132
  cron: string;
962
1133
  };
963
1134
  type: "cron";
1135
+ accountId?: string | undefined;
964
1136
  metadata?: any;
965
1137
  } | {
966
1138
  options: {
967
1139
  seconds: number;
968
1140
  };
969
1141
  type: "interval";
1142
+ accountId?: string | undefined;
970
1143
  metadata?: any;
971
1144
  };
972
1145
  active: boolean;
@@ -976,6 +1149,7 @@ declare class IO {
976
1149
  * @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
1150
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
978
1151
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1152
+ * @deprecated Use `DynamicSchedule.unregister` instead.
979
1153
  */
980
1154
  unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
981
1155
  ok: boolean;
@@ -985,6 +1159,7 @@ declare class IO {
985
1159
  * @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
986
1160
  * @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
987
1161
  * @param params The params for the trigger.
1162
+ * @deprecated Use `DynamicTrigger.register` instead.
988
1163
  */
989
1164
  registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
990
1165
  id: string;
@@ -1097,8 +1272,8 @@ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegratio
1097
1272
  get name(): string;
1098
1273
  get trigger(): TTrigger;
1099
1274
  get version(): string;
1100
- get integrations(): Record<string, IntegrationConfig>;
1101
1275
  get logLevel(): LogLevel | undefined;
1276
+ get integrations(): Record<string, IntegrationConfig>;
1102
1277
  toJSON(): JobMetadata;
1103
1278
  }
1104
1279
 
@@ -1123,7 +1298,7 @@ type TriggerOptions<TEvent> = {
1123
1298
  /** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
1124
1299
  * The default is `z.any()` which is `any`.
1125
1300
  * */
1126
- schema?: z.Schema<TEvent>;
1301
+ schema?: SchemaParser<TEvent>;
1127
1302
  /** You can use this to filter events based on the source. */
1128
1303
  source?: string;
1129
1304
  /** Used to filter which events trigger the Job
@@ -1174,8 +1349,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1174
1349
  id: string;
1175
1350
  scopes: string[];
1176
1351
  title: string;
1177
- createdAt: Date;
1178
1352
  updatedAt: Date;
1353
+ createdAt: Date;
1179
1354
  };
1180
1355
  authorizationUrl: string;
1181
1356
  } | {
@@ -1189,8 +1364,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1189
1364
  id: string;
1190
1365
  scopes: string[];
1191
1366
  title: string;
1192
- createdAt: Date;
1193
1367
  updatedAt: Date;
1368
+ createdAt: Date;
1194
1369
  };
1195
1370
  authorizationUrl: string;
1196
1371
  };
@@ -1219,8 +1394,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1219
1394
  id: string;
1220
1395
  scopes: string[];
1221
1396
  title: string;
1222
- createdAt: Date;
1223
1397
  updatedAt: Date;
1398
+ createdAt: Date;
1224
1399
  integrationIdentifier: string;
1225
1400
  integrationAuthMethod: string;
1226
1401
  };
@@ -1236,8 +1411,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1236
1411
  id: string;
1237
1412
  scopes: string[];
1238
1413
  title: string;
1239
- createdAt: Date;
1240
1414
  updatedAt: Date;
1415
+ createdAt: Date;
1241
1416
  integrationIdentifier: string;
1242
1417
  integrationAuthMethod: string;
1243
1418
  };
@@ -1290,4 +1465,4 @@ type Task = ServerTask;
1290
1465
  type SentEvent = ApiEventLog;
1291
1466
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1292
1467
 
1293
- 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 };
1468
+ export { AuthResolverResult, 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, SchemaParser, SchemaParserIssue, SchemaParserResult, SentEvent, Task, TaskLogger, Trigger, TriggerAuthResolver, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerOptionRecord, TriggerPayload, TriggerPreprocessContext, cronTrigger, eventTrigger, intervalTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry };