@genz-its/sevdesk-sdk 0.0.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 +114 -0
- package/dist/index.d.ts +1990 -0
- package/dist/index.js +2017 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# @genz-its/sevdesk-sdk
|
|
2
|
+
|
|
3
|
+
Unofficial Node.js SDK for the [sevdesk](https://sevdesk.de/) API.[^1]
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🧩 **Complete resource coverage**: Vouchers, transactions, check accounts, contacts, invoices, credit notes, orders, parts, tags, exports, reports and receipt guidance.
|
|
8
|
+
- 🪶 **Zero dependencies**: Built on the native `fetch` API.
|
|
9
|
+
- 🔁 **Resilient**: Automatic retries with exponential backoff for network errors, `429` and `5xx` responses on idempotent requests.
|
|
10
|
+
- 🦺 **Fully typed**: Hand-written TypeScript types that reflect the actual API behavior, including the quirks the OpenAPI specification gets wrong.
|
|
11
|
+
- 🇩🇪 **sevdesk-Update 2.0**: Built for bookkeeping system version 2.0 (`taxRule`, `accountDatev`).
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Node.js 22 or later.
|
|
16
|
+
- A sevdesk account on bookkeeping system version 2.0 (sevdesk-Update 2.0).
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @genz-its/sevdesk-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { readFile } from 'node:fs/promises';
|
|
28
|
+
import { SevDesk } from '@genz-its/sevdesk-sdk';
|
|
29
|
+
|
|
30
|
+
const sevdesk = new SevDesk({ token: process.env.SEVDESK_TOKEN! });
|
|
31
|
+
|
|
32
|
+
// Upload a receipt and create an open voucher in one call
|
|
33
|
+
const { voucher } = await sevdesk.vouchers.createFromFile({
|
|
34
|
+
file: await readFile('receipt.pdf'),
|
|
35
|
+
filename: 'receipt.pdf',
|
|
36
|
+
voucher: {
|
|
37
|
+
status: 100,
|
|
38
|
+
creditDebit: 'C',
|
|
39
|
+
taxRuleId: 9,
|
|
40
|
+
supplierName: 'ACME GmbH',
|
|
41
|
+
voucherDate: new Date(),
|
|
42
|
+
},
|
|
43
|
+
positions: [{ accountDatevId: 26, taxRate: 19, net: false, sumGross: 119 }],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Find unbooked bank transactions
|
|
47
|
+
const transactions = await sevdesk.transactions.list({ isBooked: false });
|
|
48
|
+
|
|
49
|
+
// Book the voucher against a transaction
|
|
50
|
+
await sevdesk.vouchers.book({
|
|
51
|
+
voucherId: Number(voucher.id),
|
|
52
|
+
amount: 119,
|
|
53
|
+
date: new Date(),
|
|
54
|
+
type: 'FULL_PAYMENT',
|
|
55
|
+
checkAccountId: 1,
|
|
56
|
+
checkAccountTransactionId: Number(transactions[0].id),
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Client options
|
|
61
|
+
|
|
62
|
+
| Option | Description | Default |
|
|
63
|
+
| ----------- | --------------------------------------------------------------------- | ------------------------------ |
|
|
64
|
+
| `token` | The sevdesk API token, sent as raw `Authorization` header value. | – |
|
|
65
|
+
| `baseUrl` | The API base URL. | `https://my.sevdesk.de/api/v1` |
|
|
66
|
+
| `timeout` | Request timeout in milliseconds. | `30000` |
|
|
67
|
+
| `userAgent` | The `User-Agent` header value. | `@genz-its/sevdesk-sdk` |
|
|
68
|
+
| `fetch` | A custom `fetch` implementation, for example for testing or proxying. | `globalThis.fetch` |
|
|
69
|
+
|
|
70
|
+
### Resources
|
|
71
|
+
|
|
72
|
+
| Resource | Description |
|
|
73
|
+
| ------------------------- | -------------------------------------------------------------------- |
|
|
74
|
+
| `sevdesk.basics` | Detect the bookkeeping system version of the account. |
|
|
75
|
+
| `sevdesk.checkAccounts` | Manage check accounts and query balances. |
|
|
76
|
+
| `sevdesk.contacts` | Manage contacts and customer numbers. |
|
|
77
|
+
| `sevdesk.creditNotes` | Manage credit notes, send them, and book payments. |
|
|
78
|
+
| `sevdesk.exports` | Run DATEV export jobs and CSV exports. |
|
|
79
|
+
| `sevdesk.invoices` | Manage invoices, render PDFs, send them, and book payments. |
|
|
80
|
+
| `sevdesk.orders` | Manage orders and their positions. |
|
|
81
|
+
| `sevdesk.parts` | Manage parts and query stock. |
|
|
82
|
+
| `sevdesk.receiptGuidance` | Find bookable accounts (`AccountDatev`) and their allowed tax rules. |
|
|
83
|
+
| `sevdesk.reports` | Generate PDF reports. |
|
|
84
|
+
| `sevdesk.tags` | Manage tags and tag relations. |
|
|
85
|
+
| `sevdesk.transactions` | Manage check account transactions. |
|
|
86
|
+
| `sevdesk.vouchers` | Upload receipts, create and book vouchers. |
|
|
87
|
+
|
|
88
|
+
### Error handling
|
|
89
|
+
|
|
90
|
+
Any non-2xx response throws a `SevDeskError` with the HTTP `status`, `statusText`, the parsed response `body`, and a `message` extracted from the API error payload:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { SevDeskError } from '@genz-its/sevdesk-sdk';
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
await sevdesk.vouchers.get({ voucherId: 123 });
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error instanceof SevDeskError) {
|
|
99
|
+
console.error(error.status, error.message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Good to know
|
|
105
|
+
|
|
106
|
+
- The sevdesk API returns **all scalar values in responses as strings**, including IDs and amounts. The response types reflect that faithfully.
|
|
107
|
+
- Date fields accept `Date` objects, Unix timestamps or strings and are serialized per endpoint to what the API expects (`dd.mm.yyyy`/timestamp for vouchers, ISO 8601 for transactions).
|
|
108
|
+
- Use `sevdesk.basics.getBookkeepingSystemVersion()` to verify an account runs on version `2.0` — the SDK does not support the legacy 1.0 payload shapes (`taxType`, `accountingType`).
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
[MIT](../../LICENSE)
|
|
113
|
+
|
|
114
|
+
[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by sevDesk GmbH or any of their affiliates or subsidiaries.
|