@velaro/cli 1.4.179 → 1.4.180
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/commands/signup-form.js +110 -0
- package/package.json +1 -1
package/bin/velaro.js
CHANGED
|
@@ -101,6 +101,7 @@ import { statusNotifyCommand } from '../lib/commands/status-notify.js';
|
|
|
101
101
|
import { callbackCommand } from '../lib/commands/callback.js';
|
|
102
102
|
import { cobrowseCommand } from '../lib/commands/cobrowse.js';
|
|
103
103
|
import { callpresenceCommand } from '../lib/commands/callpresence.js';
|
|
104
|
+
import { signupFormCommand } from '../lib/commands/signup-form.js';
|
|
104
105
|
import { authorityCommand } from '../lib/commands/authority.js';
|
|
105
106
|
import { caseCommand } from '../lib/commands/case.js';
|
|
106
107
|
import { dealCommand } from '../lib/commands/deal.js';
|
|
@@ -263,6 +264,7 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
263
264
|
// The staff build already registers a cobrowse group that includes seats/seat set; only the public build adds this one.
|
|
264
265
|
.command(registerStaffCommands ? { command: 'cobrowse-seats-in-staff-group', describe: false, builder: (y) => y, handler: () => {} } : cobrowseCommand)
|
|
265
266
|
.command(callpresenceCommand)
|
|
267
|
+
.command(signupFormCommand)
|
|
266
268
|
.command(authorityCommand)
|
|
267
269
|
.command(caseCommand)
|
|
268
270
|
.command(dealCommand)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { messagingGet, messagingPost } from '../api.js';
|
|
2
|
+
import { runCommand } from '../run.js';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
// -- velaro signup-form ----------------------------------------------------------------------------------------------
|
|
6
|
+
// Signup forms, popups and slide-ins are the LIST-GROWTH LAYER of a survey (Survey.GrowthConfigJson), not a separate
|
|
7
|
+
// form system: fields, validation, consent wording, versions and submissions are the survey's. This group reads and
|
|
8
|
+
// writes only that layer, plus its stats and signups. Backend: velaro-messaging SurveysController (Surveys/...).
|
|
9
|
+
// The site always comes from the credential. Needs the Email Growth package (the server answers 403 naming it).
|
|
10
|
+
|
|
11
|
+
const BOLD = '\x1b[1m';
|
|
12
|
+
const DIM = '\x1b[2m';
|
|
13
|
+
const RST = '\x1b[0m';
|
|
14
|
+
|
|
15
|
+
const parseConfig = (s) => { try { return JSON.parse(s); } catch { throw new Error('growth config is not valid JSON'); } };
|
|
16
|
+
|
|
17
|
+
async function findSurvey(id) {
|
|
18
|
+
const all = (await messagingGet('/Surveys/list')) ?? [];
|
|
19
|
+
const s = all.find((x) => x.id === Number(id));
|
|
20
|
+
if (!s) throw new Error(`Survey ${id} not found`);
|
|
21
|
+
return s;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const isGrowth = (s) => { if (!s.growthConfigJson) return false; try { return !!JSON.parse(s.growthConfigJson).enabled; } catch { return false; } };
|
|
25
|
+
|
|
26
|
+
async function listHandler(argv) {
|
|
27
|
+
const all = ((await messagingGet('/Surveys/list')) ?? []).filter(isGrowth);
|
|
28
|
+
if (argv.json) { console.log(JSON.stringify(all.map((s) => ({ id: s.id, name: s.name, publicSlug: s.publicSlug, growth: JSON.parse(s.growthConfigJson) })), null, 2)); return; }
|
|
29
|
+
if (!all.length) { console.log('\n No signup forms yet. Turn on "List growth" on a survey (velaro signup-form set).\n'); return; }
|
|
30
|
+
console.log(`\n${BOLD}Signup forms${RST}`);
|
|
31
|
+
for (const s of all) {
|
|
32
|
+
const g = JSON.parse(s.growthConfigJson);
|
|
33
|
+
console.log(` #${s.id} ${s.name} ${DIM}${g.display?.type ?? 'popup'} / ${g.display?.trigger ?? 'timed'} list ${g.list?.listId ?? '-'} slug ${s.publicSlug ?? '(no shareable link yet)'}${RST}`);
|
|
34
|
+
}
|
|
35
|
+
console.log('');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function getHandler(argv) {
|
|
39
|
+
const s = await findSurvey(argv.id);
|
|
40
|
+
const out = { id: s.id, name: s.name, publicSlug: s.publicSlug, allowStandaloneAccess: s.allowStandaloneAccess, consentEnabled: s.consentEnabled, growth: s.growthConfigJson ? JSON.parse(s.growthConfigJson) : null };
|
|
41
|
+
console.log(JSON.stringify(out, null, 2));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function setHandler(argv) {
|
|
45
|
+
const s = await findSurvey(argv.id);
|
|
46
|
+
let cfg = s.growthConfigJson ? JSON.parse(s.growthConfigJson) : { enabled: false };
|
|
47
|
+
if (argv.file) cfg = parseConfig(readFileSync(argv.file, 'utf8'));
|
|
48
|
+
if (argv.config) cfg = parseConfig(argv.config);
|
|
49
|
+
if (argv.enable !== undefined) cfg.enabled = argv.enable;
|
|
50
|
+
const body = { ...s, growthConfigJson: JSON.stringify(cfg) };
|
|
51
|
+
const saved = await messagingPost('/Surveys', body);
|
|
52
|
+
if (cfg.enabled && !saved.allowStandaloneAccess) await messagingPost(`/Surveys/${saved.id}/standalone-link`);
|
|
53
|
+
console.log(argv.json ? JSON.stringify(saved, null, 2) : `Saved signup form settings on survey ${saved.id}.`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function statsHandler(argv) {
|
|
57
|
+
const r = await messagingGet(`/Surveys/${argv.id}/growth/stats?days=${argv.days}`);
|
|
58
|
+
if (argv.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
59
|
+
console.log(`\n${BOLD}Form ${argv.id}, last ${argv.days} days${RST}`);
|
|
60
|
+
console.log(` Views ${r.views} Dismissals ${r.dismissals} Signups ${r.submissions} Conversion ${r.conversionRate}%`);
|
|
61
|
+
console.log(` Subscribed ${r.subscribed} Awaiting confirmation ${r.pendingConfirmation} Confirmed ${r.confirmed} Suppressed ${r.suppressed}\n`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function submissionsHandler(argv) {
|
|
65
|
+
const q = `page=${argv.page}&pageSize=${argv.pageSize}${argv.status ? `&status=${encodeURIComponent(argv.status)}` : ''}`;
|
|
66
|
+
const r = await messagingGet(`/Surveys/${argv.id}/growth/submissions?${q}`);
|
|
67
|
+
if (argv.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
68
|
+
console.log(`\n${BOLD}Signups for form ${argv.id}${RST} ${DIM}(${r.total} total, page ${r.page})${RST}`);
|
|
69
|
+
for (const i of r.items) console.log(` ${i.submittedAt} ${i.contactEmail ?? '-'} ${i.optInStatus} consent record #${i.consentRecordId ?? '-'}`);
|
|
70
|
+
console.log('');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function snippetHandler(argv) {
|
|
74
|
+
const s = await findSurvey(argv.id);
|
|
75
|
+
if (!s.publicSlug || !s.allowStandaloneAccess) throw new Error('Enable the shareable link first (velaro signup-form set <id> --enable).');
|
|
76
|
+
const host = argv.host || 'https://messaging.velaro.com';
|
|
77
|
+
const embedded = s.growthConfigJson && JSON.parse(s.growthConfigJson).display?.type === 'embedded';
|
|
78
|
+
console.log(`<script async src="${host}/messenger/forms.js" data-form="${s.publicSlug}"></script>`);
|
|
79
|
+
if (embedded) console.log(`<div data-velaro-form="${s.publicSlug}"></div>`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const signupFormCommand = {
|
|
83
|
+
command: 'signup-form <subcommand>',
|
|
84
|
+
describe: 'Signup forms and popups: the list-growth layer of a survey (display rules, list, double opt-in, stats, signups)',
|
|
85
|
+
builder: (y) => y
|
|
86
|
+
.command({ command: 'list', describe: 'List the surveys that have the list-growth layer on', builder: (a) => a.option('json', { type: 'boolean' }), handler: runCommand(listHandler) })
|
|
87
|
+
.command({ command: 'get <id>', describe: 'Show one form (survey id) and its growth settings', builder: (a) => a.positional('id', { type: 'number' }), handler: runCommand(getHandler) })
|
|
88
|
+
.command({
|
|
89
|
+
command: 'set <id>',
|
|
90
|
+
describe: 'Change the list-growth settings of a survey (read-modify-write; the survey itself is untouched)',
|
|
91
|
+
builder: (a) => a.positional('id', { type: 'number' })
|
|
92
|
+
.option('file', { type: 'string', describe: 'JSON file with the growth settings' })
|
|
93
|
+
.option('config', { type: 'string', describe: 'Growth settings as a JSON string' })
|
|
94
|
+
.option('enable', { type: 'boolean', describe: 'Switch the layer on or off' })
|
|
95
|
+
.option('json', { type: 'boolean' }),
|
|
96
|
+
handler: runCommand(setHandler),
|
|
97
|
+
})
|
|
98
|
+
.command({ command: 'stats <id>', describe: 'Views, dismissals, signups and conversion', builder: (a) => a.positional('id', { type: 'number' }).option('days', { type: 'number', default: 30 }).option('json', { type: 'boolean' }), handler: runCommand(statsHandler) })
|
|
99
|
+
.command({
|
|
100
|
+
command: 'submissions <id>',
|
|
101
|
+
describe: 'Signups with opt-in status and consent record id (paginated)',
|
|
102
|
+
builder: (a) => a.positional('id', { type: 'number' }).option('page', { type: 'number', default: 1 }).option('page-size', { type: 'number', default: 25, alias: 'pageSize' })
|
|
103
|
+
.option('status', { type: 'string', describe: 'subscribed | pending_confirmation | confirmed | suppressed | list_sync_failed' }).option('json', { type: 'boolean' }),
|
|
104
|
+
handler: runCommand(submissionsHandler),
|
|
105
|
+
})
|
|
106
|
+
.command({ command: 'snippet <id>', describe: 'Print the one-line install snippet', builder: (a) => a.positional('id', { type: 'number' }).option('host', { type: 'string' }), handler: runCommand(snippetHandler) })
|
|
107
|
+
.demandCommand(1, 'Specify a signup-form subcommand.')
|
|
108
|
+
.strict(),
|
|
109
|
+
handler: () => {},
|
|
110
|
+
};
|
package/package.json
CHANGED