troxy-cli 1.2.2 → 1.2.4

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 (2) hide show
  1. package/bin/troxy.js +67 -0
  2. package/package.json +1 -1
package/bin/troxy.js CHANGED
@@ -81,11 +81,72 @@ 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();
87
128
  break;
88
129
 
130
+ // ── Simulate a payment evaluation ────────────────────────────
131
+ case 'pay': {
132
+ const apiKey = requireKey(flags);
133
+ const merchant = flags.merchant;
134
+ const amount = parseFloat(flags.amount);
135
+ const card = flags.card || 'Work';
136
+ const category = flags.category;
137
+ if (!merchant) { console.error(' --merchant is required\n'); process.exit(1); }
138
+ if (isNaN(amount)){ console.error(' --amount is required\n'); process.exit(1); }
139
+ const body = { card_alias: card, merchant_name: merchant, amount, agent: 'troxy-cli' };
140
+ if (category) body.merchant_category = category;
141
+ const result = await api.evaluate(body, apiKey);
142
+ const ICON = { ALLOW: '✓', BLOCK: '✗', ESCALATE: '⏳', NOTIFY: '~' };
143
+ const icon = ICON[result.decision] || '?';
144
+ console.log(`\n ${icon} ${result.decision}${result.policy ? ` ← "${result.policy}"` : ' (default action)'}`);
145
+ if (result.audit_id) console.log(` audit: ${result.audit_id}`);
146
+ console.log();
147
+ break;
148
+ }
149
+
89
150
  // ── Resources (read-only: --key or saved config; write: login) ─
90
151
  case 'policies':
91
152
  await runPolicies(positional, flags);
@@ -192,9 +253,15 @@ switch (command) {
192
253
  Setup
193
254
  troxy connect --key <api-key> Save API key (CLI only — no MCP setup)
194
255
  troxy init --key <api-key> Full setup: save key + configure MCP
256
+ troxy rotate-key Create new key + save it (requires login)
257
+ troxy rotate-key --revoke-old Same + revoke the old key immediately
195
258
  troxy uninstall Remove Troxy from this machine
196
259
  troxy status API health + which key is in use
197
260
 
261
+ Simulate
262
+ troxy pay --merchant "Amazon" --amount 50 --card "Work"
263
+ troxy pay --merchant "Google" --amount 300 --card "Work" --category software
264
+
198
265
  Inspect (uses saved key — no flags needed after init)
199
266
  troxy policies list
200
267
  troxy policies describe --name "Block Amazon"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "troxy-cli",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "AI payment control — protect your agent's payments with policies",
5
5
  "type": "module",
6
6
  "bin": {