@jasy/cli 1.0.0-alpha.2 → 1.0.0-alpha.3
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/dist/commands/validate.js +13 -6
- package/package.json +1 -1
|
@@ -62,21 +62,25 @@ export function validateCommand(args) {
|
|
|
62
62
|
vera = null;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
// VALID requires that we actually recognised EN 16931 invoice data: a file we could not parse as an
|
|
66
|
+
// invoice (random bytes, or a plain PDF with no embedded XML) is "not an invoice" - never "valid".
|
|
67
|
+
const recognized = read.meta.syntax !== "unknown";
|
|
68
|
+
const ok = recognized && (!rules || rules.valid) && (!pdfa || pdfa.ok) && (!vera || vera.ok);
|
|
66
69
|
if (!ok)
|
|
67
70
|
process.exitCode = 1;
|
|
68
71
|
if (json) {
|
|
69
|
-
console.log(JSON.stringify(toJson(file, read, rules, pdfa, vera, ok)));
|
|
72
|
+
console.log(JSON.stringify(toJson(file, read, rules, pdfa, vera, recognized, ok)));
|
|
70
73
|
return;
|
|
71
74
|
}
|
|
72
|
-
printReport(file, read, rules, pdfa, vera, ok, verbose);
|
|
75
|
+
printReport(file, read, rules, pdfa, vera, recognized, ok, verbose);
|
|
73
76
|
}
|
|
74
77
|
/** The machine-readable report (`--json`): the exact same data the printed report shows. */
|
|
75
|
-
function toJson(file, read, rules, pdfa, vera, ok) {
|
|
78
|
+
function toJson(file, read, rules, pdfa, vera, recognized, ok) {
|
|
76
79
|
var _a;
|
|
77
80
|
return {
|
|
78
81
|
file: basename(file),
|
|
79
82
|
summary: describeInvoice(read.meta),
|
|
83
|
+
recognized,
|
|
80
84
|
valid: ok,
|
|
81
85
|
businessRules: rules && {
|
|
82
86
|
kind: rules.profile.startsWith("xrechnung") ? "XRechnung" : "EN 16931",
|
|
@@ -106,7 +110,7 @@ function toJson(file, read, rules, pdfa, vera, ok) {
|
|
|
106
110
|
};
|
|
107
111
|
}
|
|
108
112
|
/** The human-readable report (default): a coloured summary line + per-check detail. */
|
|
109
|
-
function printReport(file, read, rules, pdfa, vera, ok, verbose) {
|
|
113
|
+
function printReport(file, read, rules, pdfa, vera, recognized, ok, verbose) {
|
|
110
114
|
var _a;
|
|
111
115
|
const label = (s) => s.padEnd(20);
|
|
112
116
|
console.log(`\n ${bold(basename(file))} ${dim("·")} ${describeInvoice(read.meta)}\n`);
|
|
@@ -148,5 +152,8 @@ function printReport(file, read, rules, pdfa, vera, ok, verbose) {
|
|
|
148
152
|
else if (read.isPdf) {
|
|
149
153
|
console.log(` ${label("PDF/A (veraPDF)")}${dim("n/a - `jasy verapdf --install` for the full ISO check")}`);
|
|
150
154
|
}
|
|
151
|
-
|
|
155
|
+
if (!recognized)
|
|
156
|
+
console.log(`\n → ${red(bold("NOT A ZUGFeRD / XRECHNUNG INVOICE"))} ${dim("(no EN 16931 data found)")}\n`);
|
|
157
|
+
else
|
|
158
|
+
console.log(`\n → ${ok ? green(bold("VALID")) : red(bold("INVALID"))}\n`);
|
|
152
159
|
}
|