@stackforge-eu/factur-x 1.0.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 (94) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +287 -0
  3. package/README.md +312 -0
  4. package/dist/index.cjs +1339 -0
  5. package/dist/index.d.cts +1382 -0
  6. package/dist/index.d.ts +1382 -0
  7. package/dist/index.js +1292 -0
  8. package/package.json +83 -0
  9. package/schema/README.md +39 -0
  10. package/schema/basic/FACTUR-X_BASIC.xsd +20 -0
  11. package/schema/basic/FACTUR-X_BASIC_QualifiedDataType_100.xsd +86 -0
  12. package/schema/basic/FACTUR-X_BASIC_ReusableAggregateBusinessInformationEntity_100.xsd +249 -0
  13. package/schema/basic/FACTUR-X_BASIC_UnqualifiedDataType_100.xsd +60 -0
  14. package/schema/basic-wl/FACTUR-X_BASIC-WL.xsd +20 -0
  15. package/schema/basic-wl/FACTUR-X_BASIC-WL_QualifiedDataType_100.xsd +86 -0
  16. package/schema/basic-wl/FACTUR-X_BASIC-WL_ReusableAggregateBusinessInformationEntity_100.xsd +196 -0
  17. package/schema/basic-wl/FACTUR-X_BASIC-WL_UnqualifiedDataType_100.xsd +53 -0
  18. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B.xsd +25 -0
  19. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_EDIFICAS-EU_AccountingAccountType_D11A.xsd +18 -0
  20. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_EDIFICAS-EU_AccountingAmountType_D11A.xsd +17 -0
  21. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_ISO_ISO3AlphaCurrencyCode_2012-08-31.xsd +191 -0
  22. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_ISO_ISOTwo-letterCountryCode_SecondEdition2006.xsd +260 -0
  23. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_QualifiedDataType_100.xsd +818 -0
  24. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_ReusableAggregateBusinessInformationEntity_100.xsd +6176 -0
  25. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_ActionCode_D22A.xsd +130 -0
  26. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_AddressType_D22A.xsd +19 -0
  27. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_AdjustmentReasonDescriptionCode_D22A.xsd +116 -0
  28. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_AllowanceChargeIdentificationCode_D22A.xsd +116 -0
  29. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_AllowanceChargeReasonCode_D22A.xsd +116 -0
  30. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_AutomaticDataCaptureMethodCode_D22A.xsd +21 -0
  31. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_CargoOperationalCategoryCode_D22A.xsd +36 -0
  32. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_CargoTypeCode_1996Rev2Final.xsd +20 -0
  33. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_CommodityIdentificationCode_D22A.xsd +12 -0
  34. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_CommunicationMeansTypeCode_D22A.xsd +58 -0
  35. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_ContactFunctionCode_D22A.xsd +114 -0
  36. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DangerousGoodsPackingCode_D22A.xsd +15 -0
  37. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DangerousGoodsRegulationCode_D22A.xsd +35 -0
  38. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DateOnlyFormatCode_D21B.xsd +21 -0
  39. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DeliveryTermsCode_2020.xsd +24 -0
  40. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DeliveryTermsFunctionCode_D22A.xsd +19 -0
  41. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DimensionTypeCode_D22A.xsd +35 -0
  42. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DocumentNameCode_Accounting_D22A.xsd +35 -0
  43. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DocumentNameCode_D22A.xsd +819 -0
  44. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DocumentStatusCode_D22A.xsd +61 -0
  45. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DutyTaxFeeTypeCode_D22A.xsd +67 -0
  46. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_DutyorTaxorFeeCategoryCode_D22A.xsd +33 -0
  47. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_EventTimeReferenceCodePaymentTermsEvent_D22A.xsd +16 -0
  48. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_EventTimeReferenceCode_D22A.xsd +76 -0
  49. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_FreightChargeQuantityUnitBasisCode_D22A.xsd +12 -0
  50. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_FreightChargeTariffCode_D22A.xsd +25 -0
  51. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_FreightCostCode_4.xsd +1722 -0
  52. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_GoodsTypeCode_D22A.xsd +12 -0
  53. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_GoodsTypeExtensionCode_D22A.xsd +12 -0
  54. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_LocationFunctionCode_D22A.xsd +326 -0
  55. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_MeasurementUnitCommonCodeLinear_4.xsd +17 -0
  56. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_MeasurementUnitCommonCodeVolume_4.xsd +18 -0
  57. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_MeasurementUnitCommonCodeWeight_4.xsd +15 -0
  58. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_MessageFunctionCode_D22A.xsd +84 -0
  59. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PackageTypeCode_2006.xsd +416 -0
  60. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PackagingMarkingCode_D22A.xsd +63 -0
  61. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PartyRoleCode_ChargePaying_D22A.xsd +32 -0
  62. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PartyRoleCode_D22A.xsd +635 -0
  63. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PaymentGuaranteeMeansCode_D22A.xsd +23 -0
  64. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PaymentMeansChannelCode_D22A.xsd +27 -0
  65. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PaymentMeansCode_D22A.xsd +94 -0
  66. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PaymentTermsDescriptionIdentifier_D22A.xsd +18 -0
  67. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PaymentTermsTypeCode_D22A.xsd +90 -0
  68. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_PriceTypeCode_D22A.xsd +50 -0
  69. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_ReferenceTypeCode_D22A.xsd +828 -0
  70. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_SealConditionCode_D22A.xsd +16 -0
  71. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_SealingPartyRoleCode_D22A.xsd +18 -0
  72. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_StatusCode_D22A.xsd +527 -0
  73. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_StatusDescriptionCode_AccountingDebitCredit_D22A.xsd +18 -0
  74. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_TimeOnlyFormatCode_D21B.xsd +16 -0
  75. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_TimePointFormatCode_D21B.xsd +17 -0
  76. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_TransportEquipmentCategoryCode_D22A.xsd +107 -0
  77. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_TransportEquipmentFullnessCode_D22A.xsd +24 -0
  78. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_TransportMeansTypeCode_2007.xsd +145 -0
  79. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_TransportModeCode_2.xsd +21 -0
  80. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_TransportMovementStageCode_D22A.xsd +41 -0
  81. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UNECE_TransportPaymentArrangementCode_D22A.xsd +15 -0
  82. package/schema/cii-d22b/CrossIndustryInvoice_100pD22B_UnqualifiedDataType_100.xsd +144 -0
  83. package/schema/en16931/FACTUR-X_EN16931.xsd +20 -0
  84. package/schema/en16931/FACTUR-X_EN16931_QualifiedDataType_100.xsd +94 -0
  85. package/schema/en16931/FACTUR-X_EN16931_ReusableAggregateBusinessInformationEntity_100.xsd +318 -0
  86. package/schema/en16931/FACTUR-X_EN16931_UnqualifiedDataType_100.xsd +84 -0
  87. package/schema/extended/FACTUR-X_EXTENDED.xsd +20 -0
  88. package/schema/extended/FACTUR-X_EXTENDED_QualifiedDataType_100.xsd +142 -0
  89. package/schema/extended/FACTUR-X_EXTENDED_ReusableAggregateBusinessInformationEntity_100.xsd +475 -0
  90. package/schema/extended/FACTUR-X_EXTENDED_UnqualifiedDataType_100.xsd +101 -0
  91. package/schema/minimum/FACTUR-X_MINIMUM.xsd +20 -0
  92. package/schema/minimum/FACTUR-X_MINIMUM_QualifiedDataType_100.xsd +30 -0
  93. package/schema/minimum/FACTUR-X_MINIMUM_ReusableAggregateBusinessInformationEntity_100.xsd +86 -0
  94. package/schema/minimum/FACTUR-X_MINIMUM_UnqualifiedDataType_100.xsd +38 -0
@@ -0,0 +1,1382 @@
1
+ import { Buffer } from 'node:buffer';
2
+
3
+ /**
4
+ * Factur-X Input Object Types
5
+ *
6
+ * These types define the structured input for invoice generation across
7
+ * all supported profiles (MINIMUM → EXTENDED) and flavors (factur-x,
8
+ * zugferd, xrechnung, chrono-pro).
9
+ *
10
+ * Fields are annotated with their EN 16931 Business Term (BT) mapping
11
+ * and the minimum profile level at which they become relevant.
12
+ *
13
+ * @module types/input
14
+ * @see docs/INPUT_OBJECT_SPECIFICATION.md
15
+ * @see https://fnfe-mpe.org/factur-x/
16
+ * @license EUPL-1.2
17
+ */
18
+ /**
19
+ * Invoice type codes per UNTDID 1001 — Document name code (BT-3).
20
+ *
21
+ * The full code list from the Factur-X / EN 16931 specification.
22
+ * Common codes for most implementations:
23
+ *
24
+ * | Code | Meaning | Chorus Pro |
25
+ * |------|-------------------------------|------------|
26
+ * | 380 | Commercial invoice | ✅ |
27
+ * | 381 | Credit note | ✅ |
28
+ * | 384 | Corrected invoice | ✅ |
29
+ * | 386 | Prepayment invoice | ✅ |
30
+ * | 389 | Self-billed invoice | ❌ |
31
+ * | 261 | Self-billed credit note | ❌ |
32
+ * | 751 | Invoice info for accounting | ❌ (DE only)|
33
+ *
34
+ * Code `751` is required in Germany to meet regulatory requirements.
35
+ * Codes `261`, `389`, `471`, `500`, `501`, `527` are **not accepted**
36
+ * by Chorus Pro (France).
37
+ *
38
+ * @see EN 16931 BT-3
39
+ * @see UNTDID 1001
40
+ */
41
+ declare enum DocumentTypeCode {
42
+ /** Request for payment */
43
+ REQUEST_FOR_PAYMENT = "71",
44
+ /** Debit note related to goods or services */
45
+ DEBIT_NOTE_GOODS_SERVICES = "80",
46
+ /** Credit note related to goods or services */
47
+ CREDIT_NOTE_GOODS_SERVICES = "81",
48
+ /** Metered services invoice */
49
+ METERED_SERVICES_INVOICE = "82",
50
+ /** Credit note related to financial adjustments */
51
+ CREDIT_NOTE_FINANCIAL_ADJUSTMENTS = "83",
52
+ /** Debit note related to financial adjustments */
53
+ DEBIT_NOTE_FINANCIAL_ADJUSTMENTS = "84",
54
+ /** Tax notification */
55
+ TAX_NOTIFICATION = "102",
56
+ /** Invoicing data sheet */
57
+ INVOICING_DATA_SHEET = "130",
58
+ /** Direct payment valuation */
59
+ DIRECT_PAYMENT_VALUATION = "202",
60
+ /** Provisional payment valuation */
61
+ PROVISIONAL_PAYMENT_VALUATION = "203",
62
+ /** Payment valuation */
63
+ PAYMENT_VALUATION = "204",
64
+ /** Interim application for payment */
65
+ INTERIM_APPLICATION_FOR_PAYMENT = "211",
66
+ /** Final payment request based on completion of work */
67
+ FINAL_PAYMENT_REQUEST = "218",
68
+ /** Payment request for completed units */
69
+ PAYMENT_REQUEST_COMPLETED_UNITS = "219",
70
+ /** Self-billed credit note (not accepted by Chorus Pro) */
71
+ SELF_BILLED_CREDIT_NOTE = "261",
72
+ /** Consolidated credit note — goods and services */
73
+ CONSOLIDATED_CREDIT_NOTE = "262",
74
+ /** Price variation invoice */
75
+ PRICE_VARIATION_INVOICE = "295",
76
+ /** Credit note for price variation */
77
+ CREDIT_NOTE_PRICE_VARIATION = "296",
78
+ /** Delcredere credit note */
79
+ DELCREDERE_CREDIT_NOTE = "308",
80
+ /** Proforma invoice */
81
+ PROFORMA_INVOICE = "325",
82
+ /** Partial invoice */
83
+ PARTIAL_INVOICE = "326",
84
+ /** Commercial invoice which includes a packing list */
85
+ COMMERCIAL_INVOICE_PACKING_LIST = "331",
86
+ /** Commercial invoice */
87
+ COMMERCIAL_INVOICE = "380",
88
+ /** Credit note */
89
+ CREDIT_NOTE = "381",
90
+ /** Commission note */
91
+ COMMISSION_NOTE = "382",
92
+ /** Debit note */
93
+ DEBIT_NOTE = "383",
94
+ /** Corrected invoice */
95
+ CORRECTED_INVOICE = "384",
96
+ /** Consolidated invoice */
97
+ CONSOLIDATED_INVOICE = "385",
98
+ /** Prepayment invoice */
99
+ PREPAYMENT_INVOICE = "386",
100
+ /** Hire invoice */
101
+ HIRE_INVOICE = "387",
102
+ /** Tax invoice */
103
+ TAX_INVOICE = "388",
104
+ /** Self-billed invoice (not accepted by Chorus Pro) */
105
+ SELF_BILLED_INVOICE = "389",
106
+ /** Delcredere invoice */
107
+ DELCREDERE_INVOICE = "390",
108
+ /** Factored invoice */
109
+ FACTORED_INVOICE = "393",
110
+ /** Lease invoice */
111
+ LEASE_INVOICE = "394",
112
+ /** Consignment invoice */
113
+ CONSIGNMENT_INVOICE = "395",
114
+ /** Factored credit note */
115
+ FACTORED_CREDIT_NOTE = "396",
116
+ /** Optical Character Reading (OCR) payment credit note */
117
+ OCR_PAYMENT_CREDIT_NOTE = "420",
118
+ /** Debit advice */
119
+ DEBIT_ADVICE = "456",
120
+ /** Reversal of debit */
121
+ REVERSAL_OF_DEBIT = "457",
122
+ /** Reversal of credit */
123
+ REVERSAL_OF_CREDIT = "458",
124
+ /** Self-billed corrective invoice (not accepted by Chorus Pro) */
125
+ SELF_BILLED_CORRECTIVE_INVOICE = "471",
126
+ /** Factored corrective invoice */
127
+ FACTORED_CORRECTIVE_INVOICE = "472",
128
+ /** Self-billed factored corrective invoice */
129
+ SELF_BILLED_FACTORED_CORRECTIVE_INVOICE = "473",
130
+ /** Self-billed prepayment invoice (not accepted by Chorus Pro) */
131
+ SELF_BILLED_PREPAYMENT_INVOICE = "500",
132
+ /** Self-billed factored invoice (not accepted by Chorus Pro) */
133
+ SELF_BILLED_FACTORED_INVOICE = "501",
134
+ /** Self-billed factored credit note */
135
+ SELF_BILLED_FACTORED_CREDIT_NOTE = "502",
136
+ /** Prepayment credit note */
137
+ PREPAYMENT_CREDIT_NOTE = "503",
138
+ /** Self-billed debit note (not accepted by Chorus Pro) */
139
+ SELF_BILLED_DEBIT_NOTE = "527",
140
+ /** Forwarder's credit note */
141
+ FORWARDERS_CREDIT_NOTE = "532",
142
+ /** Forwarder's invoice discrepancy report */
143
+ FORWARDERS_INVOICE_DISCREPANCY_REPORT = "553",
144
+ /** Insurer's invoice */
145
+ INSURERS_INVOICE = "575",
146
+ /** Forwarder's invoice */
147
+ FORWARDERS_INVOICE = "623",
148
+ /** Port charges documents */
149
+ PORT_CHARGES_DOCUMENTS = "633",
150
+ /**
151
+ * Invoice information for accounting purposes.
152
+ * Required in Germany for regulatory requirements.
153
+ * **Not accepted** by Chorus Pro.
154
+ */
155
+ INVOICE_INFO_ACCOUNTING = "751",
156
+ /** Freight invoice */
157
+ FREIGHT_INVOICE = "780",
158
+ /** Claim notification */
159
+ CLAIM_NOTIFICATION = "817",
160
+ /** Consular invoice */
161
+ CONSULAR_INVOICE = "870",
162
+ /** Partial construction invoice */
163
+ PARTIAL_CONSTRUCTION_INVOICE = "875",
164
+ /** Partial final construction invoice */
165
+ PARTIAL_FINAL_CONSTRUCTION_INVOICE = "876",
166
+ /** Final construction invoice */
167
+ FINAL_CONSTRUCTION_INVOICE = "877"
168
+ }
169
+ /**
170
+ * VAT category codes per UNTDID 5305 — Duty/tax/fee category code.
171
+ *
172
+ * Used on invoice line items (BT-151), allowances/charges, and
173
+ * VAT breakdown entries (BT-118) to classify the VAT treatment.
174
+ *
175
+ * | Code | Meaning |
176
+ * |------|------------------------------------------------------|
177
+ * | S | Standard rate |
178
+ * | Z | Zero rated goods |
179
+ * | E | Exempt from tax |
180
+ * | AE | VAT Reverse Charge |
181
+ * | K | Intra-community supply (goods & services) |
182
+ * | G | Free export, tax not charged |
183
+ * | O | Services outside scope of tax |
184
+ * | L | Canary Islands general indirect tax (IGIC) |
185
+ * | M | Ceuta and Melilla tax (IPSI) |
186
+ *
187
+ * Any valid UNTDID 5305 string is accepted — use this enum for
188
+ * readability and autocompletion.
189
+ *
190
+ * @see EN 16931 BT-151, BT-118
191
+ * @see UNTDID 5305
192
+ */
193
+ declare enum VatCategoryCode {
194
+ /** Standard rate */
195
+ STANDARD_RATE = "S",
196
+ /** Zero rated goods */
197
+ ZERO_RATED = "Z",
198
+ /** Exempt from tax */
199
+ EXEMPT = "E",
200
+ /** VAT Reverse Charge */
201
+ REVERSE_CHARGE = "AE",
202
+ /** Intra-community supply of goods and services */
203
+ INTRA_COMMUNITY_SUPPLY = "K",
204
+ /** Free export item, tax not charged */
205
+ FREE_EXPORT = "G",
206
+ /** Services outside scope of tax */
207
+ OUTSIDE_SCOPE = "O",
208
+ /** Canary Islands general indirect tax (IGIC) */
209
+ CANARY_ISLANDS_TAX = "L",
210
+ /** Tax for production, services and importation in Ceuta and Melilla (IPSI) */
211
+ CEUTA_MELILLA_TAX = "M"
212
+ }
213
+ /**
214
+ * Common unit of measure codes per UN/ECE Recommendation 20 (BT-130).
215
+ *
216
+ * Only codes typically found on invoices are active. Less common codes
217
+ * (imperial, scientific, niche packaging) are commented out but can be
218
+ * uncommented if needed. Any valid Rec 20 string is accepted by the
219
+ * `unitCode` field — use this enum for readability and autocompletion.
220
+ *
221
+ * @see EN 16931 BT-130
222
+ * @see https://unece.org/trade/uncefact/cl-recommendations
223
+ */
224
+ declare enum UnitCode {
225
+ /** One (unit / piece) — most common default */
226
+ UNIT = "C62",
227
+ /** Each */
228
+ EACH = "EA",
229
+ /** Piece */
230
+ PIECE = "H87",
231
+ /** Number of articles */
232
+ NUMBER_OF_ARTICLES = "NAR",
233
+ /** Pair */
234
+ PAIR = "PR",
235
+ /** Set */
236
+ SET = "SET",
237
+ /** Dozen */
238
+ DOZEN = "DZN",
239
+ /** Lot */
240
+ LOT = "LOT",
241
+ /** Hundred */
242
+ HUNDRED = "CEN",
243
+ /** Thousand */
244
+ THOUSAND = "MIL",
245
+ /** Minute */
246
+ MINUTE = "MIN",
247
+ /** Hour */
248
+ HOUR = "HUR",
249
+ /** Day */
250
+ DAY = "DAY",
251
+ /** Week */
252
+ WEEK = "WEE",
253
+ /** Month */
254
+ MONTH = "MON",
255
+ /** Year */
256
+ YEAR = "ANN",
257
+ /** Gram */
258
+ GRAM = "GRM",
259
+ /** Kilogram */
260
+ KILOGRAM = "KGM",
261
+ /** Tonne (metric ton, 1000 kg) */
262
+ TONNE = "TNE",
263
+ /** Millimetre */
264
+ MILLIMETRE = "MMT",
265
+ /** Centimetre */
266
+ CENTIMETRE = "CMT",
267
+ /** Metre */
268
+ METRE = "MTR",
269
+ /** Kilometre */
270
+ KILOMETRE = "KMT",
271
+ /** Square metre */
272
+ SQUARE_METRE = "MTK",
273
+ /** Millilitre */
274
+ MILLILITRE = "MLT",
275
+ /** Litre */
276
+ LITRE = "LTR",
277
+ /** Cubic metre */
278
+ CUBIC_METRE = "MTQ",
279
+ /** Kilowatt hour */
280
+ KILOWATT_HOUR = "KWH",
281
+ /** Megawatt hour */
282
+ MEGAWATT_HOUR = "MWH",
283
+ /** Package */
284
+ PACKAGE = "XPK",
285
+ /** Pallet */
286
+ PALLET = "XPX",
287
+ /** Box */
288
+ BOX = "XBX",
289
+ /** Carton */
290
+ CARTON = "XCT",
291
+ /** Byte (8 bits) */
292
+ BYTE = "AD",
293
+ /** Kilobyte (10³ bytes) */
294
+ KILOBYTE = "2P",
295
+ /** Megabyte (10⁶ bytes) */
296
+ MEGABYTE = "4L",
297
+ /** Gigabyte (10⁹ bytes) */
298
+ GIGABYTE = "E34",
299
+ /** Terabyte (10¹² bytes) */
300
+ TERABYTE = "E35",
301
+ /** Petabyte (10¹⁵ bytes) */
302
+ PETABYTE = "E36",
303
+ /** Byte per second */
304
+ BYTE_PER_SECOND = "P93",
305
+ /** Kilobyte per second */
306
+ KILOBYTE_PER_SECOND = "P94",
307
+ /** Lump sum */
308
+ LUMP_SUM = "LS",
309
+ /** Percent */
310
+ PERCENT = "P1",
311
+ /** Sheet */
312
+ SHEET = "ST",
313
+ /** Roll */
314
+ ROLL = "RO"
315
+ }
316
+ /**
317
+ * Note attached to the invoice document.
318
+ *
319
+ * @see EN 16931 BG-1
320
+ * @since BASIC_WL
321
+ */
322
+ interface NoteInput {
323
+ /** Free-text content of the note */
324
+ content: string;
325
+ /**
326
+ * Subject code qualifying the note (e.g. `"AAK"` = discount terms,
327
+ * `"REG"` = regulatory information). Optional.
328
+ */
329
+ subjectCode?: string;
330
+ }
331
+ /**
332
+ * Invoice document metadata.
333
+ *
334
+ * @see EN 16931 BT-1 (id), BT-2 (issueDate), BT-3 (typeCode)
335
+ */
336
+ interface InvoiceDocumentInput {
337
+ /**
338
+ * Invoice number — mandatory for all profiles.
339
+ * @see EN 16931 BT-1
340
+ */
341
+ id: string;
342
+ /**
343
+ * Issue date — mandatory, format `YYYY-MM-DD`.
344
+ * @see EN 16931 BT-2
345
+ */
346
+ issueDate: string;
347
+ /**
348
+ * Document type code (BT-3).
349
+ * Use the {@link DocumentTypeCode} enum for type-safe values.
350
+ * @default {@link DocumentTypeCode.COMMERCIAL_INVOICE} (`'380'`)
351
+ * @see EN 16931 BT-3
352
+ */
353
+ typeCode?: DocumentTypeCode;
354
+ /**
355
+ * Due date — optional at document level (often set via {@link PaymentInput.dueDate}).
356
+ * @see EN 16931 BT-9
357
+ */
358
+ dueDate?: string;
359
+ /**
360
+ * Document name / title — optional.
361
+ * @since EXTENDED
362
+ */
363
+ name?: string;
364
+ /**
365
+ * Language code (ISO 639-1, e.g. `"en"`, `"de"`, `"fr"`).
366
+ * @since EXTENDED
367
+ */
368
+ language?: string;
369
+ /**
370
+ * Buyer reference — often the purchase order or Leitweg-ID (XRechnung).
371
+ * @see EN 16931 BT-10
372
+ * @since MINIMUM
373
+ */
374
+ buyerReference?: string;
375
+ /**
376
+ * Notes attached to the invoice.
377
+ * @see EN 16931 BG-1
378
+ * @since BASIC_WL
379
+ */
380
+ notes?: NoteInput[];
381
+ /**
382
+ * Business process identifier (e.g. PEPPOL `urn:fdc:peppol.eu:2017:poacc:billing:01:1.0`).
383
+ * @see EN 16931 BT-23
384
+ */
385
+ businessProcessId?: string;
386
+ }
387
+ /**
388
+ * Postal address.
389
+ *
390
+ * @see EN 16931 BT-35–BT-39 (Seller), BT-50–BT-54 (Buyer)
391
+ */
392
+ interface AddressInput {
393
+ /** Street and number (BT-35 / BT-50) */
394
+ line1: string;
395
+ /** Additional address line (BT-36 / BT-51) */
396
+ line2?: string;
397
+ /** Third address line */
398
+ line3?: string;
399
+ /** City (BT-37 / BT-52) — mandatory when address present */
400
+ city: string;
401
+ /** Postal code (BT-38 / BT-53) */
402
+ postalCode: string;
403
+ /**
404
+ * Country code (ISO 3166-1 alpha-2, e.g. `"DE"`, `"FR"`).
405
+ * @see EN 16931 BT-40 / BT-55
406
+ */
407
+ country: string;
408
+ /** Country subdivision (e.g. state/province) */
409
+ subdivision?: string;
410
+ }
411
+ /**
412
+ * Contact information.
413
+ *
414
+ * @see EN 16931 BG-6 (Seller contact), BG-9 (Buyer contact)
415
+ * @since EN16931
416
+ */
417
+ interface ContactInput {
418
+ /** Contact person name (BT-41 / BT-56) */
419
+ name?: string;
420
+ /** Department name */
421
+ department?: string;
422
+ /** Phone number (BT-42 / BT-57) */
423
+ phone?: string;
424
+ /** Email address (BT-43 / BT-58) */
425
+ email?: string;
426
+ }
427
+ /**
428
+ * Tax registration entry (VAT ID or local tax number).
429
+ *
430
+ * The `schemeId` distinguishes `"VA"` (VAT) from `"FC"` (fiscal/tax number).
431
+ * @since MINIMUM (VAT only)
432
+ */
433
+ interface TaxRegistrationInput {
434
+ /** Tax registration ID (e.g. `"DE123456789"`) */
435
+ id: string;
436
+ /**
437
+ * Scheme: `"VA"` for VAT, `"FC"` for fiscal/tax number.
438
+ * @default `"VA"`
439
+ */
440
+ schemeId?: "VA" | "FC";
441
+ }
442
+ /**
443
+ * Legal organization details.
444
+ *
445
+ * @see EN 16931 BT-30 (Seller legal registration), BT-47 (Buyer)
446
+ * @since MINIMUM
447
+ */
448
+ interface LegalOrganizationInput {
449
+ /** Registration identifier */
450
+ id?: string;
451
+ /** Trading business name */
452
+ tradingName?: string;
453
+ }
454
+ /**
455
+ * Trade party (seller, buyer, payee, etc.).
456
+ *
457
+ * @see EN 16931 BG-4 (Seller), BG-7 (Buyer)
458
+ */
459
+ interface TradePartyInput {
460
+ /**
461
+ * Party name — mandatory for all profiles.
462
+ * @see EN 16931 BT-27 (Seller), BT-44 (Buyer)
463
+ */
464
+ name: string;
465
+ /**
466
+ * Party identifiers (can have multiples, e.g. GLN).
467
+ * @see EN 16931 BT-29 / BT-46
468
+ */
469
+ id?: string | string[];
470
+ /**
471
+ * Global identifier with scheme (e.g. GLN `"0088:1234567890123"`).
472
+ * @see EN 16931 BT-29-1 / BT-46-1
473
+ */
474
+ globalId?: string;
475
+ /** Postal address — mandatory for BASIC_WL and above */
476
+ address?: AddressInput;
477
+ /**
478
+ * Contact information.
479
+ * @since EN16931
480
+ */
481
+ contact?: ContactInput;
482
+ /**
483
+ * Electronic address (e.g. email or URI for e-delivery).
484
+ * @see EN 16931 BT-34 / BT-49
485
+ */
486
+ electronicAddress?: string;
487
+ /**
488
+ * Tax registrations (VAT ID, fiscal number).
489
+ * @see EN 16931 BT-31 / BT-48
490
+ */
491
+ taxRegistrations?: TaxRegistrationInput[];
492
+ /**
493
+ * Legal organization info.
494
+ * @see EN 16931 BT-30 / BT-47
495
+ */
496
+ legalOrganization?: LegalOrganizationInput;
497
+ /**
498
+ * Description of the party.
499
+ * @since EN16931
500
+ */
501
+ description?: string;
502
+ }
503
+ /**
504
+ * Invoice line item.
505
+ * Required for BASIC, EN 16931, EXTENDED profiles.
506
+ *
507
+ * @see EN 16931 BG-25
508
+ */
509
+ interface InvoiceLineInput {
510
+ /**
511
+ * Line ID — mandatory.
512
+ * @see EN 16931 BT-126
513
+ */
514
+ id: string;
515
+ /**
516
+ * Item name/description — mandatory.
517
+ * @see EN 16931 BT-153
518
+ */
519
+ name: string;
520
+ /**
521
+ * Quantity — mandatory.
522
+ * @see EN 16931 BT-129
523
+ */
524
+ quantity: number;
525
+ /**
526
+ * Unit of measure (UN/CEFACT Rec 20).
527
+ * Use the {@link UnitCode} enum for common codes, or pass any
528
+ * valid Rec 20 string for codes not in the enum.
529
+ *
530
+ * @default {@link UnitCode.UNIT} (`'C62'`) when omitted
531
+ * @see EN 16931 BT-130
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * unitCode: UnitCode.HOUR // 'HUR'
536
+ * unitCode: UnitCode.KILOGRAM // 'KGM'
537
+ * unitCode: 'XYZ' // any Rec 20 code
538
+ * ```
539
+ */
540
+ unitCode?: UnitCode | (string & Record<never, never>);
541
+ /**
542
+ * Net unit price — mandatory for line-level.
543
+ * @see EN 16931 BT-146
544
+ */
545
+ unitPrice: number;
546
+ /**
547
+ * Gross unit price (before allowances).
548
+ * @see EN 16931 BT-148
549
+ */
550
+ grossUnitPrice?: number;
551
+ /**
552
+ * Line total (net) — can be derived from `quantity * unitPrice`.
553
+ * @see EN 16931 BT-131
554
+ */
555
+ lineTotal?: number;
556
+ /**
557
+ * VAT category code (e.g. `"S"`, `"Z"`, `"E"`, `"G"`).
558
+ * @see EN 16931 BT-151
559
+ */
560
+ vatCategoryCode?: VatCategoryCode | (string & Record<never, never>);
561
+ /**
562
+ * VAT rate in percent (e.g. `19`, `7`, `0`).
563
+ * @see EN 16931 BT-152
564
+ */
565
+ vatRatePercent?: number;
566
+ /**
567
+ * Item description (longer than name).
568
+ * @see EN 16931 BT-154
569
+ */
570
+ description?: string;
571
+ /**
572
+ * Item standard identifier (e.g. GTIN/EAN).
573
+ * @see EN 16931 BT-157
574
+ */
575
+ standardIdentifier?: string;
576
+ /**
577
+ * Seller-assigned item identifier.
578
+ * @see EN 16931 BT-155
579
+ */
580
+ sellerAssignedId?: string;
581
+ /**
582
+ * Buyer-assigned item identifier.
583
+ * @see EN 16931 BT-156
584
+ */
585
+ buyerAssignedId?: string;
586
+ /**
587
+ * Item classification code (e.g. CPV, UNSPC).
588
+ * @see EN 16931 BT-158
589
+ */
590
+ classification?: string;
591
+ /**
592
+ * Country of origin (ISO 3166-1 alpha-2).
593
+ * @see EN 16931 BT-159
594
+ * @since EN16931
595
+ */
596
+ originCountry?: string;
597
+ /**
598
+ * Line note.
599
+ * @since BASIC
600
+ */
601
+ note?: string;
602
+ /**
603
+ * Buyer order line reference.
604
+ * @since EN16931
605
+ */
606
+ buyerOrderLineId?: string;
607
+ }
608
+ /**
609
+ * Allowance or charge at header or line level.
610
+ *
611
+ * @see EN 16931 BG-20 (document level allowances), BG-21 (charges)
612
+ * @since BASIC_WL
613
+ */
614
+ interface AllowanceChargeInput {
615
+ /**
616
+ * `true` = charge, `false` = allowance.
617
+ * @see EN 16931 BT-98 / BT-107
618
+ */
619
+ isCharge: boolean;
620
+ /**
621
+ * Amount.
622
+ * @see EN 16931 BT-99 / BT-92
623
+ */
624
+ amount: number;
625
+ /**
626
+ * Reason code (UNCL 5189 for allowances, UNCL 7161 for charges).
627
+ * @see EN 16931 BT-98 / BT-105
628
+ */
629
+ reasonCode?: string;
630
+ /** Reason text */
631
+ reason?: string;
632
+ /** Base amount (for percentage calculation) */
633
+ baseAmount?: number;
634
+ /** Percentage */
635
+ percent?: number;
636
+ /** VAT category code for this allowance/charge */
637
+ vatCategoryCode?: VatCategoryCode | (string & Record<never, never>);
638
+ /** VAT rate for this allowance/charge */
639
+ vatRatePercent?: number;
640
+ }
641
+ /**
642
+ * Payment information.
643
+ *
644
+ * @see EN 16931 BG-16
645
+ * @since BASIC_WL
646
+ */
647
+ interface PaymentInput {
648
+ /**
649
+ * Payment means code (UNCL 4461, e.g. `"30"` = credit transfer,
650
+ * `"58"` = SEPA credit transfer, `"59"` = SEPA direct debit).
651
+ * @see EN 16931 BT-81
652
+ */
653
+ meansCode?: string;
654
+ /**
655
+ * Payment due date.
656
+ * @see EN 16931 BT-9
657
+ */
658
+ dueDate?: string;
659
+ /**
660
+ * Payment reference / remittance information.
661
+ * @see EN 16931 BT-83
662
+ */
663
+ paymentReference?: string;
664
+ /**
665
+ * Creditor reference (for SEPA direct debit).
666
+ * @see EN 16931 BT-90
667
+ */
668
+ creditorReference?: string;
669
+ /**
670
+ * IBAN of the payee.
671
+ * @see EN 16931 BT-84
672
+ */
673
+ iban?: string;
674
+ /**
675
+ * Proprietary account ID (non-IBAN).
676
+ */
677
+ accountId?: string;
678
+ /**
679
+ * Account name.
680
+ * @see EN 16931 BT-85
681
+ * @since EN16931
682
+ */
683
+ accountName?: string;
684
+ /**
685
+ * BIC/SWIFT code.
686
+ * @see EN 16931 BT-86
687
+ * @since EN16931
688
+ */
689
+ bic?: string;
690
+ /**
691
+ * SEPA direct debit mandate ID.
692
+ * @see EN 16931 BT-89
693
+ */
694
+ mandateId?: string;
695
+ /**
696
+ * Debtor IBAN (for direct debit).
697
+ * @see EN 16931 BT-91
698
+ */
699
+ debtorIban?: string;
700
+ /**
701
+ * Payment terms description (free text).
702
+ * @see EN 16931 BT-20
703
+ */
704
+ termsDescription?: string;
705
+ }
706
+ /**
707
+ * Delivery information.
708
+ *
709
+ * @see EN 16931 BG-13
710
+ * @since BASIC_WL
711
+ */
712
+ interface DeliveryInput {
713
+ /**
714
+ * Actual delivery date.
715
+ * @see EN 16931 BT-72
716
+ */
717
+ date?: string;
718
+ /**
719
+ * Ship-to address.
720
+ * @see EN 16931 BG-15
721
+ */
722
+ location?: AddressInput;
723
+ /**
724
+ * Ship-to party name.
725
+ * @see EN 16931 BT-70
726
+ */
727
+ partyName?: string;
728
+ /**
729
+ * Despatch advice reference.
730
+ * @see EN 16931 BT-16
731
+ */
732
+ despatchAdviceReference?: string;
733
+ }
734
+ /**
735
+ * Invoice monetary totals — mandatory for all profiles.
736
+ *
737
+ * @see EN 16931 BG-22
738
+ */
739
+ interface InvoiceTotalsInput {
740
+ /**
741
+ * Sum of all line totals (net).
742
+ * @see EN 16931 BT-106
743
+ */
744
+ lineTotal: number;
745
+ /**
746
+ * Sum of allowances at document level.
747
+ * @see EN 16931 BT-107
748
+ */
749
+ allowanceTotal?: number;
750
+ /**
751
+ * Sum of charges at document level.
752
+ * @see EN 16931 BT-108
753
+ */
754
+ chargeTotal?: number;
755
+ /**
756
+ * Tax-exclusive amount (net total).
757
+ * @see EN 16931 BT-109
758
+ */
759
+ taxBasisTotal: number;
760
+ /**
761
+ * Total VAT amount.
762
+ * @see EN 16931 BT-110
763
+ */
764
+ taxTotal: number;
765
+ /**
766
+ * Grand total including VAT.
767
+ * @see EN 16931 BT-112
768
+ */
769
+ grandTotal: number;
770
+ /**
771
+ * Prepaid amount.
772
+ * @see EN 16931 BT-113
773
+ */
774
+ prepaidAmount?: number;
775
+ /**
776
+ * Due payable amount.
777
+ * @see EN 16931 BT-115
778
+ */
779
+ duePayableAmount: number;
780
+ /**
781
+ * Invoice currency code (ISO 4217, e.g. `"EUR"`).
782
+ * @see EN 16931 BT-5
783
+ */
784
+ currency: string;
785
+ /**
786
+ * Tax currency code (if different from invoice currency).
787
+ * @see EN 16931 BT-6
788
+ */
789
+ taxCurrency?: string;
790
+ }
791
+ /**
792
+ * VAT/tax breakdown entry — required for BASIC_WL and above.
793
+ *
794
+ * @see EN 16931 BG-23
795
+ */
796
+ interface VatBreakdownInput {
797
+ /**
798
+ * VAT category code (`"S"` = standard, `"Z"` = zero, `"E"` = exempt,
799
+ * `"G"` = free export, `"K"` = intra-community, `"AE"` = reverse charge, etc.).
800
+ * @see EN 16931 BT-118
801
+ */
802
+ categoryCode: VatCategoryCode | (string & Record<never, never>);
803
+ /**
804
+ * VAT rate in percent.
805
+ * @see EN 16931 BT-119
806
+ */
807
+ ratePercent: number;
808
+ /**
809
+ * Taxable amount (basis).
810
+ * @see EN 16931 BT-116
811
+ */
812
+ taxableAmount: number;
813
+ /**
814
+ * Tax amount.
815
+ * @see EN 16931 BT-117
816
+ */
817
+ taxAmount: number;
818
+ /**
819
+ * Exemption reason text.
820
+ * @see EN 16931 BT-120
821
+ */
822
+ exemptionReason?: string;
823
+ /**
824
+ * Exemption reason code.
825
+ * @see EN 16931 BT-121
826
+ */
827
+ exemptionReasonCode?: string;
828
+ }
829
+ /**
830
+ * Document reference (contract, order, preceding invoice, etc.).
831
+ *
832
+ * @see EN 16931 BT-12–BT-25
833
+ * @since MINIMUM (buyerOrderReference), BASIC_WL (others)
834
+ */
835
+ interface DocumentReferenceInput {
836
+ /**
837
+ * Reference ID.
838
+ * @see EN 16931 BT-13 (order), BT-12 (contract), BT-25 (preceding invoice)
839
+ */
840
+ id: string;
841
+ /**
842
+ * Reference type: determines where this reference is placed in XML.
843
+ * - `"order"` → BuyerOrderReferencedDocument
844
+ * - `"contract"` → ContractReferencedDocument
845
+ * - `"despatch"` → DespatchAdviceReferencedDocument
846
+ * - `"preceding"` → InvoiceReferencedDocument
847
+ * - `"seller-order"` → SellerOrderReferencedDocument (EN16931+)
848
+ * - `"project"` → SpecifiedProcuringProject (EN16931+)
849
+ *
850
+ * @default `"order"`
851
+ */
852
+ type?: "order" | "contract" | "despatch" | "preceding" | "seller-order" | "project";
853
+ /** Issue date of the referenced document */
854
+ issueDate?: string;
855
+ }
856
+ /**
857
+ * Billing/invoicing period.
858
+ *
859
+ * @see EN 16931 BG-14
860
+ * @since BASIC_WL
861
+ */
862
+ interface BillingPeriodInput {
863
+ /** Period start date (YYYY-MM-DD) */
864
+ startDate?: string;
865
+ /** Period end date (YYYY-MM-DD) */
866
+ endDate?: string;
867
+ }
868
+ /**
869
+ * Root input for Factur-X invoice generation.
870
+ *
871
+ * Use this object with {@link embedFacturX} or {@link toXRechnung}.
872
+ * The same structure supports all profiles; fields not applicable
873
+ * to the chosen profile are silently ignored.
874
+ *
875
+ * @example
876
+ * ```ts
877
+ * const input: FacturXInvoiceInput = {
878
+ * document: { id: 'INV-001', issueDate: '2025-03-01', typeCode: DocumentTypeCode.COMMERCIAL_INVOICE },
879
+ * seller: { name: 'StackForge UG (haftungsbeschränkt)', address: { line1: 'Bergstraße 4', city: 'Weihmichl', postalCode: '84107', country: 'DE' } },
880
+ * buyer: { name: 'Kite-Engineer by Stefan Merthan', address: { line1: 'Hauptstraße 6', city: 'Weihmichl', postalCode: '84107', country: 'DE' } },
881
+ * totals: { lineTotal: 100, taxBasisTotal: 100, taxTotal: 19, grandTotal: 119, duePayableAmount: 119, currency: 'EUR' },
882
+ * vatBreakdown: [{ categoryCode: 'S', ratePercent: 19, taxableAmount: 100, taxAmount: 19 }],
883
+ * };
884
+ * ```
885
+ *
886
+ * @see docs/INPUT_OBJECT_SPECIFICATION.md
887
+ */
888
+ interface FacturXInvoiceInput {
889
+ /** Document metadata — mandatory */
890
+ document: InvoiceDocumentInput;
891
+ /** Seller (supplier) party — mandatory */
892
+ seller: TradePartyInput;
893
+ /** Buyer party — mandatory */
894
+ buyer: TradePartyInput;
895
+ /**
896
+ * Invoice lines — required for BASIC, EN 16931, EXTENDED.
897
+ * @see EN 16931 BG-25
898
+ */
899
+ lines?: InvoiceLineInput[];
900
+ /**
901
+ * Document-level allowances and charges.
902
+ * @see EN 16931 BG-20, BG-21
903
+ * @since BASIC_WL
904
+ */
905
+ allowancesCharges?: AllowanceChargeInput[];
906
+ /**
907
+ * Payment information.
908
+ * @see EN 16931 BG-16
909
+ * @since BASIC_WL
910
+ */
911
+ payment?: PaymentInput;
912
+ /**
913
+ * Delivery information.
914
+ * @see EN 16931 BG-13
915
+ * @since BASIC_WL
916
+ */
917
+ delivery?: DeliveryInput;
918
+ /** Monetary totals — mandatory */
919
+ totals: InvoiceTotalsInput;
920
+ /**
921
+ * VAT breakdown — required for BASIC_WL and above.
922
+ * @see EN 16931 BG-23
923
+ */
924
+ vatBreakdown?: VatBreakdownInput[];
925
+ /**
926
+ * Document references (order, contract, preceding invoice, etc.).
927
+ * @see EN 16931 BG-3
928
+ */
929
+ references?: DocumentReferenceInput[];
930
+ /**
931
+ * Billing/invoicing period.
932
+ * @see EN 16931 BG-14
933
+ * @since BASIC_WL
934
+ */
935
+ billingPeriod?: BillingPeriodInput;
936
+ /**
937
+ * Payee (if different from seller).
938
+ * @see EN 16931 BG-10
939
+ * @since BASIC_WL
940
+ */
941
+ payee?: TradePartyInput;
942
+ /**
943
+ * Seller's tax representative.
944
+ * @see EN 16931 BG-11
945
+ * @since BASIC_WL
946
+ */
947
+ sellerTaxRepresentative?: TradePartyInput;
948
+ }
949
+
950
+ /**
951
+ * Flavor and Profile Constants
952
+ *
953
+ * Defines URNs, default document type codes, and standard sets
954
+ * for different country/system implementations.
955
+ *
956
+ * @module flavors/constants
957
+ */
958
+ /** Factur-X / ZUGFeRD profile levels */
959
+ declare enum Profile {
960
+ MINIMUM = "MINIMUM",
961
+ BASIC_WL = "BASIC_WL",
962
+ BASIC = "BASIC",
963
+ EN16931 = "EN16931",
964
+ EXTENDED = "EXTENDED"
965
+ }
966
+ /** Country/system flavor */
967
+ declare enum Flavor {
968
+ FACTUR_X = "factur-x",
969
+ ZUGFERD = "zugferd",
970
+ XRECHNUNG = "xrechnung",
971
+ CHRONO_PRO = "chrono-pro"
972
+ }
973
+ /** Profile URNs (GuidelineSpecifiedDocumentContextParameter) */
974
+ declare const PROFILE_URNS: Record<Profile, string>;
975
+
976
+ /**
977
+ * Default document type code per flavor.
978
+ * All flavors default to {@link DocumentTypeCode.COMMERCIAL_INVOICE} (`380`).
979
+ */
980
+ declare const FLAVOR_DEFAULT_TYPE_CODES: Record<Flavor, DocumentTypeCode>;
981
+ /**
982
+ * Schema directory names per profile (relative to schema/)
983
+ */
984
+ declare const PROFILE_SCHEMA_DIRS: Record<Profile, string>;
985
+ /**
986
+ * Main XSD filename per profile
987
+ */
988
+ declare const PROFILE_MAIN_XSD: Record<Profile, string>;
989
+
990
+ /**
991
+ * Flavor configuration registry.
992
+ *
993
+ * Provides flavor-specific settings (profiles, type codes, filenames, etc.)
994
+ * and validation/resolution utilities for invoice generation.
995
+ *
996
+ * @module flavors/registry
997
+ */
998
+
999
+ /** Configuration for a specific flavor */
1000
+ interface FlavorConfig {
1001
+ /** Display name */
1002
+ name: string;
1003
+ /** Supported profiles for this flavor */
1004
+ supportedProfiles: Profile[];
1005
+ /** Default document type code */
1006
+ defaultTypeCode: DocumentTypeCode;
1007
+ /** Business process URN (optional, e.g. PEPPOL for XRechnung) */
1008
+ businessProcessUrn?: string;
1009
+ /** XML attachment filename in the PDF */
1010
+ attachmentFilename: string;
1011
+ /** Whether this flavor embeds into PDF (false for xrechnung = XML only) */
1012
+ embedInPdf: boolean;
1013
+ /** Additional constraints or requirements description */
1014
+ description: string;
1015
+ }
1016
+ /** Flavor configuration registry */
1017
+ declare const FLAVOR_CONFIGS: Record<Flavor, FlavorConfig>;
1018
+ /**
1019
+ * Returns the configuration for a given flavor.
1020
+ * @param flavor - The flavor to look up
1021
+ * @returns The flavor configuration
1022
+ */
1023
+ declare function getFlavorConfig(flavor: Flavor): FlavorConfig;
1024
+ /**
1025
+ * Validates that the given profile is supported for the flavor.
1026
+ * @param flavor - The flavor to validate against
1027
+ * @param profile - The profile to validate
1028
+ * @throws Error if the profile is not supported for the flavor
1029
+ */
1030
+ declare function validateFlavorProfile(flavor: Flavor, profile: Profile): void;
1031
+ /**
1032
+ * Resolves the document type code from input or flavor default.
1033
+ * @param input - The invoice input
1034
+ * @param flavor - The target flavor
1035
+ * @returns The resolved type code (input's typeCode or flavor default)
1036
+ */
1037
+ declare function resolveTypeCode(input: FacturXInvoiceInput, flavor: Flavor): string;
1038
+ /**
1039
+ * Resolves the business process URN from input or flavor default.
1040
+ * @param input - The invoice input
1041
+ * @param flavor - The target flavor
1042
+ * @returns The business process URN if set on input or flavor, otherwise undefined
1043
+ */
1044
+ declare function resolveBusinessProcessUrn(input: FacturXInvoiceInput, flavor: Flavor): string | undefined;
1045
+
1046
+ /**
1047
+ * Escapes the five XML-reserved characters (`&`, `<`, `>`, `"`, `'`) and
1048
+ * strips control characters that are illegal in XML 1.0 (U+0000–U+0008,
1049
+ * U+000B–U+000C, U+000E–U+001F) so that arbitrary text can be safely
1050
+ * embedded in an XML document.
1051
+ */
1052
+ declare function escapeXml(value: string): string;
1053
+ /**
1054
+ * Builds a UN/CEFACT CrossIndustryInvoice XML string from structured input.
1055
+ *
1056
+ * The output conforms to the Factur-X 1.08 / ZUGFeRD 2.4 CII schema at the
1057
+ * requested {@link Profile} level. Elements that do not belong to the chosen
1058
+ * profile are silently omitted.
1059
+ *
1060
+ * @param input - Structured invoice data (see {@link FacturXInvoiceInput}).
1061
+ * @param profile - Target Factur-X profile (`MINIMUM` … `EXTENDED`).
1062
+ * @param flavor - Optional flavor; defaults to {@link Flavor.FACTUR_X}. Affects the
1063
+ * fallback document type code when `input.document.typeCode`
1064
+ * is not set.
1065
+ * @returns A complete XML document string (UTF-8 declaration, no BOM).
1066
+ */
1067
+ declare function buildXml(input: FacturXInvoiceInput, profile: Profile, flavor?: Flavor): string;
1068
+
1069
+ /**
1070
+ * Profile-based validation for Factur-X invoice input.
1071
+ *
1072
+ * Validates that a {@link FacturXInvoiceInput} contains all required fields
1073
+ * for a given profile level (MINIMUM → EXTENDED).
1074
+ *
1075
+ * @module validation/profile-validator
1076
+ */
1077
+
1078
+ /**
1079
+ * Describes a single validation error (missing or invalid required field).
1080
+ */
1081
+ interface ValidationError {
1082
+ /** Dot-path to the field (e.g. `"seller.address.country"`) */
1083
+ field: string;
1084
+ /** Human-readable error message */
1085
+ message: string;
1086
+ /** The profile level that requires this field */
1087
+ profile: Profile;
1088
+ }
1089
+ /**
1090
+ * Result of validating input against a profile.
1091
+ */
1092
+ interface ValidationResult {
1093
+ /** Whether validation passed (no errors) */
1094
+ valid: boolean;
1095
+ /** List of validation errors, empty when valid */
1096
+ errors: ValidationError[];
1097
+ }
1098
+ /**
1099
+ * Validates that the input contains all required fields for the given profile.
1100
+ * Requirements are cumulative: each profile includes all requirements of lower levels.
1101
+ *
1102
+ * @param input - Invoice input to validate
1103
+ * @param profile - Target profile (MINIMUM, BASIC_WL, BASIC, EN16931, or EXTENDED)
1104
+ * @returns Validation result with valid flag and any errors
1105
+ */
1106
+ declare function validateInput(input: FacturXInvoiceInput, profile: Profile): ValidationResult;
1107
+
1108
+ /**
1109
+ * XSD Schema Validation
1110
+ *
1111
+ * Validates generated CII XML against the official Factur-X / ZUGFeRD XSD
1112
+ * schemas using {@link https://github.com/jameslan/libxml2-wasm | libxml2-wasm}
1113
+ * (WebAssembly port of libxml2).
1114
+ *
1115
+ * Schema files are shipped with the package in `schema/` and loaded at
1116
+ * validation time. Because `libxml2-wasm` is ESM-only, this module uses
1117
+ * dynamic `import()` so the package stays consumable from both CJS and ESM.
1118
+ *
1119
+ * @module validation/xsd-validator
1120
+ * @license EUPL-1.2
1121
+ */
1122
+
1123
+ /**
1124
+ * A single XSD validation error.
1125
+ */
1126
+ interface XsdValidationError {
1127
+ /** Human-readable error message from the XSD validator */
1128
+ message: string;
1129
+ /** Line number in the XML document, if available */
1130
+ line?: number;
1131
+ /** Column number in the XML document, if available */
1132
+ column?: number;
1133
+ }
1134
+ /**
1135
+ * Result returned by {@link validateXsd}.
1136
+ */
1137
+ interface XsdValidationResult {
1138
+ /** Whether the XML is valid against the profile XSD */
1139
+ valid: boolean;
1140
+ /** List of XSD validation errors (empty when valid) */
1141
+ errors: XsdValidationError[];
1142
+ }
1143
+ /**
1144
+ * Options for {@link validateXsd}.
1145
+ */
1146
+ interface XsdValidateOptions {
1147
+ /**
1148
+ * Override the base path where the `schema/` folder is located.
1149
+ * Defaults to auto-detection from the package installation directory.
1150
+ */
1151
+ schemaBasePath?: string;
1152
+ }
1153
+ /**
1154
+ * Validates XML against the Factur-X XSD schema for a given profile.
1155
+ *
1156
+ * Uses `libxml2-wasm` (WASM port of libxml2) for full schema validation
1157
+ * including namespace imports. The library is loaded via dynamic `import()`
1158
+ * to keep the package compatible with CommonJS consumers.
1159
+ *
1160
+ * @param xml - The XML string to validate
1161
+ * @param profile - The Factur-X profile whose XSD to validate against
1162
+ * @param options - Optional settings (e.g. schema path override)
1163
+ * @returns Validation result with errors (if any)
1164
+ *
1165
+ * @example
1166
+ * ```ts
1167
+ * const result = await validateXsd(xmlString, Profile.EN16931);
1168
+ * if (!result.valid) {
1169
+ * console.error('XSD errors:', result.errors);
1170
+ * }
1171
+ * ```
1172
+ */
1173
+ declare function validateXsd(xml: string, profile: Profile, options?: XsdValidateOptions): Promise<XsdValidationResult>;
1174
+
1175
+ /**
1176
+ * Factur-X PDF Embedding
1177
+ *
1178
+ * Embeds structured invoice XML into a PDF document and ensures
1179
+ * PDF/A-3 compliance via XMP metadata.
1180
+ *
1181
+ * @module core/embed
1182
+ * @license EUPL-1.2
1183
+ */
1184
+
1185
+ /** Options for embedding Factur-X XML into a PDF. */
1186
+ interface EmbedOptions {
1187
+ /** Input PDF as Buffer or Uint8Array. */
1188
+ pdf: Uint8Array | Buffer;
1189
+ /** Pre-built XML string. If not provided, will build from {@link input}. */
1190
+ xml?: string;
1191
+ /** Structured invoice input. Used to build XML if {@link xml} is not provided. */
1192
+ input?: FacturXInvoiceInput;
1193
+ /** Profile level. */
1194
+ profile: Profile;
1195
+ /** Flavor (default: {@link Flavor.FACTUR_X}). */
1196
+ flavor?: Flavor;
1197
+ /** Validate input before generating XML (default: `true`). */
1198
+ validateBeforeEmbed?: boolean;
1199
+ /**
1200
+ * Run XSD schema validation on the generated XML (default: `false`).
1201
+ * Requires schema files to be present (shipped with the package).
1202
+ */
1203
+ validateXsd?: boolean;
1204
+ /** Add PDF/A-3 metadata (default: `true`). */
1205
+ addPdfA3Metadata?: boolean;
1206
+ /**
1207
+ * Override the AF relationship for the embedded XML attachment.
1208
+ *
1209
+ * Per the Factur-X specification:
1210
+ * - MINIMUM / BASIC_WL → `Data` (XML carries structured data only)
1211
+ * - BASIC / EN16931 / EXTENDED → `Alternative` (XML is a full representation)
1212
+ *
1213
+ * When not set, the correct value is derived automatically from {@link profile}.
1214
+ */
1215
+ afRelationship?: "Alternative" | "Data" | "Source";
1216
+ /** PDF metadata overrides. */
1217
+ meta?: {
1218
+ author?: string;
1219
+ title?: string;
1220
+ subject?: string;
1221
+ creator?: string;
1222
+ };
1223
+ }
1224
+ /** Result returned by {@link embedFacturX}. */
1225
+ interface EmbedResult {
1226
+ /** The resulting PDF bytes. */
1227
+ pdf: Uint8Array;
1228
+ /** The XML that was embedded. */
1229
+ xml: string;
1230
+ /** Profile validation result (if validation was performed). */
1231
+ validation?: ValidationResult;
1232
+ /** XSD schema validation result (if XSD validation was requested). */
1233
+ xsdValidation?: XsdValidationResult;
1234
+ }
1235
+ /**
1236
+ * Embeds Factur-X / ZUGFeRD XML into a PDF and sets PDF/A-3b metadata.
1237
+ *
1238
+ * Either provide a pre-built `xml` string or a structured `input` from which
1239
+ * the XML will be generated. The resulting PDF contains the XML as an
1240
+ * embedded attachment with the correct AF relationship and XMP metadata
1241
+ * declaring PDF/A-3b conformance.
1242
+ *
1243
+ * @param options - Embedding configuration
1244
+ * @returns The PDF bytes, embedded XML, and optional validation result
1245
+ *
1246
+ * @example
1247
+ * ```ts
1248
+ * const result = await embedFacturX({
1249
+ * pdf: existingPdfBytes,
1250
+ * input: invoiceData,
1251
+ * profile: Profile.EN16931,
1252
+ * });
1253
+ * fs.writeFileSync('invoice.pdf', result.pdf);
1254
+ * ```
1255
+ */
1256
+ declare function embedFacturX(options: EmbedOptions): Promise<EmbedResult>;
1257
+
1258
+ /**
1259
+ * Factur-X / ZUGFeRD XML Extraction from PDF
1260
+ *
1261
+ * Reads an embedded CII XML attachment from a PDF document.
1262
+ * Supports detection of all standard attachment filenames
1263
+ * (`factur-x.xml`, `xrechnung.xml`, `zugferd-invoice.xml`, `ZUGFeRD-invoice.xml`).
1264
+ *
1265
+ * @module core/extract
1266
+ * @license EUPL-1.2
1267
+ */
1268
+
1269
+ /**
1270
+ * Result returned by {@link extractXml}.
1271
+ */
1272
+ interface ExtractResult {
1273
+ /** The extracted XML string */
1274
+ xml: string;
1275
+ /** The filename of the embedded attachment */
1276
+ filename: string;
1277
+ /** The Factur-X profile detected from the XML (if identifiable) */
1278
+ profile?: Profile;
1279
+ }
1280
+ /**
1281
+ * Options for {@link extractXml}.
1282
+ */
1283
+ interface ExtractOptions {
1284
+ /**
1285
+ * Specific attachment filename to look for.
1286
+ * If not set, searches for all known Factur-X filenames.
1287
+ */
1288
+ filename?: string;
1289
+ }
1290
+ /**
1291
+ * Extracts Factur-X / ZUGFeRD XML from a PDF document.
1292
+ *
1293
+ * Searches the PDF's embedded files (Names → EmbeddedFiles) for a known
1294
+ * Factur-X attachment or a specific filename. Returns the XML content,
1295
+ * the filename, and the detected profile.
1296
+ *
1297
+ * @param pdf - Input PDF as `Uint8Array` or `Buffer`
1298
+ * @param options - Extraction options (e.g. specific filename)
1299
+ * @returns The extracted XML, filename, and detected profile
1300
+ *
1301
+ * @throws Error if no matching XML attachment is found
1302
+ *
1303
+ * @example
1304
+ * ```ts
1305
+ * import { extractXml } from '@stackforge-eu/factur-x';
1306
+ * import { readFile } from 'fs/promises';
1307
+ *
1308
+ * const pdf = await readFile('invoice.pdf');
1309
+ * const { xml, filename, profile } = await extractXml(pdf);
1310
+ * console.log(`Found ${filename} (profile: ${profile})`);
1311
+ * console.log(xml);
1312
+ * ```
1313
+ */
1314
+ declare function extractXml(pdf: Uint8Array | Buffer, options?: ExtractOptions): Promise<ExtractResult>;
1315
+
1316
+ /**
1317
+ * XRechnung Generation
1318
+ *
1319
+ * Generates standalone CII XML for German B2G (XRechnung) use.
1320
+ * XRechnung is a pure-XML format (no PDF embedding) that conforms
1321
+ * to EN 16931 with additional PEPPOL/German government requirements.
1322
+ *
1323
+ * @module core/xrechnung
1324
+ * @license EUPL-1.2
1325
+ */
1326
+
1327
+ /**
1328
+ * Options for XRechnung generation.
1329
+ */
1330
+ interface XRechnungOptions {
1331
+ /**
1332
+ * Profile level (default: {@link Profile.EN16931}).
1333
+ * XRechnung only supports EN16931.
1334
+ */
1335
+ profile?: Profile;
1336
+ /**
1337
+ * Validate input before generating XML (default: `true`).
1338
+ */
1339
+ validate?: boolean;
1340
+ }
1341
+ /**
1342
+ * Result of XRechnung generation.
1343
+ */
1344
+ interface XRechnungResult {
1345
+ /** The generated CII XML string */
1346
+ xml: string;
1347
+ /** Validation result (if validation was performed) */
1348
+ validation?: ValidationResult;
1349
+ }
1350
+ /**
1351
+ * Generates XRechnung-compliant CII XML from structured invoice input.
1352
+ *
1353
+ * XRechnung is a German B2G invoice format. It is a pure-XML format
1354
+ * (no PDF embedding) that uses the EN 16931 profile with a PEPPOL
1355
+ * business process identifier.
1356
+ *
1357
+ * The output can be uploaded directly to German government portals
1358
+ * (e.g. via PEPPOL or ZRE/OZG-RE).
1359
+ *
1360
+ * @param input - Structured invoice data
1361
+ * @param options - Generation options (profile, validation)
1362
+ * @returns The XRechnung CII XML and optional validation result
1363
+ *
1364
+ * @throws Error if input validation fails (when `validate` is `true`)
1365
+ * @throws Error if the profile is not supported for XRechnung
1366
+ *
1367
+ * @example
1368
+ * ```ts
1369
+ * const result = toXRechnung({
1370
+ * document: { id: 'INV-001', issueDate: '2025-03-01', buyerReference: '04011000-12345-67' },
1371
+ * seller: { name: 'StackForge UG (haftungsbeschränkt)', address: { line1: 'Bergstraße 4', city: 'Weihmichl', postalCode: '84107', country: 'DE' } },
1372
+ * buyer: { name: 'Kite-Engineer by Stefan Merthan', address: { line1: 'Hauptstraße 6', city: 'Weihmichl', postalCode: '84107', country: 'DE' } },
1373
+ * lines: [{ id: '1', name: 'Service', quantity: 1, unitPrice: 100, vatCategoryCode: 'S', vatRatePercent: 19 }],
1374
+ * totals: { lineTotal: 100, taxBasisTotal: 100, taxTotal: 19, grandTotal: 119, duePayableAmount: 119, currency: 'EUR' },
1375
+ * vatBreakdown: [{ categoryCode: 'S', ratePercent: 19, taxableAmount: 100, taxAmount: 19 }],
1376
+ * });
1377
+ * console.log(result.xml);
1378
+ * ```
1379
+ */
1380
+ declare function toXRechnung(input: FacturXInvoiceInput, options?: XRechnungOptions): XRechnungResult;
1381
+
1382
+ export { type AddressInput, type AllowanceChargeInput, type BillingPeriodInput, type ContactInput, type DeliveryInput, type DocumentReferenceInput, DocumentTypeCode, type EmbedOptions, type EmbedResult, type ExtractOptions, type ExtractResult, FLAVOR_CONFIGS, FLAVOR_DEFAULT_TYPE_CODES, type FacturXInvoiceInput, Flavor, type FlavorConfig, type InvoiceDocumentInput, type InvoiceLineInput, type InvoiceTotalsInput, type LegalOrganizationInput, type NoteInput, PROFILE_MAIN_XSD, PROFILE_SCHEMA_DIRS, PROFILE_URNS, type PaymentInput, Profile, type TaxRegistrationInput, type TradePartyInput, UnitCode, type ValidationError, type ValidationResult, type VatBreakdownInput, VatCategoryCode, type XRechnungOptions, type XRechnungResult, type XsdValidateOptions, type XsdValidationError, type XsdValidationResult, buildXml, embedFacturX, escapeXml, extractXml, getFlavorConfig, resolveBusinessProcessUrn, resolveTypeCode, toXRechnung, validateFlavorProfile, validateInput, validateXsd };