herramientaenvioestupendo 1.0.1 → 1.0.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/.idea/workspace.xml +9 -8
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/services.js +23 -2
package/.idea/workspace.xml
CHANGED
|
@@ -31,15 +31,16 @@
|
|
|
31
31
|
<option name="hideEmptyMiddlePackages" value="true" />
|
|
32
32
|
<option name="showLibraryContents" value="true" />
|
|
33
33
|
</component>
|
|
34
|
-
<component name="PropertiesComponent"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
<component name="PropertiesComponent"><![CDATA[{
|
|
35
|
+
"keyToString": {
|
|
36
|
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
|
37
|
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
38
|
+
"Shell Script.estupendo.executor": "Run",
|
|
39
|
+
"git-widget-placeholder": "main",
|
|
40
|
+
"kotlin-language-version-configured": "true",
|
|
41
|
+
"last_opened_file_path": "C:/Users/santi/Downloads/Santiago/ESTUPENDO/Herramientas/EstupendoCLI"
|
|
41
42
|
}
|
|
42
|
-
}
|
|
43
|
+
}]]></component>
|
|
43
44
|
<component name="RunManager">
|
|
44
45
|
<configuration name="estupendo" type="ShConfigurationType" temporary="true">
|
|
45
46
|
<option name="SCRIPT_TEXT" value="" />
|
package/README.md
CHANGED
|
@@ -11,10 +11,10 @@ Esta herramienta esta destinada para uso de los Ing. implementadores y de soport
|
|
|
11
11
|
Para instalar el aplicativo CLI, deben realizar el siguiente procedimiento :
|
|
12
12
|
|
|
13
13
|
- Abrir CMD(Windows) o la terminal(Unix) el siguiente comando :
|
|
14
|
-
```npm i -g
|
|
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.3 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 } from "./services.js"
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
program.name("estupendo").version("1.0.
|
|
6
|
+
program.name("estupendo").version("1.0.3")
|
|
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
|
@@ -52,19 +52,40 @@ const sendTxt = async (options) => {
|
|
|
52
52
|
const archivos = fs.readdirSync(options.directory)
|
|
53
53
|
const pattern = /.txt$/
|
|
54
54
|
const txts = archivos.filter(archivo => pattern.test(archivo))
|
|
55
|
-
let urlApi = "https://pruebas.estupendo.com.co/api/
|
|
55
|
+
let urlApi = "https://pruebas.estupendo.com.co/api/CYP"
|
|
56
56
|
if (options.prod) {
|
|
57
|
-
urlApi = "https://app.estupendo.com.co/api/
|
|
57
|
+
urlApi = "https://app.estupendo.com.co/api/CYP"
|
|
58
58
|
}
|
|
59
59
|
const output = [];
|
|
60
|
+
const pdfDir = path.join(process.cwd(), "pdfs");
|
|
61
|
+
|
|
62
|
+
if (!fs.existsSync(pdfDir)) {
|
|
63
|
+
fs.mkdirSync(pdfDir);
|
|
64
|
+
}
|
|
60
65
|
console.log("Procesando...")
|
|
61
66
|
for (let archivo of txts) {
|
|
62
67
|
const name = path.join(options.directory, archivo)
|
|
63
68
|
const content = fs.readFileSync(name, { encoding: "utf-8" })
|
|
69
|
+
console.log(`Procesando Archivo: ${archivo}`);
|
|
64
70
|
const encoded = Buffer.from(content).toString("base64")
|
|
65
71
|
const data = await request(urlApi, {
|
|
66
72
|
txtEncode: encoded
|
|
67
73
|
})
|
|
74
|
+
console.log(data);
|
|
75
|
+
// Validar que el documento fue autorizado (estado === 2)
|
|
76
|
+
if (data.result === true && data.estado === 2 && data.pdf && data.doc_id) {
|
|
77
|
+
const pdfUrl = data.pdf;
|
|
78
|
+
const pdfPath = path.join(pdfDir, `${data.doc_id}.pdf`);
|
|
79
|
+
try {
|
|
80
|
+
const response = await axios.get(pdfUrl, { responseType: 'arraybuffer' });
|
|
81
|
+
fs.writeFileSync(pdfPath, response.data);
|
|
82
|
+
console.log(`PDF guardado: ${pdfPath}`);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(`Error descargando PDF de ${data.doc_id}:`, error.message);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
console.log(`Documento no autorizado o con estado diferente de 2. Archivo: ${archivo}`);
|
|
88
|
+
}
|
|
68
89
|
output.push(data)
|
|
69
90
|
}
|
|
70
91
|
const now = new Date();
|