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.
- package/README.md +103 -103
- package/dist/client-CL3fuH6A.js +1596 -0
- package/dist/{client-zv4enyq7.d.ts → client-CickRRFr.d.ts} +307 -217
- package/dist/client-CsmGIFRS.cjs +1637 -0
- package/dist/{client-B9kbKKBf.d.cts → client-DvWZoX_E.d.cts} +307 -217
- package/dist/create-once-CqdYmQD8.js +330 -0
- package/dist/create-once-D0pwuenl.cjs +389 -0
- package/dist/crypto-B8lERvR1.cjs +56 -0
- package/dist/crypto-DK_osBVy.js +33 -0
- package/dist/{dates-DtHzwNU6.d.cts → dates-9zvESP0i.d.cts} +2 -1
- package/dist/{dates-DtHzwNU6.d.ts → dates-9zvESP0i.d.ts} +2 -1
- package/dist/{dates-PPxH0n5H.cjs → dates-CPgBodkP.cjs} +44 -1
- package/dist/{dates-D2XebOIg.js → dates-CXyj7Azy.js} +39 -2
- package/dist/delegation/index.cjs +395 -0
- package/dist/delegation/index.d.cts +99 -0
- package/dist/delegation/index.d.ts +99 -0
- package/dist/delegation/index.js +377 -0
- package/dist/{errors-DapdV5DK.js → errors-DLrb0g64.js} +122 -5
- package/dist/{errors-B0QJhUW1.cjs → errors-DxeuTslP.cjs} +127 -4
- package/dist/index.cjs +21 -1410
- package/dist/index.d.cts +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +8 -1409
- package/dist/ipn/index.cjs +1 -1
- package/dist/ipn/index.js +1 -1
- package/dist/{create-DZsl3Z4m.cjs → issue-BsyYdrIG.cjs} +664 -311
- package/dist/{create-5YkUcJSe.js → issue-C6Fcjvln.js} +589 -272
- package/dist/json-4y4E2xxS.cjs +61 -0
- package/dist/json-B70TwoX1.d.cts +4 -0
- package/dist/json-B70TwoX1.d.ts +4 -0
- package/dist/json-DjnqnaJK.js +32 -0
- package/dist/money/index.cjs +12 -10
- package/dist/money/index.js +3 -1
- package/dist/{money-C9j7nBNP.js → money-DAA7OwiO.js} +4 -101
- package/dist/{money-DkiGukAw.cjs → money-DrhGkWHW.cjs} +19 -170
- package/dist/payments/barion.cjs +208 -0
- package/dist/payments/barion.d.cts +28 -0
- package/dist/payments/barion.d.ts +28 -0
- package/dist/payments/barion.js +199 -0
- package/dist/payments/index.cjs +16 -0
- package/dist/payments/index.d.cts +31 -0
- package/dist/payments/index.d.ts +31 -0
- package/dist/payments/index.js +3 -0
- package/dist/payments/paypal.cjs +351 -0
- package/dist/payments/paypal.d.cts +59 -0
- package/dist/payments/paypal.d.ts +59 -0
- package/dist/payments/paypal.js +337 -0
- package/dist/payments/revolut.cjs +261 -0
- package/dist/payments/revolut.d.cts +48 -0
- package/dist/payments/revolut.d.ts +48 -0
- package/dist/payments/revolut.js +249 -0
- package/dist/payments/simplepay.cjs +313 -0
- package/dist/payments/simplepay.d.cts +86 -0
- package/dist/payments/simplepay.d.ts +86 -0
- package/dist/payments/simplepay.js +299 -0
- package/dist/payments/stripe.cjs +315 -0
- package/dist/payments/stripe.d.cts +49 -0
- package/dist/payments/stripe.d.ts +49 -0
- package/dist/payments/stripe.js +303 -0
- package/dist/reports/index.cjs +256 -0
- package/dist/reports/index.d.cts +70 -0
- package/dist/reports/index.d.ts +70 -0
- package/dist/reports/index.js +247 -0
- package/dist/rounding-BLyHjjI5.js +20 -0
- package/dist/rounding-TxoWy2ww.cjs +37 -0
- package/dist/storage/fs.cjs +1 -1
- package/dist/storage/fs.js +1 -1
- package/dist/storage/index.cjs +2 -2
- package/dist/storage/index.d.cts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js +2 -2
- package/dist/tax-number-BYFkBp4A.cjs +141 -0
- package/dist/tax-number-BdqKsxNR.js +76 -0
- package/dist/testing/index.cjs +183 -84
- package/dist/testing/index.d.cts +10 -2
- package/dist/testing/index.d.ts +10 -2
- package/dist/testing/index.js +181 -82
- package/dist/types-COf1LAD-.d.cts +56 -0
- package/dist/types-COf1LAD-.d.ts +56 -0
- package/dist/types-DH8QoNZK.d.cts +135 -0
- package/dist/types-k--zHf4l.d.ts +135 -0
- package/dist/validators/index.cjs +14 -88
- package/dist/validators/index.js +1 -75
- package/dist/vat-g35srbNG.cjs +116 -0
- package/dist/vat-v_dcWCto.js +81 -0
- package/dist/webhook-C76bV-4R.cjs +245 -0
- package/dist/webhook-CfaDgcL0.d.cts +6 -0
- package/dist/webhook-D4lvtex1.js +174 -0
- package/dist/webhook-q2OzNwd7.d.ts +6 -0
- package/package.json +106 -2
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_errors = require("../errors-DxeuTslP.cjs");
|
|
3
|
+
const require_client = require("../client-CsmGIFRS.cjs");
|
|
4
|
+
const require_issue = require("../issue-BsyYdrIG.cjs");
|
|
5
|
+
const require_dates = require("../dates-CPgBodkP.cjs");
|
|
6
|
+
const require_tax_number = require("../tax-number-BYFkBp4A.cjs");
|
|
7
|
+
//#region src/delegation/connect.ts
|
|
8
|
+
const CONNECT_PRINCIPAL_NAMESPACE = "http://www.szamlazz.hu/xmlcegmb";
|
|
9
|
+
const CONNECT_PRINCIPAL_SCHEMA_LOCATION = "http://www.szamlazz.hu/docs/xsds/agentmb/xmlcegmb.xsd";
|
|
10
|
+
const DELEGATE_PREFIX_PATTERN = /^[A-Z0-9]{1,5}$/;
|
|
11
|
+
const DELEGATE_PASSWORD_MIN_LENGTH = 8;
|
|
12
|
+
const DELEGATE_PASSWORD_MAX_LENGTH = 128;
|
|
13
|
+
const AGENT_RESPONSE_HEADER = "XML_AGENT_RESPONSE";
|
|
14
|
+
const AGENT_RESPONSE_TEXT = /xmlagentresponse\s*=\s*([^\r\n]*)/i;
|
|
15
|
+
const strictUtf8 = new TextDecoder("utf-8", { fatal: true });
|
|
16
|
+
function validation(message, hint) {
|
|
17
|
+
return new require_errors.SzamlazzError(message, {
|
|
18
|
+
category: "validation",
|
|
19
|
+
action: "connectPrincipal",
|
|
20
|
+
hint
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function required(value, label) {
|
|
24
|
+
const trimmed = value?.trim();
|
|
25
|
+
if (!trimmed) throw validation(`A(z) ${label} megadása kötelező.`);
|
|
26
|
+
return trimmed;
|
|
27
|
+
}
|
|
28
|
+
function optionalText(value) {
|
|
29
|
+
const trimmed = value?.trim();
|
|
30
|
+
return trimmed ? trimmed : void 0;
|
|
31
|
+
}
|
|
32
|
+
function normalizeDelegateTaxNumber(value) {
|
|
33
|
+
const parsed = require_tax_number.parseHungarianTaxNumber(value);
|
|
34
|
+
if (!parsed) throw validation(`A megbízó adószáma (${value}) nem érvényes 11 jegyű magyar adószám.`, "A Számlázz.hu a teljes, 13 karakteres adószám (12345678-1-23) pontos egyezésével keresi a meglévő fiókot; elgépelt adószámmal új, felesleges fiók jönne létre.");
|
|
35
|
+
return parsed.formatted;
|
|
36
|
+
}
|
|
37
|
+
function assertDelegatePrefix(value, label = "számlaszám-előtag") {
|
|
38
|
+
const prefix = required(value, label);
|
|
39
|
+
if (!DELEGATE_PREFIX_PATTERN.test(prefix)) throw validation(`A(z) ${label} (${prefix}) csak nagybetűt és számot tartalmazhat, és legfeljebb 5 karakter lehet (337).`);
|
|
40
|
+
return prefix;
|
|
41
|
+
}
|
|
42
|
+
function requiredEmail(value, label) {
|
|
43
|
+
const email = required(value, label);
|
|
44
|
+
if (!require_tax_number.isValidEmail(email)) throw validation(`A(z) ${label} (${email}) nem érvényes e-mail cím.`);
|
|
45
|
+
return email;
|
|
46
|
+
}
|
|
47
|
+
function optionalEmail(value, label) {
|
|
48
|
+
const email = optionalText(value);
|
|
49
|
+
if (email !== void 0 && !require_tax_number.isValidEmail(email)) throw validation(`A(z) ${label} (${email}) nem érvényes e-mail cím.`);
|
|
50
|
+
return email;
|
|
51
|
+
}
|
|
52
|
+
function assertPassword(password) {
|
|
53
|
+
if (typeof password !== "string" || password.length < 8) throw validation(`A dedikált felhasználó jelszava legalább 8 karakter legyen (506).`);
|
|
54
|
+
if (password.length > 128) throw validation(`A dedikált felhasználó jelszava legfeljebb 128 karakter lehet (507).`);
|
|
55
|
+
}
|
|
56
|
+
function optionalDate(value, label) {
|
|
57
|
+
if (value === void 0) return void 0;
|
|
58
|
+
try {
|
|
59
|
+
return require_dates.toAgentDate(value);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throw validation(`A(z) ${label} nem érvényes dátum: ${error instanceof Error ? error.message : String(error)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function assertPeriod(from, to, label) {
|
|
65
|
+
if (to !== void 0 && from === void 0) throw validation(`A(z) ${label} záródátumához kezdődátum is kell.`);
|
|
66
|
+
if (from !== void 0 && to !== void 0 && to < from) throw validation(`A(z) ${label} záródátuma nem lehet korábbi a kezdődátumnál.`);
|
|
67
|
+
}
|
|
68
|
+
function normalizeInput(input) {
|
|
69
|
+
const { principal, user } = input;
|
|
70
|
+
required(principal?.name, "megbízó cégneve");
|
|
71
|
+
const taxNumber = normalizeDelegateTaxNumber(required(principal.taxNumber, "megbízó adószáma"));
|
|
72
|
+
const invoicePrefix = assertDelegatePrefix(principal.invoicePrefix);
|
|
73
|
+
required(principal.zip, "székhely irányítószáma");
|
|
74
|
+
required(principal.city, "székhely települése");
|
|
75
|
+
required(principal.address, "székhely címe");
|
|
76
|
+
requiredEmail(principal.email, "megbízó e-mail címe");
|
|
77
|
+
optionalEmail(principal.replyToEmail, "válaszcím (replyToEmail)");
|
|
78
|
+
if (principal.postalAddress) {
|
|
79
|
+
required(principal.postalAddress.zip, "postázási irányítószám");
|
|
80
|
+
required(principal.postalAddress.city, "postázási település");
|
|
81
|
+
required(principal.postalAddress.address, "postázási cím");
|
|
82
|
+
}
|
|
83
|
+
const userEmail = requiredEmail(user?.email, "dedikált felhasználó e-mail címe");
|
|
84
|
+
assertPassword(user.password);
|
|
85
|
+
required(user.firstName, "dedikált felhasználó keresztneve");
|
|
86
|
+
const cashAccountingFrom = optionalDate(principal.cashAccountingFrom, "pénzforgalmi időszak kezdete");
|
|
87
|
+
const cashAccountingTo = optionalDate(principal.cashAccountingTo, "pénzforgalmi időszak vége");
|
|
88
|
+
const kataFrom = optionalDate(principal.kataFrom, "KATA időszak kezdete");
|
|
89
|
+
const kataTo = optionalDate(principal.kataTo, "KATA időszak vége");
|
|
90
|
+
assertPeriod(cashAccountingFrom, cashAccountingTo, "pénzforgalmi időszak");
|
|
91
|
+
assertPeriod(kataFrom, kataTo, "KATA időszak");
|
|
92
|
+
return {
|
|
93
|
+
taxNumber,
|
|
94
|
+
invoicePrefix,
|
|
95
|
+
principal,
|
|
96
|
+
user,
|
|
97
|
+
userEmail,
|
|
98
|
+
cashAccountingFrom,
|
|
99
|
+
cashAccountingTo,
|
|
100
|
+
kataFrom,
|
|
101
|
+
kataTo
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function loginNodes(credentials) {
|
|
105
|
+
const value = (name) => {
|
|
106
|
+
const node = credentials.find((candidate) => candidate.name === name);
|
|
107
|
+
return node === void 0 ? void 0 : String(node.content);
|
|
108
|
+
};
|
|
109
|
+
const agentKey = value("szamlaagentkulcs");
|
|
110
|
+
if (agentKey !== void 0) return [require_issue.el("szamlaagentkulcs", agentKey)];
|
|
111
|
+
const username = value("felhasznalo");
|
|
112
|
+
const password = value("jelszo");
|
|
113
|
+
if (username === void 0 || password === void 0) throw new require_errors.SzamlazzError("A megbízotti fiók azonosításához Agent kulcs vagy felhasználónév és jelszó kell.", {
|
|
114
|
+
category: "configuration",
|
|
115
|
+
action: "connectPrincipal"
|
|
116
|
+
});
|
|
117
|
+
return [require_issue.el("loginname", username), require_issue.el("password", password)];
|
|
118
|
+
}
|
|
119
|
+
function principalNodes(input) {
|
|
120
|
+
const { principal } = input;
|
|
121
|
+
return require_issue.el("cegMb", [
|
|
122
|
+
require_issue.el("cegcompanyname", principal.name.trim()),
|
|
123
|
+
require_issue.el("cegtaxnumber", input.taxNumber),
|
|
124
|
+
require_issue.el("cegszamlaszamelotag", input.invoicePrefix),
|
|
125
|
+
require_issue.el("cegirsz", principal.zip.trim()),
|
|
126
|
+
require_issue.el("cegcity", principal.city.trim()),
|
|
127
|
+
require_issue.el("cegaddr", principal.address.trim()),
|
|
128
|
+
require_issue.optionalEl("cegpostirsz", optionalText(principal.postalAddress?.zip)),
|
|
129
|
+
require_issue.optionalEl("cegpostcity", optionalText(principal.postalAddress?.city)),
|
|
130
|
+
require_issue.optionalEl("cegpostaddr", optionalText(principal.postalAddress?.address)),
|
|
131
|
+
require_issue.el("cegbank", optionalText(principal.bankName) ?? ""),
|
|
132
|
+
require_issue.el("cegbankaccount", optionalText(principal.bankAccount) ?? ""),
|
|
133
|
+
require_issue.el("cegemail", principal.email.trim()),
|
|
134
|
+
require_issue.el("cegemailreplyto", optionalText(principal.replyToEmail) ?? ""),
|
|
135
|
+
require_issue.optionalEl("cegpenzforgdattol", input.cashAccountingFrom),
|
|
136
|
+
require_issue.optionalEl("cegpenzforgdatig", input.cashAccountingTo),
|
|
137
|
+
require_issue.optionalEl("cegkatadattol", input.kataFrom),
|
|
138
|
+
require_issue.optionalEl("cegkatadatig", input.kataTo)
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
function userNodes(input) {
|
|
142
|
+
return require_issue.el("usrMb", [
|
|
143
|
+
require_issue.el("usremail", input.userEmail),
|
|
144
|
+
require_issue.el("usrpassword", input.user.password),
|
|
145
|
+
require_issue.optionalEl("usrvezeteknev", optionalText(input.user.lastName)),
|
|
146
|
+
require_issue.el("usrkeresztnev", input.user.firstName.trim())
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
function buildXml(credentials, input) {
|
|
150
|
+
return require_issue.buildXmlDocument({
|
|
151
|
+
root: "XmlCegMb",
|
|
152
|
+
namespace: CONNECT_PRINCIPAL_NAMESPACE,
|
|
153
|
+
schemaLocation: CONNECT_PRINCIPAL_SCHEMA_LOCATION,
|
|
154
|
+
children: [
|
|
155
|
+
require_issue.el("login", loginNodes(credentials)),
|
|
156
|
+
principalNodes(input),
|
|
157
|
+
userNodes(input)
|
|
158
|
+
]
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function buildConnectPrincipalXml(credentials, input) {
|
|
162
|
+
return buildXml(credentials, normalizeInput(input));
|
|
163
|
+
}
|
|
164
|
+
function normalizeMessage(message) {
|
|
165
|
+
return message.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
166
|
+
}
|
|
167
|
+
function connectPrincipalStatus(message) {
|
|
168
|
+
const normalized = normalizeMessage(message);
|
|
169
|
+
if (/^done(?:;|$)/.test(normalized)) return "account-created";
|
|
170
|
+
if (normalized.includes("nincs fiokgazdaja")) return "owner-invite-resent";
|
|
171
|
+
if (normalized.includes("csatlakozasi kerelem") && normalized.includes("ujrakuld")) return "join-request-resent";
|
|
172
|
+
if (normalized.includes("csatlakozasi kerelmet kuldtunk")) return "join-request-sent";
|
|
173
|
+
return "unknown";
|
|
174
|
+
}
|
|
175
|
+
const LATIN1_HIGH_START = 128;
|
|
176
|
+
const LATIN1_END = 255;
|
|
177
|
+
function looksLikeLatin1Utf8(value) {
|
|
178
|
+
let hasHighByte = false;
|
|
179
|
+
for (let index = 0; index < value.length; index++) {
|
|
180
|
+
const code = value.charCodeAt(index);
|
|
181
|
+
if (code > LATIN1_END) return false;
|
|
182
|
+
if (code >= LATIN1_HIGH_START) hasHighByte = true;
|
|
183
|
+
}
|
|
184
|
+
return hasHighByte;
|
|
185
|
+
}
|
|
186
|
+
function repairMojibake(value) {
|
|
187
|
+
if (!looksLikeLatin1Utf8(value)) return value;
|
|
188
|
+
try {
|
|
189
|
+
return strictUtf8.decode(Uint8Array.from(value, (char) => char.charCodeAt(0)));
|
|
190
|
+
} catch {
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function agentResponseMessage(response) {
|
|
195
|
+
const header = require_issue.readHeader(response.headers, AGENT_RESPONSE_HEADER, true);
|
|
196
|
+
if (header !== void 0) return repairMojibake(header);
|
|
197
|
+
const match = AGENT_RESPONSE_TEXT.exec(response.text());
|
|
198
|
+
const body = match?.[1] ? require_issue.decodeHeaderValue(match[1]).trim() : void 0;
|
|
199
|
+
return body ? body : void 0;
|
|
200
|
+
}
|
|
201
|
+
function parseConnectPrincipalResponse(response) {
|
|
202
|
+
require_issue.throwIfAnyError(response);
|
|
203
|
+
const message = agentResponseMessage(response);
|
|
204
|
+
if (message === void 0) throw require_issue.unexpectedResponse(response, "Hiányzik az XML_AGENT_RESPONSE válasz.");
|
|
205
|
+
return {
|
|
206
|
+
status: connectPrincipalStatus(message),
|
|
207
|
+
message
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
async function assertActiveTaxpayer(ctx, taxNumber, options) {
|
|
211
|
+
if (!(await require_client.queryTaxpayer(ctx, taxNumber, options)).valid) throw validation(`A(z) ${taxNumber} adószám a NAV szerint nem érvényes, ezért nem küldöm el a csatlakozási kérelmet.`, "Ellenőrizd a megbízó adószámát; elgépelt adószámmal új, felesleges fiók jönne létre.");
|
|
212
|
+
}
|
|
213
|
+
async function connectPrincipalWith(ctx, input, options = {}) {
|
|
214
|
+
const normalized = normalizeInput(input);
|
|
215
|
+
const xml = buildXml(ctx.credentials, normalized);
|
|
216
|
+
const requestOptions = { signal: options.signal };
|
|
217
|
+
if (options.verifyTaxNumber === true) await assertActiveTaxpayer(ctx, normalized.taxNumber, requestOptions);
|
|
218
|
+
return {
|
|
219
|
+
...await ctx.execute({
|
|
220
|
+
action: "connectPrincipal",
|
|
221
|
+
xml,
|
|
222
|
+
signal: options.signal
|
|
223
|
+
}, parseConnectPrincipalResponse),
|
|
224
|
+
taxNumber: normalized.taxNumber,
|
|
225
|
+
invoicePrefix: normalized.invoicePrefix,
|
|
226
|
+
userEmail: normalized.userEmail
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
async function connectPrincipal(input, options = {}) {
|
|
230
|
+
const { signal, verifyTaxNumber, ...szamlazzOptions } = options;
|
|
231
|
+
return connectPrincipalWith(require_client.createAgentContext(szamlazzOptions), input, {
|
|
232
|
+
signal,
|
|
233
|
+
verifyTaxNumber
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/delegation/pool.ts
|
|
238
|
+
const DEFAULT_POOL_SIZE = 100;
|
|
239
|
+
const RECEIPT_PREFIX_PATTERN = /^[A-Z0-9]+$/;
|
|
240
|
+
function configuration$1(message, hint) {
|
|
241
|
+
return new require_errors.SzamlazzError(message, {
|
|
242
|
+
category: "configuration",
|
|
243
|
+
hint
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function delegatePrefix(value) {
|
|
247
|
+
const prefix = value?.trim();
|
|
248
|
+
if (!prefix || !DELEGATE_PREFIX_PATTERN.test(prefix)) throw configuration$1(`A megbízotti számlaszám-előtag (${prefix ?? ""}) csak nagybetűt és számot tartalmazhat, és legfeljebb 5 karakter lehet.`, "A csatlakozáskor egyeztetett előtagot add meg; ezt a kassza minden számlában elküldi, így nem fut 357-es hibára egy második számlatömb után sem.");
|
|
249
|
+
return prefix;
|
|
250
|
+
}
|
|
251
|
+
function receiptPrefix(value) {
|
|
252
|
+
if (value === void 0) return void 0;
|
|
253
|
+
const prefix = value.trim();
|
|
254
|
+
if (!RECEIPT_PREFIX_PATTERN.test(prefix)) throw configuration$1(`A megbízotti nyugtaelőtag (${prefix}) csak nagybetűt és számot tartalmazhat.`);
|
|
255
|
+
return prefix;
|
|
256
|
+
}
|
|
257
|
+
function createDelegateKassza(options) {
|
|
258
|
+
const { username, password, invoicePrefix, receiptPrefix: receipt, defaults, ...rest } = options;
|
|
259
|
+
if (options.agentKey !== void 0) throw configuration$1("Megbízotti kiállításhoz nem használható Agent kulcs: a kulcs a fiókhoz tartozik, így a bizonylat a megbízó saját neve alatt készülne.", "Add meg a csatlakozáskor létrehozott dedikált (usrMb) felhasználó felhasználónevét és jelszavát.");
|
|
260
|
+
if (!username?.trim() || !password) throw configuration$1("Add meg a dedikált (usrMb) felhasználó felhasználónevét és jelszavát.");
|
|
261
|
+
const prefix = delegatePrefix(invoicePrefix);
|
|
262
|
+
const receiptDefaultPrefix = receiptPrefix(receipt);
|
|
263
|
+
const receiptDefaults = receiptDefaultPrefix === void 0 ? defaults?.receipt : {
|
|
264
|
+
...defaults?.receipt,
|
|
265
|
+
prefix: receiptDefaultPrefix
|
|
266
|
+
};
|
|
267
|
+
return require_client.createKassza({
|
|
268
|
+
...rest,
|
|
269
|
+
username: username.trim(),
|
|
270
|
+
password,
|
|
271
|
+
defaults: {
|
|
272
|
+
invoice: {
|
|
273
|
+
...defaults?.invoice,
|
|
274
|
+
prefix
|
|
275
|
+
},
|
|
276
|
+
...receiptDefaults === void 0 ? {} : { receipt: receiptDefaults }
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function poolSize(value) {
|
|
281
|
+
if (value === void 0) return 100;
|
|
282
|
+
if (!Number.isInteger(value) || value < 1) throw configuration$1(`A maxClients értéke legalább 1 egész szám legyen, kapott: ${value}`);
|
|
283
|
+
return value;
|
|
284
|
+
}
|
|
285
|
+
function createKasszaPool(options) {
|
|
286
|
+
const { resolve, maxClients, ...shared } = options;
|
|
287
|
+
if (typeof resolve !== "function") throw configuration$1("A kassza poolhoz add meg a resolve függvényt.");
|
|
288
|
+
const limit = poolSize(maxClients);
|
|
289
|
+
const clients = /* @__PURE__ */ new Map();
|
|
290
|
+
async function create(principalId) {
|
|
291
|
+
const credentials = await resolve(principalId);
|
|
292
|
+
if (!credentials) throw configuration$1(`Ismeretlen megbízó: ${principalId}.`);
|
|
293
|
+
return createDelegateKassza({
|
|
294
|
+
...shared,
|
|
295
|
+
...credentials
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
function evict() {
|
|
299
|
+
while (clients.size > limit) {
|
|
300
|
+
const oldest = clients.keys().next();
|
|
301
|
+
if (oldest.done) return;
|
|
302
|
+
clients.delete(oldest.value);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
get(principalId) {
|
|
307
|
+
const id = typeof principalId === "string" ? principalId.trim() : "";
|
|
308
|
+
if (!id) return Promise.reject(configuration$1("Add meg a megbízó azonosítóját."));
|
|
309
|
+
const existing = clients.get(id);
|
|
310
|
+
if (existing) {
|
|
311
|
+
clients.delete(id);
|
|
312
|
+
clients.set(id, existing);
|
|
313
|
+
return existing;
|
|
314
|
+
}
|
|
315
|
+
const created = create(id);
|
|
316
|
+
clients.set(id, created);
|
|
317
|
+
created.catch(() => {
|
|
318
|
+
if (clients.get(id) === created) clients.delete(id);
|
|
319
|
+
});
|
|
320
|
+
evict();
|
|
321
|
+
return created;
|
|
322
|
+
},
|
|
323
|
+
forget(principalId) {
|
|
324
|
+
clients.delete(principalId.trim());
|
|
325
|
+
},
|
|
326
|
+
clear() {
|
|
327
|
+
clients.clear();
|
|
328
|
+
},
|
|
329
|
+
get size() {
|
|
330
|
+
return clients.size;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/delegation/probe.ts
|
|
336
|
+
const DELEGATION_PROBE_INVOICE_NUMBER = "KASSZA-DELEGATION-PROBE-0";
|
|
337
|
+
const MESSAGES = {
|
|
338
|
+
active: "A megbízotti kapcsolat él: a dedikált felhasználó be tud lépni a megbízó fiókjába.",
|
|
339
|
+
"awaiting-approval": "A belépés sikertelen (3): a megbízó még nem fogadta el a csatlakozási kérelmet, vagy hibás a felhasználónév vagy a jelszó.",
|
|
340
|
+
"awaiting-owner-registration": "A megbízó még nem vette birtokba az új fiókot (250). A Számlázz.hu minden ilyen hívásnál újraküldi neki a fiókgazdai meghívót, ezért ne ellenőrizd ciklusban.",
|
|
341
|
+
"multi-account-user": "A dedikált felhasználó több fiókhoz fér hozzá (164), így Számla Agenttel nem használható. Vedd le a hozzáférését a többi fiókról, vagy használj új dedikált felhasználót."
|
|
342
|
+
};
|
|
343
|
+
const STATES_BY_CODE = /* @__PURE__ */ new Map([
|
|
344
|
+
[3, "awaiting-approval"],
|
|
345
|
+
[250, "awaiting-owner-registration"],
|
|
346
|
+
[164, "multi-account-user"]
|
|
347
|
+
]);
|
|
348
|
+
function configuration(message) {
|
|
349
|
+
return new require_errors.SzamlazzError(message, { category: "configuration" });
|
|
350
|
+
}
|
|
351
|
+
async function probeDelegation(options) {
|
|
352
|
+
const { signal, agentKey, ...rest } = options;
|
|
353
|
+
if (agentKey !== void 0) throw configuration("A megbízotti kapcsolat ellenőrzéséhez a dedikált felhasználó felhasználónevét és jelszavát add meg. Az Agent kulcs a fiókhoz tartozik, nem hordozza a megbízotti kapcsolatot.");
|
|
354
|
+
if (!rest.username?.trim() || !rest.password) throw configuration("Add meg a dedikált (usrMb) felhasználó felhasználónevét és jelszavát.");
|
|
355
|
+
const ctx = require_client.createAgentContext(rest);
|
|
356
|
+
try {
|
|
357
|
+
await require_client.getInvoicePdf(ctx, DELEGATION_PROBE_INVOICE_NUMBER, { signal });
|
|
358
|
+
return {
|
|
359
|
+
state: "active",
|
|
360
|
+
message: MESSAGES.active
|
|
361
|
+
};
|
|
362
|
+
} catch (error) {
|
|
363
|
+
if (!require_errors.isSzamlazzError(error)) throw error;
|
|
364
|
+
if (error.isNotFound || error.code === 7) return {
|
|
365
|
+
state: "active",
|
|
366
|
+
message: MESSAGES.active
|
|
367
|
+
};
|
|
368
|
+
const state = error.code === void 0 ? void 0 : STATES_BY_CODE.get(error.code);
|
|
369
|
+
if (state === void 0) throw error;
|
|
370
|
+
return {
|
|
371
|
+
state,
|
|
372
|
+
message: MESSAGES[state],
|
|
373
|
+
error
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
exports.CONNECT_PRINCIPAL_NAMESPACE = CONNECT_PRINCIPAL_NAMESPACE;
|
|
379
|
+
exports.CONNECT_PRINCIPAL_SCHEMA_LOCATION = CONNECT_PRINCIPAL_SCHEMA_LOCATION;
|
|
380
|
+
exports.DEFAULT_POOL_SIZE = DEFAULT_POOL_SIZE;
|
|
381
|
+
exports.DELEGATE_PASSWORD_MAX_LENGTH = DELEGATE_PASSWORD_MAX_LENGTH;
|
|
382
|
+
exports.DELEGATE_PASSWORD_MIN_LENGTH = DELEGATE_PASSWORD_MIN_LENGTH;
|
|
383
|
+
exports.DELEGATE_PREFIX_PATTERN = DELEGATE_PREFIX_PATTERN;
|
|
384
|
+
exports.DELEGATION_PROBE_INVOICE_NUMBER = DELEGATION_PROBE_INVOICE_NUMBER;
|
|
385
|
+
exports.assertDelegatePrefix = assertDelegatePrefix;
|
|
386
|
+
exports.buildConnectPrincipalXml = buildConnectPrincipalXml;
|
|
387
|
+
exports.connectPrincipal = connectPrincipal;
|
|
388
|
+
exports.connectPrincipalStatus = connectPrincipalStatus;
|
|
389
|
+
exports.connectPrincipalWith = connectPrincipalWith;
|
|
390
|
+
exports.createDelegateKassza = createDelegateKassza;
|
|
391
|
+
exports.createKasszaPool = createKasszaPool;
|
|
392
|
+
exports.normalizeDelegateTaxNumber = normalizeDelegateTaxNumber;
|
|
393
|
+
exports.parseConnectPrincipalResponse = parseConnectPrincipalResponse;
|
|
394
|
+
exports.probeDelegation = probeDelegation;
|
|
395
|
+
exports.suggestedPrefix = require_errors.suggestedPrefix;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { J as AgentContext, Kt as suggestedPrefix, Q as RequestOptions, Ut as SzamlazzError, et as SzamlazzOptions, ht as AgentResponse, i as KasszaOptions, mt as XmlNode, n as Kassza, r as KasszaDefaults } from "../client-DvWZoX_E.cjs";
|
|
2
|
+
import { t as DateInput } from "../dates-9zvESP0i.cjs";
|
|
3
|
+
//#region src/delegation/connect.d.ts
|
|
4
|
+
export declare const CONNECT_PRINCIPAL_NAMESPACE = "http://www.szamlazz.hu/xmlcegmb";
|
|
5
|
+
export declare const CONNECT_PRINCIPAL_SCHEMA_LOCATION = "http://www.szamlazz.hu/docs/xsds/agentmb/xmlcegmb.xsd";
|
|
6
|
+
export declare const DELEGATE_PREFIX_PATTERN: RegExp;
|
|
7
|
+
export declare const DELEGATE_PASSWORD_MIN_LENGTH = 8;
|
|
8
|
+
export declare const DELEGATE_PASSWORD_MAX_LENGTH = 128;
|
|
9
|
+
interface PrincipalAddress {
|
|
10
|
+
readonly zip: string;
|
|
11
|
+
readonly city: string;
|
|
12
|
+
readonly address: string;
|
|
13
|
+
}
|
|
14
|
+
interface PrincipalCompany {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly taxNumber: string;
|
|
17
|
+
readonly invoicePrefix: string;
|
|
18
|
+
readonly zip: string;
|
|
19
|
+
readonly city: string;
|
|
20
|
+
readonly address: string;
|
|
21
|
+
readonly postalAddress?: PrincipalAddress | undefined;
|
|
22
|
+
readonly bankName?: string | undefined;
|
|
23
|
+
readonly bankAccount?: string | undefined;
|
|
24
|
+
readonly email: string;
|
|
25
|
+
readonly replyToEmail?: string | undefined;
|
|
26
|
+
readonly cashAccountingFrom?: DateInput | undefined;
|
|
27
|
+
readonly cashAccountingTo?: DateInput | undefined;
|
|
28
|
+
readonly kataFrom?: DateInput | undefined;
|
|
29
|
+
readonly kataTo?: DateInput | undefined;
|
|
30
|
+
}
|
|
31
|
+
interface DelegateUser {
|
|
32
|
+
readonly email: string;
|
|
33
|
+
readonly password: string;
|
|
34
|
+
readonly firstName: string;
|
|
35
|
+
readonly lastName?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
interface ConnectPrincipalInput {
|
|
38
|
+
readonly principal: PrincipalCompany;
|
|
39
|
+
readonly user: DelegateUser;
|
|
40
|
+
}
|
|
41
|
+
type ConnectPrincipalStatus = "account-created" | "owner-invite-resent" | "join-request-resent" | "join-request-sent" | "unknown";
|
|
42
|
+
interface ConnectPrincipalResponse {
|
|
43
|
+
readonly status: ConnectPrincipalStatus;
|
|
44
|
+
readonly message: string;
|
|
45
|
+
}
|
|
46
|
+
interface ConnectPrincipalResult extends ConnectPrincipalResponse {
|
|
47
|
+
readonly taxNumber: string;
|
|
48
|
+
readonly invoicePrefix: string;
|
|
49
|
+
readonly userEmail: string;
|
|
50
|
+
}
|
|
51
|
+
interface ConnectPrincipalOptions extends SzamlazzOptions, RequestOptions {
|
|
52
|
+
readonly verifyTaxNumber?: boolean | undefined;
|
|
53
|
+
}
|
|
54
|
+
export declare function normalizeDelegateTaxNumber(value: string): string;
|
|
55
|
+
export declare function assertDelegatePrefix(value: string, label?: string): string;
|
|
56
|
+
export declare function buildConnectPrincipalXml(credentials: readonly XmlNode[], input: ConnectPrincipalInput): string;
|
|
57
|
+
export declare function connectPrincipalStatus(message: string): ConnectPrincipalStatus;
|
|
58
|
+
export declare function parseConnectPrincipalResponse(response: AgentResponse): ConnectPrincipalResponse;
|
|
59
|
+
export declare function connectPrincipalWith(ctx: AgentContext, input: ConnectPrincipalInput, options?: RequestOptions & {
|
|
60
|
+
readonly verifyTaxNumber?: boolean | undefined;
|
|
61
|
+
}): Promise<ConnectPrincipalResult>;
|
|
62
|
+
export declare function connectPrincipal(input: ConnectPrincipalInput, options?: ConnectPrincipalOptions): Promise<ConnectPrincipalResult>;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/delegation/pool.d.ts
|
|
65
|
+
export declare const DEFAULT_POOL_SIZE = 100;
|
|
66
|
+
interface DelegateCredentials {
|
|
67
|
+
readonly username: string;
|
|
68
|
+
readonly password: string;
|
|
69
|
+
readonly invoicePrefix: string;
|
|
70
|
+
readonly receiptPrefix?: string | undefined;
|
|
71
|
+
readonly defaults?: KasszaDefaults | undefined;
|
|
72
|
+
}
|
|
73
|
+
interface DelegateKasszaOptions extends Omit<KasszaOptions, "agentKey" | "username" | "password" | "defaults">, DelegateCredentials {}
|
|
74
|
+
type DelegateResolver = (principalId: string) => DelegateCredentials | undefined | Promise<DelegateCredentials | undefined>;
|
|
75
|
+
interface KasszaPoolOptions extends Omit<KasszaOptions, "agentKey" | "username" | "password" | "defaults"> {
|
|
76
|
+
readonly resolve: DelegateResolver;
|
|
77
|
+
readonly maxClients?: number | undefined;
|
|
78
|
+
}
|
|
79
|
+
interface KasszaPool {
|
|
80
|
+
get(principalId: string): Promise<Kassza>;
|
|
81
|
+
forget(principalId: string): void;
|
|
82
|
+
clear(): void;
|
|
83
|
+
readonly size: number;
|
|
84
|
+
}
|
|
85
|
+
export declare function createDelegateKassza(options: DelegateKasszaOptions): Kassza;
|
|
86
|
+
export declare function createKasszaPool(options: KasszaPoolOptions): KasszaPool;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/delegation/probe.d.ts
|
|
89
|
+
type DelegationState = "active" | "awaiting-approval" | "awaiting-owner-registration" | "multi-account-user";
|
|
90
|
+
interface DelegationProbeResult {
|
|
91
|
+
readonly state: DelegationState;
|
|
92
|
+
readonly message: string;
|
|
93
|
+
readonly error?: SzamlazzError | undefined;
|
|
94
|
+
}
|
|
95
|
+
interface ProbeDelegationOptions extends SzamlazzOptions, RequestOptions {}
|
|
96
|
+
export declare const DELEGATION_PROBE_INVOICE_NUMBER = "KASSZA-DELEGATION-PROBE-0";
|
|
97
|
+
export declare function probeDelegation(options: ProbeDelegationOptions): Promise<DelegationProbeResult>;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { type ConnectPrincipalInput, type ConnectPrincipalOptions, type ConnectPrincipalResponse, type ConnectPrincipalResult, type ConnectPrincipalStatus, type DelegateCredentials, type DelegateKasszaOptions, type DelegateResolver, type DelegateUser, type DelegationProbeResult, type DelegationState, type KasszaPool, type KasszaPoolOptions, type PrincipalAddress, type PrincipalCompany, type ProbeDelegationOptions, suggestedPrefix };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { J as AgentContext, Kt as suggestedPrefix, Q as RequestOptions, Ut as SzamlazzError, et as SzamlazzOptions, ht as AgentResponse, i as KasszaOptions, mt as XmlNode, n as Kassza, r as KasszaDefaults } from "../client-CickRRFr.js";
|
|
2
|
+
import { t as DateInput } from "../dates-9zvESP0i.js";
|
|
3
|
+
//#region src/delegation/connect.d.ts
|
|
4
|
+
export declare const CONNECT_PRINCIPAL_NAMESPACE = "http://www.szamlazz.hu/xmlcegmb";
|
|
5
|
+
export declare const CONNECT_PRINCIPAL_SCHEMA_LOCATION = "http://www.szamlazz.hu/docs/xsds/agentmb/xmlcegmb.xsd";
|
|
6
|
+
export declare const DELEGATE_PREFIX_PATTERN: RegExp;
|
|
7
|
+
export declare const DELEGATE_PASSWORD_MIN_LENGTH = 8;
|
|
8
|
+
export declare const DELEGATE_PASSWORD_MAX_LENGTH = 128;
|
|
9
|
+
interface PrincipalAddress {
|
|
10
|
+
readonly zip: string;
|
|
11
|
+
readonly city: string;
|
|
12
|
+
readonly address: string;
|
|
13
|
+
}
|
|
14
|
+
interface PrincipalCompany {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly taxNumber: string;
|
|
17
|
+
readonly invoicePrefix: string;
|
|
18
|
+
readonly zip: string;
|
|
19
|
+
readonly city: string;
|
|
20
|
+
readonly address: string;
|
|
21
|
+
readonly postalAddress?: PrincipalAddress | undefined;
|
|
22
|
+
readonly bankName?: string | undefined;
|
|
23
|
+
readonly bankAccount?: string | undefined;
|
|
24
|
+
readonly email: string;
|
|
25
|
+
readonly replyToEmail?: string | undefined;
|
|
26
|
+
readonly cashAccountingFrom?: DateInput | undefined;
|
|
27
|
+
readonly cashAccountingTo?: DateInput | undefined;
|
|
28
|
+
readonly kataFrom?: DateInput | undefined;
|
|
29
|
+
readonly kataTo?: DateInput | undefined;
|
|
30
|
+
}
|
|
31
|
+
interface DelegateUser {
|
|
32
|
+
readonly email: string;
|
|
33
|
+
readonly password: string;
|
|
34
|
+
readonly firstName: string;
|
|
35
|
+
readonly lastName?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
interface ConnectPrincipalInput {
|
|
38
|
+
readonly principal: PrincipalCompany;
|
|
39
|
+
readonly user: DelegateUser;
|
|
40
|
+
}
|
|
41
|
+
type ConnectPrincipalStatus = "account-created" | "owner-invite-resent" | "join-request-resent" | "join-request-sent" | "unknown";
|
|
42
|
+
interface ConnectPrincipalResponse {
|
|
43
|
+
readonly status: ConnectPrincipalStatus;
|
|
44
|
+
readonly message: string;
|
|
45
|
+
}
|
|
46
|
+
interface ConnectPrincipalResult extends ConnectPrincipalResponse {
|
|
47
|
+
readonly taxNumber: string;
|
|
48
|
+
readonly invoicePrefix: string;
|
|
49
|
+
readonly userEmail: string;
|
|
50
|
+
}
|
|
51
|
+
interface ConnectPrincipalOptions extends SzamlazzOptions, RequestOptions {
|
|
52
|
+
readonly verifyTaxNumber?: boolean | undefined;
|
|
53
|
+
}
|
|
54
|
+
export declare function normalizeDelegateTaxNumber(value: string): string;
|
|
55
|
+
export declare function assertDelegatePrefix(value: string, label?: string): string;
|
|
56
|
+
export declare function buildConnectPrincipalXml(credentials: readonly XmlNode[], input: ConnectPrincipalInput): string;
|
|
57
|
+
export declare function connectPrincipalStatus(message: string): ConnectPrincipalStatus;
|
|
58
|
+
export declare function parseConnectPrincipalResponse(response: AgentResponse): ConnectPrincipalResponse;
|
|
59
|
+
export declare function connectPrincipalWith(ctx: AgentContext, input: ConnectPrincipalInput, options?: RequestOptions & {
|
|
60
|
+
readonly verifyTaxNumber?: boolean | undefined;
|
|
61
|
+
}): Promise<ConnectPrincipalResult>;
|
|
62
|
+
export declare function connectPrincipal(input: ConnectPrincipalInput, options?: ConnectPrincipalOptions): Promise<ConnectPrincipalResult>;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/delegation/pool.d.ts
|
|
65
|
+
export declare const DEFAULT_POOL_SIZE = 100;
|
|
66
|
+
interface DelegateCredentials {
|
|
67
|
+
readonly username: string;
|
|
68
|
+
readonly password: string;
|
|
69
|
+
readonly invoicePrefix: string;
|
|
70
|
+
readonly receiptPrefix?: string | undefined;
|
|
71
|
+
readonly defaults?: KasszaDefaults | undefined;
|
|
72
|
+
}
|
|
73
|
+
interface DelegateKasszaOptions extends Omit<KasszaOptions, "agentKey" | "username" | "password" | "defaults">, DelegateCredentials {}
|
|
74
|
+
type DelegateResolver = (principalId: string) => DelegateCredentials | undefined | Promise<DelegateCredentials | undefined>;
|
|
75
|
+
interface KasszaPoolOptions extends Omit<KasszaOptions, "agentKey" | "username" | "password" | "defaults"> {
|
|
76
|
+
readonly resolve: DelegateResolver;
|
|
77
|
+
readonly maxClients?: number | undefined;
|
|
78
|
+
}
|
|
79
|
+
interface KasszaPool {
|
|
80
|
+
get(principalId: string): Promise<Kassza>;
|
|
81
|
+
forget(principalId: string): void;
|
|
82
|
+
clear(): void;
|
|
83
|
+
readonly size: number;
|
|
84
|
+
}
|
|
85
|
+
export declare function createDelegateKassza(options: DelegateKasszaOptions): Kassza;
|
|
86
|
+
export declare function createKasszaPool(options: KasszaPoolOptions): KasszaPool;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/delegation/probe.d.ts
|
|
89
|
+
type DelegationState = "active" | "awaiting-approval" | "awaiting-owner-registration" | "multi-account-user";
|
|
90
|
+
interface DelegationProbeResult {
|
|
91
|
+
readonly state: DelegationState;
|
|
92
|
+
readonly message: string;
|
|
93
|
+
readonly error?: SzamlazzError | undefined;
|
|
94
|
+
}
|
|
95
|
+
interface ProbeDelegationOptions extends SzamlazzOptions, RequestOptions {}
|
|
96
|
+
export declare const DELEGATION_PROBE_INVOICE_NUMBER = "KASSZA-DELEGATION-PROBE-0";
|
|
97
|
+
export declare function probeDelegation(options: ProbeDelegationOptions): Promise<DelegationProbeResult>;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { type ConnectPrincipalInput, type ConnectPrincipalOptions, type ConnectPrincipalResponse, type ConnectPrincipalResult, type ConnectPrincipalStatus, type DelegateCredentials, type DelegateKasszaOptions, type DelegateResolver, type DelegateUser, type DelegationProbeResult, type DelegationState, type KasszaPool, type KasszaPoolOptions, type PrincipalAddress, type PrincipalCompany, type ProbeDelegationOptions, suggestedPrefix };
|