@velaro/cli 1.4.232 → 1.4.234
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
|
@@ -144,6 +144,7 @@ import { aiFollowupsCommand, businessActionCommand, callCommand, conversationCom
|
|
|
144
144
|
import { crmViewCommand, crmBulkCommand, crmWebformCommand } from '../lib/commands/crm-views-bulk-webforms.js';
|
|
145
145
|
import { crmImportCommand, crmTagCommand, crmDedupeCommand, crmAuditCommand } from '../lib/commands/crm-import-dedupe-audit.js';
|
|
146
146
|
import { crmObjectCommand, crmRelCommand } from '../lib/commands/crm-objects-relationships.js';
|
|
147
|
+
import { crmDocTemplateCommand, crmDealDocCommand } from '../lib/commands/crm-document-templates.js';
|
|
147
148
|
import { crmOrderCommand, crmFulfillmentCommand, crmReturnCommand } from '../lib/commands/crm-orders-returns.js';
|
|
148
149
|
import { crmApprovalCommand, crmScoreCommand } from '../lib/commands/crm-approvals-scoring.js';
|
|
149
150
|
import { featureDiscoveryGroup } from '../lib/commands/feature-discovery.js';
|
|
@@ -343,6 +344,8 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
343
344
|
.command(crmAuditCommand)
|
|
344
345
|
.command(crmObjectCommand)
|
|
345
346
|
.command(crmRelCommand)
|
|
347
|
+
.command(crmDocTemplateCommand)
|
|
348
|
+
.command(crmDealDocCommand)
|
|
346
349
|
.command(crmOrderCommand)
|
|
347
350
|
.command(crmFulfillmentCommand)
|
|
348
351
|
.command(crmReturnCommand)
|
package/lib/api.js
CHANGED
|
@@ -156,6 +156,23 @@ export async function getBinary(path, envOverride) {
|
|
|
156
156
|
return Buffer.from(await res.arrayBuffer());
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
// Binary download from the messaging API (CRM document PDF/HTML and signed copies). Returns a Buffer.
|
|
160
|
+
export async function messagingGetBinary(path, envOverride) {
|
|
161
|
+
const creds = await getCredentials(envOverride);
|
|
162
|
+
const res = await fetch(joinUrl(creds.messagingApiBase, path), {
|
|
163
|
+
headers: {
|
|
164
|
+
Authorization: `Bearer ${creds.velaroToken}`,
|
|
165
|
+
...(creds.siteId ? { 'vmsg-siteId': String(creds.siteId) } : {}),
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
if (!res.ok) {
|
|
169
|
+
let msg = `GET ${path} -> ${res.status}`;
|
|
170
|
+
try { const t = await res.text(); if (t) msg += `: ${t}`; } catch { /* status captured */ }
|
|
171
|
+
throw new Error(msg);
|
|
172
|
+
}
|
|
173
|
+
return Buffer.from(await res.arrayBuffer());
|
|
174
|
+
}
|
|
175
|
+
|
|
159
176
|
// Same as messagingRequest but returns the raw response text (for CSV downloads).
|
|
160
177
|
export async function messagingRequestText(method, path, envOverride) {
|
|
161
178
|
const creds = await getCredentials(envOverride);
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { messagingGet, messagingPost, messagingPut, messagingDel, messagingGetBinary } from '../api.js';
|
|
3
|
+
import { runCommand } from '../run.js';
|
|
4
|
+
|
|
5
|
+
// -- velaro crm-doc-template / crm-deal-doc ---------------------------------------
|
|
6
|
+
// CLI for CRM Studio feature 20 (docs/architecture/crm-studio-program.md):
|
|
7
|
+
// crm-doc-template CrmDocumentTemplates /CrmDocumentTemplates (quote, proposal and agreement templates with merge fields)
|
|
8
|
+
// crm-deal-doc CrmDealDocuments /CrmDealDocuments (render, keep, download and send deal documents for signature)
|
|
9
|
+
// The site always comes from the signed-in credential; no command takes a site id.
|
|
10
|
+
// MCP parity: mcp/parity/crm-document-templates.customer.js (crm_doc_template_*, crm_deal_doc_* tools).
|
|
11
|
+
|
|
12
|
+
const BOLD = '\x1b[1m';
|
|
13
|
+
const DIM = '\x1b[2m';
|
|
14
|
+
const RST = '\x1b[0m';
|
|
15
|
+
|
|
16
|
+
export const TEMPLATE_KINDS = ['quote', 'proposal', 'agreement'];
|
|
17
|
+
export const SIGN_MODES = ['sequential', 'parallel'];
|
|
18
|
+
|
|
19
|
+
const data = (r) => (r && typeof r === 'object' && 'data' in r ? r.data : r);
|
|
20
|
+
const printJson = (v) => console.log(JSON.stringify(v, null, 2));
|
|
21
|
+
const done = (msg) => console.log(`\n ${msg}\n`);
|
|
22
|
+
const json = (y) => y.option('json', { type: 'boolean', default: false, describe: 'Print raw JSON' });
|
|
23
|
+
|
|
24
|
+
export const buildQuery = (o) => {
|
|
25
|
+
const p = Object.entries(o).filter(([, v]) => v !== undefined && v !== null && v !== '').map(([k, v]) => `${k}=${encodeURIComponent(v)}`);
|
|
26
|
+
return p.length ? `?${p.join('&')}` : '';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Only the fields the caller supplied are sent, so a partial update never blanks the rest.
|
|
30
|
+
// On create (includeAll) the missing ones get plain defaults.
|
|
31
|
+
export function buildTemplateBody(argv, includeAll = false) {
|
|
32
|
+
const body = {};
|
|
33
|
+
for (const k of ['name', 'kind', 'description', 'bodyHtml', 'expectedVersion']) {
|
|
34
|
+
if (argv[k] !== undefined && argv[k] !== null) body[k] = argv[k];
|
|
35
|
+
else if (includeAll && k !== 'expectedVersion') body[k] = k === 'kind' ? 'quote' : '';
|
|
36
|
+
}
|
|
37
|
+
return body;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// "Jane Doe <jane@example.com>" or "jane@example.com" -> { name, email, order }; order is the 1-based position.
|
|
41
|
+
export function parseSigner(text, index) {
|
|
42
|
+
const raw = String(text ?? '').trim();
|
|
43
|
+
const m = raw.match(/^(.*?)\s*<([^<>\s]+@[^<>\s]+)>$/);
|
|
44
|
+
const name = m ? m[1].trim() : '';
|
|
45
|
+
const email = m ? m[2] : raw;
|
|
46
|
+
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) throw new Error(`[CRM] Signer "${raw}" must be an email address, or "Name <email>".`);
|
|
47
|
+
return { name: name || email.split('@')[0], email, order: index + 1 };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function buildSendBody(argv) {
|
|
51
|
+
const list = [].concat(argv.signer ?? []).filter((s) => s !== undefined && s !== '');
|
|
52
|
+
const body = { signers: list.map(parseSigner), mode: argv.mode };
|
|
53
|
+
if (argv.message) body.message = argv.message;
|
|
54
|
+
return body;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const resolveBodyHtml = (argv) => (argv.bodyFile ? readFileSync(argv.bodyFile, 'utf8') : argv.bodyHtml);
|
|
58
|
+
|
|
59
|
+
// ---------------------------------------------------------------- templates
|
|
60
|
+
|
|
61
|
+
async function tplListHandler(argv) {
|
|
62
|
+
const r = data(await messagingGet(`/CrmDocumentTemplates${buildQuery({ kind: argv.kind })}`));
|
|
63
|
+
if (argv.json) return printJson(r);
|
|
64
|
+
const list = Array.isArray(r) ? r : r?.templates ?? [];
|
|
65
|
+
console.log(`\n${BOLD}Document templates${RST} (${list.length})`);
|
|
66
|
+
for (const t of list) console.log(` #${t.id} ${t.name} ${DIM}${t.kind} v${t.version}${RST}`);
|
|
67
|
+
console.log('');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function tplGetHandler(argv) {
|
|
71
|
+
printJson(data(await messagingGet(`/CrmDocumentTemplates/${argv.id}`)));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function tplCreateHandler(argv) {
|
|
75
|
+
const bodyHtml = resolveBodyHtml(argv);
|
|
76
|
+
const r = data(await messagingPost('/CrmDocumentTemplates', buildTemplateBody({ ...argv, bodyHtml }, true)));
|
|
77
|
+
if (argv.json) return printJson(r);
|
|
78
|
+
done(`Template saved: ${r?.name ?? argv.name}${r?.id ? ` (#${r.id})` : ''}. Unknown merge fields are rejected on save; run "crm-doc-template fields" to see the real ones.`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function tplUpdateHandler(argv) {
|
|
82
|
+
const bodyHtml = resolveBodyHtml(argv);
|
|
83
|
+
const r = data(await messagingPut(`/CrmDocumentTemplates/${argv.id}`, buildTemplateBody({ ...argv, bodyHtml })));
|
|
84
|
+
if (argv.json) return printJson(r);
|
|
85
|
+
done(`Template ${argv.id} updated${r?.version ? ` to version ${r.version}` : ''}. The earlier version is kept and can be restored.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function tplArchiveHandler(argv) {
|
|
89
|
+
await messagingDel(`/CrmDocumentTemplates/${argv.id}`);
|
|
90
|
+
done(`Template ${argv.id} archived. Documents already made from it are kept.`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function tplValidateHandler(argv) {
|
|
94
|
+
const r = data(await messagingPost('/CrmDocumentTemplates/validate', { bodyHtml: resolveBodyHtml(argv) }));
|
|
95
|
+
if (argv.json) return printJson(r);
|
|
96
|
+
console.log(`\n${BOLD}${r?.valid ? 'Valid' : 'Not valid'}${RST}`);
|
|
97
|
+
console.log(` Used: ${(r?.used ?? []).join(', ') || '(none)'}`);
|
|
98
|
+
if ((r?.unknown ?? []).length) console.log(` Unknown: ${r.unknown.join(', ')}`);
|
|
99
|
+
if ((r?.malformed ?? []).length) console.log(` Malformed: ${r.malformed.join(', ')}`);
|
|
100
|
+
console.log('');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function tplFieldsHandler(argv) {
|
|
104
|
+
const r = data(await messagingGet('/CrmDocumentTemplates/merge-fields'));
|
|
105
|
+
if (argv.json) return printJson(r);
|
|
106
|
+
const list = Array.isArray(r) ? r : r?.fields ?? [];
|
|
107
|
+
console.log(`\n${BOLD}Merge fields${RST} (${list.length})`);
|
|
108
|
+
for (const f of list) console.log(` ${f.token ?? `{{${f.key}}}`} ${DIM}${f.group ?? ''} ${f.label ?? ''}${RST}`);
|
|
109
|
+
console.log('');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function tplVersionsHandler(argv) {
|
|
113
|
+
const r = data(await messagingGet(`/CrmDocumentTemplates/${argv.id}/versions`));
|
|
114
|
+
if (argv.json) return printJson(r);
|
|
115
|
+
const list = Array.isArray(r) ? r : r?.versions ?? [];
|
|
116
|
+
console.log(`\n${BOLD}Versions of template ${argv.id}${RST} (${list.length})`);
|
|
117
|
+
for (const v of list) console.log(` v${v.version} ${DIM}${v.updatedAt ?? v.createdAt ?? ''} ${v.updatedBy ?? ''}${RST}`);
|
|
118
|
+
console.log('');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function tplRestoreHandler(argv) {
|
|
122
|
+
await messagingPost(`/CrmDocumentTemplates/${argv.id}/versions/${argv.version}/restore`, {});
|
|
123
|
+
done(`Template ${argv.id} restored from version ${argv.version}. The restore is saved as a new version.`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const idArg = (yy) => yy.positional('id', { type: 'number' });
|
|
127
|
+
const bodyOpts = (yy) => yy
|
|
128
|
+
.option('body-html', { type: 'string', alias: 'bodyHtml', describe: 'Template body as HTML with {{merge.fields}}' })
|
|
129
|
+
.option('body-file', { type: 'string', alias: 'bodyFile', describe: 'Read the template body from this HTML file' });
|
|
130
|
+
|
|
131
|
+
export const crmDocTemplateCommand = {
|
|
132
|
+
command: 'crm-doc-template <subcommand>',
|
|
133
|
+
describe: 'CRM document and quote templates with merge fields (changing templates needs a Manager or Administrator)',
|
|
134
|
+
builder: (y) => y
|
|
135
|
+
.command({
|
|
136
|
+
command: 'list',
|
|
137
|
+
describe: 'List the document templates',
|
|
138
|
+
builder: (yy) => json(yy.option('kind', { choices: TEMPLATE_KINDS })),
|
|
139
|
+
handler: runCommand(tplListHandler),
|
|
140
|
+
})
|
|
141
|
+
.command({ command: 'get <id>', describe: 'Show one template with its body', builder: idArg, handler: runCommand(tplGetHandler) })
|
|
142
|
+
.command({
|
|
143
|
+
command: 'create',
|
|
144
|
+
describe: 'Create a template',
|
|
145
|
+
builder: (yy) => json(bodyOpts(yy
|
|
146
|
+
.option('name', { type: 'string', demandOption: true })
|
|
147
|
+
.option('kind', { choices: TEMPLATE_KINDS, default: 'quote' })
|
|
148
|
+
.option('description', { type: 'string' }))),
|
|
149
|
+
handler: runCommand(tplCreateHandler),
|
|
150
|
+
})
|
|
151
|
+
.command({
|
|
152
|
+
command: 'update <id>',
|
|
153
|
+
describe: 'Change a template; only the options you pass change. Saves a new version',
|
|
154
|
+
builder: (yy) => json(bodyOpts(idArg(yy)
|
|
155
|
+
.option('name', { type: 'string' })
|
|
156
|
+
.option('kind', { choices: TEMPLATE_KINDS })
|
|
157
|
+
.option('description', { type: 'string' })
|
|
158
|
+
.option('expected-version', { type: 'number', alias: 'expectedVersion', describe: 'Refuse the save if someone else changed the template since this version' }))),
|
|
159
|
+
handler: runCommand(tplUpdateHandler),
|
|
160
|
+
})
|
|
161
|
+
.command({ command: 'archive <id>', describe: 'Archive a template (never hard-deleted)', builder: idArg, handler: runCommand(tplArchiveHandler) })
|
|
162
|
+
.command({
|
|
163
|
+
command: 'validate',
|
|
164
|
+
describe: 'Check a template body for unknown or malformed merge fields without saving',
|
|
165
|
+
builder: (yy) => json(bodyOpts(yy)),
|
|
166
|
+
handler: runCommand(tplValidateHandler),
|
|
167
|
+
})
|
|
168
|
+
.command({ command: 'fields', describe: 'List the merge fields you can use, including your custom fields', builder: json, handler: runCommand(tplFieldsHandler) })
|
|
169
|
+
.command({ command: 'versions <id>', describe: 'List the saved versions of a template', builder: (yy) => json(idArg(yy)), handler: runCommand(tplVersionsHandler) })
|
|
170
|
+
.command({
|
|
171
|
+
command: 'restore <id> <version>',
|
|
172
|
+
describe: 'Restore an earlier version (saved as a new version)',
|
|
173
|
+
builder: (yy) => idArg(yy).positional('version', { type: 'number' }),
|
|
174
|
+
handler: runCommand(tplRestoreHandler),
|
|
175
|
+
})
|
|
176
|
+
.demandCommand(1),
|
|
177
|
+
handler: () => {},
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// ---------------------------------------------------------------- deal documents
|
|
181
|
+
|
|
182
|
+
async function docPreviewHandler(argv) {
|
|
183
|
+
const r = data(await messagingPost('/CrmDealDocuments/render', { templateId: argv.templateId, dealId: argv.dealId }));
|
|
184
|
+
if (argv.json) return printJson(r);
|
|
185
|
+
if (argv.out) { writeFileSync(argv.out, r?.html ?? '', 'utf8'); return done(`Preview saved to ${argv.out}. Nothing was kept on the deal.`); }
|
|
186
|
+
console.log(r?.html ?? '');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function docGenerateHandler(argv) {
|
|
190
|
+
const r = data(await messagingPost('/CrmDealDocuments', { templateId: argv.templateId, dealId: argv.dealId }));
|
|
191
|
+
if (argv.json) return printJson(r);
|
|
192
|
+
done(`Document${r?.id ? ` #${r.id}` : ''} created as a draft and its PDF saved to the deal attachments.`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function docListHandler(argv) {
|
|
196
|
+
const r = data(await messagingGet(`/CrmDealDocuments/deal/${argv.dealId}`));
|
|
197
|
+
if (argv.json) return printJson(r);
|
|
198
|
+
const list = Array.isArray(r) ? r : r?.documents ?? [];
|
|
199
|
+
console.log(`\n${BOLD}Documents of deal ${argv.dealId}${RST} (${list.length})`);
|
|
200
|
+
for (const d of list) console.log(` #${d.id} ${d.name ?? d.title ?? ''} ${DIM}${d.status}${RST}`);
|
|
201
|
+
console.log('');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function docGetHandler(argv) {
|
|
205
|
+
printJson(data(await messagingGet(`/CrmDealDocuments/${argv.id}`)));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function docDownloadHandler(argv) {
|
|
209
|
+
const buf = await messagingGetBinary(`/CrmDealDocuments/${argv.id}/${argv.format}`);
|
|
210
|
+
const out = argv.out || `deal-document-${argv.id}.${argv.format}`;
|
|
211
|
+
writeFileSync(out, buf);
|
|
212
|
+
done(`Saved ${buf.length} bytes to ${out}.`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function docSendHandler(argv) {
|
|
216
|
+
const body = buildSendBody(argv);
|
|
217
|
+
const r = data(await messagingPost(`/CrmDealDocuments/${argv.id}/send-for-signature`, body));
|
|
218
|
+
if (argv.json) return printJson(r);
|
|
219
|
+
done(`Document ${argv.id} sent for signature${body.signers.length ? '' : ' to the primary contact of the deal'}. Status: ${r?.status ?? 'sent'}.`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async function docSyncHandler(argv) {
|
|
223
|
+
const r = data(await messagingPost(`/CrmDealDocuments/${argv.id}/sync-signature`, {}));
|
|
224
|
+
if (argv.json) return printJson(r);
|
|
225
|
+
done(`Document ${argv.id} status: ${r?.status ?? 'unknown'}.`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function docVoidHandler(argv) {
|
|
229
|
+
await messagingPost(`/CrmDealDocuments/${argv.id}/void`, {});
|
|
230
|
+
done(`Document ${argv.id} voided. Signers can no longer sign it.`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function docSignedHandler(argv) {
|
|
234
|
+
const buf = await messagingGetBinary(`/CrmDealDocuments/${argv.id}/signed-document`);
|
|
235
|
+
const out = argv.out || `deal-document-${argv.id}-signed.pdf`;
|
|
236
|
+
writeFileSync(out, buf);
|
|
237
|
+
done(`Saved the signed copy (${buf.length} bytes) to ${out}.`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const docIdArg = (yy) => yy.positional('id', { type: 'number' });
|
|
241
|
+
const tplDealArgs = (yy) => json(yy
|
|
242
|
+
.option('template-id', { type: 'number', alias: 'templateId', demandOption: true })
|
|
243
|
+
.option('deal-id', { type: 'number', alias: 'dealId', demandOption: true }));
|
|
244
|
+
|
|
245
|
+
export const crmDealDocCommand = {
|
|
246
|
+
command: 'crm-deal-doc <subcommand>',
|
|
247
|
+
describe: 'CRM deal documents: render a template for a deal, keep it, download it and send it for signature with Velaro Sign',
|
|
248
|
+
builder: (y) => y
|
|
249
|
+
.command({
|
|
250
|
+
command: 'preview',
|
|
251
|
+
describe: 'Render a template for a deal without keeping anything',
|
|
252
|
+
builder: (yy) => tplDealArgs(yy).option('out', { type: 'string', describe: 'Save the HTML here instead of printing it' }),
|
|
253
|
+
handler: runCommand(docPreviewHandler),
|
|
254
|
+
})
|
|
255
|
+
.command({ command: 'generate', describe: 'Keep a copy for the deal and save its PDF to the deal attachments', builder: tplDealArgs, handler: runCommand(docGenerateHandler) })
|
|
256
|
+
.command({
|
|
257
|
+
command: 'list <dealId>',
|
|
258
|
+
describe: 'List the documents of a deal',
|
|
259
|
+
builder: (yy) => json(yy.positional('dealId', { type: 'number' })),
|
|
260
|
+
handler: runCommand(docListHandler),
|
|
261
|
+
})
|
|
262
|
+
.command({ command: 'get <id>', describe: 'Show one deal document and its status (draft, sent, signed, voided, expired)', builder: docIdArg, handler: runCommand(docGetHandler) })
|
|
263
|
+
.command({
|
|
264
|
+
command: 'download <id>',
|
|
265
|
+
describe: 'Download the document as PDF or HTML',
|
|
266
|
+
builder: (yy) => docIdArg(yy)
|
|
267
|
+
.option('format', { choices: ['pdf', 'html'], default: 'pdf' })
|
|
268
|
+
.option('out', { type: 'string', describe: 'File to write (default deal-document-<id>.<format>)' }),
|
|
269
|
+
handler: runCommand(docDownloadHandler),
|
|
270
|
+
})
|
|
271
|
+
.command({
|
|
272
|
+
command: 'send <id>',
|
|
273
|
+
describe: 'Send for signature with Velaro Sign. With no --signer the primary contact of the deal signs',
|
|
274
|
+
builder: (yy) => json(docIdArg(yy)
|
|
275
|
+
.option('signer', { type: 'string', array: true, describe: '"Name <email>" or an email; repeat for more signers, the order given is the signing order' })
|
|
276
|
+
.option('mode', { choices: SIGN_MODES, default: 'sequential' })
|
|
277
|
+
.option('message', { type: 'string', describe: 'A note shown to the signers' })),
|
|
278
|
+
handler: runCommand(docSendHandler),
|
|
279
|
+
})
|
|
280
|
+
.command({ command: 'sync <id>', describe: 'Pull the latest signature status from Velaro Sign', builder: (yy) => json(docIdArg(yy)), handler: runCommand(docSyncHandler) })
|
|
281
|
+
.command({ command: 'void <id>', describe: 'Void a sent document so it can no longer be signed', builder: docIdArg, handler: runCommand(docVoidHandler) })
|
|
282
|
+
.command({
|
|
283
|
+
command: 'signed <id>',
|
|
284
|
+
describe: 'Download the signed PDF once every signer has signed',
|
|
285
|
+
builder: (yy) => docIdArg(yy).option('out', { type: 'string' }),
|
|
286
|
+
handler: runCommand(docSignedHandler),
|
|
287
|
+
})
|
|
288
|
+
.demandCommand(1),
|
|
289
|
+
handler: () => {},
|
|
290
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { buildQuery, buildTemplateBody, parseSigner, buildSendBody } from './crm-document-templates.js';
|
|
4
|
+
|
|
5
|
+
test('buildQuery drops blanks and encodes values', () => {
|
|
6
|
+
assert.equal(buildQuery({ kind: 'quote' }), '?kind=quote');
|
|
7
|
+
assert.equal(buildQuery({ kind: undefined, x: '' }), '');
|
|
8
|
+
assert.equal(buildQuery({ a: 'b c' }), '?a=b%20c');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('buildTemplateBody sends only the supplied fields on update', () => {
|
|
12
|
+
assert.deepEqual(buildTemplateBody({ name: 'N', expectedVersion: 3 }), { name: 'N', expectedVersion: 3 });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('buildTemplateBody fills create defaults and never sends expectedVersion', () => {
|
|
16
|
+
assert.deepEqual(buildTemplateBody({ name: 'N' }, true), { name: 'N', kind: 'quote', description: '', bodyHtml: '' });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('parseSigner accepts "Name <email>" and a bare email, order is 1-based', () => {
|
|
20
|
+
assert.deepEqual(parseSigner('Jane Doe <jane@example.com>', 0), { name: 'Jane Doe', email: 'jane@example.com', order: 1 });
|
|
21
|
+
assert.deepEqual(parseSigner('bob@example.com', 1), { name: 'bob', email: 'bob@example.com', order: 2 });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('parseSigner rejects a non-email', () => {
|
|
25
|
+
assert.throws(() => parseSigner('not an email', 0), /\[CRM\]/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('buildSendBody with no signers sends an empty list so the server uses the primary contact', () => {
|
|
29
|
+
assert.deepEqual(buildSendBody({ mode: 'sequential' }), { signers: [], mode: 'sequential' });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('buildSendBody keeps signer order and the message', () => {
|
|
33
|
+
const b = buildSendBody({ signer: ['a@x.com', 'B <b@x.com>'], mode: 'parallel', message: 'Hi' });
|
|
34
|
+
assert.equal(b.signers[1].order, 2);
|
|
35
|
+
assert.equal(b.message, 'Hi');
|
|
36
|
+
assert.equal(b.mode, 'parallel');
|
|
37
|
+
});
|
package/package.json
CHANGED