@velaro/cli 1.4.124 → 1.4.126
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 +2 -0
- package/lib/commands/deal.js +168 -0
- package/package.json +1 -1
package/bin/velaro.js
CHANGED
|
@@ -99,6 +99,7 @@ import { callbackCommand } from '../lib/commands/callback.js';
|
|
|
99
99
|
import { callpresenceCommand } from '../lib/commands/callpresence.js';
|
|
100
100
|
import { authorityCommand } from '../lib/commands/authority.js';
|
|
101
101
|
import { caseCommand } from '../lib/commands/case.js';
|
|
102
|
+
import { dealCommand } from '../lib/commands/deal.js';
|
|
102
103
|
import { ticketCommand } from '../lib/commands/ticket.js';
|
|
103
104
|
import { pickupCommand } from '../lib/commands/pickup.js';
|
|
104
105
|
import { siteSaleCommand } from '../lib/commands/site-sale.js';
|
|
@@ -247,6 +248,7 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
247
248
|
.command(callpresenceCommand)
|
|
248
249
|
.command(authorityCommand)
|
|
249
250
|
.command(caseCommand)
|
|
251
|
+
.command(dealCommand)
|
|
250
252
|
.command(ticketCommand)
|
|
251
253
|
.command(pickupCommand)
|
|
252
254
|
.command(siteSaleCommand)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
|
|
2
|
+
import { runCommand } from '../run.js';
|
|
3
|
+
|
|
4
|
+
// -- velaro deal --------------------------------------------------------------
|
|
5
|
+
// CLI for the Sales Hub parity rows QUOTE-1 and FCST-1 (velaro-messaging docs/architecture/ticketing-hubspot-parity-plan.md):
|
|
6
|
+
// quote-* DealQuotesController api/v1/deals/{dealId}/quotes, api/v1/quotes/{id}, api/v1/quotes/{id}/send
|
|
7
|
+
// forecast* CrmForecastController api/v1/forecast, api/v1/forecast/submissions, api/v1/deals/{dealId}/forecast-category
|
|
8
|
+
// The site always comes from the signed-in credential; no command takes a site id.
|
|
9
|
+
// MCP parity: mcp/parity/deal.customer.js (deal_quote_*, deal_forecast_* 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 money = (v, cur) => `${cur ?? ''} ${Number(v ?? 0).toFixed(2)}`.trim();
|
|
17
|
+
|
|
18
|
+
function printJson(v) {
|
|
19
|
+
console.log(JSON.stringify(v, null, 2));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function quoteBody(argv) {
|
|
23
|
+
const b = {};
|
|
24
|
+
if (argv.discount !== undefined) b.discountPercent = argv.discount;
|
|
25
|
+
if (argv.tax !== undefined) b.taxPercent = argv.tax;
|
|
26
|
+
if (argv.terms !== undefined) b.terms = argv.terms;
|
|
27
|
+
if (argv.notes !== undefined) b.notes = argv.notes;
|
|
28
|
+
if (argv.validUntil !== undefined) b.validUntil = argv.validUntil;
|
|
29
|
+
if (argv.contactId !== undefined) b.contactId = argv.contactId;
|
|
30
|
+
if (argv.refreshLines) b.refreshLineItems = true;
|
|
31
|
+
return b;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function printQuote(q) {
|
|
35
|
+
console.log(`\n${BOLD}${q.quoteNumber}${RST} ${q.status} deal ${q.dealId}`);
|
|
36
|
+
console.log(` Buyer: ${q.customerName ?? '-'} ${q.customerEmail ? `<${q.customerEmail}>` : ''}`);
|
|
37
|
+
for (const l of Array.isArray(q.lines) ? q.lines : []) {
|
|
38
|
+
console.log(` ${DIM}${l.quantity ?? 1} x ${l.name ?? l.description ?? ''} @ ${money(l.unitPrice ?? l.price, q.currency)}${RST}`);
|
|
39
|
+
}
|
|
40
|
+
console.log(` Subtotal ${money(q.subtotal, q.currency)} Discount ${money(q.discountAmount, q.currency)} Tax ${money(q.taxAmount, q.currency)} ${BOLD}Total ${money(q.total, q.currency)}${RST}`);
|
|
41
|
+
if (q.validUntil) console.log(` Valid until ${q.validUntil}`);
|
|
42
|
+
if (q.shareUrl) console.log(` Link: ${q.shareUrl}`);
|
|
43
|
+
console.log('');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ---- quotes (QUOTE-1) ---------------------------------------------------------
|
|
47
|
+
async function quoteListHandler(argv) {
|
|
48
|
+
const v = data(await messagingGet(`/api/v1/deals/${argv.dealId}/quotes`));
|
|
49
|
+
const list = Array.isArray(v?.quotes) ? v.quotes : [];
|
|
50
|
+
if (argv.json) return printJson(list);
|
|
51
|
+
console.log(`\n${BOLD}Quotes for deal ${argv.dealId}${RST} (${list.length})`);
|
|
52
|
+
for (const q of list) console.log(` #${q.id} ${q.quoteNumber} ${q.status} ${money(q.total, q.currency)}${q.shareUrl ? ` ${DIM}${q.shareUrl}${RST}` : ''}`);
|
|
53
|
+
console.log('');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function quoteGetHandler(argv) {
|
|
57
|
+
const q = data(await messagingGet(`/api/v1/quotes/${argv.id}`));
|
|
58
|
+
if (argv.json) return printJson(q);
|
|
59
|
+
printQuote(q);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function quoteCreateHandler(argv) {
|
|
63
|
+
const q = data(await messagingPost(`/api/v1/deals/${argv.dealId}/quotes`, quoteBody(argv)));
|
|
64
|
+
if (argv.json) return printJson(q);
|
|
65
|
+
console.log(`\n Created draft quote #${q.id} from the deal's line items.`);
|
|
66
|
+
printQuote(q);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function quoteUpdateHandler(argv) {
|
|
70
|
+
const q = data(await messagingPut(`/api/v1/quotes/${argv.id}`, quoteBody(argv)));
|
|
71
|
+
if (argv.json) return printJson(q);
|
|
72
|
+
printQuote(q);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function quoteDeleteHandler(argv) {
|
|
76
|
+
await messagingDel(`/api/v1/quotes/${argv.id}`);
|
|
77
|
+
console.log(`\n Deleted quote #${argv.id}.\n`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function quoteSendHandler(argv) {
|
|
81
|
+
const v = data(await messagingPost(`/api/v1/quotes/${argv.id}/send`, argv.email ? { email: argv.email } : {}));
|
|
82
|
+
if (argv.json) return printJson(v);
|
|
83
|
+
const q = v?.quote ?? v;
|
|
84
|
+
console.log(`\n Quote ${q?.quoteNumber ?? `#${argv.id}`} marked Sent.${v?.emailed ? ' Emailed to the buyer.' : ''}`);
|
|
85
|
+
if (v?.emailError) console.log(` ${DIM}${v.emailError}${RST}`);
|
|
86
|
+
if (q?.shareUrl ?? v?.shareUrl) console.log(` Link: ${q?.shareUrl ?? v?.shareUrl}`);
|
|
87
|
+
console.log('');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ---- forecast (FCST-1) ----------------------------------------------------------
|
|
91
|
+
async function forecastHandler(argv) {
|
|
92
|
+
const qs = new URLSearchParams();
|
|
93
|
+
if (argv.period) qs.set('period', argv.period);
|
|
94
|
+
if (argv.ownerUserId) qs.set('ownerUserId', String(argv.ownerUserId));
|
|
95
|
+
const v = data(await messagingGet(`/api/v1/forecast${qs.toString() ? `?${qs}` : ''}`));
|
|
96
|
+
if (argv.json) return printJson(v);
|
|
97
|
+
const rows = Array.isArray(v?.rows) ? v.rows : [];
|
|
98
|
+
console.log(`\n${BOLD}Forecast ${v?.period ?? ''}${RST}`);
|
|
99
|
+
console.log(` ${'Rep'.padEnd(24)}${'Quota'.padStart(12)}${'Won'.padStart(12)}${'Commit'.padStart(12)}${'Best case'.padStart(12)}${'Pipeline'.padStart(12)}${'Submitted'.padStart(12)}`);
|
|
100
|
+
for (const r of [...rows, ...(v?.totals ? [v.totals] : [])]) {
|
|
101
|
+
const n = (x) => Number(x ?? 0).toFixed(0).padStart(12);
|
|
102
|
+
console.log(` ${String(r.ownerName ?? '-').slice(0, 23).padEnd(24)}${n(r.quota)}${n(r.closedWon)}${n(r.commit)}${n(r.bestCase)}${n(r.pipeline)}${r.submittedAmount == null ? '-'.padStart(12) : n(r.submittedAmount)}`);
|
|
103
|
+
}
|
|
104
|
+
console.log('');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function forecastSubmitHandler(argv) {
|
|
108
|
+
const v = data(await messagingPost('/api/v1/forecast/submissions', { period: argv.period, amount: argv.amount, note: argv.note }));
|
|
109
|
+
if (argv.json) return printJson(v);
|
|
110
|
+
console.log(`\n Submitted ${argv.amount} for ${argv.period}.\n`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function forecastCategoryHandler(argv) {
|
|
114
|
+
const v = data(await messagingPut(`/api/v1/deals/${argv.dealId}/forecast-category`, { category: argv.category }));
|
|
115
|
+
if (argv.json) return printJson(v);
|
|
116
|
+
console.log(`\n Deal ${argv.dealId} forecast category: ${v?.effectiveCategory ?? argv.category}.\n`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const json = (y) => y.option('json', { type: 'boolean' });
|
|
120
|
+
const quoteOpts = (y) => json(y)
|
|
121
|
+
.option('discount', { type: 'number', describe: 'Discount percent' })
|
|
122
|
+
.option('tax', { type: 'number', describe: 'Tax percent' })
|
|
123
|
+
.option('terms', { type: 'string' })
|
|
124
|
+
.option('notes', { type: 'string' })
|
|
125
|
+
.option('valid-until', { type: 'string', describe: 'ISO date' })
|
|
126
|
+
.option('contact-id', { type: 'number', describe: 'Buyer contact (defaults to the deal contact)' })
|
|
127
|
+
.option('refresh-lines', { type: 'boolean', describe: "Re-copy the deal's line items" });
|
|
128
|
+
|
|
129
|
+
export const dealCommand = {
|
|
130
|
+
command: 'deal',
|
|
131
|
+
describe: 'Native CRM deals: quotes and forecast (Native CRM)',
|
|
132
|
+
builder: (y) => y
|
|
133
|
+
.command({ command: 'quote-list <dealId>', describe: 'List quotes on a deal', builder: json, handler: runCommand(quoteListHandler) })
|
|
134
|
+
.command({ command: 'quote-get <id>', describe: 'Show a quote', builder: json, handler: runCommand(quoteGetHandler) })
|
|
135
|
+
.command({ command: 'quote-create <dealId>', describe: "Create a draft quote from the deal's line items", builder: quoteOpts, handler: runCommand(quoteCreateHandler) })
|
|
136
|
+
.command({ command: 'quote-update <id>', describe: 'Edit a draft quote', builder: quoteOpts, handler: runCommand(quoteUpdateHandler) })
|
|
137
|
+
.command({ command: 'quote-delete <id>', describe: 'Delete a quote', handler: runCommand(quoteDeleteHandler) })
|
|
138
|
+
.command({
|
|
139
|
+
command: 'quote-send <id>',
|
|
140
|
+
describe: 'Mark a quote Sent, email the buyer and print the share link',
|
|
141
|
+
builder: (yy) => json(yy.option('email', { type: 'string', describe: 'Send to this address instead of the buyer on the quote' })),
|
|
142
|
+
handler: runCommand(quoteSendHandler),
|
|
143
|
+
})
|
|
144
|
+
.command({
|
|
145
|
+
command: 'forecast',
|
|
146
|
+
describe: 'Forecast by rep for a month: quota, won, commit, best case, pipeline, submitted',
|
|
147
|
+
builder: (yy) => json(yy.option('period', { type: 'string', describe: 'yyyy-MM (default this month)' }).option('owner-user-id', { type: 'number' })),
|
|
148
|
+
handler: runCommand(forecastHandler),
|
|
149
|
+
})
|
|
150
|
+
.command({
|
|
151
|
+
command: 'forecast-submit',
|
|
152
|
+
describe: 'Submit your forecast amount for a month',
|
|
153
|
+
builder: (yy) => json(yy
|
|
154
|
+
.option('period', { type: 'string', demandOption: true, describe: 'yyyy-MM' })
|
|
155
|
+
.option('amount', { type: 'number', demandOption: true })
|
|
156
|
+
.option('note', { type: 'string' })),
|
|
157
|
+
handler: runCommand(forecastSubmitHandler),
|
|
158
|
+
})
|
|
159
|
+
.command({
|
|
160
|
+
command: 'forecast-category <dealId> <category>',
|
|
161
|
+
describe: 'Set a deal forecast category: Pipeline, BestCase, Commit, Closed or Omitted',
|
|
162
|
+
builder: json,
|
|
163
|
+
handler: runCommand(forecastCategoryHandler),
|
|
164
|
+
})
|
|
165
|
+
.demandCommand(1, 'Specify a deal subcommand.')
|
|
166
|
+
.strict(),
|
|
167
|
+
handler: () => {},
|
|
168
|
+
};
|
package/package.json
CHANGED