@epostak/sdk 1.0.0 → 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/README.md +94 -396
- package/dist/client.d.ts +30 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +28 -11
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/resources/account.d.ts +25 -0
- package/dist/resources/account.d.ts.map +1 -1
- package/dist/resources/account.js +25 -0
- package/dist/resources/account.js.map +1 -1
- package/dist/resources/documents.d.ts +265 -1
- package/dist/resources/documents.d.ts.map +1 -1
- package/dist/resources/documents.js +265 -1
- package/dist/resources/documents.js.map +1 -1
- package/dist/resources/extract.d.ts +58 -0
- package/dist/resources/extract.d.ts.map +1 -1
- package/dist/resources/extract.js +64 -2
- package/dist/resources/extract.js.map +1 -1
- package/dist/resources/firms.d.ts +104 -0
- package/dist/resources/firms.d.ts.map +1 -1
- package/dist/resources/firms.js +104 -0
- package/dist/resources/firms.js.map +1 -1
- package/dist/resources/peppol.d.ts +68 -1
- package/dist/resources/peppol.d.ts.map +1 -1
- package/dist/resources/peppol.js +68 -1
- package/dist/resources/peppol.js.map +1 -1
- package/dist/resources/reporting.d.ts +28 -0
- package/dist/resources/reporting.d.ts.map +1 -1
- package/dist/resources/reporting.js +28 -0
- package/dist/resources/reporting.js.map +1 -1
- package/dist/resources/webhooks.d.ts +207 -2
- package/dist/resources/webhooks.d.ts.map +1 -1
- package/dist/resources/webhooks.js +224 -3
- package/dist/resources/webhooks.js.map +1 -1
- package/dist/types.d.ts +499 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +26 -4
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +26 -4
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/request.d.ts +42 -2
- package/dist/utils/request.d.ts.map +1 -1
- package/dist/utils/request.js +105 -30
- package/dist/utils/request.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,16 +14,15 @@ npm install @epostak/sdk
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
## Quick
|
|
17
|
+
## Quick Start
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
20
|
import { EPostak } from "@epostak/sdk";
|
|
21
21
|
|
|
22
22
|
const client = new EPostak({ apiKey: "sk_live_xxxxx" });
|
|
23
23
|
|
|
24
|
-
// Send an invoice
|
|
25
24
|
const result = await client.documents.send({
|
|
26
|
-
receiverPeppolId: "
|
|
25
|
+
receiverPeppolId: "0245:1234567890",
|
|
27
26
|
invoiceNumber: "FV-2026-001",
|
|
28
27
|
issueDate: "2026-04-04",
|
|
29
28
|
dueDate: "2026-04-18",
|
|
@@ -36,6 +35,15 @@ console.log(result.documentId, result.messageId);
|
|
|
36
35
|
|
|
37
36
|
---
|
|
38
37
|
|
|
38
|
+
## Peppol ID Formats (Slovakia)
|
|
39
|
+
|
|
40
|
+
| Scheme | Identifier | Format | Example |
|
|
41
|
+
| ------ | ----------------------- | ------------------- | ------------------- |
|
|
42
|
+
| `0245` | DIČ | `0245:XXXXXXXXXX` | `0245:1234567890` |
|
|
43
|
+
| `9950` | IČ DPH (with SK prefix) | `9950:SKXXXXXXXXXX` | `9950:SK1234567890` |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
39
47
|
## Authentication
|
|
40
48
|
|
|
41
49
|
| Key prefix | Use case |
|
|
@@ -43,15 +51,11 @@ console.log(result.documentId, result.messageId);
|
|
|
43
51
|
| `sk_live_*` | Direct access — acts on behalf of your own firm |
|
|
44
52
|
| `sk_int_*` | Integrator access — acts on behalf of client firms |
|
|
45
53
|
|
|
46
|
-
Generate keys in your ePošťák firm settings or via the dashboard.
|
|
47
|
-
|
|
48
|
-
### Constructor options
|
|
49
|
-
|
|
50
54
|
```typescript
|
|
51
55
|
const client = new EPostak({
|
|
52
|
-
apiKey: "sk_live_xxxxx",
|
|
53
|
-
baseUrl: "https://...", //
|
|
54
|
-
firmId: "uuid", //
|
|
56
|
+
apiKey: "sk_live_xxxxx",
|
|
57
|
+
baseUrl: "https://...", // optional, defaults to https://epostak.sk/api/enterprise
|
|
58
|
+
firmId: "uuid", // optional, required for integrator keys
|
|
55
59
|
});
|
|
56
60
|
```
|
|
57
61
|
|
|
@@ -61,528 +65,222 @@ const client = new EPostak({
|
|
|
61
65
|
|
|
62
66
|
### Documents
|
|
63
67
|
|
|
64
|
-
#### `documents.send(body)` — Send a document via Peppol
|
|
65
|
-
|
|
66
|
-
**JSON mode** — structured data, UBL XML is auto-generated:
|
|
67
|
-
|
|
68
68
|
```typescript
|
|
69
|
+
// Send a document (JSON mode — UBL auto-generated)
|
|
69
70
|
const result = await client.documents.send({
|
|
70
|
-
receiverPeppolId: "
|
|
71
|
+
receiverPeppolId: "0245:1234567890",
|
|
71
72
|
receiverName: "Firma s.r.o.",
|
|
72
|
-
receiverIco: "12345678",
|
|
73
|
-
receiverCountry: "SK",
|
|
74
73
|
invoiceNumber: "FV-2026-001",
|
|
75
74
|
issueDate: "2026-04-04",
|
|
76
75
|
dueDate: "2026-04-18",
|
|
77
76
|
currency: "EUR",
|
|
78
|
-
|
|
79
|
-
items: [
|
|
80
|
-
{ description: "Konzultácia", quantity: 10, unitPrice: 50, vatRate: 23 },
|
|
81
|
-
],
|
|
77
|
+
items: [{ description: "Konzultácia", quantity: 10, unitPrice: 50, vatRate: 23 }],
|
|
82
78
|
});
|
|
83
|
-
// → { documentId, messageId, status: 'SENT' }
|
|
84
|
-
```
|
|
85
79
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
80
|
+
// Send pre-built UBL XML
|
|
89
81
|
await client.documents.send({
|
|
90
|
-
receiverPeppolId: "
|
|
91
|
-
xml: '<?xml version="1.0"
|
|
82
|
+
receiverPeppolId: "0245:1234567890",
|
|
83
|
+
xml: '<?xml version="1.0"?>...',
|
|
92
84
|
});
|
|
93
|
-
```
|
|
94
85
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
86
|
+
// Get document by ID
|
|
98
87
|
const doc = await client.documents.get("doc-uuid");
|
|
99
|
-
// → { id, number, status, direction, docType, issueDate, dueDate, currency,
|
|
100
|
-
// supplier, customer, lines, totals, peppolMessageId, createdAt, updatedAt }
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
#### `documents.update(id, body)` — Update a draft document
|
|
104
|
-
|
|
105
|
-
Only documents with status `draft` can be updated. All fields are optional.
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
108
|
-
const updated = await client.documents.update("doc-uuid", {
|
|
109
|
-
invoiceNumber: "FV-2026-002",
|
|
110
|
-
dueDate: "2026-05-01",
|
|
111
|
-
items: [{ description: "Vývoj", quantity: 20, unitPrice: 75, vatRate: 23 }],
|
|
112
|
-
});
|
|
113
|
-
```
|
|
114
88
|
|
|
115
|
-
|
|
89
|
+
// Update a draft document
|
|
90
|
+
await client.documents.update("doc-uuid", { invoiceNumber: "FV-2026-002", dueDate: "2026-05-01" });
|
|
116
91
|
|
|
117
|
-
|
|
92
|
+
// Status with full history
|
|
118
93
|
const status = await client.documents.status("doc-uuid");
|
|
119
|
-
// → { id, status, documentType, senderPeppolId, receiverPeppolId,
|
|
120
|
-
// statusHistory: [{ status, timestamp, detail }],
|
|
121
|
-
// validationResult, deliveredAt, acknowledgedAt,
|
|
122
|
-
// invoiceResponseStatus, as4MessageId, createdAt, updatedAt }
|
|
123
|
-
```
|
|
124
94
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
95
|
+
// Delivery evidence (AS4, MLR, invoice response)
|
|
128
96
|
const evidence = await client.documents.evidence("doc-uuid");
|
|
129
|
-
// → { documentId, as4Receipt, mlrDocument,
|
|
130
|
-
// invoiceResponse: { status, document } | null,
|
|
131
|
-
// deliveredAt, sentAt }
|
|
132
|
-
```
|
|
133
97
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
98
|
+
// Download PDF / UBL XML
|
|
137
99
|
const pdf = await client.documents.pdf("doc-uuid");
|
|
138
|
-
require("fs").writeFileSync("invoice.pdf", pdf);
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
#### `documents.ubl(id)` — Download UBL XML as string
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
100
|
const ubl = await client.documents.ubl("doc-uuid");
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
#### `documents.respond(id, body)` — Send invoice response
|
|
148
101
|
|
|
149
|
-
|
|
102
|
+
// Respond to received invoice (AP=accept, RE=reject, UQ=query)
|
|
103
|
+
await client.documents.respond("doc-uuid", { status: "AP", note: "Akceptované" });
|
|
150
104
|
|
|
151
|
-
|
|
152
|
-
await client.documents.
|
|
153
|
-
status: "AP", // 'AP' = accepted, 'RE' = rejected, 'UQ' = under query
|
|
154
|
-
note: "Faktúra akceptovaná",
|
|
155
|
-
});
|
|
156
|
-
// → { documentId, responseStatus, respondedAt }
|
|
157
|
-
```
|
|
105
|
+
// Validate without sending
|
|
106
|
+
const validation = await client.documents.validate({ receiverPeppolId: "0245:1234567890", items: [...] });
|
|
158
107
|
|
|
159
|
-
|
|
108
|
+
// Check receiver capability
|
|
109
|
+
const check = await client.documents.preflight({ receiverPeppolId: "0245:1234567890" });
|
|
160
110
|
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
receiverPeppolId: "0191:12345678",
|
|
164
|
-
items: [{ description: "Test", quantity: 1, unitPrice: 100, vatRate: 23 }],
|
|
165
|
-
});
|
|
166
|
-
// → { valid: boolean, warnings: string[], ubl: string | null }
|
|
111
|
+
// Convert between JSON and UBL
|
|
112
|
+
const converted = await client.documents.convert({ direction: "json_to_ubl", data: { ... } });
|
|
167
113
|
```
|
|
168
114
|
|
|
169
|
-
#### `documents.preflight(body)` — Check receiver capability
|
|
170
|
-
|
|
171
|
-
```typescript
|
|
172
|
-
const check = await client.documents.preflight({
|
|
173
|
-
receiverPeppolId: "0191:12345678",
|
|
174
|
-
documentTypeId: "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
|
|
175
|
-
});
|
|
176
|
-
// → { receiverPeppolId, registered, supportsDocumentType, smpUrl }
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
#### `documents.convert(body)` — Convert between JSON and UBL
|
|
180
|
-
|
|
181
|
-
```typescript
|
|
182
|
-
// JSON → UBL
|
|
183
|
-
const result = await client.documents.convert({
|
|
184
|
-
direction: 'json_to_ubl',
|
|
185
|
-
data: { invoiceNumber: 'FV-001', items: [...] },
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// UBL → JSON
|
|
189
|
-
const result = await client.documents.convert({
|
|
190
|
-
direction: 'ubl_to_json',
|
|
191
|
-
xml: '<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">...',
|
|
192
|
-
});
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
---
|
|
196
|
-
|
|
197
115
|
### Inbox
|
|
198
116
|
|
|
199
|
-
#### `documents.inbox.list(params?)` — List received documents
|
|
200
|
-
|
|
201
117
|
```typescript
|
|
118
|
+
// List received documents
|
|
202
119
|
const inbox = await client.documents.inbox.list({
|
|
203
|
-
limit: 20,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
since: "2026-04-01T00:00:00Z", // ISO 8601
|
|
120
|
+
limit: 20,
|
|
121
|
+
status: "RECEIVED",
|
|
122
|
+
since: "2026-04-01T00:00:00Z",
|
|
207
123
|
});
|
|
208
|
-
// → { documents: InboxDocument[], total, limit, offset }
|
|
209
|
-
```
|
|
210
124
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
125
|
+
// Get full detail with UBL XML payload
|
|
214
126
|
const detail = await client.documents.inbox.get("doc-uuid");
|
|
215
|
-
console.log(detail.document);
|
|
216
|
-
console.log(detail.payload); // UBL XML string or null
|
|
217
|
-
```
|
|
127
|
+
console.log(detail.document, detail.payload);
|
|
218
128
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
129
|
+
// Acknowledge (mark as processed)
|
|
222
130
|
await client.documents.inbox.acknowledge("doc-uuid");
|
|
223
|
-
// → { documentId, status: 'ACKNOWLEDGED', acknowledgedAt }
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
#### `documents.inbox.listAll(params?)` — Cross-firm inbox (integrator)
|
|
227
|
-
|
|
228
|
-
List received documents across all firms linked to an integrator key.
|
|
229
131
|
|
|
230
|
-
|
|
132
|
+
// Cross-firm inbox (integrator only)
|
|
231
133
|
const all = await client.documents.inbox.listAll({
|
|
232
|
-
limit: 50,
|
|
233
|
-
|
|
234
|
-
status: "RECEIVED",
|
|
235
|
-
since: "2026-04-01T00:00:00Z",
|
|
236
|
-
firm_id: "specific-firm-uuid", // Optional filter
|
|
134
|
+
limit: 50,
|
|
135
|
+
firm_id: "firm-uuid",
|
|
237
136
|
});
|
|
238
|
-
// → { documents: InboxAllDocument[], total, limit, offset }
|
|
239
|
-
// Each document includes firm_id and firm_name
|
|
240
137
|
```
|
|
241
138
|
|
|
242
|
-
---
|
|
243
|
-
|
|
244
139
|
### Peppol
|
|
245
140
|
|
|
246
|
-
#### `peppol.lookup(scheme, identifier)` — SMP participant lookup
|
|
247
|
-
|
|
248
141
|
```typescript
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
#### `peppol.directory.search(params?)` — Business Card directory
|
|
142
|
+
// SMP participant lookup
|
|
143
|
+
const participant = await client.peppol.lookup("0245", "1234567890");
|
|
254
144
|
|
|
255
|
-
|
|
145
|
+
// Peppol directory search
|
|
256
146
|
const results = await client.peppol.directory.search({
|
|
257
147
|
q: "Telekom",
|
|
258
148
|
country: "SK",
|
|
259
|
-
page: 0,
|
|
260
|
-
page_size: 20,
|
|
261
149
|
});
|
|
262
|
-
// → { results: DirectoryEntry[], total, page, page_size }
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
#### `peppol.companyLookup(ico)` — Slovak company lookup
|
|
266
150
|
|
|
267
|
-
|
|
151
|
+
// Company lookup by ICO
|
|
268
152
|
const company = await client.peppol.companyLookup("12345678");
|
|
269
|
-
// → { ico, name, dic, icDph, address, peppolId }
|
|
270
153
|
```
|
|
271
154
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
### Firms (integrator keys)
|
|
275
|
-
|
|
276
|
-
#### `firms.list()` — List all accessible firms
|
|
155
|
+
### Firms (integrator)
|
|
277
156
|
|
|
278
157
|
```typescript
|
|
279
158
|
const firms = await client.firms.list();
|
|
280
|
-
// → FirmSummary[] — [{ id, name, ico, peppolId, peppolStatus }]
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
#### `firms.get(id)` — Firm detail
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
159
|
const firm = await client.firms.get("firm-uuid");
|
|
287
|
-
// → { id, name, ico, peppolId, peppolStatus, dic, icDph, address,
|
|
288
|
-
// peppolIdentifiers: [{ scheme, identifier }], createdAt }
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
#### `firms.documents(id, params?)` — List firm documents
|
|
292
|
-
|
|
293
|
-
```typescript
|
|
294
160
|
const docs = await client.firms.documents("firm-uuid", {
|
|
295
161
|
limit: 20,
|
|
296
|
-
direction: "inbound",
|
|
162
|
+
direction: "inbound",
|
|
297
163
|
});
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
#### `firms.registerPeppolId(id, peppolId)` — Register Peppol ID
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
164
|
await client.firms.registerPeppolId("firm-uuid", {
|
|
304
|
-
scheme: "
|
|
305
|
-
identifier: "
|
|
165
|
+
scheme: "0245",
|
|
166
|
+
identifier: "1234567890",
|
|
306
167
|
});
|
|
307
|
-
// → { peppolId, scheme, identifier, registeredAt }
|
|
308
|
-
```
|
|
309
168
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
```typescript
|
|
315
|
-
const result = await client.firms.assign({ ico: "12345678" });
|
|
316
|
-
// → { firm: { id, name, ico, peppol_id, peppol_status }, status: 'active' }
|
|
169
|
+
// Assign firm by ICO
|
|
170
|
+
await client.firms.assign({ ico: "12345678" });
|
|
171
|
+
await client.firms.assignBatch({ icos: ["12345678", "87654321"] });
|
|
317
172
|
```
|
|
318
173
|
|
|
319
|
-
#### `firms.assignBatch(body)` — Batch assign firms
|
|
320
|
-
|
|
321
|
-
Assign up to 50 firms in a single request.
|
|
322
|
-
|
|
323
|
-
```typescript
|
|
324
|
-
const result = await client.firms.assignBatch({
|
|
325
|
-
icos: ["12345678", "87654321", "11223344"],
|
|
326
|
-
});
|
|
327
|
-
// → { results: [{ ico, firm?, status?, error?, message? }] }
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
---
|
|
331
|
-
|
|
332
174
|
### Webhooks
|
|
333
175
|
|
|
334
|
-
#### `webhooks.create(body)` — Register a webhook
|
|
335
|
-
|
|
336
176
|
```typescript
|
|
177
|
+
// Create webhook (store secret for HMAC verification!)
|
|
337
178
|
const webhook = await client.webhooks.create({
|
|
338
179
|
url: "https://example.com/webhook",
|
|
339
180
|
events: ["document.received", "document.sent"],
|
|
340
181
|
});
|
|
341
|
-
// Store webhook.secret for HMAC-SHA256 signature verification
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
#### `webhooks.list()` — List webhooks
|
|
345
182
|
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
-
|
|
183
|
+
const list = await client.webhooks.list();
|
|
184
|
+
const detail = await client.webhooks.get(webhook.id);
|
|
185
|
+
await client.webhooks.update(webhook.id, { isActive: false });
|
|
186
|
+
await client.webhooks.delete(webhook.id);
|
|
349
187
|
```
|
|
350
188
|
|
|
351
|
-
#### `webhooks.get(id)` — Webhook detail with deliveries
|
|
352
|
-
|
|
353
|
-
```typescript
|
|
354
|
-
const detail = await client.webhooks.get("webhook-uuid");
|
|
355
|
-
// → { ...webhook, deliveries: WebhookDelivery[] }
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
#### `webhooks.update(id, body)` — Update webhook
|
|
359
|
-
|
|
360
|
-
```typescript
|
|
361
|
-
await client.webhooks.update("webhook-uuid", {
|
|
362
|
-
url: "https://example.com/new-webhook",
|
|
363
|
-
events: ["document.received"],
|
|
364
|
-
isActive: true,
|
|
365
|
-
});
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
#### `webhooks.delete(id)` — Delete webhook
|
|
369
|
-
|
|
370
|
-
```typescript
|
|
371
|
-
await client.webhooks.delete("webhook-uuid");
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
---
|
|
375
|
-
|
|
376
189
|
### Webhook Pull Queue
|
|
377
190
|
|
|
378
|
-
Alternative to push webhooks — poll for events.
|
|
379
|
-
|
|
380
|
-
#### `webhooks.queue.pull(params?)` — Fetch pending events
|
|
381
|
-
|
|
382
191
|
```typescript
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
event_type: "document.received", // Optional filter
|
|
386
|
-
});
|
|
192
|
+
// Pull pending events
|
|
193
|
+
const queue = await client.webhooks.queue.pull({ limit: 50 });
|
|
387
194
|
for (const item of queue.items) {
|
|
388
195
|
console.log(item.id, item.type, item.payload);
|
|
196
|
+
await client.webhooks.queue.ack(item.id);
|
|
389
197
|
}
|
|
390
|
-
// → { items: [{ id, type, created_at, payload }], has_more: boolean }
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
#### `webhooks.queue.ack(eventId)` — Acknowledge single event
|
|
394
|
-
|
|
395
|
-
```typescript
|
|
396
|
-
await client.webhooks.queue.ack("event-uuid");
|
|
397
|
-
// Returns void (HTTP 204)
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
#### `webhooks.queue.batchAck(eventIds)` — Batch acknowledge
|
|
401
|
-
|
|
402
|
-
```typescript
|
|
403
|
-
const ids = queue.items.map((e) => e.id);
|
|
404
|
-
await client.webhooks.queue.batchAck(ids);
|
|
405
|
-
// Returns void (HTTP 204)
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
#### `webhooks.queue.pullAll(params?)` — Cross-firm queue (integrator)
|
|
409
|
-
|
|
410
|
-
Fetch events across all firms linked to an integrator key.
|
|
411
|
-
|
|
412
|
-
```typescript
|
|
413
|
-
const queue = await client.webhooks.queue.pullAll({
|
|
414
|
-
limit: 200, // 1–500, default 100
|
|
415
|
-
since: "2026-04-01T00:00:00Z",
|
|
416
|
-
});
|
|
417
|
-
for (const event of queue.events) {
|
|
418
|
-
console.log(event.firm_id, event.event, event.payload);
|
|
419
|
-
}
|
|
420
|
-
// → { events: [{ event_id, firm_id, event, payload, created_at }], count }
|
|
421
|
-
```
|
|
422
198
|
|
|
423
|
-
|
|
199
|
+
// Batch acknowledge
|
|
200
|
+
await client.webhooks.queue.batchAck(queue.items.map((e) => e.id));
|
|
424
201
|
|
|
425
|
-
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
202
|
+
// Cross-firm (integrator)
|
|
203
|
+
const allEvents = await client.webhooks.queue.pullAll({ limit: 200 });
|
|
204
|
+
await client.webhooks.queue.batchAckAll(
|
|
205
|
+
allEvents.events.map((e) => e.event_id),
|
|
206
|
+
);
|
|
429
207
|
```
|
|
430
208
|
|
|
431
|
-
---
|
|
432
|
-
|
|
433
209
|
### Reporting
|
|
434
210
|
|
|
435
|
-
#### `reporting.statistics(params?)` — Aggregated stats
|
|
436
|
-
|
|
437
211
|
```typescript
|
|
438
212
|
const stats = await client.reporting.statistics({
|
|
439
213
|
from: "2026-01-01",
|
|
440
214
|
to: "2026-03-31",
|
|
441
215
|
});
|
|
442
|
-
// → { period: { from, to },
|
|
443
|
-
// outbound: { total, delivered, failed },
|
|
444
|
-
// inbound: { total, acknowledged, pending } }
|
|
445
216
|
```
|
|
446
217
|
|
|
447
|
-
---
|
|
448
|
-
|
|
449
218
|
### Account
|
|
450
219
|
|
|
451
|
-
#### `account.get()` — Account info
|
|
452
|
-
|
|
453
220
|
```typescript
|
|
454
221
|
const account = await client.account.get();
|
|
455
|
-
// → { firm: { name, ico, peppolId, peppolStatus },
|
|
456
|
-
// plan: { name, status },
|
|
457
|
-
// usage: { outbound, inbound } }
|
|
458
222
|
```
|
|
459
223
|
|
|
460
|
-
---
|
|
461
|
-
|
|
462
224
|
### Extract (AI OCR)
|
|
463
225
|
|
|
464
|
-
Requires Enterprise plan.
|
|
465
|
-
|
|
466
|
-
#### `extract.single(file, mimeType, fileName?)` — Single file
|
|
467
|
-
|
|
468
226
|
```typescript
|
|
469
227
|
import { readFileSync } from "fs";
|
|
470
228
|
|
|
471
|
-
|
|
229
|
+
// Single file
|
|
472
230
|
const result = await client.extract.single(
|
|
473
|
-
pdf,
|
|
231
|
+
readFileSync("invoice.pdf"),
|
|
474
232
|
"application/pdf",
|
|
475
233
|
"invoice.pdf",
|
|
476
234
|
);
|
|
477
|
-
// → { extraction: {...}, ubl_xml: string, confidence: number, file_name: string }
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
Supported MIME types: `application/pdf`, `image/jpeg`, `image/png`, `image/webp`. Max 20 MB.
|
|
481
|
-
|
|
482
|
-
#### `extract.batch(files)` — Batch extraction (server-side)
|
|
483
235
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
```typescript
|
|
487
|
-
const result = await client.extract.batch([
|
|
236
|
+
// Batch (up to 10 files, server-side)
|
|
237
|
+
const batch = await client.extract.batch([
|
|
488
238
|
{ file: pdfBuffer, mimeType: "application/pdf", fileName: "inv1.pdf" },
|
|
489
|
-
{ file:
|
|
239
|
+
{ file: imgBuffer, mimeType: "image/png", fileName: "inv2.png" },
|
|
490
240
|
]);
|
|
491
|
-
// → { batch_id, total, successful, failed,
|
|
492
|
-
// results: [{ file_name, extraction?, ubl_xml?, confidence?, error? }] }
|
|
493
241
|
```
|
|
494
242
|
|
|
495
243
|
---
|
|
496
244
|
|
|
497
245
|
## Integrator Mode
|
|
498
246
|
|
|
499
|
-
Use `sk_int_*` keys to act on behalf of client firms. Integrator keys unlock multi-tenant endpoints.
|
|
500
|
-
|
|
501
247
|
```typescript
|
|
502
|
-
// Option 1:
|
|
503
|
-
const client = new EPostak({
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
const clientA = base.withFirm('firm-uuid-a');
|
|
508
|
-
const clientB = base.withFirm('firm-uuid-b');
|
|
248
|
+
// Option 1: firmId in constructor
|
|
249
|
+
const client = new EPostak({
|
|
250
|
+
apiKey: "sk_int_xxxxx",
|
|
251
|
+
firmId: "client-firm-uuid",
|
|
252
|
+
});
|
|
509
253
|
|
|
510
|
-
|
|
511
|
-
|
|
254
|
+
// Option 2: withFirm() for switching
|
|
255
|
+
const base = new EPostak({ apiKey: "sk_int_xxxxx" });
|
|
256
|
+
const clientA = base.withFirm("firm-uuid-a");
|
|
257
|
+
const clientB = base.withFirm("firm-uuid-b");
|
|
512
258
|
```
|
|
513
259
|
|
|
514
|
-
### Integrator-only endpoints
|
|
515
|
-
|
|
516
|
-
These endpoints require an integrator key (`sk_int_*`) and operate across all linked firms:
|
|
517
|
-
|
|
518
|
-
| Method | Description |
|
|
519
|
-
| --------------------------------- | -------------------------------------- |
|
|
520
|
-
| `firms.assign({ ico })` | Link a firm to the integrator |
|
|
521
|
-
| `firms.assignBatch({ icos })` | Batch link firms (max 50) |
|
|
522
|
-
| `documents.inbox.listAll()` | Cross-firm inbox with `firm_id` filter |
|
|
523
|
-
| `webhooks.queue.pullAll()` | Cross-firm event queue |
|
|
524
|
-
| `webhooks.queue.batchAckAll(ids)` | Cross-firm batch acknowledge |
|
|
525
|
-
|
|
526
260
|
---
|
|
527
261
|
|
|
528
262
|
## Error Handling
|
|
529
263
|
|
|
530
|
-
All errors are thrown as `EPostakError`:
|
|
531
|
-
|
|
532
264
|
```typescript
|
|
533
|
-
import { EPostak, EPostakError } from
|
|
265
|
+
import { EPostak, EPostakError } from "@epostak/sdk";
|
|
534
266
|
|
|
535
267
|
try {
|
|
536
268
|
await client.documents.send({ ... });
|
|
537
269
|
} catch (err) {
|
|
538
270
|
if (err instanceof EPostakError) {
|
|
539
|
-
console.error(err.status); // HTTP status
|
|
540
|
-
console.error(err.code); //
|
|
541
|
-
console.error(err.message); // Human-readable
|
|
542
|
-
console.error(err.details); // Validation details (
|
|
271
|
+
console.error(err.status); // HTTP status (0 for network errors)
|
|
272
|
+
console.error(err.code); // e.g. 'VALIDATION_ERROR'
|
|
273
|
+
console.error(err.message); // Human-readable
|
|
274
|
+
console.error(err.details); // Validation details (422)
|
|
543
275
|
}
|
|
544
276
|
}
|
|
545
277
|
```
|
|
546
278
|
|
|
547
|
-
### Common error codes
|
|
548
|
-
|
|
549
|
-
| Status | Code | Meaning |
|
|
550
|
-
| ------ | ---------------------- | ------------------------------------------------ |
|
|
551
|
-
| 400 | `BAD_REQUEST` | Invalid request body or parameters |
|
|
552
|
-
| 401 | `UNAUTHORIZED` | Missing or invalid API key |
|
|
553
|
-
| 403 | `FORBIDDEN` | Insufficient permissions or wrong plan |
|
|
554
|
-
| 404 | `NOT_FOUND` | Resource not found |
|
|
555
|
-
| 409 | `CONFLICT` | Duplicate operation (e.g. firm already assigned) |
|
|
556
|
-
| 422 | `UNPROCESSABLE_ENTITY` | Validation failed (check `err.details`) |
|
|
557
|
-
| 429 | `RATE_LIMITED` | Too many requests |
|
|
558
|
-
| 503 | `SERVICE_UNAVAILABLE` | Extraction service not configured |
|
|
559
|
-
|
|
560
|
-
---
|
|
561
|
-
|
|
562
|
-
## TypeScript Support
|
|
563
|
-
|
|
564
|
-
The SDK is written in TypeScript with strict mode. All request params and response shapes are fully typed:
|
|
565
|
-
|
|
566
|
-
```typescript
|
|
567
|
-
import type {
|
|
568
|
-
SendDocumentJsonRequest,
|
|
569
|
-
InboxDocument,
|
|
570
|
-
InboxAllDocument,
|
|
571
|
-
PeppolParticipant,
|
|
572
|
-
Webhook,
|
|
573
|
-
WebhookQueueItem,
|
|
574
|
-
Statistics,
|
|
575
|
-
Account,
|
|
576
|
-
ExtractResult,
|
|
577
|
-
BatchExtractResult,
|
|
578
|
-
} from "@epostak/sdk";
|
|
579
|
-
```
|
|
580
|
-
|
|
581
279
|
---
|
|
582
280
|
|
|
583
|
-
## Full
|
|
281
|
+
## Full Endpoint Map
|
|
584
282
|
|
|
585
|
-
|
|
|
283
|
+
| Method | HTTP | Path |
|
|
586
284
|
| ---------------------------------- | ------ | ------------------------------------ |
|
|
587
285
|
| `documents.get(id)` | GET | `/documents/{id}` |
|
|
588
286
|
| `documents.update(id, body)` | PATCH | `/documents/{id}` |
|
|
@@ -623,10 +321,10 @@ import type {
|
|
|
623
321
|
| `extract.single(file, mime)` | POST | `/extract` |
|
|
624
322
|
| `extract.batch(files)` | POST | `/extract/batch` |
|
|
625
323
|
|
|
626
|
-
All paths
|
|
324
|
+
All paths relative to `https://epostak.sk/api/enterprise`.
|
|
627
325
|
|
|
628
326
|
---
|
|
629
327
|
|
|
630
|
-
##
|
|
328
|
+
## License
|
|
631
329
|
|
|
632
|
-
|
|
330
|
+
MIT
|