@fin.cx/einvoice 5.1.4 → 5.2.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.
Files changed (118) hide show
  1. package/.smartconfig.json +59 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/einvoice.d.ts +14 -5
  4. package/dist_ts/einvoice.js +173 -66
  5. package/dist_ts/errors.js +14 -4
  6. package/dist_ts/formats/base/base.decoder.d.ts +4 -0
  7. package/dist_ts/formats/base/base.decoder.js +9 -1
  8. package/dist_ts/formats/base/base.validator.js +3 -2
  9. package/dist_ts/formats/cii/cii.decoder.d.ts +1 -0
  10. package/dist_ts/formats/cii/cii.decoder.js +20 -10
  11. package/dist_ts/formats/cii/cii.encoder.js +2 -5
  12. package/dist_ts/formats/cii/cii.validator.d.ts +1 -1
  13. package/dist_ts/formats/cii/cii.validator.js +19 -12
  14. package/dist_ts/formats/cii/facturx/facturx.encoder.js +25 -16
  15. package/dist_ts/formats/converters/xml-to-einvoice.converter.js +3 -3
  16. package/dist_ts/formats/factories/decoder.factory.d.ts +3 -1
  17. package/dist_ts/formats/factories/decoder.factory.js +4 -3
  18. package/dist_ts/formats/factories/validator.factory.d.ts +4 -1
  19. package/dist_ts/formats/factories/validator.factory.js +11 -8
  20. package/dist_ts/formats/pdf/extractors/associated.extractor.js +3 -2
  21. package/dist_ts/formats/pdf/extractors/base.extractor.d.ts +1 -1
  22. package/dist_ts/formats/pdf/extractors/base.extractor.js +50 -52
  23. package/dist_ts/formats/pdf/extractors/standard.extractor.js +3 -2
  24. package/dist_ts/formats/pdf/extractors/text.extractor.js +19 -22
  25. package/dist_ts/formats/pdf/pdf.embedder.js +3 -2
  26. package/dist_ts/formats/pdf/pdf.extractor.d.ts +2 -1
  27. package/dist_ts/formats/pdf/pdf.extractor.js +20 -10
  28. package/dist_ts/formats/semantic/semantic.adapter.js +42 -12
  29. package/dist_ts/formats/semantic/semantic.validator.js +3 -1
  30. package/dist_ts/formats/ubl/en16931.ubl.validator.js +5 -3
  31. package/dist_ts/formats/ubl/generic/ubl.encoder.js +11 -7
  32. package/dist_ts/formats/ubl/ubl.decoder.d.ts +1 -0
  33. package/dist_ts/formats/ubl/ubl.decoder.js +18 -8
  34. package/dist_ts/formats/ubl/ubl.validator.d.ts +1 -1
  35. package/dist_ts/formats/ubl/ubl.validator.js +17 -10
  36. package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.js +37 -29
  37. package/dist_ts/formats/utils/currency.calculator.decimal.js +4 -1
  38. package/dist_ts/formats/utils/currency.utils.js +4 -1
  39. package/dist_ts/formats/utils/decimal.js +9 -2
  40. package/dist_ts/formats/utils/format.detector.js +47 -17
  41. package/dist_ts/formats/validation/codelist.validator.js +2 -4
  42. package/dist_ts/formats/validation/conformance.harness.js +13 -6
  43. package/dist_ts/formats/validation/en16931.business-rules.validator.js +4 -4
  44. package/dist_ts/formats/validation/en16931.validator.d.ts +6 -0
  45. package/dist_ts/formats/validation/en16931.validator.js +18 -12
  46. package/dist_ts/formats/validation/facturx.validator.js +147 -148
  47. package/dist_ts/formats/validation/integrated.validator.js +12 -4
  48. package/dist_ts/formats/validation/peppol.validator.js +2 -1
  49. package/dist_ts/formats/validation/schematron.downloader.d.ts +0 -1
  50. package/dist_ts/formats/validation/schematron.downloader.js +12 -7
  51. package/dist_ts/formats/validation/schematron.integration.js +16 -6
  52. package/dist_ts/formats/validation/schematron.validator.d.ts +9 -11
  53. package/dist_ts/formats/validation/schematron.validator.js +70 -72
  54. package/dist_ts/formats/validation/schematron.worker.d.ts +7 -6
  55. package/dist_ts/formats/validation/schematron.worker.js +48 -42
  56. package/dist_ts/formats/validation/vat-categories.validator.js +3 -4
  57. package/dist_ts/formats/validation/xrechnung.validator.js +7 -7
  58. package/dist_ts/index.js +3 -2
  59. package/dist_ts/interfaces/common.js +1 -2
  60. package/dist_ts/plugins.d.ts +3 -6
  61. package/dist_ts/plugins.js +3 -12
  62. package/dist_ts/vendor/pako.d.ts +5 -0
  63. package/dist_ts/vendor/pako.js +3 -0
  64. package/dist_ts/vendor/pdflib.d.ts +2 -0
  65. package/dist_ts/vendor/pdflib.js +9 -0
  66. package/dist_ts/vendor/saxonjs.d.ts +23 -0
  67. package/dist_ts/vendor/saxonjs.js +9 -0
  68. package/dist_ts/vendor/xmldom.d.ts +20 -0
  69. package/dist_ts/vendor/xmldom.js +5 -0
  70. package/dist_ts_install/download-schematron.d.ts +0 -3
  71. package/dist_ts_install/download-schematron.js +20 -11
  72. package/dist_ts_install/download-test-samples.d.ts +0 -3
  73. package/dist_ts_install/download-test-samples.js +4 -2
  74. package/dist_ts_install/download-xrechnung-rules.js +2 -1
  75. package/dist_ts_install/index.d.ts +0 -5
  76. package/dist_ts_install/index.js +26 -12
  77. package/license +21 -0
  78. package/package.json +21 -15
  79. package/readme.hints.md +24 -8
  80. package/readme.md +195 -328
  81. package/ts/00_commitinfo_data.ts +1 -1
  82. package/ts/einvoice.ts +156 -33
  83. package/ts/formats/base/base.decoder.ts +7 -0
  84. package/ts/formats/cii/cii.decoder.ts +17 -8
  85. package/ts/formats/cii/cii.validator.ts +18 -13
  86. package/ts/formats/cii/facturx/facturx.encoder.ts +25 -15
  87. package/ts/formats/converters/xml-to-einvoice.converter.ts +4 -5
  88. package/ts/formats/factories/decoder.factory.ts +7 -2
  89. package/ts/formats/factories/validator.factory.ts +14 -8
  90. package/ts/formats/pdf/extractors/associated.extractor.ts +2 -1
  91. package/ts/formats/pdf/extractors/base.extractor.ts +3 -2
  92. package/ts/formats/pdf/extractors/standard.extractor.ts +2 -1
  93. package/ts/formats/pdf/pdf.embedder.ts +6 -3
  94. package/ts/formats/pdf/pdf.extractor.ts +24 -16
  95. package/ts/formats/semantic/semantic.adapter.ts +49 -15
  96. package/ts/formats/ubl/en16931.ubl.validator.ts +5 -3
  97. package/ts/formats/ubl/generic/ubl.encoder.ts +12 -7
  98. package/ts/formats/ubl/ubl.decoder.ts +18 -9
  99. package/ts/formats/ubl/ubl.validator.ts +17 -12
  100. package/ts/formats/ubl/xrechnung/xrechnung.decoder.ts +41 -28
  101. package/ts/formats/utils/format.detector.ts +57 -19
  102. package/ts/formats/validation/conformance.harness.ts +6 -4
  103. package/ts/formats/validation/en16931.validator.ts +20 -10
  104. package/ts/formats/validation/integrated.validator.ts +5 -3
  105. package/ts/formats/validation/schematron.downloader.ts +11 -8
  106. package/ts/formats/validation/schematron.integration.ts +11 -5
  107. package/ts/formats/validation/schematron.validator.ts +79 -79
  108. package/ts/formats/validation/schematron.worker.ts +59 -41
  109. package/ts/index.ts +2 -1
  110. package/ts/interfaces/common.ts +1 -3
  111. package/ts/plugins.ts +2 -29
  112. package/ts/readme.md +76 -0
  113. package/ts/vendor/modules.d.ts +32 -0
  114. package/ts/vendor/pako.ts +8 -0
  115. package/ts/vendor/pdflib.ts +12 -0
  116. package/ts/vendor/saxonjs.ts +36 -0
  117. package/ts/vendor/xmldom.ts +27 -0
  118. package/npmextra.json +0 -35
package/ts/plugins.ts CHANGED
@@ -9,27 +9,12 @@ import * as fs from 'fs/promises';
9
9
  import * as path from 'path';
10
10
  import * as crypto from 'crypto';
11
11
 
12
- // PDF-related imports
13
- import {
14
- PDFDocument,
15
- PDFDict,
16
- PDFName,
17
- PDFRawStream,
18
- PDFArray,
19
- PDFString,
20
- AFRelationship
21
- } from 'pdf-lib';
22
-
23
12
  // XML-related imports
24
- import { DOMParser, XMLSerializer } from 'xmldom';
25
- import * as xmldom from 'xmldom';
13
+ import { DOMParser, XMLSerializer, xmldom } from './vendor/xmldom.js';
26
14
  import * as xpath from 'xpath';
27
15
 
28
- // XSLT/Schematron imports
29
- import * as SaxonJS from 'saxon-js';
30
-
31
16
  // Compression-related imports
32
- import * as pako from 'pako';
17
+ import { pako } from './vendor/pako.js';
33
18
 
34
19
  // Business model imports
35
20
  import { business, finance, general } from '@tsclass/tsclass';
@@ -41,24 +26,12 @@ export {
41
26
  path,
42
27
  crypto,
43
28
 
44
- // PDF-lib exports
45
- PDFDocument,
46
- PDFDict,
47
- PDFName,
48
- PDFRawStream,
49
- PDFArray,
50
- PDFString,
51
- AFRelationship,
52
-
53
29
  // XML-related exports
54
30
  DOMParser,
55
31
  XMLSerializer,
56
32
  xmldom,
57
33
  xpath,
58
34
 
59
- // XSLT/Schematron exports
60
- SaxonJS,
61
-
62
35
  // Compression-related exports
63
36
  pako,
64
37
 
package/ts/readme.md ADDED
@@ -0,0 +1,76 @@
1
+ # @fin.cx/einvoice
2
+
3
+ Source module for the main `@fin.cx/einvoice` package.
4
+
5
+ This directory contains the public TypeScript API for loading, validating, converting, and embedding European e-invoice XML.
6
+
7
+ ## Issue Reporting and Security
8
+
9
+ For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
10
+
11
+ ## What this module exports
12
+
13
+ - `EInvoice`
14
+ - `createEInvoice()`
15
+ - `validateXml(xml, level?)`
16
+ - `FormatDetector`
17
+ - `PDFExtractor`, `PDFEmbedder`
18
+ - `DecoderFactory`, `EncoderFactory`, `ValidatorFactory`
19
+ - `BaseDecoder`, `BaseEncoder`, `BaseValidator`
20
+ - `UBLBase*` and `CIIBase*` extension points
21
+ - Factur-X and ZUGFeRD format-specific classes
22
+ - root types such as `TInvoice`, `ValidationResult`, `ExportFormat`, `IPdf`
23
+
24
+ ## Main workflow
25
+
26
+ ```ts
27
+ import { EInvoice, ValidationLevel } from '@fin.cx/einvoice';
28
+
29
+ const invoice = await EInvoice.fromFile('./invoice.xml');
30
+ const validation = await invoice.validate(ValidationLevel.BUSINESS);
31
+ const xml = await invoice.exportXml('facturx');
32
+ ```
33
+
34
+ ## Format support
35
+
36
+ | Format | Detect | Import | Export | Notes |
37
+ | --- | --- | --- | --- | --- |
38
+ | `ubl` | Yes | Yes | Yes | Generic UBL flow |
39
+ | `xrechnung` | Yes | Yes | Yes | UBL-based profile |
40
+ | `cii` | Yes | Yes | Yes | Generic export currently routes through the Factur-X encoder path |
41
+ | `facturx` | Yes | Yes | Yes | Main CII generation path |
42
+ | `zugferd` | Yes | Yes | Yes | Input supports v1 and v2+ |
43
+ | `fatturapa` | Yes | No | No | Detection only at the moment |
44
+
45
+ ## Important implementation notes
46
+
47
+ - `peppol` is not a root-level XML export target.
48
+ - `FatturaPA` is not fully implemented for import/export.
49
+ - PDF support means extracting or embedding XML into existing PDFs, not generating invoice PDFs from scratch.
50
+ - Validation is useful and extensive, but should not be documented as blanket certification.
51
+
52
+ ## Related directories
53
+
54
+ - `../readme.md`: full package README for end users
55
+ - `../ts_install/readme.md`: install-time resource bootstrap module
56
+
57
+ ## License and Legal Information
58
+
59
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](../license) file.
60
+
61
+ **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
62
+
63
+ ### Trademarks
64
+
65
+ This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
66
+
67
+ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
68
+
69
+ ### Company Information
70
+
71
+ Task Venture Capital GmbH<br>
72
+ Registered at District Court Bremen HRB 35230 HB, Germany
73
+
74
+ For any legal inquiries or further information, please contact us via email at hello@task.vc.
75
+
76
+ By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
@@ -0,0 +1,32 @@
1
+ declare module 'xmldom' {
2
+ export class DOMParser {
3
+ parseFromString(source: string, mimeType: string): Document;
4
+ }
5
+
6
+ export class XMLSerializer {
7
+ serializeToString(node: Node): string;
8
+ }
9
+ }
10
+
11
+ declare module 'pako' {
12
+ export function inflate(input: Uint8Array | ArrayBuffer | string, options?: unknown): Uint8Array;
13
+ }
14
+
15
+ declare module 'saxon-js' {
16
+ export function compile(options: {
17
+ stylesheetText: string;
18
+ warnings?: string;
19
+ [key: string]: unknown;
20
+ }): Promise<unknown>;
21
+
22
+ export function transform(options: {
23
+ stylesheetInternal?: unknown;
24
+ sourceText: string;
25
+ destination?: string;
26
+ stylesheetParams?: Record<string, unknown>;
27
+ [key: string]: unknown;
28
+ }): Promise<{
29
+ principalResult: string;
30
+ [key: string]: unknown;
31
+ }>;
32
+ }
@@ -0,0 +1,8 @@
1
+ import * as pakoRuntime from 'pako';
2
+
3
+ export interface IPakoModule {
4
+ inflate(input: Uint8Array | ArrayBuffer | string, options?: unknown): Uint8Array;
5
+ [key: string]: unknown;
6
+ }
7
+
8
+ export const pako: IPakoModule = pakoRuntime as unknown as IPakoModule;
@@ -0,0 +1,12 @@
1
+ export type TPdfLibModule = typeof import('pdf-lib');
2
+
3
+ let cachedPdfLib: Promise<TPdfLibModule> | undefined;
4
+
5
+ // Use pdf-lib's bundled UMD build; the package entry requires JSON font assets,
6
+ // which some TS runners corrupt with require hooks.
7
+ const nativeImport = Function('specifier', 'return import(specifier)') as (specifier: string) => Promise<TPdfLibModule>;
8
+
9
+ export const loadPdfLib = async (): Promise<TPdfLibModule> => {
10
+ cachedPdfLib ||= nativeImport('pdf-lib/dist/pdf-lib.js');
11
+ return cachedPdfLib;
12
+ };
@@ -0,0 +1,36 @@
1
+ export interface ISaxonJSCompileOptions {
2
+ stylesheetText: string;
3
+ warnings?: string;
4
+ [key: string]: unknown;
5
+ }
6
+
7
+ export interface ISaxonJSTransformOptions {
8
+ stylesheetInternal?: unknown;
9
+ stylesheetFileName?: string;
10
+ sourceText: string;
11
+ destination?: string;
12
+ stylesheetParams?: Record<string, unknown>;
13
+ [key: string]: unknown;
14
+ }
15
+
16
+ export interface ISaxonJSTransformResult {
17
+ principalResult: string;
18
+ [key: string]: unknown;
19
+ }
20
+
21
+ export interface ISaxonJSModule {
22
+ compile?: (options: ISaxonJSCompileOptions) => Promise<unknown>;
23
+ transform(options: ISaxonJSTransformOptions, executionMode?: 'async' | 'sync'): Promise<ISaxonJSTransformResult> | ISaxonJSTransformResult;
24
+ [key: string]: unknown;
25
+ }
26
+
27
+ let cachedSaxonJS: Promise<ISaxonJSModule> | undefined;
28
+
29
+ export const loadSaxonJS = async (): Promise<ISaxonJSModule> => {
30
+ cachedSaxonJS ||= import('saxon-js').then((saxonJSRuntime) => {
31
+ const runtime = (saxonJSRuntime as any).default ?? saxonJSRuntime;
32
+ return runtime as ISaxonJSModule;
33
+ });
34
+
35
+ return cachedSaxonJS;
36
+ };
@@ -0,0 +1,27 @@
1
+ import * as xmldomRuntime from 'xmldom';
2
+
3
+ export interface IDOMParser {
4
+ parseFromString(source: string, mimeType: string): Document;
5
+ }
6
+
7
+ export interface IDOMParserConstructor {
8
+ new (): IDOMParser;
9
+ }
10
+
11
+ export interface IXMLSerializer {
12
+ serializeToString(node: Node): string;
13
+ }
14
+
15
+ export interface IXMLSerializerConstructor {
16
+ new (): IXMLSerializer;
17
+ }
18
+
19
+ export interface IXmlDomModule {
20
+ DOMParser: IDOMParserConstructor;
21
+ XMLSerializer: IXMLSerializerConstructor;
22
+ [key: string]: unknown;
23
+ }
24
+
25
+ export const DOMParser: IDOMParserConstructor = xmldomRuntime.DOMParser as unknown as IDOMParserConstructor;
26
+ export const XMLSerializer: IXMLSerializerConstructor = xmldomRuntime.XMLSerializer as unknown as IXMLSerializerConstructor;
27
+ export const xmldom: IXmlDomModule = xmldomRuntime as unknown as IXmlDomModule;
package/npmextra.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "gitzone": {
3
- "projectType": "npm",
4
- "module": {
5
- "githost": "code.foss.global",
6
- "gitscope": "fin.cx",
7
- "gitrepo": "xinvoice",
8
- "description": "A TypeScript module for creating, manipulating, and embedding XML data within PDF files specifically tailored for xinvoice packages.",
9
- "npmPackagename": "@fin.cx/xinvoice",
10
- "license": "MIT",
11
- "projectDomain": "fin.cx",
12
- "keywords": [
13
- "xinvoice",
14
- "XML embedding",
15
- "PDF manipulation",
16
- "invoice processing",
17
- "financial documents",
18
- "document generation",
19
- "typescript",
20
- "ZUGFeRD",
21
- "XML parsing",
22
- "PDF library",
23
- "esm",
24
- "financial technology"
25
- ]
26
- }
27
- },
28
- "npmci": {
29
- "npmGlobalTools": [],
30
- "npmAccessLevel": "public"
31
- },
32
- "tsdoc": {
33
- "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
34
- }
35
- }