@trigger.dev/core 3.0.0-beta.33 → 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.
@@ -11,6 +11,8 @@ var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
11
11
  var semanticConventions = require('@opentelemetry/semantic-conventions');
12
12
  var zod = require('zod');
13
13
  var zodValidationError = require('zod-validation-error');
14
+ var formDataEncoder = require('form-data-encoder');
15
+ var stream = require('stream');
14
16
  var preciseDate = require('@google-cloud/precise-date');
15
17
  var util = require('util');
16
18
 
@@ -355,6 +357,9 @@ function getEnvVar(name) {
355
357
  }
356
358
  __name(getEnvVar, "getEnvVar");
357
359
 
360
+ // package.json
361
+ var version = "3.0.0-beta.34";
362
+
358
363
  // src/v3/otel/tracingSDK.ts
359
364
  var _a;
360
365
  var AsyncResourceDetector = (_a = class {
@@ -392,7 +397,8 @@ var _TracingSDK = class _TracingSDK {
392
397
  ]
393
398
  }).merge(new resources.Resource({
394
399
  [semanticConventions.SemanticResourceAttributes.CLOUD_PROVIDER]: "trigger.dev",
395
- [SemanticInternalAttributes.TRIGGER]: true
400
+ [SemanticInternalAttributes.TRIGGER]: true,
401
+ [SemanticInternalAttributes.CLI_VERSION]: version
396
402
  })).merge(config.resource ?? new resources.Resource({})).merge(new resources.Resource(envResourceAttributes));
397
403
  const traceProvider = new sdkTraceNode.NodeTracerProvider({
398
404
  forceFlushTimeoutMillis: config.forceFlushTimeoutMillis ?? 500,
@@ -1120,6 +1126,28 @@ var RetrieveRunResponse = zod.z.object({
1120
1126
  completedAt: zod.z.coerce.date().optional()
1121
1127
  }).optional())
1122
1128
  });
1129
+ zod.z.object({
1130
+ name: zod.z.string(),
1131
+ value: zod.z.string()
1132
+ });
1133
+ zod.z.object({
1134
+ value: zod.z.string()
1135
+ });
1136
+ zod.z.object({
1137
+ variables: zod.z.record(zod.z.string()),
1138
+ override: zod.z.boolean().optional()
1139
+ });
1140
+ var EnvironmentVariableResponseBody = zod.z.object({
1141
+ success: zod.z.boolean()
1142
+ });
1143
+ var EnvironmentVariableValue = zod.z.object({
1144
+ value: zod.z.string()
1145
+ });
1146
+ var EnvironmentVariable = zod.z.object({
1147
+ name: zod.z.string(),
1148
+ value: zod.z.string()
1149
+ });
1150
+ var EnvironmentVariables = zod.z.array(EnvironmentVariable);
1123
1151
 
1124
1152
  // src/v3/apiErrors.ts
1125
1153
  var _APIError = class _APIError extends Error {
@@ -1281,8 +1309,6 @@ function calculateNextRetryDelay(options, attempt) {
1281
1309
  return Math.round(timeout);
1282
1310
  }
1283
1311
  __name(calculateNextRetryDelay, "calculateNextRetryDelay");
1284
-
1285
- // src/v3/zodfetch.ts
1286
1312
  var defaultRetryOptions2 = {
1287
1313
  maxAttempts: 3,
1288
1314
  factor: 2,
@@ -1294,6 +1320,32 @@ async function zodfetch(schema, url, requestInit, options) {
1294
1320
  return await _doZodFetch(schema, url, requestInit, options);
1295
1321
  }
1296
1322
  __name(zodfetch, "zodfetch");
1323
+ async function zodupload(schema, url, body, requestInit, options) {
1324
+ const form = await createForm(body);
1325
+ const encoder = new formDataEncoder.FormDataEncoder(form);
1326
+ const finalHeaders = {};
1327
+ for (const [key, value] of Object.entries(requestInit?.headers || {})) {
1328
+ finalHeaders[key] = value;
1329
+ }
1330
+ for (const [key, value] of Object.entries(encoder.headers)) {
1331
+ finalHeaders[key] = value;
1332
+ }
1333
+ finalHeaders["Content-Length"] = String(encoder.contentLength);
1334
+ const finalRequestInit = {
1335
+ ...requestInit,
1336
+ headers: finalHeaders,
1337
+ body: stream.Readable.from(encoder),
1338
+ // @ts-expect-error
1339
+ duplex: "half"
1340
+ };
1341
+ return await _doZodFetch(schema, url, finalRequestInit, options);
1342
+ }
1343
+ __name(zodupload, "zodupload");
1344
+ var createForm = /* @__PURE__ */ __name(async (body) => {
1345
+ const form = new FormData();
1346
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
1347
+ return form;
1348
+ }, "createForm");
1297
1349
  async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1298
1350
  try {
1299
1351
  const response = await fetch(url, requestInitWithCache(requestInit));
@@ -1415,9 +1467,95 @@ function requestInitWithCache(requestInit) {
1415
1467
  }
1416
1468
  }
1417
1469
  __name(requestInitWithCache, "requestInitWithCache");
1418
-
1419
- // package.json
1420
- var version = "3.0.0-beta.33";
1470
+ var addFormValue = /* @__PURE__ */ __name(async (form, key, value) => {
1471
+ if (value === void 0)
1472
+ return;
1473
+ if (value == null) {
1474
+ throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
1475
+ }
1476
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1477
+ form.append(key, String(value));
1478
+ } else if (isUploadable(value) || isBlobLike(value) || value instanceof Buffer || value instanceof ArrayBuffer) {
1479
+ const file = await toFile(value);
1480
+ form.append(key, file);
1481
+ } else if (Array.isArray(value)) {
1482
+ await Promise.all(value.map((entry) => addFormValue(form, key + "[]", entry)));
1483
+ } else if (typeof value === "object") {
1484
+ await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
1485
+ } else {
1486
+ throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
1487
+ }
1488
+ }, "addFormValue");
1489
+ async function toFile(value, name, options) {
1490
+ value = await value;
1491
+ options ??= isFileLike(value) ? {
1492
+ lastModified: value.lastModified,
1493
+ type: value.type
1494
+ } : {};
1495
+ if (isResponseLike(value)) {
1496
+ const blob = await value.blob();
1497
+ name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? "unknown_file";
1498
+ return new File([
1499
+ blob
1500
+ ], name, options);
1501
+ }
1502
+ const bits = await getBytes(value);
1503
+ name ||= getName(value) ?? "unknown_file";
1504
+ if (!options.type) {
1505
+ const type = bits[0]?.type;
1506
+ if (typeof type === "string") {
1507
+ options = {
1508
+ ...options,
1509
+ type
1510
+ };
1511
+ }
1512
+ }
1513
+ return new File(bits, name, options);
1514
+ }
1515
+ __name(toFile, "toFile");
1516
+ function getName(value) {
1517
+ return getStringFromMaybeBuffer(value.name) || getStringFromMaybeBuffer(value.filename) || // For fs.ReadStream
1518
+ getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop();
1519
+ }
1520
+ __name(getName, "getName");
1521
+ var getStringFromMaybeBuffer = /* @__PURE__ */ __name((x) => {
1522
+ if (typeof x === "string")
1523
+ return x;
1524
+ if (typeof Buffer !== "undefined" && x instanceof Buffer)
1525
+ return String(x);
1526
+ return void 0;
1527
+ }, "getStringFromMaybeBuffer");
1528
+ async function getBytes(value) {
1529
+ let parts = [];
1530
+ if (typeof value === "string" || ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
1531
+ value instanceof ArrayBuffer) {
1532
+ parts.push(value);
1533
+ } else if (isBlobLike(value)) {
1534
+ parts.push(await value.arrayBuffer());
1535
+ } else if (isAsyncIterableIterator(value)) {
1536
+ for await (const chunk of value) {
1537
+ parts.push(chunk);
1538
+ }
1539
+ } else {
1540
+ throw new Error(`Unexpected data type: ${typeof value}; constructor: ${value?.constructor?.name}; props: ${propsForError(value)}`);
1541
+ }
1542
+ return parts;
1543
+ }
1544
+ __name(getBytes, "getBytes");
1545
+ function propsForError(value) {
1546
+ const props = Object.getOwnPropertyNames(value);
1547
+ return `[${props.map((p) => `"${p}"`).join(", ")}]`;
1548
+ }
1549
+ __name(propsForError, "propsForError");
1550
+ var isAsyncIterableIterator = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function", "isAsyncIterableIterator");
1551
+ var isResponseLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.url === "string" && typeof value.blob === "function", "isResponseLike");
1552
+ var isFileLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.name === "string" && typeof value.lastModified === "number" && isBlobLike(value), "isFileLike");
1553
+ 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");
1554
+ var isFsReadStream = /* @__PURE__ */ __name((value) => value instanceof stream.Readable, "isFsReadStream");
1555
+ var isUploadable = /* @__PURE__ */ __name((value) => {
1556
+ return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
1557
+ }, "isUploadable");
1558
+ 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");
1421
1559
 
1422
1560
  // src/v3/apiClient/index.ts
1423
1561
  var zodFetchOptions = {
@@ -1552,6 +1690,52 @@ var _ApiClient = class _ApiClient {
1552
1690
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1553
1691
  });
1554
1692
  }
1693
+ listEnvVars(projectRef, slug) {
1694
+ return zodfetch(EnvironmentVariables, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
1695
+ method: "GET",
1696
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1697
+ });
1698
+ }
1699
+ importEnvVars(projectRef, slug, body) {
1700
+ if (isRecordLike(body.variables)) {
1701
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, {
1702
+ method: "POST",
1703
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1704
+ body: JSON.stringify(body)
1705
+ });
1706
+ } else {
1707
+ return zodupload(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, body, {
1708
+ method: "POST",
1709
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1710
+ });
1711
+ }
1712
+ }
1713
+ retrieveEnvVar(projectRef, slug, key) {
1714
+ return zodfetch(EnvironmentVariableValue, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1715
+ method: "GET",
1716
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1717
+ });
1718
+ }
1719
+ createEnvVar(projectRef, slug, body) {
1720
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
1721
+ method: "POST",
1722
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1723
+ body: JSON.stringify(body)
1724
+ });
1725
+ }
1726
+ updateEnvVar(projectRef, slug, key, body) {
1727
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1728
+ method: "PUT",
1729
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
1730
+ body: JSON.stringify(body)
1731
+ });
1732
+ }
1733
+ deleteEnvVar(projectRef, slug, key) {
1734
+ return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
1735
+ method: "DELETE",
1736
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1737
+ });
1738
+ }
1555
1739
  };
1556
1740
  _getHeaders = new WeakSet();
1557
1741
  getHeaders_fn = /* @__PURE__ */ __name(function(spanParentAsLink) {
@@ -1597,7 +1781,7 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
1597
1781
  }
1598
1782
  get accessToken() {
1599
1783
  const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
1600
- return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY");
1784
+ return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY") ?? getEnvVar("TRIGGER_ACCESS_TOKEN");
1601
1785
  }
1602
1786
  get client() {
1603
1787
  if (!this.baseURL || !this.accessToken) {