ksef-client-ts 0.5.0 → 0.5.1
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/README.md +2 -1
- package/dist/cli.js +5053 -4332
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -526,7 +526,7 @@ declare const SchemaRegistry: {
|
|
|
526
526
|
* - Level 3: Business rules (NIP/PESEL checksum verification)
|
|
527
527
|
*/
|
|
528
528
|
|
|
529
|
-
type InvoiceValidationErrorCode = 'MALFORMED_XML' | 'MISSING_REQUIRED_ELEMENT' | 'INVALID_VALUE' | 'INVALID_ENUM_VALUE' | 'PATTERN_MISMATCH' | 'MAX_OCCURS_EXCEEDED' | 'UNKNOWN_SCHEMA' | 'SCHEMA_VALIDATION_ERROR' | 'INVALID_NIP_CHECKSUM' | 'INVALID_PESEL_CHECKSUM';
|
|
529
|
+
type InvoiceValidationErrorCode = 'MALFORMED_XML' | 'MISSING_REQUIRED_ELEMENT' | 'INVALID_VALUE' | 'INVALID_ENUM_VALUE' | 'PATTERN_MISMATCH' | 'MAX_OCCURS_EXCEEDED' | 'UNKNOWN_SCHEMA' | 'SCHEMA_VALIDATION_ERROR' | 'INVALID_NIP_CHECKSUM' | 'INVALID_PESEL_CHECKSUM' | 'FUTURE_INVOICE_DATE';
|
|
530
530
|
interface InvoiceValidationError {
|
|
531
531
|
/** Error classification code. */
|
|
532
532
|
code: InvoiceValidationErrorCode;
|
package/dist/index.d.ts
CHANGED
|
@@ -526,7 +526,7 @@ declare const SchemaRegistry: {
|
|
|
526
526
|
* - Level 3: Business rules (NIP/PESEL checksum verification)
|
|
527
527
|
*/
|
|
528
528
|
|
|
529
|
-
type InvoiceValidationErrorCode = 'MALFORMED_XML' | 'MISSING_REQUIRED_ELEMENT' | 'INVALID_VALUE' | 'INVALID_ENUM_VALUE' | 'PATTERN_MISMATCH' | 'MAX_OCCURS_EXCEEDED' | 'UNKNOWN_SCHEMA' | 'SCHEMA_VALIDATION_ERROR' | 'INVALID_NIP_CHECKSUM' | 'INVALID_PESEL_CHECKSUM';
|
|
529
|
+
type InvoiceValidationErrorCode = 'MALFORMED_XML' | 'MISSING_REQUIRED_ELEMENT' | 'INVALID_VALUE' | 'INVALID_ENUM_VALUE' | 'PATTERN_MISMATCH' | 'MAX_OCCURS_EXCEEDED' | 'UNKNOWN_SCHEMA' | 'SCHEMA_VALIDATION_ERROR' | 'INVALID_NIP_CHECKSUM' | 'INVALID_PESEL_CHECKSUM' | 'FUTURE_INVOICE_DATE';
|
|
530
530
|
interface InvoiceValidationError {
|
|
531
531
|
/** Error classification code. */
|
|
532
532
|
code: InvoiceValidationErrorCode;
|
package/dist/index.js
CHANGED
|
@@ -4292,6 +4292,7 @@ function validateBusinessRules(xml, _parsed) {
|
|
|
4292
4292
|
const schemaType = SchemaRegistry.detect(namespace, rootElement);
|
|
4293
4293
|
const errors = [];
|
|
4294
4294
|
collectNipPeselErrors(object, rootElement ? `/${rootElement}` : "", errors);
|
|
4295
|
+
collectDateErrors(object, rootElement, errors);
|
|
4295
4296
|
return { valid: errors.length === 0, schemaType, errors };
|
|
4296
4297
|
}
|
|
4297
4298
|
function collectNipPeselErrors(obj, path, errors) {
|
|
@@ -4326,6 +4327,24 @@ function collectNipPeselErrors(obj, path, errors) {
|
|
|
4326
4327
|
}
|
|
4327
4328
|
}
|
|
4328
4329
|
}
|
|
4330
|
+
function getPolandLocalDate() {
|
|
4331
|
+
return new Intl.DateTimeFormat("sv-SE", { timeZone: "Europe/Warsaw" }).format(Date.now());
|
|
4332
|
+
}
|
|
4333
|
+
function collectDateErrors(obj, rootElement, errors) {
|
|
4334
|
+
const fa = obj["Fa"];
|
|
4335
|
+
if (!fa || typeof fa !== "object") return;
|
|
4336
|
+
const p1 = fa["P_1"];
|
|
4337
|
+
if (typeof p1 !== "string") return;
|
|
4338
|
+
const today = getPolandLocalDate();
|
|
4339
|
+
if (p1 > today) {
|
|
4340
|
+
const prefix = rootElement ? `/${rootElement}` : "";
|
|
4341
|
+
errors.push({
|
|
4342
|
+
code: "FUTURE_INVOICE_DATE",
|
|
4343
|
+
message: `Invoice date P_1 (${p1}) is in the future \u2014 KSeF rejects invoices with P_1 > today (${today})`,
|
|
4344
|
+
path: `${prefix}/Fa/P_1`
|
|
4345
|
+
});
|
|
4346
|
+
}
|
|
4347
|
+
}
|
|
4329
4348
|
async function validate(xml, options) {
|
|
4330
4349
|
const parsed = xml && xml.trim() ? xmlToObject(xml) : void 0;
|
|
4331
4350
|
const l1 = validateWellFormedness(xml, parsed);
|