@financica/ubl 0.15.1 → 0.17.0

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.
package/dist/index.d.ts CHANGED
@@ -1,220 +1,12 @@
1
- //#region src/types.d.ts
2
- interface UblAddress {
3
- street: string;
4
- additionalStreet?: string;
5
- city: string;
6
- postalZone: string;
7
- countrySubentity?: string;
8
- countryCode: string;
9
- }
10
- interface UblContact {
11
- name?: string;
12
- phone?: string;
13
- email?: string;
14
- }
15
- interface UblPartyIdentification {
16
- id: string;
17
- schemeId?: string;
18
- }
19
- interface UblParty {
20
- name: string;
21
- registrationName?: string;
22
- companyLegalForm?: string;
23
- vatId?: string;
24
- taxSchemeId?: string;
25
- companyId?: string;
26
- companyIdSchemeId?: string;
27
- endpointId?: string;
28
- endpointSchemeId?: string;
29
- partyIdentifications?: UblPartyIdentification[];
30
- address?: UblAddress;
31
- contact?: UblContact;
32
- }
33
- interface UblItemProperty {
34
- name: string;
35
- value: string;
36
- }
37
- interface UblLine {
38
- id: string;
39
- description: string;
40
- quantity: number;
41
- unitCode: string;
42
- unitPrice: number;
43
- lineExtensionAmount: number;
44
- taxPercent?: number;
45
- taxAmount?: number;
46
- taxCategoryId?: string;
47
- taxSchemeId?: string;
48
- taxSubtotals?: UblTaxSubtotal[];
49
- allowanceCharges?: UblAllowanceCharge[];
50
- discountAmount?: number;
51
- chargeAmount?: number;
52
- itemName?: string;
53
- sellersItemId?: string;
54
- buyersItemId?: string;
55
- additionalItemProperties?: UblItemProperty[];
56
- /** EN 16931 BT-134/BT-135: the line's own service period. */
57
- invoicePeriod?: UblInvoicePeriod;
58
- }
59
- interface UblAllowanceCharge {
60
- chargeIndicator: boolean;
61
- amount: number;
62
- baseAmount?: number;
63
- multiplierFactorNumeric?: number;
64
- reason?: string;
65
- reasonCode?: string;
66
- taxPercent?: number;
67
- taxCategoryId?: string;
68
- taxSchemeId?: string;
69
- }
70
- interface UblTaxSubtotal {
71
- taxableAmount: number;
72
- taxAmount: number;
73
- taxPercent: number;
74
- taxCategoryId?: string;
75
- taxSchemeId?: string;
76
- taxExemptionReason?: string;
77
- }
78
- interface UblMonetaryTotal {
79
- lineExtensionAmount: number;
80
- taxExclusiveAmount: number;
81
- taxInclusiveAmount: number;
82
- allowanceTotalAmount?: number;
83
- chargeTotalAmount?: number;
84
- prepaidAmount?: number;
85
- payableRoundingAmount?: number;
86
- payableAmount: number;
87
- }
88
- interface UblPaymentMeans {
89
- code: string;
90
- codeName?: string;
91
- paymentId?: string;
92
- iban?: string;
93
- bic?: string;
94
- accountName?: string;
95
- mandateId?: string;
96
- }
97
- interface UblInvoicePeriod {
98
- startDate?: string;
99
- endDate?: string;
100
- descriptionCode?: string;
101
- }
102
- interface UblAttachment {
103
- id: string;
104
- filename?: string;
105
- mimeCode?: string;
106
- description?: string;
107
- base64Content?: string;
108
- externalUri?: string;
109
- }
110
- interface UblDocumentReference {
111
- id: string;
112
- description?: string;
113
- }
114
- interface UblDelivery {
115
- actualDeliveryDate?: string;
116
- address?: UblAddress;
117
- }
118
- interface UblBillingReference {
119
- invoiceId?: string;
120
- invoiceIssueDate?: string;
121
- }
122
- interface UblInvoice {
123
- documentType: "Invoice" | "CreditNote";
124
- customizationId?: string;
125
- profileId?: string;
126
- id: string;
127
- invoiceTypeCode?: string;
128
- issueDate: string;
129
- dueDate?: string;
130
- taxPointDate?: string;
131
- currency: string;
132
- buyerReference?: string;
133
- orderReference?: string;
134
- salesOrderId?: string;
135
- contractReference?: string;
136
- projectReference?: string;
137
- billingReference?: UblBillingReference;
138
- seller: UblParty;
139
- buyer: UblParty;
140
- delivery?: UblDelivery;
141
- lines: UblLine[];
142
- taxSubtotals: UblTaxSubtotal[];
143
- monetaryTotal: UblMonetaryTotal;
144
- paymentMeans?: UblPaymentMeans;
145
- paymentMeansList?: UblPaymentMeans[];
146
- invoicePeriod?: UblInvoicePeriod;
147
- note?: string;
148
- paymentTermsNote?: string;
149
- attachments?: UblAttachment[];
150
- documentReferences?: UblDocumentReference[];
151
- allowanceCharges?: UblAllowanceCharge[];
152
- }
153
- interface InvoiceExtractionDTO {
154
- provider: string;
155
- document_id: string;
156
- invoice: {
157
- invoice_number: string | null;
158
- invoice_date: string | null;
159
- due_date: string | null;
160
- /** EN 16931 BT-73/BT-74: the period the document bills for. */
161
- period_start: string | null;
162
- period_end: string | null;
163
- currency: string | null;
164
- subtotal: number | null;
165
- tax_total: number | null;
166
- total: number | null;
167
- amount_due: number | null;
168
- amount_paid: number | null;
169
- discount_total: number | null;
170
- shipping_total: number | null;
171
- /** EN 16931 BT-114, signed. Outside the VAT breakdown (BR-CO-16). */
172
- rounding_total: number | null;
173
- payment_terms: string | null;
174
- po_number: string | null;
175
- supplier: {
176
- name: string | null;
177
- address: string | null;
178
- tax_id: string | null;
179
- iban: string | null;
180
- bic: string | null;
181
- };
182
- receiver: {
183
- name: string | null;
184
- address: string | null;
185
- tax_id: string | null;
186
- };
187
- extra: Record<string, unknown>;
188
- };
189
- line_items: Array<{
190
- description: string;
191
- quantity: number | null;
192
- unit: string | null;
193
- unit_price: number | null;
194
- amount: number | null;
195
- tax_amount: number | null;
196
- tax_rate: number | null;
197
- product_code: string | null;
198
- discount_amount: number | null;
199
- /** EN 16931 BT-134/BT-135: the line's own service period. */
200
- period_start: string | null;
201
- period_end: string | null;
202
- extra: Record<string, unknown>;
203
- }>;
204
- confidence: {
205
- overall: number | null;
206
- fields: Record<string, number>;
207
- };
208
- }
209
- //#endregion
1
+ import { C as UblParseError, S as UblBuildError, _ as UblPartyIdentification, a as UblBillingReference, b as UblTaxSubtotal, c as UblDelivery, d as UblInvoice, f as UblInvoicePeriod, g as UblParty, h as UblMonetaryTotal, i as UblAttachment, l as UblDocumentReference, m as UblLine, n as UblAddress, o as UblCompanyId, p as UblItemProperty, r as UblAllowanceCharge, s as UblContact, t as InvoiceExtractionDTO, u as UblEndpoint, v as UblPaymentMeans, x as UblTaxTotal, y as UblTaxCategory } from "./types-DossV2at.js";
210
2
  //#region src/attachments.d.ts
211
3
  /**
212
4
  * An embedded attachment extracted from a UBL document's
213
5
  * `AdditionalDocumentReference` entries, with its binary content still
214
- * base64-encoded. `sizeBytes` is the approximate decoded size.
6
+ * base64-encoded. `sizeBytes` is the decoded size.
215
7
  */
216
8
  interface UblEmbeddedAttachment {
217
- id: string | null;
9
+ id?: string | undefined;
218
10
  filename: string;
219
11
  mimeCode: string;
220
12
  sizeBytes: number;
@@ -227,6 +19,8 @@ interface UblEmbeddedAttachment {
227
19
  * UBL invoice or credit note XML. Attachments referenced only by external URI
228
20
  * (no `EmbeddedDocumentBinaryObject`) are skipped; use {@link parseUblInvoice}
229
21
  * directly when those matter.
22
+ *
23
+ * @throws {UblParseError} when the XML is malformed or not a UBL invoice.
230
24
  */
231
25
  declare const extractUblEmbeddedAttachments: (xml: string) => UblEmbeddedAttachment[];
232
26
  /**
@@ -236,6 +30,14 @@ declare const extractUblEmbeddedAttachments: (xml: string) => UblEmbeddedAttachm
236
30
  declare const isPdfLikeAttachment: (attachment: Pick<UblAttachment, "filename" | "mimeCode">) => boolean;
237
31
  //#endregion
238
32
  //#region src/parser.d.ts
33
+ /**
34
+ * Parse a UBL 2.1 Invoice or CreditNote.
35
+ *
36
+ * Returns `null` when the XML is well-formed but its root is not a UBL
37
+ * `Invoice`/`CreditNote`. Throws {@link UblParseError} when the XML is
38
+ * malformed or the document lacks an element EN 16931 makes mandatory
39
+ * (document id, issue date, currency, line id).
40
+ */
239
41
  declare function parseUblInvoice(xml: string): UblInvoice | null;
240
42
  //#endregion
241
43
  //#region src/mlr.d.ts
@@ -248,21 +50,22 @@ declare const PEPPOL_MLR_DOCUMENT_TYPE_VALUE = "urn:oasis:names:specification:ub
248
50
  declare const PEPPOL_MLR_PROCESS_VALUE = "urn:fdc:peppol.eu:poacc:bis:mlr:3";
249
51
  /**
250
52
  * A parsed Peppol Message Level Response (a UBL `ApplicationResponse`). Every
251
- * field is nullable: a given MLR may omit any of them.
53
+ * field is optional: a given MLR may omit any of them, and an omitted field is
54
+ * an absent key.
252
55
  */
253
56
  interface PeppolMessageLevelResponse {
254
- customizationId: string | null;
255
- profileId: string | null;
256
- responseId: string | null;
257
- issueDate: string | null;
258
- issueTime: string | null;
259
- referencedDocumentId: string | null;
260
- responseCode: string | null;
261
- description: string | null;
57
+ customizationId?: string | undefined;
58
+ profileId?: string | undefined;
59
+ responseId?: string | undefined;
60
+ issueDate?: string | undefined;
61
+ issueTime?: string | undefined;
62
+ referencedDocumentId?: string | undefined;
63
+ responseCode?: string | undefined;
64
+ description?: string | undefined;
262
65
  /** Sender participant id as `schemeID:value` (e.g. `0208:0793904121`). */
263
- senderIdentifier: string | null;
66
+ senderIdentifier?: string | undefined;
264
67
  /** Receiver participant id as `schemeID:value`. */
265
- receiverIdentifier: string | null;
68
+ receiverIdentifier?: string | undefined;
266
69
  }
267
70
  /**
268
71
  * Whether an inbound document is a Peppol Message Level Response, identified by
@@ -276,8 +79,8 @@ declare const isPeppolMessageLevelResponse: (params: {
276
79
  }) => boolean;
277
80
  /**
278
81
  * Parse a Peppol Message Level Response (UBL `ApplicationResponse`), unwrapping
279
- * an SBDH envelope when present. Throws when the XML is not an
280
- * ApplicationResponse.
82
+ * an SBDH envelope when present. Throws {@link UblParseError} when the XML is
83
+ * malformed or is not an ApplicationResponse.
281
84
  */
282
85
  declare const parsePeppolMessageLevelResponse: (xml: string) => PeppolMessageLevelResponse;
283
86
  //#endregion
@@ -291,6 +94,9 @@ declare const decodeXmlBytes: (bytes: Uint8Array) => string;
291
94
  /**
292
95
  * Parse a UBL XML string and normalize it into a flat DTO suitable for
293
96
  * database storage or API responses.
97
+ *
98
+ * @throws {UblParseError} when the XML is malformed, not a UBL invoice, or
99
+ * lacks a mandatory element.
294
100
  */
295
101
  declare const normalizeUblResponse: (xml: string, documentId: string) => {
296
102
  extracted: InvoiceExtractionDTO;
@@ -311,5 +117,5 @@ declare const parseUblInvoiceDocument: (params: {
311
117
  providerJobId: string | null;
312
118
  };
313
119
  //#endregion
314
- export { type InvoiceExtractionDTO, PEPPOL_MLR_DOCUMENT_TYPE_VALUE, PEPPOL_MLR_PROCESS_VALUE, type PeppolMessageLevelResponse, type UblAddress, type UblAllowanceCharge, type UblAttachment, type UblBillingReference, type UblContact, type UblDelivery, type UblDocumentReference, type UblEmbeddedAttachment, type UblInvoice, type UblInvoicePeriod, type UblItemProperty, type UblLine, type UblMonetaryTotal, type UblParty, type UblPartyIdentification, type UblPaymentMeans, type UblTaxSubtotal, decodeXmlBytes, extractUblEmbeddedAttachments, isPdfLikeAttachment, isPeppolMessageLevelResponse, normalizeCurrency, normalizeUblResponse, parseDate, parsePeppolMessageLevelResponse, parseUblInvoice, parseUblInvoiceDocument };
120
+ export { type InvoiceExtractionDTO, PEPPOL_MLR_DOCUMENT_TYPE_VALUE, PEPPOL_MLR_PROCESS_VALUE, type PeppolMessageLevelResponse, type UblAddress, type UblAllowanceCharge, type UblAttachment, type UblBillingReference, UblBuildError, type UblCompanyId, type UblContact, type UblDelivery, type UblDocumentReference, type UblEmbeddedAttachment, type UblEndpoint, type UblInvoice, type UblInvoicePeriod, type UblItemProperty, type UblLine, type UblMonetaryTotal, UblParseError, type UblParty, type UblPartyIdentification, type UblPaymentMeans, type UblTaxCategory, type UblTaxSubtotal, type UblTaxTotal, decodeXmlBytes, extractUblEmbeddedAttachments, isPdfLikeAttachment, isPeppolMessageLevelResponse, normalizeCurrency, normalizeUblResponse, parseDate, parsePeppolMessageLevelResponse, parseUblInvoice, parseUblInvoiceDocument };
315
121
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/attachments.ts","../src/parser.ts","../src/mlr.ts","../src/normalize.ts"],"mappings":";UAEiB;EAChB;EACA;EACA;EACA;EACA;EACA;;UAGgB;EAChB;EACA;EACA;;UAGgB;EAChB;EACA;;UAGgB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,uBAAuB;EACvB,UAAU;EACV,UAAU;;UAGM;EAChB;EACA;;UAGgB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,eAAe;EACf,mBAAmB;EACnB;EACA;EACA;EACA;EACA;EACA,2BAA2B;;EAE3B,gBAAgB;;UAGA;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGgB;EAChB;EACA;EACA;EACA;EACA;EACA;;UAGgB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGgB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;;UAGgB;EAChB;EACA;EACA;;UAGgB;EAChB;EACA;EACA;EACA;EACA;EACA;;UAGgB;EAChB;EACA;;UAGgB;EAChB;EACA,UAAU;;UAGM;EAChB;EACA;;UAGgB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,mBAAmB;EACnB,QAAQ;EACR,OAAO;EACP,WAAW;EACX,OAAO;EACP,cAAc;EACd,eAAe;EACf,eAAe;EACf,mBAAmB;EACnB,gBAAgB;EAChB;EACA;EACA,cAAc;EACd,qBAAqB;EACrB,mBAAmB;;UAKH;EAChB;EACA;EACA;IACC;IACA;IACA;;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;IACA;IACA;IACA;MACC;MACA;MACA;MACA;MACA;;IAED;MACC;MACA;MACA;;IAED,OAAO;;EAER,YAAY;IACX;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;IACA;IACA,OAAO;;EAER;IACC;IACA,QAAQ;;;;;;;;;;UCxNO;EAChB;EACA;EACA;EACA;;EAEA;EACA;;;;;;;;cAYY,gCAA6B,gBAAkB;;;;;cAwB/C,sBAAmB,YACnB,KAAK;;;iBCycF,gBAAgB,cAAc;;;;;;;cCnfjC;;cAIA;;;;;UAMI;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;;;;;;cA8FY,+BAA4B;EACxC;EACA;EACA;;;;;;;cAgBY,kCAA+B,gBAEzC;;;cCxHU,oBAAiB;cAOjB,YAAS;;;;cAmHT,iBAAc,OAAW;;;;;cASzB,uBAAoB,aACrB;EAGX,WAAW;EACX,YAAY;;;;;cA4OA,0BAAuB;EACnC,OAAO;EACP;EACA;;;;;aAFO;EAYiB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/attachments.ts","../src/parser.ts","../src/mlr.ts","../src/normalize.ts"],"mappings":";;;;;;;UASiB;EAChB;EACA;EACA;EACA;;EAEA;EACA;;;;;;;;;;cAmBY,gCAA6B,gBAAkB;;;;;cAyB/C,sBAAmB,YACnB,KAAK;;;;;;;;;;;iBC4gBF,gBAAgB,cAAc;;;;;;;cCjkBjC;;cAIA;;;;;;UAOI;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;;;;;;cAuEY,+BAA4B;EACxC;EACA;EACA;;;;;;;cAsBY,kCAA+B,gBAEzC;;;cCpGU,oBAAiB;cAOjB,YAAS;;;;cAuHT,iBAAc,OAAW;;;;;;;;cAYzB,uBAAoB,aACrB;EAGX,WAAW;EACX,YAAY;;;;;cA4NA,0BAAuB;EACnC,OAAO;EACP;EACA;;;;;aAFO;EAYiB"}