@velaro/cli 1.4.159 → 1.4.160
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 +2 -0
- package/lib/booking-defaults.js +99 -0
- package/lib/booking-defaults.test.js +36 -0
- package/lib/commands/booking-defaults.js +81 -0
- package/package.json +1 -1
package/bin/velaro.js
CHANGED
|
@@ -39,6 +39,7 @@ import { copilotStudioCommand } from '../lib/commands/copilotstudio.js';
|
|
|
39
39
|
import { applePayPresetCommand } from '../lib/commands/apple-pay-preset.js';
|
|
40
40
|
import { integrationCommand } from '../lib/commands/integration.js';
|
|
41
41
|
import { appointmentsCommand } from '../lib/commands/appointments.js';
|
|
42
|
+
import { bookingDefaultsCommand } from '../lib/commands/booking-defaults.js';
|
|
42
43
|
import { bookingCommand } from '../lib/commands/booking.js';
|
|
43
44
|
import { reportCommand } from '../lib/commands/report.js';
|
|
44
45
|
import { scheduleAdherenceCommand } from '../lib/commands/schedule-adherence.js';
|
|
@@ -188,6 +189,7 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
188
189
|
.command(applePayPresetCommand)
|
|
189
190
|
.command(integrationCommand)
|
|
190
191
|
.command(appointmentsCommand)
|
|
192
|
+
.command(bookingDefaultsCommand)
|
|
191
193
|
.command(bookingCommand)
|
|
192
194
|
.command(reportCommand)
|
|
193
195
|
.command(conversationEfficiencyCommand)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Pure helpers for `velaro booking-defaults` (velaro-messaging BookingDefaults API). Kept free of I/O so
|
|
2
|
+
// node:test can pin the request bodies. The messaging PUT replaces the defaults row, so `set` always
|
|
3
|
+
// starts from the current values and only overrides the flags the caller named.
|
|
4
|
+
|
|
5
|
+
export const PROVIDERS = ['calendly', 'acuity', 'msbookings', 'outlook'];
|
|
6
|
+
export const MEETING_TYPES = ['phone', 'video', 'in_person', 'other'];
|
|
7
|
+
|
|
8
|
+
export function parseOnOff(value, flag) {
|
|
9
|
+
if (value === undefined || value === null) return undefined;
|
|
10
|
+
const v = String(value).toLowerCase();
|
|
11
|
+
if (v === 'on' || v === 'true') return true;
|
|
12
|
+
if (v === 'off' || v === 'false') return false;
|
|
13
|
+
throw new Error(`--${flag} must be on or off`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function clearable(value) {
|
|
17
|
+
if (value === undefined) return undefined;
|
|
18
|
+
return String(value).toLowerCase() === 'none' ? null : value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function buildDefaultsBody(current, argv) {
|
|
22
|
+
const d = current || {};
|
|
23
|
+
const body = {
|
|
24
|
+
defaultProviderSlug: d.defaultProviderSlug ?? null,
|
|
25
|
+
defaultPresetId: d.defaultPresetId ?? null,
|
|
26
|
+
defaultDurationMinutes: d.defaultDurationMinutes ?? null,
|
|
27
|
+
defaultMeetingType: d.defaultMeetingType ?? null,
|
|
28
|
+
defaultLocation: d.defaultLocation ?? null,
|
|
29
|
+
timeZoneId: d.timeZoneId ?? null,
|
|
30
|
+
prefillName: d.prefillName ?? true,
|
|
31
|
+
prefillEmail: d.prefillEmail ?? true,
|
|
32
|
+
prefillPhone: d.prefillPhone ?? true,
|
|
33
|
+
confirmPrefilled: d.confirmPrefilled ?? true,
|
|
34
|
+
enabled: d.enabled ?? true
|
|
35
|
+
};
|
|
36
|
+
const provider = clearable(argv.provider);
|
|
37
|
+
if (provider !== undefined) {
|
|
38
|
+
if (provider !== null && !PROVIDERS.includes(String(provider).toLowerCase())) throw new Error(`--provider must be one of ${PROVIDERS.join(', ')} or none`);
|
|
39
|
+
body.defaultProviderSlug = provider === null ? null : String(provider).toLowerCase();
|
|
40
|
+
}
|
|
41
|
+
const preset = clearable(argv.preset);
|
|
42
|
+
if (preset !== undefined) {
|
|
43
|
+
if (preset !== null && !Number.isInteger(Number(preset))) throw new Error('--preset must be a preset id or none');
|
|
44
|
+
body.defaultPresetId = preset === null ? null : Number(preset);
|
|
45
|
+
}
|
|
46
|
+
const duration = clearable(argv.duration);
|
|
47
|
+
if (duration !== undefined) {
|
|
48
|
+
if (duration !== null && !(Number(duration) >= 5 && Number(duration) <= 480)) throw new Error('--duration must be 5 to 480 minutes or none');
|
|
49
|
+
body.defaultDurationMinutes = duration === null ? null : Number(duration);
|
|
50
|
+
}
|
|
51
|
+
const meeting = clearable(argv.meetingType);
|
|
52
|
+
if (meeting !== undefined) {
|
|
53
|
+
if (meeting !== null && !MEETING_TYPES.includes(String(meeting).toLowerCase())) throw new Error(`--meeting-type must be one of ${MEETING_TYPES.join(', ')} or none`);
|
|
54
|
+
body.defaultMeetingType = meeting === null ? null : String(meeting).toLowerCase();
|
|
55
|
+
}
|
|
56
|
+
const location = clearable(argv.location);
|
|
57
|
+
if (location !== undefined) body.defaultLocation = location;
|
|
58
|
+
const tz = clearable(argv.timezone);
|
|
59
|
+
if (tz !== undefined) body.timeZoneId = tz;
|
|
60
|
+
for (const [flag, key] of [['prefill-name', 'prefillName'], ['prefill-email', 'prefillEmail'], ['prefill-phone', 'prefillPhone'], ['confirm-prefilled', 'confirmPrefilled'], ['enabled', 'enabled']]) {
|
|
61
|
+
const v = parseOnOff(argv[flag], flag);
|
|
62
|
+
if (v !== undefined) body[key] = v;
|
|
63
|
+
}
|
|
64
|
+
return body;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function buildPresetBody(argv) {
|
|
68
|
+
const provider = String(argv.provider || '').toLowerCase();
|
|
69
|
+
if (!argv.label || !String(argv.label).trim()) throw new Error('--label is required');
|
|
70
|
+
if (!PROVIDERS.includes(provider)) throw new Error(`--provider must be one of ${PROVIDERS.join(', ')}`);
|
|
71
|
+
if (provider !== 'outlook' && !argv.resource) throw new Error(`--resource is required for ${provider} (event type URI / appointment type id / service id)`);
|
|
72
|
+
if (argv.duration !== undefined && !(Number(argv.duration) >= 5 && Number(argv.duration) <= 480)) throw new Error('--duration must be 5 to 480 minutes');
|
|
73
|
+
if (argv.meetingType !== undefined && !MEETING_TYPES.includes(String(argv.meetingType).toLowerCase())) throw new Error(`--meeting-type must be one of ${MEETING_TYPES.join(', ')}`);
|
|
74
|
+
return {
|
|
75
|
+
label: String(argv.label).trim(),
|
|
76
|
+
description: argv.description ?? null,
|
|
77
|
+
providerSlug: provider,
|
|
78
|
+
providerResourceId: provider === 'outlook' ? '' : String(argv.resource).trim(),
|
|
79
|
+
durationMinutes: argv.duration === undefined ? null : Number(argv.duration),
|
|
80
|
+
meetingType: argv.meetingType === undefined ? null : String(argv.meetingType).toLowerCase(),
|
|
81
|
+
location: argv.location ?? null,
|
|
82
|
+
isActive: argv.hidden ? false : true
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Resolves `remove <idOrLabel>` against the listed presets. Numeric = id, otherwise case-insensitive label. */
|
|
87
|
+
export function findPreset(presets, idOrLabel) {
|
|
88
|
+
const list = Array.isArray(presets) ? presets : [];
|
|
89
|
+
const key = String(idOrLabel).trim();
|
|
90
|
+
const byId = /^\d+$/.test(key) ? list.find(p => p.id === Number(key)) : undefined;
|
|
91
|
+
const found = byId || list.find(p => String(p.label).toLowerCase() === key.toLowerCase());
|
|
92
|
+
if (!found) throw new Error(`No booking preset matches "${idOrLabel}"`);
|
|
93
|
+
return found;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function formatPresetLine(p) {
|
|
97
|
+
const bits = [p.providerSlug, p.durationMinutes ? `${p.durationMinutes} min` : null, p.meetingType, p.isActive ? null : 'hidden'].filter(Boolean);
|
|
98
|
+
return ` #${p.id} ${p.label} (${bits.join(', ')})`;
|
|
99
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { buildDefaultsBody, buildPresetBody, findPreset, parseOnOff } from './booking-defaults.js';
|
|
4
|
+
|
|
5
|
+
test('set keeps every value it was not asked to change', () => {
|
|
6
|
+
const current = { defaultProviderSlug: 'acuity', defaultPresetId: 4, defaultDurationMinutes: 30, defaultMeetingType: 'video', defaultLocation: 'Zoom', timeZoneId: 'America/Chicago', prefillName: true, prefillEmail: false, prefillPhone: true, confirmPrefilled: true, enabled: true };
|
|
7
|
+
const body = buildDefaultsBody(current, { duration: '45', 'prefill-email': 'on' });
|
|
8
|
+
assert.deepEqual(body, { ...current, defaultDurationMinutes: 45, prefillEmail: true });
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('none clears a value and unknown choices are rejected', () => {
|
|
12
|
+
const body = buildDefaultsBody({ defaultProviderSlug: 'calendly', defaultPresetId: 2 }, { provider: 'none', preset: 'none' });
|
|
13
|
+
assert.equal(body.defaultProviderSlug, null);
|
|
14
|
+
assert.equal(body.defaultPresetId, null);
|
|
15
|
+
assert.throws(() => buildDefaultsBody({}, { provider: 'zoom' }), /--provider must be one of/);
|
|
16
|
+
assert.throws(() => buildDefaultsBody({}, { duration: '2' }), /5 to 480/);
|
|
17
|
+
assert.throws(() => buildDefaultsBody({}, { 'prefill-name': 'maybe' }), /--prefill-name must be on or off/);
|
|
18
|
+
assert.equal(parseOnOff(undefined, 'x'), undefined);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('preset body requires a resource except for outlook', () => {
|
|
22
|
+
assert.throws(() => buildPresetBody({ label: 'Demo', provider: 'calendly' }), /--resource is required/);
|
|
23
|
+
assert.deepEqual(buildPresetBody({ label: ' Demo 30 min ', provider: 'Calendly', resource: 'https://api.calendly.com/event_types/X', duration: 30, meetingType: 'video' }), {
|
|
24
|
+
label: 'Demo 30 min', description: null, providerSlug: 'calendly', providerResourceId: 'https://api.calendly.com/event_types/X', durationMinutes: 30, meetingType: 'video', location: null, isActive: true
|
|
25
|
+
});
|
|
26
|
+
const outlook = buildPresetBody({ label: 'Call', provider: 'outlook', resource: 'ignored', hidden: true });
|
|
27
|
+
assert.equal(outlook.providerResourceId, '');
|
|
28
|
+
assert.equal(outlook.isActive, false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('findPreset resolves by id or case-insensitive label', () => {
|
|
32
|
+
const presets = [{ id: 7, label: 'Demo 30 min' }, { id: 8, label: 'Support 15' }];
|
|
33
|
+
assert.equal(findPreset(presets, '8').label, 'Support 15');
|
|
34
|
+
assert.equal(findPreset(presets, 'demo 30 MIN').id, 7);
|
|
35
|
+
assert.throws(() => findPreset(presets, 'nope'), /No booking preset matches/);
|
|
36
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
|
|
2
|
+
import { runCommand } from '../run.js';
|
|
3
|
+
import { buildDefaultsBody, buildPresetBody, findPreset, formatPresetLine, PROVIDERS, MEETING_TYPES } from '../booking-defaults.js';
|
|
4
|
+
|
|
5
|
+
// ── velaro booking-defaults ───────────────────────────────────────────────────
|
|
6
|
+
// CLI surface for per-site booking defaults and booking presets ("Demo 30 min").
|
|
7
|
+
// Mirrors the booking_defaults_* MCP tools. Routes live in velaro-messaging at
|
|
8
|
+
// /BookingDefaults (BookingDefaultsController); the site always comes from the login.
|
|
9
|
+
|
|
10
|
+
export const bookingDefaultsCommand = {
|
|
11
|
+
command: 'booking-defaults <subcommand>',
|
|
12
|
+
describe: 'Booking defaults and booking choices (presets) offered on every channel',
|
|
13
|
+
builder: yargs => yargs
|
|
14
|
+
.command({
|
|
15
|
+
command: 'get',
|
|
16
|
+
describe: 'Show the booking defaults and presets',
|
|
17
|
+
handler: runCommand(async () => {
|
|
18
|
+
const data = await messagingGet('/BookingDefaults');
|
|
19
|
+
console.log(JSON.stringify(data, null, 2));
|
|
20
|
+
}),
|
|
21
|
+
})
|
|
22
|
+
.command({
|
|
23
|
+
command: 'set',
|
|
24
|
+
describe: 'Change booking defaults (only the flags you pass change; use none to clear a value)',
|
|
25
|
+
builder: y => y
|
|
26
|
+
.option('provider', { type: 'string', describe: `Default provider: ${PROVIDERS.join(' | ')} | none` })
|
|
27
|
+
.option('preset', { type: 'string', describe: 'Default preset id, or none' })
|
|
28
|
+
.option('duration', { type: 'string', describe: 'Default length in minutes (5-480), or none' })
|
|
29
|
+
.option('meeting-type', { type: 'string', describe: `Default meeting type: ${MEETING_TYPES.join(' | ')} | none` })
|
|
30
|
+
.option('location', { type: 'string', describe: 'Default location or link, or none' })
|
|
31
|
+
.option('timezone', { type: 'string', describe: 'Time zone id (America/Los_Angeles), or none for the site time zone' })
|
|
32
|
+
.option('prefill-name', { type: 'string', describe: 'on | off' })
|
|
33
|
+
.option('prefill-email', { type: 'string', describe: 'on | off' })
|
|
34
|
+
.option('prefill-phone', { type: 'string', describe: 'on | off' })
|
|
35
|
+
.option('confirm-prefilled', { type: 'string', describe: 'on | off: confirm pre-filled details with the customer' })
|
|
36
|
+
.option('enabled', { type: 'string', describe: 'on | off: use booking defaults at all' }),
|
|
37
|
+
handler: runCommand(async argv => {
|
|
38
|
+
const current = await messagingGet('/BookingDefaults');
|
|
39
|
+
const body = buildDefaultsBody(current?.defaults, argv);
|
|
40
|
+
const saved = await messagingPut('/BookingDefaults', body);
|
|
41
|
+
console.log('\n✓ Booking defaults saved');
|
|
42
|
+
console.log(JSON.stringify(saved?.defaults ?? body, null, 2));
|
|
43
|
+
}),
|
|
44
|
+
})
|
|
45
|
+
.command({
|
|
46
|
+
command: 'presets <action> [target]',
|
|
47
|
+
describe: 'List, add or remove booking presets (list | add | remove <id or label>)',
|
|
48
|
+
builder: y => y
|
|
49
|
+
.positional('action', { type: 'string', choices: ['list', 'add', 'remove'] })
|
|
50
|
+
.positional('target', { type: 'string', describe: 'Preset id or label (remove)' })
|
|
51
|
+
.option('label', { type: 'string', describe: 'add: name customers see, e.g. "Demo 30 min"' })
|
|
52
|
+
.option('provider', { type: 'string', describe: `add: ${PROVIDERS.join(' | ')}` })
|
|
53
|
+
.option('resource', { type: 'string', describe: 'add: Calendly event type URI / Acuity appointment type id / Microsoft Bookings service id' })
|
|
54
|
+
.option('duration', { type: 'number', describe: 'add: length in minutes (5-480)' })
|
|
55
|
+
.option('meeting-type', { type: 'string', describe: `add: ${MEETING_TYPES.join(' | ')}` })
|
|
56
|
+
.option('location', { type: 'string', describe: 'add: location or link' })
|
|
57
|
+
.option('description', { type: 'string', describe: 'add: short description' })
|
|
58
|
+
.option('hidden', { type: 'boolean', describe: 'add: create it hidden from customers' }),
|
|
59
|
+
handler: runCommand(async argv => {
|
|
60
|
+
if (argv.action === 'list') {
|
|
61
|
+
const data = await messagingGet('/BookingDefaults');
|
|
62
|
+
const presets = data?.presets ?? [];
|
|
63
|
+
if (!presets.length) { console.log('\nNo booking presets yet.\n'); return; }
|
|
64
|
+
console.log('');
|
|
65
|
+
for (const p of presets) console.log(formatPresetLine(p));
|
|
66
|
+
console.log('');
|
|
67
|
+
} else if (argv.action === 'add') {
|
|
68
|
+
const created = await messagingPost('/BookingDefaults/Presets', buildPresetBody(argv));
|
|
69
|
+
console.log(`\n✓ Added preset #${created?.id} "${created?.label}"\n`);
|
|
70
|
+
} else if (argv.action === 'remove') {
|
|
71
|
+
if (!argv.target) throw new Error('Pass the preset id or label to remove');
|
|
72
|
+
const data = await messagingGet('/BookingDefaults');
|
|
73
|
+
const preset = findPreset(data?.presets, argv.target);
|
|
74
|
+
await messagingDel(`/BookingDefaults/Presets/${preset.id}`);
|
|
75
|
+
console.log(`\n✓ Removed preset #${preset.id} "${preset.label}"\n`);
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
})
|
|
79
|
+
.demandCommand(1, 'Specify a subcommand: get | set | presets'),
|
|
80
|
+
handler: () => {},
|
|
81
|
+
};
|
package/package.json
CHANGED