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
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { i as hmacHex } from "../crypto-usDg8L2K.js";
|
|
2
|
+
//#region src/observe/metrics.ts
|
|
3
|
+
const DEFAULT_DURATION_BUCKETS_MS = [
|
|
4
|
+
50,
|
|
5
|
+
100,
|
|
6
|
+
250,
|
|
7
|
+
500,
|
|
8
|
+
1e3,
|
|
9
|
+
2500,
|
|
10
|
+
5e3,
|
|
11
|
+
1e4,
|
|
12
|
+
3e4,
|
|
13
|
+
6e4
|
|
14
|
+
];
|
|
15
|
+
const METRIC_HELP = {
|
|
16
|
+
kassza_requests_total: "Számla Agent próbálkozások száma kimenet szerint",
|
|
17
|
+
kassza_request_duration_ms: "Számla Agent próbálkozások időtartama ezredmásodpercben",
|
|
18
|
+
kassza_retries_total: "Automatikus újrapróbálások száma",
|
|
19
|
+
kassza_maintenance_total: "Karbantartás (1-es hiba) miatt elbukott kérések",
|
|
20
|
+
kassza_unexpected_response_total: "Ismeretlen formátumú Számlázz.hu válaszok",
|
|
21
|
+
kassza_store_errors_total: "Tároló (session, napló, zár, gyorsítótár) hibái",
|
|
22
|
+
kassza_warnings_total: "Figyelmeztetések fajta szerint",
|
|
23
|
+
kassza_documents_total: "Kiállított bizonylatok fajta és művelet szerint"
|
|
24
|
+
};
|
|
25
|
+
const NAME_PATTERN = /^[a-zA-Z_:][a-zA-Z0-9_:]*$/;
|
|
26
|
+
const LABEL_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
27
|
+
function escapeLabel(value) {
|
|
28
|
+
return value.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, "\\\"");
|
|
29
|
+
}
|
|
30
|
+
function labelKey(labels) {
|
|
31
|
+
const entries = Object.entries(labels ?? {}).sort(([a], [b]) => a.localeCompare(b));
|
|
32
|
+
for (const [name] of entries) if (!LABEL_PATTERN.test(name)) throw new TypeError(`Érvénytelen metrika-címke: ${name}`);
|
|
33
|
+
return entries.map(([name, value]) => `${name}="${escapeLabel(value)}"`).join(",");
|
|
34
|
+
}
|
|
35
|
+
function assertName(name) {
|
|
36
|
+
if (!NAME_PATTERN.test(name)) throw new TypeError(`Érvénytelen metrikanév: ${name}`);
|
|
37
|
+
}
|
|
38
|
+
function series(name, key, extra) {
|
|
39
|
+
const labels = [key, extra].filter(Boolean).join(",");
|
|
40
|
+
return labels ? `${name}{${labels}}` : name;
|
|
41
|
+
}
|
|
42
|
+
function formatNumber(value) {
|
|
43
|
+
if (value === Number.POSITIVE_INFINITY) return "+Inf";
|
|
44
|
+
return String(value);
|
|
45
|
+
}
|
|
46
|
+
function createMetricsRegistry(buckets = DEFAULT_DURATION_BUCKETS_MS) {
|
|
47
|
+
const sorted = [...buckets].sort((a, b) => a - b);
|
|
48
|
+
if (sorted.some((bucket) => !Number.isFinite(bucket))) throw new TypeError("A hisztogram határai véges számok legyenek.");
|
|
49
|
+
const counters = /* @__PURE__ */ new Map();
|
|
50
|
+
const histograms = /* @__PURE__ */ new Map();
|
|
51
|
+
return {
|
|
52
|
+
counter(name, labels, value = 1) {
|
|
53
|
+
assertName(name);
|
|
54
|
+
if (!Number.isFinite(value) || value < 0) throw new TypeError(`A számláló csak nemnegatív értékkel nőhet, kapott: ${value}`);
|
|
55
|
+
const byLabels = counters.get(name) ?? /* @__PURE__ */ new Map();
|
|
56
|
+
const key = labelKey(labels);
|
|
57
|
+
byLabels.set(key, (byLabels.get(key) ?? 0) + value);
|
|
58
|
+
counters.set(name, byLabels);
|
|
59
|
+
},
|
|
60
|
+
histogram(name, value, labels) {
|
|
61
|
+
assertName(name);
|
|
62
|
+
if (!Number.isFinite(value)) throw new TypeError(`A hisztogram értéke véges szám legyen.`);
|
|
63
|
+
const byLabels = histograms.get(name) ?? /* @__PURE__ */ new Map();
|
|
64
|
+
const key = labelKey(labels);
|
|
65
|
+
const histogram = byLabels.get(key) ?? {
|
|
66
|
+
buckets: sorted.map(() => 0),
|
|
67
|
+
sum: 0,
|
|
68
|
+
count: 0
|
|
69
|
+
};
|
|
70
|
+
sorted.forEach((bound, index) => {
|
|
71
|
+
if (value <= bound) histogram.buckets[index] = (histogram.buckets[index] ?? 0) + 1;
|
|
72
|
+
});
|
|
73
|
+
histogram.sum += value;
|
|
74
|
+
histogram.count += 1;
|
|
75
|
+
byLabels.set(key, histogram);
|
|
76
|
+
histograms.set(name, byLabels);
|
|
77
|
+
},
|
|
78
|
+
renderPrometheus() {
|
|
79
|
+
const lines = [];
|
|
80
|
+
for (const name of [...counters.keys()].sort()) {
|
|
81
|
+
const help = METRIC_HELP[name];
|
|
82
|
+
if (help) lines.push(`# HELP ${name} ${help}`);
|
|
83
|
+
lines.push(`# TYPE ${name} counter`);
|
|
84
|
+
for (const [key, value] of [...counters.get(name) ?? []].sort()) lines.push(`${series(name, key)} ${formatNumber(value)}`);
|
|
85
|
+
}
|
|
86
|
+
for (const name of [...histograms.keys()].sort()) {
|
|
87
|
+
const help = METRIC_HELP[name];
|
|
88
|
+
if (help) lines.push(`# HELP ${name} ${help}`);
|
|
89
|
+
lines.push(`# TYPE ${name} histogram`);
|
|
90
|
+
for (const [key, histogram] of [...histograms.get(name) ?? []].sort()) {
|
|
91
|
+
sorted.forEach((bound, index) => {
|
|
92
|
+
lines.push(`${series(`${name}_bucket`, key, `le="${formatNumber(bound)}"`)} ${histogram.buckets[index] ?? 0}`);
|
|
93
|
+
});
|
|
94
|
+
lines.push(`${series(`${name}_bucket`, key, "le=\"+Inf\"")} ${histogram.count}`);
|
|
95
|
+
lines.push(`${series(`${name}_sum`, key)} ${formatNumber(histogram.sum)}`);
|
|
96
|
+
lines.push(`${series(`${name}_count`, key)} ${histogram.count}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return lines.length > 0 ? `${lines.join("\n")}\n` : "";
|
|
100
|
+
},
|
|
101
|
+
reset() {
|
|
102
|
+
counters.clear();
|
|
103
|
+
histograms.clear();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/observe/observe.ts
|
|
109
|
+
const SPAN_STATUS_OK = 1;
|
|
110
|
+
const SPAN_STATUS_ERROR = 2;
|
|
111
|
+
const MAX_OPEN_SPANS = 1e3;
|
|
112
|
+
const STORE_WARNINGS = /* @__PURE__ */ new Set([
|
|
113
|
+
"session",
|
|
114
|
+
"ledger",
|
|
115
|
+
"lock",
|
|
116
|
+
"dedupe",
|
|
117
|
+
"cache"
|
|
118
|
+
]);
|
|
119
|
+
function randomSalt() {
|
|
120
|
+
return Array.from(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
121
|
+
}
|
|
122
|
+
function safely(run) {
|
|
123
|
+
try {
|
|
124
|
+
run();
|
|
125
|
+
} catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function orderNumberOf(event) {
|
|
130
|
+
if (event.kind === "receipt") return event.document.orderNumber;
|
|
131
|
+
if (event.action === "created") return event.input.orderNumber?.trim() || void 0;
|
|
132
|
+
}
|
|
133
|
+
function spanKey(event) {
|
|
134
|
+
return `${event.requestId}:${event.attempt}`;
|
|
135
|
+
}
|
|
136
|
+
function observe(options = {}) {
|
|
137
|
+
const { logger, tracer, metrics } = options;
|
|
138
|
+
const redact = options.redact !== false;
|
|
139
|
+
const salt = options.orderRefSalt ?? randomSalt();
|
|
140
|
+
const spans = /* @__PURE__ */ new Map();
|
|
141
|
+
async function orderRef(orderNumber) {
|
|
142
|
+
if (orderNumber === void 0) return void 0;
|
|
143
|
+
if (!redact) return orderNumber;
|
|
144
|
+
return `hmac:${(await hmacHex("SHA-256", salt, orderNumber)).slice(0, 16)}`;
|
|
145
|
+
}
|
|
146
|
+
const onRequest = (event) => {
|
|
147
|
+
if (tracer) safely(() => {
|
|
148
|
+
if (spans.size >= 1e3) {
|
|
149
|
+
const oldest = spans.keys().next().value;
|
|
150
|
+
if (oldest !== void 0) {
|
|
151
|
+
spans.get(oldest)?.end();
|
|
152
|
+
spans.delete(oldest);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
spans.set(spanKey(event), tracer.startSpan(`kassza ${event.action}`, { attributes: {
|
|
156
|
+
"kassza.action": event.action,
|
|
157
|
+
"kassza.attempt": event.attempt,
|
|
158
|
+
"kassza.request_id": event.requestId
|
|
159
|
+
} }));
|
|
160
|
+
});
|
|
161
|
+
if (options.logRequests === true) safely(() => logger?.debug?.({
|
|
162
|
+
event: "kassza.request.start",
|
|
163
|
+
...event
|
|
164
|
+
}, `kassza: ${event.action} kérés indul`));
|
|
165
|
+
};
|
|
166
|
+
const onResponse = (event) => {
|
|
167
|
+
const span = spans.get(spanKey(event));
|
|
168
|
+
if (!span) return;
|
|
169
|
+
safely(() => {
|
|
170
|
+
span.setAttribute("http.status_code", event.status);
|
|
171
|
+
span.setAttribute("kassza.response_bytes", event.responseBytes);
|
|
172
|
+
span.setAttribute("kassza.session_reused", event.sessionReused);
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
const onComplete = (event) => {
|
|
176
|
+
const key = spanKey(event);
|
|
177
|
+
const span = spans.get(key);
|
|
178
|
+
spans.delete(key);
|
|
179
|
+
const category = event.error?.category;
|
|
180
|
+
const code = event.error?.code;
|
|
181
|
+
if (span) safely(() => {
|
|
182
|
+
if (category) span.setAttribute("kassza.error.category", category);
|
|
183
|
+
if (code !== void 0) span.setAttribute("kassza.error.code", code);
|
|
184
|
+
if (event.error) {
|
|
185
|
+
span.recordException(event.error);
|
|
186
|
+
span.setStatus({
|
|
187
|
+
code: 2,
|
|
188
|
+
message: event.error.message
|
|
189
|
+
});
|
|
190
|
+
} else if (event.outcome === "error") span.setStatus({ code: 2 });
|
|
191
|
+
else span.setStatus({ code: 1 });
|
|
192
|
+
span.end();
|
|
193
|
+
});
|
|
194
|
+
if (metrics) safely(() => {
|
|
195
|
+
metrics.counter("kassza_requests_total", {
|
|
196
|
+
action: event.action,
|
|
197
|
+
outcome: event.outcome === "success" ? "success" : category ?? "error"
|
|
198
|
+
});
|
|
199
|
+
metrics.histogram("kassza_request_duration_ms", event.durationMs, { action: event.action });
|
|
200
|
+
if (event.willRetry) metrics.counter("kassza_retries_total", { action: event.action });
|
|
201
|
+
if (category === "maintenance") metrics.counter("kassza_maintenance_total");
|
|
202
|
+
if (category === "unexpected_response") metrics.counter("kassza_unexpected_response_total", { action: event.action });
|
|
203
|
+
});
|
|
204
|
+
const data = {
|
|
205
|
+
event: "kassza.request",
|
|
206
|
+
action: event.action,
|
|
207
|
+
attempt: event.attempt,
|
|
208
|
+
requestId: event.requestId,
|
|
209
|
+
outcome: event.outcome,
|
|
210
|
+
durationMs: event.durationMs,
|
|
211
|
+
willRetry: event.willRetry,
|
|
212
|
+
...category ? { errorCategory: category } : {},
|
|
213
|
+
...code === void 0 ? {} : { errorCode: code }
|
|
214
|
+
};
|
|
215
|
+
safely(() => {
|
|
216
|
+
if (event.outcome === "success") logger?.info?.(data, `kassza: ${event.action} sikeres (${event.durationMs} ms)`);
|
|
217
|
+
else logger?.warn?.(data, `kassza: ${event.action} sikertelen${category ? ` (${category})` : ""}${event.willRetry ? ", újrapróbálás" : ""}`);
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
const onWarning = (warning) => {
|
|
221
|
+
safely(() => {
|
|
222
|
+
metrics?.counter("kassza_warnings_total", { kind: warning.kind });
|
|
223
|
+
if (STORE_WARNINGS.has(warning.kind)) metrics?.counter("kassza_store_errors_total", { store: warning.kind });
|
|
224
|
+
});
|
|
225
|
+
safely(() => logger?.warn?.({
|
|
226
|
+
event: "kassza.warning",
|
|
227
|
+
kind: warning.kind,
|
|
228
|
+
...warning.action ? { action: warning.action } : {},
|
|
229
|
+
...warning.operation ? { operation: warning.operation } : {},
|
|
230
|
+
error: warning.error instanceof Error ? warning.error.message : String(warning.error)
|
|
231
|
+
}, warning.message));
|
|
232
|
+
};
|
|
233
|
+
const onDocument = async (event) => {
|
|
234
|
+
safely(() => metrics?.counter("kassza_documents_total", {
|
|
235
|
+
kind: event.kind,
|
|
236
|
+
action: event.action
|
|
237
|
+
}));
|
|
238
|
+
if (!logger?.info) return;
|
|
239
|
+
try {
|
|
240
|
+
const ref = await orderRef(orderNumberOf(event));
|
|
241
|
+
logger.info({
|
|
242
|
+
event: "kassza.document",
|
|
243
|
+
kind: event.kind,
|
|
244
|
+
action: event.action,
|
|
245
|
+
number: event.number,
|
|
246
|
+
...ref === void 0 ? {} : { orderRef: ref }
|
|
247
|
+
}, `kassza: ${event.kind} ${event.action} ${event.number}`);
|
|
248
|
+
} catch {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
return {
|
|
253
|
+
onRequest,
|
|
254
|
+
onResponse,
|
|
255
|
+
onComplete,
|
|
256
|
+
onWarning,
|
|
257
|
+
onDocument
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
const SYNC_HOOKS = [
|
|
261
|
+
"onRequest",
|
|
262
|
+
"onResponse",
|
|
263
|
+
"onError",
|
|
264
|
+
"onComplete",
|
|
265
|
+
"onWarning"
|
|
266
|
+
];
|
|
267
|
+
function combineSync(hooks, name) {
|
|
268
|
+
const handlers = hooks.map((hook) => hook[name]).filter((handler) => handler !== void 0);
|
|
269
|
+
if (handlers.length === 0) return void 0;
|
|
270
|
+
return (event) => {
|
|
271
|
+
let failure;
|
|
272
|
+
for (const handler of handlers) try {
|
|
273
|
+
const result = handler(event);
|
|
274
|
+
if (result instanceof Promise) result.catch(() => void 0);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
failure ??= { error };
|
|
277
|
+
}
|
|
278
|
+
if (failure) throw failure.error;
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function combineHooks(...hooks) {
|
|
282
|
+
const present = hooks.filter((hook) => hook !== void 0);
|
|
283
|
+
const combined = {};
|
|
284
|
+
for (const name of SYNC_HOOKS) {
|
|
285
|
+
const handler = combineSync(present, name);
|
|
286
|
+
if (handler) combined[name] = handler;
|
|
287
|
+
}
|
|
288
|
+
const documentHooks = present.map((hook) => hook.onDocument).filter((hook) => hook !== void 0);
|
|
289
|
+
if (documentHooks.length > 0) combined.onDocument = async (event) => {
|
|
290
|
+
let failure;
|
|
291
|
+
for (const hook of documentHooks) try {
|
|
292
|
+
await hook(event);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
failure ??= { error };
|
|
295
|
+
}
|
|
296
|
+
if (failure) throw failure.error;
|
|
297
|
+
};
|
|
298
|
+
const mode = present.map((hook) => hook.onDocumentError).findLast((value) => value !== void 0);
|
|
299
|
+
if (mode !== void 0) combined.onDocumentError = mode;
|
|
300
|
+
return combined;
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
export { DEFAULT_DURATION_BUCKETS_MS, MAX_OPEN_SPANS, METRIC_HELP, SPAN_STATUS_ERROR, SPAN_STATUS_OK, combineHooks, createMetricsRegistry, observe };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const require_errors = require("./errors-EE96_6D_.cjs");
|
|
2
|
+
//#region src/core/once.ts
|
|
3
|
+
const DEFAULT_RECOVERY_DELAY_MS = 1e3;
|
|
4
|
+
const UNCERTAIN_CATEGORIES = /* @__PURE__ */ new Set([
|
|
5
|
+
"network",
|
|
6
|
+
"timeout",
|
|
7
|
+
"partial_success",
|
|
8
|
+
"duplicate",
|
|
9
|
+
"unexpected_response",
|
|
10
|
+
"unknown"
|
|
11
|
+
]);
|
|
12
|
+
function isUncertainOutcome(error) {
|
|
13
|
+
return error instanceof require_errors.SzamlazzError && UNCERTAIN_CATEGORIES.has(error.category);
|
|
14
|
+
}
|
|
15
|
+
function resolveRecoveryDelay(value) {
|
|
16
|
+
if (value === void 0) return DEFAULT_RECOVERY_DELAY_MS;
|
|
17
|
+
if (!Number.isFinite(value) || value < 0) throw new require_errors.SzamlazzError(`A recoveryDelayMs értéke nemnegatív szám legyen, kapott: ${value}`, { category: "configuration" });
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function wait(ms, signal) {
|
|
21
|
+
if (ms <= 0) return Promise.resolve();
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
if (signal?.aborted) {
|
|
24
|
+
reject(signal.reason);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const timer = setTimeout(() => {
|
|
28
|
+
signal?.removeEventListener("abort", onAbort);
|
|
29
|
+
resolve();
|
|
30
|
+
}, ms);
|
|
31
|
+
const onAbort = () => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
reject(signal?.reason);
|
|
34
|
+
};
|
|
35
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function recoverAfterFailure(lookup, delayMs, signal, state = {}) {
|
|
39
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
40
|
+
await wait(delayMs * attempt, signal);
|
|
41
|
+
let found;
|
|
42
|
+
try {
|
|
43
|
+
found = await lookup();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (!(error instanceof require_errors.SzamlazzError)) throw error;
|
|
46
|
+
state.lookupError = error;
|
|
47
|
+
if (!error.retryable) return null;
|
|
48
|
+
found = void 0;
|
|
49
|
+
}
|
|
50
|
+
if (found) return found;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function unknownOutcomeError(error, reference, options = {}) {
|
|
55
|
+
const lookupError = options.lookupError;
|
|
56
|
+
const lookupNote = lookupError ? ` A visszakeresés is hibát adott (${lookupError.category}: ${lookupError.message}), ezt előbb hárítsd el.` : "";
|
|
57
|
+
return new require_errors.SzamlazzError(error.message, {
|
|
58
|
+
category: error.category,
|
|
59
|
+
code: error.code,
|
|
60
|
+
action: error.action,
|
|
61
|
+
httpStatus: error.httpStatus,
|
|
62
|
+
rawResponse: error.rawResponse,
|
|
63
|
+
details: {
|
|
64
|
+
...error.details,
|
|
65
|
+
outcome: "unknown",
|
|
66
|
+
reference,
|
|
67
|
+
...lookupError ? { lookupError: `${lookupError.category}: ${lookupError.message}` } : {}
|
|
68
|
+
},
|
|
69
|
+
hint: `Nem tudni biztosan, hogy a(z) ${reference} ${options.subject ?? "bizonylata"} elkészült-e, és a visszakeresés sem találta meg.${lookupNote} Ne állítsd ki kézzel újra: később hívd meg ugyanígy a ${options.method ?? "createOnce"}-t, az előbb visszakeres.`,
|
|
70
|
+
cause: error
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
Object.defineProperty(exports, "DEFAULT_RECOVERY_DELAY_MS", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function() {
|
|
77
|
+
return DEFAULT_RECOVERY_DELAY_MS;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "isUncertainOutcome", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function() {
|
|
83
|
+
return isUncertainOutcome;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, "recoverAfterFailure", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function() {
|
|
89
|
+
return recoverAfterFailure;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, "resolveRecoveryDelay", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function() {
|
|
95
|
+
return resolveRecoveryDelay;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, "unknownOutcomeError", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return unknownOutcomeError;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { r as SzamlazzError } from "./errors-DtN4g5Z9.js";
|
|
2
|
+
//#region src/core/once.ts
|
|
3
|
+
const DEFAULT_RECOVERY_DELAY_MS = 1e3;
|
|
4
|
+
const UNCERTAIN_CATEGORIES = /* @__PURE__ */ new Set([
|
|
5
|
+
"network",
|
|
6
|
+
"timeout",
|
|
7
|
+
"partial_success",
|
|
8
|
+
"duplicate",
|
|
9
|
+
"unexpected_response",
|
|
10
|
+
"unknown"
|
|
11
|
+
]);
|
|
12
|
+
function isUncertainOutcome(error) {
|
|
13
|
+
return error instanceof SzamlazzError && UNCERTAIN_CATEGORIES.has(error.category);
|
|
14
|
+
}
|
|
15
|
+
function resolveRecoveryDelay(value) {
|
|
16
|
+
if (value === void 0) return DEFAULT_RECOVERY_DELAY_MS;
|
|
17
|
+
if (!Number.isFinite(value) || value < 0) throw new SzamlazzError(`A recoveryDelayMs értéke nemnegatív szám legyen, kapott: ${value}`, { category: "configuration" });
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function wait(ms, signal) {
|
|
21
|
+
if (ms <= 0) return Promise.resolve();
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
if (signal?.aborted) {
|
|
24
|
+
reject(signal.reason);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const timer = setTimeout(() => {
|
|
28
|
+
signal?.removeEventListener("abort", onAbort);
|
|
29
|
+
resolve();
|
|
30
|
+
}, ms);
|
|
31
|
+
const onAbort = () => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
reject(signal?.reason);
|
|
34
|
+
};
|
|
35
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function recoverAfterFailure(lookup, delayMs, signal, state = {}) {
|
|
39
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
40
|
+
await wait(delayMs * attempt, signal);
|
|
41
|
+
let found;
|
|
42
|
+
try {
|
|
43
|
+
found = await lookup();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (!(error instanceof SzamlazzError)) throw error;
|
|
46
|
+
state.lookupError = error;
|
|
47
|
+
if (!error.retryable) return null;
|
|
48
|
+
found = void 0;
|
|
49
|
+
}
|
|
50
|
+
if (found) return found;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function unknownOutcomeError(error, reference, options = {}) {
|
|
55
|
+
const lookupError = options.lookupError;
|
|
56
|
+
const lookupNote = lookupError ? ` A visszakeresés is hibát adott (${lookupError.category}: ${lookupError.message}), ezt előbb hárítsd el.` : "";
|
|
57
|
+
return new SzamlazzError(error.message, {
|
|
58
|
+
category: error.category,
|
|
59
|
+
code: error.code,
|
|
60
|
+
action: error.action,
|
|
61
|
+
httpStatus: error.httpStatus,
|
|
62
|
+
rawResponse: error.rawResponse,
|
|
63
|
+
details: {
|
|
64
|
+
...error.details,
|
|
65
|
+
outcome: "unknown",
|
|
66
|
+
reference,
|
|
67
|
+
...lookupError ? { lookupError: `${lookupError.category}: ${lookupError.message}` } : {}
|
|
68
|
+
},
|
|
69
|
+
hint: `Nem tudni biztosan, hogy a(z) ${reference} ${options.subject ?? "bizonylata"} elkészült-e, és a visszakeresés sem találta meg.${lookupNote} Ne állítsd ki kézzel újra: később hívd meg ugyanígy a ${options.method ?? "createOnce"}-t, az előbb visszakeres.`,
|
|
70
|
+
cause: error
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { unknownOutcomeError as a, resolveRecoveryDelay as i, isUncertainOutcome as n, recoverAfterFailure as r, DEFAULT_RECOVERY_DELAY_MS as t };
|