@trigger.dev/sdk 2.0.0-next.19 → 2.0.0-next.20

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 zod from 'zod';
2
- import { z } from 'zod';
2
+ import { z, ZodObject } from 'zod';
3
3
 
4
4
  /**
5
5
  * Represents different log levels.
@@ -810,6 +810,53 @@ declare const RawEventSchema: z.ZodObject<{
810
810
  }>;
811
811
  /** The event you wish to send to Trigger a Job */
812
812
  type SendEvent = z.input<typeof RawEventSchema>;
813
+ /** The event that was sent */
814
+ declare const ApiEventLogSchema: z.ZodObject<{
815
+ /** The `id` of the event that was sent.
816
+ */
817
+ id: z.ZodString;
818
+ /** The `name` of the event that was sent. */
819
+ name: z.ZodString;
820
+ /** The `payload` of the event that was sent */
821
+ payload: z.ZodType<DeserializedJson, z.ZodTypeDef, DeserializedJson>;
822
+ /** The `context` of the event that was sent. Is `undefined` if no context was
823
+ set when sending the event. */
824
+ context: z.ZodNullable<z.ZodOptional<z.ZodType<DeserializedJson, z.ZodTypeDef, DeserializedJson>>>;
825
+ /** The `timestamp` of the event that was sent */
826
+ timestamp: z.ZodDate;
827
+ /** The timestamp when the event will be delivered to any matching Jobs. Is
828
+ `undefined` if `deliverAt` or `deliverAfter` wasn't set when sending the
829
+ event. */
830
+ deliverAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
831
+ /** The timestamp when the event was delivered. Is `undefined` if `deliverAt`
832
+ or `deliverAfter` were set when sending the event. */
833
+ deliveredAt: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
834
+ }, "strip", z.ZodTypeAny, {
835
+ id: string;
836
+ name: string;
837
+ payload: ((string | number | boolean | {
838
+ [key: string]: DeserializedJson;
839
+ } | DeserializedJson[]) & (string | number | boolean | {
840
+ [key: string]: DeserializedJson;
841
+ } | DeserializedJson[] | undefined)) | null;
842
+ timestamp: Date;
843
+ context?: DeserializedJson | undefined;
844
+ deliverAt?: Date | null | undefined;
845
+ deliveredAt?: Date | null | undefined;
846
+ }, {
847
+ id: string;
848
+ name: string;
849
+ payload: ((string | number | boolean | {
850
+ [key: string]: DeserializedJson;
851
+ } | DeserializedJson[]) & (string | number | boolean | {
852
+ [key: string]: DeserializedJson;
853
+ } | DeserializedJson[] | undefined)) | null;
854
+ timestamp: Date;
855
+ context?: DeserializedJson | undefined;
856
+ deliverAt?: Date | null | undefined;
857
+ deliveredAt?: Date | null | undefined;
858
+ }>;
859
+ type ApiEventLog = z.infer<typeof ApiEventLogSchema>;
813
860
  /** Options to control the delivery of the event */
814
861
  declare const SendEventOptionsSchema: z.ZodObject<{
815
862
  /** An optional Date when you want the event to trigger Jobs. The event will
@@ -3138,6 +3185,37 @@ declare const FetchRetryOptionsSchema: z.ZodRecord<z.ZodString, z.ZodDiscriminat
3138
3185
  */
3139
3186
  type FetchRetryOptions = z.infer<typeof FetchRetryOptionsSchema>;
3140
3187
 
3188
+ declare const GetRunOptionsWithTaskDetailsSchema: ZodObject<{
3189
+ subtasks: z.ZodOptional<z.ZodBoolean>;
3190
+ cursor: z.ZodOptional<z.ZodString>;
3191
+ take: z.ZodOptional<z.ZodNumber>;
3192
+ taskdetails: z.ZodOptional<z.ZodBoolean>;
3193
+ }, "strip", z.ZodTypeAny, {
3194
+ subtasks?: boolean | undefined;
3195
+ cursor?: string | undefined;
3196
+ take?: number | undefined;
3197
+ taskdetails?: boolean | undefined;
3198
+ }, {
3199
+ subtasks?: boolean | undefined;
3200
+ cursor?: string | undefined;
3201
+ take?: number | undefined;
3202
+ taskdetails?: boolean | undefined;
3203
+ }>;
3204
+ type GetRunOptionsWithTaskDetails = z.infer<typeof GetRunOptionsWithTaskDetailsSchema>;
3205
+ declare const GetRunsOptionsSchema: ZodObject<{
3206
+ /** You can use this to get more tasks, if there are more than are returned in a single batch @default undefined */
3207
+ cursor: z.ZodOptional<z.ZodString>;
3208
+ /** How many runs you want to return in one go, max 50. @default 20 */
3209
+ take: z.ZodOptional<z.ZodNumber>;
3210
+ }, "strip", z.ZodTypeAny, {
3211
+ cursor?: string | undefined;
3212
+ take?: number | undefined;
3213
+ }, {
3214
+ cursor?: string | undefined;
3215
+ take?: number | undefined;
3216
+ }>;
3217
+ type GetRunsOptions = z.infer<typeof GetRunsOptionsSchema>;
3218
+
3141
3219
  type ApiClientOptions = {
3142
3220
  apiKey?: string;
3143
3221
  apiUrl?: string;
@@ -3302,6 +3380,46 @@ declare class ApiClient {
3302
3380
  scopes?: string[] | undefined;
3303
3381
  additionalFields?: Record<string, string> | undefined;
3304
3382
  } | undefined>;
3383
+ getEvent(eventId: string): Promise<{
3384
+ id: string;
3385
+ name: string;
3386
+ createdAt: Date;
3387
+ updatedAt: Date;
3388
+ runs: {
3389
+ id: string;
3390
+ status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
3391
+ startedAt?: Date | null | undefined;
3392
+ completedAt?: Date | null | undefined;
3393
+ }[];
3394
+ }>;
3395
+ getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
3396
+ id: string;
3397
+ startedAt: Date | null;
3398
+ completedAt: Date | null;
3399
+ status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
3400
+ tasks: {
3401
+ id: string;
3402
+ name: string;
3403
+ icon: string | null;
3404
+ startedAt: Date | null;
3405
+ completedAt: Date | null;
3406
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
3407
+ displayKey: string | null;
3408
+ }[];
3409
+ updatedAt: Date | null;
3410
+ output?: any;
3411
+ nextCursor?: string | undefined;
3412
+ }>;
3413
+ getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
3414
+ runs: {
3415
+ id: string;
3416
+ startedAt: Date | null;
3417
+ completedAt: Date | null;
3418
+ status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
3419
+ updatedAt: Date | null;
3420
+ }[];
3421
+ nextCursor?: string | undefined;
3422
+ }>;
3305
3423
  }
3306
3424
 
3307
3425
  interface TriggerContext {
@@ -3686,6 +3804,46 @@ declare class TriggerClient {
3686
3804
  unregisterSchedule(id: string, key: string): Promise<{
3687
3805
  ok: boolean;
3688
3806
  }>;
3807
+ getEvent(eventId: string): Promise<{
3808
+ id: string;
3809
+ name: string;
3810
+ createdAt: Date;
3811
+ updatedAt: Date;
3812
+ runs: {
3813
+ id: string;
3814
+ status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
3815
+ startedAt?: Date | null | undefined;
3816
+ completedAt?: Date | null | undefined;
3817
+ }[];
3818
+ }>;
3819
+ getRun(runId: string, options?: GetRunOptionsWithTaskDetails): Promise<{
3820
+ id: string;
3821
+ startedAt: Date | null;
3822
+ completedAt: Date | null;
3823
+ status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
3824
+ tasks: {
3825
+ id: string;
3826
+ name: string;
3827
+ icon: string | null;
3828
+ startedAt: Date | null;
3829
+ completedAt: Date | null;
3830
+ status: "PENDING" | "WAITING" | "RUNNING" | "COMPLETED" | "ERRORED" | "CANCELED";
3831
+ displayKey: string | null;
3832
+ }[];
3833
+ updatedAt: Date | null;
3834
+ output?: any;
3835
+ nextCursor?: string | undefined;
3836
+ }>;
3837
+ getRuns(jobSlug: string, options?: GetRunsOptions): Promise<{
3838
+ runs: {
3839
+ id: string;
3840
+ startedAt: Date | null;
3841
+ completedAt: Date | null;
3842
+ status: "PENDING" | "CANCELED" | "SUCCESS" | "QUEUED" | "WAITING_ON_CONNECTIONS" | "PREPROCESSING" | "STARTED" | "FAILURE" | "TIMED_OUT" | "ABORTED";
3843
+ updatedAt: Date | null;
3844
+ }[];
3845
+ nextCursor?: string | undefined;
3846
+ }>;
3689
3847
  authorized(apiKey?: string | null): "authorized" | "unauthorized" | "missing-client" | "missing-header";
3690
3848
  apiKey(): string | undefined;
3691
3849
  defineJob<TTrigger extends Trigger<EventSpecification<any>>, TIntegrations extends Record<string, TriggerIntegration<IntegrationClient<any, any>>> = {}>(options: JobOptions<TTrigger, TIntegrations>): Job<TTrigger, TIntegrations>;
@@ -4293,6 +4451,8 @@ declare class CanceledWithTaskError {
4293
4451
  declare function isTriggerError(err: unknown): err is ResumeWithTaskError | RetryWithTaskError | CanceledWithTaskError;
4294
4452
 
4295
4453
  type Task = ServerTask;
4454
+
4455
+ type SentEvent = ApiEventLog;
4296
4456
  declare function redactString(strings: TemplateStringsArray, ...interpolations: string[]): RedactString;
4297
4457
 
4298
- export { AuthenticatedTask, ClientFactory, CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventFilter, EventSpecification, EventSpecificationExample, EventTrigger, EventTypeFromSpecification, ExternalSource, ExternalSourceParams, ExternalSourceTrigger, ExternalSourceTriggerOptions, HandlerEvent, HttpSourceEvent, IO, IOLogger, IOOptions, IOTask, IOWithIntegrations, IntegrationClient, IntervalTrigger, Job, JobOptions, Logger, MissingConnectionNotification, MissingConnectionResolvedNotification, NormalizedRequest, PreprocessResults, RedactString, Task, TaskLogger, Trigger, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerPreprocessContext, authenticatedTask, cronTrigger, eventTrigger, intervalTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString };
4458
+ export { AuthenticatedTask, ClientFactory, CronTrigger, DynamicIntervalOptions, DynamicSchedule, DynamicTrigger, DynamicTriggerOptions, EventFilter, EventSpecification, EventSpecificationExample, EventTrigger, EventTypeFromSpecification, ExternalSource, ExternalSourceParams, ExternalSourceTrigger, ExternalSourceTriggerOptions, HandlerEvent, HttpSourceEvent, IO, IOLogger, IOOptions, IOTask, IOWithIntegrations, IntegrationClient, IntervalTrigger, Job, JobOptions, Logger, MissingConnectionNotification, MissingConnectionResolvedNotification, NormalizedRequest, PreprocessResults, RedactString, SentEvent, Task, TaskLogger, Trigger, TriggerClient, TriggerClientOptions, TriggerContext, TriggerEventType, TriggerIntegration, TriggerPreprocessContext, authenticatedTask, cronTrigger, eventTrigger, intervalTrigger, isTriggerError, missingConnectionNotification, missingConnectionResolvedNotification, omit, redactString };
package/dist/index.js CHANGED
@@ -968,6 +968,75 @@ var FetchOperationSchema = import_zod11.z.object({
968
968
  retry: import_zod11.z.record(FetchRetryStrategySchema).optional()
969
969
  });
970
970
 
971
+ // ../internal/src/schemas/events.ts
972
+ var import_zod13 = require("zod");
973
+
974
+ // ../internal/src/schemas/runs.ts
975
+ var import_zod12 = require("zod");
976
+ var RunStatusSchema = import_zod12.z.union([
977
+ import_zod12.z.literal("PENDING"),
978
+ import_zod12.z.literal("QUEUED"),
979
+ import_zod12.z.literal("WAITING_ON_CONNECTIONS"),
980
+ import_zod12.z.literal("PREPROCESSING"),
981
+ import_zod12.z.literal("STARTED"),
982
+ import_zod12.z.literal("SUCCESS"),
983
+ import_zod12.z.literal("FAILURE"),
984
+ import_zod12.z.literal("TIMED_OUT"),
985
+ import_zod12.z.literal("ABORTED"),
986
+ import_zod12.z.literal("CANCELED")
987
+ ]);
988
+ var RunTaskSchema = import_zod12.z.object({
989
+ id: import_zod12.z.string(),
990
+ displayKey: import_zod12.z.string().nullable(),
991
+ status: TaskStatusSchema,
992
+ name: import_zod12.z.string(),
993
+ icon: import_zod12.z.string().nullable(),
994
+ startedAt: import_zod12.z.coerce.date().nullable(),
995
+ completedAt: import_zod12.z.coerce.date().nullable()
996
+ });
997
+ var GetRunOptionsSchema = import_zod12.z.object({
998
+ subtasks: import_zod12.z.boolean().optional(),
999
+ cursor: import_zod12.z.string().optional(),
1000
+ take: import_zod12.z.number().optional()
1001
+ });
1002
+ var GetRunOptionsWithTaskDetailsSchema = GetRunOptionsSchema.extend({
1003
+ taskdetails: import_zod12.z.boolean().optional()
1004
+ });
1005
+ var RunSchema = import_zod12.z.object({
1006
+ id: import_zod12.z.string(),
1007
+ status: RunStatusSchema,
1008
+ startedAt: import_zod12.z.coerce.date().nullable(),
1009
+ updatedAt: import_zod12.z.coerce.date().nullable(),
1010
+ completedAt: import_zod12.z.coerce.date().nullable()
1011
+ });
1012
+ var GetRunSchema = RunSchema.extend({
1013
+ output: import_zod12.z.any().optional(),
1014
+ tasks: import_zod12.z.array(RunTaskSchema),
1015
+ nextCursor: import_zod12.z.string().optional()
1016
+ });
1017
+ var GetRunsOptionsSchema = import_zod12.z.object({
1018
+ cursor: import_zod12.z.string().optional(),
1019
+ take: import_zod12.z.number().optional()
1020
+ });
1021
+ var GetRunsSchema = import_zod12.z.object({
1022
+ runs: RunSchema.array(),
1023
+ nextCursor: import_zod12.z.string().optional()
1024
+ });
1025
+
1026
+ // ../internal/src/schemas/events.ts
1027
+ var GetEventSchema = import_zod13.z.object({
1028
+ id: import_zod13.z.string(),
1029
+ name: import_zod13.z.string(),
1030
+ createdAt: import_zod13.z.coerce.date(),
1031
+ updatedAt: import_zod13.z.coerce.date(),
1032
+ runs: import_zod13.z.array(import_zod13.z.object({
1033
+ id: import_zod13.z.string(),
1034
+ status: RunStatusSchema,
1035
+ startedAt: import_zod13.z.coerce.date().optional().nullable(),
1036
+ completedAt: import_zod13.z.coerce.date().optional().nullable()
1037
+ }))
1038
+ });
1039
+
971
1040
  // ../internal/src/utils.ts
972
1041
  function deepMergeFilters(filter, other) {
973
1042
  const result = {
@@ -1026,9 +1095,22 @@ var currentDate = {
1026
1095
  }
1027
1096
  };
1028
1097
 
1098
+ // ../internal/src/searchParams.ts
1099
+ function urlWithSearchParams(url, params) {
1100
+ if (!params) {
1101
+ return url;
1102
+ }
1103
+ const urlObj = new URL(url);
1104
+ for (const [key, value] of Object.entries(params)) {
1105
+ urlObj.searchParams.append(key, String(value));
1106
+ }
1107
+ return urlObj.toString();
1108
+ }
1109
+ __name(urlWithSearchParams, "urlWithSearchParams");
1110
+
1029
1111
  // src/apiClient.ts
1030
- var import_zod12 = require("zod");
1031
1112
  var import_node_fetch = __toESM(require("node-fetch"));
1113
+ var import_zod14 = require("zod");
1032
1114
  var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
1033
1115
  var ApiClient = class {
1034
1116
  constructor(options) {
@@ -1197,8 +1279,8 @@ var ApiClient = class {
1197
1279
  __privateGet(this, _logger).debug("unregistering schedule", {
1198
1280
  id
1199
1281
  });
1200
- const response = await zodfetch(import_zod12.z.object({
1201
- ok: import_zod12.z.boolean()
1282
+ const response = await zodfetch(import_zod14.z.object({
1283
+ ok: import_zod14.z.boolean()
1202
1284
  }), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
1203
1285
  method: "DELETE",
1204
1286
  headers: {
@@ -1224,6 +1306,42 @@ var ApiClient = class {
1224
1306
  });
1225
1307
  return response;
1226
1308
  }
1309
+ async getEvent(eventId) {
1310
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
1311
+ __privateGet(this, _logger).debug("Getting Event", {
1312
+ eventId
1313
+ });
1314
+ return await zodfetch(GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
1315
+ method: "GET",
1316
+ headers: {
1317
+ Authorization: `Bearer ${apiKey}`
1318
+ }
1319
+ });
1320
+ }
1321
+ async getRun(runId, options) {
1322
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
1323
+ __privateGet(this, _logger).debug("Getting Run", {
1324
+ runId
1325
+ });
1326
+ return await zodfetch(GetRunSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
1327
+ method: "GET",
1328
+ headers: {
1329
+ Authorization: `Bearer ${apiKey}`
1330
+ }
1331
+ });
1332
+ }
1333
+ async getRuns(jobSlug, options) {
1334
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
1335
+ __privateGet(this, _logger).debug("Getting Runs", {
1336
+ jobSlug
1337
+ });
1338
+ return await zodfetch(GetRunsSchema, urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
1339
+ method: "GET",
1340
+ headers: {
1341
+ Authorization: `Bearer ${apiKey}`
1342
+ }
1343
+ });
1344
+ }
1227
1345
  };
1228
1346
  __name(ApiClient, "ApiClient");
1229
1347
  _apiUrl = new WeakMap();
@@ -2315,6 +2433,15 @@ var TriggerClient = class {
2315
2433
  async unregisterSchedule(id, key) {
2316
2434
  return __privateGet(this, _client).unregisterSchedule(this.id, id, key);
2317
2435
  }
2436
+ async getEvent(eventId) {
2437
+ return __privateGet(this, _client).getEvent(eventId);
2438
+ }
2439
+ async getRun(runId, options) {
2440
+ return __privateGet(this, _client).getRun(runId, options);
2441
+ }
2442
+ async getRuns(jobSlug, options) {
2443
+ return __privateGet(this, _client).getRuns(jobSlug, options);
2444
+ }
2318
2445
  authorized(apiKey) {
2319
2446
  if (typeof apiKey !== "string") {
2320
2447
  return "missing-header";