arca-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +262 -0
- package/dist/index.cjs +769 -0
- package/dist/index.d.cts +326 -0
- package/dist/index.d.ts +326 -0
- package/dist/index.js +725 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# 🇦🇷 arca-sdk
|
|
2
|
+
|
|
3
|
+
**La SDK moderna de ARCA (ex-AFIP) que no te rompe las bolas.**
|
|
4
|
+
|
|
5
|
+
SDK en TypeScript para integración con servicios de ARCA:
|
|
6
|
+
- ✅ **Type-safe**: TypeScript strict mode
|
|
7
|
+
- ✅ **Simple**: No más XML manual
|
|
8
|
+
- ✅ **Automático**: Cache de tokens, retry logic
|
|
9
|
+
- ✅ **Moderno**: ESM + CJS, Node.js 18+
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 🚀 Instalación
|
|
14
|
+
```bash
|
|
15
|
+
npm install arca-sdk
|
|
16
|
+
# o
|
|
17
|
+
bun add arca-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## ⚡ Quick Start
|
|
23
|
+
```typescript
|
|
24
|
+
import { WsaaService } from 'arca-sdk';
|
|
25
|
+
import * as fs from 'node:fs';
|
|
26
|
+
|
|
27
|
+
// 1. Crear servicio con tus certificados
|
|
28
|
+
const wsaa = new WsaaService({
|
|
29
|
+
environment: 'homologacion', // 'homologacion' o 'produccion'
|
|
30
|
+
cuit: '20123456789',
|
|
31
|
+
cert: fs.readFileSync('./cert.pem', 'utf-8'),
|
|
32
|
+
key: fs.readFileSync('./key.pem', 'utf-8'),
|
|
33
|
+
service: 'wsfe',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 2. Obtener ticket (automático, con cache)
|
|
37
|
+
const ticket = await wsaa.login();
|
|
38
|
+
|
|
39
|
+
// 3. Usar token en otros servicios ARCA
|
|
40
|
+
console.log('Token:', ticket.token);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Eso es todo.** No XML. No SOAP. No pain.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 📖 Servicios Disponibles
|
|
48
|
+
|
|
49
|
+
### WSAA - Autenticación
|
|
50
|
+
```typescript
|
|
51
|
+
import { WsaaService } from 'arca-sdk';
|
|
52
|
+
|
|
53
|
+
const wsaa = new WsaaService({
|
|
54
|
+
environment: 'homologacion',
|
|
55
|
+
cuit: '20123456789',
|
|
56
|
+
cert: '...certificado PEM...',
|
|
57
|
+
key: '...clave privada PEM...',
|
|
58
|
+
service: 'wsfe', // o 'wsmtxca', etc
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const ticket = await wsaa.login();
|
|
62
|
+
// Ticket válido por ~12 horas
|
|
63
|
+
// Se renueva automáticamente
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### WSFE - Facturación *(próximamente)*
|
|
67
|
+
```typescript
|
|
68
|
+
// Próximamente:
|
|
69
|
+
const wsfe = new WsfeService(config);
|
|
70
|
+
await wsfe.emitirFacturaC({ ... });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 🔑 Certificados
|
|
76
|
+
|
|
77
|
+
Necesitás certificados de ARCA en formato PEM:
|
|
78
|
+
- `cert.pem`: Certificado X.509
|
|
79
|
+
- `key.pem`: Clave privada
|
|
80
|
+
|
|
81
|
+
**Homologación (testing):**
|
|
82
|
+
1. Ir a [ARCA Homologación](https://www.afip.gob.ar/ws/documentacion/certificados.asp)
|
|
83
|
+
2. Generar certificado de prueba
|
|
84
|
+
3. Descargar cert + key
|
|
85
|
+
|
|
86
|
+
**Producción:**
|
|
87
|
+
1. Generar CSR con tu CUIT
|
|
88
|
+
2. Subir a ARCA
|
|
89
|
+
3. Descargar certificado firmado
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🛠️ Ejemplos
|
|
94
|
+
|
|
95
|
+
Ver carpeta [`/examples`](./examples):
|
|
96
|
+
- [`autenticacion.ts`](./examples/autenticacion.ts) - Obtener ticket WSAA
|
|
97
|
+
- [`quick-start.ts`](./examples/quick-start.ts) - Inicio rápido
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 🧪 Testing
|
|
102
|
+
```bash
|
|
103
|
+
# Tests unitarios
|
|
104
|
+
bun test
|
|
105
|
+
|
|
106
|
+
# Build
|
|
107
|
+
bun run build
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 📝 TypeScript
|
|
113
|
+
|
|
114
|
+
La SDK exporta todos los tipos:
|
|
115
|
+
```typescript
|
|
116
|
+
import type {
|
|
117
|
+
LoginTicket,
|
|
118
|
+
WsaaConfig,
|
|
119
|
+
Environment
|
|
120
|
+
} from 'arca-sdk';
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Autocomplete completo en tu IDE. ✨
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## ⚠️ Manejo de Errores
|
|
128
|
+
```typescript
|
|
129
|
+
import { ArcaAuthError, ArcaValidationError } from 'arca-sdk';
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const ticket = await wsaa.login();
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error instanceof ArcaAuthError) {
|
|
135
|
+
console.error('Error de autenticación:', error.message);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (error instanceof ArcaValidationError) {
|
|
139
|
+
console.error('Configuración inválida:', error.message);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Los errores incluyen contexto útil en `error.details`.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
### WSFE - Facturación Electrónica
|
|
149
|
+
|
|
150
|
+
#### Ticket C Simple (solo total)
|
|
151
|
+
```typescript
|
|
152
|
+
import { WsaaService, WsfeService } from 'arca-sdk';
|
|
153
|
+
|
|
154
|
+
// 1. Autenticar
|
|
155
|
+
const wsaa = new WsaaService({ ... });
|
|
156
|
+
const ticket = await wsaa.login();
|
|
157
|
+
|
|
158
|
+
// 2. Crear servicio WSFE
|
|
159
|
+
const wsfe = new WsfeService({
|
|
160
|
+
environment: 'homologacion',
|
|
161
|
+
cuit: '20123456789',
|
|
162
|
+
ticket,
|
|
163
|
+
puntoVenta: 4,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// 3. Emitir ticket (modo simple)
|
|
167
|
+
const cae = await wsfe.emitirTicketCSimple({
|
|
168
|
+
total: 3500
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
console.log('CAE:', cae.cae);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### Ticket C con Items
|
|
175
|
+
```typescript
|
|
176
|
+
// Modo completo: con detalle de items
|
|
177
|
+
const cae = await wsfe.emitirTicketC({
|
|
178
|
+
items: [
|
|
179
|
+
{ descripcion: 'Producto 1', cantidad: 2, precioUnitario: 500 },
|
|
180
|
+
{ descripcion: 'Producto 2', cantidad: 1, precioUnitario: 1000 },
|
|
181
|
+
],
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Los items NO se envían a ARCA
|
|
185
|
+
// Pero se retornan en la respuesta para que los guardes
|
|
186
|
+
console.log('Items:', cae.items);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### Factura B (IVA discriminado)
|
|
190
|
+
```typescript
|
|
191
|
+
import { TipoDocumento } from 'arca-sdk';
|
|
192
|
+
|
|
193
|
+
const cae = await wsfe.emitirFacturaB({
|
|
194
|
+
items: [
|
|
195
|
+
{
|
|
196
|
+
descripcion: 'Servicio',
|
|
197
|
+
cantidad: 10,
|
|
198
|
+
precioUnitario: 1000,
|
|
199
|
+
alicuotaIva: 21, // ← OBLIGATORIO
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
comprador: {
|
|
203
|
+
tipoDocumento: TipoDocumento.CUIT,
|
|
204
|
+
nroDocumento: '20987654321',
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
console.log('CAE:', cae.cae);
|
|
209
|
+
console.log('IVA:', cae.iva);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
#### Factura A (RI a RI)
|
|
213
|
+
```typescript
|
|
214
|
+
const cae = await wsfe.emitirFacturaA({
|
|
215
|
+
items: [
|
|
216
|
+
{ descripcion: 'Producto', cantidad: 5, precioUnitario: 2000, alicuotaIva: 21 },
|
|
217
|
+
],
|
|
218
|
+
comprador: {
|
|
219
|
+
tipoDocumento: TipoDocumento.CUIT,
|
|
220
|
+
nroDocumento: '20111111119',
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## 🎯 Tipos de Comprobante
|
|
228
|
+
|
|
229
|
+
| Tipo | Uso | IVA Discriminado | Items requeridos |
|
|
230
|
+
|------|-----|------------------|------------------|
|
|
231
|
+
| **Ticket C** | Consumidor final | No | Opcional (solo local) |
|
|
232
|
+
| **Factura C** | Consumidor final | No | Opcional |
|
|
233
|
+
| **Factura B** | Monotributo → RI | Sí | **Obligatorio** |
|
|
234
|
+
| **Factura A** | RI → RI | Sí | **Obligatorio** |
|
|
235
|
+
|
|
236
|
+
**Importante:** Factura B y A requieren `alicuotaIva` en cada item.
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## 🤝 Contribuir
|
|
241
|
+
|
|
242
|
+
Contribuciones bienvenidas! Ver [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## 📄 Licencia
|
|
247
|
+
|
|
248
|
+
MIT © [Marcela Borgarello](https://github.com/marcelaborgarello)
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## 🔗 Links
|
|
253
|
+
|
|
254
|
+
- [Documentación ARCA](https://www.afip.gob.ar/ws/)
|
|
255
|
+
- [Issues](https://github.com/marcelaborgarello/arca-sdk/issues)
|
|
256
|
+
- [NPM](https://www.npmjs.com/package/arca-sdk)
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
**Hecho con ❤️ en Argentina 🇦🇷**
|
|
261
|
+
|
|
262
|
+
*Porque integrar con ARCA no tiene por qué ser un infierno.*
|