@beel_es/sdk 1.1.0 → 1.3.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 CHANGED
@@ -32,23 +32,155 @@ import { BeeL } from '@beel_es/sdk';
32
32
 
33
33
  const beel = new BeeL({ apiKey: 'beel_sk_live_...' });
34
34
 
35
+ // Address a company (NIF) explicitly — the recommended multi-NIF surface
36
+ const company = beel.company('company-uuid');
37
+
35
38
  // Create a draft invoice
36
- const invoice = await beel.invoices.create({
39
+ const invoice = await company.invoices.create({
37
40
  type: 'STANDARD',
38
41
  recipient: { customer_id: 'customer-uuid' },
39
42
  lines: [
40
- { description: 'Consulting', quantity: 1, unit_price: 100, discount_percentage: 0 },
43
+ { line_type: 'NORMAL', description: 'Consulting', quantity: 1, unit_price: 100, discount_percentage: 0 },
41
44
  ],
42
45
  });
43
46
 
44
47
  console.log(invoice.id); // UUID assigned immediately
45
48
 
46
49
  // Issue it to assign an invoice number and trigger VeriFactu
47
- const issued = await beel.invoices.issue(invoice.id);
50
+ const issued = await company.invoices.issue(invoice.id);
48
51
  console.log(issued.invoice_number); // e.g. "A-2026/0001"
49
52
  ```
50
53
 
51
- ## Resources
54
+ ## Companies (multi-NIF)
55
+
56
+ Every operation on `beel.company(companyId)` addresses the company in the URL path, so it
57
+ works with any number of NIFs and never depends on a session focus:
58
+
59
+ ```typescript
60
+ const company = beel.company('company-uuid');
61
+
62
+ // Invoices — full lifecycle
63
+ const { invoices, pagination } = await company.invoices.list({ status: 'ISSUED' });
64
+ await company.invoices.issue('invoice-uuid');
65
+ await company.invoices.void('invoice-uuid', { reason: 'Billing error' });
66
+ await company.invoices.createCorrective('invoice-uuid', { ... });
67
+ const pdf = await company.invoices.getPdf('invoice-uuid');
68
+
69
+ // Customers, products, series
70
+ const customer = await company.customers.create({ ... });
71
+ const product = await company.products.create({ ... });
72
+ await company.series.ensureDefaults(); // idempotent seeding of the typed default series
73
+
74
+ // Recurring invoices
75
+ await company.recurringInvoices.create({ ... });
76
+ await company.recurringInvoices.setStatus('rec-uuid', { status: 'PAUSED' });
77
+
78
+ // Scheduling — one PUT sets or moves it, one DELETE clears it
79
+ await company.invoices.schedule.set('invoice-uuid', { scheduled_for: '2026-12-01' });
80
+ await company.invoices.schedule.clear('invoice-uuid');
81
+
82
+ // Derive a new invoice from an existing one
83
+ const copy = await company.invoices.derive({ from_invoice_id: 'invoice-uuid' });
84
+
85
+ // Fiscal configuration of this NIF
86
+ const verifactu = await company.verifactuConfiguration.get();
87
+ await company.verifactuConfiguration.update({ enabled: true });
88
+ const taxes = await company.taxConfiguration.get();
89
+
90
+ // Company health
91
+ const summary = await company.fiscalSummary({ year: 2026 });
92
+ const readiness = await company.issuingReadiness();
93
+ ```
94
+
95
+ Whether an invoice reaches AEAT is a fact of the **NIF**, resolved at issue time — not a
96
+ per-invoice choice. `enabled` is the only writable field of the VeriFactu configuration.
97
+
98
+ ### Payment connections (Stripe per NIF)
99
+
100
+ A connection links Stripe to one NIF so its charges auto-generate invoices under it. It is
101
+ addressed by **its own UUID**, not by the provider slug — a NIF can hold several
102
+ connections of the same provider. The slug only appears when you start an authorization.
103
+
104
+ ```typescript
105
+ const { connections } = await company.paymentConnections.list();
106
+
107
+ const { authorization_url } = await company.paymentConnections.authorize({
108
+ provider: 'stripe',
109
+ });
110
+
111
+ const events = company.paymentConnections.events(connections[0].id);
112
+ const { events: pending } = await events.list({ needs_action: true });
113
+
114
+ // Recovery levers for a charge that did not invoice
115
+ await events.retry('event-uuid');
116
+ const { invoice_id } = await events.draft('event-uuid'); // review before issuing
117
+ await events.resolve('event-uuid');
118
+
119
+ await company.paymentConnections.disconnect(connections[0].id);
120
+ ```
121
+
122
+ ## Catalogs and preferences
123
+
124
+ ```typescript
125
+ const taxTypes = await beel.catalogs.taxTypes();
126
+ const options = await beel.catalogs.invoiceCustomizationOptions();
127
+ await beel.catalogs.updateMe({ language: 'es' }); // the language belongs to the person
128
+ ```
129
+
130
+ ## Any endpoint: `beel.raw`
131
+
132
+ A route reaches the generated types as soon as the contract is synced, but its ergonomic
133
+ wrapper is written by hand. `beel.raw` lets you call anything in the contract today,
134
+ without waiting for a release:
135
+
136
+ ```typescript
137
+ const { data } = await beel.raw.GET('/v1/companies/{company_id}/logo', {
138
+ params: { path: { company_id: 'company-uuid' } },
139
+ });
140
+ ```
141
+
142
+ It is the same client the resources use — authentication, retries and `Idempotency-Key`
143
+ still apply — and it stays typed: a path, parameter or body the contract does not have
144
+ will not compile. What you give up is the sugar and the naming stability of the wrappers.
145
+
146
+ ## Accounts (managed accounts, members & webhooks)
147
+
148
+ For integrators managing several accounts (provisioning, gestorías, platforms):
149
+
150
+ ```typescript
151
+ // List and provision managed accounts
152
+ const { accounts } = await beel.accounts.list();
153
+ const created = await beel.accounts.provision({ external_ref: 'client-42' });
154
+
155
+ // Scope to one account
156
+ const account = beel.account(created.account_id);
157
+
158
+ // Companies (NIFs) under the account
159
+ const { companies } = await account.companies.list();
160
+ await account.companies.create({ nif: 'B12345678', ... });
161
+
162
+ // Members, roles and per-company grants
163
+ const members = await account.members.list();
164
+ await account.members.putGrant('member-id', 'company-id', { permissions: [...] });
165
+
166
+ // Invitations
167
+ await account.invitations.create({ invited_email: 'user@example.com', account_role: 'MEMBER' });
168
+
169
+ // Account-scoped webhooks
170
+ const webhook = await account.webhooks.create({ url: 'https://...', events: ['invoice.issued'] });
171
+ await account.webhooks.test(webhook.id);
172
+ await account.webhooks.rotateSecret(webhook.id);
173
+
174
+ // Usage & ownership
175
+ const usage = await account.usage();
176
+ await account.createClaimToken(); // let the end user claim the account
177
+ ```
178
+
179
+ ## Resources (deprecated session-focus surface)
180
+
181
+ > **Deprecated:** the API contract marks the whole session-focus surface (`beel.invoices`,
182
+ > `beel.customers`, `beel.products`, `beel.series`, `beel.configuration`) as deprecated.
183
+ > Prefer the company-scoped equivalents above. These keep working during the sunset window.
52
184
 
53
185
  ```typescript
54
186
  // Invoices