@velaro/cli 1.4.186 → 1.4.188
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/api.js +31 -0
- package/lib/commands/routing.js +60 -1
- package/lib/commands/sign.js +168 -20
- package/lib/escalation-settings.js +45 -0
- package/lib/escalation-settings.test.js +37 -0
- package/lib/sign.test.js +19 -0
- package/package.json +1 -1
package/lib/api.js
CHANGED
|
@@ -104,6 +104,23 @@ 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 upload to the admin API (staff Bearer). `form` is a FormData. Returns parsed JSON.
|
|
108
|
+
export async function postForm(path, form, envOverride) {
|
|
109
|
+
const creds = await getCredentials(envOverride);
|
|
110
|
+
const res = await fetch(joinUrl(creds.adminApiBase, path), {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: { Authorization: `Bearer ${creds.velaroToken}` },
|
|
113
|
+
body: form,
|
|
114
|
+
});
|
|
115
|
+
if (!res.ok) {
|
|
116
|
+
let msg = `POST ${path} -> ${res.status}`;
|
|
117
|
+
try { const t = await res.text(); if (t) msg += `: ${t}`; } catch { /* status captured */ }
|
|
118
|
+
throw new Error(msg);
|
|
119
|
+
}
|
|
120
|
+
const text = await res.text();
|
|
121
|
+
return text ? JSON.parse(text) : null;
|
|
122
|
+
}
|
|
123
|
+
|
|
107
124
|
// multipart/form-data POST (ChatWindow/Update takes [FromForm]); fetch sets the boundary header itself.
|
|
108
125
|
export async function messagingPostForm(path, form, envOverride) {
|
|
109
126
|
const creds = await getCredentials(envOverride);
|
|
@@ -124,6 +141,20 @@ export async function messagingPostForm(path, form, envOverride) {
|
|
|
124
141
|
return text ? JSON.parse(text) : null;
|
|
125
142
|
}
|
|
126
143
|
|
|
144
|
+
// Binary download from the admin API. Returns a Buffer.
|
|
145
|
+
export async function getBinary(path, envOverride) {
|
|
146
|
+
const creds = await getCredentials(envOverride);
|
|
147
|
+
const res = await fetch(joinUrl(creds.adminApiBase, path), {
|
|
148
|
+
headers: { Authorization: `Bearer ${creds.velaroToken}` },
|
|
149
|
+
});
|
|
150
|
+
if (!res.ok) {
|
|
151
|
+
let msg = `GET ${path} -> ${res.status}`;
|
|
152
|
+
try { const t = await res.text(); if (t) msg += `: ${t}`; } catch { /* status captured */ }
|
|
153
|
+
throw new Error(msg);
|
|
154
|
+
}
|
|
155
|
+
return Buffer.from(await res.arrayBuffer());
|
|
156
|
+
}
|
|
157
|
+
|
|
127
158
|
// Same as messagingRequest but returns the raw response text (for CSV downloads).
|
|
128
159
|
export async function messagingRequestText(method, path, envOverride) {
|
|
129
160
|
const creds = await getCredentials(envOverride);
|
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
|
};
|
package/lib/commands/sign.js
CHANGED
|
@@ -1,9 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { get, post, put, postForm, getBinary, getCredentials } from '../api.js';
|
|
4
|
+
import { runCommand } from '../run.js';
|
|
5
|
+
import { versionsPath, diffPath, uploadPath, describeVersions, describeDiff, buildUploadForm, OWNER_ONLY_RULE } from '../sign-versions.js';
|
|
6
|
+
|
|
7
|
+
// velaro sign -- Velaro Sign routing, reminders, final PDF download, file verification.
|
|
8
|
+
// Backend: server/Velaro.Admin/Controllers/ContractSignersController.cs (route api/Contract)
|
|
9
|
+
// GET api/Contract/{id}/signers
|
|
10
|
+
// PUT api/Contract/{id}/signers
|
|
11
|
+
// POST api/Contract/{id}/signers/reassignments/{requestId}/approve|deny
|
|
12
|
+
// PUT api/Contract/{id}/reminders
|
|
13
|
+
// GET api/Contract/{id}/signed-document
|
|
14
|
+
// POST api/Contract/verify (multipart 'file')
|
|
15
|
+
|
|
16
|
+
const csv = (v) => (v == null ? [] : String(v).split(',').map(s => s.trim()).filter(Boolean));
|
|
17
|
+
|
|
18
|
+
export function buildSignersBody(existing, argv) {
|
|
19
|
+
const emails = csv(argv.order);
|
|
20
|
+
const names = csv(argv.names);
|
|
21
|
+
const roles = csv(argv.roles);
|
|
22
|
+
const body = {
|
|
23
|
+
mode: argv.mode || existing?.mode || 'sequential',
|
|
24
|
+
allowReassignment: argv.allowReassign != null ? !!argv.allowReassign : existing?.allowReassignment,
|
|
25
|
+
reminderEveryDays: existing?.reminderEveryDays,
|
|
26
|
+
reminderMaxCount: existing?.reminderMaxCount,
|
|
27
|
+
};
|
|
28
|
+
if (emails.length) {
|
|
29
|
+
const prior = new Map((existing?.signers || []).map(s => [String(s.email).toLowerCase(), s]));
|
|
30
|
+
body.signers = emails.map((email, i) => {
|
|
31
|
+
const p = prior.get(email.toLowerCase());
|
|
32
|
+
return {
|
|
33
|
+
order: i + 1,
|
|
34
|
+
role: roles[i] || p?.role || 'customer',
|
|
35
|
+
name: names[i] || p?.name || email.split('@')[0],
|
|
36
|
+
email,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
body.signers = (existing?.signers || []).map((s, i) => ({ order: s.order ?? i + 1, role: s.role, name: s.name, email: s.email }));
|
|
41
|
+
}
|
|
42
|
+
return body;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function showSigners(r) {
|
|
46
|
+
console.log(`\nContract status: ${r.contractStatus} routing: ${r.routingStatus} mode: ${r.mode} reassignment: ${r.allowReassignment ? 'allowed' : 'off'}`);
|
|
47
|
+
console.log(`Reminders: every ${r.reminderEveryDays ?? '-'}d, max ${r.reminderMaxCount ?? '-'}`);
|
|
48
|
+
console.log(`Original SHA-256: ${r.originalSha256 || '-'}`);
|
|
49
|
+
console.log(`Signed SHA-256: ${r.signedSha256 || '-'} (final PDF ${r.finalPdfAvailable ? 'available' : 'not available'})`);
|
|
50
|
+
for (const s of r.signers || []) {
|
|
51
|
+
console.log(` ${s.order}. [${s.role}] ${s.name} <${s.email}> ${s.status}${s.signedAt ? ' ' + s.signedAt : ''}`);
|
|
52
|
+
}
|
|
53
|
+
for (const q of r.reassignmentRequests || []) {
|
|
54
|
+
console.log(` reassignment request: ${JSON.stringify(q)}`);
|
|
55
|
+
}
|
|
56
|
+
console.log('');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function signersHandler(argv) {
|
|
60
|
+
const base = `/api/Contract/${argv.id}/signers`;
|
|
61
|
+
const existing = await get(base);
|
|
62
|
+
if (argv.action !== 'set') return showSigners(existing);
|
|
63
|
+
await put(base, buildSignersBody(existing, argv));
|
|
64
|
+
showSigners(await get(base));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function reassignHandler(argv) {
|
|
68
|
+
await post(`/api/Contract/${argv.id}/signers/reassignments/${argv.requestId}/${argv.decision}`, argv.note ? { note: argv.note } : {});
|
|
69
|
+
console.log(`\nReassignment ${argv.requestId} ${argv.decision === 'approve' ? 'approved' : 'denied'}.\n`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function remindersHandler(argv) {
|
|
73
|
+
await put(`/api/Contract/${argv.id}/reminders`, { everyDays: argv.every, maxCount: argv.max });
|
|
74
|
+
console.log(`\nReminders set: every ${argv.every} day(s), max ${argv.max}.\n`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function downloadHandler(argv) {
|
|
78
|
+
const buf = await getBinary(`/api/Contract/${argv.id}/signed-document`);
|
|
79
|
+
const out = argv.out || `contract-${argv.id}-signed.pdf`;
|
|
80
|
+
writeFileSync(out, buf);
|
|
81
|
+
console.log(`\nSaved ${buf.length} bytes to ${out}\n`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function verifyHandler(argv) {
|
|
85
|
+
const form = new FormData();
|
|
86
|
+
form.append('file', new Blob([readFileSync(argv.file)]), basename(argv.file));
|
|
87
|
+
const r = await postForm('/api/Contract/verify', form);
|
|
88
|
+
if (r?.match) {
|
|
89
|
+
console.log(`\nMATCH contract ${r.contractId} "${r.title ?? ''}" (${r.status}) matched ${r.matched}\n sha256 ${r.sha256}\n`);
|
|
90
|
+
} else {
|
|
91
|
+
console.log(`\nNO MATCH sha256 ${r?.sha256 ?? '-'}\n`);
|
|
92
|
+
process.exitCode = 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
7
95
|
|
|
8
96
|
async function versions(id, json) {
|
|
9
97
|
const res = await get(versionsPath(id));
|
|
@@ -31,19 +119,79 @@ async function uploadVersion(id, file, note) {
|
|
|
31
119
|
}
|
|
32
120
|
|
|
33
121
|
export const signCommand = {
|
|
34
|
-
command:
|
|
35
|
-
describe: 'Velaro Sign
|
|
36
|
-
builder:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
122
|
+
command: 'sign <subcommand>',
|
|
123
|
+
describe: 'Velaro Sign -- signer routing, reminders, final PDF, file verification',
|
|
124
|
+
builder: (y) => y
|
|
125
|
+
.command({
|
|
126
|
+
command: 'signers <id> [action]',
|
|
127
|
+
describe: 'Show signers (default) or "set" the routing',
|
|
128
|
+
builder: (y2) => y2
|
|
129
|
+
.positional('id', { type: 'number' })
|
|
130
|
+
.positional('action', { type: 'string', choices: ['set'] })
|
|
131
|
+
.option('order', { describe: 'Comma-separated signer emails in signing order', type: 'string' })
|
|
132
|
+
.option('names', { describe: 'Comma-separated names matching --order', type: 'string' })
|
|
133
|
+
.option('roles', { describe: 'Comma-separated roles (customer|velaro) matching --order', type: 'string' })
|
|
134
|
+
.option('mode', { describe: 'sequential | parallel', type: 'string', choices: ['sequential', 'parallel'] })
|
|
135
|
+
.option('allow-reassign', { describe: 'Allow signers to request reassignment', type: 'boolean' }),
|
|
136
|
+
handler: runCommand(signersHandler),
|
|
137
|
+
})
|
|
138
|
+
.command({
|
|
139
|
+
command: 'reassign <decision> <id> <requestId>',
|
|
140
|
+
describe: 'Approve or deny a signer reassignment request',
|
|
141
|
+
builder: (y2) => y2
|
|
142
|
+
.positional('decision', { type: 'string', choices: ['approve', 'deny'] })
|
|
143
|
+
.positional('id', { type: 'number' })
|
|
144
|
+
.positional('requestId', { type: 'number' })
|
|
145
|
+
.option('note', { type: 'string' }),
|
|
146
|
+
handler: runCommand(reassignHandler),
|
|
147
|
+
})
|
|
148
|
+
.command({
|
|
149
|
+
command: 'reminders set <id>',
|
|
150
|
+
describe: 'Set reminder cadence',
|
|
151
|
+
builder: (y2) => y2
|
|
152
|
+
.positional('id', { type: 'number' })
|
|
153
|
+
.option('every', { describe: 'Days between reminders', type: 'number', demandOption: true })
|
|
154
|
+
.option('max', { describe: 'Max reminders', type: 'number', demandOption: true }),
|
|
155
|
+
handler: runCommand(remindersHandler),
|
|
156
|
+
})
|
|
157
|
+
.command({
|
|
158
|
+
command: 'download <id>',
|
|
159
|
+
describe: 'Download the final signed PDF',
|
|
160
|
+
builder: (y2) => y2.positional('id', { type: 'number' }).option('out', { type: 'string', describe: 'Output file' }),
|
|
161
|
+
handler: runCommand(downloadHandler),
|
|
162
|
+
})
|
|
163
|
+
.command({
|
|
164
|
+
command: 'verify <file>',
|
|
165
|
+
describe: 'Verify a file against original/final contract hashes (exit 1 on no match)',
|
|
166
|
+
builder: (y2) => y2.positional('file', { type: 'string' }),
|
|
167
|
+
handler: runCommand(verifyHandler),
|
|
168
|
+
})
|
|
169
|
+
.command({
|
|
170
|
+
command: 'versions <contractId>',
|
|
171
|
+
describe: 'List every uploaded document version of a contract (owner-only)',
|
|
172
|
+
builder: (y2) => y2.positional('contractId', { type: 'number' }).option('json', { type: 'boolean', default: false }),
|
|
173
|
+
handler: runCommand((a) => versions(a.contractId, a.json)),
|
|
174
|
+
})
|
|
175
|
+
.command({
|
|
176
|
+
command: 'diff <contractId> <from> <to>',
|
|
177
|
+
describe: 'Text diff between two document versions (owner-only)',
|
|
178
|
+
builder: (y2) => y2
|
|
179
|
+
.positional('contractId', { type: 'number' })
|
|
180
|
+
.positional('from', { type: 'number' })
|
|
181
|
+
.positional('to', { type: 'number' })
|
|
182
|
+
.option('json', { type: 'boolean', default: false }),
|
|
183
|
+
handler: runCommand((a) => diff(a.contractId, a.from, a.to, a.json)),
|
|
184
|
+
})
|
|
185
|
+
.command({
|
|
186
|
+
command: 'upload-version <contractId> <file>',
|
|
187
|
+
describe: 'Upload a new PDF version (draft contracts only; after send/sign void and re-send)',
|
|
188
|
+
builder: (y2) => y2
|
|
189
|
+
.positional('contractId', { type: 'number' })
|
|
190
|
+
.positional('file', { type: 'string' })
|
|
191
|
+
.option('note', { type: 'string', describe: 'Change note stored with the version' }),
|
|
192
|
+
handler: runCommand((a) => uploadVersion(a.contractId, a.file, a.note)),
|
|
193
|
+
})
|
|
194
|
+
.demandCommand(1, 'Specify: signers | reassign | reminders | download | verify | versions | diff | upload-version')
|
|
195
|
+
.strict(),
|
|
48
196
|
handler: () => {},
|
|
49
197
|
};
|
|
@@ -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/lib/sign.test.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { buildSignersBody } from './commands/sign.js';
|
|
4
|
+
|
|
5
|
+
test('buildSignersBody builds ordered signers and keeps existing settings', () => {
|
|
6
|
+
const b = buildSignersBody({ mode: 'parallel', allowReassignment: true, reminderEveryDays: 3, reminderMaxCount: 5, signers: [] },
|
|
7
|
+
{ order: 'a@x.com,b@y.com', roles: 'customer,velaro' });
|
|
8
|
+
assert.equal(b.mode, 'parallel');
|
|
9
|
+
assert.equal(b.allowReassignment, true);
|
|
10
|
+
assert.deepEqual(b.signers.map(s => [s.order, s.role, s.email]), [[1, 'customer', 'a@x.com'], [2, 'velaro', 'b@y.com']]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('buildSignersBody merges mode flag and preserves existing names', () => {
|
|
14
|
+
const b = buildSignersBody({ mode: 'sequential', signers: [{ order: 1, role: 'customer', name: 'Ann', email: 'a@x.com' }] },
|
|
15
|
+
{ order: 'a@x.com', mode: 'parallel', allowReassign: true });
|
|
16
|
+
assert.equal(b.mode, 'parallel');
|
|
17
|
+
assert.equal(b.allowReassignment, true);
|
|
18
|
+
assert.equal(b.signers[0].name, 'Ann');
|
|
19
|
+
});
|
package/package.json
CHANGED