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

@ramiidv/arca-cdc

v0.1.0

Published

SDK para el web service WSCDC de ARCA (ex AFIP) - Constatacion de Comprobantes

Downloads

141

Readme

@ramiidv/arca-cdc

npm License: MIT Node >= 18

SDK en TypeScript para el web service WSCDC (Constatacion de Comprobantes) de ARCA (ex AFIP).

Permite verificar programaticamente si los comprobantes recibidos fueron efectivamente autorizados por ARCA. Valida codigos CAE, CAI o CAEA. Servicio de solo lectura.

Instalacion

npm install @ramiidv/arca-cdc

Requisitos

Uso rapido

import fs from "fs";
import { ArcaCdc } from "@ramiidv/arca-cdc";

const cdc = new ArcaCdc({
  cuit: 20123456789,
  cert: fs.readFileSync("./cert.crt", "utf-8"),
  key: fs.readFileSync("./key.key", "utf-8"),
  production: false, // true para produccion
});

// Verificar un comprobante
const result = await cdc.constatar({
  CbteTipo: 1,           // Factura A
  PtoVta: 1,
  CbteNro: 150,
  CbteFch: "20260315",   // Fecha YYYYMMDD
  ImpTotal: 12100,
  CodAutorizacion: "73429843294823", // CAE, CAI, o CAEA
  DocTipoReceptor: 80,   // CUIT
  DocNroReceptor: 30712345678,
});

if (result.Resultado === "A") {
  console.log("Comprobante verificado correctamente");
} else {
  console.log("Comprobante rechazado");
  console.log(result.Observaciones);
}

Configuracion

const cdc = new ArcaCdc({
  cuit: 20123456789,          // CUIT sin guiones
  cert: "...",                 // Certificado X.509 (PEM)
  key: "...",                  // Clave privada (PEM)
  production: false,           // Default: false (testing/homologacion)
  timeout: 30_000,             // Default: 30000 (30 segundos)
  retries: 1,                  // Default: 1 (reintentos en errores transitorios)
  retryDelayMs: 1_000,         // Default: 1000 (backoff exponencial: 1s, 2s, ...)
  onEvent: (e) => {            // Opcional: callback para logging/debugging
    console.log(e.type, e);
  },
});

API

new ArcaCdc(config)

| Parametro | Tipo | Default | Descripcion | | --- | --- | --- | --- | | cuit | number | -- | CUIT del contribuyente (sin guiones) | | cert | string | -- | Contenido del certificado X.509 (PEM) | | key | string | -- | Contenido de la clave privada (PEM) | | production | boolean | false | Entorno de produccion | | timeout | number | 30000 | Timeout HTTP en milisegundos | | retries | number | 1 | Reintentos en errores transitorios | | retryDelayMs | number | 1000 | Delay inicial entre reintentos (exponencial) | | onEvent | function | -- | Callback para eventos del SDK |

Metodos

| Metodo | Descripcion | | --- | --- | | constatar(input) | Verifica si un comprobante fue autorizado por ARCA | | status() | Health check del servicio (no requiere autenticacion) | | getModalidades() | Consulta modalidades de facturacion habilitadas | | getTiposCbte() | Consulta tipos de comprobante habilitados | | getDocTipos() | Consulta tipos de documento habilitados | | clearAuthCache() | Invalida los tickets de acceso cacheados |

constatar(input)

Verifica si un comprobante fue efectivamente autorizado por ARCA. Valida codigos CAE, CAI, o CAEA.

interface ConstatarInput {
  CbteTipo: number;          // Tipo de comprobante
  PtoVta: number;            // Punto de venta
  CbteNro: number;           // Numero de comprobante
  CbteFch: string;           // Fecha (YYYYMMDD)
  ImpTotal: number;          // Importe total
  CodAutorizacion: string;   // CAE, CAI, o CAEA
  DocTipoReceptor: number;   // Tipo de documento del receptor
  DocNroReceptor: number;    // Numero de documento del receptor
}

interface ConstatarResult {
  Resultado: "A" | "R";               // A=Aprobado, R=Rechazado
  Observaciones?: { Code, Msg }[];    // Detalles del rechazo
  Errors?: { Code, Msg }[];           // Errores del servicio
}

Consultas de parametros

// Modalidades de facturacion
const modalidades = await cdc.getModalidades();

// Tipos de comprobante
const tiposCbte = await cdc.getTiposCbte();

// Tipos de documento
const docTipos = await cdc.getDocTipos();

Cada item retorna { Id: number, Desc: string, FchDesde?: string, FchHasta?: string }.

Acceso a clientes de bajo nivel

Para casos avanzados, se pueden usar los clientes individuales directamente:

const cdc = new ArcaCdc({ /* ... */ });

// Obtener ticket de acceso manualmente
const ticket = await cdc.wsaa.getAccessTicket("wscdc");

const auth = {
  Token: ticket.token,
  Sign: ticket.sign,
  Cuit: 20123456789,
};

// Llamar directamente al servicio
const result = await cdc.client.constatar(auth, { /* ... */ });

Manejo de errores

El SDK usa la jerarquia de errores de @ramiidv/arca-common:

import {
  ArcaAuthError,
  ArcaServiceError,
  ArcaSoapError,
} from "@ramiidv/arca-cdc";

try {
  const result = await cdc.constatar({ /* ... */ });
} catch (e) {
  if (e instanceof ArcaAuthError) {
    // Error de autenticacion WSAA (certificado invalido, expirado, etc.)
    console.error("Auth error:", e.message);
    cdc.clearAuthCache();
  }

  if (e instanceof ArcaServiceError) {
    // Error de negocio devuelto por ARCA
    for (const err of e.errors) {
      console.error(`[${err.code}] ${err.msg}`);
    }
  }

  if (e instanceof ArcaSoapError) {
    // Error HTTP/SOAP (timeout, servidor caido, etc.)
    console.error("HTTP status:", e.statusCode);
  }
}

| Clase | Cuando se lanza | | --- | --- | | ArcaAuthError | Falla en login WSAA, respuesta inesperada, token/sign invalidos | | ArcaServiceError | Error devuelto por WSCDC (campos invalidos, CUIT no autorizado, etc.). Contiene errors: { code, msg }[] | | ArcaSoapError | Error HTTP, timeout, SOAP Fault. Contiene statusCode?: number | | ArcaError | Clase base para todos los errores del SDK |

Eventos

El SDK emite eventos para debugging y monitoreo:

const cdc = new ArcaCdc({
  // ...
  onEvent: (evento) => {
    switch (evento.type) {
      case "auth:login":
        console.log(`Login para ${evento.service}`);
        break;
      case "auth:cache-hit":
        console.log(`Token cacheado para ${evento.service}`);
        break;
      case "request:start":
        console.log(`Inicio ${evento.method}`);
        break;
      case "request:end":
        console.log(`Fin ${evento.method} (${evento.durationMs}ms)`);
        break;
      case "request:retry":
        console.log(`Reintento #${evento.attempt}`);
        break;
      case "request:error":
        console.log(`Error: ${evento.error}`);
        break;
    }
  },
});

| Evento | Cuando | Datos | | --- | --- | --- | | auth:login | Nuevo token obtenido | service, durationMs | | auth:cache-hit | Token cacheado reutilizado | service | | request:start | Antes de una llamada SOAP | method, endpoint | | request:end | Llamada SOAP completada | method, durationMs | | request:retry | Reintentando tras error | method, attempt, error | | request:error | Llamada SOAP fallo | method, error |

Entornos

| Entorno | WSAA | WSCDC | | --- | --- | --- | | Testing | wsaahomo.afip.gov.ar | wswhomo.afip.gov.ar | | Produccion | wsaa.afip.gov.ar | servicios1.arca.gob.ar |

Licencia

MIT