herramientaenvioestupendo 1.0.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/.idea/workspace.xml +75 -0
- package/README.md +31 -0
- package/package.json +33 -0
- package/src/index.js +32 -0
- package/src/request_api.js +23 -0
- package/src/services.js +122 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="AutoImportSettings">
|
|
4
|
+
<option name="autoReloadType" value="SELECTIVE" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ChangeListManager">
|
|
7
|
+
<list default="true" id="42d78bf6-fefd-4426-94f9-19ac4df7f61c" name="Changes" comment="">
|
|
8
|
+
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
|
9
|
+
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
|
|
10
|
+
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
11
|
+
<change beforePath="$PROJECT_DIR$/src/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.js" afterDir="false" />
|
|
12
|
+
<change beforePath="$PROJECT_DIR$/src/services.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/services.js" afterDir="false" />
|
|
13
|
+
</list>
|
|
14
|
+
<option name="SHOW_DIALOG" value="false" />
|
|
15
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
16
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
17
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
18
|
+
</component>
|
|
19
|
+
<component name="Git.Settings">
|
|
20
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
21
|
+
</component>
|
|
22
|
+
<component name="MarkdownSettingsMigration">
|
|
23
|
+
<option name="stateVersion" value="1" />
|
|
24
|
+
</component>
|
|
25
|
+
<component name="ProjectColorInfo"><![CDATA[{
|
|
26
|
+
"associatedIndex": 5
|
|
27
|
+
}]]></component>
|
|
28
|
+
<component name="ProjectId" id="2yc1qSsSi5574fZhln7kTm64g2J" />
|
|
29
|
+
<component name="ProjectViewState">
|
|
30
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
|
31
|
+
<option name="showLibraryContents" value="true" />
|
|
32
|
+
</component>
|
|
33
|
+
<component name="PropertiesComponent"><![CDATA[{
|
|
34
|
+
"keyToString": {
|
|
35
|
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
|
36
|
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
37
|
+
"git-widget-placeholder": "main",
|
|
38
|
+
"kotlin-language-version-configured": "true",
|
|
39
|
+
"last_opened_file_path": "C:/Users/santi/Downloads/Santiago/ESTUPENDO/Herramientas/EstupendoCLI"
|
|
40
|
+
}
|
|
41
|
+
}]]></component>
|
|
42
|
+
<component name="RunManager">
|
|
43
|
+
<configuration name="estupendo" type="ShConfigurationType" temporary="true">
|
|
44
|
+
<option name="SCRIPT_TEXT" value="" />
|
|
45
|
+
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
|
46
|
+
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/node_modules/.bin/estupendo" />
|
|
47
|
+
<option name="SCRIPT_OPTIONS" value="" />
|
|
48
|
+
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
|
49
|
+
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/node_modules/.bin" />
|
|
50
|
+
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
|
51
|
+
<option name="INTERPRETER_PATH" value="/bin/sh" />
|
|
52
|
+
<option name="INTERPRETER_OPTIONS" value="" />
|
|
53
|
+
<option name="EXECUTE_IN_TERMINAL" value="true" />
|
|
54
|
+
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
|
55
|
+
<envs />
|
|
56
|
+
<method v="2" />
|
|
57
|
+
</configuration>
|
|
58
|
+
<recent_temporary>
|
|
59
|
+
<list>
|
|
60
|
+
<item itemvalue="Shell Script.estupendo" />
|
|
61
|
+
</list>
|
|
62
|
+
</recent_temporary>
|
|
63
|
+
</component>
|
|
64
|
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
65
|
+
<component name="TaskManager">
|
|
66
|
+
<task active="true" id="Default" summary="Default task">
|
|
67
|
+
<changelist id="42d78bf6-fefd-4426-94f9-19ac4df7f61c" name="Changes" comment="" />
|
|
68
|
+
<created>1750119237774</created>
|
|
69
|
+
<option name="number" value="Default" />
|
|
70
|
+
<option name="presentableId" value="Default" />
|
|
71
|
+
<updated>1750119237774</updated>
|
|
72
|
+
</task>
|
|
73
|
+
<servers />
|
|
74
|
+
</component>
|
|
75
|
+
</project>
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# EstupendoCLI
|
|
2
|
+
|
|
3
|
+
Esta herramienta esta destinada para uso de los Ing. implementadores y de soporte de la empresa Estupendo-Colombia.
|
|
4
|
+
*Requerimientos :
|
|
5
|
+
|
|
6
|
+
- node 20.9.0 [Descargar aqui](https://nodejs.org/en/download)
|
|
7
|
+
|
|
8
|
+
- npm 9.6.7
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Para instalar el aplicativo CLI, deben realizar el siguiente procedimiento :
|
|
12
|
+
|
|
13
|
+
- Abrir CMD(Windows) o la terminal(Unix) el siguiente comando :
|
|
14
|
+
```npm i -g @estupendo/herramientaenvio```
|
|
15
|
+
|
|
16
|
+
- Luego de esto deben validar la version de la herramienta :
|
|
17
|
+
```estupendo --version```, si esta indica que es la 1.0.0 es la correcta.
|
|
18
|
+
|
|
19
|
+
- Para conocer que opciones tienen de comandos solo deben ingresar en su CMD :
|
|
20
|
+
```estupendo --help```
|
|
21
|
+
|
|
22
|
+
## Ejemplos de comando valido :
|
|
23
|
+
- ```estupendo send_txt -d [Carpeta donde se encuentran los archivos txt]```
|
|
24
|
+
- ```estupendo send_xml -d [Carpeta donde se encuentran los archivos xml] -n [Nit de la empresa que emite documentos]```
|
|
25
|
+
- ```estupendo send_attached -d [Carpeta donde se encuentran los archivos xml] -p[Produccion, si no es enviado toma api pruebas]```
|
|
26
|
+
|
|
27
|
+
Parametros :
|
|
28
|
+
- -d = ruta de los documentos a leer en la maquina.
|
|
29
|
+
- -n = nit
|
|
30
|
+
- -p = produccion(si no es enviado por defecto toma pruebas).
|
|
31
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "herramientaenvioestupendo",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Proyecto para envio documentos masivos",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"homepage": "",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": ""
|
|
11
|
+
},
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"author": "santiago.escudero",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"bin": {
|
|
17
|
+
"estupendo": "src/index.js"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "^1.6.2",
|
|
24
|
+
"commander": "^11.1.0",
|
|
25
|
+
"form-data": "^4.0.0",
|
|
26
|
+
"herramientaenvioestupendo": "file:HerramientaEnvioEstupendo-1.0.0.tgz",
|
|
27
|
+
"HerramientaEnvioEstupendo": "file:HerramientaEnvioEstupendo-1.0.0.tgz"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from "commander"
|
|
3
|
+
import { sendTxt, sendXml, sendAttached } from "./services.js"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
program.name("estupendo").version("1.0.0")
|
|
7
|
+
|
|
8
|
+
program.command("send_xml")
|
|
9
|
+
.requiredOption("-d, --directory <char>", "Directorio donde se encuentran los documentos XML")
|
|
10
|
+
.option("-p, --prod", "Producción, si no es enviado recibe el api pruebas")
|
|
11
|
+
.requiredOption("-n, --nit <char>", "Nit de la empresa")
|
|
12
|
+
.description("Envio masivos XML")
|
|
13
|
+
.action(sendXml)
|
|
14
|
+
|
|
15
|
+
program.command("send_txt")
|
|
16
|
+
.requiredOption("-d, --directory <char>", "Directorio donde se encuentran los documentos TXT")
|
|
17
|
+
.option("-p, --prod", "Producción, si no es enviado recibe el api pruebas")
|
|
18
|
+
.description("Envio masivo TXT")
|
|
19
|
+
.action(sendTxt)
|
|
20
|
+
|
|
21
|
+
program.command("send_attached")
|
|
22
|
+
.requiredOption("-d, --directory <char>", "Directorio donde se encuentran los documentos para recepcionar")
|
|
23
|
+
.option("-p, --prod", "Producción, si no es enviado recibe el api pruebas")
|
|
24
|
+
.description("Envio masivo attachedPdf")
|
|
25
|
+
.action(sendAttached)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
program.parse()
|
|
31
|
+
|
|
32
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import axios from "axios"
|
|
2
|
+
|
|
3
|
+
const request = async (url, body) => {
|
|
4
|
+
const res = await fetch(url, {
|
|
5
|
+
method: "POST",
|
|
6
|
+
body: JSON.stringify(body),
|
|
7
|
+
headers: {
|
|
8
|
+
"Content-Type": "application/json"
|
|
9
|
+
}
|
|
10
|
+
})
|
|
11
|
+
const data = await res.json()
|
|
12
|
+
return data
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const requestFile = async (url, fd) => {
|
|
16
|
+
const {data} = await axios.post(url, fd, {
|
|
17
|
+
headers: {
|
|
18
|
+
"Content-Type": "multipart/form-data"
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
return data
|
|
22
|
+
}
|
|
23
|
+
export { request, requestFile }
|
package/src/services.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import fs from "fs"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import FormData from "form-data"
|
|
4
|
+
import { fileURLToPath } from "url"
|
|
5
|
+
import { request, requestFile } from "./request_api.js"
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
7
|
+
const __dirname = path.dirname(__filename)
|
|
8
|
+
|
|
9
|
+
//envio aumaticos XML
|
|
10
|
+
|
|
11
|
+
const sendXml = async (options) => {
|
|
12
|
+
if (!fs.existsSync(options.directory)) {
|
|
13
|
+
console.error("La carpeta no existe")
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
const archivos = fs.readdirSync(options.directory)
|
|
17
|
+
const pattern = /.xml$/
|
|
18
|
+
const xmls = archivos.filter(archivo => pattern.test(archivo))
|
|
19
|
+
let urlApi = "https://pruebas.estupendo.com.co/api/documento"
|
|
20
|
+
let identificacion = "";
|
|
21
|
+
if (options.prod) {
|
|
22
|
+
urlApi = "https://app.estupendo.com.co/api/documento"
|
|
23
|
+
}
|
|
24
|
+
if (options.nit) {
|
|
25
|
+
identificacion = options.nit
|
|
26
|
+
}
|
|
27
|
+
const output = []
|
|
28
|
+
console.log("Procesando...")
|
|
29
|
+
for (let archivo of xmls) {
|
|
30
|
+
const name = path.join(options.directory, archivo)
|
|
31
|
+
const content = fs.readFileSync(name, { encoding: "utf-8" })
|
|
32
|
+
const encoded = Buffer.from(content).toString("base64")
|
|
33
|
+
const data = await request(urlApi, {
|
|
34
|
+
api_key: "",
|
|
35
|
+
nit: identificacion, // enviar nit de la empresa que deseo recorrer
|
|
36
|
+
prefijo: "",
|
|
37
|
+
contingencia: false,
|
|
38
|
+
xml: encoded
|
|
39
|
+
})
|
|
40
|
+
output.push(data)
|
|
41
|
+
}
|
|
42
|
+
const ruta = path.join(process.cwd(), "Output_xml.json")
|
|
43
|
+
fs.appendFile(ruta, JSON.stringify(output, null, 4), () => { })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// envios automaticos TXT
|
|
47
|
+
const sendTxt = async (options) => {
|
|
48
|
+
if (!fs.existsSync(options.directory)) {
|
|
49
|
+
console.error("La carpeta no existe")
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
const archivos = fs.readdirSync(options.directory)
|
|
53
|
+
const pattern = /.txt$/
|
|
54
|
+
const txts = archivos.filter(archivo => pattern.test(archivo))
|
|
55
|
+
let urlApi = "https://pruebas.estupendo.com.co/api/cargarDocumentoTxt"
|
|
56
|
+
if (options.prod) {
|
|
57
|
+
urlApi = "https://app.estupendo.com.co/api/cargarDocumentoTxt"
|
|
58
|
+
}
|
|
59
|
+
const output = [];
|
|
60
|
+
console.log("Procesando...")
|
|
61
|
+
for (let archivo of txts) {
|
|
62
|
+
const name = path.join(options.directory, archivo)
|
|
63
|
+
const content = fs.readFileSync(name, { encoding: "utf-8" })
|
|
64
|
+
const encoded = Buffer.from(content).toString("base64")
|
|
65
|
+
const data = await request(urlApi, {
|
|
66
|
+
txtEncode: encoded
|
|
67
|
+
})
|
|
68
|
+
output.push(data)
|
|
69
|
+
}
|
|
70
|
+
const now = new Date();
|
|
71
|
+
const fecha = now.toISOString().slice(0, 19).replace("T", "_").replace(/:/g, "-");
|
|
72
|
+
const filenameDate = `Output_txt_${fecha}.json`;
|
|
73
|
+
const ruta = path.join(process.cwd(), filenameDate)
|
|
74
|
+
fs.appendFile(ruta, JSON.stringify(output, null, 4), () => { })
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// cargue masivo Attached
|
|
79
|
+
|
|
80
|
+
const sendAttached = async (options) => {
|
|
81
|
+
if (!fs.existsSync(options.directory)) {
|
|
82
|
+
console.error("La carpeta no existe")
|
|
83
|
+
}
|
|
84
|
+
const archivos = fs.readdirSync(options.directory)
|
|
85
|
+
const pattern = /\.(zip|xml)$/i;
|
|
86
|
+
const attached = archivos.filter(archivo => pattern.test(archivo))
|
|
87
|
+
let urlApi = "https://pruebas.estupendo.com.co/api/race/documento/cargar"
|
|
88
|
+
if (options.prod) {
|
|
89
|
+
urlApi = "https://app.estupendo.com.co/api/race/documento/cargar"
|
|
90
|
+
}
|
|
91
|
+
const output = [];
|
|
92
|
+
console.log("Procesando...")
|
|
93
|
+
for (let archivo of attached) {
|
|
94
|
+
const name = path.join(options.directory, archivo)
|
|
95
|
+
const fileStream = fs.createReadStream(name);
|
|
96
|
+
const fd = new FormData()
|
|
97
|
+
fd.append('file', fileStream, { filename: archivo });
|
|
98
|
+
try {
|
|
99
|
+
const filename = name.split("\\").at(-1)
|
|
100
|
+
console.log(`Procesando archivo: ${filename}`);
|
|
101
|
+
const data = await requestFile(urlApi, fd)
|
|
102
|
+
output.push(`Nombre del archivo: ${filename}`)
|
|
103
|
+
output.push(data)
|
|
104
|
+
} catch (error) {
|
|
105
|
+
const filename = name.split("\\").at(-1)
|
|
106
|
+
console.error(`Error al procesar el archivo ${name}:`, error);
|
|
107
|
+
output.push(`El archivo ${filename} no se pudo procesar debido a: ${error.message}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const ruta = path.join(process.cwd(), "Output_attached.json")
|
|
111
|
+
fs.appendFile(ruta, JSON.stringify(output, null, 4), (err) => {
|
|
112
|
+
if (err) {
|
|
113
|
+
console.error('Error al escribir en el archivo:', err);
|
|
114
|
+
} else {
|
|
115
|
+
console.log('Los resultados han sido guardados en Output_attached.json');
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { sendTxt, sendXml, sendAttached }
|