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

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 (59) hide show
  1. package/dist/catalog-BUwiuDbt.d.mts +202 -0
  2. package/dist/catalog-eKgqBHUA.d.ts +202 -0
  3. package/dist/index.d.mts +60 -1
  4. package/dist/index.d.ts +60 -1
  5. package/dist/index.js +7 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +7 -1
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/{manager-WNMVbgHf.d.mts → manager-uPyMRN8k.d.mts} +24 -23
  10. package/dist/{manager-WNMVbgHf.d.ts → manager-uPyMRN8k.d.ts} +24 -23
  11. package/dist/{messages-vq7Bk4Ap.d.mts → messages-l9PdIyKF.d.mts} +4975 -1072
  12. package/dist/{messages-vq7Bk4Ap.d.ts → messages-l9PdIyKF.d.ts} +4975 -1072
  13. package/dist/{catalog-KbyTBoap.d.ts → schemas-b8tRw8dX.d.mts} +21 -186
  14. package/dist/{catalog-ck7x04PV.d.mts → schemas-b8tRw8dX.d.ts} +21 -186
  15. package/dist/v3/dev/index.d.mts +2 -2
  16. package/dist/v3/dev/index.d.ts +2 -2
  17. package/dist/v3/dev/index.js +4 -4
  18. package/dist/v3/dev/index.js.map +1 -1
  19. package/dist/v3/dev/index.mjs +4 -4
  20. package/dist/v3/dev/index.mjs.map +1 -1
  21. package/dist/v3/index.d.mts +121 -7
  22. package/dist/v3/index.d.ts +121 -7
  23. package/dist/v3/index.js +735 -352
  24. package/dist/v3/index.js.map +1 -1
  25. package/dist/v3/index.mjs +728 -353
  26. package/dist/v3/index.mjs.map +1 -1
  27. package/dist/v3/otel/index.js +5 -1
  28. package/dist/v3/otel/index.js.map +1 -1
  29. package/dist/v3/otel/index.mjs +5 -1
  30. package/dist/v3/otel/index.mjs.map +1 -1
  31. package/dist/v3/prod/index.d.mts +3 -3
  32. package/dist/v3/prod/index.d.ts +3 -3
  33. package/dist/v3/prod/index.js +90 -15
  34. package/dist/v3/prod/index.js.map +1 -1
  35. package/dist/v3/prod/index.mjs +90 -15
  36. package/dist/v3/prod/index.mjs.map +1 -1
  37. package/dist/v3/workers/index.d.mts +6 -5
  38. package/dist/v3/workers/index.d.ts +6 -5
  39. package/dist/v3/workers/index.js +204 -9
  40. package/dist/v3/workers/index.js.map +1 -1
  41. package/dist/v3/workers/index.mjs +204 -9
  42. package/dist/v3/workers/index.mjs.map +1 -1
  43. package/dist/v3/zodMessageHandler.d.mts +1 -1
  44. package/dist/v3/zodMessageHandler.d.ts +1 -1
  45. package/dist/v3/zodNamespace.js +16 -6
  46. package/dist/v3/zodNamespace.js.map +1 -1
  47. package/dist/v3/zodNamespace.mjs +17 -7
  48. package/dist/v3/zodNamespace.mjs.map +1 -1
  49. package/dist/v3/zodSocket.js +16 -6
  50. package/dist/v3/zodSocket.js.map +1 -1
  51. package/dist/v3/zodSocket.mjs +17 -7
  52. package/dist/v3/zodSocket.mjs.map +1 -1
  53. package/dist/v3/zodfetch.d.mts +78 -0
  54. package/dist/v3/zodfetch.d.ts +78 -0
  55. package/dist/v3/zodfetch.js +446 -0
  56. package/dist/v3/zodfetch.js.map +1 -0
  57. package/dist/v3/zodfetch.mjs +433 -0
  58. package/dist/v3/zodfetch.mjs.map +1 -0
  59. package/package.json +13 -4
@@ -9,6 +9,8 @@ import { NodeTracerProvider, BatchSpanProcessor, SimpleSpanProcessor } from '@op
9
9
  import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
10
10
  import { z } from 'zod';
11
11
  import { fromZodError } from 'zod-validation-error';
12
+ import { FormDataEncoder } from 'form-data-encoder';
13
+ import { Readable } from 'node:stream';
12
14
  import { PreciseDate } from '@google-cloud/precise-date';
13
15
  import util from 'node:util';
14
16
 
@@ -349,6 +351,9 @@ function getEnvVar(name) {
349
351
  }
350
352
  __name(getEnvVar, "getEnvVar");
351
353
 
354
+ // package.json
355
+ var version = "3.0.0-beta.35";
356
+
352
357
  // src/v3/otel/tracingSDK.ts
353
358
  var _a;
354
359
  var AsyncResourceDetector = (_a = class {
@@ -386,7 +391,8 @@ var _TracingSDK = class _TracingSDK {
386
391
  ]
387
392
  }).merge(new Resource({
388
393
  [SemanticResourceAttributes.CLOUD_PROVIDER]: "trigger.dev",
389
- [SemanticInternalAttributes.TRIGGER]: true
394
+ [SemanticInternalAttributes.TRIGGER]: true,
395
+ [SemanticInternalAttributes.CLI_VERSION]: version
390
396
  })).merge(config.resource ?? new Resource({})).merge(new Resource(envResourceAttributes));
391
397
  const traceProvider = new NodeTracerProvider({
392
398
  forceFlushTimeoutMillis: config.forceFlushTimeoutMillis ?? 500,
@@ -516,6 +522,7 @@ var TaskRunErrorCodes = {
516
522
  TASK_EXECUTION_FAILED: "TASK_EXECUTION_FAILED",
517
523
  TASK_EXECUTION_ABORTED: "TASK_EXECUTION_ABORTED",
518
524
  TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE: "TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE",
525
+ TASK_PROCESS_SIGKILL_TIMEOUT: "TASK_PROCESS_SIGKILL_TIMEOUT",
519
526
  TASK_RUN_CANCELLED: "TASK_RUN_CANCELLED",
520
527
  TASK_OUTPUT_ERROR: "TASK_OUTPUT_ERROR",
521
528
  HANDLE_ERROR_ERROR: "HANDLE_ERROR_ERROR",
@@ -531,10 +538,12 @@ var TaskRunInternalError = z.object({
531
538
  "TASK_EXECUTION_FAILED",
532
539
  "TASK_EXECUTION_ABORTED",
533
540
  "TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE",
541
+ "TASK_PROCESS_SIGKILL_TIMEOUT",
534
542
  "TASK_RUN_CANCELLED",
535
543
  "TASK_OUTPUT_ERROR",
536
544
  "HANDLE_ERROR_ERROR",
537
- "GRACEFUL_EXIT_TIMEOUT"
545
+ "GRACEFUL_EXIT_TIMEOUT",
546
+ "TASK_RUN_HEARTBEAT_TIMEOUT"
538
547
  ]),
539
548
  message: z.string().optional()
540
549
  });
@@ -837,6 +846,13 @@ z.enum([
837
846
  "WAIT_FOR_TASK",
838
847
  "WAIT_FOR_BATCH"
839
848
  ]);
849
+ z.object({
850
+ runId: z.string(),
851
+ messageId: z.string(),
852
+ isTest: z.boolean(),
853
+ traceContext: z.record(z.unknown()),
854
+ environment: z.record(z.string()).optional()
855
+ });
840
856
 
841
857
  // src/v3/schemas/resources.ts
842
858
  var TaskResource = z.object({
@@ -886,7 +902,8 @@ z.object({
886
902
  });
887
903
  z.object({
888
904
  localOnly: z.boolean(),
889
- metadata: BackgroundWorkerMetadata
905
+ metadata: BackgroundWorkerMetadata,
906
+ supportsLazyAttempts: z.boolean().optional()
890
907
  });
891
908
  z.object({
892
909
  id: z.string(),
@@ -1114,6 +1131,28 @@ var RetrieveRunResponse = z.object({
1114
1131
  completedAt: z.coerce.date().optional()
1115
1132
  }).optional())
1116
1133
  });
1134
+ z.object({
1135
+ name: z.string(),
1136
+ value: z.string()
1137
+ });
1138
+ z.object({
1139
+ value: z.string()
1140
+ });
1141
+ z.object({
1142
+ variables: z.record(z.string()),
1143
+ override: z.boolean().optional()
1144
+ });
1145
+ var EnvironmentVariableResponseBody = z.object({
1146
+ success: z.boolean()
1147
+ });
1148
+ var EnvironmentVariableValue = z.object({
1149
+ value: z.string()
1150
+ });
1151
+ var EnvironmentVariable = z.object({
1152
+ name: z.string(),
1153
+ value: z.string()
1154
+ });
1155
+ var EnvironmentVariables = z.array(EnvironmentVariable);
1117
1156
 
1118
1157
  // src/v3/apiErrors.ts
1119
1158
  var _APIError = class _APIError extends Error {
@@ -1275,8 +1314,6 @@ function calculateNextRetryDelay(options, attempt) {
1275
1314
  return Math.round(timeout);
1276
1315
  }
1277
1316
  __name(calculateNextRetryDelay, "calculateNextRetryDelay");
1278
-
1279
- // src/v3/zodfetch.ts
1280
1317
  var defaultRetryOptions2 = {
1281
1318
  maxAttempts: 3,
1282
1319
  factor: 2,
@@ -1288,6 +1325,32 @@ async function zodfetch(schema, url, requestInit, options) {
1288
1325
  return await _doZodFetch(schema, url, requestInit, options);
1289
1326
  }
1290
1327
  __name(zodfetch, "zodfetch");
1328
+ async function zodupload(schema, url, body, requestInit, options) {
1329
+ const form = await createForm(body);
1330
+ const encoder = new FormDataEncoder(form);
1331
+ const finalHeaders = {};
1332
+ for (const [key, value] of Object.entries(requestInit?.headers || {})) {
1333
+ finalHeaders[key] = value;
1334
+ }
1335
+ for (const [key, value] of Object.entries(encoder.headers)) {
1336
+ finalHeaders[key] = value;
1337
+ }
1338
+ finalHeaders["Content-Length"] = String(encoder.contentLength);
1339
+ const finalRequestInit = {
1340
+ ...requestInit,
1341
+ headers: finalHeaders,
1342
+ body: Readable.from(encoder),
1343
+ // @ts-expect-error
1344
+ duplex: "half"
1345
+ };
1346
+ return await _doZodFetch(schema, url, finalRequestInit, options);
1347
+ }
1348
+ __name(zodupload, "zodupload");
1349
+ var createForm = /* @__PURE__ */ __name(async (body) => {
1350
+ const form = new FormData();
1351
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
1352
+ return form;
1353
+ }, "createForm");
1291
1354
  async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1292
1355
  try {
1293
1356
  const response = await fetch(url, requestInitWithCache(requestInit));
@@ -1409,9 +1472,95 @@ function requestInitWithCache(requestInit) {
1409
1472
  }
1410
1473
  }
1411
1474
  __name(requestInitWithCache, "requestInitWithCache");
1412
-
1413
- // package.json
1414
- var version = "3.0.0-beta.33";
1475
+ var addFormValue = /* @__PURE__ */ __name(async (form, key, value) => {
1476
+ if (value === void 0)
1477
+ return;
1478
+ if (value == null) {
1479
+ throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
1480
+ }
1481
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1482
+ form.append(key, String(value));
1483
+ } else if (isUploadable(value) || isBlobLike(value) || value instanceof Buffer || value instanceof ArrayBuffer) {
1484
+ const file = await toFile(value);
1485
+ form.append(key, file);
1486
+ } else if (Array.isArray(value)) {
1487
+ await Promise.all(value.map((entry) => addFormValue(form, key + "[]", entry)));
1488
+ } else if (typeof value === "object") {
1489
+ await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
1490
+ } else {
1491
+ throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
1492
+ }
1493
+ }, "addFormValue");
1494
+ async function toFile(value, name, options) {
1495
+ value = await value;
1496
+ options ??= isFileLike(value) ? {
1497
+ lastModified: value.lastModified,
1498
+ type: value.type
1499
+ } : {};
1500
+ if (isResponseLike(value)) {
1501
+ const blob = await value.blob();
1502
+ name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? "unknown_file";
1503
+ return new File([
1504
+ blob
1505
+ ], name, options);
1506
+ }
1507
+ const bits = await getBytes(value);
1508
+ name ||= getName(value) ?? "unknown_file";
1509
+ if (!options.type) {
1510
+ const type = bits[0]?.type;
1511
+ if (typeof type === "string") {
1512
+ options = {
1513
+ ...options,
1514
+ type
1515
+ };
1516
+ }
1517
+ }
1518
+ return new File(bits, name, options);
1519
+ }
1520
+ __name(toFile, "toFile");
1521
+ function getName(value) {
1522
+ return getStringFromMaybeBuffer(value.name) || getStringFromMaybeBuffer(value.filename) || // For fs.ReadStream
1523
+ getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop();
1524
+ }
1525
+ __name(getName, "getName");
1526
+ var getStringFromMaybeBuffer = /* @__PURE__ */ __name((x) => {
1527
+ if (typeof x === "string")
1528
+ return x;
1529
+ if (typeof Buffer !== "undefined" && x instanceof Buffer)
1530
+ return String(x);
1531
+ return void 0;
1532
+ }, "getStringFromMaybeBuffer");
1533
+ async function getBytes(value) {
1534
+ let parts = [];
1535
+ if (typeof value === "string" || ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
1536
+ value instanceof ArrayBuffer) {
1537
+ parts.push(value);
1538
+ } else if (isBlobLike(value)) {
1539
+ parts.push(await value.arrayBuffer());
1540
+ } else if (isAsyncIterableIterator(value)) {
1541
+ for await (const chunk of value) {
1542
+ parts.push(chunk);
1543
+ }
1544
+ } else {
1545
+ throw new Error(`Unexpected data type: ${typeof value}; constructor: ${value?.constructor?.name}; props: ${propsForError(value)}`);
1546
+ }
1547
+ return parts;
1548
+ }
1549
+ __name(getBytes, "getBytes");
1550
+ function propsForError(value) {
1551
+ const props = Object.getOwnPropertyNames(value);
1552
+ return `[${props.map((p) => `"${p}"`).join(", ")}]`;
1553
+ }
1554
+ __name(propsForError, "propsForError");
1555
+ var isAsyncIterableIterator = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function", "isAsyncIterableIterator");
1556
+ var isResponseLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.url === "string" && typeof value.blob === "function", "isResponseLike");
1557
+ var isFileLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.name === "string" && typeof value.lastModified === "number" && isBlobLike(value), "isFileLike");
1558
+ var isBlobLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.size === "number" && typeof value.type === "string" && typeof value.text === "function" && typeof value.slice === "function" && typeof value.arrayBuffer === "function", "isBlobLike");
1559
+ var isFsReadStream = /* @__PURE__ */ __name((value) => value instanceof Readable, "isFsReadStream");
1560
+ var isUploadable = /* @__PURE__ */ __name((value) => {
1561
+ return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
1562
+ }, "isUploadable");
1563
+ 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");
1415
1564
 
1416
1565
  // src/v3/apiClient/index.ts
1417
1566
  var zodFetchOptions = {
@@ -1546,6 +1695,52 @@ var _ApiClient = class _ApiClient {
1546
1695
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1547
1696
  });
1548
1697
  }
1698
+ listEnvVars(projectRef, slug) {
1699
+ return zodfetch(EnvironmentVariables, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
1700
+ method: "GET",
1701
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1702
+ });
1703
+ }
1704
+ importEnvVars(projectRef, slug, body) {
1705
+ if (isRecordLike(body.variables)) {
1706
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, {
1707
+ method: "POST",
1708
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1709
+ body: JSON.stringify(body)
1710
+ });
1711
+ } else {
1712
+ return zodupload(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, body, {
1713
+ method: "POST",
1714
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1715
+ });
1716
+ }
1717
+ }
1718
+ retrieveEnvVar(projectRef, slug, key) {
1719
+ return zodfetch(EnvironmentVariableValue, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1720
+ method: "GET",
1721
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1722
+ });
1723
+ }
1724
+ createEnvVar(projectRef, slug, body) {
1725
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
1726
+ method: "POST",
1727
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1728
+ body: JSON.stringify(body)
1729
+ });
1730
+ }
1731
+ updateEnvVar(projectRef, slug, key, body) {
1732
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1733
+ method: "PUT",
1734
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1735
+ body: JSON.stringify(body)
1736
+ });
1737
+ }
1738
+ deleteEnvVar(projectRef, slug, key) {
1739
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1740
+ method: "DELETE",
1741
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1742
+ });
1743
+ }
1549
1744
  };
1550
1745
  _getHeaders = new WeakSet();
1551
1746
  getHeaders_fn = /* @__PURE__ */ __name(function(spanParentAsLink) {
@@ -1591,7 +1786,7 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
1591
1786
  }
1592
1787
  get accessToken() {
1593
1788
  const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
1594
- return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY");
1789
+ return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY") ?? getEnvVar("TRIGGER_ACCESS_TOKEN");
1595
1790
  }
1596
1791
  get client() {
1597
1792
  if (!this.baseURL || !this.accessToken) {