@beel_es/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/LICENSE +21 -0
- package/README.md +167 -76
- package/dist/index.d.mts +9744 -0
- package/dist/index.d.ts +9736 -18
- package/dist/index.js +801 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +756 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +48 -19
- package/dist/client.d.ts +0 -54
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -94
- package/dist/client.js.map +0 -1
- package/dist/generated/client/client.gen.d.ts +0 -3
- package/dist/generated/client/client.gen.d.ts.map +0 -1
- package/dist/generated/client/client.gen.js +0 -240
- package/dist/generated/client/client.gen.js.map +0 -1
- package/dist/generated/client/index.d.ts +0 -9
- package/dist/generated/client/index.d.ts.map +0 -1
- package/dist/generated/client/index.js +0 -18
- package/dist/generated/client/index.js.map +0 -1
- package/dist/generated/client/types.gen.d.ts +0 -118
- package/dist/generated/client/types.gen.d.ts.map +0 -1
- package/dist/generated/client/types.gen.js +0 -4
- package/dist/generated/client/types.gen.js.map +0 -1
- package/dist/generated/client/utils.gen.d.ts +0 -34
- package/dist/generated/client/utils.gen.d.ts.map +0 -1
- package/dist/generated/client/utils.gen.js +0 -242
- package/dist/generated/client/utils.gen.js.map +0 -1
- package/dist/generated/client.gen.d.ts +0 -13
- package/dist/generated/client.gen.d.ts.map +0 -1
- package/dist/generated/client.gen.js +0 -7
- package/dist/generated/client.gen.js.map +0 -1
- package/dist/generated/core/auth.gen.d.ts +0 -19
- package/dist/generated/core/auth.gen.d.ts.map +0 -1
- package/dist/generated/core/auth.gen.js +0 -19
- package/dist/generated/core/auth.gen.js.map +0 -1
- package/dist/generated/core/bodySerializer.gen.d.ts +0 -26
- package/dist/generated/core/bodySerializer.gen.d.ts.map +0 -1
- package/dist/generated/core/bodySerializer.gen.js +0 -61
- package/dist/generated/core/bodySerializer.gen.js.map +0 -1
- package/dist/generated/core/params.gen.d.ts +0 -44
- package/dist/generated/core/params.gen.d.ts.map +0 -1
- package/dist/generated/core/params.gen.js +0 -105
- package/dist/generated/core/params.gen.js.map +0 -1
- package/dist/generated/core/pathSerializer.gen.d.ts +0 -34
- package/dist/generated/core/pathSerializer.gen.d.ts.map +0 -1
- package/dist/generated/core/pathSerializer.gen.js +0 -116
- package/dist/generated/core/pathSerializer.gen.js.map +0 -1
- package/dist/generated/core/queryKeySerializer.gen.d.ts +0 -19
- package/dist/generated/core/queryKeySerializer.gen.d.ts.map +0 -1
- package/dist/generated/core/queryKeySerializer.gen.js +0 -99
- package/dist/generated/core/queryKeySerializer.gen.js.map +0 -1
- package/dist/generated/core/serverSentEvents.gen.d.ts +0 -72
- package/dist/generated/core/serverSentEvents.gen.d.ts.map +0 -1
- package/dist/generated/core/serverSentEvents.gen.js +0 -138
- package/dist/generated/core/serverSentEvents.gen.js.map +0 -1
- package/dist/generated/core/types.gen.d.ts +0 -79
- package/dist/generated/core/types.gen.d.ts.map +0 -1
- package/dist/generated/core/types.gen.js +0 -4
- package/dist/generated/core/types.gen.js.map +0 -1
- package/dist/generated/core/utils.gen.d.ts +0 -20
- package/dist/generated/core/utils.gen.d.ts.map +0 -1
- package/dist/generated/core/utils.gen.js +0 -94
- package/dist/generated/core/utils.gen.js.map +0 -1
- package/dist/generated/index.d.ts +0 -3
- package/dist/generated/index.d.ts.map +0 -1
- package/dist/generated/index.js +0 -84
- package/dist/generated/index.js.map +0 -1
- package/dist/generated/sdk.gen.d.ts +0 -966
- package/dist/generated/sdk.gen.d.ts.map +0 -1
- package/dist/generated/sdk.gen.js +0 -1490
- package/dist/generated/sdk.gen.js.map +0 -1
- package/dist/generated/types.gen.d.ts +0 -5646
- package/dist/generated/types.gen.d.ts.map +0 -1
- package/dist/generated/types.gen.js +0 -4
- package/dist/generated/types.gen.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/resources/companies.d.ts +0 -75
- package/dist/resources/companies.d.ts.map +0 -1
- package/dist/resources/companies.js +0 -77
- package/dist/resources/companies.js.map +0 -1
- package/dist/resources/config.d.ts +0 -106
- package/dist/resources/config.d.ts.map +0 -1
- package/dist/resources/config.js +0 -86
- package/dist/resources/config.js.map +0 -1
- package/dist/resources/customers.d.ts +0 -172
- package/dist/resources/customers.d.ts.map +0 -1
- package/dist/resources/customers.js +0 -96
- package/dist/resources/customers.js.map +0 -1
- package/dist/resources/invoices.d.ts +0 -370
- package/dist/resources/invoices.d.ts.map +0 -1
- package/dist/resources/invoices.js +0 -174
- package/dist/resources/invoices.js.map +0 -1
- package/dist/resources/products.d.ts +0 -155
- package/dist/resources/products.d.ts.map +0 -1
- package/dist/resources/products.js +0 -96
- package/dist/resources/products.js.map +0 -1
- package/dist/resources/series.d.ts +0 -98
- package/dist/resources/series.d.ts.map +0 -1
- package/dist/resources/series.js +0 -83
- package/dist/resources/series.js.map +0 -1
- package/dist/webhooks/index.d.ts +0 -20
- package/dist/webhooks/index.d.ts.map +0 -1
- package/dist/webhooks/index.js +0 -70
- package/dist/webhooks/index.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 BeeL - Facturación para Autónomos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,131 +1,222 @@
|
|
|
1
|
-
# BeeL
|
|
1
|
+
# BeeL Node.js SDK
|
|
2
2
|
|
|
3
|
-
[](https://www.typescriptlang.org/)
|
|
3
|
+
[](https://www.npmjs.com/package/@beel_es/sdk)
|
|
5
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
6
|
|
|
7
|
-
Official TypeScript
|
|
7
|
+
Official Node.js/TypeScript SDK for the [BeeL API](https://beel.es) — Spanish invoicing for self-employed professionals with VeriFactu compliance.
|
|
8
|
+
|
|
9
|
+
**Node.js 18+. Single dependency ([openapi-fetch](https://openapi-ts.dev/openapi-fetch/)).**
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Full TypeScript types** auto-generated from OpenAPI spec
|
|
14
|
+
- **Automatic retries** with exponential backoff on 429 and 5xx
|
|
15
|
+
- **Auto idempotency keys** on every POST request
|
|
16
|
+
- **Typed errors** — catch `BeeLNotFoundError` instead of checking status codes
|
|
17
|
+
- **PDF download** as Buffer
|
|
18
|
+
- **Webhook signature verification** with HMAC-SHA256
|
|
19
|
+
- **Instance-based client** — multiple API keys, no global state
|
|
20
|
+
- **ESM + CommonJS**
|
|
8
21
|
|
|
9
22
|
## Installation
|
|
10
23
|
|
|
11
24
|
```bash
|
|
12
|
-
npm install @
|
|
25
|
+
npm install @beel_es/sdk
|
|
13
26
|
```
|
|
14
27
|
|
|
15
28
|
## Quick Start
|
|
16
29
|
|
|
17
30
|
```typescript
|
|
18
|
-
import { BeeL } from '@
|
|
31
|
+
import { BeeL } from '@beel_es/sdk';
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
const beel = await BeeL.create('beel_sk_live_...');
|
|
33
|
+
const beel = new BeeL({ apiKey: 'beel_sk_live_...' });
|
|
22
34
|
|
|
23
|
-
//
|
|
24
|
-
const
|
|
35
|
+
// Create a draft invoice
|
|
36
|
+
const invoice = await beel.invoices.create({
|
|
37
|
+
type: 'STANDARD',
|
|
38
|
+
recipient: { customer_id: 'customer-uuid' },
|
|
39
|
+
lines: [
|
|
40
|
+
{ description: 'Consulting', quantity: 1, unit_price: 100, discount_percentage: 0 },
|
|
41
|
+
],
|
|
42
|
+
});
|
|
25
43
|
|
|
26
|
-
//
|
|
27
|
-
const invoice = await beel.invoices.get('550e8400-e29b-41d4-a716-446655440000');
|
|
28
|
-
```
|
|
44
|
+
console.log(invoice.id); // UUID assigned immediately
|
|
29
45
|
|
|
30
|
-
|
|
46
|
+
// Issue it to assign an invoice number and trigger VeriFactu
|
|
47
|
+
const issued = await beel.invoices.issue(invoice.id);
|
|
48
|
+
console.log(issued.invoice_number); // e.g. "A-2026/0001"
|
|
49
|
+
```
|
|
31
50
|
|
|
32
|
-
|
|
51
|
+
## Resources
|
|
33
52
|
|
|
34
53
|
```typescript
|
|
35
|
-
//
|
|
36
|
-
const invoices = await beel.invoices.list({
|
|
37
|
-
|
|
54
|
+
// Invoices
|
|
55
|
+
const { invoices, pagination } = await beel.invoices.list({ status: 'ISSUED', limit: 20 });
|
|
56
|
+
const invoice = await beel.invoices.get('invoice-uuid');
|
|
57
|
+
const created = await beel.invoices.create({ ... });
|
|
58
|
+
const updated = await beel.invoices.update('id', { ... });
|
|
59
|
+
await beel.invoices.delete('id');
|
|
60
|
+
|
|
61
|
+
// Invoice lifecycle
|
|
62
|
+
await beel.invoices.issue('id');
|
|
63
|
+
await beel.invoices.markPaid('id');
|
|
64
|
+
await beel.invoices.markSent('id');
|
|
65
|
+
await beel.invoices.void('id', { reason: 'Duplicate invoice sent in error' });
|
|
66
|
+
await beel.invoices.schedule('id', { scheduled_for: '2026-04-15' });
|
|
67
|
+
await beel.invoices.unschedule('id');
|
|
68
|
+
await beel.invoices.duplicate('id');
|
|
69
|
+
await beel.invoices.createCorrective('id', { ... });
|
|
70
|
+
|
|
71
|
+
// Customers
|
|
72
|
+
const { customers, pagination } = await beel.customers.list({ search: 'Acme' });
|
|
73
|
+
const customer = await beel.customers.create({
|
|
74
|
+
legal_name: 'Acme SL',
|
|
75
|
+
nif: 'B86561412',
|
|
76
|
+
address: { street: 'Calle Mayor', number: '1', postal_code: '28001', city: 'Madrid', province: 'Madrid', country: 'Spain', country_code: 'ES' },
|
|
38
77
|
});
|
|
39
78
|
|
|
40
|
-
//
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
customer_id: 'uuid',
|
|
44
|
-
issue_date: '2026-03-10',
|
|
45
|
-
lines: [{ description: 'Service', quantity: 1, unit_price: 100 }]
|
|
46
|
-
}
|
|
47
|
-
});
|
|
79
|
+
// Products
|
|
80
|
+
const { products } = await beel.products.list();
|
|
81
|
+
const results = await beel.products.search('consulting');
|
|
48
82
|
|
|
49
|
-
//
|
|
50
|
-
await beel.
|
|
51
|
-
await beel.
|
|
52
|
-
await beel.invoices.markPaid('invoice-id', { body: { payment_date: '2026-03-10' } });
|
|
83
|
+
// Configuration
|
|
84
|
+
const taxConfig = await beel.configuration.getTaxConfig();
|
|
85
|
+
const series = await beel.series.list();
|
|
53
86
|
|
|
54
|
-
//
|
|
55
|
-
const
|
|
87
|
+
// NIF validation
|
|
88
|
+
const result = await beel.nif.validate('B12345678');
|
|
56
89
|
```
|
|
57
90
|
|
|
58
|
-
|
|
91
|
+
## Typed Errors
|
|
92
|
+
|
|
93
|
+
Every API error maps to a specific error class:
|
|
59
94
|
|
|
60
95
|
```typescript
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
await beel.
|
|
96
|
+
import { BeeL, BeeLNotFoundError, BeeLValidationError } from '@beel_es/sdk';
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
await beel.invoices.get('nonexistent-id');
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error instanceof BeeLNotFoundError) {
|
|
102
|
+
console.log(error.message); // "Invoice not found"
|
|
103
|
+
console.log(error.requestId); // "abc123" (for support)
|
|
104
|
+
}
|
|
105
|
+
if (error instanceof BeeLValidationError) {
|
|
106
|
+
console.log(error.message); // "El NIF no tiene un formato válido"
|
|
107
|
+
console.log(error.details); // { field: "nif", invalid_value: "..." }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
65
110
|
```
|
|
66
111
|
|
|
67
|
-
|
|
112
|
+
| Error class | Status | When |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| `BeeLAuthError` | 401, 403 | Invalid or missing API key |
|
|
115
|
+
| `BeeLNotFoundError` | 404 | Resource doesn't exist |
|
|
116
|
+
| `BeeLValidationError` | 422 | Invalid data |
|
|
117
|
+
| `BeeLConflictError` | 409 | Duplicate (e.g. same NIF) |
|
|
118
|
+
| `BeeLRateLimitError` | 429 | Too many requests (auto-retried) |
|
|
119
|
+
| `BeeLApiError` | 5xx | Server error (auto-retried) |
|
|
68
120
|
|
|
69
|
-
|
|
70
|
-
const products = await beel.products.list();
|
|
71
|
-
const results = await beel.products.search({ query: { q: 'hosting' } });
|
|
72
|
-
```
|
|
121
|
+
## Automatic Retries
|
|
73
122
|
|
|
74
|
-
|
|
123
|
+
429 and 5xx errors are retried with exponential backoff. Client errors (400, 401, 404, 422) are never retried.
|
|
75
124
|
|
|
76
125
|
```typescript
|
|
77
|
-
const
|
|
78
|
-
|
|
126
|
+
const beel = new BeeL({
|
|
127
|
+
apiKey: 'beel_sk_live_...',
|
|
128
|
+
maxRetries: 5, // default: 3
|
|
129
|
+
retryDelayMs: 1000, // default: 500
|
|
130
|
+
maxRetryDelayMs: 60000, // default: 30000
|
|
131
|
+
});
|
|
79
132
|
```
|
|
80
133
|
|
|
81
|
-
|
|
134
|
+
## PDF Download
|
|
82
135
|
|
|
83
136
|
```typescript
|
|
84
|
-
|
|
85
|
-
|
|
137
|
+
import fs from 'fs';
|
|
138
|
+
|
|
139
|
+
const { buffer, fileName } = await beel.downloadPdf('invoice-uuid');
|
|
140
|
+
fs.writeFileSync(fileName, buffer);
|
|
141
|
+
// => factura_A-2026-0001.pdf
|
|
86
142
|
```
|
|
87
143
|
|
|
88
|
-
##
|
|
144
|
+
## Webhooks
|
|
145
|
+
|
|
146
|
+
Verify webhook signatures before processing:
|
|
89
147
|
|
|
90
148
|
```typescript
|
|
91
|
-
import
|
|
149
|
+
import express from 'express';
|
|
150
|
+
import { WebhookVerifier } from '@beel_es/sdk';
|
|
92
151
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
152
|
+
const verifier = new WebhookVerifier(process.env.BEEL_WEBHOOK_SECRET!);
|
|
153
|
+
|
|
154
|
+
app.post('/webhooks/beel', express.raw({ type: 'application/json' }), (req, res) => {
|
|
155
|
+
try {
|
|
156
|
+
const event = verifier.verify(
|
|
157
|
+
req.body.toString('utf8'),
|
|
158
|
+
req.headers['beel-signature'] as string,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
if (event.type === 'verifactu.status.updated') {
|
|
162
|
+
console.log(event.data.new_status); // 'ACCEPTED' | 'REJECTED'
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
res.status(200).send('OK');
|
|
166
|
+
} catch {
|
|
167
|
+
res.status(400).send('Invalid signature');
|
|
99
168
|
}
|
|
100
|
-
}
|
|
169
|
+
});
|
|
101
170
|
```
|
|
102
171
|
|
|
103
|
-
##
|
|
172
|
+
## Builders
|
|
173
|
+
|
|
174
|
+
Optional fluent builders for common operations:
|
|
104
175
|
|
|
105
176
|
```typescript
|
|
106
|
-
|
|
107
|
-
|
|
177
|
+
import { InvoiceBuilder, CustomerBuilder } from '@beel_es/sdk';
|
|
178
|
+
|
|
179
|
+
const customer = CustomerBuilder.create()
|
|
180
|
+
.name('Acme SL')
|
|
181
|
+
.nif('B12345678')
|
|
182
|
+
.email('contact@acme.com')
|
|
183
|
+
.address('Calle Mayor', '1', '28001', 'Madrid', 'Madrid', 'Spain')
|
|
184
|
+
.build();
|
|
185
|
+
|
|
186
|
+
const invoice = InvoiceBuilder.create()
|
|
187
|
+
.forCustomer('customer-uuid')
|
|
188
|
+
.addLine('Service A', 5, 100.0)
|
|
189
|
+
.addLine('Service B', 3, 150.0)
|
|
190
|
+
.metadata({ stripe_id: 'pi_abc123' })
|
|
191
|
+
.build();
|
|
192
|
+
```
|
|
108
193
|
|
|
109
|
-
|
|
110
|
-
const beel = await BeeL.create({
|
|
111
|
-
apiKey: 'beel_sk_live_...',
|
|
112
|
-
baseUrl: 'https://test.beel.es/api',
|
|
113
|
-
});
|
|
194
|
+
## Environments
|
|
114
195
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
196
|
+
```typescript
|
|
197
|
+
// Sandbox — no VeriFactu quota consumed, safe to test
|
|
198
|
+
const sandbox = new BeeL({ apiKey: 'beel_sk_test_...' });
|
|
199
|
+
|
|
200
|
+
// Production
|
|
201
|
+
const prod = new BeeL({ apiKey: 'beel_sk_live_...' });
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Full Configuration
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
const beel = new BeeL({
|
|
208
|
+
apiKey: 'beel_sk_live_...', // Required
|
|
209
|
+
baseUrl: 'https://app.beel.es/api', // Default
|
|
210
|
+
maxRetries: 3, // Default
|
|
211
|
+
retryDelayMs: 500, // Default
|
|
212
|
+
maxRetryDelayMs: 30000, // Default
|
|
119
213
|
});
|
|
120
214
|
```
|
|
121
215
|
|
|
122
|
-
##
|
|
216
|
+
## Documentation
|
|
123
217
|
|
|
124
|
-
|
|
125
|
-
- TypeScript 5.0+ (optional but recommended)
|
|
218
|
+
Full API docs: [docs.beel.es](https://docs.beel.es)
|
|
126
219
|
|
|
127
|
-
##
|
|
220
|
+
## License
|
|
128
221
|
|
|
129
|
-
|
|
130
|
-
- [Website](https://beel.es)
|
|
131
|
-
- [Support](mailto:info@beel.es)
|
|
222
|
+
MIT
|