e-bon
e-bon.ro
TypeScript SDK

client.commands

Reference for the CommandsResource — submit fiscal commands asynchronously, list, poll a single command and cancel a pending one, mirroring /api/v1/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>
NameTypeRequiredNotes
deviceIdstringyesTarget device.
typeCommandTypeyesCommand kind — see @e-bon/types.
payloadunknownnoCommand-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[]>
NameTypeRequiredNotes
deviceIdstringnoFilter by device.
statusstringnoOne of pending, sent, completed, failed, cancelled — see CommandStatus.
typestringnoFilter by CommandType.
limitnumbernoPage 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>
NameTypeRequiredNotes
idstringyesCommand 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>
NameTypeRequiredNotes
idstringyesCommand identifier.

Returns the updated FiscalCommand (status moves to cancelled if the command had not yet been dispatched).

await client.commands.cancel('cmd_01HZ...');