@velaro/cli 1.4.116 → 1.4.118
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/parity-staff-tools.js +15 -2
- package/lib/commands/report.js +51 -0
- package/lib/commands/ticket.js +320 -0
- package/package.json +1 -1
package/bin/velaro.js
CHANGED
|
@@ -126,6 +126,7 @@ import { emailInboxCommand } from '../lib/commands/email-inbox.js';
|
|
|
126
126
|
import { callbackCommand } from '../lib/commands/callback.js';
|
|
127
127
|
import { authorityCommand } from '../lib/commands/authority.js';
|
|
128
128
|
import { caseCommand } from '../lib/commands/case.js';
|
|
129
|
+
import { ticketCommand } from '../lib/commands/ticket.js';
|
|
129
130
|
import { pickupCommand } from '../lib/commands/pickup.js';
|
|
130
131
|
import { siteSaleCommand } from '../lib/commands/site-sale.js';
|
|
131
132
|
import { visitorMonitorCommand } from '../lib/commands/visitor-monitor.js';
|
|
@@ -295,6 +296,7 @@ await yargs(hideBin(process.argv))
|
|
|
295
296
|
.command(callbackCommand)
|
|
296
297
|
.command(authorityCommand)
|
|
297
298
|
.command(caseCommand)
|
|
299
|
+
.command(ticketCommand)
|
|
298
300
|
.command(pickupCommand)
|
|
299
301
|
.command(siteSaleCommand)
|
|
300
302
|
.command(visitorMonitorCommand)
|
|
@@ -41,6 +41,18 @@ async function call(s, a) {
|
|
|
41
41
|
return fn(s.method || 'GET', s.path(a), s.body ? s.body(a) : undefined);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// Safety guard for subscription/expiry writes. Default is DENY: these commands refuse to run
|
|
45
|
+
// unless VELARO_ALLOW_SUBSCRIPTION_WRITE=1 is set, and a protected site can never be written from
|
|
46
|
+
// the CLI. Site 20678 (Northern New England Poison Control) is protected: it stays on its own
|
|
47
|
+
// account and expiry controls, and must not be extended, flagged, or changed from this CLI.
|
|
48
|
+
const PROTECTED_SITE_IDS = new Set([20678]);
|
|
49
|
+
function subscriptionWriteGuard(a) {
|
|
50
|
+
if (process.env.VELARO_ALLOW_SUBSCRIPTION_WRITE !== '1') return 'Subscription writes are disabled in the CLI. Set VELARO_ALLOW_SUBSCRIPTION_WRITE=1 for one deliberate run.';
|
|
51
|
+
const id = Number(a.site);
|
|
52
|
+
if (PROTECTED_SITE_IDS.has(id)) return `Site ${id} is protected. Subscription and expiry changes for it are not allowed from the CLI.`;
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
44
56
|
export function addRoutes(y, specs) {
|
|
45
57
|
for (const s of specs) {
|
|
46
58
|
y.command(s.name, s.desc, (yy) => {
|
|
@@ -50,6 +62,7 @@ export function addRoutes(y, specs) {
|
|
|
50
62
|
}, async (a) => {
|
|
51
63
|
try {
|
|
52
64
|
if ((s.yes || (s.needsYes && s.needsYes(a))) && !a.yes) { console.error(`Refusing without --yes: ${s.desc}`); process.exit(1); }
|
|
65
|
+
if (s.guard) { const why = s.guard(a); if (why) { console.error(`Refused: ${why}`); process.exit(1); } }
|
|
53
66
|
out(s.run ? await s.run(a) : await call(s, a));
|
|
54
67
|
} catch (e) { console.error(e.message); process.exit(1); }
|
|
55
68
|
});
|
|
@@ -75,9 +88,9 @@ export const SUPPORT_EXTRA = [
|
|
|
75
88
|
{ name: 'site-health', desc: 'Site health: subscription, agents, last login, 7-day errors', opts: site, path: (a) => `${SP(a)}/health` },
|
|
76
89
|
{ name: 'site-agents', desc: 'Agents on a site', opts: site, path: (a) => `${SP(a)}/agents` },
|
|
77
90
|
{ name: 'site-activity', desc: 'Activity log for a site', opts: { ...site, page: N('Page'), 'page-size': N('Page size (max 200)'), category: S('Category') }, path: (a) => `${SP(a)}/activity${qs({ page: a.page ?? 1, pageSize: Math.min(200, a.pageSize ?? 50), category: a.category })}` },
|
|
78
|
-
{ name: 'extend-subscription', desc: 'Extend a site subscription by N days', yes: true, method: 'POST', opts: { ...site, days: N('Days', true) }, path: (a) => `${SP(a)}/extend-subscription`, body: (a) => ({ days: a.days }) },
|
|
91
|
+
{ name: 'extend-subscription', desc: 'Extend a site subscription by N days', guard: subscriptionWriteGuard, yes: true, method: 'POST', opts: { ...site, days: N('Days', true) }, path: (a) => `${SP(a)}/extend-subscription`, body: (a) => ({ days: a.days }) },
|
|
79
92
|
{ name: 'set-user-active', desc: 'Activate/deactivate a user on a site', yes: true, method: 'POST', opts: { ...site, 'user-id': N('User id', true), active: { type: 'boolean', demandOption: true, describe: 'true or false' } }, path: (a) => `SupportTools/users/${a.userId}/sites/${a.site}/set-active`, body: (a) => ({ isActive: a.active }) },
|
|
80
|
-
{ name: 'bulk-set-flags', desc: 'Set several subscription flags at once (JSON object)', yes: true, method: 'POST', opts: { ...site, flags: S('JSON object or @file.json', true) }, path: (a) => `${SP(a)}/subscription/bulk-flags`, body: (a) => ({ flags: json(a.flags) }) },
|
|
93
|
+
{ name: 'bulk-set-flags', desc: 'Set several subscription flags at once (JSON object)', guard: subscriptionWriteGuard, yes: true, method: 'POST', opts: { ...site, flags: S('JSON object or @file.json', true) }, path: (a) => `${SP(a)}/subscription/bulk-flags`, body: (a) => ({ flags: json(a.flags) }) },
|
|
81
94
|
{ name: 'create-agent', desc: 'Create an agent on any site (staff)', api: 'msg', method: 'POST', opts: { ...site, email: S('Email', true), 'first-name': S('First name'), 'last-name': S('Last name'), roles: S('Comma list of roles'), 'team-ids': S('Comma list of team ids'), 'max-chats': N('Max chats (0 = default)') }, path: (a) => `/SupportTools/sites/${a.site}/agents`, body: (a) => ({ email: a.email, firstName: a.firstName, lastName: a.lastName, roles: csv(a.roles), teamIds: csvN(a.teamIds), maxChats: a.maxChats ?? 0 }) },
|
|
82
95
|
{ name: 'schedule-adherence', desc: 'Schedule adherence diagnostics for a site', api: 'msg', opts: { ...site, role: S('role'), 'agent-id': N('Agent id (required when role=agent)'), start: S('Start'), end: S('End'), tz: S('Timezone') }, path: (a) => `/Reports/sites/${a.site}/schedule-adherence-diagnostics${qs({ detail: 'true', role: a.role, agentId: a.agentId, start: a.start, end: a.end, tz: a.tz })}` },
|
|
83
96
|
{ name: 'appointments-list-sites', desc: 'Sites with Velaro Appointments enabled', api: 'msg', path: () => '/Appointments/admin/sites-with-appointments' },
|
package/lib/commands/report.js
CHANGED
|
@@ -740,6 +740,55 @@ const countryCommand = {
|
|
|
740
740
|
handler: () => {},
|
|
741
741
|
};
|
|
742
742
|
|
|
743
|
+
// ── custom report builder (velaro-messaging CustomReportsController, parity row RPT-1) ──────────
|
|
744
|
+
|
|
745
|
+
async function customRunHandler(argv) {
|
|
746
|
+
const filters = {};
|
|
747
|
+
for (const pair of [].concat(argv.filter ?? [])) {
|
|
748
|
+
const i = String(pair).indexOf('=');
|
|
749
|
+
if (i < 1) throw new Error(`--filter must be key=value, got "${pair}"`);
|
|
750
|
+
filters[String(pair).slice(0, i)] = String(pair).slice(i + 1);
|
|
751
|
+
}
|
|
752
|
+
const end = new Date();
|
|
753
|
+
const start = new Date(end.getTime() - (argv.days ?? 90) * 86400000);
|
|
754
|
+
const r = await messagingRequest('POST', '/api/v1/custom-reports/run', {
|
|
755
|
+
object: argv.object, groupBy: argv.groupBy, measure: argv.measure, start: start.toISOString(), end: end.toISOString(), filters,
|
|
756
|
+
});
|
|
757
|
+
const rows = r?.data?.rows ?? [];
|
|
758
|
+
if (argv.json) { console.log(JSON.stringify({ rows, meta: r?.meta }, null, 2)); return; }
|
|
759
|
+
console.log(`\n${argv.object} by ${argv.groupBy} (${argv.measure}), last ${argv.days ?? 90} days`);
|
|
760
|
+
for (const row of rows) console.log(` ${String(row.group).padEnd(32)} ${row.value} (${row.count} records)`);
|
|
761
|
+
if (r?.meta?.truncated) console.log(' (only the newest 50,000 records were included)');
|
|
762
|
+
console.log('');
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
async function customCatalogHandler() {
|
|
766
|
+
const r = await messagingRequest('GET', '/api/v1/custom-reports/catalog');
|
|
767
|
+
for (const o of r?.data?.objects ?? []) {
|
|
768
|
+
console.log(`\n${o.name}\n group by: ${o.groupBys.join(', ')}\n measures: ${o.measures.join(', ')}\n filters: ${o.filters.join(', ') || '(none)'}`);
|
|
769
|
+
}
|
|
770
|
+
console.log('');
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
const customCatalogCommand = {
|
|
774
|
+
command: 'custom-catalog',
|
|
775
|
+
describe: 'List what the custom report builder can group by, measure and filter (Manager/Administrator)',
|
|
776
|
+
handler: runCommand(customCatalogHandler),
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
const customRunCommand = {
|
|
780
|
+
command: 'custom-run',
|
|
781
|
+
describe: 'Run a custom report: --object tickets|deals|contacts|companies --group-by <field> [--measure] [--filter k=v]',
|
|
782
|
+
builder: (y) => y
|
|
783
|
+
.option('object', { type: 'string', demandOption: true })
|
|
784
|
+
.option('group-by', { type: 'string', demandOption: true })
|
|
785
|
+
.option('measure', { type: 'string', default: 'count' })
|
|
786
|
+
.option('days', { type: 'number', default: 90 })
|
|
787
|
+
.option('filter', { type: 'string', array: true })
|
|
788
|
+
.option('json', { type: 'boolean' }),
|
|
789
|
+
handler: runCommand(customRunHandler),
|
|
790
|
+
};
|
|
791
|
+
|
|
743
792
|
// ── top-level report command ──────────────────────────────────────────────────
|
|
744
793
|
|
|
745
794
|
export const reportCommand = {
|
|
@@ -755,6 +804,8 @@ export const reportCommand = {
|
|
|
755
804
|
.command(schedulesCommand)
|
|
756
805
|
.command(exportCommand)
|
|
757
806
|
.command(countryCommand)
|
|
807
|
+
.command(customCatalogCommand)
|
|
808
|
+
.command(customRunCommand)
|
|
758
809
|
.demandCommand(1, 'Specify a report type. Run "velaro report --help" for options.'),
|
|
759
810
|
handler: () => {},
|
|
760
811
|
};
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
|
|
2
|
+
import { runCommand } from '../run.js';
|
|
3
|
+
|
|
4
|
+
// -- velaro ticket ------------------------------------------------------------
|
|
5
|
+
// CLI for the Velaro help desk parity features (velaro-messaging docs/architecture/ticketing-hubspot-parity-plan.md):
|
|
6
|
+
// assoc TicketAssociationsController api/v1/tickets/{id}/associations, api/v1/companies/{id}/tickets
|
|
7
|
+
// property RecordPropertiesController api/v1/ticket-properties, api/v1/tickets/{id}/properties
|
|
8
|
+
// pipeline TicketPipelinesController api/v1/ticket-pipelines, /{id}/board, api/v1/tickets/{id}/stage
|
|
9
|
+
// view TicketViewsController api/v1/ticket-views
|
|
10
|
+
// sla TicketController Ticket/sla-policies
|
|
11
|
+
// The site always comes from the signed-in credential; no command takes a site id.
|
|
12
|
+
// MCP parity: mcp/parity/ticket.customer.js (ticket_* tools).
|
|
13
|
+
|
|
14
|
+
const BOLD = '\x1b[1m';
|
|
15
|
+
const DIM = '\x1b[2m';
|
|
16
|
+
const RED = '\x1b[31m';
|
|
17
|
+
const RST = '\x1b[0m';
|
|
18
|
+
|
|
19
|
+
const data = (r) => (r && typeof r === 'object' && 'data' in r ? r.data : r);
|
|
20
|
+
|
|
21
|
+
function printJson(v) {
|
|
22
|
+
console.log(JSON.stringify(v, null, 2));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ---- associations -------------------------------------------------------------
|
|
26
|
+
async function assocListHandler(argv) {
|
|
27
|
+
const v = data(await messagingGet(`/api/v1/tickets/${argv.ticketId}/associations`));
|
|
28
|
+
if (argv.json) return printJson(v);
|
|
29
|
+
for (const [label, rows] of [['Contacts', v?.contacts], ['Companies', v?.companies], ['Deals', v?.deals], ['Calls', v?.calls]]) {
|
|
30
|
+
const list = Array.isArray(rows) ? rows : [];
|
|
31
|
+
console.log(`\n${BOLD}${label}${RST} (${list.length})`);
|
|
32
|
+
for (const r of list) {
|
|
33
|
+
const tag = r.primary ? ' (primary)' : r.derived ? ' (from contact)' : '';
|
|
34
|
+
const name = r.name || r.email || (r.startedAt ? `${r.direction} call ${r.startedAt}` : `#${r.id}`);
|
|
35
|
+
console.log(` #${r.id} ${name}${tag}${r.label ? ` ${DIM}${r.label}${RST}` : ''}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
console.log('');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function assocAddHandler(argv) {
|
|
42
|
+
await messagingPost(`/api/v1/tickets/${argv.ticketId}/associations`, { type: argv.type, targetId: argv.targetId, label: argv.label });
|
|
43
|
+
console.log(`\n Linked ${argv.type} ${argv.targetId} to ticket ${argv.ticketId}.\n`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function assocRemoveHandler(argv) {
|
|
47
|
+
await messagingDel(`/api/v1/tickets/${argv.ticketId}/associations/${argv.type}/${argv.targetId}`);
|
|
48
|
+
console.log(`\n Removed ${argv.type} ${argv.targetId} from ticket ${argv.ticketId}.\n`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function companyTicketsHandler(argv) {
|
|
52
|
+
const v = data(await messagingGet(`/api/v1/companies/${argv.companyId}/tickets?openOnly=${argv.openOnly ? 'true' : 'false'}`));
|
|
53
|
+
const list = Array.isArray(v?.tickets) ? v.tickets : [];
|
|
54
|
+
if (argv.json) return printJson(list);
|
|
55
|
+
console.log(`\n${BOLD}Tickets of company ${argv.companyId}${RST} (${list.length})`);
|
|
56
|
+
for (const t of list) console.log(` ${t.ticketNumber ?? `#${t.id}`} ${t.status} ${t.priority} ${DIM}${t.subject ?? ''}${RST}`);
|
|
57
|
+
console.log('');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ---- properties --------------------------------------------------------------
|
|
61
|
+
const entityBase = (entity) => (entity === 'company' ? '/api/v1/company-properties' : '/api/v1/ticket-properties');
|
|
62
|
+
const recordBase = (entity, id) => (entity === 'company' ? `/api/v1/companies/${id}/properties` : `/api/v1/tickets/${id}/properties`);
|
|
63
|
+
|
|
64
|
+
async function propertyListHandler(argv) {
|
|
65
|
+
const v = data(await messagingGet(entityBase(argv.entity)));
|
|
66
|
+
const list = Array.isArray(v?.properties) ? v.properties : [];
|
|
67
|
+
if (argv.json) return printJson(list);
|
|
68
|
+
console.log(`\n${BOLD}${argv.entity} properties${RST} (${list.length})`);
|
|
69
|
+
for (const p of list) console.log(` #${p.id} ${p.label} ${DIM}${p.fieldType}${p.options?.length ? ` [${p.options.join(', ')}]` : ''}${p.isRequired ? ' required-on-stage' : ''}${RST}`);
|
|
70
|
+
console.log('');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function propertyDefineHandler(argv) {
|
|
74
|
+
const body = {
|
|
75
|
+
label: argv.label,
|
|
76
|
+
fieldType: argv.type,
|
|
77
|
+
options: argv.options ? String(argv.options).split(',').map((s) => s.trim()).filter(Boolean) : [],
|
|
78
|
+
isRequired: !!argv.required,
|
|
79
|
+
sortOrder: argv.sortOrder ?? 0,
|
|
80
|
+
};
|
|
81
|
+
const r = argv.id
|
|
82
|
+
? await messagingPut(`${entityBase(argv.entity)}/${argv.id}`, body)
|
|
83
|
+
: await messagingPost(entityBase(argv.entity), body);
|
|
84
|
+
const p = data(r);
|
|
85
|
+
console.log(`\n Saved ${argv.entity} property "${p?.label}" (id ${p?.id}).\n`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function propertyArchiveHandler(argv) {
|
|
89
|
+
await messagingDel(`${entityBase(argv.entity)}/${argv.id}`);
|
|
90
|
+
console.log(`\n Archived ${argv.entity} property ${argv.id}.\n`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function propertyGetHandler(argv) {
|
|
94
|
+
const v = data(await messagingGet(recordBase(argv.entity, argv.recordId)));
|
|
95
|
+
const list = Array.isArray(v?.properties) ? v.properties : [];
|
|
96
|
+
if (argv.json) return printJson(list);
|
|
97
|
+
console.log(`\n${BOLD}${argv.entity} ${argv.recordId}${RST}`);
|
|
98
|
+
for (const p of list) console.log(` ${p.label}: ${p.value ?? `${DIM}(empty)${RST}`}`);
|
|
99
|
+
console.log('');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function propertySetHandler(argv) {
|
|
103
|
+
const pairs = [].concat(argv.value ?? []);
|
|
104
|
+
const values = {};
|
|
105
|
+
for (const pair of pairs) {
|
|
106
|
+
const i = String(pair).indexOf('=');
|
|
107
|
+
if (i < 1) throw new Error(`--value must be fieldId=value, got "${pair}"`);
|
|
108
|
+
values[String(pair).slice(0, i)] = String(pair).slice(i + 1);
|
|
109
|
+
}
|
|
110
|
+
await messagingPut(recordBase(argv.entity, argv.recordId), values);
|
|
111
|
+
console.log(`\n Saved ${Object.keys(values).length} value(s) on ${argv.entity} ${argv.recordId}.\n`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ---- pipelines ----------------------------------------------------------------
|
|
115
|
+
async function pipelineListHandler(argv) {
|
|
116
|
+
const v = data(await messagingGet('/api/v1/ticket-pipelines'));
|
|
117
|
+
const list = Array.isArray(v?.pipelines) ? v.pipelines : [];
|
|
118
|
+
if (argv.json) return printJson(list);
|
|
119
|
+
for (const p of list) {
|
|
120
|
+
console.log(`\n${BOLD}#${p.id} ${p.name}${RST}${p.isDefault ? ' (default)' : ''}`);
|
|
121
|
+
for (const s of p.stages ?? []) console.log(` ${s.id} ${s.name} ${DIM}${s.status}${s.requiredPropertyIds?.length ? ` requires ${s.requiredPropertyIds.join(',')}` : ''}${RST}`);
|
|
122
|
+
}
|
|
123
|
+
console.log('');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function pipelineBoardHandler(argv) {
|
|
127
|
+
const v = data(await messagingGet(`/api/v1/ticket-pipelines/${argv.pipelineId}/board?closedDays=${argv.closedDays ?? 14}`));
|
|
128
|
+
if (argv.json) return printJson(v);
|
|
129
|
+
for (const s of v?.stages ?? []) {
|
|
130
|
+
console.log(`\n${BOLD}${s.name}${RST} (${s.tickets?.length ?? 0})`);
|
|
131
|
+
for (const t of s.tickets ?? []) console.log(` ${t.ticketNumber ?? `#${t.id}`} ${t.priority} ${DIM}${t.subject ?? ''}${RST}${t.slaBreached ? ` ${RED}SLA breached${RST}` : ''}`);
|
|
132
|
+
}
|
|
133
|
+
console.log('');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function pipelineMoveHandler(argv) {
|
|
137
|
+
await messagingPut(`/api/v1/tickets/${argv.ticketId}/stage`, { pipelineId: argv.pipeline ?? null, stageId: argv.stageId });
|
|
138
|
+
console.log(`\n Ticket ${argv.ticketId} moved to stage "${argv.stageId}".\n`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function pipelineSaveHandler(argv) {
|
|
142
|
+
// --stages "New:new,Diagnosing:open,Tech dispatched:open:12|14,Waiting on customer:pending,Resolved:resolved,Closed:closed"
|
|
143
|
+
const stages = String(argv.stages).split(',').map((raw) => {
|
|
144
|
+
const [name, status, required] = raw.split(':').map((x) => x?.trim());
|
|
145
|
+
return { name, status, requiredPropertyIds: required ? required.split('|').map(Number).filter(Boolean) : [] };
|
|
146
|
+
});
|
|
147
|
+
const body = { name: argv.name, isDefault: !!argv.default, stages };
|
|
148
|
+
const r = argv.id ? await messagingPut(`/api/v1/ticket-pipelines/${argv.id}`, body) : await messagingPost('/api/v1/ticket-pipelines', body);
|
|
149
|
+
const p = data(r);
|
|
150
|
+
console.log(`\n Saved pipeline "${p?.name}" (id ${p?.id}) with ${p?.stages?.length ?? 0} stages.\n`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ---- views ----------------------------------------------------------------------
|
|
154
|
+
async function viewListHandler(argv) {
|
|
155
|
+
const v = data(await messagingGet('/api/v1/ticket-views'));
|
|
156
|
+
const list = Array.isArray(v?.views) ? v.views : [];
|
|
157
|
+
if (argv.json) return printJson(list);
|
|
158
|
+
console.log(`\n${BOLD}Ticket views${RST}`);
|
|
159
|
+
for (const view of list) console.log(` ${view.id} ${view.name} ${DIM}${view.builtIn ? 'built-in' : view.visibility} ${JSON.stringify(view.filters ?? {})}${RST}`);
|
|
160
|
+
console.log('');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function viewSaveHandler(argv) {
|
|
164
|
+
let filters = {};
|
|
165
|
+
if (argv.filters) {
|
|
166
|
+
try { filters = JSON.parse(argv.filters); } catch { throw new Error('--filters must be JSON, e.g. {"status":"new,open","priority":"urgent"}'); }
|
|
167
|
+
}
|
|
168
|
+
const body = { name: argv.name, visibility: argv.visibility ?? 'personal', teamId: argv.teamId ?? null, filters };
|
|
169
|
+
const r = argv.id ? await messagingPut(`/api/v1/ticket-views/${argv.id}`, body) : await messagingPost('/api/v1/ticket-views', body);
|
|
170
|
+
console.log(`\n Saved view "${data(r)?.name}" (id ${data(r)?.id}).\n`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function viewDeleteHandler(argv) {
|
|
174
|
+
await messagingDel(`/api/v1/ticket-views/${argv.id}`);
|
|
175
|
+
console.log(`\n Deleted view ${argv.id}.\n`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---- playbooks (PLAY-1) ---------------------------------------------------------
|
|
179
|
+
async function playbookListHandler(argv) {
|
|
180
|
+
const v = data(await messagingGet(`/api/v1/playbooks${argv.appliesTo ? `?appliesTo=${encodeURIComponent(argv.appliesTo)}` : ''}`));
|
|
181
|
+
const list = Array.isArray(v?.playbooks) ? v.playbooks : [];
|
|
182
|
+
if (argv.json) return printJson(list);
|
|
183
|
+
console.log(`\n${BOLD}Playbooks${RST}`);
|
|
184
|
+
for (const p of list) {
|
|
185
|
+
console.log(` #${p.id} ${p.name} ${DIM}${p.appliesTo}${p.isActive ? '' : ' (off)'}${RST}`);
|
|
186
|
+
for (const s of p.steps ?? []) console.log(` ${s.type === 'question' ? '?' : '-'} ${s.id}: ${s.title}${s.required ? ' *' : ''}`);
|
|
187
|
+
}
|
|
188
|
+
console.log('');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function playbookRespondHandler(argv) {
|
|
192
|
+
const answers = {};
|
|
193
|
+
for (const pair of [].concat(argv.answer ?? [])) {
|
|
194
|
+
const i = String(pair).indexOf('=');
|
|
195
|
+
if (i < 1) throw new Error(`--answer must be stepId=value, got "${pair}"`);
|
|
196
|
+
answers[String(pair).slice(0, i)] = String(pair).slice(i + 1);
|
|
197
|
+
}
|
|
198
|
+
await messagingPost(`/api/v1/playbooks/${argv.playbookId}/responses`, { recordType: argv.recordType, recordId: argv.recordId, answers });
|
|
199
|
+
console.log(`\n Saved playbook ${argv.playbookId} answers on ${argv.recordType} ${argv.recordId}.\n`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ---- customer portal link (PORTAL-1) ------------------------------------------
|
|
203
|
+
async function portalLinkHandler(argv) {
|
|
204
|
+
const v = data(argv.rotate ? await messagingPost('/api/v1/ticket-portal/rotate', {}) : await messagingGet('/api/v1/ticket-portal'));
|
|
205
|
+
if (argv.json) return printJson(v);
|
|
206
|
+
console.log(`\n Customer portal: ${v?.url ?? '(AppBaseUrl not configured)'}${v?.signInAvailable === false ? ` ${RED}(sign-in not configured)${RST}` : ''}\n`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ---- SLA policies -------------------------------------------------------------
|
|
210
|
+
async function slaListHandler(argv) {
|
|
211
|
+
const list = await messagingGet('/Ticket/sla-policies');
|
|
212
|
+
if (argv.json) return printJson(list);
|
|
213
|
+
console.log(`\n${BOLD}SLA policies${RST}`);
|
|
214
|
+
for (const p of Array.isArray(list) ? list : []) {
|
|
215
|
+
console.log(` #${p.id} ${p.name} ${DIM}${p.priority} first ${p.firstResponseMinutes}m next ${p.nextResponseMinutes ?? 0}m resolve ${p.resolutionMinutes}m${p.businessHoursOnly ? ' business hours' : ''}${p.pauseWhenPending ? ' pauses on pending' : ''}${p.isActive ? '' : ' inactive'}${RST}`);
|
|
216
|
+
}
|
|
217
|
+
console.log('');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const json = (y) => y.option('json', { type: 'boolean', describe: 'Print raw JSON' });
|
|
221
|
+
const entity = (y) => y.option('entity', { choices: ['ticket', 'company'], default: 'ticket', describe: 'Which record type' });
|
|
222
|
+
|
|
223
|
+
export const ticketCommand = {
|
|
224
|
+
command: 'ticket <subcommand>',
|
|
225
|
+
describe: 'Help desk: ticket associations, properties, pipelines, saved views, SLA policies',
|
|
226
|
+
builder: (y) => y
|
|
227
|
+
.command({ command: 'assoc-list <ticketId>', describe: 'List contacts, companies, deals and calls linked to a ticket', builder: json, handler: runCommand(assocListHandler) })
|
|
228
|
+
.command({
|
|
229
|
+
command: 'assoc-add <ticketId> <type> <targetId>',
|
|
230
|
+
describe: 'Link a contact, company, deal or call to a ticket (type = contact | company | deal | call)',
|
|
231
|
+
builder: (yy) => yy.option('label', { type: 'string', describe: 'Optional association label' }),
|
|
232
|
+
handler: runCommand(assocAddHandler),
|
|
233
|
+
})
|
|
234
|
+
.command({ command: 'assoc-remove <ticketId> <type> <targetId>', describe: 'Unlink a record from a ticket', handler: runCommand(assocRemoveHandler) })
|
|
235
|
+
.command({
|
|
236
|
+
command: 'company-tickets <companyId>',
|
|
237
|
+
describe: 'List the tickets of a company (linked + tickets of its contacts)',
|
|
238
|
+
builder: (yy) => json(yy.option('open-only', { type: 'boolean', default: false })),
|
|
239
|
+
handler: runCommand(companyTicketsHandler),
|
|
240
|
+
})
|
|
241
|
+
.command({ command: 'property-list', describe: 'List ticket (or company) property definitions', builder: (yy) => json(entity(yy)), handler: runCommand(propertyListHandler) })
|
|
242
|
+
.command({
|
|
243
|
+
command: 'property-define',
|
|
244
|
+
describe: 'Create or update a ticket (or company) property definition (Administrator)',
|
|
245
|
+
builder: (yy) => entity(yy)
|
|
246
|
+
.option('id', { type: 'number', describe: 'Existing property id to update' })
|
|
247
|
+
.option('label', { type: 'string', demandOption: true })
|
|
248
|
+
.option('type', { choices: ['Text', 'Number', 'Date', 'Dropdown', 'Checkbox', 'Currency'], default: 'Text' })
|
|
249
|
+
.option('options', { type: 'string', describe: 'Comma-separated dropdown options' })
|
|
250
|
+
.option('required', { type: 'boolean', describe: 'Can be required by pipeline stages' })
|
|
251
|
+
.option('sort-order', { type: 'number' }),
|
|
252
|
+
handler: runCommand(propertyDefineHandler),
|
|
253
|
+
})
|
|
254
|
+
.command({ command: 'property-archive <id>', describe: 'Archive a property definition (Administrator)', builder: entity, handler: runCommand(propertyArchiveHandler) })
|
|
255
|
+
.command({ command: 'property-get <recordId>', describe: 'Show the property values of a ticket (or company)', builder: (yy) => json(entity(yy)), handler: runCommand(propertyGetHandler) })
|
|
256
|
+
.command({
|
|
257
|
+
command: 'property-set <recordId>',
|
|
258
|
+
describe: 'Set property values: --value <fieldId>=<value> (repeatable; empty value clears)',
|
|
259
|
+
builder: (yy) => entity(yy).option('value', { type: 'string', array: true, demandOption: true }),
|
|
260
|
+
handler: runCommand(propertySetHandler),
|
|
261
|
+
})
|
|
262
|
+
.command({ command: 'pipeline-list', describe: 'List ticket pipelines and their stages', builder: json, handler: runCommand(pipelineListHandler) })
|
|
263
|
+
.command({
|
|
264
|
+
command: 'pipeline-save',
|
|
265
|
+
describe: 'Create or update a ticket pipeline (Administrator). --stages "Name:status[:requiredId|requiredId],..."',
|
|
266
|
+
builder: (yy) => yy
|
|
267
|
+
.option('id', { type: 'number' })
|
|
268
|
+
.option('name', { type: 'string', demandOption: true })
|
|
269
|
+
.option('default', { type: 'boolean' })
|
|
270
|
+
.option('stages', { type: 'string', demandOption: true }),
|
|
271
|
+
handler: runCommand(pipelineSaveHandler),
|
|
272
|
+
})
|
|
273
|
+
.command({
|
|
274
|
+
command: 'pipeline-board <pipelineId>',
|
|
275
|
+
describe: 'Show the pipeline board (tickets by stage)',
|
|
276
|
+
builder: (yy) => json(yy.option('closed-days', { type: 'number', default: 14 })),
|
|
277
|
+
handler: runCommand(pipelineBoardHandler),
|
|
278
|
+
})
|
|
279
|
+
.command({
|
|
280
|
+
command: 'pipeline-move <ticketId> <stageId>',
|
|
281
|
+
describe: 'Move a ticket to a pipeline stage (required properties are enforced)',
|
|
282
|
+
builder: (yy) => yy.option('pipeline', { type: 'number', describe: 'Pipeline id (default: the ticket\'s pipeline)' }),
|
|
283
|
+
handler: runCommand(pipelineMoveHandler),
|
|
284
|
+
})
|
|
285
|
+
.command({ command: 'view-list', describe: 'List saved and built-in Help Desk ticket views', builder: json, handler: runCommand(viewListHandler) })
|
|
286
|
+
.command({
|
|
287
|
+
command: 'view-save',
|
|
288
|
+
describe: 'Create or update a saved ticket view',
|
|
289
|
+
builder: (yy) => yy
|
|
290
|
+
.option('id', { type: 'number' })
|
|
291
|
+
.option('name', { type: 'string', demandOption: true })
|
|
292
|
+
.option('visibility', { choices: ['personal', 'team', 'everyone'], default: 'personal' })
|
|
293
|
+
.option('team-id', { type: 'number' })
|
|
294
|
+
.option('filters', { type: 'string', describe: 'JSON of Ticket list filters' }),
|
|
295
|
+
handler: runCommand(viewSaveHandler),
|
|
296
|
+
})
|
|
297
|
+
.command({ command: 'view-delete <id>', describe: 'Delete a saved ticket view', handler: runCommand(viewDeleteHandler) })
|
|
298
|
+
.command({ command: 'sla-list', describe: 'List SLA policies (business hours, next response, pause on pending)', builder: json, handler: runCommand(slaListHandler) })
|
|
299
|
+
.command({
|
|
300
|
+
command: 'playbook-list',
|
|
301
|
+
describe: 'List playbooks and their steps',
|
|
302
|
+
builder: (yy) => json(yy.option('applies-to', { choices: ['ticket', 'call', 'deal'] })),
|
|
303
|
+
handler: runCommand(playbookListHandler),
|
|
304
|
+
})
|
|
305
|
+
.command({
|
|
306
|
+
command: 'playbook-respond <playbookId> <recordType> <recordId>',
|
|
307
|
+
describe: 'Save playbook answers on a ticket, call or deal: --answer <stepId>=<value> (repeatable)',
|
|
308
|
+
builder: (yy) => yy.option('answer', { type: 'string', array: true }),
|
|
309
|
+
handler: runCommand(playbookRespondHandler),
|
|
310
|
+
})
|
|
311
|
+
.command({
|
|
312
|
+
command: 'portal-link',
|
|
313
|
+
describe: 'Show the customer portal link (--rotate makes a new one; Administrator)',
|
|
314
|
+
builder: (yy) => json(yy.option('rotate', { type: 'boolean' })),
|
|
315
|
+
handler: runCommand(portalLinkHandler),
|
|
316
|
+
})
|
|
317
|
+
.demandCommand(1, 'Specify a ticket subcommand.')
|
|
318
|
+
.strict(),
|
|
319
|
+
handler: () => {},
|
|
320
|
+
};
|
package/package.json
CHANGED