kassza 0.12.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 +427 -32
- package/agents/README.md +26 -6
- package/agents/api.md +218 -3
- package/agents/pitfalls.md +27 -3
- package/agents/recipes.md +280 -51
- package/agents/skills/kassza/SKILL.md +14 -8
- 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 +643 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +643 -0
- package/dist/client-CLFvJCVW.cjs +1452 -0
- package/dist/{client-CL3fuH6A.js → client-Cvf-hTz_.js} +306 -515
- package/dist/client-DeWWQ-RZ.d.ts +341 -0
- package/dist/client-SVZu25MB.d.cts +341 -0
- package/dist/context-CFNKzStE.d.cts +449 -0
- package/dist/context-kb33TgzE.d.ts +449 -0
- 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-D0pwuenl.cjs → create-once-9yxR_Er_.cjs} +291 -33
- package/dist/create-once-Bh6fOWkW.d.cts +20 -0
- package/dist/{create-once-CqdYmQD8.js → create-once-Ca2gMk1h.js} +250 -34
- package/dist/create-once-VKp0tVow.d.ts +20 -0
- package/dist/{crypto-B8lERvR1.cjs → crypto-Dpn4FHQ6.cjs} +9 -0
- package/dist/{crypto-DK_osBVy.js → crypto-usDg8L2K.js} +4 -1
- package/dist/data-link/index.cjs +232 -0
- package/dist/data-link/index.d.cts +29 -0
- package/dist/data-link/index.d.ts +29 -0
- package/dist/data-link/index.js +224 -0
- package/dist/delegation/index.cjs +35 -34
- package/dist/delegation/index.d.cts +2 -1
- package/dist/delegation/index.d.ts +2 -1
- package/dist/delegation/index.js +4 -3
- package/dist/{errors-DLrb0g64.js → errors-DtN4g5Z9.js} +9 -1
- package/dist/{errors-DxeuTslP.cjs → errors-EE96_6D_.cjs} +20 -0
- package/dist/get-BdMTseh4.cjs +271 -0
- package/dist/get-Byc9T5WO.d.cts +151 -0
- package/dist/get-Byc9T5WO.d.ts +151 -0
- package/dist/get-CZEShCcj.js +260 -0
- 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 +11 -19
- package/dist/index.d.ts +11 -19
- 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-Bin4tKD_.cjs +988 -0
- package/dist/issue-DMA1Nbr1.js +905 -0
- 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 +10 -0
- package/dist/mcp/index.d.cts +71 -0
- package/dist/mcp/index.d.ts +71 -0
- package/dist/mcp/index.js +2 -0
- 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-DAA7OwiO.js → money-Cw457SD6.js} +120 -12
- package/dist/{money-DrhGkWHW.cjs → money-K9j0wPit.cjs} +124 -10
- package/dist/nav/index.cjs +1046 -0
- package/dist/nav/index.d.cts +247 -0
- package/dist/nav/index.d.ts +247 -0
- package/dist/nav/index.js +1012 -0
- package/dist/nav-BNbc8U0R.cjs +203 -0
- package/dist/nav-BcCerwWS.js +156 -0
- 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-Cr7yQ3_z.js +291 -0
- package/dist/parse-DOA2XQ3e.cjs +380 -0
- 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 +17 -3
- package/dist/payments/revolut.d.cts +2 -2
- package/dist/payments/revolut.d.ts +2 -2
- package/dist/payments/revolut.js +17 -3
- package/dist/payments/simplepay.cjs +37 -5
- package/dist/payments/simplepay.d.cts +2 -2
- package/dist/payments/simplepay.d.ts +2 -2
- package/dist/payments/simplepay.js +37 -5
- package/dist/payments/stripe.cjs +20 -3
- package/dist/payments/stripe.d.cts +2 -2
- package/dist/payments/stripe.d.ts +2 -2
- package/dist/payments/stripe.js +20 -3
- 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 +11 -164
- package/dist/reports/index.d.cts +1 -1
- package/dist/reports/index.d.ts +1 -1
- package/dist/reports/index.js +1 -154
- package/dist/request-body-CH6ZGOrq.cjs +34 -0
- package/dist/request-body-uZHMRlQr.js +29 -0
- package/dist/serialize-B2eFh3D-.js +219 -0
- package/dist/serialize-CquIsxA-.cjs +290 -0
- package/dist/server-BrJUbXs7.js +1505 -0
- package/dist/server-Dw9j8Mnd.cjs +1558 -0
- 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 +1500 -15
- package/dist/testing/index.d.cts +198 -3
- package/dist/testing/index.d.ts +198 -3
- package/dist/testing/index.js +1498 -15
- package/dist/{types-COf1LAD-.d.ts → types-B1A8mUIE.d.cts} +14 -2
- package/dist/{types-COf1LAD-.d.cts → types-ByAEvGsZ.d.ts} +14 -2
- 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-D4lvtex1.js → webhook-CQVShAfI.js} +47 -26
- package/dist/{webhook-C76bV-4R.cjs → webhook-Ckj-_hPD.cjs} +70 -25
- package/dist/webhook-CmdhGiH5.d.cts +11 -0
- package/dist/webhook-D6lEejob.d.ts +11 -0
- package/llms.txt +6 -5
- package/package.json +134 -4
- package/dist/client-CickRRFr.d.ts +0 -838
- package/dist/client-CsmGIFRS.cjs +0 -1637
- package/dist/client-DvWZoX_E.d.cts +0 -838
- package/dist/issue-BsyYdrIG.cjs +0 -1531
- package/dist/issue-C6Fcjvln.js +0 -1274
- package/dist/session-Dm_45x8K.d.cts +0 -11
- package/dist/session-Dm_45x8K.d.ts +0 -11
- package/dist/webhook-CfaDgcL0.d.cts +0 -6
- package/dist/webhook-q2OzNwd7.d.ts +0 -6
package/dist/reports/index.cjs
CHANGED
|
@@ -1,159 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_errors = require("../errors-DxeuTslP.cjs");
|
|
3
2
|
const require_rounding = require("../rounding-TxoWy2ww.cjs");
|
|
4
|
-
const
|
|
5
|
-
//#region src/reports/vat-category.ts
|
|
6
|
-
const NAV_VAT_CATEGORIES = [
|
|
7
|
-
"0%",
|
|
8
|
-
"5%",
|
|
9
|
-
"18%",
|
|
10
|
-
"27%",
|
|
11
|
-
"Alanyi adómentes",
|
|
12
|
-
"Egyéb"
|
|
13
|
-
];
|
|
14
|
-
const NUMERIC_CATEGORIES = /* @__PURE__ */ new Map([
|
|
15
|
-
[0, "0%"],
|
|
16
|
-
[5, "5%"],
|
|
17
|
-
[18, "18%"],
|
|
18
|
-
[27, "27%"]
|
|
19
|
-
]);
|
|
20
|
-
function navVatCategory(vat) {
|
|
21
|
-
if (typeof vat === "number") return NUMERIC_CATEGORIES.get(vat) ?? "Egyéb";
|
|
22
|
-
if (vat === "AAM") return "Alanyi adómentes";
|
|
23
|
-
return "Egyéb";
|
|
24
|
-
}
|
|
25
|
-
function isNavVatCategory(value) {
|
|
26
|
-
return NAV_VAT_CATEGORIES.includes(value);
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/reports/nav.ts
|
|
30
|
-
const SEQUENCE_PATTERN = /^(.*)-(\d+)$/;
|
|
31
|
-
function splitReceiptNumber(receiptNumber) {
|
|
32
|
-
const match = SEQUENCE_PATTERN.exec(receiptNumber.trim());
|
|
33
|
-
if (!match?.[1]) return {
|
|
34
|
-
series: receiptNumber.trim(),
|
|
35
|
-
sequence: void 0
|
|
36
|
-
};
|
|
37
|
-
return {
|
|
38
|
-
series: match[1],
|
|
39
|
-
sequence: Number(match[2])
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function navCurrencyCode(currency) {
|
|
43
|
-
return require_vat.isHuf(currency) ? "HUF" : currency.trim().toUpperCase();
|
|
44
|
-
}
|
|
45
|
-
function compareReceiptNumbers(a, b) {
|
|
46
|
-
const left = splitReceiptNumber(a);
|
|
47
|
-
const right = splitReceiptNumber(b);
|
|
48
|
-
if (left.series === right.series && left.sequence !== void 0 && right.sequence !== void 0) return left.sequence - right.sequence;
|
|
49
|
-
return a.localeCompare(b, "hu");
|
|
50
|
-
}
|
|
51
|
-
function reportError(message) {
|
|
52
|
-
return new require_errors.SzamlazzError(message, { category: "validation" });
|
|
53
|
-
}
|
|
54
|
-
function exchangeRateOf(receipt, currency) {
|
|
55
|
-
if (currency === "HUF") return null;
|
|
56
|
-
const rate = receipt.exchangeRate;
|
|
57
|
-
if (rate === void 0 || !Number.isFinite(rate) || rate <= 0) throw reportError(`A(z) ${receipt.number} devizás (${currency}) nyugtán nincs érvényes árfolyam, ezért nem összesíthető.`);
|
|
58
|
-
return require_rounding.roundMoney(rate, 4);
|
|
59
|
-
}
|
|
60
|
-
function signedGross(item, receipt) {
|
|
61
|
-
return receipt.type === "reversal" ? -Math.abs(item.grossAmount) : item.grossAmount;
|
|
62
|
-
}
|
|
63
|
-
function bucketFor(buckets, receipt, series, currency, exchangeRate) {
|
|
64
|
-
const key = JSON.stringify([
|
|
65
|
-
receipt.issueDate,
|
|
66
|
-
series,
|
|
67
|
-
currency,
|
|
68
|
-
exchangeRate
|
|
69
|
-
]);
|
|
70
|
-
const existing = buckets.get(key);
|
|
71
|
-
if (existing) return existing;
|
|
72
|
-
const created = {
|
|
73
|
-
applicableDate: receipt.issueDate,
|
|
74
|
-
series,
|
|
75
|
-
currency,
|
|
76
|
-
exchangeRate,
|
|
77
|
-
categories: /* @__PURE__ */ new Map(),
|
|
78
|
-
numbers: [],
|
|
79
|
-
sales: 0,
|
|
80
|
-
modifying: 0
|
|
81
|
-
};
|
|
82
|
-
buckets.set(key, created);
|
|
83
|
-
return created;
|
|
84
|
-
}
|
|
85
|
-
function categoryOrder(name) {
|
|
86
|
-
const index = NAV_VAT_CATEGORIES.indexOf(name);
|
|
87
|
-
return index === -1 ? NAV_VAT_CATEGORIES.length : index;
|
|
88
|
-
}
|
|
89
|
-
function toReport(bucket) {
|
|
90
|
-
const vatCategories = [...bucket.categories.entries()].map(([vat, totals]) => ({
|
|
91
|
-
vat,
|
|
92
|
-
saleDocument: require_rounding.roundMoney(totals.sale, 2),
|
|
93
|
-
modifyingDocument: require_rounding.roundMoney(totals.modifying, 2)
|
|
94
|
-
})).sort((a, b) => categoryOrder(a.vat) - categoryOrder(b.vat) || a.vat.localeCompare(b.vat));
|
|
95
|
-
const total = require_rounding.roundMoney(vatCategories.reduce((sum, row) => sum + row.saleDocument + row.modifyingDocument, 0), 2);
|
|
96
|
-
const receiptNumbers = [...bucket.numbers].sort(compareReceiptNumbers);
|
|
97
|
-
return {
|
|
98
|
-
applicableDate: bucket.applicableDate,
|
|
99
|
-
series: bucket.series,
|
|
100
|
-
serialNumber: receiptNumbers[0] ?? "",
|
|
101
|
-
currency: bucket.currency,
|
|
102
|
-
exchangeRate: bucket.exchangeRate,
|
|
103
|
-
vatCategories,
|
|
104
|
-
total,
|
|
105
|
-
numberOfSaleDocument: bucket.sales,
|
|
106
|
-
numberOfModifyingDocument: bucket.modifying,
|
|
107
|
-
receiptNumbers
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function assertIssueDate(receipt) {
|
|
111
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(receipt.issueDate)) throw reportError(`A(z) ${receipt.number} nyugta kelte érvénytelen: "${receipt.issueDate}".`);
|
|
112
|
-
}
|
|
113
|
-
function navDailyReports(receipts, options = {}) {
|
|
114
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
115
|
-
const seen = /* @__PURE__ */ new Set();
|
|
116
|
-
const seriesOf = options.series ?? ((number) => splitReceiptNumber(number).series);
|
|
117
|
-
const categoryOf = options.vatCategory ?? ((item) => navVatCategory(item.vat));
|
|
118
|
-
for (const receipt of receipts) {
|
|
119
|
-
if (receipt.isTest && options.includeTest !== true) continue;
|
|
120
|
-
if (seen.has(receipt.number)) continue;
|
|
121
|
-
seen.add(receipt.number);
|
|
122
|
-
assertIssueDate(receipt);
|
|
123
|
-
const currency = navCurrencyCode(receipt.currency);
|
|
124
|
-
const bucket = bucketFor(buckets, receipt, seriesOf(receipt.number), currency, exchangeRateOf(receipt, currency));
|
|
125
|
-
bucket.numbers.push(receipt.number);
|
|
126
|
-
const isModifying = receipt.type === "reversal";
|
|
127
|
-
if (isModifying) bucket.modifying += 1;
|
|
128
|
-
else bucket.sales += 1;
|
|
129
|
-
for (const item of receipt.items) {
|
|
130
|
-
const name = categoryOf(item, receipt);
|
|
131
|
-
const totals = bucket.categories.get(name) ?? {
|
|
132
|
-
sale: 0,
|
|
133
|
-
modifying: 0
|
|
134
|
-
};
|
|
135
|
-
if (isModifying) totals.modifying += signedGross(item, receipt);
|
|
136
|
-
else totals.sale += signedGross(item, receipt);
|
|
137
|
-
bucket.categories.set(name, totals);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return [...buckets.values()].map(toReport).sort((a, b) => a.applicableDate.localeCompare(b.applicableDate) || a.series.localeCompare(b.series, "hu") || a.currency.localeCompare(b.currency) || (a.exchangeRate ?? 0) - (b.exchangeRate ?? 0));
|
|
141
|
-
}
|
|
142
|
-
const amountFormatter = new Intl.NumberFormat("hu-HU", {
|
|
143
|
-
minimumFractionDigits: 0,
|
|
144
|
-
maximumFractionDigits: 2
|
|
145
|
-
});
|
|
146
|
-
function describeNavReport(report) {
|
|
147
|
-
return [
|
|
148
|
-
`Tárgynap: ${report.applicableDate}`,
|
|
149
|
-
`Kezdő nyugtasorszám: ${report.serialNumber}`,
|
|
150
|
-
`Pénznem: ${report.currency}${report.exchangeRate === null ? "" : ` (árfolyam: ${report.exchangeRate})`}`,
|
|
151
|
-
...report.vatCategories.map((row) => `${row.vat}: értékesítés ${amountFormatter.format(row.saleDocument)}, módosító/érvénytelenítő ${amountFormatter.format(row.modifyingDocument)}`),
|
|
152
|
-
`Végösszeg: ${amountFormatter.format(report.total)}`,
|
|
153
|
-
`Nyugták száma: ${report.numberOfSaleDocument}, módosító/érvénytelenítő bizonylatok száma: ${report.numberOfModifyingDocument}`
|
|
154
|
-
].join("\n");
|
|
155
|
-
}
|
|
156
|
-
//#endregion
|
|
3
|
+
const require_nav = require("../nav-BNbc8U0R.cjs");
|
|
157
4
|
//#region src/reports/close.ts
|
|
158
5
|
function sign(receipt, amount) {
|
|
159
6
|
return receipt.type === "reversal" ? -Math.abs(amount) : amount;
|
|
@@ -207,7 +54,7 @@ function toSummary(bucket) {
|
|
|
207
54
|
vatAmount: require_rounding.roundMoney(totals.vatAmount, 2),
|
|
208
55
|
grossAmount: require_rounding.roundMoney(totals.gross, 2)
|
|
209
56
|
})).sort((a, b) => String(a.vat).localeCompare(String(b.vat), "hu", { numeric: true })),
|
|
210
|
-
receiptNumbers: [...bucket.numbers].sort(compareReceiptNumbers)
|
|
57
|
+
receiptNumbers: [...bucket.numbers].sort(require_nav.compareReceiptNumbers)
|
|
211
58
|
};
|
|
212
59
|
}
|
|
213
60
|
function dailyClose(receipts, options = {}) {
|
|
@@ -217,7 +64,7 @@ function dailyClose(receipts, options = {}) {
|
|
|
217
64
|
if (receipt.isTest && options.includeTest !== true) continue;
|
|
218
65
|
if (seen.has(receipt.number)) continue;
|
|
219
66
|
seen.add(receipt.number);
|
|
220
|
-
const currency = navCurrencyCode(receipt.currency);
|
|
67
|
+
const currency = require_nav.navCurrencyCode(receipt.currency);
|
|
221
68
|
const key = `${receipt.issueDate}|${currency}`;
|
|
222
69
|
const bucket = buckets.get(key) ?? {
|
|
223
70
|
date: receipt.issueDate,
|
|
@@ -245,12 +92,12 @@ function dailyClose(receipts, options = {}) {
|
|
|
245
92
|
return [...buckets.values()].map(toSummary).sort((a, b) => a.date.localeCompare(b.date) || a.currency.localeCompare(b.currency));
|
|
246
93
|
}
|
|
247
94
|
//#endregion
|
|
248
|
-
exports.NAV_VAT_CATEGORIES = NAV_VAT_CATEGORIES;
|
|
249
|
-
exports.compareReceiptNumbers = compareReceiptNumbers;
|
|
95
|
+
exports.NAV_VAT_CATEGORIES = require_nav.NAV_VAT_CATEGORIES;
|
|
96
|
+
exports.compareReceiptNumbers = require_nav.compareReceiptNumbers;
|
|
250
97
|
exports.dailyClose = dailyClose;
|
|
251
|
-
exports.describeNavReport = describeNavReport;
|
|
252
|
-
exports.isNavVatCategory = isNavVatCategory;
|
|
253
|
-
exports.navCurrencyCode = navCurrencyCode;
|
|
254
|
-
exports.navDailyReports = navDailyReports;
|
|
255
|
-
exports.navVatCategory = navVatCategory;
|
|
256
|
-
exports.splitReceiptNumber = splitReceiptNumber;
|
|
98
|
+
exports.describeNavReport = require_nav.describeNavReport;
|
|
99
|
+
exports.isNavVatCategory = require_nav.isNavVatCategory;
|
|
100
|
+
exports.navCurrencyCode = require_nav.navCurrencyCode;
|
|
101
|
+
exports.navDailyReports = require_nav.navDailyReports;
|
|
102
|
+
exports.navVatCategory = require_nav.navVatCategory;
|
|
103
|
+
exports.splitReceiptNumber = require_nav.splitReceiptNumber;
|
package/dist/reports/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ReceiptItem, p as ReceiptVatRate, r as Receipt } from "../types-
|
|
1
|
+
import { a as ReceiptItem, p as ReceiptVatRate, r as Receipt } from "../types-lnKkQdot.cjs";
|
|
2
2
|
//#region src/reports/close.d.ts
|
|
3
3
|
interface DailyClosePaymentTotal {
|
|
4
4
|
readonly method: string;
|
package/dist/reports/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ReceiptItem, p as ReceiptVatRate, r as Receipt } from "../types-
|
|
1
|
+
import { a as ReceiptItem, p as ReceiptVatRate, r as Receipt } from "../types-D1zDOH_F.js";
|
|
2
2
|
//#region src/reports/close.d.ts
|
|
3
3
|
interface DailyClosePaymentTotal {
|
|
4
4
|
readonly method: string;
|
package/dist/reports/index.js
CHANGED
|
@@ -1,158 +1,5 @@
|
|
|
1
|
-
import { n as SzamlazzError } from "../errors-DLrb0g64.js";
|
|
2
1
|
import { r as roundMoney } from "../rounding-BLyHjjI5.js";
|
|
3
|
-
import { i as
|
|
4
|
-
//#region src/reports/vat-category.ts
|
|
5
|
-
const NAV_VAT_CATEGORIES = [
|
|
6
|
-
"0%",
|
|
7
|
-
"5%",
|
|
8
|
-
"18%",
|
|
9
|
-
"27%",
|
|
10
|
-
"Alanyi adómentes",
|
|
11
|
-
"Egyéb"
|
|
12
|
-
];
|
|
13
|
-
const NUMERIC_CATEGORIES = /* @__PURE__ */ new Map([
|
|
14
|
-
[0, "0%"],
|
|
15
|
-
[5, "5%"],
|
|
16
|
-
[18, "18%"],
|
|
17
|
-
[27, "27%"]
|
|
18
|
-
]);
|
|
19
|
-
function navVatCategory(vat) {
|
|
20
|
-
if (typeof vat === "number") return NUMERIC_CATEGORIES.get(vat) ?? "Egyéb";
|
|
21
|
-
if (vat === "AAM") return "Alanyi adómentes";
|
|
22
|
-
return "Egyéb";
|
|
23
|
-
}
|
|
24
|
-
function isNavVatCategory(value) {
|
|
25
|
-
return NAV_VAT_CATEGORIES.includes(value);
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/reports/nav.ts
|
|
29
|
-
const SEQUENCE_PATTERN = /^(.*)-(\d+)$/;
|
|
30
|
-
function splitReceiptNumber(receiptNumber) {
|
|
31
|
-
const match = SEQUENCE_PATTERN.exec(receiptNumber.trim());
|
|
32
|
-
if (!match?.[1]) return {
|
|
33
|
-
series: receiptNumber.trim(),
|
|
34
|
-
sequence: void 0
|
|
35
|
-
};
|
|
36
|
-
return {
|
|
37
|
-
series: match[1],
|
|
38
|
-
sequence: Number(match[2])
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function navCurrencyCode(currency) {
|
|
42
|
-
return isHuf(currency) ? "HUF" : currency.trim().toUpperCase();
|
|
43
|
-
}
|
|
44
|
-
function compareReceiptNumbers(a, b) {
|
|
45
|
-
const left = splitReceiptNumber(a);
|
|
46
|
-
const right = splitReceiptNumber(b);
|
|
47
|
-
if (left.series === right.series && left.sequence !== void 0 && right.sequence !== void 0) return left.sequence - right.sequence;
|
|
48
|
-
return a.localeCompare(b, "hu");
|
|
49
|
-
}
|
|
50
|
-
function reportError(message) {
|
|
51
|
-
return new SzamlazzError(message, { category: "validation" });
|
|
52
|
-
}
|
|
53
|
-
function exchangeRateOf(receipt, currency) {
|
|
54
|
-
if (currency === "HUF") return null;
|
|
55
|
-
const rate = receipt.exchangeRate;
|
|
56
|
-
if (rate === void 0 || !Number.isFinite(rate) || rate <= 0) throw reportError(`A(z) ${receipt.number} devizás (${currency}) nyugtán nincs érvényes árfolyam, ezért nem összesíthető.`);
|
|
57
|
-
return roundMoney(rate, 4);
|
|
58
|
-
}
|
|
59
|
-
function signedGross(item, receipt) {
|
|
60
|
-
return receipt.type === "reversal" ? -Math.abs(item.grossAmount) : item.grossAmount;
|
|
61
|
-
}
|
|
62
|
-
function bucketFor(buckets, receipt, series, currency, exchangeRate) {
|
|
63
|
-
const key = JSON.stringify([
|
|
64
|
-
receipt.issueDate,
|
|
65
|
-
series,
|
|
66
|
-
currency,
|
|
67
|
-
exchangeRate
|
|
68
|
-
]);
|
|
69
|
-
const existing = buckets.get(key);
|
|
70
|
-
if (existing) return existing;
|
|
71
|
-
const created = {
|
|
72
|
-
applicableDate: receipt.issueDate,
|
|
73
|
-
series,
|
|
74
|
-
currency,
|
|
75
|
-
exchangeRate,
|
|
76
|
-
categories: /* @__PURE__ */ new Map(),
|
|
77
|
-
numbers: [],
|
|
78
|
-
sales: 0,
|
|
79
|
-
modifying: 0
|
|
80
|
-
};
|
|
81
|
-
buckets.set(key, created);
|
|
82
|
-
return created;
|
|
83
|
-
}
|
|
84
|
-
function categoryOrder(name) {
|
|
85
|
-
const index = NAV_VAT_CATEGORIES.indexOf(name);
|
|
86
|
-
return index === -1 ? NAV_VAT_CATEGORIES.length : index;
|
|
87
|
-
}
|
|
88
|
-
function toReport(bucket) {
|
|
89
|
-
const vatCategories = [...bucket.categories.entries()].map(([vat, totals]) => ({
|
|
90
|
-
vat,
|
|
91
|
-
saleDocument: roundMoney(totals.sale, 2),
|
|
92
|
-
modifyingDocument: roundMoney(totals.modifying, 2)
|
|
93
|
-
})).sort((a, b) => categoryOrder(a.vat) - categoryOrder(b.vat) || a.vat.localeCompare(b.vat));
|
|
94
|
-
const total = roundMoney(vatCategories.reduce((sum, row) => sum + row.saleDocument + row.modifyingDocument, 0), 2);
|
|
95
|
-
const receiptNumbers = [...bucket.numbers].sort(compareReceiptNumbers);
|
|
96
|
-
return {
|
|
97
|
-
applicableDate: bucket.applicableDate,
|
|
98
|
-
series: bucket.series,
|
|
99
|
-
serialNumber: receiptNumbers[0] ?? "",
|
|
100
|
-
currency: bucket.currency,
|
|
101
|
-
exchangeRate: bucket.exchangeRate,
|
|
102
|
-
vatCategories,
|
|
103
|
-
total,
|
|
104
|
-
numberOfSaleDocument: bucket.sales,
|
|
105
|
-
numberOfModifyingDocument: bucket.modifying,
|
|
106
|
-
receiptNumbers
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
function assertIssueDate(receipt) {
|
|
110
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(receipt.issueDate)) throw reportError(`A(z) ${receipt.number} nyugta kelte érvénytelen: "${receipt.issueDate}".`);
|
|
111
|
-
}
|
|
112
|
-
function navDailyReports(receipts, options = {}) {
|
|
113
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
114
|
-
const seen = /* @__PURE__ */ new Set();
|
|
115
|
-
const seriesOf = options.series ?? ((number) => splitReceiptNumber(number).series);
|
|
116
|
-
const categoryOf = options.vatCategory ?? ((item) => navVatCategory(item.vat));
|
|
117
|
-
for (const receipt of receipts) {
|
|
118
|
-
if (receipt.isTest && options.includeTest !== true) continue;
|
|
119
|
-
if (seen.has(receipt.number)) continue;
|
|
120
|
-
seen.add(receipt.number);
|
|
121
|
-
assertIssueDate(receipt);
|
|
122
|
-
const currency = navCurrencyCode(receipt.currency);
|
|
123
|
-
const bucket = bucketFor(buckets, receipt, seriesOf(receipt.number), currency, exchangeRateOf(receipt, currency));
|
|
124
|
-
bucket.numbers.push(receipt.number);
|
|
125
|
-
const isModifying = receipt.type === "reversal";
|
|
126
|
-
if (isModifying) bucket.modifying += 1;
|
|
127
|
-
else bucket.sales += 1;
|
|
128
|
-
for (const item of receipt.items) {
|
|
129
|
-
const name = categoryOf(item, receipt);
|
|
130
|
-
const totals = bucket.categories.get(name) ?? {
|
|
131
|
-
sale: 0,
|
|
132
|
-
modifying: 0
|
|
133
|
-
};
|
|
134
|
-
if (isModifying) totals.modifying += signedGross(item, receipt);
|
|
135
|
-
else totals.sale += signedGross(item, receipt);
|
|
136
|
-
bucket.categories.set(name, totals);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return [...buckets.values()].map(toReport).sort((a, b) => a.applicableDate.localeCompare(b.applicableDate) || a.series.localeCompare(b.series, "hu") || a.currency.localeCompare(b.currency) || (a.exchangeRate ?? 0) - (b.exchangeRate ?? 0));
|
|
140
|
-
}
|
|
141
|
-
const amountFormatter = new Intl.NumberFormat("hu-HU", {
|
|
142
|
-
minimumFractionDigits: 0,
|
|
143
|
-
maximumFractionDigits: 2
|
|
144
|
-
});
|
|
145
|
-
function describeNavReport(report) {
|
|
146
|
-
return [
|
|
147
|
-
`Tárgynap: ${report.applicableDate}`,
|
|
148
|
-
`Kezdő nyugtasorszám: ${report.serialNumber}`,
|
|
149
|
-
`Pénznem: ${report.currency}${report.exchangeRate === null ? "" : ` (árfolyam: ${report.exchangeRate})`}`,
|
|
150
|
-
...report.vatCategories.map((row) => `${row.vat}: értékesítés ${amountFormatter.format(row.saleDocument)}, módosító/érvénytelenítő ${amountFormatter.format(row.modifyingDocument)}`),
|
|
151
|
-
`Végösszeg: ${amountFormatter.format(report.total)}`,
|
|
152
|
-
`Nyugták száma: ${report.numberOfSaleDocument}, módosító/érvénytelenítő bizonylatok száma: ${report.numberOfModifyingDocument}`
|
|
153
|
-
].join("\n");
|
|
154
|
-
}
|
|
155
|
-
//#endregion
|
|
2
|
+
import { a as splitReceiptNumber, c as navVatCategory, i as navDailyReports, n as describeNavReport, o as NAV_VAT_CATEGORIES, r as navCurrencyCode, s as isNavVatCategory, t as compareReceiptNumbers } from "../nav-BcCerwWS.js";
|
|
156
3
|
//#region src/reports/close.ts
|
|
157
4
|
function sign(receipt, amount) {
|
|
158
5
|
return receipt.type === "reversal" ? -Math.abs(amount) : amount;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const require_binary = require("./binary-B89HM03_.cjs");
|
|
2
|
+
//#region src/core/request-body.ts
|
|
3
|
+
async function readRequestText(request, maxBytes, tooLarge) {
|
|
4
|
+
const declared = Number(request.headers.get("content-length"));
|
|
5
|
+
if (Number.isFinite(declared) && declared > maxBytes) throw tooLarge();
|
|
6
|
+
if (!request.body) return "";
|
|
7
|
+
const reader = request.body.getReader();
|
|
8
|
+
const chunks = [];
|
|
9
|
+
let total = 0;
|
|
10
|
+
for (;;) {
|
|
11
|
+
const chunk = await reader.read();
|
|
12
|
+
if (chunk.done) break;
|
|
13
|
+
total += chunk.value.byteLength;
|
|
14
|
+
if (total > maxBytes) {
|
|
15
|
+
await reader.cancel().catch(() => void 0);
|
|
16
|
+
throw tooLarge();
|
|
17
|
+
}
|
|
18
|
+
chunks.push(chunk.value);
|
|
19
|
+
}
|
|
20
|
+
const bytes = new Uint8Array(total);
|
|
21
|
+
let offset = 0;
|
|
22
|
+
for (const chunk of chunks) {
|
|
23
|
+
bytes.set(chunk, offset);
|
|
24
|
+
offset += chunk.byteLength;
|
|
25
|
+
}
|
|
26
|
+
return require_binary.decodeUtf8(bytes);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
Object.defineProperty(exports, "readRequestText", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function() {
|
|
32
|
+
return readRequestText;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { r as decodeUtf8 } from "./binary-D0M9U2MD.js";
|
|
2
|
+
//#region src/core/request-body.ts
|
|
3
|
+
async function readRequestText(request, maxBytes, tooLarge) {
|
|
4
|
+
const declared = Number(request.headers.get("content-length"));
|
|
5
|
+
if (Number.isFinite(declared) && declared > maxBytes) throw tooLarge();
|
|
6
|
+
if (!request.body) return "";
|
|
7
|
+
const reader = request.body.getReader();
|
|
8
|
+
const chunks = [];
|
|
9
|
+
let total = 0;
|
|
10
|
+
for (;;) {
|
|
11
|
+
const chunk = await reader.read();
|
|
12
|
+
if (chunk.done) break;
|
|
13
|
+
total += chunk.value.byteLength;
|
|
14
|
+
if (total > maxBytes) {
|
|
15
|
+
await reader.cancel().catch(() => void 0);
|
|
16
|
+
throw tooLarge();
|
|
17
|
+
}
|
|
18
|
+
chunks.push(chunk.value);
|
|
19
|
+
}
|
|
20
|
+
const bytes = new Uint8Array(total);
|
|
21
|
+
let offset = 0;
|
|
22
|
+
for (const chunk of chunks) {
|
|
23
|
+
bytes.set(chunk, offset);
|
|
24
|
+
offset += chunk.byteLength;
|
|
25
|
+
}
|
|
26
|
+
return decodeUtf8(bytes);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { readRequestText as t };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
//#region src/core/xml/parse.ts
|
|
2
|
+
var XmlParseError = class extends Error {
|
|
3
|
+
name = "XmlParseError";
|
|
4
|
+
};
|
|
5
|
+
const NAMED_ENTITIES = {
|
|
6
|
+
amp: "&",
|
|
7
|
+
lt: "<",
|
|
8
|
+
gt: ">",
|
|
9
|
+
quot: "\"",
|
|
10
|
+
apos: "'"
|
|
11
|
+
};
|
|
12
|
+
const MAX_CODE_POINT = 1114111;
|
|
13
|
+
const MIN_SURROGATE = 55296;
|
|
14
|
+
const MAX_SURROGATE = 57343;
|
|
15
|
+
function codePointToString(codePoint, fallback) {
|
|
16
|
+
return Number.isInteger(codePoint) && codePoint >= 0 && codePoint <= MAX_CODE_POINT && (codePoint < MIN_SURROGATE || codePoint > MAX_SURROGATE) ? String.fromCodePoint(codePoint) : fallback;
|
|
17
|
+
}
|
|
18
|
+
function decodeEntities(value) {
|
|
19
|
+
return value.replace(/&(#x[0-9a-fA-F]+|#\d+|[a-zA-Z]+);/g, (match, entity) => {
|
|
20
|
+
if (entity.startsWith("#x")) return codePointToString(Number.parseInt(entity.slice(2), 16), match);
|
|
21
|
+
if (entity.startsWith("#")) return codePointToString(Number.parseInt(entity.slice(1), 10), match);
|
|
22
|
+
return NAMED_ENTITIES[entity] ?? match;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function localName(qualifiedName) {
|
|
26
|
+
const colon = qualifiedName.indexOf(":");
|
|
27
|
+
return colon === -1 ? qualifiedName : qualifiedName.slice(colon + 1);
|
|
28
|
+
}
|
|
29
|
+
const ATTRIBUTE_PATTERN = /([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')/g;
|
|
30
|
+
function parseAttributes(source) {
|
|
31
|
+
const attributes = {};
|
|
32
|
+
for (const match of source.matchAll(ATTRIBUTE_PATTERN)) {
|
|
33
|
+
const [, name, , doubleQuoted, singleQuoted] = match;
|
|
34
|
+
if (name === void 0) continue;
|
|
35
|
+
attributes[name] = decodeEntities(doubleQuoted ?? singleQuoted ?? "");
|
|
36
|
+
}
|
|
37
|
+
return attributes;
|
|
38
|
+
}
|
|
39
|
+
function findTagEnd(xml, from) {
|
|
40
|
+
let quote;
|
|
41
|
+
for (let index = from; index < xml.length; index++) {
|
|
42
|
+
const char = xml[index];
|
|
43
|
+
if (quote !== void 0) {
|
|
44
|
+
if (char === quote) quote = void 0;
|
|
45
|
+
} else if (char === "\"" || char === "'") quote = char;
|
|
46
|
+
else if (char === ">") return index;
|
|
47
|
+
}
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
50
|
+
function skipUntil(xml, from, terminator) {
|
|
51
|
+
const end = xml.indexOf(terminator, from);
|
|
52
|
+
if (end === -1) throw new XmlParseError(`Lezáratlan szerkezet, hiányzik: ${terminator}`);
|
|
53
|
+
return end + terminator.length;
|
|
54
|
+
}
|
|
55
|
+
function parseXml(xml) {
|
|
56
|
+
const stack = [];
|
|
57
|
+
let root;
|
|
58
|
+
let position = xml.charCodeAt(0) === 65279 ? 1 : 0;
|
|
59
|
+
const appendText = (value) => {
|
|
60
|
+
const current = stack.at(-1);
|
|
61
|
+
if (current) current.text += value;
|
|
62
|
+
};
|
|
63
|
+
while (position < xml.length) {
|
|
64
|
+
const tagStart = xml.indexOf("<", position);
|
|
65
|
+
if (tagStart === -1) {
|
|
66
|
+
appendText(decodeEntities(xml.slice(position)));
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (tagStart > position) appendText(decodeEntities(xml.slice(position, tagStart)));
|
|
70
|
+
if (xml.startsWith("<!--", tagStart)) {
|
|
71
|
+
position = skipUntil(xml, tagStart + 4, "-->");
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (xml.startsWith("<![CDATA[", tagStart)) {
|
|
75
|
+
const end = xml.indexOf("]]>", tagStart + 9);
|
|
76
|
+
if (end === -1) throw new XmlParseError("Lezáratlan CDATA szakasz");
|
|
77
|
+
appendText(xml.slice(tagStart + 9, end));
|
|
78
|
+
position = end + 3;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (xml.startsWith("<?", tagStart)) {
|
|
82
|
+
position = skipUntil(xml, tagStart + 2, "?>");
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (xml.startsWith("<!", tagStart)) {
|
|
86
|
+
position = skipUntil(xml, tagStart + 2, ">");
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const tagEnd = findTagEnd(xml, tagStart + 1);
|
|
90
|
+
if (tagEnd === -1) throw new XmlParseError("Lezáratlan XML tag");
|
|
91
|
+
const rawTag = xml.slice(tagStart + 1, tagEnd);
|
|
92
|
+
position = tagEnd + 1;
|
|
93
|
+
if (rawTag.startsWith("/")) {
|
|
94
|
+
const closingName = localName(rawTag.slice(1).trim());
|
|
95
|
+
const current = stack.pop();
|
|
96
|
+
if (!current || current.name !== closingName) throw new XmlParseError(`Váratlan záró tag: ${closingName}`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const selfClosing = rawTag.endsWith("/");
|
|
100
|
+
const tagBody = selfClosing ? rawTag.slice(0, -1) : rawTag;
|
|
101
|
+
const nameMatch = /^\s*([^\s/>]+)/.exec(tagBody);
|
|
102
|
+
if (!nameMatch?.[1]) throw new XmlParseError("Érvénytelen XML tag");
|
|
103
|
+
const element = {
|
|
104
|
+
name: localName(nameMatch[1]),
|
|
105
|
+
attributes: parseAttributes(tagBody.slice(nameMatch[0].length)),
|
|
106
|
+
children: [],
|
|
107
|
+
text: ""
|
|
108
|
+
};
|
|
109
|
+
const parent = stack.at(-1);
|
|
110
|
+
if (parent) parent.children.push(element);
|
|
111
|
+
else if (root) throw new XmlParseError("Az XML-nek csak egy gyökéreleme lehet");
|
|
112
|
+
else root = element;
|
|
113
|
+
if (!selfClosing) {
|
|
114
|
+
if (stack.length >= 256) throw new XmlParseError(`Az XML túl mélyen ágyazott (legfeljebb 256 szint).`);
|
|
115
|
+
stack.push(element);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (stack.length > 0) throw new XmlParseError(`Lezáratlan elem: ${stack.at(-1)?.name}`);
|
|
119
|
+
if (!root) throw new XmlParseError("Üres XML dokumentum");
|
|
120
|
+
return root;
|
|
121
|
+
}
|
|
122
|
+
function findChild(element, name) {
|
|
123
|
+
return element?.children.find((child) => child.name === name);
|
|
124
|
+
}
|
|
125
|
+
function findChildren(element, name) {
|
|
126
|
+
return element?.children.filter((child) => child.name === name) ?? [];
|
|
127
|
+
}
|
|
128
|
+
function childText(element, name) {
|
|
129
|
+
const child = findChild(element, name);
|
|
130
|
+
if (!child) return void 0;
|
|
131
|
+
const value = child.text.trim();
|
|
132
|
+
return value === "" ? void 0 : value;
|
|
133
|
+
}
|
|
134
|
+
function childNumber(element, name) {
|
|
135
|
+
const value = childText(element, name);
|
|
136
|
+
if (value === void 0) return void 0;
|
|
137
|
+
const parsed = Number(value.replace(",", "."));
|
|
138
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
139
|
+
}
|
|
140
|
+
function childBoolean(element, name) {
|
|
141
|
+
const value = childText(element, name)?.toLowerCase();
|
|
142
|
+
if (value === "true" || value === "1") return true;
|
|
143
|
+
if (value === "false" || value === "0") return false;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/core/xml/serialize.ts
|
|
147
|
+
function el(name, content, attributes) {
|
|
148
|
+
return attributes === void 0 ? {
|
|
149
|
+
name,
|
|
150
|
+
content
|
|
151
|
+
} : {
|
|
152
|
+
name,
|
|
153
|
+
content,
|
|
154
|
+
attributes
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function optionalEl(name, content) {
|
|
158
|
+
if (content === void 0 || content === null) return void 0;
|
|
159
|
+
if (Array.isArray(content) && !content.some(Boolean)) return void 0;
|
|
160
|
+
return {
|
|
161
|
+
name,
|
|
162
|
+
content
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function isAllowedXmlChar(codePoint) {
|
|
166
|
+
if (codePoint === 9 || codePoint === 10 || codePoint === 13) return true;
|
|
167
|
+
if (codePoint < 32) return false;
|
|
168
|
+
if (codePoint >= 55296 && codePoint <= 57343) return false;
|
|
169
|
+
return codePoint !== 65534 && codePoint !== 65535;
|
|
170
|
+
}
|
|
171
|
+
function stripInvalidXmlChars(value) {
|
|
172
|
+
let result = "";
|
|
173
|
+
for (const char of value) if (isAllowedXmlChar(char.codePointAt(0) ?? 0)) result += char;
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
function escapeXml(value) {
|
|
177
|
+
return stripInvalidXmlChars(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
178
|
+
}
|
|
179
|
+
function formatXmlNumber(value) {
|
|
180
|
+
if (!Number.isFinite(value)) throw new RangeError(`Az XML-be csak véges szám írható, kapott: ${value}`);
|
|
181
|
+
if (Math.abs(value) > Number.MAX_SAFE_INTEGER) throw new RangeError(`Az XML-be írható szám abszolút értéke legfeljebb 2^53 - 1 lehet, kapott: ${value}`);
|
|
182
|
+
if (Number.isInteger(value)) return value.toString();
|
|
183
|
+
const fixed = value.toFixed(10).replace(/0+$/, "").replace(/\.$/, "");
|
|
184
|
+
return fixed === "-0" ? "0" : fixed;
|
|
185
|
+
}
|
|
186
|
+
function formatScalar(value) {
|
|
187
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
188
|
+
if (typeof value === "number") return formatXmlNumber(value);
|
|
189
|
+
return escapeXml(value);
|
|
190
|
+
}
|
|
191
|
+
function isPresent(child) {
|
|
192
|
+
return Boolean(child);
|
|
193
|
+
}
|
|
194
|
+
function renderAttributes(attributes) {
|
|
195
|
+
if (attributes === void 0) return "";
|
|
196
|
+
return Object.entries(attributes).map(([key, value]) => ` ${key}="${escapeXml(value)}"`).join("");
|
|
197
|
+
}
|
|
198
|
+
function renderNode(node, depth) {
|
|
199
|
+
const indent = " ".repeat(depth);
|
|
200
|
+
const { name, content } = node;
|
|
201
|
+
const open = `${name}${renderAttributes(node.attributes)}`;
|
|
202
|
+
if (content === void 0 || content === null) return `${indent}<${open}></${name}>`;
|
|
203
|
+
if (!Array.isArray(content)) return `${indent}<${open}>${formatScalar(content)}</${name}>`;
|
|
204
|
+
const children = content.filter(isPresent);
|
|
205
|
+
if (children.length === 0) return `${indent}<${open}></${name}>`;
|
|
206
|
+
return `${indent}<${open}>\n${children.map((child) => renderNode(child, depth + 1)).join("\n")}\n${indent}</${name}>`;
|
|
207
|
+
}
|
|
208
|
+
const XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
|
|
209
|
+
function buildXmlDocument(options) {
|
|
210
|
+
const declarations = /* @__PURE__ */ new Map([["xmlns", options.namespace]]);
|
|
211
|
+
for (const [prefix, uri] of Object.entries(options.namespaces ?? {})) declarations.set(`xmlns:${prefix}`, uri);
|
|
212
|
+
if (options.schemaLocation !== void 0) declarations.set("xmlns:xsi", XSI_NAMESPACE);
|
|
213
|
+
const attributes = [...declarations].map(([name, value]) => `${name}="${escapeXml(value)}"`);
|
|
214
|
+
if (options.schemaLocation !== void 0) attributes.push(`xsi:schemaLocation="${options.namespace} ${options.schemaLocation}"`);
|
|
215
|
+
const body = options.children.filter(isPresent).map((child) => renderNode(child, 1)).join("\n");
|
|
216
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<${options.root} ${attributes.join(" ")}>\n${body}\n</${options.root}>\n`;
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
export { optionalEl as a, childNumber as c, findChildren as d, parseXml as f, formatXmlNumber as i, childText as l, buildXmlDocument as n, XmlParseError as o, el as r, childBoolean as s, XSI_NAMESPACE as t, findChild as u };
|