@velaro/cli 1.4.172 → 1.4.174
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
|
@@ -57,6 +57,7 @@ import { aiFieldExtractionCommand } from '../lib/commands/ai-field-extraction.js
|
|
|
57
57
|
import { sentimentCommand, qualityCommand, chatIntelligenceThemesCommand } from '../lib/commands/quality-reports.js';
|
|
58
58
|
import { cannedLearningCommand } from '../lib/commands/canned-learning.js';
|
|
59
59
|
import { csatOverrideUnapproveCommand } from '../lib/commands/csat-override.js';
|
|
60
|
+
import { moshkyWriteAccessCommand } from '../lib/commands/moshky-write-access.js';
|
|
60
61
|
import { chatIntelligenceTopicsCommand } from '../lib/commands/chat-intelligence-topics.js';
|
|
61
62
|
import { focusCommand } from '../lib/commands/focus.js';
|
|
62
63
|
import { automationDraftCommand } from '../lib/commands/automation-draft.js';
|
|
@@ -216,6 +217,7 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
216
217
|
.command(cannedLearningCommand)
|
|
217
218
|
.command(chatIntelligenceTopicsCommand)
|
|
218
219
|
.command(csatOverrideUnapproveCommand)
|
|
220
|
+
.command(moshkyWriteAccessCommand)
|
|
219
221
|
.command(focusCommand)
|
|
220
222
|
.command(automationDraftCommand)
|
|
221
223
|
.command(magentoCommand)
|
|
@@ -5,6 +5,7 @@ import { runCommand } from '../run.js';
|
|
|
5
5
|
// CLI for CRM Studio (docs/architecture/crm-studio-program.md):
|
|
6
6
|
// field-* CrmCustomFieldsController /CrmCustomFields
|
|
7
7
|
// layout-* CrmFormLayoutsController /CrmFormLayouts
|
|
8
|
+
// formula-test POST /CrmCustomFields/formula/test (dry run of a calculated field or rollup; writes nothing)
|
|
8
9
|
// The site always comes from the signed-in credential; no command takes a site id.
|
|
9
10
|
// MCP parity: mcp/parity/crm-studio.customer.js (crm_* tools).
|
|
10
11
|
|
|
@@ -26,6 +27,29 @@ const q = (o) => {
|
|
|
26
27
|
return p.length ? `?${p.join('&')}` : '';
|
|
27
28
|
};
|
|
28
29
|
|
|
30
|
+
// Calculated fields (CRM Studio): a field whose FormulaJson is { kind: 'formula'|'rollup', expr, resultType, when|where }.
|
|
31
|
+
// Expressions: + - * / %, comparisons, && || !, IF ROUND MIN MAX ABS CONCAT COALESCE TODAY DAYS_BETWEEN; refs are built-in field
|
|
32
|
+
// names or cf:<id>. Rollups: SUM|COUNT|MIN|MAX|AVG of lineItems (deal), deals (company, contact) or tickets (contact).
|
|
33
|
+
const RESULT_TYPES = ['number', 'text', 'date', 'boolean'];
|
|
34
|
+
const RESULT_FOR_FIELD = { Number: 'number', Currency: 'number', Percent: 'number', Text: 'text', LongText: 'text', Date: 'date', Checkbox: 'boolean' };
|
|
35
|
+
const parseJsonOpt = (v, name) => {
|
|
36
|
+
try { return JSON.parse(v); } catch { throw new Error(`[CRM] --${name} must be valid JSON.`); }
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// --formula takes the whole spec as JSON ("" clears it); --expr builds one from the pieces.
|
|
40
|
+
function formulaArg(argv) {
|
|
41
|
+
if (argv.formula !== undefined) return argv.formula;
|
|
42
|
+
if (argv.expr === undefined) return undefined;
|
|
43
|
+
const kind = argv.kind ?? 'formula';
|
|
44
|
+
const spec = { kind, expr: argv.expr };
|
|
45
|
+
const resultType = argv.resultType ?? (kind === 'rollup' ? 'number' : RESULT_FOR_FIELD[argv.type]);
|
|
46
|
+
if (!resultType) throw new Error('[CRM] --result-type is required (number, text, date or boolean) when it cannot be taken from --type.');
|
|
47
|
+
spec.resultType = resultType;
|
|
48
|
+
if (argv.when !== undefined) spec.when = parseJsonOpt(argv.when, 'when');
|
|
49
|
+
if (argv.where !== undefined) spec.where = parseJsonOpt(argv.where, 'where');
|
|
50
|
+
return JSON.stringify(spec);
|
|
51
|
+
}
|
|
52
|
+
|
|
29
53
|
const json = (y) => y.option('json', { type: 'boolean', default: false, describe: 'Print raw JSON' });
|
|
30
54
|
const entity = (y) => y.option('entity', { choices: ENTITIES, demandOption: true, describe: 'Record type' });
|
|
31
55
|
|
|
@@ -58,11 +82,27 @@ async function fieldDefineHandler(argv) {
|
|
|
58
82
|
set('readRolesJson', listArg(argv.readRoles));
|
|
59
83
|
set('writeRolesJson', listArg(argv.writeRoles));
|
|
60
84
|
set('visibleWhenJson', argv.visibleWhen);
|
|
85
|
+
set('formulaJson', formulaArg(argv));
|
|
61
86
|
const r = data(argv.id ? await messagingPut(`/CrmCustomFields/${argv.id}`, body) : await messagingPost('/CrmCustomFields', body));
|
|
62
87
|
if (argv.json) return printJson(r);
|
|
63
88
|
console.log(`\n Field saved: ${argv.label}${r?.id ? ` (#${r.id})` : ''}.\n`);
|
|
64
89
|
}
|
|
65
90
|
|
|
91
|
+
async function formulaTestHandler(argv) {
|
|
92
|
+
const body = { entity: argv.entity };
|
|
93
|
+
if (argv.formula !== undefined) body.formulaJson = argv.formula;
|
|
94
|
+
else {
|
|
95
|
+
body.expr = argv.expr;
|
|
96
|
+
body.resultType = argv.resultType ?? 'number';
|
|
97
|
+
}
|
|
98
|
+
if (argv.sample !== undefined) body.sampleValues = parseJsonOpt(argv.sample, 'sample');
|
|
99
|
+
if (argv.recordId !== undefined) body.recordId = argv.recordId;
|
|
100
|
+
const r = data(await messagingPost('/CrmCustomFields/formula/test', body));
|
|
101
|
+
if (argv.json) return printJson(r);
|
|
102
|
+
if (r?.error) console.log(`\n ${BOLD}Could not calculate:${RST} ${r.error}\n`);
|
|
103
|
+
else console.log(`\n ${BOLD}Result${RST} (${r?.resultType}): ${r?.value === null || r?.value === undefined ? 'no value' : r.value}\n`);
|
|
104
|
+
}
|
|
105
|
+
|
|
66
106
|
async function fieldArchiveHandler(argv) {
|
|
67
107
|
await messagingDel(`/CrmCustomFields/${argv.id}`);
|
|
68
108
|
console.log(`\n Field ${argv.id} archived. Saved values are kept.\n`);
|
|
@@ -143,9 +183,27 @@ export const crmCommand = {
|
|
|
143
183
|
.option('validation', { type: 'string', describe: 'JSON, for example {"min":0,"max":100}' })
|
|
144
184
|
.option('read-roles', { type: 'string', alias: 'readRoles', describe: 'Comma-separated role names; empty means everyone' })
|
|
145
185
|
.option('write-roles', { type: 'string', alias: 'writeRoles', describe: 'Comma-separated role names; empty means everyone' })
|
|
146
|
-
.option('visible-when', { type: 'string', alias: 'visibleWhen', describe: 'JSON rule' })
|
|
186
|
+
.option('visible-when', { type: 'string', alias: 'visibleWhen', describe: 'JSON rule' })
|
|
187
|
+
.option('formula', { type: 'string', describe: 'Calculated field spec as JSON, for example {"kind":"formula","expr":"amount * 2","resultType":"number"}; empty clears it' })
|
|
188
|
+
.option('expr', { type: 'string', describe: 'Calculated field expression, for example "ROUND(amount * probability / 100, 2)" or "SUM(lineItems.total)" (builds --formula)' })
|
|
189
|
+
.option('kind', { choices: ['formula', 'rollup'], describe: 'With --expr: a formula (default) or a rollup over related records' })
|
|
190
|
+
.option('result-type', { choices: RESULT_TYPES, alias: 'resultType', describe: 'With --expr: defaults from --type (Number, Currency, Percent = number); rollups are numbers' })
|
|
191
|
+
.option('when', { type: 'string', describe: 'With --expr (formula): JSON rule; the field has a value only when it is true' })
|
|
192
|
+
.option('where', { type: 'string', describe: 'With --expr (rollup): JSON rule over the related rows; only matching rows are counted' })),
|
|
147
193
|
handler: runCommand(fieldDefineHandler),
|
|
148
194
|
})
|
|
195
|
+
.command({
|
|
196
|
+
command: 'formula-test',
|
|
197
|
+
describe: 'Dry-run a calculated field expression or rollup against sample values or a real record (Administrator; writes nothing)',
|
|
198
|
+
builder: (yy) => json(entity(yy)
|
|
199
|
+
.option('expr', { type: 'string', describe: 'Expression, for example "amount * 2"' })
|
|
200
|
+
.option('formula', { type: 'string', describe: 'Whole spec as JSON instead of --expr (use for rollups)' })
|
|
201
|
+
.option('result-type', { choices: RESULT_TYPES, alias: 'resultType', describe: 'Defaults to number' })
|
|
202
|
+
.option('sample', { type: 'string', describe: 'JSON object of sample values, for example {"amount":100,"cf:12":"Gold"}' })
|
|
203
|
+
.option('record-id', { type: 'number', alias: 'recordId', describe: "Use this record's real values underneath the samples (required to test a rollup)" })
|
|
204
|
+
.check((a) => (a.expr || a.formula !== undefined) ? true : '[CRM] Pass --expr or --formula.')),
|
|
205
|
+
handler: runCommand(formulaTestHandler),
|
|
206
|
+
})
|
|
149
207
|
.command({ command: 'field-archive <id>', describe: 'Archive a CRM custom field (Administrator)', handler: runCommand(fieldArchiveHandler) })
|
|
150
208
|
.command({
|
|
151
209
|
command: 'layout-list',
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { get as adminGet, put as adminPut } from '../api.js';
|
|
2
|
+
import { runCommand } from '../run.js';
|
|
3
|
+
|
|
4
|
+
// velaro moshky-write-access show state + consent version
|
|
5
|
+
// velaro moshky-write-access --on --acknowledge --consent-version <v> turn on (customer accepted the consent text)
|
|
6
|
+
// velaro moshky-write-access --off turn off
|
|
7
|
+
// REST: admin GET/PUT /Copilot/WriteAccess (site comes from the session; audit-logged)
|
|
8
|
+
export const moshkyWriteAccessCommand = {
|
|
9
|
+
command: 'moshky-write-access',
|
|
10
|
+
describe: "Show or change 'Moshky can make changes' for this site",
|
|
11
|
+
builder: (y) => y
|
|
12
|
+
.option('on', { type: 'boolean', describe: 'Turn on (needs --acknowledge and --consent-version)' })
|
|
13
|
+
.option('off', { type: 'boolean', describe: 'Turn off' })
|
|
14
|
+
.option('acknowledge', { type: 'boolean', describe: 'Customer accepted the consent text' })
|
|
15
|
+
.option('consent-version', { type: 'string', describe: 'Version from the show output' }),
|
|
16
|
+
handler: runCommand(async (a) => {
|
|
17
|
+
if (a.on && a.off) throw new Error('choose --on or --off, not both');
|
|
18
|
+
if (!a.on && !a.off) {
|
|
19
|
+
console.log(JSON.stringify(await adminGet('/Copilot/WriteAccess'), null, 2));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
console.log(JSON.stringify(await adminPut('/Copilot/WriteAccess', {
|
|
23
|
+
enabled: !!a.on,
|
|
24
|
+
acknowledged: !!a.acknowledge,
|
|
25
|
+
consentVersion: a['consent-version'] || '',
|
|
26
|
+
}), null, 2));
|
|
27
|
+
}),
|
|
28
|
+
};
|
package/package.json
CHANGED