@le-space/eigenbeleg 0.6.1 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/eigenbeleg",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "The Eigenbeleg and the Kontoauszug of Le Space's tools: a payer's own receipt for payments without one from the other side (a period's network fees, one booking in any script), a blockchain account's statement (Aleph credits as a Verbrauchsauszug), as PDF/A-2b and CSV. Browser and Node; the rates handed in.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "type": "module",
@@ -37,15 +37,15 @@
37
37
  "pdf-lib": "1.17.1",
38
38
  "uqr": "0.1.3",
39
39
  "@le-space/charts": "^0.2.0",
40
- "@le-space/pdf": "^0.2.0",
41
- "@le-space/ledger": "^0.3.0"
40
+ "@le-space/pdf": "^0.3.0",
41
+ "@le-space/ledger": "^0.3.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@noble/hashes": "2.4.0",
45
45
  "prettier": "3.6.2",
46
46
  "unpdf": "1.8.1",
47
47
  "@le-space/browser-test": "0.1.0",
48
- "@le-space/chains": "^0.7.0"
48
+ "@le-space/chains": "^0.8.0"
49
49
  },
50
50
  "scripts": {
51
51
  "test": "node --test --test-reporter=spec \"test/*.test.js\"",
package/src/document.js CHANGED
@@ -181,7 +181,9 @@ export const CHAIN_NAMES = {
181
181
  aleph: 'Aleph Cloud (Credits)',
182
182
  'filecoin-pay': 'Filecoin Pay',
183
183
  ethereum: 'Ethereum',
184
- base: 'Base'
184
+ base: 'Base',
185
+ bitcoin: 'Bitcoin',
186
+ doichain: 'Doichain'
185
187
  };
186
188
 
187
189
  /**
@@ -196,9 +198,22 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
196
198
  aleph: 'Aleph-API (api2.aleph.im)',
197
199
  'filecoin-pay': 'Index von Filecoin Pay (Goldsky), Blockscout, Filfox',
198
200
  ethereum: 'Alchemy APIs (Ethereum Mainnet)',
199
- base: 'Alchemy APIs (Base Mainnet)'
201
+ base: 'Alchemy APIs (Base Mainnet)',
202
+ bitcoin: 'Esplora-API von mempool.space',
203
+ doichain: 'ElectrumX-Server des Doichain-Netzes'
200
204
  });
201
205
 
206
+ /**
207
+ * The data source a document names: the one the caller read from when it
208
+ * says so (an own Esplora, say), else the chain's usual one.
209
+ *
210
+ * @param {string} chain
211
+ * @param {string} chainName
212
+ * @param {string} [given]
213
+ */
214
+ export const dataSourceOf = (chain, chainName, given) =>
215
+ given?.trim() || DATA_SOURCES[chain] || chainName;
216
+
202
217
  /**
203
218
  * @typedef {object} Payer who pays and issues the Eigenbeleg
204
219
  * @property {string} name
@@ -246,6 +261,7 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
246
261
  * @param {string[]} [p.includeKinds]
247
262
  * @param {string} [p.issuedAt] ISO; now when not given
248
263
  * @param {'collective' | 'single'} [p.layout]
264
+ * @param {string} [p.dataSource] where the entries were read from, when not the chain's usual source
249
265
  * @param {string} [p.currency] the document's currency (DOCUMENT_CURRENCIES), EUR when not
250
266
  * given; the entries are valued in it. The fields named `eur…` hold the values in this
251
267
  * currency: they keep the name they had when every document was in euro.
@@ -260,6 +276,7 @@ export function buildDocument({
260
276
  includeKinds = DEFAULT_KINDS,
261
277
  issuedAt,
262
278
  layout = 'collective',
279
+ dataSource,
263
280
  currency: asked
264
281
  }) {
265
282
  if (layout !== 'collective' && layout !== 'single')
@@ -365,6 +382,7 @@ export function buildDocument({
365
382
  },
366
383
  chain,
367
384
  chainName,
385
+ dataSource: dataSourceOf(chain, chainName, dataSource),
368
386
  network,
369
387
  testnet: network !== 'mainnet',
370
388
  period,
package/src/index.js CHANGED
@@ -13,6 +13,7 @@ export {
13
13
  ALEPH_NOTE,
14
14
  noInvoice,
15
15
  CHAIN_NAMES,
16
+ dataSourceOf,
16
17
  DATA_SOURCES,
17
18
  deNumber,
18
19
  deRate,
package/src/layout.js CHANGED
@@ -273,8 +273,9 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
273
273
  * @param {string} caption
274
274
  */
275
275
  signature(caption) {
276
- l.ensure(70);
277
- l.gap(40);
276
+ // What it takes and no more: a line to sign alone on a new page helps nobody.
277
+ l.ensure(54);
278
+ l.gap(36);
278
279
  l.page.drawLine({
279
280
  start: { x: margin, y: l.y },
280
281
  end: { x: margin + 230, y: l.y },
package/src/pdf.js CHANGED
@@ -61,7 +61,7 @@ export async function eigenbelegPdf(
61
61
  : `unter ${money(places ? `0.${'1'.padStart(places, '0')}` : '1')}`;
62
62
  let pageNo = 1;
63
63
  let current = doc.number;
64
- const footerRight = `Daten: ${DATA_SOURCES[doc.chain] ?? doc.chainName} · Kurse: siehe Kursquelle`;
64
+ const footerRight = `Daten: ${doc.dataSource ?? DATA_SOURCES[doc.chain] ?? doc.chainName} · Kurse: siehe Kursquelle`;
65
65
 
66
66
  const footer = (/** @type {import('./layout.js').Layout} */ l) =>
67
67
  l.foot(l.page, `${current} · Seite ${pageNo}`, footerRight);
@@ -112,11 +112,13 @@ export async function eigenbelegPdf(
112
112
  }
113
113
 
114
114
  const columns = [
115
- { title: 'Bewegung', width: 150 },
116
- { title: 'Menge', width: 112, right: true },
117
- // Six significant digits (deRate): the smallest rate, Aleph's credits, still fits on one line.
118
- { title: `Kurs ${cur}`, width: 58, right: true },
119
- { title: `Wert ${cur}`, width: 66, right: true },
115
+ // Measured in the document's face, whose figures are wider than its letters: a rate of six
116
+ // significant digits below a millionth (deRate; Aleph's credits) and a value of four digits
117
+ // before the comma with a currency's code each stand on one line.
118
+ { title: 'Bewegung', width: 143 },
119
+ { title: 'Menge', width: 106, right: true },
120
+ { title: `Kurs ${cur}`, width: 67, right: true },
121
+ { title: `Wert ${cur}`, width: 70, right: true },
120
122
  { title: 'Auf dem Beleg', width: width - 386 }
121
123
  ];
122
124
 
@@ -317,7 +317,7 @@ export async function statementPdf(
317
317
  );
318
318
 
319
319
  // page numbers and footer on every page
320
- const data = `Daten: ${DATA_SOURCES[st.chain] ?? st.chainName} · kein Dokument eines Kreditinstituts`;
320
+ const data = `Daten: ${st.dataSource ?? DATA_SOURCES[st.chain] ?? st.chainName} · kein Dokument eines Kreditinstituts`;
321
321
  l.pages.forEach((p, i) => l.foot(p, `${st.number} · Seite ${i + 1} von ${l.pages.length}`, data));
322
322
 
323
323
  return savePdfA(pdf, {
package/src/statement.js CHANGED
@@ -22,6 +22,7 @@
22
22
  import { normalize, sum } from '@le-space/ledger';
23
23
  import {
24
24
  CHAIN_NAMES,
25
+ dataSourceOf,
25
26
  checkValued,
26
27
  conversionText,
27
28
  documentCurrency,
@@ -186,6 +187,7 @@ export function monthly(rows) {
186
187
  * @param {Map<string, string>} [p.belege] hash → Eigenbeleg number
187
188
  * @param {string} [p.number]
188
189
  * @param {string} [p.issuedAt]
190
+ * @param {string} [p.dataSource] where the entries were read from, when not the chain's usual source
189
191
  * @param {string} [p.currency] the statement's currency (DOCUMENT_CURRENCIES), EUR when not
190
192
  * given; the entries are valued in it, and the fields named `eur…` hold values in it
191
193
  */
@@ -203,6 +205,7 @@ export function buildStatement({
203
205
  belege = new Map(),
204
206
  number,
205
207
  issuedAt,
208
+ dataSource,
206
209
  currency: asked
207
210
  }) {
208
211
  const currency = documentCurrency(asked);
@@ -282,6 +285,11 @@ export function buildStatement({
282
285
  account,
283
286
  chain,
284
287
  chainName: CHAIN_NAMES[/** @type {keyof typeof CHAIN_NAMES} */ (chain)] ?? chain,
288
+ dataSource: dataSourceOf(
289
+ chain,
290
+ CHAIN_NAMES[/** @type {keyof typeof CHAIN_NAMES} */ (chain)] ?? chain,
291
+ dataSource
292
+ ),
285
293
  network,
286
294
  testnet: network !== 'mainnet',
287
295
  period,