@troxy/cli 0.1.3 → 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 +1 -1
- package/src/init.js +14 -8
package/package.json
CHANGED
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
|
-
|
|
48
|
-
{ agent: 'troxy-init',
|
|
47
|
+
await evaluatePayment(
|
|
48
|
+
{ agent: 'troxy-init', card_alias_name: '__ping__', amount: 0 },
|
|
49
49
|
key,
|
|
50
50
|
);
|
|
51
|
-
|
|
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
|