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

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-9lty-Du5.d.mts} +139 -166
  6. package/dist/{messages-l9PdIyKF.d.ts → messages-9lty-Du5.d.ts} +139 -166
  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 +587 -122
  12. package/dist/v3/index.d.ts +587 -122
  13. package/dist/v3/index.js +749 -348
  14. package/dist/v3/index.js.map +1 -1
  15. package/dist/v3/index.mjs +740 -347
  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 +465 -52
  26. package/dist/v3/workers/index.js.map +1 -1
  27. package/dist/v3/workers/index.mjs +465 -52
  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
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var api = require('@opentelemetry/api');
4
+ var zod = require('zod');
4
5
  var apiLogs = require('@opentelemetry/api-logs');
5
6
  var exporterLogsOtlpHttp = require('@opentelemetry/exporter-logs-otlp-http');
6
7
  var exporterTraceOtlpHttp = require('@opentelemetry/exporter-trace-otlp-http');
@@ -9,7 +10,6 @@ var resources = require('@opentelemetry/resources');
9
10
  var sdkLogs = require('@opentelemetry/sdk-logs');
10
11
  var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
11
12
  var semanticConventions = require('@opentelemetry/semantic-conventions');
12
- var zod = require('zod');
13
13
  var zodValidationError = require('zod-validation-error');
14
14
  var formDataEncoder = require('form-data-encoder');
15
15
  var stream = require('stream');
@@ -44,8 +44,6 @@ var __privateMethod = (obj, member, method) => {
44
44
  __accessCheck(obj, member, "access private method");
45
45
  return method;
46
46
  };
47
-
48
- // src/v3/errors.ts
49
47
  function parseError(error) {
50
48
  if (error instanceof Error) {
51
49
  return {
@@ -74,6 +72,11 @@ function parseError(error) {
74
72
  }
75
73
  }
76
74
  __name(parseError, "parseError");
75
+ var SerializedError = zod.z.object({
76
+ message: zod.z.string(),
77
+ name: zod.z.string().optional(),
78
+ stackTrace: zod.z.string().optional()
79
+ });
77
80
 
78
81
  // src/v3/limits.ts
79
82
  var OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = 256;
@@ -358,7 +361,7 @@ function getEnvVar(name) {
358
361
  __name(getEnvVar, "getEnvVar");
359
362
 
360
363
  // package.json
361
- var version = "3.0.0-beta.35";
364
+ var version = "3.0.0-beta.37";
362
365
 
363
366
  // src/v3/otel/tracingSDK.ts
364
367
  var _a;
@@ -799,7 +802,7 @@ var QueueOptions = zod.z.object({
799
802
  /** @deprecated This feature is coming soon */
800
803
  rateLimit: RateLimitOptions.optional()
801
804
  });
802
- var TaskMetadata = zod.z.object({
805
+ zod.z.object({
803
806
  id: zod.z.string(),
804
807
  packageVersion: zod.z.string(),
805
808
  queue: QueueOptions.optional(),
@@ -807,11 +810,20 @@ var TaskMetadata = zod.z.object({
807
810
  machine: Machine.partial().optional(),
808
811
  triggerSource: zod.z.string().optional()
809
812
  });
810
- var TaskFileMetadata = zod.z.object({
813
+ zod.z.object({
814
+ filePath: zod.z.string(),
815
+ exportName: zod.z.string()
816
+ });
817
+ zod.z.object({
818
+ id: zod.z.string(),
819
+ packageVersion: zod.z.string(),
820
+ queue: QueueOptions.optional(),
821
+ retry: RetryOptions.optional(),
822
+ machine: Machine.partial().optional(),
823
+ triggerSource: zod.z.string().optional(),
811
824
  filePath: zod.z.string(),
812
825
  exportName: zod.z.string()
813
826
  });
814
- TaskMetadata.merge(TaskFileMetadata);
815
827
  zod.z.enum([
816
828
  "index",
817
829
  "create",
@@ -986,7 +998,8 @@ zod.z.object({
986
998
  var DeploymentErrorData = zod.z.object({
987
999
  name: zod.z.string(),
988
1000
  message: zod.z.string(),
989
- stack: zod.z.string().optional()
1001
+ stack: zod.z.string().optional(),
1002
+ stderr: zod.z.string().optional()
990
1003
  });
991
1004
  zod.z.object({
992
1005
  id: zod.z.string(),
@@ -1022,7 +1035,7 @@ var ReplayRunResponse = zod.z.object({
1022
1035
  id: zod.z.string()
1023
1036
  });
1024
1037
  var CanceledRunResponse = zod.z.object({
1025
- message: zod.z.string()
1038
+ id: zod.z.string()
1026
1039
  });
1027
1040
  zod.z.object({
1028
1041
  /** The schedule id associated with this run (you can have many schedules for the same task).
@@ -1071,17 +1084,18 @@ zod.z.object({
1071
1084
  */
1072
1085
  externalId: zod.z.string().optional()
1073
1086
  });
1087
+ var ScheduleGenerator = zod.z.object({
1088
+ type: zod.z.literal("CRON"),
1089
+ expression: zod.z.string(),
1090
+ description: zod.z.string()
1091
+ });
1074
1092
  var ScheduleObject = zod.z.object({
1075
1093
  id: zod.z.string(),
1076
1094
  task: zod.z.string(),
1077
1095
  active: zod.z.boolean(),
1078
1096
  deduplicationKey: zod.z.string().nullish(),
1079
1097
  externalId: zod.z.string().nullish(),
1080
- generator: zod.z.object({
1081
- type: zod.z.literal("CRON"),
1082
- expression: zod.z.string(),
1083
- description: zod.z.string()
1084
- }),
1098
+ generator: ScheduleGenerator,
1085
1099
  nextRun: zod.z.coerce.date().nullish(),
1086
1100
  environments: zod.z.array(zod.z.object({
1087
1101
  id: zod.z.string(),
@@ -1092,7 +1106,7 @@ var ScheduleObject = zod.z.object({
1092
1106
  var DeletedScheduleObject = zod.z.object({
1093
1107
  id: zod.z.string()
1094
1108
  });
1095
- var ListSchedulesResult = zod.z.object({
1109
+ zod.z.object({
1096
1110
  data: zod.z.array(ScheduleObject),
1097
1111
  pagination: zod.z.object({
1098
1112
  currentPage: zod.z.number(),
@@ -1105,12 +1119,28 @@ zod.z.object({
1105
1119
  perPage: zod.z.number().optional()
1106
1120
  });
1107
1121
  var RunStatus = zod.z.enum([
1108
- "PENDING",
1122
+ /// Task hasn't been deployed yet but is waiting to be executed
1123
+ "WAITING_FOR_DEPLOY",
1124
+ /// Task is waiting to be executed by a worker
1125
+ "QUEUED",
1126
+ /// Task is currently being executed by a worker
1109
1127
  "EXECUTING",
1110
- "PAUSED",
1128
+ /// Task has failed and is waiting to be retried
1129
+ "REATTEMPTING",
1130
+ /// Task has been paused by the system, and will be resumed by the system
1131
+ "FROZEN",
1132
+ /// Task has been completed successfully
1111
1133
  "COMPLETED",
1134
+ /// Task has been canceled by the user
1135
+ "CANCELED",
1136
+ /// Task has been completed with errors
1112
1137
  "FAILED",
1113
- "CANCELED"
1138
+ /// Task has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage
1139
+ "CRASHED",
1140
+ /// Task was interrupted during execution, mostly this happens in development environments
1141
+ "INTERRUPTED",
1142
+ /// Task has failed to complete, due to an error in the system
1143
+ "SYSTEM_FAILURE"
1114
1144
  ]);
1115
1145
  var AttemptStatus = zod.z.enum([
1116
1146
  "PENDING",
@@ -1120,23 +1150,61 @@ var AttemptStatus = zod.z.enum([
1120
1150
  "FAILED",
1121
1151
  "CANCELED"
1122
1152
  ]);
1123
- var RetrieveRunResponse = zod.z.object({
1153
+ var RunEnvironmentDetails = zod.z.object({
1154
+ id: zod.z.string(),
1155
+ name: zod.z.string(),
1156
+ user: zod.z.string().optional()
1157
+ });
1158
+ var RunScheduleDetails = zod.z.object({
1159
+ id: zod.z.string(),
1160
+ externalId: zod.z.string().optional(),
1161
+ deduplicationKey: zod.z.string().optional(),
1162
+ generator: ScheduleGenerator
1163
+ });
1164
+ var CommonRunFields = {
1124
1165
  id: zod.z.string(),
1125
1166
  status: RunStatus,
1126
1167
  taskIdentifier: zod.z.string(),
1127
1168
  idempotencyKey: zod.z.string().optional(),
1128
1169
  version: zod.z.string().optional(),
1170
+ isQueued: zod.z.boolean(),
1171
+ isExecuting: zod.z.boolean(),
1172
+ isCompleted: zod.z.boolean(),
1173
+ isSuccess: zod.z.boolean(),
1174
+ isFailed: zod.z.boolean(),
1175
+ isCancelled: zod.z.boolean(),
1176
+ isTest: zod.z.boolean(),
1129
1177
  createdAt: zod.z.coerce.date(),
1130
1178
  updatedAt: zod.z.coerce.date(),
1179
+ startedAt: zod.z.coerce.date().optional(),
1180
+ finishedAt: zod.z.coerce.date().optional()
1181
+ };
1182
+ var RetrieveRunResponse = zod.z.object({
1183
+ ...CommonRunFields,
1184
+ payload: zod.z.any().optional(),
1185
+ output: zod.z.any().optional(),
1186
+ schedule: RunScheduleDetails.optional(),
1131
1187
  attempts: zod.z.array(zod.z.object({
1132
1188
  id: zod.z.string(),
1133
1189
  status: AttemptStatus,
1134
1190
  createdAt: zod.z.coerce.date(),
1135
1191
  updatedAt: zod.z.coerce.date(),
1136
1192
  startedAt: zod.z.coerce.date().optional(),
1137
- completedAt: zod.z.coerce.date().optional()
1193
+ completedAt: zod.z.coerce.date().optional(),
1194
+ error: SerializedError.optional()
1138
1195
  }).optional())
1139
1196
  });
1197
+ var ListRunResponseItem = zod.z.object({
1198
+ ...CommonRunFields,
1199
+ env: RunEnvironmentDetails
1200
+ });
1201
+ zod.z.object({
1202
+ data: zod.z.array(ListRunResponseItem),
1203
+ pagination: zod.z.object({
1204
+ next: zod.z.string().optional(),
1205
+ previous: zod.z.string().optional()
1206
+ })
1207
+ });
1140
1208
  zod.z.object({
1141
1209
  name: zod.z.string(),
1142
1210
  value: zod.z.string()
@@ -1160,10 +1228,10 @@ var EnvironmentVariable = zod.z.object({
1160
1228
  });
1161
1229
  var EnvironmentVariables = zod.z.array(EnvironmentVariable);
1162
1230
 
1163
- // src/v3/apiErrors.ts
1164
- var _APIError = class _APIError extends Error {
1231
+ // src/v3/apiClient/errors.ts
1232
+ var _ApiError = class _ApiError extends Error {
1165
1233
  constructor(status, error, message, headers) {
1166
- super(`${_APIError.makeMessage(status, error, message)}`);
1234
+ super(`${_ApiError.makeMessage(status, error, message)}`);
1167
1235
  this.status = status;
1168
1236
  this.headers = headers;
1169
1237
  const data = error;
@@ -1187,7 +1255,7 @@ var _APIError = class _APIError extends Error {
1187
1255
  }
1188
1256
  static generate(status, errorResponse, message, headers) {
1189
1257
  if (!status) {
1190
- return new APIConnectionError({
1258
+ return new ApiConnectionError({
1191
1259
  cause: castToError(errorResponse)
1192
1260
  });
1193
1261
  }
@@ -1216,12 +1284,12 @@ var _APIError = class _APIError extends Error {
1216
1284
  if (status >= 500) {
1217
1285
  return new InternalServerError(status, error, message, headers);
1218
1286
  }
1219
- return new _APIError(status, error, message, headers);
1287
+ return new _ApiError(status, error, message, headers);
1220
1288
  }
1221
1289
  };
1222
- __name(_APIError, "APIError");
1223
- var APIError = _APIError;
1224
- var _APIConnectionError = class _APIConnectionError extends APIError {
1290
+ __name(_ApiError, "ApiError");
1291
+ var ApiError = _ApiError;
1292
+ var _ApiConnectionError = class _ApiConnectionError extends ApiError {
1225
1293
  constructor({ message, cause }) {
1226
1294
  super(void 0, void 0, message || "Connection error.", void 0);
1227
1295
  __publicField(this, "status");
@@ -1229,9 +1297,9 @@ var _APIConnectionError = class _APIConnectionError extends APIError {
1229
1297
  this.cause = cause;
1230
1298
  }
1231
1299
  };
1232
- __name(_APIConnectionError, "APIConnectionError");
1233
- var APIConnectionError = _APIConnectionError;
1234
- var _BadRequestError = class _BadRequestError extends APIError {
1300
+ __name(_ApiConnectionError, "ApiConnectionError");
1301
+ var ApiConnectionError = _ApiConnectionError;
1302
+ var _BadRequestError = class _BadRequestError extends ApiError {
1235
1303
  constructor() {
1236
1304
  super(...arguments);
1237
1305
  __publicField(this, "status", 400);
@@ -1239,7 +1307,7 @@ var _BadRequestError = class _BadRequestError extends APIError {
1239
1307
  };
1240
1308
  __name(_BadRequestError, "BadRequestError");
1241
1309
  var BadRequestError = _BadRequestError;
1242
- var _AuthenticationError = class _AuthenticationError extends APIError {
1310
+ var _AuthenticationError = class _AuthenticationError extends ApiError {
1243
1311
  constructor() {
1244
1312
  super(...arguments);
1245
1313
  __publicField(this, "status", 401);
@@ -1247,7 +1315,7 @@ var _AuthenticationError = class _AuthenticationError extends APIError {
1247
1315
  };
1248
1316
  __name(_AuthenticationError, "AuthenticationError");
1249
1317
  var AuthenticationError = _AuthenticationError;
1250
- var _PermissionDeniedError = class _PermissionDeniedError extends APIError {
1318
+ var _PermissionDeniedError = class _PermissionDeniedError extends ApiError {
1251
1319
  constructor() {
1252
1320
  super(...arguments);
1253
1321
  __publicField(this, "status", 403);
@@ -1255,7 +1323,7 @@ var _PermissionDeniedError = class _PermissionDeniedError extends APIError {
1255
1323
  };
1256
1324
  __name(_PermissionDeniedError, "PermissionDeniedError");
1257
1325
  var PermissionDeniedError = _PermissionDeniedError;
1258
- var _NotFoundError = class _NotFoundError extends APIError {
1326
+ var _NotFoundError = class _NotFoundError extends ApiError {
1259
1327
  constructor() {
1260
1328
  super(...arguments);
1261
1329
  __publicField(this, "status", 404);
@@ -1263,7 +1331,7 @@ var _NotFoundError = class _NotFoundError extends APIError {
1263
1331
  };
1264
1332
  __name(_NotFoundError, "NotFoundError");
1265
1333
  var NotFoundError = _NotFoundError;
1266
- var _ConflictError = class _ConflictError extends APIError {
1334
+ var _ConflictError = class _ConflictError extends ApiError {
1267
1335
  constructor() {
1268
1336
  super(...arguments);
1269
1337
  __publicField(this, "status", 409);
@@ -1271,7 +1339,7 @@ var _ConflictError = class _ConflictError extends APIError {
1271
1339
  };
1272
1340
  __name(_ConflictError, "ConflictError");
1273
1341
  var ConflictError = _ConflictError;
1274
- var _UnprocessableEntityError = class _UnprocessableEntityError extends APIError {
1342
+ var _UnprocessableEntityError = class _UnprocessableEntityError extends ApiError {
1275
1343
  constructor() {
1276
1344
  super(...arguments);
1277
1345
  __publicField(this, "status", 422);
@@ -1279,7 +1347,7 @@ var _UnprocessableEntityError = class _UnprocessableEntityError extends APIError
1279
1347
  };
1280
1348
  __name(_UnprocessableEntityError, "UnprocessableEntityError");
1281
1349
  var UnprocessableEntityError = _UnprocessableEntityError;
1282
- var _RateLimitError = class _RateLimitError extends APIError {
1350
+ var _RateLimitError = class _RateLimitError extends ApiError {
1283
1351
  constructor() {
1284
1352
  super(...arguments);
1285
1353
  __publicField(this, "status", 429);
@@ -1287,7 +1355,7 @@ var _RateLimitError = class _RateLimitError extends APIError {
1287
1355
  };
1288
1356
  __name(_RateLimitError, "RateLimitError");
1289
1357
  var RateLimitError = _RateLimitError;
1290
- var _InternalServerError = class _InternalServerError extends APIError {
1358
+ var _InternalServerError = class _InternalServerError extends ApiError {
1291
1359
  };
1292
1360
  __name(_InternalServerError, "InternalServerError");
1293
1361
  var InternalServerError = _InternalServerError;
@@ -1320,6 +1388,108 @@ function calculateNextRetryDelay(options, attempt) {
1320
1388
  return Math.round(timeout);
1321
1389
  }
1322
1390
  __name(calculateNextRetryDelay, "calculateNextRetryDelay");
1391
+
1392
+ // src/v3/apiClient/pagination.ts
1393
+ var _CursorPage = class _CursorPage {
1394
+ constructor(data, pagination, pageFetcher) {
1395
+ this.pageFetcher = pageFetcher;
1396
+ this.data = data;
1397
+ this.pagination = pagination;
1398
+ }
1399
+ getPaginatedItems() {
1400
+ return this.data ?? [];
1401
+ }
1402
+ hasNextPage() {
1403
+ return !!this.pagination.next;
1404
+ }
1405
+ hasPreviousPage() {
1406
+ return !!this.pagination.previous;
1407
+ }
1408
+ getNextPage() {
1409
+ if (!this.pagination.next) {
1410
+ throw new Error("No next page available");
1411
+ }
1412
+ return this.pageFetcher({
1413
+ after: this.pagination.next
1414
+ });
1415
+ }
1416
+ getPreviousPage() {
1417
+ if (!this.pagination.previous) {
1418
+ throw new Error("No previous page available");
1419
+ }
1420
+ return this.pageFetcher({
1421
+ before: this.pagination.previous
1422
+ });
1423
+ }
1424
+ async *iterPages() {
1425
+ let page = this;
1426
+ yield page;
1427
+ while (page.hasNextPage()) {
1428
+ page = await page.getNextPage();
1429
+ yield page;
1430
+ }
1431
+ }
1432
+ async *[Symbol.asyncIterator]() {
1433
+ for await (const page of this.iterPages()) {
1434
+ for (const item of page.getPaginatedItems()) {
1435
+ yield item;
1436
+ }
1437
+ }
1438
+ }
1439
+ };
1440
+ __name(_CursorPage, "CursorPage");
1441
+ var CursorPage = _CursorPage;
1442
+ var _OffsetLimitPage = class _OffsetLimitPage {
1443
+ constructor(data, pagination, pageFetcher) {
1444
+ this.pageFetcher = pageFetcher;
1445
+ this.data = data;
1446
+ this.pagination = pagination;
1447
+ }
1448
+ getPaginatedItems() {
1449
+ return this.data ?? [];
1450
+ }
1451
+ hasNextPage() {
1452
+ return this.pagination.currentPage < this.pagination.totalPages;
1453
+ }
1454
+ hasPreviousPage() {
1455
+ return this.pagination.currentPage > 1;
1456
+ }
1457
+ getNextPage() {
1458
+ if (!this.hasNextPage()) {
1459
+ throw new Error("No next page available");
1460
+ }
1461
+ return this.pageFetcher({
1462
+ page: this.pagination.currentPage + 1
1463
+ });
1464
+ }
1465
+ getPreviousPage() {
1466
+ if (!this.hasPreviousPage()) {
1467
+ throw new Error("No previous page available");
1468
+ }
1469
+ return this.pageFetcher({
1470
+ page: this.pagination.currentPage - 1
1471
+ });
1472
+ }
1473
+ async *iterPages() {
1474
+ let page = this;
1475
+ yield page;
1476
+ while (page.hasNextPage()) {
1477
+ page = await page.getNextPage();
1478
+ yield page;
1479
+ }
1480
+ }
1481
+ async *[Symbol.asyncIterator]() {
1482
+ for await (const page of this.iterPages()) {
1483
+ for (const item of page.getPaginatedItems()) {
1484
+ yield item;
1485
+ }
1486
+ }
1487
+ }
1488
+ };
1489
+ __name(_OffsetLimitPage, "OffsetLimitPage");
1490
+ var OffsetLimitPage = _OffsetLimitPage;
1491
+
1492
+ // src/v3/apiClient/core.ts
1323
1493
  var defaultRetryOptions2 = {
1324
1494
  maxAttempts: 3,
1325
1495
  factor: 2,
@@ -1327,11 +1497,62 @@ var defaultRetryOptions2 = {
1327
1497
  maxTimeoutInMs: 6e4,
1328
1498
  randomize: false
1329
1499
  };
1330
- async function zodfetch(schema, url, requestInit, options) {
1331
- return await _doZodFetch(schema, url, requestInit, options);
1500
+ function zodfetch(schema, url, requestInit, options) {
1501
+ return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
1332
1502
  }
1333
1503
  __name(zodfetch, "zodfetch");
1334
- async function zodupload(schema, url, body, requestInit, options) {
1504
+ function zodfetchCursorPage(schema, url, params, requestInit, options) {
1505
+ const query = new URLSearchParams(params.query);
1506
+ if (params.limit) {
1507
+ query.set("page[size]", String(params.limit));
1508
+ }
1509
+ if (params.after) {
1510
+ query.set("page[after]", params.after);
1511
+ }
1512
+ if (params.before) {
1513
+ query.set("page[before]", params.before);
1514
+ }
1515
+ const cursorPageSchema = zod.z.object({
1516
+ data: zod.z.array(schema),
1517
+ pagination: zod.z.object({
1518
+ next: zod.z.string().optional(),
1519
+ previous: zod.z.string().optional()
1520
+ })
1521
+ });
1522
+ const $url = new URL(url);
1523
+ $url.search = query.toString();
1524
+ const fetchResult = _doZodFetch(cursorPageSchema, $url.href, requestInit, options);
1525
+ return new CursorPagePromise(fetchResult, schema, url, params, requestInit, options);
1526
+ }
1527
+ __name(zodfetchCursorPage, "zodfetchCursorPage");
1528
+ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
1529
+ const query = new URLSearchParams(params.query);
1530
+ if (params.limit) {
1531
+ query.set("perPage", String(params.limit));
1532
+ }
1533
+ if (params.page) {
1534
+ query.set("page", String(params.page));
1535
+ }
1536
+ const offsetLimitPageSchema = zod.z.object({
1537
+ data: zod.z.array(schema),
1538
+ pagination: zod.z.object({
1539
+ currentPage: zod.z.coerce.number(),
1540
+ totalPages: zod.z.coerce.number(),
1541
+ count: zod.z.coerce.number()
1542
+ })
1543
+ });
1544
+ const $url = new URL(url);
1545
+ $url.search = query.toString();
1546
+ const fetchResult = _doZodFetch(offsetLimitPageSchema, $url.href, requestInit, options);
1547
+ return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
1548
+ }
1549
+ __name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
1550
+ function zodupload(schema, url, body, requestInit, options) {
1551
+ const finalRequestInit = createMultipartFormRequestInit(body, requestInit);
1552
+ return new ApiPromise(_doZodFetch(schema, url, finalRequestInit, options));
1553
+ }
1554
+ __name(zodupload, "zodupload");
1555
+ async function createMultipartFormRequestInit(body, requestInit) {
1335
1556
  const form = await createForm(body);
1336
1557
  const encoder = new formDataEncoder.FormDataEncoder(form);
1337
1558
  const finalHeaders = {};
@@ -1349,9 +1570,9 @@ async function zodupload(schema, url, body, requestInit, options) {
1349
1570
  // @ts-expect-error
1350
1571
  duplex: "half"
1351
1572
  };
1352
- return await _doZodFetch(schema, url, finalRequestInit, options);
1573
+ return finalRequestInit;
1353
1574
  }
1354
- __name(zodupload, "zodupload");
1575
+ __name(createMultipartFormRequestInit, "createMultipartFormRequestInit");
1355
1576
  var createForm = /* @__PURE__ */ __name(async (body) => {
1356
1577
  const form = new FormData();
1357
1578
  await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
@@ -1359,7 +1580,8 @@ var createForm = /* @__PURE__ */ __name(async (body) => {
1359
1580
  }, "createForm");
1360
1581
  async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1361
1582
  try {
1362
- const response = await fetch(url, requestInitWithCache(requestInit));
1583
+ const $requestInit = await requestInit;
1584
+ const response = await fetch(url, requestInitWithCache($requestInit));
1363
1585
  const responseHeaders = createResponseHeaders(response.headers);
1364
1586
  if (!response.ok) {
1365
1587
  const retryResult = shouldRetry(response, attempt, options?.retry);
@@ -1370,17 +1592,20 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1370
1592
  const errText = await response.text().catch((e) => castToError2(e).message);
1371
1593
  const errJSON = safeJsonParse(errText);
1372
1594
  const errMessage = errJSON ? void 0 : errText;
1373
- throw APIError.generate(response.status, errJSON, errMessage, responseHeaders);
1595
+ throw ApiError.generate(response.status, errJSON, errMessage, responseHeaders);
1374
1596
  }
1375
1597
  }
1376
1598
  const jsonBody = await response.json();
1377
1599
  const parsedResult = schema.safeParse(jsonBody);
1378
1600
  if (parsedResult.success) {
1379
- return parsedResult.data;
1601
+ return {
1602
+ data: parsedResult.data,
1603
+ response
1604
+ };
1380
1605
  }
1381
1606
  throw zodValidationError.fromZodError(parsedResult.error);
1382
1607
  } catch (error) {
1383
- if (error instanceof APIError) {
1608
+ if (error instanceof ApiError) {
1384
1609
  throw error;
1385
1610
  }
1386
1611
  if (options?.retry) {
@@ -1394,7 +1619,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1394
1619
  return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
1395
1620
  }
1396
1621
  }
1397
- throw new APIConnectionError({
1622
+ throw new ApiConnectionError({
1398
1623
  cause: castToError2(error)
1399
1624
  });
1400
1625
  }
@@ -1567,6 +1792,128 @@ var isUploadable = /* @__PURE__ */ __name((value) => {
1567
1792
  return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
1568
1793
  }, "isUploadable");
1569
1794
  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");
1795
+ var _ApiPromise = class _ApiPromise extends Promise {
1796
+ constructor(responsePromise) {
1797
+ super((resolve) => {
1798
+ resolve(null);
1799
+ });
1800
+ this.responsePromise = responsePromise;
1801
+ }
1802
+ /**
1803
+ * Gets the raw `Response` instance instead of parsing the response
1804
+ * data.
1805
+ *
1806
+ * If you want to parse the response body but still get the `Response`
1807
+ * instance, you can use {@link withResponse()}.
1808
+ */
1809
+ asResponse() {
1810
+ return this.responsePromise.then((p) => p.response);
1811
+ }
1812
+ /**
1813
+ * Gets the parsed response data and the raw `Response` instance.
1814
+ *
1815
+ * If you just want to get the raw `Response` instance without parsing it,
1816
+ * you can use {@link asResponse()}.
1817
+ */
1818
+ async withResponse() {
1819
+ const [data, response] = await Promise.all([
1820
+ this.parse(),
1821
+ this.asResponse()
1822
+ ]);
1823
+ return {
1824
+ data,
1825
+ response
1826
+ };
1827
+ }
1828
+ parse() {
1829
+ return this.responsePromise.then((result) => result.data);
1830
+ }
1831
+ then(onfulfilled, onrejected) {
1832
+ return this.parse().then(onfulfilled, onrejected);
1833
+ }
1834
+ catch(onrejected) {
1835
+ return this.parse().catch(onrejected);
1836
+ }
1837
+ finally(onfinally) {
1838
+ return this.parse().finally(onfinally);
1839
+ }
1840
+ };
1841
+ __name(_ApiPromise, "ApiPromise");
1842
+ var ApiPromise = _ApiPromise;
1843
+ var _fetchPage, fetchPage_fn;
1844
+ var _CursorPagePromise = class _CursorPagePromise extends ApiPromise {
1845
+ constructor(result, schema, url, params, requestInit, options) {
1846
+ super(result.then((result2) => ({
1847
+ data: new CursorPage(result2.data.data, result2.data.pagination, __privateMethod(this, _fetchPage, fetchPage_fn).bind(this)),
1848
+ response: result2.response
1849
+ })));
1850
+ __privateAdd(this, _fetchPage);
1851
+ this.schema = schema;
1852
+ this.url = url;
1853
+ this.params = params;
1854
+ this.requestInit = requestInit;
1855
+ this.options = options;
1856
+ }
1857
+ /**
1858
+ * Allow auto-paginating iteration on an unawaited list call, eg:
1859
+ *
1860
+ * for await (const item of client.items.list()) {
1861
+ * console.log(item)
1862
+ * }
1863
+ */
1864
+ async *[Symbol.asyncIterator]() {
1865
+ const page = await this;
1866
+ for await (const item of page) {
1867
+ yield item;
1868
+ }
1869
+ }
1870
+ };
1871
+ _fetchPage = new WeakSet();
1872
+ fetchPage_fn = /* @__PURE__ */ __name(function(params) {
1873
+ return zodfetchCursorPage(this.schema, this.url, {
1874
+ ...this.params,
1875
+ ...params
1876
+ }, this.requestInit, this.options);
1877
+ }, "#fetchPage");
1878
+ __name(_CursorPagePromise, "CursorPagePromise");
1879
+ var CursorPagePromise = _CursorPagePromise;
1880
+ var _fetchPage2, fetchPage_fn2;
1881
+ var _OffsetLimitPagePromise = class _OffsetLimitPagePromise extends ApiPromise {
1882
+ constructor(result, schema, url, params, requestInit, options) {
1883
+ super(result.then((result2) => ({
1884
+ data: new OffsetLimitPage(result2.data.data, result2.data.pagination, __privateMethod(this, _fetchPage2, fetchPage_fn2).bind(this)),
1885
+ response: result2.response
1886
+ })));
1887
+ __privateAdd(this, _fetchPage2);
1888
+ this.schema = schema;
1889
+ this.url = url;
1890
+ this.params = params;
1891
+ this.requestInit = requestInit;
1892
+ this.options = options;
1893
+ }
1894
+ /**
1895
+ * Allow auto-paginating iteration on an unawaited list call, eg:
1896
+ *
1897
+ * for await (const item of client.items.list()) {
1898
+ * console.log(item)
1899
+ * }
1900
+ */
1901
+ async *[Symbol.asyncIterator]() {
1902
+ const page = await this;
1903
+ for await (const item of page) {
1904
+ yield item;
1905
+ }
1906
+ }
1907
+ };
1908
+ _fetchPage2 = new WeakSet();
1909
+ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
1910
+ return zodfetchOffsetLimitPage(this.schema, this.url, {
1911
+ ...this.params,
1912
+ ...params1
1913
+ }, this.requestInit, this.options);
1914
+ }, "#fetchPage");
1915
+ __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
1916
+ var OffsetLimitPagePromise = _OffsetLimitPagePromise;
1570
1917
 
1571
1918
  // src/v3/apiClient/index.ts
1572
1919
  var zodFetchOptions = {
@@ -1592,7 +1939,7 @@ var _ApiClient = class _ApiClient {
1592
1939
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1593
1940
  }, zodFetchOptions);
1594
1941
  } catch (error) {
1595
- if (error instanceof APIError) {
1942
+ if (error instanceof ApiError) {
1596
1943
  if (error.status === 404) {
1597
1944
  return void 0;
1598
1945
  }
@@ -1607,14 +1954,16 @@ var _ApiClient = class _ApiClient {
1607
1954
  }, zodFetchOptions);
1608
1955
  }
1609
1956
  triggerTask(taskId, body, options) {
1610
- return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/trigger`, {
1957
+ const encodedTaskId = encodeURIComponent(taskId);
1958
+ return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/trigger`, {
1611
1959
  method: "POST",
1612
1960
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
1613
1961
  body: JSON.stringify(body)
1614
1962
  }, zodFetchOptions);
1615
1963
  }
1616
1964
  batchTriggerTask(taskId, body, options) {
1617
- return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/batch`, {
1965
+ const encodedTaskId = encodeURIComponent(taskId);
1966
+ return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/batch`, {
1618
1967
  method: "POST",
1619
1968
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
1620
1969
  body: JSON.stringify(body)
@@ -1638,6 +1987,33 @@ var _ApiClient = class _ApiClient {
1638
1987
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1639
1988
  }, zodFetchOptions);
1640
1989
  }
1990
+ listRuns(query) {
1991
+ const searchParams = createSearchQueryForListRuns(query);
1992
+ return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/runs`, {
1993
+ query: searchParams,
1994
+ limit: query?.limit,
1995
+ after: query?.after,
1996
+ before: query?.before
1997
+ }, {
1998
+ method: "GET",
1999
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2000
+ }, zodFetchOptions);
2001
+ }
2002
+ listProjectRuns(projectRef, query) {
2003
+ const searchParams = createSearchQueryForListRuns(query);
2004
+ if (query?.env) {
2005
+ searchParams.append("filter[env]", Array.isArray(query.env) ? query.env.join(",") : query.env);
2006
+ }
2007
+ return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/projects/${projectRef}/runs`, {
2008
+ query: searchParams,
2009
+ limit: query?.limit,
2010
+ after: query?.after,
2011
+ before: query?.before
2012
+ }, {
2013
+ method: "GET",
2014
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2015
+ }, zodFetchOptions);
2016
+ }
1641
2017
  replayRun(runId) {
1642
2018
  return zodfetch(ReplayRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/replay`, {
1643
2019
  method: "POST",
@@ -1665,7 +2041,10 @@ var _ApiClient = class _ApiClient {
1665
2041
  if (options?.perPage) {
1666
2042
  searchParams.append("perPage", options.perPage.toString());
1667
2043
  }
1668
- return zodfetch(ListSchedulesResult, `${this.baseUrl}/api/v1/schedules${searchParams.size > 0 ? `?${searchParams}` : ""}`, {
2044
+ return zodfetchOffsetLimitPage(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
2045
+ page: options?.page,
2046
+ limit: options?.perPage
2047
+ }, {
1669
2048
  method: "GET",
1670
2049
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1671
2050
  });
@@ -1766,6 +2145,40 @@ getHeaders_fn = /* @__PURE__ */ __name(function(spanParentAsLink) {
1766
2145
  }, "#getHeaders");
1767
2146
  __name(_ApiClient, "ApiClient");
1768
2147
  var ApiClient = _ApiClient;
2148
+ function createSearchQueryForListRuns(query) {
2149
+ const searchParams = new URLSearchParams();
2150
+ if (query) {
2151
+ if (query.status) {
2152
+ searchParams.append("filter[status]", Array.isArray(query.status) ? query.status.join(",") : query.status);
2153
+ }
2154
+ if (query.taskIdentifier) {
2155
+ searchParams.append("filter[taskIdentifier]", Array.isArray(query.taskIdentifier) ? query.taskIdentifier.join(",") : query.taskIdentifier);
2156
+ }
2157
+ if (query.version) {
2158
+ searchParams.append("filter[version]", Array.isArray(query.version) ? query.version.join(",") : query.version);
2159
+ }
2160
+ if (query.bulkAction) {
2161
+ searchParams.append("filter[bulkAction]", query.bulkAction);
2162
+ }
2163
+ if (query.schedule) {
2164
+ searchParams.append("filter[schedule]", query.schedule);
2165
+ }
2166
+ if (typeof query.isTest === "boolean") {
2167
+ searchParams.append("filter[isTest]", String(query.isTest));
2168
+ }
2169
+ if (query.from) {
2170
+ searchParams.append("filter[createdAt][from]", query.from instanceof Date ? query.from.getTime().toString() : query.from.toString());
2171
+ }
2172
+ if (query.to) {
2173
+ searchParams.append("filter[createdAt][to]", query.to instanceof Date ? query.to.getTime().toString() : query.to.toString());
2174
+ }
2175
+ if (query.period) {
2176
+ searchParams.append("filter[createdAt][period]", query.period);
2177
+ }
2178
+ }
2179
+ return searchParams;
2180
+ }
2181
+ __name(createSearchQueryForListRuns, "createSearchQueryForListRuns");
1769
2182
 
1770
2183
  // src/v3/apiClientManager/index.ts
1771
2184
  var API_NAME2 = "api-client";