dgii-ts 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/README.en.md +64 -26
  2. package/README.md +64 -25
  3. package/package.json +25 -7
package/README.en.md CHANGED
@@ -19,11 +19,13 @@ basic RNC or NCF lookups. Dominican developers rely on fragile scrapers that
19
19
  parse ASP.NET WebForms pages with ViewState — and those pages have changed URLs
20
20
  at least three times, breaking every existing integration.
21
21
 
22
- **dgii-ts** solves this with a three-layer approach designed for resilience:
22
+ **dgii-ts** solves this with a four-layer approach designed for resilience:
23
23
 
24
24
  1. **Offline validation** — never fails, zero network calls
25
- 2. **SOAP client** — real-time queries against the WSMovilDGII service
26
- 3. **Bulk data** — import DGII's daily bulk RNC file (DGII\_RNC.zip)
25
+ 2. **Web scraping** — real-time queries against DGII's ASP.NET pages
26
+ 3. **SOAP client** *(deprecated)* WSMovilDGII wrapper, blocked by
27
+ DGII since January 2025
28
+ 4. **Bulk data** — import DGII's daily bulk RNC file (DGII\_RNC.zip)
27
29
 
28
30
  ## Features
29
31
 
@@ -35,11 +37,23 @@ points of failure. Includes whitelists of 578 Cedulas and 23 RNCs
35
37
  (source: [python-stdnum](https://github.com/arthurdejong/python-stdnum))
36
38
  that pass validation despite failing the check-digit algorithm.
37
39
 
38
- ### SOAP client (WSMovilDGII)
40
+ ### Resilient client (DgiiClient)
39
41
 
40
- Typed wrapper around DGII's SOAP service for taxpayer lookups
41
- (`GetContribuyentes`) and fiscal receipt validation (`GetNCF`). Includes
42
- full TypeScript types for all responses.
42
+ `DgiiClient` is the recommended entry point for real-time queries. It uses
43
+ web scraping as its primary strategy with SOAP fallback, a circuit breaker
44
+ to prevent cascading failures, and retry with exponential backoff.
45
+
46
+ ### Web scraping
47
+
48
+ Queries DGII's ASP.NET pages by extracting ViewState tokens and parsing
49
+ response HTML. This is the primary strategy since DGII blocked the SOAP
50
+ endpoint in January 2025.
51
+
52
+ ### SOAP client (WSMovilDGII) — deprecated
53
+
54
+ Typed wrapper around DGII's SOAP service. **Permanently blocked by DGII
55
+ since January 2025.** Kept as an internal fallback but not recommended
56
+ for direct use.
43
57
 
44
58
  ### Bulk data importer
45
59
 
@@ -104,22 +118,26 @@ const result = validateEcf('E310000000001');
104
118
  import { validateRnc } from 'dgii-ts/validators';
105
119
  ```
106
120
 
107
- Available submodules: `dgii-ts/validators`, `dgii-ts/soap`, and
108
- `dgii-ts/bulk`.
109
-
110
- ### Look up a taxpayer (SOAP) — *coming soon*
121
+ Available submodules: `dgii-ts/validators`, `dgii-ts/client`,
122
+ `dgii-ts/scraping`, `dgii-ts/soap`, `dgii-ts/bulk`, and `dgii-ts/errors`.
111
123
 
112
- > **Note:** The SOAP client is not yet implemented. The interface is defined
113
- > and will be available in a future release.
124
+ ### Look up a taxpayer
114
125
 
115
126
  ```typescript
116
- import { DgiiSoapClient } from 'dgii-ts';
127
+ import { DgiiClient } from 'dgii-ts/client';
117
128
 
118
- const client = new DgiiSoapClient();
129
+ const client = new DgiiClient();
119
130
  const result = await client.getContribuyente('131098193');
120
131
  // { rnc: '131098193', nombre: '...', estado: '...', ... }
121
132
  ```
122
133
 
134
+ ### Validate an NCF online
135
+
136
+ ```typescript
137
+ const ncfResult = await client.getNCF('131098193', 'B0100000001');
138
+ // { rnc: '131098193', ncf: 'B0100000001', estado: '...', ... }
139
+ ```
140
+
123
141
  ## API reference
124
142
 
125
143
  ### Validators
@@ -131,20 +149,36 @@ const result = await client.getContribuyente('131098193');
131
149
  | `validateNcf(value)` | Validates NCF format and type (B-series) |
132
150
  | `validateEcf(value)` | Validates e-NCF format and type (E-series) |
133
151
 
134
- ### SOAP client
152
+ ### Resilient client
135
153
 
136
154
  | Class/Method | Description |
137
155
  | --- | --- |
138
- | `DgiiSoapClient` | Typed client for WSMovilDGII |
156
+ | `DgiiClient` | Scraping + SOAP fallback, circuit breaker, retry |
139
157
  | `client.getContribuyente(rnc)` | Looks up taxpayer data by RNC |
140
158
  | `client.getNCF(rnc, ncf)` | Validates a fiscal receipt against DGII |
141
159
 
160
+ ### Scraping
161
+
162
+ | Class/Method | Description |
163
+ | --- | --- |
164
+ | `ScrapingClient` | Queries DGII's ASP.NET pages |
165
+ | `client.getContribuyente(rnc)` | Looks up taxpayer data by RNC |
166
+ | `client.getNCF(rnc, ncf)` | Validates a fiscal receipt |
167
+
168
+ ### SOAP client (deprecated)
169
+
170
+ | Class/Method | Description |
171
+ | --- | --- |
172
+ | `DgiiSoapClient` | WSMovilDGII client (blocked) |
173
+ | `client.getContribuyente(rnc)` | Looks up taxpayer data by RNC |
174
+ | `client.getNCF(rnc, ncf)` | Validates a fiscal receipt |
175
+
142
176
  ### Bulk data
143
177
 
144
178
  | Class/Method | Description |
145
179
  | --- | --- |
146
- | `downloadBulkFile(path)` | Downloads DGII\_RNC.zip to the given directory |
147
- | `parseBulkFile(path)` | Parses the taxpayer TXT file |
180
+ | `downloadBulkFile(options)` | Downloads DGII\_RNC.zip to the given directory |
181
+ | `parseBulkFile(options)` | Parses the taxpayer TXT file |
148
182
 
149
183
  ## Architecture
150
184
 
@@ -155,8 +189,9 @@ const result = await client.getContribuyente('131098193');
155
189
  │ Layer 1: Offline validation │
156
190
  │ ✓ RNC/Cedula check-digit ✓ NCF/e-NCF format │
157
191
  ├─────────────────────────────────────────────────┤
158
- │ Layer 2: SOAP client (WSMovilDGII)
159
- │ ✓ Taxpayer lookup ✓ NCF validation
192
+ │ Layer 2: DgiiClient (resilient)
193
+ │ ✓ Web scraping (primary)
194
+ │ ✓ SOAP fallback ✓ Circuit breaker ✓ Retry │
160
195
  ├─────────────────────────────────────────────────┤
161
196
  │ Layer 3: Bulk data (DGII_RNC.zip) │
162
197
  │ ✓ Daily download ✓ TXT parsing │
@@ -164,15 +199,18 @@ const result = await client.getContribuyente('131098193');
164
199
  ```
165
200
 
166
201
  **Layer 1** is instant and works offline. **Layer 2** provides real-time data
167
- for recently registered taxpayers. **Layer 3** is ideal for batch operations
168
- where you need to look up thousands of RNCs quickly.
202
+ using web scraping as the primary strategy, with SOAP fallback, circuit
203
+ breaker, and retry with exponential backoff. **Layer 3** is ideal for batch
204
+ operations where you need to look up thousands of RNCs quickly.
169
205
 
170
206
  ## Project status
171
207
 
172
208
  - [x] Offline validation (RNC, Cedula, NCF, e-NCF)
173
- - [ ] SOAP client (WSMovilDGII)
174
- - [ ] Bulk data importer (DGII\_RNC.zip)
175
- - [ ] CLI tool
209
+ - [x] Web scraping of DGII's ASP.NET pages
210
+ - [x] SOAP client WSMovilDGII (deprecated — blocked by DGII)
211
+ - [x] Resilient client with circuit breaker and retry
212
+ - [x] Bulk data importer (download + parsing)
213
+ - [x] Published on npm
176
214
 
177
215
  ## Security
178
216
 
package/README.md CHANGED
@@ -20,12 +20,15 @@ dependen de scrapers frágiles que parsean páginas ASP.NET con ViewState — y
20
20
  esas páginas han cambiado de URL al menos tres veces, rompiendo cada integración
21
21
  existente.
22
22
 
23
- **dgii-ts** resuelve esto con un enfoque de tres capas diseñado para
23
+ **dgii-ts** resuelve esto con un enfoque de cuatro capas diseñado para
24
24
  resiliencia:
25
25
 
26
26
  1. **Validación offline** — nunca falla, cero llamadas de red
27
- 2. **Cliente SOAP** — consultas en tiempo real contra el servicio WSMovilDGII
28
- 3. **Datos masivos** — importación del archivo diario DGII\_RNC.zip
27
+ 2. **Web scraping** — consultas en tiempo real contra las páginas
28
+ ASP.NET de la DGII
29
+ 3. **Cliente SOAP** *(deprecated)* — wrapper del servicio WSMovilDGII,
30
+ bloqueado por la DGII en enero 2025
31
+ 4. **Datos masivos** — importación del archivo diario DGII\_RNC.zip
29
32
 
30
33
  ## Características
31
34
 
@@ -37,11 +40,23 @@ puntos de fallo externos. Incluye whitelists de 578 cédulas y 23 RNCs
37
40
  (fuente: [python-stdnum](https://github.com/arthurdejong/python-stdnum)) que
38
41
  pasan validación aunque no cumplan el algoritmo de dígito verificador.
39
42
 
40
- ### Cliente SOAP (WSMovilDGII)
43
+ ### Cliente resiliente (DgiiClient)
41
44
 
42
- Wrapper tipado alrededor del servicio SOAP de la DGII para consultas de
43
- contribuyentes (`GetContribuyentes`) y validación de comprobantes fiscales
44
- (`GetNCF`). Incluye tipos TypeScript completos para todas las respuestas.
45
+ `DgiiClient` es el punto de entrada recomendado para consultas en tiempo real.
46
+ Usa web scraping como estrategia primaria con fallback a SOAP, circuit breaker
47
+ para evitar cascadas de errores, y retry con backoff exponencial.
48
+
49
+ ### Web scraping
50
+
51
+ Consulta las páginas ASP.NET de la DGII extrayendo tokens ViewState y
52
+ parseando el HTML de respuesta. Es la estrategia principal desde que la DGII
53
+ bloqueó el endpoint SOAP en enero 2025.
54
+
55
+ ### Cliente SOAP (WSMovilDGII) — deprecated
56
+
57
+ Wrapper tipado alrededor del servicio SOAP de la DGII. **Bloqueado
58
+ permanentemente por la DGII en enero 2025.** Se mantiene como fallback
59
+ interno pero no se recomienda su uso directo.
45
60
 
46
61
  ### Importador de datos masivos
47
62
 
@@ -106,22 +121,26 @@ const result = validateEcf('E310000000001');
106
121
  import { validateRnc } from 'dgii-ts/validators';
107
122
  ```
108
123
 
109
- Los submódulos disponibles son `dgii-ts/validators`, `dgii-ts/soap` y
110
- `dgii-ts/bulk`.
111
-
112
- ### Consultar contribuyente (SOAP) — *pendiente*
124
+ Los submódulos disponibles son `dgii-ts/validators`, `dgii-ts/client`,
125
+ `dgii-ts/scraping`, `dgii-ts/soap`, `dgii-ts/bulk` y `dgii-ts/errors`.
113
126
 
114
- > **Nota:** El cliente SOAP aún no está implementado. La interfaz está definida
115
- > y estará disponible en una futura versión.
127
+ ### Consultar contribuyente
116
128
 
117
129
  ```typescript
118
- import { DgiiSoapClient } from 'dgii-ts';
130
+ import { DgiiClient } from 'dgii-ts/client';
119
131
 
120
- const client = new DgiiSoapClient();
132
+ const client = new DgiiClient();
121
133
  const result = await client.getContribuyente('131098193');
122
134
  // { rnc: '131098193', nombre: '...', estado: '...', ... }
123
135
  ```
124
136
 
137
+ ### Validar NCF en línea
138
+
139
+ ```typescript
140
+ const ncfResult = await client.getNCF('131098193', 'B0100000001');
141
+ // { rnc: '131098193', ncf: 'B0100000001', estado: '...', ... }
142
+ ```
143
+
125
144
  ## Referencia del API
126
145
 
127
146
  ### Validadores
@@ -133,20 +152,36 @@ const result = await client.getContribuyente('131098193');
133
152
  | `validateNcf(value)` | Valida formato y tipo de NCF (serie B) |
134
153
  | `validateEcf(value)` | Valida formato y tipo de e-NCF (serie E) |
135
154
 
136
- ### Cliente SOAP
155
+ ### Cliente resiliente
137
156
 
138
157
  | Clase/Método | Descripción |
139
158
  | --- | --- |
140
- | `DgiiSoapClient` | Cliente tipado para WSMovilDGII |
159
+ | `DgiiClient` | Cliente con scraping + SOAP fallback, circuit breaker y retry |
141
160
  | `client.getContribuyente(rnc)` | Consulta datos de un contribuyente por RNC |
142
161
  | `client.getNCF(rnc, ncf)` | Valida un comprobante fiscal contra la DGII |
143
162
 
163
+ ### Scraping
164
+
165
+ | Clase/Método | Descripción |
166
+ | --- | --- |
167
+ | `ScrapingClient` | Consulta páginas ASP.NET de la DGII |
168
+ | `client.getContribuyente(rnc)` | Consulta contribuyente por RNC |
169
+ | `client.getNCF(rnc, ncf)` | Valida comprobante fiscal |
170
+
171
+ ### Cliente SOAP (deprecated)
172
+
173
+ | Clase/Método | Descripción |
174
+ | --- | --- |
175
+ | `DgiiSoapClient` | Cliente para WSMovilDGII (bloqueado) |
176
+ | `client.getContribuyente(rnc)` | Consulta contribuyente por RNC |
177
+ | `client.getNCF(rnc, ncf)` | Valida comprobante fiscal |
178
+
144
179
  ### Datos masivos
145
180
 
146
181
  | Clase/Método | Descripción |
147
182
  | --- | --- |
148
- | `downloadBulkFile(path)` | Descarga DGII\_RNC.zip al directorio especificado |
149
- | `parseBulkFile(path)` | Parsea el archivo TXT de contribuyentes |
183
+ | `downloadBulkFile(options)` | Descarga DGII\_RNC.zip |
184
+ | `parseBulkFile(options)` | Parsea el archivo TXT |
150
185
 
151
186
  ## Arquitectura
152
187
 
@@ -157,8 +192,9 @@ const result = await client.getContribuyente('131098193');
157
192
  │ Capa 1: Validación offline │
158
193
  │ ✓ Check-digit RNC/Cédula ✓ Formato NCF/e-NCF │
159
194
  ├─────────────────────────────────────────────────┤
160
- │ Capa 2: Cliente SOAP (WSMovilDGII)
161
- │ ✓ Consulta contribuyentes ✓ Validación NCF
195
+ │ Capa 2: DgiiClient (resiliente)
196
+ │ ✓ Web scraping (primario)
197
+ │ ✓ SOAP fallback ✓ Circuit breaker ✓ Retry │
162
198
  ├─────────────────────────────────────────────────┤
163
199
  │ Capa 3: Datos masivos (DGII_RNC.zip) │
164
200
  │ ✓ Descarga diaria ✓ Parseo TXT │
@@ -166,15 +202,18 @@ const result = await client.getContribuyente('131098193');
166
202
  ```
167
203
 
168
204
  La **capa 1** es instantánea y funciona sin conexión. La **capa 2** ofrece
169
- datos en tiempo real para contribuyentes recién registrados. La **capa 3** es
205
+ datos en tiempo real con web scraping como estrategia primaria, fallback a
206
+ SOAP, circuit breaker y retry con backoff exponencial. La **capa 3** es
170
207
  ideal para operaciones en lote donde necesitas buscar miles de RNC rápidamente.
171
208
 
172
209
  ## Estado del proyecto
173
210
 
174
211
  - [x] Validación offline (RNC, cédula, NCF, e-NCF)
175
- - [ ] Cliente SOAP WSMovilDGII
176
- - [ ] Importador DGII\_RNC.zip
177
- - [ ] Herramienta CLI
212
+ - [x] Web scraping de las páginas ASP.NET de la DGII
213
+ - [x] Cliente SOAP WSMovilDGII (deprecated — bloqueado por la DGII)
214
+ - [x] Cliente resiliente con circuit breaker y retry
215
+ - [x] Importador DGII\_RNC.zip (descarga + parseo)
216
+ - [x] Publicado en npm
178
217
 
179
218
  ## Seguridad
180
219
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dgii-ts",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Librería TypeScript para validación e integración con la DGII de República Dominicana — RNC, Cédula, NCF, e-NCF",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -48,16 +48,34 @@
48
48
  }
49
49
  },
50
50
  "./scraping": {
51
- "import": { "types": "./dist/scraping.d.ts", "default": "./dist/scraping.js" },
52
- "require": { "types": "./dist/scraping.d.cts", "default": "./dist/scraping.cjs" }
51
+ "import": {
52
+ "types": "./dist/scraping.d.ts",
53
+ "default": "./dist/scraping.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/scraping.d.cts",
57
+ "default": "./dist/scraping.cjs"
58
+ }
53
59
  },
54
60
  "./client": {
55
- "import": { "types": "./dist/client.d.ts", "default": "./dist/client.js" },
56
- "require": { "types": "./dist/client.d.cts", "default": "./dist/client.cjs" }
61
+ "import": {
62
+ "types": "./dist/client.d.ts",
63
+ "default": "./dist/client.js"
64
+ },
65
+ "require": {
66
+ "types": "./dist/client.d.cts",
67
+ "default": "./dist/client.cjs"
68
+ }
57
69
  },
58
70
  "./errors": {
59
- "import": { "types": "./dist/errors.d.ts", "default": "./dist/errors.js" },
60
- "require": { "types": "./dist/errors.d.cts", "default": "./dist/errors.cjs" }
71
+ "import": {
72
+ "types": "./dist/errors.d.ts",
73
+ "default": "./dist/errors.js"
74
+ },
75
+ "require": {
76
+ "types": "./dist/errors.d.cts",
77
+ "default": "./dist/errors.cjs"
78
+ }
61
79
  }
62
80
  },
63
81
  "sideEffects": false,