kassza 0.13.0 → 0.14.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.en.md +48 -0
- package/README.md +152 -22
- package/agents/README.md +6 -1
- package/agents/api.md +64 -12
- package/agents/pitfalls.md +12 -1
- package/agents/recipes.md +67 -8
- package/agents/skills/kassza/SKILL.md +3 -0
- package/agents/skills/migrate-from-szamlazz-js/SKILL.md +39 -0
- package/dist/batch/index.cjs +346 -0
- package/dist/batch/index.d.cts +91 -0
- package/dist/batch/index.d.ts +91 -0
- package/dist/batch/index.js +339 -0
- package/dist/cli.cjs +105 -14
- package/dist/cli.js +104 -13
- package/dist/{client-C-PdfL_P.cjs → client-CLFvJCVW.cjs} +358 -181
- package/dist/{client-CfaS1-Jx.js → client-Cvf-hTz_.js} +311 -152
- package/dist/{client-6MkeuFqD.d.ts → client-DeWWQ-RZ.d.ts} +99 -26
- package/dist/{client-B5FryKxJ.d.cts → client-SVZu25MB.d.cts} +99 -26
- package/dist/{context-DXNbTPwz.d.cts → context-CFNKzStE.d.cts} +82 -58
- package/dist/{context-BxQlIlug.d.ts → context-kb33TgzE.d.ts} +82 -58
- package/dist/cookie-stores/index.cjs +21 -150
- package/dist/cookie-stores/index.d.cts +4 -63
- package/dist/cookie-stores/index.d.ts +4 -63
- package/dist/cookie-stores/index.js +3 -144
- package/dist/create-CflXrPip.js +204 -0
- package/dist/create-CvUvLUaT.cjs +257 -0
- package/dist/{create-once-DgMtKKcG.cjs → create-once-9yxR_Er_.cjs} +285 -33
- package/dist/create-once-Bh6fOWkW.d.cts +20 -0
- package/dist/{create-once-Cz621l8r.js → create-once-Ca2gMk1h.js} +250 -34
- package/dist/create-once-VKp0tVow.d.ts +20 -0
- package/dist/data-link/index.cjs +4 -4
- package/dist/data-link/index.d.cts +2 -52
- package/dist/data-link/index.d.ts +2 -52
- package/dist/data-link/index.js +4 -4
- package/dist/delegation/index.cjs +4 -4
- package/dist/delegation/index.d.cts +2 -2
- package/dist/delegation/index.d.ts +2 -2
- package/dist/delegation/index.js +4 -4
- package/dist/{errors-DLrb0g64.js → errors-DtN4g5Z9.js} +9 -1
- package/dist/{errors-DxeuTslP.cjs → errors-EE96_6D_.cjs} +20 -0
- package/dist/{get-Csm2n0rZ.cjs → get-BdMTseh4.cjs} +9 -183
- package/dist/{get-DT3JEgQ6.js → get-CZEShCcj.js} +4 -124
- package/dist/index-BhUPY_EH.d.cts +109 -0
- package/dist/index-BqGgQ4t3.d.ts +109 -0
- package/dist/{index-CYAGCdKJ.d.cts → index-C-7yWV7L.d.cts} +24 -1
- package/dist/{index-CYAGCdKJ.d.ts → index-C-7yWV7L.d.ts} +24 -1
- package/dist/index.cjs +19 -5
- package/dist/index.d.cts +10 -20
- package/dist/index.d.ts +10 -20
- package/dist/index.js +6 -6
- package/dist/ipn/index.cjs +26 -5
- package/dist/ipn/index.d.cts +12 -1
- package/dist/ipn/index.d.ts +12 -1
- package/dist/ipn/index.js +26 -6
- package/dist/{issue-AGRohSm7.cjs → issue-Bin4tKD_.cjs} +416 -342
- package/dist/{issue-DtSLpVdJ.js → issue-DMA1Nbr1.js} +394 -266
- package/dist/journal/index.cjs +454 -0
- package/dist/journal/index.d.cts +18 -0
- package/dist/journal/index.d.ts +18 -0
- package/dist/journal/index.js +445 -0
- package/dist/journal-DvI81Kt7.d.cts +114 -0
- package/dist/journal-Y9qrIB8G.d.ts +114 -0
- package/dist/mcp/index.cjs +1 -1
- package/dist/mcp/index.d.cts +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/money/index.cjs +2 -1
- package/dist/money/index.d.cts +2 -2
- package/dist/money/index.d.ts +2 -2
- package/dist/money/index.js +2 -2
- package/dist/{money-t7uy1n91.js → money-Cw457SD6.js} +95 -3
- package/dist/{money-BxytJW6f.cjs → money-K9j0wPit.cjs} +99 -1
- package/dist/nav/index.cjs +2 -2
- package/dist/nav/index.d.cts +1 -1
- package/dist/nav/index.d.ts +1 -1
- package/dist/nav/index.js +2 -2
- package/dist/{nav-BEwcX7-N.cjs → nav-BNbc8U0R.cjs} +1 -1
- package/dist/{nav-CK1WgYo7.js → nav-BcCerwWS.js} +1 -1
- package/dist/node/index.cjs +124 -0
- package/dist/node/index.d.cts +35 -0
- package/dist/node/index.d.ts +35 -0
- package/dist/node/index.js +120 -0
- package/dist/observe/index.cjs +311 -0
- package/dist/observe/index.d.cts +53 -0
- package/dist/observe/index.d.ts +53 -0
- package/dist/observe/index.js +303 -0
- package/dist/once-BN_3B5OF.cjs +103 -0
- package/dist/once-CqqZxsXG.js +74 -0
- package/dist/{parse-C608ehqM.js → parse-Cr7yQ3_z.js} +2 -2
- package/dist/{parse-BJj-aqKy.cjs → parse-DOA2XQ3e.cjs} +2 -2
- package/dist/payments/barion.cjs +26 -2
- package/dist/payments/barion.d.cts +2 -2
- package/dist/payments/barion.d.ts +2 -2
- package/dist/payments/barion.js +26 -2
- package/dist/payments/index.cjs +7 -2
- package/dist/payments/index.d.cts +4 -4
- package/dist/payments/index.d.ts +4 -4
- package/dist/payments/index.js +3 -3
- package/dist/payments/paypal.cjs +16 -2
- package/dist/payments/paypal.d.cts +2 -2
- package/dist/payments/paypal.d.ts +2 -2
- package/dist/payments/paypal.js +16 -2
- package/dist/payments/revolut.cjs +16 -2
- package/dist/payments/revolut.d.cts +2 -2
- package/dist/payments/revolut.d.ts +2 -2
- package/dist/payments/revolut.js +16 -2
- package/dist/payments/simplepay.cjs +36 -4
- package/dist/payments/simplepay.d.cts +2 -2
- package/dist/payments/simplepay.d.ts +2 -2
- package/dist/payments/simplepay.js +36 -4
- package/dist/payments/stripe.cjs +19 -2
- package/dist/payments/stripe.d.cts +2 -2
- package/dist/payments/stripe.d.ts +2 -2
- package/dist/payments/stripe.js +19 -2
- package/dist/push-BXj0Sf0Z.d.ts +52 -0
- package/dist/push-D4nNbCNV.d.cts +52 -0
- package/dist/reference-B5TATqb5.js +124 -0
- package/dist/reference-BIdYMK0t.cjs +183 -0
- package/dist/reports/index.cjs +1 -1
- package/dist/reports/index.d.cts +1 -1
- package/dist/reports/index.d.ts +1 -1
- package/dist/reports/index.js +1 -1
- package/dist/{serialize-DSE_o9RK.js → serialize-B2eFh3D-.js} +5 -1
- package/dist/{serialize-BXOww1Uq.cjs → serialize-CquIsxA-.cjs} +5 -1
- package/dist/{server-Cd8HB661.js → server-BrJUbXs7.js} +8 -7
- package/dist/{server-C6PoNkdD.cjs → server-Dw9j8Mnd.cjs} +17 -16
- package/dist/session-Ckl5eJhV.d.ts +7 -0
- package/dist/{session-CKOuE6Jc.cjs → session-DeM5vjvC.cjs} +69 -13
- package/dist/{session-rMKaJcmq.js → session-SaEEXu2N.js} +58 -14
- package/dist/session-YbChChx7.d.cts +7 -0
- package/dist/storage/fs.cjs +1 -1
- package/dist/storage/fs.js +1 -1
- package/dist/storage/index.cjs +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/store-C1rHd9DB.d.cts +19 -0
- package/dist/store-C1rHd9DB.d.ts +19 -0
- package/dist/stores/index.cjs +24 -0
- package/dist/stores/index.d.cts +4 -0
- package/dist/stores/index.d.ts +4 -0
- package/dist/stores/index.js +3 -0
- package/dist/stores-BNrS0dWl.cjs +506 -0
- package/dist/stores-DhjGBrl_.js +441 -0
- package/dist/testing/index.cjs +28 -16
- package/dist/testing/index.d.cts +6 -3
- package/dist/testing/index.d.ts +6 -3
- package/dist/testing/index.js +26 -14
- package/dist/{types-BVeR7KyU.d.ts → types-B1A8mUIE.d.cts} +13 -1
- package/dist/{types-BVeR7KyU.d.cts → types-ByAEvGsZ.d.ts} +13 -1
- package/dist/{types-k--zHf4l.d.ts → types-D1zDOH_F.d.ts} +1 -1
- package/dist/{types-DH8QoNZK.d.cts → types-lnKkQdot.d.cts} +1 -1
- package/dist/warnings-B3DXnveC.d.cts +31 -0
- package/dist/warnings-B3DXnveC.d.ts +31 -0
- package/dist/warnings-DeIw5RFj.cjs +20 -0
- package/dist/warnings-DwTl5J-2.js +15 -0
- package/dist/{webhook-CrEGohbg.js → webhook-CQVShAfI.js} +44 -1
- package/dist/{webhook-81giRMdQ.cjs → webhook-Ckj-_hPD.cjs} +67 -0
- package/dist/webhook-CmdhGiH5.d.cts +11 -0
- package/dist/webhook-D6lEejob.d.ts +11 -0
- package/llms.txt +4 -3
- package/package.json +92 -4
- package/dist/session-Dm_45x8K.d.cts +0 -11
- package/dist/session-Dm_45x8K.d.ts +0 -11
- package/dist/webhook-CpCMHhn2.d.ts +0 -6
- package/dist/webhook-CpMJuP6c.d.cts +0 -6
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { r as SzamlazzError } from "../errors-DtN4g5Z9.js";
|
|
2
|
+
import { n as isUncertainOutcome } from "../once-CqqZxsXG.js";
|
|
3
|
+
import { i as toBudapestTimestamp, n as toAgentDate, t as addBudapestDays } from "../dates-CXyj7Azy.js";
|
|
4
|
+
//#region src/journal/dates.ts
|
|
5
|
+
const MAX_JOURNAL_RANGE_DAYS = 366;
|
|
6
|
+
const DAY_IN_MS = 864e5;
|
|
7
|
+
function invalid(message) {
|
|
8
|
+
return new SzamlazzError(message, { category: "validation" });
|
|
9
|
+
}
|
|
10
|
+
function parseDay(value, field) {
|
|
11
|
+
try {
|
|
12
|
+
return toAgentDate(value);
|
|
13
|
+
} catch {
|
|
14
|
+
throw invalid(`A napló ${field} dátuma YYYY-MM-DD formájú legyen, kapott: ${value}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function dayNumber(day) {
|
|
18
|
+
return Date.parse(`${day}T00:00:00Z`) / DAY_IN_MS;
|
|
19
|
+
}
|
|
20
|
+
function normalizeRange(range) {
|
|
21
|
+
const from = parseDay(range.from, "from");
|
|
22
|
+
const to = parseDay(range.to, "to");
|
|
23
|
+
const span = dayNumber(to) - dayNumber(from) + 1;
|
|
24
|
+
if (span < 1) throw invalid(`A napló időszakának kezdete (${from}) később van, mint a vége (${to}).`);
|
|
25
|
+
if (span > 366) throw invalid(`A napló egyszerre legfeljebb 366 napot kérdez le, kapott: ${span} nap.`);
|
|
26
|
+
return {
|
|
27
|
+
from,
|
|
28
|
+
to
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function daysOf(range) {
|
|
32
|
+
const { from, to } = normalizeRange(range);
|
|
33
|
+
const days = [];
|
|
34
|
+
const last = dayNumber(to);
|
|
35
|
+
for (let day = dayNumber(from); day <= last; day++) days.push((/* @__PURE__ */ new Date(day * DAY_IN_MS)).toISOString().slice(0, 10));
|
|
36
|
+
return days;
|
|
37
|
+
}
|
|
38
|
+
function inRange(day, range) {
|
|
39
|
+
return day >= range.from && day <= range.to;
|
|
40
|
+
}
|
|
41
|
+
function recentRange(now, days) {
|
|
42
|
+
return {
|
|
43
|
+
from: addBudapestDays(now, -(days - 1)),
|
|
44
|
+
to: toAgentDate(now)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/journal/entries.ts
|
|
49
|
+
function withoutPdf(receipt) {
|
|
50
|
+
if (receipt.pdf === void 0) return receipt;
|
|
51
|
+
const { pdf: _pdf, ...rest } = receipt;
|
|
52
|
+
return rest;
|
|
53
|
+
}
|
|
54
|
+
function compact(value) {
|
|
55
|
+
return Object.fromEntries(Object.entries(value).filter(([, field]) => field !== void 0));
|
|
56
|
+
}
|
|
57
|
+
function inputDate(value, fallback) {
|
|
58
|
+
if (value instanceof Date || typeof value === "string") try {
|
|
59
|
+
return toAgentDate(value);
|
|
60
|
+
} catch {
|
|
61
|
+
return fallback;
|
|
62
|
+
}
|
|
63
|
+
return fallback;
|
|
64
|
+
}
|
|
65
|
+
function receiptEntry(receipt, source, now) {
|
|
66
|
+
const reversal = receipt.type === "reversal";
|
|
67
|
+
return compact({
|
|
68
|
+
kind: "receipt",
|
|
69
|
+
type: reversal ? "reversal" : "document",
|
|
70
|
+
number: receipt.number,
|
|
71
|
+
date: inputDate(receipt.issueDate, toAgentDate(now)),
|
|
72
|
+
recordedAt: toBudapestTimestamp(now),
|
|
73
|
+
source,
|
|
74
|
+
orderNumber: receipt.orderNumber,
|
|
75
|
+
reversedNumber: reversal ? receipt.reversedReceiptNumber : void 0,
|
|
76
|
+
netTotal: receipt.totals.netAmount,
|
|
77
|
+
grossTotal: receipt.totals.grossAmount,
|
|
78
|
+
currency: receipt.currency,
|
|
79
|
+
isTest: receipt.isTest,
|
|
80
|
+
receipt: withoutPdf(receipt)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function invoiceDetailsEntry(details, source, now) {
|
|
84
|
+
const reversal = details.header.type === "reversal";
|
|
85
|
+
return compact({
|
|
86
|
+
kind: "invoice",
|
|
87
|
+
type: reversal ? "reversal" : "document",
|
|
88
|
+
number: details.header.number,
|
|
89
|
+
date: inputDate(details.header.issueDate, toAgentDate(now)),
|
|
90
|
+
recordedAt: toBudapestTimestamp(now),
|
|
91
|
+
source,
|
|
92
|
+
orderNumber: details.header.orderNumber,
|
|
93
|
+
reversedNumber: reversal ? details.header.referencedInvoiceNumber : void 0,
|
|
94
|
+
netTotal: details.totals.netAmount,
|
|
95
|
+
grossTotal: details.totals.grossAmount,
|
|
96
|
+
currency: details.header.currency,
|
|
97
|
+
isTest: details.header.test
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function invoiceResultEntry(result, orderNumber, source, now) {
|
|
101
|
+
if (result.details) return invoiceDetailsEntry(result.details, source, now);
|
|
102
|
+
return compact({
|
|
103
|
+
kind: "invoice",
|
|
104
|
+
type: "document",
|
|
105
|
+
number: result.number,
|
|
106
|
+
date: toAgentDate(now),
|
|
107
|
+
recordedAt: toBudapestTimestamp(now),
|
|
108
|
+
source,
|
|
109
|
+
orderNumber,
|
|
110
|
+
netTotal: result.invoice?.netTotal,
|
|
111
|
+
grossTotal: result.invoice?.grossTotal
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function eventEntry(event, now) {
|
|
115
|
+
const today = toAgentDate(now);
|
|
116
|
+
const recordedAt = toBudapestTimestamp(now);
|
|
117
|
+
if (event.kind === "receipt") return receiptEntry(event.document, "hook", now);
|
|
118
|
+
if (event.action === "payment") return void 0;
|
|
119
|
+
if (event.action === "created") return compact({
|
|
120
|
+
kind: "invoice",
|
|
121
|
+
type: "document",
|
|
122
|
+
number: event.number,
|
|
123
|
+
date: inputDate(event.input.issueDate, today),
|
|
124
|
+
recordedAt,
|
|
125
|
+
source: "hook",
|
|
126
|
+
orderNumber: event.input.orderNumber?.trim() || void 0,
|
|
127
|
+
netTotal: event.document.netTotal,
|
|
128
|
+
grossTotal: event.document.grossTotal,
|
|
129
|
+
currency: event.input.currency
|
|
130
|
+
});
|
|
131
|
+
return compact({
|
|
132
|
+
kind: "invoice",
|
|
133
|
+
type: "reversal",
|
|
134
|
+
number: event.number,
|
|
135
|
+
date: today,
|
|
136
|
+
recordedAt,
|
|
137
|
+
source: "hook",
|
|
138
|
+
reversedNumber: event.reversedNumber,
|
|
139
|
+
netTotal: event.document.netTotal,
|
|
140
|
+
grossTotal: event.document.grossTotal
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/journal/journal.ts
|
|
145
|
+
const DEFAULT_PENDING_DAYS = 30;
|
|
146
|
+
var JournalWriteError = class extends Error {
|
|
147
|
+
name = "JournalWriteError";
|
|
148
|
+
result;
|
|
149
|
+
orderNumber;
|
|
150
|
+
constructor(orderNumber, result, cause) {
|
|
151
|
+
super(`A(z) ${orderNumber} rendelés bizonylata elkészült, de a naplóba írás nem sikerült. A tétel befejezetlenként a naplóban maradt: a journal.settle() később pótolja. Ne állítsd ki újra a bizonylatot.`, { cause });
|
|
152
|
+
this.orderNumber = orderNumber;
|
|
153
|
+
this.result = result;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
function requireOrderNumber(orderNumber) {
|
|
157
|
+
const trimmed = orderNumber?.trim();
|
|
158
|
+
if (!trimmed) throw new SzamlazzError("A naplóhoz add meg a rendelésszámot (orderNumber).", { category: "validation" });
|
|
159
|
+
return trimmed;
|
|
160
|
+
}
|
|
161
|
+
const UNSETTLED_CATEGORIES = /* @__PURE__ */ new Set(["in_progress", "store_unavailable"]);
|
|
162
|
+
function isDefinitelyNotCreated(error) {
|
|
163
|
+
if (!(error instanceof SzamlazzError)) return false;
|
|
164
|
+
return !isUncertainOutcome(error) && !UNSETTLED_CATEGORIES.has(error.category) && error.details?.outcome !== "unknown";
|
|
165
|
+
}
|
|
166
|
+
function archivedReceipt(item) {
|
|
167
|
+
return "receipt" in item && typeof item.receipt === "object" ? item.receipt : item;
|
|
168
|
+
}
|
|
169
|
+
function archiveRange(receipts) {
|
|
170
|
+
const dates = receipts.map((receipt) => receipt.issueDate).filter((date) => /^\d{4}-\d{2}-\d{2}$/.test(date));
|
|
171
|
+
if (dates.length === 0) return void 0;
|
|
172
|
+
const sorted = [...dates].sort();
|
|
173
|
+
return {
|
|
174
|
+
from: sorted[0],
|
|
175
|
+
to: sorted[sorted.length - 1]
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function createJournal(storage, options = {}) {
|
|
179
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
180
|
+
const put = (entry) => entry ? storage.putEntry(entry) : Promise.resolve(false);
|
|
181
|
+
async function reserve(kind, orderNumber) {
|
|
182
|
+
const current = now();
|
|
183
|
+
return storage.putReservation({
|
|
184
|
+
kind,
|
|
185
|
+
orderNumber: requireOrderNumber(orderNumber),
|
|
186
|
+
date: toAgentDate(current),
|
|
187
|
+
reservedAt: toBudapestTimestamp(current)
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
async function release(kind, orderNumber) {
|
|
191
|
+
await storage.deleteReservation(kind, requireOrderNumber(orderNumber));
|
|
192
|
+
}
|
|
193
|
+
async function track(kind, orderNumber, run, entryOf) {
|
|
194
|
+
const order = requireOrderNumber(orderNumber);
|
|
195
|
+
const ownsReservation = await reserve(kind, order);
|
|
196
|
+
let result;
|
|
197
|
+
try {
|
|
198
|
+
result = await run();
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (ownsReservation && isDefinitelyNotCreated(error)) await storage.deleteReservation(kind, order);
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
await storage.putEntry(entryOf(result));
|
|
205
|
+
await storage.deleteReservation(kind, order);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
throw new JournalWriteError(order, result, error);
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
async function settleOne(api, reservation) {
|
|
212
|
+
if (reservation.kind === "receipt") {
|
|
213
|
+
if (!api.receipts) throw new TypeError("A nyugták rendezéséhez add meg a receipts API-t.");
|
|
214
|
+
const receipt = await api.receipts.find({
|
|
215
|
+
orderNumber: reservation.orderNumber,
|
|
216
|
+
downloadPdf: false
|
|
217
|
+
});
|
|
218
|
+
if (!receipt) return "notFound";
|
|
219
|
+
await storage.putEntry(receiptEntry(receipt, "settle", now()));
|
|
220
|
+
return "recorded";
|
|
221
|
+
}
|
|
222
|
+
if (!api.invoices) throw new TypeError("A számlák rendezéséhez add meg az invoices API-t.");
|
|
223
|
+
const details = await api.invoices.find({ orderNumber: reservation.orderNumber });
|
|
224
|
+
if (!details) return "notFound";
|
|
225
|
+
await storage.putEntry(invoiceDetailsEntry(details, "settle", now()));
|
|
226
|
+
return "recorded";
|
|
227
|
+
}
|
|
228
|
+
const journal = {
|
|
229
|
+
storage,
|
|
230
|
+
async record(event) {
|
|
231
|
+
await put(eventEntry(event, now()));
|
|
232
|
+
},
|
|
233
|
+
recordReceipt: (receipt) => storage.putEntry(receiptEntry(receipt, "manual", now())),
|
|
234
|
+
recordInvoice: (details) => storage.putEntry(invoiceDetailsEntry(details, "manual", now())),
|
|
235
|
+
reserve,
|
|
236
|
+
release,
|
|
237
|
+
trackReceipt: (orderNumber, run) => track("receipt", orderNumber, run, (result) => receiptEntry("receipt" in result ? result.receipt : result, "track", now())),
|
|
238
|
+
trackInvoice: (orderNumber, run) => track("invoice", orderNumber, run, (result) => invoiceResultEntry(result, requireOrderNumber(orderNumber), "track", now())),
|
|
239
|
+
async entries(query) {
|
|
240
|
+
return (await storage.listEntries(normalizeRange(query))).filter((entry) => query.kind === void 0 || entry.kind === query.kind).sort((a, b) => a.date.localeCompare(b.date) || a.number.localeCompare(b.number, "hu"));
|
|
241
|
+
},
|
|
242
|
+
async receipts(query) {
|
|
243
|
+
return (await journal.entries({
|
|
244
|
+
...query,
|
|
245
|
+
kind: "receipt"
|
|
246
|
+
})).map((entry) => entry.receipt).filter((receipt) => receipt !== void 0).filter((receipt) => query.includeTest === true || !receipt.isTest);
|
|
247
|
+
},
|
|
248
|
+
async pending(range) {
|
|
249
|
+
return storage.listReservations(range ?? recentRange(now(), 30));
|
|
250
|
+
},
|
|
251
|
+
async settle(api, settleOptions = {}) {
|
|
252
|
+
const reservations = await journal.pending(settleOptions.range);
|
|
253
|
+
const recorded = [];
|
|
254
|
+
const notFound = [];
|
|
255
|
+
const failed = [];
|
|
256
|
+
for (const reservation of reservations) try {
|
|
257
|
+
const outcome = await settleOne(api, reservation);
|
|
258
|
+
if (outcome === "recorded" || settleOptions.releaseNotFound === true) await storage.deleteReservation(reservation.kind, reservation.orderNumber);
|
|
259
|
+
if (outcome === "recorded") recorded.push(reservation);
|
|
260
|
+
else notFound.push(reservation);
|
|
261
|
+
} catch (error) {
|
|
262
|
+
failed.push({
|
|
263
|
+
reservation,
|
|
264
|
+
error
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
recorded,
|
|
269
|
+
notFound,
|
|
270
|
+
failed
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
async reconcile(archive, reconcileOptions = {}) {
|
|
274
|
+
const receipts = archive.map(archivedReceipt);
|
|
275
|
+
const derived = archiveRange(receipts);
|
|
276
|
+
const range = reconcileOptions.from !== void 0 || reconcileOptions.to !== void 0 ? normalizeRange({
|
|
277
|
+
from: reconcileOptions.from ?? derived?.from ?? reconcileOptions.to ?? "",
|
|
278
|
+
to: reconcileOptions.to ?? derived?.to ?? reconcileOptions.from ?? ""
|
|
279
|
+
}) : derived;
|
|
280
|
+
const journaled = range ? await journal.entries({
|
|
281
|
+
...range,
|
|
282
|
+
kind: "receipt"
|
|
283
|
+
}) : [];
|
|
284
|
+
const known = new Set(journaled.map((entry) => entry.number));
|
|
285
|
+
const archived = /* @__PURE__ */ new Set();
|
|
286
|
+
const added = [];
|
|
287
|
+
for (const receipt of receipts) {
|
|
288
|
+
if (archived.has(receipt.number)) continue;
|
|
289
|
+
archived.add(receipt.number);
|
|
290
|
+
if (range && !inRange(receipt.issueDate, range)) continue;
|
|
291
|
+
if (known.has(receipt.number)) continue;
|
|
292
|
+
if (reconcileOptions.dryRun !== true) await storage.putEntry(receiptEntry(receipt, "reconcile", now()));
|
|
293
|
+
added.push(receipt.number);
|
|
294
|
+
}
|
|
295
|
+
const missingFromArchive = journaled.map((entry) => entry.number).filter((number) => !archived.has(number));
|
|
296
|
+
return {
|
|
297
|
+
range,
|
|
298
|
+
added,
|
|
299
|
+
missingFromArchive,
|
|
300
|
+
matched: journaled.length - missingFromArchive.length
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
return journal;
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/journal/storage.ts
|
|
308
|
+
const JOURNAL_KEY_PREFIX = "szamlazz:journal:";
|
|
309
|
+
const DEFAULT_JOURNAL_RETENTION_DAYS = 400;
|
|
310
|
+
const DEFAULT_RESERVATION_TTL_DAYS = 30;
|
|
311
|
+
const DAY_IN_SECONDS = 86400;
|
|
312
|
+
const READ_BATCH = 50;
|
|
313
|
+
function configurationError(message) {
|
|
314
|
+
return new SzamlazzError(message, { category: "configuration" });
|
|
315
|
+
}
|
|
316
|
+
function positiveDays(value, fallback, field) {
|
|
317
|
+
if (value === void 0) return fallback;
|
|
318
|
+
if (!Number.isFinite(value) || value < 1) throw configurationError(`A(z) ${field} legalább 1 nap legyen, kapott: ${String(value)}`);
|
|
319
|
+
return Math.ceil(value);
|
|
320
|
+
}
|
|
321
|
+
function parseJson(value, guard) {
|
|
322
|
+
if (typeof value !== "string" || value === "") return void 0;
|
|
323
|
+
try {
|
|
324
|
+
const parsed = JSON.parse(value);
|
|
325
|
+
return guard(parsed) ? parsed : void 0;
|
|
326
|
+
} catch {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function isEntry(value) {
|
|
331
|
+
if (typeof value !== "object" || value === null) return false;
|
|
332
|
+
const entry = value;
|
|
333
|
+
return (entry.kind === "invoice" || entry.kind === "receipt") && typeof entry.number === "string" && typeof entry.date === "string";
|
|
334
|
+
}
|
|
335
|
+
function isReservation(value) {
|
|
336
|
+
if (typeof value !== "object" || value === null) return false;
|
|
337
|
+
const reservation = value;
|
|
338
|
+
return (reservation.kind === "invoice" || reservation.kind === "receipt") && typeof reservation.orderNumber === "string" && typeof reservation.date === "string";
|
|
339
|
+
}
|
|
340
|
+
function slotTarget(value) {
|
|
341
|
+
if (typeof value !== "string") return void 0;
|
|
342
|
+
const separator = value.indexOf(":");
|
|
343
|
+
if (separator <= 0) return void 0;
|
|
344
|
+
const kind = value.slice(0, separator);
|
|
345
|
+
if (kind !== "invoice" && kind !== "receipt") return void 0;
|
|
346
|
+
return [kind, value.slice(separator + 1)];
|
|
347
|
+
}
|
|
348
|
+
async function inBatches(items, run) {
|
|
349
|
+
const results = [];
|
|
350
|
+
for (let index = 0; index < items.length; index += READ_BATCH) results.push(...await Promise.all(items.slice(index, index + READ_BATCH).map(run)));
|
|
351
|
+
return results;
|
|
352
|
+
}
|
|
353
|
+
function kvJournal(store, options = {}) {
|
|
354
|
+
const increment = store.increment?.bind(store);
|
|
355
|
+
if (!increment) throw configurationError("A naplóhoz olyan tároló kell, amely atomikusan tud számlálót növelni (increment), különben párhuzamos írásnál bejegyzés veszhet el. Használd a kassza/stores Redis, Upstash vagy Durable Object tárolóját. A Cloudflare KV erre nem alkalmas.");
|
|
356
|
+
const prefix = options.prefix ?? "szamlazz:journal:";
|
|
357
|
+
const retention = positiveDays(options.retentionDays, 400, "retentionDays") * DAY_IN_SECONDS;
|
|
358
|
+
const reservationTtl = positiveDays(options.reservationTtlDays, 30, "reservationTtlDays") * DAY_IN_SECONDS;
|
|
359
|
+
const entryKey = (kind, number) => `${prefix}entry:${kind}:${number}`;
|
|
360
|
+
const reservationKey = (kind, orderNumber) => `${prefix}reservation:${kind}:${orderNumber}`;
|
|
361
|
+
async function appendToDay(index, day, target, ttl) {
|
|
362
|
+
const slot = await increment?.(`${prefix}${index}:${day}:count`, ttl);
|
|
363
|
+
await store.set(`${prefix}${index}:${day}:${slot}`, target, ttl);
|
|
364
|
+
}
|
|
365
|
+
async function slotsOf(index, range) {
|
|
366
|
+
const targets = [];
|
|
367
|
+
for (const day of daysOf(range)) {
|
|
368
|
+
const count = Number.parseInt(await store.get(`${prefix}${index}:${day}:count`) ?? "0", 10);
|
|
369
|
+
if (!Number.isInteger(count) || count < 1) continue;
|
|
370
|
+
const slots = Array.from({ length: count }, (_, slot) => `${prefix}${index}:${day}:${slot + 1}`);
|
|
371
|
+
for (const value of await inBatches(slots, async (key) => store.get(key))) if (typeof value === "string") targets.push(value);
|
|
372
|
+
}
|
|
373
|
+
return [...new Set(targets)];
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
async getEntry(kind, number) {
|
|
377
|
+
return parseJson(await store.get(entryKey(kind, number)), isEntry);
|
|
378
|
+
},
|
|
379
|
+
async putEntry(entry) {
|
|
380
|
+
const key = entryKey(entry.kind, entry.number);
|
|
381
|
+
const existing = await store.get(key);
|
|
382
|
+
if (existing !== void 0 && existing !== null) return false;
|
|
383
|
+
await appendToDay("day", entry.date, `${entry.kind}:${entry.number}`, retention);
|
|
384
|
+
const value = JSON.stringify(entry);
|
|
385
|
+
if (store.setIfAbsent) return store.setIfAbsent(key, value, retention);
|
|
386
|
+
await store.set(key, value, retention);
|
|
387
|
+
return true;
|
|
388
|
+
},
|
|
389
|
+
async listEntries(range) {
|
|
390
|
+
const normalized = normalizeRange(range);
|
|
391
|
+
return (await inBatches((await slotsOf("day", normalized)).map(slotTarget).filter((t) => t !== void 0), async ([kind, number]) => parseJson(await store.get(entryKey(kind, number)), isEntry))).filter((entry) => entry !== void 0 && inRange(entry.date, normalized));
|
|
392
|
+
},
|
|
393
|
+
async putReservation(reservation) {
|
|
394
|
+
const key = reservationKey(reservation.kind, reservation.orderNumber);
|
|
395
|
+
const value = JSON.stringify(reservation);
|
|
396
|
+
await appendToDay("rday", reservation.date, `${reservation.kind}:${reservation.orderNumber}`, reservationTtl);
|
|
397
|
+
if (store.setIfAbsent) return store.setIfAbsent(key, value, reservationTtl);
|
|
398
|
+
const existing = await store.get(key);
|
|
399
|
+
if (existing !== void 0 && existing !== null) return false;
|
|
400
|
+
await store.set(key, value, reservationTtl);
|
|
401
|
+
return true;
|
|
402
|
+
},
|
|
403
|
+
async deleteReservation(kind, orderNumber) {
|
|
404
|
+
await store.delete(reservationKey(kind, orderNumber));
|
|
405
|
+
},
|
|
406
|
+
async listReservations(range) {
|
|
407
|
+
return (await inBatches((await slotsOf("rday", normalizeRange(range))).map(slotTarget).filter((t) => t !== void 0), async ([kind, orderNumber]) => parseJson(await store.get(reservationKey(kind, orderNumber)), isReservation))).filter((reservation) => reservation !== void 0);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function memoryJournal() {
|
|
412
|
+
const entries = /* @__PURE__ */ new Map();
|
|
413
|
+
const reservations = /* @__PURE__ */ new Map();
|
|
414
|
+
const key = (kind, id) => `${kind}:${id}`;
|
|
415
|
+
return {
|
|
416
|
+
async getEntry(kind, number) {
|
|
417
|
+
return entries.get(key(kind, number));
|
|
418
|
+
},
|
|
419
|
+
async putEntry(entry) {
|
|
420
|
+
const id = key(entry.kind, entry.number);
|
|
421
|
+
if (entries.has(id)) return false;
|
|
422
|
+
entries.set(id, entry);
|
|
423
|
+
return true;
|
|
424
|
+
},
|
|
425
|
+
async listEntries(range) {
|
|
426
|
+
const normalized = normalizeRange(range);
|
|
427
|
+
return [...entries.values()].filter((entry) => inRange(entry.date, normalized));
|
|
428
|
+
},
|
|
429
|
+
async putReservation(reservation) {
|
|
430
|
+
const id = key(reservation.kind, reservation.orderNumber);
|
|
431
|
+
if (reservations.has(id)) return false;
|
|
432
|
+
reservations.set(id, reservation);
|
|
433
|
+
return true;
|
|
434
|
+
},
|
|
435
|
+
async deleteReservation(kind, orderNumber) {
|
|
436
|
+
reservations.delete(key(kind, orderNumber));
|
|
437
|
+
},
|
|
438
|
+
async listReservations(range) {
|
|
439
|
+
const normalized = normalizeRange(range);
|
|
440
|
+
return [...reservations.values()].filter((reservation) => inRange(reservation.date, normalized));
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
//#endregion
|
|
445
|
+
export { DEFAULT_JOURNAL_RETENTION_DAYS, DEFAULT_PENDING_DAYS, DEFAULT_RESERVATION_TTL_DAYS, JOURNAL_KEY_PREFIX, JournalWriteError, MAX_JOURNAL_RANGE_DAYS, createJournal, kvJournal, memoryJournal };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { f as DocumentEvent } from "./context-CFNKzStE.cjs";
|
|
2
|
+
import { r as Receipt } from "./types-lnKkQdot.cjs";
|
|
3
|
+
import { n as InvoiceDetails } from "./get-Byc9T5WO.cjs";
|
|
4
|
+
import { n as InvoiceOnceResult, t as ReceiptOnceResult } from "./create-once-Bh6fOWkW.cjs";
|
|
5
|
+
import { t as DataLinkArchivedReceipt } from "./push-D4nNbCNV.cjs";
|
|
6
|
+
//#region src/journal/types.d.ts
|
|
7
|
+
type JournalDocumentKind = "invoice" | "receipt";
|
|
8
|
+
type JournalEntryType = "document" | "reversal";
|
|
9
|
+
type JournalEntrySource = "hook" | "track" | "reconcile" | "settle" | "manual";
|
|
10
|
+
interface JournalEntry {
|
|
11
|
+
readonly kind: JournalDocumentKind;
|
|
12
|
+
readonly type: JournalEntryType;
|
|
13
|
+
readonly number: string;
|
|
14
|
+
readonly date: string;
|
|
15
|
+
readonly recordedAt: string;
|
|
16
|
+
readonly source: JournalEntrySource;
|
|
17
|
+
readonly orderNumber?: string | undefined;
|
|
18
|
+
readonly reversedNumber?: string | undefined;
|
|
19
|
+
readonly netTotal?: number | undefined;
|
|
20
|
+
readonly grossTotal?: number | undefined;
|
|
21
|
+
readonly currency?: string | undefined;
|
|
22
|
+
readonly isTest?: boolean | undefined;
|
|
23
|
+
readonly receipt?: Receipt | undefined;
|
|
24
|
+
}
|
|
25
|
+
interface JournalReservation {
|
|
26
|
+
readonly kind: JournalDocumentKind;
|
|
27
|
+
readonly orderNumber: string;
|
|
28
|
+
readonly date: string;
|
|
29
|
+
readonly reservedAt: string;
|
|
30
|
+
}
|
|
31
|
+
interface JournalRange {
|
|
32
|
+
readonly from: string;
|
|
33
|
+
readonly to: string;
|
|
34
|
+
}
|
|
35
|
+
interface JournalStorage {
|
|
36
|
+
getEntry(kind: JournalDocumentKind, number: string): Promise<JournalEntry | undefined>;
|
|
37
|
+
putEntry(entry: JournalEntry): Promise<boolean>;
|
|
38
|
+
listEntries(range: JournalRange): Promise<JournalEntry[]>;
|
|
39
|
+
putReservation(reservation: JournalReservation): Promise<boolean>;
|
|
40
|
+
deleteReservation(kind: JournalDocumentKind, orderNumber: string): Promise<void>;
|
|
41
|
+
listReservations(range: JournalRange): Promise<JournalReservation[]>;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/journal/journal.d.ts
|
|
45
|
+
declare const DEFAULT_PENDING_DAYS = 30;
|
|
46
|
+
declare class JournalWriteError extends Error {
|
|
47
|
+
override readonly name: string;
|
|
48
|
+
readonly result: unknown;
|
|
49
|
+
readonly orderNumber: string;
|
|
50
|
+
constructor(orderNumber: string, result: unknown, cause: unknown);
|
|
51
|
+
}
|
|
52
|
+
interface JournalOptions {
|
|
53
|
+
readonly now?: (() => Date) | undefined;
|
|
54
|
+
}
|
|
55
|
+
interface JournalEntryQuery extends JournalRange {
|
|
56
|
+
readonly kind?: JournalDocumentKind | undefined;
|
|
57
|
+
}
|
|
58
|
+
interface JournalReceiptQuery extends JournalRange {
|
|
59
|
+
readonly includeTest?: boolean | undefined;
|
|
60
|
+
}
|
|
61
|
+
interface JournalReconcileOptions {
|
|
62
|
+
readonly from?: string | undefined;
|
|
63
|
+
readonly to?: string | undefined;
|
|
64
|
+
readonly dryRun?: boolean | undefined;
|
|
65
|
+
}
|
|
66
|
+
interface JournalReconciliation {
|
|
67
|
+
readonly range: JournalRange | undefined;
|
|
68
|
+
readonly added: readonly string[];
|
|
69
|
+
readonly missingFromArchive: readonly string[];
|
|
70
|
+
readonly matched: number;
|
|
71
|
+
}
|
|
72
|
+
interface JournalSettleApi {
|
|
73
|
+
readonly invoices?: {
|
|
74
|
+
find(reference: {
|
|
75
|
+
readonly orderNumber: string;
|
|
76
|
+
}): Promise<InvoiceDetails | null>;
|
|
77
|
+
};
|
|
78
|
+
readonly receipts?: {
|
|
79
|
+
find(input: {
|
|
80
|
+
readonly orderNumber: string;
|
|
81
|
+
readonly downloadPdf?: boolean;
|
|
82
|
+
}): Promise<Receipt | null>;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
interface JournalSettleOptions {
|
|
86
|
+
readonly range?: JournalRange | undefined;
|
|
87
|
+
readonly releaseNotFound?: boolean | undefined;
|
|
88
|
+
}
|
|
89
|
+
interface JournalSettlement {
|
|
90
|
+
readonly recorded: readonly JournalReservation[];
|
|
91
|
+
readonly notFound: readonly JournalReservation[];
|
|
92
|
+
readonly failed: readonly {
|
|
93
|
+
readonly reservation: JournalReservation;
|
|
94
|
+
readonly error: unknown;
|
|
95
|
+
}[];
|
|
96
|
+
}
|
|
97
|
+
interface Journal {
|
|
98
|
+
readonly storage: JournalStorage;
|
|
99
|
+
record(event: DocumentEvent): Promise<void>;
|
|
100
|
+
recordReceipt(receipt: Receipt): Promise<boolean>;
|
|
101
|
+
recordInvoice(details: InvoiceDetails): Promise<boolean>;
|
|
102
|
+
reserve(kind: JournalDocumentKind, orderNumber: string): Promise<boolean>;
|
|
103
|
+
release(kind: JournalDocumentKind, orderNumber: string): Promise<void>;
|
|
104
|
+
trackReceipt(orderNumber: string, run: () => Promise<ReceiptOnceResult | Receipt>): Promise<ReceiptOnceResult | Receipt>;
|
|
105
|
+
trackInvoice(orderNumber: string, run: () => Promise<InvoiceOnceResult>): Promise<InvoiceOnceResult>;
|
|
106
|
+
entries(query: JournalEntryQuery): Promise<JournalEntry[]>;
|
|
107
|
+
receipts(query: JournalReceiptQuery): Promise<Receipt[]>;
|
|
108
|
+
pending(range?: JournalRange): Promise<JournalReservation[]>;
|
|
109
|
+
settle(api: JournalSettleApi, options?: JournalSettleOptions): Promise<JournalSettlement>;
|
|
110
|
+
reconcile(archive: readonly (Receipt | DataLinkArchivedReceipt)[], options?: JournalReconcileOptions): Promise<JournalReconciliation>;
|
|
111
|
+
}
|
|
112
|
+
declare function createJournal(storage: JournalStorage, options?: JournalOptions): Journal;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { JournalRange as _, JournalReceiptQuery as a, JournalSettleApi as c, JournalWriteError as d, createJournal as f, JournalEntryType as g, JournalEntrySource as h, JournalOptions as i, JournalSettleOptions as l, JournalEntry as m, Journal as n, JournalReconcileOptions as o, JournalDocumentKind as p, JournalEntryQuery as r, JournalReconciliation as s, DEFAULT_PENDING_DAYS as t, JournalSettlement as u, JournalReservation as v, JournalStorage as y };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { f as DocumentEvent } from "./context-kb33TgzE.js";
|
|
2
|
+
import { r as Receipt } from "./types-D1zDOH_F.js";
|
|
3
|
+
import { n as InvoiceDetails } from "./get-Byc9T5WO.js";
|
|
4
|
+
import { n as InvoiceOnceResult, t as ReceiptOnceResult } from "./create-once-VKp0tVow.js";
|
|
5
|
+
import { t as DataLinkArchivedReceipt } from "./push-BXj0Sf0Z.js";
|
|
6
|
+
//#region src/journal/types.d.ts
|
|
7
|
+
type JournalDocumentKind = "invoice" | "receipt";
|
|
8
|
+
type JournalEntryType = "document" | "reversal";
|
|
9
|
+
type JournalEntrySource = "hook" | "track" | "reconcile" | "settle" | "manual";
|
|
10
|
+
interface JournalEntry {
|
|
11
|
+
readonly kind: JournalDocumentKind;
|
|
12
|
+
readonly type: JournalEntryType;
|
|
13
|
+
readonly number: string;
|
|
14
|
+
readonly date: string;
|
|
15
|
+
readonly recordedAt: string;
|
|
16
|
+
readonly source: JournalEntrySource;
|
|
17
|
+
readonly orderNumber?: string | undefined;
|
|
18
|
+
readonly reversedNumber?: string | undefined;
|
|
19
|
+
readonly netTotal?: number | undefined;
|
|
20
|
+
readonly grossTotal?: number | undefined;
|
|
21
|
+
readonly currency?: string | undefined;
|
|
22
|
+
readonly isTest?: boolean | undefined;
|
|
23
|
+
readonly receipt?: Receipt | undefined;
|
|
24
|
+
}
|
|
25
|
+
interface JournalReservation {
|
|
26
|
+
readonly kind: JournalDocumentKind;
|
|
27
|
+
readonly orderNumber: string;
|
|
28
|
+
readonly date: string;
|
|
29
|
+
readonly reservedAt: string;
|
|
30
|
+
}
|
|
31
|
+
interface JournalRange {
|
|
32
|
+
readonly from: string;
|
|
33
|
+
readonly to: string;
|
|
34
|
+
}
|
|
35
|
+
interface JournalStorage {
|
|
36
|
+
getEntry(kind: JournalDocumentKind, number: string): Promise<JournalEntry | undefined>;
|
|
37
|
+
putEntry(entry: JournalEntry): Promise<boolean>;
|
|
38
|
+
listEntries(range: JournalRange): Promise<JournalEntry[]>;
|
|
39
|
+
putReservation(reservation: JournalReservation): Promise<boolean>;
|
|
40
|
+
deleteReservation(kind: JournalDocumentKind, orderNumber: string): Promise<void>;
|
|
41
|
+
listReservations(range: JournalRange): Promise<JournalReservation[]>;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/journal/journal.d.ts
|
|
45
|
+
declare const DEFAULT_PENDING_DAYS = 30;
|
|
46
|
+
declare class JournalWriteError extends Error {
|
|
47
|
+
override readonly name: string;
|
|
48
|
+
readonly result: unknown;
|
|
49
|
+
readonly orderNumber: string;
|
|
50
|
+
constructor(orderNumber: string, result: unknown, cause: unknown);
|
|
51
|
+
}
|
|
52
|
+
interface JournalOptions {
|
|
53
|
+
readonly now?: (() => Date) | undefined;
|
|
54
|
+
}
|
|
55
|
+
interface JournalEntryQuery extends JournalRange {
|
|
56
|
+
readonly kind?: JournalDocumentKind | undefined;
|
|
57
|
+
}
|
|
58
|
+
interface JournalReceiptQuery extends JournalRange {
|
|
59
|
+
readonly includeTest?: boolean | undefined;
|
|
60
|
+
}
|
|
61
|
+
interface JournalReconcileOptions {
|
|
62
|
+
readonly from?: string | undefined;
|
|
63
|
+
readonly to?: string | undefined;
|
|
64
|
+
readonly dryRun?: boolean | undefined;
|
|
65
|
+
}
|
|
66
|
+
interface JournalReconciliation {
|
|
67
|
+
readonly range: JournalRange | undefined;
|
|
68
|
+
readonly added: readonly string[];
|
|
69
|
+
readonly missingFromArchive: readonly string[];
|
|
70
|
+
readonly matched: number;
|
|
71
|
+
}
|
|
72
|
+
interface JournalSettleApi {
|
|
73
|
+
readonly invoices?: {
|
|
74
|
+
find(reference: {
|
|
75
|
+
readonly orderNumber: string;
|
|
76
|
+
}): Promise<InvoiceDetails | null>;
|
|
77
|
+
};
|
|
78
|
+
readonly receipts?: {
|
|
79
|
+
find(input: {
|
|
80
|
+
readonly orderNumber: string;
|
|
81
|
+
readonly downloadPdf?: boolean;
|
|
82
|
+
}): Promise<Receipt | null>;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
interface JournalSettleOptions {
|
|
86
|
+
readonly range?: JournalRange | undefined;
|
|
87
|
+
readonly releaseNotFound?: boolean | undefined;
|
|
88
|
+
}
|
|
89
|
+
interface JournalSettlement {
|
|
90
|
+
readonly recorded: readonly JournalReservation[];
|
|
91
|
+
readonly notFound: readonly JournalReservation[];
|
|
92
|
+
readonly failed: readonly {
|
|
93
|
+
readonly reservation: JournalReservation;
|
|
94
|
+
readonly error: unknown;
|
|
95
|
+
}[];
|
|
96
|
+
}
|
|
97
|
+
interface Journal {
|
|
98
|
+
readonly storage: JournalStorage;
|
|
99
|
+
record(event: DocumentEvent): Promise<void>;
|
|
100
|
+
recordReceipt(receipt: Receipt): Promise<boolean>;
|
|
101
|
+
recordInvoice(details: InvoiceDetails): Promise<boolean>;
|
|
102
|
+
reserve(kind: JournalDocumentKind, orderNumber: string): Promise<boolean>;
|
|
103
|
+
release(kind: JournalDocumentKind, orderNumber: string): Promise<void>;
|
|
104
|
+
trackReceipt(orderNumber: string, run: () => Promise<ReceiptOnceResult | Receipt>): Promise<ReceiptOnceResult | Receipt>;
|
|
105
|
+
trackInvoice(orderNumber: string, run: () => Promise<InvoiceOnceResult>): Promise<InvoiceOnceResult>;
|
|
106
|
+
entries(query: JournalEntryQuery): Promise<JournalEntry[]>;
|
|
107
|
+
receipts(query: JournalReceiptQuery): Promise<Receipt[]>;
|
|
108
|
+
pending(range?: JournalRange): Promise<JournalReservation[]>;
|
|
109
|
+
settle(api: JournalSettleApi, options?: JournalSettleOptions): Promise<JournalSettlement>;
|
|
110
|
+
reconcile(archive: readonly (Receipt | DataLinkArchivedReceipt)[], options?: JournalReconcileOptions): Promise<JournalReconciliation>;
|
|
111
|
+
}
|
|
112
|
+
declare function createJournal(storage: JournalStorage, options?: JournalOptions): Journal;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { JournalRange as _, JournalReceiptQuery as a, JournalSettleApi as c, JournalWriteError as d, createJournal as f, JournalEntryType as g, JournalEntrySource as h, JournalOptions as i, JournalSettleOptions as l, JournalEntry as m, Journal as n, JournalReconcileOptions as o, JournalDocumentKind as p, JournalEntryQuery as r, JournalReconciliation as s, DEFAULT_PENDING_DAYS as t, JournalSettlement as u, JournalReservation as v, JournalStorage as y };
|
package/dist/mcp/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_server = require("../server-
|
|
2
|
+
const require_server = require("../server-Dw9j8Mnd.cjs");
|
|
3
3
|
exports.DEFAULT_CONFIRMATION_TTL_MS = require_server.DEFAULT_CONFIRMATION_TTL_MS;
|
|
4
4
|
exports.MCP_LEGACY_VERSIONS = require_server.MCP_LEGACY_VERSIONS;
|
|
5
5
|
exports.MCP_MODERN_VERSIONS = require_server.MCP_MODERN_VERSIONS;
|
package/dist/mcp/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as KasszaOptions } from "../client-
|
|
1
|
+
import { i as KasszaOptions } from "../client-SVZu25MB.cjs";
|
|
2
2
|
//#region src/mcp/protocol.d.ts
|
|
3
3
|
export declare const MCP_MODERN_VERSIONS: readonly string[];
|
|
4
4
|
export declare const MCP_LEGACY_VERSIONS: readonly string[];
|