@trigger.dev/core 0.0.0-v3-prerelease-20240517090458 → 0.0.0-v3-prerelease-20240523152756

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
 
@@ -350,7 +352,7 @@ function getEnvVar(name) {
350
352
  __name(getEnvVar, "getEnvVar");
351
353
 
352
354
  // package.json
353
- var version = "0.0.0-v3-prerelease-20240517090458";
355
+ var version = "0.0.0-v3-prerelease-20240523152756";
354
356
 
355
357
  // src/v3/otel/tracingSDK.ts
356
358
  var _a;
@@ -1118,6 +1120,28 @@ var RetrieveRunResponse = z.object({
1118
1120
  completedAt: z.coerce.date().optional()
1119
1121
  }).optional())
1120
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);
1121
1145
 
1122
1146
  // src/v3/apiErrors.ts
1123
1147
  var _APIError = class _APIError extends Error {
@@ -1279,8 +1303,6 @@ function calculateNextRetryDelay(options, attempt) {
1279
1303
  return Math.round(timeout);
1280
1304
  }
1281
1305
  __name(calculateNextRetryDelay, "calculateNextRetryDelay");
1282
-
1283
- // src/v3/zodfetch.ts
1284
1306
  var defaultRetryOptions2 = {
1285
1307
  maxAttempts: 3,
1286
1308
  factor: 2,
@@ -1292,6 +1314,32 @@ async function zodfetch(schema, url, requestInit, options) {
1292
1314
  return await _doZodFetch(schema, url, requestInit, options);
1293
1315
  }
1294
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");
1295
1343
  async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1296
1344
  try {
1297
1345
  const response = await fetch(url, requestInitWithCache(requestInit));
@@ -1413,6 +1461,95 @@ function requestInitWithCache(requestInit) {
1413
1461
  }
1414
1462
  }
1415
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");
1416
1553
 
1417
1554
  // src/v3/apiClient/index.ts
1418
1555
  var zodFetchOptions = {
@@ -1547,6 +1684,52 @@ var _ApiClient = class _ApiClient {
1547
1684
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1548
1685
  });
1549
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
+ }
1550
1733
  };
1551
1734
  _getHeaders = new WeakSet();
1552
1735
  getHeaders_fn = /* @__PURE__ */ __name(function(spanParentAsLink) {
@@ -1592,7 +1775,7 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
1592
1775
  }
1593
1776
  get accessToken() {
1594
1777
  const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
1595
- return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY");
1778
+ return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY") ?? getEnvVar("TRIGGER_ACCESS_TOKEN");
1596
1779
  }
1597
1780
  get client() {
1598
1781
  if (!this.baseURL || !this.accessToken) {