SDK overview
SDK overview
@e-bon/sdk is the official TypeScript client for the e-bon REST API and events WebSocket. It is the same library used internally by the e-bon Portal and is the recommended way to talk to https://api.e-bon.ro from any TypeScript or modern JavaScript runtime (Node 22+, Deno, Bun, modern browsers).
What the SDK gives you on top of raw fetch:
- A typed
EBonClientwith one accessor per resource (devices,commands,receipts, …). - Automatic auth header handling — pass an API key or a JWT once and forget about it.
- A real
EBonApiErrorexception withstatus,code,detailsandretryAfterso you can branch on the error envelope without parsing JSON yourself. - A
FiscalErrorexception for fiscal command failures, with a precomputedretryableflag. - An
EventSubscriberthat wraps the events WebSocket with auto-reconnect and typed event payloads.
The SDK is a thin, faithful mapping over the documented HTTP API. Everything it does is also possible with curl — see the API overview for the wire-level reference.
Install
pnpm add @e-bon/sdk
The package is also installable with npm install @e-bon/sdk or yarn add @e-bon/sdk. It has a single runtime dependency (@e-bon/types) and ships with TypeScript declarations.
fetch and native WebSocket. On Node it requires Node 22 or newer. There is no polyfill bundled — if you need to run on older Node, install a global fetch and WebSocket polyfill before importing the SDK.Instantiate the client
EBonClient is the single entry point. It takes an EBonClientOptions object with one of two auth modes — never both at once.
With an API key (POS partners, server integrations)
import { EBonClient } from '@e-bon/sdk';
const client = new EBonClient({
baseUrl: 'https://api.e-bon.ro',
apiKey: 'ebon_live_<orgId>_<32-hex>',
});
The SDK sends the key as X-API-Key on every request. This is the mode you want for any unattended backend.
With a JWT (portal sessions, the mobile app)
import { EBonClient } from '@e-bon/sdk';
const client = new EBonClient({
baseUrl: 'https://api.e-bon.ro',
token: 'eyJ...',
});
The SDK sends the token as Authorization: Bearer <token>. After a refresh, push the new access token into the same client without re-creating it:
client.setToken('eyJ...new-access-token');
Configure other options
| Option | Type | Default | Meaning |
|---|---|---|---|
baseUrl | string | — | Required. The API base URL (https://api.e-bon.ro in production). |
apiKey | string | — | API key. Mutually exclusive with token. |
token | string | — | JWT access token. Mutually exclusive with apiKey. |
timeout | number | 30000 | Per-request timeout in milliseconds. Aborts via AbortController. |
If you pass neither apiKey nor token, every request will fail with 401 UNAUTHORIZED. If baseUrl is missing the constructor throws synchronously.
Access resources
EBonClient exposes ten typed resource accessors. Each one wraps a slice of /api/v1/* and returns plain TypeScript objects backed by the types in @e-bon/types.
| Accessor | Wraps | Purpose |
|---|---|---|
client.devices | /api/v1/devices/* | Device CRUD, status, commands, receipts, alerts, header/footer, VAT, operator. → reference |
client.commands | /api/v1/commands/* | Submit fiscal commands, list, poll a single command, cancel a pending one. → reference |
client.receipts | /api/v1/receipts/* | Store and retrieve receipts. → reference |
client.reports | /api/v1/reports/* | X / Z / JE / MF report management and ANAF XML downloads. → reference |
client.billing | /api/v1/billing/* | Stripe subscriptions, invoices and the customer-portal redirect. → reference |
client.org | /api/v1/org/* | Organization profile, locations, notification settings. → reference |
client.apiKeys | /api/v1/api-keys/* | Programmatic API-key management (Owners and Admins only). → reference |
client.appInstances | /api/v1/app-instances/* | Connected E-BON mobile-app instances. → reference |
client.users | /api/v1/users/* | Authenticated user profile, settings, password change. → reference |
client.webhooks | /api/v1/org/webhooks/* | Webhook subscription management and delivery history. → reference |
Every accessor is constructed once when you instantiate EBonClient; they are stable references you can safely store on a long-lived object.
Handle errors
Every HTTP call routes through the same handler and surfaces errors as one of two concrete classes:
EBonApiError— wraps any non-2xx HTTP response. Carriesstatus,code(matches the HTTP error catalogue),message,detailsand, on429,retryAfter(seconds).FiscalError— surfaced when a fiscal command fails on the printer. Carriescode(ErrorCodeenum),message,retryable,commandIdanddeviceId.
The retryable flag on FiscalError is precomputed from the RETRYABLE_ERRORS set in @e-bon/types, so you can branch directly:
import { FiscalError, isRetryable } from '@e-bon/sdk';
try {
await client.commands.send({ deviceId, type: 'print_receipt', payload });
} catch (err) {
if (err instanceof FiscalError && err.retryable) {
// Safe to re-send with the same Idempotency-Key
} else {
throw err;
}
}
The full catalogue of error codes, the retry pattern and the EBonApiError shape live on the Errors page.
Subscribe to real-time events
EBonClient carries a small events accessor that hands you an EventSubscriber connected to the events WebSocket using the same credentials as the HTTP client:
const events = client.events.subscribe();
events.on('receipt.created', (data) => console.log('receipt', data.receiptId));
events.on('command.failed', (data) => console.error('failed', data.fiscalError));
events.close();
The subscriber reconnects automatically with exponential backoff. The full event catalogue, payload types and reconnect semantics are documented on the Events page.
Where to next
- Getting started — install, get an API key, instantiate the client and issue your first receipt.
- Events —
EventSubscriber, the typedEventMapand auto-reconnect. - Errors —
FiscalError,EBonApiErrorand the recommended retry pattern. - API overview — the wire-level REST reference the SDK is built on.
- Receipts, Commands, Devices — per-resource HTTP references with request and response schemas.
Commands
REST endpoints for queueing fiscal commands against an AMEF — submit a command, list and filter the queue, poll a single command for completion, and cancel a pending one.
Manage subscriptions and invoices
Start Stripe Checkout sessions, open the customer portal, check subscription status, list invoices, and cancel or reactivate subscriptions from the SDK.