npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@motor-tributario/pos-terminal-client

v0.1.1

Published

Cliente chico para @motor-tributario/pos-terminal-agente — llama a POST /venta, POST /anular del agente local con una función tipada en vez de armar fetch() a mano. Corre en cualquier entorno con fetch nativo (navegador o Node 18+) — es justo lo que un ER

Readme

@motor-tributario/pos-terminal-client

Cliente HTTP chico para @motor-tributario/pos-terminal-agente — el agente local que corre en la PC del punto de venta y habla de verdad con el terminal Transbank.

Sin este paquete, cualquiera que quiera cobrar contra el agente tiene que armar el fetch() a mano, parsear el JSON de respuesta, y traducir un 502 a "el terminal no respondió" por su cuenta. Este paquete hace las 3 cosas con una función tipada.

Para quién es esto

Para el backend o frontend de un ERP que ya sabe que en esa PC hay un agente local corriendo (instalado aparte, ver el README de @motor-tributario/pos-terminal-agente) y sólo necesita pedirle "cobra $X" o "anula esta operación" — sin instalar transbank-pos-sdk ni ningún driver, porque de eso se encarga el agente.

Corre en cualquier entorno con fetch nativo: navegador o Node.js 18+. No trae ninguna dependencia nativa ni de hardware — sólo usa @motor-tributario/pos-terminal para los tipos compartidos (RespuestaVentaPos, RespuestaAnulacionPos, PosNoResponde), nunca sus subpaths /node o /web.

Instalación

npm install @motor-tributario/pos-terminal-client

Uso

import { PosTerminalAgenteClient, PosNoResponde } from "@motor-tributario/pos-terminal-client";

// baseUrl es opcional — por defecto apunta a http://127.0.0.1:9090, el puerto por defecto del agente.
const pos = new PosTerminalAgenteClient();

// Antes de cobrar, opcionalmente confirmar que el agente está vivo:
const salud = await pos.salud();
// { ok: true, agente: "@motor-tributario/pos-terminal-agente", version: "0.1.0" }

try {
  const resultado = await pos.venderConPos(9990, "boleta-00123");
  console.log("Cobro aprobado:", resultado.authorizationCode);
} catch (error) {
  if (error instanceof PosNoResponde) {
    // El agente no está instalado, no está corriendo, o el terminal no respondió — mismo tipo que
    // ya usan @motor-tributario/pos-terminal y venderConInstrumentoAutomatico() del SDK del Motor.
    // Un `intentarPagoEnPos` que llama a este cliente no necesita manejo especial de errores:
    // cualquier fallo real de cobro cae acá y dispara contingencia automáticamente.
    console.error("No se pudo cobrar:", error.failureCode, error.message);
  } else {
    // Error de programación (parámetro inválido) o falla interna del agente — no de hardware.
    throw error;
  }
}

// Anular una venta ya aprobada:
await pos.anularEnPos(resultado.operationNumber ?? "");

API

new PosTerminalAgenteClient(opciones?)

  • opciones.baseUrl — URL base del agente. Default: http://127.0.0.1:9090.

salud(): Promise<{ ok: boolean; agente: string; version: string }>

Llama a GET /salud. Útil para mostrar "terminal listo" en la interfaz antes de intentar cobrar.

venderConPos(monto: number, ticket: string, portName?: string): Promise<RespuestaVentaPos>

Llama a POST /venta. Lanza PosNoResponde si el agente no está disponible o el terminal no respondió; lanza Error genérico para errores de validación (400) o fallas internas del agente (500).

anularEnPos(operationId: string, portName?: string): Promise<RespuestaAnulacionPos>

Llama a POST /anular. Mismas reglas de error que venderConPos.

Manejo de errores

| Escenario | Excepción | |---|---| | Agente no instalado / no corriendo / puerto equivocado | PosNoResponde("AGENT_UNREACHABLE", ...) | | Agente corriendo, pero sin terminal conectado o sin responder | PosNoResponde(failureCode real del agente, ...) | | Parámetros inválidos (ej. monto faltante o negativo) | Error genérico (HTTP 400) | | Falla interna del agente | Error genérico (HTTP 500) |

Verificado en vivo (2026-08-17)

Contra una instancia real de @motor-tributario/pos-terminal-agente corriendo en 127.0.0.1:9090 (sin terminal físico conectado, entorno de desarrollo):

  • salud() → { ok: true, ... } ✅
  • venderConPos(1000, "ticket") sin terminal → PosNoResponde("NO_PORT_FOUND", ...) ✅
  • venderConPos(-5, "ticket") (monto inválido) → Error genérico, no PosNoResponde ✅
  • salud() contra un puerto donde nadie escucha → PosNoResponde("AGENT_UNREACHABLE", ...) ✅

Build

npm run build   # genera dist/ (ESM) y dist-cjs/ (CommonJS)

Licencia

UNLICENSED — parte del monorepo del Motor Tributario.