troxy-cli 1.2.2 → 1.2.3
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/bin/troxy.js +43 -0
- package/package.json +1 -1
package/bin/troxy.js
CHANGED
|
@@ -81,6 +81,47 @@ switch (command) {
|
|
|
81
81
|
console.log('\n Logged out ✓\n');
|
|
82
82
|
break;
|
|
83
83
|
|
|
84
|
+
case 'rotate-key': {
|
|
85
|
+
const jwt = requireJwt();
|
|
86
|
+
const { loadConfig, saveConfig } = await import('../src/config.js');
|
|
87
|
+
const oldKey = loadConfig()?.apiKey;
|
|
88
|
+
const oldPrefix = oldKey ? oldKey.substring(0, 11) : null;
|
|
89
|
+
const name = flags.name || 'Rotated key';
|
|
90
|
+
const revokeOld = !!flags['revoke-old'];
|
|
91
|
+
|
|
92
|
+
process.stdout.write('\n Creating new key... ');
|
|
93
|
+
const result = await api.createToken(jwt, { name });
|
|
94
|
+
const newKey = result.key;
|
|
95
|
+
const newPrefix = result.prefix;
|
|
96
|
+
console.log('✓');
|
|
97
|
+
|
|
98
|
+
saveConfig({ apiKey: newKey });
|
|
99
|
+
console.log(' Saved to ~/.troxy/config.json ✓');
|
|
100
|
+
|
|
101
|
+
if (revokeOld && oldPrefix) {
|
|
102
|
+
process.stdout.write(` Revoking old key ${oldPrefix}... `);
|
|
103
|
+
const { tokens = [] } = await api.listTokens(jwt);
|
|
104
|
+
const old = tokens.find(t => t.prefix === oldPrefix);
|
|
105
|
+
if (old) { await api.revokeToken(jwt, old.id); console.log('✓'); }
|
|
106
|
+
else console.log('(already revoked)');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
console.log(`
|
|
110
|
+
Key rotated:
|
|
111
|
+
Old: ${oldPrefix ? oldPrefix + '...' : '(none)'}
|
|
112
|
+
New: ${newPrefix}...
|
|
113
|
+
|
|
114
|
+
New key (shown once — save it now):
|
|
115
|
+
${newKey}
|
|
116
|
+
|
|
117
|
+
~/.troxy/config.json updated ✓
|
|
118
|
+
|
|
119
|
+
⚠ If this key runs an MCP, update TROXY_API_KEY in your MCP
|
|
120
|
+
config and restart the MCP server.
|
|
121
|
+
`);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
84
125
|
// ── MCP server (started by MCP clients) ───────────────────────
|
|
85
126
|
case 'mcp':
|
|
86
127
|
await runMcp();
|
|
@@ -192,6 +233,8 @@ switch (command) {
|
|
|
192
233
|
Setup
|
|
193
234
|
troxy connect --key <api-key> Save API key (CLI only — no MCP setup)
|
|
194
235
|
troxy init --key <api-key> Full setup: save key + configure MCP
|
|
236
|
+
troxy rotate-key Create new key + save it (requires login)
|
|
237
|
+
troxy rotate-key --revoke-old Same + revoke the old key immediately
|
|
195
238
|
troxy uninstall Remove Troxy from this machine
|
|
196
239
|
troxy status API health + which key is in use
|
|
197
240
|
|