@velaro/cli 1.4.241 → 1.4.243
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/booking.js +59 -7
- package/lib/commands/mcp-key.js +11 -1
- package/lib/commands/mcp-key.test.js +11 -0
- package/lib/commands/scheduler.js +205 -30
- package/package.json +1 -1
package/lib/commands/booking.js
CHANGED
|
@@ -13,7 +13,31 @@ import { runCommand } from '../run.js';
|
|
|
13
13
|
// Mirrors the booking_* MCP tools. SiteId always derives from the caller's
|
|
14
14
|
// JWT server-side -- never accepted as a CLI argument.
|
|
15
15
|
|
|
16
|
-
const RESOURCE_TYPES = ['Staff', 'Room', 'Equipment', 'Virtual'];
|
|
16
|
+
const RESOURCE_TYPES = ['Staff', 'Room', 'Equipment', 'Virtual', 'Table'];
|
|
17
|
+
const BOOKING_MODES = ['StaffSchedule', 'TableCapacity', 'SeatCapacity'];
|
|
18
|
+
|
|
19
|
+
// Booking modes (velaro-messaging docs/design/booking-modes.md section 4.5): every field is
|
|
20
|
+
// optional and sent only when supplied (apply-if-present on PUT).
|
|
21
|
+
function parseBySize(v) {
|
|
22
|
+
if (v == null) return undefined;
|
|
23
|
+
if (v === '') return '';
|
|
24
|
+
try { return JSON.parse(v); } catch { throw new Error('--turn-minutes-by-size must be JSON, e.g. {"1-2":60,"3-5":90,"6+":120}'); }
|
|
25
|
+
}
|
|
26
|
+
function resourceModeBody(argv) {
|
|
27
|
+
return { minParty: argv.minParty, maxParty: argv.maxParty, turnMinutes: argv.turnMinutes, combineGroup: argv.combineGroup };
|
|
28
|
+
}
|
|
29
|
+
function serviceModeBody(argv) {
|
|
30
|
+
return {
|
|
31
|
+
bookingMode: argv.bookingMode,
|
|
32
|
+
turnMinutes: argv.turnMinutes,
|
|
33
|
+
turnMinutesBySize: parseBySize(argv.turnMinutesBySize),
|
|
34
|
+
bufferBeforeMinutes: argv.bufferBefore,
|
|
35
|
+
bufferAfterMinutes: argv.bufferAfter,
|
|
36
|
+
allowTableCombining: argv.allowTableCombining,
|
|
37
|
+
minParty: argv.minParty,
|
|
38
|
+
maxParty: argv.maxParty,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
17
41
|
|
|
18
42
|
function fmtDate(d) { return d ? new Date(d).toISOString().replace('T', ' ').slice(0, 16) : '-'; }
|
|
19
43
|
function fmtTime(t) { return t == null ? '-' : String(t); }
|
|
@@ -59,7 +83,7 @@ export const bookingCommand = {
|
|
|
59
83
|
}
|
|
60
84
|
console.log('\nBookable Resources\n');
|
|
61
85
|
for (const r of resources) {
|
|
62
|
-
console.log(` id:${r.id} ${r.name} type:${RESOURCE_TYPES[r.resourceType] ?? r.resourceType} active:${r.isActive}`);
|
|
86
|
+
console.log(` id:${r.id} ${r.name} type:${RESOURCE_TYPES[r.resourceType] ?? r.resourceType} party:${r.minParty ?? '-'}-${r.maxParty ?? '-'} active:${r.isActive}`);
|
|
63
87
|
}
|
|
64
88
|
console.log('');
|
|
65
89
|
}),
|
|
@@ -79,12 +103,17 @@ export const bookingCommand = {
|
|
|
79
103
|
builder: y2 => y2
|
|
80
104
|
.option('name', { type: 'string', demandOption: true, describe: 'Resource name -- required' })
|
|
81
105
|
.option('type', { type: 'string', choices: RESOURCE_TYPES, describe: 'Resource type (Staff | Room | Equipment | Virtual, default Staff)' })
|
|
82
|
-
.option('active', { type: 'boolean', describe: 'Whether the resource is active (default true)' })
|
|
106
|
+
.option('active', { type: 'boolean', describe: 'Whether the resource is active (default true)' })
|
|
107
|
+
.option('min-party', { type: 'number', describe: 'Smallest party this table seats' })
|
|
108
|
+
.option('max-party', { type: 'number', describe: 'Largest party this table seats' })
|
|
109
|
+
.option('turn-minutes', { type: 'number', describe: 'Minutes a party occupies this table (overrides the service default)' })
|
|
110
|
+
.option('combine-group', { type: 'string', describe: 'Group name; tables in one group can be combined for larger parties' }),
|
|
83
111
|
handler: runCommand(async argv => {
|
|
84
112
|
const resource = await messagingPost('/BookableResources', {
|
|
85
113
|
name: argv.name,
|
|
86
114
|
resourceType: argv.type,
|
|
87
115
|
isActive: argv.active,
|
|
116
|
+
...resourceModeBody(argv),
|
|
88
117
|
});
|
|
89
118
|
console.log(`\n✓ Created resource id:${resource.id} "${resource.name}"\n`);
|
|
90
119
|
}),
|
|
@@ -96,12 +125,17 @@ export const bookingCommand = {
|
|
|
96
125
|
.positional('id', { type: 'number', describe: 'Resource id' })
|
|
97
126
|
.option('name', { type: 'string', describe: 'New name' })
|
|
98
127
|
.option('type', { type: 'string', choices: RESOURCE_TYPES, describe: 'New resource type' })
|
|
99
|
-
.option('active', { type: 'boolean', describe: 'New active state' })
|
|
128
|
+
.option('active', { type: 'boolean', describe: 'New active state' })
|
|
129
|
+
.option('min-party', { type: 'number', describe: 'Smallest party this table seats' })
|
|
130
|
+
.option('max-party', { type: 'number', describe: 'Largest party this table seats' })
|
|
131
|
+
.option('turn-minutes', { type: 'number', describe: 'Minutes a party occupies this table (overrides the service default)' })
|
|
132
|
+
.option('combine-group', { type: 'string', describe: 'Group name; tables in one group can be combined for larger parties' }),
|
|
100
133
|
handler: runCommand(async argv => {
|
|
101
134
|
const resource = await messagingPut(`/BookableResources/${argv.id}`, {
|
|
102
135
|
name: argv.name,
|
|
103
136
|
resourceType: argv.type,
|
|
104
137
|
isActive: argv.active,
|
|
138
|
+
...resourceModeBody(argv),
|
|
105
139
|
});
|
|
106
140
|
console.log(`\n✓ Updated resource id:${resource.id} "${resource.name}"\n`);
|
|
107
141
|
}),
|
|
@@ -133,7 +167,7 @@ export const bookingCommand = {
|
|
|
133
167
|
}
|
|
134
168
|
console.log('\nBookable Services\n');
|
|
135
169
|
for (const s of services) {
|
|
136
|
-
console.log(` id:${s.id} ${s.name} ${s.durationMinutes}min capacity:${s.defaultCapacity} requiresResource:${s.requiresResource} category:${s.category ?? '-'} active:${s.isActive}`);
|
|
170
|
+
console.log(` id:${s.id} ${s.name} ${s.durationMinutes}min mode:${s.bookingMode ?? 'default'} capacity:${s.defaultCapacity} requiresResource:${s.requiresResource} category:${s.category ?? '-'} active:${s.isActive}`);
|
|
137
171
|
}
|
|
138
172
|
console.log('');
|
|
139
173
|
}),
|
|
@@ -156,9 +190,18 @@ export const bookingCommand = {
|
|
|
156
190
|
.option('capacity', { type: 'number', describe: 'Default seats per slot (default 1)' })
|
|
157
191
|
.option('requires-resource', { type: 'boolean', describe: 'Whether a slot must be tied to a specific resource (default true)' })
|
|
158
192
|
.option('category', { type: 'string', describe: 'Free-text grouping, e.g. "Hair" or "Fitness Classes"' })
|
|
159
|
-
.option('active', { type: 'boolean', describe: 'Whether the service is active (default true)' })
|
|
193
|
+
.option('active', { type: 'boolean', describe: 'Whether the service is active (default true)' })
|
|
194
|
+
.option('booking-mode', { type: 'string', choices: BOOKING_MODES, describe: 'StaffSchedule | TableCapacity | SeatCapacity' })
|
|
195
|
+
.option('turn-minutes', { type: 'number', describe: 'Default minutes a party occupies a table' })
|
|
196
|
+
.option('turn-minutes-by-size', { type: 'string', describe: 'JSON turn time by party size, e.g. {"1-2":60,"3-5":90,"6+":120} (pass "" to clear on update)' })
|
|
197
|
+
.option('buffer-before', { type: 'number', describe: 'Minutes held free before each booking' })
|
|
198
|
+
.option('buffer-after', { type: 'number', describe: 'Minutes held free after each booking' })
|
|
199
|
+
.option('allow-table-combining', { type: 'boolean', describe: 'Allow combining tables in a combine group' })
|
|
200
|
+
.option('min-party', { type: 'number', describe: 'Smallest party accepted' })
|
|
201
|
+
.option('max-party', { type: 'number', describe: 'Largest party accepted' }),
|
|
160
202
|
handler: runCommand(async argv => {
|
|
161
203
|
const service = await messagingPost('/BookableServices', {
|
|
204
|
+
...serviceModeBody(argv),
|
|
162
205
|
name: argv.name,
|
|
163
206
|
durationMinutes: argv.duration,
|
|
164
207
|
defaultCapacity: argv.capacity,
|
|
@@ -179,9 +222,18 @@ export const bookingCommand = {
|
|
|
179
222
|
.option('capacity', { type: 'number', describe: 'New default seats per slot' })
|
|
180
223
|
.option('requires-resource', { type: 'boolean', describe: 'New requires-resource flag' })
|
|
181
224
|
.option('category', { type: 'string', describe: 'New category (pass "" to clear)' })
|
|
182
|
-
.option('active', { type: 'boolean', describe: 'New active state' })
|
|
225
|
+
.option('active', { type: 'boolean', describe: 'New active state' })
|
|
226
|
+
.option('booking-mode', { type: 'string', choices: BOOKING_MODES, describe: 'StaffSchedule | TableCapacity | SeatCapacity' })
|
|
227
|
+
.option('turn-minutes', { type: 'number', describe: 'Default minutes a party occupies a table' })
|
|
228
|
+
.option('turn-minutes-by-size', { type: 'string', describe: 'JSON turn time by party size, e.g. {"1-2":60,"3-5":90,"6+":120} (pass "" to clear on update)' })
|
|
229
|
+
.option('buffer-before', { type: 'number', describe: 'Minutes held free before each booking' })
|
|
230
|
+
.option('buffer-after', { type: 'number', describe: 'Minutes held free after each booking' })
|
|
231
|
+
.option('allow-table-combining', { type: 'boolean', describe: 'Allow combining tables in a combine group' })
|
|
232
|
+
.option('min-party', { type: 'number', describe: 'Smallest party accepted' })
|
|
233
|
+
.option('max-party', { type: 'number', describe: 'Largest party accepted' }),
|
|
183
234
|
handler: runCommand(async argv => {
|
|
184
235
|
const service = await messagingPut(`/BookableServices/${argv.id}`, {
|
|
236
|
+
...serviceModeBody(argv),
|
|
185
237
|
name: argv.name,
|
|
186
238
|
durationMinutes: argv.duration,
|
|
187
239
|
defaultCapacity: argv.capacity,
|
package/lib/commands/mcp-key.js
CHANGED
|
@@ -6,6 +6,16 @@ import { getActiveEnv, ENVS } from '../config.js';
|
|
|
6
6
|
import { runCommand } from '../run.js';
|
|
7
7
|
import { confirmDestructive } from '../confirm.js';
|
|
8
8
|
|
|
9
|
+
// Scopes the server grants on key creation (McpApiKeysController.GrantableScopes).
|
|
10
|
+
export const GRANTABLE_SCOPES = ['admin'];
|
|
11
|
+
|
|
12
|
+
export function parseScopes(value) {
|
|
13
|
+
const scopes = String(value).split(',').map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
14
|
+
const bad = scopes.filter((s) => !GRANTABLE_SCOPES.includes(s));
|
|
15
|
+
if (bad.length) throw new Error(`Unknown scope: ${bad.join(', ')}. Allowed scopes: ${GRANTABLE_SCOPES.join(', ')}.`);
|
|
16
|
+
return [...new Set(scopes)];
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
// The API returns { keys, monthlyLimit }; older deployments returned an array.
|
|
10
20
|
// Fail on any other shape so a contract change cannot appear as an empty list.
|
|
11
21
|
export function normalizeMcpKeysResponse(response) {
|
|
@@ -76,7 +86,7 @@ const mcpKeyCreateCommand = {
|
|
|
76
86
|
if (when.getTime() <= Date.now()) throw new Error(`--expires "${argv.expires}" is in the past. Choose a future date.`);
|
|
77
87
|
payload.expiresAt = when.toISOString();
|
|
78
88
|
}
|
|
79
|
-
if (argv.scopes) payload.scopes =
|
|
89
|
+
if (argv.scopes) payload.scopes = parseScopes(argv.scopes);
|
|
80
90
|
|
|
81
91
|
const result = await post('/McpApiKeys', payload);
|
|
82
92
|
console.log(`MCP key created: ${result.label}`);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { parseScopes, GRANTABLE_SCOPES } from './mcp-key.js';
|
|
4
|
+
|
|
5
|
+
test('parseScopes accepts admin, trims, lowercases and de-duplicates', () => {
|
|
6
|
+
assert.deepEqual(parseScopes(' Admin , admin '), ['admin']);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('parseScopes rejects an unknown scope with the allowed list', () => {
|
|
10
|
+
assert.throws(() => parseScopes('admin,root'), (e) => /Unknown scope: root/.test(e.message) && e.message.includes(GRANTABLE_SCOPES.join(', ')));
|
|
11
|
+
});
|
|
@@ -1,30 +1,205 @@
|
|
|
1
|
-
import { messagingGet, messagingPost } from '../api.js';
|
|
2
|
-
import { runCommand } from '../run.js';
|
|
3
|
-
|
|
4
|
-
// velaro scheduler
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
|
|
2
|
+
import { runCommand } from '../run.js';
|
|
3
|
+
|
|
4
|
+
// -- velaro scheduler ------------------------------------------------------------
|
|
5
|
+
// Intake questions per bookable service and time off / special hours (date
|
|
6
|
+
// overrides) for the Velaro scheduler. Backend (velaro-messaging):
|
|
7
|
+
// /BookableServiceIntakeQuestions and /BookingDateOverrides. SiteId always derives
|
|
8
|
+
// from the caller's JWT server-side, never a CLI argument. Mirrors the
|
|
9
|
+
// scheduler_intake_question_* and scheduler_date_override_* MCP tools and the
|
|
10
|
+
// Moshky tools in CopilotBookingTools.cs.
|
|
11
|
+
|
|
12
|
+
const QUESTION_TYPES = ['text', 'textarea', 'select', 'checkbox'];
|
|
13
|
+
|
|
14
|
+
// Only send options the caller actually passed, so a PUT stays partial.
|
|
15
|
+
function pick(obj) {
|
|
16
|
+
const out = {};
|
|
17
|
+
for (const [k, v] of Object.entries(obj)) if (v !== undefined) out[k] = v;
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
function csv(v) { return v === undefined ? undefined : String(v).split(',').map(s => s.trim()).filter(Boolean); }
|
|
21
|
+
|
|
22
|
+
export const schedulerCommand = {
|
|
23
|
+
command: 'scheduler <subcommand>',
|
|
24
|
+
describe: 'Velaro scheduler -- booking calendar choice, intake questions and time off',
|
|
25
|
+
builder: yargs => yargs
|
|
26
|
+
.command({
|
|
27
|
+
command: 'intake <action>',
|
|
28
|
+
describe: 'Manage the intake questions customers answer when booking a service',
|
|
29
|
+
builder: y => y
|
|
30
|
+
.command({
|
|
31
|
+
command: 'list',
|
|
32
|
+
describe: 'List intake questions, optionally for one service',
|
|
33
|
+
builder: y2 => y2.option('service', { type: 'number', describe: 'Service id' }),
|
|
34
|
+
handler: runCommand(async argv => {
|
|
35
|
+
const qs = argv.service != null ? `?serviceId=${argv.service}` : '';
|
|
36
|
+
const rows = await messagingGet(`/BookableServiceIntakeQuestions${qs}`);
|
|
37
|
+
if (!Array.isArray(rows) || !rows.length) { console.log('\n No intake questions found.\n'); return; }
|
|
38
|
+
console.log('\nIntake Questions\n');
|
|
39
|
+
for (const q of rows) console.log(` id:${q.id} service:${q.bookableServiceId} [${q.questionType}]${q.isRequired ? ' required' : ''}${q.isActive === false ? ' (inactive)' : ''} ${q.label}`);
|
|
40
|
+
console.log('');
|
|
41
|
+
}),
|
|
42
|
+
})
|
|
43
|
+
.command({
|
|
44
|
+
command: 'get <id>',
|
|
45
|
+
describe: 'Get one intake question',
|
|
46
|
+
builder: y2 => y2.positional('id', { type: 'number' }),
|
|
47
|
+
handler: runCommand(async argv => {
|
|
48
|
+
console.log(JSON.stringify(await messagingGet(`/BookableServiceIntakeQuestions/${argv.id}`), null, 2));
|
|
49
|
+
}),
|
|
50
|
+
})
|
|
51
|
+
.command({
|
|
52
|
+
command: 'create',
|
|
53
|
+
describe: 'Add an intake question to a service',
|
|
54
|
+
builder: y2 => y2
|
|
55
|
+
.option('service', { type: 'number', demandOption: true, describe: 'Service id' })
|
|
56
|
+
.option('label', { type: 'string', demandOption: true, describe: 'Question text' })
|
|
57
|
+
.option('type', { type: 'string', choices: QUESTION_TYPES, demandOption: true })
|
|
58
|
+
.option('options', { type: 'string', describe: 'Comma-separated choices (select only)' })
|
|
59
|
+
.option('required', { type: 'boolean', describe: 'Customer must answer' })
|
|
60
|
+
.option('sort-order', { type: 'number' })
|
|
61
|
+
.option('active', { type: 'boolean' }),
|
|
62
|
+
handler: runCommand(async argv => {
|
|
63
|
+
const q = await messagingPost('/BookableServiceIntakeQuestions', pick({
|
|
64
|
+
bookableServiceId: argv.service, label: argv.label, questionType: argv.type,
|
|
65
|
+
options: csv(argv.options), isRequired: argv.required, sortOrder: argv.sortOrder, isActive: argv.active,
|
|
66
|
+
}));
|
|
67
|
+
console.log(`\n✓ Created intake question id:${q.id}\n`);
|
|
68
|
+
}),
|
|
69
|
+
})
|
|
70
|
+
.command({
|
|
71
|
+
command: 'update <id>',
|
|
72
|
+
describe: 'Update an intake question -- only supplied fields change',
|
|
73
|
+
builder: y2 => y2
|
|
74
|
+
.positional('id', { type: 'number' })
|
|
75
|
+
.option('label', { type: 'string' })
|
|
76
|
+
.option('type', { type: 'string', choices: QUESTION_TYPES })
|
|
77
|
+
.option('options', { type: 'string', describe: 'Comma-separated choices (select only)' })
|
|
78
|
+
.option('required', { type: 'boolean' })
|
|
79
|
+
.option('sort-order', { type: 'number' })
|
|
80
|
+
.option('active', { type: 'boolean' }),
|
|
81
|
+
handler: runCommand(async argv => {
|
|
82
|
+
await messagingPut(`/BookableServiceIntakeQuestions/${argv.id}`, pick({
|
|
83
|
+
label: argv.label, questionType: argv.type, options: csv(argv.options),
|
|
84
|
+
isRequired: argv.required, sortOrder: argv.sortOrder, isActive: argv.active,
|
|
85
|
+
}));
|
|
86
|
+
console.log(`\n✓ Updated intake question id:${argv.id}\n`);
|
|
87
|
+
}),
|
|
88
|
+
})
|
|
89
|
+
.command({
|
|
90
|
+
command: 'delete <id>',
|
|
91
|
+
describe: 'Delete an intake question',
|
|
92
|
+
builder: y2 => y2.positional('id', { type: 'number' }),
|
|
93
|
+
handler: runCommand(async argv => {
|
|
94
|
+
await messagingDel(`/BookableServiceIntakeQuestions/${argv.id}`);
|
|
95
|
+
console.log(`\n✓ Deleted intake question id:${argv.id}\n`);
|
|
96
|
+
}),
|
|
97
|
+
})
|
|
98
|
+
.demandCommand(1, 'Specify an intake action: list | get | create | update | delete'),
|
|
99
|
+
})
|
|
100
|
+
.command({
|
|
101
|
+
command: 'time-off <action>',
|
|
102
|
+
describe: 'Manage time off and special hours (date overrides)',
|
|
103
|
+
builder: y => y
|
|
104
|
+
.command({
|
|
105
|
+
command: 'list',
|
|
106
|
+
describe: 'List time off / special hours, optionally for one resource or from a date',
|
|
107
|
+
builder: y2 => y2
|
|
108
|
+
.option('resource', { type: 'number', describe: 'Resource id' })
|
|
109
|
+
.option('from', { type: 'string', describe: 'From date, yyyy-MM-dd' }),
|
|
110
|
+
handler: runCommand(async argv => {
|
|
111
|
+
const q = new URLSearchParams();
|
|
112
|
+
if (argv.resource != null) q.set('resourceId', String(argv.resource));
|
|
113
|
+
if (argv.from) q.set('fromDate', argv.from);
|
|
114
|
+
const rows = await messagingGet(`/BookingDateOverrides${q.toString() ? '?' + q : ''}`);
|
|
115
|
+
if (!Array.isArray(rows) || !rows.length) { console.log('\n No time off or special hours found.\n'); return; }
|
|
116
|
+
console.log('\nTime Off and Special Hours\n');
|
|
117
|
+
for (const o of rows) {
|
|
118
|
+
const what = o.isClosed ? 'closed' : `${o.startLocal || '-'}-${o.endLocal || '-'}`;
|
|
119
|
+
console.log(` id:${o.id} ${o.startDate}..${o.endDate} ${what} ${o.resourceId == null ? 'whole business' : 'resource:' + o.resourceId}${o.reason ? ' ' + o.reason : ''}`);
|
|
120
|
+
}
|
|
121
|
+
console.log('');
|
|
122
|
+
}),
|
|
123
|
+
})
|
|
124
|
+
.command({
|
|
125
|
+
command: 'get <id>',
|
|
126
|
+
describe: 'Get one time off entry',
|
|
127
|
+
builder: y2 => y2.positional('id', { type: 'number' }),
|
|
128
|
+
handler: runCommand(async argv => {
|
|
129
|
+
console.log(JSON.stringify(await messagingGet(`/BookingDateOverrides/${argv.id}`), null, 2));
|
|
130
|
+
}),
|
|
131
|
+
})
|
|
132
|
+
.command({
|
|
133
|
+
command: 'create',
|
|
134
|
+
describe: 'Add time off (default) or custom hours for a date range',
|
|
135
|
+
builder: y2 => y2
|
|
136
|
+
.option('start', { type: 'string', demandOption: true, describe: 'Start date, yyyy-MM-dd' })
|
|
137
|
+
.option('end', { type: 'string', demandOption: true, describe: 'End date, yyyy-MM-dd (inclusive)' })
|
|
138
|
+
.option('resource', { type: 'number', describe: 'Resource id (omit for the whole business)' })
|
|
139
|
+
.option('open-from', { type: 'string', describe: 'Custom hours start HH:mm (makes it special hours, not time off)' })
|
|
140
|
+
.option('open-to', { type: 'string', describe: 'Custom hours end HH:mm' })
|
|
141
|
+
.option('reason', { type: 'string' })
|
|
142
|
+
.option('timezone', { type: 'string', describe: 'IANA timezone id' })
|
|
143
|
+
.option('active', { type: 'boolean' }),
|
|
144
|
+
handler: runCommand(async argv => {
|
|
145
|
+
const custom = argv.openFrom != null || argv.openTo != null;
|
|
146
|
+
const o = await messagingPost('/BookingDateOverrides', pick({
|
|
147
|
+
resourceId: argv.resource, startDate: argv.start, endDate: argv.end, isClosed: !custom,
|
|
148
|
+
startLocal: argv.openFrom, endLocal: argv.openTo, reason: argv.reason, ianaTimeZone: argv.timezone, isActive: argv.active,
|
|
149
|
+
}));
|
|
150
|
+
console.log(`\n✓ Created ${custom ? 'special hours' : 'time off'} id:${o.id}\n`);
|
|
151
|
+
}),
|
|
152
|
+
})
|
|
153
|
+
.command({
|
|
154
|
+
command: 'update <id>',
|
|
155
|
+
describe: 'Update a time off entry -- only supplied fields change',
|
|
156
|
+
builder: y2 => y2
|
|
157
|
+
.positional('id', { type: 'number' })
|
|
158
|
+
.option('start', { type: 'string' })
|
|
159
|
+
.option('end', { type: 'string' })
|
|
160
|
+
.option('resource', { type: 'number' })
|
|
161
|
+
.option('closed', { type: 'boolean', describe: 'true = time off, false = custom hours' })
|
|
162
|
+
.option('open-from', { type: 'string' })
|
|
163
|
+
.option('open-to', { type: 'string' })
|
|
164
|
+
.option('reason', { type: 'string' })
|
|
165
|
+
.option('timezone', { type: 'string' })
|
|
166
|
+
.option('active', { type: 'boolean' }),
|
|
167
|
+
handler: runCommand(async argv => {
|
|
168
|
+
await messagingPut(`/BookingDateOverrides/${argv.id}`, pick({
|
|
169
|
+
resourceId: argv.resource, startDate: argv.start, endDate: argv.end, isClosed: argv.closed,
|
|
170
|
+
startLocal: argv.openFrom, endLocal: argv.openTo, reason: argv.reason, ianaTimeZone: argv.timezone, isActive: argv.active,
|
|
171
|
+
}));
|
|
172
|
+
console.log(`\n✓ Updated time off id:${argv.id}\n`);
|
|
173
|
+
}),
|
|
174
|
+
})
|
|
175
|
+
.command({
|
|
176
|
+
command: 'delete <id>',
|
|
177
|
+
describe: 'Delete a time off entry',
|
|
178
|
+
builder: y2 => y2.positional('id', { type: 'number' }),
|
|
179
|
+
handler: runCommand(async argv => {
|
|
180
|
+
await messagingDel(`/BookingDateOverrides/${argv.id}`);
|
|
181
|
+
console.log(`\n✓ Deleted time off id:${argv.id}\n`);
|
|
182
|
+
}),
|
|
183
|
+
})
|
|
184
|
+
.demandCommand(1, 'Specify a time-off action: list | get | create | update | delete'),
|
|
185
|
+
})
|
|
186
|
+
.command({
|
|
187
|
+
command: 'get',
|
|
188
|
+
describe: 'Show which scheduler receives new bookings',
|
|
189
|
+
handler: runCommand(async () => {
|
|
190
|
+
const r = await messagingGet('/Appointments/Settings');
|
|
191
|
+
console.log(`\nNew bookings go to: ${r?.writeTargetSlug || 'Velaro (first connected calendar)'}\n`);
|
|
192
|
+
}),
|
|
193
|
+
})
|
|
194
|
+
.command({
|
|
195
|
+
command: 'set <slug>',
|
|
196
|
+
describe: 'Choose the scheduler (GoogleCalendar | OutlookCalendar | MicrosoftBookings | Calendly | Acuity | CalCom | none for Velaro)',
|
|
197
|
+
builder: y => y.positional('slug', { describe: 'Provider slug, or "none"', type: 'string' }),
|
|
198
|
+
handler: runCommand(async (argv) => {
|
|
199
|
+
const slug = argv.slug.toLowerCase() === 'none' ? null : argv.slug;
|
|
200
|
+
await messagingPost('/Appointments/Settings', { writeTargetSlug: slug });
|
|
201
|
+
console.log(`\n✓ New bookings now go to ${slug ?? 'Velaro (first connected calendar)'}.\n`);
|
|
202
|
+
}),
|
|
203
|
+
})
|
|
204
|
+
.demandCommand(1, 'Specify a subcommand: get | set | intake | time-off'),
|
|
205
|
+
};
|
package/package.json
CHANGED