@dura-run/cli 0.2.1 → 0.3.1

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 (3) hide show
  1. package/README.md +40 -0
  2. package/dist/dura.js +739 -640
  3. package/package.json +3 -3
package/dist/dura.js CHANGED
@@ -2356,13 +2356,44 @@ var init_config_store = () => {};
2356
2356
  var exports_login = {};
2357
2357
  __export(exports_login, {
2358
2358
  startCallbackServer: () => startCallbackServer,
2359
- registerLoginCommand: () => registerLoginCommand
2359
+ registerLoginCommand: () => registerLoginCommand,
2360
+ isAllowedReferer: () => isAllowedReferer,
2361
+ CLI_CALLBACK_PORT_MIN: () => CLI_CALLBACK_PORT_MIN,
2362
+ CLI_CALLBACK_PORT_MAX: () => CLI_CALLBACK_PORT_MAX
2360
2363
  });
2364
+ import { randomBytes, timingSafeEqual } from "node:crypto";
2361
2365
  import {
2362
2366
  createServer
2363
2367
  } from "node:http";
2364
2368
  import { URL as URL2 } from "node:url";
2365
- function startCallbackServer() {
2369
+ function safeEqual(a, b) {
2370
+ const aBuf = Buffer.from(a);
2371
+ const bBuf = Buffer.from(b);
2372
+ if (aBuf.length !== bBuf.length)
2373
+ return false;
2374
+ return timingSafeEqual(aBuf, bBuf);
2375
+ }
2376
+ function isAllowedReferer(referer, consoleUrl, apiUrl) {
2377
+ if (!referer)
2378
+ return true;
2379
+ let refOrigin;
2380
+ try {
2381
+ refOrigin = new URL2(referer).origin;
2382
+ } catch {
2383
+ return false;
2384
+ }
2385
+ const allowed = new Set;
2386
+ for (const u of [consoleUrl, apiUrl]) {
2387
+ try {
2388
+ allowed.add(new URL2(u).origin);
2389
+ } catch {}
2390
+ }
2391
+ return allowed.has(refOrigin);
2392
+ }
2393
+ function startCallbackServer(opts) {
2394
+ const consoleUrl = opts?.consoleUrl ?? getConsoleUrl();
2395
+ const apiUrl = opts?.apiUrl ?? getApiUrl();
2396
+ const state = randomBytes(32).toString("hex");
2366
2397
  return new Promise((resolveSetup, rejectSetup) => {
2367
2398
  let resolveCode;
2368
2399
  let rejectCode;
@@ -2377,14 +2408,29 @@ function startCallbackServer() {
2377
2408
  res.end("Not found");
2378
2409
  return;
2379
2410
  }
2411
+ const referer = req.headers["referer"] || req.headers["referrer"];
2412
+ const refererValue = Array.isArray(referer) ? referer[0] : referer;
2413
+ if (!isAllowedReferer(refererValue, consoleUrl, apiUrl)) {
2414
+ res.writeHead(400, { "Content-Type": "text/html" });
2415
+ res.end("<html><body><h1>Invalid callback</h1><p>Unexpected referrer.</p></body></html>");
2416
+ rejectCode(new Error("Invalid callback: referrer is not from the dura.run console"));
2417
+ return;
2418
+ }
2380
2419
  const code = url.searchParams.get("code");
2381
2420
  const error = url.searchParams.get("error");
2421
+ const callbackState = url.searchParams.get("state");
2382
2422
  if (error) {
2383
2423
  res.writeHead(200, { "Content-Type": "text/html" });
2384
2424
  res.end("<html><body><h1>Login failed</h1><p>You can close this window.</p></body></html>");
2385
2425
  rejectCode(new Error(`Login failed: ${error}`));
2386
2426
  return;
2387
2427
  }
2428
+ if (!callbackState || !safeEqual(callbackState, state)) {
2429
+ res.writeHead(400, { "Content-Type": "text/html" });
2430
+ res.end("<html><body><h1>Invalid callback</h1><p>Missing or invalid state parameter.</p></body></html>");
2431
+ rejectCode(new Error("Invalid callback: missing or invalid state parameter"));
2432
+ return;
2433
+ }
2388
2434
  if (!code) {
2389
2435
  res.writeHead(400, { "Content-Type": "text/html" });
2390
2436
  res.end("<html><body><h1>Invalid callback</h1><p>Missing code parameter.</p></body></html>");
@@ -2395,15 +2441,24 @@ function startCallbackServer() {
2395
2441
  res.end("<html><body><h1>Login successful!</h1><p>You can close this window and return to your terminal.</p></body></html>");
2396
2442
  resolveCode(code);
2397
2443
  });
2398
- server.listen(0, "127.0.0.1", () => {
2399
- const addr = server.address();
2400
- if (!addr || typeof addr === "string") {
2401
- rejectSetup(new Error("Failed to bind callback server"));
2402
- return;
2403
- }
2404
- resolveSetup({ server, port: addr.port, codePromise });
2405
- });
2406
- server.on("error", rejectSetup);
2444
+ const tryPort = (p) => {
2445
+ server.once("error", (err) => {
2446
+ if (err.code === "EADDRINUSE" && p < CLI_CALLBACK_PORT_MAX) {
2447
+ tryPort(p + 1);
2448
+ } else {
2449
+ rejectSetup(err);
2450
+ }
2451
+ });
2452
+ server.listen(p, "127.0.0.1", () => {
2453
+ const addr = server.address();
2454
+ if (!addr || typeof addr === "string") {
2455
+ rejectSetup(new Error("Failed to bind callback server"));
2456
+ return;
2457
+ }
2458
+ resolveSetup({ server, port: addr.port, state, codePromise });
2459
+ });
2460
+ };
2461
+ tryPort(CLI_CALLBACK_PORT_MIN);
2407
2462
  });
2408
2463
  }
2409
2464
  async function openBrowser(url) {
@@ -2440,10 +2495,13 @@ function registerLoginCommand(program2) {
2440
2495
  const consoleUrl = getConsoleUrl();
2441
2496
  let server;
2442
2497
  try {
2443
- const callbackResult = await startCallbackServer();
2498
+ const callbackResult = await startCallbackServer({
2499
+ consoleUrl,
2500
+ apiUrl
2501
+ });
2444
2502
  server = callbackResult.server;
2445
- const { port } = callbackResult;
2446
- const loginUrl = `${consoleUrl}/cli-auth?port=${port}`;
2503
+ const { port, state } = callbackResult;
2504
+ const loginUrl = `${consoleUrl}/cli-auth?port=${port}&state=${state}`;
2447
2505
  output.info("Opening browser for login...");
2448
2506
  output.info(`If the browser doesn't open, visit: ${loginUrl}`);
2449
2507
  await openBrowser(loginUrl);
@@ -2491,6 +2549,7 @@ function registerLoginCommand(program2) {
2491
2549
  }
2492
2550
  });
2493
2551
  }
2552
+ var CLI_CALLBACK_PORT_MIN = 31180, CLI_CALLBACK_PORT_MAX = 31199;
2494
2553
  var init_login = __esm(() => {
2495
2554
  init_src3();
2496
2555
  init_config_store();
@@ -2775,6 +2834,22 @@ var init_hello = __esm(() => {
2775
2834
  HELLO_TEMPLATE = GET_TEMPLATE;
2776
2835
  });
2777
2836
 
2837
+ // src/lib/handle-api-error.ts
2838
+ function reportApiError(output, err, fallbackCode) {
2839
+ if (err instanceof ApiClientError) {
2840
+ output.error(err.code, err.message, err.suggestion);
2841
+ return;
2842
+ }
2843
+ if (err instanceof Error) {
2844
+ output.error(fallbackCode, err.message);
2845
+ return;
2846
+ }
2847
+ output.error(fallbackCode, String(err));
2848
+ }
2849
+ var init_handle_api_error = __esm(() => {
2850
+ init_api_client();
2851
+ });
2852
+
2778
2853
  // src/commands/new.ts
2779
2854
  var exports_new = {};
2780
2855
  __export(exports_new, {
@@ -2831,11 +2906,7 @@ function registerNewCommand(program2) {
2831
2906
  Set required secrets: ${result.requiredSecrets.join(", ")}`);
2832
2907
  }
2833
2908
  } catch (err) {
2834
- if (err instanceof ApiClientError) {
2835
- output.error(err.code, err.message, err.suggestion);
2836
- } else if (err instanceof Error) {
2837
- output.error("FORK_FAILED", err.message);
2838
- }
2909
+ reportApiError(output, err, "FORK_FAILED");
2839
2910
  }
2840
2911
  return;
2841
2912
  }
@@ -2889,6 +2960,7 @@ var init_new = __esm(() => {
2889
2960
  init_hello();
2890
2961
  init_api_client();
2891
2962
  init_config_store();
2963
+ init_handle_api_error();
2892
2964
  });
2893
2965
 
2894
2966
  // src/lib/project-id.ts
@@ -2943,9 +3015,7 @@ function registerSecretsCommand(program2) {
2943
3015
  const result = await client.put(`/api/v1/projects/${projectId}/secrets`, { name, value });
2944
3016
  output.success(result);
2945
3017
  } catch (err) {
2946
- if (err instanceof Error) {
2947
- output.error("SECRET_SET_FAILED", err.message);
2948
- }
3018
+ reportApiError(output, err, "SECRET_SET_FAILED");
2949
3019
  }
2950
3020
  });
2951
3021
  secrets.command("list").description("List secret names (values never shown)").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -2958,9 +3028,7 @@ function registerSecretsCommand(program2) {
2958
3028
  const result = await client.get(`/api/v1/projects/${projectId}/secrets`);
2959
3029
  output.table(["Name", "Created", "Updated"], result.map((s) => [s.name, s.createdAt, s.updatedAt]));
2960
3030
  } catch (err) {
2961
- if (err instanceof Error) {
2962
- output.error("SECRET_LIST_FAILED", err.message);
2963
- }
3031
+ reportApiError(output, err, "SECRET_LIST_FAILED");
2964
3032
  }
2965
3033
  });
2966
3034
  secrets.command("remove <name>").description("Remove a secret").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Confirm this destructive operation").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (name, opts, cmd) => {
@@ -2977,9 +3045,7 @@ function registerSecretsCommand(program2) {
2977
3045
  await client.delete(`/api/v1/projects/${projectId}/secrets/${name}`);
2978
3046
  output.success({ deleted: true, name });
2979
3047
  } catch (err) {
2980
- if (err instanceof Error) {
2981
- output.error("SECRET_REMOVE_FAILED", err.message);
2982
- }
3048
+ reportApiError(output, err, "SECRET_REMOVE_FAILED");
2983
3049
  }
2984
3050
  });
2985
3051
  secrets.command("pull").description("Write secrets to .env.local for local development").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").option("--dir <path>", "Directory to write .env.local to", ".").action(async (opts, cmd) => {
@@ -3000,9 +3066,7 @@ function registerSecretsCommand(program2) {
3000
3066
  count: Object.keys(values).length
3001
3067
  });
3002
3068
  } catch (err) {
3003
- if (err instanceof Error) {
3004
- output.error("SECRET_PULL_FAILED", err.message);
3005
- }
3069
+ reportApiError(output, err, "SECRET_PULL_FAILED");
3006
3070
  }
3007
3071
  });
3008
3072
  }
@@ -3010,6 +3074,7 @@ var init_secrets = __esm(() => {
3010
3074
  init_src3();
3011
3075
  init_api_client();
3012
3076
  init_config_store();
3077
+ init_handle_api_error();
3013
3078
  init_project_id();
3014
3079
  });
3015
3080
 
@@ -7187,7 +7252,7 @@ var init_marketplace = __esm(() => {
7187
7252
  entrypoint: exports_external.string().min(1, "Entrypoint is required"),
7188
7253
  configSchema: exports_external.record(exports_external.unknown()).optional(),
7189
7254
  readme: exports_external.string().max(50000).optional()
7190
- });
7255
+ }).strict();
7191
7256
  installAdapterSchema = exports_external.object({
7192
7257
  adapterId: exports_external.string().min(1, "Adapter ID is required"),
7193
7258
  config: exports_external.record(exports_external.unknown()).optional()
@@ -7201,7 +7266,7 @@ var init_marketplace = __esm(() => {
7201
7266
  });
7202
7267
  });
7203
7268
 
7204
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/query.js
7269
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/query.js
7205
7270
  function cachedError(xs) {
7206
7271
  if (originCache.has(xs))
7207
7272
  return originCache.get(xs);
@@ -7341,7 +7406,7 @@ var init_query = __esm(() => {
7341
7406
  };
7342
7407
  });
7343
7408
 
7344
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/errors.js
7409
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/errors.js
7345
7410
  function connection(x, options, socket) {
7346
7411
  const { host, port } = socket || options;
7347
7412
  const error = Object.assign(new Error("write " + x + " " + (options.path || host + ":" + port)), {
@@ -7387,7 +7452,7 @@ var init_errors2 = __esm(() => {
7387
7452
  };
7388
7453
  });
7389
7454
 
7390
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/types.js
7455
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/types.js
7391
7456
  class NotTagged {
7392
7457
  then() {
7393
7458
  notTagged();
@@ -7658,7 +7723,7 @@ var init_types2 = __esm(() => {
7658
7723
  kebab.column.to = fromKebab;
7659
7724
  });
7660
7725
 
7661
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/result.js
7726
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/result.js
7662
7727
  var Result;
7663
7728
  var init_result = __esm(() => {
7664
7729
  Result = class Result extends Array {
@@ -7678,7 +7743,7 @@ var init_result = __esm(() => {
7678
7743
  };
7679
7744
  });
7680
7745
 
7681
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/queue.js
7746
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/queue.js
7682
7747
  function Queue(initial = []) {
7683
7748
  let xs = initial.slice();
7684
7749
  let index = 0;
@@ -7708,7 +7773,7 @@ var init_queue = __esm(() => {
7708
7773
  queue_default = Queue;
7709
7774
  });
7710
7775
 
7711
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/bytes.js
7776
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/bytes.js
7712
7777
  function fit(x) {
7713
7778
  if (buffer.length - b.i < x) {
7714
7779
  const prev = buffer, length = prev.length;
@@ -7783,7 +7848,7 @@ var init_bytes = __esm(() => {
7783
7848
  bytes_default = b;
7784
7849
  });
7785
7850
 
7786
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/connection.js
7851
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/connection.js
7787
7852
  import net from "net";
7788
7853
  import tls from "tls";
7789
7854
  import crypto from "crypto";
@@ -8518,7 +8583,7 @@ var init_connection = __esm(() => {
8518
8583
  };
8519
8584
  });
8520
8585
 
8521
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/subscribe.js
8586
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/subscribe.js
8522
8587
  function Subscribe(postgres2, options) {
8523
8588
  const subscribers = new Map, slot = "postgresjs_" + Math.random().toString(36).slice(2), state = {};
8524
8589
  let connection2, stream, ended = false;
@@ -8714,7 +8779,7 @@ function parseEvent(x) {
8714
8779
  }
8715
8780
  var noop2 = () => {};
8716
8781
 
8717
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/large.js
8782
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/large.js
8718
8783
  import Stream2 from "stream";
8719
8784
  function largeObject(sql, oid, mode = 131072 | 262144) {
8720
8785
  return new Promise(async (resolve2, reject) => {
@@ -8781,7 +8846,7 @@ function largeObject(sql, oid, mode = 131072 | 262144) {
8781
8846
  }
8782
8847
  var init_large = () => {};
8783
8848
 
8784
- // ../../node_modules/.bun/postgres@3.4.8/node_modules/postgres/src/index.js
8849
+ // ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/index.js
8785
8850
  import os from "os";
8786
8851
  import fs from "fs";
8787
8852
  function Postgres(a, b2) {
@@ -9185,7 +9250,7 @@ var init_src = __esm(() => {
9185
9250
  });
9186
9251
  });
9187
9252
 
9188
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/entity.js
9253
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/entity.js
9189
9254
  function is(value, type) {
9190
9255
  if (!value || typeof value !== "object") {
9191
9256
  return false;
@@ -9213,10 +9278,10 @@ var init_entity = __esm(() => {
9213
9278
  hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
9214
9279
  });
9215
9280
 
9216
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/logger.js
9281
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/logger.js
9217
9282
  var init_logger = () => {};
9218
9283
 
9219
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/query-promise.js
9284
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/query-promise.js
9220
9285
  var QueryPromise;
9221
9286
  var init_query_promise = __esm(() => {
9222
9287
  init_entity();
@@ -9241,7 +9306,7 @@ var init_query_promise = __esm(() => {
9241
9306
  };
9242
9307
  });
9243
9308
 
9244
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/column.js
9309
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/column.js
9245
9310
  var Column;
9246
9311
  var init_column = __esm(() => {
9247
9312
  init_entity();
@@ -9295,7 +9360,7 @@ var init_column = __esm(() => {
9295
9360
  };
9296
9361
  });
9297
9362
 
9298
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/column-builder.js
9363
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/column-builder.js
9299
9364
  var ColumnBuilder;
9300
9365
  var init_column_builder = __esm(() => {
9301
9366
  init_entity();
@@ -9355,13 +9420,13 @@ var init_column_builder = __esm(() => {
9355
9420
  };
9356
9421
  });
9357
9422
 
9358
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/table.utils.js
9423
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/table.utils.js
9359
9424
  var TableName;
9360
9425
  var init_table_utils = __esm(() => {
9361
9426
  TableName = Symbol.for("drizzle:Name");
9362
9427
  });
9363
9428
 
9364
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/foreign-keys.js
9429
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/foreign-keys.js
9365
9430
  var ForeignKeyBuilder, ForeignKey;
9366
9431
  var init_foreign_keys = __esm(() => {
9367
9432
  init_entity();
@@ -9419,13 +9484,13 @@ var init_foreign_keys = __esm(() => {
9419
9484
  };
9420
9485
  });
9421
9486
 
9422
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/tracing-utils.js
9487
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/tracing-utils.js
9423
9488
  function iife(fn, ...args) {
9424
9489
  return fn(...args);
9425
9490
  }
9426
9491
  var init_tracing_utils = () => {};
9427
9492
 
9428
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/unique-constraint.js
9493
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/unique-constraint.js
9429
9494
  function uniqueKeyName(table, columns) {
9430
9495
  return `${table[TableName]}_${columns.join("_")}_unique`;
9431
9496
  }
@@ -9433,7 +9498,7 @@ var init_unique_constraint = __esm(() => {
9433
9498
  init_table_utils();
9434
9499
  });
9435
9500
 
9436
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/utils/array.js
9501
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/utils/array.js
9437
9502
  function parsePgArrayValue(arrayString, startFrom, inQuotes) {
9438
9503
  for (let i = startFrom;i < arrayString.length; i++) {
9439
9504
  const char = arrayString[i];
@@ -9510,7 +9575,7 @@ function makePgArray(array) {
9510
9575
  }
9511
9576
  var init_array = () => {};
9512
9577
 
9513
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/common.js
9578
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/common.js
9514
9579
  var PgColumnBuilder, PgColumn, ExtraConfigColumn, IndexedColumn, PgArrayBuilder, PgArray;
9515
9580
  var init_common = __esm(() => {
9516
9581
  init_column_builder();
@@ -9663,7 +9728,7 @@ var init_common = __esm(() => {
9663
9728
  };
9664
9729
  });
9665
9730
 
9666
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/enum.js
9731
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/enum.js
9667
9732
  function isPgEnum(obj) {
9668
9733
  return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
9669
9734
  }
@@ -9708,7 +9773,7 @@ var init_enum = __esm(() => {
9708
9773
  };
9709
9774
  });
9710
9775
 
9711
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/subquery.js
9776
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/subquery.js
9712
9777
  var Subquery;
9713
9778
  var init_subquery = __esm(() => {
9714
9779
  init_entity();
@@ -9726,11 +9791,11 @@ var init_subquery = __esm(() => {
9726
9791
  };
9727
9792
  });
9728
9793
 
9729
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/version.js
9794
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/version.js
9730
9795
  var version = "0.39.3";
9731
9796
  var init_version = () => {};
9732
9797
 
9733
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/tracing.js
9798
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/tracing.js
9734
9799
  var otel, rawTracer, tracer;
9735
9800
  var init_tracing = __esm(() => {
9736
9801
  init_tracing_utils();
@@ -9760,13 +9825,13 @@ var init_tracing = __esm(() => {
9760
9825
  };
9761
9826
  });
9762
9827
 
9763
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/view-common.js
9828
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/view-common.js
9764
9829
  var ViewBaseConfig;
9765
9830
  var init_view_common = __esm(() => {
9766
9831
  ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
9767
9832
  });
9768
9833
 
9769
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/table.js
9834
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/table.js
9770
9835
  function getTableName(table) {
9771
9836
  return table[TableName];
9772
9837
  }
@@ -9811,7 +9876,7 @@ var init_table = __esm(() => {
9811
9876
  };
9812
9877
  });
9813
9878
 
9814
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/sql/sql.js
9879
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/sql/sql.js
9815
9880
  function isSQLWrapper(value) {
9816
9881
  return value !== null && value !== undefined && typeof value.getSQL === "function";
9817
9882
  }
@@ -10168,7 +10233,7 @@ var init_sql = __esm(() => {
10168
10233
  };
10169
10234
  });
10170
10235
 
10171
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/alias.js
10236
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/alias.js
10172
10237
  var ColumnAliasProxyHandler, TableAliasProxyHandler;
10173
10238
  var init_alias = __esm(() => {
10174
10239
  init_column();
@@ -10230,7 +10295,7 @@ var init_alias = __esm(() => {
10230
10295
  };
10231
10296
  });
10232
10297
 
10233
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/selection-proxy.js
10298
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/selection-proxy.js
10234
10299
  var SelectionProxyHandler;
10235
10300
  var init_selection_proxy = __esm(() => {
10236
10301
  init_alias();
@@ -10291,7 +10356,7 @@ var init_selection_proxy = __esm(() => {
10291
10356
  };
10292
10357
  });
10293
10358
 
10294
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/utils.js
10359
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/utils.js
10295
10360
  function orderSelectedFields(fields, pathPrefix) {
10296
10361
  return Object.entries(fields).reduce((result, [name, field]) => {
10297
10362
  if (typeof name !== "string") {
@@ -10348,13 +10413,13 @@ var init_utils = __esm(() => {
10348
10413
  init_view_common();
10349
10414
  });
10350
10415
 
10351
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/query-builders/delete.js
10416
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/query-builders/delete.js
10352
10417
  var init_delete = () => {};
10353
10418
 
10354
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/errors.js
10419
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/errors.js
10355
10420
  var init_errors3 = () => {};
10356
10421
 
10357
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/int.common.js
10422
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/int.common.js
10358
10423
  var PgIntColumnBaseBuilder;
10359
10424
  var init_int_common = __esm(() => {
10360
10425
  init_entity();
@@ -10398,7 +10463,7 @@ var init_int_common = __esm(() => {
10398
10463
  };
10399
10464
  });
10400
10465
 
10401
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/bigint.js
10466
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/bigint.js
10402
10467
  function bigint(a, b2) {
10403
10468
  const { name, config } = getColumnNameAndConfig(a, b2);
10404
10469
  if (config.mode === "number") {
@@ -10453,7 +10518,7 @@ var init_bigint = __esm(() => {
10453
10518
  };
10454
10519
  });
10455
10520
 
10456
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/bigserial.js
10521
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/bigserial.js
10457
10522
  function bigserial(a, b2) {
10458
10523
  const { name, config } = getColumnNameAndConfig(a, b2);
10459
10524
  if (config.mode === "number") {
@@ -10510,7 +10575,7 @@ var init_bigserial = __esm(() => {
10510
10575
  };
10511
10576
  });
10512
10577
 
10513
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/boolean.js
10578
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/boolean.js
10514
10579
  function boolean(name) {
10515
10580
  return new PgBooleanBuilder(name ?? "");
10516
10581
  }
@@ -10535,7 +10600,7 @@ var init_boolean = __esm(() => {
10535
10600
  };
10536
10601
  });
10537
10602
 
10538
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/char.js
10603
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/char.js
10539
10604
  function char(a, b2 = {}) {
10540
10605
  const { name, config } = getColumnNameAndConfig(a, b2);
10541
10606
  return new PgCharBuilder(name, config);
@@ -10566,7 +10631,7 @@ var init_char = __esm(() => {
10566
10631
  };
10567
10632
  });
10568
10633
 
10569
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/cidr.js
10634
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/cidr.js
10570
10635
  function cidr(name) {
10571
10636
  return new PgCidrBuilder(name ?? "");
10572
10637
  }
@@ -10591,7 +10656,7 @@ var init_cidr = __esm(() => {
10591
10656
  };
10592
10657
  });
10593
10658
 
10594
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/custom.js
10659
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/custom.js
10595
10660
  function customType(customTypeParams) {
10596
10661
  return (a, b2) => {
10597
10662
  const { name, config } = getColumnNameAndConfig(a, b2);
@@ -10637,7 +10702,7 @@ var init_custom = __esm(() => {
10637
10702
  };
10638
10703
  });
10639
10704
 
10640
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/date.common.js
10705
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/date.common.js
10641
10706
  var PgDateColumnBaseBuilder;
10642
10707
  var init_date_common = __esm(() => {
10643
10708
  init_entity();
@@ -10651,7 +10716,7 @@ var init_date_common = __esm(() => {
10651
10716
  };
10652
10717
  });
10653
10718
 
10654
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/date.js
10719
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/date.js
10655
10720
  function date(a, b2) {
10656
10721
  const { name, config } = getColumnNameAndConfig(a, b2);
10657
10722
  if (config?.mode === "date") {
@@ -10703,7 +10768,7 @@ var init_date = __esm(() => {
10703
10768
  };
10704
10769
  });
10705
10770
 
10706
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/double-precision.js
10771
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/double-precision.js
10707
10772
  function doublePrecision(name) {
10708
10773
  return new PgDoublePrecisionBuilder(name ?? "");
10709
10774
  }
@@ -10734,7 +10799,7 @@ var init_double_precision = __esm(() => {
10734
10799
  };
10735
10800
  });
10736
10801
 
10737
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/inet.js
10802
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/inet.js
10738
10803
  function inet(name) {
10739
10804
  return new PgInetBuilder(name ?? "");
10740
10805
  }
@@ -10759,7 +10824,7 @@ var init_inet = __esm(() => {
10759
10824
  };
10760
10825
  });
10761
10826
 
10762
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/integer.js
10827
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/integer.js
10763
10828
  function integer(name) {
10764
10829
  return new PgIntegerBuilder(name ?? "");
10765
10830
  }
@@ -10791,7 +10856,7 @@ var init_integer = __esm(() => {
10791
10856
  };
10792
10857
  });
10793
10858
 
10794
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/interval.js
10859
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/interval.js
10795
10860
  function interval(a, b2 = {}) {
10796
10861
  const { name, config } = getColumnNameAndConfig(a, b2);
10797
10862
  return new PgIntervalBuilder(name, config);
@@ -10823,7 +10888,7 @@ var init_interval = __esm(() => {
10823
10888
  };
10824
10889
  });
10825
10890
 
10826
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/json.js
10891
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/json.js
10827
10892
  function json(name) {
10828
10893
  return new PgJsonBuilder(name ?? "");
10829
10894
  }
@@ -10864,7 +10929,7 @@ var init_json = __esm(() => {
10864
10929
  };
10865
10930
  });
10866
10931
 
10867
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/jsonb.js
10932
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/jsonb.js
10868
10933
  function jsonb(name) {
10869
10934
  return new PgJsonbBuilder(name ?? "");
10870
10935
  }
@@ -10905,7 +10970,7 @@ var init_jsonb = __esm(() => {
10905
10970
  };
10906
10971
  });
10907
10972
 
10908
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/line.js
10973
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/line.js
10909
10974
  function line(a, b2) {
10910
10975
  const { name, config } = getColumnNameAndConfig(a, b2);
10911
10976
  if (!config?.mode || config.mode === "tuple") {
@@ -10964,7 +11029,7 @@ var init_line = __esm(() => {
10964
11029
  };
10965
11030
  });
10966
11031
 
10967
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/macaddr.js
11032
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/macaddr.js
10968
11033
  function macaddr(name) {
10969
11034
  return new PgMacaddrBuilder(name ?? "");
10970
11035
  }
@@ -10989,7 +11054,7 @@ var init_macaddr = __esm(() => {
10989
11054
  };
10990
11055
  });
10991
11056
 
10992
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/macaddr8.js
11057
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/macaddr8.js
10993
11058
  function macaddr8(name) {
10994
11059
  return new PgMacaddr8Builder(name ?? "");
10995
11060
  }
@@ -11014,7 +11079,7 @@ var init_macaddr8 = __esm(() => {
11014
11079
  };
11015
11080
  });
11016
11081
 
11017
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/numeric.js
11082
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/numeric.js
11018
11083
  function numeric(a, b2) {
11019
11084
  const { name, config } = getColumnNameAndConfig(a, b2);
11020
11085
  return new PgNumericBuilder(name, config?.precision, config?.scale);
@@ -11056,7 +11121,7 @@ var init_numeric = __esm(() => {
11056
11121
  };
11057
11122
  });
11058
11123
 
11059
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/point.js
11124
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/point.js
11060
11125
  function point(a, b2) {
11061
11126
  const { name, config } = getColumnNameAndConfig(a, b2);
11062
11127
  if (!config?.mode || config.mode === "tuple") {
@@ -11121,7 +11186,7 @@ var init_point = __esm(() => {
11121
11186
  };
11122
11187
  });
11123
11188
 
11124
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/postgis_extension/utils.js
11189
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/postgis_extension/utils.js
11125
11190
  function hexToBytes(hex) {
11126
11191
  const bytes = [];
11127
11192
  for (let c = 0;c < hex.length; c += 2) {
@@ -11161,7 +11226,7 @@ function parseEWKB(hex) {
11161
11226
  }
11162
11227
  var init_utils2 = () => {};
11163
11228
 
11164
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/postgis_extension/geometry.js
11229
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/postgis_extension/geometry.js
11165
11230
  function geometry(a, b2) {
11166
11231
  const { name, config } = getColumnNameAndConfig(a, b2);
11167
11232
  if (!config?.mode || config.mode === "tuple") {
@@ -11220,7 +11285,7 @@ var init_geometry = __esm(() => {
11220
11285
  };
11221
11286
  });
11222
11287
 
11223
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/real.js
11288
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/real.js
11224
11289
  function real(name) {
11225
11290
  return new PgRealBuilder(name ?? "");
11226
11291
  }
@@ -11255,7 +11320,7 @@ var init_real = __esm(() => {
11255
11320
  };
11256
11321
  });
11257
11322
 
11258
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/serial.js
11323
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/serial.js
11259
11324
  function serial(name) {
11260
11325
  return new PgSerialBuilder(name ?? "");
11261
11326
  }
@@ -11282,7 +11347,7 @@ var init_serial = __esm(() => {
11282
11347
  };
11283
11348
  });
11284
11349
 
11285
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/smallint.js
11350
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/smallint.js
11286
11351
  function smallint(name) {
11287
11352
  return new PgSmallIntBuilder(name ?? "");
11288
11353
  }
@@ -11314,7 +11379,7 @@ var init_smallint = __esm(() => {
11314
11379
  };
11315
11380
  });
11316
11381
 
11317
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/smallserial.js
11382
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/smallserial.js
11318
11383
  function smallserial(name) {
11319
11384
  return new PgSmallSerialBuilder(name ?? "");
11320
11385
  }
@@ -11341,7 +11406,7 @@ var init_smallserial = __esm(() => {
11341
11406
  };
11342
11407
  });
11343
11408
 
11344
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/text.js
11409
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/text.js
11345
11410
  function text(a, b2 = {}) {
11346
11411
  const { name, config } = getColumnNameAndConfig(a, b2);
11347
11412
  return new PgTextBuilder(name, config);
@@ -11370,7 +11435,7 @@ var init_text = __esm(() => {
11370
11435
  };
11371
11436
  });
11372
11437
 
11373
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/time.js
11438
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/time.js
11374
11439
  function time(a, b2 = {}) {
11375
11440
  const { name, config } = getColumnNameAndConfig(a, b2);
11376
11441
  return new PgTimeBuilder(name, config.withTimezone ?? false, config.precision);
@@ -11410,7 +11475,7 @@ var init_time = __esm(() => {
11410
11475
  };
11411
11476
  });
11412
11477
 
11413
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/timestamp.js
11478
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/timestamp.js
11414
11479
  function timestamp(a, b2 = {}) {
11415
11480
  const { name, config } = getColumnNameAndConfig(a, b2);
11416
11481
  if (config?.mode === "string") {
@@ -11482,7 +11547,7 @@ var init_timestamp = __esm(() => {
11482
11547
  };
11483
11548
  });
11484
11549
 
11485
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/uuid.js
11550
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/uuid.js
11486
11551
  function uuid(name) {
11487
11552
  return new PgUUIDBuilder(name ?? "");
11488
11553
  }
@@ -11511,7 +11576,7 @@ var init_uuid = __esm(() => {
11511
11576
  };
11512
11577
  });
11513
11578
 
11514
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/varchar.js
11579
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/varchar.js
11515
11580
  function varchar(a, b2 = {}) {
11516
11581
  const { name, config } = getColumnNameAndConfig(a, b2);
11517
11582
  return new PgVarcharBuilder(name, config);
@@ -11542,7 +11607,7 @@ var init_varchar = __esm(() => {
11542
11607
  };
11543
11608
  });
11544
11609
 
11545
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/vector_extension/bit.js
11610
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/vector_extension/bit.js
11546
11611
  function bit(a, b2) {
11547
11612
  const { name, config } = getColumnNameAndConfig(a, b2);
11548
11613
  return new PgBinaryVectorBuilder(name, config);
@@ -11571,7 +11636,7 @@ var init_bit = __esm(() => {
11571
11636
  };
11572
11637
  });
11573
11638
 
11574
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/vector_extension/halfvec.js
11639
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/vector_extension/halfvec.js
11575
11640
  function halfvec(a, b2) {
11576
11641
  const { name, config } = getColumnNameAndConfig(a, b2);
11577
11642
  return new PgHalfVectorBuilder(name, config);
@@ -11606,7 +11671,7 @@ var init_halfvec = __esm(() => {
11606
11671
  };
11607
11672
  });
11608
11673
 
11609
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/vector_extension/sparsevec.js
11674
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/vector_extension/sparsevec.js
11610
11675
  function sparsevec(a, b2) {
11611
11676
  const { name, config } = getColumnNameAndConfig(a, b2);
11612
11677
  return new PgSparseVectorBuilder(name, config);
@@ -11635,7 +11700,7 @@ var init_sparsevec = __esm(() => {
11635
11700
  };
11636
11701
  });
11637
11702
 
11638
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/vector_extension/vector.js
11703
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/vector_extension/vector.js
11639
11704
  function vector(a, b2) {
11640
11705
  const { name, config } = getColumnNameAndConfig(a, b2);
11641
11706
  return new PgVectorBuilder(name, config);
@@ -11670,7 +11735,7 @@ var init_vector = __esm(() => {
11670
11735
  };
11671
11736
  });
11672
11737
 
11673
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/index.js
11738
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/index.js
11674
11739
  var init_columns = __esm(() => {
11675
11740
  init_bigint();
11676
11741
  init_bigserial();
@@ -11709,7 +11774,7 @@ var init_columns = __esm(() => {
11709
11774
  init_vector();
11710
11775
  });
11711
11776
 
11712
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/columns/all.js
11777
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/columns/all.js
11713
11778
  function getPgColumnBuilders() {
11714
11779
  return {
11715
11780
  bigint,
@@ -11781,7 +11846,7 @@ var init_all = __esm(() => {
11781
11846
  init_vector();
11782
11847
  });
11783
11848
 
11784
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/table.js
11849
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/table.js
11785
11850
  function pgTableWithSchema(name, columns, extraConfig, schema, baseName = name) {
11786
11851
  const rawTable = new PgTable(name, schema, baseName);
11787
11852
  const parsedColumns = typeof columns === "function" ? columns(getPgColumnBuilders()) : columns;
@@ -11832,7 +11897,7 @@ var init_table2 = __esm(() => {
11832
11897
  };
11833
11898
  });
11834
11899
 
11835
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/primary-keys.js
11900
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/primary-keys.js
11836
11901
  function primaryKey(...config) {
11837
11902
  if (config[0].columns) {
11838
11903
  return new PrimaryKeyBuilder(config[0].columns, config[0].name);
@@ -11870,44 +11935,49 @@ var init_primary_keys = __esm(() => {
11870
11935
  };
11871
11936
  });
11872
11937
 
11873
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/sql/expressions/conditions.js
11938
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/sql/expressions/conditions.js
11874
11939
  var init_conditions = () => {};
11875
11940
 
11876
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/sql/expressions/select.js
11877
- var init_select = () => {};
11941
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/sql/expressions/select.js
11942
+ function desc(column) {
11943
+ return sql`${column} desc`;
11944
+ }
11945
+ var init_select = __esm(() => {
11946
+ init_sql();
11947
+ });
11878
11948
 
11879
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/sql/expressions/index.js
11949
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/sql/expressions/index.js
11880
11950
  var init_expressions = __esm(() => {
11881
11951
  init_conditions();
11882
11952
  init_select();
11883
11953
  });
11884
11954
 
11885
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/relations.js
11955
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/relations.js
11886
11956
  var init_relations = () => {};
11887
11957
 
11888
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/sql/functions/aggregate.js
11958
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/sql/functions/aggregate.js
11889
11959
  var init_aggregate = () => {};
11890
11960
 
11891
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/sql/functions/vector.js
11961
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/sql/functions/vector.js
11892
11962
  var init_vector2 = () => {};
11893
11963
 
11894
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/sql/functions/index.js
11964
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/sql/functions/index.js
11895
11965
  var init_functions = __esm(() => {
11896
11966
  init_aggregate();
11897
11967
  init_vector2();
11898
11968
  });
11899
11969
 
11900
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/sql/index.js
11970
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/sql/index.js
11901
11971
  var init_sql2 = __esm(() => {
11902
11972
  init_expressions();
11903
11973
  init_functions();
11904
11974
  init_sql();
11905
11975
  });
11906
11976
 
11907
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/dialect.js
11977
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/dialect.js
11908
11978
  var init_dialect = () => {};
11909
11979
 
11910
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/query-builders/query-builder.js
11980
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/query-builders/query-builder.js
11911
11981
  var TypedQueryBuilder;
11912
11982
  var init_query_builder = __esm(() => {
11913
11983
  init_entity();
@@ -11919,7 +11989,7 @@ var init_query_builder = __esm(() => {
11919
11989
  };
11920
11990
  });
11921
11991
 
11922
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/query-builders/select.js
11992
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/query-builders/select.js
11923
11993
  function createSetOperator(type, isAll) {
11924
11994
  return (leftSelect, rightSelect, ...restSelects) => {
11925
11995
  const setOperators = [rightSelect, ...restSelects].map((select3) => ({
@@ -12172,16 +12242,16 @@ var init_select2 = __esm(() => {
12172
12242
  exceptAll = createSetOperator("except", true);
12173
12243
  });
12174
12244
 
12175
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/query-builders/query-builder.js
12245
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/query-builders/query-builder.js
12176
12246
  var init_query_builder2 = () => {};
12177
12247
 
12178
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/query-builders/insert.js
12248
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/query-builders/insert.js
12179
12249
  var init_insert = () => {};
12180
12250
 
12181
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.js
12251
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.js
12182
12252
  var init_refresh_materialized_view = () => {};
12183
12253
 
12184
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/query-builders/update.js
12254
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/query-builders/update.js
12185
12255
  var PgUpdateBase;
12186
12256
  var init_update = __esm(() => {
12187
12257
  init_entity();
@@ -12325,7 +12395,7 @@ var init_update = __esm(() => {
12325
12395
  };
12326
12396
  });
12327
12397
 
12328
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/query-builders/index.js
12398
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/query-builders/index.js
12329
12399
  var init_query_builders = __esm(() => {
12330
12400
  init_delete();
12331
12401
  init_insert();
@@ -12335,13 +12405,13 @@ var init_query_builders = __esm(() => {
12335
12405
  init_update();
12336
12406
  });
12337
12407
 
12338
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/db.js
12408
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/db.js
12339
12409
  var init_db = () => {};
12340
12410
 
12341
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/alias.js
12411
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/alias.js
12342
12412
  var init_alias2 = () => {};
12343
12413
 
12344
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/checks.js
12414
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/checks.js
12345
12415
  function check(name, value) {
12346
12416
  return new CheckBuilder(name, value);
12347
12417
  }
@@ -12371,7 +12441,7 @@ var init_checks = __esm(() => {
12371
12441
  };
12372
12442
  });
12373
12443
 
12374
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/indexes.js
12444
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/indexes.js
12375
12445
  function index(name) {
12376
12446
  return new IndexBuilderOn(false, name);
12377
12447
  }
@@ -12460,42 +12530,42 @@ var init_indexes = __esm(() => {
12460
12530
  };
12461
12531
  });
12462
12532
 
12463
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/policies.js
12533
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/policies.js
12464
12534
  var init_policies = () => {};
12465
12535
 
12466
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/roles.js
12536
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/roles.js
12467
12537
  var init_roles = () => {};
12468
12538
 
12469
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/sequence.js
12539
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/sequence.js
12470
12540
  var init_sequence = () => {};
12471
12541
 
12472
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/view-common.js
12542
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/view-common.js
12473
12543
  var PgViewConfig;
12474
12544
  var init_view_common2 = __esm(() => {
12475
12545
  PgViewConfig = Symbol.for("drizzle:PgViewConfig");
12476
12546
  });
12477
12547
 
12478
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/view.js
12548
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/view.js
12479
12549
  var PgMaterializedViewConfig;
12480
12550
  var init_view = __esm(() => {
12481
12551
  PgMaterializedViewConfig = Symbol.for("drizzle:PgMaterializedViewConfig");
12482
12552
  });
12483
12553
 
12484
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/schema.js
12554
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/schema.js
12485
12555
  var init_schema = () => {};
12486
12556
 
12487
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/session.js
12557
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/session.js
12488
12558
  var init_session = () => {};
12489
12559
 
12490
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/utils.js
12560
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/utils.js
12491
12561
  var init_utils3 = () => {};
12492
12562
 
12493
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/utils/index.js
12563
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/utils/index.js
12494
12564
  var init_utils4 = __esm(() => {
12495
12565
  init_array();
12496
12566
  });
12497
12567
 
12498
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/pg-core/index.js
12568
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/pg-core/index.js
12499
12569
  var init_pg_core = __esm(() => {
12500
12570
  init_alias2();
12501
12571
  init_checks();
@@ -12531,6 +12601,7 @@ var init_users = __esm(() => {
12531
12601
  emailVerified: boolean("email_verified").notNull().default(false),
12532
12602
  image: text("image"),
12533
12603
  twoFactorEnabled: boolean("two_factor_enabled").default(false),
12604
+ isSuperadmin: boolean("is_superadmin").notNull().default(false),
12534
12605
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12535
12606
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
12536
12607
  });
@@ -12647,9 +12718,33 @@ var init_triggers = __esm(() => {
12647
12718
  }, (table2) => [index("triggers_automation_idx").on(table2.automationId)]);
12648
12719
  });
12649
12720
 
12721
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/expressions.js
12722
+ var init_expressions2 = __esm(() => {
12723
+ init_expressions();
12724
+ });
12725
+
12726
+ // ../../node_modules/.bun/drizzle-orm@0.39.3+a324ea3b81409b9a/node_modules/drizzle-orm/index.js
12727
+ var init_drizzle_orm = __esm(() => {
12728
+ init_alias();
12729
+ init_column_builder();
12730
+ init_column();
12731
+ init_entity();
12732
+ init_errors3();
12733
+ init_expressions2();
12734
+ init_logger();
12735
+ init_query_promise();
12736
+ init_relations();
12737
+ init_sql2();
12738
+ init_subquery();
12739
+ init_table();
12740
+ init_utils();
12741
+ init_view_common();
12742
+ });
12743
+
12650
12744
  // ../shared/src/db/schema/deployments.ts
12651
12745
  var deploymentStatusEnum, deployments;
12652
12746
  var init_deployments = __esm(() => {
12747
+ init_drizzle_orm();
12653
12748
  init_pg_core();
12654
12749
  init_projects();
12655
12750
  deploymentStatusEnum = pgEnum("deployment_status", [
@@ -12672,10 +12767,11 @@ var init_deployments = __esm(() => {
12672
12767
  activatedAt: timestamp("activated_at", { withTimezone: true }),
12673
12768
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12674
12769
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
12675
- }, (table2) => [
12676
- index("deployments_project_idx").on(table2.projectId),
12677
- index("deployments_project_status_idx").on(table2.projectId, table2.status),
12678
- index("deployments_environment_idx").on(table2.environmentId)
12770
+ }, (table3) => [
12771
+ index("deployments_project_idx").on(table3.projectId),
12772
+ index("deployments_project_status_idx").on(table3.projectId, table3.status),
12773
+ index("deployments_environment_idx").on(table3.environmentId),
12774
+ index("deployments_project_created_idx").on(table3.projectId, desc(table3.createdAt))
12679
12775
  ]);
12680
12776
  });
12681
12777
 
@@ -12720,14 +12816,14 @@ var init_execution_records = __esm(() => {
12720
12816
  replayOverrides: jsonb("replay_overrides").$type(),
12721
12817
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12722
12818
  completedAt: timestamp("completed_at", { withTimezone: true })
12723
- }, (table2) => [
12724
- index("execution_records_automation_idx").on(table2.automationId),
12725
- index("execution_records_deployment_idx").on(table2.deploymentId),
12726
- index("execution_records_status_idx").on(table2.status),
12727
- index("execution_records_trace_idx").on(table2.traceId),
12728
- index("execution_records_created_idx").on(table2.createdAt),
12729
- index("execution_records_automation_created_idx").on(table2.automationId, table2.createdAt),
12730
- index("execution_records_replay_of_idx").on(table2.replayOf)
12819
+ }, (table3) => [
12820
+ index("execution_records_automation_idx").on(table3.automationId),
12821
+ index("execution_records_deployment_idx").on(table3.deploymentId),
12822
+ index("execution_records_status_idx").on(table3.status),
12823
+ index("execution_records_trace_idx").on(table3.traceId),
12824
+ index("execution_records_created_idx").on(table3.createdAt),
12825
+ index("execution_records_automation_created_idx").on(table3.automationId, table3.createdAt),
12826
+ index("execution_records_replay_of_idx").on(table3.replayOf)
12731
12827
  ]);
12732
12828
  });
12733
12829
 
@@ -12751,10 +12847,10 @@ var init_log_entries = __esm(() => {
12751
12847
  level: logLevelEnum("level").notNull(),
12752
12848
  message: text("message").notNull(),
12753
12849
  fields: jsonb("fields")
12754
- }, (table2) => [
12755
- index("log_entries_execution_idx").on(table2.executionId),
12756
- index("log_entries_project_idx").on(table2.projectId),
12757
- index("log_entries_timestamp_idx").on(table2.timestamp)
12850
+ }, (table3) => [
12851
+ index("log_entries_execution_idx").on(table3.executionId),
12852
+ index("log_entries_project_idx").on(table3.projectId),
12853
+ index("log_entries_timestamp_idx").on(table3.timestamp)
12758
12854
  ]);
12759
12855
  });
12760
12856
 
@@ -12772,11 +12868,11 @@ var init_metrics = __esm(() => {
12772
12868
  name: text("name").notNull(),
12773
12869
  value: doublePrecision("value").notNull(),
12774
12870
  tags: jsonb("tags")
12775
- }, (table2) => [
12776
- index("metrics_execution_idx").on(table2.executionId),
12777
- index("metrics_project_idx").on(table2.projectId),
12778
- index("metrics_name_idx").on(table2.name),
12779
- index("metrics_timestamp_idx").on(table2.timestamp)
12871
+ }, (table3) => [
12872
+ index("metrics_execution_idx").on(table3.executionId),
12873
+ index("metrics_project_idx").on(table3.projectId),
12874
+ index("metrics_name_idx").on(table3.name),
12875
+ index("metrics_timestamp_idx").on(table3.timestamp)
12780
12876
  ]);
12781
12877
  });
12782
12878
 
@@ -12797,9 +12893,9 @@ var init_artifacts = __esm(() => {
12797
12893
  storageUrl: text("storage_url").notNull(),
12798
12894
  metadata: jsonb("metadata"),
12799
12895
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
12800
- }, (table2) => [
12801
- index("artifacts_execution_idx").on(table2.executionId),
12802
- index("artifacts_project_idx").on(table2.projectId)
12896
+ }, (table3) => [
12897
+ index("artifacts_execution_idx").on(table3.executionId),
12898
+ index("artifacts_project_idx").on(table3.projectId)
12803
12899
  ]);
12804
12900
  });
12805
12901
 
@@ -12822,10 +12918,10 @@ var init_secrets2 = __esm(() => {
12822
12918
  nonce: bytea("nonce").notNull(),
12823
12919
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12824
12920
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
12825
- }, (table2) => [
12826
- uniqueIndex("secrets_project_name_idx").on(table2.projectId, table2.name),
12827
- index("secrets_project_idx").on(table2.projectId),
12828
- index("secrets_environment_idx").on(table2.environmentId)
12921
+ }, (table3) => [
12922
+ uniqueIndex("secrets_project_name_idx").on(table3.projectId, table3.name),
12923
+ index("secrets_project_idx").on(table3.projectId),
12924
+ index("secrets_environment_idx").on(table3.environmentId)
12829
12925
  ]);
12830
12926
  });
12831
12927
 
@@ -12847,11 +12943,11 @@ var init_api_keys = __esm(() => {
12847
12943
  lastUsedAt: timestamp("last_used_at", { withTimezone: true }),
12848
12944
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12849
12945
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
12850
- }, (table2) => [
12851
- index("api_keys_org_idx").on(table2.organizationId),
12852
- index("api_keys_user_idx").on(table2.userId),
12853
- index("api_keys_prefix_idx").on(table2.keyPrefix),
12854
- uniqueIndex("api_keys_hash_idx").on(table2.keyHash)
12946
+ }, (table3) => [
12947
+ index("api_keys_org_idx").on(table3.organizationId),
12948
+ index("api_keys_user_idx").on(table3.userId),
12949
+ index("api_keys_prefix_idx").on(table3.keyPrefix),
12950
+ uniqueIndex("api_keys_hash_idx").on(table3.keyHash)
12855
12951
  ]);
12856
12952
  });
12857
12953
 
@@ -12876,10 +12972,10 @@ var init_endpoint_keys = __esm(() => {
12876
12972
  revokedAt: timestamp("revoked_at", { withTimezone: true }),
12877
12973
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12878
12974
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
12879
- }, (table2) => [
12880
- index("endpoint_keys_project_idx").on(table2.projectId),
12881
- index("endpoint_keys_prefix_idx").on(table2.keyPrefix),
12882
- uniqueIndex("endpoint_keys_hash_idx").on(table2.keyHash)
12975
+ }, (table3) => [
12976
+ index("endpoint_keys_project_idx").on(table3.projectId),
12977
+ index("endpoint_keys_prefix_idx").on(table3.keyPrefix),
12978
+ uniqueIndex("endpoint_keys_hash_idx").on(table3.keyHash)
12883
12979
  ]);
12884
12980
  });
12885
12981
 
@@ -12901,11 +12997,11 @@ var init_audit_log = __esm(() => {
12901
12997
  metadata: jsonb("metadata"),
12902
12998
  ipAddress: text("ip_address"),
12903
12999
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
12904
- }, (table2) => [
12905
- index("audit_log_org_idx").on(table2.organizationId),
12906
- index("audit_log_user_idx").on(table2.userId),
12907
- index("audit_log_action_idx").on(table2.action),
12908
- index("audit_log_created_idx").on(table2.createdAt)
13000
+ }, (table3) => [
13001
+ index("audit_log_org_idx").on(table3.organizationId),
13002
+ index("audit_log_user_idx").on(table3.userId),
13003
+ index("audit_log_action_idx").on(table3.action),
13004
+ index("audit_log_created_idx").on(table3.createdAt)
12909
13005
  ]);
12910
13006
  });
12911
13007
 
@@ -12942,40 +13038,17 @@ var init_metering_rollups = __esm(() => {
12942
13038
  }).notNull().default(0),
12943
13039
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12944
13040
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
12945
- }, (table2) => [
12946
- uniqueIndex("metering_rollups_natural_key").on(table2.automationId, table2.granularity, table2.bucketStart),
12947
- index("metering_rollups_org_idx").on(table2.organizationId),
12948
- index("metering_rollups_project_idx").on(table2.projectId),
12949
- index("metering_rollups_automation_idx").on(table2.automationId),
12950
- index("metering_rollups_granularity_idx").on(table2.granularity),
12951
- index("metering_rollups_bucket_idx").on(table2.bucketStart),
12952
- index("metering_rollups_project_bucket_idx").on(table2.projectId, table2.granularity, table2.bucketStart)
13041
+ }, (table3) => [
13042
+ uniqueIndex("metering_rollups_natural_key").on(table3.automationId, table3.granularity, table3.bucketStart),
13043
+ index("metering_rollups_org_idx").on(table3.organizationId),
13044
+ index("metering_rollups_project_idx").on(table3.projectId),
13045
+ index("metering_rollups_automation_idx").on(table3.automationId),
13046
+ index("metering_rollups_granularity_idx").on(table3.granularity),
13047
+ index("metering_rollups_bucket_idx").on(table3.bucketStart),
13048
+ index("metering_rollups_project_bucket_idx").on(table3.projectId, table3.granularity, table3.bucketStart)
12953
13049
  ]);
12954
13050
  });
12955
13051
 
12956
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/expressions.js
12957
- var init_expressions2 = __esm(() => {
12958
- init_expressions();
12959
- });
12960
-
12961
- // ../../node_modules/.bun/drizzle-orm@0.39.3+7505325c0ab11955/node_modules/drizzle-orm/index.js
12962
- var init_drizzle_orm = __esm(() => {
12963
- init_alias();
12964
- init_column_builder();
12965
- init_column();
12966
- init_entity();
12967
- init_errors3();
12968
- init_expressions2();
12969
- init_logger();
12970
- init_query_promise();
12971
- init_relations();
12972
- init_sql2();
12973
- init_subquery();
12974
- init_table();
12975
- init_utils();
12976
- init_view_common();
12977
- });
12978
-
12979
13052
  // ../shared/src/db/schema/credit-ledger.ts
12980
13053
  var creditLedgerEntryTypeEnum, creditLedger;
12981
13054
  var init_credit_ledger = __esm(() => {
@@ -13591,6 +13664,56 @@ var init_auth = __esm(() => {
13591
13664
  });
13592
13665
  });
13593
13666
 
13667
+ // ../shared/src/db/schema/admin-sessions.ts
13668
+ var bytea2, adminSessions;
13669
+ var init_admin_sessions = __esm(() => {
13670
+ init_pg_core();
13671
+ init_users();
13672
+ bytea2 = customType({
13673
+ dataType() {
13674
+ return "bytea";
13675
+ }
13676
+ });
13677
+ adminSessions = pgTable("admin_sessions", {
13678
+ id: uuid("id").defaultRandom().primaryKey(),
13679
+ sessionTokenHash: bytea2("session_token_hash").notNull(),
13680
+ userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
13681
+ issuedAt: timestamp("issued_at", { withTimezone: true }).notNull().defaultNow(),
13682
+ lastActivityAt: timestamp("last_activity_at", { withTimezone: true }).notNull().defaultNow(),
13683
+ stepUpVerifiedAt: timestamp("step_up_verified_at", { withTimezone: true }),
13684
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
13685
+ }, (table3) => [
13686
+ uniqueIndex("admin_sessions_token_idx").on(table3.sessionTokenHash),
13687
+ index("admin_sessions_user_idx").on(table3.userId)
13688
+ ]);
13689
+ });
13690
+
13691
+ // ../shared/src/db/schema/admin-audit-log.ts
13692
+ var adminAuditLog;
13693
+ var init_admin_audit_log = __esm(() => {
13694
+ init_pg_core();
13695
+ init_users();
13696
+ adminAuditLog = pgTable("admin_audit_log", {
13697
+ id: uuid("id").defaultRandom().primaryKey(),
13698
+ userId: uuid("user_id").references(() => users.id, {
13699
+ onDelete: "set null"
13700
+ }),
13701
+ actorLabel: text("actor_label").notNull(),
13702
+ route: text("route").notNull(),
13703
+ method: text("method").notNull(),
13704
+ queryParams: jsonb("query_params").$type(),
13705
+ statusCode: integer("status_code").notNull(),
13706
+ ipAddress: text("ip_address"),
13707
+ userAgent: text("user_agent"),
13708
+ actionPayload: jsonb("action_payload").$type(),
13709
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
13710
+ }, (table3) => [
13711
+ index("admin_audit_log_user_idx").on(table3.userId),
13712
+ index("admin_audit_log_created_idx").on(table3.createdAt),
13713
+ index("admin_audit_log_route_idx").on(table3.route)
13714
+ ]);
13715
+ });
13716
+
13594
13717
  // ../shared/src/db/schema/index.ts
13595
13718
  var init_schema2 = __esm(() => {
13596
13719
  init_users();
@@ -13625,6 +13748,8 @@ var init_schema2 = __esm(() => {
13625
13748
  init_healing();
13626
13749
  init_playground();
13627
13750
  init_auth();
13751
+ init_admin_sessions();
13752
+ init_admin_audit_log();
13628
13753
  });
13629
13754
 
13630
13755
  // ../shared/src/db/index.ts
@@ -13639,6 +13764,22 @@ var init_url_validator = __esm(() => {
13639
13764
  BLOCKED_HOSTNAMES = new Set(["localhost", "metadata.google.internal"]);
13640
13765
  });
13641
13766
 
13767
+ // ../shared/src/crypto/session-token.ts
13768
+ var init_session_token = () => {};
13769
+
13770
+ // ../shared/src/http/parse-body.ts
13771
+ function parseHttpBody(body, _headers) {
13772
+ if (typeof body !== "string")
13773
+ return body;
13774
+ if (body === "")
13775
+ return null;
13776
+ try {
13777
+ return JSON.parse(body);
13778
+ } catch {
13779
+ return body;
13780
+ }
13781
+ }
13782
+
13642
13783
  // ../shared/src/index.ts
13643
13784
  var init_src2 = __esm(() => {
13644
13785
  init_billing();
@@ -13650,6 +13791,7 @@ var init_src2 = __esm(() => {
13650
13791
  init_marketplace();
13651
13792
  init_db2();
13652
13793
  init_url_validator();
13794
+ init_session_token();
13653
13795
  });
13654
13796
 
13655
13797
  // src/lib/manifest.ts
@@ -13748,9 +13890,7 @@ function registerConfigCommand(program2) {
13748
13890
  setManifestValue(opts.dir, path, parsed);
13749
13891
  output.success({ path, value: parsed });
13750
13892
  } catch (err) {
13751
- if (err instanceof Error) {
13752
- output.error("CONFIG_SET_FAILED", err.message);
13753
- }
13893
+ reportApiError(output, err, "CONFIG_SET_FAILED");
13754
13894
  }
13755
13895
  });
13756
13896
  config.command("get <path>").description("Get a config value using dot-path notation").option("--dir <path>", "Project directory", ".").action((path, opts, cmd) => {
@@ -13763,15 +13903,14 @@ function registerConfigCommand(program2) {
13763
13903
  }
13764
13904
  output.success({ path, value });
13765
13905
  } catch (err) {
13766
- if (err instanceof Error) {
13767
- output.error("CONFIG_GET_FAILED", err.message);
13768
- }
13906
+ reportApiError(output, err, "CONFIG_GET_FAILED");
13769
13907
  }
13770
13908
  });
13771
13909
  }
13772
13910
  var init_config = __esm(() => {
13773
13911
  init_src3();
13774
13912
  init_manifest2();
13913
+ init_handle_api_error();
13775
13914
  });
13776
13915
 
13777
13916
  // src/commands/status.ts
@@ -13793,9 +13932,7 @@ function registerStatusCommand(program2) {
13793
13932
  const project = await client.get(`/api/v1/orgs/${opts.org}/projects/${opts.project}`);
13794
13933
  output.success(project);
13795
13934
  } catch (err) {
13796
- if (err instanceof Error) {
13797
- output.error("STATUS_FAILED", err.message);
13798
- }
13935
+ reportApiError(output, err, "STATUS_FAILED");
13799
13936
  }
13800
13937
  });
13801
13938
  }
@@ -13803,6 +13940,7 @@ var init_status = __esm(() => {
13803
13940
  init_src3();
13804
13941
  init_api_client();
13805
13942
  init_config_store();
13943
+ init_handle_api_error();
13806
13944
  });
13807
13945
 
13808
13946
  // src/commands/audit.ts
@@ -13834,9 +13972,7 @@ function registerAuditCommand(program2) {
13834
13972
  e.userId
13835
13973
  ]));
13836
13974
  } catch (err) {
13837
- if (err instanceof Error) {
13838
- output.error("AUDIT_FAILED", err.message);
13839
- }
13975
+ reportApiError(output, err, "AUDIT_FAILED");
13840
13976
  }
13841
13977
  });
13842
13978
  }
@@ -13844,6 +13980,7 @@ var init_audit = __esm(() => {
13844
13980
  init_src3();
13845
13981
  init_api_client();
13846
13982
  init_config_store();
13983
+ init_handle_api_error();
13847
13984
  });
13848
13985
 
13849
13986
  // src/lib/manifest-generator.ts
@@ -14094,11 +14231,7 @@ Live at:`);
14094
14231
  }
14095
14232
  }
14096
14233
  } catch (err) {
14097
- if (err instanceof ApiClientError) {
14098
- output.error(err.code, err.message, err.suggestion);
14099
- } else if (err instanceof Error) {
14100
- output.error("DEPLOY_FAILED", err.message);
14101
- }
14234
+ reportApiError(output, err, "DEPLOY_FAILED");
14102
14235
  }
14103
14236
  });
14104
14237
  }
@@ -14108,6 +14241,7 @@ var init_deploy = __esm(() => {
14108
14241
  init_config_store();
14109
14242
  init_bundler();
14110
14243
  init_manifest2();
14244
+ init_handle_api_error();
14111
14245
  });
14112
14246
 
14113
14247
  // src/commands/rollback.ts
@@ -14137,11 +14271,7 @@ function registerRollbackCommand(program2) {
14137
14271
  activatedAt: deployment.activatedAt
14138
14272
  });
14139
14273
  } catch (err) {
14140
- if (err instanceof ApiClientError) {
14141
- output.error(err.code, err.message, err.suggestion);
14142
- } else if (err instanceof Error) {
14143
- output.error("ROLLBACK_FAILED", err.message);
14144
- }
14274
+ reportApiError(output, err, "ROLLBACK_FAILED");
14145
14275
  }
14146
14276
  });
14147
14277
  }
@@ -14149,6 +14279,7 @@ var init_rollback = __esm(() => {
14149
14279
  init_src3();
14150
14280
  init_api_client();
14151
14281
  init_config_store();
14282
+ init_handle_api_error();
14152
14283
  });
14153
14284
 
14154
14285
  // src/commands/openapi.ts
@@ -14170,9 +14301,7 @@ function registerOpenApiCommand(program2) {
14170
14301
  const spec = await client.get(`/api/v1/projects/${opts.project}/openapi/_dura/openapi.json`, { projectId: opts.project });
14171
14302
  output.success(spec);
14172
14303
  } catch (err) {
14173
- if (err instanceof Error) {
14174
- output.error("OPENAPI_FAILED", err.message);
14175
- }
14304
+ reportApiError(output, err, "OPENAPI_FAILED");
14176
14305
  }
14177
14306
  });
14178
14307
  }
@@ -14180,6 +14309,7 @@ var init_openapi = __esm(() => {
14180
14309
  init_src3();
14181
14310
  init_api_client();
14182
14311
  init_config_store();
14312
+ init_handle_api_error();
14183
14313
  });
14184
14314
 
14185
14315
  // src/commands/logs.ts
@@ -14443,11 +14573,7 @@ Error: ${name}
14443
14573
  ]));
14444
14574
  }
14445
14575
  } catch (err) {
14446
- if (err instanceof ApiClientError) {
14447
- output.error(err.code, err.message, err.suggestion);
14448
- } else if (err instanceof Error) {
14449
- output.error("LOGS_FAILED", err.message);
14450
- }
14576
+ reportApiError(output, err, "LOGS_FAILED");
14451
14577
  }
14452
14578
  });
14453
14579
  }
@@ -14456,6 +14582,7 @@ var init_logs = __esm(() => {
14456
14582
  init_api_client();
14457
14583
  init_config_store();
14458
14584
  init_project_id();
14585
+ init_handle_api_error();
14459
14586
  });
14460
14587
 
14461
14588
  // src/commands/run.ts
@@ -14489,11 +14616,7 @@ function registerRunCommand(program2) {
14489
14616
  });
14490
14617
  output.success(result);
14491
14618
  } catch (err) {
14492
- if (err instanceof ApiClientError) {
14493
- output.error(err.code, err.message, err.suggestion);
14494
- } else if (err instanceof Error) {
14495
- output.error("RUN_FAILED", err.message);
14496
- }
14619
+ reportApiError(output, err, "RUN_FAILED");
14497
14620
  }
14498
14621
  });
14499
14622
  }
@@ -14501,6 +14624,7 @@ var init_run = __esm(() => {
14501
14624
  init_src3();
14502
14625
  init_api_client();
14503
14626
  init_config_store();
14627
+ init_handle_api_error();
14504
14628
  });
14505
14629
 
14506
14630
  // src/commands/schedule.ts
@@ -14536,11 +14660,7 @@ function registerScheduleCommand(program2) {
14536
14660
  });
14537
14661
  output.success(result);
14538
14662
  } catch (err) {
14539
- if (err instanceof ApiClientError) {
14540
- output.error(err.code, err.message, err.suggestion);
14541
- } else if (err instanceof Error) {
14542
- output.error("SCHEDULE_FAILED", err.message);
14543
- }
14663
+ reportApiError(output, err, "SCHEDULE_FAILED");
14544
14664
  }
14545
14665
  });
14546
14666
  schedule.command("list").description("List cron schedules for a project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -14559,11 +14679,7 @@ function registerScheduleCommand(program2) {
14559
14679
  const result = await auth.client.get(`/api/v1/projects/${projectId}/schedules`);
14560
14680
  output.success(result);
14561
14681
  } catch (err) {
14562
- if (err instanceof ApiClientError) {
14563
- output.error(err.code, err.message, err.suggestion);
14564
- } else if (err instanceof Error) {
14565
- output.error("SCHEDULE_LIST_FAILED", err.message);
14566
- }
14682
+ reportApiError(output, err, "SCHEDULE_LIST_FAILED");
14567
14683
  }
14568
14684
  });
14569
14685
  schedule.command("remove <schedule-id>").description("Remove a cron schedule").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").option("--confirm", "Confirm the destructive delete operation").action(async (scheduleId, opts, cmd) => {
@@ -14586,11 +14702,7 @@ function registerScheduleCommand(program2) {
14586
14702
  const result = await auth.client.delete(`/api/v1/projects/${projectId}/schedules/${scheduleId}`);
14587
14703
  output.success(result);
14588
14704
  } catch (err) {
14589
- if (err instanceof ApiClientError) {
14590
- output.error(err.code, err.message, err.suggestion);
14591
- } else if (err instanceof Error) {
14592
- output.error("SCHEDULE_REMOVE_FAILED", err.message);
14593
- }
14705
+ reportApiError(output, err, "SCHEDULE_REMOVE_FAILED");
14594
14706
  }
14595
14707
  });
14596
14708
  }
@@ -14599,6 +14711,115 @@ var init_schedule = __esm(() => {
14599
14711
  init_api_client();
14600
14712
  init_config_store();
14601
14713
  init_project_id();
14714
+ init_handle_api_error();
14715
+ });
14716
+
14717
+ // src/lib/dev-trust.ts
14718
+ import { existsSync as existsSync6, mkdirSync as mkdirSync4, writeFileSync as writeFileSync6 } from "node:fs";
14719
+ import { dirname, join as join7 } from "node:path";
14720
+ function hasStoredCredentials() {
14721
+ try {
14722
+ const cfg = readConfig();
14723
+ const apiKey = typeof cfg.apiKey === "string" ? cfg.apiKey : "";
14724
+ const authToken = typeof cfg.authToken === "string" ? cfg.authToken : "";
14725
+ return apiKey.length > 0 || authToken.length > 0;
14726
+ } catch {
14727
+ return false;
14728
+ }
14729
+ }
14730
+ function hasProjectTrustMarker(projectDir) {
14731
+ return existsSync6(join7(projectDir, TRUST_MARKER_RELATIVE_PATH));
14732
+ }
14733
+ function grantProjectTrust(projectDir) {
14734
+ const markerPath = join7(projectDir, TRUST_MARKER_RELATIVE_PATH);
14735
+ const dir = dirname(markerPath);
14736
+ if (!existsSync6(dir)) {
14737
+ mkdirSync4(dir, { recursive: true });
14738
+ }
14739
+ const note = [
14740
+ "# dura dev trust marker",
14741
+ "#",
14742
+ "# This file records that you accepted the risk of running `dura dev`",
14743
+ "# in-process with access to your local credentials (see GH #118).",
14744
+ "# Delete this file to revoke trust for this project.",
14745
+ `# Granted: ${new Date().toISOString()}`,
14746
+ ""
14747
+ ].join(`
14748
+ `);
14749
+ writeFileSync6(markerPath, note, { mode: 384 });
14750
+ }
14751
+ function isEnvTruthy(val) {
14752
+ if (!val)
14753
+ return false;
14754
+ const v = val.trim().toLowerCase();
14755
+ return v === "1" || v === "true" || v === "yes";
14756
+ }
14757
+ function evaluateDevTrust(input) {
14758
+ if (!hasStoredCredentials()) {
14759
+ return { allow: true, warn: false, reason: "NO_CREDENTIALS" };
14760
+ }
14761
+ if (input.trustFlag) {
14762
+ grantProjectTrust(input.projectDir);
14763
+ return { allow: true, warn: true, reason: "TRUST_GRANTED_FLAG" };
14764
+ }
14765
+ if (isEnvTruthy(input.trustEnv)) {
14766
+ grantProjectTrust(input.projectDir);
14767
+ return { allow: true, warn: true, reason: "TRUST_GRANTED_ENV" };
14768
+ }
14769
+ if (hasProjectTrustMarker(input.projectDir)) {
14770
+ return { allow: true, warn: true, reason: "MARKER_PRESENT" };
14771
+ }
14772
+ return { allow: false, warn: true, reason: "TRUST_REQUIRED" };
14773
+ }
14774
+ function renderTrustWarning(opts) {
14775
+ const color = opts?.color ?? process.stderr.isTTY ?? false;
14776
+ const red = color ? RED : "";
14777
+ const yellow = color ? YELLOW : "";
14778
+ const bold = color ? BOLD : "";
14779
+ const reset2 = color ? RESET : "";
14780
+ const lines = [
14781
+ `${red}${bold}╔══════════════════════════════════════════════════════════════════════╗${reset2}`,
14782
+ `${red}${bold}║ SECURITY WARNING — dura dev runs automation code with your local ║${reset2}`,
14783
+ `${red}${bold}║ filesystem privileges. A malicious npm dependency in your handler ║${reset2}`,
14784
+ `${red}${bold}║ graph can read ~/.dura/config (your API key), ~/.ssh, ~/.aws, etc. ║${reset2}`,
14785
+ `${red}${bold}║ See https://github.com/dura-run/dura-run/issues/118 for details. ║${reset2}`,
14786
+ `${red}${bold}╚══════════════════════════════════════════════════════════════════════╝${reset2}`,
14787
+ `${yellow} Tip: audit your dependencies before trusting this project.${reset2}`,
14788
+ ""
14789
+ ];
14790
+ return lines.join(`
14791
+ `);
14792
+ }
14793
+ function renderTrustRefusal() {
14794
+ const color = process.stderr.isTTY ?? false;
14795
+ const yellow = color ? YELLOW : "";
14796
+ const bold = color ? BOLD : "";
14797
+ const reset2 = color ? RESET : "";
14798
+ return [
14799
+ `${bold}${yellow}dura dev refuses to start.${reset2}`,
14800
+ "",
14801
+ "Your local machine has stored dura credentials, and `dura dev` currently",
14802
+ "loads your handler code with full filesystem access. Until we ship an",
14803
+ "isolated-vm sandbox for local dev, you must explicitly accept this risk.",
14804
+ "",
14805
+ "To proceed, pick ONE of:",
14806
+ "",
14807
+ " 1. Run with --trust (one-time; remembered via .dura/dev-trust):",
14808
+ " dura dev --trust",
14809
+ "",
14810
+ " 2. Set the env var (same effect):",
14811
+ " DURA_DEV_TRUST=1 dura dev",
14812
+ "",
14813
+ " 3. Log out first (removes the credentials being protected):",
14814
+ " dura logout",
14815
+ ""
14816
+ ].join(`
14817
+ `);
14818
+ }
14819
+ var TRUST_MARKER_RELATIVE_PATH, RED = "\x1B[31m", YELLOW = "\x1B[33m", BOLD = "\x1B[1m", RESET = "\x1B[0m";
14820
+ var init_dev_trust = __esm(() => {
14821
+ init_config_store();
14822
+ TRUST_MARKER_RELATIVE_PATH = join7(".dura", "dev-trust");
14602
14823
  });
14603
14824
 
14604
14825
  // src/dev/server.ts
@@ -14680,7 +14901,7 @@ function createDevServer(options) {
14680
14901
  headers,
14681
14902
  query,
14682
14903
  params: match.params,
14683
- body
14904
+ body: parseHttpBody(body, headers)
14684
14905
  });
14685
14906
  return options.onRequest(match.route, duraReq);
14686
14907
  }
@@ -14711,12 +14932,7 @@ function createDevServer(options) {
14711
14932
  resolve3(null);
14712
14933
  return;
14713
14934
  }
14714
- const raw = Buffer.concat(chunks).toString("utf-8");
14715
- try {
14716
- resolve3(JSON.parse(raw));
14717
- } catch {
14718
- resolve3(raw);
14719
- }
14935
+ resolve3(Buffer.concat(chunks).toString("utf-8"));
14720
14936
  });
14721
14937
  });
14722
14938
  }
@@ -14788,6 +15004,7 @@ function createDevServer(options) {
14788
15004
  }
14789
15005
  var CORS_HEADERS;
14790
15006
  var init_server = __esm(() => {
15007
+ init_src2();
14791
15008
  CORS_HEADERS = {
14792
15009
  "access-control-allow-origin": "*",
14793
15010
  "access-control-allow-methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS",
@@ -15131,8 +15348,8 @@ __export(exports_file_watcher, {
15131
15348
  resolveAffectedAutomation: () => resolveAffectedAutomation,
15132
15349
  createFileWatcher: () => createFileWatcher
15133
15350
  });
15134
- import { watch, existsSync as existsSync6 } from "node:fs";
15135
- import { join as join7 } from "node:path";
15351
+ import { watch, existsSync as existsSync7 } from "node:fs";
15352
+ import { join as join8 } from "node:path";
15136
15353
  function resolveAffectedAutomation(manifest, changedPath) {
15137
15354
  const normalized = changedPath.replace(/\\/g, "/");
15138
15355
  const directMatch = manifest.automations.filter((a) => a.entrypoint.replace(/\\/g, "/") === normalized);
@@ -15151,7 +15368,7 @@ function createFileWatcher(options) {
15151
15368
  return;
15152
15369
  if (!/\.(ts|tsx|js|jsx|mjs|mts)$/.test(filename))
15153
15370
  return;
15154
- const relativePath = join7(dir, filename).replace(/\\/g, "/");
15371
+ const relativePath = join8(dir, filename).replace(/\\/g, "/");
15155
15372
  const existing = debounceTimers.get(relativePath);
15156
15373
  if (existing) {
15157
15374
  clearTimeout(existing);
@@ -15167,8 +15384,8 @@ function createFileWatcher(options) {
15167
15384
  return;
15168
15385
  watching = true;
15169
15386
  for (const dir of watchDirs) {
15170
- const fullDir = join7(projectDir, dir);
15171
- if (!existsSync6(fullDir))
15387
+ const fullDir = join8(projectDir, dir);
15388
+ if (!existsSync7(fullDir))
15172
15389
  continue;
15173
15390
  try {
15174
15391
  const fsWatcher = watch(fullDir, { recursive: true }, (_eventType, filename) => {
@@ -15249,9 +15466,22 @@ function extractCronTriggers(manifest) {
15249
15466
  return entries;
15250
15467
  }
15251
15468
  function registerDevCommand(program2) {
15252
- program2.command("dev").description("Start the local development server with hot-reload").option("--dir <path>", "Project directory", ".").option("--port <port>", "Dev server port", "3000").action(async (opts, cmd) => {
15469
+ program2.command("dev").description("Start the local development server with hot-reload").option("--dir <path>", "Project directory", ".").option("--port <port>", "Dev server port", "3000").option("--trust", "Acknowledge that `dura dev` runs user code with your local filesystem privileges (see GH #118). Required when credentials are stored locally; remembered in .dura/dev-trust.").action(async (opts, cmd) => {
15253
15470
  const output = getOutput(cmd);
15254
15471
  const projectDir = opts.dir ?? ".";
15472
+ const trustDecision = evaluateDevTrust({
15473
+ projectDir,
15474
+ trustFlag: opts.trust === true,
15475
+ trustEnv: process.env["DURA_DEV_TRUST"]
15476
+ });
15477
+ if (trustDecision.warn) {
15478
+ process.stderr.write(renderTrustWarning());
15479
+ }
15480
+ if (!trustDecision.allow) {
15481
+ process.stderr.write(renderTrustRefusal());
15482
+ output.error("DEV_TRUST_REQUIRED", "dura dev refused to start — credentials are stored locally and trust was not granted.", "Re-run with --trust or set DURA_DEV_TRUST=1 after reviewing the warning above.");
15483
+ return;
15484
+ }
15255
15485
  const port = parseInt(opts.port ?? "3000", 10);
15256
15486
  if (isNaN(port) || port < 1 || port > 65535) {
15257
15487
  output.error("INVALID_PORT", `Invalid port: "${opts.port}". Must be a number between 1 and 65535.`);
@@ -15267,11 +15497,11 @@ function registerDevCommand(program2) {
15267
15497
  }
15268
15498
  throw err;
15269
15499
  }
15270
- const { existsSync: existsSync7, readFileSync: readFileSync6 } = await import("node:fs");
15271
- const { join: join8 } = await import("node:path");
15272
- const envPath = join8(projectDir, ".env.local");
15500
+ const { existsSync: existsSync8, readFileSync: readFileSync6 } = await import("node:fs");
15501
+ const { join: join9 } = await import("node:path");
15502
+ const envPath = join9(projectDir, ".env.local");
15273
15503
  let secrets2 = {};
15274
- if (existsSync7(envPath)) {
15504
+ if (existsSync8(envPath)) {
15275
15505
  const content = readFileSync6(envPath, "utf-8");
15276
15506
  secrets2 = parseEnvFile(content);
15277
15507
  output.info(`Loaded ${Object.keys(secrets2).length} secret(s) from .env.local`);
@@ -15375,6 +15605,7 @@ Shutting down...`);
15375
15605
  var init_dev = __esm(() => {
15376
15606
  init_src3();
15377
15607
  init_manifest2();
15608
+ init_dev_trust();
15378
15609
  });
15379
15610
  // src/snapshot/comparator.ts
15380
15611
  function getAtPath(obj, path) {
@@ -15622,14 +15853,14 @@ var init_comparator = __esm(() => {
15622
15853
 
15623
15854
  // src/snapshot/file-manager.ts
15624
15855
  import {
15625
- existsSync as existsSync7,
15626
- mkdirSync as mkdirSync4,
15856
+ existsSync as existsSync8,
15857
+ mkdirSync as mkdirSync5,
15627
15858
  readFileSync as readFileSync6,
15628
- writeFileSync as writeFileSync6,
15859
+ writeFileSync as writeFileSync7,
15629
15860
  readdirSync as readdirSync2,
15630
15861
  unlinkSync
15631
15862
  } from "node:fs";
15632
- import { join as join8 } from "node:path";
15863
+ import { join as join9 } from "node:path";
15633
15864
  function automationNameToFileName(automationName) {
15634
15865
  return automationName.replace(/\//g, "-") + ".snap.json";
15635
15866
  }
@@ -15640,19 +15871,19 @@ function fileNameToAutomationName(fileName) {
15640
15871
  class SnapshotFileManager {
15641
15872
  snapshotsDir;
15642
15873
  constructor(projectDir) {
15643
- this.snapshotsDir = join8(projectDir, SNAPSHOTS_DIR);
15874
+ this.snapshotsDir = join9(projectDir, SNAPSHOTS_DIR);
15644
15875
  }
15645
15876
  filePath(automationName) {
15646
- return join8(this.snapshotsDir, automationNameToFileName(automationName));
15877
+ return join9(this.snapshotsDir, automationNameToFileName(automationName));
15647
15878
  }
15648
15879
  ensureDir() {
15649
- if (!existsSync7(this.snapshotsDir)) {
15650
- mkdirSync4(this.snapshotsDir, { recursive: true });
15880
+ if (!existsSync8(this.snapshotsDir)) {
15881
+ mkdirSync5(this.snapshotsDir, { recursive: true });
15651
15882
  }
15652
15883
  }
15653
15884
  read(automationName) {
15654
15885
  const path = this.filePath(automationName);
15655
- if (!existsSync7(path))
15886
+ if (!existsSync8(path))
15656
15887
  return null;
15657
15888
  try {
15658
15889
  const raw = readFileSync6(path, "utf-8");
@@ -15664,7 +15895,7 @@ class SnapshotFileManager {
15664
15895
  write(automationName, snapshotFile) {
15665
15896
  this.ensureDir();
15666
15897
  const path = this.filePath(automationName);
15667
- writeFileSync6(path, JSON.stringify(snapshotFile, null, 2) + `
15898
+ writeFileSync7(path, JSON.stringify(snapshotFile, null, 2) + `
15668
15899
  `, "utf-8");
15669
15900
  }
15670
15901
  updateSnapshot(automationName, snapshot) {
@@ -15685,12 +15916,12 @@ class SnapshotFileManager {
15685
15916
  });
15686
15917
  }
15687
15918
  listAutomationNames() {
15688
- if (!existsSync7(this.snapshotsDir))
15919
+ if (!existsSync8(this.snapshotsDir))
15689
15920
  return [];
15690
15921
  const files = readdirSync2(this.snapshotsDir).filter((f) => f.endsWith(".snap.json"));
15691
15922
  const names = [];
15692
15923
  for (const file of files) {
15693
- const path = join8(this.snapshotsDir, file);
15924
+ const path = join9(this.snapshotsDir, file);
15694
15925
  try {
15695
15926
  const raw = readFileSync6(path, "utf-8");
15696
15927
  const parsed = JSON.parse(raw);
@@ -15703,7 +15934,7 @@ class SnapshotFileManager {
15703
15934
  }
15704
15935
  delete(automationName) {
15705
15936
  const path = this.filePath(automationName);
15706
- if (existsSync7(path)) {
15937
+ if (existsSync8(path)) {
15707
15938
  unlinkSync(path);
15708
15939
  }
15709
15940
  }
@@ -15712,15 +15943,15 @@ var SNAPSHOTS_DIR = "__snapshots__";
15712
15943
  var init_file_manager = () => {};
15713
15944
 
15714
15945
  // src/snapshot/config-reader.ts
15715
- import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
15716
- import { join as join9 } from "node:path";
15946
+ import { existsSync as existsSync9, readFileSync as readFileSync7 } from "node:fs";
15947
+ import { join as join10 } from "node:path";
15717
15948
  function readSnapshotConfig(projectDir) {
15718
- const durajsonPath = join9(projectDir, "dura.json");
15719
- const testjsonPath = join9(projectDir, "dura.test.json");
15949
+ const durajsonPath = join10(projectDir, "dura.json");
15950
+ const testjsonPath = join10(projectDir, "dura.test.json");
15720
15951
  let fromDuraJson = {};
15721
15952
  let fromTestJson = {};
15722
15953
  let mocks;
15723
- if (existsSync8(durajsonPath)) {
15954
+ if (existsSync9(durajsonPath)) {
15724
15955
  try {
15725
15956
  const raw = JSON.parse(readFileSync7(durajsonPath, "utf-8"));
15726
15957
  if (raw["snapshots"] && typeof raw["snapshots"] === "object" && !Array.isArray(raw["snapshots"])) {
@@ -15728,7 +15959,7 @@ function readSnapshotConfig(projectDir) {
15728
15959
  }
15729
15960
  } catch {}
15730
15961
  }
15731
- if (existsSync8(testjsonPath)) {
15962
+ if (existsSync9(testjsonPath)) {
15732
15963
  try {
15733
15964
  const raw = JSON.parse(readFileSync7(testjsonPath, "utf-8"));
15734
15965
  if (raw["snapshots"] && typeof raw["snapshots"] === "object" && !Array.isArray(raw["snapshots"])) {
@@ -16328,9 +16559,7 @@ Add this TXT record to your DNS:
16328
16559
  Then run: dura domains verify ${result.id} --project ${projectId}`);
16329
16560
  }
16330
16561
  } catch (err) {
16331
- if (err instanceof Error) {
16332
- output.error("DOMAIN_ADD_FAILED", err.message);
16333
- }
16562
+ reportApiError(output, err, "DOMAIN_ADD_FAILED");
16334
16563
  }
16335
16564
  });
16336
16565
  domains.command("list").description("List custom domains").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -16348,9 +16577,7 @@ Then run: dura domains verify ${result.id} --project ${projectId}`);
16348
16577
  d.createdAt
16349
16578
  ]));
16350
16579
  } catch (err) {
16351
- if (err instanceof Error) {
16352
- output.error("DOMAIN_LIST_FAILED", err.message);
16353
- }
16580
+ reportApiError(output, err, "DOMAIN_LIST_FAILED");
16354
16581
  }
16355
16582
  });
16356
16583
  domains.command("remove <domainId>").description("Remove a custom domain").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Confirm this destructive operation").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (domainId, opts, cmd) => {
@@ -16367,9 +16594,7 @@ Then run: dura domains verify ${result.id} --project ${projectId}`);
16367
16594
  await client.delete(`/api/v1/projects/${projectId}/domains/${domainId}`);
16368
16595
  output.success({ deleted: true, domainId });
16369
16596
  } catch (err) {
16370
- if (err instanceof Error) {
16371
- output.error("DOMAIN_REMOVE_FAILED", err.message);
16372
- }
16597
+ reportApiError(output, err, "DOMAIN_REMOVE_FAILED");
16373
16598
  }
16374
16599
  });
16375
16600
  domains.command("verify <domainId>").description("Verify a domain's DNS TXT record").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (domainId, opts, cmd) => {
@@ -16382,9 +16607,7 @@ Then run: dura domains verify ${result.id} --project ${projectId}`);
16382
16607
  const result = await client.post(`/api/v1/projects/${projectId}/domains/${domainId}/verify`, {});
16383
16608
  output.success(result);
16384
16609
  } catch (err) {
16385
- if (err instanceof Error) {
16386
- output.error("DOMAIN_VERIFY_FAILED", err.message);
16387
- }
16610
+ reportApiError(output, err, "DOMAIN_VERIFY_FAILED");
16388
16611
  }
16389
16612
  });
16390
16613
  }
@@ -16393,6 +16616,7 @@ var init_domains = __esm(() => {
16393
16616
  init_api_client();
16394
16617
  init_config_store();
16395
16618
  init_project_id();
16619
+ init_handle_api_error();
16396
16620
  });
16397
16621
 
16398
16622
  // src/commands/endpoint-keys.ts
@@ -16432,9 +16656,7 @@ function registerEndpointKeysCommand(program2) {
16432
16656
  output.warn("Save the key now — it will not be shown again.");
16433
16657
  }
16434
16658
  } catch (err) {
16435
- if (err instanceof Error) {
16436
- output.error("ENDPOINT_KEY_CREATE_FAILED", err.message);
16437
- }
16659
+ reportApiError(output, err, "ENDPOINT_KEY_CREATE_FAILED");
16438
16660
  }
16439
16661
  });
16440
16662
  keys.command("list").description("List endpoint keys for a project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -16454,9 +16676,7 @@ function registerEndpointKeysCommand(program2) {
16454
16676
  k.createdAt
16455
16677
  ]));
16456
16678
  } catch (err) {
16457
- if (err instanceof Error) {
16458
- output.error("ENDPOINT_KEY_LIST_FAILED", err.message);
16459
- }
16679
+ reportApiError(output, err, "ENDPOINT_KEY_LIST_FAILED");
16460
16680
  }
16461
16681
  });
16462
16682
  keys.command("revoke <keyId>").description("Revoke an endpoint key").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Confirm this destructive operation").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (keyId, opts, cmd) => {
@@ -16473,9 +16693,7 @@ function registerEndpointKeysCommand(program2) {
16473
16693
  await client.post(`/api/v1/projects/${projectId}/endpoint-keys/${keyId}/revoke`, {});
16474
16694
  output.success({ revoked: true, keyId });
16475
16695
  } catch (err) {
16476
- if (err instanceof Error) {
16477
- output.error("ENDPOINT_KEY_REVOKE_FAILED", err.message);
16478
- }
16696
+ reportApiError(output, err, "ENDPOINT_KEY_REVOKE_FAILED");
16479
16697
  }
16480
16698
  });
16481
16699
  }
@@ -16484,6 +16702,81 @@ var init_endpoint_keys2 = __esm(() => {
16484
16702
  init_api_client();
16485
16703
  init_config_store();
16486
16704
  init_project_id();
16705
+ init_handle_api_error();
16706
+ });
16707
+
16708
+ // src/commands/events.ts
16709
+ var exports_events = {};
16710
+ __export(exports_events, {
16711
+ resolvePayload: () => resolvePayload,
16712
+ registerEventsCommand: () => registerEventsCommand
16713
+ });
16714
+ import { readFileSync as readFileSync8 } from "node:fs";
16715
+ function resolvePayload(opts) {
16716
+ if (opts.payload !== undefined && opts.payloadFile !== undefined) {
16717
+ throw new Error("Use either --payload or --payload-file, not both");
16718
+ }
16719
+ if (opts.payload === undefined && opts.payloadFile === undefined) {
16720
+ throw new Error("--payload or --payload-file is required");
16721
+ }
16722
+ const raw = opts.payload !== undefined ? opts.payload : readFileSync8(opts.payloadFile, "utf-8");
16723
+ try {
16724
+ return JSON.parse(raw);
16725
+ } catch (err) {
16726
+ throw new Error(`Invalid JSON in payload: ${err.message}`);
16727
+ }
16728
+ }
16729
+ function registerEventsCommand(program2) {
16730
+ const events = program2.command("events").description("Emit and inspect project events");
16731
+ events.command("emit <source>").description("Emit an event to all matching event triggers").option("--payload <json>", "Inline JSON payload").option("--payload-file <path>", "Path to a JSON file containing the payload").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (source, opts, cmd) => {
16732
+ const output = getOutput(cmd);
16733
+ let payload;
16734
+ try {
16735
+ payload = resolvePayload(opts);
16736
+ } catch (err) {
16737
+ output.error("INVALID_PAYLOAD", err.message);
16738
+ return;
16739
+ }
16740
+ const projectId = resolveProjectId({ project: opts.project });
16741
+ if (!projectId) {
16742
+ output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
16743
+ return;
16744
+ }
16745
+ const token = opts.token || getAuthToken();
16746
+ if (!token) {
16747
+ output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
16748
+ return;
16749
+ }
16750
+ const apiUrl = opts.apiUrl || getApiUrl();
16751
+ const client = new ApiClient(apiUrl, token);
16752
+ try {
16753
+ const result = await client.post(`/api/v1/projects/${projectId}/events`, { source, payload });
16754
+ if (output.isJson()) {
16755
+ output.success(result);
16756
+ return;
16757
+ }
16758
+ if (result.jobs.length === 0) {
16759
+ process.stdout.write(`Event "${source}" emitted — no subscribers matched.
16760
+ `);
16761
+ return;
16762
+ }
16763
+ process.stdout.write(`Event "${source}" emitted — enqueued ${result.jobs.length} execution(s):
16764
+ `);
16765
+ for (const job of result.jobs) {
16766
+ process.stdout.write(` • ${job.automationName} → execution ${job.trigger.executionId}
16767
+ `);
16768
+ }
16769
+ } catch (err) {
16770
+ const e = err;
16771
+ output.error(e.code ?? "EMIT_FAILED", e.message);
16772
+ }
16773
+ });
16774
+ }
16775
+ var init_events = __esm(() => {
16776
+ init_src3();
16777
+ init_api_client();
16778
+ init_config_store();
16779
+ init_project_id();
16487
16780
  });
16488
16781
 
16489
16782
  // src/commands/usage.ts
@@ -16570,11 +16863,7 @@ function registerUsageCommand(program2) {
16570
16863
  browserTime: formatMs(summary.totals.totalBrowserSessionMs)
16571
16864
  });
16572
16865
  } catch (err) {
16573
- if (err instanceof ApiClientError) {
16574
- output.error(err.code, err.message, err.suggestion);
16575
- } else if (err instanceof Error) {
16576
- output.error("USAGE_QUERY_FAILED", err.message);
16577
- }
16866
+ reportApiError(output, err, "USAGE_QUERY_FAILED");
16578
16867
  }
16579
16868
  });
16580
16869
  }
@@ -16582,6 +16871,7 @@ var init_usage = __esm(() => {
16582
16871
  init_src3();
16583
16872
  init_api_client();
16584
16873
  init_config_store();
16874
+ init_handle_api_error();
16585
16875
  });
16586
16876
 
16587
16877
  // src/commands/marketplace.ts
@@ -16619,11 +16909,7 @@ function registerMarketplaceCommand(program2) {
16619
16909
  status: adapter.status
16620
16910
  });
16621
16911
  } catch (err) {
16622
- if (err instanceof ApiClientError) {
16623
- output.error(err.code, err.message, err.suggestion);
16624
- } else if (err instanceof Error) {
16625
- output.error("PUBLISH_FAILED", err.message);
16626
- }
16912
+ reportApiError(output, err, "PUBLISH_FAILED");
16627
16913
  }
16628
16914
  });
16629
16915
  marketplace.command("install").description("Install an adapter into a project").requiredOption("--project <id>", "Project ID").requiredOption("--adapter <id>", "Adapter ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -16644,11 +16930,7 @@ function registerMarketplaceCommand(program2) {
16644
16930
  version: install.adapterVersion
16645
16931
  });
16646
16932
  } catch (err) {
16647
- if (err instanceof ApiClientError) {
16648
- output.error(err.code, err.message, err.suggestion);
16649
- } else if (err instanceof Error) {
16650
- output.error("INSTALL_FAILED", err.message);
16651
- }
16933
+ reportApiError(output, err, "INSTALL_FAILED");
16652
16934
  }
16653
16935
  });
16654
16936
  marketplace.command("list").description("List available adapters").option("--category <cat>", "Filter by category").option("--query <q>", "Search query").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -16684,11 +16966,7 @@ function registerMarketplaceCommand(program2) {
16684
16966
  a.status
16685
16967
  ]));
16686
16968
  } catch (err) {
16687
- if (err instanceof ApiClientError) {
16688
- output.error(err.code, err.message, err.suggestion);
16689
- } else if (err instanceof Error) {
16690
- output.error("LIST_FAILED", err.message);
16691
- }
16969
+ reportApiError(output, err, "LIST_FAILED");
16692
16970
  }
16693
16971
  });
16694
16972
  marketplace.command("uninstall").description("Uninstall an adapter from a project").requiredOption("--project <id>", "Project ID").requiredOption("--adapter <id>", "Adapter ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").option("--confirm", "Confirm the destructive uninstall operation").action(async (opts, cmd) => {
@@ -16708,11 +16986,7 @@ function registerMarketplaceCommand(program2) {
16708
16986
  await client.post(`/api/v1/projects/${opts.project}/adapters/uninstall`, { adapterId: opts.adapter });
16709
16987
  output.success({ uninstalled: true, adapterId: opts.adapter });
16710
16988
  } catch (err) {
16711
- if (err instanceof ApiClientError) {
16712
- output.error(err.code, err.message, err.suggestion);
16713
- } else if (err instanceof Error) {
16714
- output.error("UNINSTALL_FAILED", err.message);
16715
- }
16989
+ reportApiError(output, err, "UNINSTALL_FAILED");
16716
16990
  }
16717
16991
  });
16718
16992
  }
@@ -16720,6 +16994,7 @@ var init_marketplace2 = __esm(() => {
16720
16994
  init_src3();
16721
16995
  init_api_client();
16722
16996
  init_config_store();
16997
+ init_handle_api_error();
16723
16998
  });
16724
16999
 
16725
17000
  // src/commands/export.ts
@@ -16730,19 +17005,19 @@ __export(exports_export, {
16730
17005
  collectExportFiles: () => collectExportFiles
16731
17006
  });
16732
17007
  import {
16733
- existsSync as existsSync9,
16734
- readFileSync as readFileSync8,
17008
+ existsSync as existsSync10,
17009
+ readFileSync as readFileSync9,
16735
17010
  readdirSync as readdirSync3,
16736
17011
  statSync,
16737
- writeFileSync as writeFileSync7
17012
+ writeFileSync as writeFileSync8
16738
17013
  } from "node:fs";
16739
- import { join as join10, relative, resolve as resolve4 } from "node:path";
17014
+ import { join as join11, relative, resolve as resolve4 } from "node:path";
16740
17015
  function collectExportFiles(baseDir, currentDir) {
16741
17016
  const dir = currentDir ?? baseDir;
16742
17017
  const entries = [];
16743
17018
  const items = readdirSync3(dir);
16744
17019
  for (const item of items) {
16745
- const fullPath = join10(dir, item);
17020
+ const fullPath = join11(dir, item);
16746
17021
  const relPath = relative(baseDir, fullPath);
16747
17022
  const stat = statSync(fullPath);
16748
17023
  if (stat.isDirectory()) {
@@ -16751,7 +17026,7 @@ function collectExportFiles(baseDir, currentDir) {
16751
17026
  }
16752
17027
  } else if (stat.isFile()) {
16753
17028
  if (!EXCLUDED_FILES.has(item)) {
16754
- const content = readFileSync8(fullPath, "utf-8");
17029
+ const content = readFileSync9(fullPath, "utf-8");
16755
17030
  entries.push({ relativePath: relPath, content });
16756
17031
  }
16757
17032
  }
@@ -16775,14 +17050,14 @@ function registerExportCommand(program2) {
16775
17050
  program2.command("export").description("Export project source + config into a portable archive").option("--dir <path>", "Project directory", ".").option("--output <path>", "Output file path").action(async (opts, cmd) => {
16776
17051
  const output = getOutput(cmd);
16777
17052
  const projectDir = resolve4(opts.dir ?? ".");
16778
- const manifestPath = join10(projectDir, "dura.json");
16779
- if (!existsSync9(manifestPath)) {
17053
+ const manifestPath = join11(projectDir, "dura.json");
17054
+ if (!existsSync10(manifestPath)) {
16780
17055
  output.error("EXPORT_NO_MANIFEST", "No dura.json found in project directory", "Run this command from a dura project directory or use --dir");
16781
17056
  return;
16782
17057
  }
16783
17058
  let projectName;
16784
17059
  try {
16785
- const manifestContent = readFileSync8(manifestPath, "utf-8");
17060
+ const manifestContent = readFileSync9(manifestPath, "utf-8");
16786
17061
  const manifest = JSON.parse(manifestContent);
16787
17062
  projectName = manifest.name ?? "unnamed-project";
16788
17063
  } catch {
@@ -16796,9 +17071,9 @@ function registerExportCommand(program2) {
16796
17071
  return;
16797
17072
  }
16798
17073
  const archive = createArchive(projectName, files);
16799
- const outputPath = opts.output ?? join10(projectDir, `${projectName}-export.json`);
17074
+ const outputPath = opts.output ?? join11(projectDir, `${projectName}-export.json`);
16800
17075
  try {
16801
- writeFileSync7(outputPath, archive, "utf-8");
17076
+ writeFileSync8(outputPath, archive, "utf-8");
16802
17077
  } catch (err) {
16803
17078
  output.error("EXPORT_FAILED", `Failed to write archive: ${err instanceof Error ? err.message : String(err)}`);
16804
17079
  return;
@@ -16870,11 +17145,7 @@ function registerReplayCommand(program2) {
16870
17145
  const result = await client.post(`/api/v1/projects/${projectId}/executions/${executionId}/replay`, { overrides });
16871
17146
  output.success(result);
16872
17147
  } catch (err) {
16873
- if (err instanceof ApiClientError) {
16874
- output.error(err.code, err.message, err.suggestion);
16875
- } else if (err instanceof Error) {
16876
- output.error("REPLAY_FAILED", err.message);
16877
- }
17148
+ reportApiError(output, err, "REPLAY_FAILED");
16878
17149
  }
16879
17150
  });
16880
17151
  }
@@ -16911,11 +17182,7 @@ function registerReplaysCommand(program2) {
16911
17182
  r.replayOf ?? "-"
16912
17183
  ]));
16913
17184
  } catch (err) {
16914
- if (err instanceof ApiClientError) {
16915
- output.error(err.code, err.message, err.suggestion);
16916
- } else if (err instanceof Error) {
16917
- output.error("REPLAYS_FAILED", err.message);
16918
- }
17185
+ reportApiError(output, err, "REPLAYS_FAILED");
16919
17186
  }
16920
17187
  });
16921
17188
  }
@@ -16924,6 +17191,7 @@ var init_replay = __esm(() => {
16924
17191
  init_api_client();
16925
17192
  init_config_store();
16926
17193
  init_project_id();
17194
+ init_handle_api_error();
16927
17195
  });
16928
17196
 
16929
17197
  // src/commands/kv.ts
@@ -16970,11 +17238,7 @@ function registerKvCommand(program2) {
16970
17238
  }
16971
17239
  output.table(["Key"], keys.map((k) => [k]));
16972
17240
  } catch (err) {
16973
- if (err instanceof ApiClientError) {
16974
- output.error(err.code, err.message, err.suggestion);
16975
- } else if (err instanceof Error) {
16976
- output.error("KV_LIST_FAILED", err.message);
16977
- }
17241
+ reportApiError(output, err, "KV_LIST_FAILED");
16978
17242
  }
16979
17243
  });
16980
17244
  kv.command("get <key>").description("Get the value for a key").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (key, opts, cmd) => {
@@ -16987,11 +17251,7 @@ function registerKvCommand(program2) {
16987
17251
  const result = await client.get(`/api/v1/projects/${projectId}/kv/${encodeURIComponent(key)}`);
16988
17252
  output.success(result);
16989
17253
  } catch (err) {
16990
- if (err instanceof ApiClientError) {
16991
- output.error(err.code, err.message, err.suggestion);
16992
- } else if (err instanceof Error) {
16993
- output.error("KV_GET_FAILED", err.message);
16994
- }
17254
+ reportApiError(output, err, "KV_GET_FAILED");
16995
17255
  }
16996
17256
  });
16997
17257
  kv.command("set <key> <value>").description("Set a value for a key").option("--project <id>", "Project ID (defaults to dura.json)").option("--ttl <seconds>", "Time-to-live in seconds (0 = no expiry)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (key, valueStr, opts, cmd) => {
@@ -17014,11 +17274,7 @@ function registerKvCommand(program2) {
17014
17274
  const result = await client.put(`/api/v1/projects/${projectId}/kv/${encodeURIComponent(key)}`, body);
17015
17275
  output.success(result);
17016
17276
  } catch (err) {
17017
- if (err instanceof ApiClientError) {
17018
- output.error(err.code, err.message, err.suggestion);
17019
- } else if (err instanceof Error) {
17020
- output.error("KV_SET_FAILED", err.message);
17021
- }
17277
+ reportApiError(output, err, "KV_SET_FAILED");
17022
17278
  }
17023
17279
  });
17024
17280
  kv.command("delete <key>").description("Delete a key from the KV namespace").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Required to actually perform the delete").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (key, opts, cmd) => {
@@ -17035,11 +17291,7 @@ function registerKvCommand(program2) {
17035
17291
  await client.delete(`/api/v1/projects/${projectId}/kv/${encodeURIComponent(key)}`);
17036
17292
  output.success({ deleted: true, key });
17037
17293
  } catch (err) {
17038
- if (err instanceof ApiClientError) {
17039
- output.error(err.code, err.message, err.suggestion);
17040
- } else if (err instanceof Error) {
17041
- output.error("KV_DELETE_FAILED", err.message);
17042
- }
17294
+ reportApiError(output, err, "KV_DELETE_FAILED");
17043
17295
  }
17044
17296
  });
17045
17297
  kv.command("flush").description("Remove all keys in the project KV namespace").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Required to actually perform the flush").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -17056,11 +17308,7 @@ function registerKvCommand(program2) {
17056
17308
  await client.delete(`/api/v1/projects/${projectId}/kv`);
17057
17309
  output.success({ flushed: true });
17058
17310
  } catch (err) {
17059
- if (err instanceof ApiClientError) {
17060
- output.error(err.code, err.message, err.suggestion);
17061
- } else if (err instanceof Error) {
17062
- output.error("KV_FLUSH_FAILED", err.message);
17063
- }
17311
+ reportApiError(output, err, "KV_FLUSH_FAILED");
17064
17312
  }
17065
17313
  });
17066
17314
  kv.command("stats").description("Show KV usage statistics for the project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -17073,11 +17321,7 @@ function registerKvCommand(program2) {
17073
17321
  const stats = await client.get(`/api/v1/projects/${projectId}/kv/stats`);
17074
17322
  output.success(stats);
17075
17323
  } catch (err) {
17076
- if (err instanceof ApiClientError) {
17077
- output.error(err.code, err.message, err.suggestion);
17078
- } else if (err instanceof Error) {
17079
- output.error("KV_STATS_FAILED", err.message);
17080
- }
17324
+ reportApiError(output, err, "KV_STATS_FAILED");
17081
17325
  }
17082
17326
  });
17083
17327
  }
@@ -17086,6 +17330,7 @@ var init_kv2 = __esm(() => {
17086
17330
  init_api_client();
17087
17331
  init_config_store();
17088
17332
  init_project_id();
17333
+ init_handle_api_error();
17089
17334
  });
17090
17335
 
17091
17336
  // src/commands/webhook.ts
@@ -17152,9 +17397,7 @@ Webhook relay "${result.name}" created.
17152
17397
  ` + `ID: ${result.id}`);
17153
17398
  }
17154
17399
  } catch (err) {
17155
- if (err instanceof Error) {
17156
- output.error("WEBHOOK_CREATE_FAILED", err.message);
17157
- }
17400
+ reportApiError(output, err, "WEBHOOK_CREATE_FAILED");
17158
17401
  }
17159
17402
  });
17160
17403
  webhook.command("list").description("List webhook relays").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -17177,9 +17420,7 @@ Webhook relay "${result.name}" created.
17177
17420
  ]));
17178
17421
  }
17179
17422
  } catch (err) {
17180
- if (err instanceof Error) {
17181
- output.error("WEBHOOK_LIST_FAILED", err.message);
17182
- }
17423
+ reportApiError(output, err, "WEBHOOK_LIST_FAILED");
17183
17424
  }
17184
17425
  });
17185
17426
  webhook.command("show <nameOrId>").description("Show webhook relay details").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (nameOrId, opts, cmd) => {
@@ -17192,9 +17433,7 @@ Webhook relay "${result.name}" created.
17192
17433
  const result = await client.get(`${webhookBase(opts.project)}/${nameOrId}`);
17193
17434
  output.success(result);
17194
17435
  } catch (err) {
17195
- if (err instanceof Error) {
17196
- output.error("WEBHOOK_SHOW_FAILED", err.message);
17197
- }
17436
+ reportApiError(output, err, "WEBHOOK_SHOW_FAILED");
17198
17437
  }
17199
17438
  });
17200
17439
  webhook.command("update <nameOrId>").description("Update a webhook relay").requiredOption("--project <id>", "Project ID").option("--name <name>", "New relay name").option("--events <events>", "New comma-separated event types").option("--forward <url>", "New destination URL").option("--transform <json>", "New transform template JSON").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (nameOrId, opts, cmd) => {
@@ -17228,9 +17467,7 @@ Webhook relay "${result.name}" created.
17228
17467
  const result = await client.patch(`${webhookBase(opts.project)}/${nameOrId}`, patch);
17229
17468
  output.success(result);
17230
17469
  } catch (err) {
17231
- if (err instanceof Error) {
17232
- output.error("WEBHOOK_UPDATE_FAILED", err.message);
17233
- }
17470
+ reportApiError(output, err, "WEBHOOK_UPDATE_FAILED");
17234
17471
  }
17235
17472
  });
17236
17473
  webhook.command("delete <nameOrId>").description("Delete a webhook relay").requiredOption("--project <id>", "Project ID").option("--confirm", "Confirm this destructive operation").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (nameOrId, opts, cmd) => {
@@ -17247,9 +17484,7 @@ Webhook relay "${result.name}" created.
17247
17484
  await client.delete(`${webhookBase(opts.project)}/${nameOrId}`);
17248
17485
  output.success({ deleted: true, nameOrId });
17249
17486
  } catch (err) {
17250
- if (err instanceof Error) {
17251
- output.error("WEBHOOK_DELETE_FAILED", err.message);
17252
- }
17487
+ reportApiError(output, err, "WEBHOOK_DELETE_FAILED");
17253
17488
  }
17254
17489
  });
17255
17490
  webhook.command("enable <nameOrId>").description("Enable a webhook relay").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (nameOrId, opts, cmd) => {
@@ -17262,9 +17497,7 @@ Webhook relay "${result.name}" created.
17262
17497
  const result = await client.patch(`${webhookBase(opts.project)}/${nameOrId}`, { enabled: true });
17263
17498
  output.success(result);
17264
17499
  } catch (err) {
17265
- if (err instanceof Error) {
17266
- output.error("WEBHOOK_ENABLE_FAILED", err.message);
17267
- }
17500
+ reportApiError(output, err, "WEBHOOK_ENABLE_FAILED");
17268
17501
  }
17269
17502
  });
17270
17503
  webhook.command("disable <nameOrId>").description("Disable a webhook relay").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (nameOrId, opts, cmd) => {
@@ -17277,9 +17510,7 @@ Webhook relay "${result.name}" created.
17277
17510
  const result = await client.patch(`${webhookBase(opts.project)}/${nameOrId}`, { enabled: false });
17278
17511
  output.success(result);
17279
17512
  } catch (err) {
17280
- if (err instanceof Error) {
17281
- output.error("WEBHOOK_DISABLE_FAILED", err.message);
17282
- }
17513
+ reportApiError(output, err, "WEBHOOK_DISABLE_FAILED");
17283
17514
  }
17284
17515
  });
17285
17516
  webhook.command("test <nameOrId>").description("Test a webhook relay with a sample payload").requiredOption("--project <id>", "Project ID").option("--payload <json>", "JSON payload to send", "{}").option("--event <type>", "Event type (sets X-GitHub-Event header for github sources)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (nameOrId, opts, cmd) => {
@@ -17316,9 +17547,7 @@ Webhook relay "${result.name}" created.
17316
17547
  }
17317
17548
  }
17318
17549
  } catch (err) {
17319
- if (err instanceof Error) {
17320
- output.error("WEBHOOK_TEST_FAILED", err.message);
17321
- }
17550
+ reportApiError(output, err, "WEBHOOK_TEST_FAILED");
17322
17551
  }
17323
17552
  });
17324
17553
  webhook.command("deliveries <nameOrId>").description("Show recent deliveries for a webhook relay").requiredOption("--project <id>", "Project ID").option("--last <n>", "Number of recent deliveries to show", "10").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (nameOrId, opts, cmd) => {
@@ -17351,9 +17580,7 @@ Webhook relay "${result.name}" created.
17351
17580
  ]));
17352
17581
  }
17353
17582
  } catch (err) {
17354
- if (err instanceof Error) {
17355
- output.error("WEBHOOK_DELIVERIES_FAILED", err.message);
17356
- }
17583
+ reportApiError(output, err, "WEBHOOK_DELIVERIES_FAILED");
17357
17584
  }
17358
17585
  });
17359
17586
  }
@@ -17361,6 +17588,7 @@ var init_webhook = __esm(() => {
17361
17588
  init_src3();
17362
17589
  init_api_client();
17363
17590
  init_config_store();
17591
+ init_handle_api_error();
17364
17592
  });
17365
17593
 
17366
17594
  // src/commands/template.ts
@@ -17402,11 +17630,7 @@ function registerTemplateCommand(program2) {
17402
17630
  String(t.starCount)
17403
17631
  ]));
17404
17632
  } catch (err) {
17405
- if (err instanceof ApiClientError) {
17406
- output.error(err.code, err.message, err.suggestion);
17407
- } else if (err instanceof Error) {
17408
- output.error("LIST_FAILED", err.message);
17409
- }
17633
+ reportApiError(output, err, "LIST_FAILED");
17410
17634
  }
17411
17635
  });
17412
17636
  const template = program2.command("template").description("Manage project templates");
@@ -17435,11 +17659,7 @@ function registerTemplateCommand(program2) {
17435
17659
  }
17436
17660
  output.success({ slug: t.slug, bundleRef: t.bundleRef });
17437
17661
  } catch (err) {
17438
- if (err instanceof ApiClientError) {
17439
- output.error(err.code, err.message, err.suggestion);
17440
- } else if (err instanceof Error) {
17441
- output.error("SHOW_FAILED", err.message);
17442
- }
17662
+ reportApiError(output, err, "SHOW_FAILED");
17443
17663
  }
17444
17664
  });
17445
17665
  template.command("publish").description("Publish a project as a template").requiredOption("--name <name>", "Template name").requiredOption("--slug <slug>", "Unique slug").requiredOption("--description <desc>", "Short description").requiredOption("--version <ver>", "Semver version (e.g. 1.0.0)").requiredOption("--bundle-ref <ref>", "Bundle storage reference (bucket/key)").option("--category <cat>", "Category", "general").option("--tags <tags>", "Comma-separated tags").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -17471,11 +17691,7 @@ function registerTemplateCommand(program2) {
17471
17691
  status: t.status
17472
17692
  });
17473
17693
  } catch (err) {
17474
- if (err instanceof ApiClientError) {
17475
- output.error(err.code, err.message, err.suggestion);
17476
- } else if (err instanceof Error) {
17477
- output.error("PUBLISH_FAILED", err.message);
17478
- }
17694
+ reportApiError(output, err, "PUBLISH_FAILED");
17479
17695
  }
17480
17696
  });
17481
17697
  program2.command("fork <slug>").description("Fork a template into a new project").requiredOption("--name <name>", "New project name").option("--org <id>", "Organization ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (slug, opts, cmd) => {
@@ -17511,11 +17727,7 @@ Set required secrets: ${result.requiredSecrets.join(", ")}`);
17511
17727
  output.info("Run: dura secrets set <name> <value>");
17512
17728
  }
17513
17729
  } catch (err) {
17514
- if (err instanceof ApiClientError) {
17515
- output.error(err.code, err.message, err.suggestion);
17516
- } else if (err instanceof Error) {
17517
- output.error("FORK_FAILED", err.message);
17518
- }
17730
+ reportApiError(output, err, "FORK_FAILED");
17519
17731
  }
17520
17732
  });
17521
17733
  }
@@ -17523,6 +17735,7 @@ var init_template = __esm(() => {
17523
17735
  init_src3();
17524
17736
  init_api_client();
17525
17737
  init_config_store();
17738
+ init_handle_api_error();
17526
17739
  });
17527
17740
 
17528
17741
  // src/commands/deployments.ts
@@ -17564,11 +17777,7 @@ function registerDeploymentsCommand(program2) {
17564
17777
  }
17565
17778
  output.table(["ID", "Status", "Created At"], deploymentList.map((d) => [d.id, d.status, d.createdAt]));
17566
17779
  } catch (err) {
17567
- if (err instanceof ApiClientError) {
17568
- output.error(err.code, err.message, err.suggestion);
17569
- } else if (err instanceof Error) {
17570
- output.error("DEPLOYMENTS_LIST_FAILED", err.message);
17571
- }
17780
+ reportApiError(output, err, "DEPLOYMENTS_LIST_FAILED");
17572
17781
  }
17573
17782
  });
17574
17783
  deployments2.command("get").description("Show details for a specific deployment").option("--project <id>", "Project ID (defaults to dura.json)").requiredOption("--id <deploymentId>", "Deployment ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -17581,11 +17790,7 @@ function registerDeploymentsCommand(program2) {
17581
17790
  const deployment = await client.get(`/api/v1/projects/${projectId}/deployments/${opts.id}`);
17582
17791
  output.success(deployment);
17583
17792
  } catch (err) {
17584
- if (err instanceof ApiClientError) {
17585
- output.error(err.code, err.message, err.suggestion);
17586
- } else if (err instanceof Error) {
17587
- output.error("DEPLOYMENTS_GET_FAILED", err.message);
17588
- }
17793
+ reportApiError(output, err, "DEPLOYMENTS_GET_FAILED");
17589
17794
  }
17590
17795
  });
17591
17796
  }
@@ -17594,6 +17799,7 @@ var init_deployments2 = __esm(() => {
17594
17799
  init_api_client();
17595
17800
  init_config_store();
17596
17801
  init_project_id();
17802
+ init_handle_api_error();
17597
17803
  });
17598
17804
 
17599
17805
  // src/commands/diagnose.ts
@@ -17703,11 +17909,7 @@ Analyzing execution ${targetExecutionId}...`);
17703
17909
  output.info(formatDiagnosisHuman(diagnosis));
17704
17910
  }
17705
17911
  } catch (err) {
17706
- if (err instanceof ApiClientError) {
17707
- output.error(err.code, err.message, err.suggestion);
17708
- } else if (err instanceof Error) {
17709
- output.error("DIAGNOSE_FAILED", err.message);
17710
- }
17912
+ reportApiError(output, err, "DIAGNOSE_FAILED");
17711
17913
  }
17712
17914
  });
17713
17915
  }
@@ -17716,6 +17918,7 @@ var init_diagnose = __esm(() => {
17716
17918
  init_api_client();
17717
17919
  init_config_store();
17718
17920
  init_project_id();
17921
+ init_handle_api_error();
17719
17922
  });
17720
17923
 
17721
17924
  // src/commands/create.ts
@@ -17725,27 +17928,27 @@ __export(exports_create, {
17725
17928
  registerAddCommand: () => registerAddCommand
17726
17929
  });
17727
17930
  import {
17728
- existsSync as existsSync10,
17729
- mkdirSync as mkdirSync5,
17730
- writeFileSync as writeFileSync8,
17731
- readFileSync as readFileSync9,
17931
+ existsSync as existsSync11,
17932
+ mkdirSync as mkdirSync6,
17933
+ writeFileSync as writeFileSync9,
17934
+ readFileSync as readFileSync10,
17732
17935
  readdirSync as readdirSync4
17733
17936
  } from "node:fs";
17734
- import { join as join11, resolve as resolve5, dirname } from "node:path";
17937
+ import { join as join12, resolve as resolve5, dirname as dirname2 } from "node:path";
17735
17938
  function slugifyDescription(description) {
17736
17939
  return description.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 30).replace(/-+$/, "");
17737
17940
  }
17738
17941
  function getExistingRoutes(projectDir) {
17739
- const routesDir = join11(projectDir, "routes");
17740
- const jobsDir = join11(projectDir, "jobs");
17942
+ const routesDir = join12(projectDir, "routes");
17943
+ const jobsDir = join12(projectDir, "jobs");
17741
17944
  const routes = [];
17742
- if (existsSync10(routesDir)) {
17945
+ if (existsSync11(routesDir)) {
17743
17946
  try {
17744
17947
  const files = readdirSync4(routesDir);
17745
17948
  routes.push(...files.map((f) => `routes/${f}`));
17746
17949
  } catch {}
17747
17950
  }
17748
- if (existsSync10(jobsDir)) {
17951
+ if (existsSync11(jobsDir)) {
17749
17952
  try {
17750
17953
  const files = readdirSync4(jobsDir);
17751
17954
  routes.push(...files.map((f) => `jobs/${f}`));
@@ -17755,12 +17958,12 @@ function getExistingRoutes(projectDir) {
17755
17958
  }
17756
17959
  function writeGeneratedFiles(projectDir, files) {
17757
17960
  for (const file of files) {
17758
- const filePath = join11(projectDir, file.path);
17759
- const dir = dirname(filePath);
17760
- if (!existsSync10(dir)) {
17761
- mkdirSync5(dir, { recursive: true });
17961
+ const filePath = join12(projectDir, file.path);
17962
+ const dir = dirname2(filePath);
17963
+ if (!existsSync11(dir)) {
17964
+ mkdirSync6(dir, { recursive: true });
17762
17965
  }
17763
- writeFileSync8(filePath, file.content, "utf-8");
17966
+ writeFileSync9(filePath, file.content, "utf-8");
17764
17967
  }
17765
17968
  }
17766
17969
  async function confirm(question) {
@@ -17789,8 +17992,8 @@ function registerCreateCommand(program2) {
17789
17992
  }
17790
17993
  const projectName = opts.name || slugifyDescription(description);
17791
17994
  const parentDir = opts.dir ? resolve5(opts.dir) : process.cwd();
17792
- const projectDir = join11(parentDir, projectName);
17793
- if (existsSync10(projectDir)) {
17995
+ const projectDir = join12(parentDir, projectName);
17996
+ if (existsSync11(projectDir)) {
17794
17997
  output.error("DIRECTORY_EXISTS", `Directory "${projectName}" already exists`, "Choose a different name with --name or remove the existing directory");
17795
17998
  return;
17796
17999
  }
@@ -17801,11 +18004,7 @@ function registerCreateCommand(program2) {
17801
18004
  try {
17802
18005
  generateResult = await client.post(`/api/v1/projects/${projectId}/ai/generate`, { description });
17803
18006
  } catch (err) {
17804
- if (err instanceof ApiClientError) {
17805
- output.error(err.code, err.message, err.suggestion);
17806
- } else if (err instanceof Error) {
17807
- output.error("GENERATE_FAILED", err.message);
17808
- }
18007
+ reportApiError(output, err, "GENERATE_FAILED");
17809
18008
  return;
17810
18009
  }
17811
18010
  output.info(`Generated ${generateResult.files.length} file(s): ${generateResult.files.map((f) => f.path).join(", ")}`);
@@ -17819,8 +18018,8 @@ function registerCreateCommand(program2) {
17819
18018
  return;
17820
18019
  }
17821
18020
  }
17822
- mkdirSync5(join11(projectDir, "routes"), { recursive: true });
17823
- mkdirSync5(join11(projectDir, "jobs"), { recursive: true });
18021
+ mkdirSync6(join12(projectDir, "routes"), { recursive: true });
18022
+ mkdirSync6(join12(projectDir, "jobs"), { recursive: true });
17824
18023
  writeGeneratedFiles(projectDir, generateResult.files);
17825
18024
  output.info(`Files written to ${projectDir}`);
17826
18025
  if (opts.deploy !== false) {
@@ -17851,15 +18050,15 @@ function registerAddCommand(program2) {
17851
18050
  return;
17852
18051
  }
17853
18052
  const projectDir = opts.dir ? resolve5(opts.dir) : process.cwd();
17854
- const duraJsonPath = join11(projectDir, "dura.json");
17855
- if (!existsSync10(duraJsonPath)) {
18053
+ const duraJsonPath = join12(projectDir, "dura.json");
18054
+ if (!existsSync11(duraJsonPath)) {
17856
18055
  output.error("NOT_A_DURA_PROJECT", "No dura.json found in the current directory", "Run this command from a dura project directory or use --dir");
17857
18056
  return;
17858
18057
  }
17859
18058
  const existingRoutes = getExistingRoutes(projectDir);
17860
18059
  let projectConfig = {};
17861
18060
  try {
17862
- projectConfig = JSON.parse(readFileSync9(duraJsonPath, "utf-8"));
18061
+ projectConfig = JSON.parse(readFileSync10(duraJsonPath, "utf-8"));
17863
18062
  } catch {}
17864
18063
  const apiUrl = getApiUrl();
17865
18064
  const client = new ApiClient(apiUrl, token);
@@ -17874,11 +18073,7 @@ function registerAddCommand(program2) {
17874
18073
  }
17875
18074
  });
17876
18075
  } catch (err) {
17877
- if (err instanceof ApiClientError) {
17878
- output.error(err.code, err.message, err.suggestion);
17879
- } else if (err instanceof Error) {
17880
- output.error("GENERATE_FAILED", err.message);
17881
- }
18076
+ reportApiError(output, err, "GENERATE_FAILED");
17882
18077
  return;
17883
18078
  }
17884
18079
  output.info(`Generated ${generateResult.files.length} file(s): ${generateResult.files.map((f) => f.path).join(", ")}`);
@@ -17909,6 +18104,7 @@ var init_create = __esm(() => {
17909
18104
  init_src3();
17910
18105
  init_api_client();
17911
18106
  init_config_store();
18107
+ init_handle_api_error();
17912
18108
  });
17913
18109
 
17914
18110
  // src/commands/workflow.ts
@@ -17953,11 +18149,7 @@ function registerWorkflowsCommand(program2) {
17953
18149
  d.createdAt
17954
18150
  ]));
17955
18151
  } catch (err) {
17956
- if (err instanceof ApiClientError) {
17957
- output.error(err.code, err.message, err.suggestion);
17958
- } else if (err instanceof Error) {
17959
- output.error("WORKFLOWS_LIST_FAILED", err.message);
17960
- }
18152
+ reportApiError(output, err, "WORKFLOWS_LIST_FAILED");
17961
18153
  }
17962
18154
  });
17963
18155
  }
@@ -17986,11 +18178,7 @@ function registerWorkflowCommand(program2) {
17986
18178
  }
17987
18179
  output.info(`Workflow run started: ${result.runId}`);
17988
18180
  } catch (err) {
17989
- if (err instanceof ApiClientError) {
17990
- output.error(err.code, err.message, err.suggestion);
17991
- } else if (err instanceof Error) {
17992
- output.error("WORKFLOW_RUN_FAILED", err.message);
17993
- }
18181
+ reportApiError(output, err, "WORKFLOW_RUN_FAILED");
17994
18182
  }
17995
18183
  });
17996
18184
  workflow.command("runs <name>").description("List workflow runs").requiredOption("--project <id>", "Project ID").option("--status <status>", "Filter by status (pending/running/completed/failed)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (name, opts, cmd) => {
@@ -18014,11 +18202,7 @@ function registerWorkflowCommand(program2) {
18014
18202
  }
18015
18203
  output.table(["ID", "Status", "Trigger", "Created"], runs.map((r) => [r.id, r.status, r.triggerType, r.createdAt]));
18016
18204
  } catch (err) {
18017
- if (err instanceof ApiClientError) {
18018
- output.error(err.code, err.message, err.suggestion);
18019
- } else if (err instanceof Error) {
18020
- output.error("WORKFLOW_RUNS_FAILED", err.message);
18021
- }
18205
+ reportApiError(output, err, "WORKFLOW_RUNS_FAILED");
18022
18206
  }
18023
18207
  });
18024
18208
  workflow.command("cancel <run-id>").description("Cancel a running workflow").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").option("--confirm", "Confirm the destructive cancel operation").action(async (runId, opts, cmd) => {
@@ -18035,11 +18219,7 @@ function registerWorkflowCommand(program2) {
18035
18219
  await client.post(`/api/v1/projects/${opts.project}/workflow-runs/${encodeURIComponent(runId)}/cancel`, {});
18036
18220
  output.info(`Workflow run ${runId} cancelled.`);
18037
18221
  } catch (err) {
18038
- if (err instanceof ApiClientError) {
18039
- output.error(err.code, err.message, err.suggestion);
18040
- } else if (err instanceof Error) {
18041
- output.error("WORKFLOW_CANCEL_FAILED", err.message);
18042
- }
18222
+ reportApiError(output, err, "WORKFLOW_CANCEL_FAILED");
18043
18223
  }
18044
18224
  });
18045
18225
  }
@@ -18071,11 +18251,7 @@ function registerApprovalsCommand(program2) {
18071
18251
  a.createdAt
18072
18252
  ]));
18073
18253
  } catch (err) {
18074
- if (err instanceof ApiClientError) {
18075
- output.error(err.code, err.message, err.suggestion);
18076
- } else if (err instanceof Error) {
18077
- output.error("APPROVALS_LIST_FAILED", err.message);
18078
- }
18254
+ reportApiError(output, err, "APPROVALS_LIST_FAILED");
18079
18255
  }
18080
18256
  });
18081
18257
  }
@@ -18090,11 +18266,7 @@ function registerApproveCommand(program2) {
18090
18266
  await client.post(`/api/v1/projects/${opts.project}/approvals/${encodeURIComponent(approvalId)}/approve`, { decidedBy: opts.decidedBy });
18091
18267
  output.info(`Approval ${approvalId} approved.`);
18092
18268
  } catch (err) {
18093
- if (err instanceof ApiClientError) {
18094
- output.error(err.code, err.message, err.suggestion);
18095
- } else if (err instanceof Error) {
18096
- output.error("APPROVE_FAILED", err.message);
18097
- }
18269
+ reportApiError(output, err, "APPROVE_FAILED");
18098
18270
  }
18099
18271
  });
18100
18272
  }
@@ -18109,11 +18281,7 @@ function registerRejectCommand(program2) {
18109
18281
  await client.post(`/api/v1/projects/${opts.project}/approvals/${encodeURIComponent(approvalId)}/reject`, { decidedBy: opts.decidedBy, reason: opts.reason });
18110
18282
  output.info(`Approval ${approvalId} rejected.`);
18111
18283
  } catch (err) {
18112
- if (err instanceof ApiClientError) {
18113
- output.error(err.code, err.message, err.suggestion);
18114
- } else if (err instanceof Error) {
18115
- output.error("REJECT_FAILED", err.message);
18116
- }
18284
+ reportApiError(output, err, "REJECT_FAILED");
18117
18285
  }
18118
18286
  });
18119
18287
  }
@@ -18121,6 +18289,7 @@ var init_workflow = __esm(() => {
18121
18289
  init_src3();
18122
18290
  init_api_client();
18123
18291
  init_config_store();
18292
+ init_handle_api_error();
18124
18293
  });
18125
18294
 
18126
18295
  // src/commands/env.ts
@@ -18162,11 +18331,7 @@ function registerEnvCommand(program2) {
18162
18331
  });
18163
18332
  output.success(env2);
18164
18333
  } catch (err) {
18165
- if (err instanceof ApiClientError) {
18166
- output.error(err.code, err.message, err.suggestion);
18167
- } else if (err instanceof Error) {
18168
- output.error("ENV_CREATE_FAILED", err.message);
18169
- }
18334
+ reportApiError(output, err, "ENV_CREATE_FAILED");
18170
18335
  }
18171
18336
  });
18172
18337
  env.command("list").description("List all environments for a project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -18179,11 +18344,7 @@ function registerEnvCommand(program2) {
18179
18344
  const envs = await client.get(`/api/v1/projects/${projectId}/environments`);
18180
18345
  output.success(envs);
18181
18346
  } catch (err) {
18182
- if (err instanceof ApiClientError) {
18183
- output.error(err.code, err.message, err.suggestion);
18184
- } else if (err instanceof Error) {
18185
- output.error("ENV_LIST_FAILED", err.message);
18186
- }
18347
+ reportApiError(output, err, "ENV_LIST_FAILED");
18187
18348
  }
18188
18349
  });
18189
18350
  env.command("delete <name>").description("Delete an environment").option("--project <id>", "Project ID (defaults to dura.json)").option("--env-id <id>", "Environment ID (alternative to name)").option("--confirm", "Confirm deletion (required for destructive operation)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (name, opts, cmd) => {
@@ -18210,11 +18371,7 @@ function registerEnvCommand(program2) {
18210
18371
  await client.delete(`/api/v1/projects/${projectId}/environments/${envId}`);
18211
18372
  output.success({ deleted: true, name });
18212
18373
  } catch (err) {
18213
- if (err instanceof ApiClientError) {
18214
- output.error(err.code, err.message, err.suggestion);
18215
- } else if (err instanceof Error) {
18216
- output.error("ENV_DELETE_FAILED", err.message);
18217
- }
18374
+ reportApiError(output, err, "ENV_DELETE_FAILED");
18218
18375
  }
18219
18376
  });
18220
18377
  env.command("diff <env1> <env2>").description("Compare two environments").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (env1, env2, opts, cmd) => {
@@ -18242,11 +18399,7 @@ function registerEnvCommand(program2) {
18242
18399
  };
18243
18400
  output.success(diff);
18244
18401
  } catch (err) {
18245
- if (err instanceof ApiClientError) {
18246
- output.error(err.code, err.message, err.suggestion);
18247
- } else if (err instanceof Error) {
18248
- output.error("ENV_DIFF_FAILED", err.message);
18249
- }
18402
+ reportApiError(output, err, "ENV_DIFF_FAILED");
18250
18403
  }
18251
18404
  });
18252
18405
  }
@@ -18299,11 +18452,7 @@ function registerPromoteCommand(program2) {
18299
18452
  });
18300
18453
  output.success(promotion);
18301
18454
  } catch (err) {
18302
- if (err instanceof ApiClientError) {
18303
- output.error(err.code, err.message, err.suggestion);
18304
- } else if (err instanceof Error) {
18305
- output.error("PROMOTE_FAILED", err.message);
18306
- }
18455
+ reportApiError(output, err, "PROMOTE_FAILED");
18307
18456
  }
18308
18457
  });
18309
18458
  }
@@ -18327,11 +18476,7 @@ function registerCanaryCommand(program2) {
18327
18476
  const canary2 = await client.get(`/api/v1/projects/${projectId}/canary?envId=${opts.env}`);
18328
18477
  output.success(canary2);
18329
18478
  } catch (err) {
18330
- if (err instanceof ApiClientError) {
18331
- output.error(err.code, err.message, err.suggestion);
18332
- } else if (err instanceof Error) {
18333
- output.error("CANARY_STATUS_FAILED", err.message);
18334
- }
18479
+ reportApiError(output, err, "CANARY_STATUS_FAILED");
18335
18480
  }
18336
18481
  });
18337
18482
  canary.command("complete").description("Force-complete an active canary (100% traffic to new)").option("--project <id>", "Project ID (defaults to dura.json)").requiredOption("--canary-id <id>", "Canary deployment ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -18352,11 +18497,7 @@ function registerCanaryCommand(program2) {
18352
18497
  const canary2 = await client.post(`/api/v1/projects/${projectId}/canary/complete`, { canaryId: opts.canaryId });
18353
18498
  output.success(canary2);
18354
18499
  } catch (err) {
18355
- if (err instanceof ApiClientError) {
18356
- output.error(err.code, err.message, err.suggestion);
18357
- } else if (err instanceof Error) {
18358
- output.error("CANARY_COMPLETE_FAILED", err.message);
18359
- }
18500
+ reportApiError(output, err, "CANARY_COMPLETE_FAILED");
18360
18501
  }
18361
18502
  });
18362
18503
  canary.command("rollback").description("Force-rollback an active canary (restore old deployment)").option("--project <id>", "Project ID (defaults to dura.json)").requiredOption("--canary-id <id>", "Canary deployment ID").option("--reason <reason>", "Reason for rollback").option("--confirm", "Confirm rollback (required)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -18381,11 +18522,7 @@ function registerCanaryCommand(program2) {
18381
18522
  const canary2 = await client.post(`/api/v1/projects/${projectId}/canary/rollback`, { canaryId: opts.canaryId, reason: opts.reason });
18382
18523
  output.success(canary2);
18383
18524
  } catch (err) {
18384
- if (err instanceof ApiClientError) {
18385
- output.error(err.code, err.message, err.suggestion);
18386
- } else if (err instanceof Error) {
18387
- output.error("CANARY_ROLLBACK_FAILED", err.message);
18388
- }
18525
+ reportApiError(output, err, "CANARY_ROLLBACK_FAILED");
18389
18526
  }
18390
18527
  });
18391
18528
  }
@@ -18413,6 +18550,7 @@ var init_env = __esm(() => {
18413
18550
  init_api_client();
18414
18551
  init_config_store();
18415
18552
  init_project_id();
18553
+ init_handle_api_error();
18416
18554
  });
18417
18555
 
18418
18556
  // src/commands/reports.ts
@@ -18729,16 +18867,13 @@ function parseChannelSpec(spec) {
18729
18867
  return null;
18730
18868
  }
18731
18869
  function handleError(err, output, defaultCode) {
18732
- if (err instanceof ApiClientError) {
18733
- output.error(err.code, err.message, err.suggestion);
18734
- } else if (err instanceof Error) {
18735
- output.error(defaultCode, err.message);
18736
- }
18870
+ reportApiError(output, err, defaultCode);
18737
18871
  }
18738
18872
  var init_reports = __esm(() => {
18739
18873
  init_src3();
18740
18874
  init_api_client();
18741
18875
  init_config_store();
18876
+ init_handle_api_error();
18742
18877
  });
18743
18878
 
18744
18879
  // src/commands/heal.ts
@@ -18856,11 +18991,7 @@ Healing configuration:
18856
18991
  }
18857
18992
  }
18858
18993
  } catch (err) {
18859
- if (err instanceof ApiClientError) {
18860
- output.error(err.code, err.message, err.suggestion);
18861
- } else if (err instanceof Error) {
18862
- output.error("HEAL_CONFIG_FAILED", err.message);
18863
- }
18994
+ reportApiError(output, err, "HEAL_CONFIG_FAILED");
18864
18995
  }
18865
18996
  });
18866
18997
  heal.command("list").description("List healing records").requiredOption("--project <id>", "Project ID").option("--status <status>", "Filter by status (e.g. suggested, deployed)").option("--limit <n>", "Max records to show", parseInt).option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -18892,11 +19023,7 @@ ${records.length} healing record(s):
18892
19023
  }
18893
19024
  }
18894
19025
  } catch (err) {
18895
- if (err instanceof ApiClientError) {
18896
- output.error(err.code, err.message, err.suggestion);
18897
- } else if (err instanceof Error) {
18898
- output.error("HEAL_LIST_FAILED", err.message);
18899
- }
19026
+ reportApiError(output, err, "HEAL_LIST_FAILED");
18900
19027
  }
18901
19028
  });
18902
19029
  heal.command("show <record-id>").description("Show healing record details").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (recordId, opts, cmd) => {
@@ -18915,11 +19042,7 @@ ${records.length} healing record(s):
18915
19042
  ${formatRecord(record)}`);
18916
19043
  }
18917
19044
  } catch (err) {
18918
- if (err instanceof ApiClientError) {
18919
- output.error(err.code, err.message, err.suggestion);
18920
- } else if (err instanceof Error) {
18921
- output.error("HEAL_SHOW_FAILED", err.message);
18922
- }
19045
+ reportApiError(output, err, "HEAL_SHOW_FAILED");
18923
19046
  }
18924
19047
  });
18925
19048
  heal.command("trigger <execution-id>").description("Manually trigger healing for a failed execution").requiredOption("--project <id>", "Project ID").requiredOption("--automation <name>", "Automation name").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (executionId, opts, cmd) => {
@@ -18939,11 +19062,7 @@ Healing triggered. Record: ${record.id}`);
18939
19062
  output.info(`Status: ${record.status}`);
18940
19063
  }
18941
19064
  } catch (err) {
18942
- if (err instanceof ApiClientError) {
18943
- output.error(err.code, err.message, err.suggestion);
18944
- } else if (err instanceof Error) {
18945
- output.error("HEAL_TRIGGER_FAILED", err.message);
18946
- }
19065
+ reportApiError(output, err, "HEAL_TRIGGER_FAILED");
18947
19066
  }
18948
19067
  });
18949
19068
  heal.command("approve <record-id>").description("Approve a suggested fix and deploy it").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (recordId, opts, cmd) => {
@@ -18961,11 +19080,7 @@ Healing triggered. Record: ${record.id}`);
18961
19080
  output.info(`Fix ${recordId} approved and queued for deployment.`);
18962
19081
  }
18963
19082
  } catch (err) {
18964
- if (err instanceof ApiClientError) {
18965
- output.error(err.code, err.message, err.suggestion);
18966
- } else if (err instanceof Error) {
18967
- output.error("HEAL_APPROVE_FAILED", err.message);
18968
- }
19083
+ reportApiError(output, err, "HEAL_APPROVE_FAILED");
18969
19084
  }
18970
19085
  });
18971
19086
  heal.command("reject <record-id>").description("Reject a suggested fix").requiredOption("--project <id>", "Project ID").option("--reason <reason>", "Reason for rejection").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (recordId, opts, cmd) => {
@@ -18983,11 +19098,7 @@ Healing triggered. Record: ${record.id}`);
18983
19098
  output.info(`Fix ${recordId} rejected.`);
18984
19099
  }
18985
19100
  } catch (err) {
18986
- if (err instanceof ApiClientError) {
18987
- output.error(err.code, err.message, err.suggestion);
18988
- } else if (err instanceof Error) {
18989
- output.error("HEAL_REJECT_FAILED", err.message);
18990
- }
19101
+ reportApiError(output, err, "HEAL_REJECT_FAILED");
18991
19102
  }
18992
19103
  });
18993
19104
  heal.command("rollback <record-id>").description("Rollback a deployed fix").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (recordId, opts, cmd) => {
@@ -19005,11 +19116,7 @@ Healing triggered. Record: ${record.id}`);
19005
19116
  output.info(`Fix ${recordId} rolled back.`);
19006
19117
  }
19007
19118
  } catch (err) {
19008
- if (err instanceof ApiClientError) {
19009
- output.error(err.code, err.message, err.suggestion);
19010
- } else if (err instanceof Error) {
19011
- output.error("HEAL_ROLLBACK_FAILED", err.message);
19012
- }
19119
+ reportApiError(output, err, "HEAL_ROLLBACK_FAILED");
19013
19120
  }
19014
19121
  });
19015
19122
  heal.command("diff <record-id>").description("Show the generated code patch (diff view)").requiredOption("--project <id>", "Project ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (recordId, opts, cmd) => {
@@ -19033,11 +19140,7 @@ Healing triggered. Record: ${record.id}`);
19033
19140
  ${formatDiff(record)}`);
19034
19141
  }
19035
19142
  } catch (err) {
19036
- if (err instanceof ApiClientError) {
19037
- output.error(err.code, err.message, err.suggestion);
19038
- } else if (err instanceof Error) {
19039
- output.error("HEAL_DIFF_FAILED", err.message);
19040
- }
19143
+ reportApiError(output, err, "HEAL_DIFF_FAILED");
19041
19144
  }
19042
19145
  });
19043
19146
  }
@@ -19045,34 +19148,35 @@ var init_heal = __esm(() => {
19045
19148
  init_src3();
19046
19149
  init_api_client();
19047
19150
  init_config_store();
19151
+ init_handle_api_error();
19048
19152
  });
19049
19153
 
19050
19154
  // src/lib/skill-installer.ts
19051
- import { existsSync as existsSync11, mkdirSync as mkdirSync6, readFileSync as readFileSync10, writeFileSync as writeFileSync9 } from "node:fs";
19052
- import { join as join12, dirname as dirname2 } from "node:path";
19155
+ import { existsSync as existsSync12, mkdirSync as mkdirSync7, readFileSync as readFileSync11, writeFileSync as writeFileSync10 } from "node:fs";
19156
+ import { join as join13, dirname as dirname3 } from "node:path";
19053
19157
  import { homedir as homedir2 } from "node:os";
19054
19158
  import { fileURLToPath } from "node:url";
19055
19159
  function getSkillSourceDir() {
19056
19160
  const __filename2 = fileURLToPath(import.meta.url);
19057
- return join12(dirname2(dirname2(__filename2)), "skills");
19161
+ return join13(dirname3(dirname3(__filename2)), "skills");
19058
19162
  }
19059
19163
  function getGlobalSkillsDir() {
19060
- return join12(homedir2(), ".claude", "skills", "dura");
19164
+ return join13(homedir2(), ".claude", "skills", "dura");
19061
19165
  }
19062
19166
  function getLocalSkillsDir(projectDir) {
19063
- return join12(projectDir, ".claude", "skills", "dura");
19167
+ return join13(projectDir, ".claude", "skills", "dura");
19064
19168
  }
19065
19169
  function installSkills(targetDir) {
19066
19170
  const sourceDir = getSkillSourceDir();
19067
- if (!existsSync11(targetDir)) {
19068
- mkdirSync6(targetDir, { recursive: true });
19171
+ if (!existsSync12(targetDir)) {
19172
+ mkdirSync7(targetDir, { recursive: true });
19069
19173
  }
19070
19174
  const installedFiles = [];
19071
19175
  for (const file of SKILL_FILES) {
19072
- const sourcePath = join12(sourceDir, file);
19073
- const targetPath = join12(targetDir, file);
19074
- const content = readFileSync10(sourcePath, "utf-8");
19075
- writeFileSync9(targetPath, content, "utf-8");
19176
+ const sourcePath = join13(sourceDir, file);
19177
+ const targetPath = join13(targetDir, file);
19178
+ const content = readFileSync11(sourcePath, "utf-8");
19179
+ writeFileSync10(targetPath, content, "utf-8");
19076
19180
  installedFiles.push(targetPath);
19077
19181
  }
19078
19182
  return {
@@ -19096,8 +19200,8 @@ var exports_init = {};
19096
19200
  __export(exports_init, {
19097
19201
  registerInitCommand: () => registerInitCommand
19098
19202
  });
19099
- import { existsSync as existsSync12, mkdirSync as mkdirSync7, writeFileSync as writeFileSync10 } from "node:fs";
19100
- import { join as join13, resolve as resolve6, basename } from "node:path";
19203
+ import { existsSync as existsSync13, mkdirSync as mkdirSync8, writeFileSync as writeFileSync11 } from "node:fs";
19204
+ import { join as join14, resolve as resolve6, basename } from "node:path";
19101
19205
  function registerInitCommand(program2) {
19102
19206
  program2.command("init").description("Initialize a dura project in the current directory and install AI agent skills").option("--dir <path>", "Project directory (defaults to current dir)").option("--name <name>", "Project name (defaults to directory name)").option("--global", "Install AI agent skills globally (~/.claude/skills/dura/)").option("--local", "Install AI agent skills locally (.claude/skills/dura/)").option("--skip-skills", "Skip AI agent skill installation").action(async (opts, cmd) => {
19103
19207
  const output = getOutput(cmd);
@@ -19107,24 +19211,24 @@ function registerInitCommand(program2) {
19107
19211
  output.error("INVALID_NAME", `Invalid project name "${projectName}"`, "Project name must start with a letter and contain only letters, numbers, hyphens, and underscores. Use --name to specify a valid name.");
19108
19212
  return;
19109
19213
  }
19110
- mkdirSync7(join13(projectDir, "routes"), { recursive: true });
19111
- mkdirSync7(join13(projectDir, "jobs"), { recursive: true });
19112
- const manifestPath = join13(projectDir, "dura.json");
19113
- const alreadyInitialized = existsSync12(manifestPath);
19214
+ mkdirSync8(join14(projectDir, "routes"), { recursive: true });
19215
+ mkdirSync8(join14(projectDir, "jobs"), { recursive: true });
19216
+ const manifestPath = join14(projectDir, "dura.json");
19217
+ const alreadyInitialized = existsSync13(manifestPath);
19114
19218
  if (!alreadyInitialized) {
19115
- writeFileSync10(manifestPath, duraJsonTemplate(projectName));
19219
+ writeFileSync11(manifestPath, duraJsonTemplate(projectName));
19116
19220
  } else {
19117
19221
  output.info(`dura.json already exists in ${projectDir} — leaving it in place.`);
19118
19222
  }
19119
- const helloPath = join13(projectDir, "routes", "hello.ts");
19120
- if (existsSync12(helloPath)) {
19223
+ const helloPath = join14(projectDir, "routes", "hello.ts");
19224
+ if (existsSync13(helloPath)) {
19121
19225
  output.warn("routes/hello.ts already exists — skipping");
19122
19226
  } else {
19123
- writeFileSync10(helloPath, HELLO_TEMPLATE);
19227
+ writeFileSync11(helloPath, HELLO_TEMPLATE);
19124
19228
  }
19125
- const gitignorePath = join13(projectDir, ".gitignore");
19126
- if (!existsSync12(gitignorePath)) {
19127
- writeFileSync10(gitignorePath, GITIGNORE_CONTENT2);
19229
+ const gitignorePath = join14(projectDir, ".gitignore");
19230
+ if (!existsSync13(gitignorePath)) {
19231
+ writeFileSync11(gitignorePath, GITIGNORE_CONTENT2);
19128
19232
  }
19129
19233
  if (alreadyInitialized) {
19130
19234
  output.info(`Re-checked dura project "${projectName}" in ${projectDir}`);
@@ -19230,11 +19334,7 @@ function registerProjectsCommand(program2) {
19230
19334
  const project = await client.get(`/api/v1/orgs/${orgId}/projects/${projectId}`);
19231
19335
  output.success(project);
19232
19336
  } catch (err) {
19233
- if (err instanceof ApiClientError) {
19234
- output.error(err.code, err.message, err.suggestion);
19235
- } else if (err instanceof Error) {
19236
- output.error("PROJECTS_GET_FAILED", err.message);
19237
- }
19337
+ reportApiError(output, err, "PROJECTS_GET_FAILED");
19238
19338
  }
19239
19339
  });
19240
19340
  projects2.command("list").description("List all projects in the organization").option("--org <id>", "Organization ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
@@ -19268,11 +19368,7 @@ function registerProjectsCommand(program2) {
19268
19368
  ]));
19269
19369
  }
19270
19370
  } catch (err) {
19271
- if (err instanceof ApiClientError) {
19272
- output.error(err.code, err.message, err.suggestion);
19273
- } else if (err instanceof Error) {
19274
- output.error("PROJECTS_LIST_FAILED", err.message);
19275
- }
19371
+ reportApiError(output, err, "PROJECTS_LIST_FAILED");
19276
19372
  }
19277
19373
  });
19278
19374
  }
@@ -19280,6 +19376,7 @@ var init_projects2 = __esm(() => {
19280
19376
  init_src3();
19281
19377
  init_api_client();
19282
19378
  init_config_store();
19379
+ init_handle_api_error();
19283
19380
  });
19284
19381
 
19285
19382
  // src/index.ts
@@ -19321,6 +19418,7 @@ async function registerAllCommands(program2) {
19321
19418
  const { registerTestCommand: registerTestCommand2 } = await Promise.resolve().then(() => (init_test(), exports_test));
19322
19419
  const { registerDomainsCommand: registerDomainsCommand2 } = await Promise.resolve().then(() => (init_domains(), exports_domains));
19323
19420
  const { registerEndpointKeysCommand: registerEndpointKeysCommand2 } = await Promise.resolve().then(() => (init_endpoint_keys2(), exports_endpoint_keys));
19421
+ const { registerEventsCommand: registerEventsCommand2 } = await Promise.resolve().then(() => (init_events(), exports_events));
19324
19422
  const { registerUsageCommand: registerUsageCommand2 } = await Promise.resolve().then(() => (init_usage(), exports_usage));
19325
19423
  const { registerMarketplaceCommand: registerMarketplaceCommand2 } = await Promise.resolve().then(() => (init_marketplace2(), exports_marketplace));
19326
19424
  const { registerExportCommand: registerExportCommand2 } = await Promise.resolve().then(() => (init_export(), exports_export));
@@ -19365,6 +19463,7 @@ async function registerAllCommands(program2) {
19365
19463
  registerTestCommand2(program2);
19366
19464
  registerRunCommand2(program2);
19367
19465
  registerScheduleCommand2(program2);
19466
+ registerEventsCommand2(program2);
19368
19467
  registerStatusCommand2(program2);
19369
19468
  registerLogsCommand2(program2);
19370
19469
  registerUsageCommand2(program2);
@@ -19386,7 +19485,7 @@ async function registerAllCommands(program2) {
19386
19485
  registerOpenApiCommand2(program2);
19387
19486
  return program2;
19388
19487
  }
19389
- var CLI_VERSION = "0.2.1";
19488
+ var CLI_VERSION = "0.3.1";
19390
19489
  var init_src3 = __esm(() => {
19391
19490
  init_esm();
19392
19491
  if (import.meta.url === `file://${realpathSync(process.argv[1] ?? "").replace(/\\/g, "/")}`) {
@@ -19403,4 +19502,4 @@ export {
19403
19502
  CLI_VERSION
19404
19503
  };
19405
19504
 
19406
- //# debugId=25AB4373003CF5A164756E2164756E21
19505
+ //# debugId=A22178BD000AEBBE64756E2164756E21