@fin.cx/einvoice 5.0.2

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 (171) hide show
  1. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  2. package/dist_ts/00_commitinfo_data.js +9 -0
  3. package/dist_ts/classes.decoder.d.ts +40 -0
  4. package/dist_ts/classes.decoder.js +320 -0
  5. package/dist_ts/classes.encoder.d.ts +51 -0
  6. package/dist_ts/classes.encoder.js +293 -0
  7. package/dist_ts/classes.xinvoice.d.ts +136 -0
  8. package/dist_ts/classes.xinvoice.js +352 -0
  9. package/dist_ts/einvoice.d.ts +217 -0
  10. package/dist_ts/einvoice.js +505 -0
  11. package/dist_ts/errors.d.ts +121 -0
  12. package/dist_ts/errors.js +241 -0
  13. package/dist_ts/formats/base/base.decoder.d.ts +32 -0
  14. package/dist_ts/formats/base/base.decoder.js +52 -0
  15. package/dist_ts/formats/base/base.encoder.d.ts +13 -0
  16. package/dist_ts/formats/base/base.encoder.js +7 -0
  17. package/dist_ts/formats/base/base.validator.d.ts +44 -0
  18. package/dist_ts/formats/base/base.validator.js +39 -0
  19. package/dist_ts/formats/base.decoder.d.ts +19 -0
  20. package/dist_ts/formats/base.decoder.js +130 -0
  21. package/dist_ts/formats/base.validator.d.ts +44 -0
  22. package/dist_ts/formats/base.validator.js +39 -0
  23. package/dist_ts/formats/cii/cii.decoder.d.ts +61 -0
  24. package/dist_ts/formats/cii/cii.decoder.js +111 -0
  25. package/dist_ts/formats/cii/cii.encoder.d.ts +43 -0
  26. package/dist_ts/formats/cii/cii.encoder.js +48 -0
  27. package/dist_ts/formats/cii/cii.types.d.ts +31 -0
  28. package/dist_ts/formats/cii/cii.types.js +40 -0
  29. package/dist_ts/formats/cii/cii.validator.d.ts +56 -0
  30. package/dist_ts/formats/cii/cii.validator.js +146 -0
  31. package/dist_ts/formats/cii/facturx/facturx.decoder.d.ts +43 -0
  32. package/dist_ts/formats/cii/facturx/facturx.decoder.js +207 -0
  33. package/dist_ts/formats/cii/facturx/facturx.encoder.d.ts +82 -0
  34. package/dist_ts/formats/cii/facturx/facturx.encoder.js +400 -0
  35. package/dist_ts/formats/cii/facturx/facturx.types.d.ts +10 -0
  36. package/dist_ts/formats/cii/facturx/facturx.types.js +15 -0
  37. package/dist_ts/formats/cii/facturx/facturx.validator.d.ts +32 -0
  38. package/dist_ts/formats/cii/facturx/facturx.validator.js +138 -0
  39. package/dist_ts/formats/cii/zugferd/zugferd.decoder.d.ts +43 -0
  40. package/dist_ts/formats/cii/zugferd/zugferd.decoder.js +218 -0
  41. package/dist_ts/formats/cii/zugferd/zugferd.encoder.d.ts +97 -0
  42. package/dist_ts/formats/cii/zugferd/zugferd.encoder.js +550 -0
  43. package/dist_ts/formats/cii/zugferd/zugferd.types.d.ts +10 -0
  44. package/dist_ts/formats/cii/zugferd/zugferd.types.js +15 -0
  45. package/dist_ts/formats/cii/zugferd/zugferd.v1.decoder.d.ts +49 -0
  46. package/dist_ts/formats/cii/zugferd/zugferd.v1.decoder.js +229 -0
  47. package/dist_ts/formats/cii/zugferd/zugferd.validator.d.ts +16 -0
  48. package/dist_ts/formats/cii/zugferd/zugferd.validator.js +29 -0
  49. package/dist_ts/formats/decoder.factory.d.ts +15 -0
  50. package/dist_ts/formats/decoder.factory.js +46 -0
  51. package/dist_ts/formats/factories/decoder.factory.d.ts +13 -0
  52. package/dist_ts/formats/factories/decoder.factory.js +56 -0
  53. package/dist_ts/formats/factories/encoder.factory.d.ts +14 -0
  54. package/dist_ts/formats/factories/encoder.factory.js +40 -0
  55. package/dist_ts/formats/factories/validator.factory.d.ts +12 -0
  56. package/dist_ts/formats/factories/validator.factory.js +110 -0
  57. package/dist_ts/formats/factorx.decoder.d.ts +18 -0
  58. package/dist_ts/formats/factorx.decoder.js +178 -0
  59. package/dist_ts/formats/factorx.encoder.d.ts +51 -0
  60. package/dist_ts/formats/factorx.encoder.js +293 -0
  61. package/dist_ts/formats/facturx.decoder.d.ts +18 -0
  62. package/dist_ts/formats/facturx.decoder.js +210 -0
  63. package/dist_ts/formats/facturx.encoder.d.ts +51 -0
  64. package/dist_ts/formats/facturx.encoder.js +293 -0
  65. package/dist_ts/formats/facturx.validator.d.ts +67 -0
  66. package/dist_ts/formats/facturx.validator.js +266 -0
  67. package/dist_ts/formats/pdf/extractors/associated.extractor.d.ts +14 -0
  68. package/dist_ts/formats/pdf/extractors/associated.extractor.js +68 -0
  69. package/dist_ts/formats/pdf/extractors/base.extractor.d.ts +92 -0
  70. package/dist_ts/formats/pdf/extractors/base.extractor.js +319 -0
  71. package/dist_ts/formats/pdf/extractors/index.d.ts +4 -0
  72. package/dist_ts/formats/pdf/extractors/index.js +5 -0
  73. package/dist_ts/formats/pdf/extractors/standard.extractor.d.ts +13 -0
  74. package/dist_ts/formats/pdf/extractors/standard.extractor.js +74 -0
  75. package/dist_ts/formats/pdf/extractors/text.extractor.d.ts +45 -0
  76. package/dist_ts/formats/pdf/extractors/text.extractor.js +151 -0
  77. package/dist_ts/formats/pdf/pdf.embedder.d.ts +69 -0
  78. package/dist_ts/formats/pdf/pdf.embedder.js +183 -0
  79. package/dist_ts/formats/pdf/pdf.extractor.d.ts +49 -0
  80. package/dist_ts/formats/pdf/pdf.extractor.js +98 -0
  81. package/dist_ts/formats/pdf/robust-pdf.extractor.d.ts +40 -0
  82. package/dist_ts/formats/pdf/robust-pdf.extractor.js +324 -0
  83. package/dist_ts/formats/ubl/en16931.ubl.validator.d.ts +18 -0
  84. package/dist_ts/formats/ubl/en16931.ubl.validator.js +169 -0
  85. package/dist_ts/formats/ubl/generic/ubl.encoder.d.ts +151 -0
  86. package/dist_ts/formats/ubl/generic/ubl.encoder.js +892 -0
  87. package/dist_ts/formats/ubl/ubl.decoder.d.ts +61 -0
  88. package/dist_ts/formats/ubl/ubl.decoder.js +95 -0
  89. package/dist_ts/formats/ubl/ubl.encoder.d.ts +38 -0
  90. package/dist_ts/formats/ubl/ubl.encoder.js +46 -0
  91. package/dist_ts/formats/ubl/ubl.types.d.ts +16 -0
  92. package/dist_ts/formats/ubl/ubl.types.js +21 -0
  93. package/dist_ts/formats/ubl/ubl.validator.d.ts +50 -0
  94. package/dist_ts/formats/ubl/ubl.validator.js +112 -0
  95. package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.d.ts +34 -0
  96. package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.js +424 -0
  97. package/dist_ts/formats/ubl/xrechnung/xrechnung.encoder.d.ts +75 -0
  98. package/dist_ts/formats/ubl/xrechnung/xrechnung.encoder.js +555 -0
  99. package/dist_ts/formats/ubl/xrechnung.validator.d.ts +15 -0
  100. package/dist_ts/formats/ubl/xrechnung.validator.js +107 -0
  101. package/dist_ts/formats/ubl.validator.d.ts +82 -0
  102. package/dist_ts/formats/ubl.validator.js +306 -0
  103. package/dist_ts/formats/utils/format.detector.d.ts +62 -0
  104. package/dist_ts/formats/utils/format.detector.js +249 -0
  105. package/dist_ts/formats/validation/en16931.validator.d.ts +23 -0
  106. package/dist_ts/formats/validation/en16931.validator.js +119 -0
  107. package/dist_ts/formats/validator.factory.d.ts +18 -0
  108. package/dist_ts/formats/validator.factory.js +78 -0
  109. package/dist_ts/formats/xinvoice.decoder.d.ts +28 -0
  110. package/dist_ts/formats/xinvoice.decoder.js +332 -0
  111. package/dist_ts/formats/xinvoice.encoder.d.ts +19 -0
  112. package/dist_ts/formats/xinvoice.encoder.js +282 -0
  113. package/dist_ts/index.d.ts +51 -0
  114. package/dist_ts/index.js +90 -0
  115. package/dist_ts/interfaces/common.d.ts +79 -0
  116. package/dist_ts/interfaces/common.js +24 -0
  117. package/dist_ts/interfaces.d.ts +87 -0
  118. package/dist_ts/interfaces.js +23 -0
  119. package/dist_ts/plugins.d.ts +14 -0
  120. package/dist_ts/plugins.js +31 -0
  121. package/npmextra.json +35 -0
  122. package/package.json +71 -0
  123. package/readme.hints.md +1107 -0
  124. package/readme.howtofixtests.md +38 -0
  125. package/readme.literature.md +1 -0
  126. package/readme.md +998 -0
  127. package/readme.plan.md +481 -0
  128. package/ts/00_commitinfo_data.ts +8 -0
  129. package/ts/einvoice.ts +603 -0
  130. package/ts/errors.ts +341 -0
  131. package/ts/formats/base/base.decoder.ts +68 -0
  132. package/ts/formats/base/base.encoder.ts +14 -0
  133. package/ts/formats/base/base.validator.ts +64 -0
  134. package/ts/formats/cii/cii.decoder.ts +139 -0
  135. package/ts/formats/cii/cii.encoder.ts +64 -0
  136. package/ts/formats/cii/cii.types.ts +44 -0
  137. package/ts/formats/cii/cii.validator.ts +171 -0
  138. package/ts/formats/cii/facturx/facturx.decoder.ts +243 -0
  139. package/ts/formats/cii/facturx/facturx.encoder.ts +483 -0
  140. package/ts/formats/cii/facturx/facturx.types.ts +18 -0
  141. package/ts/formats/cii/facturx/facturx.validator.ts +180 -0
  142. package/ts/formats/cii/zugferd/zugferd.decoder.ts +256 -0
  143. package/ts/formats/cii/zugferd/zugferd.encoder.ts +661 -0
  144. package/ts/formats/cii/zugferd/zugferd.types.ts +18 -0
  145. package/ts/formats/cii/zugferd/zugferd.v1.decoder.ts +267 -0
  146. package/ts/formats/cii/zugferd/zugferd.validator.ts +31 -0
  147. package/ts/formats/factories/decoder.factory.ts +62 -0
  148. package/ts/formats/factories/encoder.factory.ts +47 -0
  149. package/ts/formats/factories/validator.factory.ts +134 -0
  150. package/ts/formats/pdf/extractors/associated.extractor.ts +78 -0
  151. package/ts/formats/pdf/extractors/base.extractor.ts +355 -0
  152. package/ts/formats/pdf/extractors/index.ts +4 -0
  153. package/ts/formats/pdf/extractors/standard.extractor.ts +86 -0
  154. package/ts/formats/pdf/extractors/text.extractor.ts +162 -0
  155. package/ts/formats/pdf/pdf.embedder.ts +242 -0
  156. package/ts/formats/pdf/pdf.extractor.ts +141 -0
  157. package/ts/formats/ubl/en16931.ubl.validator.ts +216 -0
  158. package/ts/formats/ubl/generic/ubl.encoder.ts +1041 -0
  159. package/ts/formats/ubl/ubl.decoder.ts +121 -0
  160. package/ts/formats/ubl/ubl.encoder.ts +63 -0
  161. package/ts/formats/ubl/ubl.types.ts +22 -0
  162. package/ts/formats/ubl/ubl.validator.ts +133 -0
  163. package/ts/formats/ubl/xrechnung/xrechnung.decoder.ts +471 -0
  164. package/ts/formats/ubl/xrechnung/xrechnung.encoder.ts +619 -0
  165. package/ts/formats/ubl/xrechnung.validator.ts +185 -0
  166. package/ts/formats/utils/format.detector.ts +306 -0
  167. package/ts/formats/validation/en16931.validator.ts +135 -0
  168. package/ts/index.ts +164 -0
  169. package/ts/interfaces/common.ts +90 -0
  170. package/ts/interfaces.ts +98 -0
  171. package/ts/plugins.ts +61 -0
package/ts/index.ts ADDED
@@ -0,0 +1,164 @@
1
+ // Import main class
2
+ import { EInvoice } from './einvoice.js';
3
+
4
+ // Import interfaces
5
+ import * as common from './interfaces/common.js';
6
+
7
+ // Import factories
8
+ import { DecoderFactory } from './formats/factories/decoder.factory.js';
9
+ import { EncoderFactory } from './formats/factories/encoder.factory.js';
10
+ import { ValidatorFactory } from './formats/factories/validator.factory.js';
11
+
12
+ // Import base classes
13
+ import { BaseDecoder } from './formats/base/base.decoder.js';
14
+ import { BaseEncoder } from './formats/base/base.encoder.js';
15
+ import { BaseValidator } from './formats/base/base.validator.js';
16
+
17
+ // Import UBL base classes
18
+ import { UBLBaseDecoder } from './formats/ubl/ubl.decoder.js';
19
+ import { UBLBaseEncoder } from './formats/ubl/ubl.encoder.js';
20
+ import { UBLBaseValidator } from './formats/ubl/ubl.validator.js';
21
+
22
+ // Import CII base classes
23
+ import { CIIBaseDecoder } from './formats/cii/cii.decoder.js';
24
+ import { CIIBaseEncoder } from './formats/cii/cii.encoder.js';
25
+ import { CIIBaseValidator } from './formats/cii/cii.validator.js';
26
+
27
+ // Import PDF utilities
28
+ import { PDFEmbedder } from './formats/pdf/pdf.embedder.js';
29
+ import { PDFExtractor } from './formats/pdf/pdf.extractor.js';
30
+ import {
31
+ BaseXMLExtractor,
32
+ StandardXMLExtractor,
33
+ AssociatedFilesExtractor,
34
+ TextXMLExtractor
35
+ } from './formats/pdf/extractors/index.js';
36
+
37
+ // Import format detector
38
+ import { FormatDetector } from './formats/utils/format.detector.js';
39
+
40
+ // Import error classes
41
+ import {
42
+ EInvoiceError,
43
+ EInvoiceParsingError,
44
+ EInvoiceValidationError,
45
+ EInvoicePDFError,
46
+ EInvoiceFormatError,
47
+ ErrorRecovery,
48
+ ErrorContext
49
+ } from './errors.js';
50
+
51
+ // Import Factur-X implementation
52
+ import { FacturXDecoder } from './formats/cii/facturx/facturx.decoder.js';
53
+ import { FacturXEncoder } from './formats/cii/facturx/facturx.encoder.js';
54
+ import { FacturXValidator } from './formats/cii/facturx/facturx.validator.js';
55
+
56
+ // Import ZUGFeRD implementation
57
+ import { ZUGFeRDDecoder } from './formats/cii/zugferd/zugferd.decoder.js';
58
+ import { ZUGFeRDEncoder } from './formats/cii/zugferd/zugferd.encoder.js';
59
+ import { ZUGFeRDValidator } from './formats/cii/zugferd/zugferd.validator.js';
60
+ import { ZUGFeRDV1Decoder } from './formats/cii/zugferd/zugferd.v1.decoder.js';
61
+
62
+ // Export interfaces
63
+ export type {
64
+ // Common interfaces
65
+ TInvoice,
66
+ TCreditNote,
67
+ TDebitNote,
68
+ TContact,
69
+ TLetterEnvelope,
70
+ TDocumentEnvelope,
71
+ IPdf,
72
+
73
+ // Validation interfaces
74
+ ValidationError,
75
+ ValidationResult,
76
+ IValidator,
77
+
78
+ // Format interfaces
79
+ ExportFormat,
80
+ EInvoiceOptions
81
+ } from './interfaces/common.js';
82
+
83
+ export { ValidationLevel, InvoiceFormat } from './interfaces/common.js';
84
+
85
+ // Export interfaces (legacy support)
86
+ export { common as interfaces };
87
+
88
+ // Export main class
89
+ export { EInvoice };
90
+
91
+ // Export factories
92
+ export { DecoderFactory, EncoderFactory, ValidatorFactory };
93
+
94
+ // Export base classes
95
+ export { BaseDecoder, BaseEncoder, BaseValidator };
96
+
97
+ // Export UBL base classes
98
+ export { UBLBaseDecoder, UBLBaseEncoder, UBLBaseValidator };
99
+
100
+ // Export CII base classes
101
+ export { CIIBaseDecoder, CIIBaseEncoder, CIIBaseValidator };
102
+
103
+ // Export Factur-X implementation
104
+ export { FacturXDecoder, FacturXEncoder, FacturXValidator };
105
+
106
+ // Export ZUGFeRD implementation
107
+ export { ZUGFeRDDecoder, ZUGFeRDEncoder, ZUGFeRDValidator, ZUGFeRDV1Decoder };
108
+
109
+ // Export PDF utilities
110
+ export {
111
+ PDFEmbedder,
112
+ PDFExtractor,
113
+ BaseXMLExtractor,
114
+ StandardXMLExtractor,
115
+ AssociatedFilesExtractor,
116
+ TextXMLExtractor
117
+ };
118
+
119
+ // Export format detector
120
+ export { FormatDetector };
121
+
122
+ // Export error classes
123
+ export {
124
+ EInvoiceError,
125
+ EInvoiceParsingError,
126
+ EInvoiceValidationError,
127
+ EInvoicePDFError,
128
+ EInvoiceFormatError,
129
+ ErrorRecovery,
130
+ ErrorContext
131
+ };
132
+
133
+ /**
134
+ * Validates an XML string against the appropriate format rules
135
+ * @param xml XML content to validate
136
+ * @param level Validation level (syntax, semantic, business)
137
+ * @returns ValidationResult with the result of validation
138
+ */
139
+ export function validateXml(
140
+ xml: string,
141
+ level: common.ValidationLevel = common.ValidationLevel.SYNTAX
142
+ ): common.ValidationResult {
143
+ try {
144
+ const validator = ValidatorFactory.createValidator(xml);
145
+ return validator.validate(level);
146
+ } catch (error) {
147
+ return {
148
+ valid: false,
149
+ errors: [{
150
+ code: 'VAL-ERROR',
151
+ message: `Validation error: ${error.message}`
152
+ }],
153
+ level
154
+ };
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Creates a new EInvoice instance
160
+ * @returns A new EInvoice instance
161
+ */
162
+ export function createEInvoice(): EInvoice {
163
+ return new EInvoice();
164
+ }
@@ -0,0 +1,90 @@
1
+ import { business, finance } from '../plugins.js';
2
+
3
+ /**
4
+ * Supported electronic invoice formats
5
+ */
6
+ export enum InvoiceFormat {
7
+ UNKNOWN = 'unknown',
8
+ UBL = 'ubl', // Universal Business Language
9
+ CII = 'cii', // Cross-Industry Invoice
10
+ ZUGFERD = 'zugferd', // ZUGFeRD (German e-invoice format)
11
+ FACTURX = 'facturx', // Factur-X (French e-invoice format)
12
+ XRECHNUNG = 'xrechnung', // XRechnung (German e-invoice implementation of EN16931)
13
+ FATTURAPA = 'fatturapa' // FatturaPA (Italian e-invoice format)
14
+ }
15
+
16
+ /**
17
+ * Formats supported for export operations
18
+ * This is a subset of InvoiceFormat that only includes formats
19
+ * that can be generated and embedded in PDFs
20
+ */
21
+ export type ExportFormat = 'facturx' | 'zugferd' | 'xrechnung' | 'ubl' | 'cii';
22
+
23
+ /**
24
+ * Describes a validation level for invoice validation
25
+ */
26
+ export enum ValidationLevel {
27
+ SYNTAX = 'syntax', // Schema validation only
28
+ SEMANTIC = 'semantic', // Semantic validation (field types, required fields, etc.)
29
+ BUSINESS = 'business' // Business rule validation
30
+ }
31
+
32
+ /**
33
+ * Describes a validation error
34
+ */
35
+ export interface ValidationError {
36
+ code: string; // Error code (e.g. "BR-16")
37
+ message: string; // Error message
38
+ location?: string; // XPath or location in the document
39
+ }
40
+
41
+ /**
42
+ * Result of a validation operation
43
+ */
44
+ export interface ValidationResult {
45
+ valid: boolean; // Overall validation result
46
+ errors: ValidationError[]; // List of validation errors
47
+ level: ValidationLevel; // The level that was validated
48
+ }
49
+
50
+ /**
51
+ * Options for the EInvoice class
52
+ */
53
+ export interface EInvoiceOptions {
54
+ validateOnLoad?: boolean; // Whether to validate when loading an invoice
55
+ validationLevel?: ValidationLevel; // Level of validation to perform
56
+ }
57
+
58
+ /**
59
+ * Interface for validator implementations
60
+ */
61
+ export interface IValidator {
62
+ validate(level?: ValidationLevel): ValidationResult;
63
+ isValid(): boolean;
64
+ getValidationErrors(): ValidationError[];
65
+ }
66
+
67
+ /**
68
+ * PDF interface
69
+ */
70
+ export interface IPdf {
71
+ name: string;
72
+ id: string;
73
+ metadata: {
74
+ textExtraction: string;
75
+ format?: string;
76
+ embeddedXml?: {
77
+ filename: string;
78
+ description: string;
79
+ };
80
+ };
81
+ buffer: Uint8Array;
82
+ }
83
+
84
+ // Re-export types from tsclass for convenience
85
+ export type { TInvoice } from '@tsclass/tsclass/dist_ts/finance/index.js';
86
+ export type { TCreditNote } from '@tsclass/tsclass/dist_ts/finance/index.js';
87
+ export type { TDebitNote } from '@tsclass/tsclass/dist_ts/finance/index.js';
88
+ export type { TContact } from '@tsclass/tsclass/dist_ts/business/index.js';
89
+ export type { TLetterEnvelope } from '@tsclass/tsclass/dist_ts/business/index.js';
90
+ export type { TDocumentEnvelope } from '@tsclass/tsclass/dist_ts/business/index.js';
@@ -0,0 +1,98 @@
1
+ export interface IEInvoice {
2
+ InvoiceNumber: string;
3
+ DateIssued: string; // Date in ISO 8601 format
4
+ Seller: IParty;
5
+ Buyer: IParty;
6
+ Items: IInvoiceItem[];
7
+ TotalAmount: number;
8
+ }
9
+
10
+ export interface IParty {
11
+ Name: string;
12
+ Address: IAddress;
13
+ Contact: IContact;
14
+ TaxRegistration?: string;
15
+ }
16
+
17
+ export interface IAddress {
18
+ Street: string;
19
+ City: string;
20
+ PostalCode: string;
21
+ Country: string;
22
+ }
23
+
24
+ export interface IContact {
25
+ Email: string;
26
+ Phone: string;
27
+ }
28
+
29
+ export interface IInvoiceItem {
30
+ Description: string;
31
+ Quantity: number;
32
+ UnitPrice: number;
33
+ TotalPrice: number;
34
+ }
35
+
36
+ /**
37
+ * Supported electronic invoice formats
38
+ */
39
+ export enum InvoiceFormat {
40
+ UNKNOWN = 'unknown',
41
+ UBL = 'ubl', // Universal Business Language
42
+ CII = 'cii', // Cross-Industry Invoice
43
+ ZUGFERD = 'zugferd', // ZUGFeRD (German e-invoice format)
44
+ FACTURX = 'facturx', // Factur-X (French e-invoice format)
45
+ XRECHNUNG = 'xrechnung', // XRechnung (German e-invoice implementation of EN16931)
46
+ FATTURAPA = 'fatturapa' // FatturaPA (Italian e-invoice format)
47
+ }
48
+
49
+ /**
50
+ * Formats supported for export operations
51
+ * This is a subset of InvoiceFormat that only includes formats
52
+ * that can be generated and embedded in PDFs
53
+ */
54
+ export type ExportFormat = 'facturx' | 'zugferd' | 'xrechnung' | 'ubl' | 'cii';
55
+
56
+ /**
57
+ * Describes a validation level for invoice validation
58
+ */
59
+ export enum ValidationLevel {
60
+ SYNTAX = 'syntax', // Schema validation only
61
+ SEMANTIC = 'semantic', // Semantic validation (field types, required fields, etc.)
62
+ BUSINESS = 'business' // Business rule validation
63
+ }
64
+
65
+ /**
66
+ * Describes a validation error
67
+ */
68
+ export interface ValidationError {
69
+ code: string; // Error code (e.g. "BR-16")
70
+ message: string; // Error message
71
+ location?: string; // XPath or location in the document
72
+ }
73
+
74
+ /**
75
+ * Result of a validation operation
76
+ */
77
+ export interface ValidationResult {
78
+ valid: boolean; // Overall validation result
79
+ errors: ValidationError[]; // List of validation errors
80
+ level: ValidationLevel; // The level that was validated
81
+ }
82
+
83
+ /**
84
+ * Options for the EInvoice class
85
+ */
86
+ export interface EInvoiceOptions {
87
+ validateOnLoad?: boolean; // Whether to validate when loading an invoice
88
+ validationLevel?: ValidationLevel; // Level of validation to perform
89
+ }
90
+
91
+ /**
92
+ * Interface for validator implementations
93
+ */
94
+ export interface IValidator {
95
+ validate(level?: ValidationLevel): ValidationResult;
96
+ isValid(): boolean;
97
+ getValidationErrors(): ValidationError[];
98
+ }
package/ts/plugins.ts ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Centralized imports for all external npm modules
3
+ * This file serves as a single point of import for all external dependencies
4
+ * to make the codebase more maintainable and follow the DRY principle.
5
+ */
6
+
7
+ // Node.js built-in modules
8
+ import * as fs from 'fs/promises';
9
+ import * as path from 'path';
10
+ import * as crypto from 'crypto';
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
+ // XML-related imports
24
+ import { DOMParser, XMLSerializer } from 'xmldom';
25
+ import * as xpath from 'xpath';
26
+
27
+ // Compression-related imports
28
+ import * as pako from 'pako';
29
+
30
+ // Business model imports
31
+ import { business, finance, general } from '@tsclass/tsclass';
32
+
33
+ // Re-export all imports
34
+ export {
35
+ // Node.js built-in modules
36
+ fs,
37
+ path,
38
+ crypto,
39
+
40
+ // PDF-lib exports
41
+ PDFDocument,
42
+ PDFDict,
43
+ PDFName,
44
+ PDFRawStream,
45
+ PDFArray,
46
+ PDFString,
47
+ AFRelationship,
48
+
49
+ // XML-related exports
50
+ DOMParser,
51
+ XMLSerializer,
52
+ xpath,
53
+
54
+ // Compression-related exports
55
+ pako,
56
+
57
+ // Business model exports
58
+ business,
59
+ finance,
60
+ general
61
+ };