kassza 0.10.0 → 0.12.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 (90) hide show
  1. package/README.md +103 -103
  2. package/dist/client-CL3fuH6A.js +1596 -0
  3. package/dist/{client-zv4enyq7.d.ts → client-CickRRFr.d.ts} +307 -217
  4. package/dist/client-CsmGIFRS.cjs +1637 -0
  5. package/dist/{client-B9kbKKBf.d.cts → client-DvWZoX_E.d.cts} +307 -217
  6. package/dist/create-once-CqdYmQD8.js +330 -0
  7. package/dist/create-once-D0pwuenl.cjs +389 -0
  8. package/dist/crypto-B8lERvR1.cjs +56 -0
  9. package/dist/crypto-DK_osBVy.js +33 -0
  10. package/dist/{dates-DtHzwNU6.d.cts → dates-9zvESP0i.d.cts} +2 -1
  11. package/dist/{dates-DtHzwNU6.d.ts → dates-9zvESP0i.d.ts} +2 -1
  12. package/dist/{dates-PPxH0n5H.cjs → dates-CPgBodkP.cjs} +44 -1
  13. package/dist/{dates-D2XebOIg.js → dates-CXyj7Azy.js} +39 -2
  14. package/dist/delegation/index.cjs +395 -0
  15. package/dist/delegation/index.d.cts +99 -0
  16. package/dist/delegation/index.d.ts +99 -0
  17. package/dist/delegation/index.js +377 -0
  18. package/dist/{errors-DapdV5DK.js → errors-DLrb0g64.js} +122 -5
  19. package/dist/{errors-B0QJhUW1.cjs → errors-DxeuTslP.cjs} +127 -4
  20. package/dist/index.cjs +21 -1410
  21. package/dist/index.d.cts +18 -3
  22. package/dist/index.d.ts +18 -3
  23. package/dist/index.js +8 -1409
  24. package/dist/ipn/index.cjs +1 -1
  25. package/dist/ipn/index.js +1 -1
  26. package/dist/{create-DZsl3Z4m.cjs → issue-BsyYdrIG.cjs} +664 -311
  27. package/dist/{create-5YkUcJSe.js → issue-C6Fcjvln.js} +589 -272
  28. package/dist/json-4y4E2xxS.cjs +61 -0
  29. package/dist/json-B70TwoX1.d.cts +4 -0
  30. package/dist/json-B70TwoX1.d.ts +4 -0
  31. package/dist/json-DjnqnaJK.js +32 -0
  32. package/dist/money/index.cjs +12 -10
  33. package/dist/money/index.js +3 -1
  34. package/dist/{money-C9j7nBNP.js → money-DAA7OwiO.js} +4 -101
  35. package/dist/{money-DkiGukAw.cjs → money-DrhGkWHW.cjs} +19 -170
  36. package/dist/payments/barion.cjs +208 -0
  37. package/dist/payments/barion.d.cts +28 -0
  38. package/dist/payments/barion.d.ts +28 -0
  39. package/dist/payments/barion.js +199 -0
  40. package/dist/payments/index.cjs +16 -0
  41. package/dist/payments/index.d.cts +31 -0
  42. package/dist/payments/index.d.ts +31 -0
  43. package/dist/payments/index.js +3 -0
  44. package/dist/payments/paypal.cjs +351 -0
  45. package/dist/payments/paypal.d.cts +59 -0
  46. package/dist/payments/paypal.d.ts +59 -0
  47. package/dist/payments/paypal.js +337 -0
  48. package/dist/payments/revolut.cjs +261 -0
  49. package/dist/payments/revolut.d.cts +48 -0
  50. package/dist/payments/revolut.d.ts +48 -0
  51. package/dist/payments/revolut.js +249 -0
  52. package/dist/payments/simplepay.cjs +313 -0
  53. package/dist/payments/simplepay.d.cts +86 -0
  54. package/dist/payments/simplepay.d.ts +86 -0
  55. package/dist/payments/simplepay.js +299 -0
  56. package/dist/payments/stripe.cjs +315 -0
  57. package/dist/payments/stripe.d.cts +49 -0
  58. package/dist/payments/stripe.d.ts +49 -0
  59. package/dist/payments/stripe.js +303 -0
  60. package/dist/reports/index.cjs +256 -0
  61. package/dist/reports/index.d.cts +70 -0
  62. package/dist/reports/index.d.ts +70 -0
  63. package/dist/reports/index.js +247 -0
  64. package/dist/rounding-BLyHjjI5.js +20 -0
  65. package/dist/rounding-TxoWy2ww.cjs +37 -0
  66. package/dist/storage/fs.cjs +1 -1
  67. package/dist/storage/fs.js +1 -1
  68. package/dist/storage/index.cjs +2 -2
  69. package/dist/storage/index.d.cts +1 -1
  70. package/dist/storage/index.d.ts +1 -1
  71. package/dist/storage/index.js +2 -2
  72. package/dist/tax-number-BYFkBp4A.cjs +141 -0
  73. package/dist/tax-number-BdqKsxNR.js +76 -0
  74. package/dist/testing/index.cjs +183 -84
  75. package/dist/testing/index.d.cts +10 -2
  76. package/dist/testing/index.d.ts +10 -2
  77. package/dist/testing/index.js +181 -82
  78. package/dist/types-COf1LAD-.d.cts +56 -0
  79. package/dist/types-COf1LAD-.d.ts +56 -0
  80. package/dist/types-DH8QoNZK.d.cts +135 -0
  81. package/dist/types-k--zHf4l.d.ts +135 -0
  82. package/dist/validators/index.cjs +14 -88
  83. package/dist/validators/index.js +1 -75
  84. package/dist/vat-g35srbNG.cjs +116 -0
  85. package/dist/vat-v_dcWCto.js +81 -0
  86. package/dist/webhook-C76bV-4R.cjs +245 -0
  87. package/dist/webhook-CfaDgcL0.d.cts +6 -0
  88. package/dist/webhook-D4lvtex1.js +174 -0
  89. package/dist/webhook-q2OzNwd7.d.ts +6 -0
  90. package/package.json +106 -2
@@ -0,0 +1,389 @@
1
+ const require_errors = require("./errors-DxeuTslP.cjs");
2
+ const require_binary = require("./binary-B89HM03_.cjs");
3
+ const require_issue = require("./issue-BsyYdrIG.cjs");
4
+ const require_dates = require("./dates-CPgBodkP.cjs");
5
+ const require_vat = require("./vat-g35srbNG.cjs");
6
+ const require_money = require("./money-DrhGkWHW.cjs");
7
+ //#region src/core/actions.ts
8
+ const SZAMLAZZ_AGENT_URL = "https://www.szamlazz.hu/szamla/";
9
+ const AGENT_ACTIONS = {
10
+ createInvoice: "action-xmlagentxmlfile",
11
+ reverseInvoice: "action-szamla_agent_st",
12
+ registerPayment: "action-szamla_agent_kifiz",
13
+ getInvoicePdf: "action-szamla_agent_pdf",
14
+ getInvoiceXml: "action-szamla_agent_xml",
15
+ deleteProforma: "action-szamla_agent_dijbekero_torlese",
16
+ createReceipt: "action-szamla_agent_nyugta_create",
17
+ reverseReceipt: "action-szamla_agent_nyugta_storno",
18
+ getReceipt: "action-szamla_agent_nyugta_get",
19
+ sendReceipt: "action-szamla_agent_nyugta_send",
20
+ queryTaxpayer: "action-szamla_agent_taxpayer",
21
+ connectPrincipal: "action-agent_ceg_mb"
22
+ };
23
+ const MAX_INVOICE_ATTACHMENTS = 5;
24
+ //#endregion
25
+ //#region src/core/document-events.ts
26
+ async function emitDocumentEvent(hook, event) {
27
+ if (!hook) return;
28
+ try {
29
+ await hook(event);
30
+ } 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);
32
+ }
33
+ }
34
+ //#endregion
35
+ //#region src/invoices/create-types.ts
36
+ const INVOICE_TYPES = [
37
+ "invoice",
38
+ "proforma",
39
+ "advance",
40
+ "final",
41
+ "corrective",
42
+ "deliveryNote"
43
+ ];
44
+ const INVOICE_LANGUAGES = [
45
+ "hu",
46
+ "en",
47
+ "de",
48
+ "it",
49
+ "ro",
50
+ "sk",
51
+ "hr",
52
+ "fr",
53
+ "es",
54
+ "cz",
55
+ "pl",
56
+ "bg",
57
+ "nl",
58
+ "ru",
59
+ "si"
60
+ ];
61
+ const INVOICE_TEMPLATES = [
62
+ "SzlaMost",
63
+ "SzlaAlap",
64
+ "SzlaNoEnv",
65
+ "Szla8cm",
66
+ "SzlaTomb",
67
+ "SzlaFuvarlevelesAlap"
68
+ ];
69
+ const TAXPAYER_TYPE_CODES = {
70
+ nonEuBusiness: 7,
71
+ euBusiness: 6,
72
+ hungarianTaxNumber: 1,
73
+ unknown: 0,
74
+ noTaxNumber: -1
75
+ };
76
+ const SIMPLE_ITEMS_MAX = 2;
77
+ const SIMPLE_ITEMS_FINAL_MAX = 4;
78
+ const SIMPLE_ITEMS_VAT_RATES = /* @__PURE__ */ new Set([
79
+ 0,
80
+ 5,
81
+ 18,
82
+ 27,
83
+ "TAM",
84
+ "AAM",
85
+ "K.AFA",
86
+ "F.AFA"
87
+ ]);
88
+ const LANGUAGES = new Set(INVOICE_LANGUAGES);
89
+ const TEMPLATES = new Set(INVOICE_TEMPLATES);
90
+ const TYPES = new Set(INVOICE_TYPES);
91
+ function invalid(message, cause) {
92
+ return new require_errors.SzamlazzError(message, {
93
+ category: "validation",
94
+ cause
95
+ });
96
+ }
97
+ function presentText(value) {
98
+ return value === void 0 || value.trim() === "" ? void 0 : value;
99
+ }
100
+ function agentDate(value, field) {
101
+ try {
102
+ return require_dates.toAgentDate(value);
103
+ } catch (error) {
104
+ throw invalid(`A(z) ${field} mező nem érvényes dátum: ${String(value)}`, error);
105
+ }
106
+ }
107
+ function optionalAgentDate(value, field) {
108
+ return value === void 0 ? void 0 : agentDate(value, field);
109
+ }
110
+ function requireText(value, message) {
111
+ if (typeof value !== "string" || value.trim() === "") throw invalid(message);
112
+ }
113
+ function assertNonNegativeInteger(value, field) {
114
+ if (value === void 0) return;
115
+ if (!Number.isInteger(value) || value < 0) throw invalid(`A(z) ${field} mező nemnegatív egész szám legyen, kapott: ${value}`);
116
+ }
117
+ function assertFinite(value, field) {
118
+ if (value !== void 0 && !Number.isFinite(value)) throw invalid(`A(z) ${field} mező nem érvényes szám: ${value}`);
119
+ }
120
+ function mergeSeller(defaults = {}, input = {}) {
121
+ return {
122
+ bank: input.bank ?? defaults.bank,
123
+ bankAccount: input.bankAccount ?? defaults.bankAccount,
124
+ emailReplyTo: input.emailReplyTo ?? defaults.emailReplyTo,
125
+ emailSubject: input.emailSubject ?? defaults.emailSubject,
126
+ emailText: input.emailText ?? defaults.emailText,
127
+ signatoryName: input.signatoryName ?? defaults.signatoryName
128
+ };
129
+ }
130
+ function resolveType(input) {
131
+ const type = input.type ?? "invoice";
132
+ if (!TYPES.has(type)) throw invalid(`Ismeretlen bizonylattípus: ${String(type)}`);
133
+ if (input.type === "corrective") requireText(input.correctedInvoiceNumber, "Helyesbítő számlához add meg a helyesbített számla számát (correctedInvoiceNumber).");
134
+ if (input.type === "final" && !presentText(input.advanceInvoiceNumber)) requireText(input.orderNumber, "Végszámlához add meg az előlegszámla számát (advanceInvoiceNumber) vagy az előlegszámla rendelésszámát (orderNumber).");
135
+ return type;
136
+ }
137
+ function resolveDates(defaults, input, now) {
138
+ if (input.dueDate !== void 0 && input.paymentDueInDays !== void 0) throw invalid("A dueDate és a paymentDueInDays közül csak az egyiket add meg.");
139
+ const issueDate = optionalAgentDate(input.issueDate, "issueDate") ?? agentDate(now, "now");
140
+ const fulfillmentDate = optionalAgentDate(input.fulfillmentDate, "fulfillmentDate") ?? issueDate;
141
+ const explicitDue = optionalAgentDate(input.dueDate, "dueDate");
142
+ if (explicitDue !== void 0) return {
143
+ issueDate,
144
+ fulfillmentDate,
145
+ dueDate: explicitDue
146
+ };
147
+ const days = input.paymentDueInDays ?? defaults.paymentDueInDays ?? 0;
148
+ assertNonNegativeInteger(days, "paymentDueInDays");
149
+ return {
150
+ issueDate,
151
+ fulfillmentDate,
152
+ dueDate: require_dates.addBudapestDays(/* @__PURE__ */ new Date(`${issueDate}T12:00:00Z`), days)
153
+ };
154
+ }
155
+ function resolveCurrency(defaults, input) {
156
+ const currency = presentText(input.currency) ?? presentText(defaults.currency) ?? "HUF";
157
+ const exchangeRate = input.exchangeRate;
158
+ if (require_vat.isHuf(currency)) {
159
+ if (exchangeRate !== void 0 || presentText(input.exchangeBank) !== void 0) throw invalid("Forintos számlán nem adható meg árfolyam (exchangeRate, exchangeBank).");
160
+ return {
161
+ currency,
162
+ exchangeBank: void 0,
163
+ exchangeRate: void 0
164
+ };
165
+ }
166
+ if (exchangeRate !== void 0 && !(Number.isFinite(exchangeRate) && exchangeRate > 0)) throw invalid(`Az árfolyam (exchangeRate) pozitív szám legyen, kapott: ${exchangeRate}`);
167
+ const exchangeBank = presentText(input.exchangeBank) ?? presentText(defaults.exchangeBank) ?? "MNB";
168
+ if (exchangeRate === void 0 && exchangeBank.trim().toUpperCase() !== "MNB") throw invalid(`Devizás számlához (${currency}) add meg az árfolyamot (exchangeRate). Árfolyam nélkül csak az MNB automatikus árfolyama használható.`);
169
+ return {
170
+ currency,
171
+ exchangeBank,
172
+ exchangeRate
173
+ };
174
+ }
175
+ function resolveItems(items, currency) {
176
+ if (!Array.isArray(items) || items.length === 0) throw invalid("A számlán legalább egy tételnek szerepelnie kell.");
177
+ return items.map((item, index) => {
178
+ const label = `${index + 1}. tétel`;
179
+ requireText(item.name, `A(z) ${label} megnevezése (name) nem lehet üres.`);
180
+ const unit = item.unit ?? "db";
181
+ requireText(unit, `A(z) ${label} mennyiségi egysége (unit) nem lehet üres.`);
182
+ assertNonNegativeInteger(item.dataDeletionCode, `${label} dataDeletionCode`);
183
+ assertFinite(item.marginVatBase, `${label} marginVatBase`);
184
+ let amounts;
185
+ try {
186
+ amounts = require_money.calculateInvoiceItem(item, currency);
187
+ } catch (error) {
188
+ const message = error instanceof Error ? error.message : String(error);
189
+ throw invalid(`${label} (${item.name}): ${message}`, error);
190
+ }
191
+ return {
192
+ input: item,
193
+ unit,
194
+ amounts: {
195
+ name: item.name,
196
+ ...amounts
197
+ }
198
+ };
199
+ });
200
+ }
201
+ function validateSimpleItems(type, items) {
202
+ if (type === "corrective" || type === "deliveryNote") throw invalid("Egyszerűsített számlakép (simpleItems) helyesbítő számlán és szállítólevélen nem használható.");
203
+ const max = type === "final" ? SIMPLE_ITEMS_FINAL_MAX : SIMPLE_ITEMS_MAX;
204
+ if (items.length > max) throw invalid(`Egyszerűsített számlaképen (simpleItems) legfeljebb ${max} tétel adható meg.`);
205
+ const invalidItem = items.find((item) => !SIMPLE_ITEMS_VAT_RATES.has(item.amounts.vat));
206
+ if (invalidItem) throw invalid(`Egyszerűsített számlaképen (simpleItems) csak 0, 5, 18, 27, TAM, AAM, K.AFA vagy F.AFA áfakulcs használható, kapott: ${String(invalidItem.amounts.vat)}`);
207
+ }
208
+ function attachmentSize(content) {
209
+ if (typeof content === "string") return require_binary.encodeUtf8(content).byteLength;
210
+ if (content instanceof Blob) return content.size;
211
+ return content.byteLength;
212
+ }
213
+ function validateAttachments(attachments, sendEmail) {
214
+ if (attachments.length === 0) return attachments;
215
+ if (attachments.length > 5) throw invalid(`Legfeljebb 5 melléklet csatolható, kapott: ${attachments.length}`);
216
+ if (!sendEmail) throw invalid("Mellékletet csak e-mail értesítővel lehet küldeni: add meg a vevő e-mail címét, és ne kapcsold ki a sendEmail beállítást.");
217
+ for (const attachment of attachments) {
218
+ requireText(attachment.filename, "A melléklet fájlneve (filename) nem lehet üres.");
219
+ if (attachmentSize(attachment.content) > 2097152) throw invalid(`A(z) ${attachment.filename} melléklet nagyobb 2 MB-nál.`);
220
+ }
221
+ return attachments;
222
+ }
223
+ function validateWaybill(waybill) {
224
+ if (!waybill) return;
225
+ assertNonNegativeInteger(waybill.transOFlex?.packageCount, "waybill.transOFlex.packageCount");
226
+ assertNonNegativeInteger(waybill.sprinter?.packageCount, "waybill.sprinter.packageCount");
227
+ const mpl = waybill.mpl;
228
+ if (!mpl) return;
229
+ requireText(mpl.customerCode, "Az MPL fuvarlevélhez add meg a vevőkódot (customerCode).");
230
+ requireText(mpl.barcode, "Az MPL fuvarlevélhez add meg a vonalkódot (barcode).");
231
+ requireText(String(mpl.weight ?? ""), "Az MPL fuvarlevélhez add meg a tömeget (weight).");
232
+ assertFinite(mpl.declaredValue, "waybill.mpl.declaredValue");
233
+ }
234
+ function resolveSendEmail(defaults, input) {
235
+ const hasEmail = presentText(input.buyer.email) !== void 0;
236
+ if (input.buyer.sendEmail === true && !hasEmail) throw invalid("A sendEmail be van kapcsolva, de a vevőnek nincs e-mail címe (buyer.email).");
237
+ if (!hasEmail) return false;
238
+ return input.buyer.sendEmail ?? defaults.sendEmail ?? true;
239
+ }
240
+ function validateBuyer(input) {
241
+ const buyer = input.buyer;
242
+ if (!buyer || typeof buyer !== "object") throw invalid("A vevő adatai (buyer) kötelezők.");
243
+ requireText(buyer.name, "A vevő neve (buyer.name) nem lehet üres.");
244
+ requireText(buyer.zip, "A vevő irányítószáma (buyer.zip) nem lehet üres.");
245
+ requireText(buyer.city, "A vevő települése (buyer.city) nem lehet üres.");
246
+ requireText(buyer.address, "A vevő címe (buyer.address) nem lehet üres.");
247
+ }
248
+ function resolveInvoice(defaults, input, now) {
249
+ validateBuyer(input);
250
+ const type = resolveType(input);
251
+ const language = input.language ?? defaults.language ?? "hu";
252
+ if (!LANGUAGES.has(language)) throw invalid(`Ismeretlen számlanyelv: ${String(language)}`);
253
+ const template = input.template ?? defaults.template;
254
+ if (template !== void 0 && !TEMPLATES.has(template)) throw invalid(`Ismeretlen számlasablon: ${String(template)}`);
255
+ assertFinite(input.paymentCorrection, "paymentCorrection");
256
+ const currency = resolveCurrency(defaults, input);
257
+ const dates = resolveDates(defaults, input, now);
258
+ const items = resolveItems(input.items, currency.currency);
259
+ const simpleItems = input.simpleItems ?? defaults.simpleItems;
260
+ if (simpleItems) validateSimpleItems(type, items);
261
+ validateWaybill(input.waybill);
262
+ const sendEmail = resolveSendEmail(defaults, input);
263
+ const attachments = validateAttachments(input.attachments ?? [], sendEmail);
264
+ return {
265
+ input,
266
+ type,
267
+ ...dates,
268
+ ...currency,
269
+ paymentMethod: presentText(input.paymentMethod) ?? presentText(defaults.paymentMethod) ?? "Átutalás",
270
+ language,
271
+ prefix: presentText(input.prefix) ?? presentText(defaults.prefix),
272
+ eInvoice: input.eInvoice ?? defaults.eInvoice ?? false,
273
+ downloadPdf: input.downloadPdf ?? defaults.downloadPdf ?? true,
274
+ template,
275
+ simpleItems,
276
+ euVat: input.euVat ?? defaults.euVat,
277
+ logoExtra: presentText(input.logoExtra) ?? presentText(defaults.logoExtra),
278
+ aggregator: presentText(input.aggregator) ?? presentText(defaults.aggregator),
279
+ guardian: input.guardian ?? defaults.guardian,
280
+ articleIdentifierInvoice: input.articleIdentifierInvoice ?? defaults.articleIdentifierInvoice,
281
+ seller: mergeSeller(defaults.seller, input.seller),
282
+ sendEmail,
283
+ items,
284
+ attachments
285
+ };
286
+ }
287
+ //#endregion
288
+ //#region src/receipts/create-once.ts
289
+ function requireOrderNumber(input) {
290
+ const orderNumber = input.orderNumber?.trim();
291
+ 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
+ return orderNumber;
293
+ }
294
+ async function createReceiptOnce(api, input, options = {}) {
295
+ const orderNumber = requireOrderNumber(input);
296
+ const callId = input.callId?.trim() || orderNumber;
297
+ const delayMs = require_issue.resolveRecoveryDelay(options.recoveryDelayMs);
298
+ const lookup = () => api.find({
299
+ orderNumber,
300
+ downloadPdf: input.downloadPdf
301
+ }, 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
+ }
328
+ }
329
+ //#endregion
330
+ Object.defineProperty(exports, "AGENT_ACTIONS", {
331
+ enumerable: true,
332
+ get: function() {
333
+ return AGENT_ACTIONS;
334
+ }
335
+ });
336
+ Object.defineProperty(exports, "INVOICE_TEMPLATES", {
337
+ enumerable: true,
338
+ get: function() {
339
+ return INVOICE_TEMPLATES;
340
+ }
341
+ });
342
+ Object.defineProperty(exports, "MAX_INVOICE_ATTACHMENTS", {
343
+ enumerable: true,
344
+ get: function() {
345
+ return MAX_INVOICE_ATTACHMENTS;
346
+ }
347
+ });
348
+ Object.defineProperty(exports, "SZAMLAZZ_AGENT_URL", {
349
+ enumerable: true,
350
+ get: function() {
351
+ return SZAMLAZZ_AGENT_URL;
352
+ }
353
+ });
354
+ Object.defineProperty(exports, "TAXPAYER_TYPE_CODES", {
355
+ enumerable: true,
356
+ get: function() {
357
+ return TAXPAYER_TYPE_CODES;
358
+ }
359
+ });
360
+ Object.defineProperty(exports, "createReceiptOnce", {
361
+ enumerable: true,
362
+ get: function() {
363
+ return createReceiptOnce;
364
+ }
365
+ });
366
+ Object.defineProperty(exports, "emitDocumentEvent", {
367
+ enumerable: true,
368
+ get: function() {
369
+ return emitDocumentEvent;
370
+ }
371
+ });
372
+ Object.defineProperty(exports, "optionalAgentDate", {
373
+ enumerable: true,
374
+ get: function() {
375
+ return optionalAgentDate;
376
+ }
377
+ });
378
+ Object.defineProperty(exports, "presentText", {
379
+ enumerable: true,
380
+ get: function() {
381
+ return presentText;
382
+ }
383
+ });
384
+ Object.defineProperty(exports, "resolveInvoice", {
385
+ enumerable: true,
386
+ get: function() {
387
+ return resolveInvoice;
388
+ }
389
+ });
@@ -0,0 +1,56 @@
1
+ //#region src/core/crypto.ts
2
+ const encoder = new TextEncoder();
3
+ function toBytes(data) {
4
+ if (typeof data === "string") return encoder.encode(data);
5
+ const copy = new Uint8Array(data.byteLength);
6
+ copy.set(data);
7
+ return copy;
8
+ }
9
+ function bytesToHex(bytes) {
10
+ let hex = "";
11
+ for (const byte of bytes) hex += byte.toString(16).padStart(2, "0");
12
+ return hex;
13
+ }
14
+ async function hmac(algorithm, key, data) {
15
+ const cryptoKey = await crypto.subtle.importKey("raw", toBytes(key), {
16
+ name: "HMAC",
17
+ hash: algorithm
18
+ }, false, ["sign"]);
19
+ return new Uint8Array(await crypto.subtle.sign("HMAC", cryptoKey, toBytes(data)));
20
+ }
21
+ async function hmacHex(algorithm, key, data) {
22
+ return bytesToHex(await hmac(algorithm, key, data));
23
+ }
24
+ function timingSafeEqual(left, right) {
25
+ const a = encoder.encode(left);
26
+ const b = encoder.encode(right);
27
+ let difference = a.length ^ b.length;
28
+ const length = Math.max(a.length, b.length);
29
+ for (let index = 0; index < length; index++) difference |= (a[index] ?? 0) ^ (b[index] ?? 0);
30
+ return difference === 0;
31
+ }
32
+ //#endregion
33
+ Object.defineProperty(exports, "bytesToHex", {
34
+ enumerable: true,
35
+ get: function() {
36
+ return bytesToHex;
37
+ }
38
+ });
39
+ Object.defineProperty(exports, "hmac", {
40
+ enumerable: true,
41
+ get: function() {
42
+ return hmac;
43
+ }
44
+ });
45
+ Object.defineProperty(exports, "hmacHex", {
46
+ enumerable: true,
47
+ get: function() {
48
+ return hmacHex;
49
+ }
50
+ });
51
+ Object.defineProperty(exports, "timingSafeEqual", {
52
+ enumerable: true,
53
+ get: function() {
54
+ return timingSafeEqual;
55
+ }
56
+ });
@@ -0,0 +1,33 @@
1
+ //#region src/core/crypto.ts
2
+ const encoder = new TextEncoder();
3
+ function toBytes(data) {
4
+ if (typeof data === "string") return encoder.encode(data);
5
+ const copy = new Uint8Array(data.byteLength);
6
+ copy.set(data);
7
+ return copy;
8
+ }
9
+ function bytesToHex(bytes) {
10
+ let hex = "";
11
+ for (const byte of bytes) hex += byte.toString(16).padStart(2, "0");
12
+ return hex;
13
+ }
14
+ async function hmac(algorithm, key, data) {
15
+ const cryptoKey = await crypto.subtle.importKey("raw", toBytes(key), {
16
+ name: "HMAC",
17
+ hash: algorithm
18
+ }, false, ["sign"]);
19
+ return new Uint8Array(await crypto.subtle.sign("HMAC", cryptoKey, toBytes(data)));
20
+ }
21
+ async function hmacHex(algorithm, key, data) {
22
+ return bytesToHex(await hmac(algorithm, key, data));
23
+ }
24
+ function timingSafeEqual(left, right) {
25
+ const a = encoder.encode(left);
26
+ const b = encoder.encode(right);
27
+ let difference = a.length ^ b.length;
28
+ const length = Math.max(a.length, b.length);
29
+ for (let index = 0; index < length; index++) difference |= (a[index] ?? 0) ^ (b[index] ?? 0);
30
+ return difference === 0;
31
+ }
32
+ //#endregion
33
+ export { timingSafeEqual as i, hmac as n, hmacHex as r, bytesToHex as t };
@@ -1,7 +1,8 @@
1
1
  //#region src/core/dates.d.ts
2
2
  declare function toBudapestDate(date: Date): string;
3
+ declare function toBudapestTimestamp(date: Date): string;
3
4
  declare function addBudapestDays(date: Date, days: number): string;
4
5
  type DateInput = Date | string;
5
6
  declare function todayInBudapest(now?: Date): string;
6
7
  //#endregion
7
- export { todayInBudapest as i, addBudapestDays as n, toBudapestDate as r, DateInput as t };
8
+ export { todayInBudapest as a, toBudapestTimestamp as i, addBudapestDays as n, toBudapestDate as r, DateInput as t };
@@ -1,7 +1,8 @@
1
1
  //#region src/core/dates.d.ts
2
2
  declare function toBudapestDate(date: Date): string;
3
+ declare function toBudapestTimestamp(date: Date): string;
3
4
  declare function addBudapestDays(date: Date, days: number): string;
4
5
  type DateInput = Date | string;
5
6
  declare function todayInBudapest(now?: Date): string;
6
7
  //#endregion
7
- export { todayInBudapest as i, addBudapestDays as n, toBudapestDate as r, DateInput as t };
8
+ export { todayInBudapest as a, toBudapestTimestamp as i, addBudapestDays as n, toBudapestDate as r, DateInput as t };
@@ -1,6 +1,7 @@
1
1
  //#region src/core/dates.ts
2
+ const BUDAPEST_TIME_ZONE = "Europe/Budapest";
2
3
  const budapestDateFormatter = new Intl.DateTimeFormat("en-CA", {
3
- timeZone: "Europe/Budapest",
4
+ timeZone: BUDAPEST_TIME_ZONE,
4
5
  year: "numeric",
5
6
  month: "2-digit",
6
7
  day: "2-digit"
@@ -11,6 +12,42 @@ function toBudapestDate(date) {
11
12
  const get = (type) => parts.find((part) => part.type === type)?.value ?? "";
12
13
  return `${get("year")}-${get("month")}-${get("day")}`;
13
14
  }
15
+ const budapestTimestampFormatter = new Intl.DateTimeFormat("en-CA", {
16
+ timeZone: BUDAPEST_TIME_ZONE,
17
+ year: "numeric",
18
+ month: "2-digit",
19
+ day: "2-digit",
20
+ hour: "2-digit",
21
+ minute: "2-digit",
22
+ second: "2-digit",
23
+ hourCycle: "h23"
24
+ });
25
+ const MINUTE_IN_MS = 6e4;
26
+ function pad2(value) {
27
+ return String(value).padStart(2, "0");
28
+ }
29
+ function toBudapestTimestamp(date) {
30
+ const time = date.getTime();
31
+ if (Number.isNaN(time)) throw new RangeError("Érvénytelen dátum");
32
+ const parts = budapestTimestampFormatter.formatToParts(date);
33
+ const get = (type) => Number(parts.find((part) => part.type === type)?.value ?? NaN);
34
+ const [year, month, day] = [
35
+ get("year"),
36
+ get("month"),
37
+ get("day")
38
+ ];
39
+ const [hour, minute, second] = [
40
+ get("hour"),
41
+ get("minute"),
42
+ get("second")
43
+ ];
44
+ const localAsUtc = Date.UTC(year, month - 1, day, hour, minute, second);
45
+ const offsetMinutes = Math.round((localAsUtc - Math.floor(time / 1e3) * 1e3) / MINUTE_IN_MS);
46
+ const sign = offsetMinutes < 0 ? "-" : "+";
47
+ const absolute = Math.abs(offsetMinutes);
48
+ const offset = `${sign}${pad2(Math.floor(absolute / 60))}:${pad2(absolute % 60)}`;
49
+ return `${year}-${pad2(month)}-${pad2(day)}T${pad2(hour)}:${pad2(minute)}:${pad2(second)}${offset}`;
50
+ }
14
51
  const DAY_IN_MS = 864e5;
15
52
  function addBudapestDays(date, days) {
16
53
  if (!Number.isInteger(days)) throw new RangeError(`A napok számának egésznek kell lennie, kapott: ${days}`);
@@ -49,6 +86,12 @@ Object.defineProperty(exports, "toBudapestDate", {
49
86
  return toBudapestDate;
50
87
  }
51
88
  });
89
+ Object.defineProperty(exports, "toBudapestTimestamp", {
90
+ enumerable: true,
91
+ get: function() {
92
+ return toBudapestTimestamp;
93
+ }
94
+ });
52
95
  Object.defineProperty(exports, "todayInBudapest", {
53
96
  enumerable: true,
54
97
  get: function() {
@@ -1,6 +1,7 @@
1
1
  //#region src/core/dates.ts
2
+ const BUDAPEST_TIME_ZONE = "Europe/Budapest";
2
3
  const budapestDateFormatter = new Intl.DateTimeFormat("en-CA", {
3
- timeZone: "Europe/Budapest",
4
+ timeZone: BUDAPEST_TIME_ZONE,
4
5
  year: "numeric",
5
6
  month: "2-digit",
6
7
  day: "2-digit"
@@ -11,6 +12,42 @@ function toBudapestDate(date) {
11
12
  const get = (type) => parts.find((part) => part.type === type)?.value ?? "";
12
13
  return `${get("year")}-${get("month")}-${get("day")}`;
13
14
  }
15
+ const budapestTimestampFormatter = new Intl.DateTimeFormat("en-CA", {
16
+ timeZone: BUDAPEST_TIME_ZONE,
17
+ year: "numeric",
18
+ month: "2-digit",
19
+ day: "2-digit",
20
+ hour: "2-digit",
21
+ minute: "2-digit",
22
+ second: "2-digit",
23
+ hourCycle: "h23"
24
+ });
25
+ const MINUTE_IN_MS = 6e4;
26
+ function pad2(value) {
27
+ return String(value).padStart(2, "0");
28
+ }
29
+ function toBudapestTimestamp(date) {
30
+ const time = date.getTime();
31
+ if (Number.isNaN(time)) throw new RangeError("Érvénytelen dátum");
32
+ const parts = budapestTimestampFormatter.formatToParts(date);
33
+ const get = (type) => Number(parts.find((part) => part.type === type)?.value ?? NaN);
34
+ const [year, month, day] = [
35
+ get("year"),
36
+ get("month"),
37
+ get("day")
38
+ ];
39
+ const [hour, minute, second] = [
40
+ get("hour"),
41
+ get("minute"),
42
+ get("second")
43
+ ];
44
+ const localAsUtc = Date.UTC(year, month - 1, day, hour, minute, second);
45
+ const offsetMinutes = Math.round((localAsUtc - Math.floor(time / 1e3) * 1e3) / MINUTE_IN_MS);
46
+ const sign = offsetMinutes < 0 ? "-" : "+";
47
+ const absolute = Math.abs(offsetMinutes);
48
+ const offset = `${sign}${pad2(Math.floor(absolute / 60))}:${pad2(absolute % 60)}`;
49
+ return `${year}-${pad2(month)}-${pad2(day)}T${pad2(hour)}:${pad2(minute)}:${pad2(second)}${offset}`;
50
+ }
14
51
  const DAY_IN_MS = 864e5;
15
52
  function addBudapestDays(date, days) {
16
53
  if (!Number.isInteger(days)) throw new RangeError(`A napok számának egésznek kell lennie, kapott: ${days}`);
@@ -31,4 +68,4 @@ function todayInBudapest(now = /* @__PURE__ */ new Date()) {
31
68
  return toBudapestDate(now);
32
69
  }
33
70
  //#endregion
34
- export { todayInBudapest as i, toAgentDate as n, toBudapestDate as r, addBudapestDays as t };
71
+ export { todayInBudapest as a, toBudapestTimestamp as i, toAgentDate as n, toBudapestDate as r, addBudapestDays as t };