herramientaenvioestupendo 1.1.21 → 1.1.23
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/README.md +1 -1
- package/package.json +1 -1
- package/src/db2_connector.js +29 -10
- package/src/index.js +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Para instalar el aplicativo CLI, deben realizar el siguiente procedimiento :
|
|
|
17
17
|
```npm update herramientaenvioestupendo -g```
|
|
18
18
|
|
|
19
19
|
- Luego de esto deben validar la version de la herramienta :
|
|
20
|
-
```estupendo --version```, si esta indica que es la 1.1.
|
|
20
|
+
```estupendo --version```, si esta indica que es la 1.1.23 es la correcta.
|
|
21
21
|
|
|
22
22
|
- Para conocer que opciones tienen de comandos solo deben ingresar en su CMD :
|
|
23
23
|
```estupendo --help```
|
package/package.json
CHANGED
package/src/db2_connector.js
CHANGED
|
@@ -111,10 +111,22 @@ const closeConnection = async (connection) => {
|
|
|
111
111
|
await new Promise((resolve) => connection._conn.close(() => resolve()))
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
const formatOdbcError = (error, sql) => {
|
|
115
|
+
const details = error.odbcErrors || error.odbcError || []
|
|
116
|
+
const codes = Array.isArray(details)
|
|
117
|
+
? details.map((e) => `[${e.state}] ${e.message} (code: ${e.code})`).join(" | ")
|
|
118
|
+
: ""
|
|
119
|
+
return new Error(`${error.message}${codes ? ` — ${codes}` : ""} | SQL: ${sql}`)
|
|
120
|
+
}
|
|
121
|
+
|
|
114
122
|
const query = async (connection, sql, params = []) => {
|
|
115
123
|
if (connection._type === "odbc") {
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
try {
|
|
125
|
+
const result = await connection._conn.query(sql, params)
|
|
126
|
+
return Array.from(result)
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw formatOdbcError(error, sql)
|
|
129
|
+
}
|
|
118
130
|
}
|
|
119
131
|
return new Promise((resolve, reject) => {
|
|
120
132
|
connection._conn.query(sql, params, (error, rows) => {
|
|
@@ -130,21 +142,24 @@ const assertSafeDbIdentifier = (identifier, label) => {
|
|
|
130
142
|
}
|
|
131
143
|
}
|
|
132
144
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
return
|
|
145
|
+
// IBM i ODBC driver no soporta SQLPrepare para CALL — se ejecuta directo con valores embebidos
|
|
146
|
+
const sqlLiteral = (value) => {
|
|
147
|
+
if (value === null || value === undefined) return "NULL"
|
|
148
|
+
if (typeof value === "number") return String(value)
|
|
149
|
+
return `'${String(value).replace(/'/g, "''")}'`
|
|
137
150
|
}
|
|
138
151
|
|
|
139
152
|
const callListPending = async (connection, spName, nit, limit) => {
|
|
140
153
|
assertSafeDbIdentifier(spName, "SP de pendientes")
|
|
141
|
-
|
|
142
|
-
|
|
154
|
+
if (connection._type === "odbc") {
|
|
155
|
+
const sql = `{CALL ${spName}(${sqlLiteral(nit)}, ${sqlLiteral(Number(limit))})}`
|
|
156
|
+
return query(connection, sql)
|
|
157
|
+
}
|
|
158
|
+
return query(connection, `CALL ${spName}(?, ?)`, [nit, Number(limit)])
|
|
143
159
|
}
|
|
144
160
|
|
|
145
161
|
const callUpdateStatus = async (connection, spName, nit, result) => {
|
|
146
162
|
assertSafeDbIdentifier(spName, "SP de actualizacion")
|
|
147
|
-
const sql = buildCallSql(connection, spName, 16)
|
|
148
163
|
const params = [
|
|
149
164
|
nit,
|
|
150
165
|
result.documentType || result.tipoDocumento || "",
|
|
@@ -164,7 +179,11 @@ const callUpdateStatus = async (connection, spName, nit, result) => {
|
|
|
164
179
|
result.extraValue2 || "",
|
|
165
180
|
]
|
|
166
181
|
|
|
167
|
-
|
|
182
|
+
if (connection._type === "odbc") {
|
|
183
|
+
const sql = `{CALL ${spName}(${params.map(sqlLiteral).join(", ")})}`
|
|
184
|
+
return query(connection, sql)
|
|
185
|
+
}
|
|
186
|
+
return query(connection, `CALL ${spName}(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, params)
|
|
168
187
|
}
|
|
169
188
|
|
|
170
189
|
const normalizeValue = (value) => {
|
package/src/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { sendTxt, sendXml, sendAttached, sendJson, requestDocumentRace, sendTxtC
|
|
|
4
4
|
import { sendDb2Sp } from "./db2_connector.js"
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
program.name("estupendo").version("1.1.
|
|
7
|
+
program.name("estupendo").version("1.1.23")
|
|
8
8
|
|
|
9
9
|
program.command("send_xml")
|
|
10
10
|
.requiredOption("-d, --directory <char>", "Directorio donde se encuentran los documentos XML")
|