herramientaenvioestupendo 1.0.34 → 1.0.35
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/.idea/workspace.xml +2 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/index.js +8 -2
- package/src/request_api.js +12 -0
- package/src/services.js +94 -2
package/.idea/workspace.xml
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
|
|
13
13
|
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
14
14
|
<change beforePath="$PROJECT_DIR$/src/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.js" afterDir="false" />
|
|
15
|
+
<change beforePath="$PROJECT_DIR$/src/request_api.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/request_api.js" afterDir="false" />
|
|
15
16
|
<change beforePath="$PROJECT_DIR$/src/services.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/services.js" afterDir="false" />
|
|
16
17
|
</list>
|
|
17
18
|
<option name="SHOW_DIALOG" value="false" />
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"keyToString": {
|
|
38
39
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
|
39
40
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
41
|
+
"RunOnceActivity.git.unshallow": "true",
|
|
40
42
|
"Shell Script.estupendo.executor": "Run",
|
|
41
43
|
"git-widget-placeholder": "main",
|
|
42
44
|
"kotlin-language-version-configured": "true",
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Para instalar el aplicativo CLI, deben realizar el siguiente procedimiento :
|
|
|
14
14
|
```npm i -g herramientaenvioestupendo```
|
|
15
15
|
|
|
16
16
|
- Luego de esto deben validar la version de la herramienta :
|
|
17
|
-
```estupendo --version```, si esta indica que es la 1.0.
|
|
17
|
+
```estupendo --version```, si esta indica que es la 1.0.35 es la correcta.
|
|
18
18
|
|
|
19
19
|
- Para conocer que opciones tienen de comandos solo deben ingresar en su CMD :
|
|
20
20
|
```estupendo --help```
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { program } from "commander"
|
|
|
3
3
|
import { sendTxt, sendXml, sendAttached, sendJson } from "./services.js"
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
program.name("estupendo").version("1.0.
|
|
6
|
+
program.name("estupendo").version("1.0.35")
|
|
7
7
|
|
|
8
8
|
program.command("send_xml")
|
|
9
9
|
.requiredOption("-d, --directory <char>", "Directorio donde se encuentran los documentos XML")
|
|
@@ -28,7 +28,13 @@ program.command("send_json")
|
|
|
28
28
|
.option("-p, --prod", "Producción, si no es enviado recibe el api pruebas")
|
|
29
29
|
.description("Envio masivo json nomina")
|
|
30
30
|
.action(sendJson)
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
program.command("request_document_race")
|
|
33
|
+
.requiredOption("-d, --directory <char>", "Directorio donde se encuentran los documentos XML")
|
|
34
|
+
.option("-p, --prod", "Producción, si no es enviado recibe el api pruebas")
|
|
35
|
+
.requiredOption("-n, --nit <char>", "Nit de la empresa")
|
|
36
|
+
.description("Descargar xml y pdf de los documentos recepcionados")
|
|
37
|
+
.action(requestDocumentRace)
|
|
32
38
|
|
|
33
39
|
|
|
34
40
|
|
package/src/request_api.js
CHANGED
|
@@ -21,3 +21,15 @@ const requestFile = async (url, fd) => {
|
|
|
21
21
|
return data
|
|
22
22
|
}
|
|
23
23
|
export { request, requestFile }
|
|
24
|
+
|
|
25
|
+
const requestGet = async (url, body) => {
|
|
26
|
+
const res = await fetch(url, {
|
|
27
|
+
method: "GET",
|
|
28
|
+
body: JSON.stringify(body),
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/json"
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
const data = await res.json()
|
|
34
|
+
return data
|
|
35
|
+
}
|
package/src/services.js
CHANGED
|
@@ -216,7 +216,7 @@ const sendAttached = async (options) => {
|
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
//envio aumaticos
|
|
219
|
+
//envio aumaticos json
|
|
220
220
|
const sendJson = async (options) => {
|
|
221
221
|
if (!fs.existsSync(options.directory)) {
|
|
222
222
|
console.error("La carpeta no existe")
|
|
@@ -293,6 +293,98 @@ const sendJson = async (options) => {
|
|
|
293
293
|
|
|
294
294
|
|
|
295
295
|
}
|
|
296
|
+
const now = new Date();
|
|
297
|
+
const fecha = now.toISOString().slice(0, 19).replace("T", "_").replace(/:/g, "-");
|
|
298
|
+
const filenameDate = `Output_txt_${fecha}.json`;
|
|
299
|
+
const ruta = path.join(process.cwd(), filenameDate)
|
|
300
|
+
fs.appendFile(ruta, JSON.stringify(output, null, 4), () => { })
|
|
301
|
+
}
|
|
302
|
+
//envio requestDocumentRace
|
|
303
|
+
const requestDocumentRace = async (options) => {
|
|
304
|
+
if (!fs.existsSync(options.directory)) {
|
|
305
|
+
console.error("La carpeta no existe")
|
|
306
|
+
return
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
let urlBase = "https://pruebas.estupendo.com.co/api"
|
|
310
|
+
let identificacion = "";
|
|
311
|
+
if (options.prod) {
|
|
312
|
+
urlBase = "https://app.estupendo.com.co/api"
|
|
313
|
+
}
|
|
314
|
+
if (options.nit) {
|
|
315
|
+
identificacion = options.nit
|
|
316
|
+
}
|
|
317
|
+
const urlApiConsulta = `${urlBase}/race/consultarDocumentosRecepcionados`;;
|
|
318
|
+
const output = [];
|
|
319
|
+
const pdfDir = path.join(process.cwd(), "pdfs");
|
|
320
|
+
const xmlDir = path.join(process.cwd(), "xmls");
|
|
321
|
+
|
|
322
|
+
// Crear carpetas si no existen
|
|
323
|
+
if (!fs.existsSync(pdfDir)) fs.mkdirSync(pdfDir);
|
|
324
|
+
if (!fs.existsSync(xmlDir)) fs.mkdirSync(xmlDir);
|
|
325
|
+
|
|
326
|
+
console.log("Procesando...")
|
|
327
|
+
const now = new Date();
|
|
328
|
+
now.setDate(now.getDate() - 1);
|
|
329
|
+
|
|
330
|
+
const year = now.getFullYear();
|
|
331
|
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
332
|
+
const day = String(now.getDate()).padStart(2, '0');
|
|
333
|
+
|
|
334
|
+
const fechaAnterior = `${year}-${month}-${day}`;
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
try {
|
|
338
|
+
const data = await requestGet(urlApiConsulta, {
|
|
339
|
+
fechaIni:fechaAnterior,
|
|
340
|
+
fechaFin:fechaAnterior,
|
|
341
|
+
nit: identificacion
|
|
342
|
+
})
|
|
343
|
+
console.log(data)
|
|
344
|
+
|
|
345
|
+
if (Array.isArray(data)) {
|
|
346
|
+
for (const item of data) {
|
|
347
|
+
const { xml, pdf } = item;
|
|
348
|
+
|
|
349
|
+
// Obtener nombre base de cada archivo
|
|
350
|
+
const xmlName = xml ? path.basename(xml) : null;
|
|
351
|
+
const pdfName = pdf ? path.basename(pdf) : null;
|
|
352
|
+
|
|
353
|
+
// Descargar y guardar XML
|
|
354
|
+
if (xml) {
|
|
355
|
+
const xmlPath = path.join(xmlDir, xmlName);
|
|
356
|
+
try {
|
|
357
|
+
const response = await axios.get(xml, { responseType: 'arraybuffer' });
|
|
358
|
+
fs.writeFileSync(xmlPath, response.data);
|
|
359
|
+
console.log(`XML guardado: ${xmlPath}`);
|
|
360
|
+
} catch (error) {
|
|
361
|
+
console.error(`Error descargando XML: ${xml}`, error.message);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Descargar y guardar PDF
|
|
366
|
+
if (pdf) {
|
|
367
|
+
const pdfPath = path.join(pdfDir, pdfName);
|
|
368
|
+
try {
|
|
369
|
+
const response = await axios.get(pdf, { responseType: 'arraybuffer' });
|
|
370
|
+
fs.writeFileSync(pdfPath, response.data);
|
|
371
|
+
console.log(`PDF guardado: ${pdfPath}`);
|
|
372
|
+
} catch (error) {
|
|
373
|
+
console.error(`Error descargando PDF: ${pdf}`, error.message);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
output.push(item);
|
|
378
|
+
}
|
|
379
|
+
} else {
|
|
380
|
+
console.error("La respuesta de la API no es un array de documentos.");
|
|
381
|
+
}
|
|
382
|
+
} catch (error) {
|
|
383
|
+
console.error(`Error al procesar el archivo ${archivo}:`, error);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
296
388
|
const now = new Date();
|
|
297
389
|
const fecha = now.toISOString().slice(0, 19).replace("T", "_").replace(/:/g, "-");
|
|
298
390
|
const filenameDate = `Output_txt_${fecha}.json`;
|
|
@@ -300,4 +392,4 @@ const sendJson = async (options) => {
|
|
|
300
392
|
fs.appendFile(ruta, JSON.stringify(output, null, 4), () => { })
|
|
301
393
|
}
|
|
302
394
|
|
|
303
|
-
export { sendTxt, sendXml, sendAttached, sendJson }
|
|
395
|
+
export { sendTxt, sendXml, sendAttached, sendJson, requestDocumentRace }
|