@ekwo-ai/core 0.11.0 → 0.12.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.
Files changed (48) hide show
  1. package/README.md +5 -0
  2. package/dist/books/document-pdf.d.ts +87 -0
  3. package/dist/books/document-pdf.d.ts.map +1 -0
  4. package/dist/books/document-pdf.js +222 -0
  5. package/dist/books/document-pdf.js.map +1 -0
  6. package/dist/books/index.d.ts +1 -0
  7. package/dist/books/index.d.ts.map +1 -1
  8. package/dist/books/index.js +1 -0
  9. package/dist/books/index.js.map +1 -1
  10. package/dist/einvoicing/directory.d.ts +38 -0
  11. package/dist/einvoicing/directory.d.ts.map +1 -0
  12. package/dist/einvoicing/directory.js +121 -0
  13. package/dist/einvoicing/directory.js.map +1 -0
  14. package/dist/einvoicing/formats.d.ts +65 -0
  15. package/dist/einvoicing/formats.d.ts.map +1 -0
  16. package/dist/einvoicing/formats.js +380 -0
  17. package/dist/einvoicing/formats.js.map +1 -0
  18. package/dist/einvoicing/index.d.ts +11 -0
  19. package/dist/einvoicing/index.d.ts.map +1 -0
  20. package/dist/einvoicing/index.js +11 -0
  21. package/dist/einvoicing/index.js.map +1 -0
  22. package/dist/einvoicing/issue.d.ts +98 -0
  23. package/dist/einvoicing/issue.d.ts.map +1 -0
  24. package/dist/einvoicing/issue.js +398 -0
  25. package/dist/einvoicing/issue.js.map +1 -0
  26. package/dist/einvoicing/transport.d.ts +130 -0
  27. package/dist/einvoicing/transport.d.ts.map +1 -0
  28. package/dist/einvoicing/transport.js +60 -0
  29. package/dist/einvoicing/transport.js.map +1 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +2 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/proofs/filing-proofs.d.ts +93 -0
  35. package/dist/proofs/filing-proofs.d.ts.map +1 -0
  36. package/dist/proofs/filing-proofs.js +161 -0
  37. package/dist/proofs/filing-proofs.js.map +1 -0
  38. package/dist/proofs/index.d.ts +7 -0
  39. package/dist/proofs/index.d.ts.map +1 -0
  40. package/dist/proofs/index.js +7 -0
  41. package/dist/proofs/index.js.map +1 -0
  42. package/dist/proofs/opentimestamps.d.ts +185 -0
  43. package/dist/proofs/opentimestamps.d.ts.map +1 -0
  44. package/dist/proofs/opentimestamps.js +508 -0
  45. package/dist/proofs/opentimestamps.js.map +1 -0
  46. package/dist/schema.d.ts +1 -1
  47. package/dist/schema.js +1 -1
  48. package/package.json +14 -11
@@ -0,0 +1,380 @@
1
+ /**
2
+ * Which brick writes which profile, and how each is fed from the books.
3
+ *
4
+ * A country pack says which e-invoicing profile its companies issue in —
5
+ * `peppol-bis-3`, `factur-x-en16931`, `xrechnung`, a PINT — and the socle
6
+ * compiles it into `country_defaults.einvoice_profile`, which
7
+ * `document_header` publishes. A profile is a format, not a country: the
8
+ * mapping below names no country and would be the same for any pack that
9
+ * declared the same profile.
10
+ *
11
+ * **A profile without a brick is refused by name**, `format_without_brick`,
12
+ * and never written in the nearest format that exists: a file in another
13
+ * profile is a file the network or the platform refuses, after it has left.
14
+ * Adding a profile is adding an entry here and a brick under
15
+ * `packages/formats/`, nothing else.
16
+ *
17
+ * Every writer reads the same three rows the views publish and nothing else,
18
+ * plus one fact the views do not carry and the books do: which invoice a
19
+ * credit note credits (BG-3), read from `documents.reversed_document_id`.
20
+ * Nothing is defaulted on the way: a value the books do not hold is a value
21
+ * the file does not hold, and the rule that wanted it is reported.
22
+ */
23
+ import { CUSTOMIZATION_ID, PeppolUblError, generatePeppolUbl } from '@ekwo-ai/peppol-ubl';
24
+ import { computeTotals, generateCiiXml, GUIDELINES } from '@ekwo-ai/factur-x';
25
+ import { BooksError } from '../books/backend.js';
26
+ // ---------------------------------------------------------------------------
27
+ // Peppol BIS Billing 3.0 — UBL 2.1, by @ekwo-ai/peppol-ubl
28
+ //
29
+ // The brick was written for exactly this: it reads the three views as they
30
+ // are, writes the figures as posted, and names every rule the file breaks. So
31
+ // the adapter is one call, and the preceding invoice of a credit note.
32
+ // ---------------------------------------------------------------------------
33
+ const PEPPOL_BIS_3 = {
34
+ profile: 'peppol-bis-3',
35
+ brick: '@ekwo-ai/peppol-ubl',
36
+ syntax: 'UBL 2.1',
37
+ mediaType: 'application/xml',
38
+ specification: CUSTOMIZATION_ID,
39
+ write(source) {
40
+ try {
41
+ const written = generatePeppolUbl({
42
+ header: source.header,
43
+ lines: source.lines,
44
+ taxes: source.taxes,
45
+ }, source.preceding === null
46
+ ? {}
47
+ : {
48
+ precedingInvoice: source.preceding.issueDate === null
49
+ ? { number: source.preceding.number }
50
+ : { number: source.preceding.number, issueDate: source.preceding.issueDate },
51
+ });
52
+ return { content: written.file, filename: written.filename, violations: written.violations };
53
+ }
54
+ catch (error) {
55
+ if (error instanceof PeppolUblError) {
56
+ throw new BooksError(`einvoice_unwritable: ${error.message}`);
57
+ }
58
+ throw error;
59
+ }
60
+ },
61
+ };
62
+ // ---------------------------------------------------------------------------
63
+ // Factur-X, EN 16931 profile — UN/CEFACT CII D16B, by @ekwo-ai/factur-x
64
+ //
65
+ // The older brick. It takes a plain invoice object of JavaScript numbers,
66
+ // computes its own totals and fills in what it is not given: a currency, a
67
+ // unit, a payment means, a delivery date, the sentence of an exemption.
68
+ // Decision 0050 names it as the brick to move to the contract of the views;
69
+ // until it is, this adapter holds it to the books from the outside:
70
+ //
71
+ // * everything it would default is given from the books, or not given and
72
+ // reported — never left for it to invent;
73
+ // * what it computes is compared with what was posted, total by total and
74
+ // group by group, and a difference is a broken rule. A file that disagrees
75
+ // with the ledger by a cent is worse than a file that is refused.
76
+ //
77
+ // The file kept is the CII XML. The PDF/A-3 that carries it is rendered on
78
+ // demand by `renderDocumentPdf()` (books/document-pdf.ts), which hands this
79
+ // writer's XML and the visual invoice to the brick's `/pdf` entry.
80
+ // ---------------------------------------------------------------------------
81
+ /** A decimal as text without the zeros that say nothing: `100.50`, `100.5` and `100.500` are one amount. */
82
+ function canonical(value) {
83
+ if (value === null || value === undefined || value === '')
84
+ return null;
85
+ const text = String(value).trim();
86
+ if (!/^-?\d+(\.\d+)?$/.test(text))
87
+ return text;
88
+ const negative = text.startsWith('-');
89
+ const [whole = '0', fraction = ''] = (negative ? text.slice(1) : text).split('.');
90
+ const digits = whole.replace(/^0+(?=\d)/, '');
91
+ const decimals = fraction.replace(/0+$/, '');
92
+ const body = decimals === '' ? digits : `${digits}.${decimals}`;
93
+ return negative && body !== '0' ? `-${body}` : body;
94
+ }
95
+ /** The brick's figure, as the two decimals it writes, in the same canonical form. */
96
+ const written = (value) => canonical(value.toFixed(2));
97
+ const text = (value) => {
98
+ if (value === null || value === undefined)
99
+ return null;
100
+ const out = String(value).trim();
101
+ return out === '' ? null : out;
102
+ };
103
+ /** The rule an exempting category breaks when nothing says why (BR-E-10, BR-AE-10, BR-IC-10, BR-G-10, BR-O-10). */
104
+ const REASON_RULE = { E: 'E', AE: 'AE', K: 'IC', G: 'G', O: 'O' };
105
+ const CATEGORIES = new Set(['S', 'Z', 'E', 'AE', 'K', 'G', 'O']);
106
+ function partyOf(header, side, violations) {
107
+ const name = text(header[`${side}_legal_name`]) ?? text(header[`${side}_name`]);
108
+ const country = text(header[`${side}_country`]);
109
+ if (name === null) {
110
+ violations.push({ code: side === 'seller' ? 'BR-06' : 'BR-07', message: `The ${side} has no name in the books.` });
111
+ }
112
+ if (country === null) {
113
+ violations.push({
114
+ code: side === 'seller' ? 'BR-09' : 'BR-11',
115
+ message: `The postal address of the ${side} has no country in the books.`,
116
+ });
117
+ }
118
+ const party = {
119
+ name: name ?? '',
120
+ address: {
121
+ line1: text(header[`${side}_address_line1`]) ?? '',
122
+ postalCode: text(header[`${side}_postal_code`]) ?? '',
123
+ city: text(header[`${side}_city`]) ?? '',
124
+ country: country ?? '',
125
+ },
126
+ };
127
+ const line2 = text(header[`${side}_address_line2`]);
128
+ if (line2 !== null)
129
+ party.address.line2 = line2;
130
+ const region = text(header[`${side}_region`]);
131
+ if (region !== null)
132
+ party.address.subdivision = region;
133
+ const vat = text(header[`${side}_vat_number`]);
134
+ if (vat !== null)
135
+ party.vatId = vat;
136
+ const scheme = text(header[`${side}_peppol_scheme`]);
137
+ const identifier = text(header[`${side}_peppol_identifier`]);
138
+ if (scheme !== null && identifier !== null)
139
+ party.electronicAddress = { scheme, value: identifier };
140
+ return party;
141
+ }
142
+ /** The net price of a line, exactly, as the brick's number: the price as keyed less its discount. */
143
+ function netPrice(line) {
144
+ const price = Number(line['unit_price'] ?? 0);
145
+ const discount = Number(line['discount_percent'] ?? 0);
146
+ return discount === 0 ? price : (price * (100 - discount)) / 100;
147
+ }
148
+ function writeFacturX(source) {
149
+ const { header } = source;
150
+ const violations = [];
151
+ const number = text(header['number']);
152
+ const issueDate = text(header['document_date']);
153
+ const currency = text(header['currency_code']);
154
+ const docType = text(header['doc_type']);
155
+ if (docType !== 'sale_invoice' && docType !== 'sale_credit_note') {
156
+ throw new BooksError(`einvoice_unwritable: a ${docType ?? 'document'} is not a sale invoice or a sale credit note`);
157
+ }
158
+ if (number === null)
159
+ throw new BooksError('einvoice_unwritable: a document without a number was never issued');
160
+ if (issueDate === null)
161
+ throw new BooksError('einvoice_unwritable: the document has no date');
162
+ if (currency === null)
163
+ throw new BooksError('einvoice_unwritable: the document has no currency');
164
+ const seller = partyOf(header, 'seller', violations);
165
+ const buyer = partyOf(header, 'buyer', violations);
166
+ if (seller.vatId === undefined && text(header['seller_registration_number']) === null) {
167
+ violations.push({
168
+ code: 'BR-CO-26',
169
+ message: 'The seller has neither a VAT number nor a registration number in the books.',
170
+ });
171
+ }
172
+ // The day the supply happened. The books state it, or derive it when the
173
+ // document is posted (the tax point); the brick would write the date of the
174
+ // invoice instead, which is a fact nobody stated.
175
+ const delivery = text(header['delivery_date']) ?? text(header['tax_point_date']);
176
+ if (delivery === null) {
177
+ violations.push({
178
+ code: 'delivery-date-missing',
179
+ message: 'The books state no date of delivery and no tax point for this document, and Factur-X writes one on every invoice (BT-72): the brick would put the date of the invoice there.',
180
+ });
181
+ }
182
+ // The sentence of each exempting group, from the breakdown and nowhere else.
183
+ const reasons = {};
184
+ for (const tax of source.taxes) {
185
+ const category = text(tax['vat_category']);
186
+ const reason = text(tax['exemption_reason']);
187
+ if (category === null || REASON_RULE[category] === undefined)
188
+ continue;
189
+ if (reason !== null)
190
+ reasons[category] = reason;
191
+ else {
192
+ violations.push({
193
+ code: `BR-${REASON_RULE[category]}-10`,
194
+ message: `The VAT group ${category} charges nothing and the books carry no sentence saying why; the brick would write one of its own.`,
195
+ });
196
+ }
197
+ }
198
+ const lines = [];
199
+ for (const row of source.lines) {
200
+ if (text(row['line_type']) !== null && text(row['line_type']) !== 'product')
201
+ continue;
202
+ const id = String(row['sequence'] ?? lines.length + 1);
203
+ const category = text(row['vat_category']);
204
+ if (category === null || !CATEGORIES.has(category)) {
205
+ violations.push({
206
+ code: 'BR-CO-04',
207
+ message: category === null ? 'The line carries no VAT category.' : `${category} is not a VAT category of EN 16931.`,
208
+ line: id,
209
+ });
210
+ }
211
+ if (row['unit_price_includes_tax'] === true) {
212
+ violations.push({
213
+ code: 'BR-26',
214
+ message: 'The price of this line was keyed with its tax in it, and the books publish no net price for it (BT-146): working one out is a rounding the books have not made.',
215
+ line: id,
216
+ });
217
+ }
218
+ const line = {
219
+ id,
220
+ name: text(row['item_name']) ?? '',
221
+ quantity: Number(row['quantity'] ?? 0),
222
+ unitPrice: row['unit_price_includes_tax'] === true ? 0 : netPrice(row),
223
+ vatRate: Number(row['vat_rate'] ?? 0),
224
+ netAmount: Number(row['amount_untaxed'] ?? 0),
225
+ };
226
+ if (category !== null && CATEGORIES.has(category))
227
+ line.vatCategory = category;
228
+ const unit = text(row['unit_code']);
229
+ if (unit !== null)
230
+ line.unitCode = unit;
231
+ const description = text(row['item_description']);
232
+ if (description !== null)
233
+ line.description = description;
234
+ const sellerItem = text(row['seller_item_identifier']);
235
+ if (sellerItem !== null)
236
+ line.sellerItemId = sellerItem;
237
+ lines.push(line);
238
+ }
239
+ if (lines.length === 0)
240
+ throw new BooksError('einvoice_unwritable: the document has no line to invoice');
241
+ const invoice = {
242
+ number,
243
+ type: docType === 'sale_credit_note' ? 'credit-note' : 'invoice',
244
+ issueDate,
245
+ currency,
246
+ seller,
247
+ buyer,
248
+ lines,
249
+ exemptionReasons: reasons,
250
+ };
251
+ if (delivery !== null)
252
+ invoice.deliveryDate = delivery;
253
+ const due = text(header['due_date']);
254
+ if (due !== null)
255
+ invoice.dueDate = due;
256
+ for (const [field, column] of [
257
+ ['buyerReference', 'buyer_reference'],
258
+ ['orderReference', 'order_reference'],
259
+ ['contractReference', 'contract_reference'],
260
+ ['note', 'note'],
261
+ ]) {
262
+ const value = text(header[column]);
263
+ if (value !== null)
264
+ invoice[field] = value;
265
+ }
266
+ if (source.preceding !== null) {
267
+ invoice.precedingInvoice =
268
+ source.preceding.issueDate === null
269
+ ? { number: source.preceding.number }
270
+ : { number: source.preceding.number, issueDate: source.preceding.issueDate };
271
+ }
272
+ // Payment: a means is a code the books hold or nothing. An account without
273
+ // a code is not written, because the brick would call it a transfer.
274
+ const means = text(header['payment_means_code']);
275
+ const iban = text(header['payee_iban']);
276
+ const terms = text(header['payment_terms']);
277
+ const reference = text(header['payment_reference']);
278
+ if (iban !== null && means === null) {
279
+ violations.push({
280
+ code: 'payment-means-missing',
281
+ message: 'The books hold an account to pay into and no payment means code (BT-81): the account is not written.',
282
+ });
283
+ }
284
+ if (means !== null || terms !== null || reference !== null) {
285
+ invoice.payment = {};
286
+ if (means !== null) {
287
+ invoice.payment.meansCode = means;
288
+ if (iban !== null)
289
+ invoice.payment.iban = iban;
290
+ const bic = text(header['payee_bic']);
291
+ if (bic !== null)
292
+ invoice.payment.bic = bic;
293
+ }
294
+ if (terms !== null)
295
+ invoice.payment.terms = terms;
296
+ if (reference !== null)
297
+ invoice.payment.reference = reference;
298
+ }
299
+ const paid = canonical(header['amount_paid']);
300
+ if (paid !== null && paid !== '0')
301
+ invoice.prepaidAmount = Number(paid);
302
+ const residual = canonical(header['amount_residual']);
303
+ if (docType === 'sale_invoice' && due === null && terms === null && residual !== null && residual !== '0') {
304
+ violations.push({
305
+ code: 'BR-CO-25',
306
+ message: 'An amount is due and the books state neither a due date nor payment terms.',
307
+ });
308
+ }
309
+ // The brick's arithmetic against the ledger's, figure by figure.
310
+ const totals = computeTotals(invoice);
311
+ for (const [what, books, brick] of [
312
+ ['total without VAT (BT-109)', header['amount_untaxed'], totals.taxBasisTotal],
313
+ ['total VAT (BT-110)', header['amount_tax'], totals.taxTotal],
314
+ ['total with VAT (BT-112)', header['amount_total'], totals.grandTotal],
315
+ ['amount due (BT-115)', header['amount_residual'], totals.duePayable],
316
+ ]) {
317
+ if (canonical(books) !== null && canonical(books) !== written(brick)) {
318
+ violations.push({
319
+ code: 'totals-disagree',
320
+ message: `The ${what} the file would carry, ${brick.toFixed(2)}, is not the ${String(books)} the books posted.`,
321
+ });
322
+ }
323
+ }
324
+ const posted = new Map();
325
+ for (const tax of source.taxes) {
326
+ const category = text(tax['vat_category']) ?? '';
327
+ const rate = category === 'S' ? canonical(tax['tax_rate']) ?? '0' : '0';
328
+ const key = `${category}|${rate}`;
329
+ const group = posted.get(key) ?? { base: 0, tax: 0 };
330
+ group.base += Number(tax['base_amount'] ?? 0);
331
+ group.tax += Number(tax['tax_charged'] ?? 0);
332
+ posted.set(key, group);
333
+ }
334
+ for (const group of totals.breakdown) {
335
+ const key = `${group.category}|${canonical(group.rate) ?? '0'}`;
336
+ const books = posted.get(key);
337
+ if (books === undefined || written(books.base) !== written(group.basis) || written(books.tax) !== written(group.tax)) {
338
+ violations.push({
339
+ code: 'breakdown-disagree',
340
+ message: `The VAT group ${group.category} at ${group.rate} % would carry ${group.basis.toFixed(2)} and ${group.tax.toFixed(2)} of VAT, which is not what the books posted for it${books === undefined ? ' — they posted no such group' : `: ${books.base.toFixed(2)} and ${books.tax.toFixed(2)}`}.`,
341
+ });
342
+ }
343
+ }
344
+ const safe = number.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');
345
+ return {
346
+ content: generateCiiXml(invoice, { profile: 'en16931' }),
347
+ filename: `${docType === 'sale_credit_note' ? 'credit-note' : 'invoice'}-${safe === '' ? 'document' : safe}.cii.xml`,
348
+ violations,
349
+ };
350
+ }
351
+ const FACTUR_X_EN16931 = {
352
+ profile: 'factur-x-en16931',
353
+ brick: '@ekwo-ai/factur-x',
354
+ syntax: 'UN/CEFACT CII D16B',
355
+ mediaType: 'application/xml',
356
+ specification: GUIDELINES.en16931,
357
+ write: writeFacturX,
358
+ };
359
+ /** Every profile a brick of this release writes, by the name a pack declares it under. */
360
+ export const EINVOICE_FORMATS = {
361
+ [PEPPOL_BIS_3.profile]: PEPPOL_BIS_3,
362
+ [FACTUR_X_EN16931.profile]: FACTUR_X_EN16931,
363
+ };
364
+ /**
365
+ * The format of a profile, or the refusal that names what is missing: no
366
+ * profile in the pack (`no_einvoicing_profile`), or a profile no brick of this
367
+ * release writes (`format_without_brick`).
368
+ */
369
+ export function einvoiceFormat(profile) {
370
+ if (profile === null || profile === undefined || profile.trim() === '') {
371
+ throw new BooksError('no_einvoicing_profile: the country pack of this company declares no e-invoicing profile, so there is no format to issue in.', { hint: 'A pack says which profile its companies issue in, in its einvoicing section; describe_pack (ekwo pack describe) shows it.' });
372
+ }
373
+ const format = EINVOICE_FORMATS[profile];
374
+ if (format === undefined) {
375
+ throw new BooksError(`format_without_brick: the country pack of this company issues in ${profile}, and no brick of packages/formats/ writes ${profile} yet. ` +
376
+ `This release writes ${Object.keys(EINVOICE_FORMATS).join(' and ')}; a file in one of those is not a ${profile} file, and none is written in its place.`);
377
+ }
378
+ return format;
379
+ }
380
+ //# sourceMappingURL=formats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.js","sourceRoot":"","sources":["../../src/einvoicing/formats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,iBAAiB,EAAE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BAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAkC;IAC/D,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACvE,MAAM,IAAI,UAAU,CAClB,6HAA6H,EAC7H,EAAE,IAAI,EAAE,2HAA2H,EAAE,CACtI,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,UAAU,CAClB,oEAAoE,OAAO,8CAA8C,OAAO,QAAQ;YACtI,uBAAuB,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,qCAAqC,OAAO,0CAA0C,CAC3J,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Electronic invoicing: the file of a posted sale, kept, and sent through a
3
+ * transport the caller brings. The schema is the `einvoicing` module's; the
4
+ * formats are the bricks of `packages/formats/`; the transports are the
5
+ * contract in `transport.ts`, and one of them — a folder — ships.
6
+ */
7
+ export * from './transport.js';
8
+ export * from './directory.js';
9
+ export * from './formats.js';
10
+ export * from './issue.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/einvoicing/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Electronic invoicing: the file of a posted sale, kept, and sent through a
3
+ * transport the caller brings. The schema is the `einvoicing` module's; the
4
+ * formats are the bricks of `packages/formats/`; the transports are the
5
+ * contract in `transport.ts`, and one of them — a folder — ships.
6
+ */
7
+ export * from './transport.js';
8
+ export * from './directory.js';
9
+ export * from './formats.js';
10
+ export * from './issue.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/einvoicing/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Issuing the electronic invoice of a posted sale, for every surface at once.
3
+ *
4
+ * The MCP server and the command line call these four functions with their
5
+ * own `Backend`, which acts as the person signed in:
6
+ *
7
+ * - `validateEinvoice()` writes the file and says what is wrong with it,
8
+ * and records nothing. A question, asked as often as one likes.
9
+ * - `issueEinvoice()` writes it and keeps it — the exact text, its
10
+ * checksum, the rules it breaks — through `einvoicing.record_issue()`;
11
+ * and, given a transport and asked to, sends it: a transmission recorded
12
+ * as prepared, the file handed over, and what the transport answered
13
+ * recorded beside it, in its own words.
14
+ * - `einvoiceStatus()` is what is known of a document: its files, its
15
+ * sendings and every answer; given the transport that sent it, it asks
16
+ * that transport again and records what it says.
17
+ * - `listEinvoiceTransmissions()` is every sending of a company, or of one
18
+ * document.
19
+ *
20
+ * The rules that matter are the database's: a document that is not a posted
21
+ * sale, a profile that is not the pack's, a file that breaks a rule, a second
22
+ * sending of a document already on its way, a state that would move backwards
23
+ * — each is refused there, by name, for this code and for any other client.
24
+ * What is here is what only a program can do: run the brick, compute a
25
+ * checksum, call a transport.
26
+ */
27
+ import { type Backend, type Row } from '../books/backend.js';
28
+ import { type EinvoiceSource, type EinvoiceViolation } from './formats.js';
29
+ import { type EinvoiceTransport, type ElectronicAddress, type TransmissionState } from './transport.js';
30
+ /** SHA-256 of a file as UTF-8, in lower-case hexadecimal: what the database computes again. */
31
+ export declare function einvoiceChecksum(content: string): string;
32
+ /** A file written from the books, before anything was recorded. */
33
+ export interface ProducedEinvoice {
34
+ document_id: string;
35
+ company_id: string;
36
+ doc_type: string;
37
+ number: string | null;
38
+ profile: string;
39
+ brick: string;
40
+ syntax: string;
41
+ specification: string;
42
+ filename: string;
43
+ media_type: string;
44
+ checksum: string;
45
+ byte_size: number;
46
+ violations: EinvoiceViolation[];
47
+ sendable: boolean;
48
+ content: string;
49
+ sender: ElectronicAddress | null;
50
+ recipient: ElectronicAddress | null;
51
+ }
52
+ /** The three views of one document, and the invoice it credits where it is a credit note. */
53
+ export declare function readEinvoiceSource(backend: Backend, documentId: string): Promise<EinvoiceSource>;
54
+ /**
55
+ * Writes the file of a posted sale, in the profile of its company's country
56
+ * pack, and says which rules it breaks. Records nothing.
57
+ */
58
+ export declare function produceEinvoice(backend: Backend, documentId: string): Promise<ProducedEinvoice>;
59
+ export interface ValidateEinvoiceArgs {
60
+ document_id: string;
61
+ /** Hand the file back too. Left out, the answer is what is wrong with it. */
62
+ include_file?: boolean;
63
+ }
64
+ /** The file a posted sale would be issued as, and every rule it breaks. Nothing is recorded. */
65
+ export declare function validateEinvoice(backend: Backend, args: ValidateEinvoiceArgs): Promise<Row>;
66
+ export interface IssueEinvoiceArgs {
67
+ document_id: string;
68
+ /** Send it as well, through `transport`. Left out, the file is kept and nothing leaves. */
69
+ send?: boolean;
70
+ /** Hand the file back too. */
71
+ include_file?: boolean;
72
+ }
73
+ /**
74
+ * Writes the file of a posted sale and keeps it; sends it too when asked and
75
+ * given a transport. The same file twice is one issue, and a document already
76
+ * on its way is refused by the database rather than sent twice.
77
+ */
78
+ export declare function issueEinvoice(backend: Backend, args: IssueEinvoiceArgs, transport?: EinvoiceTransport): Promise<Row>;
79
+ export interface EinvoiceStatusArgs {
80
+ document_id: string;
81
+ /** Ask the transport again about the sending that is still open, and record what it says. */
82
+ refresh?: boolean;
83
+ }
84
+ /**
85
+ * Everything known of the electronic invoice of one document: its files,
86
+ * every sending and every answer. Asked to refresh and given the transport the
87
+ * open sending went through, asks it again and records the answer.
88
+ */
89
+ export declare function einvoiceStatus(backend: Backend, args: EinvoiceStatusArgs, transport?: EinvoiceTransport): Promise<Row>;
90
+ export interface ListEinvoiceTransmissionsArgs {
91
+ company_id: string;
92
+ document_id?: string;
93
+ state?: TransmissionState;
94
+ limit?: number;
95
+ }
96
+ /** Every sending of a company, or of one of its documents, the latest first, with the file each one sent. */
97
+ export declare function listEinvoiceTransmissions(backend: Backend, args: ListEinvoiceTransmissionsArgs): Promise<Row>;
98
+ //# sourceMappingURL=issue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.d.ts","sourceRoot":"","sources":["../../src/einvoicing/issue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAc,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAkB,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3F,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAC;AAkDxB,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,mEAAmE;AACnE,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB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