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
- const require_errors = require("./errors-DxeuTslP.cjs");
1
+ const require_errors = require("./errors-EE96_6D_.cjs");
2
2
  const require_binary = require("./binary-B89HM03_.cjs");
3
+ const require_serialize = require("./serialize-CquIsxA-.cjs");
4
+ const require_warnings = require("./warnings-DeIw5RFj.cjs");
5
+ const require_once = require("./once-BN_3B5OF.cjs");
6
+ const require_issue = require("./issue-Bin4tKD_.cjs");
3
7
  const require_dates = require("./dates-CPgBodkP.cjs");
4
8
  const require_vat = require("./vat-g35srbNG.cjs");
5
- const require_money = require("./money-BxytJW6f.cjs");
6
- const require_issue = require("./issue-AGRohSm7.cjs");
9
+ const require_money = require("./money-K9j0wPit.cjs");
10
+ const require_reference = require("./reference-BIdYMK0t.cjs");
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
+ require_warnings.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 require_reference.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 require_reference.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 require_reference.validationError(`A(z) ${position}. befizetés összege (amount) nem véges szám.`);
354
+ return require_serialize.el("kifizetes", [
355
+ require_serialize.el("datum", payment.date === void 0 ? require_dates.todayInBudapest() : require_reference.agentDate(payment.date, "date")),
356
+ require_serialize.el("jogcim", require_reference.requireText(payment.method, `Add meg a(z) ${position}. befizetés módját (method).`)),
357
+ require_serialize.el("osszeg", payment.amount),
358
+ require_serialize.optionalEl("leiras", require_reference.optionalText(payment.description))
359
+ ]);
360
+ }
361
+ function buildPaymentXml(credentials, request) {
362
+ const invoiceNumber = require_reference.requireText(request.invoiceNumber, "Add meg a számla számát (invoiceNumber), amelyhez a befizetés tartozik.");
363
+ return require_serialize.buildXmlDocument({
364
+ root: "xmlszamlakifiz",
365
+ namespace: "http://www.szamlazz.hu/xmlszamlakifiz",
366
+ schemaLocation: `${require_reference.AGENT_XSD_BASE_URL}agentkifiz/xmlszamlakifiz.xsd`,
367
+ children: [require_serialize.el("beallitasok", [
368
+ ...credentials,
369
+ require_serialize.el("szamlaszam", invoiceNumber),
370
+ require_serialize.optionalEl("adoszam", require_reference.optionalText(request.taxNumber)),
371
+ require_serialize.el("additiv", request.additive),
372
+ require_serialize.el("valaszVerzio", 2)
373
+ ]), ...request.payments.map(paymentNode)]
374
+ });
375
+ }
376
+ function parseRegisterPaymentResponse(response, invoiceNumber) {
377
+ const result = require_reference.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 require_errors.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 require_errors.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 = require_once.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 (!require_once.isUncertainOutcome(error)) throw error;
469
+ const state = {};
470
+ const recovered = await require_once.recoverAfterFailure(lookup, delayMs, options.signal, state);
471
+ if (recovered) return {
472
+ ...base,
473
+ created: true,
474
+ existing: recovered
475
+ };
476
+ throw require_once.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 require_issue.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,40 +500,47 @@ function requireOrderNumber(input) {
291
500
  if (!orderNumber) throw new require_errors.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
- const delayMs = require_issue.resolveRecoveryDelay(options.recoveryDelayMs);
506
+ const delayMs = require_once.resolveRecoveryDelay(options.recoveryDelayMs);
298
507
  const lookup = () => api.find({
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 (!require_issue.isUncertainOutcome(error)) throw error;
320
- const recovered = await require_issue.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 require_issue.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 (!require_once.isUncertainOutcome(error)) throw error;
530
+ const state = {};
531
+ const recovered = await require_once.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 require_once.unknownOutcomeError(error, `${orderNumber} rendelés`, { lookupError: state.lookupError });
538
+ }
539
+ };
540
+ return require_issue.guardOnce(guard, `receipt:order:${orderNumber}`, options, run, (result) => ({
541
+ ...result,
542
+ created: false
543
+ }));
328
544
  }
329
545
  //#endregion
330
546
  Object.defineProperty(exports, "AGENT_ACTIONS", {
@@ -333,6 +549,12 @@ Object.defineProperty(exports, "AGENT_ACTIONS", {
333
549
  return AGENT_ACTIONS;
334
550
  }
335
551
  });
552
+ Object.defineProperty(exports, "DocumentHookError", {
553
+ enumerable: true,
554
+ get: function() {
555
+ return DocumentHookError;
556
+ }
557
+ });
336
558
  Object.defineProperty(exports, "INVOICE_LANGUAGES", {
337
559
  enumerable: true,
338
560
  get: function() {
@@ -363,6 +585,12 @@ Object.defineProperty(exports, "TAXPAYER_TYPE_CODES", {
363
585
  return TAXPAYER_TYPE_CODES;
364
586
  }
365
587
  });
588
+ Object.defineProperty(exports, "clearPayments", {
589
+ enumerable: true,
590
+ get: function() {
591
+ return clearPayments;
592
+ }
593
+ });
366
594
  Object.defineProperty(exports, "createReceiptOnce", {
367
595
  enumerable: true,
368
596
  get: function() {
@@ -375,18 +603,42 @@ Object.defineProperty(exports, "emitDocumentEvent", {
375
603
  return emitDocumentEvent;
376
604
  }
377
605
  });
606
+ Object.defineProperty(exports, "isDocumentHookError", {
607
+ enumerable: true,
608
+ get: function() {
609
+ return isDocumentHookError;
610
+ }
611
+ });
378
612
  Object.defineProperty(exports, "optionalAgentDate", {
379
613
  enumerable: true,
380
614
  get: function() {
381
615
  return optionalAgentDate;
382
616
  }
383
617
  });
618
+ Object.defineProperty(exports, "paymentMarker", {
619
+ enumerable: true,
620
+ get: function() {
621
+ return paymentMarker;
622
+ }
623
+ });
384
624
  Object.defineProperty(exports, "presentText", {
385
625
  enumerable: true,
386
626
  get: function() {
387
627
  return presentText;
388
628
  }
389
629
  });
630
+ Object.defineProperty(exports, "registerPayment", {
631
+ enumerable: true,
632
+ get: function() {
633
+ return registerPayment;
634
+ }
635
+ });
636
+ Object.defineProperty(exports, "registerPaymentOnce", {
637
+ enumerable: true,
638
+ get: function() {
639
+ return registerPaymentOnce;
640
+ }
641
+ });
390
642
  Object.defineProperty(exports, "resolveInvoice", {
391
643
  enumerable: true,
392
644
  get: function() {
@@ -0,0 +1,20 @@
1
+ import { G as InvoiceType, N as CreatedInvoice } from "./context-CFNKzStE.cjs";
2
+ import { r as Receipt } from "./types-lnKkQdot.cjs";
3
+ import { n as InvoiceDetails } from "./get-Byc9T5WO.cjs";
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 };