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

@ar-agents/wscdc

v0.2.2

Published

Agent toolkit for AFIP WSCDC (Web Service Constatación de Comprobantes Destinatarios): validate that a factura received from a supplier was actually issued by AFIP with a real CAE. Pair with @ar-agents/identity for WSAA cert + signature handling.

Readme

@ar-agents/wscdc

Agent toolkit for AFIP WSCDC (Web Service Constatación de Comprobantes Destinatarios). Validate that a factura received from a supplier was actually issued by AFIP with a real CAE — before ingesting it into accounts payable.

pnpm add @ar-agents/wscdc

What this package does

  • HttpWscdcAdapter — real adapter that POSTs SOAP to AFIP WSCDC (homo or prod). Caller supplies a WSAA access ticket; the adapter handles envelope construction, SoapAction header, and response parsing.
  • InMemoryWscdcAdapter — deterministic adapter for integration tests + cockpit demos. Pre-seed expected (CAE, emisor, cbte) triples; everything else returns "N".
  • UnconfiguredWscdcAdapter — explicit throws on every call default. Safe for unit tests that exercise validation primitives without AFIP creds.
  • Pure validationvalidateConstatarRequest() catches CUIT shape, date format, CAE length, etc. before the network round-trip so a typo doesn't cost a billable AFIP call.
  • Two Vercel AI SDK toolswscdc_validate_comprobante + wscdc_health.

What this package does NOT do

  • Acquire the WSAA ticket. The caller passes an AccessTicket (token + sign + cuitRepresentada) it already has. Use @ar-agents/identity's WSAA helpers or any compatible WSAA client. The wscdc service requires its own AFIP authorization separate from wsfe.
  • Catch every AFIP wire quirk. AFIP sometimes returns HTTP 500 with SOAP faults for legitimate-but-expired tokens; we translate those to WscdcProtocolError with faultCode set so callers can retry or surface to the operator.

Quick start

import {
  HttpWscdcAdapter,
  type AccessTicket,
} from "@ar-agents/wscdc";

// Acquire a TA from your WSAA flow first — example:
//   const ta = await acquireWsaaTicket("wscdc", { certPem, keyPem });
const ticket: AccessTicket = /* ... */ undefined!;

const wscdc = new HttpWscdcAdapter({ env: "prod", ticket });

const result = await wscdc.validateComprobante({
  cbteModo: "CAE",
  cuitEmisor: "30-50000001-8",
  ptoVta: 1,
  cbteTipo: 11, // Factura C
  cbteNro: 1234,
  cbteFch: "20260515", // YYYYMMDD (AFIP wire format)
  impTotal: 12100.0,
  codAutorizacion: "70123456789012",
  docTipoReceptor: 80, // CUIT
  docNroReceptor: "20417581015",
});

if (result.resultado === "A") {
  // Approved — safe to ingest into AP.
} else if (result.resultado === "N") {
  // Rejected — likely forged or wrong data. Refuse the factura.
  console.error("Forged?", result.errors);
} else {
  // Observed — exists but a soft field differs. Caller decides.
  console.warn("Mismatches:", result.observaciones);
}

Wired as agent tools:

import { Experimental_Agent as Agent } from "ai";
import { wscdcTools, HttpWscdcAdapter } from "@ar-agents/wscdc";
import { anthropic } from "@ai-sdk/anthropic";

const agent = new Agent({
  model: anthropic("claude-sonnet-4-7"),
  tools: wscdcTools({
    adapter: new HttpWscdcAdapter({ env: "prod", ticket }),
  }),
  system: "Eres un agente que valida facturas recibidas antes de ingestarlas en AP.",
});

Result shape

interface ConstatarResult {
  resultado: "A" | "N" | "O";
  observaciones: ReadonlyArray<{ code: number; msg: string }>;
  errors: ReadonlyArray<{ code: number; msg: string }>;
  fchProceso?: string; // YYYYMMDDhhmmss as returned by AFIP
}
  • "A" — every field matched what AFIP has on record. Safe.
  • "N" — at least one hard field (CAE, emisor, cbte number) didn't match. Treat as forged or wrong-data. Refuse to ingest.
  • "O" — exists, but a soft field (typically total) differs. Look at observaciones and decide.

In-memory testing

import { InMemoryWscdcAdapter, wscdcTools } from "@ar-agents/wscdc";

const adapter = new InMemoryWscdcAdapter([
  {
    cuitEmisor: "30-50000001-8",
    ptoVta: 1,
    cbteTipo: 11,
    cbteNro: 1234,
    impTotal: 12100.0,
    codAutorizacion: "70123456789012",
  },
]);

const tools = wscdcTools({ adapter });
// Tests against AFIP-realistic semantics, zero credentials needed.

Errors

import {
  WscdcError,
  WscdcValidationError,  // bad input — do NOT retry
  WscdcProtocolError,    // network / HTTP / SOAP fault — may retry
  WscdcUnconfiguredError,
} from "@ar-agents/wscdc";

A resultado: "N" is NOT an error — it's a valid response that says "this comprobante is forged." Switching on resultado is the correct flow control.

Constraints

  • cbteFch is YYYYMMDD (AFIP wire format, no hyphens).
  • codAutorizacion is exactly 14 digits (CAE or CAEA).
  • impTotal is a number with up to 2 decimals. The package formats it as toFixed(2) on the wire.
  • docNroReceptor is a string (Consumidor Final = "0").

For LLM agents using these tools, see AGENTS.md.

License

MIT — Nazareno Clemente [email protected]