@trigger.dev/sdk 0.0.0-isomorphic-sdk-20230918151405 → 0.0.0-statuses-20230921210707

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, DeserializedJson, IntervalOptions, CronOptions, ScheduledPayload, 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<{
@@ -168,31 +188,60 @@ declare class ApiClient {
168
188
  getEvent(eventId: string): Promise<{
169
189
  id: string;
170
190
  name: string;
171
- createdAt: Date;
172
191
  updatedAt: Date;
173
192
  runs: {
174
193
  id: string;
175
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
194
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
176
195
  startedAt?: Date | null | undefined;
177
196
  completedAt?: Date | null | undefined;
178
197
  }[];
198
+ createdAt: Date;
179
199
  }>;
180
200
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
181
201
  id: string;
182
202
  startedAt: Date | null;
183
203
  completedAt: Date | null;
184
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
185
- tasks: _trigger_dev_core.RunTaskWithSubtasks[];
204
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
186
205
  updatedAt: Date | null;
206
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
187
207
  output?: any;
208
+ statuses?: {
209
+ label: string;
210
+ key: string;
211
+ history: {
212
+ label?: string | undefined;
213
+ state?: "loading" | "success" | "failure" | undefined;
214
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
215
+ }[];
216
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
217
+ state?: "loading" | "success" | "failure" | undefined;
218
+ }[] | undefined;
188
219
  nextCursor?: string | undefined;
189
220
  }>;
221
+ getRunStatuses(runId: string): Promise<{
222
+ statuses: {
223
+ label: string;
224
+ key: string;
225
+ history: {
226
+ label?: string | undefined;
227
+ state?: "loading" | "success" | "failure" | undefined;
228
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
229
+ }[];
230
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
231
+ state?: "loading" | "success" | "failure" | undefined;
232
+ }[];
233
+ run: {
234
+ id: string;
235
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
236
+ output?: any;
237
+ };
238
+ }>;
190
239
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
191
240
  runs: {
192
241
  id: string;
193
242
  startedAt: Date | null;
194
243
  completedAt: Date | null;
195
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
244
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
196
245
  updatedAt: Date | null;
197
246
  }[];
198
247
  nextCursor?: string | undefined;
@@ -314,7 +363,7 @@ type HttpSourceEvent = {
314
363
  url: string;
315
364
  method: string;
316
365
  headers: Record<string, string>;
317
- rawBody?: Uint8Array | null;
366
+ rawBody?: Buffer | null;
318
367
  };
319
368
  type SmtpSourceEvent = {
320
369
  from: string;
@@ -608,6 +657,17 @@ declare class TriggerClient {
608
657
  deliveredAt?: Date | null | undefined;
609
658
  cancelledAt?: Date | null | undefined;
610
659
  }>;
660
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
661
+ label: string;
662
+ key: string;
663
+ history: {
664
+ label?: string | undefined;
665
+ state?: "loading" | "success" | "failure" | undefined;
666
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
667
+ }[];
668
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
669
+ state?: "loading" | "success" | "failure" | undefined;
670
+ }>;
611
671
  registerSchedule(id: string, key: string, schedule: ScheduleMetadata): Promise<{
612
672
  id: string;
613
673
  schedule: {
@@ -632,23 +692,34 @@ declare class TriggerClient {
632
692
  getEvent(eventId: string): Promise<{
633
693
  id: string;
634
694
  name: string;
635
- createdAt: Date;
636
695
  updatedAt: Date;
637
696
  runs: {
638
697
  id: string;
639
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
698
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
640
699
  startedAt?: Date | null | undefined;
641
700
  completedAt?: Date | null | undefined;
642
701
  }[];
702
+ createdAt: Date;
643
703
  }>;
644
704
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
645
705
  id: string;
646
706
  startedAt: Date | null;
647
707
  completedAt: Date | null;
648
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
649
- tasks: _trigger_dev_core.RunTaskWithSubtasks[];
708
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
650
709
  updatedAt: Date | null;
710
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
651
711
  output?: any;
712
+ statuses?: {
713
+ label: string;
714
+ key: string;
715
+ history: {
716
+ label?: string | undefined;
717
+ state?: "loading" | "success" | "failure" | undefined;
718
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
719
+ }[];
720
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
721
+ state?: "loading" | "success" | "failure" | undefined;
722
+ }[] | undefined;
652
723
  nextCursor?: string | undefined;
653
724
  }>;
654
725
  getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
@@ -656,11 +727,29 @@ declare class TriggerClient {
656
727
  id: string;
657
728
  startedAt: Date | null;
658
729
  completedAt: Date | null;
659
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
730
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
660
731
  updatedAt: Date | null;
661
732
  }[];
662
733
  nextCursor?: string | undefined;
663
734
  }>;
735
+ getRunStatuses(runId: string): Promise<{
736
+ statuses: {
737
+ label: string;
738
+ key: string;
739
+ history: {
740
+ label?: string | undefined;
741
+ state?: "loading" | "success" | "failure" | undefined;
742
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
743
+ }[];
744
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
745
+ state?: "loading" | "success" | "failure" | undefined;
746
+ }[];
747
+ run: {
748
+ id: string;
749
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
750
+ output?: any;
751
+ };
752
+ }>;
664
753
  authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
665
754
  apiKey(): string | undefined;
666
755
  defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
@@ -796,6 +885,23 @@ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
796
885
  toJSON(): TriggerMetadata;
797
886
  }
798
887
 
888
+ declare class TriggerStatus {
889
+ private id;
890
+ private io;
891
+ constructor(id: string, io: IO);
892
+ update(key: IntegrationTaskKey, status: StatusUpdate): Promise<{
893
+ label: string;
894
+ key: string;
895
+ history: {
896
+ label?: string | undefined;
897
+ state?: "loading" | "success" | "failure" | undefined;
898
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
899
+ }[];
900
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
901
+ state?: "loading" | "success" | "failure" | undefined;
902
+ }>;
903
+ }
904
+
799
905
  type IOTask = ServerTask;
800
906
  type IOOptions = {
801
907
  id: string;
@@ -838,6 +944,39 @@ declare class IO {
838
944
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
839
945
  */
840
946
  wait(key: string | any[], seconds: number): Promise<void>;
947
+ /** `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
948
+ * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
949
+ * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
950
+ * @returns a TriggerStatus object that you can call `update()` on, to update the status.
951
+ * @example
952
+ * ```ts
953
+ * client.defineJob(
954
+ //...
955
+ run: async (payload, io, ctx) => {
956
+ const generatingImages = await io.createStatus("generating-images", {
957
+ label: "Generating Images",
958
+ state: "loading",
959
+ data: {
960
+ progress: 0.1,
961
+ },
962
+ });
963
+
964
+ //...do stuff
965
+
966
+ await generatingImages.update("completed-generation", {
967
+ label: "Generated images",
968
+ state: "success",
969
+ data: {
970
+ progress: 1.0,
971
+ urls: ["http://..."]
972
+ },
973
+ });
974
+
975
+ //...
976
+ });
977
+ * ```
978
+ */
979
+ createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
841
980
  /** `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
981
  * @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
982
  * @param url The URL to fetch from.
@@ -872,14 +1011,14 @@ declare class IO {
872
1011
  getEvent(key: string | any[], id: string): Promise<{
873
1012
  id: string;
874
1013
  name: string;
875
- createdAt: Date;
876
1014
  updatedAt: Date;
877
1015
  runs: {
878
1016
  id: string;
879
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1017
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
880
1018
  startedAt?: Date | null | undefined;
881
1019
  completedAt?: Date | null | undefined;
882
1020
  }[];
1021
+ createdAt: Date;
883
1022
  }>;
884
1023
  /** `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
1024
  * @param key
@@ -1165,8 +1304,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1165
1304
  id: string;
1166
1305
  scopes: string[];
1167
1306
  title: string;
1168
- createdAt: Date;
1169
1307
  updatedAt: Date;
1308
+ createdAt: Date;
1170
1309
  };
1171
1310
  authorizationUrl: string;
1172
1311
  } | {
@@ -1180,8 +1319,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1180
1319
  id: string;
1181
1320
  scopes: string[];
1182
1321
  title: string;
1183
- createdAt: Date;
1184
1322
  updatedAt: Date;
1323
+ createdAt: Date;
1185
1324
  };
1186
1325
  authorizationUrl: string;
1187
1326
  };
@@ -1210,8 +1349,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1210
1349
  id: string;
1211
1350
  scopes: string[];
1212
1351
  title: string;
1213
- createdAt: Date;
1214
1352
  updatedAt: Date;
1353
+ createdAt: Date;
1215
1354
  integrationIdentifier: string;
1216
1355
  integrationAuthMethod: string;
1217
1356
  };
@@ -1227,8 +1366,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1227
1366
  id: string;
1228
1367
  scopes: string[];
1229
1368
  title: string;
1230
- createdAt: Date;
1231
1369
  updatedAt: Date;
1370
+ createdAt: Date;
1232
1371
  integrationIdentifier: string;
1233
1372
  integrationAuthMethod: string;
1234
1373
  };
package/dist/index.js CHANGED
@@ -150,6 +150,7 @@ var import_core5 = require("@trigger.dev/core");
150
150
 
151
151
  // src/apiClient.ts
152
152
  var import_core = require("@trigger.dev/core");
153
+ var import_node_fetch = __toESM(require("node-fetch"));
153
154
  var import_zod = require("zod");
154
155
  var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
155
156
  var ApiClient = class {
@@ -162,6 +163,32 @@ var ApiClient = class {
162
163
  __privateSet(this, _apiUrl, __privateGet(this, _options).apiUrl ?? process.env.TRIGGER_API_URL ?? "https://api.trigger.dev");
163
164
  __privateSet(this, _logger, new import_core.Logger("trigger.dev", __privateGet(this, _options).logLevel));
164
165
  }
166
+ async registerEndpoint(options) {
167
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
168
+ __privateGet(this, _logger).debug("Registering endpoint", {
169
+ url: options.url,
170
+ name: options.name
171
+ });
172
+ const response = await (0, import_node_fetch.default)(`${__privateGet(this, _apiUrl)}/api/v1/endpoints`, {
173
+ method: "POST",
174
+ headers: {
175
+ "Content-Type": "application/json",
176
+ Authorization: `Bearer ${apiKey}`
177
+ },
178
+ body: JSON.stringify({
179
+ url: options.url,
180
+ name: options.name
181
+ })
182
+ });
183
+ if (response.status >= 400 && response.status < 500) {
184
+ const body = await response.json();
185
+ throw new Error(body.error);
186
+ }
187
+ if (response.status !== 200) {
188
+ throw new Error(`Failed to register entry point, got status code ${response.status}`);
189
+ }
190
+ return await response.json();
191
+ }
165
192
  async runTask(runId, task) {
166
193
  const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
167
194
  __privateGet(this, _logger).debug("Running Task", {
@@ -237,6 +264,21 @@ var ApiClient = class {
237
264
  }
238
265
  });
239
266
  }
267
+ async updateStatus(runId, id, status) {
268
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
269
+ __privateGet(this, _logger).debug("Update status", {
270
+ id,
271
+ status
272
+ });
273
+ return await zodfetch(import_core.JobRunStatusRecordSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses/${id}`, {
274
+ method: "PUT",
275
+ headers: {
276
+ "Content-Type": "application/json",
277
+ Authorization: `Bearer ${apiKey}`
278
+ },
279
+ body: JSON.stringify(status)
280
+ });
281
+ }
240
282
  async updateSource(client, key, source) {
241
283
  const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
242
284
  __privateGet(this, _logger).debug("activating http source", {
@@ -343,6 +385,18 @@ var ApiClient = class {
343
385
  }
344
386
  });
345
387
  }
388
+ async getRunStatuses(runId) {
389
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
390
+ __privateGet(this, _logger).debug("Getting Run statuses", {
391
+ runId
392
+ });
393
+ return await zodfetch(import_core.GetRunStatusesSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses`, {
394
+ method: "GET",
395
+ headers: {
396
+ Authorization: `Bearer ${apiKey}`
397
+ }
398
+ });
399
+ }
346
400
  async getRuns(jobSlug, options) {
347
401
  const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
348
402
  __privateGet(this, _logger).debug("Getting Runs", {
@@ -391,7 +445,7 @@ function getApiKey(key) {
391
445
  }
392
446
  __name(getApiKey, "getApiKey");
393
447
  async function zodfetch(schema, url, requestInit, options) {
394
- const response = await fetch(url, requestInit);
448
+ const response = await (0, import_node_fetch.default)(url, requestInit);
395
449
  if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
396
450
  return;
397
451
  }
@@ -435,7 +489,8 @@ __name(isTriggerError, "isTriggerError");
435
489
 
436
490
  // src/io.ts
437
491
  var import_core3 = require("@trigger.dev/core");
438
- var import_node_async_hooks = require("node:async_hooks");
492
+ var import_node_async_hooks = require("async_hooks");
493
+ var import_node_crypto = require("crypto");
439
494
 
440
495
  // src/retry.ts
441
496
  var import_core2 = require("@trigger.dev/core");
@@ -449,8 +504,41 @@ var retry = {
449
504
  }
450
505
  };
451
506
 
507
+ // src/status.ts
508
+ var TriggerStatus = class {
509
+ constructor(id, io) {
510
+ this.id = id;
511
+ this.io = io;
512
+ }
513
+ async update(key, status) {
514
+ const properties = [];
515
+ if (status.label) {
516
+ properties.push({
517
+ label: "Label",
518
+ text: status.label
519
+ });
520
+ }
521
+ if (status.state) {
522
+ properties.push({
523
+ label: "State",
524
+ text: status.state
525
+ });
526
+ }
527
+ return await this.io.runTask(key, async (task) => {
528
+ return await this.io.triggerClient.updateStatus(this.io.runId, this.id, status);
529
+ }, {
530
+ name: status.label ?? `Status update`,
531
+ icon: "clock",
532
+ params: {
533
+ ...status
534
+ },
535
+ properties
536
+ });
537
+ }
538
+ };
539
+ __name(TriggerStatus, "TriggerStatus");
540
+
452
541
  // src/io.ts
453
- var import_node_buffer = require("buffer");
454
542
  var _addToCachedTasks, addToCachedTasks_fn;
455
543
  var IO = class {
456
544
  constructor(options) {
@@ -470,6 +558,12 @@ var IO = class {
470
558
  this._taskStorage = new import_node_async_hooks.AsyncLocalStorage();
471
559
  this._context = options.context;
472
560
  }
561
+ get runId() {
562
+ return this._id;
563
+ }
564
+ get triggerClient() {
565
+ return this._triggerClient;
566
+ }
473
567
  get logger() {
474
568
  return new IOLogger(async (level, message, data) => {
475
569
  let logLevel = "info";
@@ -540,6 +634,12 @@ var IO = class {
540
634
  }
541
635
  });
542
636
  }
637
+ async createStatus(key, initialStatus) {
638
+ const id = typeof key === "string" ? key : key.join("-");
639
+ const status = new TriggerStatus(id, this);
640
+ await status.update(key, initialStatus);
641
+ return status;
642
+ }
543
643
  async backgroundFetch(key, url, requestInit, retry2) {
544
644
  const urlObject = new URL(url);
545
645
  return await this.runTask(key, async (task) => {
@@ -923,8 +1023,8 @@ async function generateIdempotencyKey(keyMaterial) {
923
1023
  return stableStringify(key2);
924
1024
  });
925
1025
  const key = keys.join(":");
926
- const hash = await crypto.subtle.digest("SHA-256", import_node_buffer.Buffer.from(key));
927
- return import_node_buffer.Buffer.from(hash).toString("hex");
1026
+ const hash = await import_node_crypto.webcrypto.subtle.digest("SHA-256", Buffer.from(key));
1027
+ return Buffer.from(hash).toString("hex");
928
1028
  }
929
1029
  __name(generateIdempotencyKey, "generateIdempotencyKey");
930
1030
  function stableStringify(obj) {
@@ -1467,6 +1567,9 @@ var TriggerClient = class {
1467
1567
  async cancelEvent(eventId) {
1468
1568
  return __privateGet(this, _client).cancelEvent(eventId);
1469
1569
  }
1570
+ async updateStatus(runId, id, status) {
1571
+ return __privateGet(this, _client).updateStatus(runId, id, status);
1572
+ }
1470
1573
  async registerSchedule(id, key, schedule) {
1471
1574
  return __privateGet(this, _client).registerSchedule(this.id, id, key, schedule);
1472
1575
  }
@@ -1482,6 +1585,9 @@ var TriggerClient = class {
1482
1585
  async getRuns(jobSlug, options) {
1483
1586
  return __privateGet(this, _client).getRuns(jobSlug, options);
1484
1587
  }
1588
+ async getRunStatuses(runId) {
1589
+ return __privateGet(this, _client).getRunStatuses(runId);
1590
+ }
1485
1591
  authorized(apiKey) {
1486
1592
  if (typeof apiKey !== "string") {
1487
1593
  return "missing-header";