@halftome/szamlazz-client 1.0.8 → 1.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/dist/index.d.ts +42 -3
- package/dist/index.js +51 -27
- package/dist/types.d.ts +4 -4
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,53 @@
|
|
|
1
|
-
import type { InvoiceOptions, LineItem, ReverseInvoiceOptions, KeyAuth, CredentialAuth,
|
|
1
|
+
import type { InvoiceOptions, LineItem, ReverseInvoiceOptions, KeyAuth, CredentialAuth, InvoiceItemResponse } from './types';
|
|
2
2
|
export declare class Client {
|
|
3
3
|
readonly key?: string;
|
|
4
4
|
readonly username?: string;
|
|
5
5
|
readonly password?: string;
|
|
6
6
|
readonly apiUrl = "https://www.szamlazz.hu/szamla/";
|
|
7
7
|
constructor(auth: KeyAuth | CredentialAuth);
|
|
8
|
+
private decodeResponse;
|
|
8
9
|
private sendRequest;
|
|
9
10
|
private authAttributes;
|
|
10
|
-
generateInvoice(options: InvoiceOptions, items?: Array<LineItem>): Promise<
|
|
11
|
-
reverseInvoice(invoice: string, options: ReverseInvoiceOptions): Promise<
|
|
11
|
+
generateInvoice(options: InvoiceOptions, items?: Array<LineItem>): Promise<InvoiceItemResponse>;
|
|
12
|
+
reverseInvoice(invoice: string, options: ReverseInvoiceOptions): Promise<InvoiceItemResponse>;
|
|
13
|
+
testConnection(): Promise<boolean>;
|
|
12
14
|
}
|
|
13
15
|
export default Client;
|
|
14
16
|
export * from './types';
|
|
17
|
+
/**
|
|
18
|
+
|
|
19
|
+
const c = new Client({ username: 'demo', password: 'demo' })
|
|
20
|
+
|
|
21
|
+
c.generateInvoice(
|
|
22
|
+
{
|
|
23
|
+
eInvoice: true,
|
|
24
|
+
currency: Currency.HUF,
|
|
25
|
+
sendEmail: false,
|
|
26
|
+
language: Language.HU,
|
|
27
|
+
paymentMethod: PaymentMethod.Card,
|
|
28
|
+
settled: true,
|
|
29
|
+
comment: 'some random comment',
|
|
30
|
+
customer: {
|
|
31
|
+
name: 'Test',
|
|
32
|
+
address: 'Test',
|
|
33
|
+
city: 'Test',
|
|
34
|
+
zip: 'TST111',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
[
|
|
38
|
+
{
|
|
39
|
+
amount: 1,
|
|
40
|
+
amountName: 'db',
|
|
41
|
+
grossAmount: 1000,
|
|
42
|
+
netAmount: 1000,
|
|
43
|
+
name: 'Test',
|
|
44
|
+
netUnitPrice: 1000,
|
|
45
|
+
taxAmount: 0,
|
|
46
|
+
vatRate: NamedVATRate.AAM,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
).then((r) => {
|
|
50
|
+
console.log(r)
|
|
51
|
+
c.reverseInvoice(r.invoice.number, { eInvoice: true }).then((r) => console.log(r))
|
|
52
|
+
})
|
|
53
|
+
*/
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -18,6 +22,8 @@ const xmlbuilder2_1 = require("xmlbuilder2");
|
|
|
18
22
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
19
23
|
const form_data_1 = __importDefault(require("form-data"));
|
|
20
24
|
const url_1 = require("url");
|
|
25
|
+
const luxon_1 = require("luxon");
|
|
26
|
+
const today = () => luxon_1.DateTime.now().setZone('Europe/Budapest').toFormat('yyyy-LL-dd');
|
|
21
27
|
class Client {
|
|
22
28
|
constructor(auth) {
|
|
23
29
|
this.apiUrl = 'https://www.szamlazz.hu/szamla/';
|
|
@@ -25,19 +31,10 @@ class Client {
|
|
|
25
31
|
this.username = auth.username;
|
|
26
32
|
this.password = auth.password;
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
// Build XML
|
|
30
|
-
const doc = (0, xmlbuilder2_1.create)({ encoding: 'UTF-8' }, content);
|
|
31
|
-
const xml = doc.end({ prettyPrint: false });
|
|
32
|
-
// Build Request
|
|
33
|
-
const form = new form_data_1.default();
|
|
34
|
-
form.append(type, xml, type);
|
|
35
|
-
// Send Request
|
|
36
|
-
const response = await (0, node_fetch_1.default)(this.apiUrl, { method: 'POST', body: form });
|
|
37
|
-
const result = await response.text();
|
|
34
|
+
decodeResponse(response) {
|
|
38
35
|
// Decode Response
|
|
39
36
|
try {
|
|
40
|
-
const obj = (0, xmlbuilder2_1.convert)(
|
|
37
|
+
const obj = (0, xmlbuilder2_1.convert)(response, { format: 'object' });
|
|
41
38
|
// Decode hosted url params:
|
|
42
39
|
const url = new url_1.URL(obj.xmlszamlavalasz?.vevoifiokurl?.$);
|
|
43
40
|
const pdfUrl = new url_1.URL(obj.xmlszamlavalasz?.vevoifiokurl?.$);
|
|
@@ -61,9 +58,20 @@ class Client {
|
|
|
61
58
|
return decoded;
|
|
62
59
|
}
|
|
63
60
|
catch (e) {
|
|
64
|
-
throw new Error(
|
|
61
|
+
throw new Error(response);
|
|
65
62
|
}
|
|
66
63
|
}
|
|
64
|
+
async sendRequest(type, content) {
|
|
65
|
+
// Build XML
|
|
66
|
+
const doc = (0, xmlbuilder2_1.create)({ encoding: 'UTF-8' }, content);
|
|
67
|
+
const xml = doc.end({ prettyPrint: false });
|
|
68
|
+
// Build Request
|
|
69
|
+
const form = new form_data_1.default();
|
|
70
|
+
form.append(type, xml, type);
|
|
71
|
+
// Send Request
|
|
72
|
+
const response = await (0, node_fetch_1.default)(this.apiUrl, { method: 'POST', body: form });
|
|
73
|
+
return await response.text();
|
|
74
|
+
}
|
|
67
75
|
authAttributes() {
|
|
68
76
|
return {
|
|
69
77
|
szamlaagentkulcs: this.key,
|
|
@@ -72,6 +80,7 @@ class Client {
|
|
|
72
80
|
};
|
|
73
81
|
}
|
|
74
82
|
async generateInvoice(options, items = []) {
|
|
83
|
+
const now = today();
|
|
75
84
|
const doc = {
|
|
76
85
|
xmlszamla: {
|
|
77
86
|
'@xmlns': 'http://www.szamlazz.hu/xmlszamla',
|
|
@@ -84,9 +93,9 @@ class Client {
|
|
|
84
93
|
valaszVerzio: 2,
|
|
85
94
|
},
|
|
86
95
|
fejlec: {
|
|
87
|
-
keltDatum: options.issueDate,
|
|
88
|
-
teljesitesDatum: options.completionDate,
|
|
89
|
-
fizetesiHataridoDatum: options.dueDate,
|
|
96
|
+
keltDatum: options.issueDate ?? now,
|
|
97
|
+
teljesitesDatum: options.completionDate ?? now,
|
|
98
|
+
fizetesiHataridoDatum: options.dueDate ?? now,
|
|
90
99
|
fizmod: options.paymentMethod,
|
|
91
100
|
penznem: options.currency,
|
|
92
101
|
szamlaNyelve: options.language,
|
|
@@ -133,9 +142,10 @@ class Client {
|
|
|
133
142
|
},
|
|
134
143
|
},
|
|
135
144
|
};
|
|
136
|
-
return await this.sendRequest('action-xmlagentxmlfile', doc);
|
|
145
|
+
return this.decodeResponse(await this.sendRequest('action-xmlagentxmlfile', doc));
|
|
137
146
|
}
|
|
138
147
|
async reverseInvoice(invoice, options) {
|
|
148
|
+
const now = today();
|
|
139
149
|
const doc = {
|
|
140
150
|
xmlszamlast: {
|
|
141
151
|
'@xmlns': 'http://www.szamlazz.hu/xmlszamlast',
|
|
@@ -149,27 +159,38 @@ class Client {
|
|
|
149
159
|
},
|
|
150
160
|
fejlec: {
|
|
151
161
|
szamlaszam: invoice,
|
|
152
|
-
keltDatum: options.issueDate,
|
|
153
|
-
teljesitesDatum: options.completionDate,
|
|
162
|
+
keltDatum: options.issueDate ?? now,
|
|
163
|
+
teljesitesDatum: options.completionDate ?? now,
|
|
154
164
|
},
|
|
155
165
|
},
|
|
156
166
|
};
|
|
157
|
-
return await this.sendRequest('action-szamla_agent_st', doc);
|
|
167
|
+
return this.decodeResponse(await this.sendRequest('action-szamla_agent_st', doc));
|
|
168
|
+
}
|
|
169
|
+
async testConnection() {
|
|
170
|
+
const doc = {
|
|
171
|
+
xmlszamlaxml: {
|
|
172
|
+
'@xmlns': 'http://www.szamlazz.hu/xmlszamlaxml',
|
|
173
|
+
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
|
174
|
+
'@xsi:schemaLocation': 'http://www.szamlazz.hu/xmlszamlaxml https://www.szamlazz.hu/szamla/docs/xsds/agentxml/xmlszamlaxml.xsd',
|
|
175
|
+
...this.authAttributes(),
|
|
176
|
+
szamlaszam: 'NEMLETEZIKSOHANEMISFOG',
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
const r = await this.sendRequest('action-szamla_agent_xml', doc);
|
|
180
|
+
const obj = (0, xmlbuilder2_1.convert)(r, { format: 'object' });
|
|
181
|
+
return obj.xmlszamlavalasz?.hibakod.$ == 7;
|
|
158
182
|
}
|
|
159
183
|
}
|
|
160
184
|
exports.Client = Client;
|
|
161
185
|
exports.default = Client;
|
|
162
186
|
__exportStar(require("./types"), exports);
|
|
163
|
-
|
|
187
|
+
/**
|
|
188
|
+
|
|
164
189
|
const c = new Client({ username: 'demo', password: 'demo' })
|
|
165
|
-
const now = new Date().toISOString().split('T')[0]
|
|
166
190
|
|
|
167
191
|
c.generateInvoice(
|
|
168
192
|
{
|
|
169
193
|
eInvoice: true,
|
|
170
|
-
completionDate: now,
|
|
171
|
-
dueDate: now,
|
|
172
|
-
issueDate: now,
|
|
173
194
|
currency: Currency.HUF,
|
|
174
195
|
sendEmail: false,
|
|
175
196
|
language: Language.HU,
|
|
@@ -195,5 +216,8 @@ c.generateInvoice(
|
|
|
195
216
|
vatRate: NamedVATRate.AAM,
|
|
196
217
|
},
|
|
197
218
|
],
|
|
198
|
-
).then(
|
|
199
|
-
|
|
219
|
+
).then((r) => {
|
|
220
|
+
console.log(r)
|
|
221
|
+
c.reverseInvoice(r.invoice.number, { eInvoice: true }).then((r) => console.log(r))
|
|
222
|
+
})
|
|
223
|
+
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -52,9 +52,9 @@ export interface InvoiceOptions {
|
|
|
52
52
|
payee?: PayeeDetails;
|
|
53
53
|
customer: CustomerDetails;
|
|
54
54
|
eInvoice: boolean;
|
|
55
|
-
issueDate
|
|
56
|
-
completionDate
|
|
57
|
-
dueDate
|
|
55
|
+
issueDate?: string;
|
|
56
|
+
completionDate?: string;
|
|
57
|
+
dueDate?: string;
|
|
58
58
|
paymentMethod: PaymentMethod | string;
|
|
59
59
|
currency: Currency;
|
|
60
60
|
language: Language;
|
|
@@ -109,7 +109,7 @@ export interface CredentialAuth {
|
|
|
109
109
|
username: string;
|
|
110
110
|
password: string;
|
|
111
111
|
}
|
|
112
|
-
export interface
|
|
112
|
+
export interface InvoiceItemResponse {
|
|
113
113
|
invoice: HostedInvoice;
|
|
114
114
|
net: number;
|
|
115
115
|
gross: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@halftome/szamlazz-client",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Node.js client for using szamlazz.hu API",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"homepage": "https://github.com/half2me/szamlazz-client#readme",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@tsconfig/node14": "^1.0.1",
|
|
30
|
+
"@types/luxon": "^2.3.1",
|
|
30
31
|
"@types/node": "^16.3.3",
|
|
31
32
|
"@types/node-fetch": "^2.5.11",
|
|
32
33
|
"prettier": "^2.3.2",
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"form-data": "^4.0.0",
|
|
39
|
+
"luxon": "^2.3.2",
|
|
38
40
|
"node-fetch": "^2.6.1",
|
|
39
41
|
"xmlbuilder2": "^3.0.2"
|
|
40
42
|
}
|