@velaro/cli 1.4.221 → 1.4.223
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
CHANGED
|
@@ -358,6 +358,17 @@ export const bookingCommand = {
|
|
|
358
358
|
console.log(JSON.stringify(booking, null, 2));
|
|
359
359
|
}),
|
|
360
360
|
})
|
|
361
|
+
.command({
|
|
362
|
+
command: 'reschedule <id> <new-slot-id>',
|
|
363
|
+
describe: 'Move a booking to another open slot (staff-initiated)',
|
|
364
|
+
builder: y2 => y2
|
|
365
|
+
.positional('id', { type: 'number', describe: 'Booking id' })
|
|
366
|
+
.positional('new-slot-id', { type: 'number', describe: 'Target booking slot id' }),
|
|
367
|
+
handler: runCommand(async argv => {
|
|
368
|
+
const result = await messagingPost(`/Bookings/${argv.id}/reschedule`, { newSlotId: argv.newSlotId });
|
|
369
|
+
console.log(`\n✓ Rescheduled booking id:${result.bookingId} to slot ${result.slotId} (status: ${result.status})\n`);
|
|
370
|
+
}),
|
|
371
|
+
})
|
|
361
372
|
.command({
|
|
362
373
|
command: 'cancel <id>',
|
|
363
374
|
describe: 'Cancel a booking (staff-initiated)',
|
|
@@ -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)
|
|
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
|
-
|
|
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
|
+
});
|
package/package.json
CHANGED