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

Open
#4,968 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
32/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
github-actions, node.js, typescript

Research direction

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.

Written by the indexing model from the issue text.

Description

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/

Dominant language
TypeScript
Stars
30
Forks
10
Avg merge
2d 12h
Merged PRs (30d)
276

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Urigo/accounter-fullstack

All issues in Urigo/accounter-fullstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.