@trigger.dev/sdk 0.0.0-isomorphic-sdk-20230918150523 → 0.0.0-prerelease-20230922185725

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,5 +1,5 @@
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
5
  import { z } from 'zod';
@@ -9,9 +9,18 @@ type ApiClientOptions = {
9
9
  apiUrl?: string;
10
10
  logLevel?: LogLevel;
11
11
  };
12
+ type EndpointRecord = {
13
+ id: string;
14
+ name: string;
15
+ url: string;
16
+ };
12
17
  declare class ApiClient {
13
18
  #private;
14
19
  constructor(options: ApiClientOptions);
20
+ registerEndpoint(options: {
21
+ url: string;
22
+ name: string;
23
+ }): Promise<EndpointRecord>;
15
24
  runTask(runId: string, task: RunTaskBodyInput): Promise<{
16
25
  id: string;
17
26
  name: string;
@@ -136,6 +145,17 @@ declare class ApiClient {
136
145
  deliveredAt?: Date | null | undefined;
137
146
  cancelledAt?: Date | null | undefined;
138
147
  }>;
148
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
149
+ label: string;
150
+ key: string;
151
+ history: {
152
+ label?: string | undefined;
153
+ state?: "loading" | "success" | "failure" | undefined;
154
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
155
+ }[];
156
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
157
+ state?: "loading" | "success" | "failure" | undefined;
158
+ }>;
139
159
  updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
140
160
  registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2): Promise<RegisterSourceEventV2>;
141
161
  registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
@@ -145,12 +165,14 @@ declare class ApiClient {
145
165
  cron: string;
146
166
  };
147
167
  type: "cron";
168
+ accountId?: string | undefined;
148
169
  metadata?: any;
149
170
  } | {
150
171
  options: {
151
172
  seconds: number;
152
173
  };
153
174
  type: "interval";
175
+ accountId?: string | undefined;
154
176
  metadata?: any;
155
177
  };
156
178
  active: boolean;
@@ -160,7 +182,7 @@ declare class ApiClient {
160
182
  ok: boolean;
161
183
  }>;
162
184
  getAuth(client: string, id: string): Promise<{
163
- type: "oauth2";
185
+ type: "oauth2" | "apiKey";
164
186
  accessToken: string;
165
187
  scopes?: string[] | undefined;
166
188
  additionalFields?: Record<string, string> | undefined;
@@ -168,31 +190,60 @@ declare class ApiClient {
168
190
  getEvent(eventId: string): Promise<{
169
191
  id: string;
170
192
  name: string;
171
- createdAt: Date;
172
193
  updatedAt: Date;
173
194
  runs: {
174
195
  id: string;
175
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
196
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
176
197
  startedAt?: Date | null | undefined;
177
198
  completedAt?: Date | null | undefined;
178
199
  }[];
200
+ createdAt: Date;
179
201
  }>;
180
202
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
181
203
  id: string;
182
204
  startedAt: Date | null;
183
205
  completedAt: Date | null;
184
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
185
- tasks: _trigger_dev_core.RunTaskWithSubtasks[];
206
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
186
207
  updatedAt: Date | null;
208
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
187
209
  output?: any;
210
+ statuses?: {
211
+ label: string;
212
+ key: string;
213
+ history: {
214
+ label?: string | undefined;
215
+ state?: "loading" | "success" | "failure" | undefined;
216
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
217
+ }[];
218
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
219
+ state?: "loading" | "success" | "failure" | undefined;
220
+ }[] | undefined;
188
221
  nextCursor?: string | undefined;
189
222
  }>;
223
+ getRunStatuses(runId: string): Promise<{
224
+ statuses: {
225
+ label: string;
226
+ key: string;
227
+ history: {
228
+ label?: string | undefined;
229
+ state?: "loading" | "success" | "failure" | undefined;
230
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
231
+ }[];
232
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
233
+ state?: "loading" | "success" | "failure" | undefined;
234
+ }[];
235
+ run: {
236
+ id: string;
237
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
238
+ output?: any;
239
+ };
240
+ }>;
190
241
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
191
242
  runs: {
192
243
  id: string;
193
244
  startedAt: Date | null;
194
245
  completedAt: Date | null;
195
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
246
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
196
247
  updatedAt: Date | null;
197
248
  }[];
198
249
  nextCursor?: string | undefined;
@@ -438,9 +489,7 @@ declare class ExternalSource<TIntegration extends TriggerIntegration, TParams ex
438
489
  get id(): string;
439
490
  get version(): string;
440
491
  }
441
- type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams & {
442
- filter?: EventFilter;
443
- } : never;
492
+ type ExternalSourceParams<TExternalSource extends ExternalSource<any, any, any>> = TExternalSource extends ExternalSource<any, infer TParams, any> ? TParams : never;
444
493
  type ExternalSourceTriggerOptions<TEventSpecification extends EventSpecification<any>, TEventSource extends ExternalSource<any, any, any>, TTriggerOptionDefinitions extends Record<string, string[]> = any> = {
445
494
  event: TEventSpecification;
446
495
  source: TEventSource;
@@ -471,7 +520,7 @@ type DynamicTriggerOptions<TEventSpec extends EventSpecification<any>, TExternal
471
520
  * ```ts
472
521
  * import { events } from "@trigger.dev/github";
473
522
  *
474
- * const dynamicOnIssueOpened = new DynamicTrigger(client, {
523
+ * const dynamicOnIssueOpened = client.defineDynamicTrigger({
475
524
  id: "github-issue-opened",
476
525
  event: events.onIssueOpened,
477
526
  source: github.sources.repo,
@@ -489,19 +538,156 @@ declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExtern
489
538
  * @param options The options for the dynamic trigger.
490
539
  * */
491
540
  constructor(client: TriggerClient, options: DynamicTriggerOptions<TEventSpec, TExternalSource>);
492
- toJSON(): TriggerMetadata;
493
541
  get id(): string;
494
542
  get event(): TEventSpec;
495
- registeredTriggerForParams(params: ExternalSourceParams<TExternalSource>): RegisterTriggerBodyV2;
496
543
  /** Use this method to register a new configuration with the DynamicTrigger.
497
544
  * @param key The key for the configuration. This will be used to identify the configuration when it is triggered.
498
545
  * @param params The params for the configuration.
546
+ * @param options Options for the configuration.
547
+ * @param options.accountId The accountId to associate with the configuration.
548
+ * @param options.filter The filter to use for the configuration.
549
+ *
499
550
  */
500
- register(key: string, params: ExternalSourceParams<TExternalSource>): Promise<RegisterSourceEventV2>;
551
+ register(key: string, params: ExternalSourceParams<TExternalSource>, options?: {
552
+ accountId?: string;
553
+ filter?: EventFilter;
554
+ }): Promise<RegisterSourceEventV2>;
501
555
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
502
556
  get preprocessRuns(): boolean;
503
557
  }
504
558
 
559
+ type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
560
+ declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
561
+ private options;
562
+ constructor(options: IntervalOptions);
563
+ get event(): {
564
+ name: string;
565
+ title: string;
566
+ source: string;
567
+ icon: string;
568
+ examples: {
569
+ id: string;
570
+ name: string;
571
+ icon: string;
572
+ payload: {
573
+ ts: string;
574
+ lastTimestamp: string;
575
+ };
576
+ }[];
577
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
578
+ ts: Date;
579
+ lastTimestamp?: Date | undefined;
580
+ };
581
+ properties: {
582
+ label: string;
583
+ text: string;
584
+ }[];
585
+ };
586
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
587
+ get preprocessRuns(): boolean;
588
+ toJSON(): TriggerMetadata;
589
+ }
590
+ /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
591
+ * @param options An object containing options about the interval.
592
+ */
593
+ declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
594
+ declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
595
+ private options;
596
+ constructor(options: CronOptions);
597
+ get event(): {
598
+ name: string;
599
+ title: string;
600
+ source: string;
601
+ icon: string;
602
+ examples: {
603
+ id: string;
604
+ name: string;
605
+ icon: string;
606
+ payload: {
607
+ ts: string;
608
+ lastTimestamp: string;
609
+ };
610
+ }[];
611
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
612
+ ts: Date;
613
+ lastTimestamp?: Date | undefined;
614
+ };
615
+ properties: {
616
+ label: string;
617
+ text: string;
618
+ }[];
619
+ };
620
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
621
+ get preprocessRuns(): boolean;
622
+ toJSON(): TriggerMetadata;
623
+ }
624
+ /** `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.
625
+ * @param options An object containing options about the CRON schedule.
626
+ */
627
+ declare function cronTrigger(options: CronOptions): CronTrigger;
628
+ /** DynamicSchedule options
629
+ * @param id Used to uniquely identify a DynamicSchedule
630
+ */
631
+ type DynamicIntervalOptions = {
632
+ id: string;
633
+ };
634
+ /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
635
+ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
636
+ private client;
637
+ private options;
638
+ /**
639
+ * @param client The `TriggerClient` instance to use for registering the trigger.
640
+ * @param options The options for the schedule.
641
+ */
642
+ constructor(client: TriggerClient, options: DynamicIntervalOptions);
643
+ get id(): string;
644
+ get event(): {
645
+ name: string;
646
+ title: string;
647
+ source: string;
648
+ icon: string;
649
+ examples: {
650
+ id: string;
651
+ name: string;
652
+ icon: string;
653
+ payload: {
654
+ ts: string;
655
+ lastTimestamp: string;
656
+ };
657
+ }[];
658
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
659
+ ts: Date;
660
+ lastTimestamp?: Date | undefined;
661
+ };
662
+ };
663
+ register(key: string, metadata: ScheduleMetadata): Promise<{
664
+ id: string;
665
+ schedule: {
666
+ options: {
667
+ cron: string;
668
+ };
669
+ type: "cron";
670
+ accountId?: string | undefined;
671
+ metadata?: any;
672
+ } | {
673
+ options: {
674
+ seconds: number;
675
+ };
676
+ type: "interval";
677
+ accountId?: string | undefined;
678
+ metadata?: any;
679
+ };
680
+ active: boolean;
681
+ metadata?: any;
682
+ }>;
683
+ unregister(key: string): Promise<{
684
+ ok: boolean;
685
+ }>;
686
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
687
+ get preprocessRuns(): boolean;
688
+ toJSON(): TriggerMetadata;
689
+ }
690
+
505
691
  type TriggerClientOptions = {
506
692
  /** The `id` property is used to uniquely identify the client.
507
693
  */
@@ -521,12 +707,22 @@ type TriggerClientOptions = {
521
707
  /** Default is unset and off. If set to true it will log to the server's console as well as the Trigger.dev platform */
522
708
  ioLogLocalEnabled?: boolean;
523
709
  };
710
+ type AuthResolverResult = {
711
+ type: "apiKey" | "oauth";
712
+ token: string;
713
+ additionalFields?: Record<string, string>;
714
+ };
715
+ type TriggerAuthResolver = (ctx: TriggerContext, integration: TriggerIntegration) => Promise<AuthResolverResult | void | undefined>;
524
716
  /** 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). */
525
717
  declare class TriggerClient {
526
718
  #private;
527
719
  id: string;
528
720
  constructor(options: Prettify<TriggerClientOptions>);
529
721
  handleRequest(request: Request): Promise<NormalizedResponse>;
722
+ defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
723
+ defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
724
+ defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
725
+ defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
530
726
  attach(job: Job<Trigger<any>, any>): void;
531
727
  attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
532
728
  attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
@@ -537,7 +733,8 @@ declare class TriggerClient {
537
733
  params: any;
538
734
  options?: Record<string, string[]>;
539
735
  }): void;
540
- attachDynamicSchedule(key: string, job: Job<Trigger<any>, any>): void;
736
+ attachDynamicSchedule(key: string): void;
737
+ attachDynamicScheduleToJob(key: string, job: Job<Trigger<any>, any>): void;
541
738
  registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
542
739
  id: string;
543
740
  options: {
@@ -570,7 +767,7 @@ declare class TriggerClient {
570
767
  dynamicTriggerId?: string | undefined;
571
768
  }>;
572
769
  getAuth(id: string): Promise<{
573
- type: "oauth2";
770
+ type: "oauth2" | "apiKey";
574
771
  accessToken: string;
575
772
  scopes?: string[] | undefined;
576
773
  additionalFields?: Record<string, string> | undefined;
@@ -608,6 +805,17 @@ declare class TriggerClient {
608
805
  deliveredAt?: Date | null | undefined;
609
806
  cancelledAt?: Date | null | undefined;
610
807
  }>;
808
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
809
+ label: string;
810
+ key: string;
811
+ history: {
812
+ label?: string | undefined;
813
+ state?: "loading" | "success" | "failure" | undefined;
814
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
815
+ }[];
816
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
817
+ state?: "loading" | "success" | "failure" | undefined;
818
+ }>;
611
819
  registerSchedule(id: string, key: string, schedule: ScheduleMetadata): Promise<{
612
820
  id: string;
613
821
  schedule: {
@@ -615,12 +823,14 @@ declare class TriggerClient {
615
823
  cron: string;
616
824
  };
617
825
  type: "cron";
826
+ accountId?: string | undefined;
618
827
  metadata?: any;
619
828
  } | {
620
829
  options: {
621
830
  seconds: number;
622
831
  };
623
832
  type: "interval";
833
+ accountId?: string | undefined;
624
834
  metadata?: any;
625
835
  };
626
836
  active: boolean;
@@ -632,23 +842,34 @@ declare class TriggerClient {
632
842
  getEvent(eventId: string): Promise<{
633
843
  id: string;
634
844
  name: string;
635
- createdAt: Date;
636
845
  updatedAt: Date;
637
846
  runs: {
638
847
  id: string;
639
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
848
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
640
849
  startedAt?: Date | null | undefined;
641
850
  completedAt?: Date | null | undefined;
642
851
  }[];
852
+ createdAt: Date;
643
853
  }>;
644
854
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
645
855
  id: string;
646
856
  startedAt: Date | null;
647
857
  completedAt: Date | null;
648
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
649
- tasks: _trigger_dev_core.RunTaskWithSubtasks[];
858
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
650
859
  updatedAt: Date | null;
860
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
651
861
  output?: any;
862
+ statuses?: {
863
+ label: string;
864
+ key: string;
865
+ history: {
866
+ label?: string | undefined;
867
+ state?: "loading" | "success" | "failure" | undefined;
868
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
869
+ }[];
870
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
871
+ state?: "loading" | "success" | "failure" | undefined;
872
+ }[] | undefined;
652
873
  nextCursor?: string | undefined;
653
874
  }>;
654
875
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
@@ -656,144 +877,48 @@ declare class TriggerClient {
656
877
  id: string;
657
878
  startedAt: Date | null;
658
879
  completedAt: Date | null;
659
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
880
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
660
881
  updatedAt: Date | null;
661
882
  }[];
662
883
  nextCursor?: string | undefined;
663
884
  }>;
664
- authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
665
- apiKey(): string | undefined;
666
- defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
667
- }
668
-
669
- type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
670
- declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
671
- private options;
672
- constructor(options: IntervalOptions);
673
- get event(): {
674
- name: string;
675
- title: string;
676
- source: string;
677
- icon: string;
678
- examples: {
679
- id: string;
680
- name: string;
681
- icon: string;
682
- payload: {
683
- ts: string;
684
- lastTimestamp: string;
685
- };
686
- }[];
687
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
688
- ts: Date;
689
- lastTimestamp?: Date | undefined;
690
- };
691
- properties: {
885
+ getRunStatuses(runId: string): Promise<{
886
+ statuses: {
692
887
  label: string;
693
- text: string;
888
+ key: string;
889
+ history: {
890
+ label?: string | undefined;
891
+ state?: "loading" | "success" | "failure" | undefined;
892
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
893
+ }[];
894
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
895
+ state?: "loading" | "success" | "failure" | undefined;
694
896
  }[];
695
- };
696
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
697
- get preprocessRuns(): boolean;
698
- toJSON(): TriggerMetadata;
699
- }
700
- /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
701
- * @param options An object containing options about the interval.
702
- */
703
- declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
704
- declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
705
- private options;
706
- constructor(options: CronOptions);
707
- get event(): {
708
- name: string;
709
- title: string;
710
- source: string;
711
- icon: string;
712
- examples: {
897
+ run: {
713
898
  id: string;
714
- name: string;
715
- icon: string;
716
- payload: {
717
- ts: string;
718
- lastTimestamp: string;
719
- };
720
- }[];
721
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
722
- ts: Date;
723
- lastTimestamp?: Date | undefined;
899
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
900
+ output?: any;
724
901
  };
725
- properties: {
726
- label: string;
727
- text: string;
728
- }[];
729
- };
730
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
731
- get preprocessRuns(): boolean;
732
- toJSON(): TriggerMetadata;
902
+ }>;
903
+ authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
904
+ apiKey(): string | undefined;
733
905
  }
734
- /** `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.
735
- * @param options An object containing options about the CRON schedule.
736
- */
737
- declare function cronTrigger(options: CronOptions): CronTrigger;
738
- /** DynamicSchedule options
739
- * @param id Used to uniquely identify a DynamicSchedule
740
- */
741
- type DynamicIntervalOptions = {
742
- id: string;
743
- };
744
- /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
745
- declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
746
- private client;
747
- private options;
748
- /**
749
- * @param client The `TriggerClient` instance to use for registering the trigger.
750
- * @param options The options for the schedule.
751
- */
752
- constructor(client: TriggerClient, options: DynamicIntervalOptions);
753
- get id(): string;
754
- get event(): {
755
- name: string;
756
- title: string;
757
- source: string;
758
- icon: string;
759
- examples: {
760
- id: string;
761
- name: string;
762
- icon: string;
763
- payload: {
764
- ts: string;
765
- lastTimestamp: string;
766
- };
906
+
907
+ declare class TriggerStatus {
908
+ private id;
909
+ private io;
910
+ constructor(id: string, io: IO);
911
+ update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
912
+ label: string;
913
+ key: string;
914
+ history: {
915
+ label?: string | undefined;
916
+ state?: "loading" | "success" | "failure" | undefined;
917
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
767
918
  }[];
768
- parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
769
- ts: Date;
770
- lastTimestamp?: Date | undefined;
771
- };
772
- };
773
- register(key: string, metadata: ScheduleMetadata): Promise<{
774
- id: string;
775
- schedule: {
776
- options: {
777
- cron: string;
778
- };
779
- type: "cron";
780
- metadata?: any;
781
- } | {
782
- options: {
783
- seconds: number;
784
- };
785
- type: "interval";
786
- metadata?: any;
787
- };
788
- active: boolean;
789
- metadata?: any;
790
- }>;
791
- unregister(key: string): Promise<{
792
- ok: boolean;
919
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
920
+ state?: "loading" | "success" | "failure" | undefined;
793
921
  }>;
794
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
795
- get preprocessRuns(): boolean;
796
- toJSON(): TriggerMetadata;
797
922
  }
798
923
 
799
924
  type IOTask = ServerTask;
@@ -815,9 +940,10 @@ type JsonRecord<T> = {
815
940
  };
816
941
  type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
817
942
  type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
818
- retryAt: Date;
943
+ retryAt?: Date;
819
944
  error?: Error;
820
945
  jitter?: number;
946
+ skipRetrying?: boolean;
821
947
  } | Error | undefined | void;
822
948
  declare class IO {
823
949
  #private;
@@ -838,6 +964,39 @@ declare class IO {
838
964
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
839
965
  */
840
966
  wait(key: string | any[], seconds: number): Promise<void>;
967
+ /** `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
968
+ * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
969
+ * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
970
+ * @returns a TriggerStatus object that you can call `update()` on, to update the status.
971
+ * @example
972
+ * ```ts
973
+ * client.defineJob(
974
+ //...
975
+ run: async (payload, io, ctx) => {
976
+ const generatingImages = await io.createStatus("generating-images", {
977
+ label: "Generating Images",
978
+ state: "loading",
979
+ data: {
980
+ progress: 0.1,
981
+ },
982
+ });
983
+
984
+ //...do stuff
985
+
986
+ await generatingImages.update("completed-generation", {
987
+ label: "Generated images",
988
+ state: "success",
989
+ data: {
990
+ progress: 1.0,
991
+ urls: ["http://..."]
992
+ },
993
+ });
994
+
995
+ //...
996
+ });
997
+ * ```
998
+ */
999
+ createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
841
1000
  /** `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.
842
1001
  * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
843
1002
  * @param url The URL to fetch from.
@@ -872,14 +1031,14 @@ declare class IO {
872
1031
  getEvent(key: string | any[], id: string): Promise<{
873
1032
  id: string;
874
1033
  name: string;
875
- createdAt: Date;
876
1034
  updatedAt: Date;
877
1035
  runs: {
878
1036
  id: string;
879
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1037
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
880
1038
  startedAt?: Date | null | undefined;
881
1039
  completedAt?: Date | null | undefined;
882
1040
  }[];
1041
+ createdAt: Date;
883
1042
  }>;
884
1043
  /** `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
885
1044
  * @param key
@@ -912,6 +1071,7 @@ declare class IO {
912
1071
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
913
1072
  * @param options The options for the interval.
914
1073
  * @returns A promise that has information about the interval.
1074
+ * @deprecated Use `DynamicSchedule.register` instead.
915
1075
  */
916
1076
  registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
917
1077
  id: string;
@@ -920,12 +1080,14 @@ declare class IO {
920
1080
  cron: string;
921
1081
  };
922
1082
  type: "cron";
1083
+ accountId?: string | undefined;
923
1084
  metadata?: any;
924
1085
  } | {
925
1086
  options: {
926
1087
  seconds: number;
927
1088
  };
928
1089
  type: "interval";
1090
+ accountId?: string | undefined;
929
1091
  metadata?: any;
930
1092
  };
931
1093
  active: boolean;
@@ -935,6 +1097,7 @@ declare class IO {
935
1097
  * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
936
1098
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
937
1099
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1100
+ * @deprecated Use `DynamicSchedule.unregister` instead.
938
1101
  */
939
1102
  unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
940
1103
  ok: boolean;
@@ -944,6 +1107,7 @@ declare class IO {
944
1107
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
945
1108
  * @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
946
1109
  * @param options The options for the CRON schedule.
1110
+ * @deprecated Use `DynamicSchedule.register` instead.
947
1111
  */
948
1112
  registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
949
1113
  id: string;
@@ -952,12 +1116,14 @@ declare class IO {
952
1116
  cron: string;
953
1117
  };
954
1118
  type: "cron";
1119
+ accountId?: string | undefined;
955
1120
  metadata?: any;
956
1121
  } | {
957
1122
  options: {
958
1123
  seconds: number;
959
1124
  };
960
1125
  type: "interval";
1126
+ accountId?: string | undefined;
961
1127
  metadata?: any;
962
1128
  };
963
1129
  active: boolean;
@@ -967,6 +1133,7 @@ declare class IO {
967
1133
  * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
968
1134
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
969
1135
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1136
+ * @deprecated Use `DynamicSchedule.unregister` instead.
970
1137
  */
971
1138
  unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
972
1139
  ok: boolean;
@@ -976,6 +1143,7 @@ declare class IO {
976
1143
  * @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
977
1144
  * @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
978
1145
  * @param params The params for the trigger.
1146
+ * @deprecated Use `DynamicTrigger.register` instead.
979
1147
  */
980
1148
  registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
981
1149
  id: string;
@@ -1088,8 +1256,8 @@ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegratio
1088
1256
  get name(): string;
1089
1257
  get trigger(): TTrigger;
1090
1258
  get version(): string;
1091
- get integrations(): Record<string, IntegrationConfig>;
1092
1259
  get logLevel(): LogLevel | undefined;
1260
+ get integrations(): Record<string, IntegrationConfig>;
1093
1261
  toJSON(): JobMetadata;
1094
1262
  }
1095
1263
 
@@ -1165,8 +1333,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1165
1333
  id: string;
1166
1334
  scopes: string[];
1167
1335
  title: string;
1168
- createdAt: Date;
1169
1336
  updatedAt: Date;
1337
+ createdAt: Date;
1170
1338
  };
1171
1339
  authorizationUrl: string;
1172
1340
  } | {
@@ -1180,8 +1348,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1180
1348
  id: string;
1181
1349
  scopes: string[];
1182
1350
  title: string;
1183
- createdAt: Date;
1184
1351
  updatedAt: Date;
1352
+ createdAt: Date;
1185
1353
  };
1186
1354
  authorizationUrl: string;
1187
1355
  };
@@ -1210,8 +1378,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1210
1378
  id: string;
1211
1379
  scopes: string[];
1212
1380
  title: string;
1213
- createdAt: Date;
1214
1381
  updatedAt: Date;
1382
+ createdAt: Date;
1215
1383
  integrationIdentifier: string;
1216
1384
  integrationAuthMethod: string;
1217
1385
  };
@@ -1227,8 +1395,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1227
1395
  id: string;
1228
1396
  scopes: string[];
1229
1397
  title: string;
1230
- createdAt: Date;
1231
1398
  updatedAt: Date;
1399
+ createdAt: Date;
1232
1400
  integrationIdentifier: string;
1233
1401
  integrationAuthMethod: string;
1234
1402
  };
@@ -1281,4 +1449,4 @@ type Task = ServerTask;
1281
1449
  type SentEvent = ApiEventLog;
1282
1450
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1283
1451
 
1284
- 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 };
1452
+ 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, SentEvent, Task, TaskLogger, Trigger, TriggerAuthResolver, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerOptionRecord, TriggerPayload, TriggerPreprocessContext, cronTrigger, eventTrigger, intervalTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString, retry };