@fin.cx/einvoice 5.0.3 → 5.1.3

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 (117) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/einvoice.d.ts +4 -8
  3. package/dist_ts/einvoice.js +46 -7
  4. package/dist_ts/formats/converters/xml-to-einvoice.converter.d.ts +21 -0
  5. package/dist_ts/formats/converters/xml-to-einvoice.converter.js +127 -0
  6. package/dist_ts/formats/semantic/bt-bg.model.d.ts +445 -0
  7. package/dist_ts/formats/semantic/bt-bg.model.js +12 -0
  8. package/dist_ts/formats/semantic/semantic.adapter.d.ts +87 -0
  9. package/dist_ts/formats/semantic/semantic.adapter.js +538 -0
  10. package/dist_ts/formats/semantic/semantic.validator.d.ts +48 -0
  11. package/dist_ts/formats/semantic/semantic.validator.js +596 -0
  12. package/dist_ts/formats/utils/currency.calculator.decimal.d.ts +98 -0
  13. package/dist_ts/formats/utils/currency.calculator.decimal.js +212 -0
  14. package/dist_ts/formats/utils/currency.utils.d.ts +99 -0
  15. package/dist_ts/formats/utils/currency.utils.js +250 -0
  16. package/dist_ts/formats/utils/decimal.d.ts +151 -0
  17. package/dist_ts/formats/utils/decimal.js +435 -0
  18. package/dist_ts/formats/validation/codelist.validator.d.ts +49 -0
  19. package/dist_ts/formats/validation/codelist.validator.js +188 -0
  20. package/dist_ts/formats/validation/conformance.harness.d.ts +99 -0
  21. package/dist_ts/formats/validation/conformance.harness.js +471 -0
  22. package/dist_ts/formats/validation/en16931.business-rules.validator.d.ts +58 -0
  23. package/dist_ts/formats/validation/en16931.business-rules.validator.js +459 -0
  24. package/dist_ts/formats/validation/facturx.validator.d.ts +75 -0
  25. package/dist_ts/formats/validation/facturx.validator.js +522 -0
  26. package/dist_ts/formats/validation/integrated.validator.d.ts +82 -0
  27. package/dist_ts/formats/validation/integrated.validator.js +311 -0
  28. package/dist_ts/formats/validation/peppol.validator.d.ts +77 -0
  29. package/dist_ts/formats/validation/peppol.validator.js +529 -0
  30. package/dist_ts/formats/validation/schematron.downloader.d.ts +71 -0
  31. package/dist_ts/formats/validation/schematron.downloader.js +254 -0
  32. package/dist_ts/formats/validation/schematron.integration.d.ts +60 -0
  33. package/dist_ts/formats/validation/schematron.integration.js +230 -0
  34. package/dist_ts/formats/validation/schematron.validator.d.ts +79 -0
  35. package/dist_ts/formats/validation/schematron.validator.js +288 -0
  36. package/dist_ts/formats/validation/schematron.worker.d.ts +50 -0
  37. package/dist_ts/formats/validation/schematron.worker.js +185 -0
  38. package/dist_ts/formats/validation/validation.types.d.ts +163 -0
  39. package/dist_ts/formats/validation/validation.types.js +181 -0
  40. package/dist_ts/formats/validation/vat-categories.validator.d.ts +87 -0
  41. package/dist_ts/formats/validation/vat-categories.validator.js +497 -0
  42. package/dist_ts/formats/validation/xrechnung.validator.d.ts +92 -0
  43. package/dist_ts/formats/validation/xrechnung.validator.js +417 -0
  44. package/dist_ts/interfaces/common.d.ts +1 -0
  45. package/dist_ts/interfaces/en16931-metadata.d.ts +83 -0
  46. package/dist_ts/interfaces/en16931-metadata.js +6 -0
  47. package/dist_ts/plugins.d.ts +3 -1
  48. package/dist_ts/plugins.js +7 -2
  49. package/dist_ts_install/download-schematron.d.ts +6 -0
  50. package/dist_ts_install/download-schematron.js +62 -0
  51. package/dist_ts_install/download-test-samples.d.ts +19 -0
  52. package/dist_ts_install/download-test-samples.js +169 -0
  53. package/dist_ts_install/download-xrechnung-rules.d.ts +7 -0
  54. package/dist_ts_install/download-xrechnung-rules.js +146 -0
  55. package/dist_ts_install/index.d.ts +8 -0
  56. package/dist_ts_install/index.js +246 -0
  57. package/npmextra.json +1 -1
  58. package/package.json +12 -6
  59. package/readme.md +255 -810
  60. package/ts/00_commitinfo_data.ts +1 -1
  61. package/ts/einvoice.ts +63 -14
  62. package/ts/formats/converters/xml-to-einvoice.converter.ts +142 -0
  63. package/ts/formats/semantic/bt-bg.model.ts +524 -0
  64. package/ts/formats/semantic/semantic.adapter.ts +600 -0
  65. package/ts/formats/semantic/semantic.validator.ts +654 -0
  66. package/ts/formats/utils/currency.calculator.decimal.ts +323 -0
  67. package/ts/formats/utils/currency.utils.ts +299 -0
  68. package/ts/formats/utils/decimal.ts +509 -0
  69. package/ts/formats/validation/codelist.validator.ts +317 -0
  70. package/ts/formats/validation/conformance.harness.ts +591 -0
  71. package/ts/formats/validation/en16931.business-rules.validator.ts +694 -0
  72. package/ts/formats/validation/facturx.validator.ts +579 -0
  73. package/ts/formats/validation/integrated.validator.ts +405 -0
  74. package/ts/formats/validation/peppol.validator.ts +589 -0
  75. package/ts/formats/validation/schematron.downloader.ts +304 -0
  76. package/ts/formats/validation/schematron.integration.ts +285 -0
  77. package/ts/formats/validation/schematron.validator.ts +348 -0
  78. package/ts/formats/validation/schematron.worker.ts +221 -0
  79. package/ts/formats/validation/validation.types.ts +274 -0
  80. package/ts/formats/validation/vat-categories.validator.ts +845 -0
  81. package/ts/formats/validation/xrechnung.validator.ts +494 -0
  82. package/ts/interfaces/common.ts +1 -0
  83. package/ts/interfaces/en16931-metadata.ts +104 -0
  84. package/ts/plugins.ts +8 -0
  85. package/ts/tspublish.json +3 -0
  86. package/dist_ts/classes.decoder.d.ts +0 -40
  87. package/dist_ts/classes.decoder.js +0 -320
  88. package/dist_ts/classes.encoder.d.ts +0 -51
  89. package/dist_ts/classes.encoder.js +0 -293
  90. package/dist_ts/classes.xinvoice.d.ts +0 -136
  91. package/dist_ts/classes.xinvoice.js +0 -352
  92. package/dist_ts/formats/base.decoder.d.ts +0 -19
  93. package/dist_ts/formats/base.decoder.js +0 -130
  94. package/dist_ts/formats/base.validator.d.ts +0 -44
  95. package/dist_ts/formats/base.validator.js +0 -39
  96. package/dist_ts/formats/decoder.factory.d.ts +0 -15
  97. package/dist_ts/formats/decoder.factory.js +0 -46
  98. package/dist_ts/formats/factorx.decoder.d.ts +0 -18
  99. package/dist_ts/formats/factorx.decoder.js +0 -178
  100. package/dist_ts/formats/factorx.encoder.d.ts +0 -51
  101. package/dist_ts/formats/factorx.encoder.js +0 -293
  102. package/dist_ts/formats/facturx.decoder.d.ts +0 -18
  103. package/dist_ts/formats/facturx.decoder.js +0 -210
  104. package/dist_ts/formats/facturx.encoder.d.ts +0 -51
  105. package/dist_ts/formats/facturx.encoder.js +0 -293
  106. package/dist_ts/formats/facturx.validator.d.ts +0 -67
  107. package/dist_ts/formats/facturx.validator.js +0 -266
  108. package/dist_ts/formats/pdf/robust-pdf.extractor.d.ts +0 -40
  109. package/dist_ts/formats/pdf/robust-pdf.extractor.js +0 -324
  110. package/dist_ts/formats/ubl.validator.d.ts +0 -82
  111. package/dist_ts/formats/ubl.validator.js +0 -306
  112. package/dist_ts/formats/validator.factory.d.ts +0 -18
  113. package/dist_ts/formats/validator.factory.js +0 -78
  114. package/dist_ts/formats/xinvoice.decoder.d.ts +0 -28
  115. package/dist_ts/formats/xinvoice.decoder.js +0 -332
  116. package/dist_ts/formats/xinvoice.encoder.d.ts +0 -19
  117. package/dist_ts/formats/xinvoice.encoder.js +0 -282
@@ -0,0 +1,274 @@
1
+ /**
2
+ * Enhanced validation types for EN16931 compliance
3
+ */
4
+
5
+ export interface ValidationResult {
6
+ // Core identification
7
+ ruleId: string; // e.g., "BR-CO-14"
8
+ source: string; // e.g., "EN16931", "PEPPOL", "XRECHNUNG"
9
+ severity: 'error' | 'warning' | 'info';
10
+ message: string;
11
+
12
+ // Semantic references
13
+ btReference?: string; // Business Term reference (e.g., "BT-112")
14
+ bgReference?: string; // Business Group reference (e.g., "BG-23")
15
+
16
+ // Location information
17
+ semanticPath?: string; // BT/BG-based path (portable across syntaxes)
18
+ syntaxPath?: string; // XPath/JSON Pointer to concrete field
19
+ field?: string; // Simple field name
20
+
21
+ // Values and validation context
22
+ value?: any; // Actual value found
23
+ expected?: any; // Expected value or pattern
24
+ tolerance?: number; // Numeric tolerance applied
25
+
26
+ // Context
27
+ profile?: string; // e.g., "EN16931", "PEPPOL_BIS_3.0", "XRECHNUNG_3.0"
28
+ codeList?: {
29
+ name: string; // e.g., "ISO4217", "UNCL5305"
30
+ version: string; // e.g., "2021"
31
+ };
32
+
33
+ // Remediation
34
+ hint?: string; // Machine-friendly hint key
35
+ remediation?: string; // Human-readable fix suggestion
36
+ }
37
+
38
+ export interface ValidationOptions {
39
+ // Profile and target
40
+ profile?: 'EN16931' | 'PEPPOL_BIS_3.0' | 'XRECHNUNG_3.0' | 'FACTURX_BASIC' | 'FACTURX_EN16931';
41
+ formatHint?: 'UBL' | 'CII';
42
+
43
+ // Validation toggles
44
+ checkCalculations?: boolean;
45
+ checkVAT?: boolean;
46
+ checkAllowances?: boolean;
47
+ checkCodeLists?: boolean;
48
+ checkCardinality?: boolean;
49
+
50
+ // Tolerances
51
+ tolerance?: number; // Default 0.01 for currency
52
+ currencyMinorUnits?: Map<string, number>; // Currency-specific decimal places
53
+
54
+ // Mode
55
+ strictMode?: boolean; // Fail on warnings
56
+ reportOnly?: boolean; // Non-blocking validation
57
+ featureFlags?: string[]; // Enable specific rule sets
58
+ }
59
+
60
+ export interface ValidationReport {
61
+ // Summary
62
+ valid: boolean;
63
+ profile: string;
64
+ timestamp: string;
65
+ validatorVersion: string;
66
+ rulesetVersion: string;
67
+
68
+ // Results
69
+ results: ValidationResult[];
70
+ errorCount: number;
71
+ warningCount: number;
72
+ infoCount: number;
73
+
74
+ // Coverage
75
+ rulesChecked: number;
76
+ rulesTotal: number;
77
+ coverage: number; // Percentage
78
+
79
+ // Performance
80
+ validationTime: number; // Milliseconds
81
+
82
+ // Document info
83
+ documentId?: string;
84
+ documentType?: string;
85
+ format?: string;
86
+ }
87
+
88
+ // Code list definitions
89
+ export const CodeLists = {
90
+ // ISO 4217 Currency codes
91
+ ISO4217: {
92
+ version: '2021',
93
+ codes: new Set([
94
+ 'EUR', 'USD', 'GBP', 'CHF', 'SEK', 'NOK', 'DKK', 'PLN', 'CZK', 'HUF',
95
+ 'RON', 'BGN', 'HRK', 'TRY', 'ISK', 'JPY', 'CNY', 'AUD', 'CAD', 'NZD'
96
+ ])
97
+ },
98
+
99
+ // ISO 3166-1 alpha-2 Country codes
100
+ ISO3166: {
101
+ version: '2020',
102
+ codes: new Set([
103
+ 'DE', 'FR', 'IT', 'ES', 'NL', 'BE', 'AT', 'CH', 'GB', 'IE', 'PT', 'GR',
104
+ 'SE', 'NO', 'DK', 'FI', 'PL', 'CZ', 'HU', 'RO', 'BG', 'HR', 'SI', 'SK',
105
+ 'LT', 'LV', 'EE', 'LU', 'MT', 'CY', 'US', 'CA', 'AU', 'NZ', 'JP', 'CN'
106
+ ])
107
+ },
108
+
109
+ // UNCL5305 Tax category codes
110
+ UNCL5305: {
111
+ version: 'D16B',
112
+ codes: new Map([
113
+ ['S', 'Standard rate'],
114
+ ['Z', 'Zero rated'],
115
+ ['E', 'Exempt from tax'],
116
+ ['AE', 'VAT Reverse Charge'],
117
+ ['K', 'VAT exempt for EEA intra-community supply'],
118
+ ['G', 'Free export outside EU'],
119
+ ['O', 'Services outside scope of tax'],
120
+ ['L', 'Canary Islands general indirect tax'],
121
+ ['M', 'Tax for production, services and importation in Ceuta and Melilla']
122
+ ])
123
+ },
124
+
125
+ // UNCL1001 Document type codes
126
+ UNCL1001: {
127
+ version: 'D16B',
128
+ codes: new Map([
129
+ ['380', 'Commercial invoice'],
130
+ ['381', 'Credit note'],
131
+ ['383', 'Debit note'],
132
+ ['384', 'Corrected invoice'],
133
+ ['389', 'Self-billed invoice'],
134
+ ['751', 'Invoice information for accounting purposes']
135
+ ])
136
+ },
137
+
138
+ // UNCL4461 Payment means codes
139
+ UNCL4461: {
140
+ version: 'D16B',
141
+ codes: new Map([
142
+ ['1', 'Instrument not defined'],
143
+ ['10', 'In cash'],
144
+ ['20', 'Cheque'],
145
+ ['30', 'Credit transfer'],
146
+ ['31', 'Debit transfer'],
147
+ ['42', 'Payment to bank account'],
148
+ ['48', 'Bank card'],
149
+ ['49', 'Direct debit'],
150
+ ['58', 'SEPA credit transfer'],
151
+ ['59', 'SEPA direct debit']
152
+ ])
153
+ },
154
+
155
+ // UNECE Rec 20 Unit codes (subset)
156
+ UNECERec20: {
157
+ version: '2021',
158
+ codes: new Map([
159
+ ['C62', 'One (unit)'],
160
+ ['DAY', 'Day'],
161
+ ['HAR', 'Hectare'],
162
+ ['HUR', 'Hour'],
163
+ ['KGM', 'Kilogram'],
164
+ ['KTM', 'Kilometre'],
165
+ ['KWH', 'Kilowatt hour'],
166
+ ['LS', 'Lump sum'],
167
+ ['LTR', 'Litre'],
168
+ ['MIN', 'Minute'],
169
+ ['MMT', 'Millimetre'],
170
+ ['MON', 'Month'],
171
+ ['MTK', 'Square metre'],
172
+ ['MTQ', 'Cubic metre'],
173
+ ['MTR', 'Metre'],
174
+ ['NAR', 'Number of articles'],
175
+ ['NPR', 'Number of pairs'],
176
+ ['P1', 'Percent'],
177
+ ['SET', 'Set'],
178
+ ['TNE', 'Tonne (metric ton)'],
179
+ ['WEE', 'Week']
180
+ ])
181
+ }
182
+ };
183
+
184
+ // Business Term (BT) and Business Group (BG) mappings
185
+ export const SemanticModel = {
186
+ // Document level BTs
187
+ BT1: 'Invoice number',
188
+ BT2: 'Invoice issue date',
189
+ BT3: 'Invoice type code',
190
+ BT5: 'Invoice currency code',
191
+ BT6: 'VAT accounting currency code',
192
+ BT7: 'Value added tax point date',
193
+ BT8: 'Value added tax point date code',
194
+ BT9: 'Payment due date',
195
+ BT10: 'Buyer reference',
196
+ BT11: 'Project reference',
197
+ BT12: 'Contract reference',
198
+ BT13: 'Purchase order reference',
199
+ BT14: 'Sales order reference',
200
+ BT15: 'Receiving advice reference',
201
+ BT16: 'Despatch advice reference',
202
+ BT17: 'Tender or lot reference',
203
+ BT18: 'Invoiced object identifier',
204
+ BT19: 'Buyer accounting reference',
205
+ BT20: 'Payment terms',
206
+ BT21: 'Seller note',
207
+ BT22: 'Buyer note',
208
+ BT23: 'Business process',
209
+ BT24: 'Specification identifier',
210
+
211
+ // Seller BTs (BG-4)
212
+ BT27: 'Seller name',
213
+ BT28: 'Seller trading name',
214
+ BT29: 'Seller identifier',
215
+ BT30: 'Seller legal registration identifier',
216
+ BT31: 'Seller VAT identifier',
217
+ BT32: 'Seller tax registration identifier',
218
+ BT33: 'Seller additional legal information',
219
+ BT34: 'Seller electronic address',
220
+
221
+ // Buyer BTs (BG-7)
222
+ BT44: 'Buyer name',
223
+ BT45: 'Buyer trading name',
224
+ BT46: 'Buyer identifier',
225
+ BT47: 'Buyer legal registration identifier',
226
+ BT48: 'Buyer VAT identifier',
227
+ BT49: 'Buyer electronic address',
228
+
229
+ // Monetary totals (BG-22)
230
+ BT106: 'Sum of Invoice line net amount',
231
+ BT107: 'Sum of allowances on document level',
232
+ BT108: 'Sum of charges on document level',
233
+ BT109: 'Invoice total amount without VAT',
234
+ BT110: 'Invoice total VAT amount',
235
+ BT111: 'Invoice total VAT amount in accounting currency',
236
+ BT112: 'Invoice total amount with VAT',
237
+ BT113: 'Paid amount',
238
+ BT114: 'Rounding amount',
239
+ BT115: 'Amount due for payment',
240
+
241
+ // Business Groups
242
+ BG1: 'Invoice note',
243
+ BG2: 'Process control',
244
+ BG3: 'Preceding Invoice reference',
245
+ BG4: 'Seller',
246
+ BG5: 'Seller postal address',
247
+ BG6: 'Seller contact',
248
+ BG7: 'Buyer',
249
+ BG8: 'Buyer postal address',
250
+ BG9: 'Buyer contact',
251
+ BG10: 'Payee',
252
+ BG11: 'Seller tax representative',
253
+ BG12: 'Seller tax representative postal address',
254
+ BG13: 'Delivery information',
255
+ BG14: 'Delivery or invoice period',
256
+ BG15: 'Deliver to address',
257
+ BG16: 'Payment instructions',
258
+ BG17: 'Credit transfer',
259
+ BG18: 'Payment card information',
260
+ BG19: 'Direct debit',
261
+ BG20: 'Document level allowances',
262
+ BG21: 'Document level charges',
263
+ BG22: 'Document totals',
264
+ BG23: 'VAT breakdown',
265
+ BG24: 'Additional supporting documents',
266
+ BG25: 'Invoice line',
267
+ BG26: 'Invoice line period',
268
+ BG27: 'Invoice line allowances',
269
+ BG28: 'Invoice line charges',
270
+ BG29: 'Price details',
271
+ BG30: 'Line VAT information',
272
+ BG31: 'Item information',
273
+ BG32: 'Item attributes'
274
+ };