@trigger.dev/core 3.0.0-beta.35 → 3.0.0-beta.36

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.
Files changed (37) hide show
  1. package/dist/{catalog-BUwiuDbt.d.mts → catalog-XTlJQaMn.d.mts} +3 -3
  2. package/dist/{catalog-eKgqBHUA.d.ts → catalog-dRKTgwQ7.d.ts} +3 -3
  3. package/dist/{manager-uPyMRN8k.d.mts → manager-JkbddlcO.d.mts} +19 -19
  4. package/dist/{manager-uPyMRN8k.d.ts → manager-JkbddlcO.d.ts} +19 -19
  5. package/dist/{messages-l9PdIyKF.d.mts → messages-6_-q72KG.d.mts} +119 -119
  6. package/dist/{messages-l9PdIyKF.d.ts → messages-6_-q72KG.d.ts} +119 -119
  7. package/dist/{schemas-b8tRw8dX.d.mts → schemas-r4ZP9S-F.d.mts} +2 -2
  8. package/dist/{schemas-b8tRw8dX.d.ts → schemas-r4ZP9S-F.d.ts} +2 -2
  9. package/dist/v3/dev/index.d.mts +1 -1
  10. package/dist/v3/dev/index.d.ts +1 -1
  11. package/dist/v3/index.d.mts +579 -122
  12. package/dist/v3/index.d.ts +579 -122
  13. package/dist/v3/index.js +739 -319
  14. package/dist/v3/index.js.map +1 -1
  15. package/dist/v3/index.mjs +730 -318
  16. package/dist/v3/index.mjs.map +1 -1
  17. package/dist/v3/otel/index.js +1 -1
  18. package/dist/v3/otel/index.js.map +1 -1
  19. package/dist/v3/otel/index.mjs +1 -1
  20. package/dist/v3/otel/index.mjs.map +1 -1
  21. package/dist/v3/prod/index.d.mts +2 -2
  22. package/dist/v3/prod/index.d.ts +2 -2
  23. package/dist/v3/workers/index.d.mts +6 -6
  24. package/dist/v3/workers/index.d.ts +6 -6
  25. package/dist/v3/workers/index.js +463 -51
  26. package/dist/v3/workers/index.js.map +1 -1
  27. package/dist/v3/workers/index.mjs +463 -51
  28. package/dist/v3/workers/index.mjs.map +1 -1
  29. package/dist/v3/zodMessageHandler.d.mts +1 -1
  30. package/dist/v3/zodMessageHandler.d.ts +1 -1
  31. package/dist/v3/zodfetch.d.mts +194 -10
  32. package/dist/v3/zodfetch.d.ts +194 -10
  33. package/dist/v3/zodfetch.js +336 -38
  34. package/dist/v3/zodfetch.js.map +1 -1
  35. package/dist/v3/zodfetch.mjs +320 -37
  36. package/dist/v3/zodfetch.mjs.map +1 -1
  37. package/package.json +1 -1
package/dist/v3/index.mjs CHANGED
@@ -29,7 +29,7 @@ var __privateMethod = (obj, member, method) => {
29
29
  };
30
30
 
31
31
  // package.json
32
- var version = "3.0.0-beta.35";
32
+ var version = "3.0.0-beta.36";
33
33
  var dependencies = {
34
34
  "@google-cloud/precise-date": "^4.0.0",
35
35
  "@opentelemetry/api": "^1.8.0",
@@ -52,144 +52,6 @@ var dependencies = {
52
52
  "zod-error": "1.5.0",
53
53
  "zod-validation-error": "^1.5.0"
54
54
  };
55
-
56
- // src/v3/apiErrors.ts
57
- var _APIError = class _APIError extends Error {
58
- constructor(status, error, message, headers) {
59
- super(`${_APIError.makeMessage(status, error, message)}`);
60
- this.status = status;
61
- this.headers = headers;
62
- const data = error;
63
- this.error = data;
64
- this.code = data?.["code"];
65
- this.param = data?.["param"];
66
- this.type = data?.["type"];
67
- }
68
- static makeMessage(status, error, message) {
69
- const msg = error?.message ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : message;
70
- if (status && msg) {
71
- return `${status} ${msg}`;
72
- }
73
- if (status) {
74
- return `${status} status code (no body)`;
75
- }
76
- if (msg) {
77
- return msg;
78
- }
79
- return "(no status code or body)";
80
- }
81
- static generate(status, errorResponse, message, headers) {
82
- if (!status) {
83
- return new APIConnectionError({
84
- cause: castToError(errorResponse)
85
- });
86
- }
87
- const error = errorResponse?.["error"];
88
- if (status === 400) {
89
- return new BadRequestError(status, error, message, headers);
90
- }
91
- if (status === 401) {
92
- return new AuthenticationError(status, error, message, headers);
93
- }
94
- if (status === 403) {
95
- return new PermissionDeniedError(status, error, message, headers);
96
- }
97
- if (status === 404) {
98
- return new NotFoundError(status, error, message, headers);
99
- }
100
- if (status === 409) {
101
- return new ConflictError(status, error, message, headers);
102
- }
103
- if (status === 422) {
104
- return new UnprocessableEntityError(status, error, message, headers);
105
- }
106
- if (status === 429) {
107
- return new RateLimitError(status, error, message, headers);
108
- }
109
- if (status >= 500) {
110
- return new InternalServerError(status, error, message, headers);
111
- }
112
- return new _APIError(status, error, message, headers);
113
- }
114
- };
115
- __name(_APIError, "APIError");
116
- var APIError = _APIError;
117
- var _APIConnectionError = class _APIConnectionError extends APIError {
118
- constructor({ message, cause }) {
119
- super(void 0, void 0, message || "Connection error.", void 0);
120
- __publicField(this, "status");
121
- if (cause)
122
- this.cause = cause;
123
- }
124
- };
125
- __name(_APIConnectionError, "APIConnectionError");
126
- var APIConnectionError = _APIConnectionError;
127
- var _BadRequestError = class _BadRequestError extends APIError {
128
- constructor() {
129
- super(...arguments);
130
- __publicField(this, "status", 400);
131
- }
132
- };
133
- __name(_BadRequestError, "BadRequestError");
134
- var BadRequestError = _BadRequestError;
135
- var _AuthenticationError = class _AuthenticationError extends APIError {
136
- constructor() {
137
- super(...arguments);
138
- __publicField(this, "status", 401);
139
- }
140
- };
141
- __name(_AuthenticationError, "AuthenticationError");
142
- var AuthenticationError = _AuthenticationError;
143
- var _PermissionDeniedError = class _PermissionDeniedError extends APIError {
144
- constructor() {
145
- super(...arguments);
146
- __publicField(this, "status", 403);
147
- }
148
- };
149
- __name(_PermissionDeniedError, "PermissionDeniedError");
150
- var PermissionDeniedError = _PermissionDeniedError;
151
- var _NotFoundError = class _NotFoundError extends APIError {
152
- constructor() {
153
- super(...arguments);
154
- __publicField(this, "status", 404);
155
- }
156
- };
157
- __name(_NotFoundError, "NotFoundError");
158
- var NotFoundError = _NotFoundError;
159
- var _ConflictError = class _ConflictError extends APIError {
160
- constructor() {
161
- super(...arguments);
162
- __publicField(this, "status", 409);
163
- }
164
- };
165
- __name(_ConflictError, "ConflictError");
166
- var ConflictError = _ConflictError;
167
- var _UnprocessableEntityError = class _UnprocessableEntityError extends APIError {
168
- constructor() {
169
- super(...arguments);
170
- __publicField(this, "status", 422);
171
- }
172
- };
173
- __name(_UnprocessableEntityError, "UnprocessableEntityError");
174
- var UnprocessableEntityError = _UnprocessableEntityError;
175
- var _RateLimitError = class _RateLimitError extends APIError {
176
- constructor() {
177
- super(...arguments);
178
- __publicField(this, "status", 429);
179
- }
180
- };
181
- __name(_RateLimitError, "RateLimitError");
182
- var RateLimitError = _RateLimitError;
183
- var _InternalServerError = class _InternalServerError extends APIError {
184
- };
185
- __name(_InternalServerError, "InternalServerError");
186
- var InternalServerError = _InternalServerError;
187
- function castToError(err) {
188
- if (err instanceof Error)
189
- return err;
190
- return new Error(err);
191
- }
192
- __name(castToError, "castToError");
193
55
  var CreateAuthorizationCodeResponseSchema = z.object({
194
56
  url: z.string().url(),
195
57
  authorizationCode: z.string()
@@ -508,7 +370,16 @@ var TaskFileMetadata = z.object({
508
370
  filePath: z.string(),
509
371
  exportName: z.string()
510
372
  });
511
- var TaskMetadataWithFilePath = TaskMetadata.merge(TaskFileMetadata);
373
+ var TaskMetadataWithFilePath = z.object({
374
+ id: z.string(),
375
+ packageVersion: z.string(),
376
+ queue: QueueOptions.optional(),
377
+ retry: RetryOptions.optional(),
378
+ machine: Machine.partial().optional(),
379
+ triggerSource: z.string().optional(),
380
+ filePath: z.string(),
381
+ exportName: z.string()
382
+ });
512
383
  var PostStartCauses = z.enum([
513
384
  "index",
514
385
  "create",
@@ -577,6 +448,152 @@ var ImageDetailsMetadata = z.object({
577
448
  contentHash: z.string(),
578
449
  imageTag: z.string()
579
450
  });
451
+ function parseError(error) {
452
+ if (error instanceof Error) {
453
+ return {
454
+ type: "BUILT_IN_ERROR",
455
+ name: error.name,
456
+ message: error.message,
457
+ stackTrace: error.stack ?? ""
458
+ };
459
+ }
460
+ if (typeof error === "string") {
461
+ return {
462
+ type: "STRING_ERROR",
463
+ raw: error
464
+ };
465
+ }
466
+ try {
467
+ return {
468
+ type: "CUSTOM_ERROR",
469
+ raw: JSON.stringify(error)
470
+ };
471
+ } catch (e) {
472
+ return {
473
+ type: "CUSTOM_ERROR",
474
+ raw: String(error)
475
+ };
476
+ }
477
+ }
478
+ __name(parseError, "parseError");
479
+ function createErrorTaskError(error) {
480
+ switch (error.type) {
481
+ case "BUILT_IN_ERROR": {
482
+ const e = new Error(error.message);
483
+ e.name = error.name;
484
+ e.stack = error.stackTrace;
485
+ return e;
486
+ }
487
+ case "STRING_ERROR": {
488
+ return error.raw;
489
+ }
490
+ case "CUSTOM_ERROR": {
491
+ return JSON.parse(error.raw);
492
+ }
493
+ case "INTERNAL_ERROR": {
494
+ return new Error(`trigger.dev internal error (${error.code})`);
495
+ }
496
+ }
497
+ }
498
+ __name(createErrorTaskError, "createErrorTaskError");
499
+ var SerializedError = z.object({
500
+ message: z.string(),
501
+ name: z.string().optional(),
502
+ stackTrace: z.string().optional()
503
+ });
504
+ function createJsonErrorObject(error) {
505
+ switch (error.type) {
506
+ case "BUILT_IN_ERROR": {
507
+ return {
508
+ name: error.name,
509
+ message: error.message,
510
+ stackTrace: error.stackTrace
511
+ };
512
+ }
513
+ case "STRING_ERROR": {
514
+ return {
515
+ message: error.raw
516
+ };
517
+ }
518
+ case "CUSTOM_ERROR": {
519
+ return {
520
+ message: error.raw
521
+ };
522
+ }
523
+ case "INTERNAL_ERROR": {
524
+ return {
525
+ message: `trigger.dev internal error (${error.code})`
526
+ };
527
+ }
528
+ }
529
+ }
530
+ __name(createJsonErrorObject, "createJsonErrorObject");
531
+ function correctErrorStackTrace(stackTrace, projectDir, options) {
532
+ const [errorLine, ...traceLines] = stackTrace.split("\n");
533
+ return [
534
+ options?.removeFirstLine ? void 0 : errorLine,
535
+ ...traceLines.map((line) => correctStackTraceLine(line, projectDir, options?.isDev))
536
+ ].filter(Boolean).join("\n");
537
+ }
538
+ __name(correctErrorStackTrace, "correctErrorStackTrace");
539
+ var LINES_TO_IGNORE = [
540
+ /ConsoleInterceptor/,
541
+ /TriggerTracer/,
542
+ /TaskExecutor/,
543
+ /EXECUTE_TASK_RUN/,
544
+ /@trigger.dev\/core/,
545
+ /packages\/core\/src\/v3/,
546
+ /safeJsonProcess/,
547
+ /__entryPoint.ts/,
548
+ /ZodIpc/,
549
+ /startActiveSpan/,
550
+ /processTicksAndRejections/
551
+ ];
552
+ function correctStackTraceLine(line, projectDir, isDev) {
553
+ if (LINES_TO_IGNORE.some((regex) => regex.test(line))) {
554
+ return;
555
+ }
556
+ if (isDev && projectDir && !line.includes(projectDir)) {
557
+ return;
558
+ }
559
+ return line.trim();
560
+ }
561
+ __name(correctStackTraceLine, "correctStackTraceLine");
562
+ function groupTaskMetadataIssuesByTask(tasks, issues) {
563
+ return issues.reduce((acc, issue) => {
564
+ if (issue.path.length === 0) {
565
+ return acc;
566
+ }
567
+ const taskIndex = issue.path[1];
568
+ if (typeof taskIndex !== "number") {
569
+ return acc;
570
+ }
571
+ const task = tasks[taskIndex];
572
+ if (!task) {
573
+ return acc;
574
+ }
575
+ const restOfPath = issue.path.slice(2);
576
+ const taskId = task.id;
577
+ const taskName = task.exportName;
578
+ const filePath = task.filePath;
579
+ const key = taskIndex;
580
+ const existing = acc[key] ?? {
581
+ id: taskId,
582
+ exportName: taskName,
583
+ filePath,
584
+ issues: []
585
+ };
586
+ existing.issues.push({
587
+ message: issue.message,
588
+ path: restOfPath.length === 0 ? void 0 : restOfPath.join(".")
589
+ });
590
+ return {
591
+ ...acc,
592
+ [key]: existing
593
+ };
594
+ }, {});
595
+ }
596
+ __name(groupTaskMetadataIssuesByTask, "groupTaskMetadataIssuesByTask");
580
597
 
581
598
  // src/v3/schemas/api.ts
582
599
  var WhoAmIResponseSchema = z.object({
@@ -719,7 +736,7 @@ var ReplayRunResponse = z.object({
719
736
  id: z.string()
720
737
  });
721
738
  var CanceledRunResponse = z.object({
722
- message: z.string()
739
+ id: z.string()
723
740
  });
724
741
  var ScheduledTaskPayload = z.object({
725
742
  /** The schedule id associated with this run (you can have many schedules for the same task).
@@ -769,17 +786,18 @@ var CreateScheduleOptions = z.object({
769
786
  externalId: z.string().optional()
770
787
  });
771
788
  var UpdateScheduleOptions = CreateScheduleOptions;
789
+ var ScheduleGenerator = z.object({
790
+ type: z.literal("CRON"),
791
+ expression: z.string(),
792
+ description: z.string()
793
+ });
772
794
  var ScheduleObject = z.object({
773
795
  id: z.string(),
774
796
  task: z.string(),
775
797
  active: z.boolean(),
776
798
  deduplicationKey: z.string().nullish(),
777
799
  externalId: z.string().nullish(),
778
- generator: z.object({
779
- type: z.literal("CRON"),
780
- expression: z.string(),
781
- description: z.string()
782
- }),
800
+ generator: ScheduleGenerator,
783
801
  nextRun: z.coerce.date().nullish(),
784
802
  environments: z.array(z.object({
785
803
  id: z.string(),
@@ -803,12 +821,28 @@ var ListScheduleOptions = z.object({
803
821
  perPage: z.number().optional()
804
822
  });
805
823
  var RunStatus = z.enum([
806
- "PENDING",
824
+ /// Task hasn't been deployed yet but is waiting to be executed
825
+ "WAITING_FOR_DEPLOY",
826
+ /// Task is waiting to be executed by a worker
827
+ "QUEUED",
828
+ /// Task is currently being executed by a worker
807
829
  "EXECUTING",
808
- "PAUSED",
830
+ /// Task has failed and is waiting to be retried
831
+ "REATTEMPTING",
832
+ /// Task has been paused by the system, and will be resumed by the system
833
+ "FROZEN",
834
+ /// Task has been completed successfully
809
835
  "COMPLETED",
836
+ /// Task has been canceled by the user
837
+ "CANCELED",
838
+ /// Task has been completed with errors
810
839
  "FAILED",
811
- "CANCELED"
840
+ /// Task has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage
841
+ "CRASHED",
842
+ /// Task was interrupted during execution, mostly this happens in development environments
843
+ "INTERRUPTED",
844
+ /// Task has failed to complete, due to an error in the system
845
+ "SYSTEM_FAILURE"
812
846
  ]);
813
847
  var AttemptStatus = z.enum([
814
848
  "PENDING",
@@ -818,23 +852,61 @@ var AttemptStatus = z.enum([
818
852
  "FAILED",
819
853
  "CANCELED"
820
854
  ]);
821
- var RetrieveRunResponse = z.object({
855
+ var RunEnvironmentDetails = z.object({
856
+ id: z.string(),
857
+ name: z.string(),
858
+ user: z.string().optional()
859
+ });
860
+ var RunScheduleDetails = z.object({
861
+ id: z.string(),
862
+ externalId: z.string().optional(),
863
+ deduplicationKey: z.string().optional(),
864
+ generator: ScheduleGenerator
865
+ });
866
+ var CommonRunFields = {
822
867
  id: z.string(),
823
868
  status: RunStatus,
824
869
  taskIdentifier: z.string(),
825
870
  idempotencyKey: z.string().optional(),
826
871
  version: z.string().optional(),
872
+ isQueued: z.boolean(),
873
+ isExecuting: z.boolean(),
874
+ isCompleted: z.boolean(),
875
+ isSuccess: z.boolean(),
876
+ isFailed: z.boolean(),
877
+ isCancelled: z.boolean(),
878
+ isTest: z.boolean(),
827
879
  createdAt: z.coerce.date(),
828
880
  updatedAt: z.coerce.date(),
881
+ startedAt: z.coerce.date().optional(),
882
+ finishedAt: z.coerce.date().optional()
883
+ };
884
+ var RetrieveRunResponse = z.object({
885
+ ...CommonRunFields,
886
+ payload: z.any().optional(),
887
+ output: z.any().optional(),
888
+ schedule: RunScheduleDetails.optional(),
829
889
  attempts: z.array(z.object({
830
890
  id: z.string(),
831
891
  status: AttemptStatus,
832
892
  createdAt: z.coerce.date(),
833
893
  updatedAt: z.coerce.date(),
834
894
  startedAt: z.coerce.date().optional(),
835
- completedAt: z.coerce.date().optional()
895
+ completedAt: z.coerce.date().optional(),
896
+ error: SerializedError.optional()
836
897
  }).optional())
837
898
  });
899
+ var ListRunResponseItem = z.object({
900
+ ...CommonRunFields,
901
+ env: RunEnvironmentDetails
902
+ });
903
+ var ListRunResponse = z.object({
904
+ data: z.array(ListRunResponseItem),
905
+ pagination: z.object({
906
+ next: z.string().optional(),
907
+ previous: z.string().optional()
908
+ })
909
+ });
838
910
  var CreateEnvironmentVariableRequestBody = z.object({
839
911
  name: z.string(),
840
912
  value: z.string()
@@ -2085,15 +2157,153 @@ var _TaskContextAPI = class _TaskContextAPI {
2085
2157
  return registerGlobal(API_NAME, taskContext2);
2086
2158
  }
2087
2159
  };
2088
- _getTaskContext = new WeakSet();
2089
- getTaskContext_fn = /* @__PURE__ */ __name(function() {
2090
- return getGlobal(API_NAME);
2091
- }, "#getTaskContext");
2092
- __name(_TaskContextAPI, "TaskContextAPI");
2093
- var TaskContextAPI = _TaskContextAPI;
2094
-
2095
- // src/v3/task-context-api.ts
2096
- var taskContext = TaskContextAPI.getInstance();
2160
+ _getTaskContext = new WeakSet();
2161
+ getTaskContext_fn = /* @__PURE__ */ __name(function() {
2162
+ return getGlobal(API_NAME);
2163
+ }, "#getTaskContext");
2164
+ __name(_TaskContextAPI, "TaskContextAPI");
2165
+ var TaskContextAPI = _TaskContextAPI;
2166
+
2167
+ // src/v3/task-context-api.ts
2168
+ var taskContext = TaskContextAPI.getInstance();
2169
+
2170
+ // src/v3/apiClient/errors.ts
2171
+ var _ApiError = class _ApiError extends Error {
2172
+ constructor(status, error, message, headers) {
2173
+ super(`${_ApiError.makeMessage(status, error, message)}`);
2174
+ this.status = status;
2175
+ this.headers = headers;
2176
+ const data = error;
2177
+ this.error = data;
2178
+ this.code = data?.["code"];
2179
+ this.param = data?.["param"];
2180
+ this.type = data?.["type"];
2181
+ }
2182
+ static makeMessage(status, error, message) {
2183
+ const msg = error?.message ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : message;
2184
+ if (status && msg) {
2185
+ return `${status} ${msg}`;
2186
+ }
2187
+ if (status) {
2188
+ return `${status} status code (no body)`;
2189
+ }
2190
+ if (msg) {
2191
+ return msg;
2192
+ }
2193
+ return "(no status code or body)";
2194
+ }
2195
+ static generate(status, errorResponse, message, headers) {
2196
+ if (!status) {
2197
+ return new ApiConnectionError({
2198
+ cause: castToError(errorResponse)
2199
+ });
2200
+ }
2201
+ const error = errorResponse?.["error"];
2202
+ if (status === 400) {
2203
+ return new BadRequestError(status, error, message, headers);
2204
+ }
2205
+ if (status === 401) {
2206
+ return new AuthenticationError(status, error, message, headers);
2207
+ }
2208
+ if (status === 403) {
2209
+ return new PermissionDeniedError(status, error, message, headers);
2210
+ }
2211
+ if (status === 404) {
2212
+ return new NotFoundError(status, error, message, headers);
2213
+ }
2214
+ if (status === 409) {
2215
+ return new ConflictError(status, error, message, headers);
2216
+ }
2217
+ if (status === 422) {
2218
+ return new UnprocessableEntityError(status, error, message, headers);
2219
+ }
2220
+ if (status === 429) {
2221
+ return new RateLimitError(status, error, message, headers);
2222
+ }
2223
+ if (status >= 500) {
2224
+ return new InternalServerError(status, error, message, headers);
2225
+ }
2226
+ return new _ApiError(status, error, message, headers);
2227
+ }
2228
+ };
2229
+ __name(_ApiError, "ApiError");
2230
+ var ApiError = _ApiError;
2231
+ var _ApiConnectionError = class _ApiConnectionError extends ApiError {
2232
+ constructor({ message, cause }) {
2233
+ super(void 0, void 0, message || "Connection error.", void 0);
2234
+ __publicField(this, "status");
2235
+ if (cause)
2236
+ this.cause = cause;
2237
+ }
2238
+ };
2239
+ __name(_ApiConnectionError, "ApiConnectionError");
2240
+ var ApiConnectionError = _ApiConnectionError;
2241
+ var _BadRequestError = class _BadRequestError extends ApiError {
2242
+ constructor() {
2243
+ super(...arguments);
2244
+ __publicField(this, "status", 400);
2245
+ }
2246
+ };
2247
+ __name(_BadRequestError, "BadRequestError");
2248
+ var BadRequestError = _BadRequestError;
2249
+ var _AuthenticationError = class _AuthenticationError extends ApiError {
2250
+ constructor() {
2251
+ super(...arguments);
2252
+ __publicField(this, "status", 401);
2253
+ }
2254
+ };
2255
+ __name(_AuthenticationError, "AuthenticationError");
2256
+ var AuthenticationError = _AuthenticationError;
2257
+ var _PermissionDeniedError = class _PermissionDeniedError extends ApiError {
2258
+ constructor() {
2259
+ super(...arguments);
2260
+ __publicField(this, "status", 403);
2261
+ }
2262
+ };
2263
+ __name(_PermissionDeniedError, "PermissionDeniedError");
2264
+ var PermissionDeniedError = _PermissionDeniedError;
2265
+ var _NotFoundError = class _NotFoundError extends ApiError {
2266
+ constructor() {
2267
+ super(...arguments);
2268
+ __publicField(this, "status", 404);
2269
+ }
2270
+ };
2271
+ __name(_NotFoundError, "NotFoundError");
2272
+ var NotFoundError = _NotFoundError;
2273
+ var _ConflictError = class _ConflictError extends ApiError {
2274
+ constructor() {
2275
+ super(...arguments);
2276
+ __publicField(this, "status", 409);
2277
+ }
2278
+ };
2279
+ __name(_ConflictError, "ConflictError");
2280
+ var ConflictError = _ConflictError;
2281
+ var _UnprocessableEntityError = class _UnprocessableEntityError extends ApiError {
2282
+ constructor() {
2283
+ super(...arguments);
2284
+ __publicField(this, "status", 422);
2285
+ }
2286
+ };
2287
+ __name(_UnprocessableEntityError, "UnprocessableEntityError");
2288
+ var UnprocessableEntityError = _UnprocessableEntityError;
2289
+ var _RateLimitError = class _RateLimitError extends ApiError {
2290
+ constructor() {
2291
+ super(...arguments);
2292
+ __publicField(this, "status", 429);
2293
+ }
2294
+ };
2295
+ __name(_RateLimitError, "RateLimitError");
2296
+ var RateLimitError = _RateLimitError;
2297
+ var _InternalServerError = class _InternalServerError extends ApiError {
2298
+ };
2299
+ __name(_InternalServerError, "InternalServerError");
2300
+ var InternalServerError = _InternalServerError;
2301
+ function castToError(err) {
2302
+ if (err instanceof Error)
2303
+ return err;
2304
+ return new Error(err);
2305
+ }
2306
+ __name(castToError, "castToError");
2097
2307
 
2098
2308
  // src/retry.ts
2099
2309
  function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
@@ -2201,6 +2411,108 @@ function calculateResetAt2(resets, format, now = Date.now()) {
2201
2411
  return resetAt?.getTime();
2202
2412
  }
2203
2413
  __name(calculateResetAt2, "calculateResetAt");
2414
+
2415
+ // src/v3/apiClient/pagination.ts
2416
+ var _CursorPage = class _CursorPage {
2417
+ constructor(data, pagination, pageFetcher) {
2418
+ this.pageFetcher = pageFetcher;
2419
+ this.data = data;
2420
+ this.pagination = pagination;
2421
+ }
2422
+ getPaginatedItems() {
2423
+ return this.data ?? [];
2424
+ }
2425
+ hasNextPage() {
2426
+ return !!this.pagination.next;
2427
+ }
2428
+ hasPreviousPage() {
2429
+ return !!this.pagination.previous;
2430
+ }
2431
+ getNextPage() {
2432
+ if (!this.pagination.next) {
2433
+ throw new Error("No next page available");
2434
+ }
2435
+ return this.pageFetcher({
2436
+ after: this.pagination.next
2437
+ });
2438
+ }
2439
+ getPreviousPage() {
2440
+ if (!this.pagination.previous) {
2441
+ throw new Error("No previous page available");
2442
+ }
2443
+ return this.pageFetcher({
2444
+ before: this.pagination.previous
2445
+ });
2446
+ }
2447
+ async *iterPages() {
2448
+ let page = this;
2449
+ yield page;
2450
+ while (page.hasNextPage()) {
2451
+ page = await page.getNextPage();
2452
+ yield page;
2453
+ }
2454
+ }
2455
+ async *[Symbol.asyncIterator]() {
2456
+ for await (const page of this.iterPages()) {
2457
+ for (const item of page.getPaginatedItems()) {
2458
+ yield item;
2459
+ }
2460
+ }
2461
+ }
2462
+ };
2463
+ __name(_CursorPage, "CursorPage");
2464
+ var CursorPage = _CursorPage;
2465
+ var _OffsetLimitPage = class _OffsetLimitPage {
2466
+ constructor(data, pagination, pageFetcher) {
2467
+ this.pageFetcher = pageFetcher;
2468
+ this.data = data;
2469
+ this.pagination = pagination;
2470
+ }
2471
+ getPaginatedItems() {
2472
+ return this.data ?? [];
2473
+ }
2474
+ hasNextPage() {
2475
+ return this.pagination.currentPage < this.pagination.totalPages;
2476
+ }
2477
+ hasPreviousPage() {
2478
+ return this.pagination.currentPage > 1;
2479
+ }
2480
+ getNextPage() {
2481
+ if (!this.hasNextPage()) {
2482
+ throw new Error("No next page available");
2483
+ }
2484
+ return this.pageFetcher({
2485
+ page: this.pagination.currentPage + 1
2486
+ });
2487
+ }
2488
+ getPreviousPage() {
2489
+ if (!this.hasPreviousPage()) {
2490
+ throw new Error("No previous page available");
2491
+ }
2492
+ return this.pageFetcher({
2493
+ page: this.pagination.currentPage - 1
2494
+ });
2495
+ }
2496
+ async *iterPages() {
2497
+ let page = this;
2498
+ yield page;
2499
+ while (page.hasNextPage()) {
2500
+ page = await page.getNextPage();
2501
+ yield page;
2502
+ }
2503
+ }
2504
+ async *[Symbol.asyncIterator]() {
2505
+ for await (const page of this.iterPages()) {
2506
+ for (const item of page.getPaginatedItems()) {
2507
+ yield item;
2508
+ }
2509
+ }
2510
+ }
2511
+ };
2512
+ __name(_OffsetLimitPage, "OffsetLimitPage");
2513
+ var OffsetLimitPage = _OffsetLimitPage;
2514
+
2515
+ // src/v3/apiClient/core.ts
2204
2516
  var defaultRetryOptions2 = {
2205
2517
  maxAttempts: 3,
2206
2518
  factor: 2,
@@ -2208,11 +2520,62 @@ var defaultRetryOptions2 = {
2208
2520
  maxTimeoutInMs: 6e4,
2209
2521
  randomize: false
2210
2522
  };
2211
- async function zodfetch(schema, url, requestInit, options) {
2212
- return await _doZodFetch(schema, url, requestInit, options);
2523
+ function zodfetch(schema, url, requestInit, options) {
2524
+ return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
2213
2525
  }
2214
2526
  __name(zodfetch, "zodfetch");
2215
- async function zodupload(schema, url, body, requestInit, options) {
2527
+ function zodfetchCursorPage(schema, url, params, requestInit, options) {
2528
+ const query = new URLSearchParams(params.query);
2529
+ if (params.limit) {
2530
+ query.set("page[size]", String(params.limit));
2531
+ }
2532
+ if (params.after) {
2533
+ query.set("page[after]", params.after);
2534
+ }
2535
+ if (params.before) {
2536
+ query.set("page[before]", params.before);
2537
+ }
2538
+ const cursorPageSchema = z.object({
2539
+ data: z.array(schema),
2540
+ pagination: z.object({
2541
+ next: z.string().optional(),
2542
+ previous: z.string().optional()
2543
+ })
2544
+ });
2545
+ const $url = new URL(url);
2546
+ $url.search = query.toString();
2547
+ const fetchResult = _doZodFetch(cursorPageSchema, $url.href, requestInit, options);
2548
+ return new CursorPagePromise(fetchResult, schema, url, params, requestInit, options);
2549
+ }
2550
+ __name(zodfetchCursorPage, "zodfetchCursorPage");
2551
+ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
2552
+ const query = new URLSearchParams(params.query);
2553
+ if (params.limit) {
2554
+ query.set("perPage", String(params.limit));
2555
+ }
2556
+ if (params.page) {
2557
+ query.set("page", String(params.page));
2558
+ }
2559
+ const offsetLimitPageSchema = z.object({
2560
+ data: z.array(schema),
2561
+ pagination: z.object({
2562
+ currentPage: z.coerce.number(),
2563
+ totalPages: z.coerce.number(),
2564
+ count: z.coerce.number()
2565
+ })
2566
+ });
2567
+ const $url = new URL(url);
2568
+ $url.search = query.toString();
2569
+ const fetchResult = _doZodFetch(offsetLimitPageSchema, $url.href, requestInit, options);
2570
+ return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
2571
+ }
2572
+ __name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
2573
+ function zodupload(schema, url, body, requestInit, options) {
2574
+ const finalRequestInit = createMultipartFormRequestInit(body, requestInit);
2575
+ return new ApiPromise(_doZodFetch(schema, url, finalRequestInit, options));
2576
+ }
2577
+ __name(zodupload, "zodupload");
2578
+ async function createMultipartFormRequestInit(body, requestInit) {
2216
2579
  const form = await createForm(body);
2217
2580
  const encoder = new FormDataEncoder(form);
2218
2581
  const finalHeaders = {};
@@ -2230,9 +2593,9 @@ async function zodupload(schema, url, body, requestInit, options) {
2230
2593
  // @ts-expect-error
2231
2594
  duplex: "half"
2232
2595
  };
2233
- return await _doZodFetch(schema, url, finalRequestInit, options);
2596
+ return finalRequestInit;
2234
2597
  }
2235
- __name(zodupload, "zodupload");
2598
+ __name(createMultipartFormRequestInit, "createMultipartFormRequestInit");
2236
2599
  var createForm = /* @__PURE__ */ __name(async (body) => {
2237
2600
  const form = new FormData();
2238
2601
  await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
@@ -2240,7 +2603,8 @@ var createForm = /* @__PURE__ */ __name(async (body) => {
2240
2603
  }, "createForm");
2241
2604
  async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2242
2605
  try {
2243
- const response = await fetch(url, requestInitWithCache(requestInit));
2606
+ const $requestInit = await requestInit;
2607
+ const response = await fetch(url, requestInitWithCache($requestInit));
2244
2608
  const responseHeaders = createResponseHeaders(response.headers);
2245
2609
  if (!response.ok) {
2246
2610
  const retryResult = shouldRetry(response, attempt, options?.retry);
@@ -2251,17 +2615,20 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2251
2615
  const errText = await response.text().catch((e) => castToError2(e).message);
2252
2616
  const errJSON = safeJsonParse(errText);
2253
2617
  const errMessage = errJSON ? void 0 : errText;
2254
- throw APIError.generate(response.status, errJSON, errMessage, responseHeaders);
2618
+ throw ApiError.generate(response.status, errJSON, errMessage, responseHeaders);
2255
2619
  }
2256
2620
  }
2257
2621
  const jsonBody = await response.json();
2258
2622
  const parsedResult = schema.safeParse(jsonBody);
2259
2623
  if (parsedResult.success) {
2260
- return parsedResult.data;
2624
+ return {
2625
+ data: parsedResult.data,
2626
+ response
2627
+ };
2261
2628
  }
2262
2629
  throw fromZodError(parsedResult.error);
2263
2630
  } catch (error) {
2264
- if (error instanceof APIError) {
2631
+ if (error instanceof ApiError) {
2265
2632
  throw error;
2266
2633
  }
2267
2634
  if (options?.retry) {
@@ -2275,7 +2642,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2275
2642
  return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
2276
2643
  }
2277
2644
  }
2278
- throw new APIConnectionError({
2645
+ throw new ApiConnectionError({
2279
2646
  cause: castToError2(error)
2280
2647
  });
2281
2648
  }
@@ -2448,6 +2815,128 @@ var isUploadable = /* @__PURE__ */ __name((value) => {
2448
2815
  return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
2449
2816
  }, "isUploadable");
2450
2817
  var isRecordLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length > 0 && Object.keys(value).every((key) => typeof key === "string" && typeof value[key] === "string"), "isRecordLike");
2818
+ var _ApiPromise = class _ApiPromise extends Promise {
2819
+ constructor(responsePromise) {
2820
+ super((resolve) => {
2821
+ resolve(null);
2822
+ });
2823
+ this.responsePromise = responsePromise;
2824
+ }
2825
+ /**
2826
+ * Gets the raw `Response` instance instead of parsing the response
2827
+ * data.
2828
+ *
2829
+ * If you want to parse the response body but still get the `Response`
2830
+ * instance, you can use {@link withResponse()}.
2831
+ */
2832
+ asResponse() {
2833
+ return this.responsePromise.then((p) => p.response);
2834
+ }
2835
+ /**
2836
+ * Gets the parsed response data and the raw `Response` instance.
2837
+ *
2838
+ * If you just want to get the raw `Response` instance without parsing it,
2839
+ * you can use {@link asResponse()}.
2840
+ */
2841
+ async withResponse() {
2842
+ const [data, response] = await Promise.all([
2843
+ this.parse(),
2844
+ this.asResponse()
2845
+ ]);
2846
+ return {
2847
+ data,
2848
+ response
2849
+ };
2850
+ }
2851
+ parse() {
2852
+ return this.responsePromise.then((result) => result.data);
2853
+ }
2854
+ then(onfulfilled, onrejected) {
2855
+ return this.parse().then(onfulfilled, onrejected);
2856
+ }
2857
+ catch(onrejected) {
2858
+ return this.parse().catch(onrejected);
2859
+ }
2860
+ finally(onfinally) {
2861
+ return this.parse().finally(onfinally);
2862
+ }
2863
+ };
2864
+ __name(_ApiPromise, "ApiPromise");
2865
+ var ApiPromise = _ApiPromise;
2866
+ var _fetchPage, fetchPage_fn;
2867
+ var _CursorPagePromise = class _CursorPagePromise extends ApiPromise {
2868
+ constructor(result, schema, url, params, requestInit, options) {
2869
+ super(result.then((result2) => ({
2870
+ data: new CursorPage(result2.data.data, result2.data.pagination, __privateMethod(this, _fetchPage, fetchPage_fn).bind(this)),
2871
+ response: result2.response
2872
+ })));
2873
+ __privateAdd(this, _fetchPage);
2874
+ this.schema = schema;
2875
+ this.url = url;
2876
+ this.params = params;
2877
+ this.requestInit = requestInit;
2878
+ this.options = options;
2879
+ }
2880
+ /**
2881
+ * Allow auto-paginating iteration on an unawaited list call, eg:
2882
+ *
2883
+ * for await (const item of client.items.list()) {
2884
+ * console.log(item)
2885
+ * }
2886
+ */
2887
+ async *[Symbol.asyncIterator]() {
2888
+ const page = await this;
2889
+ for await (const item of page) {
2890
+ yield item;
2891
+ }
2892
+ }
2893
+ };
2894
+ _fetchPage = new WeakSet();
2895
+ fetchPage_fn = /* @__PURE__ */ __name(function(params) {
2896
+ return zodfetchCursorPage(this.schema, this.url, {
2897
+ ...this.params,
2898
+ ...params
2899
+ }, this.requestInit, this.options);
2900
+ }, "#fetchPage");
2901
+ __name(_CursorPagePromise, "CursorPagePromise");
2902
+ var CursorPagePromise = _CursorPagePromise;
2903
+ var _fetchPage2, fetchPage_fn2;
2904
+ var _OffsetLimitPagePromise = class _OffsetLimitPagePromise extends ApiPromise {
2905
+ constructor(result, schema, url, params, requestInit, options) {
2906
+ super(result.then((result2) => ({
2907
+ data: new OffsetLimitPage(result2.data.data, result2.data.pagination, __privateMethod(this, _fetchPage2, fetchPage_fn2).bind(this)),
2908
+ response: result2.response
2909
+ })));
2910
+ __privateAdd(this, _fetchPage2);
2911
+ this.schema = schema;
2912
+ this.url = url;
2913
+ this.params = params;
2914
+ this.requestInit = requestInit;
2915
+ this.options = options;
2916
+ }
2917
+ /**
2918
+ * Allow auto-paginating iteration on an unawaited list call, eg:
2919
+ *
2920
+ * for await (const item of client.items.list()) {
2921
+ * console.log(item)
2922
+ * }
2923
+ */
2924
+ async *[Symbol.asyncIterator]() {
2925
+ const page = await this;
2926
+ for await (const item of page) {
2927
+ yield item;
2928
+ }
2929
+ }
2930
+ };
2931
+ _fetchPage2 = new WeakSet();
2932
+ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
2933
+ return zodfetchOffsetLimitPage(this.schema, this.url, {
2934
+ ...this.params,
2935
+ ...params1
2936
+ }, this.requestInit, this.options);
2937
+ }, "#fetchPage");
2938
+ __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
2939
+ var OffsetLimitPagePromise = _OffsetLimitPagePromise;
2451
2940
 
2452
2941
  // src/v3/apiClient/index.ts
2453
2942
  var zodFetchOptions = {
@@ -2473,7 +2962,7 @@ var _ApiClient = class _ApiClient {
2473
2962
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2474
2963
  }, zodFetchOptions);
2475
2964
  } catch (error) {
2476
- if (error instanceof APIError) {
2965
+ if (error instanceof ApiError) {
2477
2966
  if (error.status === 404) {
2478
2967
  return void 0;
2479
2968
  }
@@ -2488,14 +2977,16 @@ var _ApiClient = class _ApiClient {
2488
2977
  }, zodFetchOptions);
2489
2978
  }
2490
2979
  triggerTask(taskId, body, options) {
2491
- return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/trigger`, {
2980
+ const encodedTaskId = encodeURIComponent(taskId);
2981
+ return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/trigger`, {
2492
2982
  method: "POST",
2493
2983
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2494
2984
  body: JSON.stringify(body)
2495
2985
  }, zodFetchOptions);
2496
2986
  }
2497
2987
  batchTriggerTask(taskId, body, options) {
2498
- return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/batch`, {
2988
+ const encodedTaskId = encodeURIComponent(taskId);
2989
+ return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/batch`, {
2499
2990
  method: "POST",
2500
2991
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2501
2992
  body: JSON.stringify(body)
@@ -2519,6 +3010,33 @@ var _ApiClient = class _ApiClient {
2519
3010
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2520
3011
  }, zodFetchOptions);
2521
3012
  }
3013
+ listRuns(query) {
3014
+ const searchParams = createSearchQueryForListRuns(query);
3015
+ return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/runs`, {
3016
+ query: searchParams,
3017
+ limit: query?.limit,
3018
+ after: query?.after,
3019
+ before: query?.before
3020
+ }, {
3021
+ method: "GET",
3022
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3023
+ }, zodFetchOptions);
3024
+ }
3025
+ listProjectRuns(projectRef, query) {
3026
+ const searchParams = createSearchQueryForListRuns(query);
3027
+ if (query?.env) {
3028
+ searchParams.append("filter[env]", Array.isArray(query.env) ? query.env.join(",") : query.env);
3029
+ }
3030
+ return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/projects/${projectRef}/runs`, {
3031
+ query: searchParams,
3032
+ limit: query?.limit,
3033
+ after: query?.after,
3034
+ before: query?.before
3035
+ }, {
3036
+ method: "GET",
3037
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3038
+ }, zodFetchOptions);
3039
+ }
2522
3040
  replayRun(runId) {
2523
3041
  return zodfetch(ReplayRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/replay`, {
2524
3042
  method: "POST",
@@ -2546,7 +3064,10 @@ var _ApiClient = class _ApiClient {
2546
3064
  if (options?.perPage) {
2547
3065
  searchParams.append("perPage", options.perPage.toString());
2548
3066
  }
2549
- return zodfetch(ListSchedulesResult, `${this.baseUrl}/api/v1/schedules${searchParams.size > 0 ? `?${searchParams}` : ""}`, {
3067
+ return zodfetchOffsetLimitPage(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
3068
+ page: options?.page,
3069
+ limit: options?.perPage
3070
+ }, {
2550
3071
  method: "GET",
2551
3072
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2552
3073
  });
@@ -2647,6 +3168,40 @@ getHeaders_fn = /* @__PURE__ */ __name(function(spanParentAsLink) {
2647
3168
  }, "#getHeaders");
2648
3169
  __name(_ApiClient, "ApiClient");
2649
3170
  var ApiClient = _ApiClient;
3171
+ function createSearchQueryForListRuns(query) {
3172
+ const searchParams = new URLSearchParams();
3173
+ if (query) {
3174
+ if (query.status) {
3175
+ searchParams.append("filter[status]", Array.isArray(query.status) ? query.status.join(",") : query.status);
3176
+ }
3177
+ if (query.taskIdentifier) {
3178
+ searchParams.append("filter[taskIdentifier]", Array.isArray(query.taskIdentifier) ? query.taskIdentifier.join(",") : query.taskIdentifier);
3179
+ }
3180
+ if (query.version) {
3181
+ searchParams.append("filter[version]", Array.isArray(query.version) ? query.version.join(",") : query.version);
3182
+ }
3183
+ if (query.bulkAction) {
3184
+ searchParams.append("filter[bulkAction]", query.bulkAction);
3185
+ }
3186
+ if (query.schedule) {
3187
+ searchParams.append("filter[schedule]", query.schedule);
3188
+ }
3189
+ if (typeof query.isTest === "boolean") {
3190
+ searchParams.append("filter[isTest]", String(query.isTest));
3191
+ }
3192
+ if (query.from) {
3193
+ searchParams.append("filter[createdAt][from]", query.from instanceof Date ? query.from.getTime().toString() : query.from.toString());
3194
+ }
3195
+ if (query.to) {
3196
+ searchParams.append("filter[createdAt][to]", query.to instanceof Date ? query.to.getTime().toString() : query.to.toString());
3197
+ }
3198
+ if (query.period) {
3199
+ searchParams.append("filter[createdAt][period]", query.period);
3200
+ }
3201
+ }
3202
+ return searchParams;
3203
+ }
3204
+ __name(createSearchQueryForListRuns, "createSearchQueryForListRuns");
2650
3205
  var _SimpleClock = class _SimpleClock {
2651
3206
  preciseNow() {
2652
3207
  const now = new PreciseDate();
@@ -2696,149 +3251,6 @@ var ClockAPI = _ClockAPI;
2696
3251
  // src/v3/clock-api.ts
2697
3252
  var clock = ClockAPI.getInstance();
2698
3253
 
2699
- // src/v3/errors.ts
2700
- function parseError(error) {
2701
- if (error instanceof Error) {
2702
- return {
2703
- type: "BUILT_IN_ERROR",
2704
- name: error.name,
2705
- message: error.message,
2706
- stackTrace: error.stack ?? ""
2707
- };
2708
- }
2709
- if (typeof error === "string") {
2710
- return {
2711
- type: "STRING_ERROR",
2712
- raw: error
2713
- };
2714
- }
2715
- try {
2716
- return {
2717
- type: "CUSTOM_ERROR",
2718
- raw: JSON.stringify(error)
2719
- };
2720
- } catch (e) {
2721
- return {
2722
- type: "CUSTOM_ERROR",
2723
- raw: String(error)
2724
- };
2725
- }
2726
- }
2727
- __name(parseError, "parseError");
2728
- function createErrorTaskError(error) {
2729
- switch (error.type) {
2730
- case "BUILT_IN_ERROR": {
2731
- const e = new Error(error.message);
2732
- e.name = error.name;
2733
- e.stack = error.stackTrace;
2734
- return e;
2735
- }
2736
- case "STRING_ERROR": {
2737
- return error.raw;
2738
- }
2739
- case "CUSTOM_ERROR": {
2740
- return JSON.parse(error.raw);
2741
- }
2742
- case "INTERNAL_ERROR": {
2743
- return new Error(`trigger.dev internal error (${error.code})`);
2744
- }
2745
- }
2746
- }
2747
- __name(createErrorTaskError, "createErrorTaskError");
2748
- function createJsonErrorObject(error) {
2749
- switch (error.type) {
2750
- case "BUILT_IN_ERROR": {
2751
- return {
2752
- name: error.name,
2753
- message: error.message,
2754
- stackTrace: error.stackTrace
2755
- };
2756
- }
2757
- case "STRING_ERROR": {
2758
- return {
2759
- message: error.raw
2760
- };
2761
- }
2762
- case "CUSTOM_ERROR": {
2763
- return {
2764
- message: error.raw
2765
- };
2766
- }
2767
- case "INTERNAL_ERROR": {
2768
- return {
2769
- message: `trigger.dev internal error (${error.code})`
2770
- };
2771
- }
2772
- }
2773
- }
2774
- __name(createJsonErrorObject, "createJsonErrorObject");
2775
- function correctErrorStackTrace(stackTrace, projectDir, options) {
2776
- const [errorLine, ...traceLines] = stackTrace.split("\n");
2777
- return [
2778
- options?.removeFirstLine ? void 0 : errorLine,
2779
- ...traceLines.map((line) => correctStackTraceLine(line, projectDir, options?.isDev))
2780
- ].filter(Boolean).join("\n");
2781
- }
2782
- __name(correctErrorStackTrace, "correctErrorStackTrace");
2783
- var LINES_TO_IGNORE = [
2784
- /ConsoleInterceptor/,
2785
- /TriggerTracer/,
2786
- /TaskExecutor/,
2787
- /EXECUTE_TASK_RUN/,
2788
- /@trigger.dev\/core/,
2789
- /packages\/core\/src\/v3/,
2790
- /safeJsonProcess/,
2791
- /__entryPoint.ts/,
2792
- /ZodIpc/,
2793
- /startActiveSpan/,
2794
- /processTicksAndRejections/
2795
- ];
2796
- function correctStackTraceLine(line, projectDir, isDev) {
2797
- if (LINES_TO_IGNORE.some((regex) => regex.test(line))) {
2798
- return;
2799
- }
2800
- if (isDev && projectDir && !line.includes(projectDir)) {
2801
- return;
2802
- }
2803
- return line.trim();
2804
- }
2805
- __name(correctStackTraceLine, "correctStackTraceLine");
2806
- function groupTaskMetadataIssuesByTask(tasks, issues) {
2807
- return issues.reduce((acc, issue) => {
2808
- if (issue.path.length === 0) {
2809
- return acc;
2810
- }
2811
- const taskIndex = issue.path[1];
2812
- if (typeof taskIndex !== "number") {
2813
- return acc;
2814
- }
2815
- const task = tasks[taskIndex];
2816
- if (!task) {
2817
- return acc;
2818
- }
2819
- const restOfPath = issue.path.slice(2);
2820
- const taskId = task.id;
2821
- const taskName = task.exportName;
2822
- const filePath = task.filePath;
2823
- const key = taskIndex;
2824
- const existing = acc[key] ?? {
2825
- id: taskId,
2826
- exportName: taskName,
2827
- filePath,
2828
- issues: []
2829
- };
2830
- existing.issues.push({
2831
- message: issue.message,
2832
- path: restOfPath.length === 0 ? void 0 : restOfPath.join(".")
2833
- });
2834
- return {
2835
- ...acc,
2836
- [key]: existing
2837
- };
2838
- }, {});
2839
- }
2840
- __name(groupTaskMetadataIssuesByTask, "groupTaskMetadataIssuesByTask");
2841
-
2842
3254
  // src/v3/limits.ts
2843
3255
  var OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = 256;
2844
3256
  var OTEL_LOG_ATTRIBUTE_COUNT_LIMIT = 256;
@@ -3870,6 +4282,6 @@ function safeJsonParse2(value) {
3870
4282
  }
3871
4283
  __name(safeJsonParse2, "safeJsonParse");
3872
4284
 
3873
- export { APIConnectionError, APIError, ApiClient, AttemptStatus, AuthenticationError, BackgroundWorkerClientMessages, BackgroundWorkerMetadata, BackgroundWorkerProperties, BackgroundWorkerServerMessages, BadRequestError, BatchTaskRunExecutionResult, BatchTriggerTaskRequestBody, BatchTriggerTaskResponse, CanceledRunResponse, CancellationSpanEvent, ClientToSharedQueueMessages, Config, ConflictError, CoordinatorToPlatformMessages, CoordinatorToProdWorkerMessages, CreateAuthorizationCodeResponseSchema, CreateBackgroundWorkerRequestBody, CreateBackgroundWorkerResponse, CreateEnvironmentVariableRequestBody, CreateScheduleOptions, CreateUploadPayloadUrlResponseBody, DeletedScheduleObject, DeploymentErrorData, EnvironmentType, EnvironmentVariable, EnvironmentVariableResponseBody, EnvironmentVariableValue, EnvironmentVariables, EventFilter, ExceptionEventProperties, ExceptionSpanEvent, ExternalBuildData, FetchRetryBackoffStrategy, FetchRetryByStatusOptions, FetchRetryHeadersStrategy, FetchRetryOptions, FetchRetryStrategy, FetchTimeoutOptions, FixedWindowRateLimit, GetBatchResponseBody, GetDeploymentResponseBody, GetEnvironmentVariablesResponseBody, GetPersonalAccessTokenRequestSchema, GetPersonalAccessTokenResponseSchema, GetProjectEnvResponse, GetProjectResponseBody, GetProjectsResponseBody, ImageDetailsMetadata, ImportEnvironmentVariablesRequestBody, InitializeDeploymentRequestBody, InitializeDeploymentResponseBody, InternalServerError, ListScheduleOptions, ListSchedulesResult, Machine, MachineCpu, MachineMemory, NULL_SENTINEL, NotFoundError, OFFLOAD_IO_PACKET_LENGTH_LIMIT, OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT, OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT, OTEL_LINK_COUNT_LIMIT, OTEL_LOG_ATTRIBUTE_COUNT_LIMIT, OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_EVENT_COUNT_LIMIT, OtherSpanEvent, PRIMARY_VARIANT, PermissionDeniedError, PlatformToCoordinatorMessages, PlatformToProviderMessages, PostStartCauses, PreStopCauses, ProdChildToWorkerMessages, ProdTaskRunExecution, ProdTaskRunExecutionPayload, ProdWorkerSocketData, ProdWorkerToChildMessages, ProdWorkerToCoordinatorMessages, ProviderToPlatformMessages, QueueOptions, RateLimitError, RateLimitOptions, ReplayRunResponse, RetrieveRunResponse, RetryOptions, RunStatus, ScheduleObject, ScheduledTaskPayload, SemanticInternalAttributes, SharedQueueToClientMessages, SlidingWindowRateLimit, SpanEvent, SpanEvents, SpanMessagingEvent, StartDeploymentIndexingRequestBody, StartDeploymentIndexingResponseBody, TaskEventStyle, TaskFileMetadata, TaskMetadata, TaskMetadataFailedToParseData, TaskMetadataWithFilePath, TaskResource, TaskRun, TaskRunBuiltInError, TaskRunContext, TaskRunCustomErrorObject, TaskRunError, TaskRunErrorCodes, TaskRunExecution, TaskRunExecutionAttempt, TaskRunExecutionBatch, TaskRunExecutionEnvironment, TaskRunExecutionLazyAttemptPayload, TaskRunExecutionOrganization, TaskRunExecutionPayload, TaskRunExecutionProject, TaskRunExecutionQueue, TaskRunExecutionResult, TaskRunExecutionRetry, TaskRunExecutionTask, TaskRunFailedExecutionResult, TaskRunInternalError, TaskRunStringError, TaskRunSuccessfulExecutionResult, TriggerTaskRequestBody, TriggerTaskResponse, TriggerTracer, UncaughtExceptionMessage, UnprocessableEntityError, UpdateEnvironmentVariableRequestBody, UpdateScheduleOptions, WaitReason, WhoAmIResponseSchema, accessoryAttributes, apiClientManager, calculateNextRetryDelay, calculateResetAt2 as calculateResetAt, childToWorkerMessages, clientWebsocketMessages, clock, conditionallyExportPacket, conditionallyImportPacket, correctErrorStackTrace, createErrorTaskError, createJsonErrorObject, createPacketAttributes, createPacketAttributesAsJson, defaultFetchRetryOptions, defaultRetryOptions, detectDependencyVersion, eventFilterMatches, flattenAttributes, formatDuration, formatDurationInDays, formatDurationMilliseconds, formatDurationNanoseconds, groupTaskMetadataIssuesByTask, imposeAttributeLimits, isCancellationSpanEvent, isExceptionSpanEvent, logger, millisecondsToNanoseconds, nanosecondsToMilliseconds, omit, packetRequiresOffloading, parseError, parsePacket, prettyPrintPacket, primitiveValueOrflattenedAttributes, runtime, serverWebsocketMessages, stringPatternMatchers, stringifyIO, taskCatalog, taskContext, unflattenAttributes, workerToChildMessages };
4285
+ export { ApiClient, ApiConnectionError, ApiError, AttemptStatus, AuthenticationError, BackgroundWorkerClientMessages, BackgroundWorkerMetadata, BackgroundWorkerProperties, BackgroundWorkerServerMessages, BadRequestError, BatchTaskRunExecutionResult, BatchTriggerTaskRequestBody, BatchTriggerTaskResponse, CanceledRunResponse, CancellationSpanEvent, ClientToSharedQueueMessages, Config, ConflictError, CoordinatorToPlatformMessages, CoordinatorToProdWorkerMessages, CreateAuthorizationCodeResponseSchema, CreateBackgroundWorkerRequestBody, CreateBackgroundWorkerResponse, CreateEnvironmentVariableRequestBody, CreateScheduleOptions, CreateUploadPayloadUrlResponseBody, CursorPage, DeletedScheduleObject, DeploymentErrorData, EnvironmentType, EnvironmentVariable, EnvironmentVariableResponseBody, EnvironmentVariableValue, EnvironmentVariables, EventFilter, ExceptionEventProperties, ExceptionSpanEvent, ExternalBuildData, FetchRetryBackoffStrategy, FetchRetryByStatusOptions, FetchRetryHeadersStrategy, FetchRetryOptions, FetchRetryStrategy, FetchTimeoutOptions, FixedWindowRateLimit, GetBatchResponseBody, GetDeploymentResponseBody, GetEnvironmentVariablesResponseBody, GetPersonalAccessTokenRequestSchema, GetPersonalAccessTokenResponseSchema, GetProjectEnvResponse, GetProjectResponseBody, GetProjectsResponseBody, ImageDetailsMetadata, ImportEnvironmentVariablesRequestBody, InitializeDeploymentRequestBody, InitializeDeploymentResponseBody, InternalServerError, ListRunResponse, ListRunResponseItem, ListScheduleOptions, ListSchedulesResult, Machine, MachineCpu, MachineMemory, NULL_SENTINEL, NotFoundError, OFFLOAD_IO_PACKET_LENGTH_LIMIT, OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT, OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT, OTEL_LINK_COUNT_LIMIT, OTEL_LOG_ATTRIBUTE_COUNT_LIMIT, OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_EVENT_COUNT_LIMIT, OffsetLimitPage, OtherSpanEvent, PRIMARY_VARIANT, PermissionDeniedError, PlatformToCoordinatorMessages, PlatformToProviderMessages, PostStartCauses, PreStopCauses, ProdChildToWorkerMessages, ProdTaskRunExecution, ProdTaskRunExecutionPayload, ProdWorkerSocketData, ProdWorkerToChildMessages, ProdWorkerToCoordinatorMessages, ProviderToPlatformMessages, QueueOptions, RateLimitError, RateLimitOptions, ReplayRunResponse, RetrieveRunResponse, RetryOptions, RunEnvironmentDetails, RunScheduleDetails, RunStatus, ScheduleGenerator, ScheduleObject, ScheduledTaskPayload, SemanticInternalAttributes, SerializedError, SharedQueueToClientMessages, SlidingWindowRateLimit, SpanEvent, SpanEvents, SpanMessagingEvent, StartDeploymentIndexingRequestBody, StartDeploymentIndexingResponseBody, TaskEventStyle, TaskFileMetadata, TaskMetadata, TaskMetadataFailedToParseData, TaskMetadataWithFilePath, TaskResource, TaskRun, TaskRunBuiltInError, TaskRunContext, TaskRunCustomErrorObject, TaskRunError, TaskRunErrorCodes, TaskRunExecution, TaskRunExecutionAttempt, TaskRunExecutionBatch, TaskRunExecutionEnvironment, TaskRunExecutionLazyAttemptPayload, TaskRunExecutionOrganization, TaskRunExecutionPayload, TaskRunExecutionProject, TaskRunExecutionQueue, TaskRunExecutionResult, TaskRunExecutionRetry, TaskRunExecutionTask, TaskRunFailedExecutionResult, TaskRunInternalError, TaskRunStringError, TaskRunSuccessfulExecutionResult, TriggerTaskRequestBody, TriggerTaskResponse, TriggerTracer, UncaughtExceptionMessage, UnprocessableEntityError, UpdateEnvironmentVariableRequestBody, UpdateScheduleOptions, WaitReason, WhoAmIResponseSchema, accessoryAttributes, apiClientManager, calculateNextRetryDelay, calculateResetAt2 as calculateResetAt, childToWorkerMessages, clientWebsocketMessages, clock, conditionallyExportPacket, conditionallyImportPacket, correctErrorStackTrace, createErrorTaskError, createJsonErrorObject, createPacketAttributes, createPacketAttributesAsJson, defaultFetchRetryOptions, defaultRetryOptions, detectDependencyVersion, eventFilterMatches, flattenAttributes, formatDuration, formatDurationInDays, formatDurationMilliseconds, formatDurationNanoseconds, groupTaskMetadataIssuesByTask, imposeAttributeLimits, isCancellationSpanEvent, isExceptionSpanEvent, logger, millisecondsToNanoseconds, nanosecondsToMilliseconds, omit, packetRequiresOffloading, parseError, parsePacket, prettyPrintPacket, primitiveValueOrflattenedAttributes, runtime, serverWebsocketMessages, stringPatternMatchers, stringifyIO, taskCatalog, taskContext, unflattenAttributes, workerToChildMessages };
3874
4286
  //# sourceMappingURL=out.js.map
3875
4287
  //# sourceMappingURL=index.mjs.map