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/dist/index.cjs CHANGED
@@ -4456,6 +4456,7 @@ function validateBusinessRules(xml, _parsed) {
4456
4456
  const schemaType = SchemaRegistry.detect(namespace, rootElement);
4457
4457
  const errors = [];
4458
4458
  collectNipPeselErrors(object, rootElement ? `/${rootElement}` : "", errors);
4459
+ collectDateErrors(object, rootElement, errors);
4459
4460
  return { valid: errors.length === 0, schemaType, errors };
4460
4461
  }
4461
4462
  function collectNipPeselErrors(obj, path, errors) {
@@ -4490,6 +4491,24 @@ function collectNipPeselErrors(obj, path, errors) {
4490
4491
  }
4491
4492
  }
4492
4493
  }
4494
+ function getPolandLocalDate() {
4495
+ return new Intl.DateTimeFormat("sv-SE", { timeZone: "Europe/Warsaw" }).format(Date.now());
4496
+ }
4497
+ function collectDateErrors(obj, rootElement, errors) {
4498
+ const fa = obj["Fa"];
4499
+ if (!fa || typeof fa !== "object") return;
4500
+ const p1 = fa["P_1"];
4501
+ if (typeof p1 !== "string") return;
4502
+ const today = getPolandLocalDate();
4503
+ if (p1 > today) {
4504
+ const prefix = rootElement ? `/${rootElement}` : "";
4505
+ errors.push({
4506
+ code: "FUTURE_INVOICE_DATE",
4507
+ message: `Invoice date P_1 (${p1}) is in the future \u2014 KSeF rejects invoices with P_1 > today (${today})`,
4508
+ path: `${prefix}/Fa/P_1`
4509
+ });
4510
+ }
4511
+ }
4493
4512
  async function validate(xml, options) {
4494
4513
  const parsed = xml && xml.trim() ? xmlToObject(xml) : void 0;
4495
4514
  const l1 = validateWellFormedness(xml, parsed);