@velaro/cli 1.4.175 → 1.4.177

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
@@ -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)
package/lib/api.js CHANGED
@@ -104,6 +104,26 @@ export const messagingPut = (path, body) => messagingRequest('PUT', path, bod
104
104
  export const messagingPatch = (path, body) => messagingRequest('PATCH', path, body);
105
105
  export const messagingDel = (path) => messagingRequest('DELETE', path);
106
106
 
107
+ // multipart/form-data POST (ChatWindow/Update takes [FromForm]); fetch sets the boundary header itself.
108
+ export async function messagingPostForm(path, form, envOverride) {
109
+ const creds = await getCredentials(envOverride);
110
+ const res = await fetch(joinUrl(creds.messagingApiBase, path), {
111
+ method: 'POST',
112
+ headers: {
113
+ Authorization: `Bearer ${creds.velaroToken}`,
114
+ ...(creds.siteId ? { 'vmsg-siteId': String(creds.siteId) } : {}),
115
+ },
116
+ body: form,
117
+ });
118
+ if (!res.ok) {
119
+ let msg = `POST ${path} → ${res.status}`;
120
+ try { const t = await res.text(); if (t) msg += `: ${t}`; } catch { /* status already captured */ }
121
+ throw new Error(msg);
122
+ }
123
+ const text = await res.text();
124
+ return text ? JSON.parse(text) : null;
125
+ }
126
+
107
127
  // Same as messagingRequest but returns the raw response text (for CSV downloads).
108
128
  export async function messagingRequestText(method, path, envOverride) {
109
129
  const creds = await getCredentials(envOverride);
@@ -0,0 +1,27 @@
1
+ // Per-chat-window multi-tab mode (velaro-messaging MessengerStyleConfig.MultiTabMode).
2
+ // null/absent = follow the site/platform default. ChatWindow/Update is a full replace
3
+ // (multipart name + styleConfig + languageConfig), so we read first and merge.
4
+ export const MULTI_TAB_MODES = ['active-only', 'all-live'];
5
+
6
+ /** Returns 'active-only' | 'all-live' | null (follow default). Throws on anything else. */
7
+ export function normalizeMultiTabMode(raw) {
8
+ if (raw === null || raw === undefined) return null;
9
+ const v = String(raw).trim().toLowerCase();
10
+ if (v === '' || v === 'default' || v === 'follow-default' || v === 'null') return null;
11
+ if (!MULTI_TAB_MODES.includes(v)) {
12
+ throw new Error('multiTabMode must be "active-only", "all-live" or "default" (follows the site/platform default).');
13
+ }
14
+ return v;
15
+ }
16
+
17
+ /** Fields of the update form for a chat window with only multiTabMode changed. */
18
+ export function buildMultiTabUpdateFields(current, mode) {
19
+ if (!current || typeof current !== 'object') throw new Error('chat window not found');
20
+ const styleConfig = { ...(current.styleConfig ?? {}) };
21
+ if (mode === null) delete styleConfig.multiTabMode; else styleConfig.multiTabMode = mode;
22
+ return {
23
+ name: current.name ?? '',
24
+ styleConfig: JSON.stringify(styleConfig),
25
+ languageConfig: JSON.stringify(current.languageConfig ?? {}),
26
+ };
27
+ }
@@ -0,0 +1,25 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { normalizeMultiTabMode, buildMultiTabUpdateFields } from './chat-window-style.js';
4
+
5
+ test('normalize accepts the two modes and maps default to null', () => {
6
+ assert.equal(normalizeMultiTabMode('Active-Only'), 'active-only');
7
+ assert.equal(normalizeMultiTabMode('all-live'), 'all-live');
8
+ assert.equal(normalizeMultiTabMode('default'), null);
9
+ assert.equal(normalizeMultiTabMode(''), null);
10
+ assert.equal(normalizeMultiTabMode(undefined), null);
11
+ });
12
+
13
+ test('normalize rejects unknown values', () => {
14
+ assert.throws(() => normalizeMultiTabMode('both'), /multiTabMode must be/);
15
+ });
16
+
17
+ test('update fields keep the rest of the window and only change multiTabMode', () => {
18
+ const cw = { name: 'Main', styleConfig: { launcherText: 'Help', multiTabMode: 'all-live' }, languageConfig: { greeting: 'Hi' } };
19
+ const f = buildMultiTabUpdateFields(cw, 'active-only');
20
+ assert.equal(f.name, 'Main');
21
+ assert.deepEqual(JSON.parse(f.styleConfig), { launcherText: 'Help', multiTabMode: 'active-only' });
22
+ assert.deepEqual(JSON.parse(f.languageConfig), { greeting: 'Hi' });
23
+ assert.ok(!('multiTabMode' in JSON.parse(buildMultiTabUpdateFields(cw, null).styleConfig)));
24
+ assert.equal(cw.styleConfig.multiTabMode, 'all-live');
25
+ });
@@ -2,7 +2,8 @@
2
2
  // Site isolation is enforced server-side (ClientControllerBase SiteId), never passed by the client.
3
3
  // To show different copy on different pages: create one chat window per page type, set its
4
4
  // label/greeting here, then pick it with a Select Chat Window workflow node.
5
- import { messagingGet, messagingPut } from '../api.js';
5
+ import { messagingGet, messagingPut, messagingPostForm } from '../api.js';
6
+ import { normalizeMultiTabMode, buildMultiTabUpdateFields } from '../chat-window-style.js';
6
7
  import { runCommand } from '../run.js';
7
8
 
8
9
  export const chatWindowCommand = {
@@ -42,6 +43,31 @@ export const chatWindowCommand = {
42
43
  console.log(` greeting: ${r.greeting ?? '(none)'}`);
43
44
  }),
44
45
  })
45
- .demandCommand(1, 'Specify a subcommand: list, set-copy'),
46
+ .command({
47
+ command: 'get-style <id>',
48
+ describe: 'Show a chat window style and its multi-tab mode',
49
+ builder: (y) => y.positional('id', { type: 'number', describe: 'Chat window ID' }),
50
+ handler: runCommand(async (argv) => {
51
+ const w = await messagingGet(`/ChatWindow/get/${argv.id}`);
52
+ console.log(`${w.id} ${w.name ?? '(unnamed)'}`);
53
+ console.log(` multiTabMode: ${w.styleConfig?.multiTabMode ?? '(follow site/platform default)'}`);
54
+ }),
55
+ })
56
+ .command({
57
+ command: 'set-multi-tab-mode <id> <mode>',
58
+ describe: 'How the chat behaves across several open tabs: active-only | all-live | default',
59
+ builder: (y) => y
60
+ .positional('id', { type: 'number', describe: 'Chat window ID' })
61
+ .positional('mode', { type: 'string', choices: ['active-only', 'all-live', 'default'], describe: '"default" follows the site/platform default' }),
62
+ handler: runCommand(async (argv) => {
63
+ const mode = normalizeMultiTabMode(argv.mode);
64
+ const current = await messagingGet(`/ChatWindow/get/${argv.id}`);
65
+ const form = new FormData();
66
+ for (const [k, v] of Object.entries(buildMultiTabUpdateFields(current, mode))) form.append(k, v);
67
+ const r = await messagingPostForm(`/ChatWindow/Update/${argv.id}`, form);
68
+ console.log(`Updated chat window ${r.id}. multiTabMode: ${r.styleConfig?.multiTabMode ?? '(follow default)'}`);
69
+ }),
70
+ })
71
+ .demandCommand(1, 'Specify a subcommand: list, set-copy, get-style, set-multi-tab-mode'),
46
72
  handler: () => {},
47
73
  };
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.175",
3
+ "version": "1.4.177",
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": {