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
@@ -1,9 +1,13 @@
1
- import { n as SzamlazzError } from "./errors-DLrb0g64.js";
1
+ import { r as SzamlazzError } from "./errors-DtN4g5Z9.js";
2
2
  import { i as encodeUtf8 } from "./binary-D0M9U2MD.js";
3
- import { n as toAgentDate, t as addBudapestDays } from "./dates-CXyj7Azy.js";
3
+ import { a as optionalEl, n as buildXmlDocument, r as el } from "./serialize-B2eFh3D-.js";
4
+ import { t as emitWarning } from "./warnings-DwTl5J-2.js";
5
+ import { a as unknownOutcomeError, i as resolveRecoveryDelay, n as isUncertainOutcome, r as recoverAfterFailure } from "./once-CqqZxsXG.js";
6
+ import { m as guardOnce } from "./issue-DMA1Nbr1.js";
7
+ import { a as todayInBudapest, n as toAgentDate, t as addBudapestDays } from "./dates-CXyj7Azy.js";
4
8
  import { i as isHuf } from "./vat-v_dcWCto.js";
5
- import { t as calculateInvoiceItem } from "./money-t7uy1n91.js";
6
- import { C as unknownOutcomeError, S as resolveRecoveryDelay, b as isUncertainOutcome, x as recoverAfterFailure } from "./issue-DtSLpVdJ.js";
9
+ import { n as calculateInvoiceItem } from "./money-Cw457SD6.js";
10
+ import { a as optionalText, c as requireText$1, n as agentDate$1, o as parseInvoiceResult, t as AGENT_XSD_BASE_URL, u as validationError } from "./reference-B5TATqb5.js";
7
11
  //#region src/core/actions.ts
8
12
  const SZAMLAZZ_AGENT_URL = "https://www.szamlazz.hu/szamla/";
9
13
  const AGENT_ACTIONS = {
@@ -23,12 +27,47 @@ const AGENT_ACTIONS = {
23
27
  const MAX_INVOICE_ATTACHMENTS = 5;
24
28
  //#endregion
25
29
  //#region src/core/document-events.ts
26
- async function emitDocumentEvent(hook, event) {
30
+ var DocumentHookError = class extends Error {
31
+ name = "DocumentHookError";
32
+ event;
33
+ constructor(event, cause) {
34
+ super(`Az onDocument hook hibát dobott a(z) ${event.number} bizonylatnál. A bizonylat elkészült, csak a hook (például a napló mentése) maradt el: mentsd el újra az error.event alapján, és ne állítsd ki újra a bizonylatot.`, { cause });
35
+ this.event = event;
36
+ }
37
+ get number() {
38
+ return this.event.number;
39
+ }
40
+ get document() {
41
+ return this.event.document;
42
+ }
43
+ };
44
+ function isDocumentHookError(error) {
45
+ return error instanceof DocumentHookError;
46
+ }
47
+ function warnDocumentHook(onWarning, event, error) {
48
+ emitWarning(onWarning, {
49
+ kind: "document",
50
+ message: `Az onDocument hook hibát dobott a(z) ${event.number} bizonylatnál. A bizonylat elkészült, a hiba nem érinti.`,
51
+ error,
52
+ operation: `${event.kind}.${event.action}`
53
+ }, "console");
54
+ }
55
+ async function emitDocumentEvent(hook, event, options = {}) {
27
56
  if (!hook) return;
28
57
  try {
29
58
  await hook(event);
30
59
  } catch (error) {
31
- console.warn(`[szamlazz] Az onDocument hook hibát dobott a(z) ${event.number} bizonylatnál. A bizonylat elkészült, a hiba nem érinti.`, error);
60
+ const mode = options.mode ?? "warn";
61
+ if (mode === "warn") {
62
+ warnDocumentHook(options.onWarning, event, error);
63
+ return;
64
+ }
65
+ if (mode === "throw") throw new DocumentHookError(event, error);
66
+ try {
67
+ await mode(error, event);
68
+ } catch (handlerError) {
69
+ throw new DocumentHookError(event, handlerError);
70
+ }
32
71
  }
33
72
  }
34
73
  //#endregion
@@ -284,6 +323,176 @@ function resolveInvoice(defaults, input, now) {
284
323
  attachments
285
324
  };
286
325
  }
326
+ function normalizeRegisterInput(input) {
327
+ const payments = "payments" in input ? input.payments : [{
328
+ amount: input.amount,
329
+ method: input.method ?? "átutalás",
330
+ date: input.date,
331
+ description: input.description
332
+ }];
333
+ if (!Array.isArray(payments) || payments.length === 0) throw validationError("Adj meg legalább egy befizetést (payments). A korábbi befizetések törléséhez a clearPayments függvényt használd.");
334
+ if (payments.length > 5) throw validationError(`Egy kérésben legfeljebb 5 befizetés rögzíthető, kapott: ${payments.length}.`);
335
+ return {
336
+ invoiceNumber: input.invoiceNumber,
337
+ taxNumber: input.taxNumber,
338
+ additive: input.additive ?? true,
339
+ payments
340
+ };
341
+ }
342
+ function normalizeClearInput(input) {
343
+ const target = typeof input === "string" ? { invoiceNumber: input } : input;
344
+ return {
345
+ invoiceNumber: target.invoiceNumber,
346
+ taxNumber: target.taxNumber,
347
+ additive: false,
348
+ payments: []
349
+ };
350
+ }
351
+ function paymentNode(payment, index) {
352
+ const position = index + 1;
353
+ if (typeof payment.amount !== "number" || !Number.isFinite(payment.amount)) throw validationError(`A(z) ${position}. befizetés összege (amount) nem véges szám.`);
354
+ return el("kifizetes", [
355
+ el("datum", payment.date === void 0 ? todayInBudapest() : agentDate$1(payment.date, "date")),
356
+ el("jogcim", requireText$1(payment.method, `Add meg a(z) ${position}. befizetés módját (method).`)),
357
+ el("osszeg", payment.amount),
358
+ optionalEl("leiras", optionalText(payment.description))
359
+ ]);
360
+ }
361
+ function buildPaymentXml(credentials, request) {
362
+ const invoiceNumber = requireText$1(request.invoiceNumber, "Add meg a számla számát (invoiceNumber), amelyhez a befizetés tartozik.");
363
+ return buildXmlDocument({
364
+ root: "xmlszamlakifiz",
365
+ namespace: "http://www.szamlazz.hu/xmlszamlakifiz",
366
+ schemaLocation: `${AGENT_XSD_BASE_URL}agentkifiz/xmlszamlakifiz.xsd`,
367
+ children: [el("beallitasok", [
368
+ ...credentials,
369
+ el("szamlaszam", invoiceNumber),
370
+ optionalEl("adoszam", optionalText(request.taxNumber)),
371
+ el("additiv", request.additive),
372
+ el("valaszVerzio", 2)
373
+ ]), ...request.payments.map(paymentNode)]
374
+ });
375
+ }
376
+ function parseRegisterPaymentResponse(response, invoiceNumber) {
377
+ const result = parseInvoiceResult(response);
378
+ return {
379
+ invoiceNumber: result.number ?? invoiceNumber.trim(),
380
+ netTotal: result.netTotal,
381
+ grossTotal: result.grossTotal,
382
+ outstanding: result.outstanding,
383
+ buyerAccountUrl: result.buyerAccountUrl
384
+ };
385
+ }
386
+ function sendPaymentRequest(ctx, request, options) {
387
+ const xml = buildPaymentXml(ctx.credentials, request);
388
+ return ctx.execute({
389
+ action: "registerPayment",
390
+ xml,
391
+ signal: options.signal,
392
+ safeToRetry: !request.additive
393
+ }, (response) => parseRegisterPaymentResponse(response, request.invoiceNumber));
394
+ }
395
+ async function registerPayment(ctx, input, options = {}) {
396
+ return sendPaymentRequest(ctx, normalizeRegisterInput(input), options);
397
+ }
398
+ async function clearPayments(ctx, input, options = {}) {
399
+ return sendPaymentRequest(ctx, normalizeClearInput(input), options);
400
+ }
401
+ //#endregion
402
+ //#region src/invoices/payment-once.ts
403
+ const KEY_PATTERN = /^[A-Za-z0-9_.:-]{1,48}$/;
404
+ function validation(message, hint) {
405
+ return new SzamlazzError(message, {
406
+ category: "validation",
407
+ hint
408
+ });
409
+ }
410
+ function paymentMarker(key) {
411
+ const trimmed = key?.trim();
412
+ if (!trimmed || !KEY_PATTERN.test(trimmed)) throw validation(`A registerPaymentOnce kulcsa (key) 1–48 karakter legyen, csak betű, szám és _ . : - jellel, kapott: ${String(key)}`, "Használj rövid, stabil azonosítót, például a banki tranzakció vagy a fizetés azonosítóját.");
413
+ return `[kassza:${trimmed}]`;
414
+ }
415
+ function matchingPayment(details, marker) {
416
+ return details.payments.find((payment) => payment.comment?.includes(marker) === true);
417
+ }
418
+ function describe(description, marker) {
419
+ const text = description?.trim();
420
+ return text ? `${marker} ${text}` : marker;
421
+ }
422
+ function unreadableMarker(invoiceNumber, marker) {
423
+ return new SzamlazzError(`A(z) ${invoiceNumber} számlán a befizetés rögzült, de a jelölő (${marker}) a számla lekérdezésében nem látszik, így a registerPaymentOnce nem tudja megakadályozni az ismételt rögzítést.`, {
424
+ category: "unexpected_response",
425
+ details: {
426
+ invoiceNumber,
427
+ marker,
428
+ registered: "true"
429
+ },
430
+ hint: "NE hívd újra ezt a rögzítést: a befizetés már rögzült. Jelezd a kassza hibajegyében; addig a befizetéseket a saját rendszeredben tartsd nyilván, és a registerPayment-et csak egyszer hívd."
431
+ });
432
+ }
433
+ const QUERY = { includePdf: false };
434
+ async function registerPaymentOnce(api, input, options = {}, guard) {
435
+ const invoiceNumber = input.invoiceNumber?.trim();
436
+ if (!invoiceNumber) throw validation("Add meg a számla számát (invoiceNumber).");
437
+ if (typeof input.amount !== "number" || !Number.isFinite(input.amount) || input.amount === 0) throw validation("A befizetés összege (amount) nullától különböző véges szám legyen.");
438
+ const marker = paymentMarker(input.key);
439
+ const key = input.key.trim();
440
+ const delayMs = resolveRecoveryDelay(options.recoveryDelayMs);
441
+ const lookup = async () => {
442
+ return matchingPayment(await api.get(invoiceNumber, QUERY, options), marker) ?? null;
443
+ };
444
+ const base = {
445
+ invoiceNumber,
446
+ key,
447
+ marker
448
+ };
449
+ const run = async () => {
450
+ const existing = await lookup();
451
+ if (existing) return {
452
+ ...base,
453
+ created: false,
454
+ existing
455
+ };
456
+ let payment;
457
+ try {
458
+ payment = await api.registerPayment({
459
+ invoiceNumber,
460
+ taxNumber: input.taxNumber,
461
+ additive: true,
462
+ amount: input.amount,
463
+ method: input.method ?? "átutalás",
464
+ date: input.date,
465
+ description: describe(input.description, marker)
466
+ }, options);
467
+ } catch (error) {
468
+ if (!isUncertainOutcome(error)) throw error;
469
+ const state = {};
470
+ const recovered = await recoverAfterFailure(lookup, delayMs, options.signal, state);
471
+ if (recovered) return {
472
+ ...base,
473
+ created: true,
474
+ existing: recovered
475
+ };
476
+ throw unknownOutcomeError(error, `${invoiceNumber} számla`, {
477
+ subject: `${key} kulcsú befizetése`,
478
+ lookupError: state.lookupError,
479
+ method: "registerPaymentOnce"
480
+ });
481
+ }
482
+ const confirmed = await lookup();
483
+ if (!confirmed) throw unreadableMarker(invoiceNumber, marker);
484
+ return {
485
+ ...base,
486
+ created: true,
487
+ payment,
488
+ existing: confirmed
489
+ };
490
+ };
491
+ return guardOnce(guard, `payment:${JSON.stringify([invoiceNumber, key])}`, options, run, (result) => ({
492
+ ...result,
493
+ created: false
494
+ }));
495
+ }
287
496
  //#endregion
288
497
  //#region src/receipts/create-once.ts
289
498
  function requireOrderNumber(input) {
@@ -291,7 +500,7 @@ function requireOrderNumber(input) {
291
500
  if (!orderNumber) throw new SzamlazzError("A createOnce-hoz add meg a rendelésszámot (orderNumber), ez azonosítja a nyugtát.", { category: "validation" });
292
501
  return orderNumber;
293
502
  }
294
- async function createReceiptOnce(api, input, options = {}) {
503
+ async function createReceiptOnce(api, input, options = {}, guard) {
295
504
  const orderNumber = requireOrderNumber(input);
296
505
  const callId = input.callId?.trim() || orderNumber;
297
506
  const delayMs = resolveRecoveryDelay(options.recoveryDelayMs);
@@ -299,32 +508,39 @@ async function createReceiptOnce(api, input, options = {}) {
299
508
  orderNumber,
300
509
  downloadPdf: input.downloadPdf
301
510
  }, options);
302
- if (options.lookupFirst !== false) {
303
- const existing = await lookup();
304
- if (existing) return {
305
- receipt: existing,
306
- created: false
307
- };
308
- }
309
- try {
310
- return {
311
- receipt: await api.create({
312
- ...input,
313
- orderNumber,
314
- callId
315
- }, options),
316
- created: true
317
- };
318
- } catch (error) {
319
- if (!isUncertainOutcome(error)) throw error;
320
- const recovered = await recoverAfterFailure(lookup, delayMs, options.signal);
321
- if (recovered) return {
322
- receipt: recovered,
323
- created: error.category !== "duplicate"
324
- };
325
- if (error.category === "duplicate") throw error;
326
- throw unknownOutcomeError(error, `${orderNumber} rendelés`);
327
- }
511
+ const run = async (recheck) => {
512
+ if (recheck || options.lookupFirst !== false) {
513
+ const existing = await lookup();
514
+ if (existing) return {
515
+ receipt: existing,
516
+ created: false
517
+ };
518
+ }
519
+ try {
520
+ return {
521
+ receipt: await api.create({
522
+ ...input,
523
+ orderNumber,
524
+ callId
525
+ }, options),
526
+ created: true
527
+ };
528
+ } catch (error) {
529
+ if (!isUncertainOutcome(error)) throw error;
530
+ const state = {};
531
+ const recovered = await recoverAfterFailure(lookup, delayMs, options.signal, state);
532
+ if (recovered) return {
533
+ receipt: recovered,
534
+ created: error.category !== "duplicate"
535
+ };
536
+ if (error.category === "duplicate" && !state.lookupError) throw error;
537
+ throw unknownOutcomeError(error, `${orderNumber} rendelés`, { lookupError: state.lookupError });
538
+ }
539
+ };
540
+ return guardOnce(guard, `receipt:order:${orderNumber}`, options, run, (result) => ({
541
+ ...result,
542
+ created: false
543
+ }));
328
544
  }
329
545
  //#endregion
330
- export { INVOICE_LANGUAGES as a, emitDocumentEvent as c, SZAMLAZZ_AGENT_URL as d, resolveInvoice as i, AGENT_ACTIONS as l, optionalAgentDate as n, INVOICE_TEMPLATES as o, presentText as r, TAXPAYER_TYPE_CODES as s, createReceiptOnce as t, MAX_INVOICE_ATTACHMENTS as u };
546
+ export { SZAMLAZZ_AGENT_URL as _, registerPayment as a, resolveInvoice as c, TAXPAYER_TYPE_CODES as d, DocumentHookError as f, MAX_INVOICE_ATTACHMENTS as g, AGENT_ACTIONS as h, clearPayments as i, INVOICE_LANGUAGES as l, isDocumentHookError as m, paymentMarker as n, optionalAgentDate as o, emitDocumentEvent as p, registerPaymentOnce as r, presentText as s, createReceiptOnce as t, INVOICE_TEMPLATES as u };
@@ -0,0 +1,20 @@
1
+ import { G as InvoiceType, N as CreatedInvoice } from "./context-kb33TgzE.js";
2
+ import { r as Receipt } from "./types-D1zDOH_F.js";
3
+ import { n as InvoiceDetails } from "./get-Byc9T5WO.js";
4
+ //#region src/invoices/create-once.d.ts
5
+ interface InvoiceOnceResult {
6
+ readonly number: string;
7
+ readonly created: boolean;
8
+ readonly externalId: string;
9
+ readonly invoice?: CreatedInvoice | undefined;
10
+ readonly details?: InvoiceDetails | undefined;
11
+ }
12
+ declare function invoiceOnceExternalId(type: InvoiceType, orderNumber: string): string;
13
+ //#endregion
14
+ //#region src/receipts/create-once.d.ts
15
+ interface ReceiptOnceResult {
16
+ readonly receipt: Receipt;
17
+ readonly created: boolean;
18
+ }
19
+ //#endregion
20
+ export { InvoiceOnceResult as n, invoiceOnceExternalId as r, ReceiptOnceResult as t };
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors = require("../errors-DxeuTslP.cjs");
2
+ const require_errors = require("../errors-EE96_6D_.cjs");
3
3
  const require_binary = require("../binary-B89HM03_.cjs");
4
- const require_serialize = require("../serialize-BXOww1Uq.cjs");
5
- const require_parse = require("../parse-BJj-aqKy.cjs");
6
- const require_get = require("../get-Csm2n0rZ.cjs");
4
+ const require_serialize = require("../serialize-CquIsxA-.cjs");
5
+ const require_parse = require("../parse-DOA2XQ3e.cjs");
6
+ const require_get = require("../get-BdMTseh4.cjs");
7
7
  const require_crypto = require("../crypto-Dpn4FHQ6.cjs");
8
8
  const require_request_body = require("../request-body-CH6ZGOrq.cjs");
9
9
  //#region src/data-link/push.ts
@@ -1,54 +1,4 @@
1
- import { r as Receipt } from "../types-DH8QoNZK.cjs";
2
- import { n as InvoiceDetails } from "../get-Byc9T5WO.cjs";
3
- //#region src/data-link/push.d.ts
4
- type DataLinkPushKind = "invoice" | "incoming-invoice" | "bank-transaction" | "receipts";
5
- type DataLinkErrorReason = "invalid_payload" | "payload_too_large" | "unknown_document" | "missing_key";
6
- export declare class DataLinkError extends Error {
7
- override readonly name: string;
8
- readonly reason: DataLinkErrorReason;
9
- constructor(reason: DataLinkErrorReason, message: string, cause?: unknown);
10
- }
11
- interface DataLinkPushBase {
12
- readonly key: string | undefined;
13
- readonly raw: string;
14
- }
15
- interface DataLinkInvoicePush extends DataLinkPushBase {
16
- readonly kind: "invoice" | "incoming-invoice";
17
- readonly id: number;
18
- readonly invoice: InvoiceDetails;
19
- readonly deleted: boolean;
20
- }
21
- interface DataLinkBankTransactionPartner {
22
- readonly name?: string | undefined;
23
- readonly accountNumber?: string | undefined;
24
- }
25
- interface DataLinkBankTransaction {
26
- readonly id: number;
27
- readonly accountNumber: string;
28
- readonly valueDate: string;
29
- readonly direction: "in" | "out";
30
- readonly type?: string | undefined;
31
- readonly technical: boolean;
32
- readonly amount: number;
33
- readonly currency: string;
34
- readonly partner?: DataLinkBankTransactionPartner | undefined;
35
- readonly reference?: string | undefined;
36
- }
37
- interface DataLinkBankTransactionPush extends DataLinkPushBase {
38
- readonly kind: "bank-transaction";
39
- readonly transaction: DataLinkBankTransaction;
40
- }
41
- interface DataLinkArchivedReceipt {
42
- readonly receipt: Receipt;
43
- readonly issuerTaxNumber?: string | undefined;
44
- }
45
- interface DataLinkReceiptsPush extends DataLinkPushBase {
46
- readonly kind: "receipts";
47
- readonly receipts: readonly DataLinkArchivedReceipt[];
48
- }
49
- type DataLinkPush = DataLinkInvoicePush | DataLinkBankTransactionPush | DataLinkReceiptsPush;
50
- export declare function parseDataLinkPush(xml: string, key?: string | undefined): DataLinkPush;
51
- //#endregion
1
+ import { a as DataLinkError, c as DataLinkPush, d as parseDataLinkPush, i as DataLinkBankTransactionPush, l as DataLinkPushKind, n as DataLinkBankTransaction, o as DataLinkErrorReason, r as DataLinkBankTransactionPartner, s as DataLinkInvoicePush, t as DataLinkArchivedReceipt, u as DataLinkReceiptsPush } from "../push-D4nNbCNV.cjs";
52
2
  //#region src/data-link/response.d.ts
53
3
  type DataLinkKeyError = "KEY_ERR" | "KEY_DEL";
54
4
  interface DataLinkAcknowledgement {
@@ -76,4 +26,4 @@ interface DataLinkHandlerOptions {
76
26
  type DataLinkHandler = (request: Request) => Promise<Response>;
77
27
  export declare function dataLinkHandler(options: DataLinkHandlerOptions): DataLinkHandler;
78
28
  //#endregion
79
- export type { DataLinkAcknowledgement, DataLinkArchivedReceipt, DataLinkBankTransaction, DataLinkBankTransactionPartner, DataLinkBankTransactionPush, DataLinkErrorReason, DataLinkHandler, DataLinkHandlerOptions, DataLinkInvoicePush, DataLinkKeyCheck, DataLinkKeyError, DataLinkPush, DataLinkPushKind, DataLinkReceiptsPush };
29
+ export { type DataLinkAcknowledgement, type DataLinkArchivedReceipt, type DataLinkBankTransaction, type DataLinkBankTransactionPartner, type DataLinkBankTransactionPush, DataLinkError, type DataLinkErrorReason, type DataLinkHandler, type DataLinkHandlerOptions, type DataLinkInvoicePush, type DataLinkKeyCheck, type DataLinkKeyError, type DataLinkPush, type DataLinkPushKind, type DataLinkReceiptsPush, parseDataLinkPush };
@@ -1,54 +1,4 @@
1
- import { r as Receipt } from "../types-k--zHf4l.js";
2
- import { n as InvoiceDetails } from "../get-Byc9T5WO.js";
3
- //#region src/data-link/push.d.ts
4
- type DataLinkPushKind = "invoice" | "incoming-invoice" | "bank-transaction" | "receipts";
5
- type DataLinkErrorReason = "invalid_payload" | "payload_too_large" | "unknown_document" | "missing_key";
6
- export declare class DataLinkError extends Error {
7
- override readonly name: string;
8
- readonly reason: DataLinkErrorReason;
9
- constructor(reason: DataLinkErrorReason, message: string, cause?: unknown);
10
- }
11
- interface DataLinkPushBase {
12
- readonly key: string | undefined;
13
- readonly raw: string;
14
- }
15
- interface DataLinkInvoicePush extends DataLinkPushBase {
16
- readonly kind: "invoice" | "incoming-invoice";
17
- readonly id: number;
18
- readonly invoice: InvoiceDetails;
19
- readonly deleted: boolean;
20
- }
21
- interface DataLinkBankTransactionPartner {
22
- readonly name?: string | undefined;
23
- readonly accountNumber?: string | undefined;
24
- }
25
- interface DataLinkBankTransaction {
26
- readonly id: number;
27
- readonly accountNumber: string;
28
- readonly valueDate: string;
29
- readonly direction: "in" | "out";
30
- readonly type?: string | undefined;
31
- readonly technical: boolean;
32
- readonly amount: number;
33
- readonly currency: string;
34
- readonly partner?: DataLinkBankTransactionPartner | undefined;
35
- readonly reference?: string | undefined;
36
- }
37
- interface DataLinkBankTransactionPush extends DataLinkPushBase {
38
- readonly kind: "bank-transaction";
39
- readonly transaction: DataLinkBankTransaction;
40
- }
41
- interface DataLinkArchivedReceipt {
42
- readonly receipt: Receipt;
43
- readonly issuerTaxNumber?: string | undefined;
44
- }
45
- interface DataLinkReceiptsPush extends DataLinkPushBase {
46
- readonly kind: "receipts";
47
- readonly receipts: readonly DataLinkArchivedReceipt[];
48
- }
49
- type DataLinkPush = DataLinkInvoicePush | DataLinkBankTransactionPush | DataLinkReceiptsPush;
50
- export declare function parseDataLinkPush(xml: string, key?: string | undefined): DataLinkPush;
51
- //#endregion
1
+ import { a as DataLinkError, c as DataLinkPush, d as parseDataLinkPush, i as DataLinkBankTransactionPush, l as DataLinkPushKind, n as DataLinkBankTransaction, o as DataLinkErrorReason, r as DataLinkBankTransactionPartner, s as DataLinkInvoicePush, t as DataLinkArchivedReceipt, u as DataLinkReceiptsPush } from "../push-BXj0Sf0Z.js";
52
2
  //#region src/data-link/response.d.ts
53
3
  type DataLinkKeyError = "KEY_ERR" | "KEY_DEL";
54
4
  interface DataLinkAcknowledgement {
@@ -76,4 +26,4 @@ interface DataLinkHandlerOptions {
76
26
  type DataLinkHandler = (request: Request) => Promise<Response>;
77
27
  export declare function dataLinkHandler(options: DataLinkHandlerOptions): DataLinkHandler;
78
28
  //#endregion
79
- export type { DataLinkAcknowledgement, DataLinkArchivedReceipt, DataLinkBankTransaction, DataLinkBankTransactionPartner, DataLinkBankTransactionPush, DataLinkErrorReason, DataLinkHandler, DataLinkHandlerOptions, DataLinkInvoicePush, DataLinkKeyCheck, DataLinkKeyError, DataLinkPush, DataLinkPushKind, DataLinkReceiptsPush };
29
+ export { type DataLinkAcknowledgement, type DataLinkArchivedReceipt, type DataLinkBankTransaction, type DataLinkBankTransactionPartner, type DataLinkBankTransactionPush, DataLinkError, type DataLinkErrorReason, type DataLinkHandler, type DataLinkHandlerOptions, type DataLinkInvoicePush, type DataLinkKeyCheck, type DataLinkKeyError, type DataLinkPush, type DataLinkPushKind, type DataLinkReceiptsPush, parseDataLinkPush };
@@ -1,8 +1,8 @@
1
- import { n as SzamlazzError } from "../errors-DLrb0g64.js";
1
+ import { r as SzamlazzError } from "../errors-DtN4g5Z9.js";
2
2
  import { i as encodeUtf8 } from "../binary-D0M9U2MD.js";
3
- import { a as optionalEl, c as childNumber, d as findChildren, f as parseXml, l as childText, n as buildXmlDocument, o as XmlParseError, r as el, s as childBoolean, u as findChild } from "../serialize-DSE_o9RK.js";
4
- import { r as createAgentResponse, t as parseReceiptElement } from "../parse-C608ehqM.js";
5
- import { n as parseInvoiceDetailsXml } from "../get-DT3JEgQ6.js";
3
+ import { a as optionalEl, c as childNumber, d as findChildren, f as parseXml, l as childText, n as buildXmlDocument, o as XmlParseError, r as el, s as childBoolean, u as findChild } from "../serialize-B2eFh3D-.js";
4
+ import { r as createAgentResponse, t as parseReceiptElement } from "../parse-Cr7yQ3_z.js";
5
+ import { n as parseInvoiceDetailsXml } from "../get-CZEShCcj.js";
6
6
  import { a as timingSafeEqual } from "../crypto-usDg8L2K.js";
7
7
  import { t as readRequestText } from "../request-body-uZHMRlQr.js";
8
8
  //#region src/data-link/push.ts
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors = require("../errors-DxeuTslP.cjs");
3
- const require_client = require("../client-C-PdfL_P.cjs");
4
- const require_serialize = require("../serialize-BXOww1Uq.cjs");
5
- const require_parse = require("../parse-BJj-aqKy.cjs");
2
+ const require_errors = require("../errors-EE96_6D_.cjs");
3
+ const require_client = require("../client-CLFvJCVW.cjs");
4
+ const require_serialize = require("../serialize-CquIsxA-.cjs");
5
+ const require_parse = require("../parse-DOA2XQ3e.cjs");
6
6
  const require_dates = require("../dates-CPgBodkP.cjs");
7
7
  const require_tax_number = require("../tax-number-BYFkBp4A.cjs");
8
8
  //#region src/delegation/connect.ts
@@ -1,6 +1,6 @@
1
- import { C as AgentResponse, E as SzamlazzError, S as XmlNode, c as SzamlazzOptions, k as suggestedPrefix, n as AgentContext, o as RequestOptions } from "../context-DXNbTPwz.cjs";
2
1
  import { t as DateInput } from "../dates-9zvESP0i.cjs";
3
- import { i as KasszaOptions, n as Kassza, r as KasszaDefaults } from "../client-B5FryKxJ.cjs";
2
+ import { D as XmlNode, O as AgentResponse, dt as suggestedPrefix, l as SzamlazzOptions, r as AgentContext, s as RequestOptions, st as SzamlazzError } from "../context-CFNKzStE.cjs";
3
+ import { i as KasszaOptions, n as Kassza, r as KasszaDefaults } from "../client-SVZu25MB.cjs";
4
4
  //#region src/delegation/connect.d.ts
5
5
  export declare const CONNECT_PRINCIPAL_NAMESPACE = "http://www.szamlazz.hu/xmlcegmb";
6
6
  export declare const CONNECT_PRINCIPAL_SCHEMA_LOCATION = "http://www.szamlazz.hu/docs/xsds/agentmb/xmlcegmb.xsd";
@@ -1,6 +1,6 @@
1
- import { C as AgentResponse, E as SzamlazzError, S as XmlNode, c as SzamlazzOptions, k as suggestedPrefix, n as AgentContext, o as RequestOptions } from "../context-BxQlIlug.js";
2
1
  import { t as DateInput } from "../dates-9zvESP0i.js";
3
- import { i as KasszaOptions, n as Kassza, r as KasszaDefaults } from "../client-6MkeuFqD.js";
2
+ import { D as XmlNode, O as AgentResponse, dt as suggestedPrefix, l as SzamlazzOptions, r as AgentContext, s as RequestOptions, st as SzamlazzError } from "../context-kb33TgzE.js";
3
+ import { i as KasszaOptions, n as Kassza, r as KasszaDefaults } from "../client-DeWWQ-RZ.js";
4
4
  //#region src/delegation/connect.d.ts
5
5
  export declare const CONNECT_PRINCIPAL_NAMESPACE = "http://www.szamlazz.hu/xmlcegmb";
6
6
  export declare const CONNECT_PRINCIPAL_SCHEMA_LOCATION = "http://www.szamlazz.hu/docs/xsds/agentmb/xmlcegmb.xsd";
@@ -1,7 +1,7 @@
1
- import { i as isSzamlazzError, n as SzamlazzError, o as suggestedPrefix } from "../errors-DLrb0g64.js";
2
- import { a as createAgentContext, n as queryTaxpayer, r as getInvoicePdf, t as createKassza } from "../client-CfaS1-Jx.js";
3
- import { a as optionalEl, n as buildXmlDocument, r as el } from "../serialize-DSE_o9RK.js";
4
- import { h as unexpectedResponse, i as decodeHeaderValue, l as readHeader, u as throwIfAnyError } from "../parse-C608ehqM.js";
1
+ import { c as suggestedPrefix, o as isSzamlazzError, r as SzamlazzError } from "../errors-DtN4g5Z9.js";
2
+ import { a as queryTaxpayer, c as createAgentContext, o as getInvoicePdf, t as createKassza } from "../client-Cvf-hTz_.js";
3
+ import { a as optionalEl, n as buildXmlDocument, r as el } from "../serialize-B2eFh3D-.js";
4
+ import { h as unexpectedResponse, i as decodeHeaderValue, l as readHeader, u as throwIfAnyError } from "../parse-Cr7yQ3_z.js";
5
5
  import { n as toAgentDate } from "../dates-CXyj7Azy.js";
6
6
  import { o as parseHungarianTaxNumber, s as isValidEmail } from "../tax-number-BdqKsxNR.js";
7
7
  //#region src/delegation/connect.ts
@@ -327,6 +327,11 @@ const AGENT_ERROR_CODES = {
327
327
  hint: SIMPLE_ITEMS_HINT
328
328
  }
329
329
  };
330
+ const KASSZA_ERROR_DOCS_URL = "https://kasszajs.hu/docs/hibakodok";
331
+ function errorCodeDocsUrl(code) {
332
+ if (code === void 0 || AGENT_ERROR_CODES[code] === void 0) return void 0;
333
+ return `${KASSZA_ERROR_DOCS_URL}/${code}`;
334
+ }
330
335
  const RETRYABLE_CATEGORIES = /* @__PURE__ */ new Set([
331
336
  "maintenance",
332
337
  "network",
@@ -353,6 +358,9 @@ var SzamlazzError = class extends Error {
353
358
  this.rawResponse = options.rawResponse;
354
359
  this.details = options.details;
355
360
  }
361
+ get docsUrl() {
362
+ return errorCodeDocsUrl(this.code);
363
+ }
356
364
  get isDuplicate() {
357
365
  return this.category === "duplicate";
358
366
  }
@@ -387,4 +395,4 @@ function parseErrorCode(value) {
387
395
  return Number(trimmed);
388
396
  }
389
397
  //#endregion
390
- export { parseErrorCode as a, isSzamlazzError as i, SzamlazzError as n, suggestedPrefix as o, createAgentError as r, AGENT_ERROR_CODES as t };
398
+ export { errorCodeDocsUrl as a, suggestedPrefix as c, createAgentError as i, KASSZA_ERROR_DOCS_URL as n, isSzamlazzError as o, SzamlazzError as r, parseErrorCode as s, AGENT_ERROR_CODES as t };
@@ -327,6 +327,11 @@ const AGENT_ERROR_CODES = {
327
327
  hint: SIMPLE_ITEMS_HINT
328
328
  }
329
329
  };
330
+ const KASSZA_ERROR_DOCS_URL = "https://kasszajs.hu/docs/hibakodok";
331
+ function errorCodeDocsUrl(code) {
332
+ if (code === void 0 || AGENT_ERROR_CODES[code] === void 0) return void 0;
333
+ return `${KASSZA_ERROR_DOCS_URL}/${code}`;
334
+ }
330
335
  const RETRYABLE_CATEGORIES = /* @__PURE__ */ new Set([
331
336
  "maintenance",
332
337
  "network",
@@ -353,6 +358,9 @@ var SzamlazzError = class extends Error {
353
358
  this.rawResponse = options.rawResponse;
354
359
  this.details = options.details;
355
360
  }
361
+ get docsUrl() {
362
+ return errorCodeDocsUrl(this.code);
363
+ }
356
364
  get isDuplicate() {
357
365
  return this.category === "duplicate";
358
366
  }
@@ -393,6 +401,12 @@ Object.defineProperty(exports, "AGENT_ERROR_CODES", {
393
401
  return AGENT_ERROR_CODES;
394
402
  }
395
403
  });
404
+ Object.defineProperty(exports, "KASSZA_ERROR_DOCS_URL", {
405
+ enumerable: true,
406
+ get: function() {
407
+ return KASSZA_ERROR_DOCS_URL;
408
+ }
409
+ });
396
410
  Object.defineProperty(exports, "SzamlazzError", {
397
411
  enumerable: true,
398
412
  get: function() {
@@ -405,6 +419,12 @@ Object.defineProperty(exports, "createAgentError", {
405
419
  return createAgentError;
406
420
  }
407
421
  });
422
+ Object.defineProperty(exports, "errorCodeDocsUrl", {
423
+ enumerable: true,
424
+ get: function() {
425
+ return errorCodeDocsUrl;
426
+ }
427
+ });
408
428
  Object.defineProperty(exports, "isSzamlazzError", {
409
429
  enumerable: true,
410
430
  get: function() {