troxy-cli 1.4.17 → 1.4.19
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/mcp-server.js +2 -2
- package/src/policies.js +40 -9
package/package.json
CHANGED
package/src/mcp-server.js
CHANGED
|
@@ -104,7 +104,7 @@ export async function runMcp() {
|
|
|
104
104
|
'based on your Troxy policies. Call this before initiating any payment.',
|
|
105
105
|
inputSchema: {
|
|
106
106
|
type: 'object',
|
|
107
|
-
required: ['merchant_name', 'amount'],
|
|
107
|
+
required: ['merchant_name', 'amount', 'currency'],
|
|
108
108
|
properties: {
|
|
109
109
|
merchant_name: {
|
|
110
110
|
type: 'string',
|
|
@@ -124,7 +124,7 @@ export async function runMcp() {
|
|
|
124
124
|
},
|
|
125
125
|
currency: {
|
|
126
126
|
type: 'string',
|
|
127
|
-
description: '
|
|
127
|
+
description: 'ISO 4217 currency code — always include this. Examples: "ILS" for Israeli Shekel (NIS), "USD" for US Dollar, "EUR" for Euro.',
|
|
128
128
|
},
|
|
129
129
|
approval_token: {
|
|
130
130
|
type: 'string',
|
package/src/policies.js
CHANGED
|
@@ -11,17 +11,18 @@ function _scope(p) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const HELP = {
|
|
14
|
-
list:
|
|
15
|
-
describe:
|
|
16
|
-
create:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
list: ` troxy policies list\n\n Lists all policies in your account with their action, scope, status, and conditions.\n`,
|
|
15
|
+
describe: ` troxy policies describe --name <policy-name>\n\n Shows full details for a single policy.\n\n Options:\n --name Name of the policy (use single quotes for names with special chars)\n`,
|
|
16
|
+
create: ` troxy policies create --name <name> --action <action> [options]\n\n Creates a new policy. Login required.\n\n Required:\n --name Policy name\n --action ALLOW, BLOCK, NOTIFY, or ESCALATE\n\n Optional conditions:\n --field Field to match: amount, merchant_name, merchant_category,\n merchant_country, currency, agent_name, hour, day_of_week\n --operator eq, neq, gt, gte, lt, lte, contains, between\n --value Comparison value (e.g. 500, amazon, Monday)\n --value2 Upper bound for 'between' operator\n\n Priority:\n --priority <n> Explicit priority number (default: auto, max+10)\n Lower number = higher priority (evaluated first).\n\n Scope:\n --mcp <name> Scope policy to a specific MCP only (default: all MCPs)\n Run 'troxy mcps list' to see MCP names.\n\n Examples:\n troxy policies create --name "Block large" --action BLOCK --field amount --operator gte --value 500\n troxy policies create --name "Block Amazon" --action BLOCK --field merchant_name --operator contains --value amazon\n troxy policies create --name "Cap spend" --action BLOCK --mcp "My Laptop" --field amount --operator gte --value 200\n troxy policies create --name "Allow Wiki" --action ALLOW --priority 5 --field merchant_name --operator contains --value Wiki\n`,
|
|
17
|
+
'set-priority': ` troxy policies set-priority --name <policy-name> --priority <n>\n\n Changes the priority of a policy. Lower number = higher priority (evaluated first).\n\n Options:\n --name Name of the policy\n --priority New priority number (e.g. 10, 20, 50)\n\n Example:\n troxy policies set-priority --name "Block Wiki" --priority 5\n`,
|
|
18
|
+
enable: ` troxy policies enable --name <policy-name>\n\n Enables a disabled policy.\n\n Options:\n --name Name of the policy to enable\n`,
|
|
19
|
+
disable: ` troxy policies disable --name <policy-name>\n\n Disables a policy without deleting it.\n\n Options:\n --name Name of the policy to disable\n`,
|
|
20
|
+
delete: ` troxy policies delete --name <policy-name>\n\n Permanently deletes a policy.\n\n Options:\n --name Name of the policy to delete\n`,
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export async function runPolicies([sub, ...args], flags) {
|
|
23
24
|
if (flags.help || flags.h) {
|
|
24
|
-
console.log('\n' + (HELP[sub] || ` troxy policies <subcommand> [options]\n\n Subcommands:\n list
|
|
25
|
+
console.log('\n' + (HELP[sub] || ` troxy policies <subcommand> [options]\n\n Subcommands:\n list List all policies\n describe Show details for a policy\n create Create a new policy\n set-priority Change a policy's priority\n enable Enable a policy\n disable Disable a policy\n delete Delete a policy\n\n Run 'troxy policies <subcommand> --help' for subcommand help.\n`));
|
|
25
26
|
process.exit(0);
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -117,7 +118,13 @@ export async function runPolicies([sub, ...args], flags) {
|
|
|
117
118
|
console.log(`\n Scoping to MCP: ${match.name || match.agent_name || match.prefix}`);
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
const
|
|
121
|
+
const priority = flags.priority != null ? parseInt(flags.priority, 10) : undefined;
|
|
122
|
+
if (flags.priority != null && isNaN(priority)) {
|
|
123
|
+
console.error(' --priority must be a number\n'); process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
const body = { name, action, conditions, enabled: true, global: isGlobal, mcp_ids: mcpIds };
|
|
126
|
+
if (priority != null) body.priority = priority;
|
|
127
|
+
const policy = await api.createPolicy(jwt, body);
|
|
121
128
|
const scope = isGlobal ? 'all MCPs' : (policy.mcps?.[0]?.name || flags.mcp);
|
|
122
129
|
console.log(`\n Policy "${policy.name}" created ✓ (priority: ${policy.priority}, scope: ${scope})\n`);
|
|
123
130
|
break;
|
|
@@ -155,9 +162,33 @@ export async function runPolicies([sub, ...args], flags) {
|
|
|
155
162
|
break;
|
|
156
163
|
}
|
|
157
164
|
|
|
165
|
+
case 'set-priority': {
|
|
166
|
+
const name = flags.name;
|
|
167
|
+
if (!name) { console.error(' --name is required\n'); process.exit(1); }
|
|
168
|
+
if (flags.priority == null) { console.error(' --priority is required\n'); process.exit(1); }
|
|
169
|
+
const priority = parseInt(flags.priority, 10);
|
|
170
|
+
if (isNaN(priority)) { console.error(' --priority must be a number\n'); process.exit(1); }
|
|
171
|
+
const { policies = [] } = await api.listPolicies(jwt);
|
|
172
|
+
const policy = policies.find(p => p.name === name);
|
|
173
|
+
if (!policy) { console.error(` Policy "${name}" not found\n`); process.exit(1); }
|
|
174
|
+
await api.updatePolicy(jwt, policy.id, {
|
|
175
|
+
name: policy.name,
|
|
176
|
+
action: policy.action,
|
|
177
|
+
description: policy.description || '',
|
|
178
|
+
conditions: policy.conditions || [],
|
|
179
|
+
or_conditions: policy.or_conditions || [],
|
|
180
|
+
tiers: policy.tiers || null,
|
|
181
|
+
global: policy.global !== false,
|
|
182
|
+
enabled: policy.enabled,
|
|
183
|
+
priority,
|
|
184
|
+
});
|
|
185
|
+
console.log(`\n Policy "${name}" priority set to ${priority} ✓\n`);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
|
|
158
189
|
default:
|
|
159
190
|
console.error(` Unknown subcommand: ${sub}`);
|
|
160
|
-
console.error(' Usage: troxy policies [list|describe|create|delete|enable|disable]\n');
|
|
191
|
+
console.error(' Usage: troxy policies [list|describe|create|set-priority|delete|enable|disable]\n');
|
|
161
192
|
process.exit(1);
|
|
162
193
|
}
|
|
163
194
|
}
|