@secondlayer/cli 5.1.5 → 5.2.0

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.
package/dist/cli.js CHANGED
@@ -2518,64 +2518,106 @@ var init_session = __esm(() => {
2518
2518
  SESSION_PATH = join(SESSION_DIR, "session.json");
2519
2519
  });
2520
2520
 
2521
- // src/lib/http.ts
2522
- async function request(url, opts) {
2523
- const headers = {
2524
- "content-type": "application/json",
2525
- ...opts.headers ?? {}
2526
- };
2527
- if (opts.bearer)
2528
- headers.authorization = `Bearer ${opts.bearer}`;
2529
- const res = await fetch(url, {
2530
- method: opts.method ?? "GET",
2531
- headers,
2532
- body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
2533
- signal: AbortSignal.timeout(opts.timeoutMs ?? REQUEST_TIMEOUT_MS)
2534
- });
2535
- if (!res.ok) {
2536
- let body = {};
2537
- try {
2538
- body = await res.json();
2539
- } catch {
2540
- body = { error: await res.text().catch(() => "") };
2541
- }
2542
- const code = body.code ?? (res.status === 401 ? "SESSION_EXPIRED" : res.status === 404 ? "NOT_FOUND" : `HTTP_${res.status}`);
2543
- const message = body.message ?? body.error ?? `HTTP ${res.status}`;
2544
- throw new CliHttpError(res.status, code, body, message);
2521
+ // src/lib/resolve-tenant.ts
2522
+ async function resolveActiveTenant(_opts = {}) {
2523
+ const envUrl = process.env.SL_API_URL;
2524
+ const envKey = process.env.SL_SERVICE_KEY;
2525
+ if (envUrl && envKey) {
2526
+ return { apiUrl: envUrl, ephemeralKey: envKey, fromEnv: true };
2545
2527
  }
2546
- if (res.status === 204)
2547
- return;
2548
- return await res.json();
2549
- }
2550
- async function httpPlatform(path2, opts = {}) {
2551
2528
  const session = await readSession();
2552
2529
  if (!session) {
2553
- throw new CliHttpError(401, "SESSION_EXPIRED", { error: "Not logged in" }, "Not logged in — run `sl login`");
2530
+ const err = new Error("Not logged in — run `sl login`");
2531
+ err.code = "SESSION_EXPIRED";
2532
+ throw err;
2554
2533
  }
2555
- return request(`${PLATFORM_API_URL}${path2}`, {
2556
- ...opts,
2557
- bearer: session.token
2558
- });
2534
+ return {
2535
+ apiUrl: PLATFORM_API_URL2,
2536
+ ephemeralKey: session.token,
2537
+ fromEnv: false
2538
+ };
2559
2539
  }
2560
- async function httpPlatformAnon(path2, opts = {}) {
2561
- return request(`${PLATFORM_API_URL}${path2}`, opts);
2540
+ function isOssMode() {
2541
+ return !!process.env.SL_API_URL && !process.env.SL_SERVICE_KEY;
2562
2542
  }
2563
- var CliHttpError, PLATFORM_API_URL, REQUEST_TIMEOUT_MS = 30000;
2564
- var init_http = __esm(() => {
2543
+ var PLATFORM_API_URL2;
2544
+ var init_resolve_tenant = __esm(() => {
2565
2545
  init_session();
2566
- CliHttpError = class CliHttpError extends Error {
2567
- status;
2568
- code;
2569
- body;
2570
- name = "CliHttpError";
2571
- constructor(status, code, body, message) {
2572
- super(message);
2573
- this.status = status;
2574
- this.code = code;
2575
- this.body = body;
2576
- }
2546
+ PLATFORM_API_URL2 = process.env.SL_PLATFORM_API_URL ?? "https://api.secondlayer.tools";
2547
+ });
2548
+
2549
+ // src/lib/output.ts
2550
+ function red(text) {
2551
+ return `${colors.red}${text}${colors.reset}`;
2552
+ }
2553
+ function green(text) {
2554
+ return `${colors.green}${text}${colors.reset}`;
2555
+ }
2556
+ function yellow(text) {
2557
+ return `${colors.yellow}${text}${colors.reset}`;
2558
+ }
2559
+ function blue(text) {
2560
+ return `${colors.blue}${text}${colors.reset}`;
2561
+ }
2562
+ function magenta(text) {
2563
+ return `${colors.magenta}${text}${colors.reset}`;
2564
+ }
2565
+ function cyan(text) {
2566
+ return `${colors.cyan}${text}${colors.reset}`;
2567
+ }
2568
+ function dim(text) {
2569
+ return `${colors.dim}${text}${colors.reset}`;
2570
+ }
2571
+ function success(message) {
2572
+ console.log(green(`✓ ${message}`));
2573
+ }
2574
+ function error(message) {
2575
+ const text = message.trim() || "Command failed.";
2576
+ console.error(red(`✗ ${text}`));
2577
+ }
2578
+ function warn(message) {
2579
+ console.log(yellow(`⚠ ${message}`));
2580
+ }
2581
+ function info(message) {
2582
+ console.log(blue(`ℹ ${message}`));
2583
+ }
2584
+ function stripAnsi(text) {
2585
+ return text.replace(ANSI_ESCAPE_PATTERN, "");
2586
+ }
2587
+ function formatTable(headers, rows) {
2588
+ const widths = headers.map((h, i) => {
2589
+ const colValues = [h, ...rows.map((r) => r[i] || "")];
2590
+ return Math.max(...colValues.map((v) => stripAnsi(v).length));
2591
+ });
2592
+ const headerRow = headers.map((h, i) => h.padEnd(widths[i] ?? 0)).join(" ");
2593
+ const separator = widths.map((w) => "-".repeat(w)).join(" ");
2594
+ const dataRows = rows.map((row) => row.map((cell, i) => {
2595
+ const width = widths[i] ?? 0;
2596
+ const padding = width - stripAnsi(cell).length;
2597
+ return cell + " ".repeat(Math.max(0, padding));
2598
+ }).join(" "));
2599
+ return [headerRow, separator, ...dataRows].join(`
2600
+ `);
2601
+ }
2602
+ function formatKeyValue(pairs) {
2603
+ const maxKeyLen = Math.max(...pairs.map(([k]) => k.length));
2604
+ return pairs.map(([key, value]) => `${dim(key.padEnd(maxKeyLen))} ${value}`).join(`
2605
+ `);
2606
+ }
2607
+ var colors, ANSI_ESCAPE_PATTERN;
2608
+ var init_output = __esm(() => {
2609
+ colors = {
2610
+ reset: "\x1B[0m",
2611
+ red: "\x1B[31m",
2612
+ green: "\x1B[32m",
2613
+ yellow: "\x1B[33m",
2614
+ blue: "\x1B[34m",
2615
+ magenta: "\x1B[35m",
2616
+ cyan: "\x1B[36m",
2617
+ dim: "\x1B[2m",
2618
+ bold: "\x1B[1m"
2577
2619
  };
2578
- PLATFORM_API_URL = process.env.SL_PLATFORM_API_URL ?? "https://api.secondlayer.tools";
2620
+ ANSI_ESCAPE_PATTERN = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
2579
2621
  });
2580
2622
 
2581
2623
  // src/lib/fs.ts
@@ -2688,7 +2730,7 @@ async function loadConfig() {
2688
2730
  const raw = await readJsonFile(CONFIG_PATH);
2689
2731
  const migrated = migrateConfig(raw);
2690
2732
  config = ConfigSchema.parse(migrated);
2691
- } catch (error) {
2733
+ } catch (error2) {
2692
2734
  console.error("Warning: Invalid config file, using defaults");
2693
2735
  config = { ...DEFAULT_CONFIG };
2694
2736
  }
@@ -2844,167 +2886,6 @@ var init_config = __esm(() => {
2844
2886
  };
2845
2887
  });
2846
2888
 
2847
- // src/lib/project-file.ts
2848
- import { existsSync } from "node:fs";
2849
- import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
2850
- import { homedir as homedir3 } from "node:os";
2851
- import { dirname as dirname2, join as join3, parse as parsePath, resolve } from "node:path";
2852
- import { z as z3 } from "zod/v4";
2853
- async function readActiveProject(cwd, globalDefault) {
2854
- let dir = resolve(cwd);
2855
- const home = resolve(homedir3());
2856
- const fsRoot = parsePath(dir).root;
2857
- while (true) {
2858
- const candidate = join3(dir, DIRNAME, FILENAME);
2859
- if (existsSync(candidate)) {
2860
- try {
2861
- const raw = await readFile3(candidate, "utf8");
2862
- const parsed = ProjectFileSchema.parse(JSON.parse(raw));
2863
- return { slug: parsed.slug, resolvedFrom: candidate };
2864
- } catch {}
2865
- }
2866
- if (existsSync(join3(dir, ".git")))
2867
- break;
2868
- if (dir === home || dir === fsRoot)
2869
- break;
2870
- const parent = dirname2(dir);
2871
- if (parent === dir)
2872
- break;
2873
- dir = parent;
2874
- }
2875
- if (globalDefault) {
2876
- return {
2877
- slug: globalDefault,
2878
- resolvedFrom: join3(homedir3(), ".secondlayer", "config.json")
2879
- };
2880
- }
2881
- return null;
2882
- }
2883
- async function writeActiveProject(slug, cwd) {
2884
- const dir = join3(resolve(cwd), DIRNAME);
2885
- await mkdir3(dir, { recursive: true });
2886
- const file = join3(dir, FILENAME);
2887
- await writeFile3(file, `${JSON.stringify({ slug }, null, 2)}
2888
- `, "utf8");
2889
- return file;
2890
- }
2891
- var ProjectFileSchema, FILENAME = "project", DIRNAME = ".secondlayer";
2892
- var init_project_file = __esm(() => {
2893
- ProjectFileSchema = z3.object({
2894
- slug: z3.string().min(1)
2895
- });
2896
- });
2897
-
2898
- // src/lib/resolve-tenant.ts
2899
- async function resolveActiveTenant(opts = {}) {
2900
- const envUrl = process.env.SL_API_URL;
2901
- const envKey = process.env.SL_SERVICE_KEY;
2902
- if (envUrl && envKey) {
2903
- return { apiUrl: envUrl, ephemeralKey: envKey, fromEnv: true };
2904
- }
2905
- opts.tenant;
2906
- try {
2907
- const res = await httpPlatform("/api/tenants/me/keys/mint-ephemeral", { method: "POST" });
2908
- return {
2909
- apiUrl: res.apiUrl,
2910
- ephemeralKey: res.serviceKey,
2911
- fromEnv: false
2912
- };
2913
- } catch (err) {
2914
- if (err instanceof CliHttpError) {
2915
- if (err.status === 404) {
2916
- const config = await loadConfig();
2917
- const active = await readActiveProject(process.cwd(), config.defaultProject);
2918
- const hint = active ? `Run 'sl instance create --plan launch' to provision for project ${active.slug}` : "Run 'sl project create <name>' then 'sl instance create --plan launch'";
2919
- throw new CliHttpError(404, "NO_TENANT_FOR_PROJECT", { error: hint }, hint);
2920
- }
2921
- }
2922
- throw err;
2923
- }
2924
- }
2925
- function isOssMode() {
2926
- return !!process.env.SL_API_URL && !process.env.SL_SERVICE_KEY;
2927
- }
2928
- var init_resolve_tenant = __esm(() => {
2929
- init_config();
2930
- init_http();
2931
- init_project_file();
2932
- });
2933
-
2934
- // src/lib/output.ts
2935
- function red(text) {
2936
- return `${colors.red}${text}${colors.reset}`;
2937
- }
2938
- function green(text) {
2939
- return `${colors.green}${text}${colors.reset}`;
2940
- }
2941
- function yellow(text) {
2942
- return `${colors.yellow}${text}${colors.reset}`;
2943
- }
2944
- function blue(text) {
2945
- return `${colors.blue}${text}${colors.reset}`;
2946
- }
2947
- function magenta(text) {
2948
- return `${colors.magenta}${text}${colors.reset}`;
2949
- }
2950
- function cyan(text) {
2951
- return `${colors.cyan}${text}${colors.reset}`;
2952
- }
2953
- function dim(text) {
2954
- return `${colors.dim}${text}${colors.reset}`;
2955
- }
2956
- function success(message) {
2957
- console.log(green(`✓ ${message}`));
2958
- }
2959
- function error(message) {
2960
- const text = message.trim() || "Command failed.";
2961
- console.error(red(`✗ ${text}`));
2962
- }
2963
- function warn(message) {
2964
- console.log(yellow(`⚠ ${message}`));
2965
- }
2966
- function info(message) {
2967
- console.log(blue(`ℹ ${message}`));
2968
- }
2969
- function stripAnsi(text) {
2970
- return text.replace(ANSI_ESCAPE_PATTERN, "");
2971
- }
2972
- function formatTable(headers, rows) {
2973
- const widths = headers.map((h, i) => {
2974
- const colValues = [h, ...rows.map((r) => r[i] || "")];
2975
- return Math.max(...colValues.map((v) => stripAnsi(v).length));
2976
- });
2977
- const headerRow = headers.map((h, i) => h.padEnd(widths[i] ?? 0)).join(" ");
2978
- const separator = widths.map((w) => "-".repeat(w)).join(" ");
2979
- const dataRows = rows.map((row) => row.map((cell, i) => {
2980
- const width = widths[i] ?? 0;
2981
- const padding = width - stripAnsi(cell).length;
2982
- return cell + " ".repeat(Math.max(0, padding));
2983
- }).join(" "));
2984
- return [headerRow, separator, ...dataRows].join(`
2985
- `);
2986
- }
2987
- function formatKeyValue(pairs) {
2988
- const maxKeyLen = Math.max(...pairs.map(([k]) => k.length));
2989
- return pairs.map(([key, value]) => `${dim(key.padEnd(maxKeyLen))} ${value}`).join(`
2990
- `);
2991
- }
2992
- var colors, ANSI_ESCAPE_PATTERN;
2993
- var init_output = __esm(() => {
2994
- colors = {
2995
- reset: "\x1B[0m",
2996
- red: "\x1B[31m",
2997
- green: "\x1B[32m",
2998
- yellow: "\x1B[33m",
2999
- blue: "\x1B[34m",
3000
- magenta: "\x1B[35m",
3001
- cyan: "\x1B[36m",
3002
- dim: "\x1B[2m",
3003
- bold: "\x1B[1m"
3004
- };
3005
- ANSI_ESCAPE_PATTERN = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
3006
- });
3007
-
3008
2889
  // src/lib/docker.ts
3009
2890
  async function isDockerAvailable() {
3010
2891
  try {
@@ -3063,9 +2944,9 @@ var init_query = __esm(() => {
3063
2944
  CLOSE = {};
3064
2945
  Query = class Query extends Promise {
3065
2946
  constructor(strings, args, handler, canceller, options = {}) {
3066
- let resolve2, reject;
2947
+ let resolve, reject;
3067
2948
  super((a, b) => {
3068
- resolve2 = a;
2949
+ resolve = a;
3069
2950
  reject = b;
3070
2951
  });
3071
2952
  this.tagged = Array.isArray(strings.raw);
@@ -3076,7 +2957,7 @@ var init_query = __esm(() => {
3076
2957
  this.options = options;
3077
2958
  this.state = null;
3078
2959
  this.statement = null;
3079
- this.resolve = (x) => (this.active = false, resolve2(x));
2960
+ this.resolve = (x) => (this.active = false, resolve(x));
3080
2961
  this.reject = (x) => (this.active = false, reject(x));
3081
2962
  this.active = false;
3082
2963
  this.cancelled = null;
@@ -3124,12 +3005,12 @@ var init_query = __esm(() => {
3124
3005
  if (this.executed && !this.active)
3125
3006
  return { done: true };
3126
3007
  prev && prev();
3127
- const promise = new Promise((resolve2, reject) => {
3008
+ const promise = new Promise((resolve, reject) => {
3128
3009
  this.cursorFn = (value) => {
3129
- resolve2({ value, done: false });
3010
+ resolve({ value, done: false });
3130
3011
  return new Promise((r) => prev = r);
3131
3012
  };
3132
- this.resolve = () => (this.active = false, resolve2({ done: true }));
3013
+ this.resolve = () => (this.active = false, resolve({ done: true }));
3133
3014
  this.reject = (x) => (this.active = false, reject(x));
3134
3015
  });
3135
3016
  this.execute();
@@ -3683,12 +3564,12 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
3683
3564
  x.on("drain", drain);
3684
3565
  return x;
3685
3566
  }
3686
- async function cancel({ pid, secret }, resolve2, reject) {
3567
+ async function cancel({ pid, secret }, resolve, reject) {
3687
3568
  try {
3688
3569
  cancelMessage = bytes_default().i32(16).i32(80877102).i32(pid).i32(secret).end(16);
3689
3570
  await connect();
3690
3571
  socket.once("error", reject);
3691
- socket.once("close", resolve2);
3572
+ socket.once("close", resolve);
3692
3573
  } catch (error3) {
3693
3574
  reject(error3);
3694
3575
  }
@@ -4561,7 +4442,7 @@ var noop2 = () => {};
4561
4442
  // ../../node_modules/postgres/src/large.js
4562
4443
  import Stream2 from "stream";
4563
4444
  function largeObject(sql, oid, mode = 131072 | 262144) {
4564
- return new Promise(async (resolve2, reject) => {
4445
+ return new Promise(async (resolve, reject) => {
4565
4446
  await sql.begin(async (sql2) => {
4566
4447
  let finish;
4567
4448
  !oid && ([{ oid }] = await sql2`select lo_creat(-1) as oid`);
@@ -4587,7 +4468,7 @@ function largeObject(sql, oid, mode = 131072 | 262144) {
4587
4468
  ) seek
4588
4469
  `
4589
4470
  };
4590
- resolve2(lo);
4471
+ resolve(lo);
4591
4472
  return new Promise(async (r) => finish = r);
4592
4473
  async function readable({
4593
4474
  highWaterMark = 2048 * 8,
@@ -4747,8 +4628,8 @@ function Postgres(a, b2) {
4747
4628
  }
4748
4629
  async function reserve() {
4749
4630
  const queue = queue_default();
4750
- const c = open.length ? open.shift() : await new Promise((resolve2, reject) => {
4751
- const query = { reserve: resolve2, reject };
4631
+ const c = open.length ? open.shift() : await new Promise((resolve, reject) => {
4632
+ const query = { reserve: resolve, reject };
4752
4633
  queries.push(query);
4753
4634
  closed.length && connect(closed.shift(), query);
4754
4635
  });
@@ -4785,9 +4666,9 @@ function Postgres(a, b2) {
4785
4666
  let uncaughtError, result;
4786
4667
  name && await sql2`savepoint ${sql2(name)}`;
4787
4668
  try {
4788
- result = await new Promise((resolve2, reject) => {
4669
+ result = await new Promise((resolve, reject) => {
4789
4670
  const x = fn2(sql2);
4790
- Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve2, reject);
4671
+ Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve, reject);
4791
4672
  });
4792
4673
  if (uncaughtError)
4793
4674
  throw uncaughtError;
@@ -4844,8 +4725,8 @@ function Postgres(a, b2) {
4844
4725
  return c.execute(query) ? move(c, busy) : move(c, full);
4845
4726
  }
4846
4727
  function cancel(query) {
4847
- return new Promise((resolve2, reject) => {
4848
- query.state ? query.active ? connection_default(options).cancel(query.state, resolve2, reject) : query.cancelled = { resolve: resolve2, reject } : (queries.remove(query), query.cancelled = true, query.reject(Errors.generic("57014", "canceling statement due to user request")), resolve2());
4728
+ return new Promise((resolve, reject) => {
4729
+ query.state ? query.active ? connection_default(options).cancel(query.state, resolve, reject) : query.cancelled = { resolve, reject } : (queries.remove(query), query.cancelled = true, query.reject(Errors.generic("57014", "canceling statement due to user request")), resolve());
4849
4730
  });
4850
4731
  }
4851
4732
  async function end({ timeout = null } = {}) {
@@ -4861,11 +4742,11 @@ function Postgres(a, b2) {
4861
4742
  async function close() {
4862
4743
  await Promise.all(connections.map((c) => c.end()));
4863
4744
  }
4864
- async function destroy(resolve2) {
4745
+ async function destroy(resolve) {
4865
4746
  await Promise.all(connections.map((c) => c.terminate()));
4866
4747
  while (queries.length)
4867
4748
  queries.shift().reject(Errors.connection("CONNECTION_DESTROYED", options));
4868
- resolve2();
4749
+ resolve();
4869
4750
  }
4870
4751
  function connect(c, query) {
4871
4752
  move(c, connecting);
@@ -5049,13 +4930,13 @@ __export(exports_dev_state, {
5049
4930
  clearLogs: () => clearLogs,
5050
4931
  clearDevState: () => clearDevState
5051
4932
  });
5052
- import { homedir as homedir5 } from "node:os";
5053
- import { join as join6 } from "node:path";
4933
+ import { homedir as homedir4 } from "node:os";
4934
+ import { join as join5 } from "node:path";
5054
4935
  function getLogsDir() {
5055
4936
  return LOGS_DIR;
5056
4937
  }
5057
4938
  function getLogFile(service) {
5058
- return join6(LOGS_DIR, `${service}.log`);
4939
+ return join5(LOGS_DIR, `${service}.log`);
5059
4940
  }
5060
4941
  async function ensureDirs() {
5061
4942
  await Bun.$`mkdir -p ${STATE_DIR}`.quiet();
@@ -5112,9 +4993,9 @@ async function isDevRunning() {
5112
4993
  }
5113
4994
  var STATE_DIR, DEV_STATE_PATH, LOGS_DIR;
5114
4995
  var init_dev_state = __esm(() => {
5115
- STATE_DIR = join6(homedir5(), ".secondlayer");
5116
- DEV_STATE_PATH = join6(STATE_DIR, "dev.json");
5117
- LOGS_DIR = join6(STATE_DIR, "logs");
4996
+ STATE_DIR = join5(homedir4(), ".secondlayer");
4997
+ DEV_STATE_PATH = join5(STATE_DIR, "dev.json");
4998
+ LOGS_DIR = join5(STATE_DIR, "logs");
5118
4999
  });
5119
5000
 
5120
5001
  // src/utils/abi-compat.ts
@@ -5783,9 +5664,9 @@ var init_dist = __esm(() => {
5783
5664
  class PCancelable {
5784
5665
  static fn(userFunction) {
5785
5666
  return (...arguments_) => {
5786
- return new PCancelable((resolve3, reject, onCancel) => {
5667
+ return new PCancelable((resolve2, reject, onCancel) => {
5787
5668
  arguments_.push(onCancel);
5788
- userFunction(...arguments_).then(resolve3, reject);
5669
+ userFunction(...arguments_).then(resolve2, reject);
5789
5670
  });
5790
5671
  };
5791
5672
  }
@@ -5794,12 +5675,12 @@ class PCancelable {
5794
5675
  this._isPending = true;
5795
5676
  this._isCanceled = false;
5796
5677
  this._rejectOnCancel = true;
5797
- this._promise = new Promise((resolve3, reject) => {
5678
+ this._promise = new Promise((resolve2, reject) => {
5798
5679
  this._reject = reject;
5799
5680
  const onResolve = (value) => {
5800
5681
  if (!this._isCanceled || !onCancel.shouldReject) {
5801
5682
  this._isPending = false;
5802
- resolve3(value);
5683
+ resolve2(value);
5803
5684
  }
5804
5685
  };
5805
5686
  const onReject = (error2) => {
@@ -6443,7 +6324,7 @@ var require_get_stream = __commonJS((exports, module) => {
6443
6324
  };
6444
6325
  const { maxBuffer } = options;
6445
6326
  const stream2 = bufferStream(options);
6446
- await new Promise((resolve3, reject) => {
6327
+ await new Promise((resolve2, reject) => {
6447
6328
  const rejectPromise = (error2) => {
6448
6329
  if (error2 && stream2.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
6449
6330
  error2.bufferedData = stream2.getBufferedValue();
@@ -6453,7 +6334,7 @@ var require_get_stream = __commonJS((exports, module) => {
6453
6334
  (async () => {
6454
6335
  try {
6455
6336
  await streamPipelinePromisified(inputStream, stream2);
6456
- resolve3();
6337
+ resolve2();
6457
6338
  } catch (error2) {
6458
6339
  rejectPromise(error2);
6459
6340
  }
@@ -7355,11 +7236,11 @@ class CacheableRequest {
7355
7236
  madeRequest = true;
7356
7237
  let requestErrored = false;
7357
7238
  let requestErrorCallback = () => {};
7358
- const requestErrorPromise = new Promise((resolve3) => {
7239
+ const requestErrorPromise = new Promise((resolve2) => {
7359
7240
  requestErrorCallback = () => {
7360
7241
  if (!requestErrored) {
7361
7242
  requestErrored = true;
7362
- resolve3();
7243
+ resolve2();
7363
7244
  }
7364
7245
  };
7365
7246
  });
@@ -7369,8 +7250,8 @@ class CacheableRequest {
7369
7250
  const revalidatedPolicy = import_http_cache_semantics.default.fromObject(revalidate.cachePolicy).revalidatedPolicy(options_, response);
7370
7251
  if (!revalidatedPolicy.modified) {
7371
7252
  response.resume();
7372
- await new Promise((resolve3) => {
7373
- response.once("end", resolve3);
7253
+ await new Promise((resolve2) => {
7254
+ response.once("end", resolve2);
7374
7255
  });
7375
7256
  const headers = convertHeaders(revalidatedPolicy.policy.responseHeaders());
7376
7257
  response = new Response({ statusCode: revalidate.statusCode, headers, body: revalidate.body, url: revalidate.url });
@@ -7390,8 +7271,8 @@ class CacheableRequest {
7390
7271
  const bodyPromise = import_get_stream.default.buffer(response);
7391
7272
  await Promise.race([
7392
7273
  requestErrorPromise,
7393
- new Promise((resolve3) => response.once("end", resolve3)),
7394
- new Promise((resolve3) => response.once("close", resolve3))
7274
+ new Promise((resolve2) => response.once("end", resolve2)),
7275
+ new Promise((resolve2) => response.once("close", resolve2))
7395
7276
  ]);
7396
7277
  const body = await bodyPromise;
7397
7278
  let value = {
@@ -7722,7 +7603,7 @@ var require_get_stream2 = __commonJS((exports, module) => {
7722
7603
  };
7723
7604
  const { maxBuffer } = options;
7724
7605
  const stream3 = bufferStream(options);
7725
- await new Promise((resolve3, reject) => {
7606
+ await new Promise((resolve2, reject) => {
7726
7607
  const rejectPromise = (error2) => {
7727
7608
  if (error2 && stream3.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
7728
7609
  error2.bufferedData = stream3.getBufferedValue();
@@ -7732,7 +7613,7 @@ var require_get_stream2 = __commonJS((exports, module) => {
7732
7613
  (async () => {
7733
7614
  try {
7734
7615
  await streamPipelinePromisified(inputStream, stream3);
7735
- resolve3();
7616
+ resolve2();
7736
7617
  } catch (error2) {
7737
7618
  rejectPromise(error2);
7738
7619
  }
@@ -8918,12 +8799,12 @@ var require_agent = __commonJS((exports, module) => {
8918
8799
  }
8919
8800
  }
8920
8801
  getSession(origin, options, listeners) {
8921
- return new Promise((resolve3, reject) => {
8802
+ return new Promise((resolve2, reject) => {
8922
8803
  if (Array.isArray(listeners) && listeners.length > 0) {
8923
8804
  listeners = [...listeners];
8924
- resolve3();
8805
+ resolve2();
8925
8806
  } else {
8926
- listeners = [{ resolve: resolve3, reject }];
8807
+ listeners = [{ resolve: resolve2, reject }];
8927
8808
  }
8928
8809
  try {
8929
8810
  if (typeof origin === "string") {
@@ -9202,14 +9083,14 @@ var require_agent = __commonJS((exports, module) => {
9202
9083
  });
9203
9084
  }
9204
9085
  request(origin, options, headers, streamOptions) {
9205
- return new Promise((resolve3, reject) => {
9086
+ return new Promise((resolve2, reject) => {
9206
9087
  this.getSession(origin, options, [{
9207
9088
  reject,
9208
9089
  resolve: (session) => {
9209
9090
  try {
9210
9091
  const stream2 = session.request(headers, streamOptions);
9211
9092
  delayAsyncDestroy(stream2);
9212
- resolve3(stream2);
9093
+ resolve2(stream2);
9213
9094
  } catch (error2) {
9214
9095
  reject(error2);
9215
9096
  }
@@ -9930,7 +9811,7 @@ var require_client_request = __commonJS((exports, module) => {
9930
9811
  // ../../node_modules/resolve-alpn/index.js
9931
9812
  var require_resolve_alpn = __commonJS((exports, module) => {
9932
9813
  var tls2 = __require("tls");
9933
- module.exports = (options = {}, connect = tls2.connect) => new Promise((resolve3, reject) => {
9814
+ module.exports = (options = {}, connect = tls2.connect) => new Promise((resolve2, reject) => {
9934
9815
  let timeout = false;
9935
9816
  let socket;
9936
9817
  const callback = async () => {
@@ -9938,14 +9819,14 @@ var require_resolve_alpn = __commonJS((exports, module) => {
9938
9819
  socket.off("timeout", onTimeout);
9939
9820
  socket.off("error", reject);
9940
9821
  if (options.resolveSocket) {
9941
- resolve3({ alpnProtocol: socket.alpnProtocol, socket, timeout });
9822
+ resolve2({ alpnProtocol: socket.alpnProtocol, socket, timeout });
9942
9823
  if (timeout) {
9943
9824
  await Promise.resolve();
9944
9825
  socket.emit("timeout");
9945
9826
  }
9946
9827
  } else {
9947
9828
  socket.destroy();
9948
- resolve3({ alpnProtocol: socket.alpnProtocol, timeout });
9829
+ resolve2({ alpnProtocol: socket.alpnProtocol, timeout });
9949
9830
  }
9950
9831
  };
9951
9832
  const onTimeout = async () => {
@@ -10348,11 +10229,11 @@ var require_h2_over_h2 = __commonJS((exports, module) => {
10348
10229
  var { globalAgent } = require_agent();
10349
10230
  var Http2OverHttpX = require_h2_over_hx();
10350
10231
  var getAuthorizationHeaders = require_get_auth_headers();
10351
- var getStatusCode = (stream2) => new Promise((resolve3, reject) => {
10232
+ var getStatusCode = (stream2) => new Promise((resolve2, reject) => {
10352
10233
  stream2.once("error", reject);
10353
10234
  stream2.once("response", (headers) => {
10354
10235
  stream2.off("error", reject);
10355
- resolve3(headers[":status"]);
10236
+ resolve2(headers[":status"]);
10356
10237
  });
10357
10238
  });
10358
10239
 
@@ -10379,11 +10260,11 @@ var require_h2_over_h1 = __commonJS((exports, module) => {
10379
10260
  var https = __require("https");
10380
10261
  var Http2OverHttpX = require_h2_over_hx();
10381
10262
  var getAuthorizationHeaders = require_get_auth_headers();
10382
- var getStream2 = (request2) => new Promise((resolve3, reject) => {
10263
+ var getStream2 = (request2) => new Promise((resolve2, reject) => {
10383
10264
  const onConnect = (response, socket, head) => {
10384
10265
  socket.unshift(head);
10385
10266
  request2.off("error", reject);
10386
- resolve3([socket, response.statusCode, response.statusMessage]);
10267
+ resolve2([socket, response.statusCode, response.statusMessage]);
10387
10268
  };
10388
10269
  request2.once("error", reject);
10389
10270
  request2.once("connect", onConnect);
@@ -12008,11 +11889,11 @@ var init_core = __esm(() => {
12008
11889
  return;
12009
11890
  }
12010
11891
  if (backoff2) {
12011
- await new Promise((resolve3) => {
12012
- const timeout = setTimeout(resolve3, backoff2);
11892
+ await new Promise((resolve2) => {
11893
+ const timeout = setTimeout(resolve2, backoff2);
12013
11894
  this._stopRetry = () => {
12014
11895
  clearTimeout(timeout);
12015
- resolve3();
11896
+ resolve2();
12016
11897
  };
12017
11898
  });
12018
11899
  if (this.destroyed) {
@@ -12388,13 +12269,13 @@ var init_core = __esm(() => {
12388
12269
  this.emit("request", request2);
12389
12270
  }
12390
12271
  async _asyncWrite(chunk) {
12391
- return new Promise((resolve3, reject) => {
12272
+ return new Promise((resolve2, reject) => {
12392
12273
  super.write(chunk, (error2) => {
12393
12274
  if (error2) {
12394
12275
  reject(error2);
12395
12276
  return;
12396
12277
  }
12397
- resolve3();
12278
+ resolve2();
12398
12279
  });
12399
12280
  });
12400
12281
  }
@@ -12454,7 +12335,7 @@ var init_core = __esm(() => {
12454
12335
  }
12455
12336
  }
12456
12337
  async _createCacheableRequest(url, options) {
12457
- return new Promise((resolve3, reject) => {
12338
+ return new Promise((resolve2, reject) => {
12458
12339
  Object.assign(options, urlToOptions(url));
12459
12340
  let request2;
12460
12341
  const cacheRequest = cacheableStore.get(options.cache)(options, async (response) => {
@@ -12469,12 +12350,12 @@ var init_core = __esm(() => {
12469
12350
  fix();
12470
12351
  (await request2).emit("cacheableResponse", response);
12471
12352
  }
12472
- resolve3(response);
12353
+ resolve2(response);
12473
12354
  });
12474
12355
  cacheRequest.once("error", reject);
12475
12356
  cacheRequest.once("request", async (requestOrPromise) => {
12476
12357
  request2 = requestOrPromise;
12477
- resolve3(request2);
12358
+ resolve2(request2);
12478
12359
  });
12479
12360
  });
12480
12361
  }
@@ -12652,7 +12533,7 @@ function asPromise(firstRequest) {
12652
12533
  let globalResponse;
12653
12534
  let normalizedOptions;
12654
12535
  const emitter = new EventEmitter2;
12655
- const promise = new PCancelable((resolve3, reject, onCancel) => {
12536
+ const promise = new PCancelable((resolve2, reject, onCancel) => {
12656
12537
  onCancel(() => {
12657
12538
  globalRequest.destroy();
12658
12539
  });
@@ -12709,7 +12590,7 @@ function asPromise(firstRequest) {
12709
12590
  return;
12710
12591
  }
12711
12592
  request2.destroy();
12712
- resolve3(request2.options.resolveBodyOnly ? response.body : response);
12593
+ resolve2(request2.options.resolveBodyOnly ? response.body : response);
12713
12594
  });
12714
12595
  const onError = (error2) => {
12715
12596
  if (promise.isCanceled) {
@@ -12719,7 +12600,7 @@ function asPromise(firstRequest) {
12719
12600
  if (error2 instanceof HTTPError && !options.throwHttpErrors) {
12720
12601
  const { response } = error2;
12721
12602
  request2.destroy();
12722
- resolve3(request2.options.resolveBodyOnly ? response.body : response);
12603
+ resolve2(request2.options.resolveBodyOnly ? response.body : response);
12723
12604
  return;
12724
12605
  }
12725
12606
  reject(error2);
@@ -12792,8 +12673,8 @@ var init_as_promise = __esm(() => {
12792
12673
  });
12793
12674
 
12794
12675
  // ../../node_modules/got/dist/source/create.js
12795
- var delay = async (ms) => new Promise((resolve3) => {
12796
- setTimeout(resolve3, ms);
12676
+ var delay = async (ms) => new Promise((resolve2) => {
12677
+ setTimeout(resolve2, ms);
12797
12678
  }), isGotInstance = (value) => dist_default.function_(value), aliases, create = (defaults) => {
12798
12679
  defaults = {
12799
12680
  options: new Options(undefined, undefined, defaults.options),
@@ -13467,11 +13348,11 @@ var init_manager = __esm(() => {
13467
13348
  });
13468
13349
 
13469
13350
  // src/services/indexer.ts
13470
- import { dirname as dirname5, resolve as resolve4 } from "node:path";
13351
+ import { dirname as dirname4, resolve as resolve3 } from "node:path";
13471
13352
  async function startIndexer(options2) {
13472
13353
  const port = options2.port ?? 3700;
13473
- const rootDir = dirname5(dirname5(dirname5(dirname5(import.meta.dir))));
13474
- const indexerPath = resolve4(rootDir, "packages/indexer/src/index.ts");
13354
+ const rootDir = dirname4(dirname4(dirname4(dirname4(import.meta.dir))));
13355
+ const indexerPath = resolve3(rootDir, "packages/indexer/src/index.ts");
13475
13356
  await serviceManager.start(SERVICE_NAME, ["bun", "run", "--watch", indexerPath], {
13476
13357
  port,
13477
13358
  env: {
@@ -13487,10 +13368,10 @@ var init_indexer = __esm(() => {
13487
13368
  });
13488
13369
 
13489
13370
  // src/services/worker.ts
13490
- import { dirname as dirname6, resolve as resolve5 } from "node:path";
13371
+ import { dirname as dirname5, resolve as resolve4 } from "node:path";
13491
13372
  async function startWorker(options2) {
13492
- const rootDir = dirname6(dirname6(dirname6(dirname6(import.meta.dir))));
13493
- const workerPath = resolve5(rootDir, "packages/worker/src/index.ts");
13373
+ const rootDir = dirname5(dirname5(dirname5(dirname5(import.meta.dir))));
13374
+ const workerPath = resolve4(rootDir, "packages/worker/src/index.ts");
13494
13375
  await serviceManager.start(SERVICE_NAME2, ["bun", "run", "--watch", workerPath], {
13495
13376
  onStdout: options2.onLog,
13496
13377
  onStderr: options2.onLog
@@ -13502,11 +13383,11 @@ var init_worker = __esm(() => {
13502
13383
  });
13503
13384
 
13504
13385
  // src/services/api.ts
13505
- import { dirname as dirname7, resolve as resolve6 } from "node:path";
13386
+ import { dirname as dirname6, resolve as resolve5 } from "node:path";
13506
13387
  async function startApi(options2) {
13507
13388
  const port = options2.port ?? 3800;
13508
- const rootDir = dirname7(dirname7(dirname7(dirname7(import.meta.dir))));
13509
- const apiPath = resolve6(rootDir, "packages/api/src/index.ts");
13389
+ const rootDir = dirname6(dirname6(dirname6(dirname6(import.meta.dir))));
13390
+ const apiPath = resolve5(rootDir, "packages/api/src/index.ts");
13510
13391
  await serviceManager.start(SERVICE_NAME3, ["bun", "run", "--watch", apiPath], {
13511
13392
  port,
13512
13393
  env: {
@@ -13522,10 +13403,10 @@ var init_api2 = __esm(() => {
13522
13403
  });
13523
13404
 
13524
13405
  // src/services/subgraph-processor.ts
13525
- import { dirname as dirname8, resolve as resolve7 } from "node:path";
13406
+ import { dirname as dirname7, resolve as resolve6 } from "node:path";
13526
13407
  async function startSubgraphProcessor(options2) {
13527
- const rootDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
13528
- const servicePath = resolve7(rootDir, "packages/subgraphs/src/service.ts");
13408
+ const rootDir = dirname7(dirname7(dirname7(dirname7(import.meta.dir))));
13409
+ const servicePath = resolve6(rootDir, "packages/subgraphs/src/service.ts");
13529
13410
  await serviceManager.start(SERVICE_NAME4, ["bun", "run", "--watch", servicePath], {
13530
13411
  env: {
13531
13412
  SUBGRAPH_CONCURRENCY: String(options2.concurrency ?? 5)
@@ -13560,7 +13441,7 @@ __export(exports_dev_impl, {
13560
13441
  isDevAlreadyRunning: () => isDevAlreadyRunning
13561
13442
  });
13562
13443
  import { mkdirSync as mkdirSync3 } from "node:fs";
13563
- import { dirname as dirname9, join as join8, resolve as resolve8 } from "node:path";
13444
+ import { dirname as dirname8, join as join7, resolve as resolve7 } from "node:path";
13564
13445
  async function isDevAlreadyRunning() {
13565
13446
  if (await isDevRunning()) {
13566
13447
  const running = await getRunningServices();
@@ -13638,10 +13519,10 @@ async function runBackground(options2) {
13638
13519
  startedAt: new Date().toISOString()
13639
13520
  };
13640
13521
  try {
13641
- const packagesDir = dirname9(dirname9(dirname9(dirname9(import.meta.dir))));
13522
+ const packagesDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
13642
13523
  const env = { DATABASE_URL: databaseUrl, DEV_MODE: "true" };
13643
13524
  const apiLogFile = getLogFile("api");
13644
- const apiProc = Bun.spawn(["bun", "run", resolve8(packagesDir, "packages/api/src/index.ts")], {
13525
+ const apiProc = Bun.spawn(["bun", "run", resolve7(packagesDir, "packages/api/src/index.ts")], {
13645
13526
  env: { ...process.env, ...env, PORT: String(apiPort) },
13646
13527
  stdout: Bun.file(apiLogFile),
13647
13528
  stderr: Bun.file(apiLogFile)
@@ -13654,7 +13535,7 @@ async function runBackground(options2) {
13654
13535
  };
13655
13536
  console.log(green(" ✓ API"), dim(`http://localhost:${apiPort}`));
13656
13537
  const indexerLogFile = getLogFile("indexer");
13657
- const indexerProc = Bun.spawn(["bun", "run", resolve8(packagesDir, "packages/indexer/src/index.ts")], {
13538
+ const indexerProc = Bun.spawn(["bun", "run", resolve7(packagesDir, "packages/indexer/src/index.ts")], {
13658
13539
  env: { ...process.env, ...env, PORT: String(indexerPort) },
13659
13540
  stdout: Bun.file(indexerLogFile),
13660
13541
  stderr: Bun.file(indexerLogFile)
@@ -13668,7 +13549,7 @@ async function runBackground(options2) {
13668
13549
  console.log(green(" ✓ Indexer"), dim(`http://localhost:${indexerPort}`));
13669
13550
  if (options2.worker) {
13670
13551
  const workerLogFile = getLogFile("worker");
13671
- const workerProc = Bun.spawn(["bun", "run", resolve8(packagesDir, "packages/worker/src/index.ts")], {
13552
+ const workerProc = Bun.spawn(["bun", "run", resolve7(packagesDir, "packages/worker/src/index.ts")], {
13672
13553
  env: { ...process.env, ...env },
13673
13554
  stdout: Bun.file(workerLogFile),
13674
13555
  stderr: Bun.file(workerLogFile)
@@ -13686,7 +13567,7 @@ async function runBackground(options2) {
13686
13567
  const subgraphsProc = Bun.spawn([
13687
13568
  "bun",
13688
13569
  "run",
13689
- resolve8(packagesDir, "packages/subgraphs/src/service.ts")
13570
+ resolve7(packagesDir, "packages/subgraphs/src/service.ts")
13690
13571
  ], {
13691
13572
  env: { ...process.env, ...env },
13692
13573
  stdout: Bun.file(subgraphsLogFile),
@@ -13988,7 +13869,7 @@ async function restartDev() {
13988
13869
  await clearDevState();
13989
13870
  await clearLogs();
13990
13871
  const config = await loadConfig();
13991
- const packagesDir = dirname9(dirname9(dirname9(dirname9(import.meta.dir))));
13872
+ const packagesDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
13992
13873
  const env = state.env;
13993
13874
  const newState = {
13994
13875
  services: {},
@@ -13998,7 +13879,7 @@ async function restartDev() {
13998
13879
  };
13999
13880
  const apiPort = config.ports.api;
14000
13881
  const apiLogFile = getLogFile("api");
14001
- const apiProc = Bun.spawn(["bun", "run", resolve8(packagesDir, "packages/api/src/index.ts")], {
13882
+ const apiProc = Bun.spawn(["bun", "run", resolve7(packagesDir, "packages/api/src/index.ts")], {
14002
13883
  env: { ...process.env, ...env, PORT: String(apiPort) },
14003
13884
  stdout: Bun.file(apiLogFile),
14004
13885
  stderr: Bun.file(apiLogFile)
@@ -14012,7 +13893,7 @@ async function restartDev() {
14012
13893
  console.log(green(" ✓ API"), dim(`http://localhost:${apiPort}`));
14013
13894
  const indexerPort = config.ports.indexer;
14014
13895
  const indexerLogFile = getLogFile("indexer");
14015
- const indexerProc = Bun.spawn(["bun", "run", resolve8(packagesDir, "packages/indexer/src/index.ts")], {
13896
+ const indexerProc = Bun.spawn(["bun", "run", resolve7(packagesDir, "packages/indexer/src/index.ts")], {
14016
13897
  env: { ...process.env, ...env, PORT: String(indexerPort) },
14017
13898
  stdout: Bun.file(indexerLogFile),
14018
13899
  stderr: Bun.file(indexerLogFile)
@@ -14026,7 +13907,7 @@ async function restartDev() {
14026
13907
  console.log(green(" ✓ Indexer"), dim(`http://localhost:${indexerPort}`));
14027
13908
  if (state.services.worker) {
14028
13909
  const workerLogFile = getLogFile("worker");
14029
- const workerProc = Bun.spawn(["bun", "run", resolve8(packagesDir, "packages/worker/src/index.ts")], {
13910
+ const workerProc = Bun.spawn(["bun", "run", resolve7(packagesDir, "packages/worker/src/index.ts")], {
14030
13911
  env: { ...process.env, ...env },
14031
13912
  stdout: Bun.file(workerLogFile),
14032
13913
  stderr: Bun.file(workerLogFile)
@@ -14041,7 +13922,7 @@ async function restartDev() {
14041
13922
  }
14042
13923
  if (state.services.subgraphs) {
14043
13924
  const subgraphsLogFile = getLogFile("subgraphs");
14044
- const subgraphsProc = Bun.spawn(["bun", "run", resolve8(packagesDir, "packages/subgraphs/src/service.ts")], {
13925
+ const subgraphsProc = Bun.spawn(["bun", "run", resolve7(packagesDir, "packages/subgraphs/src/service.ts")], {
14045
13926
  env: { ...process.env, ...env },
14046
13927
  stdout: Bun.file(subgraphsLogFile),
14047
13928
  stderr: Bun.file(subgraphsLogFile)
@@ -14169,7 +14050,7 @@ async function ensureDevPostgres(dataDir) {
14169
14050
  if (check.stdout.toString().trim()) {
14170
14051
  return false;
14171
14052
  }
14172
- const pgDataDir = join8(dataDir, "postgres");
14053
+ const pgDataDir = join7(dataDir, "postgres");
14173
14054
  mkdirSync3(pgDataDir, { recursive: true });
14174
14055
  const stopped = await Bun.$`docker ps -aq -f name=secondlayer-dev-postgres`.quiet().nothrow();
14175
14056
  if (stopped.stdout.toString().trim()) {
@@ -14185,8 +14066,8 @@ async function ensureDevPostgres(dataDir) {
14185
14066
  throw new Error("PostgreSQL failed to start");
14186
14067
  }
14187
14068
  async function runMigrations(databaseUrl) {
14188
- const packagesDir = dirname9(dirname9(dirname9(dirname9(import.meta.dir))));
14189
- const migrateScript = resolve8(packagesDir, "packages/shared/src/db/migrate.ts");
14069
+ const packagesDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
14070
+ const migrateScript = resolve7(packagesDir, "packages/shared/src/db/migrate.ts");
14190
14071
  const result = await Bun.$`DATABASE_URL=${databaseUrl} bun run ${migrateScript}`.quiet().nothrow();
14191
14072
  if (result.exitCode !== 0) {
14192
14073
  throw new Error(`Migration failed: ${result.stderr.toString()}`);
@@ -32443,7 +32324,7 @@ var {
32443
32324
  // package.json
32444
32325
  var package_default = {
32445
32326
  name: "@secondlayer/cli",
32446
- version: "5.1.5",
32327
+ version: "5.2.0",
32447
32328
  description: "CLI for subgraphs and blockchain indexing on Stacks",
32448
32329
  type: "module",
32449
32330
  bin: {
@@ -32486,8 +32367,8 @@ var package_default = {
32486
32367
  dependencies: {
32487
32368
  "@inquirer/prompts": "^8.2.0",
32488
32369
  "@secondlayer/bundler": "^0.3.5",
32489
- "@secondlayer/sdk": "^3.5.4",
32490
- "@secondlayer/shared": "^6.3.2",
32370
+ "@secondlayer/sdk": "^3.6.0",
32371
+ "@secondlayer/shared": "^6.3.4",
32491
32372
  "@secondlayer/stacks": "^2.2.0",
32492
32373
  "@secondlayer/subgraphs": "^2.0.0",
32493
32374
  "@biomejs/js-api": "^0.7.0",
@@ -32511,23 +32392,75 @@ var package_default = {
32511
32392
  };
32512
32393
 
32513
32394
  // src/lib/api-client.ts
32514
- init_http();
32515
- init_resolve_tenant();
32516
32395
  import { ApiError, SecondLayer } from "@secondlayer/sdk";
32396
+
32397
+ // src/lib/http.ts
32398
+ init_session();
32399
+
32400
+ class CliHttpError extends Error {
32401
+ status;
32402
+ code;
32403
+ body;
32404
+ name = "CliHttpError";
32405
+ constructor(status, code, body, message) {
32406
+ super(message);
32407
+ this.status = status;
32408
+ this.code = code;
32409
+ this.body = body;
32410
+ }
32411
+ }
32412
+ var PLATFORM_API_URL = process.env.SL_PLATFORM_API_URL ?? "https://api.secondlayer.tools";
32413
+ var REQUEST_TIMEOUT_MS = 30000;
32414
+ async function request(url, opts) {
32415
+ const headers = {
32416
+ "content-type": "application/json",
32417
+ ...opts.headers ?? {}
32418
+ };
32419
+ if (opts.bearer)
32420
+ headers.authorization = `Bearer ${opts.bearer}`;
32421
+ const res = await fetch(url, {
32422
+ method: opts.method ?? "GET",
32423
+ headers,
32424
+ body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
32425
+ signal: AbortSignal.timeout(opts.timeoutMs ?? REQUEST_TIMEOUT_MS)
32426
+ });
32427
+ if (!res.ok) {
32428
+ let body = {};
32429
+ try {
32430
+ body = await res.json();
32431
+ } catch {
32432
+ body = { error: await res.text().catch(() => "") };
32433
+ }
32434
+ const code = body.code ?? (res.status === 401 ? "SESSION_EXPIRED" : res.status === 404 ? "NOT_FOUND" : `HTTP_${res.status}`);
32435
+ const message = body.message ?? body.error ?? `HTTP ${res.status}`;
32436
+ throw new CliHttpError(res.status, code, body, message);
32437
+ }
32438
+ if (res.status === 204)
32439
+ return;
32440
+ return await res.json();
32441
+ }
32442
+ async function httpPlatform(path2, opts = {}) {
32443
+ const session = await readSession();
32444
+ if (!session) {
32445
+ throw new CliHttpError(401, "SESSION_EXPIRED", { error: "Not logged in" }, "Not logged in — run `sl login`");
32446
+ }
32447
+ return request(`${PLATFORM_API_URL}${path2}`, {
32448
+ ...opts,
32449
+ bearer: session.token
32450
+ });
32451
+ }
32452
+ async function httpPlatformAnon(path2, opts = {}) {
32453
+ return request(`${PLATFORM_API_URL}${path2}`, opts);
32454
+ }
32455
+
32456
+ // src/lib/api-client.ts
32457
+ init_resolve_tenant();
32517
32458
  function handleApiError(err, action) {
32518
32459
  if (err instanceof CliHttpError) {
32519
32460
  if (err.code === "SESSION_EXPIRED") {
32520
32461
  console.error("Session expired. Run: sl login");
32521
32462
  process.exit(1);
32522
32463
  }
32523
- if (err.code === "TENANT_SUSPENDED") {
32524
- console.error("Tenant is suspended. Run: sl instance resume");
32525
- process.exit(1);
32526
- }
32527
- if (err.code === "NO_TENANT_FOR_PROJECT") {
32528
- console.error(err.message);
32529
- process.exit(1);
32530
- }
32531
32464
  }
32532
32465
  if (err instanceof ApiError && err.status === 401) {
32533
32466
  console.error("Authentication required. Run: sl login");
@@ -32549,48 +32482,48 @@ function withErrorHandling(fn, options) {
32549
32482
  }
32550
32483
  };
32551
32484
  }
32552
- async function getTenantClient() {
32485
+ async function getPlatformClient() {
32553
32486
  const { apiUrl, ephemeralKey } = await resolveActiveTenant();
32554
- return new SecondLayer({ tenantBaseUrl: apiUrl, apiKey: ephemeralKey });
32487
+ return new SecondLayer({ baseUrl: apiUrl, apiKey: ephemeralKey });
32555
32488
  }
32556
32489
  async function listSubgraphsApi() {
32557
- return (await getTenantClient()).subgraphs.list();
32490
+ return (await getPlatformClient()).subgraphs.list();
32558
32491
  }
32559
32492
  async function getSubgraphApi(name) {
32560
- return (await getTenantClient()).subgraphs.get(name);
32493
+ return (await getPlatformClient()).subgraphs.get(name);
32561
32494
  }
32562
32495
  async function getSubgraphOpenApi(name, options) {
32563
- return (await getTenantClient()).subgraphs.openapi(name, options);
32496
+ return (await getPlatformClient()).subgraphs.openapi(name, options);
32564
32497
  }
32565
32498
  async function getSubgraphAgentSchema(name, options) {
32566
- return (await getTenantClient()).subgraphs.schema(name, options);
32499
+ return (await getPlatformClient()).subgraphs.schema(name, options);
32567
32500
  }
32568
32501
  async function getSubgraphMarkdown(name, options) {
32569
- return (await getTenantClient()).subgraphs.markdown(name, options);
32502
+ return (await getPlatformClient()).subgraphs.markdown(name, options);
32570
32503
  }
32571
32504
  async function reindexSubgraphApi(name, options) {
32572
- return (await getTenantClient()).subgraphs.reindex(name, options);
32505
+ return (await getPlatformClient()).subgraphs.reindex(name, options);
32573
32506
  }
32574
32507
  async function backfillSubgraphApi(name, options) {
32575
- return (await getTenantClient()).subgraphs.backfill(name, options);
32508
+ return (await getPlatformClient()).subgraphs.backfill(name, options);
32576
32509
  }
32577
32510
  async function stopSubgraphApi(name) {
32578
- return (await getTenantClient()).subgraphs.stop(name);
32511
+ return (await getPlatformClient()).subgraphs.stop(name);
32579
32512
  }
32580
32513
  async function deleteSubgraphApi(name, options) {
32581
- return (await getTenantClient()).subgraphs.delete(name, options);
32514
+ return (await getPlatformClient()).subgraphs.delete(name, options);
32582
32515
  }
32583
32516
  async function deploySubgraphApi(data) {
32584
- return (await getTenantClient()).subgraphs.deploy(data);
32517
+ return (await getPlatformClient()).subgraphs.deploy(data);
32585
32518
  }
32586
32519
  async function querySubgraphTable(name, table, params = {}) {
32587
- return (await getTenantClient()).subgraphs.queryTable(name, table, params);
32520
+ return (await getPlatformClient()).subgraphs.queryTable(name, table, params);
32588
32521
  }
32589
32522
  async function querySubgraphTableCount(name, table, params = {}) {
32590
- return (await getTenantClient()).subgraphs.queryTableCount(name, table, params);
32523
+ return (await getPlatformClient()).subgraphs.queryTableCount(name, table, params);
32591
32524
  }
32592
32525
  async function getSubgraphGaps(name, opts) {
32593
- return (await getTenantClient()).subgraphs.gaps(name, opts);
32526
+ return (await getPlatformClient()).subgraphs.gaps(name, opts);
32594
32527
  }
32595
32528
  async function getAccountProfile() {
32596
32529
  return httpPlatform("/api/accounts/me");
@@ -32641,7 +32574,6 @@ function registerAccountCommand(program2) {
32641
32574
  }, { action: "manage profile" }));
32642
32575
  }
32643
32576
  // src/commands/billing.ts
32644
- init_http();
32645
32577
  init_output();
32646
32578
  function registerBillingCommand(program2) {
32647
32579
  const billing = program2.command("billing").description("Inspect billing state");
@@ -32704,8 +32636,8 @@ init_config();
32704
32636
 
32705
32637
  // src/lib/detect.ts
32706
32638
  init_docker();
32707
- import { homedir as homedir4 } from "node:os";
32708
- import { join as join4 } from "node:path";
32639
+ import { homedir as homedir3 } from "node:os";
32640
+ import { join as join3 } from "node:path";
32709
32641
  var STACKS_CONTAINER_PATTERNS = [
32710
32642
  "stacks-blockchain",
32711
32643
  "stacks-node",
@@ -32773,8 +32705,8 @@ async function findDockerComposeRoot(startPath) {
32773
32705
  let current = startPath;
32774
32706
  while (current && current !== "/") {
32775
32707
  try {
32776
- const composeYml = Bun.file(join4(current, "docker-compose.yml"));
32777
- const composeYaml = Bun.file(join4(current, "docker-compose.yaml"));
32708
+ const composeYml = Bun.file(join3(current, "docker-compose.yml"));
32709
+ const composeYaml = Bun.file(join3(current, "docker-compose.yaml"));
32778
32710
  if (await composeYml.exists() || await composeYaml.exists()) {
32779
32711
  return current;
32780
32712
  }
@@ -32821,9 +32753,9 @@ var SEARCH_PATTERNS = [
32821
32753
  "/Volumes/stacks-node",
32822
32754
  "/Volumes/*/stacks-blockchain-docker",
32823
32755
  "/Volumes/*/stacks-node",
32824
- `${homedir4()}/stacks-blockchain-docker`,
32825
- `${homedir4()}/stacks-node`,
32826
- `${homedir4()}/stacks-*`,
32756
+ `${homedir3()}/stacks-blockchain-docker`,
32757
+ `${homedir3()}/stacks-node`,
32758
+ `${homedir3()}/stacks-*`,
32827
32759
  "/opt/stacks-blockchain-docker",
32828
32760
  "/opt/stacks-node",
32829
32761
  "/opt/stacks-*"
@@ -32870,8 +32802,8 @@ async function isValidStacksNodeDir(path2) {
32870
32802
  return true;
32871
32803
  }
32872
32804
  try {
32873
- const composeYml = Bun.file(join4(path2, "docker-compose.yml"));
32874
- const composeYaml = Bun.file(join4(path2, "docker-compose.yaml"));
32805
+ const composeYml = Bun.file(join3(path2, "docker-compose.yml"));
32806
+ const composeYaml = Bun.file(join3(path2, "docker-compose.yaml"));
32875
32807
  const hasCompose = await composeYml.exists() || await composeYaml.exists();
32876
32808
  if (!hasCompose) {
32877
32809
  return false;
@@ -32884,7 +32816,7 @@ async function isValidStacksNodeDir(path2) {
32884
32816
  }
32885
32817
  }
32886
32818
  async function detectNetworkFromFilesystem(path2) {
32887
- const envFile = Bun.file(join4(path2, ".env"));
32819
+ const envFile = Bun.file(join3(path2, ".env"));
32888
32820
  if (await envFile.exists()) {
32889
32821
  try {
32890
32822
  const content = await envFile.text();
@@ -32896,12 +32828,12 @@ async function detectNetworkFromFilesystem(path2) {
32896
32828
  }
32897
32829
  } catch {}
32898
32830
  }
32899
- const testnetConfig = Bun.file(join4(path2, "configurations/testnet"));
32900
- const mainnetConfig = Bun.file(join4(path2, "configurations/mainnet"));
32901
- const activeConfig = Bun.file(join4(path2, "configurations/active"));
32831
+ const testnetConfig = Bun.file(join3(path2, "configurations/testnet"));
32832
+ const mainnetConfig = Bun.file(join3(path2, "configurations/mainnet"));
32833
+ const activeConfig = Bun.file(join3(path2, "configurations/active"));
32902
32834
  if (await activeConfig.exists()) {
32903
32835
  try {
32904
- const result = await Bun.$`readlink ${join4(path2, "configurations/active")}`.quiet().nothrow();
32836
+ const result = await Bun.$`readlink ${join3(path2, "configurations/active")}`.quiet().nothrow();
32905
32837
  const link = result.stdout.toString().trim();
32906
32838
  if (link.includes("testnet"))
32907
32839
  return "testnet";
@@ -32914,7 +32846,7 @@ async function detectNetworkFromFilesystem(path2) {
32914
32846
  }
32915
32847
  async function isComposeProjectRunning(path2) {
32916
32848
  try {
32917
- const result = await Bun.$`docker compose -f ${join4(path2, "docker-compose.yml")} ps -q`.quiet().nothrow();
32849
+ const result = await Bun.$`docker compose -f ${join3(path2, "docker-compose.yml")} ps -q`.quiet().nothrow();
32918
32850
  return result.exitCode === 0 && result.stdout.toString().trim().length > 0;
32919
32851
  } catch {
32920
32852
  return false;
@@ -33066,14 +32998,14 @@ async function validateDatabaseConnection(url) {
33066
32998
  // src/commands/create.ts
33067
32999
  import {
33068
33000
  copyFileSync,
33069
- existsSync as existsSync2,
33001
+ existsSync,
33070
33002
  mkdirSync,
33071
33003
  readFileSync,
33072
33004
  readdirSync,
33073
33005
  statSync,
33074
33006
  writeFileSync
33075
33007
  } from "node:fs";
33076
- import { dirname as dirname3, join as join5, relative, resolve as resolve2 } from "node:path";
33008
+ import { dirname as dirname2, join as join4, relative, resolve } from "node:path";
33077
33009
  import { fileURLToPath } from "node:url";
33078
33010
  import { input, select as select2 } from "@inquirer/prompts";
33079
33011
  import { SecondLayer as SecondLayer2 } from "@secondlayer/sdk";
@@ -33175,21 +33107,21 @@ var FORMAT_BY_RUNTIME = {
33175
33107
  node: "standard-webhooks"
33176
33108
  };
33177
33109
  function templatesRoot() {
33178
- const here = dirname3(fileURLToPath(import.meta.url));
33179
- const candidateDist = resolve2(here, "..", "templates", "subscriptions");
33180
- if (existsSync2(candidateDist))
33110
+ const here = dirname2(fileURLToPath(import.meta.url));
33111
+ const candidateDist = resolve(here, "..", "templates", "subscriptions");
33112
+ if (existsSync(candidateDist))
33181
33113
  return candidateDist;
33182
- return resolve2(here, "..", "..", "templates", "subscriptions");
33114
+ return resolve(here, "..", "..", "templates", "subscriptions");
33183
33115
  }
33184
33116
  function copyTemplate(src, dest, vars) {
33185
- if (!existsSync2(src)) {
33117
+ if (!existsSync(src)) {
33186
33118
  throw new Error(`template dir missing: ${src}`);
33187
33119
  }
33188
33120
  mkdirSync(dest, { recursive: true });
33189
33121
  const entries = readdirSync(src);
33190
33122
  for (const entry of entries) {
33191
- const from = join5(src, entry);
33192
- const to = join5(dest, entry);
33123
+ const from = join4(src, entry);
33124
+ const to = join4(dest, entry);
33193
33125
  const st = statSync(from);
33194
33126
  if (st.isDirectory()) {
33195
33127
  copyTemplate(from, to, vars);
@@ -33254,13 +33186,13 @@ async function createSubscription(name, opts) {
33254
33186
  }
33255
33187
  }
33256
33188
  const eventName = `${subgraph}.${table}.created`;
33257
- const targetDir = resolve2(process.cwd(), name);
33258
- if (existsSync2(targetDir)) {
33189
+ const targetDir = resolve(process.cwd(), name);
33190
+ if (existsSync(targetDir)) {
33259
33191
  error(`Directory already exists: ${relative(process.cwd(), targetDir)}`);
33260
33192
  process.exit(1);
33261
33193
  }
33262
33194
  const tplRoot = templatesRoot();
33263
- const tplDir = join5(tplRoot, runtime);
33195
+ const tplDir = join4(tplRoot, runtime);
33264
33196
  info(`Scaffolding ${blue(runtime)} template at ${blue(targetDir)}`);
33265
33197
  copyTemplate(tplDir, targetDir, {
33266
33198
  NAME: name,
@@ -33292,12 +33224,12 @@ async function createSubscription(name, opts) {
33292
33224
  }
33293
33225
  }
33294
33226
  if (signingSecret) {
33295
- const envTarget = join5(targetDir, ".env");
33296
- const envExample = join5(targetDir, ".env.example");
33297
- if (existsSync2(envExample) && !existsSync2(envTarget)) {
33227
+ const envTarget = join4(targetDir, ".env");
33228
+ const envExample = join4(targetDir, ".env.example");
33229
+ if (existsSync(envExample) && !existsSync(envTarget)) {
33298
33230
  copyFileSync(envExample, envTarget);
33299
33231
  }
33300
- if (existsSync2(envTarget)) {
33232
+ if (existsSync(envTarget)) {
33301
33233
  const cur = readFileSync(envTarget, "utf8");
33302
33234
  const next = cur.replace(/^SIGNING_SECRET=.*/m, `SIGNING_SECRET=${signingSecret}`);
33303
33235
  writeFileSync(envTarget, next.includes("SIGNING_SECRET=") ? next : `${cur}
@@ -33358,7 +33290,6 @@ function registerCreateCommand(program2) {
33358
33290
  }
33359
33291
  // src/commands/status.ts
33360
33292
  init_config();
33361
- init_http();
33362
33293
  init_output();
33363
33294
  function registerStatusCommand(program2) {
33364
33295
  program2.command("status").description("Show system status").option("--json", "Output as JSON").action(async (options) => {
@@ -34389,13 +34320,13 @@ async function resyncDatabase(skipConfirm, backfill) {
34389
34320
  // src/commands/subgraphs.ts
34390
34321
  import { spawn } from "node:child_process";
34391
34322
  import {
34392
- existsSync as existsSync3,
34323
+ existsSync as existsSync2,
34393
34324
  mkdirSync as mkdirSync2,
34394
34325
  readFileSync as readFileSync2,
34395
34326
  watch,
34396
34327
  writeFileSync as writeFileSync2
34397
34328
  } from "node:fs";
34398
- import { dirname as dirname4, join as join7, resolve as resolve3 } from "node:path";
34329
+ import { dirname as dirname3, join as join6, resolve as resolve2 } from "node:path";
34399
34330
  import { fileURLToPath as fileURLToPath2 } from "node:url";
34400
34331
  import { confirm as confirm3 } from "@inquirer/prompts";
34401
34332
 
@@ -34603,10 +34534,9 @@ init_fs();
34603
34534
  init_output();
34604
34535
 
34605
34536
  // src/commands/login.ts
34606
- init_http();
34537
+ import { input as input2 } from "@inquirer/prompts";
34607
34538
  init_output();
34608
34539
  init_session();
34609
- import { input as input2 } from "@inquirer/prompts";
34610
34540
  async function runLoginFlow() {
34611
34541
  const email = await input2({
34612
34542
  message: "Email",
@@ -34646,7 +34576,7 @@ async function runLoginFlow() {
34646
34576
  expiresAt
34647
34577
  });
34648
34578
  success(`Logged in as ${verified.account.email}`);
34649
- await printPostLoginHints();
34579
+ info(dim("Run 'sl whoami' to see your account status."));
34650
34580
  } catch (err) {
34651
34581
  if (err instanceof CliHttpError) {
34652
34582
  error(err.message);
@@ -34656,38 +34586,6 @@ async function runLoginFlow() {
34656
34586
  process.exit(1);
34657
34587
  }
34658
34588
  }
34659
- async function printPostLoginHints() {
34660
- let hasTenant = false;
34661
- try {
34662
- const tenant = await httpPlatform("/api/tenants/me");
34663
- hasTenant = Boolean(tenant.tenant?.apiUrl);
34664
- } catch (err) {
34665
- if (!(err instanceof CliHttpError && err.status === 404)) {
34666
- info(dim("Run 'sl whoami' to see your account status."));
34667
- return;
34668
- }
34669
- }
34670
- if (hasTenant) {
34671
- info(dim("Run 'sl whoami' to see your account status."));
34672
- return;
34673
- }
34674
- console.log();
34675
- info("First time? Here's the path to your first query:");
34676
- console.log();
34677
- console.log(dim(" 1. ") + cyan("sl project create my-app"));
34678
- console.log(dim(" ") + dim("# scopes your data and routing — pick any name"));
34679
- console.log();
34680
- console.log(dim(" 2. ") + cyan("sl instance create --plan launch"));
34681
- console.log(dim(" ") + dim("# $99/mo · 2 vCPU / 6GB · run `sl --help` for other plans"));
34682
- console.log();
34683
- console.log(dim(" 3. ") + cyan("sl subgraphs new my-watcher --template sip-010-balances"));
34684
- console.log(dim(" ") + dim("# five templates ship with the CLI"));
34685
- console.log();
34686
- console.log(dim(" 4. ") + cyan("sl subgraphs deploy subgraphs/my-watcher.ts"));
34687
- console.log(dim(" ") + dim("# six seconds, backfill auto-starts"));
34688
- console.log();
34689
- info(dim("Run `sl whoami` at any time to see where you are in the flow."));
34690
- }
34691
34589
  function registerLoginCommand(program2) {
34692
34590
  program2.command("login").description("Log in to Secondlayer (magic-link email)").action(runLoginFlow);
34693
34591
  }
@@ -35110,9 +35008,9 @@ async function writeOrPrintSubgraphSpec(spec, format, output) {
35110
35008
  process.stdout.write(text);
35111
35009
  return;
35112
35010
  }
35113
- const outPath = resolve3(output);
35114
- const dir = resolve3(outPath, "..");
35115
- if (!existsSync3(dir))
35011
+ const outPath = resolve2(output);
35012
+ const dir = resolve2(outPath, "..");
35013
+ if (!existsSync2(dir))
35116
35014
  mkdirSync2(dir, { recursive: true });
35117
35015
  await writeTextFile(outPath, text);
35118
35016
  success(`Created ${outPath}`);
@@ -35175,13 +35073,13 @@ function createLocalSubgraphDetail(input3) {
35175
35073
  };
35176
35074
  }
35177
35075
  function readCliSubgraphsDependency() {
35178
- const here = dirname4(fileURLToPath2(import.meta.url));
35076
+ const here = dirname3(fileURLToPath2(import.meta.url));
35179
35077
  const candidates = [
35180
- resolve3(here, "..", "..", "package.json"),
35181
- resolve3(here, "..", "package.json")
35078
+ resolve2(here, "..", "..", "package.json"),
35079
+ resolve2(here, "..", "package.json")
35182
35080
  ];
35183
35081
  for (const candidate of candidates) {
35184
- if (!existsSync3(candidate))
35082
+ if (!existsSync2(candidate))
35185
35083
  continue;
35186
35084
  const pkg = JSON.parse(readFileSync2(candidate, "utf8"));
35187
35085
  const dep = pkg.dependencies?.["@secondlayer/subgraphs"];
@@ -35191,9 +35089,9 @@ function readCliSubgraphsDependency() {
35191
35089
  return "^1.3.2";
35192
35090
  }
35193
35091
  function ensureScaffoldPackageJson(dir) {
35194
- const packagePath = join7(dir, "package.json");
35092
+ const packagePath = join6(dir, "package.json");
35195
35093
  const subgraphsDep = readCliSubgraphsDependency();
35196
- if (!existsSync3(packagePath)) {
35094
+ if (!existsSync2(packagePath)) {
35197
35095
  writeFileSync2(packagePath, `${JSON.stringify({
35198
35096
  type: "module",
35199
35097
  dependencies: {
@@ -35317,13 +35215,13 @@ ${SUBGRAPH_TEMPLATE_SLUGS.map((s) => ` ${s.padEnd(20)} ${SUBGRAPH_TEMPLATE_DESC
35317
35215
  `)}`);
35318
35216
  process.exit(1);
35319
35217
  }
35320
- const dir = resolve3("subgraphs");
35321
- const filePath = resolve3(dir, `${name}.ts`);
35322
- if (existsSync3(filePath)) {
35218
+ const dir = resolve2("subgraphs");
35219
+ const filePath = resolve2(dir, `${name}.ts`);
35220
+ if (existsSync2(filePath)) {
35323
35221
  error(`File already exists: ${filePath}`);
35324
35222
  process.exit(1);
35325
35223
  }
35326
- if (!existsSync3(dir)) {
35224
+ if (!existsSync2(dir)) {
35327
35225
  mkdirSync2(dir, { recursive: true });
35328
35226
  }
35329
35227
  const content = generateSubgraphTemplate(name, slug);
@@ -35336,8 +35234,8 @@ ${SUBGRAPH_TEMPLATE_SLUGS.map((s) => ` ${s.padEnd(20)} ${SUBGRAPH_TEMPLATE_DESC
35336
35234
  });
35337
35235
  subgraphs.command("dev <file>").description("Watch a subgraph file and auto-redeploy on change").action(async (file) => {
35338
35236
  await requireLocalNetwork();
35339
- const absPath = resolve3(file);
35340
- if (!existsSync3(absPath)) {
35237
+ const absPath = resolve2(file);
35238
+ if (!existsSync2(absPath)) {
35341
35239
  error(`File not found: ${absPath}`);
35342
35240
  process.exit(1);
35343
35241
  }
@@ -35397,7 +35295,7 @@ Stopped watching.`);
35397
35295
  });
35398
35296
  subgraphs.command("deploy <file>").description("Deploy a subgraph definition file").option("--version <semver>", "Explicit version (default: auto-increment patch)").option("--start-block <n>", "Override the subgraph definition startBlock for this deploy").option("--dry-run", "Validate and preview deploy without writing changes").option("--preview", "Alias for --dry-run").option("--force", "Skip confirmation prompt for reindex operations").action(async (file, options2) => {
35399
35297
  try {
35400
- const absPath = resolve3(file);
35298
+ const absPath = resolve2(file);
35401
35299
  const config = await loadConfig();
35402
35300
  if (config.network !== "local") {
35403
35301
  await requireAuth();
@@ -35415,8 +35313,8 @@ Stopped watching.`);
35415
35313
  const validated = validateSubgraphDefinition(effectiveDef);
35416
35314
  if (config.network !== "local") {
35417
35315
  info(`${dryRun ? "Bundling for remote deploy dry run" : "Bundling for remote deploy"} (${config.network})...`);
35418
- const { readFile: readFile4 } = await import("node:fs/promises");
35419
- const source = await readFile4(absPath, "utf8");
35316
+ const { readFile: readFile3 } = await import("node:fs/promises");
35317
+ const source = await readFile3(absPath, "utf8");
35420
35318
  const { bundleSubgraphCode } = await import("@secondlayer/bundler");
35421
35319
  const bundled = await bundleSubgraphCode(source);
35422
35320
  const handlerCode = bundled.handlerCode;
@@ -35608,12 +35506,12 @@ Table endpoints:`));
35608
35506
  subgraphs.command("inspect <file>").description("Output API documentation for a local subgraph file").option("--format <format>", "Output format: openapi, agent, markdown", "agent").option("-o, --output <path>", "Write output to a file").option("--server <url>", "Override the server URL in generated docs").action(async (file, options2) => {
35609
35507
  try {
35610
35508
  const format = parseSubgraphSpecFormat(options2.format);
35611
- const absPath = resolve3(file);
35612
- if (!existsSync3(absPath)) {
35509
+ const absPath = resolve2(file);
35510
+ if (!existsSync2(absPath)) {
35613
35511
  error(`File not found: ${absPath}`);
35614
35512
  process.exit(1);
35615
35513
  }
35616
- const { readFile: readFile4 } = await import("node:fs/promises");
35514
+ const { readFile: readFile3 } = await import("node:fs/promises");
35617
35515
  const { bundleSubgraphCode } = await import("@secondlayer/bundler");
35618
35516
  const { generateSubgraphSQL } = await import("@secondlayer/subgraphs");
35619
35517
  const {
@@ -35621,7 +35519,7 @@ Table endpoints:`));
35621
35519
  generateSubgraphMarkdown,
35622
35520
  generateSubgraphOpenApi
35623
35521
  } = await import("@secondlayer/shared/subgraphs/spec");
35624
- const source = await readFile4(absPath, "utf8");
35522
+ const source = await readFile3(absPath, "utf8");
35625
35523
  const bundled = await bundleSubgraphCode(source);
35626
35524
  const { hash } = generateSubgraphSQL({
35627
35525
  name: bundled.name,
@@ -35798,7 +35696,7 @@ ${rows.length} row(s)`));
35798
35696
  error("--output <path> is required");
35799
35697
  process.exit(1);
35800
35698
  }
35801
- const outPath = resolve3(options2.output);
35699
+ const outPath = resolve2(options2.output);
35802
35700
  const network = inferNetwork(contractAddress) ?? "mainnet";
35803
35701
  const apiKey = options2.apiKey ?? process.env.STACKS_NODE_API_KEY ?? process.env.HIRO_API_KEY;
35804
35702
  const client = new StacksApiClient(network, apiKey);
@@ -35810,8 +35708,8 @@ ${rows.length} row(s)`));
35810
35708
  contractId: contractAddress,
35811
35709
  functions: abi.functions
35812
35710
  });
35813
- const dir = resolve3(outPath, "..");
35814
- if (!existsSync3(dir))
35711
+ const dir = resolve2(outPath, "..");
35712
+ if (!existsSync2(dir))
35815
35713
  mkdirSync2(dir, { recursive: true });
35816
35714
  await writeTextFile(outPath, content);
35817
35715
  ensureScaffoldPackageJson(dir);
@@ -35840,13 +35738,13 @@ ${rows.length} row(s)`));
35840
35738
  error("--output <path> is required");
35841
35739
  process.exit(1);
35842
35740
  }
35843
- const outPath = resolve3(options2.output);
35741
+ const outPath = resolve2(options2.output);
35844
35742
  info(`Fetching subgraph metadata for "${subgraphName}"...`);
35845
35743
  const subgraphDetail = await getSubgraphApi(subgraphName);
35846
35744
  info("Generating typed client...");
35847
35745
  const content = await generateSubgraphConsumer(subgraphName, subgraphDetail);
35848
- const dir = resolve3(outPath, "..");
35849
- if (!existsSync3(dir))
35746
+ const dir = resolve2(outPath, "..");
35747
+ if (!existsSync2(dir))
35850
35748
  mkdirSync2(dir, { recursive: true });
35851
35749
  await writeTextFile(outPath, content);
35852
35750
  success(`Created ${outPath}`);
@@ -36323,7 +36221,6 @@ async function checkHealth() {
36323
36221
  }
36324
36222
 
36325
36223
  // src/commands/doctor.ts
36326
- init_http();
36327
36224
  init_network();
36328
36225
  init_output();
36329
36226
  function registerDoctorCommand(program2) {
@@ -36803,9 +36700,59 @@ function formatLogLine3(service, line) {
36803
36700
  }
36804
36701
  // src/commands/whoami.ts
36805
36702
  init_config();
36806
- init_http();
36807
36703
  init_output();
36808
- init_project_file();
36704
+
36705
+ // src/lib/project-file.ts
36706
+ import { existsSync as existsSync3 } from "node:fs";
36707
+ import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
36708
+ import { homedir as homedir5 } from "node:os";
36709
+ import { dirname as dirname9, join as join8, parse as parsePath, resolve as resolve8 } from "node:path";
36710
+ import { z as z3 } from "zod/v4";
36711
+ var ProjectFileSchema = z3.object({
36712
+ slug: z3.string().min(1)
36713
+ });
36714
+ var FILENAME = "project";
36715
+ var DIRNAME = ".secondlayer";
36716
+ async function readActiveProject(cwd, globalDefault) {
36717
+ let dir = resolve8(cwd);
36718
+ const home = resolve8(homedir5());
36719
+ const fsRoot = parsePath(dir).root;
36720
+ while (true) {
36721
+ const candidate = join8(dir, DIRNAME, FILENAME);
36722
+ if (existsSync3(candidate)) {
36723
+ try {
36724
+ const raw = await readFile3(candidate, "utf8");
36725
+ const parsed = ProjectFileSchema.parse(JSON.parse(raw));
36726
+ return { slug: parsed.slug, resolvedFrom: candidate };
36727
+ } catch {}
36728
+ }
36729
+ if (existsSync3(join8(dir, ".git")))
36730
+ break;
36731
+ if (dir === home || dir === fsRoot)
36732
+ break;
36733
+ const parent = dirname9(dir);
36734
+ if (parent === dir)
36735
+ break;
36736
+ dir = parent;
36737
+ }
36738
+ if (globalDefault) {
36739
+ return {
36740
+ slug: globalDefault,
36741
+ resolvedFrom: join8(homedir5(), ".secondlayer", "config.json")
36742
+ };
36743
+ }
36744
+ return null;
36745
+ }
36746
+ async function writeActiveProject(slug, cwd) {
36747
+ const dir = join8(resolve8(cwd), DIRNAME);
36748
+ await mkdir3(dir, { recursive: true });
36749
+ const file = join8(dir, FILENAME);
36750
+ await writeFile3(file, `${JSON.stringify({ slug }, null, 2)}
36751
+ `, "utf8");
36752
+ return file;
36753
+ }
36754
+
36755
+ // src/commands/whoami.ts
36809
36756
  init_session();
36810
36757
  function registerWhoamiCommand(program2) {
36811
36758
  program2.command("whoami").description("Show current authenticated account + active project + tenant").action(async () => {
@@ -36851,7 +36798,6 @@ function registerWhoamiCommand(program2) {
36851
36798
  });
36852
36799
  }
36853
36800
  // src/commands/logout.ts
36854
- init_http();
36855
36801
  init_output();
36856
36802
  init_session();
36857
36803
  function registerLogoutCommand(program2) {
@@ -36874,11 +36820,9 @@ function registerLogoutCommand(program2) {
36874
36820
  }
36875
36821
  // src/commands/instance.ts
36876
36822
  init_config();
36877
- init_http();
36823
+ import { confirm as confirm5, input as input4, select as select4 } from "@inquirer/prompts";
36878
36824
  init_output();
36879
- init_project_file();
36880
36825
  init_resolve_tenant();
36881
- import { confirm as confirm5, input as input4, select as select4 } from "@inquirer/prompts";
36882
36826
  var INSTANCE_CREATE_TIMEOUT_MS = 180000;
36883
36827
  function registerInstanceCommand(program2) {
36884
36828
  const instance = program2.command("instance").description("Manage your dedicated Secondlayer instance");
@@ -37257,10 +37201,8 @@ function handleInstanceError(err, action) {
37257
37201
  }
37258
37202
  // src/commands/project.ts
37259
37203
  init_config();
37260
- init_http();
37261
- init_output();
37262
- init_project_file();
37263
37204
  import { input as input5 } from "@inquirer/prompts";
37205
+ init_output();
37264
37206
  function registerProjectCommand(program2) {
37265
37207
  const project = program2.command("project").description("Manage Secondlayer projects");
37266
37208
  project.command("create [name]").description("Create a new project").option("--slug <slug>", "Project URL identifier").action(async (nameArg, options2 = {}) => {
@@ -37402,5 +37344,5 @@ registerAccountCommand(program);
37402
37344
  registerBillingCommand(program);
37403
37345
  program.parse();
37404
37346
 
37405
- //# debugId=7BAF23F53752FABB64756E2164756E21
37347
+ //# debugId=9232228B9119962364756E2164756E21
37406
37348
  //# sourceMappingURL=cli.js.map