kassza 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.en.md +48 -0
  2. package/README.md +427 -32
  3. package/agents/README.md +26 -6
  4. package/agents/api.md +218 -3
  5. package/agents/pitfalls.md +27 -3
  6. package/agents/recipes.md +280 -51
  7. package/agents/skills/kassza/SKILL.md +14 -8
  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 +643 -0
  14. package/dist/cli.d.cts +1 -0
  15. package/dist/cli.d.ts +1 -0
  16. package/dist/cli.js +643 -0
  17. package/dist/client-CLFvJCVW.cjs +1452 -0
  18. package/dist/{client-CL3fuH6A.js → client-Cvf-hTz_.js} +306 -515
  19. package/dist/client-DeWWQ-RZ.d.ts +341 -0
  20. package/dist/client-SVZu25MB.d.cts +341 -0
  21. package/dist/context-CFNKzStE.d.cts +449 -0
  22. package/dist/context-kb33TgzE.d.ts +449 -0
  23. package/dist/cookie-stores/index.cjs +21 -150
  24. package/dist/cookie-stores/index.d.cts +4 -63
  25. package/dist/cookie-stores/index.d.ts +4 -63
  26. package/dist/cookie-stores/index.js +3 -144
  27. package/dist/create-CflXrPip.js +204 -0
  28. package/dist/create-CvUvLUaT.cjs +257 -0
  29. package/dist/{create-once-D0pwuenl.cjs → create-once-9yxR_Er_.cjs} +291 -33
  30. package/dist/create-once-Bh6fOWkW.d.cts +20 -0
  31. package/dist/{create-once-CqdYmQD8.js → create-once-Ca2gMk1h.js} +250 -34
  32. package/dist/create-once-VKp0tVow.d.ts +20 -0
  33. package/dist/{crypto-B8lERvR1.cjs → crypto-Dpn4FHQ6.cjs} +9 -0
  34. package/dist/{crypto-DK_osBVy.js → crypto-usDg8L2K.js} +4 -1
  35. package/dist/data-link/index.cjs +232 -0
  36. package/dist/data-link/index.d.cts +29 -0
  37. package/dist/data-link/index.d.ts +29 -0
  38. package/dist/data-link/index.js +224 -0
  39. package/dist/delegation/index.cjs +35 -34
  40. package/dist/delegation/index.d.cts +2 -1
  41. package/dist/delegation/index.d.ts +2 -1
  42. package/dist/delegation/index.js +4 -3
  43. package/dist/{errors-DLrb0g64.js → errors-DtN4g5Z9.js} +9 -1
  44. package/dist/{errors-DxeuTslP.cjs → errors-EE96_6D_.cjs} +20 -0
  45. package/dist/get-BdMTseh4.cjs +271 -0
  46. package/dist/get-Byc9T5WO.d.cts +151 -0
  47. package/dist/get-Byc9T5WO.d.ts +151 -0
  48. package/dist/get-CZEShCcj.js +260 -0
  49. package/dist/index-BhUPY_EH.d.cts +109 -0
  50. package/dist/index-BqGgQ4t3.d.ts +109 -0
  51. package/dist/{index-CYAGCdKJ.d.cts → index-C-7yWV7L.d.cts} +24 -1
  52. package/dist/{index-CYAGCdKJ.d.ts → index-C-7yWV7L.d.ts} +24 -1
  53. package/dist/index.cjs +19 -5
  54. package/dist/index.d.cts +11 -19
  55. package/dist/index.d.ts +11 -19
  56. package/dist/index.js +6 -6
  57. package/dist/ipn/index.cjs +26 -5
  58. package/dist/ipn/index.d.cts +12 -1
  59. package/dist/ipn/index.d.ts +12 -1
  60. package/dist/ipn/index.js +26 -6
  61. package/dist/issue-Bin4tKD_.cjs +988 -0
  62. package/dist/issue-DMA1Nbr1.js +905 -0
  63. package/dist/journal/index.cjs +454 -0
  64. package/dist/journal/index.d.cts +18 -0
  65. package/dist/journal/index.d.ts +18 -0
  66. package/dist/journal/index.js +445 -0
  67. package/dist/journal-DvI81Kt7.d.cts +114 -0
  68. package/dist/journal-Y9qrIB8G.d.ts +114 -0
  69. package/dist/mcp/index.cjs +10 -0
  70. package/dist/mcp/index.d.cts +71 -0
  71. package/dist/mcp/index.d.ts +71 -0
  72. package/dist/mcp/index.js +2 -0
  73. package/dist/money/index.cjs +2 -1
  74. package/dist/money/index.d.cts +2 -2
  75. package/dist/money/index.d.ts +2 -2
  76. package/dist/money/index.js +2 -2
  77. package/dist/{money-DAA7OwiO.js → money-Cw457SD6.js} +120 -12
  78. package/dist/{money-DrhGkWHW.cjs → money-K9j0wPit.cjs} +124 -10
  79. package/dist/nav/index.cjs +1046 -0
  80. package/dist/nav/index.d.cts +247 -0
  81. package/dist/nav/index.d.ts +247 -0
  82. package/dist/nav/index.js +1012 -0
  83. package/dist/nav-BNbc8U0R.cjs +203 -0
  84. package/dist/nav-BcCerwWS.js +156 -0
  85. package/dist/node/index.cjs +124 -0
  86. package/dist/node/index.d.cts +35 -0
  87. package/dist/node/index.d.ts +35 -0
  88. package/dist/node/index.js +120 -0
  89. package/dist/observe/index.cjs +311 -0
  90. package/dist/observe/index.d.cts +53 -0
  91. package/dist/observe/index.d.ts +53 -0
  92. package/dist/observe/index.js +303 -0
  93. package/dist/once-BN_3B5OF.cjs +103 -0
  94. package/dist/once-CqqZxsXG.js +74 -0
  95. package/dist/parse-Cr7yQ3_z.js +291 -0
  96. package/dist/parse-DOA2XQ3e.cjs +380 -0
  97. package/dist/payments/barion.cjs +26 -2
  98. package/dist/payments/barion.d.cts +2 -2
  99. package/dist/payments/barion.d.ts +2 -2
  100. package/dist/payments/barion.js +26 -2
  101. package/dist/payments/index.cjs +7 -2
  102. package/dist/payments/index.d.cts +4 -4
  103. package/dist/payments/index.d.ts +4 -4
  104. package/dist/payments/index.js +3 -3
  105. package/dist/payments/paypal.cjs +16 -2
  106. package/dist/payments/paypal.d.cts +2 -2
  107. package/dist/payments/paypal.d.ts +2 -2
  108. package/dist/payments/paypal.js +16 -2
  109. package/dist/payments/revolut.cjs +17 -3
  110. package/dist/payments/revolut.d.cts +2 -2
  111. package/dist/payments/revolut.d.ts +2 -2
  112. package/dist/payments/revolut.js +17 -3
  113. package/dist/payments/simplepay.cjs +37 -5
  114. package/dist/payments/simplepay.d.cts +2 -2
  115. package/dist/payments/simplepay.d.ts +2 -2
  116. package/dist/payments/simplepay.js +37 -5
  117. package/dist/payments/stripe.cjs +20 -3
  118. package/dist/payments/stripe.d.cts +2 -2
  119. package/dist/payments/stripe.d.ts +2 -2
  120. package/dist/payments/stripe.js +20 -3
  121. package/dist/push-BXj0Sf0Z.d.ts +52 -0
  122. package/dist/push-D4nNbCNV.d.cts +52 -0
  123. package/dist/reference-B5TATqb5.js +124 -0
  124. package/dist/reference-BIdYMK0t.cjs +183 -0
  125. package/dist/reports/index.cjs +11 -164
  126. package/dist/reports/index.d.cts +1 -1
  127. package/dist/reports/index.d.ts +1 -1
  128. package/dist/reports/index.js +1 -154
  129. package/dist/request-body-CH6ZGOrq.cjs +34 -0
  130. package/dist/request-body-uZHMRlQr.js +29 -0
  131. package/dist/serialize-B2eFh3D-.js +219 -0
  132. package/dist/serialize-CquIsxA-.cjs +290 -0
  133. package/dist/server-BrJUbXs7.js +1505 -0
  134. package/dist/server-Dw9j8Mnd.cjs +1558 -0
  135. package/dist/session-Ckl5eJhV.d.ts +7 -0
  136. package/dist/{session-CKOuE6Jc.cjs → session-DeM5vjvC.cjs} +69 -13
  137. package/dist/{session-rMKaJcmq.js → session-SaEEXu2N.js} +58 -14
  138. package/dist/session-YbChChx7.d.cts +7 -0
  139. package/dist/storage/fs.cjs +1 -1
  140. package/dist/storage/fs.js +1 -1
  141. package/dist/storage/index.cjs +1 -1
  142. package/dist/storage/index.js +1 -1
  143. package/dist/store-C1rHd9DB.d.cts +19 -0
  144. package/dist/store-C1rHd9DB.d.ts +19 -0
  145. package/dist/stores/index.cjs +24 -0
  146. package/dist/stores/index.d.cts +4 -0
  147. package/dist/stores/index.d.ts +4 -0
  148. package/dist/stores/index.js +3 -0
  149. package/dist/stores-BNrS0dWl.cjs +506 -0
  150. package/dist/stores-DhjGBrl_.js +441 -0
  151. package/dist/testing/index.cjs +1500 -15
  152. package/dist/testing/index.d.cts +198 -3
  153. package/dist/testing/index.d.ts +198 -3
  154. package/dist/testing/index.js +1498 -15
  155. package/dist/{types-COf1LAD-.d.ts → types-B1A8mUIE.d.cts} +14 -2
  156. package/dist/{types-COf1LAD-.d.cts → types-ByAEvGsZ.d.ts} +14 -2
  157. package/dist/{types-k--zHf4l.d.ts → types-D1zDOH_F.d.ts} +1 -1
  158. package/dist/{types-DH8QoNZK.d.cts → types-lnKkQdot.d.cts} +1 -1
  159. package/dist/warnings-B3DXnveC.d.cts +31 -0
  160. package/dist/warnings-B3DXnveC.d.ts +31 -0
  161. package/dist/warnings-DeIw5RFj.cjs +20 -0
  162. package/dist/warnings-DwTl5J-2.js +15 -0
  163. package/dist/{webhook-D4lvtex1.js → webhook-CQVShAfI.js} +47 -26
  164. package/dist/{webhook-C76bV-4R.cjs → webhook-Ckj-_hPD.cjs} +70 -25
  165. package/dist/webhook-CmdhGiH5.d.cts +11 -0
  166. package/dist/webhook-D6lEejob.d.ts +11 -0
  167. package/llms.txt +6 -5
  168. package/package.json +134 -4
  169. package/dist/client-CickRRFr.d.ts +0 -838
  170. package/dist/client-CsmGIFRS.cjs +0 -1637
  171. package/dist/client-DvWZoX_E.d.cts +0 -838
  172. package/dist/issue-BsyYdrIG.cjs +0 -1531
  173. package/dist/issue-C6Fcjvln.js +0 -1274
  174. package/dist/session-Dm_45x8K.d.cts +0 -11
  175. package/dist/session-Dm_45x8K.d.ts +0 -11
  176. package/dist/webhook-CfaDgcL0.d.cts +0 -6
  177. package/dist/webhook-q2OzNwd7.d.ts +0 -6
@@ -0,0 +1,346 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("../errors-EE96_6D_.cjs");
3
+ const require_dates = require("../dates-CPgBodkP.cjs");
4
+ const require_create = require("../create-CvUvLUaT.cjs");
5
+ //#region src/batch/recurring.ts
6
+ const INTERVALS = /* @__PURE__ */ new Set([
7
+ "week",
8
+ "month",
9
+ "quarter",
10
+ "year"
11
+ ]);
12
+ const MONTHS = {
13
+ month: 1,
14
+ quarter: 3,
15
+ year: 12
16
+ };
17
+ function invalid$1(message) {
18
+ return new require_errors.SzamlazzError(message, { category: "validation" });
19
+ }
20
+ function parts(day) {
21
+ const [year, month, date] = day.split("-").map(Number);
22
+ return [
23
+ year,
24
+ month,
25
+ date
26
+ ];
27
+ }
28
+ function format(year, month, day) {
29
+ return `${String(year).padStart(4, "0")}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
30
+ }
31
+ function daysInMonth(year, month) {
32
+ return new Date(Date.UTC(year, month, 0)).getUTCDate();
33
+ }
34
+ function addDays(day, days) {
35
+ const [year, month, date] = parts(day);
36
+ return new Date(Date.UTC(year, month - 1, date + days)).toISOString().slice(0, 10);
37
+ }
38
+ function shift(anchor, interval, count) {
39
+ if (interval === "week") return addDays(anchor, count * 7);
40
+ const [year, month, day] = parts(anchor);
41
+ const total = year * 12 + (month - 1) + count * MONTHS[interval];
42
+ const targetYear = Math.floor(total / 12);
43
+ const targetMonth = total % 12 + 1;
44
+ return format(targetYear, targetMonth, Math.min(day, daysInMonth(targetYear, targetMonth)));
45
+ }
46
+ function resolve(options) {
47
+ if (!INTERVALS.has(options.interval)) throw invalid$1(`Ismeretlen számlázási időszak: ${String(options.interval)}`);
48
+ let anchor;
49
+ try {
50
+ anchor = require_dates.toAgentDate(options.anchor);
51
+ } catch (error) {
52
+ throw invalid$1(error instanceof Error ? error.message : String(error));
53
+ }
54
+ const due = options.paymentDueInDays;
55
+ if (due !== void 0 && (!Number.isInteger(due) || due < 0)) throw invalid$1(`A paymentDueInDays nemnegatív egész legyen, kapott: ${due}`);
56
+ return {
57
+ anchor,
58
+ interval: options.interval
59
+ };
60
+ }
61
+ function billingPeriod(options, index) {
62
+ if (!Number.isInteger(index) || index < 0) throw invalid$1(`Az időszak sorszáma nemnegatív egész legyen, kapott: ${index}`);
63
+ const { anchor, interval } = resolve(options);
64
+ const start = shift(anchor, interval, index);
65
+ const end = addDays(shift(anchor, interval, index + 1), -1);
66
+ const due = options.paymentDueInDays;
67
+ return {
68
+ index,
69
+ interval,
70
+ start,
71
+ end,
72
+ ...due === void 0 ? {} : { dueDate: addDays(start, due) },
73
+ key: `${interval}:${start}`
74
+ };
75
+ }
76
+ function billingPeriodAt(options, date) {
77
+ const { anchor, interval } = resolve(options);
78
+ let day;
79
+ try {
80
+ day = require_dates.toAgentDate(date);
81
+ } catch (error) {
82
+ throw invalid$1(error instanceof Error ? error.message : String(error));
83
+ }
84
+ if (day < anchor) throw invalid$1(`A(z) ${day} dátum korábbi, mint az első időszak kezdete (${anchor}).`);
85
+ const [anchorYear, anchorMonth] = parts(anchor);
86
+ const [year, month] = parts(day);
87
+ let index = interval === "week" ? Math.floor((Date.parse(`${day}T00:00:00Z`) - Date.parse(`${anchor}T00:00:00Z`)) / 6048e5) : Math.floor(((year - anchorYear) * 12 + (month - anchorMonth)) / MONTHS[interval]);
88
+ while (index > 0 && shift(anchor, interval, index) > day) index -= 1;
89
+ while (shift(anchor, interval, index + 1) <= day) index += 1;
90
+ return billingPeriod(options, index);
91
+ }
92
+ function billingPeriodsBetween(options, from, to) {
93
+ const first = billingPeriodAt(options, from);
94
+ const last = billingPeriodAt(options, to);
95
+ const periods = [];
96
+ for (let index = first.index; index <= last.index; index++) periods.push(billingPeriod(options, index));
97
+ return periods;
98
+ }
99
+ function todayPeriod(options, now = /* @__PURE__ */ new Date()) {
100
+ return billingPeriodAt(options, require_dates.addBudapestDays(now, 0));
101
+ }
102
+ //#endregion
103
+ //#region src/batch/run.ts
104
+ const MAX_BATCH_CONCURRENCY = 4;
105
+ const DEFAULT_BATCH_RATE_PER_MINUTE = 30;
106
+ const STOPPING_CATEGORIES = /* @__PURE__ */ new Set([
107
+ "rate_limit",
108
+ "auth",
109
+ "account",
110
+ "configuration",
111
+ "maintenance",
112
+ "attempt_limit",
113
+ "store_unavailable"
114
+ ]);
115
+ function invalid(message) {
116
+ return new require_errors.SzamlazzError(message, { category: "validation" });
117
+ }
118
+ function resolveConcurrency(value) {
119
+ if (value === void 0) return 1;
120
+ if (!Number.isInteger(value) || value < 1 || value > 4) throw new require_errors.SzamlazzError(`A concurrency 1 és 4 közötti egész legyen, kapott: ${value}. A Számlázz.hu a párhuzamos kérések kerülését kéri.`, { category: "configuration" });
121
+ return value;
122
+ }
123
+ function resolveRate(value) {
124
+ if (value === void 0) return 30;
125
+ if (!Number.isFinite(value) || value <= 0) throw new require_errors.SzamlazzError(`A ratePerMinute pozitív szám legyen, kapott: ${value}`, { category: "configuration" });
126
+ return value;
127
+ }
128
+ function assertKeys(items) {
129
+ const seen = /* @__PURE__ */ new Set();
130
+ for (const item of items) {
131
+ const key = item.key?.trim();
132
+ if (!key) throw invalid("Minden tételhez adj meg kulcsot (key), ez lesz a rendelésszám.");
133
+ if (seen.has(key)) throw invalid(`A(z) ${key} kulcs kétszer szerepel a listában.`);
134
+ seen.add(key);
135
+ }
136
+ }
137
+ function withOrderNumber(input, key) {
138
+ const own = input.orderNumber?.trim();
139
+ if (own && own !== key) throw invalid(`A(z) ${key} tétel rendelésszáma (${own}) eltér a kulcstól. A batch a kulcsot használja rendelésszámként, hogy az újrafuttatás ne állítson ki duplát.`);
140
+ return {
141
+ ...input,
142
+ orderNumber: key
143
+ };
144
+ }
145
+ function wait(ms, signal) {
146
+ if (ms <= 0) return Promise.resolve();
147
+ return new Promise((resolve, reject) => {
148
+ if (signal?.aborted) {
149
+ reject(signal.reason);
150
+ return;
151
+ }
152
+ const timer = setTimeout(() => {
153
+ signal?.removeEventListener("abort", onAbort);
154
+ resolve();
155
+ }, ms);
156
+ const onAbort = () => {
157
+ clearTimeout(timer);
158
+ reject(signal?.reason);
159
+ };
160
+ signal?.addEventListener("abort", onAbort, { once: true });
161
+ });
162
+ }
163
+ function invoiceGross(result) {
164
+ return result.invoice?.grossTotal ?? result.details?.totals.grossAmount;
165
+ }
166
+ async function previewDocument(api, document, key, signal) {
167
+ if (document.kind === "invoice") return {
168
+ key,
169
+ status: "previewed",
170
+ kind: "invoice",
171
+ grossTotal: (await api.invoices.preview(withOrderNumber(document.input, key), { signal })).grossTotal
172
+ };
173
+ const input = withOrderNumber(document.input, key);
174
+ if (input.items.length === 0) throw invalid(`A(z) ${key} nyugtán nincs tétel.`);
175
+ const gross = require_create.calculateReceiptItems(input.items, input.currency ?? "HUF").reduce((sum, item) => sum + item.amounts.grossAmount, 0);
176
+ return {
177
+ key,
178
+ status: "previewed",
179
+ kind: "receipt",
180
+ grossTotal: Math.round(gross * 100) / 100
181
+ };
182
+ }
183
+ async function issueDocument(api, document, key, options) {
184
+ const onceOptions = {
185
+ signal: options.signal,
186
+ recoveryDelayMs: options.recoveryDelayMs
187
+ };
188
+ if (document.kind === "invoice") {
189
+ const input = withOrderNumber(document.input, key);
190
+ const run = () => api.invoices.createOnce(input, onceOptions);
191
+ const result = options.journal ? await options.journal.trackInvoice(key, run) : await run();
192
+ return {
193
+ key,
194
+ status: result.created ? "created" : "existing",
195
+ kind: "invoice",
196
+ number: result.number,
197
+ grossTotal: invoiceGross(result)
198
+ };
199
+ }
200
+ const input = withOrderNumber(document.input, key);
201
+ const run = () => api.receipts.createOnce(input, onceOptions);
202
+ const result = options.journal ? await options.journal.trackReceipt(key, run) : await run();
203
+ return {
204
+ key,
205
+ status: result.created ? "created" : "existing",
206
+ kind: "receipt",
207
+ number: result.receipt.number,
208
+ grossTotal: result.receipt.totals.grossAmount
209
+ };
210
+ }
211
+ function stopReason(error) {
212
+ if (!require_errors.isSzamlazzError(error) || !STOPPING_CATEGORIES.has(error.category)) return void 0;
213
+ return `A(z) ${error.category} hiba miatt a batch leállt, a hátralévő tételek nem futottak le: ${error.message}`;
214
+ }
215
+ async function runBatch(api, options) {
216
+ const concurrency = resolveConcurrency(options.concurrency);
217
+ const intervalMs = 6e4 / resolveRate(options.ratePerMinute);
218
+ assertKeys(options.items);
219
+ const dryRun = options.dryRun === true;
220
+ const results = new Array(options.items.length);
221
+ const counts = {
222
+ created: 0,
223
+ existing: 0,
224
+ previewed: 0,
225
+ failed: 0,
226
+ skipped: 0
227
+ };
228
+ let done = 0;
229
+ let cursor = 0;
230
+ let nextStart = Date.now();
231
+ const control = { stopped: void 0 };
232
+ const currentStop = () => control.stopped;
233
+ const record = (index, result) => {
234
+ results[index] = result;
235
+ counts[result.status] += 1;
236
+ done += 1;
237
+ try {
238
+ options.onProgress?.({
239
+ total: options.items.length,
240
+ done,
241
+ ...counts,
242
+ key: result.key,
243
+ status: result.status
244
+ });
245
+ } catch {
246
+ return;
247
+ }
248
+ };
249
+ const processItem = async (index, item) => {
250
+ const key = item.key.trim();
251
+ try {
252
+ const document = await item.document();
253
+ const result = dryRun ? await previewDocument(api, document, key, options.signal) : await issueDocument(api, document, key, options);
254
+ record(index, result);
255
+ } catch (error) {
256
+ if (options.signal?.aborted && error === options.signal.reason) {
257
+ control.stopped ??= {
258
+ reason: "A batch futását megszakították.",
259
+ error
260
+ };
261
+ record(index, {
262
+ key,
263
+ status: "skipped",
264
+ reason: "Megszakítva."
265
+ });
266
+ return;
267
+ }
268
+ const reason = stopReason(error);
269
+ if (reason) control.stopped ??= {
270
+ reason,
271
+ error
272
+ };
273
+ record(index, {
274
+ key,
275
+ status: "failed",
276
+ error
277
+ });
278
+ }
279
+ };
280
+ const worker = async () => {
281
+ for (;;) {
282
+ if (control.stopped || options.signal?.aborted) return;
283
+ const index = cursor;
284
+ cursor += 1;
285
+ const item = options.items[index];
286
+ if (!item) return;
287
+ const delay = nextStart - Date.now();
288
+ nextStart = Math.max(nextStart, Date.now()) + intervalMs;
289
+ try {
290
+ await wait(delay, options.signal);
291
+ } catch (error) {
292
+ control.stopped ??= {
293
+ reason: "A batch futását megszakították.",
294
+ error
295
+ };
296
+ record(index, {
297
+ key: item.key.trim(),
298
+ status: "skipped",
299
+ reason: "Megszakítva."
300
+ });
301
+ return;
302
+ }
303
+ const stop = currentStop();
304
+ if (stop) {
305
+ record(index, {
306
+ key: item.key.trim(),
307
+ status: "skipped",
308
+ reason: stop.reason
309
+ });
310
+ return;
311
+ }
312
+ await processItem(index, item);
313
+ }
314
+ };
315
+ await Promise.all(Array.from({ length: Math.min(concurrency, options.items.length) }, worker));
316
+ if (options.signal?.aborted) control.stopped ??= { reason: "A batch futását megszakították." };
317
+ options.items.forEach((item, index) => {
318
+ if (results[index]) return;
319
+ record(index, {
320
+ key: item.key.trim(),
321
+ status: "skipped",
322
+ reason: control.stopped?.reason ?? "Nem futott le."
323
+ });
324
+ });
325
+ const by = (status) => results.filter((result) => result.status === status);
326
+ const grossTotal = results.filter((result) => result.status !== "failed" && result.status !== "skipped").reduce((sum, result) => sum + (result.grossTotal ?? 0), 0);
327
+ return {
328
+ dryRun,
329
+ items: results,
330
+ created: by("created"),
331
+ existing: by("existing"),
332
+ previewed: by("previewed"),
333
+ failed: by("failed"),
334
+ skipped: by("skipped"),
335
+ stopped: control.stopped,
336
+ grossTotal: Math.round(grossTotal * 100) / 100
337
+ };
338
+ }
339
+ //#endregion
340
+ exports.DEFAULT_BATCH_RATE_PER_MINUTE = DEFAULT_BATCH_RATE_PER_MINUTE;
341
+ exports.MAX_BATCH_CONCURRENCY = MAX_BATCH_CONCURRENCY;
342
+ exports.billingPeriod = billingPeriod;
343
+ exports.billingPeriodAt = billingPeriodAt;
344
+ exports.billingPeriodsBetween = billingPeriodsBetween;
345
+ exports.runBatch = runBatch;
346
+ exports.todayPeriod = todayPeriod;
@@ -0,0 +1,91 @@
1
+ import { t as DateInput } from "../dates-9zvESP0i.cjs";
2
+ import { M as CreateInvoiceInput } from "../context-CFNKzStE.cjs";
3
+ import { t as CreateReceiptInput } from "../types-lnKkQdot.cjs";
4
+ import { a as ReceiptsApi, t as InvoicesApi } from "../client-SVZu25MB.cjs";
5
+ import { n as Journal } from "../journal-DvI81Kt7.cjs";
6
+ //#region src/batch/recurring.d.ts
7
+ type BillingInterval = "week" | "month" | "quarter" | "year";
8
+ interface BillingPeriodOptions {
9
+ readonly interval: BillingInterval;
10
+ readonly anchor: DateInput;
11
+ readonly paymentDueInDays?: number | undefined;
12
+ }
13
+ interface BillingPeriod {
14
+ readonly index: number;
15
+ readonly interval: BillingInterval;
16
+ readonly start: string;
17
+ readonly end: string;
18
+ readonly dueDate?: string | undefined;
19
+ readonly key: string;
20
+ }
21
+ export declare function billingPeriod(options: BillingPeriodOptions, index: number): BillingPeriod;
22
+ export declare function billingPeriodAt(options: BillingPeriodOptions, date: DateInput): BillingPeriod;
23
+ export declare function billingPeriodsBetween(options: BillingPeriodOptions, from: DateInput, to: DateInput): BillingPeriod[];
24
+ export declare function todayPeriod(options: BillingPeriodOptions, now?: Date): BillingPeriod;
25
+ //#endregion
26
+ //#region src/batch/run.d.ts
27
+ export declare const MAX_BATCH_CONCURRENCY = 4;
28
+ export declare const DEFAULT_BATCH_RATE_PER_MINUTE = 30;
29
+ type BatchDocument = {
30
+ readonly kind: "invoice";
31
+ readonly input: CreateInvoiceInput;
32
+ } | {
33
+ readonly kind: "receipt";
34
+ readonly input: CreateReceiptInput;
35
+ };
36
+ interface BatchItem {
37
+ readonly key: string;
38
+ readonly document: () => BatchDocument | Promise<BatchDocument>;
39
+ }
40
+ interface BatchProgress {
41
+ readonly total: number;
42
+ readonly done: number;
43
+ readonly created: number;
44
+ readonly existing: number;
45
+ readonly previewed: number;
46
+ readonly failed: number;
47
+ readonly skipped: number;
48
+ readonly key: string;
49
+ readonly status: BatchItemStatus;
50
+ }
51
+ type BatchItemStatus = "created" | "existing" | "previewed" | "failed" | "skipped";
52
+ interface BatchItemResult {
53
+ readonly key: string;
54
+ readonly status: BatchItemStatus;
55
+ readonly kind?: "invoice" | "receipt" | undefined;
56
+ readonly number?: string | undefined;
57
+ readonly grossTotal?: number | undefined;
58
+ readonly error?: unknown;
59
+ readonly reason?: string | undefined;
60
+ }
61
+ interface BatchResult {
62
+ readonly dryRun: boolean;
63
+ readonly items: readonly BatchItemResult[];
64
+ readonly created: readonly BatchItemResult[];
65
+ readonly existing: readonly BatchItemResult[];
66
+ readonly previewed: readonly BatchItemResult[];
67
+ readonly failed: readonly BatchItemResult[];
68
+ readonly skipped: readonly BatchItemResult[];
69
+ readonly stopped?: {
70
+ readonly reason: string;
71
+ readonly error?: unknown;
72
+ } | undefined;
73
+ readonly grossTotal: number;
74
+ }
75
+ interface BatchApi {
76
+ readonly invoices: Pick<InvoicesApi, "createOnce" | "preview">;
77
+ readonly receipts: Pick<ReceiptsApi, "createOnce">;
78
+ }
79
+ interface RunBatchOptions {
80
+ readonly items: readonly BatchItem[];
81
+ readonly concurrency?: number | undefined;
82
+ readonly ratePerMinute?: number | undefined;
83
+ readonly dryRun?: boolean | undefined;
84
+ readonly journal?: Journal | undefined;
85
+ readonly signal?: AbortSignal | undefined;
86
+ readonly onProgress?: ((progress: BatchProgress) => void) | undefined;
87
+ readonly recoveryDelayMs?: number | undefined;
88
+ }
89
+ export declare function runBatch(api: BatchApi, options: RunBatchOptions): Promise<BatchResult>;
90
+ //#endregion
91
+ export type { BatchApi, BatchDocument, BatchItem, BatchItemResult, BatchItemStatus, BatchProgress, BatchResult, BillingInterval, BillingPeriod, BillingPeriodOptions, RunBatchOptions };
@@ -0,0 +1,91 @@
1
+ import { t as DateInput } from "../dates-9zvESP0i.js";
2
+ import { M as CreateInvoiceInput } from "../context-kb33TgzE.js";
3
+ import { t as CreateReceiptInput } from "../types-D1zDOH_F.js";
4
+ import { a as ReceiptsApi, t as InvoicesApi } from "../client-DeWWQ-RZ.js";
5
+ import { n as Journal } from "../journal-Y9qrIB8G.js";
6
+ //#region src/batch/recurring.d.ts
7
+ type BillingInterval = "week" | "month" | "quarter" | "year";
8
+ interface BillingPeriodOptions {
9
+ readonly interval: BillingInterval;
10
+ readonly anchor: DateInput;
11
+ readonly paymentDueInDays?: number | undefined;
12
+ }
13
+ interface BillingPeriod {
14
+ readonly index: number;
15
+ readonly interval: BillingInterval;
16
+ readonly start: string;
17
+ readonly end: string;
18
+ readonly dueDate?: string | undefined;
19
+ readonly key: string;
20
+ }
21
+ export declare function billingPeriod(options: BillingPeriodOptions, index: number): BillingPeriod;
22
+ export declare function billingPeriodAt(options: BillingPeriodOptions, date: DateInput): BillingPeriod;
23
+ export declare function billingPeriodsBetween(options: BillingPeriodOptions, from: DateInput, to: DateInput): BillingPeriod[];
24
+ export declare function todayPeriod(options: BillingPeriodOptions, now?: Date): BillingPeriod;
25
+ //#endregion
26
+ //#region src/batch/run.d.ts
27
+ export declare const MAX_BATCH_CONCURRENCY = 4;
28
+ export declare const DEFAULT_BATCH_RATE_PER_MINUTE = 30;
29
+ type BatchDocument = {
30
+ readonly kind: "invoice";
31
+ readonly input: CreateInvoiceInput;
32
+ } | {
33
+ readonly kind: "receipt";
34
+ readonly input: CreateReceiptInput;
35
+ };
36
+ interface BatchItem {
37
+ readonly key: string;
38
+ readonly document: () => BatchDocument | Promise<BatchDocument>;
39
+ }
40
+ interface BatchProgress {
41
+ readonly total: number;
42
+ readonly done: number;
43
+ readonly created: number;
44
+ readonly existing: number;
45
+ readonly previewed: number;
46
+ readonly failed: number;
47
+ readonly skipped: number;
48
+ readonly key: string;
49
+ readonly status: BatchItemStatus;
50
+ }
51
+ type BatchItemStatus = "created" | "existing" | "previewed" | "failed" | "skipped";
52
+ interface BatchItemResult {
53
+ readonly key: string;
54
+ readonly status: BatchItemStatus;
55
+ readonly kind?: "invoice" | "receipt" | undefined;
56
+ readonly number?: string | undefined;
57
+ readonly grossTotal?: number | undefined;
58
+ readonly error?: unknown;
59
+ readonly reason?: string | undefined;
60
+ }
61
+ interface BatchResult {
62
+ readonly dryRun: boolean;
63
+ readonly items: readonly BatchItemResult[];
64
+ readonly created: readonly BatchItemResult[];
65
+ readonly existing: readonly BatchItemResult[];
66
+ readonly previewed: readonly BatchItemResult[];
67
+ readonly failed: readonly BatchItemResult[];
68
+ readonly skipped: readonly BatchItemResult[];
69
+ readonly stopped?: {
70
+ readonly reason: string;
71
+ readonly error?: unknown;
72
+ } | undefined;
73
+ readonly grossTotal: number;
74
+ }
75
+ interface BatchApi {
76
+ readonly invoices: Pick<InvoicesApi, "createOnce" | "preview">;
77
+ readonly receipts: Pick<ReceiptsApi, "createOnce">;
78
+ }
79
+ interface RunBatchOptions {
80
+ readonly items: readonly BatchItem[];
81
+ readonly concurrency?: number | undefined;
82
+ readonly ratePerMinute?: number | undefined;
83
+ readonly dryRun?: boolean | undefined;
84
+ readonly journal?: Journal | undefined;
85
+ readonly signal?: AbortSignal | undefined;
86
+ readonly onProgress?: ((progress: BatchProgress) => void) | undefined;
87
+ readonly recoveryDelayMs?: number | undefined;
88
+ }
89
+ export declare function runBatch(api: BatchApi, options: RunBatchOptions): Promise<BatchResult>;
90
+ //#endregion
91
+ export type { BatchApi, BatchDocument, BatchItem, BatchItemResult, BatchItemStatus, BatchProgress, BatchResult, BillingInterval, BillingPeriod, BillingPeriodOptions, RunBatchOptions };