@velaro/cli 1.4.243 → 1.4.244

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.
@@ -1,27 +0,0 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { fieldsPath, buildFieldsBody, describeFields, buildFromSignupBody } from './sign-fields.js';
4
-
5
- const ok = { fieldType: 'fullname', page: 1, xPct: 10, yPct: 10, widthPct: 20, heightPct: 5, prefillKey: 'name' };
6
-
7
- test('fieldsPath', () => assert.equal(fieldsPath('7'), '/api/Contract/7/fields'));
8
-
9
- test('buildFieldsBody accepts new types and rejects bad ones', () => {
10
- assert.equal(buildFieldsBody([ok]).fields.length, 1);
11
- assert.throws(() => buildFieldsBody([{ ...ok, fieldType: 'nope' }]), /fieldType/);
12
- assert.throws(() => buildFieldsBody([{ ...ok, fieldType: 'dropdown' }]), /options/);
13
- assert.throws(() => buildFieldsBody([{ ...ok, page: 0 }]), /page/);
14
- assert.throws(() => buildFieldsBody([{ ...ok, signerRole: 'x' }]), /signerRole/);
15
- });
16
-
17
- test('describeFields shows prefill key', () => {
18
- const out = describeFields({ hasDocument: true, fileName: 'a.pdf', pageCount: 2, fields: [{ id: 3, page: 1, fieldType: 'email', signerRole: 'customer', required: true, prefillKey: 'email' }] });
19
- assert.match(out, /prefill=email/);
20
- assert.match(describeFields({ hasDocument: false }), /No document/);
21
- });
22
-
23
- test('buildFromSignupBody validates', () => {
24
- assert.throws(() => buildFromSignupBody({ title: 't', customerEmail: 'a@b.c' }), /siteId/);
25
- assert.throws(() => buildFromSignupBody({ siteId: 1, title: 't', customerEmail: 'x' }), /customerEmail/);
26
- assert.deepEqual(buildFromSignupBody({ siteId: 1, title: ' t ', customerEmail: 'a@b.c', sendEmail: true }), { siteId: 1, title: 't', customerEmail: 'a@b.c', sendEmail: true });
27
- });
@@ -1,58 +0,0 @@
1
- // Shared helpers for Velaro Sign document versions (owner-only; REST: ContractVersionsController +
2
- // ContractController.UploadSourceDocument). Used by `velaro sign ...`; pure functions so they unit-test cleanly.
3
- import { readFileSync, existsSync } from 'node:fs';
4
- import { basename } from 'node:path';
5
-
6
- export function versionsPath(contractId) {
7
- return `/api/Contract/${Number(contractId)}/versions`;
8
- }
9
-
10
- export function diffPath(contractId, from, to) {
11
- return `/api/Contract/${Number(contractId)}/diff?from=${Number(from)}&to=${Number(to)}`;
12
- }
13
-
14
- export function uploadPath(contractId) {
15
- return `/api/Contract/${Number(contractId)}/document`;
16
- }
17
-
18
- export function describeVersions(res) {
19
- const rows = res?.versions ?? [];
20
- if (!rows.length) return `Contract ${res?.contractId}: no document versions yet.`;
21
- const lines = [`Contract ${res.contractId}: ${rows.length} version(s), newest first`];
22
- for (const v of rows) {
23
- const kb = Math.max(1, Math.round((v.byteLength || 0) / 1024));
24
- lines.push(` v${v.versionNumber} ${String(v.uploadedAt || '').slice(0, 19)} ${v.uploadedBy || '-'} ${v.fileName || '-'} ${v.pageCount ?? '?'}p ${kb}KB sha256:${String(v.sha256 || '').slice(0, 12)}${v.note ? ` note: ${v.note}` : ''}`);
25
- }
26
- return lines.join('\n');
27
- }
28
-
29
- export function describeDiff(res) {
30
- if (res?.identical) return `v${res.from} and v${res.to} are byte-identical (same SHA-256).`;
31
- const blocks = res?.blocks ?? [];
32
- const changed = blocks.filter(b => b.kind !== 'same' && b.kind !== 'equal');
33
- const lines = [`Diff v${res.from} -> v${res.to}: ${changed.length} changed block(s)`];
34
- for (const b of changed) {
35
- for (const r of b.removed ?? []) lines.push(`- ${r}`);
36
- for (const a of b.added ?? []) lines.push(`+ ${a}`);
37
- lines.push('');
38
- }
39
- return lines.join('\n').trimEnd();
40
- }
41
-
42
- export function readPdf(filePath) {
43
- if (!filePath || !existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
44
- const buf = readFileSync(filePath);
45
- if (buf.length < 5 || buf.subarray(0, 5).toString('latin1') !== '%PDF-') throw new Error('Only PDF files can be uploaded as a contract version.');
46
- return { buf, name: basename(filePath) };
47
- }
48
-
49
- export function buildUploadForm(filePath, note) {
50
- const { buf, name } = readPdf(filePath);
51
- const form = new FormData();
52
- form.append('file', new Blob([buf], { type: 'application/pdf' }), name);
53
- if (note) form.append('note', note);
54
- return form;
55
- }
56
-
57
- export const OWNER_ONLY_RULE =
58
- 'Versions are owner-only: signers never see older versions. A new version can be uploaded only while the contract is a draft; after send/sign, void it and re-send.';
@@ -1,50 +0,0 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { writeFileSync, mkdtempSync } from 'node:fs';
4
- import { join } from 'node:path';
5
- import { tmpdir } from 'node:os';
6
- import { versionsPath, diffPath, uploadPath, describeVersions, describeDiff, buildUploadForm } from './sign-versions.js';
7
-
8
- test('paths', () => {
9
- assert.equal(versionsPath('12'), '/api/Contract/12/versions');
10
- assert.equal(diffPath(12, 1, 3), '/api/Contract/12/diff?from=1&to=3');
11
- assert.equal(uploadPath(12), '/api/Contract/12/document');
12
- });
13
-
14
- test('describeVersions lists newest first with note', () => {
15
- const out = describeVersions({ contractId: 5, versions: [
16
- { versionNumber: 2, fileName: 'b.pdf', sha256: 'abcdef1234567890', byteLength: 2048, pageCount: 3, uploadedBy: 'a@v.com', uploadedAt: '2026-10-11T10:00:00Z', note: 'fix term' },
17
- { versionNumber: 1, fileName: 'a.pdf', sha256: '1111111111111111', byteLength: 100, pageCount: 3, uploadedBy: 'a@v.com', uploadedAt: '2026-10-10T10:00:00Z' }] });
18
- assert.match(out, /2 version\(s\)/);
19
- assert.match(out, /v2 .*note: fix term/);
20
- assert.equal(describeVersions({ contractId: 5, versions: [] }), 'Contract 5: no document versions yet.');
21
- });
22
-
23
- test('describeDiff shows removed/added and identical case', () => {
24
- assert.match(describeDiff({ from: 1, to: 2, identical: true }), /byte-identical/);
25
- const out = describeDiff({ from: 1, to: 2, identical: false, blocks: [{ kind: 'changed', removed: ['Term 12 months'], added: ['Term 24 months'] }] });
26
- assert.match(out, /- Term 12 months/);
27
- assert.match(out, /\+ Term 24 months/);
28
- });
29
-
30
- test('buildUploadForm rejects non-PDF and accepts PDF', () => {
31
- const d = mkdtempSync(join(tmpdir(), 'sv-'));
32
- const bad = join(d, 'x.pdf'); writeFileSync(bad, 'hello');
33
- assert.throws(() => buildUploadForm(bad), /Only PDF/);
34
- assert.throws(() => buildUploadForm(join(d, 'missing.pdf')), /not found/);
35
- const ok = join(d, 'ok.pdf'); writeFileSync(ok, '%PDF-1.4\n%%EOF');
36
- const f = buildUploadForm(ok, 'n');
37
- assert.equal(f.get('note'), 'n');
38
- assert.equal(f.get('file').name, 'ok.pdf');
39
- });
40
-
41
- import { readFileSync } from 'node:fs';
42
- import { fileURLToPath } from 'node:url';
43
- import { dirname, join as pjoin } from 'node:path';
44
- const root = pjoin(dirname(fileURLToPath(import.meta.url)), '..', '..');
45
- for (const f of ['mcp/staff-server.js', 'server/Velaro.Admin/Controllers/StaffMcpController.cs']) {
46
- test(`${f} registers sign_versions tools`, () => {
47
- const s = readFileSync(pjoin(root, f), 'utf8');
48
- for (const t of ['sign_versions_list', 'sign_versions_diff', 'sign_versions_upload']) assert.ok(s.includes(t), `${t} missing in ${f}`);
49
- });
50
- }
package/lib/sign.test.js DELETED
@@ -1,19 +0,0 @@
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
- });