dgii-ts 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/LICENSE +21 -0
- package/README.en.md +192 -0
- package/README.md +196 -0
- package/dist/bulk.cjs +11 -0
- package/dist/bulk.d.cts +30 -0
- package/dist/bulk.d.ts +30 -0
- package/dist/bulk.js +11 -0
- package/dist/chunk-2ST6QKHA.cjs +1 -0
- package/dist/chunk-4OYLCOUL.cjs +201 -0
- package/dist/chunk-4TKAQ4WV.js +198 -0
- package/dist/chunk-53A7IG4Y.js +23 -0
- package/dist/chunk-6CIP7YH6.cjs +198 -0
- package/dist/chunk-7RJWFPCZ.cjs +44 -0
- package/dist/chunk-D26S6EXD.js +12 -0
- package/dist/chunk-DMGDJEUY.js +44 -0
- package/dist/chunk-ERBXSS64.js +0 -0
- package/dist/chunk-EZKSB553.js +0 -0
- package/dist/chunk-FZ6QDTC4.cjs +98 -0
- package/dist/chunk-HGE4QZ3H.js +281 -0
- package/dist/chunk-HR4DCHH7.js +201 -0
- package/dist/chunk-KIS7MVIW.js +98 -0
- package/dist/chunk-QH4BK5X3.cjs +12 -0
- package/dist/chunk-QOSGH7F5.cjs +1 -0
- package/dist/chunk-SUSDEKID.cjs +784 -0
- package/dist/chunk-TZC6RSWL.js +784 -0
- package/dist/chunk-VJ4ZQQIQ.cjs +281 -0
- package/dist/chunk-WY6V4Y7S.cjs +23 -0
- package/dist/client.cjs +17 -0
- package/dist/client.d.cts +95 -0
- package/dist/client.d.ts +95 -0
- package/dist/client.js +17 -0
- package/dist/errors.cjs +14 -0
- package/dist/errors.d.cts +40 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.js +14 -0
- package/dist/index-CS-7YY2y.d.cts +58 -0
- package/dist/index-CS-7YY2y.d.ts +58 -0
- package/dist/index.cjs +66 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +66 -0
- package/dist/scraping.cjs +16 -0
- package/dist/scraping.d.cts +47 -0
- package/dist/scraping.d.ts +47 -0
- package/dist/scraping.js +16 -0
- package/dist/soap.cjs +23 -0
- package/dist/soap.d.cts +38 -0
- package/dist/soap.d.ts +38 -0
- package/dist/soap.js +23 -0
- package/dist/validators.cjs +17 -0
- package/dist/validators.d.cts +55 -0
- package/dist/validators.d.ts +55 -0
- package/dist/validators.js +17 -0
- package/package.json +109 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collapseSpaces
|
|
3
|
+
} from "./chunk-D26S6EXD.js";
|
|
4
|
+
|
|
5
|
+
// src/bulk/downloader.ts
|
|
6
|
+
import { get } from "https";
|
|
7
|
+
import { createWriteStream } from "fs";
|
|
8
|
+
import { pipeline } from "stream/promises";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
|
|
11
|
+
// src/bulk/types.ts
|
|
12
|
+
var DGII_BULK_URL = "https://dgii.gov.do/app/WebApps/Consultas/RNC/DGII_RNC.zip";
|
|
13
|
+
|
|
14
|
+
// src/bulk/downloader.ts
|
|
15
|
+
async function downloadBulkFile(options) {
|
|
16
|
+
const timeout = Math.min(
|
|
17
|
+
Math.max(options.timeout ?? 6e4, 5e3),
|
|
18
|
+
6e5
|
|
19
|
+
);
|
|
20
|
+
const destPath = join(options.outputDir, "DGII_RNC.zip");
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const req = get(DGII_BULK_URL, (response) => {
|
|
23
|
+
const status = response.statusCode ?? 0;
|
|
24
|
+
if ([301, 302, 307, 308].includes(status)) {
|
|
25
|
+
const redirectUrl = response.headers["location"];
|
|
26
|
+
if (redirectUrl) {
|
|
27
|
+
response.resume();
|
|
28
|
+
const req2 = get(redirectUrl, (res2) => {
|
|
29
|
+
handleResponse(res2, destPath, resolve, reject);
|
|
30
|
+
});
|
|
31
|
+
req2.on("error", (err) => reject(
|
|
32
|
+
new Error("Error de conexi\xF3n al descargar archivo masivo", {
|
|
33
|
+
cause: err
|
|
34
|
+
})
|
|
35
|
+
));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
handleResponse(response, destPath, resolve, reject);
|
|
40
|
+
});
|
|
41
|
+
req.on("error", (err) => reject(
|
|
42
|
+
new Error("Error de conexi\xF3n al descargar archivo masivo", {
|
|
43
|
+
cause: err
|
|
44
|
+
})
|
|
45
|
+
));
|
|
46
|
+
req.setTimeout(timeout, () => {
|
|
47
|
+
req.destroy();
|
|
48
|
+
reject(new Error(
|
|
49
|
+
`Timeout de ${timeout}ms excedido al descargar archivo masivo`
|
|
50
|
+
));
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function handleResponse(response, destPath, resolve, reject) {
|
|
55
|
+
if (response.statusCode !== 200) {
|
|
56
|
+
response.resume();
|
|
57
|
+
reject(new Error(
|
|
58
|
+
`La DGII respondi\xF3 con HTTP ${response.statusCode ?? "desconocido"} al descargar el archivo masivo`
|
|
59
|
+
));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const fileStream = createWriteStream(destPath);
|
|
63
|
+
pipeline(response, fileStream).then(() => resolve(destPath)).catch((err) => reject(
|
|
64
|
+
new Error("Error al escribir archivo masivo", { cause: err })
|
|
65
|
+
));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/bulk/parser.ts
|
|
69
|
+
import { createReadStream } from "fs";
|
|
70
|
+
import { createInterface } from "readline";
|
|
71
|
+
async function parseBulkFile(options) {
|
|
72
|
+
const results = [];
|
|
73
|
+
const rl = createInterface({
|
|
74
|
+
input: createReadStream(options.filePath, { encoding: "utf-8" }),
|
|
75
|
+
crlfDelay: Infinity
|
|
76
|
+
});
|
|
77
|
+
for await (const line of rl) {
|
|
78
|
+
if (line.trim() === "") continue;
|
|
79
|
+
const fields = line.split("|");
|
|
80
|
+
if (fields.length < 7) continue;
|
|
81
|
+
results.push({
|
|
82
|
+
rnc: collapseSpaces(fields[0] ?? ""),
|
|
83
|
+
nombre: collapseSpaces(fields[1] ?? ""),
|
|
84
|
+
nombreComercial: collapseSpaces(fields[2] ?? ""),
|
|
85
|
+
actividad: collapseSpaces(fields[6] ?? ""),
|
|
86
|
+
estado: collapseSpaces(fields[5] ?? ""),
|
|
87
|
+
regimen: collapseSpaces(fields[4] ?? ""),
|
|
88
|
+
fechaConstitucion: collapseSpaces(fields[7] ?? "")
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return results;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export {
|
|
95
|
+
DGII_BULK_URL,
|
|
96
|
+
downloadBulkFile,
|
|
97
|
+
parseBulkFile
|
|
98
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/index.ts
|
|
2
|
+
function stripNonDigits(value) {
|
|
3
|
+
return value.replace(/\D/g, "");
|
|
4
|
+
}
|
|
5
|
+
function collapseSpaces(value) {
|
|
6
|
+
return value.replace(/\s+/g, " ").trim();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.stripNonDigits = stripNonDigits; exports.collapseSpaces = collapseSpaces;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|