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.
Files changed (164) hide show
  1. package/README.en.md +48 -0
  2. package/README.md +152 -22
  3. package/agents/README.md +6 -1
  4. package/agents/api.md +64 -12
  5. package/agents/pitfalls.md +12 -1
  6. package/agents/recipes.md +67 -8
  7. package/agents/skills/kassza/SKILL.md +3 -0
  8. package/agents/skills/migrate-from-szamlazz-js/SKILL.md +39 -0
  9. package/dist/batch/index.cjs +346 -0
  10. package/dist/batch/index.d.cts +91 -0
  11. package/dist/batch/index.d.ts +91 -0
  12. package/dist/batch/index.js +339 -0
  13. package/dist/cli.cjs +105 -14
  14. package/dist/cli.js +104 -13
  15. package/dist/{client-C-PdfL_P.cjs → client-CLFvJCVW.cjs} +358 -181
  16. package/dist/{client-CfaS1-Jx.js → client-Cvf-hTz_.js} +311 -152
  17. package/dist/{client-6MkeuFqD.d.ts → client-DeWWQ-RZ.d.ts} +99 -26
  18. package/dist/{client-B5FryKxJ.d.cts → client-SVZu25MB.d.cts} +99 -26
  19. package/dist/{context-DXNbTPwz.d.cts → context-CFNKzStE.d.cts} +82 -58
  20. package/dist/{context-BxQlIlug.d.ts → context-kb33TgzE.d.ts} +82 -58
  21. package/dist/cookie-stores/index.cjs +21 -150
  22. package/dist/cookie-stores/index.d.cts +4 -63
  23. package/dist/cookie-stores/index.d.ts +4 -63
  24. package/dist/cookie-stores/index.js +3 -144
  25. package/dist/create-CflXrPip.js +204 -0
  26. package/dist/create-CvUvLUaT.cjs +257 -0
  27. package/dist/{create-once-DgMtKKcG.cjs → create-once-9yxR_Er_.cjs} +285 -33
  28. package/dist/create-once-Bh6fOWkW.d.cts +20 -0
  29. package/dist/{create-once-Cz621l8r.js → create-once-Ca2gMk1h.js} +250 -34
  30. package/dist/create-once-VKp0tVow.d.ts +20 -0
  31. package/dist/data-link/index.cjs +4 -4
  32. package/dist/data-link/index.d.cts +2 -52
  33. package/dist/data-link/index.d.ts +2 -52
  34. package/dist/data-link/index.js +4 -4
  35. package/dist/delegation/index.cjs +4 -4
  36. package/dist/delegation/index.d.cts +2 -2
  37. package/dist/delegation/index.d.ts +2 -2
  38. package/dist/delegation/index.js +4 -4
  39. package/dist/{errors-DLrb0g64.js → errors-DtN4g5Z9.js} +9 -1
  40. package/dist/{errors-DxeuTslP.cjs → errors-EE96_6D_.cjs} +20 -0
  41. package/dist/{get-Csm2n0rZ.cjs → get-BdMTseh4.cjs} +9 -183
  42. package/dist/{get-DT3JEgQ6.js → get-CZEShCcj.js} +4 -124
  43. package/dist/index-BhUPY_EH.d.cts +109 -0
  44. package/dist/index-BqGgQ4t3.d.ts +109 -0
  45. package/dist/{index-CYAGCdKJ.d.cts → index-C-7yWV7L.d.cts} +24 -1
  46. package/dist/{index-CYAGCdKJ.d.ts → index-C-7yWV7L.d.ts} +24 -1
  47. package/dist/index.cjs +19 -5
  48. package/dist/index.d.cts +10 -20
  49. package/dist/index.d.ts +10 -20
  50. package/dist/index.js +6 -6
  51. package/dist/ipn/index.cjs +26 -5
  52. package/dist/ipn/index.d.cts +12 -1
  53. package/dist/ipn/index.d.ts +12 -1
  54. package/dist/ipn/index.js +26 -6
  55. package/dist/{issue-AGRohSm7.cjs → issue-Bin4tKD_.cjs} +416 -342
  56. package/dist/{issue-DtSLpVdJ.js → issue-DMA1Nbr1.js} +394 -266
  57. package/dist/journal/index.cjs +454 -0
  58. package/dist/journal/index.d.cts +18 -0
  59. package/dist/journal/index.d.ts +18 -0
  60. package/dist/journal/index.js +445 -0
  61. package/dist/journal-DvI81Kt7.d.cts +114 -0
  62. package/dist/journal-Y9qrIB8G.d.ts +114 -0
  63. package/dist/mcp/index.cjs +1 -1
  64. package/dist/mcp/index.d.cts +1 -1
  65. package/dist/mcp/index.d.ts +1 -1
  66. package/dist/mcp/index.js +1 -1
  67. package/dist/money/index.cjs +2 -1
  68. package/dist/money/index.d.cts +2 -2
  69. package/dist/money/index.d.ts +2 -2
  70. package/dist/money/index.js +2 -2
  71. package/dist/{money-t7uy1n91.js → money-Cw457SD6.js} +95 -3
  72. package/dist/{money-BxytJW6f.cjs → money-K9j0wPit.cjs} +99 -1
  73. package/dist/nav/index.cjs +2 -2
  74. package/dist/nav/index.d.cts +1 -1
  75. package/dist/nav/index.d.ts +1 -1
  76. package/dist/nav/index.js +2 -2
  77. package/dist/{nav-BEwcX7-N.cjs → nav-BNbc8U0R.cjs} +1 -1
  78. package/dist/{nav-CK1WgYo7.js → nav-BcCerwWS.js} +1 -1
  79. package/dist/node/index.cjs +124 -0
  80. package/dist/node/index.d.cts +35 -0
  81. package/dist/node/index.d.ts +35 -0
  82. package/dist/node/index.js +120 -0
  83. package/dist/observe/index.cjs +311 -0
  84. package/dist/observe/index.d.cts +53 -0
  85. package/dist/observe/index.d.ts +53 -0
  86. package/dist/observe/index.js +303 -0
  87. package/dist/once-BN_3B5OF.cjs +103 -0
  88. package/dist/once-CqqZxsXG.js +74 -0
  89. package/dist/{parse-C608ehqM.js → parse-Cr7yQ3_z.js} +2 -2
  90. package/dist/{parse-BJj-aqKy.cjs → parse-DOA2XQ3e.cjs} +2 -2
  91. package/dist/payments/barion.cjs +26 -2
  92. package/dist/payments/barion.d.cts +2 -2
  93. package/dist/payments/barion.d.ts +2 -2
  94. package/dist/payments/barion.js +26 -2
  95. package/dist/payments/index.cjs +7 -2
  96. package/dist/payments/index.d.cts +4 -4
  97. package/dist/payments/index.d.ts +4 -4
  98. package/dist/payments/index.js +3 -3
  99. package/dist/payments/paypal.cjs +16 -2
  100. package/dist/payments/paypal.d.cts +2 -2
  101. package/dist/payments/paypal.d.ts +2 -2
  102. package/dist/payments/paypal.js +16 -2
  103. package/dist/payments/revolut.cjs +16 -2
  104. package/dist/payments/revolut.d.cts +2 -2
  105. package/dist/payments/revolut.d.ts +2 -2
  106. package/dist/payments/revolut.js +16 -2
  107. package/dist/payments/simplepay.cjs +36 -4
  108. package/dist/payments/simplepay.d.cts +2 -2
  109. package/dist/payments/simplepay.d.ts +2 -2
  110. package/dist/payments/simplepay.js +36 -4
  111. package/dist/payments/stripe.cjs +19 -2
  112. package/dist/payments/stripe.d.cts +2 -2
  113. package/dist/payments/stripe.d.ts +2 -2
  114. package/dist/payments/stripe.js +19 -2
  115. package/dist/push-BXj0Sf0Z.d.ts +52 -0
  116. package/dist/push-D4nNbCNV.d.cts +52 -0
  117. package/dist/reference-B5TATqb5.js +124 -0
  118. package/dist/reference-BIdYMK0t.cjs +183 -0
  119. package/dist/reports/index.cjs +1 -1
  120. package/dist/reports/index.d.cts +1 -1
  121. package/dist/reports/index.d.ts +1 -1
  122. package/dist/reports/index.js +1 -1
  123. package/dist/{serialize-DSE_o9RK.js → serialize-B2eFh3D-.js} +5 -1
  124. package/dist/{serialize-BXOww1Uq.cjs → serialize-CquIsxA-.cjs} +5 -1
  125. package/dist/{server-Cd8HB661.js → server-BrJUbXs7.js} +8 -7
  126. package/dist/{server-C6PoNkdD.cjs → server-Dw9j8Mnd.cjs} +17 -16
  127. package/dist/session-Ckl5eJhV.d.ts +7 -0
  128. package/dist/{session-CKOuE6Jc.cjs → session-DeM5vjvC.cjs} +69 -13
  129. package/dist/{session-rMKaJcmq.js → session-SaEEXu2N.js} +58 -14
  130. package/dist/session-YbChChx7.d.cts +7 -0
  131. package/dist/storage/fs.cjs +1 -1
  132. package/dist/storage/fs.js +1 -1
  133. package/dist/storage/index.cjs +1 -1
  134. package/dist/storage/index.js +1 -1
  135. package/dist/store-C1rHd9DB.d.cts +19 -0
  136. package/dist/store-C1rHd9DB.d.ts +19 -0
  137. package/dist/stores/index.cjs +24 -0
  138. package/dist/stores/index.d.cts +4 -0
  139. package/dist/stores/index.d.ts +4 -0
  140. package/dist/stores/index.js +3 -0
  141. package/dist/stores-BNrS0dWl.cjs +506 -0
  142. package/dist/stores-DhjGBrl_.js +441 -0
  143. package/dist/testing/index.cjs +28 -16
  144. package/dist/testing/index.d.cts +6 -3
  145. package/dist/testing/index.d.ts +6 -3
  146. package/dist/testing/index.js +26 -14
  147. package/dist/{types-BVeR7KyU.d.ts → types-B1A8mUIE.d.cts} +13 -1
  148. package/dist/{types-BVeR7KyU.d.cts → types-ByAEvGsZ.d.ts} +13 -1
  149. package/dist/{types-k--zHf4l.d.ts → types-D1zDOH_F.d.ts} +1 -1
  150. package/dist/{types-DH8QoNZK.d.cts → types-lnKkQdot.d.cts} +1 -1
  151. package/dist/warnings-B3DXnveC.d.cts +31 -0
  152. package/dist/warnings-B3DXnveC.d.ts +31 -0
  153. package/dist/warnings-DeIw5RFj.cjs +20 -0
  154. package/dist/warnings-DwTl5J-2.js +15 -0
  155. package/dist/{webhook-CrEGohbg.js → webhook-CQVShAfI.js} +44 -1
  156. package/dist/{webhook-81giRMdQ.cjs → webhook-Ckj-_hPD.cjs} +67 -0
  157. package/dist/webhook-CmdhGiH5.d.cts +11 -0
  158. package/dist/webhook-D6lEejob.d.ts +11 -0
  159. package/llms.txt +4 -3
  160. package/package.json +92 -4
  161. package/dist/session-Dm_45x8K.d.cts +0 -11
  162. package/dist/session-Dm_45x8K.d.ts +0 -11
  163. package/dist/webhook-CpCMHhn2.d.ts +0 -6
  164. package/dist/webhook-CpMJuP6c.d.cts +0 -6
@@ -0,0 +1,441 @@
1
+ import { r as decodeUtf8 } from "./binary-D0M9U2MD.js";
2
+ import { o as storeCapabilities } from "./session-SaEEXu2N.js";
3
+ //#region src/cookie-stores/resilient.ts
4
+ function warnCookieStoreError(event) {
5
+ const continuation = ATOMIC_OPERATIONS.has(event.operation) ? "a hibát a kassza kapja meg és kezeli." : "a kérés session nélkül folytatódik.";
6
+ console.warn(`[szamlazz] A tároló "${event.operation}" művelete sikertelen, ${continuation}`, event.error);
7
+ }
8
+ const ATOMIC_OPERATIONS = /* @__PURE__ */ new Set([
9
+ "setIfAbsent",
10
+ "increment",
11
+ "deleteIfEquals"
12
+ ]);
13
+ function withTimeout(promise, timeoutMs, operation) {
14
+ if (timeoutMs === void 0) return promise;
15
+ let timer;
16
+ const timeout = new Promise((_, reject) => {
17
+ timer = setTimeout(() => {
18
+ reject(/* @__PURE__ */ new Error(`A session cookie store "${operation}" művelete nem fejeződött be ${timeoutMs} ms alatt.`));
19
+ }, timeoutMs);
20
+ });
21
+ return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
22
+ }
23
+ function resilientCookieStore(store, options = {}) {
24
+ const onError = options.onError ?? warnCookieStoreError;
25
+ if (options.timeoutMs !== void 0 && !(options.timeoutMs > 0)) throw new RangeError(`A timeoutMs pozitív szám legyen, kapott: ${options.timeoutMs}`);
26
+ function report(operation, key, error) {
27
+ try {
28
+ onError({
29
+ operation,
30
+ key,
31
+ error
32
+ });
33
+ } catch {
34
+ return;
35
+ }
36
+ }
37
+ async function run(operation, key, call) {
38
+ try {
39
+ return await withTimeout(Promise.resolve().then(call), options.timeoutMs, operation);
40
+ } catch (error) {
41
+ report(operation, key, error);
42
+ return;
43
+ }
44
+ }
45
+ async function strict(operation, key, call) {
46
+ try {
47
+ return await withTimeout(Promise.resolve().then(call), options.timeoutMs, operation);
48
+ } catch (error) {
49
+ report(operation, key, error);
50
+ throw error;
51
+ }
52
+ }
53
+ const setIfAbsent = store.setIfAbsent?.bind(store);
54
+ const increment = store.increment?.bind(store);
55
+ const deleteIfEquals = store.deleteIfEquals?.bind(store);
56
+ return {
57
+ async get(key) {
58
+ return await run("get", key, () => store.get(key)) ?? void 0;
59
+ },
60
+ async set(key, value, ttlSeconds) {
61
+ await run("set", key, () => store.set(key, value, ttlSeconds));
62
+ },
63
+ async delete(key) {
64
+ await run("delete", key, () => store.delete(key));
65
+ },
66
+ ...setIfAbsent && { setIfAbsent: (key, value, ttlSeconds) => strict("setIfAbsent", key, () => setIfAbsent(key, value, ttlSeconds)) },
67
+ ...increment && { increment: (key, ttlSeconds) => strict("increment", key, () => increment(key, ttlSeconds)) },
68
+ ...deleteIfEquals && { deleteIfEquals: (key, value) => strict("deleteIfEquals", key, () => deleteIfEquals(key, value)) }
69
+ };
70
+ }
71
+ //#endregion
72
+ //#region src/cookie-stores/shared.ts
73
+ function prefixKey(options, key) {
74
+ const prefix = options?.prefix;
75
+ return prefix ? `${prefix}${key}` : key;
76
+ }
77
+ function finalizeCookieStore(store, options) {
78
+ if (options?.resilient === false) return store;
79
+ return resilientCookieStore(store, {
80
+ onError: options?.onError,
81
+ timeoutMs: options?.timeoutMs
82
+ });
83
+ }
84
+ function readCookieValue(value) {
85
+ if (typeof value === "string") return value === "" ? void 0 : value;
86
+ if (value instanceof Uint8Array) return readCookieValue(decodeUtf8(value));
87
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
88
+ }
89
+ function wholeSeconds(ttlSeconds, minimum) {
90
+ if (!Number.isFinite(ttlSeconds)) return minimum;
91
+ return Math.max(minimum, Math.ceil(ttlSeconds));
92
+ }
93
+ //#endregion
94
+ //#region src/cookie-stores/cloudflare-kv.ts
95
+ const CLOUDFLARE_KV_MIN_TTL_SECONDS = 60;
96
+ function cloudflareKvCookieStore(namespace, options) {
97
+ return finalizeCookieStore({
98
+ async get(key) {
99
+ return readCookieValue(await namespace.get(prefixKey(options, key)));
100
+ },
101
+ async set(key, value, ttlSeconds) {
102
+ await namespace.put(prefixKey(options, key), value, { expirationTtl: wholeSeconds(ttlSeconds, 60) });
103
+ },
104
+ async delete(key) {
105
+ await namespace.delete(prefixKey(options, key));
106
+ }
107
+ }, options);
108
+ }
109
+ //#endregion
110
+ //#region src/cookie-stores/custom.ts
111
+ function customCookieStore(store, options) {
112
+ const prefixed = (key) => prefixKey(options, key);
113
+ const wrapped = {
114
+ get: (key) => store.get(prefixed(key)),
115
+ set: (key, value, ttlSeconds) => store.set(prefixed(key), value, ttlSeconds),
116
+ delete: (key) => store.delete(prefixed(key))
117
+ };
118
+ const setIfAbsent = store.setIfAbsent?.bind(store);
119
+ const increment = store.increment?.bind(store);
120
+ const deleteIfEquals = store.deleteIfEquals?.bind(store);
121
+ return finalizeCookieStore({
122
+ ...wrapped,
123
+ ...setIfAbsent && { setIfAbsent: (key, value, ttlSeconds) => setIfAbsent(prefixed(key), value, ttlSeconds) },
124
+ ...increment && { increment: (key, ttlSeconds) => increment(prefixed(key), ttlSeconds) },
125
+ ...deleteIfEquals && { deleteIfEquals: (key, value) => deleteIfEquals(prefixed(key), value) }
126
+ }, options);
127
+ }
128
+ //#endregion
129
+ //#region src/cookie-stores/scripts.ts
130
+ const SET_IF_ABSENT_SCRIPT = "if redis.call('SET', KEYS[1], ARGV[1], 'NX', 'EX', ARGV[2]) then return 1 else return 0 end";
131
+ const INCREMENT_SCRIPT = "local value = redis.call('INCR', KEYS[1]) redis.call('EXPIRE', KEYS[1], ARGV[1]) return value";
132
+ const DELETE_IF_EQUALS_SCRIPT = "if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) else return 0 end";
133
+ function scriptNumber(value) {
134
+ const parsed = typeof value === "number" ? value : Number(value);
135
+ if (!Number.isFinite(parsed)) throw new TypeError(`A Redis szkript nem számot adott vissza: ${String(value)}`);
136
+ return parsed;
137
+ }
138
+ function atomicOperations(run, prefixed, seconds) {
139
+ return {
140
+ async setIfAbsent(key, value, ttlSeconds) {
141
+ return scriptNumber(await run(SET_IF_ABSENT_SCRIPT, prefixed(key), [value, String(seconds(ttlSeconds))])) === 1;
142
+ },
143
+ async increment(key, ttlSeconds) {
144
+ return scriptNumber(await run(INCREMENT_SCRIPT, prefixed(key), [String(seconds(ttlSeconds))]));
145
+ },
146
+ async deleteIfEquals(key, value) {
147
+ return scriptNumber(await run(DELETE_IF_EQUALS_SCRIPT, prefixed(key), [value])) > 0;
148
+ }
149
+ };
150
+ }
151
+ //#endregion
152
+ //#region src/cookie-stores/ioredis.ts
153
+ function ioredisCookieStore(redis, options) {
154
+ const base = {
155
+ async get(key) {
156
+ return readCookieValue(await redis.get(prefixKey(options, key)));
157
+ },
158
+ async set(key, value, ttlSeconds) {
159
+ await redis.set(prefixKey(options, key), value, "EX", wholeSeconds(ttlSeconds, 1));
160
+ },
161
+ async delete(key) {
162
+ await redis.del(prefixKey(options, key));
163
+ }
164
+ };
165
+ const evaluate = redis.eval?.bind(redis);
166
+ if (!evaluate) return finalizeCookieStore(base, options);
167
+ const atomic = atomicOperations((script, key, args) => evaluate(script, 1, key, ...args), (key) => prefixKey(options, key), (ttlSeconds) => wholeSeconds(ttlSeconds, 1));
168
+ return finalizeCookieStore({
169
+ ...base,
170
+ ...atomic
171
+ }, options);
172
+ }
173
+ //#endregion
174
+ //#region src/cookie-stores/node-redis.ts
175
+ function nodeRedisCookieStore(client, options) {
176
+ const base = {
177
+ async get(key) {
178
+ return readCookieValue(await client.get(prefixKey(options, key)));
179
+ },
180
+ async set(key, value, ttlSeconds) {
181
+ await client.set(prefixKey(options, key), value, { EX: wholeSeconds(ttlSeconds, 1) });
182
+ },
183
+ async delete(key) {
184
+ await client.del(prefixKey(options, key));
185
+ }
186
+ };
187
+ const evaluate = client.eval?.bind(client);
188
+ if (!evaluate) return finalizeCookieStore(base, options);
189
+ const atomic = atomicOperations((script, key, args) => evaluate(script, {
190
+ keys: [key],
191
+ arguments: args
192
+ }), (key) => prefixKey(options, key), (ttlSeconds) => wholeSeconds(ttlSeconds, 1));
193
+ return finalizeCookieStore({
194
+ ...base,
195
+ ...atomic
196
+ }, options);
197
+ }
198
+ //#endregion
199
+ //#region src/cookie-stores/upstash.ts
200
+ function upstashRedisCookieStore(redis, options) {
201
+ const base = {
202
+ async get(key) {
203
+ return readCookieValue(await redis.get(prefixKey(options, key)));
204
+ },
205
+ async set(key, value, ttlSeconds) {
206
+ await redis.set(prefixKey(options, key), value, { ex: wholeSeconds(ttlSeconds, 1) });
207
+ },
208
+ async delete(key) {
209
+ await redis.del(prefixKey(options, key));
210
+ }
211
+ };
212
+ const evaluate = redis.eval?.bind(redis);
213
+ if (!evaluate) return finalizeCookieStore(base, options);
214
+ const atomic = atomicOperations((script, key, args) => evaluate(script, [key], args), (key) => prefixKey(options, key), (ttlSeconds) => wholeSeconds(ttlSeconds, 1));
215
+ return finalizeCookieStore({
216
+ ...base,
217
+ ...atomic
218
+ }, options);
219
+ }
220
+ //#endregion
221
+ //#region src/stores/diagnose.ts
222
+ function randomSuffix() {
223
+ return Array.from(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(8)), (byte) => byte.toString(16).padStart(2, "0")).join("");
224
+ }
225
+ function messageOf(error) {
226
+ return error instanceof Error ? error.message : String(error);
227
+ }
228
+ async function diagnoseStore(store, options = {}) {
229
+ const now = options.now ?? (() => Date.now());
230
+ const key = `${options.keyPrefix ?? "szamlazz:diagnose:"}${randomSuffix()}`;
231
+ const capabilities = storeCapabilities(store);
232
+ const problems = [];
233
+ const started = now();
234
+ const step = async (label, run) => {
235
+ try {
236
+ await run();
237
+ return true;
238
+ } catch (error) {
239
+ problems.push(`${label}: ${messageOf(error)}`);
240
+ return false;
241
+ }
242
+ };
243
+ const basic = await step("írás és olvasás", async () => {
244
+ await store.set(key, "kassza", 60);
245
+ const read = await store.get(key);
246
+ if (read !== "kassza") throw new Error(`a visszaolvasott érték: ${String(read)}`);
247
+ await store.delete(key);
248
+ const deleted = await store.get(key);
249
+ if (deleted !== void 0 && deleted !== null) throw new Error("a törölt kulcs még olvasható");
250
+ });
251
+ const lock = capabilities.setIfAbsent && await step("setIfAbsent", async () => {
252
+ if (await store.setIfAbsent?.(key, "a", 60) !== true) throw new Error("az üres kulcsra false");
253
+ if (await store.setIfAbsent?.(key, "b", 60) !== false) throw new Error("a foglalt kulcsra true");
254
+ if (capabilities.deleteIfEquals) {
255
+ if (await store.deleteIfEquals?.(key, "b") !== false) throw new Error("deleteIfEquals idegen tokenre törölt");
256
+ if (await store.deleteIfEquals?.(key, "a") !== true) throw new Error("deleteIfEquals a saját tokenre nem törölt");
257
+ } else await store.delete(key);
258
+ });
259
+ const counter = capabilities.increment && await step("increment", async () => {
260
+ const first = await store.increment?.(key, 60);
261
+ const second = await store.increment?.(key, 60);
262
+ if (first !== 1 || second !== 2) throw new Error(`a számláló értékei: ${first}, ${second}`);
263
+ await store.delete(key);
264
+ });
265
+ await Promise.resolve(store.delete(key)).catch(() => void 0);
266
+ if (!capabilities.setIfAbsent) problems.push("Nincs setIfAbsent: createOnce zárnak nem alkalmas (például Cloudflare KV).");
267
+ if (!capabilities.increment) problems.push("Nincs increment: naplónak nem alkalmas, a próbálkozás-napló nem atomikus.");
268
+ return {
269
+ ok: basic && lock === true && counter === true,
270
+ capabilities,
271
+ suitableFor: {
272
+ session: basic,
273
+ attemptLedger: basic,
274
+ createOnceLock: basic && lock === true,
275
+ journal: basic && counter === true,
276
+ webhookDedupe: basic
277
+ },
278
+ latencyMs: Math.max(0, now() - started),
279
+ problems
280
+ };
281
+ }
282
+ //#endregion
283
+ //#region src/stores/durable-object.ts
284
+ const OPERATIONS = /* @__PURE__ */ new Set([
285
+ "get",
286
+ "set",
287
+ "delete",
288
+ "setIfAbsent",
289
+ "increment",
290
+ "deleteIfEquals"
291
+ ]);
292
+ const DURABLE_OBJECT_STORE_URL = "https://kassza-store.internal/";
293
+ function isEntry(value) {
294
+ if (typeof value !== "object" || value === null) return false;
295
+ const entry = value;
296
+ return typeof entry.value === "string" && typeof entry.expiresAt === "number";
297
+ }
298
+ async function readLive(storage, key, now) {
299
+ const stored = await storage.get(key);
300
+ if (!isEntry(stored)) return void 0;
301
+ if (stored.expiresAt <= now) {
302
+ await storage.delete(key);
303
+ return;
304
+ }
305
+ return stored.value;
306
+ }
307
+ function expiresAt(ttlSeconds, now) {
308
+ return now + Math.max(1, Math.ceil(ttlSeconds !== void 0 && Number.isFinite(ttlSeconds) ? ttlSeconds : 1)) * 1e3;
309
+ }
310
+ function parseCommand(body) {
311
+ if (typeof body !== "object" || body === null) return void 0;
312
+ const command = body;
313
+ if (typeof command.op !== "string" || !OPERATIONS.has(command.op)) return void 0;
314
+ if (typeof command.key !== "string" || command.key === "") return void 0;
315
+ if (command.value !== void 0 && typeof command.value !== "string") return void 0;
316
+ if (command.ttlSeconds !== void 0 && typeof command.ttlSeconds !== "number") return void 0;
317
+ return command;
318
+ }
319
+ function requireValue(command) {
320
+ if (command.value === void 0) throw new TypeError(`A(z) ${command.op} művelethez érték kell.`);
321
+ return command.value;
322
+ }
323
+ async function runCommand(storage, command, now) {
324
+ const { key } = command;
325
+ switch (command.op) {
326
+ case "get": return await readLive(storage, key, now) ?? null;
327
+ case "set":
328
+ await storage.put(key, {
329
+ value: requireValue(command),
330
+ expiresAt: expiresAt(command.ttlSeconds, now)
331
+ });
332
+ return null;
333
+ case "delete":
334
+ await storage.delete(key);
335
+ return null;
336
+ case "setIfAbsent": {
337
+ const value = requireValue(command);
338
+ if (await readLive(storage, key, now) !== void 0) return false;
339
+ await storage.put(key, {
340
+ value,
341
+ expiresAt: expiresAt(command.ttlSeconds, now)
342
+ });
343
+ return true;
344
+ }
345
+ case "increment": {
346
+ const current = Number.parseInt(await readLive(storage, key, now) ?? "0", 10);
347
+ const next = (Number.isInteger(current) ? current : 0) + 1;
348
+ await storage.put(key, {
349
+ value: String(next),
350
+ expiresAt: expiresAt(command.ttlSeconds, now)
351
+ });
352
+ return next;
353
+ }
354
+ case "deleteIfEquals":
355
+ if (await readLive(storage, key, now) !== requireValue(command)) return false;
356
+ await storage.delete(key);
357
+ return true;
358
+ }
359
+ }
360
+ function jsonResponse(body, status = 200) {
361
+ return new Response(JSON.stringify(body), {
362
+ status,
363
+ headers: { "content-type": "application/json" }
364
+ });
365
+ }
366
+ async function handleDurableObjectStoreRequest(storage, request) {
367
+ if (request.method !== "POST") return jsonResponse({ error: "Csak POST kérés engedélyezett." }, 405);
368
+ let command;
369
+ try {
370
+ command = parseCommand(await request.json());
371
+ } catch {
372
+ command = void 0;
373
+ }
374
+ if (!command) return jsonResponse({ error: "Érvénytelen tároló-parancs." }, 400);
375
+ try {
376
+ return jsonResponse({ result: await runCommand(storage, command, Date.now()) });
377
+ } catch (error) {
378
+ return jsonResponse({ error: error instanceof Error ? error.message : String(error) }, 400);
379
+ }
380
+ }
381
+ async function call(stub, command) {
382
+ const response = await stub.fetch(DURABLE_OBJECT_STORE_URL, {
383
+ method: "POST",
384
+ headers: { "content-type": "application/json" },
385
+ body: JSON.stringify(command)
386
+ });
387
+ const body = await response.json().catch(() => ({}));
388
+ if (!response.ok) throw new Error(`A Durable Object tároló ${command.op} művelete sikertelen (HTTP ${response.status}): ${body.error ?? "ismeretlen hiba"}`);
389
+ return body.result ?? null;
390
+ }
391
+ function durableObjectStore(stub) {
392
+ return {
393
+ async get(key) {
394
+ const result = await call(stub, {
395
+ op: "get",
396
+ key
397
+ });
398
+ return typeof result === "string" ? result : void 0;
399
+ },
400
+ async set(key, value, ttlSeconds) {
401
+ await call(stub, {
402
+ op: "set",
403
+ key,
404
+ value,
405
+ ttlSeconds
406
+ });
407
+ },
408
+ async delete(key) {
409
+ await call(stub, {
410
+ op: "delete",
411
+ key
412
+ });
413
+ },
414
+ async setIfAbsent(key, value, ttlSeconds) {
415
+ return await call(stub, {
416
+ op: "setIfAbsent",
417
+ key,
418
+ value,
419
+ ttlSeconds
420
+ }) === true;
421
+ },
422
+ async increment(key, ttlSeconds) {
423
+ const result = await call(stub, {
424
+ op: "increment",
425
+ key,
426
+ ttlSeconds
427
+ });
428
+ if (typeof result !== "number") throw new TypeError(`A Durable Object tároló nem számot adott vissza: ${String(result)}`);
429
+ return result;
430
+ },
431
+ async deleteIfEquals(key, value) {
432
+ return await call(stub, {
433
+ op: "deleteIfEquals",
434
+ key,
435
+ value
436
+ }) === true;
437
+ }
438
+ };
439
+ }
440
+ //#endregion
441
+ export { upstashRedisCookieStore as a, customCookieStore as c, resilientCookieStore as d, diagnoseStore as i, CLOUDFLARE_KV_MIN_TTL_SECONDS as l, durableObjectStore as n, nodeRedisCookieStore as o, handleDurableObjectStoreRequest as r, ioredisCookieStore as s, DURABLE_OBJECT_STORE_URL as t, cloudflareKvCookieStore as u };
@@ -1,13 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_create_once = require("../create-once-DgMtKKcG.cjs");
3
- const require_errors = require("../errors-DxeuTslP.cjs");
2
+ const require_create_once = require("../create-once-9yxR_Er_.cjs");
3
+ const require_errors = require("../errors-EE96_6D_.cjs");
4
4
  const require_binary = require("../binary-B89HM03_.cjs");
5
- const require_serialize = require("../serialize-BXOww1Uq.cjs");
5
+ const require_serialize = require("../serialize-CquIsxA-.cjs");
6
+ const require_issue = require("../issue-Bin4tKD_.cjs");
6
7
  const require_dates = require("../dates-CPgBodkP.cjs");
7
8
  const require_rounding = require("../rounding-TxoWy2ww.cjs");
8
9
  const require_vat = require("../vat-g35srbNG.cjs");
9
- const require_money = require("../money-BxytJW6f.cjs");
10
- const require_issue = require("../issue-AGRohSm7.cjs");
10
+ const require_money = require("../money-K9j0wPit.cjs");
11
+ const require_create = require("../create-CvUvLUaT.cjs");
11
12
  //#region src/testing/fake-agent-http.ts
12
13
  const XML_CONTENT_TYPE = "application/xml; charset=UTF-8";
13
14
  const TEXT_CONTENT_TYPE = "text/plain; charset=UTF-8";
@@ -1509,11 +1510,18 @@ function normalizePayments(input, today) {
1509
1510
  description: input.description
1510
1511
  }];
1511
1512
  }
1513
+ let mockScopes = 0;
1512
1514
  function createMockKassza(options = {}) {
1513
1515
  const now = options.now ?? (() => /* @__PURE__ */ new Date());
1514
1516
  const calls = [];
1515
1517
  const failures = /* @__PURE__ */ new Map();
1516
- const onDocument = options.hooks?.onDocument;
1518
+ const hooks = options.hooks;
1519
+ const emit = (event) => require_create_once.emitDocumentEvent(hooks?.onDocument, event, {
1520
+ mode: hooks?.onDocumentError,
1521
+ onWarning: hooks?.onWarning
1522
+ });
1523
+ mockScopes += 1;
1524
+ const guard = { scope: `mock:${mockScopes}` };
1517
1525
  const invoices = /* @__PURE__ */ new Map();
1518
1526
  const receipts = /* @__PURE__ */ new Map();
1519
1527
  const sequences = /* @__PURE__ */ new Map();
@@ -1642,10 +1650,10 @@ function createMockKassza(options = {}) {
1642
1650
  };
1643
1651
  const createReceiptRecord = (input, callId) => {
1644
1652
  const defaults = options.defaults?.receipt ?? {};
1645
- require_issue.buildCreateReceiptXml([], defaults, input);
1653
+ require_create.buildCreateReceiptXml([], defaults, input);
1646
1654
  assertUniqueCallId(callId);
1647
1655
  const currency = input.currency ?? defaults.currency ?? "HUF";
1648
- const calculated = require_issue.calculateReceiptItems(input.items, currency);
1656
+ const calculated = require_create.calculateReceiptItems(input.items, currency);
1649
1657
  const totals = require_money.summarizeItems(calculated.map((item) => item.amounts));
1650
1658
  const prefix = (input.prefix ?? defaults.prefix ?? "NY").trim();
1651
1659
  const paymentMethod = (input.paymentMethod ?? defaults.paymentMethod ?? "").trim();
@@ -1726,7 +1734,7 @@ function createMockKassza(options = {}) {
1726
1734
  const invoicesApi = {
1727
1735
  async create(input) {
1728
1736
  const document = await run("invoices.create", [input], () => createInvoiceRecord(input));
1729
- await require_create_once.emitDocumentEvent(onDocument, {
1737
+ await emit({
1730
1738
  kind: "invoice",
1731
1739
  action: "created",
1732
1740
  number: document.number,
@@ -1738,7 +1746,7 @@ function createMockKassza(options = {}) {
1738
1746
  createOnce: (input, requestOptions) => run("invoices.createOnce", [input], () => require_issue.createInvoiceOnce(invoicesApi, input, {
1739
1747
  recoveryDelayMs: 0,
1740
1748
  ...requestOptions
1741
- })),
1749
+ }, guard)),
1742
1750
  preview: (input) => run("invoices.preview", [input], () => {
1743
1751
  const items = require_create_once.resolveInvoice(options.defaults?.invoice ?? {}, input, now()).items.map((item) => item.amounts);
1744
1752
  const totals = require_money.summarizeItems(items);
@@ -1791,7 +1799,7 @@ function createMockKassza(options = {}) {
1791
1799
  ...downloadPdf ? { pdf: MOCK_PDF } : {}
1792
1800
  };
1793
1801
  });
1794
- await require_create_once.emitDocumentEvent(onDocument, {
1802
+ await emit({
1795
1803
  kind: "invoice",
1796
1804
  action: "reversed",
1797
1805
  number: document.number,
@@ -1819,7 +1827,7 @@ function createMockKassza(options = {}) {
1819
1827
  outstanding: Math.max(0, found.details.totals.grossAmount - paid)
1820
1828
  };
1821
1829
  });
1822
- await require_create_once.emitDocumentEvent(onDocument, {
1830
+ await emit({
1823
1831
  kind: "invoice",
1824
1832
  action: "payment",
1825
1833
  number: document.invoiceNumber,
@@ -1827,6 +1835,10 @@ function createMockKassza(options = {}) {
1827
1835
  });
1828
1836
  return document;
1829
1837
  },
1838
+ registerPaymentOnce: (input, requestOptions) => run("invoices.registerPaymentOnce", [input], () => require_create_once.registerPaymentOnce(invoicesApi, input, {
1839
+ recoveryDelayMs: 0,
1840
+ ...requestOptions
1841
+ }, guard)),
1830
1842
  async clearPayments(input) {
1831
1843
  const document = await run("invoices.clearPayments", [input], () => {
1832
1844
  const found = findInvoice(typeof input === "string" ? input : input.invoiceNumber);
@@ -1838,7 +1850,7 @@ function createMockKassza(options = {}) {
1838
1850
  outstanding: found.details.totals.grossAmount
1839
1851
  };
1840
1852
  });
1841
- await require_create_once.emitDocumentEvent(onDocument, {
1853
+ await emit({
1842
1854
  kind: "invoice",
1843
1855
  action: "payment",
1844
1856
  number: document.invoiceNumber,
@@ -1867,7 +1879,7 @@ function createMockKassza(options = {}) {
1867
1879
  const receiptsApi = {
1868
1880
  async create(input) {
1869
1881
  const document = await run("receipts.create", [input], () => createReceiptRecord(input, input.callId));
1870
- await require_create_once.emitDocumentEvent(onDocument, {
1882
+ await emit({
1871
1883
  kind: "receipt",
1872
1884
  action: "created",
1873
1885
  number: document.number,
@@ -1878,7 +1890,7 @@ function createMockKassza(options = {}) {
1878
1890
  createOnce: (input, requestOptions) => run("receipts.createOnce", [input], () => require_create_once.createReceiptOnce(receiptsApi, input, {
1879
1891
  recoveryDelayMs: 0,
1880
1892
  ...requestOptions
1881
- })),
1893
+ }, guard)),
1882
1894
  async reverse(input) {
1883
1895
  const receiptNumber = typeof input === "string" ? input : input.receiptNumber;
1884
1896
  const callId = typeof input === "string" ? void 0 : input.callId;
@@ -1911,7 +1923,7 @@ function createMockKassza(options = {}) {
1911
1923
  pdf: MOCK_PDF
1912
1924
  };
1913
1925
  });
1914
- await require_create_once.emitDocumentEvent(onDocument, {
1926
+ await emit({
1915
1927
  kind: "receipt",
1916
1928
  action: "reversed",
1917
1929
  number: document.number,
@@ -1,6 +1,7 @@
1
- import { E as SzamlazzError, K as InvoiceType, N as CreateInvoiceInput, nt as AgentAction, u as DocumentHook } from "../context-DXNbTPwz.cjs";
2
- import { r as Receipt } from "../types-DH8QoNZK.cjs";
3
- import { c as TaxpayerInfo, n as Kassza, r as KasszaDefaults } from "../client-B5FryKxJ.cjs";
1
+ import { a as AgentAction, t as KasszaWarning } from "../warnings-B3DXnveC.cjs";
2
+ import { G as InvoiceType, M as CreateInvoiceInput, d as DocumentErrorMode, p as DocumentHook, st as SzamlazzError } from "../context-CFNKzStE.cjs";
3
+ import { r as Receipt } from "../types-lnKkQdot.cjs";
4
+ import { f as TaxpayerInfo, n as Kassza, r as KasszaDefaults } from "../client-SVZu25MB.cjs";
4
5
  import { n as InvoiceDetails, o as InvoiceDetailsPayment } from "../get-Byc9T5WO.cjs";
5
6
  //#region src/testing/fake-agent-state.d.ts
6
7
  type FakeInvoiceTypeCode = "SZ" | "D" | "ES" | "VS" | "HS" | "SS" | "SL";
@@ -218,6 +219,8 @@ export interface MockKasszaOptions {
218
219
  readonly now?: () => Date;
219
220
  readonly hooks?: {
220
221
  readonly onDocument?: DocumentHook | undefined;
222
+ readonly onDocumentError?: DocumentErrorMode | undefined;
223
+ readonly onWarning?: ((warning: KasszaWarning) => void) | undefined;
221
224
  } | undefined;
222
225
  }
223
226
  export interface MockFailureOptions {
@@ -1,6 +1,7 @@
1
- import { E as SzamlazzError, K as InvoiceType, N as CreateInvoiceInput, nt as AgentAction, u as DocumentHook } from "../context-BxQlIlug.js";
2
- import { r as Receipt } from "../types-k--zHf4l.js";
3
- import { c as TaxpayerInfo, n as Kassza, r as KasszaDefaults } from "../client-6MkeuFqD.js";
1
+ import { a as AgentAction, t as KasszaWarning } from "../warnings-B3DXnveC.js";
2
+ import { G as InvoiceType, M as CreateInvoiceInput, d as DocumentErrorMode, p as DocumentHook, st as SzamlazzError } from "../context-kb33TgzE.js";
3
+ import { r as Receipt } from "../types-D1zDOH_F.js";
4
+ import { f as TaxpayerInfo, n as Kassza, r as KasszaDefaults } from "../client-DeWWQ-RZ.js";
4
5
  import { n as InvoiceDetails, o as InvoiceDetailsPayment } from "../get-Byc9T5WO.js";
5
6
  //#region src/testing/fake-agent-state.d.ts
6
7
  type FakeInvoiceTypeCode = "SZ" | "D" | "ES" | "VS" | "HS" | "SS" | "SL";
@@ -218,6 +219,8 @@ export interface MockKasszaOptions {
218
219
  readonly now?: () => Date;
219
220
  readonly hooks?: {
220
221
  readonly onDocument?: DocumentHook | undefined;
222
+ readonly onDocumentError?: DocumentErrorMode | undefined;
223
+ readonly onWarning?: ((warning: KasszaWarning) => void) | undefined;
221
224
  } | undefined;
222
225
  }
223
226
  export interface MockFailureOptions {