@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.
@@ -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
 
@@ -356,7 +358,7 @@ function getEnvVar(name) {
356
358
  __name(getEnvVar, "getEnvVar");
357
359
 
358
360
  // package.json
359
- var version = "0.0.0-v3-prerelease-20240517090458";
361
+ var version = "0.0.0-v3-prerelease-20240523152756";
360
362
 
361
363
  // src/v3/otel/tracingSDK.ts
362
364
  var _a;
@@ -1124,6 +1126,28 @@ var RetrieveRunResponse = zod.z.object({
1124
1126
  completedAt: zod.z.coerce.date().optional()
1125
1127
  }).optional())
1126
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);
1127
1151
 
1128
1152
  // src/v3/apiErrors.ts
1129
1153
  var _APIError = class _APIError extends Error {
@@ -1285,8 +1309,6 @@ function calculateNextRetryDelay(options, attempt) {
1285
1309
  return Math.round(timeout);
1286
1310
  }
1287
1311
  __name(calculateNextRetryDelay, "calculateNextRetryDelay");
1288
-
1289
- // src/v3/zodfetch.ts
1290
1312
  var defaultRetryOptions2 = {
1291
1313
  maxAttempts: 3,
1292
1314
  factor: 2,
@@ -1298,6 +1320,32 @@ async function zodfetch(schema, url, requestInit, options) {
1298
1320
  return await _doZodFetch(schema, url, requestInit, options);
1299
1321
  }
1300
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");
1301
1349
  async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1302
1350
  try {
1303
1351
  const response = await fetch(url, requestInitWithCache(requestInit));
@@ -1419,6 +1467,95 @@ function requestInitWithCache(requestInit) {
1419
1467
  }
1420
1468
  }
1421
1469
  __name(requestInitWithCache, "requestInitWithCache");
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");
1422
1559
 
1423
1560
  // src/v3/apiClient/index.ts
1424
1561
  var zodFetchOptions = {
@@ -1553,6 +1690,52 @@ var _ApiClient = class _ApiClient {
1553
1690
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1554
1691
  });
1555
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
+ }
1556
1739
  };
1557
1740
  _getHeaders = new WeakSet();
1558
1741
  getHeaders_fn = /* @__PURE__ */ __name(function(spanParentAsLink) {
@@ -1598,7 +1781,7 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
1598
1781
  }
1599
1782
  get accessToken() {
1600
1783
  const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
1601
- return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY");
1784
+ return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY") ?? getEnvVar("TRIGGER_ACCESS_TOKEN");
1602
1785
  }
1603
1786
  get client() {
1604
1787
  if (!this.baseURL || !this.accessToken) {