@velaro/cli 1.4.187 → 1.4.188

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/api.js CHANGED
@@ -104,6 +104,23 @@ export const messagingPut = (path, body) => messagingRequest('PUT', path, bod
104
104
  export const messagingPatch = (path, body) => messagingRequest('PATCH', path, body);
105
105
  export const messagingDel = (path) => messagingRequest('DELETE', path);
106
106
 
107
+ // Multipart upload to the admin API (staff Bearer). `form` is a FormData. Returns parsed JSON.
108
+ export async function postForm(path, form, envOverride) {
109
+ const creds = await getCredentials(envOverride);
110
+ const res = await fetch(joinUrl(creds.adminApiBase, path), {
111
+ method: 'POST',
112
+ headers: { Authorization: `Bearer ${creds.velaroToken}` },
113
+ body: form,
114
+ });
115
+ if (!res.ok) {
116
+ let msg = `POST ${path} -> ${res.status}`;
117
+ try { const t = await res.text(); if (t) msg += `: ${t}`; } catch { /* status captured */ }
118
+ throw new Error(msg);
119
+ }
120
+ const text = await res.text();
121
+ return text ? JSON.parse(text) : null;
122
+ }
123
+
107
124
  // multipart/form-data POST (ChatWindow/Update takes [FromForm]); fetch sets the boundary header itself.
108
125
  export async function messagingPostForm(path, form, envOverride) {
109
126
  const creds = await getCredentials(envOverride);
@@ -124,6 +141,20 @@ export async function messagingPostForm(path, form, envOverride) {
124
141
  return text ? JSON.parse(text) : null;
125
142
  }
126
143
 
144
+ // Binary download from the admin API. Returns a Buffer.
145
+ export async function getBinary(path, envOverride) {
146
+ const creds = await getCredentials(envOverride);
147
+ const res = await fetch(joinUrl(creds.adminApiBase, path), {
148
+ headers: { Authorization: `Bearer ${creds.velaroToken}` },
149
+ });
150
+ if (!res.ok) {
151
+ let msg = `GET ${path} -> ${res.status}`;
152
+ try { const t = await res.text(); if (t) msg += `: ${t}`; } catch { /* status captured */ }
153
+ throw new Error(msg);
154
+ }
155
+ return Buffer.from(await res.arrayBuffer());
156
+ }
157
+
127
158
  // Same as messagingRequest but returns the raw response text (for CSV downloads).
128
159
  export async function messagingRequestText(method, path, envOverride) {
129
160
  const creds = await getCredentials(envOverride);
@@ -1,9 +1,97 @@
1
- // velaro sign - Velaro Sign document versions (owner-only). REST: GET /api/Contract/{id}/versions,
2
- // GET /api/Contract/{id}/diff, POST /api/Contract/{id}/document (multipart, draft only).
3
- import { getCredentials, get } from '../api.js';
4
- import {
5
- versionsPath, diffPath, uploadPath, describeVersions, describeDiff, buildUploadForm, OWNER_ONLY_RULE,
6
- } from '../sign-versions.js';
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { basename } from 'node:path';
3
+ import { get, post, put, postForm, getBinary, getCredentials } from '../api.js';
4
+ import { runCommand } from '../run.js';
5
+ import { versionsPath, diffPath, uploadPath, describeVersions, describeDiff, buildUploadForm, OWNER_ONLY_RULE } from '../sign-versions.js';
6
+
7
+ // velaro sign -- Velaro Sign routing, reminders, final PDF download, file verification.
8
+ // Backend: server/Velaro.Admin/Controllers/ContractSignersController.cs (route api/Contract)
9
+ // GET api/Contract/{id}/signers
10
+ // PUT api/Contract/{id}/signers
11
+ // POST api/Contract/{id}/signers/reassignments/{requestId}/approve|deny
12
+ // PUT api/Contract/{id}/reminders
13
+ // GET api/Contract/{id}/signed-document
14
+ // POST api/Contract/verify (multipart 'file')
15
+
16
+ const csv = (v) => (v == null ? [] : String(v).split(',').map(s => s.trim()).filter(Boolean));
17
+
18
+ export function buildSignersBody(existing, argv) {
19
+ const emails = csv(argv.order);
20
+ const names = csv(argv.names);
21
+ const roles = csv(argv.roles);
22
+ const body = {
23
+ mode: argv.mode || existing?.mode || 'sequential',
24
+ allowReassignment: argv.allowReassign != null ? !!argv.allowReassign : existing?.allowReassignment,
25
+ reminderEveryDays: existing?.reminderEveryDays,
26
+ reminderMaxCount: existing?.reminderMaxCount,
27
+ };
28
+ if (emails.length) {
29
+ const prior = new Map((existing?.signers || []).map(s => [String(s.email).toLowerCase(), s]));
30
+ body.signers = emails.map((email, i) => {
31
+ const p = prior.get(email.toLowerCase());
32
+ return {
33
+ order: i + 1,
34
+ role: roles[i] || p?.role || 'customer',
35
+ name: names[i] || p?.name || email.split('@')[0],
36
+ email,
37
+ };
38
+ });
39
+ } else {
40
+ body.signers = (existing?.signers || []).map((s, i) => ({ order: s.order ?? i + 1, role: s.role, name: s.name, email: s.email }));
41
+ }
42
+ return body;
43
+ }
44
+
45
+ function showSigners(r) {
46
+ console.log(`\nContract status: ${r.contractStatus} routing: ${r.routingStatus} mode: ${r.mode} reassignment: ${r.allowReassignment ? 'allowed' : 'off'}`);
47
+ console.log(`Reminders: every ${r.reminderEveryDays ?? '-'}d, max ${r.reminderMaxCount ?? '-'}`);
48
+ console.log(`Original SHA-256: ${r.originalSha256 || '-'}`);
49
+ console.log(`Signed SHA-256: ${r.signedSha256 || '-'} (final PDF ${r.finalPdfAvailable ? 'available' : 'not available'})`);
50
+ for (const s of r.signers || []) {
51
+ console.log(` ${s.order}. [${s.role}] ${s.name} <${s.email}> ${s.status}${s.signedAt ? ' ' + s.signedAt : ''}`);
52
+ }
53
+ for (const q of r.reassignmentRequests || []) {
54
+ console.log(` reassignment request: ${JSON.stringify(q)}`);
55
+ }
56
+ console.log('');
57
+ }
58
+
59
+ async function signersHandler(argv) {
60
+ const base = `/api/Contract/${argv.id}/signers`;
61
+ const existing = await get(base);
62
+ if (argv.action !== 'set') return showSigners(existing);
63
+ await put(base, buildSignersBody(existing, argv));
64
+ showSigners(await get(base));
65
+ }
66
+
67
+ async function reassignHandler(argv) {
68
+ await post(`/api/Contract/${argv.id}/signers/reassignments/${argv.requestId}/${argv.decision}`, argv.note ? { note: argv.note } : {});
69
+ console.log(`\nReassignment ${argv.requestId} ${argv.decision === 'approve' ? 'approved' : 'denied'}.\n`);
70
+ }
71
+
72
+ async function remindersHandler(argv) {
73
+ await put(`/api/Contract/${argv.id}/reminders`, { everyDays: argv.every, maxCount: argv.max });
74
+ console.log(`\nReminders set: every ${argv.every} day(s), max ${argv.max}.\n`);
75
+ }
76
+
77
+ async function downloadHandler(argv) {
78
+ const buf = await getBinary(`/api/Contract/${argv.id}/signed-document`);
79
+ const out = argv.out || `contract-${argv.id}-signed.pdf`;
80
+ writeFileSync(out, buf);
81
+ console.log(`\nSaved ${buf.length} bytes to ${out}\n`);
82
+ }
83
+
84
+ async function verifyHandler(argv) {
85
+ const form = new FormData();
86
+ form.append('file', new Blob([readFileSync(argv.file)]), basename(argv.file));
87
+ const r = await postForm('/api/Contract/verify', form);
88
+ if (r?.match) {
89
+ console.log(`\nMATCH contract ${r.contractId} "${r.title ?? ''}" (${r.status}) matched ${r.matched}\n sha256 ${r.sha256}\n`);
90
+ } else {
91
+ console.log(`\nNO MATCH sha256 ${r?.sha256 ?? '-'}\n`);
92
+ process.exitCode = 1;
93
+ }
94
+ }
7
95
 
8
96
  async function versions(id, json) {
9
97
  const res = await get(versionsPath(id));
@@ -31,19 +119,79 @@ async function uploadVersion(id, file, note) {
31
119
  }
32
120
 
33
121
  export const signCommand = {
34
- command: 'sign <subcommand>',
35
- describe: 'Velaro Sign document versions (owner-only; signers never see old versions)',
36
- builder: (yargs) =>
37
- yargs
38
- .command('versions <contractId>', 'List every uploaded document version of a contract', {
39
- json: { type: 'boolean', default: false },
40
- }, (a) => versions(a.contractId, a.json))
41
- .command('diff <contractId> <from> <to>', 'Text diff between two document versions', {
42
- json: { type: 'boolean', default: false },
43
- }, (a) => diff(a.contractId, a.from, a.to, a.json))
44
- .command('upload-version <contractId> <file>', 'Upload a new PDF version (draft contracts only; after send/sign void and re-send)', {
45
- note: { type: 'string', describe: 'Change note stored with the version' },
46
- }, (a) => uploadVersion(a.contractId, a.file, a.note))
47
- .demandCommand(1, 'Specify: versions | diff | upload-version'),
122
+ command: 'sign <subcommand>',
123
+ describe: 'Velaro Sign -- signer routing, reminders, final PDF, file verification',
124
+ builder: (y) => y
125
+ .command({
126
+ command: 'signers <id> [action]',
127
+ describe: 'Show signers (default) or "set" the routing',
128
+ builder: (y2) => y2
129
+ .positional('id', { type: 'number' })
130
+ .positional('action', { type: 'string', choices: ['set'] })
131
+ .option('order', { describe: 'Comma-separated signer emails in signing order', type: 'string' })
132
+ .option('names', { describe: 'Comma-separated names matching --order', type: 'string' })
133
+ .option('roles', { describe: 'Comma-separated roles (customer|velaro) matching --order', type: 'string' })
134
+ .option('mode', { describe: 'sequential | parallel', type: 'string', choices: ['sequential', 'parallel'] })
135
+ .option('allow-reassign', { describe: 'Allow signers to request reassignment', type: 'boolean' }),
136
+ handler: runCommand(signersHandler),
137
+ })
138
+ .command({
139
+ command: 'reassign <decision> <id> <requestId>',
140
+ describe: 'Approve or deny a signer reassignment request',
141
+ builder: (y2) => y2
142
+ .positional('decision', { type: 'string', choices: ['approve', 'deny'] })
143
+ .positional('id', { type: 'number' })
144
+ .positional('requestId', { type: 'number' })
145
+ .option('note', { type: 'string' }),
146
+ handler: runCommand(reassignHandler),
147
+ })
148
+ .command({
149
+ command: 'reminders set <id>',
150
+ describe: 'Set reminder cadence',
151
+ builder: (y2) => y2
152
+ .positional('id', { type: 'number' })
153
+ .option('every', { describe: 'Days between reminders', type: 'number', demandOption: true })
154
+ .option('max', { describe: 'Max reminders', type: 'number', demandOption: true }),
155
+ handler: runCommand(remindersHandler),
156
+ })
157
+ .command({
158
+ command: 'download <id>',
159
+ describe: 'Download the final signed PDF',
160
+ builder: (y2) => y2.positional('id', { type: 'number' }).option('out', { type: 'string', describe: 'Output file' }),
161
+ handler: runCommand(downloadHandler),
162
+ })
163
+ .command({
164
+ command: 'verify <file>',
165
+ describe: 'Verify a file against original/final contract hashes (exit 1 on no match)',
166
+ builder: (y2) => y2.positional('file', { type: 'string' }),
167
+ handler: runCommand(verifyHandler),
168
+ })
169
+ .command({
170
+ command: 'versions <contractId>',
171
+ describe: 'List every uploaded document version of a contract (owner-only)',
172
+ builder: (y2) => y2.positional('contractId', { type: 'number' }).option('json', { type: 'boolean', default: false }),
173
+ handler: runCommand((a) => versions(a.contractId, a.json)),
174
+ })
175
+ .command({
176
+ command: 'diff <contractId> <from> <to>',
177
+ describe: 'Text diff between two document versions (owner-only)',
178
+ builder: (y2) => y2
179
+ .positional('contractId', { type: 'number' })
180
+ .positional('from', { type: 'number' })
181
+ .positional('to', { type: 'number' })
182
+ .option('json', { type: 'boolean', default: false }),
183
+ handler: runCommand((a) => diff(a.contractId, a.from, a.to, a.json)),
184
+ })
185
+ .command({
186
+ command: 'upload-version <contractId> <file>',
187
+ describe: 'Upload a new PDF version (draft contracts only; after send/sign void and re-send)',
188
+ builder: (y2) => y2
189
+ .positional('contractId', { type: 'number' })
190
+ .positional('file', { type: 'string' })
191
+ .option('note', { type: 'string', describe: 'Change note stored with the version' }),
192
+ handler: runCommand((a) => uploadVersion(a.contractId, a.file, a.note)),
193
+ })
194
+ .demandCommand(1, 'Specify: signers | reassign | reminders | download | verify | versions | diff | upload-version')
195
+ .strict(),
48
196
  handler: () => {},
49
197
  };
@@ -0,0 +1,19 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { buildSignersBody } from './commands/sign.js';
4
+
5
+ test('buildSignersBody builds ordered signers and keeps existing settings', () => {
6
+ const b = buildSignersBody({ mode: 'parallel', allowReassignment: true, reminderEveryDays: 3, reminderMaxCount: 5, signers: [] },
7
+ { order: 'a@x.com,b@y.com', roles: 'customer,velaro' });
8
+ assert.equal(b.mode, 'parallel');
9
+ assert.equal(b.allowReassignment, true);
10
+ assert.deepEqual(b.signers.map(s => [s.order, s.role, s.email]), [[1, 'customer', 'a@x.com'], [2, 'velaro', 'b@y.com']]);
11
+ });
12
+
13
+ test('buildSignersBody merges mode flag and preserves existing names', () => {
14
+ const b = buildSignersBody({ mode: 'sequential', signers: [{ order: 1, role: 'customer', name: 'Ann', email: 'a@x.com' }] },
15
+ { order: 'a@x.com', mode: 'parallel', allowReassign: true });
16
+ assert.equal(b.mode, 'parallel');
17
+ assert.equal(b.allowReassignment, true);
18
+ assert.equal(b.signers[0].name, 'Ann');
19
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.187",
3
+ "version": "1.4.188",
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": {