@velaro/cli 1.4.225 → 1.4.227

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 CHANGED
@@ -41,6 +41,7 @@ import { copilotStudioCommand } from '../lib/commands/copilotstudio.js';
41
41
  import { applePayPresetCommand } from '../lib/commands/apple-pay-preset.js';
42
42
  import { integrationCommand } from '../lib/commands/integration.js';
43
43
  import { appointmentsCommand } from '../lib/commands/appointments.js';
44
+ import { schedulerCommand } from '../lib/commands/scheduler.js';
44
45
  import { publicApiCommand } from '../lib/commands/public-api.js';
45
46
  import { bookingDefaultsCommand } from '../lib/commands/booking-defaults.js';
46
47
  import { bookingCommand } from '../lib/commands/booking.js';
@@ -216,6 +217,7 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
216
217
  .command(applePayPresetCommand)
217
218
  .command(integrationCommand)
218
219
  .command(appointmentsCommand)
220
+ .command(schedulerCommand)
219
221
  .command(publicApiCommand)
220
222
  .command(bookingDefaultsCommand)
221
223
  .command(bookingCommand)
@@ -194,5 +194,27 @@ export const appointmentsCommand = {
194
194
  console.log(`\n✓ Appointment ${argv.appointmentId} status set to ${statusLabel(result.status)}.\n`);
195
195
  }),
196
196
  })
197
- .demandCommand(1, 'Specify a subcommand: list-slots | book | manage | install-template | manual-book | list-appointments | set-status'),
197
+ .command({
198
+ command: 'get-scheduler',
199
+ describe: 'Show which scheduler receives new bookings',
200
+ handler: runCommand(async () => {
201
+ const r = await messagingGet('/Appointments/Settings');
202
+ console.log(`
203
+ New bookings go to: ${r?.writeTargetSlug || 'Velaro (first connected calendar)'}
204
+ `);
205
+ }),
206
+ })
207
+ .command({
208
+ command: 'set-scheduler <slug>',
209
+ describe: 'Choose the scheduler for new bookings (GoogleCalendar | OutlookCalendar | MicrosoftBookings | Calendly | Acuity | CalCom | none for Velaro)',
210
+ builder: y => y.positional('slug', { describe: 'Provider slug, or "none"', type: 'string' }),
211
+ handler: runCommand(async (argv) => {
212
+ const slug = argv.slug.toLowerCase() === 'none' ? null : argv.slug;
213
+ await messagingPost('/Appointments/Settings', { writeTargetSlug: slug });
214
+ console.log(`
215
+ ✓ New bookings now go to ${slug ?? 'Velaro (first connected calendar)'}.
216
+ `);
217
+ }),
218
+ })
219
+ .demandCommand(1, 'Specify a subcommand: list-slots | book | manage | install-template | manual-book | list-appointments | set-status | get-scheduler | set-scheduler'),
198
220
  };
@@ -186,27 +186,102 @@ export const crmBulkCommand = {
186
186
 
187
187
  // ---------------------------------------------------------------- web forms
188
188
 
189
+ // Pure helpers (unit tested in crm-webform.test.js).
190
+
191
+ /** The lines that describe one web form: link and embed snippet when it is online, plus the saved settings. */
192
+ export function webformLines(f) {
193
+ const lines = [];
194
+ lines.push(` Layout #${f?.layoutId} ${f?.entity} ${f?.enabled === false ? 'offline' : 'live'} ${f?.questionCount ?? 0} questions`);
195
+ if (f?.url) lines.push(` Hosted link: ${f.url}`);
196
+ else lines.push(` Page path: ${f?.path ?? ''}${f?.enabled === false ? ' (offline, no link)' : ''}`);
197
+ if (f?.embedSnippet) lines.push(` Embed snippet: ${f.embedSnippet}`);
198
+ const st = f?.settings;
199
+ if (st && (st.successMessage || st.redirectUrl)) {
200
+ if (st.successMessage) lines.push(` Success message: ${st.successMessage}`);
201
+ if (st.redirectUrl) lines.push(` Redirect: ${st.redirectUrl}`);
202
+ }
203
+ return lines;
204
+ }
205
+
206
+ /**
207
+ * The body for PUT /CrmWebForms/{layoutId}/settings. The server replaces both fields, so an option that was not passed keeps
208
+ * the stored value; --clear resets both to the defaults.
209
+ */
210
+ export function webformSettingsBody(argv, current) {
211
+ if (argv.clear) {
212
+ if (argv.message !== undefined || argv.redirect !== undefined) throw new Error('[CRM] --clear cannot be combined with --message or --redirect.');
213
+ return { successMessage: '', redirectUrl: '' };
214
+ }
215
+ if (argv.message === undefined && argv.redirect === undefined) {
216
+ throw new Error('[CRM] Pass --message, --redirect or --clear.');
217
+ }
218
+ return {
219
+ successMessage: argv.message !== undefined ? String(argv.message) : (current?.successMessage ?? ''),
220
+ redirectUrl: argv.redirect !== undefined ? String(argv.redirect).trim() : (current?.redirectUrl ?? ''),
221
+ };
222
+ }
223
+
224
+ /** The query path for GET /CrmWebForms/{layoutId}/submissions; the server caps the page size at 100. */
225
+ export function webformSubmissionsPath(layoutId, page, pageSize) {
226
+ const p = Number.isInteger(page) && page >= 1 ? page : 1;
227
+ const n = Number.isInteger(pageSize) && pageSize >= 1 ? Math.min(pageSize, 100) : 25;
228
+ return `/CrmWebForms/${encodeURIComponent(layoutId)}/submissions?page=${p}&pageSize=${n}`;
229
+ }
230
+
189
231
  async function webformListHandler(argv) {
190
232
  const list = data(await messagingGet('/CrmWebForms'));
191
233
  if (argv.json) return printJson(list);
192
234
  const rows = Array.isArray(list) ? list : [];
193
235
  console.log(`\n${BOLD}Published web forms${RST} (${rows.length})`);
194
- for (const f of rows) console.log(` layout #${f.layoutId} ${f.entity} ${DIM}${f.path}${f.enabled ? '' : ' (offline)'}${RST}`);
236
+ for (const f of rows) {
237
+ console.log(` layout #${f.layoutId} ${f.entity} ${DIM}${f.path}${f.enabled ? '' : ' (offline)'}${RST}`);
238
+ if (f.url) console.log(` ${DIM}link ${f.url}${RST}`);
239
+ if (f.embedSnippet) console.log(` ${DIM}embed ${f.embedSnippet}${RST}`);
240
+ }
195
241
  console.log('');
196
242
  }
197
243
 
198
244
  async function webformGetHandler(argv) {
199
- printJson(data(await messagingGet(`/CrmWebForms/${argv.layoutId}`)));
245
+ const r = data(await messagingGet(`/CrmWebForms/${argv.layoutId}`));
246
+ if (argv.json) return printJson(r);
247
+ console.log(`\n${BOLD}Web form${RST}`);
248
+ for (const line of webformLines(r)) console.log(line);
249
+ console.log('');
200
250
  }
201
251
 
202
252
  async function webformPublishHandler(argv) {
203
253
  const r = data(await messagingPost(`/CrmWebForms/${argv.layoutId}/publish`, {}));
204
254
  if (argv.json) return printJson(r);
205
255
  console.log(`\n Web form ${r?.republished ? 'updated' : 'published'}: ${r?.path} (${r?.questionCount} questions).`);
256
+ if (r?.url) console.log(` Hosted link: ${r.url}`);
257
+ if (r?.embedSnippet) console.log(` Embed snippet: ${r.embedSnippet}`);
206
258
  for (const s of r?.skipped ?? []) console.log(` Left out ${s.ref}: ${s.reason}`);
207
259
  console.log('');
208
260
  }
209
261
 
262
+ async function webformSettingsHandler(argv) {
263
+ const current = argv.clear ? null : data(await messagingGet(`/CrmWebForms/${argv.layoutId}`))?.settings;
264
+ const body = webformSettingsBody(argv, current);
265
+ const r = data(await messagingPut(`/CrmWebForms/${argv.layoutId}/settings`, body));
266
+ if (argv.json) return printJson(r);
267
+ console.log(`\n Web form settings saved for layout ${argv.layoutId}.`);
268
+ console.log(` Success message: ${r?.successMessage || '(standard thank you)'}`);
269
+ console.log(` Redirect: ${r?.redirectUrl || '(none)'}`);
270
+ console.log('');
271
+ }
272
+
273
+ async function webformSubmissionsHandler(argv) {
274
+ const r = data(await messagingGet(webformSubmissionsPath(argv.layoutId, argv.page, argv.pageSize)));
275
+ if (argv.json) return printJson(r);
276
+ const items = r?.items ?? [];
277
+ console.log(`\n${BOLD}Web form submissions${RST} (page ${r?.page ?? 1}, ${items.length} of ${r?.total ?? items.length}, newest first)`);
278
+ for (const it of items) {
279
+ console.log(` #${it.id} ${it.submittedAt}`);
280
+ for (const a of it.answers ?? []) console.log(` ${DIM}${a.question}${RST} ${a.answer}`);
281
+ }
282
+ console.log('');
283
+ }
284
+
210
285
  async function webformUnpublishHandler(argv) {
211
286
  await messagingDel(`/CrmWebForms/${argv.layoutId}/publish`);
212
287
  console.log(`\n Web form for layout ${argv.layoutId} is offline.\n`);
@@ -217,7 +292,24 @@ export const crmWebformCommand = {
217
292
  describe: 'CRM web forms: publish a form layout as a public form (Administrator)',
218
293
  builder: (y) => y
219
294
  .command({ command: 'list', describe: 'List published web forms', builder: (yy) => json(yy), handler: runCommand(webformListHandler) })
220
- .command({ command: 'get <layoutId>', describe: 'Show the web form published from a layout', handler: runCommand(webformGetHandler) })
295
+ .command({ command: 'get <layoutId>', describe: 'Show the web form published from a layout, with its hosted link and embed snippet', builder: (yy) => json(yy), handler: runCommand(webformGetHandler) })
296
+ .command({
297
+ command: 'settings <layoutId>',
298
+ describe: 'Set the success message and redirect address shown after a visitor submits (plain text message up to 500 characters; full http or https redirect). Unpassed options keep their value',
299
+ builder: (yy) => json(yy
300
+ .option('message', { type: 'string', describe: 'Success message, plain text; empty restores the standard thank you' })
301
+ .option('redirect', { type: 'string', describe: 'Full http or https address visitors are sent to; empty removes it' })
302
+ .option('clear', { type: 'boolean', default: false, describe: 'Reset both to the defaults' })),
303
+ handler: runCommand(webformSettingsHandler),
304
+ })
305
+ .command({
306
+ command: 'submissions <layoutId>',
307
+ describe: 'List what visitors submitted through the web form, newest first',
308
+ builder: (yy) => json(yy
309
+ .option('page', { type: 'number', default: 1 })
310
+ .option('page-size', { type: 'number', alias: 'pageSize', default: 25, describe: 'Rows per page, at most 100' })),
311
+ handler: runCommand(webformSubmissionsHandler),
312
+ })
221
313
  .command({ command: 'publish <layoutId>', describe: 'Publish a form layout as a web form, or update the published one', builder: (yy) => json(yy), handler: runCommand(webformPublishHandler) })
222
314
  .command({ command: 'unpublish <layoutId>', describe: 'Take a web form offline', handler: runCommand(webformUnpublishHandler) })
223
315
  .demandCommand(1),
@@ -0,0 +1,54 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { webformLines, webformSettingsBody, webformSubmissionsPath } from './crm-views-bulk-webforms.js';
4
+
5
+ const form = {
6
+ layoutId: 7,
7
+ entity: 'contact',
8
+ enabled: true,
9
+ questionCount: 4,
10
+ path: '/s/contact-form',
11
+ url: 'https://v20.velaro.com/s/contact-form',
12
+ embedSnippet: '<iframe src="https://v20.velaro.com/s/contact-form"></iframe>',
13
+ settings: { successMessage: 'Thanks', redirectUrl: 'https://example.com/thanks' },
14
+ };
15
+
16
+ test('webformLines prints the hosted link, the embed snippet and the settings', () => {
17
+ const text = webformLines(form).join('\n');
18
+ assert.match(text, /Hosted link:\s+https:\/\/v20\.velaro\.com\/s\/contact-form/);
19
+ assert.match(text, /Embed snippet:\s+<iframe/);
20
+ assert.match(text, /Success message: Thanks/);
21
+ assert.match(text, /Redirect:\s+https:\/\/example\.com\/thanks/);
22
+ });
23
+
24
+ test('webformLines for an offline form shows the path and no link or snippet', () => {
25
+ const text = webformLines({ ...form, enabled: false, url: null, embedSnippet: null }).join('\n');
26
+ assert.match(text, /offline/);
27
+ assert.doesNotMatch(text, /Hosted link|Embed snippet/);
28
+ });
29
+
30
+ test('settings body: unpassed options keep the stored value', () => {
31
+ const cur = { successMessage: 'Thanks', redirectUrl: 'https://example.com/a' };
32
+ assert.deepEqual(webformSettingsBody({ message: 'Hello' }, cur), { successMessage: 'Hello', redirectUrl: 'https://example.com/a' });
33
+ assert.deepEqual(webformSettingsBody({ redirect: ' https://example.com/b ' }, cur), { successMessage: 'Thanks', redirectUrl: 'https://example.com/b' });
34
+ });
35
+
36
+ test('settings body: an empty option clears just that field', () => {
37
+ const cur = { successMessage: 'Thanks', redirectUrl: 'https://example.com/a' };
38
+ assert.deepEqual(webformSettingsBody({ redirect: '' }, cur), { successMessage: 'Thanks', redirectUrl: '' });
39
+ });
40
+
41
+ test('settings body: --clear resets both and cannot be mixed', () => {
42
+ assert.deepEqual(webformSettingsBody({ clear: true }, null), { successMessage: '', redirectUrl: '' });
43
+ assert.throws(() => webformSettingsBody({ clear: true, message: 'x' }, null), /\[CRM\] --clear cannot be combined/);
44
+ });
45
+
46
+ test('settings body: passing nothing is a plain error', () => {
47
+ assert.throws(() => webformSettingsBody({}, null), /\[CRM\] Pass --message, --redirect or --clear/);
48
+ });
49
+
50
+ test('submissions path pages, caps the size at 100 and falls back on bad input', () => {
51
+ assert.equal(webformSubmissionsPath(7, 2, 50), '/CrmWebForms/7/submissions?page=2&pageSize=50');
52
+ assert.equal(webformSubmissionsPath(7, 1, 500), '/CrmWebForms/7/submissions?page=1&pageSize=100');
53
+ assert.equal(webformSubmissionsPath(7, 0, NaN), '/CrmWebForms/7/submissions?page=1&pageSize=25');
54
+ });
@@ -0,0 +1,30 @@
1
+ import { messagingGet, messagingPost } from '../api.js';
2
+ import { runCommand } from '../run.js';
3
+
4
+ // velaro scheduler get | set <slug>
5
+ // Mirrors the scheduler_selection_get / scheduler_selection_update MCP tools.
6
+ // Same endpoints as `velaro appointments get-scheduler|set-scheduler` (kept as aliases).
7
+ export const schedulerCommand = {
8
+ command: 'scheduler <subcommand>',
9
+ describe: 'Choose which calendar/scheduler receives new bookings',
10
+ builder: yargs => yargs
11
+ .command({
12
+ command: 'get',
13
+ describe: 'Show which scheduler receives new bookings',
14
+ handler: runCommand(async () => {
15
+ const r = await messagingGet('/Appointments/Settings');
16
+ console.log(`\nNew bookings go to: ${r?.writeTargetSlug || 'Velaro (first connected calendar)'}\n`);
17
+ }),
18
+ })
19
+ .command({
20
+ command: 'set <slug>',
21
+ describe: 'Choose the scheduler (GoogleCalendar | OutlookCalendar | MicrosoftBookings | Calendly | Acuity | CalCom | none for Velaro)',
22
+ builder: y => y.positional('slug', { describe: 'Provider slug, or "none"', type: 'string' }),
23
+ handler: runCommand(async (argv) => {
24
+ const slug = argv.slug.toLowerCase() === 'none' ? null : argv.slug;
25
+ await messagingPost('/Appointments/Settings', { writeTargetSlug: slug });
26
+ console.log(`\n✓ New bookings now go to ${slug ?? 'Velaro (first connected calendar)'}.\n`);
27
+ }),
28
+ })
29
+ .demandCommand(1, 'Specify a subcommand: get | set'),
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.225",
3
+ "version": "1.4.227",
4
4
  "description": "Velaro Workspace v20 — command-line interface for managing bots, knowledge base ingestion, MCP API keys, search indexes, and ops health.",
5
5
  "type": "module",
6
6
  "bin": {