@trigger.dev/sdk 0.0.0-isomorphic-sdk-20230918151405 → 0.0.0-prerelease-20230922203841

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;
@@ -314,7 +365,7 @@ type HttpSourceEvent = {
314
365
  url: string;
315
366
  method: string;
316
367
  headers: Record<string, string>;
317
- rawBody?: Uint8Array | null;
368
+ rawBody?: Buffer | null;
318
369
  };
319
370
  type SmtpSourceEvent = {
320
371
  from: string;
@@ -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,
@@ -492,16 +541,154 @@ declare class DynamicTrigger<TEventSpec extends EventSpecification<any>, TExtern
492
541
  toJSON(): TriggerMetadata;
493
542
  get id(): string;
494
543
  get event(): TEventSpec;
495
- registeredTriggerForParams(params: ExternalSourceParams<TExternalSource>): RegisterTriggerBodyV2;
496
544
  /** Use this method to register a new configuration with the DynamicTrigger.
497
545
  * @param key The key for the configuration. This will be used to identify the configuration when it is triggered.
498
546
  * @param params The params for the configuration.
547
+ * @param options Options for the configuration.
548
+ * @param options.accountId The accountId to associate with the configuration.
549
+ * @param options.filter The filter to use for the configuration.
550
+ *
499
551
  */
500
- register(key: string, params: ExternalSourceParams<TExternalSource>): Promise<RegisterSourceEventV2>;
552
+ register(key: string, params: ExternalSourceParams<TExternalSource>, options?: {
553
+ accountId?: string;
554
+ filter?: EventFilter;
555
+ }): Promise<RegisterSourceEventV2>;
501
556
  attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpec>, any>): void;
502
557
  get preprocessRuns(): boolean;
503
558
  }
504
559
 
560
+ type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
561
+ declare class IntervalTrigger implements Trigger<ScheduledEventSpecification> {
562
+ private options;
563
+ constructor(options: IntervalOptions);
564
+ get event(): {
565
+ name: string;
566
+ title: string;
567
+ source: string;
568
+ icon: string;
569
+ examples: {
570
+ id: string;
571
+ name: string;
572
+ icon: string;
573
+ payload: {
574
+ ts: string;
575
+ lastTimestamp: string;
576
+ };
577
+ }[];
578
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
579
+ ts: Date;
580
+ lastTimestamp?: Date | undefined;
581
+ };
582
+ properties: {
583
+ label: string;
584
+ text: string;
585
+ }[];
586
+ };
587
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
588
+ get preprocessRuns(): boolean;
589
+ toJSON(): TriggerMetadata;
590
+ }
591
+ /** `intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval.
592
+ * @param options An object containing options about the interval.
593
+ */
594
+ declare function intervalTrigger(options: IntervalOptions): IntervalTrigger;
595
+ declare class CronTrigger implements Trigger<ScheduledEventSpecification> {
596
+ private options;
597
+ constructor(options: CronOptions);
598
+ get event(): {
599
+ name: string;
600
+ title: string;
601
+ source: string;
602
+ icon: string;
603
+ examples: {
604
+ id: string;
605
+ name: string;
606
+ icon: string;
607
+ payload: {
608
+ ts: string;
609
+ lastTimestamp: string;
610
+ };
611
+ }[];
612
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
613
+ ts: Date;
614
+ lastTimestamp?: Date | undefined;
615
+ };
616
+ properties: {
617
+ label: string;
618
+ text: string;
619
+ }[];
620
+ };
621
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
622
+ get preprocessRuns(): boolean;
623
+ toJSON(): TriggerMetadata;
624
+ }
625
+ /** `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.
626
+ * @param options An object containing options about the CRON schedule.
627
+ */
628
+ declare function cronTrigger(options: CronOptions): CronTrigger;
629
+ /** DynamicSchedule options
630
+ * @param id Used to uniquely identify a DynamicSchedule
631
+ */
632
+ type DynamicIntervalOptions = {
633
+ id: string;
634
+ };
635
+ /** DynamicSchedule` allows you to define a scheduled trigger that can be configured dynamically at runtime. */
636
+ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
637
+ private client;
638
+ private options;
639
+ /**
640
+ * @param client The `TriggerClient` instance to use for registering the trigger.
641
+ * @param options The options for the schedule.
642
+ */
643
+ constructor(client: TriggerClient, options: DynamicIntervalOptions);
644
+ get id(): string;
645
+ get event(): {
646
+ name: string;
647
+ title: string;
648
+ source: string;
649
+ icon: string;
650
+ examples: {
651
+ id: string;
652
+ name: string;
653
+ icon: string;
654
+ payload: {
655
+ ts: string;
656
+ lastTimestamp: string;
657
+ };
658
+ }[];
659
+ parsePayload: (data: unknown, params?: Partial<zod.ParseParams> | undefined) => {
660
+ ts: Date;
661
+ lastTimestamp?: Date | undefined;
662
+ };
663
+ };
664
+ register(key: string, metadata: ScheduleMetadata): Promise<{
665
+ id: string;
666
+ schedule: {
667
+ options: {
668
+ cron: string;
669
+ };
670
+ type: "cron";
671
+ accountId?: string | undefined;
672
+ metadata?: any;
673
+ } | {
674
+ options: {
675
+ seconds: number;
676
+ };
677
+ type: "interval";
678
+ accountId?: string | undefined;
679
+ metadata?: any;
680
+ };
681
+ active: boolean;
682
+ metadata?: any;
683
+ }>;
684
+ unregister(key: string): Promise<{
685
+ ok: boolean;
686
+ }>;
687
+ attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
688
+ get preprocessRuns(): boolean;
689
+ toJSON(): TriggerMetadata;
690
+ }
691
+
505
692
  type TriggerClientOptions = {
506
693
  /** The `id` property is used to uniquely identify the client.
507
694
  */
@@ -521,12 +708,22 @@ type TriggerClientOptions = {
521
708
  /** 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
709
  ioLogLocalEnabled?: boolean;
523
710
  };
711
+ type AuthResolverResult = {
712
+ type: "apiKey" | "oauth";
713
+ token: string;
714
+ additionalFields?: Record<string, string>;
715
+ };
716
+ type TriggerAuthResolver = (ctx: TriggerContext, integration: TriggerIntegration) => Promise<AuthResolverResult | void | undefined>;
524
717
  /** 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
718
  declare class TriggerClient {
526
719
  #private;
527
720
  id: string;
528
721
  constructor(options: Prettify<TriggerClientOptions>);
529
722
  handleRequest(request: Request): Promise<NormalizedResponse>;
723
+ defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
724
+ defineAuthResolver(integration: TriggerIntegration, resolver: TriggerAuthResolver): TriggerClient;
725
+ defineDynamicSchedule(options: DynamicIntervalOptions): DynamicSchedule;
726
+ defineDynamicTrigger<TEventSpec extends EventSpecification<any>, TExternalSource extends ExternalSource<any, any, any>>(options: DynamicTriggerOptions<TEventSpec, TExternalSource>): DynamicTrigger<TEventSpec, TExternalSource>;
530
727
  attach(job: Job<Trigger<any>, any>): void;
531
728
  attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void;
532
729
  attachJobToDynamicTrigger(job: Job<Trigger<any>, any>, trigger: DynamicTrigger<any, any>): void;
@@ -537,7 +734,8 @@ declare class TriggerClient {
537
734
  params: any;
538
735
  options?: Record<string, string[]>;
539
736
  }): void;
540
- attachDynamicSchedule(key: string, job: Job<Trigger<any>, any>): void;
737
+ attachDynamicSchedule(key: string): void;
738
+ attachDynamicScheduleToJob(key: string, job: Job<Trigger<any>, any>): void;
541
739
  registerTrigger(id: string, key: string, options: RegisterTriggerBodyV2): Promise<{
542
740
  id: string;
543
741
  options: {
@@ -570,7 +768,7 @@ declare class TriggerClient {
570
768
  dynamicTriggerId?: string | undefined;
571
769
  }>;
572
770
  getAuth(id: string): Promise<{
573
- type: "oauth2";
771
+ type: "oauth2" | "apiKey";
574
772
  accessToken: string;
575
773
  scopes?: string[] | undefined;
576
774
  additionalFields?: Record<string, string> | undefined;
@@ -608,6 +806,17 @@ declare class TriggerClient {
608
806
  deliveredAt?: Date | null | undefined;
609
807
  cancelledAt?: Date | null | undefined;
610
808
  }>;
809
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
810
+ label: string;
811
+ key: string;
812
+ history: {
813
+ label?: string | undefined;
814
+ state?: "loading" | "success" | "failure" | undefined;
815
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
816
+ }[];
817
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
818
+ state?: "loading" | "success" | "failure" | undefined;
819
+ }>;
611
820
  registerSchedule(id: string, key: string, schedule: ScheduleMetadata): Promise<{
612
821
  id: string;
613
822
  schedule: {
@@ -615,12 +824,14 @@ declare class TriggerClient {
615
824
  cron: string;
616
825
  };
617
826
  type: "cron";
827
+ accountId?: string | undefined;
618
828
  metadata?: any;
619
829
  } | {
620
830
  options: {
621
831
  seconds: number;
622
832
  };
623
833
  type: "interval";
834
+ accountId?: string | undefined;
624
835
  metadata?: any;
625
836
  };
626
837
  active: boolean;
@@ -632,23 +843,34 @@ declare class TriggerClient {
632
843
  getEvent(eventId: string): Promise<{
633
844
  id: string;
634
845
  name: string;
635
- createdAt: Date;
636
846
  updatedAt: Date;
637
847
  runs: {
638
848
  id: string;
639
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
849
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
640
850
  startedAt?: Date | null | undefined;
641
851
  completedAt?: Date | null | undefined;
642
852
  }[];
853
+ createdAt: Date;
643
854
  }>;
644
855
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
645
856
  id: string;
646
857
  startedAt: Date | null;
647
858
  completedAt: Date | null;
648
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
649
- tasks: _trigger_dev_core.RunTaskWithSubtasks[];
859
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
650
860
  updatedAt: Date | null;
861
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
651
862
  output?: any;
863
+ statuses?: {
864
+ label: string;
865
+ key: string;
866
+ history: {
867
+ label?: string | undefined;
868
+ state?: "loading" | "success" | "failure" | undefined;
869
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
870
+ }[];
871
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
872
+ state?: "loading" | "success" | "failure" | undefined;
873
+ }[] | undefined;
652
874
  nextCursor?: string | undefined;
653
875
  }>;
654
876
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
@@ -656,144 +878,48 @@ declare class TriggerClient {
656
878
  id: string;
657
879
  startedAt: Date | null;
658
880
  completedAt: Date | null;
659
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
881
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
660
882
  updatedAt: Date | null;
661
883
  }[];
662
884
  nextCursor?: string | undefined;
663
885
  }>;
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: {
886
+ getRunStatuses(runId: string): Promise<{
887
+ statuses: {
692
888
  label: string;
693
- text: string;
889
+ key: string;
890
+ history: {
891
+ label?: string | undefined;
892
+ state?: "loading" | "success" | "failure" | undefined;
893
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
894
+ }[];
895
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
896
+ state?: "loading" | "success" | "failure" | undefined;
694
897
  }[];
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: {
898
+ run: {
713
899
  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;
900
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
901
+ output?: any;
724
902
  };
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;
903
+ }>;
904
+ authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
905
+ apiKey(): string | undefined;
733
906
  }
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
- };
907
+
908
+ declare class TriggerStatus {
909
+ private id;
910
+ private io;
911
+ constructor(id: string, io: IO);
912
+ update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
913
+ label: string;
914
+ key: string;
915
+ history: {
916
+ label?: string | undefined;
917
+ state?: "loading" | "success" | "failure" | undefined;
918
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
767
919
  }[];
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;
920
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
921
+ state?: "loading" | "success" | "failure" | undefined;
793
922
  }>;
794
- attachToJob(triggerClient: TriggerClient, job: Job<Trigger<ScheduledEventSpecification>, any>): void;
795
- get preprocessRuns(): boolean;
796
- toJSON(): TriggerMetadata;
797
923
  }
798
924
 
799
925
  type IOTask = ServerTask;
@@ -815,9 +941,10 @@ type JsonRecord<T> = {
815
941
  };
816
942
  type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
817
943
  type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
818
- retryAt: Date;
944
+ retryAt?: Date;
819
945
  error?: Error;
820
946
  jitter?: number;
947
+ skipRetrying?: boolean;
821
948
  } | Error | undefined | void;
822
949
  declare class IO {
823
950
  #private;
@@ -838,6 +965,39 @@ declare class IO {
838
965
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
839
966
  */
840
967
  wait(key: string | any[], seconds: number): Promise<void>;
968
+ /** `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
969
+ * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
970
+ * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
971
+ * @returns a TriggerStatus object that you can call `update()` on, to update the status.
972
+ * @example
973
+ * ```ts
974
+ * client.defineJob(
975
+ //...
976
+ run: async (payload, io, ctx) => {
977
+ const generatingImages = await io.createStatus("generating-images", {
978
+ label: "Generating Images",
979
+ state: "loading",
980
+ data: {
981
+ progress: 0.1,
982
+ },
983
+ });
984
+
985
+ //...do stuff
986
+
987
+ await generatingImages.update("completed-generation", {
988
+ label: "Generated images",
989
+ state: "success",
990
+ data: {
991
+ progress: 1.0,
992
+ urls: ["http://..."]
993
+ },
994
+ });
995
+
996
+ //...
997
+ });
998
+ * ```
999
+ */
1000
+ createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
841
1001
  /** `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
1002
  * @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
1003
  * @param url The URL to fetch from.
@@ -872,14 +1032,14 @@ declare class IO {
872
1032
  getEvent(key: string | any[], id: string): Promise<{
873
1033
  id: string;
874
1034
  name: string;
875
- createdAt: Date;
876
1035
  updatedAt: Date;
877
1036
  runs: {
878
1037
  id: string;
879
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1038
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED" | "UNRESOLVED_AUTH";
880
1039
  startedAt?: Date | null | undefined;
881
1040
  completedAt?: Date | null | undefined;
882
1041
  }[];
1042
+ createdAt: Date;
883
1043
  }>;
884
1044
  /** `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
1045
  * @param key
@@ -912,6 +1072,7 @@ declare class IO {
912
1072
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
913
1073
  * @param options The options for the interval.
914
1074
  * @returns A promise that has information about the interval.
1075
+ * @deprecated Use `DynamicSchedule.register` instead.
915
1076
  */
916
1077
  registerInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
917
1078
  id: string;
@@ -920,12 +1081,14 @@ declare class IO {
920
1081
  cron: string;
921
1082
  };
922
1083
  type: "cron";
1084
+ accountId?: string | undefined;
923
1085
  metadata?: any;
924
1086
  } | {
925
1087
  options: {
926
1088
  seconds: number;
927
1089
  };
928
1090
  type: "interval";
1091
+ accountId?: string | undefined;
929
1092
  metadata?: any;
930
1093
  };
931
1094
  active: boolean;
@@ -935,6 +1098,7 @@ declare class IO {
935
1098
  * @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
1099
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
937
1100
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1101
+ * @deprecated Use `DynamicSchedule.unregister` instead.
938
1102
  */
939
1103
  unregisterInterval(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
940
1104
  ok: boolean;
@@ -944,6 +1108,7 @@ declare class IO {
944
1108
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
945
1109
  * @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
946
1110
  * @param options The options for the CRON schedule.
1111
+ * @deprecated Use `DynamicSchedule.register` instead.
947
1112
  */
948
1113
  registerCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
949
1114
  id: string;
@@ -952,12 +1117,14 @@ declare class IO {
952
1117
  cron: string;
953
1118
  };
954
1119
  type: "cron";
1120
+ accountId?: string | undefined;
955
1121
  metadata?: any;
956
1122
  } | {
957
1123
  options: {
958
1124
  seconds: number;
959
1125
  };
960
1126
  type: "interval";
1127
+ accountId?: string | undefined;
961
1128
  metadata?: any;
962
1129
  };
963
1130
  active: boolean;
@@ -967,6 +1134,7 @@ declare class IO {
967
1134
  * @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
1135
  * @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
969
1136
  * @param id A unique id for the interval. This is used to identify and unregister the interval later.
1137
+ * @deprecated Use `DynamicSchedule.unregister` instead.
970
1138
  */
971
1139
  unregisterCron(key: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
972
1140
  ok: boolean;
@@ -976,6 +1144,7 @@ declare class IO {
976
1144
  * @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
977
1145
  * @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
978
1146
  * @param params The params for the trigger.
1147
+ * @deprecated Use `DynamicTrigger.register` instead.
979
1148
  */
980
1149
  registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(key: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
981
1150
  id: string;
@@ -1088,8 +1257,8 @@ declare class Job<TTrigger extends Trigger<EventSpecification<any>>, TIntegratio
1088
1257
  get name(): string;
1089
1258
  get trigger(): TTrigger;
1090
1259
  get version(): string;
1091
- get integrations(): Record<string, IntegrationConfig>;
1092
1260
  get logLevel(): LogLevel | undefined;
1261
+ get integrations(): Record<string, IntegrationConfig>;
1093
1262
  toJSON(): JobMetadata;
1094
1263
  }
1095
1264
 
@@ -1165,8 +1334,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1165
1334
  id: string;
1166
1335
  scopes: string[];
1167
1336
  title: string;
1168
- createdAt: Date;
1169
1337
  updatedAt: Date;
1338
+ createdAt: Date;
1170
1339
  };
1171
1340
  authorizationUrl: string;
1172
1341
  } | {
@@ -1180,8 +1349,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1180
1349
  id: string;
1181
1350
  scopes: string[];
1182
1351
  title: string;
1183
- createdAt: Date;
1184
1352
  updatedAt: Date;
1353
+ createdAt: Date;
1185
1354
  };
1186
1355
  authorizationUrl: string;
1187
1356
  };
@@ -1210,8 +1379,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1210
1379
  id: string;
1211
1380
  scopes: string[];
1212
1381
  title: string;
1213
- createdAt: Date;
1214
1382
  updatedAt: Date;
1383
+ createdAt: Date;
1215
1384
  integrationIdentifier: string;
1216
1385
  integrationAuthMethod: string;
1217
1386
  };
@@ -1227,8 +1396,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1227
1396
  id: string;
1228
1397
  scopes: string[];
1229
1398
  title: string;
1230
- createdAt: Date;
1231
1399
  updatedAt: Date;
1400
+ createdAt: Date;
1232
1401
  integrationIdentifier: string;
1233
1402
  integrationAuthMethod: string;
1234
1403
  };
@@ -1281,4 +1450,4 @@ type Task = ServerTask;
1281
1450
  type SentEvent = ApiEventLog;
1282
1451
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
1283
1452
 
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 };
1453
+ 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 };