troxy-cli 1.4.18 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/policies.js +40 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "troxy-cli",
3
- "version": "1.4.18",
3
+ "version": "1.4.19",
4
4
  "description": "AI payment control — protect your agent's payments with policies",
5
5
  "type": "module",
6
6
  "bin": {
package/src/policies.js CHANGED
@@ -11,17 +11,18 @@ function _scope(p) {
11
11
  }
12
12
 
13
13
  const HELP = {
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 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`,
17
- 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`,
18
- 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`,
19
- 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`,
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 List all policies\n describe Show details for a policy\n create Create a new policy\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
+ 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 policy = await api.createPolicy(jwt, { name, action, conditions, enabled: true, global: isGlobal, mcp_ids: mcpIds });
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
  }