client.commands
client.commands
client.commands wraps /api/v1/commands/* — the asynchronous fiscal-command queue. send returns immediately with a pending FiscalCommand record; the actual fiscal result arrives over the events WebSocket as command.completed / command.failed. See the matching REST documentation at Commands API and the real-time delivery contract at Events.
HTTP-level failures surface as EBonApiError. Fiscal failures (printer / protocol) surface on the events stream as FiscalError instances — see Errors and the catalogue at /en/api/errors.
client.commands.send(body)
Submit a fiscal command (async dispatch).
async send(body: SendCommandBody): Promise<SendCommandResult>
| Name | Type | Required | Notes |
|---|---|---|---|
deviceId | string | yes | Target device. |
type | CommandType | yes | Command kind — see @e-bon/types. |
payload | unknown | no | Command-specific payload (shape depends on type). |
Returns SendCommandResult — the created FiscalCommand plus a deviceOnline: boolean flag set from the device's status at queue time.
const cmd = await client.commands.send({
deviceId: 'dev_01HZ...',
type: 'print_receipt',
payload: { /* receipt body */ },
});
if (!cmd.deviceOnline) {
console.warn('Device was offline — command queued, will dispatch on reconnect.');
}
client.commands.list(query?)
List commands with optional filters.
async list(query?: ListCommandsQuery): Promise<FiscalCommand[]>
| Name | Type | Required | Notes |
|---|---|---|---|
deviceId | string | no | Filter by device. |
status | string | no | One of pending, sent, completed, failed, cancelled — see CommandStatus. |
type | string | no | Filter by CommandType. |
limit | number | no | Page size; server caps the maximum. |
Returns an array of FiscalCommand.
const recent = await client.commands.list({ status: 'failed', limit: 20 });
client.commands.get(id)
Get a single command by ID (poll for result).
async get(id: string): Promise<FiscalCommand>
| Name | Type | Required | Notes |
|---|---|---|---|
id | string | yes | Command identifier. |
Returns the current FiscalCommand snapshot. Prefer subscribing to events instead of polling at high frequency.
const cmd = await client.commands.get('cmd_01HZ...');
console.log(cmd.status);
client.commands.cancel(id)
Cancel a pending/sent command.
async cancel(id: string): Promise<FiscalCommand>
| Name | Type | Required | Notes |
|---|---|---|---|
id | string | yes | Command identifier. |
Returns the updated FiscalCommand (status moves to cancelled if the command had not yet been dispatched).
await client.commands.cancel('cmd_01HZ...');
client.devices
Reference for client.devices — every method with TypeScript signatures, parameters and Node examples, mirroring the /api/v1/devices REST surface.
client.receipts
Reference for the ReceiptsResource — store fiscal receipts after printing and retrieve them with cursor-based pagination, mirroring /api/v1/receipts.