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

@danielrebolledo/cafe-ipdh-lib

v1.1.1

Published

Librería para gestionar impresoras fiscales y de recibos (AEG-R1, DTP, etc.)

Readme

cafe-ipdh-lib

Librería para gestionar impresoras fiscales y de recibos. Construye comandos y los envía mediante una API unificada (sendPrinterCommands) que soporta AEG y DTP.

Modelos soportados

| Marca | Modelo | Transporte | |-------|--------|------------| | AEG | R1 | HTTP (POST a /cmdoJson) | | DTP | 80i | TCP |

Instalación

npm install @danielrebolledo/cafe-ipdh-lib

Uso unificado: sendPrinterCommands

Tanto AEG como DTP usan la misma función:

import {
  aegPrinter,
  dtpPrinter,
  sendPrinterCommands,
  DtpClient,
} from "@danielrebolledo/cafe-ipdh-lib";

const order = {
  client: { id: "V12345678", name: "Cliente", email: "[email protected]" },
  items: [{ id: "1", name: "Producto", sku: "SKU1", price: 10, quantity: 1, total: 10, taxes: [{ id: "IVA_G" }] }],
  payments: [{ amount: 10, paymentMethod: "cash_nat" }],
  total: 10,
};

// AEG-R1 (HTTP)
const resultAeg = await sendPrinterCommands({
  brand: "AEG",
  model: "R1",
  ip: "http://192.168.1.100",
  commands: aegPrinter.buildInvoiceCommands(order, {
    paymentMethodId: "cash_nat",
    storeName: "Mi Tienda",
  }),
});

// DTP-80i (TCP; requiere client ya conectado)
const resultDtp = await sendPrinterCommands({
  brand: "DTP",
  model: "80i",
  client: dtpClient, // DtpClient conectado
  commands: dtpPrinter.buildInvoiceCommands(order, {
    paymentMethodId: "cash_nat",
    storeName: "Mi Tienda",
  }),
});

Ejemplos por entorno

Web (AEG-R1)

En un proyecto web (Next.js, Vite, etc.), normalmente se usa AEG por HTTP:

import {
  aegPrinter,
  sendPrinterCommands,
  type Order,
} from "@danielrebolledo/cafe-ipdh-lib";

async function imprimirFactura(order: Order, printerIp: string) {
  const commands = aegPrinter.buildInvoiceCommands(order, {
    paymentMethodId: "cash_nat",
    storeName: "Mi Tienda",
  });

  const result = await sendPrinterCommands({
    brand: "AEG",
    model: "R1",
    ip: printerIp,
    commands,
  });

  const invoiceRef = Array.isArray(result)
    ? result.find((r) => r.cmd === "endFac")?.dataD ?? 0
    : result.documentNumber ?? 0;

  return { success: true, invoiceRef };
}

React Native (DTP-80i)

En React Native (Expo, etc.) se suele usar DTP vía TCP con react-native-tcp-socket:

npm install react-native-tcp-socket
import TcpSocket from "react-native-tcp-socket";
import {
  DtpClient,
  dtpPrinter,
  sendPrinterCommands,
  type Order,
} from "@danielrebolledo/cafe-ipdh-lib";

const createConnection = (opts: { host: string; port: number }) =>
  new Promise((resolve, reject) => {
    const socket = TcpSocket.createConnection(opts, () => resolve(socket));
    socket.once("error", reject);
  });

async function imprimirFactura(order: Order, host: string, port: number) {
  const client = new DtpClient({
    host,
    port,
    connectTimeoutMs: 15000,
    createConnection: createConnection as any,
  });

  try {
    await client.connect();

    const commands = dtpPrinter.buildInvoiceCommands(order, {
      paymentMethodId: "cash_nat",
      storeName: "Mi Tienda",
    });

    const result = await sendPrinterCommands({
      brand: "DTP",
      model: "80i",
      client,
      commands,
    });

    return {
      success: true,
      invoiceRef: result.documentNumber ?? 0,
    };
  } finally {
    client.close();
  }
}

API

Drivers

| Driver | Modelo | Métodos | |--------|--------|---------| | aegPrinter | AEG-R1 | buildInvoiceCommands, buildReceiptCommands | | dtpPrinter | DTP-80i | buildInvoiceCommands, buildReceiptCommands, buildCreditNoteCommands |

sendPrinterCommands

Función unificada para enviar comandos a cualquier impresora.

  • AEG: { brand: "AEG", model: "R1", ip, commands }
  • DTP: { brand: "DTP", model: "80i", client, commands }

Retorna:

  • AEG: PrinterCommandResponse[]
  • DTP: { documentNumber?: number; totalAmount?: number }

Node.js y DTP

Para usar DTP en Node.js (backend), importa createNodeDtpConnection del entry node:

import {
  DtpClient,
  dtpPrinter,
  sendPrinterCommands,
} from "@danielrebolledo/cafe-ipdh-lib";
import {
  createNodeDtpConnection,
} from "@danielrebolledo/cafe-ipdh-lib/node";

const client = new DtpClient({
  host: "192.168.1.10",
  port: 3010,
  createConnection: createNodeDtpConnection,
});
await client.connect();

const result = await sendPrinterCommands({
  brand: "DTP",
  model: "80i",
  client,
  commands: dtpPrinter.buildInvoiceCommands(order, opts),
});

Tipos exportados

  • Order, OrderItem, FiscalClient, OrderPayment
  • AegPrinterCommand, DtpPrinterCommand
  • BuildInvoiceOptions, BuildReceiptOptions, BuildCreditNoteOptions
  • SendPrinterCommandsArgs, SendPrinterCommandsResult
  • PaymentMethodId, PrinterTaxValues, TaxValues

Scripts

npm run build    # Compilar
npm run dev     # Watch mode
npm run lint    # Biome
npm run test    # Vitest

Stack

  • TypeScript
  • tsup
  • Biome
  • Vitest