@velaro/cli 1.4.208 → 1.4.209

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/velaro.js CHANGED
@@ -139,6 +139,7 @@ import { aiFollowupsCommand, businessActionCommand, callCommand, conversationCom
139
139
  import { crmViewCommand, crmBulkCommand, crmWebformCommand } from '../lib/commands/crm-views-bulk-webforms.js';
140
140
  import { crmImportCommand, crmTagCommand, crmDedupeCommand, crmAuditCommand } from '../lib/commands/crm-import-dedupe-audit.js';
141
141
  import { crmObjectCommand, crmRelCommand } from '../lib/commands/crm-objects-relationships.js';
142
+ import { crmApprovalCommand, crmScoreCommand } from '../lib/commands/crm-approvals-scoring.js';
142
143
  import { featureDiscoveryGroup } from '../lib/commands/feature-discovery.js';
143
144
  import { billingInsightsGroup } from '../lib/commands/billing-insights.js';
144
145
  import { supportTicketsCommand } from '../lib/commands/support-tickets.js';
@@ -329,6 +330,8 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
329
330
  .command(crmAuditCommand)
330
331
  .command(crmObjectCommand)
331
332
  .command(crmRelCommand)
333
+ .command(crmApprovalCommand)
334
+ .command(crmScoreCommand)
332
335
  .demandCommand(1, 'Specify a command. Run "velaro --help" for options.')
333
336
  .strict()
334
337
  .fail((msg, err, y) => {
@@ -0,0 +1,179 @@
1
+ import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
2
+ import { runCommand } from '../run.js';
3
+
4
+ // -- velaro crm-approval / crm-score -------------------------------------------
5
+ // CLI for CRM Studio features 15 and 16 (docs/architecture/crm-studio-program.md):
6
+ // crm-approval CrmApprovalsController /CrmApprovals (rules that hold a deal change for a Manager or Administrator)
7
+ // crm-score CrmLeadScoringController /CrmLeadScoring (lead scoring rules, preview and recompute)
8
+ // The site always comes from the signed-in credential; no command takes a site id.
9
+ // MCP parity: mcp/parity/crm-approvals-scoring.customer.js (crm_approval_*, crm_score_* tools).
10
+
11
+ const BOLD = '\x1b[1m';
12
+ const DIM = '\x1b[2m';
13
+ const RST = '\x1b[0m';
14
+
15
+ const data = (r) => (r && typeof r === 'object' && 'data' in r ? r.data : r);
16
+ const printJson = (v) => console.log(JSON.stringify(v, null, 2));
17
+ const q = (o) => {
18
+ const p = Object.entries(o).filter(([, v]) => v !== undefined && v !== null && v !== '').map(([k, v]) => `${k}=${encodeURIComponent(v)}`);
19
+ return p.length ? `?${p.join('&')}` : '';
20
+ };
21
+ const json = (y) => y.option('json', { type: 'boolean', default: false, describe: 'Print raw JSON' });
22
+ const parseJson = (text, what) => {
23
+ try { return JSON.parse(text); } catch { throw new Error(`[CRM] ${what} must be valid JSON.`); }
24
+ };
25
+ const done = (msg) => console.log(`\n ${msg}\n`);
26
+
27
+ // ---------------------------------------------------------------- approvals
28
+
29
+ async function approvalRuleListHandler(argv) {
30
+ const r = data(await messagingGet('/CrmApprovals/rules'));
31
+ if (argv.json) return printJson(r);
32
+ const list = Array.isArray(r) ? r : r?.rules ?? [];
33
+ console.log(`\n${BOLD}Approval rules${RST} (${list.length})`);
34
+ for (const x of list) console.log(` #${x.id} ${x.name} ${DIM}${x.kind}${x.threshold != null ? `, over ${x.threshold}` : ''}${x.stageId ? `, stage ${x.stageId}` : ''}${x.isActive === false ? ', off' : ''}${RST}`);
35
+ console.log('');
36
+ }
37
+
38
+ // --body is the rule as JSON: kind (stage | amount | discount), name, stageId, pipelineId, threshold, isActive, includeManagers.
39
+ async function approvalRuleSaveHandler(argv) {
40
+ const body = parseJson(argv.body, '--body');
41
+ const r = data(argv.id ? await messagingPut(`/CrmApprovals/rules/${argv.id}`, body) : await messagingPost('/CrmApprovals/rules', body));
42
+ if (argv.json) return printJson(r);
43
+ done(`Approval rule saved${r?.id ? ` (#${r.id})` : ''}.`);
44
+ }
45
+
46
+ async function approvalRuleDeleteHandler(argv) {
47
+ await messagingDel(`/CrmApprovals/rules/${argv.id}`);
48
+ done(`Approval rule ${argv.id} deleted. Changes already waiting stay in the queue.`);
49
+ }
50
+
51
+ async function approvalListHandler(argv) {
52
+ const r = data(await messagingGet(`/CrmApprovals${q({ status: argv.status, page: argv.page, pageSize: argv.pageSize })}`));
53
+ if (argv.json) return printJson(r);
54
+ const rows = r?.items ?? [];
55
+ console.log(`\n${BOLD}Approvals (${argv.status})${RST} (${r?.total ?? rows.length})`);
56
+ for (const a of rows) console.log(` #${a.id} deal #${a.dealId} ${a.dealName ?? ''} ${a.summary} ${DIM}requested by ${a.requestedBy ?? 'unknown'}${a.reviewer ? `, ${a.status} by ${a.reviewer}` : ''}${RST}`);
57
+ console.log('');
58
+ }
59
+
60
+ async function approvalApproveHandler(argv) {
61
+ const r = data(await messagingPost(`/CrmApprovals/${argv.id}/approve`, { comment: argv.comment }));
62
+ if (argv.json) return printJson(r);
63
+ done(`Approval ${argv.id} approved and the change applied.`);
64
+ }
65
+
66
+ async function approvalRejectHandler(argv) {
67
+ const r = data(await messagingPost(`/CrmApprovals/${argv.id}/reject`, { comment: argv.comment }));
68
+ if (argv.json) return printJson(r);
69
+ done(`Approval ${argv.id} rejected. The deal was not changed.`);
70
+ }
71
+
72
+ export const crmApprovalCommand = {
73
+ command: 'crm-approval <subcommand>',
74
+ describe: 'CRM approvals: hold a deal stage move, amount or discount for a Manager or Administrator to decide',
75
+ builder: (y) => y
76
+ .command({ command: 'rule-list', describe: 'List approval rules', builder: json, handler: runCommand(approvalRuleListHandler) })
77
+ .command({
78
+ command: 'rule-save',
79
+ describe: 'Create an approval rule, or update one with --id',
80
+ builder: (yy) => json(yy
81
+ .option('id', { type: 'number' })
82
+ .option('body', { type: 'string', demandOption: true, describe: 'Rule as JSON: kind (stage, amount or discount), name, stageId, pipelineId, threshold, isActive, includeManagers' })),
83
+ handler: runCommand(approvalRuleSaveHandler),
84
+ })
85
+ .command({ command: 'rule-delete <id>', describe: 'Delete an approval rule', handler: runCommand(approvalRuleDeleteHandler) })
86
+ .command({
87
+ command: 'list',
88
+ describe: 'List approval requests',
89
+ builder: (yy) => json(yy
90
+ .option('status', { choices: ['pending', 'approved', 'rejected', 'all'], default: 'pending' })
91
+ .option('page', { type: 'number', default: 1 })
92
+ .option('page-size', { type: 'number', alias: 'pageSize' })),
93
+ handler: runCommand(approvalListHandler),
94
+ })
95
+ .command({
96
+ command: 'approve <id>',
97
+ describe: 'Approve a held change; it is applied and attributed to you',
98
+ builder: (yy) => json(yy.option('comment', { type: 'string' })),
99
+ handler: runCommand(approvalApproveHandler),
100
+ })
101
+ .command({
102
+ command: 'reject <id>',
103
+ describe: 'Reject a held change (a comment is required)',
104
+ builder: (yy) => json(yy.option('comment', { type: 'string', demandOption: true })),
105
+ handler: runCommand(approvalRejectHandler),
106
+ })
107
+ .demandCommand(1),
108
+ handler: () => {},
109
+ };
110
+
111
+ // ---------------------------------------------------------------- lead scoring
112
+
113
+ async function scoreRuleListHandler(argv) {
114
+ const r = data(await messagingGet('/CrmLeadScoring/rules'));
115
+ if (argv.json) return printJson(r);
116
+ const list = Array.isArray(r) ? r : r?.rules ?? [];
117
+ console.log(`\n${BOLD}Lead scoring rules${RST} (${list.length})`);
118
+ for (const x of list) console.log(` #${x.id} ${x.name ?? ''} ${DIM}${x.kind}, ${x.points} point(s)${x.isActive === false ? ', off' : ''}${RST}`);
119
+ console.log('');
120
+ }
121
+
122
+ // --body is the rule as JSON: kind (field | activity | decay), name, field, operator, value, activityType, windowDays, decayDays, points, maxPoints, isActive.
123
+ async function scoreRuleSaveHandler(argv) {
124
+ const body = parseJson(argv.body, '--body');
125
+ const r = data(argv.id ? await messagingPut(`/CrmLeadScoring/rules/${argv.id}`, body) : await messagingPost('/CrmLeadScoring/rules', body));
126
+ if (argv.json) return printJson(r);
127
+ done(`Scoring rule saved${r?.id ? ` (#${r.id})` : ''}.`);
128
+ }
129
+
130
+ async function scoreRuleDeleteHandler(argv) {
131
+ await messagingDel(`/CrmLeadScoring/rules/${argv.id}`);
132
+ done(`Scoring rule ${argv.id} deleted. Scores update the next time they are recomputed.`);
133
+ }
134
+
135
+ async function scorePreviewHandler(argv) {
136
+ const r = data(await messagingGet(`/CrmLeadScoring/preview${q({ contactId: argv.contactId })}`));
137
+ if (argv.json) return printJson(r);
138
+ console.log(`\n${BOLD}Score for contact #${argv.contactId}${RST}: ${r.score} (stored ${r.storedScore}). Nothing was saved.`);
139
+ for (const l of r.breakdown ?? []) console.log(` ${l.points >= 0 ? '+' : ''}${l.points} ${l.label} ${DIM}${l.detail ?? ''}${RST}`);
140
+ console.log('');
141
+ }
142
+
143
+ async function scoreRecomputeHandler(argv) {
144
+ const body = {};
145
+ if (argv.contactId !== undefined) body.contactId = argv.contactId;
146
+ if (argv.afterId !== undefined) body.afterId = argv.afterId;
147
+ if (argv.batchSize !== undefined) body.batchSize = argv.batchSize;
148
+ const r = data(await messagingPost('/CrmLeadScoring/recompute', body));
149
+ if (argv.json) return printJson(r);
150
+ printJson(r);
151
+ }
152
+
153
+ export const crmScoreCommand = {
154
+ command: 'crm-score <subcommand>',
155
+ describe: 'CRM lead scoring: rules, a score preview for a contact, and recompute',
156
+ builder: (y) => y
157
+ .command({ command: 'rule-list', describe: 'List scoring rules', builder: json, handler: runCommand(scoreRuleListHandler) })
158
+ .command({
159
+ command: 'rule-save',
160
+ describe: 'Create a scoring rule, or update one with --id',
161
+ builder: (yy) => json(yy
162
+ .option('id', { type: 'number' })
163
+ .option('body', { type: 'string', demandOption: true, describe: 'Rule as JSON: kind (field, activity or decay), name, field, operator, value, activityType, windowDays, decayDays, points, maxPoints, isActive' })),
164
+ handler: runCommand(scoreRuleSaveHandler),
165
+ })
166
+ .command({ command: 'rule-delete <id>', describe: 'Delete a scoring rule', handler: runCommand(scoreRuleDeleteHandler) })
167
+ .command({ command: 'preview', describe: 'Show the score and breakdown for one contact without saving it', builder: (yy) => json(yy.option('contact-id', { type: 'number', alias: 'contactId', demandOption: true })), handler: runCommand(scorePreviewHandler) })
168
+ .command({
169
+ command: 'recompute',
170
+ describe: 'Recompute and store scores: one contact, or batches walked with --after-id',
171
+ builder: (yy) => json(yy
172
+ .option('contact-id', { type: 'number', alias: 'contactId' })
173
+ .option('after-id', { type: 'number', alias: 'afterId' })
174
+ .option('batch-size', { type: 'number', alias: 'batchSize' })),
175
+ handler: runCommand(scoreRecomputeHandler),
176
+ })
177
+ .demandCommand(1),
178
+ handler: () => {},
179
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.208",
3
+ "version": "1.4.209",
4
4
  "description": "Velaro Workspace v20 — command-line interface for managing bots, knowledge base ingestion, MCP API keys, search indexes, and ops health.",
5
5
  "type": "module",
6
6
  "bin": {