@halftome/szamlazz-client 1.0.6 → 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 +45 -4
- package/dist/index.js +93 -19
- package/dist/types.d.ts +7 -7
- package/package.json +9 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,53 @@
|
|
|
1
|
-
import type { InvoiceOptions, LineItem, ReverseInvoiceOptions, KeyAuth, CredentialAuth,
|
|
2
|
-
export
|
|
1
|
+
import type { InvoiceOptions, LineItem, ReverseInvoiceOptions, KeyAuth, CredentialAuth, InvoiceItemResponse } from './types';
|
|
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
|
}
|
|
15
|
+
export default Client;
|
|
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,12 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
5
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Client = void 0;
|
|
6
21
|
const xmlbuilder2_1 = require("xmlbuilder2");
|
|
7
22
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
23
|
const form_data_1 = __importDefault(require("form-data"));
|
|
9
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');
|
|
10
27
|
class Client {
|
|
11
28
|
constructor(auth) {
|
|
12
29
|
this.apiUrl = 'https://www.szamlazz.hu/szamla/';
|
|
@@ -14,19 +31,10 @@ class Client {
|
|
|
14
31
|
this.username = auth.username;
|
|
15
32
|
this.password = auth.password;
|
|
16
33
|
}
|
|
17
|
-
|
|
18
|
-
// Build XML
|
|
19
|
-
const doc = xmlbuilder2_1.create({ encoding: 'UTF-8' }, content);
|
|
20
|
-
const xml = doc.end({ prettyPrint: false });
|
|
21
|
-
// Build Request
|
|
22
|
-
const form = new form_data_1.default();
|
|
23
|
-
form.append(type, xml, type);
|
|
24
|
-
// Send Request
|
|
25
|
-
const response = await node_fetch_1.default(this.apiUrl, { method: 'POST', body: form });
|
|
26
|
-
const result = await response.text();
|
|
34
|
+
decodeResponse(response) {
|
|
27
35
|
// Decode Response
|
|
28
36
|
try {
|
|
29
|
-
const obj = xmlbuilder2_1.convert(
|
|
37
|
+
const obj = (0, xmlbuilder2_1.convert)(response, { format: 'object' });
|
|
30
38
|
// Decode hosted url params:
|
|
31
39
|
const url = new url_1.URL(obj.xmlszamlavalasz?.vevoifiokurl?.$);
|
|
32
40
|
const pdfUrl = new url_1.URL(obj.xmlszamlavalasz?.vevoifiokurl?.$);
|
|
@@ -50,9 +58,20 @@ class Client {
|
|
|
50
58
|
return decoded;
|
|
51
59
|
}
|
|
52
60
|
catch (e) {
|
|
53
|
-
throw new Error(
|
|
61
|
+
throw new Error(response);
|
|
54
62
|
}
|
|
55
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
|
+
}
|
|
56
75
|
authAttributes() {
|
|
57
76
|
return {
|
|
58
77
|
szamlaagentkulcs: this.key,
|
|
@@ -61,6 +80,7 @@ class Client {
|
|
|
61
80
|
};
|
|
62
81
|
}
|
|
63
82
|
async generateInvoice(options, items = []) {
|
|
83
|
+
const now = today();
|
|
64
84
|
const doc = {
|
|
65
85
|
xmlszamla: {
|
|
66
86
|
'@xmlns': 'http://www.szamlazz.hu/xmlszamla',
|
|
@@ -73,9 +93,9 @@ class Client {
|
|
|
73
93
|
valaszVerzio: 2,
|
|
74
94
|
},
|
|
75
95
|
fejlec: {
|
|
76
|
-
keltDatum: options.issueDate,
|
|
77
|
-
teljesitesDatum: options.completionDate,
|
|
78
|
-
fizetesiHataridoDatum: options.dueDate,
|
|
96
|
+
keltDatum: options.issueDate ?? now,
|
|
97
|
+
teljesitesDatum: options.completionDate ?? now,
|
|
98
|
+
fizetesiHataridoDatum: options.dueDate ?? now,
|
|
79
99
|
fizmod: options.paymentMethod,
|
|
80
100
|
penznem: options.currency,
|
|
81
101
|
szamlaNyelve: options.language,
|
|
@@ -122,9 +142,10 @@ class Client {
|
|
|
122
142
|
},
|
|
123
143
|
},
|
|
124
144
|
};
|
|
125
|
-
return await this.sendRequest('action-xmlagentxmlfile', doc);
|
|
145
|
+
return this.decodeResponse(await this.sendRequest('action-xmlagentxmlfile', doc));
|
|
126
146
|
}
|
|
127
147
|
async reverseInvoice(invoice, options) {
|
|
148
|
+
const now = today();
|
|
128
149
|
const doc = {
|
|
129
150
|
xmlszamlast: {
|
|
130
151
|
'@xmlns': 'http://www.szamlazz.hu/xmlszamlast',
|
|
@@ -138,12 +159,65 @@ class Client {
|
|
|
138
159
|
},
|
|
139
160
|
fejlec: {
|
|
140
161
|
szamlaszam: invoice,
|
|
141
|
-
keltDatum: options.issueDate,
|
|
142
|
-
teljesitesDatum: options.completionDate,
|
|
162
|
+
keltDatum: options.issueDate ?? now,
|
|
163
|
+
teljesitesDatum: options.completionDate ?? now,
|
|
143
164
|
},
|
|
144
165
|
},
|
|
145
166
|
};
|
|
146
|
-
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;
|
|
147
182
|
}
|
|
148
183
|
}
|
|
184
|
+
exports.Client = Client;
|
|
149
185
|
exports.default = Client;
|
|
186
|
+
__exportStar(require("./types"), exports);
|
|
187
|
+
/**
|
|
188
|
+
|
|
189
|
+
const c = new Client({ username: 'demo', password: 'demo' })
|
|
190
|
+
|
|
191
|
+
c.generateInvoice(
|
|
192
|
+
{
|
|
193
|
+
eInvoice: true,
|
|
194
|
+
currency: Currency.HUF,
|
|
195
|
+
sendEmail: false,
|
|
196
|
+
language: Language.HU,
|
|
197
|
+
paymentMethod: PaymentMethod.Card,
|
|
198
|
+
settled: true,
|
|
199
|
+
comment: 'some random comment',
|
|
200
|
+
customer: {
|
|
201
|
+
name: 'Test',
|
|
202
|
+
address: 'Test',
|
|
203
|
+
city: 'Test',
|
|
204
|
+
zip: 'TST111',
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
[
|
|
208
|
+
{
|
|
209
|
+
amount: 1,
|
|
210
|
+
amountName: 'db',
|
|
211
|
+
grossAmount: 1000,
|
|
212
|
+
netAmount: 1000,
|
|
213
|
+
name: 'Test',
|
|
214
|
+
netUnitPrice: 1000,
|
|
215
|
+
taxAmount: 0,
|
|
216
|
+
vatRate: NamedVATRate.AAM,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
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,10 +52,10 @@ export interface InvoiceOptions {
|
|
|
52
52
|
payee?: PayeeDetails;
|
|
53
53
|
customer: CustomerDetails;
|
|
54
54
|
eInvoice: boolean;
|
|
55
|
-
issueDate
|
|
56
|
-
completionDate
|
|
57
|
-
dueDate
|
|
58
|
-
paymentMethod: PaymentMethod;
|
|
55
|
+
issueDate?: string;
|
|
56
|
+
completionDate?: string;
|
|
57
|
+
dueDate?: string;
|
|
58
|
+
paymentMethod: PaymentMethod | string;
|
|
59
59
|
currency: Currency;
|
|
60
60
|
language: Language;
|
|
61
61
|
sendEmail: boolean;
|
|
@@ -81,9 +81,9 @@ export interface PayeeDetails {
|
|
|
81
81
|
export interface CustomerDetails {
|
|
82
82
|
id?: string;
|
|
83
83
|
name: string;
|
|
84
|
-
zip
|
|
84
|
+
zip: string;
|
|
85
85
|
country?: string;
|
|
86
|
-
city
|
|
86
|
+
city: string;
|
|
87
87
|
address: string;
|
|
88
88
|
email?: string;
|
|
89
89
|
phone?: string;
|
|
@@ -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,8 +1,7 @@
|
|
|
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
|
-
"main": "./dist/index.js",
|
|
6
5
|
"scripts": {
|
|
7
6
|
"build": "tsc",
|
|
8
7
|
"dev": "tsc -w",
|
|
@@ -18,12 +17,17 @@
|
|
|
18
17
|
"files": [
|
|
19
18
|
"dist/**"
|
|
20
19
|
],
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/index.js"
|
|
23
|
+
},
|
|
21
24
|
"bugs": {
|
|
22
25
|
"url": "https://github.com/half2me/szamlazz-client/issues"
|
|
23
26
|
},
|
|
24
27
|
"homepage": "https://github.com/half2me/szamlazz-client#readme",
|
|
25
28
|
"devDependencies": {
|
|
26
29
|
"@tsconfig/node14": "^1.0.1",
|
|
30
|
+
"@types/luxon": "^2.3.1",
|
|
27
31
|
"@types/node": "^16.3.3",
|
|
28
32
|
"@types/node-fetch": "^2.5.11",
|
|
29
33
|
"prettier": "^2.3.2",
|
|
@@ -31,8 +35,9 @@
|
|
|
31
35
|
"typescript": "^4.3.5"
|
|
32
36
|
},
|
|
33
37
|
"dependencies": {
|
|
34
|
-
"form-data": "^
|
|
38
|
+
"form-data": "^4.0.0",
|
|
39
|
+
"luxon": "^2.3.2",
|
|
35
40
|
"node-fetch": "^2.6.1",
|
|
36
|
-
"xmlbuilder2": "^
|
|
41
|
+
"xmlbuilder2": "^3.0.2"
|
|
37
42
|
}
|
|
38
43
|
}
|