@troxy/cli 0.1.2 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@troxy/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "AI payment control — protect your agent's payments with policies",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cards.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { api } from './api.js';
2
2
  import { requireJwt } from './auth.js';
3
- import { table, fmt } from './print.js';
3
+ import { table } from './print.js';
4
4
 
5
5
  export async function runCards([sub, ...args], flags) {
6
6
  const jwt = requireJwt();
package/src/init.js CHANGED
@@ -41,23 +41,29 @@ export async function runInit({ key } = {}) {
41
41
 
42
42
  console.log('\n Troxy — AI payment control\n');
43
43
 
44
- // Validate the key by hitting /evaluate (404 card = key is valid)
44
+ // Validate the key by hitting /evaluate (404 card = key is valid, TypeError = network failure)
45
45
  process.stdout.write(' Validating API key... ');
46
46
  try {
47
- const result = await evaluatePayment(
48
- { agent: 'troxy-init', card_alias: '__ping__', amount: 0 },
47
+ await evaluatePayment(
48
+ { agent: 'troxy-init', card_alias_name: '__ping__', amount: 0 },
49
49
  key,
50
50
  );
51
- if (result.error === 'invalid or revoked API key') {
51
+ console.log('');
52
+ } catch (err) {
53
+ if (err instanceof TypeError) {
54
+ // Actual network failure — couldn't reach the API at all
55
+ console.log('✗');
56
+ console.error('\n Error: Could not reach Troxy API. Check your internet connection.\n');
57
+ process.exit(1);
58
+ }
59
+ // API was reachable — check what it said
60
+ if (err.message?.toLowerCase().includes('invalid') || err.message?.toLowerCase().includes('revoked')) {
52
61
  console.log('✗');
53
62
  console.error('\n Error: Invalid or revoked API key.\n');
54
63
  process.exit(1);
55
64
  }
65
+ // 404 (card not found) or any other API error = key is valid, API is up
56
66
  console.log('✓');
57
- } catch {
58
- console.log('✗');
59
- console.error('\n Error: Could not reach Troxy API. Check your internet connection.\n');
60
- process.exit(1);
61
67
  }
62
68
 
63
69
  // Save config