varcrypt 0.0.1 → 0.1.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.
Files changed (3) hide show
  1. package/index.mjs +101 -0
  2. package/package.json +14 -11
  3. package/index.js +0 -1
package/index.mjs ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, writeFileSync, mkdirSync } from "fs";
3
+ import { homedir } from "os";
4
+ import { join } from "path";
5
+ import * as readline from "readline/promises";
6
+
7
+ const CONFIG_DIR = join(homedir(), ".varcrypt");
8
+ const CONFIG_FILE = join(CONFIG_DIR, "config.json");
9
+ const DEFAULT_HOST = "http://localhost:3000";
10
+
11
+ function loadConfig() {
12
+ try {
13
+ return JSON.parse(readFileSync(CONFIG_FILE, "utf8"));
14
+ } catch {
15
+ return {};
16
+ }
17
+ }
18
+
19
+ function saveConfig(config) {
20
+ mkdirSync(CONFIG_DIR, { recursive: true });
21
+ writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
22
+ }
23
+
24
+ async function login() {
25
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
26
+ const token = await rl.question("Paste your API token: ");
27
+ rl.close();
28
+
29
+ const trimmed = token.trim();
30
+ if (!trimmed.startsWith("vc_")) {
31
+ console.error("Invalid token — must start with vc_");
32
+ process.exit(1);
33
+ }
34
+
35
+ const config = loadConfig();
36
+ config.token = trimmed;
37
+ saveConfig(config);
38
+ console.log("Token saved to ~/.varcrypt/config.json");
39
+ }
40
+
41
+ async function pull(project, env, opts) {
42
+ const config = loadConfig();
43
+ if (!config.token) {
44
+ console.error("Not logged in. Run: varcrypt login");
45
+ process.exit(1);
46
+ }
47
+
48
+ const host = opts.host ?? config.host ?? DEFAULT_HOST;
49
+ const url = `${host}/api/secrets?project=${encodeURIComponent(project)}&env=${encodeURIComponent(env)}`;
50
+
51
+ const res = await fetch(url, {
52
+ headers: { Authorization: `Bearer ${config.token}` },
53
+ });
54
+
55
+ if (!res.ok) {
56
+ const body = await res.json().catch(() => ({}));
57
+ console.error(`Error ${res.status}: ${body.error ?? res.statusText}`);
58
+ process.exit(1);
59
+ }
60
+
61
+ const { secrets } = await res.json();
62
+
63
+ if (opts.output === "export") {
64
+ for (const [k, v] of Object.entries(secrets)) {
65
+ console.log(`export ${k}="${v}"`);
66
+ }
67
+ } else {
68
+ for (const [k, v] of Object.entries(secrets)) {
69
+ console.log(`${k}=${v}`);
70
+ }
71
+ }
72
+ }
73
+
74
+ function usage() {
75
+ console.log(`
76
+ varcrypt <command> [options]
77
+
78
+ Commands:
79
+ login Save your API token
80
+ pull <project> <env> Print secrets as KEY=value
81
+ --output export Print as export KEY="value" instead
82
+ --host <url> Override API host (default: http://localhost:3000)
83
+ `);
84
+ }
85
+
86
+ const [,, cmd, ...args] = process.argv;
87
+
88
+ if (cmd === "login") {
89
+ await login();
90
+ } else if (cmd === "pull") {
91
+ const [project, env, ...rest] = args;
92
+ if (!project || !env) { usage(); process.exit(1); }
93
+ const opts = {};
94
+ for (let i = 0; i < rest.length; i++) {
95
+ if (rest[i] === "--output") opts.output = rest[++i];
96
+ if (rest[i] === "--host") opts.host = rest[++i];
97
+ }
98
+ await pull(project, env, opts);
99
+ } else {
100
+ usage();
101
+ }
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "varcrypt",
3
- "version": "0.0.1",
4
- "description": "Encrypted environment variable sharing for dev teams",
5
- "main": "index.js",
6
- "keywords": ["env", "secrets", "environment", "cli", "devtools"],
7
- "author": "jsg994",
8
- "license": "MIT",
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/jsg994/varcrypt"
12
- }
13
- }
3
+ "version": "0.1.0",
4
+ "description": "CLI for VarCrypt pull encrypted secrets from the cloud",
5
+ "type": "module",
6
+ "bin": {
7
+ "varcrypt": "./index.mjs"
8
+ },
9
+ "engines": {
10
+ "node": ">=18"
11
+ },
12
+ "files": [
13
+ "index.mjs"
14
+ ],
15
+ "license": "MIT"
16
+ }
package/index.js DELETED
@@ -1 +0,0 @@
1
- // VarCrypt - coming soon