@formancy/report-spec 0.1.0 → 0.2.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/NOTICE +8 -0
- package/README.md +377 -6
- package/dist/index.d.mts +1404 -24
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +8413 -1341
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.d.mts
CHANGED
|
@@ -34,6 +34,359 @@ type SpecVersionCheck = {
|
|
|
34
34
|
*/
|
|
35
35
|
export declare function checkSpecVersion(document: unknown): SpecVersionCheck;
|
|
36
36
|
//#endregion
|
|
37
|
+
//#region src/e-invoice.d.ts
|
|
38
|
+
/** The kinds of e-invoice. A kind this version does not know is refused, never skipped. */
|
|
39
|
+
export declare const E_INVOICE_KINDS: readonly ["facturX"];
|
|
40
|
+
type EInvoiceKind = (typeof E_INVOICE_KINDS)[number];
|
|
41
|
+
/** The Factur-X profiles this version writes: EN 16931 alone, which Germany counts as an e-invoice and FeRD recommends. */
|
|
42
|
+
export declare const E_INVOICE_PROFILES: readonly ["en16931"];
|
|
43
|
+
type EInvoiceProfile = (typeof E_INVOICE_PROFILES)[number];
|
|
44
|
+
/** The invoice type codes (BT-3, UNTDID 1001) this version writes: 380, a commercial invoice. No credit note yet. */
|
|
45
|
+
export declare const INVOICE_TYPE_CODES: readonly ["380"];
|
|
46
|
+
type InvoiceTypeCode = (typeof INVOICE_TYPE_CODES)[number];
|
|
47
|
+
/** The currencies (BT-5, ISO 4217) this version writes: EUR. A second would bring BT-6 and BT-111 with it. */
|
|
48
|
+
export declare const E_INVOICE_CURRENCIES: readonly ["EUR"];
|
|
49
|
+
type EInvoiceCurrency = (typeof E_INVOICE_CURRENCIES)[number];
|
|
50
|
+
/**
|
|
51
|
+
* The VAT categories (BT-118, BT-151; UNCL 5305) this version writes:
|
|
52
|
+
* standard rated, exempt from VAT, and reverse charge. CEN's BR-CL-17 and
|
|
53
|
+
* BR-CL-18 take seven more, Z, K, G, O, L, M and B, which wait.
|
|
54
|
+
*/
|
|
55
|
+
export declare const VAT_CATEGORY_CODES: readonly ["S", "E", "AE"];
|
|
56
|
+
type VatCategoryCode = (typeof VAT_CATEGORY_CODES)[number];
|
|
57
|
+
/** The payment means (BT-81, UNTDID 4461) this version writes: 58, a SEPA credit transfer, and 30, a credit transfer. */
|
|
58
|
+
export declare const PAYMENT_MEANS_CODES: readonly ["58", "30"];
|
|
59
|
+
type PaymentMeansCode = (typeof PAYMENT_MEANS_CODES)[number];
|
|
60
|
+
/**
|
|
61
|
+
* The units of measure (BT-130; UN/ECE Recommendation 20, revision 11e) a
|
|
62
|
+
* line's quantity may be in, and no other (BR-CL-23): the counted, time,
|
|
63
|
+
* mass, length, area, volume and energy units a German invoice is written
|
|
64
|
+
* in. CEN takes 2,162; the packaging codes of Recommendation 21 among them
|
|
65
|
+
* wait.
|
|
66
|
+
*/
|
|
67
|
+
export declare const UNIT_CODES: readonly ["C62", "H87", "SET", "PR", "LS", "MIN", "HUR", "DAY", "WEE", "MON", "ANN", "GRM", "KGM", "TNE", "MTR", "KMT", "MTK", "MTQ", "MLT", "LTR", "KWH"];
|
|
68
|
+
type UnitCode = (typeof UNIT_CODES)[number];
|
|
69
|
+
/**
|
|
70
|
+
* The countries (BT-40, BT-55; ISO 3166-1 alpha-2) a seller or a buyer may
|
|
71
|
+
* be in, and no other (BR-CL-14): the 27 member states of the EU, the EEA's
|
|
72
|
+
* Iceland, Liechtenstein and Norway, Switzerland, and the United Kingdom.
|
|
73
|
+
* CEN takes 251. Greece is GR here, and EL only as a VAT prefix.
|
|
74
|
+
*/
|
|
75
|
+
export declare const COUNTRY_CODES: readonly ["AT", "BE", "BG", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FR", "GR", "HR", "HU", "IE", "IT", "LT", "LU", "LV", "MT", "NL", "PL", "PT", "RO", "SE", "SI", "SK", "IS", "LI", "NO", "CH", "GB"];
|
|
76
|
+
type CountryCode = (typeof COUNTRY_CODES)[number];
|
|
77
|
+
/**
|
|
78
|
+
* The prefixes a VAT identifier (BT-31, BT-48) may begin with (BR-CO-09):
|
|
79
|
+
* a country of `COUNTRY_CODES`, or EL, which Greece writes its VAT
|
|
80
|
+
* identifiers with. BR-CO-09's message allows EL in both releases, but only
|
|
81
|
+
* 1.3.16's test, which the pinned validators run, holds it; 1.3.17's does
|
|
82
|
+
* not. EL is taken while the pinned oracle takes it, and the gate fails on
|
|
83
|
+
* the release that does not.
|
|
84
|
+
*/
|
|
85
|
+
export declare const VAT_PREFIXES: readonly string[];
|
|
86
|
+
/**
|
|
87
|
+
* The schemes (BT-30-1, BT-47-1; ISO 6523 ICD) a legal registration
|
|
88
|
+
* identifier may be given in, and no other (BR-CL-11). An identifier may be
|
|
89
|
+
* given without one, as a German commercial register number is. France's
|
|
90
|
+
* SIREN and SIRET, since a French buyer's SIREN is the one detail of
|
|
91
|
+
* France's the XML holds; and the two that name a company anywhere. CEN
|
|
92
|
+
* takes 246; the Leitweg-ID, 0204, which routes an invoice to a German
|
|
93
|
+
* public buyer in BT-10, waits with XRechnung.
|
|
94
|
+
*/
|
|
95
|
+
export declare const SCHEME_IDS: readonly ["0002", "0009", "0060", "0088"];
|
|
96
|
+
type SchemeId = (typeof SCHEME_IDS)[number];
|
|
97
|
+
/** What names each profile, in the XML and in the PDF that carries it. */
|
|
98
|
+
interface FacturXProfileTerms {
|
|
99
|
+
/** The specification identifier (BT-24), which the XML opens with. */
|
|
100
|
+
readonly guideline: string;
|
|
101
|
+
/** The XMP's `fx:ConformanceLevel` [S]. */
|
|
102
|
+
readonly conformanceLevel: string;
|
|
103
|
+
/** The embedded file's `/AFRelationship` [S]. */
|
|
104
|
+
readonly relationship: 'Alternative';
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Each profile's names. A table over every profile, so a profile added to
|
|
108
|
+
* `E_INVOICE_PROFILES` without them does not compile.
|
|
109
|
+
* - BT-24 is the EN 16931 profile's identifier as the Factur-X 1.09.2
|
|
110
|
+
* schematron's code list 1 gives it (`FACTUR-X_EN16931_codedb.xml`, read
|
|
111
|
+
* in akretion's copy). Mustang refuses the old `urn:factur-x.eu:1p0:en16931`.
|
|
112
|
+
* - `Alternative` is Germany's relationship for EN 16931, and one of the
|
|
113
|
+
* three France allows [S].
|
|
114
|
+
*/
|
|
115
|
+
export declare const FACTUR_X_PROFILES: { readonly [P in EInvoiceProfile]: FacturXProfileTerms; };
|
|
116
|
+
/**
|
|
117
|
+
* The file a Factur-X PDF embeds, and the XMP that describes it [S]: the
|
|
118
|
+
* name, the media type, the fx extension's namespace (its trailing `#`
|
|
119
|
+
* required) and prefix, and the document type and the version it states.
|
|
120
|
+
* The namespace is the transcription's section 6.3.1; its BR-HYBRID-04
|
|
121
|
+
* gives it without `:invoice`, an inconsistency the transcription resolves
|
|
122
|
+
* for section 6.3.1, as akretion's generator and PDFlib's sample do (0031).
|
|
123
|
+
* No validator checks the namespace: Mustang reads the four properties by
|
|
124
|
+
* local name, and veraPDF checks only that the extension schema describes
|
|
125
|
+
* them. The renderer embeds what these say (0031), and its test holds the
|
|
126
|
+
* PDF to the transcription's values, written there and not read from here;
|
|
127
|
+
* the official package's XMP example, which would hold them to more, waits
|
|
128
|
+
* for a registration with FeRD nobody here has made.
|
|
129
|
+
*/
|
|
130
|
+
export declare const FACTUR_X: {
|
|
131
|
+
readonly fileName: "factur-x.xml";
|
|
132
|
+
readonly mediaType: "text/xml";
|
|
133
|
+
readonly xmpNamespace: "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#";
|
|
134
|
+
readonly xmpPrefix: "fx";
|
|
135
|
+
readonly documentType: "INVOICE";
|
|
136
|
+
readonly version: "1.0";
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* The names an expression reads in a report that is an e-invoice, beside
|
|
140
|
+
* `EXPRESSION_NAMES`'s, and in no other report (0027, an addition to
|
|
141
|
+
* 0007's names): `invoice` holds the document's totals (BG-22), and
|
|
142
|
+
* `vatBasis` and `vatAmount` each declared VAT category's taxable and tax
|
|
143
|
+
* amount (BG-23) by the category's id, null when no line is in it. The
|
|
144
|
+
* runtime computes each once, from the lines, for the page and the XML
|
|
145
|
+
* alike. They are read wherever `totals` is, except where they are
|
|
146
|
+
* computed from: an aggregate's expression, the e-invoice's own, and the
|
|
147
|
+
* columns that print a line's terms. The editing core refuses a read
|
|
148
|
+
* there, and in any other report.
|
|
149
|
+
*/
|
|
150
|
+
export declare const E_INVOICE_NAMES: readonly ["invoice", "vatBasis", "vatAmount"];
|
|
151
|
+
type EInvoiceName = (typeof E_INVOICE_NAMES)[number];
|
|
152
|
+
/**
|
|
153
|
+
* The members of `invoice`, each one of the document's totals (BG-22), as a
|
|
154
|
+
* refusal names it: every one a decimal of two places in the invoice's
|
|
155
|
+
* currency. With no allowances and no charges, the total without VAT is
|
|
156
|
+
* the sum of the lines. `paid` is a member only of an invoice that
|
|
157
|
+
* declares a paid amount, and is what that gives; with none, the amount
|
|
158
|
+
* due is the total with VAT.
|
|
159
|
+
*/
|
|
160
|
+
export declare const INVOICE_TOTALS: {
|
|
161
|
+
readonly lineTotal: "the sum of the invoice line net amounts (BT-106)";
|
|
162
|
+
readonly taxBasisTotal: "the invoice total amount without VAT (BT-109)";
|
|
163
|
+
readonly taxTotal: "the invoice total VAT amount (BT-110)";
|
|
164
|
+
readonly grandTotal: "the invoice total amount with VAT (BT-112)";
|
|
165
|
+
readonly paid: "the paid amount (BT-113)";
|
|
166
|
+
readonly duePayable: "the amount due for payment (BT-115)";
|
|
167
|
+
};
|
|
168
|
+
type InvoiceTotal = keyof typeof INVOICE_TOTALS;
|
|
169
|
+
/** What `vatBasis` and `vatAmount` hold of each declared category, as a refusal names it. */
|
|
170
|
+
export declare const VAT_BREAKDOWN: { readonly [N in Exclude<EInvoiceName, 'invoice'>]: string; };
|
|
171
|
+
/**
|
|
172
|
+
* A postal address (BG-5, BG-8): the first line, the post code, the city
|
|
173
|
+
* and the country are needed, the second line may be left out. Each is
|
|
174
|
+
* runs; the country is a code of `COUNTRY_CODES`.
|
|
175
|
+
*/
|
|
176
|
+
interface EInvoiceAddress {
|
|
177
|
+
readonly line1: readonly Inline[];
|
|
178
|
+
readonly line2?: readonly Inline[];
|
|
179
|
+
readonly postalCode: readonly Inline[];
|
|
180
|
+
readonly city: readonly Inline[];
|
|
181
|
+
readonly country: readonly Inline[];
|
|
182
|
+
}
|
|
183
|
+
/** A legal registration identifier (BT-30, BT-47), and the scheme it is given in, if one. */
|
|
184
|
+
interface LegalIdentifier {
|
|
185
|
+
readonly id: readonly Inline[];
|
|
186
|
+
readonly scheme?: SchemeId;
|
|
187
|
+
}
|
|
188
|
+
/** The seller (BG-4): its name (BT-27), its VAT identifier (BT-31), its tax number (BT-32), its legal registration (BT-30) and its address (BG-5). */
|
|
189
|
+
interface EInvoiceSeller {
|
|
190
|
+
readonly name: readonly Inline[];
|
|
191
|
+
readonly vatId?: readonly Inline[];
|
|
192
|
+
readonly taxNumber?: readonly Inline[];
|
|
193
|
+
readonly legalId?: LegalIdentifier;
|
|
194
|
+
readonly address: EInvoiceAddress;
|
|
195
|
+
}
|
|
196
|
+
/** The buyer (BG-7): its name (BT-44), its VAT identifier (BT-48), its legal registration (BT-47) and its address (BG-8). A buyer has no BT-32. */
|
|
197
|
+
interface EInvoiceBuyer {
|
|
198
|
+
readonly name: readonly Inline[];
|
|
199
|
+
readonly vatId?: readonly Inline[];
|
|
200
|
+
readonly legalId?: LegalIdentifier;
|
|
201
|
+
readonly address: EInvoiceAddress;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* A VAT category the invoice's lines are in, one VAT breakdown (BG-23) each
|
|
205
|
+
* when a line uses it.
|
|
206
|
+
*/
|
|
207
|
+
interface VatCategory {
|
|
208
|
+
/** A field key: what the page reads its basis and its amount as, `vatBasis.<id>` and `vatAmount.<id>`, and what a line names it by. */
|
|
209
|
+
readonly id: string;
|
|
210
|
+
readonly code: VatCategoryCode;
|
|
211
|
+
/** The rate in per cent (BT-119, BT-152), an exact decimal: more than 0 when standard rated, 0 otherwise. */
|
|
212
|
+
readonly rate: string;
|
|
213
|
+
/** The exemption reason (BT-120): needed for E and AE, never for S. */
|
|
214
|
+
readonly reason?: readonly Inline[];
|
|
215
|
+
}
|
|
216
|
+
/** The invoicing period (BG-14): its start (BT-73), its end (BT-74), or both. */
|
|
217
|
+
interface InvoicingPeriod {
|
|
218
|
+
readonly start?: Expression;
|
|
219
|
+
readonly end?: Expression;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The lines (BG-25), one per row of the table over the detail dataset. The
|
|
223
|
+
* name, the quantity, the net price and the net amount are column ids of
|
|
224
|
+
* that table: what each column prints, once per row, is what the line
|
|
225
|
+
* holds. The identifier, the unit and the VAT category are read from each
|
|
226
|
+
* row, as an aggregate reads it.
|
|
227
|
+
*/
|
|
228
|
+
interface EInvoiceLines {
|
|
229
|
+
/** The id of the table over the detail dataset. */
|
|
230
|
+
readonly table: string;
|
|
231
|
+
/** The column that prints the item name (BT-153). */
|
|
232
|
+
readonly name: string;
|
|
233
|
+
/** The column that prints the invoiced quantity (BT-129). */
|
|
234
|
+
readonly quantity: string;
|
|
235
|
+
/** The column that prints the item net price (BT-146). */
|
|
236
|
+
readonly netPrice: string;
|
|
237
|
+
/** The column that prints the line net amount (BT-131), a whole number of cents. */
|
|
238
|
+
readonly netAmount: string;
|
|
239
|
+
/** The line identifier (BT-126). */
|
|
240
|
+
readonly id: RowValue;
|
|
241
|
+
/** The unit of measure (BT-130), a code of `UNIT_CODES`. */
|
|
242
|
+
readonly unit: RowValue;
|
|
243
|
+
/** The id of the line's VAT category (BT-151, BT-152): one the invoice declares. */
|
|
244
|
+
readonly vat: RowValue;
|
|
245
|
+
}
|
|
246
|
+
/** The payment instructions (BG-16): how the invoice is paid, and to which account. */
|
|
247
|
+
interface PaymentInstructions {
|
|
248
|
+
/** BT-81. */
|
|
249
|
+
readonly means: PaymentMeansCode;
|
|
250
|
+
/** The payment account (BT-84): an IBAN. Spaces are for reading, and are dropped. */
|
|
251
|
+
readonly iban: readonly Inline[];
|
|
252
|
+
/** The BIC of the account's bank (BT-86). */
|
|
253
|
+
readonly bic?: readonly Inline[];
|
|
254
|
+
/** The account's name (BT-85). */
|
|
255
|
+
readonly accountName?: readonly Inline[];
|
|
256
|
+
/** The remittance information (BT-83): what a payer writes on the transfer. */
|
|
257
|
+
readonly remittance?: readonly Inline[];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* A Factur-X invoice in the EN 16931 profile. Each text is runs, one at
|
|
261
|
+
* least where it is present; an optional one absent is a term the XML
|
|
262
|
+
* leaves out, never an empty list of runs, so that one invoice has one
|
|
263
|
+
* spelling and one hash. Each expression is compiled and typed by the
|
|
264
|
+
* editing core: the dates are dates, the paid amount a decimal.
|
|
265
|
+
*/
|
|
266
|
+
interface FacturXInvoice {
|
|
267
|
+
readonly kind: 'facturX';
|
|
268
|
+
readonly profile: EInvoiceProfile;
|
|
269
|
+
/** BT-3. */
|
|
270
|
+
readonly type: InvoiceTypeCode;
|
|
271
|
+
/** BT-5. */
|
|
272
|
+
readonly currency: EInvoiceCurrency;
|
|
273
|
+
/** The invoice number (BT-1). */
|
|
274
|
+
readonly number: readonly Inline[];
|
|
275
|
+
/** The issue date (BT-2). */
|
|
276
|
+
readonly issued: Expression;
|
|
277
|
+
readonly seller: EInvoiceSeller;
|
|
278
|
+
readonly buyer: EInvoiceBuyer;
|
|
279
|
+
/** The buyer's reference (BT-10). */
|
|
280
|
+
readonly buyerReference?: readonly Inline[];
|
|
281
|
+
/** The actual delivery date (BT-72). A delivery date, a period or both: a German invoice says when it was supplied. */
|
|
282
|
+
readonly delivered?: Expression;
|
|
283
|
+
readonly period?: InvoicingPeriod;
|
|
284
|
+
/** The VAT categories its lines may be in, one at least. */
|
|
285
|
+
readonly vat: readonly VatCategory[];
|
|
286
|
+
readonly lines: EInvoiceLines;
|
|
287
|
+
readonly payment?: PaymentInstructions;
|
|
288
|
+
/** The payment due date (BT-9). */
|
|
289
|
+
readonly due?: Expression;
|
|
290
|
+
/** The payment terms (BT-20), where a Skonto is written. */
|
|
291
|
+
readonly terms?: readonly Inline[];
|
|
292
|
+
/** The amount already paid (BT-113), a whole number of cents. */
|
|
293
|
+
readonly paid?: Expression;
|
|
294
|
+
}
|
|
295
|
+
type EInvoice = FacturXInvoice;
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/epc-qr-code.d.ts
|
|
298
|
+
/**
|
|
299
|
+
* What a code may be framed and captioned with: Austria's frame and the
|
|
300
|
+
* words "Zahlen mit Code" (PSA v3.0 5), drawn inside the code's square.
|
|
301
|
+
* Absent, the code is printed alone, as a QR code is.
|
|
302
|
+
*/
|
|
303
|
+
export declare const EPC_CAPTIONS: readonly ["zahlenMitCode"];
|
|
304
|
+
type EpcCaption = (typeof EPC_CAPTIONS)[number];
|
|
305
|
+
/**
|
|
306
|
+
* An EPC QR code. Each text is runs, one at least where it is present; an
|
|
307
|
+
* optional one absent is an element the code leaves empty, never an empty
|
|
308
|
+
* list of runs, so that one code has one spelling and one hash.
|
|
309
|
+
*/
|
|
310
|
+
interface EpcQrCodeComponent extends ComponentBase {
|
|
311
|
+
readonly kind: 'epcQrCode';
|
|
312
|
+
/** The side of the square in points: the quiet zone, and the frame and caption when there are any, inside it. */
|
|
313
|
+
readonly size: number;
|
|
314
|
+
/** The beneficiary's name (AT-E001): at most 70 characters. */
|
|
315
|
+
readonly beneficiary: readonly Inline[];
|
|
316
|
+
/** The beneficiary's IBAN (AT-C001), of a country of SEPA. Spaces are for reading, and are dropped. */
|
|
317
|
+
readonly iban: readonly Inline[];
|
|
318
|
+
/** The BIC of the beneficiary's bank (AT-C002): needed for an account outside the EEA, and may be left out for one inside it. */
|
|
319
|
+
readonly bic?: readonly Inline[];
|
|
320
|
+
/** The amount in euro, a decimal of at most two places. Absent, or null, leaves the amount for the payer to fill in. */
|
|
321
|
+
readonly amount?: Expression;
|
|
322
|
+
/** The purpose code (AT-T007): four capital letters, written into the template. */
|
|
323
|
+
readonly purpose?: string;
|
|
324
|
+
/** A creditor reference (AT-T009, structured): RF and its check digits. Never with `text`. */
|
|
325
|
+
readonly reference?: readonly Inline[];
|
|
326
|
+
/** The remittance text (AT-T009, unstructured): at most 140 characters. Never with `reference`. */
|
|
327
|
+
readonly text?: readonly Inline[];
|
|
328
|
+
/** Information for the payer, shown by the banking app and not sent with the transfer: at most 70 characters. */
|
|
329
|
+
readonly information?: readonly Inline[];
|
|
330
|
+
readonly caption?: EpcCaption;
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/payment-part.d.ts
|
|
334
|
+
/**
|
|
335
|
+
* The languages a QR-bill's headings may be printed in: German, French,
|
|
336
|
+
* Italian, English, and Romansh since 1 January 2026 (IG 2.4, Annex C). A
|
|
337
|
+
* report in any other language prints its slip in one of these.
|
|
338
|
+
*/
|
|
339
|
+
export declare const QR_BILL_LANGUAGES: readonly ["de", "fr", "it", "en", "rm"];
|
|
340
|
+
type QrBillLanguage = (typeof QR_BILL_LANGUAGES)[number];
|
|
341
|
+
/** The currencies a QR-bill pays in, and the only ones (IG Table 8, Ccy). */
|
|
342
|
+
export declare const QR_BILL_CURRENCIES: readonly ["CHF", "EUR"];
|
|
343
|
+
type QrBillCurrency = (typeof QR_BILL_CURRENCIES)[number];
|
|
344
|
+
/**
|
|
345
|
+
* A party's address, structured: the one address type SIX has taken since
|
|
346
|
+
* version 2.3 removed the combined one. Each part is runs of text; what
|
|
347
|
+
* each may hold is `QR_BILL_ADDRESS_RULES`.
|
|
348
|
+
*/
|
|
349
|
+
interface QrBillAddress {
|
|
350
|
+
/** A person's first and last name, or a company's: 70 characters. */
|
|
351
|
+
readonly name: readonly Inline[];
|
|
352
|
+
/** The street or post office box, without the building number: 70 characters. */
|
|
353
|
+
readonly street?: readonly Inline[];
|
|
354
|
+
readonly buildingNumber?: readonly Inline[];
|
|
355
|
+
/** Without a country prefix. */
|
|
356
|
+
readonly postalCode: readonly Inline[];
|
|
357
|
+
readonly town: readonly Inline[];
|
|
358
|
+
/** ISO 3166-1's two capital letters: CH. */
|
|
359
|
+
readonly country: readonly Inline[];
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* A Swiss QR-bill. Each text is runs, one at least where it is present; an
|
|
363
|
+
* optional one absent is a field the bill leaves empty, never an empty
|
|
364
|
+
* list of runs, so that one bill has one spelling and one hash.
|
|
365
|
+
*/
|
|
366
|
+
interface SwissQrBill {
|
|
367
|
+
readonly kind: 'swissQrBill';
|
|
368
|
+
/** The language of the slip's headings, which may differ from the report's. */
|
|
369
|
+
readonly language: QrBillLanguage;
|
|
370
|
+
/** The creditor's IBAN or QR-IBAN, of Switzerland or Liechtenstein. Spaces are for reading, and are dropped. */
|
|
371
|
+
readonly account: readonly Inline[];
|
|
372
|
+
readonly creditor: QrBillAddress;
|
|
373
|
+
readonly currency: QrBillCurrency;
|
|
374
|
+
/** A decimal of at most two places. Absent, or null, leaves the amount for the payer to fill in. */
|
|
375
|
+
readonly amount?: Expression;
|
|
376
|
+
/** Who pays. Absent leaves a field for the payer's name and address. */
|
|
377
|
+
readonly debtor?: QrBillAddress;
|
|
378
|
+
/** A QR reference, with a QR-IBAN, or a creditor reference, with an IBAN. Absent, the bill has none. */
|
|
379
|
+
readonly reference?: readonly Inline[];
|
|
380
|
+
/** The unstructured message: what the payment is for. */
|
|
381
|
+
readonly message?: readonly Inline[];
|
|
382
|
+
/** Coded information for the payer's software, beginning with `//`. */
|
|
383
|
+
readonly billingInformation?: readonly Inline[];
|
|
384
|
+
}
|
|
385
|
+
/** The kinds of payment part. A kind this version does not know is refused, never skipped. */
|
|
386
|
+
export declare const PAYMENT_PART_KINDS: readonly ["swissQrBill"];
|
|
387
|
+
type PaymentPartKind = (typeof PAYMENT_PART_KINDS)[number];
|
|
388
|
+
type PaymentPart = SwissQrBill;
|
|
389
|
+
//#endregion
|
|
37
390
|
//#region src/types.d.ts
|
|
38
391
|
export declare const PAGE_SIZE_NAMES: readonly ["A4", "Letter"];
|
|
39
392
|
type PageSizeName = (typeof PAGE_SIZE_NAMES)[number];
|
|
@@ -121,7 +474,8 @@ interface ParameterDef {
|
|
|
121
474
|
/** A boolean for a boolean parameter; for every other type, the exact value as a string. */
|
|
122
475
|
readonly default?: string | boolean;
|
|
123
476
|
}
|
|
124
|
-
|
|
477
|
+
/** An asset's bytes are a PNG, a JPEG, or an SVG in the form report-spec's `cleanSvg` writes (0030). */
|
|
478
|
+
export declare const ASSET_MEDIA_TYPES: readonly ["image/png", "image/jpeg", "image/svg+xml"];
|
|
125
479
|
type AssetMediaType = (typeof ASSET_MEDIA_TYPES)[number];
|
|
126
480
|
/**
|
|
127
481
|
* An approved asset, named by id and pinned by digest. The bytes never live
|
|
@@ -338,6 +692,26 @@ interface ImageComponent extends ComponentBase {
|
|
|
338
692
|
readonly height: number;
|
|
339
693
|
readonly fit: ImageFit;
|
|
340
694
|
}
|
|
695
|
+
/**
|
|
696
|
+
* How much of a QR code may be lost and its content still read: ISO/IEC
|
|
697
|
+
* 18004's four levels, which restore about 7, 15, 25 and 30 % of the
|
|
698
|
+
* codewords. A higher level holds less content in the same square.
|
|
699
|
+
*/
|
|
700
|
+
export declare const QR_ERROR_CORRECTION: readonly ["L", "M", "Q", "H"];
|
|
701
|
+
type QrErrorCorrection = (typeof QR_ERROR_CORRECTION)[number];
|
|
702
|
+
/**
|
|
703
|
+
* A QR code of the text its content prints, drawn as a square of fixed
|
|
704
|
+
* size. The content is read once, as a paragraph's in the same place is,
|
|
705
|
+
* and resolved whole before there are pages: it never holds a page number
|
|
706
|
+
* or count, in any region.
|
|
707
|
+
*/
|
|
708
|
+
interface QrCodeComponent extends ComponentBase {
|
|
709
|
+
readonly kind: 'qrCode';
|
|
710
|
+
readonly content: readonly Inline[];
|
|
711
|
+
/** The side of the square in points, the quiet zone around the modules included. */
|
|
712
|
+
readonly size: number;
|
|
713
|
+
readonly errorCorrection: QrErrorCorrection;
|
|
714
|
+
}
|
|
341
715
|
interface LineComponent extends ComponentBase {
|
|
342
716
|
readonly kind: 'line';
|
|
343
717
|
readonly thickness: number;
|
|
@@ -447,9 +821,9 @@ interface KeepTogetherComponent extends ComponentBase {
|
|
|
447
821
|
readonly kind: 'keepTogether';
|
|
448
822
|
readonly components: readonly Component[];
|
|
449
823
|
}
|
|
450
|
-
export declare const COMPONENT_KINDS: readonly ["text", "image", "line", "rectangle", "spacer", "columns", "section", "table", "pageBreak", "keepTogether"];
|
|
824
|
+
export declare const COMPONENT_KINDS: readonly ["text", "image", "qrCode", "epcQrCode", "line", "rectangle", "spacer", "columns", "section", "table", "pageBreak", "keepTogether"];
|
|
451
825
|
type ComponentKind = (typeof COMPONENT_KINDS)[number];
|
|
452
|
-
type Component = TextComponent | ImageComponent | LineComponent | RectangleComponent | SpacerComponent | ColumnsComponent | SectionComponent | TableComponent | PageBreakComponent | KeepTogetherComponent;
|
|
826
|
+
type Component = TextComponent | ImageComponent | QrCodeComponent | EpcQrCodeComponent | LineComponent | RectangleComponent | SpacerComponent | ColumnsComponent | SectionComponent | TableComponent | PageBreakComponent | KeepTogetherComponent;
|
|
453
827
|
/**
|
|
454
828
|
* The report's regions, in the order a reader meets them. The body is flow
|
|
455
829
|
* only in version 0: ordered blocks, so a growing table pushes what follows
|
|
@@ -489,9 +863,698 @@ interface ReportDefinition {
|
|
|
489
863
|
readonly assets: readonly AssetRef[];
|
|
490
864
|
readonly aggregates: readonly AggregateDef[];
|
|
491
865
|
readonly regions: Regions;
|
|
866
|
+
/** A slip to pay the report by, printed at the foot of its last page: a Swiss QR-bill. Absent, the report has none. */
|
|
867
|
+
readonly paymentPart?: PaymentPart;
|
|
868
|
+
/** The EN 16931 invoice the report is, written as Factur-X from what its page prints. Absent, the report is none. */
|
|
869
|
+
readonly eInvoice?: EInvoice;
|
|
492
870
|
readonly provenance?: Provenance;
|
|
493
871
|
}
|
|
494
872
|
//#endregion
|
|
873
|
+
//#region src/page.d.ts
|
|
874
|
+
interface PageDimensions {
|
|
875
|
+
readonly width: number;
|
|
876
|
+
readonly height: number;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Portrait sizes in points. A4 is ISO 216's 210 x 297 mm, converted and
|
|
880
|
+
* rounded like any other length (595.28 x 841.89, the values PDF engines
|
|
881
|
+
* use); Letter is 8.5 x 11 inches, exactly 612 x 792.
|
|
882
|
+
*/
|
|
883
|
+
export declare const PAGE_SIZES: { readonly [S in PageSizeName]: PageDimensions; };
|
|
884
|
+
/** The page's width and height as oriented: landscape swaps the sides. */
|
|
885
|
+
export declare function pageDimensions(page: {
|
|
886
|
+
readonly size: PageSizeName;
|
|
887
|
+
readonly orientation: Orientation;
|
|
888
|
+
}): PageDimensions;
|
|
889
|
+
/** What the margins leave of the oriented page, to the hundredth of a point that lengths are stored at. */
|
|
890
|
+
export declare function printableArea(page: PageSettings): PageDimensions;
|
|
891
|
+
/**
|
|
892
|
+
* The largest square `area` holds: the length of its shorter side, and
|
|
893
|
+
* which side that is, the width when the two are equal. The validator
|
|
894
|
+
* measures a QR code's square against it and refuses one that overruns it
|
|
895
|
+
* on that side; the builders size a new code by it and name it as the room
|
|
896
|
+
* a refused size lacks.
|
|
897
|
+
*/
|
|
898
|
+
export declare function squareRoom(area: PageDimensions): {
|
|
899
|
+
readonly side: 'width' | 'height';
|
|
900
|
+
readonly length: number;
|
|
901
|
+
};
|
|
902
|
+
//#endregion
|
|
903
|
+
//#region src/payment-reference.d.ts
|
|
904
|
+
/**
|
|
905
|
+
* What every payment code a report prints shares: ISO 7064's check modulo
|
|
906
|
+
* 97, which ISO 13616 checks an IBAN with and ISO 11649 a creditor
|
|
907
|
+
* reference; the creditor reference itself; and what a check says.
|
|
908
|
+
*
|
|
909
|
+
* One check, read by the QR-bill's rules (`qr-bill.ts`) and the EPC QR
|
|
910
|
+
* code's (`epc-payload.ts`): two copies could disagree about which account
|
|
911
|
+
* is typed right, and nobody would find out until a bank refused a payment.
|
|
912
|
+
* What only one code allows -- the QR-bill's accounts of Switzerland and
|
|
913
|
+
* Liechtenstein, its QR reference, the EPC's countries of SEPA -- stays
|
|
914
|
+
* with that code's rules.
|
|
915
|
+
*
|
|
916
|
+
* A rule broken is said without the value that broke it: an IBAN or a
|
|
917
|
+
* reference may be a person's.
|
|
918
|
+
*/
|
|
919
|
+
/** What a check made of a text it accepts, or the rule the text breaks. */
|
|
920
|
+
type PaymentCheck<T> = {
|
|
921
|
+
readonly ok: true;
|
|
922
|
+
readonly value: T;
|
|
923
|
+
} | {
|
|
924
|
+
readonly ok: false;
|
|
925
|
+
readonly rule: string;
|
|
926
|
+
};
|
|
927
|
+
//#endregion
|
|
928
|
+
//#region src/qr-bill.d.ts
|
|
929
|
+
/** What a check made of a text it accepts, or the rule the text breaks: every payment code's `PaymentCheck`. */
|
|
930
|
+
type QrBillCheck<T> = PaymentCheck<T>;
|
|
931
|
+
/**
|
|
932
|
+
* The slip: the receipt and the payment part, 210 by 105 mm (IG 3.1),
|
|
933
|
+
* across the foot of an A4 page in portrait. The builders' band and the
|
|
934
|
+
* renderer's slip are this size.
|
|
935
|
+
*/
|
|
936
|
+
export declare const QR_BILL_SIZE: PageDimensions;
|
|
937
|
+
/**
|
|
938
|
+
* How far down its page the slip starts, in points from the paper's top:
|
|
939
|
+
* 105 mm above the foot of the A4 page (IG 3.1), stored as every length
|
|
940
|
+
* is. The renderer draws the slip from here, and `qrBillPageBreak` keeps
|
|
941
|
+
* what the page prints above it out of it.
|
|
942
|
+
*/
|
|
943
|
+
export declare const QR_BILL_TOP: number;
|
|
944
|
+
/** A rule a page breaks by carrying a QR-bill, and what it is said of: the page's size and orientation, or its top margin. */
|
|
945
|
+
interface QrBillPageBreak {
|
|
946
|
+
readonly field: 'page' | 'topMargin';
|
|
947
|
+
readonly rule: string;
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* The rule `page` breaks by carrying a QR-bill's slip, or undefined. The
|
|
951
|
+
* slip is printed across the foot of an A4 page in portrait (IG 3.1), and
|
|
952
|
+
* what the page prints above it ends at its top, `QR_BILL_TOP`: the page
|
|
953
|
+
* header and the body, which start at the top margin. The page footer
|
|
954
|
+
* never meets it: the slip stands in its place on the last page, and the
|
|
955
|
+
* footers of the pages before it are on pages of their own.
|
|
956
|
+
*
|
|
957
|
+
* `above` is what stands between the top margin and the slip that only a
|
|
958
|
+
* render measures: the page header's height, and the instruction to
|
|
959
|
+
* separate that a PDF prints over the slip's top line (IG 3.7). The
|
|
960
|
+
* validator knows neither and passes none, so it refuses what the top
|
|
961
|
+
* margin alone decides; the renderer passes both, and the same rule
|
|
962
|
+
* refuses the rest. One rule, so that where the slip starts and what
|
|
963
|
+
* reaching into it is are decided once.
|
|
964
|
+
*/
|
|
965
|
+
export declare function qrBillPageBreak(page: PageSettings, above?: number): QrBillPageBreak | undefined;
|
|
966
|
+
interface QrBillAccount {
|
|
967
|
+
/** The IBAN as the code holds it: 21 characters, no spaces. */
|
|
968
|
+
readonly iban: string;
|
|
969
|
+
/** Whether its institution is a QR-IID, so that it is paid to with a QR reference. */
|
|
970
|
+
readonly qrIban: boolean;
|
|
971
|
+
}
|
|
972
|
+
/** The account: an IBAN or a QR-IBAN of Switzerland or Liechtenstein (IG Table 8, IBAN), its spaces dropped. */
|
|
973
|
+
export declare function checkQrBillAccount(text: string): QrBillCheck<QrBillAccount>;
|
|
974
|
+
/** The kinds of reference a bill holds (IG Table 8, Tp): a QR reference, a creditor reference, or none. */
|
|
975
|
+
type QrBillReferenceType = 'QRR' | 'SCOR' | 'NON';
|
|
976
|
+
interface QrBillReference {
|
|
977
|
+
readonly type: 'QRR' | 'SCOR';
|
|
978
|
+
/** The reference as the code holds it: no spaces, in the case it was written. */
|
|
979
|
+
readonly reference: string;
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* The reference: a QR reference of 27 digits, the last its check digit
|
|
983
|
+
* (IG 2.12.1, Annex B), or a creditor reference (IG Table 8, Ref), its
|
|
984
|
+
* spaces dropped.
|
|
985
|
+
*/
|
|
986
|
+
export declare function checkQrBillReference(text: string): QrBillCheck<QrBillReference>;
|
|
987
|
+
/** What a text of the bill may hold: whether it must, how many characters, and a syntax it must have when it is not empty. */
|
|
988
|
+
interface QrBillTextRule {
|
|
989
|
+
/** What a person calls it, for a message: "postal code". */
|
|
990
|
+
readonly said: string;
|
|
991
|
+
readonly required: boolean;
|
|
992
|
+
/** Characters, as SIX counts them: every character it allows is one UTF-16 unit. */
|
|
993
|
+
readonly max: number;
|
|
994
|
+
readonly syntax?: {
|
|
995
|
+
readonly pattern: RegExp;
|
|
996
|
+
readonly rule: string;
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Each part of an address, in the order the code holds them, with what it
|
|
1001
|
+
* may hold (IG Table 8, Cdtr and UltmtDbtr). The name, the postal code,
|
|
1002
|
+
* the town and the country "must be filled in" (IG 4.3.1). A table over
|
|
1003
|
+
* every part, so a part added to `QrBillAddress` without its rule does not
|
|
1004
|
+
* compile, and what reads an address reads it in this order.
|
|
1005
|
+
*/
|
|
1006
|
+
export declare const QR_BILL_ADDRESS_RULES: { readonly [P in keyof QrBillAddress]-?: QrBillTextRule; };
|
|
1007
|
+
/** The most characters the message and the billing information hold together (IG Table 8, AddInf). */
|
|
1008
|
+
export declare const MAX_QR_BILL_ADDITIONAL_INFORMATION = 140;
|
|
1009
|
+
/** The unstructured message (IG Table 8, Ustrd). */
|
|
1010
|
+
export declare const QR_BILL_MESSAGE_RULE: QrBillTextRule;
|
|
1011
|
+
/**
|
|
1012
|
+
* The billing information (IG Table 8, StrdBkgInf; 4.3.3): it begins with
|
|
1013
|
+
* `//` and the two letters or digits that name its syntax, as SIX's own,
|
|
1014
|
+
* `S1`. What follows is the syntax's, which SIX does not standardise.
|
|
1015
|
+
*/
|
|
1016
|
+
export declare const QR_BILL_BILLING_RULE: QrBillTextRule;
|
|
1017
|
+
/**
|
|
1018
|
+
* A text of the bill, without the blanks around it, which SIX never sends
|
|
1019
|
+
* (IG 4.1.3), checked against `rule` and the characters SIX allows. The
|
|
1020
|
+
* first character outside them is named by its position in the text as
|
|
1021
|
+
* written, counted in characters from 1, and never quoted.
|
|
1022
|
+
*/
|
|
1023
|
+
export declare function checkQrBillText(text: string, rule: QrBillTextRule): QrBillCheck<string>;
|
|
1024
|
+
/** The rule the message and the billing information break together, each already checked on its own, or undefined. */
|
|
1025
|
+
export declare function checkQrBillAdditionalInformation(message: string, billingInformation: string): string | undefined;
|
|
1026
|
+
/** A rule an account, a reference and a currency break together, and the field it is reported on. */
|
|
1027
|
+
interface QrBillPairingBreak {
|
|
1028
|
+
readonly field: 'reference' | 'currency';
|
|
1029
|
+
readonly rule: string;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* The rules an account, a reference and a currency break together. A
|
|
1033
|
+
* QR-IBAN is paid to with a QR reference and nothing else; a QR reference
|
|
1034
|
+
* only to a QR-IBAN (IG Table 8, Tp); and from version 2.4 both are for
|
|
1035
|
+
* CHF only (IG 2.4, 2.10). An account or a reference that is not known --
|
|
1036
|
+
* read from data, before a render -- is undefined, and nothing is said of
|
|
1037
|
+
* it.
|
|
1038
|
+
*/
|
|
1039
|
+
export declare function qrBillPairing(account: 'iban' | 'qrIban' | undefined, reference: QrBillReferenceType | undefined, currency: QrBillCurrency): readonly QrBillPairingBreak[];
|
|
1040
|
+
/**
|
|
1041
|
+
* The amount as the code writes it: the exact decimal's own digits, a
|
|
1042
|
+
* point and two decimals (IG Table 8, Amt), from 0.01 to 999 999 999.99.
|
|
1043
|
+
* `DECIMAL` admits no leading zero, so none is written. Never rounded: an
|
|
1044
|
+
* amount written with more than two decimals is refused, a third decimal
|
|
1045
|
+
* of zero among them, so that a template that does not round is refused
|
|
1046
|
+
* on its first render.
|
|
1047
|
+
*/
|
|
1048
|
+
export declare function checkQrBillAmount(decimal: string): QrBillCheck<string>;
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region src/epc-payload.d.ts
|
|
1051
|
+
/** The most bytes the whole payload may take (EPC 2.2): what a version 13 code holds at level M (EPC 2.1). */
|
|
1052
|
+
export declare const EPC_MAX_BYTES = 331;
|
|
1053
|
+
/**
|
|
1054
|
+
* The account (EPC 2.2, AT-C001: "Only IBAN is allowed"): an IBAN of a
|
|
1055
|
+
* country of SEPA, of that country's length, its check digits right. Its
|
|
1056
|
+
* spaces are dropped and its letters made capitals, as the electronic form
|
|
1057
|
+
* writes it -- after its letters are known to be A to Z, so that no letter
|
|
1058
|
+
* becomes two.
|
|
1059
|
+
*
|
|
1060
|
+
* And no QR-IBAN, which SIX keeps for a QR-bill in francs paid with a QR
|
|
1061
|
+
* reference (SIX's QR-bill guidelines 2.8, 2.10): a transfer in euro with
|
|
1062
|
+
* a creditor reference or none is not one it is credited by. That rule is
|
|
1063
|
+
* SIX's, not the EPC's, and its range is the QR-bill's (`isQrIban`).
|
|
1064
|
+
*
|
|
1065
|
+
* An e-invoice's payment account (BT-84) is held by this rule too
|
|
1066
|
+
* (`en16931.ts`): every credit transfer it writes is paid in euro, and an
|
|
1067
|
+
* invoice that prints an EPC QR code beside it names one account.
|
|
1068
|
+
*/
|
|
1069
|
+
export declare function checkEpcIban(text: string): PaymentCheck<string>;
|
|
1070
|
+
/** The BIC of the beneficiary's bank (EPC 2.2, AT-C002), of a bank in SEPA. */
|
|
1071
|
+
export declare function checkEpcBic(text: string): PaymentCheck<string>;
|
|
1072
|
+
/** A rule an IBAN and a BIC break together, reported on the BIC. */
|
|
1073
|
+
interface EpcPairingBreak {
|
|
1074
|
+
readonly field: 'bic';
|
|
1075
|
+
readonly rule: string;
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* The rules an IBAN and a BIC break together. An account outside the EEA
|
|
1079
|
+
* is paid to with its bank's BIC: version 002 lets a code leave the BIC
|
|
1080
|
+
* out, and "the BIC will continue to be mandatory for SEPA payment
|
|
1081
|
+
* transactions involving SCT scheme participants from non-EEA countries"
|
|
1082
|
+
* (EPC 2.2). Those participants are the payer's bank as well as the
|
|
1083
|
+
* beneficiary's, and the payer is not known here: only the account's side
|
|
1084
|
+
* is held.
|
|
1085
|
+
*
|
|
1086
|
+
* And a BIC is of the account's country, by the territory codes EPC409-09
|
|
1087
|
+
* gives each country's BICs and IBANs (5). That pairing is this module's
|
|
1088
|
+
* inference, so that a BIC typed for the wrong country is refused: neither
|
|
1089
|
+
* EPC document says an account's bank has a BIC of the account's country,
|
|
1090
|
+
* and one whose bank's BIC is another country's is refused too. `bic` is
|
|
1091
|
+
* null when the code has none; an IBAN or a BIC that is not known -- read
|
|
1092
|
+
* from data, before a render, or already refused -- is undefined, and
|
|
1093
|
+
* nothing is said of it.
|
|
1094
|
+
*/
|
|
1095
|
+
export declare function epcPairing(iban: string | undefined, bic: string | null | undefined): readonly EpcPairingBreak[];
|
|
1096
|
+
/**
|
|
1097
|
+
* The structured remittance information (EPC 2.2, AT-T009): "ISO 11649 RF
|
|
1098
|
+
* Creditor Reference may be used", and it is the one structured reference
|
|
1099
|
+
* this code takes. Checked as a QR-bill's creditor reference is, and then
|
|
1100
|
+
* made capitals, as the IBAN's letters are -- after they are known to be A
|
|
1101
|
+
* to Z. The EPC marks the reference as one the payer should not change
|
|
1102
|
+
* (2.2, "Fixed") and says nothing of its case, so it is written in one
|
|
1103
|
+
* case, not left to each banking app; a QR-bill keeps the case it was
|
|
1104
|
+
* written in, as SIX says banks draw no distinction.
|
|
1105
|
+
*/
|
|
1106
|
+
export declare function checkEpcReference(text: string): PaymentCheck<string>;
|
|
1107
|
+
/** What a free text of the code may hold: how many characters. */
|
|
1108
|
+
interface EpcTextRule {
|
|
1109
|
+
/** Characters, as the EPC counts them: code points, whatever their bytes. */
|
|
1110
|
+
readonly max: number;
|
|
1111
|
+
}
|
|
1112
|
+
/** The beneficiary's name (EPC 2.2, AT-E001): at most 70 characters. */
|
|
1113
|
+
export declare const EPC_BENEFICIARY_RULE: EpcTextRule;
|
|
1114
|
+
/** The unstructured remittance information (EPC 2.2, AT-T009): at most 140 characters. */
|
|
1115
|
+
export declare const EPC_TEXT_RULE: EpcTextRule;
|
|
1116
|
+
/** The beneficiary to originator information (EPC 2.2): at most 70 characters, shown to the payer and not sent on (PSA 3, note 8). */
|
|
1117
|
+
export declare const EPC_INFORMATION_RULE: EpcTextRule;
|
|
1118
|
+
/**
|
|
1119
|
+
* A free text of the code, checked against `rule`: its characters and its
|
|
1120
|
+
* length. The EPC names character sets (2.1) and no narrower one, so in
|
|
1121
|
+
* UTF-8 any character is taken but a control character, a line break or
|
|
1122
|
+
* half of one: any of them would end the text's element early, or be
|
|
1123
|
+
* written as something else. The first is named by its position, counted
|
|
1124
|
+
* in characters from 1, and never quoted. A text is not trimmed: the EPC
|
|
1125
|
+
* asks for nothing of the kind. Whether it may be blank is its field's
|
|
1126
|
+
* question (`checkEpcField`).
|
|
1127
|
+
*/
|
|
1128
|
+
export declare function checkEpcText(text: string, rule: EpcTextRule): PaymentCheck<string>;
|
|
1129
|
+
/** The texts a code holds, by their names in its component, in the order its payload holds them. */
|
|
1130
|
+
type EpcTextField = 'bic' | 'beneficiary' | 'iban' | 'reference' | 'text' | 'information';
|
|
1131
|
+
/** How a text of the code is held: what a refusal calls it, whether the code may leave its element unused, and the rule it is held to when it holds one. */
|
|
1132
|
+
interface EpcTextFieldRule {
|
|
1133
|
+
readonly what: string;
|
|
1134
|
+
readonly optional: boolean;
|
|
1135
|
+
readonly check: (text: string) => PaymentCheck<string>;
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Each text of the code (EPC 2.2): the name and the IBAN mandatory, the
|
|
1139
|
+
* BIC, the reference, the text and the information optional. One table,
|
|
1140
|
+
* which the validator reads for a literal text and the runtime for one the
|
|
1141
|
+
* data resolved: two could call a field two things, or disagree about
|
|
1142
|
+
* which one a code may leave out, and nobody would find out.
|
|
1143
|
+
*/
|
|
1144
|
+
export declare const EPC_TEXT_FIELDS: { readonly [K in EpcTextField]: EpcTextFieldRule; };
|
|
1145
|
+
/** Whether a text prints nothing a payer reads: empty, or white space alone. */
|
|
1146
|
+
export declare function epcBlank(text: string): boolean;
|
|
1147
|
+
/**
|
|
1148
|
+
* The text of `field`, held to its rule. An element the code holds has one
|
|
1149
|
+
* character at least (EPC 2.2: "1..70an", "1..140an"), so a blank text is
|
|
1150
|
+
* refused: a required one as needed, an optional one as the element left
|
|
1151
|
+
* out, written a second way. That is what the validator says of a literal;
|
|
1152
|
+
* an optional text the data resolves to blank is its element unused
|
|
1153
|
+
* instead, which the runtime decides by `epcBlank` before it asks here.
|
|
1154
|
+
*/
|
|
1155
|
+
export declare function checkEpcField(field: EpcTextField, text: string): PaymentCheck<string>;
|
|
1156
|
+
/**
|
|
1157
|
+
* The purpose of the transfer (EPC 2.2, AT-T007): a purpose code, four
|
|
1158
|
+
* capital letters, as ISO 20022 writes one and the EPC's sample, GDDS, is.
|
|
1159
|
+
*/
|
|
1160
|
+
export declare function checkEpcPurpose(code: string): PaymentCheck<string>;
|
|
1161
|
+
/**
|
|
1162
|
+
* The amount in euro (EPC 2.2, AT-T002), as the code writes it after `EUR`:
|
|
1163
|
+
* from 0.01 to 999999999.99, a point and at most two decimals, and "as
|
|
1164
|
+
* short as possible" (PSA 3, note 5) -- no trailing zero after the point,
|
|
1165
|
+
* no point without a decimal after it, and no leading zero, which `DECIMAL`
|
|
1166
|
+
* admits none of. Written from the exact decimal's own digits, never a
|
|
1167
|
+
* JavaScript number. Never rounded: an amount written with more than two
|
|
1168
|
+
* decimals is refused, a third decimal of zero among them, so that a
|
|
1169
|
+
* template that does not round is refused on its first render.
|
|
1170
|
+
*/
|
|
1171
|
+
export declare function checkEpcAmount(decimal: string): PaymentCheck<string>;
|
|
1172
|
+
/**
|
|
1173
|
+
* What a payload holds, each already checked: absent, undefined or empty is
|
|
1174
|
+
* an element the code leaves unused. A reference and a text are never both
|
|
1175
|
+
* given: only one of the two may be populated (EPC 2.2, {Or}), which the
|
|
1176
|
+
* validator holds a code to.
|
|
1177
|
+
*/
|
|
1178
|
+
interface EpcPayloadFields {
|
|
1179
|
+
readonly bic?: string | undefined;
|
|
1180
|
+
readonly beneficiary: string;
|
|
1181
|
+
readonly iban: string;
|
|
1182
|
+
/** As `checkEpcAmount` writes it, without `EUR`. */
|
|
1183
|
+
readonly amount?: string | undefined;
|
|
1184
|
+
readonly purpose?: string | undefined;
|
|
1185
|
+
readonly reference?: string | undefined;
|
|
1186
|
+
readonly text?: string | undefined;
|
|
1187
|
+
readonly information?: string | undefined;
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* The text the code encodes (EPC 2.2): the service tag `BCD`, the version,
|
|
1191
|
+
* the character set `1` for UTF-8, the identification `SCT`, then the
|
|
1192
|
+
* BIC, the name, the IBAN, the amount in euro, the purpose, the reference,
|
|
1193
|
+
* the text and the information, each on its own line, separated by a line
|
|
1194
|
+
* feed. Every element up to the last the code holds is a line, empty when
|
|
1195
|
+
* it is unused, and "the last populated element is not followed by any
|
|
1196
|
+
* character or element separator" (EPC 2.2; PSA 3).
|
|
1197
|
+
*
|
|
1198
|
+
* A code with a BIC is written as version 001, as the EPC's first sample
|
|
1199
|
+
* is, and one without as 002, the version that lets the BIC be left empty.
|
|
1200
|
+
* That a reader of either version takes 001 is a reading of the two
|
|
1201
|
+
* versions (0025), not something a test here shows.
|
|
1202
|
+
*/
|
|
1203
|
+
export declare function epcPayload(fields: EpcPayloadFields): string;
|
|
1204
|
+
/** How many bytes UTF-8 writes `text` in: one to four for each code point. */
|
|
1205
|
+
export declare function utf8Length(text: string): number;
|
|
1206
|
+
/** A whole payload, held to the 331 bytes the EPC allows (2.2), counted in UTF-8's bytes and not in characters. */
|
|
1207
|
+
export declare function checkEpcPayload(payload: string): PaymentCheck<string>;
|
|
1208
|
+
//#endregion
|
|
1209
|
+
//#region src/epc-print.d.ts
|
|
1210
|
+
/** The largest version a code may have: 69 modules a side, which holds 331 bytes at level M (EPC069-12 2.1). */
|
|
1211
|
+
export declare const EPC_MAX_VERSION = 13;
|
|
1212
|
+
/** The modules a side of a symbol of `version` has: "QR-Code Version*4+17" (PSA 2; ISO/IEC 18004). */
|
|
1213
|
+
export declare function qrSymbolModules(version: number): number;
|
|
1214
|
+
/**
|
|
1215
|
+
* The frame around a captioned code, in modules (PSA 5's figure): four
|
|
1216
|
+
* between the symbol and the frame -- "Distance = 4 * m" -- and between
|
|
1217
|
+
* the symbol and the caption, which the figure asks "min. 3 * m" of: four
|
|
1218
|
+
* meets both, and keeps ISO/IEC 18004's quiet zone of four clear of the
|
|
1219
|
+
* caption. The corner's radius is "r = 2 * m". The line is at most "0,8 *
|
|
1220
|
+
* m" wide; half a module is drawn, clearly within it.
|
|
1221
|
+
*/
|
|
1222
|
+
export declare const EPC_FRAME: {
|
|
1223
|
+
readonly distance: 4;
|
|
1224
|
+
readonly radius: 2;
|
|
1225
|
+
readonly line: 0.5;
|
|
1226
|
+
};
|
|
1227
|
+
/**
|
|
1228
|
+
* The caption (PSA 5): "Zahlen mit Code", "to the right from bottom to
|
|
1229
|
+
* top", at "Font size min. 7pt" in "Arial o.s. non-serifs" -- Liberation
|
|
1230
|
+
* Sans, the QR-bill's face, here. Its band, in points, is the room to the
|
|
1231
|
+
* right of the symbol's distance, to the square's edge: one em of the
|
|
1232
|
+
* caption's size. It holds the caption's letters, which reach 0.725 em
|
|
1233
|
+
* above their baseline and 0.01 em below it in Liberation Sans 2.1.5, and
|
|
1234
|
+
* the frame's right line, which runs along the caption's baseline and is
|
|
1235
|
+
* broken where the caption stands, as in the PSA's figure.
|
|
1236
|
+
*
|
|
1237
|
+
* Its advance, in ems, is its fifteen glyphs' in Liberation Sans 2.1.5:
|
|
1238
|
+
* 15026 of the face's 2048 units per em, as fontkit lays them out for
|
|
1239
|
+
* PDFKit, with no kerning between these letters -- 51.36 pt at 7 pt,
|
|
1240
|
+
* measured on 17 October 2026, and held to the PDF the renderer draws by
|
|
1241
|
+
* report-render-pdf's `epc-qr-code.test.ts`. The caption stands beside the
|
|
1242
|
+
* symbol, centred on it, and no longer than the symbol is tall, as in the
|
|
1243
|
+
* figure, so that the frame's right line is drawn above and below it.
|
|
1244
|
+
*/
|
|
1245
|
+
export declare const EPC_CAPTION: {
|
|
1246
|
+
readonly words: "Zahlen mit Code";
|
|
1247
|
+
readonly size: 7;
|
|
1248
|
+
readonly band: 7;
|
|
1249
|
+
readonly advance: number;
|
|
1250
|
+
};
|
|
1251
|
+
/**
|
|
1252
|
+
* The modules' widths the PSA prints, in millimetres: "minimal ... 15 mil",
|
|
1253
|
+
* "shall not exceed 20 mil" (PSA 5), a mil 0.0254 mm (PSA 2). They are
|
|
1254
|
+
* 1.08 and 1.44 points exactly, `MODULE_HUNDREDTHS`.
|
|
1255
|
+
*/
|
|
1256
|
+
export declare const EPC_CAPTION_MODULE: {
|
|
1257
|
+
readonly least: 0.381;
|
|
1258
|
+
readonly most: 0.508;
|
|
1259
|
+
};
|
|
1260
|
+
/**
|
|
1261
|
+
* The side, in points, of one module of a code of `version` in a square of
|
|
1262
|
+
* `size`. Without a caption, the square holds the symbol and its quiet zone
|
|
1263
|
+
* of four modules a side, as a QR code's does (0020). With one, it holds,
|
|
1264
|
+
* from the left, the frame's line, the distance, the symbol, the distance
|
|
1265
|
+
* and the caption's band; down, the frame and the distance alone, which
|
|
1266
|
+
* take less room than the band does across.
|
|
1267
|
+
*/
|
|
1268
|
+
export declare function epcModule(size: number, version: number, caption: EpcCaption | undefined): number;
|
|
1269
|
+
/**
|
|
1270
|
+
* The least version a code is drawn at in a square of `size`. Without the
|
|
1271
|
+
* caption, 1: the encoder takes the smallest that holds the payload, as
|
|
1272
|
+
* for a QR code. With it, the least whose modules are at most 20 mil and
|
|
1273
|
+
* whose symbol is as tall as the caption, so that a payload too short for
|
|
1274
|
+
* the square is drawn in a larger version of itself, at the same level,
|
|
1275
|
+
* rather than refused; none where even version 13's modules are over 20
|
|
1276
|
+
* mil. Whether the version the payload then needs has modules of 15 mil
|
|
1277
|
+
* or more is `epcCaptionBreak`'s to say.
|
|
1278
|
+
*/
|
|
1279
|
+
export declare function epcLeastVersion(size: number, caption: EpcCaption | undefined): number | undefined;
|
|
1280
|
+
/**
|
|
1281
|
+
* The rule a captioned code in a square of `size` breaks, or undefined. A
|
|
1282
|
+
* render passes the version the encoder chose, and the rules are that
|
|
1283
|
+
* version's: modules from 15 to 20 mil, and a symbol as tall as the
|
|
1284
|
+
* caption. The validator knows no version and passes none, and refuses
|
|
1285
|
+
* only a size in which no version from 1 to 13 prints, naming the run of
|
|
1286
|
+
* sizes some version does. Sizes are compared in the hundredths of a point
|
|
1287
|
+
* they are stored in, exactly.
|
|
1288
|
+
*/
|
|
1289
|
+
export declare function epcCaptionBreak(size: number, version?: number): string | undefined;
|
|
1290
|
+
//#endregion
|
|
1291
|
+
//#region src/en16931.d.ts
|
|
1292
|
+
/**
|
|
1293
|
+
* Every rule of EN 16931 a refusal here names, and no other. The gate reads
|
|
1294
|
+
* this list; `en16931.test.ts` holds it to the ids the rules say.
|
|
1295
|
+
*/
|
|
1296
|
+
export declare const EN16931_RULES: readonly ["BR-02", "BR-03", "BR-06", "BR-07", "BR-09", "BR-11", "BR-16", "BR-21", "BR-22", "BR-23", "BR-24", "BR-25", "BR-26", "BR-27", "BR-29", "BR-61", "BR-CL-11", "BR-CL-14", "BR-CL-23", "BR-CO-04", "BR-CO-09", "BR-CO-17", "BR-CO-18", "BR-CO-19", "BR-CO-26", "BR-DEC-16", "BR-DEC-23", "BR-S-02", "BR-S-05", "BR-S-08", "BR-S-10", "BR-E-01", "BR-E-02", "BR-E-05", "BR-E-10", "BR-AE-01", "BR-AE-02", "BR-AE-05", "BR-AE-10"];
|
|
1297
|
+
type En16931Rule = (typeof EN16931_RULES)[number];
|
|
1298
|
+
/** What a rule says, with the ids of the rules it is: the one way a message here names one, so that every id is a listed one. */
|
|
1299
|
+
export declare function en16931Rule(id: En16931Rule | readonly En16931Rule[], said: string): string;
|
|
1300
|
+
/**
|
|
1301
|
+
* The section of the UStG that asks a German invoice for "die vollständige
|
|
1302
|
+
* Anschrift" of the seller and of the buyer (§ 14 Abs. 4 Satz 1 Nr. 1,
|
|
1303
|
+
* read on gesetze-im-internet.de on 17 October 2026): their street, post
|
|
1304
|
+
* code and city, which no rule of CEN's asks for. BR-08 and BR-10 need
|
|
1305
|
+
* only that each party has a postal address (BG-5, BG-8), and BR-09 and
|
|
1306
|
+
* BR-11 its country. It is the law's, not one of CEN's rules, and so not
|
|
1307
|
+
* in `EN16931_RULES`.
|
|
1308
|
+
*/
|
|
1309
|
+
export declare const FULL_ADDRESS = "§ 14 Abs. 4 Satz 1 Nr. 1 UStG";
|
|
1310
|
+
/** What asks for a term an e-invoice cannot leave out: one of EN 16931's rules, or the UStG's full address. */
|
|
1311
|
+
type EInvoiceNeed = En16931Rule | typeof FULL_ADDRESS;
|
|
1312
|
+
/** What a refusal says of a term `need` asks for that is `said` -- empty, or without a value -- and what asks for it: a rule of CEN's by its id, the UStG by its section and what it asks. */
|
|
1313
|
+
export declare function neededBy(need: EInvoiceNeed, said: string): string;
|
|
1314
|
+
/** Whether a text says nothing: empty, or white space alone. */
|
|
1315
|
+
export declare function eInvoiceBlank(text: string): boolean;
|
|
1316
|
+
/**
|
|
1317
|
+
* The rule a text breaks by holding a character XML 1.0 cannot write, or
|
|
1318
|
+
* undefined. A file that held one would not be XML, and dropping it would
|
|
1319
|
+
* change what the invoice says, so it is refused, named by its position,
|
|
1320
|
+
* counted in characters from 1, never quoted.
|
|
1321
|
+
*/
|
|
1322
|
+
export declare function xmlCharacterBreak(text: string): string | undefined;
|
|
1323
|
+
/** A country (BT-40, BT-55) of `COUNTRY_CODES`, its blanks dropped. */
|
|
1324
|
+
export declare function checkCountryCode(text: string): PaymentCheck<CountryCode>;
|
|
1325
|
+
/** A unit of measure (BT-130) of `UNIT_CODES`, its blanks dropped. */
|
|
1326
|
+
export declare function checkUnitCode(text: string): PaymentCheck<UnitCode>;
|
|
1327
|
+
/** A scheme (BT-30-1, BT-47-1) of `SCHEME_IDS`: a literal the template writes, taken as written. */
|
|
1328
|
+
export declare function checkSchemeId(code: string): PaymentCheck<SchemeId>;
|
|
1329
|
+
/**
|
|
1330
|
+
* A VAT identifier (BT-31, BT-48): a prefix of `VAT_PREFIXES`, which names
|
|
1331
|
+
* the country that issued it (BR-CO-09), and then the number it gives. The
|
|
1332
|
+
* spaces a person writes to read one are dropped, as an IBAN's are; what
|
|
1333
|
+
* follows the prefix is the issuing country's to define, and not checked.
|
|
1334
|
+
*/
|
|
1335
|
+
export declare function checkVatIdentifier(text: string): PaymentCheck<string>;
|
|
1336
|
+
/** How a text term of the e-invoice is held: what a refusal calls it, the rule its absence breaks, and its own rule. */
|
|
1337
|
+
interface EInvoiceTextRule {
|
|
1338
|
+
/** What a refusal calls it, its business term named: "the seller's name (BT-27)". */
|
|
1339
|
+
readonly what: string;
|
|
1340
|
+
/** What an empty one breaks, when the e-invoice needs it; absent, it may be left out. */
|
|
1341
|
+
readonly required?: EInvoiceNeed;
|
|
1342
|
+
/**
|
|
1343
|
+
* Whether the XML writes it as a token: the Factur-X EN 16931 XSD types
|
|
1344
|
+
* an identifier and a code (udt:IDType, udt:CodeType) as xs:token, which
|
|
1345
|
+
* a schema-aware reader collapses -- each tab and line break a space, two
|
|
1346
|
+
* spaces one, none at either end. Such a text holds none of that, or a
|
|
1347
|
+
* reader would read another identifier than the page prints.
|
|
1348
|
+
*/
|
|
1349
|
+
readonly token?: true;
|
|
1350
|
+
/** What it holds when it holds something, past its characters: the value the XML writes, or the rule it breaks. */
|
|
1351
|
+
readonly check?: (text: string) => PaymentCheck<string>;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Each text term of the e-invoice, by its business term. One table, which
|
|
1355
|
+
* the validator reads for a literal text and the runtime for one the data
|
|
1356
|
+
* resolved: two could call a term two things, or disagree about which an
|
|
1357
|
+
* invoice may leave out, and nobody would find out.
|
|
1358
|
+
*
|
|
1359
|
+
* - The address lines, post codes and cities are needed by the UStG's
|
|
1360
|
+
* full address (`FULL_ADDRESS`), past EN 16931, which asks only for the
|
|
1361
|
+
* country.
|
|
1362
|
+
* - An identifier or a code the XML writes as a token holds no white
|
|
1363
|
+
* space a token collapses (`token`).
|
|
1364
|
+
* - The payment account (BT-84) is held by the one rule an EPC QR code's
|
|
1365
|
+
* account is (`checkEpcIban`): an IBAN of a country of SEPA, of its
|
|
1366
|
+
* length, its check digits right (`payment-reference.ts`), and no
|
|
1367
|
+
* QR-IBAN; and its BIC (BT-86) by the EPC QR code's BIC rule
|
|
1368
|
+
* (`checkEpcBic`). Every credit transfer this version writes is paid in
|
|
1369
|
+
* euro, and an invoice that prints both cannot hold two rules for one
|
|
1370
|
+
* account or one bank.
|
|
1371
|
+
* - The exemption reason (BT-120) is needed by its category's code
|
|
1372
|
+
* (`vatReasonBreak`); a line's VAT category (BT-151) is one the invoice
|
|
1373
|
+
* declares (`checkLineCategory`).
|
|
1374
|
+
*/
|
|
1375
|
+
type EInvoiceTextTerm = 'BT-1' | 'BT-10' | 'BT-20' | 'BT-27' | 'BT-30' | 'BT-31' | 'BT-32' | 'BT-35' | 'BT-36' | 'BT-37' | 'BT-38' | 'BT-40' | 'BT-44' | 'BT-47' | 'BT-48' | 'BT-50' | 'BT-51' | 'BT-52' | 'BT-53' | 'BT-55' | 'BT-83' | 'BT-84' | 'BT-85' | 'BT-86' | 'BT-120' | 'BT-126' | 'BT-130' | 'BT-151' | 'BT-153';
|
|
1376
|
+
export declare const E_INVOICE_TEXTS: { readonly [T in EInvoiceTextTerm]: EInvoiceTextRule; };
|
|
1377
|
+
/** Each part of an address, by its business term. */
|
|
1378
|
+
type AddressTerms = { readonly [A in keyof EInvoiceAddress]-?: EInvoiceTextTerm; };
|
|
1379
|
+
/** Which term each text of an e-invoice is, by where it stands in it: the type of `E_INVOICE_TEXT_TERMS`, over every text the format has. */
|
|
1380
|
+
interface EInvoiceTextTerms {
|
|
1381
|
+
readonly number: EInvoiceTextTerm;
|
|
1382
|
+
readonly buyerReference: EInvoiceTextTerm;
|
|
1383
|
+
readonly terms: EInvoiceTextTerm;
|
|
1384
|
+
readonly seller: { readonly [K in Exclude<keyof EInvoiceSeller, 'address'>]-?: EInvoiceTextTerm; } & {
|
|
1385
|
+
readonly address: AddressTerms;
|
|
1386
|
+
};
|
|
1387
|
+
readonly buyer: { readonly [K in Exclude<keyof EInvoiceBuyer, 'address'>]-?: EInvoiceTextTerm; } & {
|
|
1388
|
+
readonly address: AddressTerms;
|
|
1389
|
+
};
|
|
1390
|
+
/** A VAT category's exemption reason. */
|
|
1391
|
+
readonly reason: EInvoiceTextTerm;
|
|
1392
|
+
readonly payment: { readonly [K in Exclude<keyof PaymentInstructions, 'means'>]-?: EInvoiceTextTerm; };
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Which business term each text of an e-invoice is, by where it stands:
|
|
1396
|
+
* the validator reads a literal by it and the runtime what the data
|
|
1397
|
+
* resolved, so the two cannot call one text two terms. A line's texts are
|
|
1398
|
+
* not here: the columns and the row that give them are `E_INVOICE_LINE_COLUMNS`'
|
|
1399
|
+
* and `E_INVOICE_LINE_CODES`'.
|
|
1400
|
+
*/
|
|
1401
|
+
export declare const E_INVOICE_TEXT_TERMS: EInvoiceTextTerms;
|
|
1402
|
+
/**
|
|
1403
|
+
* The text of `term`, held to its rule: one that says nothing is refused,
|
|
1404
|
+
* as needed where the e-invoice needs it and as the term left out where it
|
|
1405
|
+
* may be, a second spelling of one absent; then its characters, which XML
|
|
1406
|
+
* 1.0 must be able to write; then, for a term the XML writes as a token,
|
|
1407
|
+
* its white space; then its own rule. That is what the validator says of a
|
|
1408
|
+
* literal; an optional term the data resolves to blank is left out of the
|
|
1409
|
+
* XML instead, which the runtime decides by `eInvoiceBlank` before it asks
|
|
1410
|
+
* here.
|
|
1411
|
+
*/
|
|
1412
|
+
export declare function checkEInvoiceText(term: EInvoiceTextTerm, text: string): PaymentCheck<string>;
|
|
1413
|
+
/** How a decimal term of the e-invoice is held: what a refusal calls it, the rule a null breaks, and what it may be. */
|
|
1414
|
+
interface EInvoiceDecimalRule {
|
|
1415
|
+
readonly what: string;
|
|
1416
|
+
/** The rule a final render's null breaks; absent, the term may be left out. */
|
|
1417
|
+
readonly required?: En16931Rule;
|
|
1418
|
+
/** The rule more than two decimals break, for a term the XML writes as an amount with two. */
|
|
1419
|
+
readonly cents?: En16931Rule;
|
|
1420
|
+
/** The rule a negative value breaks, for a term that may not be one. */
|
|
1421
|
+
readonly least?: En16931Rule;
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Each decimal term the runtime reads from data, by its business term:
|
|
1425
|
+
* the line's quantity, net price and net amount, and the paid amount. The
|
|
1426
|
+
* totals and the breakdown are not here: the runtime computes them.
|
|
1427
|
+
*/
|
|
1428
|
+
type EInvoiceDecimalTerm = 'BT-129' | 'BT-146' | 'BT-131' | 'BT-113';
|
|
1429
|
+
export declare const E_INVOICE_DECIMALS: { readonly [T in EInvoiceDecimalTerm]: EInvoiceDecimalRule; };
|
|
1430
|
+
/**
|
|
1431
|
+
* The decimal of `term`, an exact decimal as a string, as the XML writes
|
|
1432
|
+
* it: an amount with exactly two decimals, from its own digits; a quantity
|
|
1433
|
+
* or a price as written. Never rounded, and never read through a
|
|
1434
|
+
* JavaScript number: an amount of 10.505 is refused, so that a template
|
|
1435
|
+
* that does not round where it computes a line is refused on its first
|
|
1436
|
+
* render, rather than writing another amount than its page prints. 10.500
|
|
1437
|
+
* is the same number of cents, and is written 10.50.
|
|
1438
|
+
*/
|
|
1439
|
+
export declare function checkEInvoiceDecimal(term: EInvoiceDecimalTerm, decimal: string): PaymentCheck<string>;
|
|
1440
|
+
/** A date term of the e-invoice: what a refusal calls it, and the rule a final render's null breaks where the e-invoice needs it. */
|
|
1441
|
+
interface EInvoiceDateRule {
|
|
1442
|
+
readonly what: string;
|
|
1443
|
+
readonly required?: En16931Rule;
|
|
1444
|
+
}
|
|
1445
|
+
type EInvoiceDateTerm = 'BT-2' | 'BT-9' | 'BT-72' | 'BT-73' | 'BT-74';
|
|
1446
|
+
/** Each date term, by its business term. */
|
|
1447
|
+
export declare const E_INVOICE_DATES: { readonly [T in EInvoiceDateTerm]: EInvoiceDateRule; };
|
|
1448
|
+
/**
|
|
1449
|
+
* A date term the data resolved, held to a day on the calendar written
|
|
1450
|
+
* YYYY-MM-DD, as the runtime holds a date. The editing core types a date
|
|
1451
|
+
* term as the ISO string a date field is read as, so any text passes it;
|
|
1452
|
+
* one that is not a day -- a name, 2026-02-29, a moment with its time --
|
|
1453
|
+
* would be written as a date no validator reads as one.
|
|
1454
|
+
*/
|
|
1455
|
+
export declare function checkEInvoiceDate(text: string): PaymentCheck<string>;
|
|
1456
|
+
/** What a line's term is read from: its business term, whose rule holds it, what a refusal calls it, and the types of field that can give it. */
|
|
1457
|
+
interface EInvoiceLineTerm {
|
|
1458
|
+
readonly term: EInvoiceTextTerm | EInvoiceDecimalTerm;
|
|
1459
|
+
readonly what: string;
|
|
1460
|
+
readonly types: readonly FieldType[];
|
|
1461
|
+
}
|
|
1462
|
+
type EInvoiceLineColumn = 'name' | 'quantity' | 'netPrice' | 'netAmount';
|
|
1463
|
+
type EInvoiceLineCode = 'id' | 'unit' | 'vat';
|
|
1464
|
+
/**
|
|
1465
|
+
* Each term a column of the lines' table prints, in the order the XML
|
|
1466
|
+
* holds a line's. A column prints a detail field of one of these types, or
|
|
1467
|
+
* an expression the editing core holds to what it reads them as: one
|
|
1468
|
+
* table, so the validator and the core cannot take a column for two
|
|
1469
|
+
* things.
|
|
1470
|
+
*/
|
|
1471
|
+
export declare const E_INVOICE_LINE_COLUMNS: { readonly [K in EInvoiceLineColumn]: EInvoiceLineTerm; };
|
|
1472
|
+
/** Each code read from a line's row, a detail field of one of these types or an expression held to them in the same way. */
|
|
1473
|
+
export declare const E_INVOICE_LINE_CODES: { readonly [K in EInvoiceLineCode]: EInvoiceLineTerm; };
|
|
1474
|
+
/**
|
|
1475
|
+
* The rule an invoicing period breaks whose dates the data resolved, or
|
|
1476
|
+
* undefined: it ends no earlier than it starts (BR-29). Both are calendar
|
|
1477
|
+
* dates written YYYY-MM-DD, as the runtime's dates are, so they compare as
|
|
1478
|
+
* text.
|
|
1479
|
+
*/
|
|
1480
|
+
export declare function checkInvoicingPeriod(start: string, end: string): string | undefined;
|
|
1481
|
+
/** The rule an invoicing period breaks by holding neither date (BR-CO-19), or undefined: `start` and `end` say which it holds. */
|
|
1482
|
+
export declare function periodBreak(start: boolean, end: boolean): string | undefined;
|
|
1483
|
+
/**
|
|
1484
|
+
* The rule an invoice breaks that says nothing of when it was supplied, or
|
|
1485
|
+
* undefined: § 14 (4) 1 no. 6 UStG asks a German invoice for the time of
|
|
1486
|
+
* supply, which the XML gives as a delivery date or an invoicing period.
|
|
1487
|
+
* Not one of CEN's rules: FeRD's BR-FX-DE-04, as the specification is
|
|
1488
|
+
* transcribed [S], only warns of an invoice without one.
|
|
1489
|
+
*/
|
|
1490
|
+
export declare function supplyBreak(delivered: boolean, period: boolean): string | undefined;
|
|
1491
|
+
/**
|
|
1492
|
+
* The rules the seller's identifiers break, `has` saying which it holds,
|
|
1493
|
+
* for an invoice whose lines are in categories of `codes`:
|
|
1494
|
+
* - BR-CO-26: a buyer identifies a seller by its VAT identifier or its
|
|
1495
|
+
* legal registration (BT-29, the third way, this version does not write);
|
|
1496
|
+
* - BR-S-02, BR-E-02, BR-AE-02: a line in any of the three categories needs
|
|
1497
|
+
* the seller's VAT identifier or its tax number.
|
|
1498
|
+
*
|
|
1499
|
+
* The validator passes what the template declares: every line is in a
|
|
1500
|
+
* category the invoice declares, and every invoice has a line, so a rule
|
|
1501
|
+
* of a declared category is one some render breaks. The runtime passes
|
|
1502
|
+
* the categories its lines use and the identifiers that print.
|
|
1503
|
+
*/
|
|
1504
|
+
export declare function sellerIdentificationBreaks(has: {
|
|
1505
|
+
readonly vatId: boolean;
|
|
1506
|
+
readonly taxNumber: boolean;
|
|
1507
|
+
readonly legalId: boolean;
|
|
1508
|
+
}, codes: readonly VatCategoryCode[]): readonly string[];
|
|
1509
|
+
/**
|
|
1510
|
+
* The rule the buyer's identifiers break, or undefined: a reverse-charged
|
|
1511
|
+
* line moves the tax to the buyer, and needs it named by its VAT identifier
|
|
1512
|
+
* or its legal registration (BR-AE-02).
|
|
1513
|
+
*/
|
|
1514
|
+
export declare function buyerIdentificationBreak(has: {
|
|
1515
|
+
readonly vatId: boolean;
|
|
1516
|
+
readonly legalId: boolean;
|
|
1517
|
+
}, codes: readonly VatCategoryCode[]): string | undefined;
|
|
1518
|
+
/**
|
|
1519
|
+
* The rate of a category of `code`, by value, without the trailing zeros
|
|
1520
|
+
* that do not change it: more than 0 when standard rated (BR-S-05), 0 when
|
|
1521
|
+
* exempt or reverse-charged (BR-E-05, BR-AE-05). Compared as text, never
|
|
1522
|
+
* as a JavaScript number: report-spec has no decimal, and needs none.
|
|
1523
|
+
*
|
|
1524
|
+
* And a standard rate of 0.5 or more (BR-CO-17). CEN's rule rounds the
|
|
1525
|
+
* rate first, and XPath's round(0.4) is 0: a breakdown whose rate rounds
|
|
1526
|
+
* to 0 must then hold a tax that rounds to 0, which a standard rated
|
|
1527
|
+
* category's tax does not past a small basis -- at 0.4, one of 125 or
|
|
1528
|
+
* more. No rate of the EU's is that low.
|
|
1529
|
+
*/
|
|
1530
|
+
export declare function checkVatRate(code: VatCategoryCode, rate: string): PaymentCheck<string>;
|
|
1531
|
+
/**
|
|
1532
|
+
* The rule a category's exemption reason (BT-120) breaks, or undefined:
|
|
1533
|
+
* exempt and reverse-charged categories say why (BR-E-10, BR-AE-10), and a
|
|
1534
|
+
* standard rated one has no reason to give (BR-S-10).
|
|
1535
|
+
*/
|
|
1536
|
+
export declare function vatReasonBreak(code: VatCategoryCode, hasReason: boolean): string | undefined;
|
|
1537
|
+
/** A rule a list of categories breaks, and the category and field it is said of. */
|
|
1538
|
+
interface VatCategoryBreak {
|
|
1539
|
+
readonly index: number;
|
|
1540
|
+
readonly field: 'code' | 'rate';
|
|
1541
|
+
readonly rule: string;
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* The rules a list of categories, each with a rate `checkVatRate` took,
|
|
1545
|
+
* breaks together: each is one VAT breakdown (BG-23), so standard rated
|
|
1546
|
+
* categories have distinct rates by value (BR-S-08), and there is one
|
|
1547
|
+
* exempt and one reverse-charged category at most (BR-E-01, BR-AE-01). Two
|
|
1548
|
+
* that would be one breakdown would each claim every one of its lines, and
|
|
1549
|
+
* the XML would fail. The later of the two is refused.
|
|
1550
|
+
*/
|
|
1551
|
+
export declare function vatCategoryBreaks(categories: readonly {
|
|
1552
|
+
readonly code: VatCategoryCode;
|
|
1553
|
+
readonly rate: string;
|
|
1554
|
+
}[]): readonly VatCategoryBreak[];
|
|
1555
|
+
/** The category a line names by `id`, a category the invoice declares (BR-CO-04). */
|
|
1556
|
+
export declare function checkLineCategory(id: string, categories: readonly VatCategory[]): PaymentCheck<VatCategory>;
|
|
1557
|
+
//#endregion
|
|
495
1558
|
//#region src/errors.d.ts
|
|
496
1559
|
/**
|
|
497
1560
|
* What validation can say is wrong with a report, as stable codes.
|
|
@@ -501,7 +1564,7 @@ interface ReportDefinition {
|
|
|
501
1564
|
* reworded once released; a new rule gets a new code. Each has a refusal
|
|
502
1565
|
* test in `validate.test.ts`, which does not compile while one is missing.
|
|
503
1566
|
*/
|
|
504
|
-
export declare const REPORT_ERROR_CODES: readonly ["not-a-report", "unsupported-version", "not-json", "too-many-errors", "wrong-type", "missing-property", "unknown-property", "unknown-kind", "not-one-of", "out-of-range", "not-an-integer", "too-precise", "too-long", "too-many", "too-few", "empty-expression", "invalid-id", "invalid-locale", "invalid-color", "invalid-currency", "invalid-digest", "invalid-default", "invalid-decimal", "printable-area-too-small", "scale-on-non-decimal", "duplicate-id", "reserved-id", "unknown-style", "unknown-dataset", "unknown-field", "unknown-parameter", "unknown-asset", "unknown-aggregate", "unknown-column", "misplaced-flow-component", "nested-flow-component", "misplaced-page-counter", "misplaced-detail-field", "misplaced-group-aggregate", "second-detail-table", "nesting-too-deep", "duplicate-component-id", "duplicate-column-id", "duplicate-footer-cell", "duplicate-sort-key", "exceeds-printable-area", "aggregate-type-mismatch", "format-type-mismatch", "binding-type-mismatch"];
|
|
1567
|
+
export declare const REPORT_ERROR_CODES: readonly ["not-a-report", "unsupported-version", "not-json", "too-many-errors", "wrong-type", "missing-property", "unknown-property", "unknown-kind", "not-one-of", "out-of-range", "not-an-integer", "too-precise", "too-long", "too-many", "too-few", "empty-expression", "invalid-id", "invalid-locale", "invalid-color", "invalid-currency", "invalid-digest", "invalid-default", "invalid-decimal", "invalid-qr-bill", "invalid-epc-qr-code", "invalid-e-invoice", "printable-area-too-small", "scale-on-non-decimal", "duplicate-id", "reserved-id", "unknown-style", "unknown-dataset", "unknown-field", "unknown-parameter", "unknown-asset", "unknown-aggregate", "unknown-column", "misplaced-flow-component", "nested-flow-component", "misplaced-page-counter", "misplaced-detail-field", "misplaced-group-aggregate", "second-detail-table", "nesting-too-deep", "duplicate-component-id", "duplicate-column-id", "duplicate-footer-cell", "duplicate-sort-key", "exceeds-printable-area", "payment-part-page", "aggregate-type-mismatch", "format-type-mismatch", "binding-type-mismatch"];
|
|
505
1568
|
type ReportErrorCode = (typeof REPORT_ERROR_CODES)[number];
|
|
506
1569
|
interface ReportError {
|
|
507
1570
|
/** A JSON Pointer (RFC 6901) to what is wrong; '' is the whole document. */
|
|
@@ -553,6 +1616,10 @@ export declare function validateReport(document: unknown): ReportValidation;
|
|
|
553
1616
|
* are not chosen, and say where they come from. Raising a bound is safe;
|
|
554
1617
|
* lowering one refuses reports that were valid, which once the format is
|
|
555
1618
|
* frozen means a new reportSpecVersion.
|
|
1619
|
+
*
|
|
1620
|
+
* The bounds of an SVG asset, at the end, are the exception: each but
|
|
1621
|
+
* `MAX_SVG_REMOVED_NAMES` was measured, and says how, on what and when
|
|
1622
|
+
* (0030).
|
|
556
1623
|
*/
|
|
557
1624
|
/**
|
|
558
1625
|
* Errors listed per validation. Past it, one `too-many-errors` entry says
|
|
@@ -594,8 +1661,32 @@ export declare const MAX_STYLE_RULES = 8;
|
|
|
594
1661
|
export declare const MAX_PARAMETERS = 32;
|
|
595
1662
|
/** Asset references: each is a lookup and a byte budget at render time. */
|
|
596
1663
|
export declare const MAX_ASSETS = 64;
|
|
1664
|
+
/**
|
|
1665
|
+
* The most bytes one image asset may have: 20 MB, the renderer trial's
|
|
1666
|
+
* limit, the plan's "enforced limits" made a number to test, and chosen, not
|
|
1667
|
+
* measured. A builder refuses a file past it before reading it, the runtime
|
|
1668
|
+
* a host's answer past it before copying it, and the renderer bytes past it
|
|
1669
|
+
* before decoding them, from this one constant; an SVG is held to
|
|
1670
|
+
* `MAX_SVG_BYTES` besides.
|
|
1671
|
+
*/
|
|
1672
|
+
export declare const MAX_ASSET_BYTES: number;
|
|
1673
|
+
/**
|
|
1674
|
+
* Pixels a side of a PNG or a JPEG asset: the renderer trial's limit too,
|
|
1675
|
+
* and as chosen. What pictures of this size cost the renderer to embed is
|
|
1676
|
+
* measured beside report-render-pdf's `MAX_IMAGE_DATA`, which bounds a
|
|
1677
|
+
* render by them. `imageHeader` holds a picture to it, where a person adds
|
|
1678
|
+
* one and where it prints.
|
|
1679
|
+
*/
|
|
1680
|
+
export declare const MAX_ASSET_SIDE = 4096;
|
|
597
1681
|
/** Aggregates: each is a pass over the detail rows, per group and once overall. */
|
|
598
1682
|
export declare const MAX_AGGREGATES = 32;
|
|
1683
|
+
/**
|
|
1684
|
+
* VAT categories an e-invoice declares, each a VAT breakdown (BG-23) its
|
|
1685
|
+
* XML writes and a basis and an amount its page reads. Germany's two rates,
|
|
1686
|
+
* an exempt category and a reverse-charged one take four; eight is twice
|
|
1687
|
+
* that, and a list of breakdowns no invoice prints is refused unread.
|
|
1688
|
+
*/
|
|
1689
|
+
export declare const MAX_VAT_CATEGORIES = 8;
|
|
599
1690
|
/** Inline runs in one paragraph or group header. A paragraph with more bindings than this is a table. */
|
|
600
1691
|
export declare const MAX_INLINES = 64;
|
|
601
1692
|
/**
|
|
@@ -628,6 +1719,157 @@ export declare const MAX_LENGTH_PT = 14400;
|
|
|
628
1719
|
* not hold a word of body text.
|
|
629
1720
|
*/
|
|
630
1721
|
export declare const MIN_PRINTABLE_PT = 72;
|
|
1722
|
+
/**
|
|
1723
|
+
* Bytes in an SVG asset, both as the file comes and as `cleanSvg` writes it:
|
|
1724
|
+
* the written form can be several times its input -- a relative path written
|
|
1725
|
+
* as absolute coordinates, a colour name as `#rrggbb` -- so a drawing whose
|
|
1726
|
+
* cleaned form would pass this is refused when it is approved, not at every
|
|
1727
|
+
* print after. A logo is kilobytes; the exporters' invented samples were
|
|
1728
|
+
* 545-2,520 bytes in and 483-994 out. At the bound the cleaner itself took
|
|
1729
|
+
* at most 179 ms in Node on the costliest it accepts (`MAX_SVG_CASCADE`'s
|
|
1730
|
+
* worst; 3,000 moves, each styled with every property and turned, written
|
|
1731
|
+
* to 1.04 MB, 141-162 ms), 35-120 ms on a mebibyte of each shape of value
|
|
1732
|
+
* `svg-threats.test.ts` holds it to, and 292-331 ms to refuse a mebibyte of
|
|
1733
|
+
* path past MAX_SVG_SEGMENTS (Node alone, on the day these were measured
|
|
1734
|
+
* again); a page of rectangles of that size takes the renderer 0.94 s to
|
|
1735
|
+
* draw.
|
|
1736
|
+
*/
|
|
1737
|
+
export declare const MAX_SVG_BYTES = 1048576;
|
|
1738
|
+
/**
|
|
1739
|
+
* Element levels in a drawing, the root's included, as the file nests them
|
|
1740
|
+
* and as `cleanSvg` writes them; also the longest chain of gradients that
|
|
1741
|
+
* name each other. pdfmake's XML reader and svg-to-pdfkit both recurse once
|
|
1742
|
+
* per level, and 5,000 levels overflowed the stack in a probe. 32 and 64
|
|
1743
|
+
* levels with a transform each cost the same as none (122 ms to render, 59-65
|
|
1744
|
+
* ms to pixels), so this bounds recursion, not time. The deepest exporter
|
|
1745
|
+
* sample nests four.
|
|
1746
|
+
*/
|
|
1747
|
+
export declare const MAX_SVG_DEPTH = 32;
|
|
1748
|
+
/**
|
|
1749
|
+
* Elements in a cleaned drawing. svg-to-pdfkit re-reads and draws every one
|
|
1750
|
+
* on every page it is drawn on, at about 34 microseconds an element: 10,000
|
|
1751
|
+
* one-unit rectangles took 545 ms of the renderer's final pass against 55
|
|
1752
|
+
* without them, and 234 ms (DPR 1) and 198 ms (DPR 2) to pixels.
|
|
1753
|
+
*/
|
|
1754
|
+
export declare const MAX_SVG_ELEMENTS = 10000;
|
|
1755
|
+
/**
|
|
1756
|
+
* What one drawing costs a reader to paint, in weighted segments. Each
|
|
1757
|
+
* command the converter draws counts: a move, a line or a close 1, a curve
|
|
1758
|
+
* 3 (10,000 short crossing cubics cost about what 30,000 such lines do, in
|
|
1759
|
+
* Node and in Chromium; a cubic spanning the box costs less than three
|
|
1760
|
+
* lines that do, 10,000 of them 238 ms against 933 ms for 30,000 lines,
|
|
1761
|
+
* as review measured the same day), an arc 3 for each curve svg-to-pdfkit splits it
|
|
1762
|
+
* into (one per 60 degrees, `source.js:1054` at its default precision), and
|
|
1763
|
+
* an arc that ends where it starts, which draws nothing, 1. A stroked shape
|
|
1764
|
+
* counts its commands twice more, three times in all when it is also filled
|
|
1765
|
+
* (10,000 lines filled and stroked cost about what 30,000 filled do). A clip
|
|
1766
|
+
* path's commands count once for every element it clips, a gradient's stops
|
|
1767
|
+
* once for every shape painted with it, and a dashed stroke one more for
|
|
1768
|
+
* each dash it could draw.
|
|
1769
|
+
*
|
|
1770
|
+
* A rasteriser's worst is a path whose every segment crosses the whole
|
|
1771
|
+
* box: it pays for each segment on every row of pixels the segment spans,
|
|
1772
|
+
* so the cost grows faster than the count. A zigzag of such lines took 121
|
|
1773
|
+
* ms to pixels at DPR 1 and 132 ms at DPR 2 in a 15 mm box at this bound,
|
|
1774
|
+
* 268-276 ms at 15,000, 490-500 ms at 20,000 and 1.15-1.27 s at 30,000; the
|
|
1775
|
+
* worst accepted -- that zigzag in a clipped group, with three more clipped
|
|
1776
|
+
* shapes, every group the bounds allow -- took 190 and 392 ms at 15 mm and
|
|
1777
|
+
* 269 and 550 ms page-wide, against 63 to 89 ms for a starter page (on
|
|
1778
|
+
* 2026-10-18, in the Chromium and pdfjs-dist above, medians of five). The
|
|
1779
|
+
* same count of 30,000 in paths whose segments were a seventh of the box
|
|
1780
|
+
* long took 184-295 ms, and spanning the box 1.15 to 1.84 s. A logo whose
|
|
1781
|
+
* curves are short costs far less than its count says, and one of more
|
|
1782
|
+
* than this is refused, to be simplified in the drawing program.
|
|
1783
|
+
*/
|
|
1784
|
+
export declare const MAX_SVG_SEGMENTS = 10000;
|
|
1785
|
+
/**
|
|
1786
|
+
* Transparency groups in one drawing, in units: a clip-path reference 1, a
|
|
1787
|
+
* group with an opacity under 1 1, and a shape painted with a gradient
|
|
1788
|
+
* whose stops come out translucent 2. svg-to-pdfkit makes every one a
|
|
1789
|
+
* group the size of the whole page, whatever the size of the logo, and a
|
|
1790
|
+
* translucent gradient two page-sized objects, so the cost is the page's
|
|
1791
|
+
* pixels: about 15 ms a clip at DPR 1 and 59 ms at DPR 2, 30 ms and 117 ms
|
|
1792
|
+
* a translucent gradient, 1.4 ms and 5.2 ms a group opacity. Four units keep
|
|
1793
|
+
* the worst accepted at about 60 ms more than a starter page at DPR 1 and
|
|
1794
|
+
* 240 ms at DPR 2, and admit every exporter sample: Figma's clipped frame is
|
|
1795
|
+
* 1, Figma's fade with a layer at 80 % is 3, Canva's two shapes 2. A
|
|
1796
|
+
* translucent stop is kept because a bound this small admits them; a Canva
|
|
1797
|
+
* logo of five shapes or more, each clipped, is refused.
|
|
1798
|
+
*/
|
|
1799
|
+
export declare const MAX_SVG_GROUPS = 4;
|
|
1800
|
+
/**
|
|
1801
|
+
* Stops in one gradient. Each use of a 64-stop gradient writes 10.9 kB into
|
|
1802
|
+
* the PDF and costs a reader about half a millisecond; `MAX_SVG_SEGMENTS`
|
|
1803
|
+
* bounds the uses, counting a gradient's stops once each. A logo's
|
|
1804
|
+
* gradients have two to five.
|
|
1805
|
+
*/
|
|
1806
|
+
export declare const MAX_SVG_STOPS = 64;
|
|
1807
|
+
/**
|
|
1808
|
+
* Entries in a stroke's dash array, after an odd list is doubled as SVG
|
|
1809
|
+
* doubles it. Every dash it draws counts against `MAX_SVG_SEGMENTS` too: a
|
|
1810
|
+
* spiral of 4,096 segments dashed at a period of 0.01 units, about 900,000
|
|
1811
|
+
* dashes, cost 219-265 ms to pixels against 70-102 ms dashed at a period of
|
|
1812
|
+
* one unit. Skia gives up at a count of its own; another reader may not.
|
|
1813
|
+
*/
|
|
1814
|
+
export declare const MAX_SVG_DASHES = 32;
|
|
1815
|
+
/**
|
|
1816
|
+
* The largest magnitude of any number in a drawing; of every entry of the
|
|
1817
|
+
* transform composed from the root down to each element, and of its
|
|
1818
|
+
* inverse, which svg-to-pdfkit computes for every clip and group opacity;
|
|
1819
|
+
* and of the matrix a gradient is drawn under, its shape's and its box's
|
|
1820
|
+
* composed with its own. With a point and a matrix both at it in a viewBox
|
|
1821
|
+
* one unit wide, the renderer drew in 115 ms with no warning, and the
|
|
1822
|
+
* device coordinates stayed near 10^13 points, far below the 10^21 at
|
|
1823
|
+
* which PDFKit throws; past it, two groups shrinking a millionfold each
|
|
1824
|
+
* under a clip, or a gradient composed to a million cubed, threw from
|
|
1825
|
+
* inside PDFKit. An e-invoice's PDF/A-3 keeps none of PDF/A-1's 32,767 for
|
|
1826
|
+
* a real: veraPDF 1.30.3's PDF/A-3b profile holds a real to 3.403 × 10^38
|
|
1827
|
+
* (its rule 6.1.13-2), past PDFKit's 10^21, and an integer to 2,147,483,647
|
|
1828
|
+
* (6.1.13-1), which the numbers the converter computes from these bounds can
|
|
1829
|
+
* pass -- a group's box under a shrink of 10^6 in a box of a point reached
|
|
1830
|
+
* 7.85 × 10^10 -- so the renderer holds an SVG in an e-invoice to that by
|
|
1831
|
+
* the extent `cleanSvg` measures (`svg-extent.ts`; report-render-pdf's
|
|
1832
|
+
* `svg-pdfa.ts`), and no bound here is lowered for it.
|
|
1833
|
+
*/
|
|
1834
|
+
export declare const MAX_SVG_COORDINATE = 1000000;
|
|
1835
|
+
/**
|
|
1836
|
+
* Simple selectors -- a type, a class or an id -- in all of a drawing's
|
|
1837
|
+
* stylesheets together, after comma lists are split. Indexing the rules by
|
|
1838
|
+
* id, class and type makes matching linear in the rules that could match,
|
|
1839
|
+
* but rules that all match every element cannot be shortened that way, so
|
|
1840
|
+
* the work is this bound times the combinations of classes elements hold.
|
|
1841
|
+
* The rules one combination matches are merged once: 256 one-class rules,
|
|
1842
|
+
* each declaring every kept property, all matching 10,000 elements, took
|
|
1843
|
+
* the cleaner 85-102 ms in Node and 63-81 ms in Chromium, against 1.9 s
|
|
1844
|
+
* when every element read every rule. Elements of combinations of their
|
|
1845
|
+
* own are bounded by `MAX_SVG_CASCADE`. Illustrator's samples hold three.
|
|
1846
|
+
*/
|
|
1847
|
+
export declare const MAX_SVG_RULES = 256;
|
|
1848
|
+
/**
|
|
1849
|
+
* The cascade's work, in all: each rule compared with a combination of
|
|
1850
|
+
* type, id and classes an element holds, and each declaration merged for it.
|
|
1851
|
+
* Merging once per combination makes ten thousand elements of one class one
|
|
1852
|
+
* merge, but elements that each hold a combination of their own are one
|
|
1853
|
+
* merge each: 9,990 elements, each of its own set of fourteen classes, under
|
|
1854
|
+
* 242 type rules declaring every kept property took the cleaner 1.8 s in
|
|
1855
|
+
* Node. At this bound the costliest shape measured -- 5,000 elements each
|
|
1856
|
+
* of its own pair of 101 classes, under 98 type rules of one declaration --
|
|
1857
|
+
* took 179 ms (158-271), within what the worst file `MAX_SVG_BYTES` admits
|
|
1858
|
+
* costs, and that shape of 9,990 elements is refused in 136 ms. An
|
|
1859
|
+
* Illustrator export, one class an element from a few dozen, merges a few
|
|
1860
|
+
* hundred times. Measured on 2026-10-18 under Node 24.21.0, medians of five,
|
|
1861
|
+
* on the machine and the terms above.
|
|
1862
|
+
*/
|
|
1863
|
+
export declare const MAX_SVG_CASCADE = 1000000;
|
|
1864
|
+
/**
|
|
1865
|
+
* Distinct names `cleanSvg` lists among what it removed; removals of every
|
|
1866
|
+
* further name are counted, not named, so that the list a person is shown
|
|
1867
|
+
* does not grow with what a file holds. Chosen, not measured: the Inkscape
|
|
1868
|
+
* sample, the most any exporter's sample removes, lists 26 names -- its
|
|
1869
|
+
* editor's attributes, namespaces, layers and text properties -- and a
|
|
1870
|
+
* bound of 16 would have cut it short.
|
|
1871
|
+
*/
|
|
1872
|
+
export declare const MAX_SVG_REMOVED_NAMES = 32;
|
|
631
1873
|
//#endregion
|
|
632
1874
|
//#region src/syntax.d.ts
|
|
633
1875
|
/**
|
|
@@ -643,6 +1885,163 @@ export declare function isIdentifier(value: unknown): value is string;
|
|
|
643
1885
|
/** Whether `value` is a field key: the id of a dataset field, a parameter or an aggregate. */
|
|
644
1886
|
export declare function isFieldKey(value: unknown): value is string;
|
|
645
1887
|
//#endregion
|
|
1888
|
+
//#region src/digest.d.ts
|
|
1889
|
+
/** `sha256:` and the lower-case hex SHA-256 of exactly `bytes`; @noble/hashes' TypeError for anything that is not a Uint8Array. */
|
|
1890
|
+
export declare function assetDigest(bytes: Uint8Array): string;
|
|
1891
|
+
//#endregion
|
|
1892
|
+
//#region src/image-header.d.ts
|
|
1893
|
+
/** A PNG's header, as the renderer needs it to check the image data: its scanlines follow from the size, the bits a pixel and the interlace. */
|
|
1894
|
+
interface PngHeader {
|
|
1895
|
+
readonly ok: true;
|
|
1896
|
+
readonly mediaType: 'image/png';
|
|
1897
|
+
readonly width: number;
|
|
1898
|
+
readonly height: number;
|
|
1899
|
+
readonly bitsPerPixel: number;
|
|
1900
|
+
/** Adam7, the one interlace method PNG defines. */
|
|
1901
|
+
readonly interlaced: boolean;
|
|
1902
|
+
/** The image data, every IDAT chunk's joined in order: compressed, and not inflated here. */
|
|
1903
|
+
readonly data: Uint8Array<ArrayBuffer>;
|
|
1904
|
+
}
|
|
1905
|
+
/** A JPEG's frame, as it is shown. */
|
|
1906
|
+
interface JpegHeader {
|
|
1907
|
+
readonly ok: true;
|
|
1908
|
+
readonly mediaType: 'image/jpeg';
|
|
1909
|
+
readonly width: number;
|
|
1910
|
+
readonly height: number;
|
|
1911
|
+
/** Grey, RGB or CMYK, as PDFKit draws a JPEG of one, three or four components (pdfkit.js 3808-3812). */
|
|
1912
|
+
readonly components: 1 | 3 | 4;
|
|
1913
|
+
}
|
|
1914
|
+
type RasterHeader = PngHeader | JpegHeader;
|
|
1915
|
+
/** Why a PNG's or a JPEG's bytes are refused, each the first thing found wrong with them. */
|
|
1916
|
+
export declare const IMAGE_REFUSAL_CODES: readonly ["not-raster", "malformed", "no-pixels", "too-large"];
|
|
1917
|
+
type ImageRefusalCode = (typeof IMAGE_REFUSAL_CODES)[number];
|
|
1918
|
+
/** A refusal, said in English after the image's name -- the renderer says `the image asset logo ${message}` -- and, for one of its size, the size, for a person's own language. */
|
|
1919
|
+
type ImageRefusal = {
|
|
1920
|
+
readonly ok: false;
|
|
1921
|
+
readonly code: 'not-raster' | 'malformed';
|
|
1922
|
+
readonly message: string;
|
|
1923
|
+
} | {
|
|
1924
|
+
readonly ok: false;
|
|
1925
|
+
readonly code: 'no-pixels' | 'too-large';
|
|
1926
|
+
readonly message: string;
|
|
1927
|
+
readonly width: number;
|
|
1928
|
+
readonly height: number;
|
|
1929
|
+
};
|
|
1930
|
+
/**
|
|
1931
|
+
* What an image's bytes are, from their first bytes alone, never a file's
|
|
1932
|
+
* name or a type a browser guessed: a PNG by its signature, a JPEG by its
|
|
1933
|
+
* start of image, and an SVG to be cleaned by `<` after an optional UTF-8
|
|
1934
|
+
* byte order mark and white space, or by a UTF-16 or UTF-32 byte order
|
|
1935
|
+
* mark, so that a person who saved one so is told to save it as UTF-8.
|
|
1936
|
+
* Undefined for anything else. A sniff is no check: the bytes are read
|
|
1937
|
+
* whole by `imageHeader` or by `cleanSvg` next.
|
|
1938
|
+
*/
|
|
1939
|
+
export declare function sniffImage(bytes: Uint8Array): AssetMediaType | undefined;
|
|
1940
|
+
/** A PNG's or a JPEG's header, read as the renderer reads it, or the first thing wrong with it. */
|
|
1941
|
+
export declare function imageHeader(bytes: Uint8Array): RasterHeader | ImageRefusal;
|
|
1942
|
+
//#endregion
|
|
1943
|
+
//#region src/svg-allow.d.ts
|
|
1944
|
+
/**
|
|
1945
|
+
* What an approved SVG may hold, as tables: the elements kept and the
|
|
1946
|
+
* geometry each is written with, the properties kept and the order they are
|
|
1947
|
+
* written in, and what is removed or refused instead (0030).
|
|
1948
|
+
*
|
|
1949
|
+
* Tables, not switches, so that the tests derive what they check from them:
|
|
1950
|
+
* the differential test reads every cleaned drawing back with another
|
|
1951
|
+
* parser and finds each element and attribute here, never by searching the
|
|
1952
|
+
* output for a phrase. Anything a table does not name is refused, named:
|
|
1953
|
+
* an SVG is untrusted input, and a construct this file has not decided
|
|
1954
|
+
* about fails closed (formancy.ai 0022).
|
|
1955
|
+
*
|
|
1956
|
+
* The lists are svg-to-pdfkit's subset, the converter pdfmake 0.3.11
|
|
1957
|
+
* vendors, cut down to what it draws as a browser draws it. Where the two
|
|
1958
|
+
* disagree -- text in a font pdfmake picks, a filter drawn as nothing -- the
|
|
1959
|
+
* construct is refused rather than drawn otherwise than its author saw it.
|
|
1960
|
+
* Every `source.js:N` cited in the SVG reader's files is a line of pdfmake
|
|
1961
|
+
* 0.3.11's `src/3rd-party/svg-to-pdfkit/source.js`; Node runs a transpiled
|
|
1962
|
+
* copy of it under `js/`, and the browser build bundles it.
|
|
1963
|
+
*/
|
|
1964
|
+
/** The elements a cleaned drawing is written with. */
|
|
1965
|
+
declare const KEPT_ELEMENTS: readonly ["svg", "g", "defs", "path", "rect", "circle", "ellipse", "line", "polyline", "polygon", "linearGradient", "radialGradient", "stop", "clipPath"];
|
|
1966
|
+
//#endregion
|
|
1967
|
+
//#region src/svg-refusal.d.ts
|
|
1968
|
+
/** Why an SVG is refused, each the first thing found that is wrong with it. */
|
|
1969
|
+
export declare const SVG_REFUSAL_CODES: readonly ["not-svg", "not-well-formed", "encoding", "doctype", "text", "raster", "reference", "unsupported", "out-of-range", "too-large", "too-deep"];
|
|
1970
|
+
type SvgRefusalCode = (typeof SVG_REFUSAL_CODES)[number];
|
|
1971
|
+
interface SvgRefusal {
|
|
1972
|
+
readonly ok: false;
|
|
1973
|
+
readonly code: SvgRefusalCode;
|
|
1974
|
+
/** English, for a log or a person: what was found and where, by element path (`svg/g[2]/text`), never a value, then what to do (`SVG_ADVICE`). */
|
|
1975
|
+
readonly message: string;
|
|
1976
|
+
}
|
|
1977
|
+
/** What cleaning removed: names only, never a value. */
|
|
1978
|
+
interface SvgRemoval {
|
|
1979
|
+
readonly kind: SvgRemovalKind;
|
|
1980
|
+
/** The element, attribute or property name as written (`sodipodi:namedview`, `onclick`, `-inkscape-stroke`); for a comment, a declaration or a DOCTYPE, the kind again. */
|
|
1981
|
+
readonly name: string;
|
|
1982
|
+
readonly count: number;
|
|
1983
|
+
}
|
|
1984
|
+
type SvgRemovalKind = 'element' | 'attribute' | 'property' | 'comment' | 'declaration' | 'doctype';
|
|
1985
|
+
//#endregion
|
|
1986
|
+
//#region src/svg-drawing.d.ts
|
|
1987
|
+
interface ViewBox {
|
|
1988
|
+
readonly x: number;
|
|
1989
|
+
readonly y: number;
|
|
1990
|
+
readonly width: number;
|
|
1991
|
+
readonly height: number;
|
|
1992
|
+
}
|
|
1993
|
+
//#endregion
|
|
1994
|
+
//#region src/svg-extent.d.ts
|
|
1995
|
+
interface SvgExtent {
|
|
1996
|
+
/** The page-sized groups': the largest row sum of the inverse of the linear part of a matrix one is drawn under, and the largest coordinate that inverse takes the viewBox's origin to. */
|
|
1997
|
+
readonly groups: {
|
|
1998
|
+
readonly inverse: number;
|
|
1999
|
+
readonly origin: number;
|
|
2000
|
+
};
|
|
2001
|
+
/** The gradients' painted outside every group: the largest entry of the linear part of a matrix one may be drawn under, its shape's box and its own transform included, and the largest coordinate of that matrix's translation less the viewBox's origin. */
|
|
2002
|
+
readonly patterns: {
|
|
2003
|
+
readonly linear: number;
|
|
2004
|
+
readonly offset: number;
|
|
2005
|
+
};
|
|
2006
|
+
/** The largest entry of a matrix the converter may write in a group's own coordinates: a gradient's inside a group, and the box of what a clip in objectBoundingBox units clips. */
|
|
2007
|
+
readonly local: number;
|
|
2008
|
+
/** The largest coordinate of a point the converter draws an outline with, in the outline's own coordinates, a clip path's included. */
|
|
2009
|
+
readonly own: number;
|
|
2010
|
+
/** The deepest the converter nests the graphics state in one content stream: once as it starts, once for the svg, once for every group and every shape, a group's own stream starting again. A clip path's stream nests two, its own save and its shape's (`source.js:2207-2219`), below any shape in the svg's. */
|
|
2011
|
+
readonly nesting: number;
|
|
2012
|
+
}
|
|
2013
|
+
//#endregion
|
|
2014
|
+
//#region src/svg.d.ts
|
|
2015
|
+
interface CleanSvg {
|
|
2016
|
+
readonly ok: true;
|
|
2017
|
+
/** The canonical drawing: ASCII, what the approved asset holds. */
|
|
2018
|
+
readonly bytes: Uint8Array;
|
|
2019
|
+
/** The drawing's own coordinates: what `contain` and `cover` keep the proportions of. */
|
|
2020
|
+
readonly viewBox: ViewBox;
|
|
2021
|
+
/** What it costs a reader to paint, in the weighted segments `MAX_SVG_SEGMENTS` bounds. */
|
|
2022
|
+
readonly segments: number;
|
|
2023
|
+
/** The transparency groups it makes, in the units `MAX_SVG_GROUPS` bounds. */
|
|
2024
|
+
readonly groups: number;
|
|
2025
|
+
/** What the converter draws each time it draws it -- moves, lines and closes; curves; elements read, a clip path's for every element it clips; gradient stops written, a gradient's for every shape painted with it -- for the renderer's budget across pages. */
|
|
2026
|
+
readonly drawn: {
|
|
2027
|
+
readonly lines: number;
|
|
2028
|
+
readonly curves: number;
|
|
2029
|
+
readonly elements: number;
|
|
2030
|
+
readonly stops: number;
|
|
2031
|
+
};
|
|
2032
|
+
/** How far the numbers svg-to-pdfkit writes for it reach wherever it is placed, and how deep it nests the graphics state: what the renderer holds an image of it to in an e-invoice's PDF/A-3 (`svg-extent.ts`). */
|
|
2033
|
+
readonly extent: SvgExtent;
|
|
2034
|
+
/** What cleaning removed, by kind and name with a count: names only, never a value; the first `MAX_SVG_REMOVED_NAMES` names. */
|
|
2035
|
+
readonly removed: readonly SvgRemoval[];
|
|
2036
|
+
/** Removals of names past those listed, counted. */
|
|
2037
|
+
readonly removedMore: number;
|
|
2038
|
+
}
|
|
2039
|
+
/** What `checkSvg` accepts: the drawing, which cleaning would not change. */
|
|
2040
|
+
type CheckedSvg = Omit<CleanSvg, 'removed' | 'removedMore'>;
|
|
2041
|
+
export declare function cleanSvg(bytes: Uint8Array): CleanSvg | SvgRefusal;
|
|
2042
|
+
/** The renderer's check: the drawing, when `bytes` are already what `cleanSvg` writes; refused naming the first difference otherwise. */
|
|
2043
|
+
export declare function checkSvg(bytes: Uint8Array): CheckedSvg | SvgRefusal;
|
|
2044
|
+
//#endregion
|
|
646
2045
|
//#region src/hash.d.ts
|
|
647
2046
|
/**
|
|
648
2047
|
* A 64-character lower-case hex SHA-256 of the report's canonical JSON,
|
|
@@ -717,24 +2116,5 @@ export declare function mmToPt(millimetres: number): number;
|
|
|
717
2116
|
*/
|
|
718
2117
|
export declare function ptToMm(points: number): number;
|
|
719
2118
|
//#endregion
|
|
720
|
-
|
|
721
|
-
interface PageDimensions {
|
|
722
|
-
readonly width: number;
|
|
723
|
-
readonly height: number;
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Portrait sizes in points. A4 is ISO 216's 210 x 297 mm, converted and
|
|
727
|
-
* rounded like any other length (595.28 x 841.89, the values PDF engines
|
|
728
|
-
* use); Letter is 8.5 x 11 inches, exactly 612 x 792.
|
|
729
|
-
*/
|
|
730
|
-
export declare const PAGE_SIZES: { readonly [S in PageSizeName]: PageDimensions; };
|
|
731
|
-
/** The page's width and height as oriented: landscape swaps the sides. */
|
|
732
|
-
export declare function pageDimensions(page: {
|
|
733
|
-
readonly size: PageSizeName;
|
|
734
|
-
readonly orientation: Orientation;
|
|
735
|
-
}): PageDimensions;
|
|
736
|
-
/** What the margins leave of the oriented page, to the hundredth of a point that lengths are stored at. */
|
|
737
|
-
export declare function printableArea(page: PageSettings): PageDimensions;
|
|
738
|
-
//#endregion
|
|
739
|
-
export type { AggregateDef, AggregateFunction, AggregateInline, AggregateScope, Alignment, AssetMediaType, AssetRef, Border, ColumnSlot, ColumnsComponent, Component, ComponentBase, ComponentKind, ComponentLocation, CurrencyFormat, CurrencySource, CurrencySourceKind, DatasetContract, DatasetRole, Datasets, DateFormat, DateStyle, Expression, ExpressionInline, FieldContract, FieldInline, FieldRef, FieldType, FontFamily, Format, FormatKind, ImageComponent, ImageFit, ImageSource, ImageSourceKind, Inline, InlineKind, KeepTogetherComponent, LineComponent, Margins, NumberFormat, Orientation, PageBreakComponent, PageCountInline, PageDimensions, PageNumberInline, PageSettings, PageSizeName, ParameterDef, ParameterInline, ParameterType, PrintStyle, Provenance, ProvenanceKind, RectangleComponent, RegionName, Regions, ReportDefinition, ReportError, ReportErrorCode, ReportValidation, Rounding, RoundingMode, RowValue, SectionComponent, SortDirection, SortKey, SpacerComponent, SpecVersionCheck, StyleRule, TableColumn, TableComponent, TableFooterCell, TableFooterRow, TableGroup, TextComponent, TextFormat, TextInline, TextTransform, ValueScope, Width };
|
|
2119
|
+
export { type AggregateDef, type AggregateFunction, type AggregateInline, type AggregateScope, type Alignment, type AssetMediaType, type AssetRef, type Border, type CheckedSvg, type CleanSvg, type ColumnSlot, type ColumnsComponent, type Component, type ComponentBase, type ComponentKind, type ComponentLocation, type CountryCode, type CurrencyFormat, type CurrencySource, type CurrencySourceKind, type DatasetContract, type DatasetRole, type Datasets, type DateFormat, type DateStyle, type EInvoice, type EInvoiceAddress, type EInvoiceBuyer, type EInvoiceCurrency, type EInvoiceDateRule, type EInvoiceDateTerm, type EInvoiceDecimalRule, type EInvoiceDecimalTerm, type EInvoiceKind, type EInvoiceLineCode, type EInvoiceLineColumn, type EInvoiceLineTerm, type EInvoiceLines, type EInvoiceName, type EInvoiceNeed, type EInvoiceProfile, type EInvoiceSeller, type EInvoiceTextRule, type EInvoiceTextTerm, type EInvoiceTextTerms, type En16931Rule, type EpcCaption, type EpcPairingBreak, type EpcPayloadFields, type EpcQrCodeComponent, type EpcTextField, type EpcTextFieldRule, type EpcTextRule, type Expression, type ExpressionInline, type FacturXInvoice, type FacturXProfileTerms, type FieldContract, type FieldInline, type FieldRef, type FieldType, type FontFamily, type Format, type FormatKind, type ImageComponent, type ImageFit, type ImageRefusal, type ImageRefusalCode, type ImageSource, type ImageSourceKind, type Inline, type InlineKind, type InvoiceTotal, type InvoiceTypeCode, type InvoicingPeriod, type JpegHeader, type KeepTogetherComponent, type LegalIdentifier, type LineComponent, type Margins, type NumberFormat, type Orientation, type PageBreakComponent, type PageCountInline, type PageDimensions, type PageNumberInline, type PageSettings, type PageSizeName, type ParameterDef, type ParameterInline, type ParameterType, type PaymentCheck, type PaymentInstructions, type PaymentMeansCode, type PaymentPart, type PaymentPartKind, type PngHeader, type PrintStyle, type Provenance, type ProvenanceKind, type QrBillAccount, type QrBillAddress, type QrBillCheck, type QrBillCurrency, type QrBillLanguage, type QrBillPageBreak, type QrBillPairingBreak, type QrBillReference, type QrBillReferenceType, type QrBillTextRule, type QrCodeComponent, type QrErrorCorrection, type RasterHeader, type RectangleComponent, type RegionName, type Regions, type ReportDefinition, type ReportError, type ReportErrorCode, type ReportValidation, type Rounding, type RoundingMode, type RowValue, KEPT_ELEMENTS as SVG_ELEMENTS, type SchemeId, type SectionComponent, type SortDirection, type SortKey, type SpacerComponent, type SpecVersionCheck, type StyleRule, type SvgExtent, type SvgRefusal, type SvgRefusalCode, type SvgRemoval, type SvgRemovalKind, type ViewBox as SvgViewBox, type SwissQrBill, type TableColumn, type TableComponent, type TableFooterCell, type TableFooterRow, type TableGroup, type TextComponent, type TextFormat, type TextInline, type TextTransform, type UnitCode, type ValueScope, type VatCategory, type VatCategoryBreak, type VatCategoryCode, type Width };
|
|
740
2120
|
//# sourceMappingURL=index.d.mts.map
|