@financica/ubl 0.7.0 → 0.9.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,203 +1,234 @@
1
+ //#region src/types.d.ts
1
2
  interface UblAddress {
2
- street: string;
3
- additionalStreet?: string;
4
- city: string;
5
- postalZone: string;
6
- countrySubentity?: string;
7
- countryCode: string;
3
+ street: string;
4
+ additionalStreet?: string;
5
+ city: string;
6
+ postalZone: string;
7
+ countrySubentity?: string;
8
+ countryCode: string;
8
9
  }
9
10
  interface UblContact {
10
- name?: string;
11
- phone?: string;
12
- email?: string;
11
+ name?: string;
12
+ phone?: string;
13
+ email?: string;
13
14
  }
14
15
  interface UblPartyIdentification {
15
- id: string;
16
- schemeId?: string;
16
+ id: string;
17
+ schemeId?: string;
17
18
  }
18
19
  interface UblParty {
19
- name: string;
20
- registrationName?: string;
21
- companyLegalForm?: string;
22
- vatId?: string;
23
- taxSchemeId?: string;
24
- companyId?: string;
25
- companyIdSchemeId?: string;
26
- endpointId?: string;
27
- endpointSchemeId?: string;
28
- partyIdentifications?: UblPartyIdentification[];
29
- address?: UblAddress;
30
- contact?: UblContact;
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;
31
32
  }
32
33
  interface UblItemProperty {
33
- name: string;
34
- value: string;
34
+ name: string;
35
+ value: string;
35
36
  }
36
37
  interface UblLine {
37
- id: string;
38
- description: string;
39
- quantity: number;
40
- unitCode: string;
41
- unitPrice: number;
42
- lineExtensionAmount: number;
43
- taxPercent?: number;
44
- taxAmount?: number;
45
- taxCategoryId?: string;
46
- taxSchemeId?: string;
47
- taxSubtotals?: UblTaxSubtotal[];
48
- allowanceCharges?: UblAllowanceCharge[];
49
- discountAmount?: number;
50
- chargeAmount?: number;
51
- itemName?: string;
52
- sellersItemId?: string;
53
- buyersItemId?: string;
54
- additionalItemProperties?: UblItemProperty[];
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[];
55
56
  }
56
57
  interface UblAllowanceCharge {
57
- chargeIndicator: boolean;
58
- amount: number;
59
- baseAmount?: number;
60
- multiplierFactorNumeric?: number;
61
- reason?: string;
62
- reasonCode?: string;
63
- taxPercent?: number;
64
- taxCategoryId?: string;
65
- taxSchemeId?: string;
58
+ chargeIndicator: boolean;
59
+ amount: number;
60
+ baseAmount?: number;
61
+ multiplierFactorNumeric?: number;
62
+ reason?: string;
63
+ reasonCode?: string;
64
+ taxPercent?: number;
65
+ taxCategoryId?: string;
66
+ taxSchemeId?: string;
66
67
  }
67
68
  interface UblTaxSubtotal {
68
- taxableAmount: number;
69
- taxAmount: number;
70
- taxPercent: number;
71
- taxCategoryId?: string;
72
- taxSchemeId?: string;
73
- taxExemptionReason?: string;
69
+ taxableAmount: number;
70
+ taxAmount: number;
71
+ taxPercent: number;
72
+ taxCategoryId?: string;
73
+ taxSchemeId?: string;
74
+ taxExemptionReason?: string;
74
75
  }
75
76
  interface UblMonetaryTotal {
76
- lineExtensionAmount: number;
77
- taxExclusiveAmount: number;
78
- taxInclusiveAmount: number;
79
- allowanceTotalAmount?: number;
80
- chargeTotalAmount?: number;
81
- prepaidAmount?: number;
82
- payableRoundingAmount?: number;
83
- payableAmount: number;
77
+ lineExtensionAmount: number;
78
+ taxExclusiveAmount: number;
79
+ taxInclusiveAmount: number;
80
+ allowanceTotalAmount?: number;
81
+ chargeTotalAmount?: number;
82
+ prepaidAmount?: number;
83
+ payableRoundingAmount?: number;
84
+ payableAmount: number;
84
85
  }
85
86
  interface UblPaymentMeans {
86
- code: string;
87
- codeName?: string;
88
- paymentId?: string;
89
- iban?: string;
90
- bic?: string;
91
- accountName?: string;
92
- mandateId?: string;
87
+ code: string;
88
+ codeName?: string;
89
+ paymentId?: string;
90
+ iban?: string;
91
+ bic?: string;
92
+ accountName?: string;
93
+ mandateId?: string;
93
94
  }
94
95
  interface UblInvoicePeriod {
95
- startDate?: string;
96
- endDate?: string;
97
- descriptionCode?: string;
96
+ startDate?: string;
97
+ endDate?: string;
98
+ descriptionCode?: string;
98
99
  }
99
100
  interface UblAttachment {
100
- id: string;
101
- filename?: string;
102
- mimeCode?: string;
103
- description?: string;
104
- base64Content?: string;
105
- externalUri?: string;
101
+ id: string;
102
+ filename?: string;
103
+ mimeCode?: string;
104
+ description?: string;
105
+ base64Content?: string;
106
+ externalUri?: string;
106
107
  }
107
108
  interface UblDocumentReference {
108
- id: string;
109
- description?: string;
109
+ id: string;
110
+ description?: string;
110
111
  }
111
112
  interface UblDelivery {
112
- actualDeliveryDate?: string;
113
- address?: UblAddress;
113
+ actualDeliveryDate?: string;
114
+ address?: UblAddress;
114
115
  }
115
116
  interface UblBillingReference {
116
- invoiceId?: string;
117
- invoiceIssueDate?: string;
117
+ invoiceId?: string;
118
+ invoiceIssueDate?: string;
118
119
  }
119
120
  interface UblInvoice {
120
- documentType: "Invoice" | "CreditNote";
121
- customizationId?: string;
122
- profileId?: string;
123
- id: string;
124
- invoiceTypeCode?: string;
125
- issueDate: string;
126
- dueDate?: string;
127
- taxPointDate?: string;
128
- currency: string;
129
- buyerReference?: string;
130
- orderReference?: string;
131
- salesOrderId?: string;
132
- contractReference?: string;
133
- projectReference?: string;
134
- billingReference?: UblBillingReference;
135
- seller: UblParty;
136
- buyer: UblParty;
137
- delivery?: UblDelivery;
138
- lines: UblLine[];
139
- taxSubtotals: UblTaxSubtotal[];
140
- monetaryTotal: UblMonetaryTotal;
141
- paymentMeans?: UblPaymentMeans;
142
- paymentMeansList?: UblPaymentMeans[];
143
- invoicePeriod?: UblInvoicePeriod;
144
- note?: string;
145
- paymentTermsNote?: string;
146
- attachments?: UblAttachment[];
147
- documentReferences?: UblDocumentReference[];
148
- allowanceCharges?: UblAllowanceCharge[];
121
+ documentType: "Invoice" | "CreditNote";
122
+ customizationId?: string;
123
+ profileId?: string;
124
+ id: string;
125
+ invoiceTypeCode?: string;
126
+ issueDate: string;
127
+ dueDate?: string;
128
+ taxPointDate?: string;
129
+ currency: string;
130
+ buyerReference?: string;
131
+ orderReference?: string;
132
+ salesOrderId?: string;
133
+ contractReference?: string;
134
+ projectReference?: string;
135
+ billingReference?: UblBillingReference;
136
+ seller: UblParty;
137
+ buyer: UblParty;
138
+ delivery?: UblDelivery;
139
+ lines: UblLine[];
140
+ taxSubtotals: UblTaxSubtotal[];
141
+ monetaryTotal: UblMonetaryTotal;
142
+ paymentMeans?: UblPaymentMeans;
143
+ paymentMeansList?: UblPaymentMeans[];
144
+ invoicePeriod?: UblInvoicePeriod;
145
+ note?: string;
146
+ paymentTermsNote?: string;
147
+ attachments?: UblAttachment[];
148
+ documentReferences?: UblDocumentReference[];
149
+ allowanceCharges?: UblAllowanceCharge[];
149
150
  }
150
151
  interface InvoiceExtractionDTO {
151
- provider: string;
152
- document_id: string;
153
- invoice: {
154
- invoice_number: string | null;
155
- invoice_date: string | null;
156
- due_date: string | null;
157
- currency: string | null;
158
- subtotal: number | null;
159
- tax_total: number | null;
160
- total: number | null;
161
- amount_due: number | null;
162
- amount_paid: number | null;
163
- discount_total: number | null;
164
- shipping_total: number | null;
165
- payment_terms: string | null;
166
- po_number: string | null;
167
- supplier: {
168
- name: string | null;
169
- address: string | null;
170
- tax_id: string | null;
171
- iban: string | null;
172
- bic: string | null;
173
- };
174
- receiver: {
175
- name: string | null;
176
- address: string | null;
177
- tax_id: string | null;
178
- };
179
- extra: Record<string, unknown>;
152
+ provider: string;
153
+ document_id: string;
154
+ invoice: {
155
+ invoice_number: string | null;
156
+ invoice_date: string | null;
157
+ due_date: string | null;
158
+ currency: string | null;
159
+ subtotal: number | null;
160
+ tax_total: number | null;
161
+ total: number | null;
162
+ amount_due: number | null;
163
+ amount_paid: number | null;
164
+ discount_total: number | null;
165
+ shipping_total: number | null;
166
+ payment_terms: string | null;
167
+ po_number: string | null;
168
+ supplier: {
169
+ name: string | null;
170
+ address: string | null;
171
+ tax_id: string | null;
172
+ iban: string | null;
173
+ bic: string | null;
180
174
  };
181
- line_items: Array<{
182
- description: string;
183
- quantity: number | null;
184
- unit: string | null;
185
- unit_price: number | null;
186
- amount: number | null;
187
- tax_amount: number | null;
188
- tax_rate: number | null;
189
- product_code: string | null;
190
- discount_amount: number | null;
191
- extra: Record<string, unknown>;
192
- }>;
193
- confidence: {
194
- overall: number | null;
195
- fields: Record<string, number>;
175
+ receiver: {
176
+ name: string | null;
177
+ address: string | null;
178
+ tax_id: string | null;
196
179
  };
180
+ extra: Record<string, unknown>;
181
+ };
182
+ line_items: Array<{
183
+ description: string;
184
+ quantity: number | null;
185
+ unit: string | null;
186
+ unit_price: number | null;
187
+ amount: number | null;
188
+ tax_amount: number | null;
189
+ tax_rate: number | null;
190
+ product_code: string | null;
191
+ discount_amount: number | null;
192
+ extra: Record<string, unknown>;
193
+ }>;
194
+ confidence: {
195
+ overall: number | null;
196
+ fields: Record<string, number>;
197
+ };
198
+ }
199
+ //#endregion
200
+ //#region src/attachments.d.ts
201
+ /**
202
+ * An embedded attachment extracted from a UBL document's
203
+ * `AdditionalDocumentReference` entries, with its binary content still
204
+ * base64-encoded. `sizeBytes` is the approximate decoded size.
205
+ */
206
+ interface UblEmbeddedAttachment {
207
+ id: string | null;
208
+ filename: string;
209
+ mimeCode: string;
210
+ sizeBytes: number;
211
+ /** Zero-based position among the document's embedded attachments. */
212
+ lineOrder: number;
213
+ base64Content: string;
197
214
  }
198
-
215
+ /**
216
+ * Extract the embedded attachments (typically the human-readable PDF) from a
217
+ * UBL invoice or credit note XML. Attachments referenced only by external URI
218
+ * (no `EmbeddedDocumentBinaryObject`) are skipped; use {@link parseUblInvoice}
219
+ * directly when those matter.
220
+ */
221
+ declare const extractUblEmbeddedAttachments: (xml: string) => UblEmbeddedAttachment[];
222
+ /**
223
+ * Whether an attachment looks like a PDF, by MIME type first and filename
224
+ * extension as a fallback.
225
+ */
226
+ declare const isPdfLikeAttachment: (attachment: Pick<UblAttachment, "filename" | "mimeCode">) => boolean;
227
+ //#endregion
228
+ //#region src/parser.d.ts
199
229
  declare function parseUblInvoice(xml: string): UblInvoice | null;
200
-
230
+ //#endregion
231
+ //#region src/mlr.d.ts
201
232
  /**
202
233
  * Peppol BIS MLR (Message Level Response) document-type identifier value
203
234
  * (Peppol `busdox-docid-qns` scheme).
@@ -210,18 +241,18 @@ declare const PEPPOL_MLR_PROCESS_VALUE = "urn:fdc:peppol.eu:poacc:bis:mlr:3";
210
241
  * field is nullable: a given MLR may omit any of them.
211
242
  */
212
243
  interface PeppolMessageLevelResponse {
213
- customizationId: string | null;
214
- profileId: string | null;
215
- responseId: string | null;
216
- issueDate: string | null;
217
- issueTime: string | null;
218
- referencedDocumentId: string | null;
219
- responseCode: string | null;
220
- description: string | null;
221
- /** Sender participant id as `schemeID:value` (e.g. `0208:0793904121`). */
222
- senderIdentifier: string | null;
223
- /** Receiver participant id as `schemeID:value`. */
224
- receiverIdentifier: string | null;
244
+ customizationId: string | null;
245
+ profileId: string | null;
246
+ responseId: string | null;
247
+ issueDate: string | null;
248
+ issueTime: string | null;
249
+ referencedDocumentId: string | null;
250
+ responseCode: string | null;
251
+ description: string | null;
252
+ /** Sender participant id as `schemeID:value` (e.g. `0208:0793904121`). */
253
+ senderIdentifier: string | null;
254
+ /** Receiver participant id as `schemeID:value`. */
255
+ receiverIdentifier: string | null;
225
256
  }
226
257
  /**
227
258
  * Whether an inbound document is a Peppol Message Level Response, identified by
@@ -229,9 +260,9 @@ interface PeppolMessageLevelResponse {
229
260
  * an `ApplicationResponse` root (SBDH-wrapped or not).
230
261
  */
231
262
  declare const isPeppolMessageLevelResponse: (params: {
232
- documentTypeValue?: string | null;
233
- processValue?: string | null;
234
- xml?: string | null;
263
+ documentTypeValue?: string | null;
264
+ processValue?: string | null;
265
+ xml?: string | null;
235
266
  }) => boolean;
236
267
  /**
237
268
  * Parse a Peppol Message Level Response (UBL `ApplicationResponse`), unwrapping
@@ -239,7 +270,8 @@ declare const isPeppolMessageLevelResponse: (params: {
239
270
  * ApplicationResponse.
240
271
  */
241
272
  declare const parsePeppolMessageLevelResponse: (xml: string) => PeppolMessageLevelResponse;
242
-
273
+ //#endregion
274
+ //#region src/normalize.d.ts
243
275
  declare const normalizeCurrency: (value?: string | null) => string | null;
244
276
  declare const parseDate: (value?: string | null) => string | null;
245
277
  /**
@@ -251,22 +283,23 @@ declare const decodeXmlBytes: (bytes: Uint8Array) => string;
251
283
  * database storage or API responses.
252
284
  */
253
285
  declare const normalizeUblResponse: (xml: string, documentId: string) => {
254
- extracted: InvoiceExtractionDTO;
255
- rawPayload: Record<string, unknown>;
286
+ extracted: InvoiceExtractionDTO;
287
+ rawPayload: Record<string, unknown>;
256
288
  };
257
289
  /**
258
290
  * Parse a UBL invoice from raw bytes and normalize it into a DTO.
259
291
  */
260
292
  declare const parseUblInvoiceDocument: (params: {
261
- bytes: Uint8Array;
262
- documentId: string;
263
- mimeType: string;
293
+ bytes: Uint8Array;
294
+ documentId: string;
295
+ mimeType: string;
264
296
  }) => {
265
- rawPayload: {
266
- mime_type: string;
267
- };
268
- extracted: InvoiceExtractionDTO;
269
- providerJobId: string | null;
297
+ rawPayload: {
298
+ mime_type: string;
299
+ };
300
+ extracted: InvoiceExtractionDTO;
301
+ providerJobId: string | null;
270
302
  };
271
-
272
- 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 UblInvoice, type UblInvoicePeriod, type UblItemProperty, type UblLine, type UblMonetaryTotal, type UblParty, type UblPartyIdentification, type UblPaymentMeans, type UblTaxSubtotal, decodeXmlBytes, isPeppolMessageLevelResponse, normalizeCurrency, normalizeUblResponse, parseDate, parsePeppolMessageLevelResponse, parseUblInvoice, parseUblInvoiceDocument };
303
+ //#endregion
304
+ 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 };
305
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;;UAGX;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;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;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;IACA,OAAO;;EAER;IACC;IACA,QAAQ;;;;;;;;;;UC9MO;EAChB;EACA;EACA;EACA;;EAEA;EACA;;;;;;;;cAYY,gCAA6B,gBAAkB;;;;;cAwB/C,sBAAmB,YACnB,KAAK;;;iBCmcF,gBAAgB,cAAc;;;;;;;cCzejC;;cAIA;;;;;UAMI;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;;;;;;cA8FY,+BAA4B;EACxC;EACA;EACA;;;;;;;cAgBY,kCAA+B,gBAEzC;;;cC9HU,oBAAiB;cAOjB,YAAS;;;;cAmHT,iBAAc,OAAW;;;;;cASzB,uBAAoB,aACrB;EAGX,WAAW;EACX,YAAY;;;;;cA8NA,0BAAuB;EACnC,OAAO;EACP;EACA;;;;;aAFO"}