@ramiidv/arca-fecred 0.1.0 → 0.3.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/llms.txt CHANGED
@@ -1,173 +1,96 @@
1
1
  # @ramiidv/arca-fecred
2
2
 
3
- > TypeScript SDK para el web service WSFECRED de ARCA (ex AFIP) - Factura de Credito Electronica MiPyME (Ley 27440)
3
+ > TypeScript SDK para el web service WSFECRED (FECredService) de ARCA (ex AFIP) - Factura de Crédito Electrónica MiPyME (Ley 27.440). Cubre todas las operaciones del WSDL.
4
4
 
5
- ## Instalacion
5
+ ## Instalación
6
6
 
7
7
  ```bash
8
8
  npm install @ramiidv/arca-fecred
9
9
  ```
10
10
 
11
- Requisitos: Node.js >= 18 (fetch nativo). ESM only.
11
+ Node.js >= 18. ESM only. Depende de @ramiidv/arca-common ^0.4.0.
12
12
 
13
- ## Configuracion
13
+ ## Configuración
14
14
 
15
15
  ```typescript
16
- import { ArcaFecred } from '@ramiidv/arca-fecred';
16
+ import { ArcaFecred, FileTicketStorage } from '@ramiidv/arca-fecred';
17
17
 
18
18
  const fecred = new ArcaFecred({
19
- cert: string, // PEM X.509 certificate
20
- key: string, // PEM RSA private key
21
- cuit: string, // CUIT representada (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,
19
+ cert: string, // PEM
20
+ key: string, // PEM
21
+ cuit: number | string, // CUIT representada (se valida dígito verificador)
22
+ production?: boolean, // default false (homologación)
23
+ timeout?: number, retries?: number, retryDelayMs?: number,
24
+ ticketStorage?: TicketStorage, // recomendado: new FileTicketStorage('./.arca-tickets')
25
+ fetch?: typeof fetch, legacyTls?: 'auto' | 'never' | 'always',
26
+ onEvent?: (e: ArcaEvent) => void,
27
+ wsaa?: WsaaClient, // compartir WSAA entre SDKs
28
+ endpoints?: { wsfecred?: string; wsaa?: string },
27
29
  });
28
30
  ```
29
31
 
30
- ## Metodos principales
32
+ Todos los métodos aceptan `opts?: { signal?: AbortSignal }` como último parámetro.
31
33
 
32
- ### consultarMontoObligadoRecepcion(cuit: string): Promise<MontoObligadoResult>
33
- Verifica si una CUIT esta obligada a recibir FCE. Retorna: { cuitConsultada, obligado: boolean, montoDesde?: number, raw }.
34
-
35
- ### consultarCtasCtes(params: ConsultarCtasCtesParams): Promise<CtaCte[]>
36
- Consulta cuentas corrientes de actividad FCE. Params: { rol: "Emisor"|"Receptor", cuitEmisor?, cuitReceptor?, fechaDesde, fechaHasta }. Retorna array de CtaCte.
37
-
38
- ### consultarComprobantes(params: ConsultarComprobantesParams): Promise<ComprobanteFecred[]>
39
- Busca comprobantes FCE. Params: { cuitEmisor?, cuitReceptor?, codCtaCte?, fechaDesde?, fechaHasta? }. Retorna array de ComprobanteFecred.
40
-
41
- ### aceptarFECred(codCtaCte: number): Promise<AceptarFecredResult>
42
- Acepta una FCE. Retorna: { codCtaCte, resultado, raw }.
43
-
44
- ### rechazarFECred(codCtaCte: number, codMotivoRechazo: number): Promise<RechazarFecredResult>
45
- Rechaza una FCE. Usar MotivoRechazo enum para codMotivoRechazo. Retorna: { codCtaCte, resultado, raw }.
46
-
47
- ### informarFacturaAceptadaCancelada(params: InformarCanceladaParams): Promise<InformarCanceladaResult>
48
- Informa que una FCE aceptada fue pagada. Params: { codCtaCte, codFormaCancelacion, observaciones? }. Usar FormaCancelacion enum.
49
-
50
- ### consultarTiposRetenciones(): Promise<TipoRetencionItem[]>
51
- Tipos de retenciones disponibles. Retorna: { codTipoRetencion, descTipoRetencion }[].
52
-
53
- ### consultarTiposFormasCancelacion(): Promise<TipoFormaCancelacionItem[]>
54
- Formas de cancelacion disponibles. Retorna: { codFormaCancelacion, descFormaCancelacion }[].
55
-
56
- ### consultarTiposAjustesOperacion(): Promise<TipoAjusteOperacionItem[]>
57
- Tipos de ajustes de operacion. Retorna: { codTipoAjuste, descTipoAjuste }[].
58
-
59
- ### consultarTiposMotivoRechazo(): Promise<TipoMotivoRechazoItem[]>
60
- Motivos de rechazo disponibles. Retorna: { codMotivoRechazo, descMotivoRechazo }[].
61
-
62
- ### status(): Promise<ServerStatus>
63
- Health check. No requiere autenticacion. Retorna: { appserver, dbserver, authserver }.
64
-
65
- ### clearAuthCache(): void
66
- Invalida el ticket de acceso cacheado para WSFECRED.
67
-
68
- ## Tipos principales
34
+ ## Tipos de entrada clave
69
35
 
70
36
  ```typescript
71
- interface CtaCte {
72
- codCtaCte: number;
73
- cuitEmisor: string;
74
- denominacionEmisor?: string;
75
- cuitReceptor: string;
76
- denominacionReceptor?: string;
77
- tipoComprobante?: number;
78
- puntoVenta?: number;
79
- nroComprobante?: number;
80
- codMoneda?: string;
81
- importeTotal?: number;
82
- saldo?: number;
83
- estado?: string;
84
- fechaEmision?: string;
85
- fechaVencimientoPago?: string;
86
- fechaVencimientoAceptacion?: string;
87
- cae?: string;
88
- }
89
-
90
- interface ComprobanteFecred {
91
- codCtaCte: number;
92
- tipoComprobante?: number;
93
- puntoVenta?: number;
94
- nroComprobante?: number;
95
- cuitEmisor: string;
96
- cuitReceptor: string;
97
- codMoneda?: string;
98
- importeTotal?: number;
99
- importeNeto?: number;
100
- saldo?: number;
101
- estado?: string;
102
- fechaEmision?: string;
103
- fechaVencimientoPago?: string;
104
- cae?: string;
105
- retenciones?: RetencionFecred[];
106
- }
107
-
108
- interface MontoObligadoResult {
109
- cuitConsultada: string;
110
- obligado: boolean;
111
- montoDesde?: number;
112
- raw: Record<string, unknown>;
113
- }
114
-
115
- interface ServerStatus {
116
- appserver: string;
117
- dbserver: string;
118
- authserver: string;
119
- }
37
+ type IdCtaCteInput = { codCtaCte: number | string } | { idFactura: IdComprobanteInput };
38
+ interface IdComprobanteInput { cuitEmisor: number | string; codTipoCmp: number; ptoVta: number; nroCmp: number }
39
+ interface FiltroFecha { tipo: 'Emision' | 'PuestaDispo' | 'VenPago' | 'VenAcep' | 'Acep' | 'InfoAgDptoCltv'; desde: Date | string; hasta: Date | string }
40
+ interface MotivoRechazo { codMotivo: number; descMotivo: string; justificacion: string } // textos 3..250
120
41
  ```
121
42
 
122
- ## Errores
43
+ Fechas: `Date`, `'YYYY-MM-DD'` o `'YYYYMMDD'`. Importes: number finito, se redondean a 2 decimales.
123
44
 
124
- 3-class hierarchy from @ramiidv/arca-common:
125
- - ArcaError: base class
126
- - ArcaAuthError: WSAA authentication failures
127
- - ArcaServiceError: business errors from WSFECRED (has errors: {code: number, msg: string}[])
128
- - ArcaSoapError: HTTP/transport errors (has statusCode?: number)
45
+ ## Consultas
129
46
 
130
47
  ```typescript
131
- import { ArcaAuthError, ArcaServiceError, ArcaSoapError } from '@ramiidv/arca-fecred';
132
-
133
- try {
134
- await fecred.aceptarFECred(codCtaCte);
135
- } catch (error) {
136
- if (error instanceof ArcaAuthError) { /* auth failure */ }
137
- if (error instanceof ArcaServiceError) { /* business error, check error.errors */ }
138
- if (error instanceof ArcaSoapError) { /* HTTP/network error, check error.statusCode */ }
139
- }
48
+ await fecred.status(); // dummy → { appserver, dbserver, authserver }
49
+ await fecred.consultarMontoObligadoRecepcion({ cuitConsultada, fechaEmision }); // { obligado: boolean, montoDesde?, observaciones }
50
+ await fecred.consultarObligadoRecepcion(cuit); // { obligado: boolean, desde?, observaciones }
51
+ await fecred.consultarCtasCtes({ rol: 'Emisor' | 'Receptor', cuitContraparte?, fecha?, estadoCtaCte?, nroPagina?, opcionTransferencia? });
52
+ // → { ctasCtes: { codCtaCte, estadoCtaCte: { estado, fechaHoraEstado }, idFacturaCredito, importeTotalFC, saldo, saldoAceptado?, codMoneda, opcionTransferencia }[], nroPagina?, hayMas? }
53
+ await fecred.consultarCtaCte(idCtaCte); // { ctaCte: CuentaCorriente }
54
+ await fecred.consultarComprobantes({ rol, cuitContraparte?, codTipoCmp?, estadoCmp?, fecha?, codCtaCte?, estadoCtaCte?, nroPagina? });
55
+ // → { comprobantes: Comprobante[] (cuitEmisor, razonSocialEmi, codTipoCmp, ptoVta, nroCmp, codAutorizacion, fechaEmision, fechaVenPago?, importeTotal, estado: { estado, fechaHoraEstado }, ...), hayMas? }
56
+ await fecred.consultarHistorialEstadosComprobante(idComprobante);
57
+ await fecred.consultarHistorialEstadosCtaCte(idCtaCte);
58
+ await fecred.obtenerRemitos(idComprobante);
59
+ await fecred.consultarCuentasEnAgtDptoCltv();
60
+ await fecred.consultarFacturasAgtDptoCltv({ idCtaCte?, fecha? });
61
+ await fecred.consultarTiposRetenciones(); // { codigoJurisdiccion, descripcionJurisdiccion, porcentajeRetencion }[]
62
+ await fecred.consultarTiposFormasCancelacion(); // { codigo, descripcion }[]
63
+ await fecred.consultarTiposMotivosRechazo(); // { codigo, descripcion }[]
64
+ await fecred.consultarTiposAjustesOperacion(); // { codigo, descripcion }[]
140
65
  ```
141
66
 
142
- ## Eventos
143
-
144
- Discriminated union types: auth:login, auth:cache-hit, request:start, request:end, request:retry, request:error.
145
-
146
- ## Enums
147
-
148
- - RolCtaCte (EMISOR="Emisor", RECEPTOR="Receptor")
149
- - EstadoCtaCte (PENDIENTE_ACEPTACION, ACEPTADA, RECHAZADA, CANCELADA, ANULADA)
150
- - MotivoRechazo (NOTA_CREDITO_DEBITO=1, CUIT_INCORRECTO=2, FECHA_INCORRECTA=3, CBU_INCORRECTO=4, OTROS=5)
151
- - FormaCancelacion (ACREDITACION_CUENTA=1, TRANSFERENCIA=2, CHEQUE=3, PAGO_ELECTRONICO=4, COMPENSACION=5, ENDOSO=6, OTRO=99)
152
- - TipoAjusteOperacion (NOTA_CREDITO=1, NOTA_DEBITO=2)
153
- - TipoRetencion (GANANCIAS=1, IVA=2, SUSS=3, INGRESOS_BRUTOS=4, OTRAS=99)
67
+ ## Operaciones (no idempotentes, nunca se reintentan)
154
68
 
155
- ## Clientes de bajo nivel
156
-
157
- Accesibles como propiedades publicas: fecred.wsaa, fecred.fecred.
69
+ ```typescript
70
+ await fecred.aceptarFECred({
71
+ idCtaCte, saldoAceptado, codMoneda, cotizacionMonedaUlt,
72
+ confirmarNotasDC?, formasCancelacion?, retenciones?, ajustesOperacion?, tipoCancelacion?: 'PAR' | 'TOT',
73
+ importeCancelado?, importeTotalRetPesos?, importeEmbargoPesos?, informaCBU?: boolean, cbuComprador?,
74
+ });
75
+ await fecred.rechazarFECred({ idCtaCte, motivos: MotivoRechazo[] });
76
+ await fecred.informarCancelacionTotalFECred({ idCtaCte, formasCancelacion: { codigo, descripcion }[], importeCancelacion });
77
+ await fecred.rechazarNotaDC({ idComprobante, motivos });
78
+ await fecred.modificarOpcionTransferencia({ idCtaCte, opcionTransferencia: 'SCA' | 'ADC' });
79
+ await fecred.informarFacturaAgtDptoCltv({ idCtaCte, ctaAgente: { cuitAgente, idCuenta, razonSocialAgente?, denominacion? } });
80
+ // → { resultado: 'A' | 'O', idCtaCte, evento?, observaciones }
81
+ ```
158
82
 
159
- ## SOAP details
83
+ ## Errores
160
84
 
161
- - WSAA service ID: "wsfecred"
162
- - Production endpoint: https://serviciosjava.afip.gob.ar/wsfecred/FECredService
163
- - Homologation endpoint: https://fwshomo.afip.gob.ar/wsfecred/FECredService
164
- - Namespace: https://serviciosjava.afip.gob.ar/wsfecred/FECredService?wsdl
165
- - Uses ser: prefix (Java-based, like padron services)
166
- - Auth passed as authRequest: { Token, Sign, Cuit }
85
+ - `ArcaValidationError`: parámetros inválidos (antes de pedir ticket o llamar a ARCA). `field`, `details`.
86
+ - `ArcaServiceError`: `arrayErrores` / `arrayErroresFormato` o `resultado = 'R'`. `errors: { code, msg, rawCode? }[]`.
87
+ - `ArcaSoapError`: HTTP / timeout / SOAP Fault / respuesta sin campo obligatorio. `uncertain = true` en una operación: pudo haberse registrado → verificar con `consultarCtaCte` o `consultarHistorialEstadosCtaCte` antes de reintentar.
88
+ - `ArcaAuthError`, `ArcaTicketVigenteError`: WSAA.
167
89
 
168
- ## Utilidades re-exportadas de arca-common
90
+ ## Notas
169
91
 
170
- - ensureArray<T>(value): T[] - normaliza single/array SOAP responses
171
- - parseXml(xml): Record<string, unknown> - parse XML
172
- - buildXml(obj): string - build XML from object
173
- - checkServiceErrors(result, serviceName): void - throws ArcaServiceError if errors found
92
+ - Los códigos de formas de cancelación, motivos de rechazo, ajustes y retenciones salen de `consultarTipos*()`; no hay enums.
93
+ - Enums del XSD (objeto + tipo literal): `RolCtaCte`, `EstadoCtaCte`, `EstadoComprobante`, `TipoFechaFiltro`, `OpcionTransferencia`, `TipoCancelacion`, `TipoAceptacion`, `Resultado`.
94
+ - `codCtaCte`, CUITs y `codAutorizacion` se devuelven como string; importes como number; S/N como boolean.
95
+ - Cliente de bajo nivel: `fecred.fecred` (`FecredClient`), con `{ token, sign, cuitRepresentada }` como primer parámetro.
96
+ - Endpoints: homologación `https://fwshomo.afip.gob.ar/wsfecred/FECredService`, producción `https://serviciosjava.afip.gob.ar/wsfecred/FECredService`. Namespace `http://ar.gob.afip.wsfecred/FECredService/`; SOAPAction = namespace + operación.
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@ramiidv/arca-fecred",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "TypeScript SDK para el web service WSFECRED de ARCA (ex AFIP) - Factura de Credito Electronica MiPyME",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "sideEffects": false,
8
9
  "exports": {
9
10
  ".": {
10
11
  "types": "./dist/index.d.ts",
@@ -24,7 +25,7 @@
24
25
  "typecheck": "tsc --noEmit",
25
26
  "test": "vitest run",
26
27
  "test:watch": "vitest",
27
- "prepublishOnly": "npm run clean && npm run build"
28
+ "prepublishOnly": "npm run clean && npm run build && npm test"
28
29
  },
29
30
  "keywords": [
30
31
  "arca",
@@ -44,7 +45,7 @@
44
45
  "type": "git",
45
46
  "url": "git+https://github.com/ramiidv/arca-fecred.git"
46
47
  },
47
- "homepage": "https://github.com/ramiidv/arca-fecred#readme",
48
+ "homepage": "https://arca-sdk.dev/fecred",
48
49
  "bugs": {
49
50
  "url": "https://github.com/ramiidv/arca-fecred/issues"
50
51
  },
@@ -55,7 +56,7 @@
55
56
  "node": ">=18"
56
57
  },
57
58
  "dependencies": {
58
- "@ramiidv/arca-common": "^0.1.0"
59
+ "@ramiidv/arca-common": "^0.4.0"
59
60
  },
60
61
  "devDependencies": {
61
62
  "@types/node": "^22.0.0",