shaam-uniform-format-generator: 0.2.7 ships incomplete `dist/`, and negative document amounts and Z900 record counts fail round-trip validation

Aperta
#4,968 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
32/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
github-actions, node.js, typescript

Direzione di ricerca

Three separate defects; start by reproducing with the gist against packages/shaam-uniform-format-generator. For the tarball, compare packages/shaam-uniform-format-generator/tsconfig.json with the root one and .github/actions/setup / publish.yml caching, then check whether tslib belongs in dependencies. For the round trip, read src/api/generate-report.ts alongside the C100Schema and D120Schema regexes and performCrossFileValidation in src/api/parse-files.ts against documentation/c100.csv, d120.csv and z900.csv. Done means a clean npm pack with full dist/, credit notes surviving parse, and no z900_total_records error in strict mode.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
  1. @accounter/[email protected] (npm latest) and 0.2.8-alpha-20261114140432-e9aa0de37e9a114ea1f604b8f8b5284c6afa2581 cannot be imported.
    The published tarball has 87 files, and dist/ contains only dist/cjs/index.js and dist/esm/index.js (0.2.6 had 228 files including all submodules and dist/typings/). Importing the package in ESM or CJS fails immediately because ./types/index.js, ./api/generate-report.js, ./api/parse-files.js, etc. are missing. In addition, dist/cjs/index.js (including in 0.2.6) emits require("tslib") via root importHelpers: true, while tslib is not listed in dependencies.

  2. Negative document amounts (credit notes, as in the README Complete Example) are emitted by generateUniformFormatReport and rejected by parseUniformFormatFiles.
    On 0.2.6 and main (bce9563), generateUniformFormatReport writes document.amount.toFixed(2) (e.g. "-100.00" for a credit note type: '330') into C100.amountIncludingVat and D120.lineAmount and succeeds under validationMode: 'fail-fast'. When parsing back, C100Schema and D120Schema validate against /^(\d{1,13}(\.\d{2})?|)$/ (unsigned only), so parseC100 and parseD120 fail with severity: 'error' and drop the credit note from data.documents. (documentation/c100.csv field 1223 and documentation/d120.csv field 1312 also specify signed X9(12)V99.)

  3. Z900 total-records cross-validation is off by one on every generated or spec-compliant report.
    generate-report.ts writes totalRecords: records.length + 1, counting A100 through Z900 inclusive per SHAAM 1.31 field 1155 (documentation/z900.csv: "Includes opening and closing records"). In src/api/parse-files.ts, performCrossFileValidation computes actualDataRecords without Z900 (// Z900 doesn't count itself), so every generated report sets summary.crossValidationPassed = false with Z900 total records mismatch: expected N, found N-1 (which becomes severity: 'error' under validationMode: 'strict', such as in ShaamImportProvider).

Your Example Website or App

https://gist.github.com/trackoor/66d1588886dcaaca7bf35e69d0b3d81b

Steps to Reproduce the Bug or Issue

Broken import on 0.2.7:

npm i @accounter/[email protected]
node --input-type=module -e "import '@accounter/shaam-uniform-format-generator'"

Actual output:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/@accounter/shaam-uniform-format-generator/dist/esm/types/index.js' imported from .../node_modules/@accounter/shaam-uniform-format-generator/dist/esm/index.js

Round-trip failures on 0.2.6 and main (bce9563):

import {
  generateUniformFormatReport,
  parseUniformFormatFiles,
} from "@accounter/shaam-uniform-format-generator";

const report = generateUniformFormatReport(
  {
    business: {
      businessId: "12345",
      name: "Example Ltd",
      taxId: "123456789",
      reportingPeriod: { startDate: "2023-01-01", endDate: "2023-12-31" },
    },
    documents: [{ id: "CN-1", type: "330", date: "2023-06-15", amount: -100 }],
    journalEntries: [
      { id: "JE-1", date: "2023-06-15", amount: -100, accountId: "1100" },
    ],
    accounts: [
      {
        id: "1100",
        name: "Revenue",
        sortCode: { key: "400" },
        accountOpeningBalance: 0,
      },
    ],
    inventory: [],
  },
  { validationMode: "fail-fast" },
);

const parsed = parseUniformFormatFiles(report.iniText, report.dataText, {
  validationMode: "strict",
});
console.log("documents:", parsed.data.documents);
console.log("crossValidationPassed:", parsed.summary.crossValidationPassed);
console.log(
  "errors:",
  parsed.summary.errors.map(e => `[${e.recordType}] ${e.field}: ${e.message}`),
);

const positiveOnly = generateUniformFormatReport({
  business: {
    businessId: "12345",
    name: "Example Ltd",
    taxId: "123456789",
    reportingPeriod: { startDate: "2023-01-01", endDate: "2023-12-31" },
  },
  documents: [{ id: "INV-1", type: "305", date: "2023-06-15", amount: 100 }],
  journalEntries: [],
  accounts: [],
  inventory: [],
});
const parsedPositive = parseUniformFormatFiles(
  positiveOnly.iniText,
  positiveOnly.dataText,
  { validationMode: "strict" },
);
console.log(
  "positive-only errors:",
  parsedPositive.summary.errors.map(
    e => `[${e.recordType}] ${e.field}: ${e.message}`,
  ),
);

Actual output:

documents: []
crossValidationPassed: false
errors: [
  '[C100] parsing: Failed to parse C100 record: [\n' +
    '  {\n' +
    '    "origin": "string",\n' +
    '    "code": "invalid_format",\n' +
    '    "format": "regex",\n' +
    '    "pattern": "/^(\\\\d{1,13}(\\\\.\\\\d{2})?|)$/",\n' +
    '    "path": [\n' +
    '      "amountIncludingVat"\n' +
    '    ],\n' +
    '    "message": "Invalid string: must match pattern /^(\\\\d{1,13}(\\\\.\\\\d{2})?|)$/"\n' +
    '  }\n' +
    ']',
  '[D120] parsing: Failed to parse D120 record: [\n' +
    '  {\n' +
    '    "origin": "string",\n' +
    '    "code": "invalid_format",\n' +
    '    "format": "regex",\n' +
    '    "pattern": "/^(\\\\d{1,13}(\\\\.\\\\d{2})?|)$/",\n' +
    '    "path": [\n' +
    '      "lineAmount"\n' +
    '    ],\n' +
    '    "message": "Invalid string: must match pattern /^(\\\\d{1,13}(\\\\.\\\\d{2})?|)$/"\n' +
    '  }\n' +
    ']',
  '[CrossValidation] C100_count: Record count mismatch for C100: expected 1, found 0',
  '[CrossValidation] D120_count: Record count mismatch for D120: expected 1, found 0',
  '[CrossValidation] z900_total_records: Z900 total records mismatch: expected 7, found 4'
]
positive-only errors: [
  '[CrossValidation] z900_total_records: Z900 total records mismatch: expected 5, found 4'
]
Expected behavior
  • @accounter/shaam-uniform-format-generator ships the full compiled dist/ tree (including dist/typings/) and declares tslib if CJS output imports it, so ESM import and CJS require both succeed.
  • Credit notes / negative document amounts accepted by generateUniformFormatReport round-trip through parseUniformFormatFiles without C100/D120 schema failures.
  • performCrossFileValidation includes Z900 (1 closing record) when comparing against Z900.totalRecords, so generated and spec-compliant reports pass cross-validation (crossValidationPassed: true, no z900_total_records error in strict mode).
Screenshots or Videos

N/A

Platform
  • OS: Linux x64
  • NodeJS: v26.13.0
  • @accounter/shaam-uniform-format-generator: 0.2.7, 0.2.8-alpha-20261114140432-e9aa0de37e9a114ea1f604b8f8b5284c6afa2581, 0.2.6, and main (bce9563582631e35463190922188d68ad879715c)
Additional context

For the incomplete 0.2.7 / 0.2.8-alpha tarball: packages/shaam-uniform-format-generator/tsconfig.json extends root tsconfig.json without overriding incremental: true or tsBuildInfoFile: "./node_modules/.cache/tsbuildinfo/root.tsbuildinfo", which .github/actions/setup restores from cache in publish.yml over a fresh checkout with no dist.

Credit: https://ucsbplse.github.io/

Lingua principale
TypeScript
Stelle
30
Fork
10
Merge medio
2g 12h
PR unite (30g)
276

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Urigo/accounter-fullstack

Tutte le issue di Urigo/accounter-fullstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.