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

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,17 +1,28 @@
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';
6
+ import * as _trigger_dev_core_schemas from '@trigger.dev/core/schemas';
7
+ import { StatusUpdate as StatusUpdate$1 } from '@trigger.dev/core/schemas';
6
8
 
7
9
  type ApiClientOptions = {
8
10
  apiKey?: string;
9
11
  apiUrl?: string;
10
12
  logLevel?: LogLevel;
11
13
  };
14
+ type EndpointRecord = {
15
+ id: string;
16
+ name: string;
17
+ url: string;
18
+ };
12
19
  declare class ApiClient {
13
20
  #private;
14
21
  constructor(options: ApiClientOptions);
22
+ registerEndpoint(options: {
23
+ url: string;
24
+ name: string;
25
+ }): Promise<EndpointRecord>;
15
26
  runTask(runId: string, task: RunTaskBodyInput): Promise<{
16
27
  id: string;
17
28
  name: string;
@@ -136,6 +147,17 @@ declare class ApiClient {
136
147
  deliveredAt?: Date | null | undefined;
137
148
  cancelledAt?: Date | null | undefined;
138
149
  }>;
150
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
151
+ label: string;
152
+ key: string;
153
+ history: {
154
+ label?: string | undefined;
155
+ state?: "loading" | "success" | "failure" | undefined;
156
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
157
+ }[];
158
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
159
+ state?: "loading" | "success" | "failure" | undefined;
160
+ }>;
139
161
  updateSource(client: string, key: string, source: UpdateTriggerSourceBodyV2): Promise<TriggerSource>;
140
162
  registerTrigger(client: string, id: string, key: string, payload: RegisterTriggerBodyV2): Promise<RegisterSourceEventV2>;
141
163
  registerSchedule(client: string, id: string, key: string, payload: ScheduleMetadata): Promise<{
@@ -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";
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";
186
207
  updatedAt: Date | null;
208
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
209
+ statuses: {
210
+ label: string;
211
+ key: string;
212
+ history: {
213
+ label?: string | undefined;
214
+ state?: "loading" | "success" | "failure" | undefined;
215
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
216
+ }[];
217
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
218
+ state?: "loading" | "success" | "failure" | undefined;
219
+ }[];
187
220
  output?: any;
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";
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";
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;
@@ -608,6 +659,17 @@ declare class TriggerClient {
608
659
  deliveredAt?: Date | null | undefined;
609
660
  cancelledAt?: Date | null | undefined;
610
661
  }>;
662
+ updateStatus(runId: string, id: string, status: StatusUpdate): Promise<{
663
+ label: string;
664
+ key: string;
665
+ history: {
666
+ label?: string | undefined;
667
+ state?: "loading" | "success" | "failure" | undefined;
668
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
669
+ }[];
670
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
671
+ state?: "loading" | "success" | "failure" | undefined;
672
+ }>;
611
673
  registerSchedule(id: string, key: string, schedule: ScheduleMetadata): Promise<{
612
674
  id: string;
613
675
  schedule: {
@@ -632,22 +694,33 @@ declare class TriggerClient {
632
694
  getEvent(eventId: string): Promise<{
633
695
  id: string;
634
696
  name: string;
635
- createdAt: Date;
636
697
  updatedAt: Date;
637
698
  runs: {
638
699
  id: string;
639
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
700
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
640
701
  startedAt?: Date | null | undefined;
641
702
  completedAt?: Date | null | undefined;
642
703
  }[];
704
+ createdAt: Date;
643
705
  }>;
644
706
  getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
645
707
  id: string;
646
708
  startedAt: Date | null;
647
709
  completedAt: Date | null;
648
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
649
- tasks: _trigger_dev_core.RunTaskWithSubtasks[];
710
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
650
711
  updatedAt: Date | null;
712
+ tasks: _trigger_dev_core.RunTaskWithSubtasks[];
713
+ statuses: {
714
+ label: string;
715
+ key: string;
716
+ history: {
717
+ label?: string | undefined;
718
+ state?: "loading" | "success" | "failure" | undefined;
719
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
720
+ }[];
721
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
722
+ state?: "loading" | "success" | "failure" | undefined;
723
+ }[];
651
724
  output?: any;
652
725
  nextCursor?: string | undefined;
653
726
  }>;
@@ -656,11 +729,29 @@ declare class TriggerClient {
656
729
  id: string;
657
730
  startedAt: Date | null;
658
731
  completedAt: Date | null;
659
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
732
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
660
733
  updatedAt: Date | null;
661
734
  }[];
662
735
  nextCursor?: string | undefined;
663
736
  }>;
737
+ getRunStatuses(runId: string): Promise<{
738
+ statuses: {
739
+ label: string;
740
+ key: string;
741
+ history: {
742
+ label?: string | undefined;
743
+ state?: "loading" | "success" | "failure" | undefined;
744
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
745
+ }[];
746
+ data?: Record<string, _trigger_dev_core.SerializableJson> | undefined;
747
+ state?: "loading" | "success" | "failure" | undefined;
748
+ }[];
749
+ run: {
750
+ id: string;
751
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
752
+ output?: any;
753
+ };
754
+ }>;
664
755
  authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
665
756
  apiKey(): string | undefined;
666
757
  defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
@@ -796,6 +887,23 @@ declare class DynamicSchedule implements Trigger<ScheduledEventSpecification> {
796
887
  toJSON(): TriggerMetadata;
797
888
  }
798
889
 
890
+ declare class TriggerStatus {
891
+ private id;
892
+ private io;
893
+ constructor(id: string, io: IO);
894
+ update(key: IntegrationTaskKey, status: StatusUpdate$1): Promise<{
895
+ label: string;
896
+ key: string;
897
+ history: {
898
+ label?: string | undefined;
899
+ state?: "loading" | "success" | "failure" | undefined;
900
+ data?: Record<string, _trigger_dev_core_schemas.SerializableJson> | undefined;
901
+ }[];
902
+ data?: Record<string, _trigger_dev_core_schemas.SerializableJson> | undefined;
903
+ state?: "loading" | "success" | "failure" | undefined;
904
+ }>;
905
+ }
906
+
799
907
  type IOTask = ServerTask;
800
908
  type IOOptions = {
801
909
  id: string;
@@ -838,6 +946,39 @@ declare class IO {
838
946
  * @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
839
947
  */
840
948
  wait(key: string | any[], seconds: number): Promise<void>;
949
+ /** `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
950
+ * @param key Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
951
+ * @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
952
+ * @returns a TriggerStatus object that you can call `update()` on, to update the status.
953
+ * @example
954
+ * ```ts
955
+ * client.defineJob(
956
+ //...
957
+ run: async (payload, io, ctx) => {
958
+ const generatingImages = await io.createStatus("generating-images", {
959
+ label: "Generating Images",
960
+ state: "loading",
961
+ data: {
962
+ progress: 0.1,
963
+ },
964
+ });
965
+
966
+ //...do stuff
967
+
968
+ await generatingImages.update("completed-generation", {
969
+ label: "Generated images",
970
+ state: "success",
971
+ data: {
972
+ progress: 1.0,
973
+ urls: ["http://..."]
974
+ },
975
+ });
976
+
977
+ //...
978
+ });
979
+ * ```
980
+ */
981
+ createStatus(key: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
841
982
  /** `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
983
  * @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
984
  * @param url The URL to fetch from.
@@ -872,14 +1013,14 @@ declare class IO {
872
1013
  getEvent(key: string | any[], id: string): Promise<{
873
1014
  id: string;
874
1015
  name: string;
875
- createdAt: Date;
876
1016
  updatedAt: Date;
877
1017
  runs: {
878
1018
  id: string;
879
- status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
1019
+ status: "PENDING" | "CANCELED" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "SUCCESS" | "FAILURE" | "TIMED_OUT" | "ABORTED";
880
1020
  startedAt?: Date | null | undefined;
881
1021
  completedAt?: Date | null | undefined;
882
1022
  }[];
1023
+ createdAt: Date;
883
1024
  }>;
884
1025
  /** `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
1026
  * @param key
@@ -1165,8 +1306,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1165
1306
  id: string;
1166
1307
  scopes: string[];
1167
1308
  title: string;
1168
- createdAt: Date;
1169
1309
  updatedAt: Date;
1310
+ createdAt: Date;
1170
1311
  };
1171
1312
  authorizationUrl: string;
1172
1313
  } | {
@@ -1180,8 +1321,8 @@ declare class MissingConnectionNotification implements Trigger<MissingConnection
1180
1321
  id: string;
1181
1322
  scopes: string[];
1182
1323
  title: string;
1183
- createdAt: Date;
1184
1324
  updatedAt: Date;
1325
+ createdAt: Date;
1185
1326
  };
1186
1327
  authorizationUrl: string;
1187
1328
  };
@@ -1210,8 +1351,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1210
1351
  id: string;
1211
1352
  scopes: string[];
1212
1353
  title: string;
1213
- createdAt: Date;
1214
1354
  updatedAt: Date;
1355
+ createdAt: Date;
1215
1356
  integrationIdentifier: string;
1216
1357
  integrationAuthMethod: string;
1217
1358
  };
@@ -1227,8 +1368,8 @@ declare class MissingConnectionResolvedNotification implements Trigger<MissingCo
1227
1368
  id: string;
1228
1369
  scopes: string[];
1229
1370
  title: string;
1230
- createdAt: Date;
1231
1371
  updatedAt: Date;
1372
+ createdAt: Date;
1232
1373
  integrationIdentifier: string;
1233
1374
  integrationAuthMethod: string;
1234
1375
  };
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";