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/dist/index.d.cts
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tipos comunes compartidos en toda la SDK
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Ambiente de ejecución ARCA
|
|
6
|
+
*/
|
|
7
|
+
type Environment = 'homologacion' | 'produccion';
|
|
8
|
+
/**
|
|
9
|
+
* Configuración base para servicios ARCA
|
|
10
|
+
*/
|
|
11
|
+
interface ArcaConfig {
|
|
12
|
+
/** Ambiente (homologación o producción) */
|
|
13
|
+
environment: Environment;
|
|
14
|
+
/** CUIT del contribuyente (11 dígitos sin guiones) */
|
|
15
|
+
cuit: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Error personalizado de ARCA SDK
|
|
19
|
+
*/
|
|
20
|
+
declare class ArcaError extends Error {
|
|
21
|
+
code: string;
|
|
22
|
+
details?: unknown | undefined;
|
|
23
|
+
constructor(message: string, code: string, details?: unknown | undefined);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error de autenticación WSAA
|
|
27
|
+
*/
|
|
28
|
+
declare class ArcaAuthError extends ArcaError {
|
|
29
|
+
constructor(message: string, details?: unknown);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Error de validación de input
|
|
33
|
+
*/
|
|
34
|
+
declare class ArcaValidationError extends ArcaError {
|
|
35
|
+
constructor(message: string, details?: unknown);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Configuración para WSAA
|
|
40
|
+
*/
|
|
41
|
+
interface WsaaConfig extends ArcaConfig {
|
|
42
|
+
/** Certificado X.509 en formato PEM */
|
|
43
|
+
cert: string;
|
|
44
|
+
/** Clave privada en formato PEM */
|
|
45
|
+
key: string;
|
|
46
|
+
/** Servicio ARCA a autenticar (ej: 'wsfe', 'wsmtxca') */
|
|
47
|
+
service: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Ticket de acceso obtenido de WSAA
|
|
51
|
+
*/
|
|
52
|
+
interface LoginTicket {
|
|
53
|
+
/** Token de autenticación */
|
|
54
|
+
token: string;
|
|
55
|
+
/** Firma del token */
|
|
56
|
+
sign: string;
|
|
57
|
+
/** Fecha de generación (ISO 8601) */
|
|
58
|
+
generationTime: Date;
|
|
59
|
+
/** Fecha de expiración (ISO 8601) */
|
|
60
|
+
expirationTime: Date;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Servicio de autenticación WSAA (Web Service de Autenticación y Autorización)
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const wsaa = new WsaaService({
|
|
69
|
+
* environment: 'homologacion',
|
|
70
|
+
* cuit: '20123456789',
|
|
71
|
+
* cert: fs.readFileSync('cert.pem', 'utf-8'),
|
|
72
|
+
* key: fs.readFileSync('key.pem', 'utf-8'),
|
|
73
|
+
* service: 'wsfe',
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* const ticket = await wsaa.login();
|
|
77
|
+
* console.log('Token:', ticket.token);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare class WsaaService {
|
|
81
|
+
private config;
|
|
82
|
+
private ticketManager;
|
|
83
|
+
constructor(config: WsaaConfig);
|
|
84
|
+
/**
|
|
85
|
+
* Valida la configuración
|
|
86
|
+
*/
|
|
87
|
+
private validateConfig;
|
|
88
|
+
/**
|
|
89
|
+
* Obtiene un ticket de acceso válido
|
|
90
|
+
* Usa cache si el ticket actual es válido
|
|
91
|
+
*
|
|
92
|
+
* @returns Ticket de acceso
|
|
93
|
+
*/
|
|
94
|
+
login(): Promise<LoginTicket>;
|
|
95
|
+
/**
|
|
96
|
+
* Solicita un nuevo ticket a WSAA
|
|
97
|
+
*/
|
|
98
|
+
private requestNewTicket;
|
|
99
|
+
/**
|
|
100
|
+
* Construye el SOAP request para WSAA
|
|
101
|
+
*/
|
|
102
|
+
private buildSoapRequest;
|
|
103
|
+
/**
|
|
104
|
+
* Limpia el ticket en cache (forzar renovación)
|
|
105
|
+
*/
|
|
106
|
+
clearCache(): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Configuración para WSFE
|
|
111
|
+
*/
|
|
112
|
+
interface WsfeConfig extends ArcaConfig {
|
|
113
|
+
/** Ticket de autenticación WSAA */
|
|
114
|
+
ticket: LoginTicket;
|
|
115
|
+
/** Punto de venta (4 dígitos) */
|
|
116
|
+
puntoVenta: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Tipo de comprobante
|
|
120
|
+
*/
|
|
121
|
+
declare enum TipoComprobante {
|
|
122
|
+
FACTURA_A = 1,
|
|
123
|
+
FACTURA_B = 6,
|
|
124
|
+
FACTURA_C = 11,
|
|
125
|
+
TICKET_A = 81,
|
|
126
|
+
TICKET_B = 82,
|
|
127
|
+
TICKET_C = 83
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Concepto de facturación
|
|
131
|
+
*/
|
|
132
|
+
declare enum Concepto {
|
|
133
|
+
PRODUCTOS = 1,// Productos
|
|
134
|
+
SERVICIOS = 2,// Servicios
|
|
135
|
+
PRODUCTOS_Y_SERVICIOS = 3
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Tipo de documento del cliente
|
|
139
|
+
*/
|
|
140
|
+
declare enum TipoDocumento {
|
|
141
|
+
CUIT = 80,
|
|
142
|
+
CUIL = 86,
|
|
143
|
+
CDI = 87,
|
|
144
|
+
LE = 89,
|
|
145
|
+
LC = 90,
|
|
146
|
+
CI_EXTRANJERA = 91,
|
|
147
|
+
PASAPORTE = 94,
|
|
148
|
+
CI_BUENOS_AIRES = 95,
|
|
149
|
+
CI_POLICIA_FEDERAL = 96,
|
|
150
|
+
DNI = 96,
|
|
151
|
+
CONSUMIDOR_FINAL = 99
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Item de factura
|
|
155
|
+
*/
|
|
156
|
+
interface FacturaItem {
|
|
157
|
+
/** Descripción del producto/servicio */
|
|
158
|
+
descripcion: string;
|
|
159
|
+
/** Cantidad */
|
|
160
|
+
cantidad: number;
|
|
161
|
+
/** Precio unitario */
|
|
162
|
+
precioUnitario: number;
|
|
163
|
+
/** IVA % (0, 10.5, 21, 27) */
|
|
164
|
+
alicuotaIva?: number;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Datos del comprador
|
|
168
|
+
*/
|
|
169
|
+
interface Comprador {
|
|
170
|
+
/** Tipo de documento */
|
|
171
|
+
tipoDocumento: TipoDocumento;
|
|
172
|
+
/** Número de documento (sin guiones) */
|
|
173
|
+
nroDocumento: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Request para emitir factura
|
|
177
|
+
*/
|
|
178
|
+
interface EmitirFacturaRequest {
|
|
179
|
+
/** Tipo de comprobante */
|
|
180
|
+
tipo: TipoComprobante;
|
|
181
|
+
/** Concepto */
|
|
182
|
+
concepto: Concepto;
|
|
183
|
+
/** Comprador (opcional para Factura C consumidor final) */
|
|
184
|
+
comprador?: Comprador;
|
|
185
|
+
/** Items de la factura (calculan el total si se proveen) */
|
|
186
|
+
items?: FacturaItem[];
|
|
187
|
+
/** Monto total (requerido si no hay items) */
|
|
188
|
+
total?: number;
|
|
189
|
+
/** Desglose de IVA (requerido para Factura B/A) */
|
|
190
|
+
ivaData?: {
|
|
191
|
+
alicuota: number;
|
|
192
|
+
baseImponible: number;
|
|
193
|
+
importe: number;
|
|
194
|
+
}[];
|
|
195
|
+
/** Fecha del comprobante (default: hoy) */
|
|
196
|
+
fecha?: Date;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Respuesta CAE (Código de Autorización Electrónico)
|
|
200
|
+
*/
|
|
201
|
+
interface CAEResponse {
|
|
202
|
+
/** Tipo de comprobante */
|
|
203
|
+
tipoComprobante: number;
|
|
204
|
+
/** Punto de venta */
|
|
205
|
+
puntoVenta: number;
|
|
206
|
+
/** Número de comprobante */
|
|
207
|
+
nroComprobante: number;
|
|
208
|
+
/** Fecha de emisión */
|
|
209
|
+
fecha: string;
|
|
210
|
+
/** CAE asignado */
|
|
211
|
+
cae: string;
|
|
212
|
+
/** Fecha de vencimiento del CAE */
|
|
213
|
+
vencimientoCae: string;
|
|
214
|
+
/** Resultado (A = Aprobado, R = Rechazado) */
|
|
215
|
+
resultado: 'A' | 'R';
|
|
216
|
+
/** Observaciones de ARCA (si hay) */
|
|
217
|
+
observaciones?: string[];
|
|
218
|
+
/** Items (se retornan si fueron proveídos en el request) */
|
|
219
|
+
items?: FacturaItem[];
|
|
220
|
+
/** Desglose IVA (solo para Factura B/A) */
|
|
221
|
+
iva?: {
|
|
222
|
+
alicuota: number;
|
|
223
|
+
baseImponible: number;
|
|
224
|
+
importe: number;
|
|
225
|
+
}[];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Servicio de Facturación Electrónica (WSFE v1)
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const wsfe = new WsfeService({
|
|
234
|
+
* environment: 'homologacion',
|
|
235
|
+
* cuit: '20123456789',
|
|
236
|
+
* ticket: await wsaa.login(),
|
|
237
|
+
* puntoVenta: 4,
|
|
238
|
+
* });
|
|
239
|
+
*
|
|
240
|
+
* const cae = await wsfe.emitirFacturaC({
|
|
241
|
+
* items: [
|
|
242
|
+
* { descripcion: 'Producto 1', cantidad: 2, precioUnitario: 100 }
|
|
243
|
+
* ]
|
|
244
|
+
* });
|
|
245
|
+
*
|
|
246
|
+
* console.log('CAE:', cae.cae);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare class WsfeService {
|
|
250
|
+
private config;
|
|
251
|
+
constructor(config: WsfeConfig);
|
|
252
|
+
private validateConfig;
|
|
253
|
+
/**
|
|
254
|
+
* Emite un Ticket C de forma simple (solo total)
|
|
255
|
+
* Tipo de comprobante: 83
|
|
256
|
+
*/
|
|
257
|
+
emitirTicketCSimple(params: {
|
|
258
|
+
total: number;
|
|
259
|
+
concepto?: Concepto;
|
|
260
|
+
fecha?: Date;
|
|
261
|
+
}): Promise<CAEResponse>;
|
|
262
|
+
/**
|
|
263
|
+
* Emite un Ticket C completo (con detalle de items)
|
|
264
|
+
* Los items no se envían a ARCA, pero se retornan en la respuesta.
|
|
265
|
+
*/
|
|
266
|
+
emitirTicketC(params: {
|
|
267
|
+
items: FacturaItem[];
|
|
268
|
+
concepto?: Concepto;
|
|
269
|
+
fecha?: Date;
|
|
270
|
+
}): Promise<CAEResponse>;
|
|
271
|
+
/**
|
|
272
|
+
* Emite una Factura B (monotributo a responsable inscripto)
|
|
273
|
+
* REQUIERE detalle de items con IVA discriminado
|
|
274
|
+
*/
|
|
275
|
+
emitirFacturaB(params: {
|
|
276
|
+
items: FacturaItem[];
|
|
277
|
+
comprador: Comprador;
|
|
278
|
+
concepto?: Concepto;
|
|
279
|
+
fecha?: Date;
|
|
280
|
+
}): Promise<CAEResponse>;
|
|
281
|
+
/**
|
|
282
|
+
* Emite una Factura A (RI a RI)
|
|
283
|
+
* REQUIERE detalle de items con IVA discriminado
|
|
284
|
+
*/
|
|
285
|
+
emitirFacturaA(params: {
|
|
286
|
+
items: FacturaItem[];
|
|
287
|
+
comprador: Comprador;
|
|
288
|
+
concepto?: Concepto;
|
|
289
|
+
fecha?: Date;
|
|
290
|
+
}): Promise<CAEResponse>;
|
|
291
|
+
/**
|
|
292
|
+
* Valida que todos los items tengan alícuota IVA definida
|
|
293
|
+
*/
|
|
294
|
+
private validateItemsWithIVA;
|
|
295
|
+
/**
|
|
296
|
+
* Calcula IVA agrupado por alícuota
|
|
297
|
+
* ARCA requiere esto para Factura B/A
|
|
298
|
+
*/
|
|
299
|
+
private calcularIVAPorAlicuota;
|
|
300
|
+
/**
|
|
301
|
+
* Emite una Factura C (consumidor final)
|
|
302
|
+
* Forma simplificada sin especificar comprador
|
|
303
|
+
*/
|
|
304
|
+
emitirFacturaC(params: {
|
|
305
|
+
items: FacturaItem[];
|
|
306
|
+
concepto?: Concepto;
|
|
307
|
+
fecha?: Date;
|
|
308
|
+
}): Promise<CAEResponse>;
|
|
309
|
+
/**
|
|
310
|
+
* Emite un comprobante (método genérico interno)
|
|
311
|
+
*/
|
|
312
|
+
emitirComprobante(request: EmitirFacturaRequest): Promise<CAEResponse>;
|
|
313
|
+
/**
|
|
314
|
+
* Obtiene el próximo número de comprobante disponible
|
|
315
|
+
*/
|
|
316
|
+
private obtenerProximoNumero;
|
|
317
|
+
private buildCAESolicitarRequest;
|
|
318
|
+
/**
|
|
319
|
+
* Mapea alícuota % a código ARCA
|
|
320
|
+
*/
|
|
321
|
+
private getCodigoAlicuota;
|
|
322
|
+
private buildProximoNumeroRequest;
|
|
323
|
+
private parseCAEResponse;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export { ArcaAuthError, type ArcaConfig, ArcaError, ArcaValidationError, type CAEResponse, type Comprador, Concepto, type EmitirFacturaRequest, type Environment, type FacturaItem, type LoginTicket, TipoComprobante, TipoDocumento, type WsaaConfig, WsaaService, type WsfeConfig, WsfeService };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tipos comunes compartidos en toda la SDK
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Ambiente de ejecución ARCA
|
|
6
|
+
*/
|
|
7
|
+
type Environment = 'homologacion' | 'produccion';
|
|
8
|
+
/**
|
|
9
|
+
* Configuración base para servicios ARCA
|
|
10
|
+
*/
|
|
11
|
+
interface ArcaConfig {
|
|
12
|
+
/** Ambiente (homologación o producción) */
|
|
13
|
+
environment: Environment;
|
|
14
|
+
/** CUIT del contribuyente (11 dígitos sin guiones) */
|
|
15
|
+
cuit: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Error personalizado de ARCA SDK
|
|
19
|
+
*/
|
|
20
|
+
declare class ArcaError extends Error {
|
|
21
|
+
code: string;
|
|
22
|
+
details?: unknown | undefined;
|
|
23
|
+
constructor(message: string, code: string, details?: unknown | undefined);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error de autenticación WSAA
|
|
27
|
+
*/
|
|
28
|
+
declare class ArcaAuthError extends ArcaError {
|
|
29
|
+
constructor(message: string, details?: unknown);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Error de validación de input
|
|
33
|
+
*/
|
|
34
|
+
declare class ArcaValidationError extends ArcaError {
|
|
35
|
+
constructor(message: string, details?: unknown);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Configuración para WSAA
|
|
40
|
+
*/
|
|
41
|
+
interface WsaaConfig extends ArcaConfig {
|
|
42
|
+
/** Certificado X.509 en formato PEM */
|
|
43
|
+
cert: string;
|
|
44
|
+
/** Clave privada en formato PEM */
|
|
45
|
+
key: string;
|
|
46
|
+
/** Servicio ARCA a autenticar (ej: 'wsfe', 'wsmtxca') */
|
|
47
|
+
service: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Ticket de acceso obtenido de WSAA
|
|
51
|
+
*/
|
|
52
|
+
interface LoginTicket {
|
|
53
|
+
/** Token de autenticación */
|
|
54
|
+
token: string;
|
|
55
|
+
/** Firma del token */
|
|
56
|
+
sign: string;
|
|
57
|
+
/** Fecha de generación (ISO 8601) */
|
|
58
|
+
generationTime: Date;
|
|
59
|
+
/** Fecha de expiración (ISO 8601) */
|
|
60
|
+
expirationTime: Date;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Servicio de autenticación WSAA (Web Service de Autenticación y Autorización)
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const wsaa = new WsaaService({
|
|
69
|
+
* environment: 'homologacion',
|
|
70
|
+
* cuit: '20123456789',
|
|
71
|
+
* cert: fs.readFileSync('cert.pem', 'utf-8'),
|
|
72
|
+
* key: fs.readFileSync('key.pem', 'utf-8'),
|
|
73
|
+
* service: 'wsfe',
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* const ticket = await wsaa.login();
|
|
77
|
+
* console.log('Token:', ticket.token);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare class WsaaService {
|
|
81
|
+
private config;
|
|
82
|
+
private ticketManager;
|
|
83
|
+
constructor(config: WsaaConfig);
|
|
84
|
+
/**
|
|
85
|
+
* Valida la configuración
|
|
86
|
+
*/
|
|
87
|
+
private validateConfig;
|
|
88
|
+
/**
|
|
89
|
+
* Obtiene un ticket de acceso válido
|
|
90
|
+
* Usa cache si el ticket actual es válido
|
|
91
|
+
*
|
|
92
|
+
* @returns Ticket de acceso
|
|
93
|
+
*/
|
|
94
|
+
login(): Promise<LoginTicket>;
|
|
95
|
+
/**
|
|
96
|
+
* Solicita un nuevo ticket a WSAA
|
|
97
|
+
*/
|
|
98
|
+
private requestNewTicket;
|
|
99
|
+
/**
|
|
100
|
+
* Construye el SOAP request para WSAA
|
|
101
|
+
*/
|
|
102
|
+
private buildSoapRequest;
|
|
103
|
+
/**
|
|
104
|
+
* Limpia el ticket en cache (forzar renovación)
|
|
105
|
+
*/
|
|
106
|
+
clearCache(): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Configuración para WSFE
|
|
111
|
+
*/
|
|
112
|
+
interface WsfeConfig extends ArcaConfig {
|
|
113
|
+
/** Ticket de autenticación WSAA */
|
|
114
|
+
ticket: LoginTicket;
|
|
115
|
+
/** Punto de venta (4 dígitos) */
|
|
116
|
+
puntoVenta: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Tipo de comprobante
|
|
120
|
+
*/
|
|
121
|
+
declare enum TipoComprobante {
|
|
122
|
+
FACTURA_A = 1,
|
|
123
|
+
FACTURA_B = 6,
|
|
124
|
+
FACTURA_C = 11,
|
|
125
|
+
TICKET_A = 81,
|
|
126
|
+
TICKET_B = 82,
|
|
127
|
+
TICKET_C = 83
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Concepto de facturación
|
|
131
|
+
*/
|
|
132
|
+
declare enum Concepto {
|
|
133
|
+
PRODUCTOS = 1,// Productos
|
|
134
|
+
SERVICIOS = 2,// Servicios
|
|
135
|
+
PRODUCTOS_Y_SERVICIOS = 3
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Tipo de documento del cliente
|
|
139
|
+
*/
|
|
140
|
+
declare enum TipoDocumento {
|
|
141
|
+
CUIT = 80,
|
|
142
|
+
CUIL = 86,
|
|
143
|
+
CDI = 87,
|
|
144
|
+
LE = 89,
|
|
145
|
+
LC = 90,
|
|
146
|
+
CI_EXTRANJERA = 91,
|
|
147
|
+
PASAPORTE = 94,
|
|
148
|
+
CI_BUENOS_AIRES = 95,
|
|
149
|
+
CI_POLICIA_FEDERAL = 96,
|
|
150
|
+
DNI = 96,
|
|
151
|
+
CONSUMIDOR_FINAL = 99
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Item de factura
|
|
155
|
+
*/
|
|
156
|
+
interface FacturaItem {
|
|
157
|
+
/** Descripción del producto/servicio */
|
|
158
|
+
descripcion: string;
|
|
159
|
+
/** Cantidad */
|
|
160
|
+
cantidad: number;
|
|
161
|
+
/** Precio unitario */
|
|
162
|
+
precioUnitario: number;
|
|
163
|
+
/** IVA % (0, 10.5, 21, 27) */
|
|
164
|
+
alicuotaIva?: number;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Datos del comprador
|
|
168
|
+
*/
|
|
169
|
+
interface Comprador {
|
|
170
|
+
/** Tipo de documento */
|
|
171
|
+
tipoDocumento: TipoDocumento;
|
|
172
|
+
/** Número de documento (sin guiones) */
|
|
173
|
+
nroDocumento: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Request para emitir factura
|
|
177
|
+
*/
|
|
178
|
+
interface EmitirFacturaRequest {
|
|
179
|
+
/** Tipo de comprobante */
|
|
180
|
+
tipo: TipoComprobante;
|
|
181
|
+
/** Concepto */
|
|
182
|
+
concepto: Concepto;
|
|
183
|
+
/** Comprador (opcional para Factura C consumidor final) */
|
|
184
|
+
comprador?: Comprador;
|
|
185
|
+
/** Items de la factura (calculan el total si se proveen) */
|
|
186
|
+
items?: FacturaItem[];
|
|
187
|
+
/** Monto total (requerido si no hay items) */
|
|
188
|
+
total?: number;
|
|
189
|
+
/** Desglose de IVA (requerido para Factura B/A) */
|
|
190
|
+
ivaData?: {
|
|
191
|
+
alicuota: number;
|
|
192
|
+
baseImponible: number;
|
|
193
|
+
importe: number;
|
|
194
|
+
}[];
|
|
195
|
+
/** Fecha del comprobante (default: hoy) */
|
|
196
|
+
fecha?: Date;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Respuesta CAE (Código de Autorización Electrónico)
|
|
200
|
+
*/
|
|
201
|
+
interface CAEResponse {
|
|
202
|
+
/** Tipo de comprobante */
|
|
203
|
+
tipoComprobante: number;
|
|
204
|
+
/** Punto de venta */
|
|
205
|
+
puntoVenta: number;
|
|
206
|
+
/** Número de comprobante */
|
|
207
|
+
nroComprobante: number;
|
|
208
|
+
/** Fecha de emisión */
|
|
209
|
+
fecha: string;
|
|
210
|
+
/** CAE asignado */
|
|
211
|
+
cae: string;
|
|
212
|
+
/** Fecha de vencimiento del CAE */
|
|
213
|
+
vencimientoCae: string;
|
|
214
|
+
/** Resultado (A = Aprobado, R = Rechazado) */
|
|
215
|
+
resultado: 'A' | 'R';
|
|
216
|
+
/** Observaciones de ARCA (si hay) */
|
|
217
|
+
observaciones?: string[];
|
|
218
|
+
/** Items (se retornan si fueron proveídos en el request) */
|
|
219
|
+
items?: FacturaItem[];
|
|
220
|
+
/** Desglose IVA (solo para Factura B/A) */
|
|
221
|
+
iva?: {
|
|
222
|
+
alicuota: number;
|
|
223
|
+
baseImponible: number;
|
|
224
|
+
importe: number;
|
|
225
|
+
}[];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Servicio de Facturación Electrónica (WSFE v1)
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const wsfe = new WsfeService({
|
|
234
|
+
* environment: 'homologacion',
|
|
235
|
+
* cuit: '20123456789',
|
|
236
|
+
* ticket: await wsaa.login(),
|
|
237
|
+
* puntoVenta: 4,
|
|
238
|
+
* });
|
|
239
|
+
*
|
|
240
|
+
* const cae = await wsfe.emitirFacturaC({
|
|
241
|
+
* items: [
|
|
242
|
+
* { descripcion: 'Producto 1', cantidad: 2, precioUnitario: 100 }
|
|
243
|
+
* ]
|
|
244
|
+
* });
|
|
245
|
+
*
|
|
246
|
+
* console.log('CAE:', cae.cae);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare class WsfeService {
|
|
250
|
+
private config;
|
|
251
|
+
constructor(config: WsfeConfig);
|
|
252
|
+
private validateConfig;
|
|
253
|
+
/**
|
|
254
|
+
* Emite un Ticket C de forma simple (solo total)
|
|
255
|
+
* Tipo de comprobante: 83
|
|
256
|
+
*/
|
|
257
|
+
emitirTicketCSimple(params: {
|
|
258
|
+
total: number;
|
|
259
|
+
concepto?: Concepto;
|
|
260
|
+
fecha?: Date;
|
|
261
|
+
}): Promise<CAEResponse>;
|
|
262
|
+
/**
|
|
263
|
+
* Emite un Ticket C completo (con detalle de items)
|
|
264
|
+
* Los items no se envían a ARCA, pero se retornan en la respuesta.
|
|
265
|
+
*/
|
|
266
|
+
emitirTicketC(params: {
|
|
267
|
+
items: FacturaItem[];
|
|
268
|
+
concepto?: Concepto;
|
|
269
|
+
fecha?: Date;
|
|
270
|
+
}): Promise<CAEResponse>;
|
|
271
|
+
/**
|
|
272
|
+
* Emite una Factura B (monotributo a responsable inscripto)
|
|
273
|
+
* REQUIERE detalle de items con IVA discriminado
|
|
274
|
+
*/
|
|
275
|
+
emitirFacturaB(params: {
|
|
276
|
+
items: FacturaItem[];
|
|
277
|
+
comprador: Comprador;
|
|
278
|
+
concepto?: Concepto;
|
|
279
|
+
fecha?: Date;
|
|
280
|
+
}): Promise<CAEResponse>;
|
|
281
|
+
/**
|
|
282
|
+
* Emite una Factura A (RI a RI)
|
|
283
|
+
* REQUIERE detalle de items con IVA discriminado
|
|
284
|
+
*/
|
|
285
|
+
emitirFacturaA(params: {
|
|
286
|
+
items: FacturaItem[];
|
|
287
|
+
comprador: Comprador;
|
|
288
|
+
concepto?: Concepto;
|
|
289
|
+
fecha?: Date;
|
|
290
|
+
}): Promise<CAEResponse>;
|
|
291
|
+
/**
|
|
292
|
+
* Valida que todos los items tengan alícuota IVA definida
|
|
293
|
+
*/
|
|
294
|
+
private validateItemsWithIVA;
|
|
295
|
+
/**
|
|
296
|
+
* Calcula IVA agrupado por alícuota
|
|
297
|
+
* ARCA requiere esto para Factura B/A
|
|
298
|
+
*/
|
|
299
|
+
private calcularIVAPorAlicuota;
|
|
300
|
+
/**
|
|
301
|
+
* Emite una Factura C (consumidor final)
|
|
302
|
+
* Forma simplificada sin especificar comprador
|
|
303
|
+
*/
|
|
304
|
+
emitirFacturaC(params: {
|
|
305
|
+
items: FacturaItem[];
|
|
306
|
+
concepto?: Concepto;
|
|
307
|
+
fecha?: Date;
|
|
308
|
+
}): Promise<CAEResponse>;
|
|
309
|
+
/**
|
|
310
|
+
* Emite un comprobante (método genérico interno)
|
|
311
|
+
*/
|
|
312
|
+
emitirComprobante(request: EmitirFacturaRequest): Promise<CAEResponse>;
|
|
313
|
+
/**
|
|
314
|
+
* Obtiene el próximo número de comprobante disponible
|
|
315
|
+
*/
|
|
316
|
+
private obtenerProximoNumero;
|
|
317
|
+
private buildCAESolicitarRequest;
|
|
318
|
+
/**
|
|
319
|
+
* Mapea alícuota % a código ARCA
|
|
320
|
+
*/
|
|
321
|
+
private getCodigoAlicuota;
|
|
322
|
+
private buildProximoNumeroRequest;
|
|
323
|
+
private parseCAEResponse;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export { ArcaAuthError, type ArcaConfig, ArcaError, ArcaValidationError, type CAEResponse, type Comprador, Concepto, type EmitirFacturaRequest, type Environment, type FacturaItem, type LoginTicket, TipoComprobante, TipoDocumento, type WsaaConfig, WsaaService, type WsfeConfig, WsfeService };
|