@velaro/cli 1.4.207 → 1.4.208

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
@@ -138,6 +138,7 @@ import { recycleBinCommand, aiUsageCommand, siteInfoCommand, billingReceiptsComm
138
138
  import { aiFollowupsCommand, businessActionCommand, callCommand, conversationCommand, conversionCommand, ivrCommand } from '../lib/commands/ops-groups.js';
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
+ import { crmObjectCommand, crmRelCommand } from '../lib/commands/crm-objects-relationships.js';
141
142
  import { featureDiscoveryGroup } from '../lib/commands/feature-discovery.js';
142
143
  import { billingInsightsGroup } from '../lib/commands/billing-insights.js';
143
144
  import { supportTicketsCommand } from '../lib/commands/support-tickets.js';
@@ -326,6 +327,8 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
326
327
  .command(crmTagCommand)
327
328
  .command(crmDedupeCommand)
328
329
  .command(crmAuditCommand)
330
+ .command(crmObjectCommand)
331
+ .command(crmRelCommand)
329
332
  .demandCommand(1, 'Specify a command. Run "velaro --help" for options.')
330
333
  .strict()
331
334
  .fail((msg, err, y) => {
@@ -0,0 +1,251 @@
1
+ import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
2
+ import { runCommand } from '../run.js';
3
+
4
+ // -- velaro crm-object / crm-rel ------------------------------------------------
5
+ // CLI for CRM Studio features 18 and 19 (docs/architecture/crm-studio-program.md):
6
+ // crm-object CrmObjectsController /CrmObjects (custom record types, their fields and records)
7
+ // crm-rel CrmRelationshipsController /CrmRelationships (typed links between any two CRM records)
8
+ // The site always comes from the signed-in credential; no command takes a site id.
9
+ // MCP parity: mcp/parity/crm-objects-relationships.customer.js (crm_object_*, crm_rel_* 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
+ // ---------------------------------------------------------------- custom objects
28
+
29
+ async function typeListHandler(argv) {
30
+ const r = data(await messagingGet('/CrmObjects'));
31
+ if (argv.json) return printJson(r);
32
+ const list = Array.isArray(r) ? r : r?.types ?? [];
33
+ console.log(`\n${BOLD}Custom objects${RST} (${list.length})`);
34
+ for (const t of list) console.log(` #${t.id} ${t.name} ${DIM}${t.pluralName ?? ''}${t.isArchived ? ' (archived)' : ''}${RST}`);
35
+ console.log('');
36
+ }
37
+
38
+ async function typeSaveHandler(argv) {
39
+ const body = { name: argv.name, pluralName: argv.pluralName, description: argv.description };
40
+ const r = data(argv.id ? await messagingPut(`/CrmObjects/${argv.id}`, body) : await messagingPost('/CrmObjects', body));
41
+ if (argv.json) return printJson(r);
42
+ done(`Object type saved: ${r?.name ?? argv.name}${r?.id ? ` (#${r.id})` : ''}.`);
43
+ }
44
+
45
+ async function typeArchiveHandler(argv) {
46
+ await messagingDel(`/CrmObjects/${argv.id}`);
47
+ done(`Object type ${argv.id} archived. Its records are kept; restore it any time.`);
48
+ }
49
+
50
+ async function typeRestoreHandler(argv) {
51
+ await messagingPost(`/CrmObjects/${argv.id}/restore`, {});
52
+ done(`Object type ${argv.id} restored.`);
53
+ }
54
+
55
+ async function fieldListHandler(argv) {
56
+ printJson(data(await messagingGet(`/CrmObjects/${argv.typeId}/fields`)));
57
+ }
58
+
59
+ // --body is the field definition as JSON: label, fieldType, optionsJson, isRequired, helpText, defaultValue, readRolesJson, writeRolesJson.
60
+ async function fieldSaveHandler(argv) {
61
+ const body = parseJson(argv.body, '--body');
62
+ const r = data(argv.fieldId
63
+ ? await messagingPut(`/CrmObjects/${argv.typeId}/fields/${argv.fieldId}`, body)
64
+ : await messagingPost(`/CrmObjects/${argv.typeId}/fields`, body));
65
+ if (argv.json) return printJson(r);
66
+ done(`Field saved${r?.id ? ` (#${r.id})` : ''}.`);
67
+ }
68
+
69
+ async function fieldArchiveHandler(argv) {
70
+ await messagingDel(`/CrmObjects/${argv.typeId}/fields/${argv.fieldId}`);
71
+ done(`Field ${argv.fieldId} archived.`);
72
+ }
73
+
74
+ async function recordListHandler(argv) {
75
+ const r = data(await messagingGet(`/CrmObjects/${argv.typeId}/records${q({ search: argv.search, includeArchived: argv.includeArchived ? 'true' : undefined, page: argv.page, pageSize: argv.pageSize })}`));
76
+ if (argv.json) return printJson(r);
77
+ const rows = r?.items ?? r?.records ?? [];
78
+ console.log(`\n${BOLD}Records${RST} (${r?.total ?? rows.length})`);
79
+ for (const x of rows) console.log(` #${x.id} ${x.name}${x.isArchived ? ` ${DIM}(archived)${RST}` : ''}`);
80
+ console.log('');
81
+ }
82
+
83
+ async function recordGetHandler(argv) {
84
+ printJson(data(await messagingGet(`/CrmObjects/${argv.typeId}/records/${argv.id}`)));
85
+ }
86
+
87
+ // --values is a JSON array of { customFieldId, value }.
88
+ async function recordSaveHandler(argv) {
89
+ const body = { name: argv.name };
90
+ if (argv.values !== undefined) body.values = parseJson(argv.values, '--values');
91
+ const r = data(argv.id
92
+ ? await messagingPut(`/CrmObjects/${argv.typeId}/records/${argv.id}`, body)
93
+ : await messagingPost(`/CrmObjects/${argv.typeId}/records`, body));
94
+ if (argv.json) return printJson(r);
95
+ done(`Record saved${r?.id ? ` (#${r.id})` : ''}.`);
96
+ }
97
+
98
+ async function recordArchiveHandler(argv) {
99
+ await messagingDel(`/CrmObjects/${argv.typeId}/records/${argv.id}`);
100
+ done(`Record ${argv.id} archived.`);
101
+ }
102
+
103
+ async function recordRestoreHandler(argv) {
104
+ await messagingPost(`/CrmObjects/${argv.typeId}/records/${argv.id}/restore`, {});
105
+ done(`Record ${argv.id} restored.`);
106
+ }
107
+
108
+ const typeIdArg = (yy) => yy.positional('typeId', { type: 'number' });
109
+
110
+ export const crmObjectCommand = {
111
+ command: 'crm-object <subcommand>',
112
+ describe: 'CRM custom objects: your own record types, fields and records (defining types and fields needs an Administrator)',
113
+ builder: (y) => y
114
+ .command({ command: 'type-list', describe: 'List the custom object types', builder: json, handler: runCommand(typeListHandler) })
115
+ .command({
116
+ command: 'type-save',
117
+ describe: 'Create an object type, or update one with --id',
118
+ builder: (yy) => json(yy
119
+ .option('id', { type: 'number' })
120
+ .option('name', { type: 'string', demandOption: true })
121
+ .option('plural-name', { type: 'string', alias: 'pluralName' })
122
+ .option('description', { type: 'string' })),
123
+ handler: runCommand(typeSaveHandler),
124
+ })
125
+ .command({ command: 'type-archive <id>', describe: 'Archive an object type (never hard-deleted)', handler: runCommand(typeArchiveHandler) })
126
+ .command({ command: 'type-restore <id>', describe: 'Restore an archived object type', handler: runCommand(typeRestoreHandler) })
127
+ .command({ command: 'field-list <typeId>', describe: 'List the fields of an object type', builder: typeIdArg, handler: runCommand(fieldListHandler) })
128
+ .command({
129
+ command: 'field-save <typeId>',
130
+ describe: 'Add a field, or update one with --field-id',
131
+ builder: (yy) => json(typeIdArg(yy)
132
+ .option('field-id', { type: 'number', alias: 'fieldId' })
133
+ .option('body', { type: 'string', demandOption: true, describe: 'Field definition as JSON: label, fieldType, optionsJson, isRequired, helpText, defaultValue' })),
134
+ handler: runCommand(fieldSaveHandler),
135
+ })
136
+ .command({ command: 'field-archive <typeId> <fieldId>', describe: 'Archive a field', handler: runCommand(fieldArchiveHandler) })
137
+ .command({
138
+ command: 'record-list <typeId>',
139
+ describe: 'List records of a type (search matches the name only)',
140
+ builder: (yy) => json(typeIdArg(yy)
141
+ .option('search', { type: 'string' })
142
+ .option('include-archived', { type: 'boolean', alias: 'includeArchived', default: false })
143
+ .option('page', { type: 'number', default: 1 })
144
+ .option('page-size', { type: 'number', alias: 'pageSize' })),
145
+ handler: runCommand(recordListHandler),
146
+ })
147
+ .command({ command: 'record-get <typeId> <id>', describe: 'Show one record with its field values', handler: runCommand(recordGetHandler) })
148
+ .command({
149
+ command: 'record-save <typeId>',
150
+ describe: 'Create a record, or update one with --id',
151
+ builder: (yy) => json(typeIdArg(yy)
152
+ .option('id', { type: 'number' })
153
+ .option('name', { type: 'string', demandOption: true })
154
+ .option('values', { type: 'string', describe: 'JSON array of { customFieldId, value }' })),
155
+ handler: runCommand(recordSaveHandler),
156
+ })
157
+ .command({ command: 'record-archive <typeId> <id>', describe: 'Archive a record', handler: runCommand(recordArchiveHandler) })
158
+ .command({ command: 'record-restore <typeId> <id>', describe: 'Restore an archived record', handler: runCommand(recordRestoreHandler) })
159
+ .demandCommand(1),
160
+ handler: () => {},
161
+ };
162
+
163
+ // ---------------------------------------------------------------- relationships
164
+
165
+ const REL_ENTITIES = ['contact', 'company', 'deal', 'object'];
166
+
167
+ async function relTypeListHandler(argv) {
168
+ const r = data(await messagingGet('/CrmRelationships/types'));
169
+ if (argv.json) return printJson(r);
170
+ const list = Array.isArray(r) ? r : r?.types ?? [];
171
+ console.log(`\n${BOLD}Relationship types${RST} (${list.length})`);
172
+ for (const t of list) console.log(` #${t.id} ${t.name}${t.inverseName ? ` / ${t.inverseName}` : ` ${DIM}(symmetric)${RST}`}${t.isArchived ? ' (archived)' : ''}`);
173
+ console.log('');
174
+ }
175
+
176
+ async function relTypeSaveHandler(argv) {
177
+ const body = { name: argv.name, inverseName: argv.inverseName };
178
+ const r = data(argv.id ? await messagingPut(`/CrmRelationships/types/${argv.id}`, body) : await messagingPost('/CrmRelationships/types', body));
179
+ if (argv.json) return printJson(r);
180
+ done(`Relationship type saved: ${r?.name ?? argv.name}${r?.id ? ` (#${r.id})` : ''}.`);
181
+ }
182
+
183
+ async function relTypeArchiveHandler(argv) {
184
+ await messagingDel(`/CrmRelationships/types/${argv.id}`);
185
+ done(`Relationship type ${argv.id} archived.`);
186
+ }
187
+
188
+ async function relTypeRestoreHandler(argv) {
189
+ await messagingPost(`/CrmRelationships/types/${argv.id}/restore`, {});
190
+ done(`Relationship type ${argv.id} restored.`);
191
+ }
192
+
193
+ async function relLinkHandler(argv) {
194
+ const r = data(await messagingPost('/CrmRelationships', {
195
+ typeId: argv.typeId, fromEntity: argv.fromEntity, fromId: argv.fromId, toEntity: argv.toEntity, toId: argv.toId,
196
+ }));
197
+ if (argv.json) return printJson(r);
198
+ done(`Linked${r?.id ? ` (#${r.id})` : ''}. Linking the same pair twice keeps one link.`);
199
+ }
200
+
201
+ async function relUnlinkHandler(argv) {
202
+ await messagingDel(`/CrmRelationships/${argv.id}`);
203
+ done(`Link ${argv.id} removed.`);
204
+ }
205
+
206
+ async function relListHandler(argv) {
207
+ const r = data(await messagingGet(`/CrmRelationships/record/${argv.entity}/${argv.id}`));
208
+ if (argv.json) return printJson(r);
209
+ const list = Array.isArray(r) ? r : r?.links ?? r?.relationships ?? [];
210
+ console.log(`\n${BOLD}Relationships of ${argv.entity} #${argv.id}${RST} (${list.length})`);
211
+ for (const l of list) console.log(` #${l.id} ${l.label ?? l.typeName ?? ''} ${l.otherEntity ?? l.toEntity ?? ''} #${l.otherId ?? l.toId ?? ''} ${DIM}${l.otherName ?? ''}${RST}`);
212
+ console.log('');
213
+ }
214
+
215
+ export const crmRelCommand = {
216
+ command: 'crm-rel <subcommand>',
217
+ describe: 'CRM relationships: typed links between contacts, companies, deals and custom object records',
218
+ builder: (y) => y
219
+ .command({ command: 'type-list', describe: 'List relationship types', builder: json, handler: runCommand(relTypeListHandler) })
220
+ .command({
221
+ command: 'type-save',
222
+ describe: 'Create a relationship type, or update one with --id. Leave --inverse-name blank for a symmetric type such as "partner of"',
223
+ builder: (yy) => json(yy
224
+ .option('id', { type: 'number' })
225
+ .option('name', { type: 'string', demandOption: true, describe: 'For example "reports to"' })
226
+ .option('inverse-name', { type: 'string', alias: 'inverseName', describe: 'For example "manages"' })),
227
+ handler: runCommand(relTypeSaveHandler),
228
+ })
229
+ .command({ command: 'type-archive <id>', describe: 'Archive a relationship type', handler: runCommand(relTypeArchiveHandler) })
230
+ .command({ command: 'type-restore <id>', describe: 'Restore a relationship type', handler: runCommand(relTypeRestoreHandler) })
231
+ .command({
232
+ command: 'link',
233
+ describe: 'Link two records',
234
+ builder: (yy) => json(yy
235
+ .option('type-id', { type: 'number', alias: 'typeId', demandOption: true })
236
+ .option('from-entity', { choices: REL_ENTITIES, alias: 'fromEntity', demandOption: true })
237
+ .option('from-id', { type: 'number', alias: 'fromId', demandOption: true })
238
+ .option('to-entity', { choices: REL_ENTITIES, alias: 'toEntity', demandOption: true })
239
+ .option('to-id', { type: 'number', alias: 'toId', demandOption: true })),
240
+ handler: runCommand(relLinkHandler),
241
+ })
242
+ .command({ command: 'unlink <id>', describe: 'Remove a link', handler: runCommand(relUnlinkHandler) })
243
+ .command({
244
+ command: 'list <entity> <id>',
245
+ describe: 'List the links of one record, both directions, each with its own label',
246
+ builder: (yy) => json(yy.positional('entity', { choices: REL_ENTITIES })),
247
+ handler: runCommand(relListHandler),
248
+ })
249
+ .demandCommand(1),
250
+ handler: () => {},
251
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.207",
3
+ "version": "1.4.208",
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": {