viagen 0.2.5 → 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 +100 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -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.
|
|
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) => {
|