@trigger.dev/core 3.0.0-beta.32 → 3.0.0-beta.34

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.
@@ -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 '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.34";
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,
@@ -1114,6 +1120,28 @@ var RetrieveRunResponse = z.object({
1114
1120
  completedAt: z.coerce.date().optional()
1115
1121
  }).optional())
1116
1122
  });
1123
+ z.object({
1124
+ name: z.string(),
1125
+ value: z.string()
1126
+ });
1127
+ z.object({
1128
+ value: z.string()
1129
+ });
1130
+ z.object({
1131
+ variables: z.record(z.string()),
1132
+ override: z.boolean().optional()
1133
+ });
1134
+ var EnvironmentVariableResponseBody = z.object({
1135
+ success: z.boolean()
1136
+ });
1137
+ var EnvironmentVariableValue = z.object({
1138
+ value: z.string()
1139
+ });
1140
+ var EnvironmentVariable = z.object({
1141
+ name: z.string(),
1142
+ value: z.string()
1143
+ });
1144
+ var EnvironmentVariables = z.array(EnvironmentVariable);
1117
1145
 
1118
1146
  // src/v3/apiErrors.ts
1119
1147
  var _APIError = class _APIError extends Error {
@@ -1275,8 +1303,6 @@ function calculateNextRetryDelay(options, attempt) {
1275
1303
  return Math.round(timeout);
1276
1304
  }
1277
1305
  __name(calculateNextRetryDelay, "calculateNextRetryDelay");
1278
-
1279
- // src/v3/zodfetch.ts
1280
1306
  var defaultRetryOptions2 = {
1281
1307
  maxAttempts: 3,
1282
1308
  factor: 2,
@@ -1288,6 +1314,32 @@ async function zodfetch(schema, url, requestInit, options) {
1288
1314
  return await _doZodFetch(schema, url, requestInit, options);
1289
1315
  }
1290
1316
  __name(zodfetch, "zodfetch");
1317
+ async function zodupload(schema, url, body, requestInit, options) {
1318
+ const form = await createForm(body);
1319
+ const encoder = new FormDataEncoder(form);
1320
+ const finalHeaders = {};
1321
+ for (const [key, value] of Object.entries(requestInit?.headers || {})) {
1322
+ finalHeaders[key] = value;
1323
+ }
1324
+ for (const [key, value] of Object.entries(encoder.headers)) {
1325
+ finalHeaders[key] = value;
1326
+ }
1327
+ finalHeaders["Content-Length"] = String(encoder.contentLength);
1328
+ const finalRequestInit = {
1329
+ ...requestInit,
1330
+ headers: finalHeaders,
1331
+ body: Readable.from(encoder),
1332
+ // @ts-expect-error
1333
+ duplex: "half"
1334
+ };
1335
+ return await _doZodFetch(schema, url, finalRequestInit, options);
1336
+ }
1337
+ __name(zodupload, "zodupload");
1338
+ var createForm = /* @__PURE__ */ __name(async (body) => {
1339
+ const form = new FormData();
1340
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
1341
+ return form;
1342
+ }, "createForm");
1291
1343
  async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1292
1344
  try {
1293
1345
  const response = await fetch(url, requestInitWithCache(requestInit));
@@ -1409,6 +1461,95 @@ function requestInitWithCache(requestInit) {
1409
1461
  }
1410
1462
  }
1411
1463
  __name(requestInitWithCache, "requestInitWithCache");
1464
+ var addFormValue = /* @__PURE__ */ __name(async (form, key, value) => {
1465
+ if (value === void 0)
1466
+ return;
1467
+ if (value == null) {
1468
+ throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
1469
+ }
1470
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1471
+ form.append(key, String(value));
1472
+ } else if (isUploadable(value) || isBlobLike(value) || value instanceof Buffer || value instanceof ArrayBuffer) {
1473
+ const file = await toFile(value);
1474
+ form.append(key, file);
1475
+ } else if (Array.isArray(value)) {
1476
+ await Promise.all(value.map((entry) => addFormValue(form, key + "[]", entry)));
1477
+ } else if (typeof value === "object") {
1478
+ await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
1479
+ } else {
1480
+ throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
1481
+ }
1482
+ }, "addFormValue");
1483
+ async function toFile(value, name, options) {
1484
+ value = await value;
1485
+ options ??= isFileLike(value) ? {
1486
+ lastModified: value.lastModified,
1487
+ type: value.type
1488
+ } : {};
1489
+ if (isResponseLike(value)) {
1490
+ const blob = await value.blob();
1491
+ name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? "unknown_file";
1492
+ return new File([
1493
+ blob
1494
+ ], name, options);
1495
+ }
1496
+ const bits = await getBytes(value);
1497
+ name ||= getName(value) ?? "unknown_file";
1498
+ if (!options.type) {
1499
+ const type = bits[0]?.type;
1500
+ if (typeof type === "string") {
1501
+ options = {
1502
+ ...options,
1503
+ type
1504
+ };
1505
+ }
1506
+ }
1507
+ return new File(bits, name, options);
1508
+ }
1509
+ __name(toFile, "toFile");
1510
+ function getName(value) {
1511
+ return getStringFromMaybeBuffer(value.name) || getStringFromMaybeBuffer(value.filename) || // For fs.ReadStream
1512
+ getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop();
1513
+ }
1514
+ __name(getName, "getName");
1515
+ var getStringFromMaybeBuffer = /* @__PURE__ */ __name((x) => {
1516
+ if (typeof x === "string")
1517
+ return x;
1518
+ if (typeof Buffer !== "undefined" && x instanceof Buffer)
1519
+ return String(x);
1520
+ return void 0;
1521
+ }, "getStringFromMaybeBuffer");
1522
+ async function getBytes(value) {
1523
+ let parts = [];
1524
+ if (typeof value === "string" || ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
1525
+ value instanceof ArrayBuffer) {
1526
+ parts.push(value);
1527
+ } else if (isBlobLike(value)) {
1528
+ parts.push(await value.arrayBuffer());
1529
+ } else if (isAsyncIterableIterator(value)) {
1530
+ for await (const chunk of value) {
1531
+ parts.push(chunk);
1532
+ }
1533
+ } else {
1534
+ throw new Error(`Unexpected data type: ${typeof value}; constructor: ${value?.constructor?.name}; props: ${propsForError(value)}`);
1535
+ }
1536
+ return parts;
1537
+ }
1538
+ __name(getBytes, "getBytes");
1539
+ function propsForError(value) {
1540
+ const props = Object.getOwnPropertyNames(value);
1541
+ return `[${props.map((p) => `"${p}"`).join(", ")}]`;
1542
+ }
1543
+ __name(propsForError, "propsForError");
1544
+ var isAsyncIterableIterator = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function", "isAsyncIterableIterator");
1545
+ var isResponseLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.url === "string" && typeof value.blob === "function", "isResponseLike");
1546
+ var isFileLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.name === "string" && typeof value.lastModified === "number" && isBlobLike(value), "isFileLike");
1547
+ 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");
1548
+ var isFsReadStream = /* @__PURE__ */ __name((value) => value instanceof Readable, "isFsReadStream");
1549
+ var isUploadable = /* @__PURE__ */ __name((value) => {
1550
+ return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
1551
+ }, "isUploadable");
1552
+ 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");
1412
1553
 
1413
1554
  // src/v3/apiClient/index.ts
1414
1555
  var zodFetchOptions = {
@@ -1543,14 +1684,62 @@ var _ApiClient = class _ApiClient {
1543
1684
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1544
1685
  });
1545
1686
  }
1687
+ listEnvVars(projectRef, slug) {
1688
+ return zodfetch(EnvironmentVariables, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
1689
+ method: "GET",
1690
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1691
+ });
1692
+ }
1693
+ importEnvVars(projectRef, slug, body) {
1694
+ if (isRecordLike(body.variables)) {
1695
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, {
1696
+ method: "POST",
1697
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1698
+ body: JSON.stringify(body)
1699
+ });
1700
+ } else {
1701
+ return zodupload(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, body, {
1702
+ method: "POST",
1703
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1704
+ });
1705
+ }
1706
+ }
1707
+ retrieveEnvVar(projectRef, slug, key) {
1708
+ return zodfetch(EnvironmentVariableValue, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1709
+ method: "GET",
1710
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1711
+ });
1712
+ }
1713
+ createEnvVar(projectRef, slug, body) {
1714
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
1715
+ method: "POST",
1716
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1717
+ body: JSON.stringify(body)
1718
+ });
1719
+ }
1720
+ updateEnvVar(projectRef, slug, key, body) {
1721
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1722
+ method: "PUT",
1723
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1724
+ body: JSON.stringify(body)
1725
+ });
1726
+ }
1727
+ deleteEnvVar(projectRef, slug, key) {
1728
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1729
+ method: "DELETE",
1730
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1731
+ });
1732
+ }
1546
1733
  };
1547
1734
  _getHeaders = new WeakSet();
1548
1735
  getHeaders_fn = /* @__PURE__ */ __name(function(spanParentAsLink) {
1549
1736
  const headers = {
1550
1737
  "Content-Type": "application/json",
1551
- Authorization: `Bearer ${this.accessToken}`
1738
+ Authorization: `Bearer ${this.accessToken}`,
1739
+ "trigger-version": version
1552
1740
  };
1553
1741
  if (taskContext.isInsideTask) {
1742
+ headers["x-trigger-worker"] = "true";
1554
1743
  propagation.inject(context.active(), headers);
1555
1744
  if (spanParentAsLink) {
1556
1745
  headers["x-trigger-span-parent-as-link"] = "1";
@@ -1586,7 +1775,7 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
1586
1775
  }
1587
1776
  get accessToken() {
1588
1777
  const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
1589
- return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY");
1778
+ return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY") ?? getEnvVar("TRIGGER_ACCESS_TOKEN");
1590
1779
  }
1591
1780
  get client() {
1592
1781
  if (!this.baseURL || !this.accessToken) {