@le-space/eigenbeleg 0.6.0 → 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 +4 -4
- package/src/document.js +29 -5
- package/src/index.js +1 -0
- package/src/layout.js +3 -2
- package/src/pdf.js +8 -6
- package/src/statement-pdf.js +20 -2
- package/src/statement.js +29 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/eigenbeleg",
|
|
3
|
-
"version": "0.
|
|
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/
|
|
41
|
-
"@le-space/
|
|
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.
|
|
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
|
@@ -109,7 +109,7 @@ export function conversionText(currency) {
|
|
|
109
109
|
const ecb = 'zum Euro-Referenzkurs der EZB des Tages oder des letzten davor';
|
|
110
110
|
if (documentCurrency(currency) === 'EUR') return '';
|
|
111
111
|
if (DOCUMENT_CURRENCIES[currency].via === 'cbr')
|
|
112
|
-
return `über den Euro in ${currency} umgerechnet zum amtlichen Kurs der Bank von Russland, gültig am Tag
|
|
112
|
+
return `über den Euro in ${currency} umgerechnet zum amtlichen Kurs der Bank von Russland, gültig am Tag`;
|
|
113
113
|
return `über den Euro in ${currency} umgerechnet ${ecb}`;
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -130,14 +130,20 @@ export function checkValued(entries, currency) {
|
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
132
|
* A rate's name without its day (`… vom 2026-08-10`), each leg of it: the day
|
|
133
|
-
* is each position's.
|
|
133
|
+
* is each position's. A reference value (`Referenzwert von …, Stand
|
|
134
|
+
* 2026-01-01 (kein Börsenkurs)`, @le-space/rates referenceRate) keeps what it
|
|
135
|
+
* is and loses only its `Stand`.
|
|
134
136
|
*
|
|
135
137
|
* @param {string} source
|
|
136
138
|
*/
|
|
137
139
|
export const sourceName = (source) =>
|
|
138
140
|
source
|
|
139
141
|
.split(' × ')
|
|
140
|
-
.map((leg) =>
|
|
142
|
+
.map((leg) =>
|
|
143
|
+
leg.startsWith('Referenzwert')
|
|
144
|
+
? leg.replace(/, Stand \d{4}-\d{2}-\d{2}/, '')
|
|
145
|
+
: leg.replace(/ \d{4}-\d{2}-\d{2}.*$/, '').replace(/ vom$/, '')
|
|
146
|
+
)
|
|
141
147
|
.join(' × ');
|
|
142
148
|
|
|
143
149
|
/** Kinds that go on the Eigenbeleg unless the payer chooses otherwise. */
|
|
@@ -175,7 +181,9 @@ export const CHAIN_NAMES = {
|
|
|
175
181
|
aleph: 'Aleph Cloud (Credits)',
|
|
176
182
|
'filecoin-pay': 'Filecoin Pay',
|
|
177
183
|
ethereum: 'Ethereum',
|
|
178
|
-
base: 'Base'
|
|
184
|
+
base: 'Base',
|
|
185
|
+
bitcoin: 'Bitcoin',
|
|
186
|
+
doichain: 'Doichain'
|
|
179
187
|
};
|
|
180
188
|
|
|
181
189
|
/**
|
|
@@ -190,9 +198,22 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
|
|
|
190
198
|
aleph: 'Aleph-API (api2.aleph.im)',
|
|
191
199
|
'filecoin-pay': 'Index von Filecoin Pay (Goldsky), Blockscout, Filfox',
|
|
192
200
|
ethereum: 'Alchemy APIs (Ethereum Mainnet)',
|
|
193
|
-
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'
|
|
194
204
|
});
|
|
195
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
|
+
|
|
196
217
|
/**
|
|
197
218
|
* @typedef {object} Payer who pays and issues the Eigenbeleg
|
|
198
219
|
* @property {string} name
|
|
@@ -240,6 +261,7 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
|
|
|
240
261
|
* @param {string[]} [p.includeKinds]
|
|
241
262
|
* @param {string} [p.issuedAt] ISO; now when not given
|
|
242
263
|
* @param {'collective' | 'single'} [p.layout]
|
|
264
|
+
* @param {string} [p.dataSource] where the entries were read from, when not the chain's usual source
|
|
243
265
|
* @param {string} [p.currency] the document's currency (DOCUMENT_CURRENCIES), EUR when not
|
|
244
266
|
* given; the entries are valued in it. The fields named `eur…` hold the values in this
|
|
245
267
|
* currency: they keep the name they had when every document was in euro.
|
|
@@ -254,6 +276,7 @@ export function buildDocument({
|
|
|
254
276
|
includeKinds = DEFAULT_KINDS,
|
|
255
277
|
issuedAt,
|
|
256
278
|
layout = 'collective',
|
|
279
|
+
dataSource,
|
|
257
280
|
currency: asked
|
|
258
281
|
}) {
|
|
259
282
|
if (layout !== 'collective' && layout !== 'single')
|
|
@@ -359,6 +382,7 @@ export function buildDocument({
|
|
|
359
382
|
},
|
|
360
383
|
chain,
|
|
361
384
|
chainName,
|
|
385
|
+
dataSource: dataSourceOf(chain, chainName, dataSource),
|
|
362
386
|
network,
|
|
363
387
|
testnet: network !== 'mainnet',
|
|
364
388
|
period,
|
package/src/index.js
CHANGED
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
|
-
|
|
277
|
-
l.
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
{ title:
|
|
119
|
-
{ title:
|
|
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
|
|
package/src/statement-pdf.js
CHANGED
|
@@ -22,6 +22,24 @@ import { BLACK, GREY, INK, MARK_SIZE, TYPE, WARN, pageLayout } from './layout.js
|
|
|
22
22
|
// The same frame as every other document of the package (layout.js).
|
|
23
23
|
const M = 48;
|
|
24
24
|
|
|
25
|
+
const MARKET_RATE = 'Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken)';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What a section's values are at, for its note: the market rate of the day, a
|
|
29
|
+
* reference value by its name, or both – as the EUR text (`zum …`) and the
|
|
30
|
+
* rate's name for another currency.
|
|
31
|
+
*
|
|
32
|
+
* @param {{ marketRate?: boolean, referenceValues?: string[] }} s
|
|
33
|
+
* @returns {[string, string]}
|
|
34
|
+
*/
|
|
35
|
+
function marketOrReference({ marketRate = true, referenceValues = [] }) {
|
|
36
|
+
const names = [
|
|
37
|
+
...(marketRate || !referenceValues.length ? [MARKET_RATE] : []),
|
|
38
|
+
...referenceValues
|
|
39
|
+
];
|
|
40
|
+
return [names.map((n) => `zum ${n}`).join(' und '), names.join(' und ')];
|
|
41
|
+
}
|
|
42
|
+
|
|
25
43
|
/** The table of bookings; its last column names the statement's currency. @param {string} currency */
|
|
26
44
|
const columns = (currency) => [
|
|
27
45
|
{ title: 'Buchungstag', width: 52 },
|
|
@@ -287,7 +305,7 @@ export async function statementPdf(
|
|
|
287
305
|
? 'Euro-Werte: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis) × EZB-Referenzkurs USD/EUR des Tages'
|
|
288
306
|
: `Werte in ${cur}: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis)${cur === 'USD' ? '' : `, ${conversionText(cur)}`}`
|
|
289
307
|
}.`
|
|
290
|
-
: `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${money(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${valued(
|
|
308
|
+
: `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${money(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${valued(...marketOrReference(s))}.`,
|
|
291
309
|
{ size: TYPE.small, color: GREY }
|
|
292
310
|
);
|
|
293
311
|
l.y -= 20;
|
|
@@ -299,7 +317,7 @@ export async function statementPdf(
|
|
|
299
317
|
);
|
|
300
318
|
|
|
301
319
|
// page numbers and footer on every page
|
|
302
|
-
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`;
|
|
303
321
|
l.pages.forEach((p, i) => l.foot(p, `${st.number} · Seite ${i + 1} von ${l.pages.length}`, data));
|
|
304
322
|
|
|
305
323
|
return savePdfA(pdf, {
|
package/src/statement.js
CHANGED
|
@@ -22,10 +22,12 @@
|
|
|
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,
|
|
28
|
-
kindText
|
|
29
|
+
kindText,
|
|
30
|
+
sourceName
|
|
29
31
|
} from './document.js';
|
|
30
32
|
|
|
31
33
|
/** Smaller than the twelve decimals the documents print (and not zero). @param {string} difference */
|
|
@@ -79,6 +81,21 @@ export function usageNote(chain, currency) {
|
|
|
79
81
|
return `${head}Wert in ${currency}: USDFC ist an den US-Dollar gebunden und wird zum Tageskurs von USDC bewertet, ${conversionText(currency)}.`;
|
|
80
82
|
}
|
|
81
83
|
|
|
84
|
+
/**
|
|
85
|
+
* How a section's values came about: at a market rate of the day, at a
|
|
86
|
+
* reference value (a rate whose first leg is a `Referenzwert`, by its name), or both.
|
|
87
|
+
*
|
|
88
|
+
* @param {StatementRow[]} rows
|
|
89
|
+
* @returns {{ marketRate: boolean, referenceValues: string[] }}
|
|
90
|
+
*/
|
|
91
|
+
export function valuedBy(rows) {
|
|
92
|
+
const legs = rows.filter((r) => r.eur).map((r) => sourceName(r.rateSource ?? '').split(' × ')[0]);
|
|
93
|
+
return {
|
|
94
|
+
marketRate: legs.some((l) => !l.startsWith('Referenzwert')),
|
|
95
|
+
referenceValues: [...new Set(legs.filter((l) => l.startsWith('Referenzwert')))]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
82
99
|
export const STATEMENT_NOTE =
|
|
83
100
|
'Kontoauszug eines Blockchain-Kontos, erstellt vom Kontoinhaber aus öffentlichen Chain-Daten. ' +
|
|
84
101
|
'Kein Dokument eines Kreditinstituts. Jede Buchung ist über ihren Transaktions-Hash in einem öffentlichen Block-Explorer nachprüfbar.';
|
|
@@ -95,6 +112,7 @@ export const STATEMENT_NOTE =
|
|
|
95
112
|
* @property {string} credit amount in, positive, or ''
|
|
96
113
|
* @property {string} balance running balance after it
|
|
97
114
|
* @property {string} eur signed value at the day's rate, in the statement's currency (EUR unless another), or ''
|
|
115
|
+
* @property {string} [rateSource] where that value's rate came from (`eur.source`), '' or absent when unknown
|
|
98
116
|
* @property {string} beleg the Eigenbeleg's number, when the booking has one
|
|
99
117
|
* @property {boolean} fee
|
|
100
118
|
* @property {boolean} usage consumption billed from the balance (Aleph credits, a Filecoin Pay settlement)
|
|
@@ -169,6 +187,7 @@ export function monthly(rows) {
|
|
|
169
187
|
* @param {Map<string, string>} [p.belege] hash → Eigenbeleg number
|
|
170
188
|
* @param {string} [p.number]
|
|
171
189
|
* @param {string} [p.issuedAt]
|
|
190
|
+
* @param {string} [p.dataSource] where the entries were read from, when not the chain's usual source
|
|
172
191
|
* @param {string} [p.currency] the statement's currency (DOCUMENT_CURRENCIES), EUR when not
|
|
173
192
|
* given; the entries are valued in it, and the fields named `eur…` hold values in it
|
|
174
193
|
*/
|
|
@@ -186,6 +205,7 @@ export function buildStatement({
|
|
|
186
205
|
belege = new Map(),
|
|
187
206
|
number,
|
|
188
207
|
issuedAt,
|
|
208
|
+
dataSource,
|
|
189
209
|
currency: asked
|
|
190
210
|
}) {
|
|
191
211
|
const currency = documentCurrency(asked);
|
|
@@ -220,6 +240,7 @@ export function buildStatement({
|
|
|
220
240
|
credit: out ? '' : e.amount,
|
|
221
241
|
balance,
|
|
222
242
|
eur: e.eur?.value ?? '',
|
|
243
|
+
rateSource: e.eur?.value ? e.eur.source : '',
|
|
223
244
|
beleg: belege.get(e.hash) ?? '',
|
|
224
245
|
fee: e.type === 'fee',
|
|
225
246
|
usage: e.kind === 'usage',
|
|
@@ -249,7 +270,8 @@ export function buildStatement({
|
|
|
249
270
|
eurIn: sum(rows.filter((r) => r.credit && r.eur).map((r) => r.eur)),
|
|
250
271
|
eurFees: sum(rows.filter((r) => r.fee && r.eur).map((r) => r.eur.replace(/^-/, ''))),
|
|
251
272
|
eurUsage: sum(rows.filter((r) => r.usage && r.eur).map((r) => r.eur.replace(/^-/, ''))),
|
|
252
|
-
unvalued: rows.filter((r) => !r.eur).length
|
|
273
|
+
unvalued: rows.filter((r) => !r.eur).length,
|
|
274
|
+
...valuedBy(rows)
|
|
253
275
|
};
|
|
254
276
|
});
|
|
255
277
|
// Aleph credits, Filecoin Pay: a monthly usage statement, laid out as the Kontoauszug.
|
|
@@ -263,6 +285,11 @@ export function buildStatement({
|
|
|
263
285
|
account,
|
|
264
286
|
chain,
|
|
265
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
|
+
),
|
|
266
293
|
network,
|
|
267
294
|
testnet: network !== 'mainnet',
|
|
268
295
|
period,
|