kassza 0.1.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.
- package/LICENSE +21 -0
- package/README.md +150 -0
- package/agents/README.md +59 -0
- package/agents/api.md +206 -0
- package/agents/pitfalls.md +52 -0
- package/agents/recipes.md +217 -0
- package/agents/skills/kassza/SKILL.md +29 -0
- package/assets/logo-wordmark.svg +25 -0
- package/assets/logo.svg +19 -0
- package/dist/binary-B89HM03_.cjs +63 -0
- package/dist/binary-D0M9U2MD.js +34 -0
- package/dist/client-B9kbKKBf.d.cts +748 -0
- package/dist/client-zv4enyq7.d.ts +748 -0
- package/dist/cookie-stores/index.cjs +153 -0
- package/dist/cookie-stores/index.d.cts +63 -0
- package/dist/cookie-stores/index.d.ts +63 -0
- package/dist/cookie-stores/index.js +144 -0
- package/dist/create-BZd6CUO7.cjs +1160 -0
- package/dist/create-DDZaNlOz.js +939 -0
- package/dist/dates-D2XebOIg.js +34 -0
- package/dist/dates-DtHzwNU6.d.cts +7 -0
- package/dist/dates-DtHzwNU6.d.ts +7 -0
- package/dist/dates-PPxH0n5H.cjs +57 -0
- package/dist/errors-B0QJhUW1.cjs +302 -0
- package/dist/errors-DapdV5DK.js +273 -0
- package/dist/index-CYAGCdKJ.d.cts +56 -0
- package/dist/index-CYAGCdKJ.d.ts +56 -0
- package/dist/index.cjs +1406 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1394 -0
- package/dist/ipn/index.cjs +108 -0
- package/dist/ipn/index.d.cts +32 -0
- package/dist/ipn/index.d.ts +32 -0
- package/dist/ipn/index.js +101 -0
- package/dist/money/index.cjs +15 -0
- package/dist/money/index.d.cts +2 -0
- package/dist/money/index.d.ts +2 -0
- package/dist/money/index.js +2 -0
- package/dist/money-C9j7nBNP.js +258 -0
- package/dist/money-DkiGukAw.cjs +335 -0
- package/dist/session-CRGOuz-R.cjs +100 -0
- package/dist/session-Dm_45x8K.d.cts +11 -0
- package/dist/session-Dm_45x8K.d.ts +11 -0
- package/dist/session-OJMLGufT.js +77 -0
- package/dist/shared-CrxlxI8n.cjs +207 -0
- package/dist/shared-D6DLa4b7.js +100 -0
- package/dist/storage/fs.cjs +88 -0
- package/dist/storage/fs.d.cts +13 -0
- package/dist/storage/fs.d.ts +13 -0
- package/dist/storage/fs.js +87 -0
- package/dist/storage/index.cjs +643 -0
- package/dist/storage/index.d.cts +288 -0
- package/dist/storage/index.d.ts +288 -0
- package/dist/storage/index.js +619 -0
- package/dist/testing/index.cjs +409 -0
- package/dist/testing/index.d.cts +35 -0
- package/dist/testing/index.d.ts +35 -0
- package/dist/testing/index.js +407 -0
- package/dist/types-DVRgwcqg.d.cts +26 -0
- package/dist/types-DVRgwcqg.d.ts +26 -0
- package/dist/validators/index.cjs +296 -0
- package/dist/validators/index.d.cts +51 -0
- package/dist/validators/index.d.ts +51 -0
- package/dist/validators/index.js +278 -0
- package/llms.txt +16 -0
- package/package.json +151 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_create = require("../create-BZd6CUO7.cjs");
|
|
3
|
+
const require_errors = require("../errors-B0QJhUW1.cjs");
|
|
4
|
+
const require_dates = require("../dates-PPxH0n5H.cjs");
|
|
5
|
+
const require_money = require("../money-DkiGukAw.cjs");
|
|
6
|
+
//#region src/testing/index.ts
|
|
7
|
+
const MOCK_PDF = new TextEncoder().encode("%PDF-1.4\n1 0 obj << /Type /Catalog >> endobj\ntrailer << /Root 1 0 R >>\n%%EOF\n");
|
|
8
|
+
function notFound(code, message) {
|
|
9
|
+
return new require_errors.SzamlazzError(`[${code}] ${message}`, {
|
|
10
|
+
category: "not_found",
|
|
11
|
+
code
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function invoiceTypeCode(type) {
|
|
15
|
+
return {
|
|
16
|
+
invoice: "SZ",
|
|
17
|
+
proforma: "D",
|
|
18
|
+
advance: "E",
|
|
19
|
+
final: "V",
|
|
20
|
+
corrective: "H",
|
|
21
|
+
deliveryNote: "SZL",
|
|
22
|
+
reversal: "SS"
|
|
23
|
+
}[type];
|
|
24
|
+
}
|
|
25
|
+
function referenceMatches(record, reference) {
|
|
26
|
+
if (typeof reference === "string") return record.number === reference;
|
|
27
|
+
if ("invoiceNumber" in reference) return record.number === reference.invoiceNumber;
|
|
28
|
+
if ("orderNumber" in reference) return record.input?.orderNumber === reference.orderNumber;
|
|
29
|
+
return record.input?.externalId === reference.externalId;
|
|
30
|
+
}
|
|
31
|
+
function normalizePayments(input, today) {
|
|
32
|
+
if ("payments" in input) return [...input.payments];
|
|
33
|
+
return [{
|
|
34
|
+
amount: input.amount,
|
|
35
|
+
method: input.method ?? "átutalás",
|
|
36
|
+
date: input.date ?? today,
|
|
37
|
+
description: input.description
|
|
38
|
+
}];
|
|
39
|
+
}
|
|
40
|
+
function createMockKassza(options = {}) {
|
|
41
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
42
|
+
const calls = [];
|
|
43
|
+
const failures = /* @__PURE__ */ new Map();
|
|
44
|
+
const invoices = /* @__PURE__ */ new Map();
|
|
45
|
+
const receipts = /* @__PURE__ */ new Map();
|
|
46
|
+
const sequences = /* @__PURE__ */ new Map();
|
|
47
|
+
let receiptId = 0;
|
|
48
|
+
const nextNumber = (prefix) => {
|
|
49
|
+
const key = `${prefix}-${require_dates.toAgentDate(now()).slice(0, 4)}`;
|
|
50
|
+
const next = (sequences.get(key) ?? 0) + 1;
|
|
51
|
+
sequences.set(key, next);
|
|
52
|
+
return `${key}-${next}`;
|
|
53
|
+
};
|
|
54
|
+
const record = (method, args) => {
|
|
55
|
+
calls.push({
|
|
56
|
+
method,
|
|
57
|
+
args
|
|
58
|
+
});
|
|
59
|
+
const failure = failures.get(method);
|
|
60
|
+
if (failure) {
|
|
61
|
+
failures.delete(method);
|
|
62
|
+
throw failure;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const findInvoice = (reference) => {
|
|
66
|
+
const found = [...invoices.values()].filter((candidate) => !candidate.deleted && referenceMatches(candidate, reference)).at(-1);
|
|
67
|
+
if (!found) throw notFound(7, "Hiányzó adat: ismeretlen számlaszám, rendelésszám vagy külső azonosító.");
|
|
68
|
+
return found;
|
|
69
|
+
};
|
|
70
|
+
const detailsOf = (found, includePdf) => ({
|
|
71
|
+
...found.details,
|
|
72
|
+
header: {
|
|
73
|
+
...found.details.header,
|
|
74
|
+
reversed: found.reversed
|
|
75
|
+
},
|
|
76
|
+
payments: [...found.payments],
|
|
77
|
+
...includePdf ? { pdf: MOCK_PDF } : {}
|
|
78
|
+
});
|
|
79
|
+
const findReceipt = (key) => {
|
|
80
|
+
const entries = [...receipts.values()];
|
|
81
|
+
const found = typeof key === "string" ? receipts.get(key) : entries.findLast((entry) => key.receiptNumber !== void 0 && entry.receipt.number === key.receiptNumber || key.orderNumber !== void 0 && entry.receipt.orderNumber === key.orderNumber);
|
|
82
|
+
if (!found) throw notFound(339, "A nyugtaszám nem létezik.");
|
|
83
|
+
return found;
|
|
84
|
+
};
|
|
85
|
+
const createInvoiceRecord = (input) => {
|
|
86
|
+
const resolved = require_create.resolveInvoice(options.defaults?.invoice ?? {}, input, now());
|
|
87
|
+
const items = resolved.items.map((item) => item.amounts);
|
|
88
|
+
const totals = require_money.summarizeItems(items);
|
|
89
|
+
const typePrefix = resolved.type === "proforma" ? "D" : "E";
|
|
90
|
+
const number = nextNumber(resolved.prefix ? `${typePrefix}-${resolved.prefix}` : `${typePrefix}-KASSZA`);
|
|
91
|
+
const details = {
|
|
92
|
+
seller: { name: "Kassza Teszt Kft." },
|
|
93
|
+
header: {
|
|
94
|
+
number,
|
|
95
|
+
type: resolved.type,
|
|
96
|
+
typeCode: invoiceTypeCode(resolved.type),
|
|
97
|
+
eInvoice: resolved.eInvoice,
|
|
98
|
+
issueDate: resolved.issueDate,
|
|
99
|
+
fulfillmentDate: resolved.fulfillmentDate,
|
|
100
|
+
dueDate: resolved.dueDate,
|
|
101
|
+
paymentMethod: resolved.paymentMethod,
|
|
102
|
+
orderNumber: input.orderNumber,
|
|
103
|
+
language: resolved.language,
|
|
104
|
+
currency: resolved.currency,
|
|
105
|
+
comment: input.comment,
|
|
106
|
+
test: true
|
|
107
|
+
},
|
|
108
|
+
buyer: {
|
|
109
|
+
name: input.buyer.name,
|
|
110
|
+
email: input.buyer.email,
|
|
111
|
+
taxNumber: input.buyer.taxNumber,
|
|
112
|
+
address: {
|
|
113
|
+
country: input.buyer.country,
|
|
114
|
+
zip: input.buyer.zip,
|
|
115
|
+
city: input.buyer.city,
|
|
116
|
+
address: input.buyer.address
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
items: resolved.items.map((item) => ({
|
|
120
|
+
name: item.amounts.name,
|
|
121
|
+
quantity: item.amounts.quantity,
|
|
122
|
+
unit: item.unit,
|
|
123
|
+
netUnitPrice: item.amounts.netUnitPrice,
|
|
124
|
+
vat: typeof item.amounts.vat === "number" ? item.amounts.vat : 0,
|
|
125
|
+
vatCode: typeof item.amounts.vat === "number" ? void 0 : item.amounts.vat,
|
|
126
|
+
netAmount: item.amounts.netAmount,
|
|
127
|
+
vatAmount: item.amounts.vatAmount,
|
|
128
|
+
grossAmount: item.amounts.grossAmount,
|
|
129
|
+
comment: item.input.comment
|
|
130
|
+
})),
|
|
131
|
+
financialItems: [],
|
|
132
|
+
labels: [],
|
|
133
|
+
totals: {
|
|
134
|
+
netAmount: totals.netAmount,
|
|
135
|
+
vatAmount: totals.vatAmount,
|
|
136
|
+
grossAmount: totals.grossAmount,
|
|
137
|
+
byVat: totals.byVat.map((bucket) => ({
|
|
138
|
+
vat: typeof bucket.vat === "number" ? bucket.vat : 0,
|
|
139
|
+
vatCode: typeof bucket.vat === "number" ? void 0 : bucket.vat,
|
|
140
|
+
netAmount: bucket.netAmount,
|
|
141
|
+
vatAmount: bucket.vatAmount,
|
|
142
|
+
grossAmount: bucket.grossAmount
|
|
143
|
+
}))
|
|
144
|
+
},
|
|
145
|
+
payments: []
|
|
146
|
+
};
|
|
147
|
+
const paid = input.paid ? [{
|
|
148
|
+
date: resolved.issueDate,
|
|
149
|
+
method: resolved.paymentMethod,
|
|
150
|
+
amount: totals.grossAmount
|
|
151
|
+
}] : [];
|
|
152
|
+
invoices.set(number, {
|
|
153
|
+
number,
|
|
154
|
+
type: resolved.type,
|
|
155
|
+
input,
|
|
156
|
+
details,
|
|
157
|
+
payments: paid,
|
|
158
|
+
reversed: false,
|
|
159
|
+
deleted: false
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
number,
|
|
163
|
+
netTotal: totals.netAmount,
|
|
164
|
+
grossTotal: totals.grossAmount,
|
|
165
|
+
outstanding: input.paid ? 0 : totals.grossAmount,
|
|
166
|
+
items,
|
|
167
|
+
...resolved.downloadPdf ? { pdf: MOCK_PDF } : {}
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
const createReceiptRecord = (input, callId) => {
|
|
171
|
+
const defaults = options.defaults?.receipt ?? {};
|
|
172
|
+
require_create.buildCreateReceiptXml([], defaults, input);
|
|
173
|
+
if (callId !== void 0 && [...receipts.values()].some((entry) => entry.receipt.callId === callId)) throw new require_errors.SzamlazzError("[338] A hívásazonosító már létezik.", {
|
|
174
|
+
category: "duplicate",
|
|
175
|
+
code: 338
|
|
176
|
+
});
|
|
177
|
+
const currency = input.currency ?? defaults.currency ?? "HUF";
|
|
178
|
+
const calculated = require_create.calculateReceiptItems(input.items, currency);
|
|
179
|
+
const totals = require_money.summarizeItems(calculated.map((item) => item.amounts));
|
|
180
|
+
const prefix = (input.prefix ?? defaults.prefix ?? "NY").trim();
|
|
181
|
+
const paymentMethod = (input.paymentMethod ?? defaults.paymentMethod ?? "").trim();
|
|
182
|
+
receiptId += 1;
|
|
183
|
+
const receipt = {
|
|
184
|
+
id: receiptId,
|
|
185
|
+
number: nextNumber(prefix),
|
|
186
|
+
callId,
|
|
187
|
+
type: "receipt",
|
|
188
|
+
isReversed: false,
|
|
189
|
+
issueDate: require_dates.toAgentDate(now()),
|
|
190
|
+
paymentMethod,
|
|
191
|
+
currency,
|
|
192
|
+
comment: input.comment,
|
|
193
|
+
isTest: true,
|
|
194
|
+
orderNumber: input.orderNumber,
|
|
195
|
+
items: calculated.map((item) => ({
|
|
196
|
+
name: item.input.name,
|
|
197
|
+
quantity: item.amounts.quantity,
|
|
198
|
+
unit: item.input.unit ?? defaults.unit ?? "db",
|
|
199
|
+
netUnitPrice: item.amounts.netUnitPrice,
|
|
200
|
+
vat: item.vat,
|
|
201
|
+
vatPercentage: typeof item.vat === "number" ? item.vat : 0,
|
|
202
|
+
netAmount: item.amounts.netAmount,
|
|
203
|
+
vatAmount: item.amounts.vatAmount,
|
|
204
|
+
grossAmount: item.amounts.grossAmount
|
|
205
|
+
})),
|
|
206
|
+
payments: (input.payments ?? []).map((payment) => ({ ...payment })),
|
|
207
|
+
totals: {
|
|
208
|
+
netAmount: totals.netAmount,
|
|
209
|
+
vatAmount: totals.vatAmount,
|
|
210
|
+
grossAmount: totals.grossAmount,
|
|
211
|
+
byVat: totals.byVat.map((bucket) => ({
|
|
212
|
+
vat: bucket.vat,
|
|
213
|
+
vatPercentage: typeof bucket.vat === "number" ? bucket.vat : 0,
|
|
214
|
+
netAmount: bucket.netAmount,
|
|
215
|
+
vatAmount: bucket.vatAmount,
|
|
216
|
+
grossAmount: bucket.grossAmount
|
|
217
|
+
}))
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
receipts.set(receipt.number, {
|
|
221
|
+
receipt,
|
|
222
|
+
sentTo: []
|
|
223
|
+
});
|
|
224
|
+
return input.downloadPdf ?? defaults.downloadPdf ?? true ? {
|
|
225
|
+
...receipt,
|
|
226
|
+
pdf: MOCK_PDF
|
|
227
|
+
} : receipt;
|
|
228
|
+
};
|
|
229
|
+
const run = async (method, args, fn) => {
|
|
230
|
+
record(method, args);
|
|
231
|
+
return fn();
|
|
232
|
+
};
|
|
233
|
+
const nullIfMissing = async (promise) => {
|
|
234
|
+
try {
|
|
235
|
+
return await promise;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (error instanceof require_errors.SzamlazzError && error.isNotFound) return null;
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const getInvoice = (reference, includePdf) => run("invoices.get", [reference], () => detailsOf(findInvoice(reference), includePdf ?? false));
|
|
242
|
+
const getReceipt = (input) => run("receipts.get", [input], () => {
|
|
243
|
+
const found = findReceipt(input);
|
|
244
|
+
return (typeof input === "string" ? true : input.downloadPdf ?? true) ? {
|
|
245
|
+
...found.receipt,
|
|
246
|
+
pdf: MOCK_PDF
|
|
247
|
+
} : found.receipt;
|
|
248
|
+
});
|
|
249
|
+
return {
|
|
250
|
+
calls,
|
|
251
|
+
invoiceRecords: invoices,
|
|
252
|
+
receiptRecords: receipts,
|
|
253
|
+
failNext(method, error) {
|
|
254
|
+
failures.set(method, error ?? new require_errors.SzamlazzError("Hálózati hiba a Számlázz.hu elérésekor.", { category: "network" }));
|
|
255
|
+
},
|
|
256
|
+
reset() {
|
|
257
|
+
calls.length = 0;
|
|
258
|
+
failures.clear();
|
|
259
|
+
invoices.clear();
|
|
260
|
+
receipts.clear();
|
|
261
|
+
sequences.clear();
|
|
262
|
+
receiptId = 0;
|
|
263
|
+
},
|
|
264
|
+
invoices: {
|
|
265
|
+
create: (input) => run("invoices.create", [input], () => createInvoiceRecord(input)),
|
|
266
|
+
preview: (input) => run("invoices.preview", [input], () => {
|
|
267
|
+
const items = require_create.resolveInvoice(options.defaults?.invoice ?? {}, input, now()).items.map((item) => item.amounts);
|
|
268
|
+
const totals = require_money.summarizeItems(items);
|
|
269
|
+
return {
|
|
270
|
+
pdf: MOCK_PDF,
|
|
271
|
+
netTotal: totals.netAmount,
|
|
272
|
+
grossTotal: totals.grossAmount,
|
|
273
|
+
items
|
|
274
|
+
};
|
|
275
|
+
}),
|
|
276
|
+
reverse: (input) => run("invoices.reverse", [input], () => {
|
|
277
|
+
const invoiceNumber = typeof input === "string" ? input : input.invoiceNumber;
|
|
278
|
+
const original = findInvoice(invoiceNumber);
|
|
279
|
+
original.reversed = true;
|
|
280
|
+
const number = nextNumber("E-STORNO");
|
|
281
|
+
const totals = original.details.totals;
|
|
282
|
+
invoices.set(number, {
|
|
283
|
+
number,
|
|
284
|
+
type: "reversal",
|
|
285
|
+
input: void 0,
|
|
286
|
+
details: {
|
|
287
|
+
...original.details,
|
|
288
|
+
header: {
|
|
289
|
+
...original.details.header,
|
|
290
|
+
number,
|
|
291
|
+
type: "reversal",
|
|
292
|
+
typeCode: "SS",
|
|
293
|
+
referencedInvoiceNumber: invoiceNumber
|
|
294
|
+
},
|
|
295
|
+
totals: {
|
|
296
|
+
netAmount: -totals.netAmount,
|
|
297
|
+
vatAmount: -totals.vatAmount,
|
|
298
|
+
grossAmount: -totals.grossAmount,
|
|
299
|
+
byVat: []
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
payments: [],
|
|
303
|
+
reversed: false,
|
|
304
|
+
deleted: false
|
|
305
|
+
});
|
|
306
|
+
const downloadPdf = typeof input === "string" || (input.downloadPdf ?? true);
|
|
307
|
+
return {
|
|
308
|
+
number,
|
|
309
|
+
netTotal: -totals.netAmount,
|
|
310
|
+
grossTotal: -totals.grossAmount,
|
|
311
|
+
...downloadPdf ? { pdf: MOCK_PDF } : {}
|
|
312
|
+
};
|
|
313
|
+
}),
|
|
314
|
+
registerPayment: (input) => run("invoices.registerPayment", [input], () => {
|
|
315
|
+
const found = findInvoice(input.invoiceNumber);
|
|
316
|
+
const today = require_dates.toAgentDate(now());
|
|
317
|
+
const entries = normalizePayments(input, today).map((entry) => ({
|
|
318
|
+
date: require_dates.toAgentDate(entry.date ?? today),
|
|
319
|
+
method: entry.method,
|
|
320
|
+
amount: entry.amount,
|
|
321
|
+
comment: entry.description
|
|
322
|
+
}));
|
|
323
|
+
found.payments = input.additive === false ? entries : [...found.payments, ...entries];
|
|
324
|
+
const paid = found.payments.reduce((sum, payment) => sum + payment.amount, 0);
|
|
325
|
+
return {
|
|
326
|
+
invoiceNumber: found.number,
|
|
327
|
+
netTotal: found.details.totals.netAmount,
|
|
328
|
+
grossTotal: found.details.totals.grossAmount,
|
|
329
|
+
outstanding: Math.max(0, found.details.totals.grossAmount - paid)
|
|
330
|
+
};
|
|
331
|
+
}),
|
|
332
|
+
clearPayments: (input) => run("invoices.clearPayments", [input], () => {
|
|
333
|
+
const found = findInvoice(typeof input === "string" ? input : input.invoiceNumber);
|
|
334
|
+
found.payments = [];
|
|
335
|
+
return {
|
|
336
|
+
invoiceNumber: found.number,
|
|
337
|
+
netTotal: found.details.totals.netAmount,
|
|
338
|
+
grossTotal: found.details.totals.grossAmount,
|
|
339
|
+
outstanding: found.details.totals.grossAmount
|
|
340
|
+
};
|
|
341
|
+
}),
|
|
342
|
+
getPdf: (reference) => run("invoices.getPdf", [reference], () => {
|
|
343
|
+
const found = findInvoice(reference);
|
|
344
|
+
return {
|
|
345
|
+
pdf: MOCK_PDF,
|
|
346
|
+
number: found.number,
|
|
347
|
+
netTotal: found.details.totals.netAmount,
|
|
348
|
+
grossTotal: found.details.totals.grossAmount
|
|
349
|
+
};
|
|
350
|
+
}),
|
|
351
|
+
get: (reference, query) => getInvoice(reference, query?.includePdf),
|
|
352
|
+
find: (reference, query) => nullIfMissing(getInvoice(reference, query?.includePdf)),
|
|
353
|
+
deleteProforma: (reference) => run("invoices.deleteProforma", [reference], () => {
|
|
354
|
+
const target = typeof reference === "string" ? reference : "proformaNumber" in reference ? reference.proformaNumber : { orderNumber: reference.orderNumber };
|
|
355
|
+
const proforma = [...invoices.values()].filter((candidate) => candidate.type === "proforma" && !candidate.deleted).findLast((candidate) => referenceMatches(candidate, target));
|
|
356
|
+
if (!proforma) throw notFound(335, "A hivatkozott díjbekérő nem található.");
|
|
357
|
+
proforma.deleted = true;
|
|
358
|
+
})
|
|
359
|
+
},
|
|
360
|
+
receipts: {
|
|
361
|
+
create: (input) => run("receipts.create", [input], () => createReceiptRecord(input, input.callId)),
|
|
362
|
+
reverse: (input) => run("receipts.reverse", [input], () => {
|
|
363
|
+
const receiptNumber = typeof input === "string" ? input : input.receiptNumber;
|
|
364
|
+
const original = findReceipt(receiptNumber);
|
|
365
|
+
original.receipt = {
|
|
366
|
+
...original.receipt,
|
|
367
|
+
isReversed: true
|
|
368
|
+
};
|
|
369
|
+
receiptId += 1;
|
|
370
|
+
const reversal = {
|
|
371
|
+
...original.receipt,
|
|
372
|
+
id: receiptId,
|
|
373
|
+
number: nextNumber(`${original.receipt.number.split("-")[0] ?? "NY"}-STORNO`),
|
|
374
|
+
type: "reversal",
|
|
375
|
+
isReversed: false,
|
|
376
|
+
reversedReceiptNumber: receiptNumber,
|
|
377
|
+
issueDate: require_dates.toAgentDate(now())
|
|
378
|
+
};
|
|
379
|
+
receipts.set(reversal.number, {
|
|
380
|
+
receipt: reversal,
|
|
381
|
+
sentTo: []
|
|
382
|
+
});
|
|
383
|
+
return {
|
|
384
|
+
...reversal,
|
|
385
|
+
pdf: MOCK_PDF
|
|
386
|
+
};
|
|
387
|
+
}),
|
|
388
|
+
get: getReceipt,
|
|
389
|
+
find: (input, requestOptions) => nullIfMissing(getReceipt(input, requestOptions)),
|
|
390
|
+
send: (input) => run("receipts.send", [input], () => {
|
|
391
|
+
const found = findReceipt(input.receiptNumber);
|
|
392
|
+
const emails = typeof input.emails === "string" ? input.emails.split(/[,;]/) : [...input.emails];
|
|
393
|
+
found.sentTo.push(emails.map((email) => email.trim()).filter(Boolean));
|
|
394
|
+
})
|
|
395
|
+
},
|
|
396
|
+
taxpayer: { query: (taxNumber) => run("taxpayer.query", [taxNumber], () => {
|
|
397
|
+
const taxpayerId = taxNumber.replace(/\D/g, "").slice(0, 8);
|
|
398
|
+
return options.taxpayers?.[taxpayerId] ?? {
|
|
399
|
+
valid: false,
|
|
400
|
+
addresses: []
|
|
401
|
+
};
|
|
402
|
+
}) },
|
|
403
|
+
verifyCredentials: () => run("verifyCredentials", [], () => options.credentialsValid ?? true),
|
|
404
|
+
resetSession: () => run("resetSession", [], () => void 0)
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
//#endregion
|
|
408
|
+
exports.MOCK_PDF = MOCK_PDF;
|
|
409
|
+
exports.createMockKassza = createMockKassza;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Ct as SzamlazzError, K as CreateInvoiceInput, P as InvoiceDetails, R as InvoiceDetailsPayment, at as InvoiceType, c as TaxpayerInfo, n as Kassza, p as Receipt, r as KasszaDefaults } from "../client-B9kbKKBf.cjs";
|
|
2
|
+
//#region src/testing/index.d.ts
|
|
3
|
+
export declare const MOCK_PDF: Uint8Array;
|
|
4
|
+
export interface MockInvoiceRecord {
|
|
5
|
+
readonly number: string;
|
|
6
|
+
readonly type: InvoiceType | "reversal";
|
|
7
|
+
readonly input: CreateInvoiceInput | undefined;
|
|
8
|
+
readonly details: InvoiceDetails;
|
|
9
|
+
payments: InvoiceDetailsPayment[];
|
|
10
|
+
reversed: boolean;
|
|
11
|
+
deleted: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface MockReceiptRecord {
|
|
14
|
+
receipt: Receipt;
|
|
15
|
+
readonly sentTo: string[][];
|
|
16
|
+
}
|
|
17
|
+
export interface MockCall {
|
|
18
|
+
readonly method: string;
|
|
19
|
+
readonly args: readonly unknown[];
|
|
20
|
+
}
|
|
21
|
+
export interface MockKasszaOptions {
|
|
22
|
+
readonly defaults?: KasszaDefaults;
|
|
23
|
+
readonly taxpayers?: Readonly<Record<string, TaxpayerInfo>>;
|
|
24
|
+
readonly credentialsValid?: boolean;
|
|
25
|
+
readonly now?: () => Date;
|
|
26
|
+
}
|
|
27
|
+
export interface MockKassza extends Kassza {
|
|
28
|
+
readonly calls: readonly MockCall[];
|
|
29
|
+
readonly invoiceRecords: ReadonlyMap<string, MockInvoiceRecord>;
|
|
30
|
+
readonly receiptRecords: ReadonlyMap<string, MockReceiptRecord>;
|
|
31
|
+
failNext(method: string, error?: SzamlazzError): void;
|
|
32
|
+
reset(): void;
|
|
33
|
+
}
|
|
34
|
+
export declare function createMockKassza(options?: MockKasszaOptions): MockKassza;
|
|
35
|
+
//#endregion
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Ct as SzamlazzError, K as CreateInvoiceInput, P as InvoiceDetails, R as InvoiceDetailsPayment, at as InvoiceType, c as TaxpayerInfo, n as Kassza, p as Receipt, r as KasszaDefaults } from "../client-zv4enyq7.js";
|
|
2
|
+
//#region src/testing/index.d.ts
|
|
3
|
+
export declare const MOCK_PDF: Uint8Array;
|
|
4
|
+
export interface MockInvoiceRecord {
|
|
5
|
+
readonly number: string;
|
|
6
|
+
readonly type: InvoiceType | "reversal";
|
|
7
|
+
readonly input: CreateInvoiceInput | undefined;
|
|
8
|
+
readonly details: InvoiceDetails;
|
|
9
|
+
payments: InvoiceDetailsPayment[];
|
|
10
|
+
reversed: boolean;
|
|
11
|
+
deleted: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface MockReceiptRecord {
|
|
14
|
+
receipt: Receipt;
|
|
15
|
+
readonly sentTo: string[][];
|
|
16
|
+
}
|
|
17
|
+
export interface MockCall {
|
|
18
|
+
readonly method: string;
|
|
19
|
+
readonly args: readonly unknown[];
|
|
20
|
+
}
|
|
21
|
+
export interface MockKasszaOptions {
|
|
22
|
+
readonly defaults?: KasszaDefaults;
|
|
23
|
+
readonly taxpayers?: Readonly<Record<string, TaxpayerInfo>>;
|
|
24
|
+
readonly credentialsValid?: boolean;
|
|
25
|
+
readonly now?: () => Date;
|
|
26
|
+
}
|
|
27
|
+
export interface MockKassza extends Kassza {
|
|
28
|
+
readonly calls: readonly MockCall[];
|
|
29
|
+
readonly invoiceRecords: ReadonlyMap<string, MockInvoiceRecord>;
|
|
30
|
+
readonly receiptRecords: ReadonlyMap<string, MockReceiptRecord>;
|
|
31
|
+
failNext(method: string, error?: SzamlazzError): void;
|
|
32
|
+
reset(): void;
|
|
33
|
+
}
|
|
34
|
+
export declare function createMockKassza(options?: MockKasszaOptions): MockKassza;
|
|
35
|
+
//#endregion
|