@ramiidv/arca-mtxca 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.
@@ -0,0 +1,211 @@
1
+ export type { AccessTicket, ArcaEvent, ServerStatus, SoapCallOptions } from '@ramiidv/arca-common';
2
+ import type { ArcaEvent } from '@ramiidv/arca-common';
3
+ export interface ArcaMtxcaConfig {
4
+ /** Contenido del certificado X.509 en formato PEM */
5
+ cert: string;
6
+ /** Contenido de la clave privada en formato PEM */
7
+ key: string;
8
+ /** CUIT del contribuyente (sin guiones) */
9
+ cuit: number;
10
+ /** Usar entorno de produccion (default: false = testing/homologacion) */
11
+ production?: boolean;
12
+ /** Timeout para requests HTTP en milisegundos (default: 30000) */
13
+ timeout?: number;
14
+ /** Cantidad de reintentos en caso de error transitorio (default: 1) */
15
+ retries?: number;
16
+ /** Delay inicial entre reintentos en milisegundos, se duplica con cada intento (default: 1000) */
17
+ retryDelayMs?: number;
18
+ /** Callback para eventos del SDK (auth, requests, retries) */
19
+ onEvent?: (event: ArcaEvent) => void;
20
+ }
21
+ export interface MtxcaAuth {
22
+ Token: string;
23
+ Sign: string;
24
+ Cuit: number;
25
+ }
26
+ export interface MtxcaItem {
27
+ /** Codigo/Barcode del producto (EAN, interno, etc.) */
28
+ codigo?: string;
29
+ /** Descripcion del producto/servicio */
30
+ descripcion: string;
31
+ /** Cantidad */
32
+ cantidad: number;
33
+ /** Codigo de unidad de medida (consultarUnidadesMedida) */
34
+ unidadMedida: number;
35
+ /** Precio unitario */
36
+ precioUnitario: number;
37
+ /** Importe total del item (cantidad * precioUnitario - bonificacion) */
38
+ importeItem: number;
39
+ /** Codigo de condicion de IVA del item (usar enum CodigoCondicionIVA) */
40
+ codigoCondicionIVA: number;
41
+ /** Importe de IVA del item */
42
+ importeIVA: number;
43
+ /** Importe de bonificacion/descuento. Default: 0 */
44
+ importeBonificacion?: number;
45
+ }
46
+ export interface SubtotalIVA {
47
+ /** Codigo de condicion de IVA */
48
+ codigo: number;
49
+ /** Base imponible */
50
+ baseImponible: number;
51
+ /** Importe de IVA */
52
+ importe: number;
53
+ }
54
+ export interface MtxcaComprobanteAsociado {
55
+ /** Tipo de comprobante asociado */
56
+ codigoTipoComprobante: number;
57
+ /** Punto de venta del comprobante asociado */
58
+ numeroPuntoVenta: number;
59
+ /** Numero de comprobante asociado */
60
+ numeroComprobante: number;
61
+ /** CUIT del emisor */
62
+ cuit?: number;
63
+ }
64
+ export interface MtxcaTributo {
65
+ /** Codigo del tributo */
66
+ codigoTributo: number;
67
+ /** Descripcion del tributo */
68
+ descripcion?: string;
69
+ /** Base imponible */
70
+ baseImponible: number;
71
+ /** Alicuota del tributo */
72
+ alicuota?: number;
73
+ /** Importe del tributo */
74
+ importe: number;
75
+ }
76
+ export interface MtxcaInvoice {
77
+ /** Concepto: 1=Productos, 2=Servicios, 3=Productos y Servicios */
78
+ concepto: number;
79
+ /** Tipo de documento del receptor */
80
+ docTipo: number;
81
+ /** Numero de documento del receptor */
82
+ docNro: number;
83
+ /** Fecha del comprobante (formato YYYY-MM-DD) */
84
+ cbteFch: string;
85
+ /** Items / articulos del comprobante */
86
+ items: MtxcaItem[];
87
+ /** Codigo de moneda (usar enum Moneda). Default: PES */
88
+ codigoMoneda?: string;
89
+ /** Cotizacion de la moneda (1 para pesos) */
90
+ cotizacionMoneda?: number;
91
+ /** Importe gravado */
92
+ importeGravado?: number;
93
+ /** Importe no gravado */
94
+ importeNoGravado?: number;
95
+ /** Importe exento */
96
+ importeExento?: number;
97
+ /** Subtotales de IVA */
98
+ subtotalesIVA?: SubtotalIVA[];
99
+ /** Importe total de tributos */
100
+ importeOtrosTributos?: number;
101
+ /** Detalle de tributos */
102
+ otrosTributos?: MtxcaTributo[];
103
+ /** Importe total del comprobante */
104
+ importeTotal: number;
105
+ /** Comprobantes asociados (para NC/ND) */
106
+ comprobanteAsociado?: MtxcaComprobanteAsociado[];
107
+ /** Fecha desde del servicio (formato YYYY-MM-DD, requerido para servicios) */
108
+ fechaDesde?: string;
109
+ /** Fecha hasta del servicio (formato YYYY-MM-DD, requerido para servicios) */
110
+ fechaHasta?: string;
111
+ /** Fecha de vencimiento de pago (formato YYYY-MM-DD, requerido para servicios) */
112
+ fechaVtoPago?: string;
113
+ /** Observaciones */
114
+ observaciones?: string;
115
+ }
116
+ export interface MtxcaObservacion {
117
+ code: number;
118
+ msg: string;
119
+ }
120
+ export interface MtxcaInvoiceResult {
121
+ /** Resultado: "A" = Aprobado, "R" = Rechazado */
122
+ resultado: string;
123
+ /** CAE otorgado (solo si aprobado) */
124
+ cae?: string;
125
+ /** Fecha de vencimiento del CAE (YYYY-MM-DD) */
126
+ caeFchVto?: string;
127
+ /** Numero de comprobante asignado */
128
+ cbteNro: number;
129
+ /** Observaciones de ARCA */
130
+ observaciones: MtxcaObservacion[];
131
+ /** Errores de ARCA */
132
+ errores: MtxcaObservacion[];
133
+ }
134
+ export interface AutorizarRequest {
135
+ /** Punto de venta */
136
+ ptoVta: number;
137
+ /** Tipo de comprobante (usar enum CbteTipo) */
138
+ cbteTipo: number;
139
+ /** Detalle del comprobante con articulos */
140
+ invoice: MtxcaInvoice;
141
+ }
142
+ export interface MtxcaComprobante {
143
+ codigoTipoComprobante: number;
144
+ numeroPuntoVenta: number;
145
+ numeroComprobante: number;
146
+ fechaEmision: string;
147
+ codigoTipoDocumento: number;
148
+ numeroDocumento: number;
149
+ importeTotal: number;
150
+ importeNoGravado: number;
151
+ importeGravado: number;
152
+ importeExento: number;
153
+ importeOtrosTributos: number;
154
+ importeSubtotal: number;
155
+ codigoMoneda: string;
156
+ cotizacionMoneda: number;
157
+ resultado: string;
158
+ codigoAutorizacion?: string;
159
+ fechaVencimiento?: string;
160
+ observaciones: MtxcaObservacion[];
161
+ items: MtxcaItem[];
162
+ }
163
+ export interface ParamItem {
164
+ /** ID numerico del parametro */
165
+ Id: number;
166
+ /** Descripcion */
167
+ Desc: string;
168
+ /** Fecha vigencia desde */
169
+ FchDesde?: string;
170
+ /** Fecha vigencia hasta */
171
+ FchHasta?: string;
172
+ }
173
+ export interface MonedaItem {
174
+ /** Codigo de moneda (ej: "PES", "DOL") */
175
+ Id: string;
176
+ /** Descripcion */
177
+ Desc: string;
178
+ /** Fecha vigencia desde */
179
+ FchDesde?: string;
180
+ /** Fecha vigencia hasta */
181
+ FchHasta?: string;
182
+ }
183
+ export interface UnidadMedidaItem {
184
+ /** Codigo de unidad de medida */
185
+ Id: number;
186
+ /** Descripcion */
187
+ Desc: string;
188
+ /** Fecha vigencia desde */
189
+ FchDesde?: string;
190
+ /** Fecha vigencia hasta */
191
+ FchHasta?: string;
192
+ }
193
+ export interface PtoVentaItem {
194
+ /** Numero de punto de venta */
195
+ Nro: number;
196
+ /** Tipo de emision (CAE/CAEA) */
197
+ EmisionTipo: string;
198
+ /** Si esta bloqueado */
199
+ Bloqueado: string;
200
+ /** Fecha de baja */
201
+ FchBaja: string;
202
+ }
203
+ export interface CotizacionResult {
204
+ /** Codigo de moneda */
205
+ monedaId: string;
206
+ /** Cotizacion */
207
+ cotizacion: number;
208
+ /** Fecha de cotizacion */
209
+ fechaCotizacion: string;
210
+ }
211
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAMtD,MAAM,WAAW,eAAe;IAC9B,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;IAC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,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,eAAe,EAAE,MAAM,CAAC;CACzB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import type { AutorizarRequest, MtxcaItem } from './types.js';
2
+ /**
3
+ * Validates a single MTXCA item (line-level detail).
4
+ *
5
+ * @throws ArcaValidationError if any field is invalid
6
+ */
7
+ export declare function validateMtxcaItem(item: MtxcaItem, index?: number): void;
8
+ /**
9
+ * Validates the full autorizar request (ptoVta, cbteTipo, invoice fields, and items).
10
+ *
11
+ * @throws ArcaValidationError if any field is invalid
12
+ */
13
+ export declare function validateAutorizarRequest(request: AutorizarRequest): void;
14
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CA0CvE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CA2ExE"}
@@ -0,0 +1,111 @@
1
+ import { ArcaValidationError } from '@ramiidv/arca-common';
2
+ /**
3
+ * Validates a single MTXCA item (line-level detail).
4
+ *
5
+ * @throws ArcaValidationError if any field is invalid
6
+ */
7
+ export function validateMtxcaItem(item, index) {
8
+ const errors = [];
9
+ const prefix = index != null ? `items[${index}].` : '';
10
+ if (!item.descripcion) {
11
+ errors.push({
12
+ field: `${prefix}descripcion`,
13
+ message: 'descripcion es requerido',
14
+ value: item.descripcion,
15
+ });
16
+ }
17
+ if (item.cantidad == null || item.cantidad <= 0) {
18
+ errors.push({
19
+ field: `${prefix}cantidad`,
20
+ message: 'cantidad debe ser > 0',
21
+ value: item.cantidad,
22
+ });
23
+ }
24
+ if (item.precioUnitario == null || item.precioUnitario < 0) {
25
+ errors.push({
26
+ field: `${prefix}precioUnitario`,
27
+ message: 'precioUnitario debe ser >= 0',
28
+ value: item.precioUnitario,
29
+ });
30
+ }
31
+ if (item.unidadMedida == null || item.unidadMedida <= 0) {
32
+ errors.push({
33
+ field: `${prefix}unidadMedida`,
34
+ message: 'unidadMedida debe ser > 0',
35
+ value: item.unidadMedida,
36
+ });
37
+ }
38
+ if (errors.length > 0) {
39
+ throw new ArcaValidationError(`Validacion de item fallida: ${errors.map((e) => e.message).join('; ')}`, errors);
40
+ }
41
+ }
42
+ /**
43
+ * Validates the full autorizar request (ptoVta, cbteTipo, invoice fields, and items).
44
+ *
45
+ * @throws ArcaValidationError if any field is invalid
46
+ */
47
+ export function validateAutorizarRequest(request) {
48
+ const errors = [];
49
+ if (request.ptoVta == null || request.ptoVta <= 0) {
50
+ errors.push({
51
+ field: 'ptoVta',
52
+ message: 'ptoVta debe ser > 0',
53
+ value: request.ptoVta,
54
+ });
55
+ }
56
+ if (request.cbteTipo == null || request.cbteTipo <= 0) {
57
+ errors.push({
58
+ field: 'cbteTipo',
59
+ message: 'cbteTipo debe ser > 0',
60
+ value: request.cbteTipo,
61
+ });
62
+ }
63
+ if (!request.invoice) {
64
+ errors.push({
65
+ field: 'invoice',
66
+ message: 'invoice es requerido',
67
+ value: request.invoice,
68
+ });
69
+ // Cannot validate further without invoice
70
+ throw new ArcaValidationError(`Validacion de AutorizarRequest fallida: ${errors.map((e) => e.message).join('; ')}`, errors);
71
+ }
72
+ const inv = request.invoice;
73
+ if (!inv.cbteFch) {
74
+ errors.push({
75
+ field: 'invoice.cbteFch',
76
+ message: 'cbteFch es requerido',
77
+ value: inv.cbteFch,
78
+ });
79
+ }
80
+ if (inv.importeTotal == null || inv.importeTotal < 0) {
81
+ errors.push({
82
+ field: 'invoice.importeTotal',
83
+ message: 'importeTotal debe ser >= 0',
84
+ value: inv.importeTotal,
85
+ });
86
+ }
87
+ if (!inv.items || inv.items.length === 0) {
88
+ errors.push({
89
+ field: 'invoice.items',
90
+ message: 'items no puede estar vacio',
91
+ value: inv.items,
92
+ });
93
+ }
94
+ else {
95
+ // Validate each item, collecting errors
96
+ for (let i = 0; i < inv.items.length; i++) {
97
+ try {
98
+ validateMtxcaItem(inv.items[i], i);
99
+ }
100
+ catch (e) {
101
+ if (e instanceof ArcaValidationError) {
102
+ errors.push(...e.details);
103
+ }
104
+ }
105
+ }
106
+ }
107
+ if (errors.length > 0) {
108
+ throw new ArcaValidationError(`Validacion de AutorizarRequest fallida: ${errors.map((e) => e.message).join('; ')}`, errors);
109
+ }
110
+ }
111
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAI3D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAe,EAAE,KAAc;IAC/D,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAEvD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC;YACV,KAAK,EAAE,GAAG,MAAM,aAAa;YAC7B,OAAO,EAAE,0BAA0B;YACnC,KAAK,EAAE,IAAI,CAAC,WAAW;SACxB,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC;YACV,KAAK,EAAE,GAAG,MAAM,UAAU;YAC1B,OAAO,EAAE,uBAAuB;YAChC,KAAK,EAAE,IAAI,CAAC,QAAQ;SACrB,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,IAAI,IAAI,CAAC,cAAc,GAAG,CAAC,EAAE,CAAC;QAC3D,MAAM,CAAC,IAAI,CAAC;YACV,KAAK,EAAE,GAAG,MAAM,gBAAgB;Y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AAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,YAAY,mBAAmB,EAAE,CAAC;oBACrC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,mBAAmB,CAC3B,2CAA2C,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EACpF,MAAM,CACP,CAAC;IACJ,CAAC;AACH,CAAC"}
package/llms.txt ADDED
@@ -0,0 +1,186 @@
1
+ # @ramiidv/arca-mtxca
2
+
3
+ > TypeScript SDK para el web service WSMTXCA de ARCA (ex AFIP) - Facturacion electronica con detalle de articulos
4
+
5
+ ## Instalacion
6
+
7
+ ```bash
8
+ npm install @ramiidv/arca-mtxca
9
+ ```
10
+
11
+ Requisitos: Node.js >= 18 (fetch nativo). ESM only.
12
+
13
+ ## Configuracion
14
+
15
+ ```typescript
16
+ import { ArcaMtxca } from '@ramiidv/arca-mtxca';
17
+
18
+ const mtxca = new ArcaMtxca({
19
+ cert: string, // PEM X.509 certificate
20
+ key: string, // PEM RSA private key
21
+ cuit: number, // CUIT del contribuyente (ej: 20123456789)
22
+ production?: boolean, // default: false (homologacion)
23
+ timeout?: number, // default: 30000
24
+ retries?: number, // default: 1
25
+ retryDelayMs?: number, // default: 1000
26
+ onEvent?: (event: ArcaEvent) => void,
27
+ });
28
+ ```
29
+
30
+ ## WSMTXCA vs WSFEv1
31
+
32
+ WSMTXCA: facturacion con detalle de articulos (arrayItems con codigo, descripcion, cantidad, precioUnitario, importeItem, codigoCondicionIVA, importeIVA por linea). Fechas en formato YYYY-MM-DD. Soporta tipos A, B, M. Protocolo SOAP Java.
33
+ WSFEv1: facturacion sin detalle de items (solo subtotales globales de IVA). Fechas en formato YYYYMMDD. Soporta A, B, C, E, M, FCE. Protocolo SOAP .NET.
34
+
35
+ ## Metodos principales
36
+
37
+ ### autorizar(request: AutorizarRequest): Promise<MtxcaInvoiceResult>
38
+ Autoriza un comprobante con detalle de articulos. Retorna CAE si aprobado. El request contiene ptoVta, cbteTipo, y un objeto invoice con concepto, docTipo, docNro, cbteFch (YYYY-MM-DD), importeTotal, items[], y campos opcionales (subtotalesIVA, otrosTributos, comprobanteAsociado, fechas de servicio).
39
+
40
+ ### ultimoComprobante(ptoVta: number, cbteTipo: number): Promise<number>
41
+ Ultimo numero de comprobante autorizado.
42
+
43
+ ### siguienteComprobante(ptoVta: number, cbteTipo: number): Promise<number>
44
+ Siguiente numero de comprobante (ultimo + 1).
45
+
46
+ ### consultarComprobante(cbteTipo: number, ptoVta: number, cbteNro: number): Promise<MtxcaComprobante>
47
+ Consulta un comprobante previamente autorizado, incluyendo detalle de items.
48
+
49
+ ### status(): Promise<ServerStatus>
50
+ Health check. No requiere autenticacion.
51
+
52
+ ### Parametros
53
+ - getTiposComprobante(): Promise<ParamItem[]>
54
+ - getTiposDocumento(): Promise<ParamItem[]>
55
+ - getAlicuotasIVA(): Promise<ParamItem[]>
56
+ - getCondicionesIVA(): Promise<ParamItem[]>
57
+ - getMonedas(): Promise<MonedaItem[]>
58
+ - getUnidadesMedida(): Promise<UnidadMedidaItem[]>
59
+ - getPuntosVenta(): Promise<PtoVentaItem[]>
60
+ - getPuntosVentaCAE(): Promise<PtoVentaItem[]>
61
+ - getPuntosVentaCAEA(): Promise<PtoVentaItem[]>
62
+ - getCotizacionMoneda(monedaId: string): Promise<CotizacionResult>
63
+
64
+ ## Tipos principales
65
+
66
+ ```typescript
67
+ interface MtxcaItem {
68
+ codigo?: string;
69
+ descripcion: string;
70
+ cantidad: number;
71
+ unidadMedida: number;
72
+ precioUnitario: number;
73
+ importeItem: number;
74
+ codigoCondicionIVA: number;
75
+ importeIVA: number;
76
+ importeBonificacion?: number;
77
+ }
78
+
79
+ interface SubtotalIVA {
80
+ codigo: number;
81
+ baseImponible: number;
82
+ importe: number;
83
+ }
84
+
85
+ interface MtxcaInvoice {
86
+ concepto: number;
87
+ docTipo: number;
88
+ docNro: number;
89
+ cbteFch: string; // YYYY-MM-DD
90
+ items: MtxcaItem[];
91
+ importeTotal: number;
92
+ codigoMoneda?: string;
93
+ cotizacionMoneda?: number;
94
+ importeGravado?: number;
95
+ importeNoGravado?: number;
96
+ importeExento?: number;
97
+ subtotalesIVA?: SubtotalIVA[];
98
+ importeOtrosTributos?: number;
99
+ otrosTributos?: MtxcaTributo[];
100
+ comprobanteAsociado?: MtxcaComprobanteAsociado[];
101
+ fechaDesde?: string;
102
+ fechaHasta?: string;
103
+ fechaVtoPago?: string;
104
+ observaciones?: string;
105
+ }
106
+
107
+ interface AutorizarRequest {
108
+ ptoVta: number;
109
+ cbteTipo: number;
110
+ invoice: MtxcaInvoice;
111
+ }
112
+
113
+ interface MtxcaInvoiceResult {
114
+ resultado: string; // "A" or "R"
115
+ cae?: string;
116
+ caeFchVto?: string;
117
+ cbteNro: number;
118
+ observaciones: MtxcaObservacion[];
119
+ errores: MtxcaObservacion[];
120
+ }
121
+
122
+ interface MtxcaComprobante {
123
+ codigoTipoComprobante: number;
124
+ numeroPuntoVenta: number;
125
+ numeroComprobante: number;
126
+ fechaEmision: string;
127
+ codigoTipoDocumento: number;
128
+ numeroDocumento: number;
129
+ importeTotal: number;
130
+ importeNoGravado: number;
131
+ importeGravado: number;
132
+ importeExento: number;
133
+ importeOtrosTributos: number;
134
+ importeSubtotal: number;
135
+ codigoMoneda: string;
136
+ cotizacionMoneda: number;
137
+ resultado: string;
138
+ codigoAutorizacion?: string;
139
+ fechaVencimiento?: string;
140
+ observaciones: MtxcaObservacion[];
141
+ items: MtxcaItem[];
142
+ }
143
+
144
+ interface MtxcaObservacion { code: number; msg: string; }
145
+ interface MtxcaTributo { codigoTributo: number; descripcion?: string; baseImponible: number; alicuota?: number; importe: number; }
146
+ interface MtxcaComprobanteAsociado { codigoTipoComprobante: number; numeroPuntoVenta: number; numeroComprobante: number; cuit?: number; }
147
+ interface ServerStatus { appserver: string; dbserver: string; authserver: string; }
148
+ interface ParamItem { Id: number; Desc: string; FchDesde?: string; FchHasta?: string; }
149
+ interface MonedaItem { Id: string; Desc: string; FchDesde?: string; FchHasta?: string; }
150
+ interface UnidadMedidaItem { Id: number; Desc: string; FchDesde?: string; FchHasta?: string; }
151
+ interface PtoVentaItem { Nro: number; EmisionTipo: string; Bloqueado: string; FchBaja: string; }
152
+ interface CotizacionResult { monedaId: string; cotizacion: number; fechaCotizacion: string; }
153
+ ```
154
+
155
+ ## Errores
156
+
157
+ 4-class hierarchy from @ramiidv/arca-common:
158
+ - ArcaError: base class
159
+ - ArcaAuthError: WSAA authentication failures
160
+ - ArcaServiceError: business errors from ARCA (has errors: {code: number, msg: string}[])
161
+ - ArcaSoapError: HTTP/transport errors (has statusCode?: number)
162
+
163
+ Note: autorizar() may return resultado="R" with errores/observaciones without throwing. Always check result.resultado.
164
+
165
+ ## Eventos
166
+
167
+ Discriminated union types: auth:login, auth:cache-hit, request:start, request:end, request:retry, request:error.
168
+
169
+ ## Enums
170
+
171
+ - CbteTipo: FACTURA_A=1, NOTA_DEBITO_A=2, NOTA_CREDITO_A=3, FACTURA_B=6, NOTA_DEBITO_B=7, NOTA_CREDITO_B=8, FACTURA_M=51, NOTA_DEBITO_M=52, NOTA_CREDITO_M=53
172
+ - Concepto: PRODUCTOS=1, SERVICIOS=2, PRODUCTOS_Y_SERVICIOS=3
173
+ - CodigoCondicionIVA: NO_GRAVADO=1, EXENTO=2, IVA_0=3, IVA_10_5=4, IVA_21=5, IVA_27=6, GRAVADO=7, IVA_5=8, IVA_2_5=9
174
+ - Moneda: PESOS="PES", DOLARES="DOL", EUROS="060", etc.
175
+
176
+ ## Clientes de bajo nivel
177
+
178
+ Accesibles como propiedades publicas: mtxca.wsaa (WsaaClient), mtxca.client (MtxcaClient).
179
+
180
+ ## SOAP details
181
+
182
+ WSAA service name: wsmtxca
183
+ Production: https://serviciosjava.afip.gob.ar/wsmtxca/services/MTXCAService
184
+ Homologation: https://fwshomo.afip.gov.ar/wsmtxca/services/MTXCAService
185
+ Namespace: http://impl.service.wsmtxca.afip.gov.ar/
186
+ Auth params use lowercase keys: token, sign, cuitRepresentada (wrapped in authRequest object).
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@ramiidv/arca-mtxca",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK para el web service WSMTXCA de ARCA (ex AFIP) - Facturacion electronica con detalle de articulos",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "sideEffects": false,
15
+ "files": [
16
+ "dist",
17
+ "llms.txt",
18
+ "LICENSE",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "clean": "rm -rf dist",
24
+ "typecheck": "tsc --noEmit",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "prepublishOnly": "npm run build"
28
+ },
29
+ "keywords": [
30
+ "arca",
31
+ "afip",
32
+ "wsmtxca",
33
+ "facturacion",
34
+ "factura-electronica",
35
+ "argentina",
36
+ "sdk",
37
+ "typescript",
38
+ "cae",
39
+ "caea",
40
+ "articulos",
41
+ "items",
42
+ "soap",
43
+ "invoice"
44
+ ],
45
+ "author": "ramiidv",
46
+ "license": "MIT",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/ramiidv/arca-mtxca.git"
50
+ },
51
+ "homepage": "https://github.com/ramiidv/arca-mtxca#readme",
52
+ "bugs": {
53
+ "url": "https://github.com/ramiidv/arca-mtxca/issues"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "engines": {
59
+ "node": ">=18"
60
+ },
61
+ "dependencies": {
62
+ "@ramiidv/arca-common": "^0.1.0"
63
+ },
64
+ "devDependencies": {
65
+ "@types/node": "^22.0.0",
66
+ "typescript": "^5.7.0",
67
+ "vitest": "^3.2.4"
68
+ }
69
+ }