herramientaenvioestupendo 1.1.0 → 1.1.2

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.
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>
package/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/herramientaenvioestupendo.iml" filepath="$PROJECT_DIR$/.idea/herramientaenvioestupendo.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
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.1.0 es la correcta.
17
+ ```estupendo --version```, si esta indica que es la 1.1.2 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "herramientaenvioestupendo",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "private": false,
5
5
  "description": "Proyecto para envio documentos masivos",
6
6
  "keywords": [],
@@ -22,7 +22,8 @@
22
22
  "dependencies": {
23
23
  "axios": "^1.6.2",
24
24
  "commander": "^11.1.0",
25
- "form-data": "^4.0.0"
25
+ "form-data": "^4.0.0",
26
+ "xml2js": "^0.6.2"
26
27
  },
27
28
  "publishConfig": {
28
29
  "access": "public"
package/src/index.js CHANGED
@@ -3,7 +3,7 @@ import { program } from "commander"
3
3
  import { sendTxt, sendXml, sendAttached, sendJson, requestDocumentRace, sendTxtCYP } from "./services.js"
4
4
 
5
5
 
6
- program.name("estupendo").version("1.1.0")
6
+ program.name("estupendo").version("1.1.2")
7
7
 
8
8
  program.command("send_xml")
9
9
  .requiredOption("-d, --directory <char>", "Directorio donde se encuentran los documentos XML")
package/src/services.js CHANGED
@@ -2,6 +2,7 @@ import fs from "fs"
2
2
  import path from "path"
3
3
  import FormData from "form-data"
4
4
  import axios from "axios"
5
+ import xml2js from "xml2js";
5
6
  import { fileURLToPath } from "url"
6
7
  import { request, requestFile, requestGet } from "./request_api.js"
7
8
  const __filename = fileURLToPath(import.meta.url)
@@ -485,9 +486,10 @@ const requestDocumentRace = async (options) => {
485
486
  const xmlDir = path.join(process.cwd(), "xmls");
486
487
  const logsDir = path.join(process.cwd(), "logs");
487
488
  const uuidDir = path.join(process.cwd(), "UUID");
489
+ const documentXMLDir = path.join(process.cwd(), "documentxmls");
488
490
 
489
491
  // Crear carpetas si no existen
490
- [pdfDir, xmlDir, logsDir, uuidDir].forEach(dir => {
492
+ [pdfDir, xmlDir, logsDir, uuidDir, documentXMLDir].forEach(dir => {
491
493
  if (!fs.existsSync(dir)) fs.mkdirSync(dir);
492
494
  });
493
495
 
@@ -530,6 +532,26 @@ const requestDocumentRace = async (options) => {
530
532
  const response = await axios.get(xml, { responseType: 'arraybuffer' });
531
533
  fs.writeFileSync(xmlPath, response.data);
532
534
  console.log(`XML guardado: ${xmlPath}`);
535
+
536
+ const xmlContent = response.data.toString();
537
+ const parser = new xml2js.Parser({ explicitArray: false });
538
+ const parsedXml = await parser.parseStringPromise(xmlContent);
539
+
540
+ // Ejemplo: extraer el valor del nodo <cbc:ID> (puedes cambiarlo)
541
+ let extractedValue = "";
542
+ if (
543
+ parsedXml &&
544
+ parsedXml["AttachedDocument"] &&
545
+ parsedXml["AttachedDocument"]["cac:Attachment"]["cac:ExternalReference"]["cbc:Description"]
546
+ ) {
547
+ extractedValue = parsedXml["AttachedDocument"]["cac:Attachment"]["cac:ExternalReference"]["cbc:Description"];
548
+ }
549
+
550
+ if (extractedValue) {
551
+ const extraFilePath = path.join(documentXMLDir, `${baseName}.xml`);
552
+ fs.writeFileSync(extraFilePath, extractedValue);
553
+ console.log(`Dato extraído guardado en: ${extraFilePath}`);
554
+ }
533
555
  } catch (error) {
534
556
  console.error(`Error descargando XML: ${baseName}`, error.message);
535
557
  }