@velaro/cli 1.4.175 → 1.4.176
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 +3 -0
- package/lib/commands/cobrowse.js +54 -0
- package/lib/commands/cobrowse.test.js +19 -0
- package/package.json +1 -1
package/bin/velaro.js
CHANGED
|
@@ -99,6 +99,7 @@ import { packageBuilderCommand } from '../lib/commands/package-builder.js';
|
|
|
99
99
|
import { routingCommand } from '../lib/commands/routing.js';
|
|
100
100
|
import { statusNotifyCommand } from '../lib/commands/status-notify.js';
|
|
101
101
|
import { callbackCommand } from '../lib/commands/callback.js';
|
|
102
|
+
import { cobrowseCommand } from '../lib/commands/cobrowse.js';
|
|
102
103
|
import { callpresenceCommand } from '../lib/commands/callpresence.js';
|
|
103
104
|
import { authorityCommand } from '../lib/commands/authority.js';
|
|
104
105
|
import { caseCommand } from '../lib/commands/case.js';
|
|
@@ -258,6 +259,8 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
258
259
|
.command(routingCommand)
|
|
259
260
|
.command(statusNotifyCommand)
|
|
260
261
|
.command(callbackCommand)
|
|
262
|
+
// The staff build already registers a cobrowse group that includes seats/seat set; only the public build adds this one.
|
|
263
|
+
.command(registerStaffCommands ? { command: 'cobrowse-seats-in-staff-group', describe: false, builder: (y) => y, handler: () => {} } : cobrowseCommand)
|
|
261
264
|
.command(callpresenceCommand)
|
|
262
265
|
.command(authorityCommand)
|
|
263
266
|
.command(caseCommand)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { messagingGet, messagingPut } from '../api.js';
|
|
2
|
+
import { runCommand } from '../run.js';
|
|
3
|
+
|
|
4
|
+
// velaro cobrowse seats | seat set <userId> --assign|--unassign
|
|
5
|
+
// Co-Browse seat assignment for the signed-in site's administrators. Routes live in velaro-messaging
|
|
6
|
+
// (GET /CobrowseSettings/Seats, PUT /CobrowseSettings/Seats/{userId}); the site always comes from the login,
|
|
7
|
+
// every change lands in the Activity Log (cobrowse.seat.assign / cobrowse.seat.unassign).
|
|
8
|
+
|
|
9
|
+
export function formatSeatsReport(data) {
|
|
10
|
+
const lines = [];
|
|
11
|
+
lines.push(data.licensed ? `Co-Browse seats: ${data.used} of ${data.seatCount} in use` : 'Co-Browse is not part of this plan.');
|
|
12
|
+
if (data.autoAssignAll) lines.push('Every agent automatically has a seat.');
|
|
13
|
+
for (const a of data.agents ?? []) lines.push(` ${String(a.userId).padEnd(8)} ${a.hasSeat ? 'seat ' : 'no seat'} ${a.name ?? ''}`);
|
|
14
|
+
return lines.join('\n');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function resolveAssigned(argv) {
|
|
18
|
+
if (argv.assign && argv.unassign) throw new Error('Pass only one of --assign or --unassign');
|
|
19
|
+
if (!argv.assign && !argv.unassign) throw new Error('Pass --assign or --unassign');
|
|
20
|
+
return Boolean(argv.assign);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Subcommands shared by the public CLI and the staff build (which also has its own cobrowse group). */
|
|
24
|
+
export const seatsCommand = {
|
|
25
|
+
command: 'seats',
|
|
26
|
+
describe: 'Show Co-Browse seats and which agents have one',
|
|
27
|
+
builder: yy => yy.option('json', { type: 'boolean', describe: 'Print raw JSON' }),
|
|
28
|
+
handler: runCommand(async argv => {
|
|
29
|
+
const data = await messagingGet('/CobrowseSettings/Seats');
|
|
30
|
+
console.log(argv.json ? JSON.stringify(data, null, 2) : formatSeatsReport(data));
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const seatSetCommand = {
|
|
35
|
+
command: 'seat set <userId>',
|
|
36
|
+
describe: 'Give an agent a Co-Browse seat or take it away',
|
|
37
|
+
builder: yy => yy
|
|
38
|
+
.positional('userId', { type: 'number', describe: 'Agent user id (see: velaro cobrowse seats)' })
|
|
39
|
+
.option('assign', { type: 'boolean', describe: 'Give the agent a seat' })
|
|
40
|
+
.option('unassign', { type: 'boolean', describe: 'Remove the agent\'s seat' }),
|
|
41
|
+
handler: runCommand(async argv => {
|
|
42
|
+
const assigned = resolveAssigned(argv);
|
|
43
|
+
if (!Number.isInteger(argv.userId) || argv.userId <= 0) throw new Error('userId must be a positive whole number');
|
|
44
|
+
await messagingPut(`/CobrowseSettings/Seats/${argv.userId}`, { assigned });
|
|
45
|
+
console.log(`Agent ${argv.userId} ${assigned ? 'now has' : 'no longer has'} a Co-Browse seat.`);
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const cobrowseCommand = {
|
|
50
|
+
command: 'cobrowse <subcommand>',
|
|
51
|
+
describe: 'Co-Browse seat assignment for your agents',
|
|
52
|
+
builder: y => y.command(seatsCommand).command(seatSetCommand).demandCommand(1, 'Specify a subcommand: seats, seat set').strict(),
|
|
53
|
+
handler: () => {},
|
|
54
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { formatSeatsReport, resolveAssigned } from './cobrowse.js';
|
|
4
|
+
|
|
5
|
+
test('formats usage and agents', () => {
|
|
6
|
+
const out = formatSeatsReport({ licensed: true, seatCount: 5, used: 2, autoAssignAll: false, agents: [{ userId: 7, name: 'Ann', hasSeat: true }, { userId: 8, name: 'Bo', hasSeat: false }] });
|
|
7
|
+
assert.match(out, /2 of 5/);
|
|
8
|
+
assert.match(out, /7\s+seat\s+Ann/);
|
|
9
|
+
assert.match(out, /8\s+no seat\s+Bo/);
|
|
10
|
+
});
|
|
11
|
+
test('says when not licensed', () => {
|
|
12
|
+
assert.match(formatSeatsReport({ licensed: false, agents: [] }), /not part of this plan/);
|
|
13
|
+
});
|
|
14
|
+
test('resolves assign / unassign and rejects ambiguity', () => {
|
|
15
|
+
assert.equal(resolveAssigned({ assign: true }), true);
|
|
16
|
+
assert.equal(resolveAssigned({ unassign: true }), false);
|
|
17
|
+
assert.throws(() => resolveAssigned({}));
|
|
18
|
+
assert.throws(() => resolveAssigned({ assign: true, unassign: true }));
|
|
19
|
+
});
|
package/package.json
CHANGED