troxy-cli 1.4.21 → 1.4.23
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 +30 -2
- package/package.json +1 -1
- package/src/config.js +8 -2
package/bin/troxy.js
CHANGED
|
@@ -170,6 +170,10 @@ switch (command) {
|
|
|
170
170
|
Simulates a payment evaluation request — identical to what your AI agent sends.
|
|
171
171
|
Use this to test your policies. Login required.
|
|
172
172
|
|
|
173
|
+
By default, payments that come back ALLOW or NOTIFY are auto-confirmed as
|
|
174
|
+
successful charges, so rows land on their final badge in the dashboard
|
|
175
|
+
instead of sitting in PENDING. Pass --no-confirm to skip that step.
|
|
176
|
+
|
|
173
177
|
Required:
|
|
174
178
|
--merchant <name> Merchant name (e.g. "Amazon")
|
|
175
179
|
--amount <n> Payment amount in USD
|
|
@@ -177,11 +181,14 @@ switch (command) {
|
|
|
177
181
|
Optional:
|
|
178
182
|
--card <alias> Card alias (default: "Work")
|
|
179
183
|
--category <cat> Merchant category (e.g. travel, software, food)
|
|
184
|
+
--no-confirm Don't auto-confirm — leaves the row PENDING
|
|
185
|
+
--fail Confirm as a failed charge instead of success
|
|
186
|
+
(simulates a declined card)
|
|
180
187
|
|
|
181
188
|
Examples:
|
|
182
189
|
troxy pay --merchant "Amazon" --amount 50
|
|
183
|
-
troxy pay --merchant "Amazon" --amount 350 --
|
|
184
|
-
troxy pay --merchant "Delta" --amount 250 --
|
|
190
|
+
troxy pay --merchant "Amazon" --amount 350 --no-confirm
|
|
191
|
+
troxy pay --merchant "Delta" --amount 250 --fail
|
|
185
192
|
`);
|
|
186
193
|
process.exit(0);
|
|
187
194
|
}
|
|
@@ -192,6 +199,8 @@ switch (command) {
|
|
|
192
199
|
const amount = parseFloat(flags.amount);
|
|
193
200
|
const card = flags.card || 'Work';
|
|
194
201
|
const category = flags.category;
|
|
202
|
+
const noConfirm = !!flags['no-confirm'];
|
|
203
|
+
const failCharge = !!flags.fail;
|
|
195
204
|
if (!merchant) { console.error(' --merchant is required\n'); process.exit(1); }
|
|
196
205
|
if (isNaN(amount)){ console.error(' --amount is required\n'); process.exit(1); }
|
|
197
206
|
const agentName = loadConfig()?.agentName || 'troxy-cli';
|
|
@@ -203,6 +212,25 @@ switch (command) {
|
|
|
203
212
|
const suffix = result.policy ? ` ← "${result.policy}"` : result.reason ? ` — ${result.reason}` : ' (default action)';
|
|
204
213
|
console.log(`\n ${icon} ${result.decision}${suffix}`);
|
|
205
214
|
if (result.audit_id) console.log(` audit: ${result.audit_id}`);
|
|
215
|
+
|
|
216
|
+
// Auto-confirm so the dashboard badge lands on its final state. ALLOW and
|
|
217
|
+
// NOTIFY decisions normally leave the row PENDING until the agent reports
|
|
218
|
+
// back; for CLI testing that's just noise, so we confirm-success by
|
|
219
|
+
// default. BLOCK and ESCALATE are final / human-gated and aren't touched.
|
|
220
|
+
const shouldConfirm = !noConfirm && result.audit_id && ['ALLOW', 'NOTIFY'].includes(result.decision);
|
|
221
|
+
if (shouldConfirm) {
|
|
222
|
+
const status = failCharge ? 'failed' : 'success';
|
|
223
|
+
try {
|
|
224
|
+
await api.confirmPayment(result.audit_id, {
|
|
225
|
+
status,
|
|
226
|
+
provider: 'troxy-cli',
|
|
227
|
+
...(failCharge ? { reason: 'simulated card decline (--fail)' } : {}),
|
|
228
|
+
}, apiKey);
|
|
229
|
+
console.log(` confirmed: charge ${status}`);
|
|
230
|
+
} catch (e) {
|
|
231
|
+
console.log(` (confirm step failed — row will stay PENDING)`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
206
234
|
console.log();
|
|
207
235
|
break;
|
|
208
236
|
}
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -14,6 +14,12 @@ export function loadConfig() {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function saveConfig(data) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// Owner-only permissions on dir + file — matches what AWS CLI does with
|
|
18
|
+
// ~/.aws/credentials. Stops other users on the same machine from reading
|
|
19
|
+
// the API key. mkdirSync's `mode` is only honoured for newly-created dirs,
|
|
20
|
+
// so we chmod afterwards too to also fix existing pre-secured installs.
|
|
21
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
22
|
+
try { fs.chmodSync(CONFIG_DIR, 0o700); } catch {}
|
|
23
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
24
|
+
try { fs.chmodSync(CONFIG_FILE, 0o600); } catch {}
|
|
19
25
|
}
|