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 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.21 es la correcta.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "herramientaenvioestupendo",
3
- "version": "1.1.21",
3
+ "version": "1.1.23",
4
4
  "private": false,
5
5
  "description": "Proyecto para envio documentos masivos",
6
6
  "keywords": [],
@@ -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
- const result = await connection._conn.query(sql, params)
117
- return Array.from(result)
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
- const buildCallSql = (connection, spName, paramCount) => {
134
- const placeholders = Array(paramCount).fill("?").join(", ")
135
- if (connection._type === "odbc") return `{CALL ${spName}(${placeholders})}`
136
- return `CALL ${spName}(${placeholders})`
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
- const sql = buildCallSql(connection, spName, 2)
142
- return query(connection, sql, [nit, Number(limit)])
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
- return query(connection, sql, params)
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.21")
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")