@velaro/cli 1.4.121 → 1.4.122
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/signature.js +39 -3
- package/lib/signature-policy.js +42 -0
- package/lib/signature-policy.test.js +28 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { messagingGet, messagingPut } from '../api.js';
|
|
1
|
+
import { messagingGet, messagingPut, messagingPost } from '../api.js';
|
|
2
2
|
import { buildPolicyBody, findPolicy, describeMode, parseTeamId } from '../signature-policy.js';
|
|
3
3
|
|
|
4
4
|
// velaro signature policy get|set
|
|
@@ -19,6 +19,8 @@ function printRow(label, row) {
|
|
|
19
19
|
const dis = row.disclaimerEnabled === null || row.disclaimerEnabled === undefined ? 'follows company-wide (off if none set)' : row.disclaimerEnabled ? 'on' : 'off';
|
|
20
20
|
console.log(` disclaimer ${dis}`);
|
|
21
21
|
if (row.disclaimerText) console.log(` text ${row.disclaimerText}`);
|
|
22
|
+
console.log(` name line ${row.nameFormat ?? 'follows (none if nothing set)'}${row.nameSource ? `, ${row.nameSource}` : ''}${row.teamLabel ? `, team label "${row.teamLabel}"` : ''}`);
|
|
23
|
+
if (row.teamId === 0) console.log(` overrides team admins ${row.allowTeamOverrides === false ? 'blocked' : 'allowed'}, agents ${row.allowAgentOverrides === false ? 'blocked' : 'allowed'}`);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
const getCommand = {
|
|
@@ -47,7 +49,13 @@ const setCommand = {
|
|
|
47
49
|
.option('signature', { type: 'string', describe: 'Company signature HTML (empty string clears it)' })
|
|
48
50
|
.option('disclaimer', { type: 'boolean', describe: 'Turn the legal disclaimer on or off' })
|
|
49
51
|
.option('disclaimer-default', { type: 'boolean', describe: 'Clear the disclaimer on/off choice back to company-wide' })
|
|
50
|
-
.option('disclaimer-text', { type: 'string', describe: 'Legal disclaimer text (empty string clears it)' })
|
|
52
|
+
.option('disclaimer-text', { type: 'string', describe: 'Legal disclaimer text (empty string clears it)' })
|
|
53
|
+
.option('name-format', { type: 'string', describe: 'none | name | team | name-and-team | default' })
|
|
54
|
+
.option('name-source', { type: 'string', describe: 'real-name | display-name | default' })
|
|
55
|
+
.option('team-label', { type: 'string', describe: 'Team name shown by the team formats (empty string clears it)' })
|
|
56
|
+
.option('allow-team-overrides', { type: 'boolean', describe: 'Company-wide only: may team admins change group settings' })
|
|
57
|
+
.option('allow-agent-overrides', { type: 'boolean', describe: 'Company-wide only: may agents choose their own name line' })
|
|
58
|
+
.option('apply-to', { type: 'string', describe: 'Company-wide only: inheritingGroups | allGroups | newGroupsOnly' }),
|
|
51
59
|
handler: async (argv) => {
|
|
52
60
|
const teamId = parseTeamId(argv['team-id']);
|
|
53
61
|
const data = await messagingGet('/Signatures/policy');
|
|
@@ -58,16 +66,44 @@ const setCommand = {
|
|
|
58
66
|
corporateSignature: argv.signature,
|
|
59
67
|
disclaimerEnabled: argv['disclaimer-default'] ? null : argv.disclaimer,
|
|
60
68
|
disclaimerText: argv['disclaimer-text'],
|
|
69
|
+
nameFormat: argv['name-format'],
|
|
70
|
+
nameSource: argv['name-source'],
|
|
71
|
+
teamLabel: argv['team-label'],
|
|
72
|
+
allowTeamOverrides: argv['allow-team-overrides'],
|
|
73
|
+
allowAgentOverrides: argv['allow-agent-overrides'],
|
|
74
|
+
applyTo: argv['apply-to'],
|
|
61
75
|
});
|
|
62
76
|
await messagingPut('/Signatures/policy', body);
|
|
63
77
|
console.log(`${GRN}Signature policy updated.${RESET} Run \`velaro signature policy get\` to review.`);
|
|
64
78
|
},
|
|
65
79
|
};
|
|
66
80
|
|
|
81
|
+
const historyCommand = {
|
|
82
|
+
command: 'history',
|
|
83
|
+
describe: 'List saved versions of the policy (newest first)',
|
|
84
|
+
builder: (y) => y.option('team-id', { type: 'number', default: 0, describe: '0 = company-wide' }),
|
|
85
|
+
handler: async (argv) => {
|
|
86
|
+
const list = await messagingGet(`/Signatures/policy/history?teamId=${parseTeamId(argv['team-id'])}`);
|
|
87
|
+
for (const v of Array.isArray(list) ? list : []) {
|
|
88
|
+
console.log(`${v.id} ${v.changedAt} ${v.changedByName || 'unknown'} ${v.action}`);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const rollbackCommand = {
|
|
94
|
+
command: 'rollback <versionId>',
|
|
95
|
+
describe: 'Restore a saved version (saved as a new version)',
|
|
96
|
+
builder: (y) => y.positional('versionId', { type: 'number' }),
|
|
97
|
+
handler: async (argv) => {
|
|
98
|
+
await messagingPost(`/Signatures/policy/rollback/${Number(argv.versionId)}`, {});
|
|
99
|
+
console.log(`${GRN}Rolled back.${RESET} Run \`velaro signature policy get\` to review.`);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
67
103
|
const policyCommand = {
|
|
68
104
|
command: 'policy <subcommand>',
|
|
69
105
|
describe: 'View and update the company email signature policy',
|
|
70
|
-
builder: (y) => y.command(getCommand).command(setCommand).demandCommand(1, 'Specify a subcommand: get | set'),
|
|
106
|
+
builder: (y) => y.command(getCommand).command(setCommand).command(historyCommand).command(rollbackCommand).demandCommand(1, 'Specify a subcommand: get | set | history | rollback'),
|
|
71
107
|
handler: () => {},
|
|
72
108
|
};
|
|
73
109
|
|
package/lib/signature-policy.js
CHANGED
|
@@ -22,6 +22,28 @@ export function parseMode(value) {
|
|
|
22
22
|
return mode;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const NAME_SOURCES = ['real_name', 'display_name'];
|
|
26
|
+
const NAME_FORMATS = ['none', 'name', 'team', 'name_and_team'];
|
|
27
|
+
const APPLY_TO = ['inheritingGroups', 'allGroups', 'newGroupsOnly'];
|
|
28
|
+
|
|
29
|
+
// undefined = not supplied, null = inherit, else a validated API value. Accepts dashes ("display-name").
|
|
30
|
+
function parseEnum(value, allowed, label) {
|
|
31
|
+
if (value === undefined) return undefined;
|
|
32
|
+
if (value === null) return null;
|
|
33
|
+
const v = String(value).trim().toLowerCase().replace(/-/g, '_');
|
|
34
|
+
if (v === '' || v === 'default' || v === 'inherit') return null;
|
|
35
|
+
if (!allowed.includes(v)) throw new Error(`${label} must be one of ${allowed.join(', ')} or default`);
|
|
36
|
+
return v;
|
|
37
|
+
}
|
|
38
|
+
export const parseNameSource = (v) => parseEnum(v, NAME_SOURCES, 'nameSource');
|
|
39
|
+
export const parseNameFormat = (v) => parseEnum(v, NAME_FORMATS, 'nameFormat');
|
|
40
|
+
|
|
41
|
+
export function parseApplyTo(value) {
|
|
42
|
+
if (value === undefined || value === null || value === '') return undefined;
|
|
43
|
+
if (!APPLY_TO.includes(value)) throw new Error(`applyTo must be one of ${APPLY_TO.join(', ')}`);
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
|
|
25
47
|
export function parseTeamId(value) {
|
|
26
48
|
if (value === undefined || value === null || value === '') return 0;
|
|
27
49
|
const n = Number(value);
|
|
@@ -39,6 +61,12 @@ export function buildPolicyBody(current, opts = {}) {
|
|
|
39
61
|
corporateSignature: cur.corporateSignature || null,
|
|
40
62
|
disclaimerEnabled: cur.disclaimerEnabled ?? null,
|
|
41
63
|
disclaimerText: cur.disclaimerText || null,
|
|
64
|
+
// PUT replaces the whole row, so the flow-down fields must be carried or a mode change would wipe them.
|
|
65
|
+
nameSource: cur.nameSource ?? null,
|
|
66
|
+
nameFormat: cur.nameFormat ?? null,
|
|
67
|
+
teamLabel: cur.teamLabel || null,
|
|
68
|
+
allowTeamOverrides: cur.allowTeamOverrides ?? null,
|
|
69
|
+
allowAgentOverrides: cur.allowAgentOverrides ?? null,
|
|
42
70
|
};
|
|
43
71
|
const mode = parseMode(opts.mode);
|
|
44
72
|
if (mode !== undefined) body.mode = mode;
|
|
@@ -50,6 +78,20 @@ export function buildPolicyBody(current, opts = {}) {
|
|
|
50
78
|
body.disclaimerEnabled = opts.disclaimerEnabled;
|
|
51
79
|
}
|
|
52
80
|
if (opts.disclaimerText !== undefined) body.disclaimerText = opts.disclaimerText || null;
|
|
81
|
+
const nameSource = parseNameSource(opts.nameSource);
|
|
82
|
+
if (nameSource !== undefined) body.nameSource = nameSource;
|
|
83
|
+
const nameFormat = parseNameFormat(opts.nameFormat);
|
|
84
|
+
if (nameFormat !== undefined) body.nameFormat = nameFormat;
|
|
85
|
+
if (opts.teamLabel !== undefined) body.teamLabel = opts.teamLabel || null;
|
|
86
|
+
for (const k of ['allowTeamOverrides', 'allowAgentOverrides']) {
|
|
87
|
+
if (opts[k] !== undefined) {
|
|
88
|
+
if (opts[k] !== null && typeof opts[k] !== 'boolean') throw new Error(`${k} must be true, false or null`);
|
|
89
|
+
body[k] = opts[k];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const applyTo = parseApplyTo(opts.applyTo);
|
|
93
|
+
if (applyTo !== undefined) body.applyTo = applyTo;
|
|
94
|
+
if (body.teamLabel && body.teamLabel.length > 100) throw new Error('teamLabel is limited to 100 characters');
|
|
53
95
|
if (body.corporateSignature && body.corporateSignature.length > 4000) throw new Error('corporateSignature is limited to 4000 characters');
|
|
54
96
|
if (body.disclaimerText && body.disclaimerText.length > 2000) throw new Error('disclaimerText is limited to 2000 characters');
|
|
55
97
|
return body;
|
|
@@ -21,12 +21,12 @@ test('parseTeamId defaults to company-wide and rejects junk', () => {
|
|
|
21
21
|
test('buildPolicyBody keeps current values for fields that are not passed', () => {
|
|
22
22
|
const cur = { teamId: 0, mode: 'company_default', corporateSignature: '<b>Acme</b>', disclaimerEnabled: true, disclaimerText: 'Confidential' };
|
|
23
23
|
const body = buildPolicyBody(cur, { mode: 'locked' });
|
|
24
|
-
assert.deepEqual(body, { teamId: 0, mode: 'admin_locked', corporateSignature: '<b>Acme</b>', disclaimerEnabled: true, disclaimerText: 'Confidential' });
|
|
24
|
+
assert.deepEqual(body, { teamId: 0, mode: 'admin_locked', corporateSignature: '<b>Acme</b>', disclaimerEnabled: true, disclaimerText: 'Confidential', nameSource: null, nameFormat: null, teamLabel: null, allowTeamOverrides: null, allowAgentOverrides: null });
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test('buildPolicyBody with no existing row starts from all-null (follow company-wide)', () => {
|
|
28
28
|
const body = buildPolicyBody(undefined, { teamId: 5, disclaimerEnabled: true });
|
|
29
|
-
assert.deepEqual(body, { teamId: 5, mode: null, corporateSignature: null, disclaimerEnabled: true, disclaimerText: null });
|
|
29
|
+
assert.deepEqual(body, { teamId: 5, mode: null, corporateSignature: null, disclaimerEnabled: true, disclaimerText: null, nameSource: null, nameFormat: null, teamLabel: null, allowTeamOverrides: null, allowAgentOverrides: null });
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
test('null clears a field and over-long text is rejected before sending', () => {
|
|
@@ -46,3 +46,29 @@ test('findPolicy picks the row for a team and describeMode is readable', () => {
|
|
|
46
46
|
assert.match(describeMode('admin_locked'), /locked/);
|
|
47
47
|
assert.match(describeMode(null), /follows/);
|
|
48
48
|
});
|
|
49
|
+
|
|
50
|
+
test('a mode change keeps the name line, team label and override switches (PUT replaces the row)', () => {
|
|
51
|
+
const cur = { teamId: 0, mode: 'company_default', nameSource: 'display_name', nameFormat: 'name_and_team', teamLabel: 'Customer Support', allowTeamOverrides: false, allowAgentOverrides: true };
|
|
52
|
+
const body = buildPolicyBody(cur, { mode: 'locked' });
|
|
53
|
+
assert.equal(body.mode, 'admin_locked');
|
|
54
|
+
assert.equal(body.nameSource, 'display_name');
|
|
55
|
+
assert.equal(body.nameFormat, 'name_and_team');
|
|
56
|
+
assert.equal(body.teamLabel, 'Customer Support');
|
|
57
|
+
assert.equal(body.allowTeamOverrides, false);
|
|
58
|
+
assert.equal(body.allowAgentOverrides, true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('name line options validate, accept dashes and clear with default', () => {
|
|
62
|
+
const body = buildPolicyBody(undefined, { nameFormat: 'name-and-team', nameSource: 'display-name', teamLabel: 'Support', allowAgentOverrides: false, applyTo: 'allGroups' });
|
|
63
|
+
assert.equal(body.nameFormat, 'name_and_team');
|
|
64
|
+
assert.equal(body.nameSource, 'display_name');
|
|
65
|
+
assert.equal(body.teamLabel, 'Support');
|
|
66
|
+
assert.equal(body.allowAgentOverrides, false);
|
|
67
|
+
assert.equal(body.applyTo, 'allGroups');
|
|
68
|
+
assert.equal(buildPolicyBody({ nameFormat: 'team' }, { nameFormat: 'default' }).nameFormat, null);
|
|
69
|
+
assert.throws(() => buildPolicyBody(undefined, { nameFormat: 'loud' }), /nameFormat must be one of/);
|
|
70
|
+
assert.throws(() => buildPolicyBody(undefined, { nameSource: 'nick' }), /nameSource must be one of/);
|
|
71
|
+
assert.throws(() => buildPolicyBody(undefined, { applyTo: 'some' }), /applyTo/);
|
|
72
|
+
assert.throws(() => buildPolicyBody(undefined, { allowTeamOverrides: 'no' }), /true, false or null/);
|
|
73
|
+
assert.throws(() => buildPolicyBody(undefined, { teamLabel: 'x'.repeat(101) }), /100/);
|
|
74
|
+
});
|
package/package.json
CHANGED