dgii-ts 0.1.1 → 0.1.3
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.en.md +4 -0
- package/README.md +4 -0
- package/dist/bulk.cjs +8 -2
- package/dist/bulk.d.cts +48 -5
- package/dist/bulk.d.ts +48 -5
- package/dist/bulk.js +7 -1
- package/dist/{chunk-VJ4ZQQIQ.cjs → chunk-AML7LZBU.cjs} +14 -12
- package/dist/{chunk-4OYLCOUL.cjs → chunk-DLB5RJ7E.cjs} +19 -17
- package/dist/{chunk-DMGDJEUY.js → chunk-IRQX4WNQ.js} +8 -1
- package/dist/{chunk-4TKAQ4WV.js → chunk-KJXLES3I.js} +3 -3
- package/dist/{chunk-53A7IG4Y.js → chunk-KW4ZV6FJ.js} +1 -1
- package/dist/{chunk-6CIP7YH6.cjs → chunk-MUAPXS3H.cjs} +12 -12
- package/dist/{chunk-7RJWFPCZ.cjs → chunk-NASWEFHN.cjs} +8 -1
- package/dist/{chunk-HR4DCHH7.js → chunk-QTN5ZT4P.js} +5 -3
- package/dist/{chunk-FZ6QDTC4.cjs → chunk-VIZWYFHP.cjs} +62 -11
- package/dist/{chunk-WY6V4Y7S.cjs → chunk-WMFHPNFP.cjs} +3 -3
- package/dist/{chunk-HGE4QZ3H.js → chunk-YTX4QOLE.js} +4 -2
- package/dist/{chunk-KIS7MVIW.js → chunk-Z72T6CZG.js} +61 -10
- package/dist/client.cjs +6 -6
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +5 -5
- package/dist/errors.cjs +4 -2
- package/dist/errors.d.cts +10 -1
- package/dist/errors.d.ts +10 -1
- package/dist/errors.js +3 -1
- package/dist/{index-CS-7YY2y.d.ts → index-KNOaUG34.d.cts} +12 -0
- package/dist/{index-CS-7YY2y.d.cts → index-KNOaUG34.d.ts} +12 -0
- package/dist/index.cjs +11 -7
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -6
- package/dist/scraping.cjs +4 -4
- package/dist/scraping.d.cts +1 -1
- package/dist/scraping.d.ts +1 -1
- package/dist/scraping.js +3 -3
- package/dist/soap.cjs +4 -4
- package/dist/soap.d.cts +1 -1
- package/dist/soap.d.ts +1 -1
- package/dist/soap.js +3 -3
- package/dist/validators.d.cts +1 -1
- package/dist/validators.d.ts +1 -1
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -180,6 +180,10 @@ const ncfResult = await client.getNCF('131098193', 'B0100000001');
|
|
|
180
180
|
| `downloadBulkFile(options)` | Downloads DGII\_RNC.zip to the given directory |
|
|
181
181
|
| `parseBulkFile(options)` | Parses the taxpayer TXT file |
|
|
182
182
|
|
|
183
|
+
`parseBulkFile` throws `BulkFormatError` if the file doesn't match the
|
|
184
|
+
expected 11-column layout (for example, if DGII changes the format). It
|
|
185
|
+
accepts an `encoding` option (defaults to `latin1`).
|
|
186
|
+
|
|
183
187
|
## Architecture
|
|
184
188
|
|
|
185
189
|
```text
|
package/README.md
CHANGED
|
@@ -183,6 +183,10 @@ const ncfResult = await client.getNCF('131098193', 'B0100000001');
|
|
|
183
183
|
| `downloadBulkFile(options)` | Descarga DGII\_RNC.zip |
|
|
184
184
|
| `parseBulkFile(options)` | Parsea el archivo TXT |
|
|
185
185
|
|
|
186
|
+
`parseBulkFile` lanza `BulkFormatError` si el archivo no coincide con el
|
|
187
|
+
layout de 11 columnas esperado (por ejemplo, si la DGII cambia el formato).
|
|
188
|
+
Acepta `encoding` en las opciones (`latin1` por defecto).
|
|
189
|
+
|
|
186
190
|
## Arquitectura
|
|
187
191
|
|
|
188
192
|
```text
|
package/dist/bulk.cjs
CHANGED
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
var _chunkVIZWYFHPcjs = require('./chunk-VIZWYFHP.cjs');
|
|
6
7
|
require('./chunk-QH4BK5X3.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
10
|
+
var _chunkNASWEFHNcjs = require('./chunk-NASWEFHN.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
9
15
|
|
|
10
16
|
|
|
11
|
-
exports.DGII_BULK_URL =
|
|
17
|
+
exports.BulkFormatError = _chunkNASWEFHNcjs.BulkFormatError; exports.DGII_BULK_URL = _chunkVIZWYFHPcjs.DGII_BULK_URL; exports.DGII_ESTADOS = _chunkVIZWYFHPcjs.DGII_ESTADOS; exports.downloadBulkFile = _chunkVIZWYFHPcjs.downloadBulkFile; exports.parseBulkFile = _chunkVIZWYFHPcjs.parseBulkFile;
|
package/dist/bulk.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { B as BulkContribuyente } from './index-
|
|
1
|
+
import { B as BulkContribuyente } from './index-KNOaUG34.cjs';
|
|
2
|
+
export { BulkFormatError } from './errors.cjs';
|
|
2
3
|
|
|
3
4
|
interface DownloadOptions {
|
|
4
5
|
/** Directorio de destino para el archivo ZIP */
|
|
@@ -9,8 +10,27 @@ interface DownloadOptions {
|
|
|
9
10
|
interface ParseOptions {
|
|
10
11
|
/** Ruta al archivo TXT extraído del ZIP */
|
|
11
12
|
filePath: string;
|
|
13
|
+
/**
|
|
14
|
+
* Codificación del archivo. La DGII publica el TXT en latin-1
|
|
15
|
+
* (ISO-8859-1), que es el valor por defecto. Permite anularla si una
|
|
16
|
+
* futura versión del archivo llega en otra codificación (p. ej. UTF-8).
|
|
17
|
+
*/
|
|
18
|
+
encoding?: BufferEncoding;
|
|
12
19
|
}
|
|
13
20
|
declare const DGII_BULK_URL: string;
|
|
21
|
+
/**
|
|
22
|
+
* Valores conocidos de la columna `estado` (col 9) en el archivo masivo,
|
|
23
|
+
* verificados contra ~778k filas en producción. El parser usa este
|
|
24
|
+
* vocabulario para detectar un cambio de layout: si ninguna fila de una
|
|
25
|
+
* muestra trae un `estado` reconocido, el formato de la DGII cambió.
|
|
26
|
+
*/
|
|
27
|
+
declare const DGII_ESTADOS: readonly ["ACTIVO", "SUSPENDIDO", "DADO DE BAJA", "CESE TEMPORAL", "ANULADO", "RECHAZADO"];
|
|
28
|
+
/**
|
|
29
|
+
* Valor de la columna `estado` del archivo masivo: uno de
|
|
30
|
+
* {@link DGII_ESTADOS}. Vocabulario completo de la DGII, distinto del
|
|
31
|
+
* `estado` binario (ACTIVO/INACTIVO) que exponen el scraping y el SOAP.
|
|
32
|
+
*/
|
|
33
|
+
type DgiiEstado = (typeof DGII_ESTADOS)[number];
|
|
14
34
|
|
|
15
35
|
/**
|
|
16
36
|
* Descarga el archivo masivo DGII_RNC.zip desde el portal de la DGII.
|
|
@@ -20,11 +40,34 @@ declare const DGII_BULK_URL: string;
|
|
|
20
40
|
declare function downloadBulkFile(options: DownloadOptions): Promise<string>;
|
|
21
41
|
|
|
22
42
|
/**
|
|
23
|
-
* Parsea el archivo TXT de contribuyentes
|
|
43
|
+
* Parsea el archivo TXT de contribuyentes extraído de DGII_RNC.zip.
|
|
44
|
+
*
|
|
45
|
+
* El archivo usa delimitador pipe (|) con 11 columnas y viene codificado
|
|
46
|
+
* en latin-1 (ISO-8859-1); leerlo como UTF-8 corrompe los nombres con
|
|
47
|
+
* ñ/acentos (p. ej. MUÑOZ, PEÑA). Usa {@link ParseOptions.encoding} para
|
|
48
|
+
* anular la codificación si una futura versión del archivo cambia.
|
|
49
|
+
*
|
|
50
|
+
* Layout verificado contra el archivo en producción (~778k filas):
|
|
51
|
+
*
|
|
52
|
+
* col 0 rnc (100% dígitos)
|
|
53
|
+
* col 1 nombre (razón social)
|
|
54
|
+
* col 2 nombreComercial
|
|
55
|
+
* col 3 actividad
|
|
56
|
+
* col 4-7 reservadas/vacías en el archivo actual
|
|
57
|
+
* col 8 fechaConstitucion (dd/mm/yyyy)
|
|
58
|
+
* col 9 estado (ACTIVO / SUSPENDIDO / DADO DE BAJA / ...)
|
|
59
|
+
* col 10 regimen (NORMAL / RST / PST)
|
|
60
|
+
*
|
|
61
|
+
* `estado` se normaliza a mayúsculas para que coincida con
|
|
62
|
+
* {@link DGII_ESTADOS} sin importar la capitalización de la fuente.
|
|
24
63
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
64
|
+
* Las filas cuyo número de columnas no sea exactamente 11 se descartan por
|
|
65
|
+
* malformadas (formato viejo más corto, o una columna añadida/insertada).
|
|
66
|
+
* Si el archivo trae filas pero la mayoría de la muestra no trae un
|
|
67
|
+
* `estado` reconocido, se lanza {@link BulkFormatError}: un cambio de
|
|
68
|
+
* layout de la DGII debe fallar ruidosamente en vez de devolver `estado`
|
|
69
|
+
* vacío o mapeado a la columna equivocada en silencio.
|
|
27
70
|
*/
|
|
28
71
|
declare function parseBulkFile(options: ParseOptions): Promise<BulkContribuyente[]>;
|
|
29
72
|
|
|
30
|
-
export { BulkContribuyente, DGII_BULK_URL, type DownloadOptions, type ParseOptions, downloadBulkFile, parseBulkFile };
|
|
73
|
+
export { BulkContribuyente, DGII_BULK_URL, DGII_ESTADOS, type DgiiEstado, type DownloadOptions, type ParseOptions, downloadBulkFile, parseBulkFile };
|
package/dist/bulk.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { B as BulkContribuyente } from './index-
|
|
1
|
+
import { B as BulkContribuyente } from './index-KNOaUG34.js';
|
|
2
|
+
export { BulkFormatError } from './errors.js';
|
|
2
3
|
|
|
3
4
|
interface DownloadOptions {
|
|
4
5
|
/** Directorio de destino para el archivo ZIP */
|
|
@@ -9,8 +10,27 @@ interface DownloadOptions {
|
|
|
9
10
|
interface ParseOptions {
|
|
10
11
|
/** Ruta al archivo TXT extraído del ZIP */
|
|
11
12
|
filePath: string;
|
|
13
|
+
/**
|
|
14
|
+
* Codificación del archivo. La DGII publica el TXT en latin-1
|
|
15
|
+
* (ISO-8859-1), que es el valor por defecto. Permite anularla si una
|
|
16
|
+
* futura versión del archivo llega en otra codificación (p. ej. UTF-8).
|
|
17
|
+
*/
|
|
18
|
+
encoding?: BufferEncoding;
|
|
12
19
|
}
|
|
13
20
|
declare const DGII_BULK_URL: string;
|
|
21
|
+
/**
|
|
22
|
+
* Valores conocidos de la columna `estado` (col 9) en el archivo masivo,
|
|
23
|
+
* verificados contra ~778k filas en producción. El parser usa este
|
|
24
|
+
* vocabulario para detectar un cambio de layout: si ninguna fila de una
|
|
25
|
+
* muestra trae un `estado` reconocido, el formato de la DGII cambió.
|
|
26
|
+
*/
|
|
27
|
+
declare const DGII_ESTADOS: readonly ["ACTIVO", "SUSPENDIDO", "DADO DE BAJA", "CESE TEMPORAL", "ANULADO", "RECHAZADO"];
|
|
28
|
+
/**
|
|
29
|
+
* Valor de la columna `estado` del archivo masivo: uno de
|
|
30
|
+
* {@link DGII_ESTADOS}. Vocabulario completo de la DGII, distinto del
|
|
31
|
+
* `estado` binario (ACTIVO/INACTIVO) que exponen el scraping y el SOAP.
|
|
32
|
+
*/
|
|
33
|
+
type DgiiEstado = (typeof DGII_ESTADOS)[number];
|
|
14
34
|
|
|
15
35
|
/**
|
|
16
36
|
* Descarga el archivo masivo DGII_RNC.zip desde el portal de la DGII.
|
|
@@ -20,11 +40,34 @@ declare const DGII_BULK_URL: string;
|
|
|
20
40
|
declare function downloadBulkFile(options: DownloadOptions): Promise<string>;
|
|
21
41
|
|
|
22
42
|
/**
|
|
23
|
-
* Parsea el archivo TXT de contribuyentes
|
|
43
|
+
* Parsea el archivo TXT de contribuyentes extraído de DGII_RNC.zip.
|
|
44
|
+
*
|
|
45
|
+
* El archivo usa delimitador pipe (|) con 11 columnas y viene codificado
|
|
46
|
+
* en latin-1 (ISO-8859-1); leerlo como UTF-8 corrompe los nombres con
|
|
47
|
+
* ñ/acentos (p. ej. MUÑOZ, PEÑA). Usa {@link ParseOptions.encoding} para
|
|
48
|
+
* anular la codificación si una futura versión del archivo cambia.
|
|
49
|
+
*
|
|
50
|
+
* Layout verificado contra el archivo en producción (~778k filas):
|
|
51
|
+
*
|
|
52
|
+
* col 0 rnc (100% dígitos)
|
|
53
|
+
* col 1 nombre (razón social)
|
|
54
|
+
* col 2 nombreComercial
|
|
55
|
+
* col 3 actividad
|
|
56
|
+
* col 4-7 reservadas/vacías en el archivo actual
|
|
57
|
+
* col 8 fechaConstitucion (dd/mm/yyyy)
|
|
58
|
+
* col 9 estado (ACTIVO / SUSPENDIDO / DADO DE BAJA / ...)
|
|
59
|
+
* col 10 regimen (NORMAL / RST / PST)
|
|
60
|
+
*
|
|
61
|
+
* `estado` se normaliza a mayúsculas para que coincida con
|
|
62
|
+
* {@link DGII_ESTADOS} sin importar la capitalización de la fuente.
|
|
24
63
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
64
|
+
* Las filas cuyo número de columnas no sea exactamente 11 se descartan por
|
|
65
|
+
* malformadas (formato viejo más corto, o una columna añadida/insertada).
|
|
66
|
+
* Si el archivo trae filas pero la mayoría de la muestra no trae un
|
|
67
|
+
* `estado` reconocido, se lanza {@link BulkFormatError}: un cambio de
|
|
68
|
+
* layout de la DGII debe fallar ruidosamente en vez de devolver `estado`
|
|
69
|
+
* vacío o mapeado a la columna equivocada en silencio.
|
|
27
70
|
*/
|
|
28
71
|
declare function parseBulkFile(options: ParseOptions): Promise<BulkContribuyente[]>;
|
|
29
72
|
|
|
30
|
-
export { BulkContribuyente, DGII_BULK_URL, type DownloadOptions, type ParseOptions, downloadBulkFile, parseBulkFile };
|
|
73
|
+
export { BulkContribuyente, DGII_BULK_URL, DGII_ESTADOS, type DgiiEstado, type DownloadOptions, type ParseOptions, downloadBulkFile, parseBulkFile };
|
package/dist/bulk.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DGII_BULK_URL,
|
|
3
|
+
DGII_ESTADOS,
|
|
3
4
|
downloadBulkFile,
|
|
4
5
|
parseBulkFile
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Z72T6CZG.js";
|
|
6
7
|
import "./chunk-D26S6EXD.js";
|
|
8
|
+
import {
|
|
9
|
+
BulkFormatError
|
|
10
|
+
} from "./chunk-IRQX4WNQ.js";
|
|
7
11
|
export {
|
|
12
|
+
BulkFormatError,
|
|
8
13
|
DGII_BULK_URL,
|
|
14
|
+
DGII_ESTADOS,
|
|
9
15
|
downloadBulkFile,
|
|
10
16
|
parseBulkFile
|
|
11
17
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkWMFHPNFPcjs = require('./chunk-WMFHPNFP.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ var _chunkQH4BK5X3cjs = require('./chunk-QH4BK5X3.cjs');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkNASWEFHNcjs = require('./chunk-NASWEFHN.cjs');
|
|
12
12
|
|
|
13
13
|
// src/scraping/endpoints.ts
|
|
14
14
|
var DGII_RNC_URL = "https://dgii.gov.do/app/WebApps/ConsultasWeb2/ConsultasWeb/consultas/rnc.aspx";
|
|
@@ -30,7 +30,7 @@ function extractViewStateTokens(html) {
|
|
|
30
30
|
const viewStateGenerator = extractInputValue(html, "__VIEWSTATEGENERATOR");
|
|
31
31
|
const eventValidation = extractInputValue(html, "__EVENTVALIDATION");
|
|
32
32
|
if (!viewState || !eventValidation) {
|
|
33
|
-
throw new (0,
|
|
33
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
34
34
|
"No se encontraron tokens ViewState en la p\xE1gina de la DGII"
|
|
35
35
|
);
|
|
36
36
|
}
|
|
@@ -43,7 +43,7 @@ function parseContribuyenteHtml(html) {
|
|
|
43
43
|
if (infoEnd !== -1) {
|
|
44
44
|
const infoBlock = html.slice(infoStart, infoEnd);
|
|
45
45
|
if (infoBlock.includes("no se encuentra")) {
|
|
46
|
-
throw new (0,
|
|
46
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiNotFoundError)(
|
|
47
47
|
"RNC o c\xE9dula no encontrado en el registro de la DGII"
|
|
48
48
|
);
|
|
49
49
|
}
|
|
@@ -52,13 +52,13 @@ function parseContribuyenteHtml(html) {
|
|
|
52
52
|
const tableId = "cphMain_dvDatosContribuyentes";
|
|
53
53
|
const tableStart = html.indexOf(tableId);
|
|
54
54
|
if (tableStart === -1) {
|
|
55
|
-
throw new (0,
|
|
55
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
56
56
|
"Formato de respuesta HTML inesperado: tabla de resultados no encontrada"
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
const tableEnd = html.indexOf("</table>", tableStart);
|
|
60
60
|
if (tableEnd === -1) {
|
|
61
|
-
throw new (0,
|
|
61
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
62
62
|
"Formato de respuesta HTML inesperado: tabla incompleta"
|
|
63
63
|
);
|
|
64
64
|
}
|
|
@@ -72,12 +72,14 @@ function parseContribuyenteHtml(html) {
|
|
|
72
72
|
const actividadEconomica = _nullishCoalesce(fields.get("Actividad Economica"), () => ( void 0));
|
|
73
73
|
const regimenDePagos = _nullishCoalesce(fields.get("Regimen de pagos"), () => ( void 0));
|
|
74
74
|
const administracionLocal = _nullishCoalesce(fields.get("Administracion Local"), () => ( void 0));
|
|
75
|
+
const rawFacturadorElectronico = _nullishCoalesce(fields.get("Facturador Electronico"), () => ( ""));
|
|
75
76
|
return {
|
|
76
77
|
rnc: _chunkQH4BK5X3cjs.stripNonDigits.call(void 0, rnc),
|
|
77
78
|
nombre: _chunkQH4BK5X3cjs.collapseSpaces.call(void 0, nombre),
|
|
78
79
|
nombreComercial: _chunkQH4BK5X3cjs.collapseSpaces.call(void 0, nombreComercial),
|
|
79
80
|
estado: rawEstado.toUpperCase().includes("ACTIVO") ? "ACTIVO" : "INACTIVO",
|
|
80
81
|
categoria: _chunkQH4BK5X3cjs.collapseSpaces.call(void 0, categoria),
|
|
82
|
+
esFacturadorElectronico: rawFacturadorElectronico.trim().toUpperCase().replace(/[ÍI]/g, "I").startsWith("SI"),
|
|
81
83
|
actividadEconomica: actividadEconomica ? _chunkQH4BK5X3cjs.collapseSpaces.call(void 0, actividadEconomica) : void 0,
|
|
82
84
|
regimenDePagos: regimenDePagos ? _chunkQH4BK5X3cjs.collapseSpaces.call(void 0, regimenDePagos) : void 0,
|
|
83
85
|
administracionLocal: administracionLocal ? _chunkQH4BK5X3cjs.collapseSpaces.call(void 0, administracionLocal) : void 0
|
|
@@ -181,7 +183,7 @@ var ScrapingClient = class {
|
|
|
181
183
|
*/
|
|
182
184
|
async getContribuyente(rnc) {
|
|
183
185
|
if (typeof rnc !== "string" || rnc.trim() === "") {
|
|
184
|
-
throw new (0,
|
|
186
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)("El par\xE1metro rnc es requerido");
|
|
185
187
|
}
|
|
186
188
|
const tokens = await this._fetchTokens(this._rncUrl);
|
|
187
189
|
const body = buildFormBody([
|
|
@@ -203,10 +205,10 @@ var ScrapingClient = class {
|
|
|
203
205
|
*/
|
|
204
206
|
async getNCF(rnc, ncf) {
|
|
205
207
|
if (typeof rnc !== "string" || rnc.trim() === "") {
|
|
206
|
-
throw new (0,
|
|
208
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)("El par\xE1metro rnc es requerido");
|
|
207
209
|
}
|
|
208
210
|
if (typeof ncf !== "string" || ncf.trim() === "") {
|
|
209
|
-
throw new (0,
|
|
211
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)("El par\xE1metro ncf es requerido");
|
|
210
212
|
}
|
|
211
213
|
const tokens = await this._fetchTokens(this._ncfUrl);
|
|
212
214
|
const body = buildFormBody([
|
|
@@ -231,7 +233,7 @@ var ScrapingClient = class {
|
|
|
231
233
|
throw this._wrapFetchError(error);
|
|
232
234
|
}
|
|
233
235
|
if (!response.ok) {
|
|
234
|
-
throw new (0,
|
|
236
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
235
237
|
`La DGII respondi\xF3 con HTTP ${response.status} al obtener la p\xE1gina`,
|
|
236
238
|
{ statusCode: response.status }
|
|
237
239
|
);
|
|
@@ -256,7 +258,7 @@ var ScrapingClient = class {
|
|
|
256
258
|
throw this._wrapFetchError(error);
|
|
257
259
|
}
|
|
258
260
|
if (!response.ok) {
|
|
259
|
-
throw new (0,
|
|
261
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
260
262
|
`La DGII respondi\xF3 con HTTP ${response.status}`,
|
|
261
263
|
{ statusCode: response.status }
|
|
262
264
|
);
|
|
@@ -264,7 +266,7 @@ var ScrapingClient = class {
|
|
|
264
266
|
return response.text();
|
|
265
267
|
}
|
|
266
268
|
_wrapFetchError(error) {
|
|
267
|
-
return
|
|
269
|
+
return _chunkWMFHPNFPcjs.wrapFetchError.call(void 0, error, this._timeout);
|
|
268
270
|
}
|
|
269
271
|
};
|
|
270
272
|
function buildFormBody(fields) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkWMFHPNFPcjs = require('./chunk-WMFHPNFP.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ var _chunkQH4BK5X3cjs = require('./chunk-QH4BK5X3.cjs');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkNASWEFHNcjs = require('./chunk-NASWEFHN.cjs');
|
|
12
12
|
|
|
13
13
|
// src/soap/endpoints.ts
|
|
14
14
|
var DGII_SOAP_BASE_URL = "https://dgii.gov.do/wsMovilDGII/WSMovilDGII.asmx";
|
|
@@ -49,13 +49,13 @@ function sanitizeJson(raw) {
|
|
|
49
49
|
function parseContribuyenteResponse(responseXml) {
|
|
50
50
|
const raw = extractTagContent(responseXml, "GetContribuyentesResult");
|
|
51
51
|
if (raw === void 0) {
|
|
52
|
-
throw new (0,
|
|
52
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
53
53
|
"Respuesta SOAP sin GetContribuyentesResult"
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
const trimmed = raw.trim();
|
|
57
57
|
if (trimmed === "0" || trimmed === "") {
|
|
58
|
-
throw new (0,
|
|
58
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiNotFoundError)(
|
|
59
59
|
"RNC o c\xE9dula no encontrado en el registro de la DGII"
|
|
60
60
|
);
|
|
61
61
|
}
|
|
@@ -65,12 +65,12 @@ function parseContribuyenteResponse(responseXml) {
|
|
|
65
65
|
try {
|
|
66
66
|
parsed = JSON.parse(sanitized);
|
|
67
67
|
} catch (e) {
|
|
68
|
-
throw new (0,
|
|
68
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
69
69
|
"Respuesta de la DGII no es JSON v\xE1lido"
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
if (typeof parsed !== "object" || parsed === null || typeof parsed["RGE_RUC"] !== "string") {
|
|
73
|
-
throw new (0,
|
|
73
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
74
74
|
"Formato de respuesta de la DGII inesperado"
|
|
75
75
|
);
|
|
76
76
|
}
|
|
@@ -80,13 +80,15 @@ function parseContribuyenteResponse(responseXml) {
|
|
|
80
80
|
nombre: _chunkQH4BK5X3cjs.collapseSpaces.call(void 0, String(_nullishCoalesce(data["RGE_NOMBRE"], () => ( "")))),
|
|
81
81
|
nombreComercial: _chunkQH4BK5X3cjs.collapseSpaces.call(void 0, String(_nullishCoalesce(data["NOMBRE_COMERCIAL"], () => ( "")))),
|
|
82
82
|
estado: String(_nullishCoalesce(data["ESTATUS"], () => ( ""))) === "2" ? "ACTIVO" : "INACTIVO",
|
|
83
|
-
categoria: String(_nullishCoalesce(data["CATEGORIA"], () => ( "")))
|
|
83
|
+
categoria: String(_nullishCoalesce(data["CATEGORIA"], () => ( ""))),
|
|
84
|
+
// TODO: derivar de la respuesta SOAP cuando la DGII restaure el endpoint
|
|
85
|
+
esFacturadorElectronico: false
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
88
|
function parseNcfResponse(responseXml) {
|
|
87
89
|
const raw = extractTagContent(responseXml, "GetNCFResult");
|
|
88
90
|
if (raw === void 0) {
|
|
89
|
-
throw new (0,
|
|
91
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)("Respuesta SOAP sin GetNCFResult");
|
|
90
92
|
}
|
|
91
93
|
const trimmed = raw.trim();
|
|
92
94
|
if (trimmed === "0" || trimmed === "") {
|
|
@@ -97,12 +99,12 @@ function parseNcfResponse(responseXml) {
|
|
|
97
99
|
try {
|
|
98
100
|
parsed = JSON.parse(sanitized);
|
|
99
101
|
} catch (e2) {
|
|
100
|
-
throw new (0,
|
|
102
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
101
103
|
"Respuesta de la DGII no es JSON v\xE1lido"
|
|
102
104
|
);
|
|
103
105
|
}
|
|
104
106
|
if (typeof parsed !== "object" || parsed === null) {
|
|
105
|
-
throw new (0,
|
|
107
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
106
108
|
"Formato de respuesta de la DGII inesperado"
|
|
107
109
|
);
|
|
108
110
|
}
|
|
@@ -142,22 +144,22 @@ var DgiiSoapClient = class {
|
|
|
142
144
|
signal: AbortSignal.timeout(timeout)
|
|
143
145
|
});
|
|
144
146
|
} catch (error) {
|
|
145
|
-
throw
|
|
147
|
+
throw _chunkWMFHPNFPcjs.wrapFetchError.call(void 0, error, timeout);
|
|
146
148
|
}
|
|
147
149
|
const contentLength = response.headers.get("content-length");
|
|
148
150
|
if (contentLength && parseInt(contentLength, 10) > 1048576) {
|
|
149
|
-
throw new (0,
|
|
151
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
150
152
|
"Respuesta de la DGII excede el tama\xF1o m\xE1ximo permitido"
|
|
151
153
|
);
|
|
152
154
|
}
|
|
153
155
|
if (response.status === 403) {
|
|
154
|
-
throw new (0,
|
|
156
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
155
157
|
"Acceso denegado por la DGII (HTTP 403). El servicio puede estar restringido por ubicaci\xF3n geogr\xE1fica.",
|
|
156
158
|
{ statusCode: 403 }
|
|
157
159
|
);
|
|
158
160
|
}
|
|
159
161
|
if (!response.ok) {
|
|
160
|
-
throw new (0,
|
|
162
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
161
163
|
`El servicio de la DGII respondi\xF3 con HTTP ${response.status}`,
|
|
162
164
|
{ statusCode: response.status }
|
|
163
165
|
);
|
|
@@ -169,7 +171,7 @@ var DgiiSoapClient = class {
|
|
|
169
171
|
*/
|
|
170
172
|
async getContribuyente(rnc) {
|
|
171
173
|
if (typeof rnc !== "string" || rnc.trim() === "") {
|
|
172
|
-
throw new (0,
|
|
174
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)("El par\xE1metro rnc es requerido");
|
|
173
175
|
}
|
|
174
176
|
const envelope = buildGetContribuyentesEnvelope(rnc.trim());
|
|
175
177
|
const responseXml = await this._fetch(
|
|
@@ -183,10 +185,10 @@ var DgiiSoapClient = class {
|
|
|
183
185
|
*/
|
|
184
186
|
async getNCF(rnc, ncf) {
|
|
185
187
|
if (typeof rnc !== "string" || rnc.trim() === "") {
|
|
186
|
-
throw new (0,
|
|
188
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)("El par\xE1metro rnc es requerido");
|
|
187
189
|
}
|
|
188
190
|
if (typeof ncf !== "string" || ncf.trim() === "") {
|
|
189
|
-
throw new (0,
|
|
191
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)("El par\xE1metro ncf es requerido");
|
|
190
192
|
}
|
|
191
193
|
const envelope = buildGetNcfEnvelope(rnc.trim(), ncf.trim());
|
|
192
194
|
const responseXml = await this._fetch(SOAP_ACTIONS.getNCF, envelope);
|
|
@@ -34,11 +34,18 @@ var AllStrategiesFailedError = class extends DgiiError {
|
|
|
34
34
|
this.errors = errors;
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
var BulkFormatError = class extends DgiiError {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message, "DGII_BULK_FORMAT_ERROR");
|
|
40
|
+
this.name = "BulkFormatError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
37
43
|
|
|
38
44
|
export {
|
|
39
45
|
DgiiError,
|
|
40
46
|
DgiiConnectionError,
|
|
41
47
|
DgiiNotFoundError,
|
|
42
48
|
DgiiServiceError,
|
|
43
|
-
AllStrategiesFailedError
|
|
49
|
+
AllStrategiesFailedError,
|
|
50
|
+
BulkFormatError
|
|
44
51
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DgiiSoapClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QTN5ZT4P.js";
|
|
4
4
|
import {
|
|
5
5
|
ScrapingClient
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YTX4QOLE.js";
|
|
7
7
|
import {
|
|
8
8
|
AllStrategiesFailedError,
|
|
9
9
|
DgiiConnectionError,
|
|
10
10
|
DgiiNotFoundError,
|
|
11
11
|
DgiiServiceError
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-IRQX4WNQ.js";
|
|
13
13
|
|
|
14
14
|
// src/client/circuit-breaker.ts
|
|
15
15
|
var DEFAULT_CIRCUIT_BREAKER_OPTIONS = /* @__PURE__ */ Object.freeze({
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkDLB5RJ7Ecjs = require('./chunk-DLB5RJ7E.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkAML7LZBUcjs = require('./chunk-AML7LZBU.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkNASWEFHNcjs = require('./chunk-NASWEFHN.cjs');
|
|
13
13
|
|
|
14
14
|
// src/client/circuit-breaker.ts
|
|
15
15
|
var DEFAULT_CIRCUIT_BREAKER_OPTIONS = /* @__PURE__ */ Object.freeze({
|
|
@@ -39,7 +39,7 @@ var ConsecutiveBreaker = class {
|
|
|
39
39
|
async execute(fn) {
|
|
40
40
|
const currentState = this.state;
|
|
41
41
|
if (currentState === "OPEN") {
|
|
42
|
-
throw new (0,
|
|
42
|
+
throw new (0, _chunkNASWEFHNcjs.DgiiServiceError)(
|
|
43
43
|
"Circuito abierto: estrategia deshabilitada temporalmente"
|
|
44
44
|
);
|
|
45
45
|
}
|
|
@@ -89,9 +89,9 @@ var DEFAULT_RETRY_OPTIONS = /* @__PURE__ */ Object.freeze({
|
|
|
89
89
|
maxDelayMs: 1e4
|
|
90
90
|
});
|
|
91
91
|
function isRetryableError(error) {
|
|
92
|
-
if (error instanceof
|
|
93
|
-
if (error instanceof
|
|
94
|
-
if (error instanceof
|
|
92
|
+
if (error instanceof _chunkNASWEFHNcjs.DgiiNotFoundError) return false;
|
|
93
|
+
if (error instanceof _chunkNASWEFHNcjs.DgiiConnectionError) return true;
|
|
94
|
+
if (error instanceof _chunkNASWEFHNcjs.DgiiServiceError) {
|
|
95
95
|
const code = error.statusCode;
|
|
96
96
|
if (code !== void 0 && code >= 500) return true;
|
|
97
97
|
return false;
|
|
@@ -123,10 +123,10 @@ async function withRetry(fn, options = DEFAULT_RETRY_OPTIONS) {
|
|
|
123
123
|
var DgiiClient = class {
|
|
124
124
|
constructor(options) {
|
|
125
125
|
const timeout = _optionalChain([options, 'optionalAccess', _ => _.timeout]);
|
|
126
|
-
this._scraping = new (0,
|
|
126
|
+
this._scraping = new (0, _chunkAML7LZBUcjs.ScrapingClient)(
|
|
127
127
|
timeout ? { timeout } : void 0
|
|
128
128
|
);
|
|
129
|
-
this._soap = new (0,
|
|
129
|
+
this._soap = new (0, _chunkDLB5RJ7Ecjs.DgiiSoapClient)(
|
|
130
130
|
timeout ? { timeout } : void 0
|
|
131
131
|
);
|
|
132
132
|
this._scrapingBreaker = new ConsecutiveBreaker(
|
|
@@ -167,7 +167,7 @@ var DgiiClient = class {
|
|
|
167
167
|
)
|
|
168
168
|
);
|
|
169
169
|
} catch (error) {
|
|
170
|
-
if (error instanceof
|
|
170
|
+
if (error instanceof _chunkNASWEFHNcjs.DgiiNotFoundError) throw error;
|
|
171
171
|
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
172
172
|
}
|
|
173
173
|
if (this._soapFallback) {
|
|
@@ -179,11 +179,11 @@ var DgiiClient = class {
|
|
|
179
179
|
)
|
|
180
180
|
);
|
|
181
181
|
} catch (error) {
|
|
182
|
-
if (error instanceof
|
|
182
|
+
if (error instanceof _chunkNASWEFHNcjs.DgiiNotFoundError) throw error;
|
|
183
183
|
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
throw new (0,
|
|
186
|
+
throw new (0, _chunkNASWEFHNcjs.AllStrategiesFailedError)(
|
|
187
187
|
`Todas las estrategias de consulta fallaron. \xDAltimo error: ${_nullishCoalesce(_optionalChain([errors, 'access', _6 => _6[errors.length - 1], 'optionalAccess', _7 => _7.message]), () => ( "desconocido"))}`,
|
|
188
188
|
errors
|
|
189
189
|
);
|
|
@@ -34,6 +34,13 @@ var AllStrategiesFailedError = class extends DgiiError {
|
|
|
34
34
|
this.errors = errors;
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
var BulkFormatError = class extends DgiiError {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message, "DGII_BULK_FORMAT_ERROR");
|
|
40
|
+
this.name = "BulkFormatError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
37
44
|
|
|
38
45
|
|
|
39
46
|
|
|
@@ -41,4 +48,4 @@ var AllStrategiesFailedError = class extends DgiiError {
|
|
|
41
48
|
|
|
42
49
|
|
|
43
50
|
|
|
44
|
-
exports.DgiiError = DgiiError; exports.DgiiConnectionError = DgiiConnectionError; exports.DgiiNotFoundError = DgiiNotFoundError; exports.DgiiServiceError = DgiiServiceError; exports.AllStrategiesFailedError = AllStrategiesFailedError;
|
|
51
|
+
exports.DgiiError = DgiiError; exports.DgiiConnectionError = DgiiConnectionError; exports.DgiiNotFoundError = DgiiNotFoundError; exports.DgiiServiceError = DgiiServiceError; exports.AllStrategiesFailedError = AllStrategiesFailedError; exports.BulkFormatError = BulkFormatError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
wrapFetchError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KW4ZV6FJ.js";
|
|
4
4
|
import {
|
|
5
5
|
collapseSpaces,
|
|
6
6
|
stripNonDigits
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
DgiiNotFoundError,
|
|
10
10
|
DgiiServiceError
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-IRQX4WNQ.js";
|
|
12
12
|
|
|
13
13
|
// src/soap/endpoints.ts
|
|
14
14
|
var DGII_SOAP_BASE_URL = "https://dgii.gov.do/wsMovilDGII/WSMovilDGII.asmx";
|
|
@@ -80,7 +80,9 @@ function parseContribuyenteResponse(responseXml) {
|
|
|
80
80
|
nombre: collapseSpaces(String(data["RGE_NOMBRE"] ?? "")),
|
|
81
81
|
nombreComercial: collapseSpaces(String(data["NOMBRE_COMERCIAL"] ?? "")),
|
|
82
82
|
estado: String(data["ESTATUS"] ?? "") === "2" ? "ACTIVO" : "INACTIVO",
|
|
83
|
-
categoria: String(data["CATEGORIA"] ?? "")
|
|
83
|
+
categoria: String(data["CATEGORIA"] ?? ""),
|
|
84
|
+
// TODO: derivar de la respuesta SOAP cuando la DGII restaure el endpoint
|
|
85
|
+
esFacturadorElectronico: false
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
88
|
function parseNcfResponse(responseXml) {
|