viagen 0.2.3 → 0.2.6

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
@@ -19835,12 +19835,13 @@ ${payload.err.frame || ""}`
19835
19835
  logBuffer.push("warn", `[viagen] Could not checkout ${gitBranch} (dirty working tree?): ${msg}`);
19836
19836
  }
19837
19837
  }
19838
+ const isChildProcess = process.env["__VIAGEN_CHILD"] === "1";
19838
19839
  const authToken = env["VIAGEN_AUTH_TOKEN"];
19839
- if (authToken) {
19840
+ if (authToken && !isChildProcess) {
19840
19841
  debug("server", "auth middleware enabled (VIAGEN_AUTH_TOKEN set)");
19841
19842
  server.middlewares.use(createAuthMiddleware(authToken));
19842
19843
  } else {
19843
- debug("server", "auth middleware DISABLED (no VIAGEN_AUTH_TOKEN)");
19844
+ debug("server", `auth middleware DISABLED (${isChildProcess ? "child process" : "no VIAGEN_AUTH_TOKEN"})`);
19844
19845
  }
19845
19846
  const platformToken = env["VIAGEN_USER_TOKEN"] || env["VIAGEN_AUTH_TOKEN"];
19846
19847
  const platformUrl = env["VIAGEN_PLATFORM_URL"] || "https://app.viagen.dev";
@@ -19957,7 +19958,6 @@ Page URL: ${pageUrl}`);
19957
19958
  let processManager;
19958
19959
  const rawAppCmd = options?.standalone ? env["VIAGEN_APP_COMMAND"] || process.env["VIAGEN_APP_COMMAND"] : void 0;
19959
19960
  const appCommand = rawAppCmd?.replace(/^["']|["']$/g, "") || void 0;
19960
- const isChildProcess = process.env["__VIAGEN_CHILD"] === "1";
19961
19961
  if (isChildProcess) {
19962
19962
  debug("server", "skipping process manager (running as child process)");
19963
19963
  } else if (appCommand) {
@@ -21037,6 +21037,103 @@ async function sync() {
21037
21037
  }
21038
21038
  console.log("You can now launch sandboxes from the web platform.");
21039
21039
  }
21040
+ async function pull() {
21041
+ const client = await requireClient();
21042
+ const cwd = process.cwd();
21043
+ const env = loadDotenv(cwd);
21044
+ console.log("viagen pull");
21045
+ console.log("");
21046
+ let environmentId = env["VIAGEN_ENVIRONMENT_ID"];
21047
+ let environmentName;
21048
+ if (environmentId) {
21049
+ try {
21050
+ const existing = await client.environments.get(environmentId);
21051
+ environmentName = existing.name;
21052
+ console.log(`Environment: ${environmentName}`);
21053
+ } catch {
21054
+ console.log("Previously synced environment not found. Choose an environment:");
21055
+ console.log("");
21056
+ environmentId = void 0;
21057
+ }
21058
+ }
21059
+ if (!environmentId) {
21060
+ const envList = await client.environments.list();
21061
+ if (envList.length === 0) {
21062
+ console.error("No environments found. Run `viagen sync` first to push your credentials.");
21063
+ process.exit(1);
21064
+ }
21065
+ console.log("Your environments:");
21066
+ console.log("");
21067
+ for (let i = 0; i < envList.length; i++) {
21068
+ const repo = envList[i].githubRepo ? ` (${envList[i].githubRepo})` : "";
21069
+ console.log(` ${i + 1}) ${envList[i].name}${repo}`);
21070
+ }
21071
+ console.log("");
21072
+ const choice = await promptUser("Choose: ");
21073
+ const idx = parseInt(choice, 10) - 1;
21074
+ if (idx >= 0 && idx < envList.length) {
21075
+ environmentId = envList[idx].id;
21076
+ environmentName = envList[idx].name;
21077
+ } else {
21078
+ console.log("Cancelled.");
21079
+ return;
21080
+ }
21081
+ }
21082
+ let secrets;
21083
+ try {
21084
+ secrets = await client.environments.pullSecrets(environmentId);
21085
+ } catch (err) {
21086
+ console.error("Failed to fetch secrets from the platform.");
21087
+ if (err instanceof Error) console.error(err.message);
21088
+ process.exit(1);
21089
+ }
21090
+ for (const key of SYNC_DENY_KEYS) {
21091
+ delete secrets[key];
21092
+ }
21093
+ const keys = Object.keys(secrets);
21094
+ if (keys.length === 0) {
21095
+ console.log("No secrets found on the platform for this environment.");
21096
+ return;
21097
+ }
21098
+ const toAdd = [];
21099
+ const toUpdate = [];
21100
+ for (const key of keys) {
21101
+ if (env[key] !== void 0) {
21102
+ toUpdate.push(key);
21103
+ } else {
21104
+ toAdd.push(key);
21105
+ }
21106
+ }
21107
+ console.log("");
21108
+ if (toUpdate.length > 0) {
21109
+ console.log(`To update (${toUpdate.length}):`);
21110
+ for (const key of toUpdate) console.log(` ${key}`);
21111
+ }
21112
+ if (toAdd.length > 0) {
21113
+ console.log(`To add (${toAdd.length}):`);
21114
+ for (const key of toAdd) console.log(` ${key}`);
21115
+ }
21116
+ console.log("");
21117
+ const answer = await promptUser("Write to .env? [y/n]: ");
21118
+ if (answer !== "y" && answer !== "yes") {
21119
+ console.log("Cancelled.");
21120
+ return;
21121
+ }
21122
+ if (toUpdate.length > 0) {
21123
+ const updates = {};
21124
+ for (const key of toUpdate) updates[key] = secrets[key];
21125
+ updateEnvVars(cwd, updates);
21126
+ }
21127
+ if (toAdd.length > 0) {
21128
+ const additions = {};
21129
+ for (const key of toAdd) additions[key] = secrets[key];
21130
+ writeEnvVars(cwd, additions);
21131
+ }
21132
+ if (!env["VIAGEN_ENVIRONMENT_ID"] && environmentId) {
21133
+ writeEnvVars(cwd, { VIAGEN_ENVIRONMENT_ID: environmentId });
21134
+ }
21135
+ console.log(`Pulled ${keys.length} secrets into .env.`);
21136
+ }
21040
21137
  var PLATFORM_URL = process.env.VIAGEN_PLATFORM_URL || "https://app.viagen.dev";
21041
21138
  async function login() {
21042
21139
  const existing = await loadCredentials();
@@ -21463,6 +21560,7 @@ function help() {
21463
21560
  console.log(" sandbox [-b branch] [-t min] Deploy your project to a Vercel Sandbox");
21464
21561
  console.log(" sandbox stop <id> Stop a running sandbox");
21465
21562
  console.log(" sync Push local credentials to the platform");
21563
+ console.log(" pull Pull platform secrets into local .env");
21466
21564
  console.log(" help Show this help message");
21467
21565
  console.log("");
21468
21566
  console.log("Serve options:");
@@ -21554,6 +21652,8 @@ async function main() {
21554
21652
  await sandbox(args.slice(1));
21555
21653
  } else if (command === "sync") {
21556
21654
  await sync();
21655
+ } else if (command === "pull") {
21656
+ await pull();
21557
21657
  } else {
21558
21658
  help();
21559
21659
  }
package/dist/index.js CHANGED
@@ -111,7 +111,7 @@ function registerHealthRoutes(server, env, errorRef) {
111
111
  );
112
112
  }
113
113
  });
114
- const currentVersion = true ? "0.2.3" : "0.0.0";
114
+ const currentVersion = true ? "0.2.6" : "0.0.0";
115
115
  debug("health", `version resolved: ${currentVersion}`);
116
116
  let versionCache = null;
117
117
  server.middlewares.use("/via/version", (_req, res) => {
@@ -19752,12 +19752,13 @@ ${payload.err.frame || ""}`
19752
19752
  logBuffer.push("warn", `[viagen] Could not checkout ${gitBranch} (dirty working tree?): ${msg}`);
19753
19753
  }
19754
19754
  }
19755
+ const isChildProcess = process.env["__VIAGEN_CHILD"] === "1";
19755
19756
  const authToken = env["VIAGEN_AUTH_TOKEN"];
19756
- if (authToken) {
19757
+ if (authToken && !isChildProcess) {
19757
19758
  debug("server", "auth middleware enabled (VIAGEN_AUTH_TOKEN set)");
19758
19759
  server.middlewares.use(createAuthMiddleware(authToken));
19759
19760
  } else {
19760
- debug("server", "auth middleware DISABLED (no VIAGEN_AUTH_TOKEN)");
19761
+ debug("server", `auth middleware DISABLED (${isChildProcess ? "child process" : "no VIAGEN_AUTH_TOKEN"})`);
19761
19762
  }
19762
19763
  const platformToken = env["VIAGEN_USER_TOKEN"] || env["VIAGEN_AUTH_TOKEN"];
19763
19764
  const platformUrl = env["VIAGEN_PLATFORM_URL"] || "https://app.viagen.dev";
@@ -19874,7 +19875,6 @@ Page URL: ${pageUrl}`);
19874
19875
  let processManager;
19875
19876
  const rawAppCmd = options?.standalone ? env["VIAGEN_APP_COMMAND"] || process.env["VIAGEN_APP_COMMAND"] : void 0;
19876
19877
  const appCommand = rawAppCmd?.replace(/^["']|["']$/g, "") || void 0;
19877
- const isChildProcess = process.env["__VIAGEN_CHILD"] === "1";
19878
19878
  if (isChildProcess) {
19879
19879
  debug("server", "skipping process manager (running as child process)");
19880
19880
  } else if (appCommand) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viagen",
3
- "version": "0.2.3",
3
+ "version": "0.2.6",
4
4
  "description": "Vite dev server plugin that exposes endpoints for chatting with Claude Code SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",