> ## Documentation Index
> Fetch the complete documentation index at: https://facturas-sdk.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction to facturas: ARCA/AFIP Invoicing for Node.js

> facturas is a TypeScript SDK that connects your Node.js application directly to ARCA/AFIP's WSFE and WSMTXCA services to issue invoices and credit notes.

**facturas** gives your Node.js application a direct, typed connection to Argentina's ARCA/AFIP tax authority. Instead of routing through a proxy service or a third-party API, the SDK communicates with WSFE and WSMTXCA over SOAP using credentials you register yourself — so your invoices stay under your own CUIT, your data never touches an intermediary, and you control the full lifecycle of every fiscal document.

## What ARCA/AFIP is and why direct integration matters

ARCA (formerly AFIP) is Argentina's federal tax authority. Every Argentine business must issue electronic invoices (*comprobantes*) through ARCA's web services, and those invoices must carry a CAE (Código de Autorización Electrónica) that ARCA grants at the moment of issuance. Without a valid CAE, an invoice has no fiscal standing.

Historically, developers used proxy services to avoid dealing with SOAP, XML signing, and credential management directly. Those proxies add latency, cost, and an additional trust boundary. **facturas** handles all of that inside your process: it signs WSAA authentication tokens, caches them, derives invoice types from your issuer condition, maps JavaScript-style inputs to the wire format, and parses every response into a typed outcome — so you never read raw SOAP.

## Key capabilities

<CardGroup cols={2}>
  <Card title="WSFE — Simple invoices" icon="file-invoice">
    Issue and query Facturas A, B, C, and their credit and debit note variants. Works for monotributo, responsable inscripto, exento, and no alcanzado issuers.
  </Card>

  <Card title="WSMTXCA — Itemized invoices" icon="list">
    Issue detailed invoices with line-item breakdowns through the WSMTXCA service using the same `arca.issue()` facade by passing `{ service: "wsmtxca" }`.
  </Card>

  <Card title="Padrón lookups" icon="magnifying-glass">
    Query ARCA's Padrón to look up a taxpayer's fiscal condition, name, and registered activities before issuing a Factura A.
  </Card>

  <Card title="Safe retries" icon="rotate">
    Pair a `store` (Postgres, Redis, file, or memory) with an `idempotencyKey` so that a crash between number reservation and authorization never causes a duplicate invoice.
  </Card>
</CardGroup>

The SDK also includes a **CLI** (`npx facturas`) that generates your private key and CSR, walks you through ARCA's registration portal step by step, and runs a layered diagnostic (`npx facturas check`) that names exactly which configuration layer is broken — without writing anything to ARCA.

## Requirements

* **Node.js >= 20** — the SDK uses native `crypto` APIs and top-level ESM features
* **ESM only** — add `"type": "module"` to your `package.json`, or use `.mjs` file extensions
* **Four environment variables** — `ARCA_TAX_ID`, `ARCA_CERTIFICATE_PEM`, `ARCA_PRIVATE_KEY_PEM`, `ARCA_ENVIRONMENT`

No database, no external service, and no additional infrastructure is required to start issuing invoices. Optional stores (Postgres, Redis, file) unlock durable idempotency and shared WSAA session caching for multi-worker deployments.

## How facturas fits into your application

In a typical integration, facturas lives alongside your order or billing service. When a sale is confirmed, your code calls `arca.issue()` with the sale's details. The SDK authenticates with WSAA (reusing a cached ticket if one exists), reserves the next voucher number, calls WSFE or WSMTXCA to authorize the invoice, and returns one of four typed outcomes: `authorized`, `rejected`, `indeterminate`, or `conflict`. You handle each outcome and persist the CAE with your own order record.

```text theme={null}
Your app ──► arca.issue() ──► WSAA (auth ticket, cached)
                          ──► WSFE / WSMTXCA (authorize)
                          ◄── { kind: "authorized", voucher, cae }
```

There is no webhook, no polling loop, and no background job needed for basic issuance — each call is synchronous from your code's perspective.

## Public API surface

The main export is `createArcaClient()`, which returns an `ArcaClient` with:

| Method                                    | What it does                                                          |
| ----------------------------------------- | --------------------------------------------------------------------- |
| `arca.issue(input, options?)`             | Issue a WSFE or WSMTXCA invoice                                       |
| `arca.preview(input, options?)`           | Inspect the derived invoice type and amounts without any network call |
| `arca.recover(key, options?)`             | Consult a stored reservation without authorizing again                |
| `arca.issueCreditNote(input, options?)`   | Issue a credit note tied to an existing voucher                       |
| `arca.issueDebitNote(input, options?)`    | Issue a debit note tied to an existing voucher                        |
| `arca.previewCreditNote(input, options?)` | Derive what `issueCreditNote()` would send, without any network call  |
| `arca.previewDebitNote(input, options?)`  | Derive what `issueDebitNote()` would send, without any network call   |

The client also exposes `arca.wsfe`, `arca.wsmtxca`, and `arca.padron` as low-level service properties for direct SOAP operations. The factory functions `createWsfeService()`, `createWsmtxcaService()`, and `createPadronService()` are also exported if you need to instantiate them independently.

<CardGroup cols={2}>
  <Card title="Quick Start" icon="bolt" href="quickstart">
    Set environment variables and issue your first invoice.
  </Card>

  <Card title="ARCA Setup" icon="key" href="arca-setup">
    Generate a key and CSR, register with ARCA, and verify every layer.
  </Card>
</CardGroup>

<Warning>
  **Pre-1.0: pin the exact version.** While the package version starts with `0.`, any minor release may introduce breaking changes to the public API. Set `"facturas": "0.11.0"` (or whatever the current version is) in your `package.json` — not a range — and read the [changelog](https://github.com/LaPyme/facturas/blob/main/packages/arca/CHANGELOG.md) before every upgrade.
</Warning>
