@le-space/eigenbeleg 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +2 -2
- package/src/document.js +2 -0
- package/src/index.js +3 -1
- package/src/statement-pdf.js +10 -6
- package/src/statement.js +22 -7
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ The Eigenbeleg and the Kontoauszug of Le Space's tools – [Belege](https://gith
|
|
|
5
5
|
An Eigenbeleg is a receipt the payer writes for a payment that has no receipt from the other side. It is never an invoice, and never one written for somebody else.
|
|
6
6
|
|
|
7
7
|
- **A period's Eigenbeleg** (Eigenbeleg's): `valueEntries(entries, rates)` values [`@le-space/ledger`](../ledger) entries at the day's rate (`rates.rateFor(asset, day)`, e.g. from [`@le-space/rates`](../rates); `fixedRates` for tests; Aleph credits at their USD price per credit). `buildDocument({ payer, chain, network, period, entries, number, includeKinds, layout })` puts the payments to the network on it (fees, storage deposits; transfers only when included) and says of every other movement why not; `layout: 'collective'` (one Sammel-Eigenbeleg) or `'single'` (one per transaction, numbered up from the first, `nthNumber`). `eigenbelegPdf(doc, { logo })`, `eigenbelegCsv(doc)` (semicolons, decimal commas, BOM; formulas defused).
|
|
8
|
-
- **The Kontoauszug** (Eigenbeleg's): `buildStatement({ payer, account, chain, period, entries, opening, closing, method, belege })` – opening balance, each booking with debit, credit and running balance, closing balance checked against the chain (`reconciled(difference)`: exactly, or but for dust below the twelve decimals the documents print, `isDust`, such as NEAR's 1 yocto deposit of a token transfer); Aleph credits as a monthly **Verbrauchsauszug
|
|
8
|
+
- **The Kontoauszug** (Eigenbeleg's): `buildStatement({ payer, account, chain, period, entries, opening, closing, method, belege })` – opening balance, each booking with debit, credit and running balance, closing balance checked against the chain (`reconciled(difference)`: exactly, or but for dust below the twelve decimals the documents print, `isDust`, such as NEAR's 1 yocto deposit of a token transfer); Aleph credits and a payer's balance in Filecoin Pay (chain `filecoin-pay`, the entries of `@le-space/chains/filecoin-pay`'s `filecoinPayEntries`) as a monthly **Verbrauchsauszug**, each with its own note (`USAGE_NOTES`). `statementPdf(st, { logo })`. `logo: true` draws the chain's mark, small, beside the title (NEAR, Akash, Filecoin, Aleph; from `@le-space/pdf`'s `LOGOS`, sources and terms in its `assets/README.md`); off unless asked for.
|
|
9
9
|
- **The Eigenbeleg of one booking** (Belege's, `@le-space/eigenbeleg/booking`, `/booking-pdf`): `bookingPdf(doc)` for a `BookingEigenbeleg` – a bank booking or a crypto payment, with an own wallet's transaction in full (whole hash, both addresses, every movement with the gas, the explorer link as a QR code). The booking's context is the caller's to gather. `nextSelfNumber(receipts, year)` – the range EB-YYYY-NNN.
|
|
10
10
|
- **A statement Eigenbeleg** (Belege's Aleph, Akash and travel statements, `@le-space/eigenbeleg/statement-layout`): `statementLayout({ title, created, continuation })` → `head`, `field`, `rule`, `heading`, `table` (the header repeats on a new page), `signature`, `save`.
|
|
11
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/eigenbeleg",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"prettier": "3.6.2",
|
|
43
43
|
"unpdf": "1.8.1",
|
|
44
44
|
"@le-space/browser-test": "0.1.0",
|
|
45
|
-
"@le-space/chains": "^0.
|
|
45
|
+
"@le-space/chains": "^0.5.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"test": "node --test --test-reporter=spec \"test/*.test.js\"",
|
package/src/document.js
CHANGED
|
@@ -93,6 +93,7 @@ export const CHAIN_NAMES = {
|
|
|
93
93
|
akash: 'Akash',
|
|
94
94
|
filecoin: 'Filecoin',
|
|
95
95
|
aleph: 'Aleph Cloud (Credits)',
|
|
96
|
+
'filecoin-pay': 'Filecoin Pay',
|
|
96
97
|
ethereum: 'Ethereum',
|
|
97
98
|
base: 'Base'
|
|
98
99
|
};
|
|
@@ -107,6 +108,7 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
|
|
|
107
108
|
filecoin: 'Filfox',
|
|
108
109
|
akash: 'Akash-RPC, Akash Console',
|
|
109
110
|
aleph: 'Aleph-API (api2.aleph.im)',
|
|
111
|
+
'filecoin-pay': 'Index von Filecoin Pay (Goldsky), Blockscout, Filfox',
|
|
110
112
|
ethereum: 'Alchemy APIs (Ethereum Mainnet)',
|
|
111
113
|
base: 'Alchemy APIs (Base Mainnet)'
|
|
112
114
|
});
|
package/src/index.js
CHANGED
|
@@ -26,7 +26,9 @@ export {
|
|
|
26
26
|
monthly,
|
|
27
27
|
reconciled,
|
|
28
28
|
STATEMENT_NOTE,
|
|
29
|
-
USAGE_NOTE
|
|
29
|
+
USAGE_NOTE,
|
|
30
|
+
USAGE_NOTES,
|
|
31
|
+
FILECOIN_PAY_USAGE_NOTE
|
|
30
32
|
} from './statement.js';
|
|
31
33
|
/** @typedef {import('./statement.js').MonthlyLine} MonthlyLine */
|
|
32
34
|
export { statementPdf } from './statement-pdf.js';
|
package/src/statement-pdf.js
CHANGED
|
@@ -44,6 +44,8 @@ export async function statementPdf(
|
|
|
44
44
|
const created = new Date(st.issuedAt);
|
|
45
45
|
// Aleph credits: a Verbrauchsauszug in the same layout, valued by its own rule.
|
|
46
46
|
const aleph = st.chain === 'aleph';
|
|
47
|
+
// Filecoin Pay: the same, in USDFC and by rail.
|
|
48
|
+
const pay = st.chain === 'filecoin-pay';
|
|
47
49
|
const title = `${st.title} ${st.number}`;
|
|
48
50
|
const subject = `${st.title} ${st.chainName} ${st.account}, ${deDate(st.period.from)} – ${deDate(st.period.to)}`;
|
|
49
51
|
const { pdf, fonts } = await createPdfA();
|
|
@@ -109,7 +111,7 @@ export async function statementPdf(
|
|
|
109
111
|
bold.draw(l.page, `${s.asset} · ${st.account}`, { x: M + 6, y: l.y - 12.5, size: 9.5 });
|
|
110
112
|
l.y -= 24;
|
|
111
113
|
// The month in sums, first (#24): what the books take as one booking each; the rows below are the proof.
|
|
112
|
-
if (aleph) {
|
|
114
|
+
if (aleph || pay) {
|
|
113
115
|
const m = s.monthly;
|
|
114
116
|
const lines = [m.usage, m.usageTotal, m.purchases, m.transfersIn, m.transfersOut]
|
|
115
117
|
.flat()
|
|
@@ -117,7 +119,7 @@ export async function statementPdf(
|
|
|
117
119
|
if (lines.length) {
|
|
118
120
|
l.ensure(14 + lines.length * 11 + 8);
|
|
119
121
|
l.at('Monatsübersicht', M, 8, bold, GREY);
|
|
120
|
-
l.right('Credits', M + 371 - 4, 7.5, bold, GREY);
|
|
122
|
+
l.right(pay ? s.asset : 'Credits', M + 371 - 4, 7.5, bold, GREY);
|
|
121
123
|
l.right('Wert EUR', M + 507 - 4, 7.5, bold, GREY);
|
|
122
124
|
l.y -= 12;
|
|
123
125
|
for (const ml of lines) {
|
|
@@ -228,15 +230,17 @@ export async function statementPdf(
|
|
|
228
230
|
);
|
|
229
231
|
} else {
|
|
230
232
|
text(
|
|
231
|
-
`Anfangs- und Endstand abgeleitet aus dem heutigen Kontostand abzüglich aller Bewegungen seither (${aleph ? 'die Aleph-API nennt den heutigen Stand und die Summen seither' : 'die Chain hält keine alten Kontostände vor'}).`,
|
|
233
|
+
`Anfangs- und Endstand abgeleitet aus dem heutigen Kontostand abzüglich aller Bewegungen seither (${aleph ? 'die Aleph-API nennt den heutigen Stand und die Summen seither' : pay ? 'der Zahlungsvertrag nennt nur den heutigen Stand' : 'die Chain hält keine alten Kontostände vor'}).`,
|
|
232
234
|
{ size: 7.5, color: GREY }
|
|
233
235
|
);
|
|
234
236
|
}
|
|
235
237
|
l.y -= 4;
|
|
236
238
|
text(
|
|
237
|
-
|
|
238
|
-
? `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Verbrauch (Aufwand) ${deEuro(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte
|
|
239
|
-
:
|
|
239
|
+
pay
|
|
240
|
+
? `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Verbrauch (Aufwand) ${deEuro(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte zum Tageskurs von USDC, an den US-Dollar gebunden wie ${s.asset} (Kurs 00:00 UTC: CoinGecko, sonst Kraken).`
|
|
241
|
+
: aleph
|
|
242
|
+
? `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Verbrauch (Aufwand) ${deEuro(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis) × EZB-Referenzkurs USD/EUR des Tages.`
|
|
243
|
+
: `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${deEuro(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte zum Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken).`,
|
|
240
244
|
{ size: 7.5, color: GREY }
|
|
241
245
|
);
|
|
242
246
|
l.y -= 12;
|
package/src/statement.js
CHANGED
|
@@ -41,6 +41,19 @@ export const USAGE_NOTE =
|
|
|
41
41
|
'Kein Dokument eines Kreditinstituts und keine Rechnung von Aleph. Verbrauch je Tag und Ressource; Euro-Wert: USD-Preis je Credit ' +
|
|
42
42
|
'(letzter Kauf am oder vor dem Tag, sonst Alephs Listenpreis von 1 USD je 1.000.000 Credits) zum EZB-Referenzkurs des Tages.';
|
|
43
43
|
|
|
44
|
+
/** Filecoin Pay: a payer's balance in the payment contract, as a monthly Verbrauchsauszug. */
|
|
45
|
+
export const FILECOIN_PAY_USAGE_NOTE =
|
|
46
|
+
'Verbrauchsauszug eines Guthabens im Zahlungsvertrag Filecoin Pay (Filecoin Onchain Cloud), erstellt vom Zahler aus öffentlichen Chain-Daten. ' +
|
|
47
|
+
'Kein Dokument eines Kreditinstituts und keine Rechnung eines Speicheranbieters. Verbrauch ist jede Abrechnung einer Rail an ihren Anbieter; ' +
|
|
48
|
+
'sie bezahlt bis zu dem Zeitpunkt, den sie nennt, und deckt darum nicht genau den Monat. Gelesen wird nur USDFC; was der Zahler selbst über Rails einnimmt, fehlt. ' +
|
|
49
|
+
'Euro-Wert: USDFC ist an den US-Dollar gebunden und wird zum Tageskurs von USDC bewertet.';
|
|
50
|
+
|
|
51
|
+
/** The chains whose statement is a Verbrauchsauszug (consumption from a prepaid balance), with its note. */
|
|
52
|
+
export const USAGE_NOTES = /** @type {Record<string, string>} */ ({
|
|
53
|
+
aleph: USAGE_NOTE,
|
|
54
|
+
'filecoin-pay': FILECOIN_PAY_USAGE_NOTE
|
|
55
|
+
});
|
|
56
|
+
|
|
44
57
|
export const STATEMENT_NOTE =
|
|
45
58
|
'Kontoauszug eines Blockchain-Kontos, erstellt vom Kontoinhaber aus öffentlichen Chain-Daten. ' +
|
|
46
59
|
'Kein Dokument eines Kreditinstituts. Jede Buchung ist über ihren Transaktions-Hash in einem öffentlichen Block-Explorer nachprüfbar.';
|
|
@@ -59,10 +72,10 @@ export const STATEMENT_NOTE =
|
|
|
59
72
|
* @property {string} eur signed EUR value at the day's rate, or ''
|
|
60
73
|
* @property {string} beleg the Eigenbeleg's number, when the booking has one
|
|
61
74
|
* @property {boolean} fee
|
|
62
|
-
* @property {boolean} usage consumption billed from the balance (Aleph credits)
|
|
75
|
+
* @property {boolean} usage consumption billed from the balance (Aleph credits, a Filecoin Pay settlement)
|
|
63
76
|
* @property {boolean} purchase credits bought from Aleph (the payment is on another chain, with its own Eigenbeleg)
|
|
64
77
|
* @property {string} label the counterparty's label alone (the resource's name, for usage)
|
|
65
|
-
* @property {string} hashLabel what the hash is: `Tx`, or `Ressource` for usage
|
|
78
|
+
* @property {string} hashLabel what the hash is: `Tx`, or `Ressource` for Aleph's usage
|
|
66
79
|
*/
|
|
67
80
|
|
|
68
81
|
/**
|
|
@@ -166,7 +179,8 @@ export function buildStatement({
|
|
|
166
179
|
rows.push({
|
|
167
180
|
date: e.date,
|
|
168
181
|
time: e.time.slice(11, 19),
|
|
169
|
-
|
|
182
|
+
// Filecoin Pay: up to when a settlement paid its rail (the entry's memo).
|
|
183
|
+
text: `${kindText(e)}${e.type === 'received' ? ' (Eingang)' : ''}${e.chain === 'filecoin-pay' && e.kind === 'usage' && e.memo ? `, ${e.memo}` : ''}`,
|
|
170
184
|
counterparty: e.counterpartyLabel
|
|
171
185
|
? `${e.counterpartyLabel} · ${e.counterparty}`
|
|
172
186
|
: e.counterparty,
|
|
@@ -181,7 +195,8 @@ export function buildStatement({
|
|
|
181
195
|
usage: e.kind === 'usage',
|
|
182
196
|
purchase: e.type === 'received' && e.counterparty === 'aleph',
|
|
183
197
|
label: e.counterpartyLabel,
|
|
184
|
-
|
|
198
|
+
// Aleph's usage names a resource; a Filecoin Pay settlement is a transaction.
|
|
199
|
+
hashLabel: e.kind === 'usage' && e.chain === 'aleph' ? 'Ressource' : 'Tx'
|
|
185
200
|
});
|
|
186
201
|
}
|
|
187
202
|
const debit = sum(rows.map((r) => r.debit || '0'));
|
|
@@ -207,8 +222,8 @@ export function buildStatement({
|
|
|
207
222
|
unvalued: rows.filter((r) => !r.eur).length
|
|
208
223
|
};
|
|
209
224
|
});
|
|
210
|
-
// Aleph credits: a monthly usage statement, laid out as the Kontoauszug.
|
|
211
|
-
const usage = chain
|
|
225
|
+
// Aleph credits, Filecoin Pay: a monthly usage statement, laid out as the Kontoauszug.
|
|
226
|
+
const usage = Object.hasOwn(USAGE_NOTES, chain);
|
|
212
227
|
return {
|
|
213
228
|
kind: 'kontoauszug',
|
|
214
229
|
title: usage ? 'Verbrauchsauszug' : 'Kontoauszug',
|
|
@@ -225,7 +240,7 @@ export function buildStatement({
|
|
|
225
240
|
at,
|
|
226
241
|
sections,
|
|
227
242
|
unlisted: mine.filter((e) => !e.priceAs && !assets.includes(e.asset)).length,
|
|
228
|
-
note: usage ?
|
|
243
|
+
note: usage ? USAGE_NOTES[chain] : STATEMENT_NOTE
|
|
229
244
|
};
|
|
230
245
|
}
|
|
231
246
|
|