intifact 1.0.0 → 1.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 +62 -125
- package/dist/index.d.ts +500 -1198
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +135 -180
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +938 -750
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -45
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# intifact
|
|
2
2
|
|
|
3
|
-
SDK TypeScript para la API de Facturación Electrónica SUNAT de
|
|
3
|
+
SDK TypeScript auto-generado para la **API de Facturación Electrónica SUNAT de Intifact** (Perú).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Sigue siempre la versión más reciente de la API: los tipos se regeneran desde el `openapi.json` que la API expone en `/docs/json`.
|
|
6
6
|
|
|
7
7
|
## Instalación
|
|
8
8
|
|
|
@@ -10,139 +10,76 @@ Emite facturas, boletas, notas de crédito/débito y guías de remisión electr
|
|
|
10
10
|
npm install intifact
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
## Uso
|
|
13
|
+
## Uso básico
|
|
14
14
|
|
|
15
|
-
```
|
|
16
|
-
import {
|
|
15
|
+
```ts
|
|
16
|
+
import { FacturacionClient } from "intifact";
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const fact = new FacturacionClient({
|
|
19
|
+
baseUrl: "https://api-facturacion.intifact.com",
|
|
20
|
+
apiKey: process.env.FACTURACION_API_KEY, // tu API key fact_live_/fact_test_
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
//
|
|
23
|
-
const { data, error } = await
|
|
23
|
+
// Enviar factura → 202 (encolada)
|
|
24
|
+
const { data, error } = await fact.sendInvoice({
|
|
24
25
|
tipoDoc: "01",
|
|
25
26
|
serie: "F001",
|
|
26
|
-
correlativo: "
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
tipoDoc: "6",
|
|
30
|
-
numDoc: "20000000001",
|
|
31
|
-
rznSocial: "Empresa SAC",
|
|
32
|
-
},
|
|
33
|
-
company: {
|
|
34
|
-
ruc: "20000000001",
|
|
35
|
-
},
|
|
36
|
-
details: [
|
|
37
|
-
{
|
|
38
|
-
codProducto: "P001",
|
|
39
|
-
unidad: "NIU",
|
|
40
|
-
cantidad: 2,
|
|
41
|
-
descripcion: "Producto de ejemplo",
|
|
42
|
-
mtoValorUnitario: 100,
|
|
43
|
-
},
|
|
44
|
-
],
|
|
27
|
+
correlativo: "1",
|
|
28
|
+
empresaRuc: "20553510661",
|
|
29
|
+
/* ...resto del payload */
|
|
45
30
|
});
|
|
46
31
|
|
|
47
|
-
if (error)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
if (error) throw error;
|
|
33
|
+
console.log("Encolada:", data.data.id);
|
|
34
|
+
|
|
35
|
+
// Esperar hasta que SUNAT responda
|
|
36
|
+
const finalDoc = await fact.waitForDocument(data.data.id);
|
|
37
|
+
console.log("Estado:", finalDoc.data.sunat.estado);
|
|
52
38
|
```
|
|
53
39
|
|
|
54
|
-
## Métodos
|
|
55
|
-
|
|
56
|
-
###
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
| Método | Descripción |
|
|
94
|
-
|--------|-------------|
|
|
95
|
-
| `listDocuments(query?)` | Listar documentos emitidos |
|
|
96
|
-
| `getDocument(id)` | Obtener documento por ID |
|
|
97
|
-
| `retryDocument(id)` | Reintentar envío de documento fallido |
|
|
98
|
-
| `getNextCorrelativo(query)` | Obtener siguiente correlativo |
|
|
99
|
-
|
|
100
|
-
### Empresas
|
|
101
|
-
|
|
102
|
-
| Método | Descripción |
|
|
103
|
-
|--------|-------------|
|
|
104
|
-
| `listCompanies()` | Listar empresas registradas |
|
|
105
|
-
| `createCompany(body)` | Registrar nueva empresa |
|
|
106
|
-
| `getCompany(id)` | Obtener datos de empresa |
|
|
107
|
-
| `updateCompany(id, body)` | Actualizar empresa |
|
|
108
|
-
| `uploadCertificate(id, body)` | Subir certificado digital |
|
|
109
|
-
| `uploadLogo(id, body)` | Subir logo (aparece en PDFs) |
|
|
110
|
-
| `getLogo(id)` | Obtener logo |
|
|
111
|
-
| `deleteLogo(id)` | Eliminar logo |
|
|
112
|
-
|
|
113
|
-
### Webhooks
|
|
114
|
-
|
|
115
|
-
| Método | Descripción |
|
|
116
|
-
|--------|-------------|
|
|
117
|
-
| `listWebhooks()` | Listar webhooks |
|
|
118
|
-
| `createWebhook(body)` | Crear webhook |
|
|
119
|
-
| `getWebhook(id)` | Obtener webhook |
|
|
120
|
-
| `updateWebhook(id, body)` | Actualizar webhook |
|
|
121
|
-
| `deleteWebhook(id)` | Eliminar webhook |
|
|
122
|
-
| `listWebhookDeliveries(id)` | Listar entregas |
|
|
123
|
-
| `redeliverWebhook(endpointId, deliveryId)` | Re-enviar entrega |
|
|
124
|
-
| `testWebhook(id)` | Enviar evento de prueba |
|
|
125
|
-
|
|
126
|
-
### Otros
|
|
127
|
-
|
|
128
|
-
| Método | Descripción |
|
|
129
|
-
|--------|-------------|
|
|
130
|
-
| `getUsage()` | Consumo actual del plan |
|
|
131
|
-
| `getQueueStats()` | Estado de las colas |
|
|
132
|
-
| `health()` | Verificar disponibilidad |
|
|
133
|
-
| `consultarDocumento(ruc, tipoDoc, serie, numero)` | Consulta pública de documento |
|
|
134
|
-
| `consultarDocumentoPdf(...)` | PDF de consulta pública |
|
|
135
|
-
| `consultarDocumentoXml(...)` | XML de consulta pública |
|
|
136
|
-
|
|
137
|
-
## Configuración
|
|
138
|
-
|
|
139
|
-
```typescript
|
|
140
|
-
const client = new Intifact({
|
|
141
|
-
apiKey: "tu-api-key",
|
|
142
|
-
baseUrl: "https://api.intifact.com", // opcional, default
|
|
143
|
-
});
|
|
40
|
+
## Métodos
|
|
41
|
+
|
|
42
|
+
### Emisión
|
|
43
|
+
- `sendInvoice(body)` — factura (01) o boleta (03)
|
|
44
|
+
- `sendNote(body)` — nota crédito (07) o débito (08)
|
|
45
|
+
- `sendDespatch(body)` — guía remisión (09 - GRE REST)
|
|
46
|
+
- `sendSummary(body)` — resumen diario boletas
|
|
47
|
+
- `sendVoided(body)` — comunicación de baja
|
|
48
|
+
|
|
49
|
+
### Consultas
|
|
50
|
+
- `listDocuments(query?)` — listado paginado con filtros
|
|
51
|
+
- `getDocument(id)` — detalle completo
|
|
52
|
+
- `getTicketStatus(ticket, ruc)` — estado de ticket asíncrono
|
|
53
|
+
|
|
54
|
+
### Archivos
|
|
55
|
+
- `getInvoiceXml(id)` → ArrayBuffer
|
|
56
|
+
- `getInvoiceCdr(id)` → ArrayBuffer (constancia SUNAT)
|
|
57
|
+
- `getInvoicePdf(id)` → ArrayBuffer
|
|
58
|
+
|
|
59
|
+
### Cola
|
|
60
|
+
- `retryDocument(id)` — re-encolar documento fallido
|
|
61
|
+
- `getQueueStats()` — estado de BullMQ
|
|
62
|
+
- `waitForDocument(id, opts?)` — polling hasta estado final
|
|
63
|
+
|
|
64
|
+
### Empresas (solo lectura)
|
|
65
|
+
- `listCompanies()`
|
|
66
|
+
- `getCompany(id)`
|
|
67
|
+
|
|
68
|
+
> Crear empresas, subir certificado/logo son operaciones administrativas
|
|
69
|
+
> (requieren `MASTER_API_KEY`) y no se exponen en el SDK — las gestiona el backend.
|
|
70
|
+
|
|
71
|
+
## Regenerar tipos
|
|
72
|
+
|
|
73
|
+
Cada vez que la API agrega o cambia endpoints:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm run gen # contra http://localhost:3000
|
|
77
|
+
npm run gen -- --url=... # contra producción
|
|
144
78
|
```
|
|
145
79
|
|
|
146
|
-
|
|
80
|
+
Esto descarga `openapi.json` y regenera `src/types.ts` con `openapi-typescript`.
|
|
81
|
+
|
|
82
|
+
## Stack
|
|
147
83
|
|
|
148
|
-
|
|
84
|
+
- `openapi-typescript` — genera tipos TS desde la spec
|
|
85
|
+
- `openapi-fetch` — runtime client liviano (<6kB) con tipado completo
|