@velaro/cli 1.4.186 → 1.4.187
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/lib/commands/routing.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { messagingGet, messagingPut, messagingPost, messagingDel, get as adminGet } from '../api.js';
|
|
2
|
+
import { escalationPath, buildPutBody as buildEscalationBody } from '../escalation-settings.js';
|
|
2
3
|
import { teamConfigPath, buildTeamConfigBody, parseExtraJson } from '../routing-team-config.js';
|
|
3
4
|
import {
|
|
4
5
|
TERMINAL_ACTION_NAMES, buildPolicyUpdate, validatePolicyUpdate, describeChain,
|
|
@@ -455,6 +456,63 @@ const teamConfigCommand = {
|
|
|
455
456
|
handler: () => {},
|
|
456
457
|
};
|
|
457
458
|
|
|
459
|
+
// -- velaro routing escalation get|set (SLA warning/breach percent, unanswered-chat escalation) --
|
|
460
|
+
|
|
461
|
+
const escalationGetCommand = {
|
|
462
|
+
command: 'get',
|
|
463
|
+
describe: 'Show SLA threshold and unanswered-chat escalation settings (omit --team for the account default)',
|
|
464
|
+
builder: (y) => y.option('team', { type: 'number', describe: 'Team (group) id' }),
|
|
465
|
+
handler: async (argv) => {
|
|
466
|
+
const r = await messagingGet(escalationPath(argv.team));
|
|
467
|
+
console.log(JSON.stringify(r, null, 2));
|
|
468
|
+
},
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
const escalationSetCommand = {
|
|
472
|
+
command: 'set',
|
|
473
|
+
describe: 'Change SLA warning/breach percent or escalation settings (only passed settings change; reads then merges)',
|
|
474
|
+
builder: (y) => y
|
|
475
|
+
.option('team', { type: 'number', describe: 'Team (group) id (omit for the account default)' })
|
|
476
|
+
.option('sla-warning', { type: 'number', describe: 'SLA warning percent of the queue timeout, 1-100 (not above breach)' })
|
|
477
|
+
.option('sla-breach', { type: 'number', describe: 'SLA breach percent, 1-100' })
|
|
478
|
+
.option('abandoned-escalation', { type: 'boolean' })
|
|
479
|
+
.option('unassigned-minutes', { type: 'number' })
|
|
480
|
+
.option('fallback-team', { type: 'number' })
|
|
481
|
+
.option('untouched-minutes', { type: 'number' })
|
|
482
|
+
.option('bounceback', { type: 'boolean' })
|
|
483
|
+
.option('reset', { type: 'string', describe: 'Comma list of settings to clear back to the default, e.g. slaWarningPercent' }),
|
|
484
|
+
handler: async (argv) => {
|
|
485
|
+
try {
|
|
486
|
+
const patch = {
|
|
487
|
+
slaWarningPercent: argv['sla-warning'], slaBreachPercent: argv['sla-breach'],
|
|
488
|
+
abandonedEscalationEnabled: argv['abandoned-escalation'], unassignedEscalationMinutes: argv['unassigned-minutes'],
|
|
489
|
+
fallbackTeamId: argv['fallback-team'], assignedButUntouchedMinutes: argv['untouched-minutes'],
|
|
490
|
+
transferBouncebackEnabled: argv.bounceback,
|
|
491
|
+
};
|
|
492
|
+
for (const k of String(argv.reset || '').split(',').map((x) => x.trim()).filter(Boolean)) patch[k] = null;
|
|
493
|
+
const path = escalationPath(argv.team);
|
|
494
|
+
const cur = await messagingGet(path);
|
|
495
|
+
const body = buildEscalationBody(cur?.overrides || {}, patch);
|
|
496
|
+
await messagingPut(path, body);
|
|
497
|
+
console.log(`\n ${GRN}\u2713${RESET} Escalation settings saved.\n`);
|
|
498
|
+
} catch (e) {
|
|
499
|
+
console.error(` ${RED}x${RESET} ${e.message}`);
|
|
500
|
+
process.exitCode = 1;
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
const escalationCommand = {
|
|
506
|
+
command: 'escalation <subcommand>',
|
|
507
|
+
describe: 'SLA warning/breach thresholds and unanswered-chat escalation (account default or per team)',
|
|
508
|
+
builder: (y) => y
|
|
509
|
+
.command(escalationGetCommand)
|
|
510
|
+
.command(escalationSetCommand)
|
|
511
|
+
.demandCommand(1, 'Specify a subcommand: get, set')
|
|
512
|
+
.strict(),
|
|
513
|
+
handler: () => {},
|
|
514
|
+
};
|
|
515
|
+
|
|
458
516
|
// ── top-level routing command ─────────────────────────────────────────────────
|
|
459
517
|
|
|
460
518
|
export const routingCommand = {
|
|
@@ -465,12 +523,13 @@ export const routingCommand = {
|
|
|
465
523
|
.command(circuitBreakerCommand)
|
|
466
524
|
.command(policyCommand)
|
|
467
525
|
.command(teamConfigCommand)
|
|
526
|
+
.command(escalationCommand)
|
|
468
527
|
.command(decisionLogCommand)
|
|
469
528
|
.command(explainCommand)
|
|
470
529
|
.command(simulateCommand)
|
|
471
530
|
.command(precedenceCommand)
|
|
472
531
|
.command(inactivityTransfersCommand)
|
|
473
|
-
.demandCommand(1, 'Specify a subcommand: engine, circuit-breaker, policy, team-config, decision-log, explain, simulate, precedence, inactivity-transfers')
|
|
532
|
+
.demandCommand(1, 'Specify a subcommand: engine, circuit-breaker, policy, team-config, escalation, decision-log, explain, simulate, precedence, inactivity-transfers')
|
|
474
533
|
.strict(),
|
|
475
534
|
handler: () => {},
|
|
476
535
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Unanswered-chat escalation + SLA threshold helpers (REST: messaging GET/PUT /EscalationSettings and
|
|
2
|
+
// /EscalationSettings/team/{id}). The PUT replaces all seven stored overrides, so a save reads the current
|
|
3
|
+
// overrides, merges only the passed fields, and sends the full set. null = "use the default".
|
|
4
|
+
|
|
5
|
+
export const FIELDS = {
|
|
6
|
+
slaWarningPercent: { min: 1, max: 100 },
|
|
7
|
+
slaBreachPercent: { min: 1, max: 100 },
|
|
8
|
+
abandonedEscalationEnabled: { bool: true },
|
|
9
|
+
unassignedEscalationMinutes: { min: 1, max: 1440 },
|
|
10
|
+
fallbackTeamId: { min: 1, max: 2147483647 },
|
|
11
|
+
assignedButUntouchedMinutes: { min: 1, max: 10080 },
|
|
12
|
+
transferBouncebackEnabled: { bool: true },
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function escalationPath(teamId) {
|
|
16
|
+
if (teamId === undefined || teamId === null || teamId === '') return '/EscalationSettings';
|
|
17
|
+
const n = Number(teamId);
|
|
18
|
+
if (!Number.isInteger(n) || n <= 0) throw new Error('teamId must be a positive integer.');
|
|
19
|
+
return `/EscalationSettings/team/${n}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// patch: { field: value | null } where null clears the field back to the default.
|
|
23
|
+
export function validatePatch(patch = {}) {
|
|
24
|
+
const keys = Object.keys(patch).filter((k) => patch[k] !== undefined);
|
|
25
|
+
if (!keys.length) throw new Error('No settings to change were provided.');
|
|
26
|
+
for (const k of keys) {
|
|
27
|
+
const d = FIELDS[k];
|
|
28
|
+
if (!d) throw new Error(`Unknown setting ${k}. Allowed: ${Object.keys(FIELDS).join(', ')}.`);
|
|
29
|
+
const v = patch[k];
|
|
30
|
+
if (v === null) continue;
|
|
31
|
+
if (d.bool) { if (typeof v !== 'boolean') throw new Error(`${k} must be true or false.`); continue; }
|
|
32
|
+
if (!Number.isInteger(v) || v < d.min || v > d.max) throw new Error(`${k} must be a whole number between ${d.min} and ${d.max}.`);
|
|
33
|
+
}
|
|
34
|
+
return keys;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function buildPutBody(currentOverrides = {}, patch = {}) {
|
|
38
|
+
validatePatch(patch);
|
|
39
|
+
const body = {};
|
|
40
|
+
for (const k of Object.keys(FIELDS)) body[k] = currentOverrides?.[k] ?? null;
|
|
41
|
+
for (const [k, v] of Object.entries(patch)) if (v !== undefined) body[k] = v;
|
|
42
|
+
const w = body.slaWarningPercent, b = body.slaBreachPercent;
|
|
43
|
+
if (w != null && b != null && w > b) throw new Error('The SLA warning percent cannot be higher than the SLA breach percent.');
|
|
44
|
+
return body;
|
|
45
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { escalationPath, validatePatch, buildPutBody } from './escalation-settings.js';
|
|
4
|
+
|
|
5
|
+
test('path scopes by team and rejects junk', () => {
|
|
6
|
+
assert.equal(escalationPath(), '/EscalationSettings');
|
|
7
|
+
assert.equal(escalationPath(4), '/EscalationSettings/team/4');
|
|
8
|
+
assert.throws(() => escalationPath(0));
|
|
9
|
+
assert.throws(() => escalationPath('x'));
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('patch validation', () => {
|
|
13
|
+
assert.throws(() => validatePatch({}));
|
|
14
|
+
assert.throws(() => validatePatch({ slaWarningPercent: 0 }));
|
|
15
|
+
assert.throws(() => validatePatch({ slaWarningPercent: 101 }));
|
|
16
|
+
assert.throws(() => validatePatch({ slaWarningPercent: 50.5 }));
|
|
17
|
+
assert.throws(() => validatePatch({ bogus: 1 }));
|
|
18
|
+
assert.throws(() => validatePatch({ transferBouncebackEnabled: 'yes' }));
|
|
19
|
+
assert.deepEqual(validatePatch({ slaWarningPercent: 50, slaBreachPercent: null }), ['slaWarningPercent', 'slaBreachPercent']);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('merge keeps untouched fields, full seven-field body, null clears', () => {
|
|
23
|
+
const cur = { slaBreachPercent: 90, unassignedEscalationMinutes: 10, fallbackTeamId: 3 };
|
|
24
|
+
const b = buildPutBody(cur, { slaWarningPercent: 60 });
|
|
25
|
+
assert.equal(Object.keys(b).length, 7);
|
|
26
|
+
assert.equal(b.slaWarningPercent, 60);
|
|
27
|
+
assert.equal(b.slaBreachPercent, 90);
|
|
28
|
+
assert.equal(b.unassignedEscalationMinutes, 10);
|
|
29
|
+
assert.equal(b.fallbackTeamId, 3);
|
|
30
|
+
assert.equal(b.abandonedEscalationEnabled, null);
|
|
31
|
+
assert.equal(buildPutBody(cur, { fallbackTeamId: null }).fallbackTeamId, null);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('warning cannot exceed breach after merge', () => {
|
|
35
|
+
assert.throws(() => buildPutBody({ slaBreachPercent: 50 }, { slaWarningPercent: 80 }), /cannot be higher/);
|
|
36
|
+
assert.doesNotThrow(() => buildPutBody({ slaBreachPercent: 50 }, { slaWarningPercent: 50 }));
|
|
37
|
+
});
|
package/package.json
CHANGED