@ekwo-ai/core 0.11.1 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +5 -0
  2. package/dist/books/columns.d.ts.map +1 -1
  3. package/dist/books/columns.js +2 -0
  4. package/dist/books/columns.js.map +1 -1
  5. package/dist/books/document-pdf.d.ts +93 -0
  6. package/dist/books/document-pdf.d.ts.map +1 -0
  7. package/dist/books/document-pdf.js +241 -0
  8. package/dist/books/document-pdf.js.map +1 -0
  9. package/dist/books/index.d.ts +1 -0
  10. package/dist/books/index.d.ts.map +1 -1
  11. package/dist/books/index.js +1 -0
  12. package/dist/books/index.js.map +1 -1
  13. package/dist/einvoicing/directory.d.ts +38 -0
  14. package/dist/einvoicing/directory.d.ts.map +1 -0
  15. package/dist/einvoicing/directory.js +121 -0
  16. package/dist/einvoicing/directory.js.map +1 -0
  17. package/dist/einvoicing/formats.d.ts +65 -0
  18. package/dist/einvoicing/formats.d.ts.map +1 -0
  19. package/dist/einvoicing/formats.js +380 -0
  20. package/dist/einvoicing/formats.js.map +1 -0
  21. package/dist/einvoicing/index.d.ts +11 -0
  22. package/dist/einvoicing/index.d.ts.map +1 -0
  23. package/dist/einvoicing/index.js +11 -0
  24. package/dist/einvoicing/index.js.map +1 -0
  25. package/dist/einvoicing/issue.d.ts +98 -0
  26. package/dist/einvoicing/issue.d.ts.map +1 -0
  27. package/dist/einvoicing/issue.js +398 -0
  28. package/dist/einvoicing/issue.js.map +1 -0
  29. package/dist/einvoicing/transport.d.ts +130 -0
  30. package/dist/einvoicing/transport.d.ts.map +1 -0
  31. package/dist/einvoicing/transport.js +60 -0
  32. package/dist/einvoicing/transport.js.map +1 -0
  33. package/dist/index.d.ts +2 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/proofs/filing-proofs.d.ts +93 -0
  38. package/dist/proofs/filing-proofs.d.ts.map +1 -0
  39. package/dist/proofs/filing-proofs.js +161 -0
  40. package/dist/proofs/filing-proofs.js.map +1 -0
  41. package/dist/proofs/index.d.ts +7 -0
  42. package/dist/proofs/index.d.ts.map +1 -0
  43. package/dist/proofs/index.js +7 -0
  44. package/dist/proofs/index.js.map +1 -0
  45. package/dist/proofs/opentimestamps.d.ts +185 -0
  46. package/dist/proofs/opentimestamps.d.ts.map +1 -0
  47. package/dist/proofs/opentimestamps.js +508 -0
  48. package/dist/proofs/opentimestamps.js.map +1 -0
  49. package/dist/schema.d.ts +1 -1
  50. package/dist/schema.js +1 -1
  51. package/package.json +14 -11
package/README.md CHANGED
@@ -12,6 +12,9 @@ TypeScript row types and a typed client for the
12
12
  - **A thin client** over the functions that carry the accounting rules —
13
13
  `post_document`, `reconcile`, `trial_balance`, `vat_return`, `fec_lines`.
14
14
  Everything else is a table, and Supabase already exposes those as REST.
15
+ - **The functions the command line and the MCP server share** — keeping the
16
+ books, issuing an electronic invoice, proving a filing by its hash — so a
17
+ rule exists once.
15
18
  - **No runtime dependency of its own.** `@supabase/supabase-js` is an optional
16
19
  peer; `@ekwo-ai/fec` is there because `generateFec()` on the client writes
17
20
  the file it has just fetched.
@@ -64,6 +67,8 @@ const file = generateFec(lines, { decimalSeparator: ',', fieldSeparator: '|' });
64
67
  | `isRegistered(instance)` | Whether the operator opted into registering with Ekwo. |
65
68
  | `isSale`, `isCreditNote`, `isAccountable` | Document type predicates. |
66
69
  | `createContact`, `createDocument`, `addDocumentLine`, `updateDocumentLines`, `postDocument`, `recordPayment`, `reconcile`, `settleFromStatement`, `listDocuments`, `getDocument`, … | Keeping the books, once for every surface: the functions the MCP server and the `ekwo` command line both call. Each takes a `Backend` — five operations, `select` `insert` `update` `remove` `rpc` — that the caller implements over whatever reaches the database as a user. No accounting rule is in them; the schema holds those. |
70
+ | `validateEinvoice`, `issueEinvoice`, `einvoiceStatus`, `listEinvoiceTransmissions`, `EinvoiceTransport`, `directoryTransport` | The electronic invoice of a posted sale, through the `einvoicing` module, and the contract a transport implements — `send`, `status`, `receive`, `lookup`, with no credential crossing it. The one transport that ships writes files to a folder. |
71
+ | `proveFile`, `upgradeFilingProofs`, `lookupFilingProof`, `checkProof` | The sha256 of a filed file committed to Bitcoin through the public OpenTimestamps calendars, and checked later by anybody holding the file ([`docs/filing-proofs.md`](../../docs/filing-proofs.md)). |
67
72
  | `BooksError`, `isRefusalState`, `socleCode`, `isServiceRoleKey` | What an error of that layer looks like, what counts as the database refusing, and the one key no surface accepts. |
68
73
  | Types | `Instance`, `InstanceAdmin`, `MemberRole`, `CompanyRole`, `Account`, `Journal`, `Entry`, `EntryLine`, `EkwoDocument`, `DocumentLine`, `Tax`, `TaxPosting`, `Contact`, `TrialBalanceRow`, `AgedBalanceRow`, `VatReturnRow`, … |
69
74
 
@@ -1 +1 @@
1
- {"version":3,"file":"columns.d.ts","sourceRoot":"","sources":["../../src/books/columns.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,OAAO,UAqCnB,CAAC;AAEF,eAAO,MAAM,WAAW,UAAoE,CAAC;AAE7F,eAAO,MAAM,OAAO,UAUnB,CAAC;AAEF,eAAO,MAAM,OAAO,UAAmD,CAAC;AAExE,eAAO,MAAM,OAAO,UAcnB,CAAC;AAEF,eAAO,MAAM,GAAG,UAsBf,CAAC;AAEF,eAAO,MAAM,QAAQ,UA2BpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,UAQlC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,UAWlC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,UAoE3B,CAAC;AAEF,eAAO,MAAM,OAAO,UAgBnB,CAAC;AAEF,eAAO,MAAM,aAAa,UAmBzB,CAAC;AAEF,eAAO,MAAM,KAAK,UAejB,CAAC;AAEF,eAAO,MAAM,UAAU,UAsBtB,CAAC;AAEF,eAAO,MAAM,YAAY,UAYxB,CA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,OAAO,UAgBnB,CAAC;AAEF;;;;GAIG;AACH,gFAAgF;AAChF,eAAO,MAAM,gBAAgB,UAS5B,CAAC;AAEF,eAAO,MAAM,UAAU,UAYtB,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,OAAO,UAWnB,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,cAAc,UAW1B,CAAC;AAEF,eAAO,MAAM,QAAQ,UAQpB,CAAC;AAEF,eAAO,MAAM,cAAc,UAa1B,CAAC;AAEF,eAAO,MAAM,SAAS,UAarB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,UAYxB,CAAC"}
@@ -32,6 +32,8 @@ export const COMPANY = [
32
32
  'activity_code',
33
33
  'activity_scheme',
34
34
  'document_template',
35
+ 'invoice_accent_color',
36
+ 'invoice_logo_position',
35
37
  'default_bank_account_id',
36
38
  'language',
37
39
  'currency_code',
@@ -1 +1 @@
1
- {"version":3,"file":"columns.js","sourceRoot":"","sources":["../../src/books/columns.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI;IACJ,MAAM;IACN,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,qBAAqB;IACrB,eAAe;IACf,eAAe;IACf,aAAa;IACb,MAAM;IACN,SAAS;IACT,QAAQ;IACR,OAAO;IACP,OAAO;IACP,SAAS;IACT,UAAU;IACV,qBAAqB;IACrB,wBAAwB;IACxB,eAAe;IACf,iBAAiB;IACjB,mBAAmB;IACnB,yBAAyB;IACzB,UAAU;IACV,eAAe;IACf,iBAAiB;IACjB,qBAAqB;IACrB,uBAAuB;IACvB,oBAAoB;IACpB,qBAAqB;IACrB,8BAA8B;IAC9B,kBAAkB;IAClB,qBAAqB;IACrB,0BAA0B;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,k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;IAClB,YAAY;IACZ,sBAAsB;CACvB,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,aAAa;IACb,mBAAmB;IACnB,SAAS;IACT,SAAS;IACT,gBAAgB;IAChB,oBAAoB;IACpB,qBAAqB;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI;IACJ,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,yEAAyE;IACzE,4EAA4E;IAC5E,qEAAqE;IACrE,iCAAiC;IACjC,aAAa;IACb,uBAAuB;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,mBAAmB;IACnB,UAAU;IACV,UAAU;IACV,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,WAAW;IACX,QAAQ;IACR,YAAY;IACZ,YAAY;CACb,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,SAAS;IACT,MAAM;IACN,SAAS;IACT,mBAAmB;IACnB,YAAY;IACZ,sBAAsB;IACtB,cAAc;IACd,oBAAoB;IACpB,UAAU;IACV,SAAS;IACT,oBAAoB;CACrB,CAAC"}
1
+ {"version":3,"file":"columns.js","sourceRoot":"","sources":["../../src/books/columns.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI;IACJ,MAAM;IACN,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,qBAAqB;IACrB,eAAe;IACf,eAAe;IACf,aAAa;IACb,MAAM;IACN,SAAS;IACT,QAAQ;IACR,OAAO;IACP,OAAO;IACP,SAAS;IACT,UAAU;IACV,qBAAqB;IACrB,wBAAwB;IACxB,eAAe;IACf,iBAAiB;IACjB,mBAAmB;IACnB,sBAAsB;IACtB,uBAAuB;IACvB,yBAA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Ac;IACd,YAAY;IACZ,kBAAkB;IAClB,kBAAkB;IAClB,oBAAoB;IACpB,kBAAkB;CACnB,CAAC;AAEF,+EAA+E;AAC/E,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI;IACJ,YAAY;IACZ,aAAa;IACb,cAAc;IACd,YAAY;IACZ,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,YAAY;IACZ,sBAAsB;CACvB,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,aAAa;IACb,mBAAmB;IACnB,SAAS;IACT,SAAS;IACT,gBAAgB;IAChB,oBAAoB;IACpB,qBAAqB;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI;IACJ,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,yEAAyE;IACzE,4EAA4E;IAC5E,qEAAqE;IACrE,iCAAiC;IACjC,aAAa;IACb,uBAAuB;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,mBAAmB;IACnB,UAAU;IACV,UAAU;IACV,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,WAAW;IACX,QAAQ;IACR,YAAY;IACZ,YAAY;CACb,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,SAAS;IACT,MAAM;IACN,SAAS;IACT,mBAAmB;IACnB,YAAY;IACZ,sBAAsB;IACtB,cAAc;IACd,oBAAoB;IACpB,UAAU;IACV,SAAS;IACT,oBAAoB;CACrB,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The PDF of a sale invoice or credit note, for every surface at once.
3
+ *
4
+ * The command line (`ekwo doc pdf`) and the MCP server (`render_invoice_pdf`)
5
+ * call this with their own `Backend`, acting as the person signed in. It reads
6
+ * the four views a document is printed from — `document_header`,
7
+ * `document_line_items`, `document_tax_summary`, `document_legal_mentions` —
8
+ * and hands the rows to `@ekwo-ai/invoice-pdf`, which renders them and knows
9
+ * nothing of a database. Here is what only a client can do: read the views,
10
+ * fetch the logo the company names by URL, apply the accent colour and the
11
+ * side of the logo the company chose, and, when asked, write the CII of
12
+ * the same document with the Factur-X adapter of the e-invoicing formats and
13
+ * embed it, so that the PDF is a Factur-X invoice.
14
+ *
15
+ * Nothing is recorded. A posted document reproduces from the books; the copy
16
+ * that was sent to a customer is another thing, and keeping it is not done
17
+ * here.
18
+ */
19
+ import { type InvoiceLabels, type InvoicePdfInput, type InvoiceTheme, type PageSize } from '@ekwo-ai/invoice-pdf';
20
+ import { type EinvoiceViolation } from '../einvoicing/formats.js';
21
+ import { type Backend } from './backend.js';
22
+ /** The four views of one document. */
23
+ export declare function readDocumentForPdf(backend: Backend, documentId: string): Promise<Omit<InvoicePdfInput, 'logo'>>;
24
+ /**
25
+ * The accent colour and the side of the logo the company chose, as the
26
+ * brick's theme; a column left null keeps the brick's default.
27
+ */
28
+ export declare function readInvoiceTheme(backend: Backend, companyId: string): Promise<InvoiceTheme>;
29
+ /** What a logo fetch may be handed: the global `fetch`, or a test's. */
30
+ export type LogoFetch = (url: string, init: {
31
+ signal: AbortSignal;
32
+ redirect: 'follow' | 'error';
33
+ }) => Promise<{
34
+ ok: boolean;
35
+ status: number;
36
+ arrayBuffer(): Promise<ArrayBuffer>;
37
+ }>;
38
+ /**
39
+ * Why a logo URL is not fetched, or null when it may be. Only `http` and
40
+ * `https`, and never a host that names this machine or a private network: the
41
+ * URL is a value a member of the company typed, and the server that fetches it
42
+ * may be somebody else's.
43
+ */
44
+ export declare function logoUrlRefusal(url: string): string | null;
45
+ /**
46
+ * The bytes of the logo at `url`, or why there are none. A logo that cannot be
47
+ * had is not a reason to refuse an invoice: the PDF is rendered with the
48
+ * company's name instead, and the reason is said.
49
+ */
50
+ export declare function fetchLogo(url: string, fetchImpl: LogoFetch): Promise<{
51
+ bytes: Uint8Array;
52
+ } | {
53
+ skipped: string;
54
+ }>;
55
+ export interface DocumentPdfArgs {
56
+ document_id: string;
57
+ /** Embed the CII of the document (Factur-X, EN 16931 profile): the PDF becomes a PDF/A-3 Factur-X invoice. */
58
+ factur_x?: boolean | undefined;
59
+ page_size?: PageSize | undefined;
60
+ /** The words of the layout in the document's language; what is left out is English. */
61
+ labels?: Partial<InvoiceLabels> | undefined;
62
+ }
63
+ export interface DocumentPdf {
64
+ document_id: string;
65
+ doc_type: string;
66
+ number: string | null;
67
+ state: string | null;
68
+ language: string | null;
69
+ filename: string;
70
+ title: string;
71
+ media_type: 'application/pdf';
72
+ byte_size: number;
73
+ page_count: number;
74
+ /** `embedded`, `none` (the company names no logo), or why the one it names was not used. */
75
+ logo: string;
76
+ /** Null without --factur-x; otherwise the rules of EN 16931 the embedded XML breaks, as the e-invoicing adapter names them. */
77
+ factur_x: {
78
+ profile: 'en16931';
79
+ violations: EinvoiceViolation[];
80
+ } | null;
81
+ file: Uint8Array;
82
+ }
83
+ /**
84
+ * Renders the PDF of a sale invoice or credit note from the views, and
85
+ * records nothing. With `factur_x`, the document must be a posted sale: the
86
+ * CII is written from the books by the same adapter `einvoicing` uses, its
87
+ * broken rules are returned, and the XML is embedded all the same — a check
88
+ * that found something, which the caller reports.
89
+ */
90
+ export declare function renderDocumentPdf(backend: Backend, args: DocumentPdfArgs, deps?: {
91
+ fetch?: LogoFetch | undefined;
92
+ }): Promise<DocumentPdf>;
93
+ //# sourceMappingURL=document-pdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-pdf.d.ts","sourceRoot":"","sources":["../../src/books/document-pdf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAQL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAEpF,OAAO,EAAc,K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EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,iBAAiB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,IAAI,EAAE,MAAM,CAAC;IACb,+HAA+H;IAC/H,QAAQ,EAAE;QAAE,OAAO,EAAE,SAAS,CAAC;QAAC,UAAU,EAAE,iBAAiB,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC;IACzE,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,eAAe,EACrB,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,CAAA;CAAO,GAC3C,OAAO,CAAC,WAAW,CAAC,CAgEtB"}
@@ -0,0 +1,241 @@
1
+ /**
2
+ * The PDF of a sale invoice or credit note, for every surface at once.
3
+ *
4
+ * The command line (`ekwo doc pdf`) and the MCP server (`render_invoice_pdf`)
5
+ * call this with their own `Backend`, acting as the person signed in. It reads
6
+ * the four views a document is printed from — `document_header`,
7
+ * `document_line_items`, `document_tax_summary`, `document_legal_mentions` —
8
+ * and hands the rows to `@ekwo-ai/invoice-pdf`, which renders them and knows
9
+ * nothing of a database. Here is what only a client can do: read the views,
10
+ * fetch the logo the company names by URL, apply the accent colour and the
11
+ * side of the logo the company chose, and, when asked, write the CII of
12
+ * the same document with the Factur-X adapter of the e-invoicing formats and
13
+ * embed it, so that the PDF is a Factur-X invoice.
14
+ *
15
+ * Nothing is recorded. A posted document reproduces from the books; the copy
16
+ * that was sent to a customer is another thing, and keeping it is not done
17
+ * here.
18
+ */
19
+ import { embedFacturX } from '@ekwo-ai/factur-x/pdf';
20
+ import { InvoicePdfError, renderFacturXPdf, renderInvoicePdf, } from '@ekwo-ai/invoice-pdf';
21
+ import { EINVOICE_FORMATS } from '../einvoicing/formats.js';
22
+ import { readEinvoiceSource } from '../einvoicing/issue.js';
23
+ import { BooksError } from './backend.js';
24
+ import { onlyVisible } from './shared.js';
25
+ /** Every column of `document_header`, dates and figures as the text the database holds. */
26
+ const HEADER = [
27
+ 'document_id', 'company_id', 'doc_type', 'state', 'payment_state', 'number', 'supplier_reference',
28
+ 'document_date::text', 'accounting_date::text', 'due_date::text', 'delivery_date::text', 'currency_code',
29
+ 'amount_untaxed::text', 'amount_tax::text', 'amount_total::text', 'amount_paid::text', 'amount_residual::text',
30
+ 'payment_terms', 'payment_means_code', 'payment_reference', 'buyer_reference', 'order_reference',
31
+ 'contract_reference', 'project_reference', 'note', 'payee_iban', 'payee_bic',
32
+ 'seller_name', 'seller_legal_name', 'seller_legal_form', 'seller_vat_number', 'seller_registration_number',
33
+ 'seller_address_line1', 'seller_address_line2', 'seller_postal_code', 'seller_city', 'seller_country',
34
+ 'seller_region', 'seller_email', 'seller_phone', 'seller_website', 'seller_logo_url',
35
+ 'seller_share_capital::text', 'seller_share_capital_currency', 'seller_activity_code', 'seller_activity_scheme',
36
+ 'document_template',
37
+ 'buyer_id', 'buyer_name', 'buyer_vat_number', 'buyer_registration_number', 'buyer_address_line1',
38
+ 'buyer_address_line2', 'buyer_postal_code', 'buyer_city', 'buyer_country', 'buyer_region', 'buyer_email',
39
+ 'country', 'number_format', 'numbering_gapless', 'legal_payment_days', 'late_payment_reference', 'tax_point_rule',
40
+ 'einvoice_profile', 'einvoice_mandatory_from::text', 'party_scheme', 'vat_scheme',
41
+ 'language', 'tax_point_date::text', 'delivery_address_line1', 'delivery_postal_code', 'delivery_city',
42
+ 'delivery_country', 'seller_peppol_scheme', 'seller_peppol_identifier', 'buyer_peppol_scheme',
43
+ 'buyer_peppol_identifier',
44
+ ];
45
+ /** Every column of `document_line_items`. */
46
+ const LINES = [
47
+ 'document_line_id', 'document_id', 'company_id', 'sequence', 'line_type', 'item_name', 'item_description',
48
+ 'seller_item_identifier', 'product_id', 'product_kind', 'quantity::text', 'unit_code', 'unit_price::text',
49
+ 'discount_percent::text', 'amount_untaxed::text', 'tax_id', 'vat_category', 'vat_rate::text', 'account_id',
50
+ 'tax_treatment', 'tax_exemption_code', 'tax_cash_basis', 'unit_price_includes_tax', 'amount_incl_tax::text',
51
+ ];
52
+ /** Every column of `document_tax_summary`. */
53
+ const TAXES = [
54
+ 'document_id', 'company_id', 'doc_type', 'tax_id', 'tax_code', 'tax_name', 'vat_category', 'tax_rate::text',
55
+ 'base_amount::text', 'tax_amount::text', 'tax_charged::text', 'exemption_code', 'exemption_reason',
56
+ 'legal_reference',
57
+ ];
58
+ /** Every column of `document_legal_mentions`. */
59
+ const MENTIONS = [
60
+ 'document_id', 'company_id', 'country', 'code', 'applies_when', 'language', 'text', 'text_i18n', 'sequence',
61
+ 'legal_reference',
62
+ ];
63
+ /** The four views of one document. */
64
+ export async function readDocumentForPdf(backend, documentId) {
65
+ const header = onlyVisible(await backend.select({
66
+ table: 'document_header',
67
+ columns: HEADER,
68
+ where: [{ column: 'document_id', op: 'eq', value: documentId }],
69
+ }), `document ${documentId}`);
70
+ const where = [{ column: 'document_id', op: 'eq', value: documentId }];
71
+ const [lines, taxes, mentions] = await Promise.all([
72
+ backend.select({ table: 'document_line_items', columns: LINES, where, order: [{ column: 'sequence' }] }),
73
+ backend.select({ table: 'document_tax_summary', columns: TAXES, where, order: [{ column: 'tax_code' }] }),
74
+ backend.select({
75
+ table: 'document_legal_mentions',
76
+ columns: MENTIONS,
77
+ where,
78
+ order: [{ column: 'sequence' }, { column: 'code' }],
79
+ }),
80
+ ]);
81
+ return {
82
+ header: header,
83
+ lines: lines,
84
+ taxes: taxes,
85
+ mentions: mentions,
86
+ };
87
+ }
88
+ /**
89
+ * The accent colour and the side of the logo the company chose, as the
90
+ * brick's theme; a column left null keeps the brick's default.
91
+ */
92
+ export async function readInvoiceTheme(backend, companyId) {
93
+ const [company] = await backend.select({
94
+ table: 'companies',
95
+ columns: ['invoice_accent_color', 'invoice_logo_position'],
96
+ where: [{ column: 'id', op: 'eq', value: companyId }],
97
+ });
98
+ const accent = company?.['invoice_accent_color'];
99
+ const side = company?.['invoice_logo_position'];
100
+ return {
101
+ ...(typeof accent === 'string' ? { accent } : {}),
102
+ ...(side === 'left' || side === 'right' ? { logoPosition: side } : {}),
103
+ };
104
+ }
105
+ const LOGO_MAX_BYTES = 2 * 1024 * 1024;
106
+ const LOGO_TIMEOUT_MS = 10_000;
107
+ /**
108
+ * Why a logo URL is not fetched, or null when it may be. Only `http` and
109
+ * `https`, and never a host that names this machine or a private network: the
110
+ * URL is a value a member of the company typed, and the server that fetches it
111
+ * may be somebody else's.
112
+ */
113
+ export function logoUrlRefusal(url) {
114
+ let parsed;
115
+ try {
116
+ parsed = new URL(url);
117
+ }
118
+ catch {
119
+ return 'it is not a URL';
120
+ }
121
+ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:')
122
+ return `${parsed.protocol} is not http or https`;
123
+ const host = parsed.hostname.toLowerCase().replace(/^\[|\]$/g, '');
124
+ if (host === 'localhost' || host.endsWith('.localhost') || host.endsWith('.local') || host.endsWith('.internal')) {
125
+ return `${host} is a local name`;
126
+ }
127
+ const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
128
+ if (v4 !== null) {
129
+ const [a, b] = [Number(v4[1]), Number(v4[2])];
130
+ if (a === 0 || a === 10 || a === 127 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 100 && b >= 64 && b <= 127)) {
131
+ return `${host} is a private or local address`;
132
+ }
133
+ }
134
+ if (host.includes(':') && (host === '::1' || host === '::' || /^f[cd]/.test(host) || /^fe[89ab]/.test(host) || host.startsWith('::ffff:'))) {
135
+ return `${host} is a private or local address`;
136
+ }
137
+ return null;
138
+ }
139
+ /**
140
+ * The bytes of the logo at `url`, or why there are none. A logo that cannot be
141
+ * had is not a reason to refuse an invoice: the PDF is rendered with the
142
+ * company's name instead, and the reason is said.
143
+ */
144
+ export async function fetchLogo(url, fetchImpl) {
145
+ const refusal = logoUrlRefusal(url);
146
+ if (refusal !== null)
147
+ return { skipped: `the logo URL is not fetched: ${refusal}` };
148
+ const controller = new AbortController();
149
+ const timer = setTimeout(() => controller.abort(), LOGO_TIMEOUT_MS);
150
+ try {
151
+ const response = await fetchImpl(url, { signal: controller.signal, redirect: 'error' });
152
+ if (!response.ok)
153
+ return { skipped: `the logo URL answered ${response.status}` };
154
+ const bytes = new Uint8Array(await response.arrayBuffer());
155
+ if (bytes.byteLength > LOGO_MAX_BYTES)
156
+ return { skipped: `the logo is ${bytes.byteLength} bytes, over ${LOGO_MAX_BYTES}` };
157
+ const png = bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47;
158
+ const jpeg = bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff;
159
+ if (!png && !jpeg)
160
+ return { skipped: 'the logo is neither a PNG nor a JPEG' };
161
+ return { bytes };
162
+ }
163
+ catch (error) {
164
+ return { skipped: `the logo could not be fetched: ${error instanceof Error ? error.message : String(error)}` };
165
+ }
166
+ finally {
167
+ clearTimeout(timer);
168
+ }
169
+ }
170
+ /**
171
+ * Renders the PDF of a sale invoice or credit note from the views, and
172
+ * records nothing. With `factur_x`, the document must be a posted sale: the
173
+ * CII is written from the books by the same adapter `einvoicing` uses, its
174
+ * broken rules are returned, and the XML is embedded all the same — a check
175
+ * that found something, which the caller reports.
176
+ */
177
+ export async function renderDocumentPdf(backend, args, deps = {}) {
178
+ const input = await readDocumentForPdf(backend, args.document_id);
179
+ const { header } = input;
180
+ let logo = 'none';
181
+ const url = typeof header.seller_logo_url === 'string' ? header.seller_logo_url.trim() : '';
182
+ if (url !== '') {
183
+ if (deps.fetch === undefined)
184
+ logo = 'the logo URL is not fetched: no fetch was given';
185
+ else {
186
+ const fetched = await fetchLogo(url, deps.fetch);
187
+ if ('bytes' in fetched) {
188
+ input.logo = fetched.bytes;
189
+ logo = 'embedded';
190
+ }
191
+ else
192
+ logo = fetched.skipped;
193
+ }
194
+ }
195
+ const options = {
196
+ theme: await readInvoiceTheme(backend, String(header.company_id)),
197
+ ...(args.page_size === undefined ? {} : { pageSize: args.page_size }),
198
+ ...(args.labels === undefined ? {} : { labels: args.labels }),
199
+ producer: '@ekwo-ai/core',
200
+ };
201
+ let factur = null;
202
+ let rendered;
203
+ try {
204
+ if (args.factur_x === true) {
205
+ if (header.state !== 'posted') {
206
+ throw new BooksError(`document_not_posted: ${String(header.doc_type)} ${String(header.number ?? args.document_id)} is ${String(header.state)}, and a Factur-X invoice is written from a posted document only.`, { hint: 'post_document (ekwo post <document>) books it; without --factur-x the PDF of a draft is rendered and titled as one.' });
207
+ }
208
+ const format = EINVOICE_FORMATS['factur-x-en16931'];
209
+ if (format === undefined)
210
+ throw new BooksError('format_without_brick: no brick writes factur-x-en16931 in this release.');
211
+ const written = format.write(await readEinvoiceSource(backend, args.document_id));
212
+ factur = { profile: 'en16931', violations: written.violations };
213
+ rendered = await renderFacturXPdf(input, { ...options, xml: written.content, profile: 'en16931', embed: embedFacturX });
214
+ }
215
+ else {
216
+ rendered = await renderInvoicePdf(input, options);
217
+ }
218
+ }
219
+ catch (error) {
220
+ if (error instanceof InvoicePdfError) {
221
+ throw new BooksError(`invoice_pdf_unrenderable: ${error.message}`);
222
+ }
223
+ throw error;
224
+ }
225
+ return {
226
+ document_id: args.document_id,
227
+ doc_type: String(header.doc_type),
228
+ number: header.number ?? null,
229
+ state: header.state ?? null,
230
+ language: header.language ?? null,
231
+ filename: rendered.filename,
232
+ title: rendered.title,
233
+ media_type: 'application/pdf',
234
+ byte_size: rendered.file.byteLength,
235
+ page_count: rendered.pageCount,
236
+ logo,
237
+ factur_x: factur,
238
+ file: rendered.file,
239
+ };
240
+ }
241
+ //# sourceMappingURL=document-pdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-pdf.js","sourceRoot":"","sources":["../../src/books/document-pdf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GASjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAA0B,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,2FAA2F;AAC3F,MAAM,MAAM,GAAG;IACb,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,oBAAoB;IACjG,qBAAqB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,eAAe;IACxG,sBAAsB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,uBAAuB;IAC9G,eAAe,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,iBAAiB;IAChG,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW;IAC5E,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,4BAA4B;IAC1G,sBAAsB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,aAAa,EAAE,gBAAgB;IACrG,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB;IACpF,4BAA4B,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,wBAAwB;IAC/G,mBAAmB;IACnB,UAAU,EAAE,YAAY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G,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;YAChE,QAAQ,GAAG,MAAM,gBAAgB,CAAC,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;QAC1H,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,MAAM,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;YACrC,MAAM,IAAI,UAAU,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjC,MAAM,EAAG,MAAM,CAAC,MAAoC,IAAI,IAAI;QAC5D,KAAK,EAAG,MAAM,CAAC,KAAmC,IAAI,IAAI;QAC1D,QAAQ,EAAG,MAAM,CAAC,QAAsC,IAAI,IAAI;QAChE,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,UAAU,EAAE,iBAAiB;QAC7B,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU;QACnC,UAAU,EAAE,QAAQ,CAAC,SAAS;QAC9B,IAAI;QACJ,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,QAAQ,CAAC,IAAI;KACpB,CAAC;AACJ,CAAC"}
@@ -19,4 +19,5 @@ export * from './entries.js';
19
19
  export * from './payments.js';
20
20
  export * from './imports.js';
21
21
  export * from './statements.js';
22
+ export * from './document-pdf.js';
22
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/books/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/books/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -19,4 +19,5 @@ export * from './entries.js';
19
19
  export * from './payments.js';
20
20
  export * from './imports.js';
21
21
  export * from './statements.js';
22
+ export * from './document-pdf.js';
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/books/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/books/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The transport that ships: a folder.
3
+ *
4
+ * It writes the file into `<root>/outbox/` and says where. No network, no
5
+ * credential, no account anywhere — which is what makes it the default, the
6
+ * one a self-hosted installation can use on the first day, and the one the
7
+ * tests run end to end. Whatever carries the files further — a script that
8
+ * uploads them to a portal, the client of an access point, a person — reads
9
+ * the folder, and may answer through it:
10
+ *
11
+ * <root>/outbox/<file> written once, never overwritten
12
+ * <root>/outbox/<file>.accepted_by_access_point
13
+ * <root>/outbox/<file>.delivered a receipt: its text is the
14
+ * <root>/outbox/<file>.rejected message, kept word for word
15
+ * <root>/inbox/<file> what arrived, read by receive()
16
+ *
17
+ * The channel is `self`: the company takes the file where it goes, through a
18
+ * program of its own. A folder cannot tell whether an address is reachable,
19
+ * and `lookup()` says exactly that.
20
+ *
21
+ * A file name carries the first twelve characters of the file's checksum and
22
+ * the first eight of the sending's identifier. Two issues of one document
23
+ * never meet in the folder, and neither do two sendings of one file: a file
24
+ * sent again after a refusal is a new file beside the refused one, so the
25
+ * receipt of the first is never read as the answer to the second. Writing for
26
+ * the same sending twice is the same file — the second write finds it and
27
+ * checks it is byte for byte the one it would have written.
28
+ */
29
+ import { type EinvoiceFile, type EinvoiceTransport } from './transport.js';
30
+ /** `invoice-INV-1.xml`, a checksum and a sending → `invoice-INV-1.0f343b093112.5c1e0a7d.xml`. */
31
+ export declare function directoryFilename(file: Pick<EinvoiceFile, 'filename' | 'checksum'>, transmissionId: string): string;
32
+ export interface DirectoryTransportOptions {
33
+ /** Recorded as the service's name. A folder is the company's own act, so none by default. */
34
+ service?: string | null;
35
+ }
36
+ /** The folder transport, rooted at `root`. The folders are created on first use. */
37
+ export declare function directoryTransport(root: string, options?: DirectoryTransportOptions): EinvoiceTransport;
38
+ //# sourceMappingURL=directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../../src/einvoicing/directory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAMvB,MAAM,gBAAgB,CAAC;AAaxB,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,UAAU,CAAC,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAMnH;AAeD,MAAM,WAAW,yBAAyB;IACxC,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,yBAA8B,GAAG,iBAAiB,CAgE3G"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * The transport that ships: a folder.
3
+ *
4
+ * It writes the file into `<root>/outbox/` and says where. No network, no
5
+ * credential, no account anywhere — which is what makes it the default, the
6
+ * one a self-hosted installation can use on the first day, and the one the
7
+ * tests run end to end. Whatever carries the files further — a script that
8
+ * uploads them to a portal, the client of an access point, a person — reads
9
+ * the folder, and may answer through it:
10
+ *
11
+ * <root>/outbox/<file> written once, never overwritten
12
+ * <root>/outbox/<file>.accepted_by_access_point
13
+ * <root>/outbox/<file>.delivered a receipt: its text is the
14
+ * <root>/outbox/<file>.rejected message, kept word for word
15
+ * <root>/inbox/<file> what arrived, read by receive()
16
+ *
17
+ * The channel is `self`: the company takes the file where it goes, through a
18
+ * program of its own. A folder cannot tell whether an address is reachable,
19
+ * and `lookup()` says exactly that.
20
+ *
21
+ * A file name carries the first twelve characters of the file's checksum and
22
+ * the first eight of the sending's identifier. Two issues of one document
23
+ * never meet in the folder, and neither do two sendings of one file: a file
24
+ * sent again after a refusal is a new file beside the refused one, so the
25
+ * receipt of the first is never read as the answer to the second. Writing for
26
+ * the same sending twice is the same file — the second write finds it and
27
+ * checks it is byte for byte the one it would have written.
28
+ */
29
+ import { mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';
30
+ import { basename, extname, join } from 'node:path';
31
+ import { TransportError, } from './transport.js';
32
+ /** The answers a carrier may leave beside a file, in the order they are read: the furthest first. */
33
+ const RECEIPTS = ['delivered', 'rejected', 'accepted_by_access_point'];
34
+ const OUTBOX = 'outbox';
35
+ const INBOX = 'inbox';
36
+ /** The media type of a file that arrived, from its name. Nothing is guessed beyond the extension. */
37
+ function mediaTypeOf(name) {
38
+ return extname(name).toLowerCase() === '.xml' ? 'application/xml' : 'application/octet-stream';
39
+ }
40
+ /** `invoice-INV-1.xml`, a checksum and a sending → `invoice-INV-1.0f343b093112.5c1e0a7d.xml`. */
41
+ export function directoryFilename(file, transmissionId) {
42
+ const safe = basename(file.filename).replace(/[^A-Za-z0-9._-]+/g, '-');
43
+ const extension = extname(safe);
44
+ const stem = extension === '' ? safe : safe.slice(0, -extension.length);
45
+ const sending = transmissionId.replace(/[^A-Za-z0-9]+/g, '').slice(0, 8);
46
+ return `${stem === '' ? 'einvoice' : stem}.${file.checksum.slice(0, 12)}${sending === '' ? '' : `.${sending}`}${extension}`;
47
+ }
48
+ /** A reference this transport gave, and nothing else: `outbox/<one file name>`. */
49
+ function outboxPath(root, reference) {
50
+ const name = reference.startsWith(`${OUTBOX}/`) ? reference.slice(OUTBOX.length + 1) : '';
51
+ if (name === '' || name !== basename(name) || name.startsWith('.')) {
52
+ throw new TransportError(`unknown_reference: ${reference} is not a file this directory wrote`);
53
+ }
54
+ return join(root, OUTBOX, name);
55
+ }
56
+ async function exists(path) {
57
+ return (await stat(path).catch(() => undefined)) !== undefined;
58
+ }
59
+ /** The folder transport, rooted at `root`. The folders are created on first use. */
60
+ export function directoryTransport(root, options = {}) {
61
+ return {
62
+ channel: 'self',
63
+ service: options.service ?? null,
64
+ async send(file, metadata) {
65
+ const name = directoryFilename(file, metadata.transmissionId);
66
+ const path = join(root, OUTBOX, name);
67
+ try {
68
+ await mkdir(join(root, OUTBOX), { recursive: true });
69
+ await writeFile(path, file.content, { encoding: 'utf8', flag: 'wx' });
70
+ }
71
+ catch (error) {
72
+ const code = error.code;
73
+ if (code !== 'EEXIST') {
74
+ throw new TransportError(`directory_unwritable: ${error.message}`);
75
+ }
76
+ // Written already: the same file, or a refusal. Never overwritten.
77
+ const there = await readFile(path, 'utf8');
78
+ if (there !== file.content) {
79
+ throw new TransportError(`directory_conflict: ${path} already holds another file under this name, and it is not overwritten`);
80
+ }
81
+ }
82
+ return { reference: `${OUTBOX}/${name}`, state: 'submitted', message: null };
83
+ },
84
+ async status(reference) {
85
+ const path = outboxPath(root, reference);
86
+ for (const state of RECEIPTS) {
87
+ const receipt = `${path}.${state}`;
88
+ if (await exists(receipt)) {
89
+ const text = await readFile(receipt, 'utf8');
90
+ return { state, message: text === '' ? null : text };
91
+ }
92
+ }
93
+ // No receipt: the file is where it was written, or whatever carries the
94
+ // files took it and has said nothing yet. Either way it was handed over.
95
+ return { state: 'submitted', message: null };
96
+ },
97
+ async receive() {
98
+ const dir = join(root, INBOX);
99
+ const names = (await readdir(dir).catch(() => [])).filter((name) => !name.startsWith('.')).sort();
100
+ const out = [];
101
+ for (const name of names) {
102
+ const path = join(dir, name);
103
+ const info = await stat(path);
104
+ if (!info.isFile())
105
+ continue;
106
+ out.push({
107
+ reference: `${INBOX}/${name}`,
108
+ filename: name,
109
+ mediaType: mediaTypeOf(name),
110
+ content: await readFile(path, 'utf8'),
111
+ receivedAt: info.mtime.toISOString(),
112
+ });
113
+ }
114
+ return out;
115
+ },
116
+ async lookup() {
117
+ return { reachable: null, message: 'a directory cannot tell whether an address is reachable' };
118
+ },
119
+ };
120
+ }
121
+ //# sourceMappingURL=directory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.js","sourceRoot":"","sources":["../../src/einvoicing/directory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,cAAc,GAQf,MAAM,gBAAgB,CAAC;AAExB,qGAAqG;AACrG,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,0BAA0B,CAAU,CAAC;AAEhF,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,KAAK,GAAG,OAAO,CAAC;AAEtB,qGAAqG;AACrG,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,0BAA0B,CAAC;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