@bkmj/node-red-contrib-odbcmj 2.0.2 → 2.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.
Files changed (2) hide show
  1. package/odbc.js +25 -12
  2. package/package.json +1 -1
package/odbc.js CHANGED
@@ -120,14 +120,18 @@ module.exports = function (RED) {
120
120
  }
121
121
  });
122
122
 
123
+ // --- API ENDPOINT POUR LE BOUTON DE TEST (VERSION CORRIGÉE) ---
123
124
  RED.httpAdmin.post("/odbc_config/:id/test", RED.auth.needsPermission("odbc.write"), async function(req, res) {
124
125
  const tempConfig = req.body;
125
- const tempCredentials = { password: tempConfig.password };
126
- delete tempConfig.password;
127
126
 
127
+ // Cette fonction interne ne doit PAS interagir avec `res`.
128
+ // Elle retourne une chaîne ou lance une erreur.
128
129
  const buildTestConnectionString = () => {
129
- if (tempConfig.connectionMode === 'structured') {
130
- if (!tempConfig.dbType || !tempConfig.server) return res.status(400).send("Mode structuré : le type de BD et le serveur sont requis.");
130
+ if (tempConfig.connectionMode === 'structured') {
131
+ if (!tempConfig.dbType || !tempConfig.server) {
132
+ // On lance une erreur au lieu d'envoyer une réponse.
133
+ throw new Error("En mode structuré, le type de base de données et le serveur sont requis.");
134
+ }
131
135
  let driver;
132
136
  let parts = [];
133
137
  switch (tempConfig.dbType) {
@@ -137,15 +141,19 @@ module.exports = function (RED) {
137
141
  default: driver = tempConfig.driver || ''; break;
138
142
  }
139
143
  if(driver) parts.unshift(`DRIVER={${driver}}`);
140
- parts.push(`SERVER=${tempConfig.server}`);
144
+ if (tempConfig.server) parts.push(`SERVER=${tempConfig.server}`);
141
145
  if (tempConfig.database) parts.push(`DATABASE=${tempConfig.database}`);
142
146
  if (tempConfig.user) parts.push(`UID=${tempConfig.user}`);
143
- if (tempCredentials.password) parts.push(`PWD=${tempCredentials.password}`);
147
+ // Le mot de passe est géré dans le bloc try/catch principal
148
+ if (tempConfig.password) parts.push(`PWD=${tempConfig.password}`);
149
+
144
150
  return parts.join(';');
145
- } else {
151
+
152
+ } else { // 'string' mode
146
153
  let connStr = tempConfig.connectionString || "";
147
- if (tempCredentials.password && connStr.includes('{{{password}}}')) {
148
- connStr = connStr.replace('{{{password}}}', tempCredentials.password);
154
+ // Le mot de passe est supposé être dans la chaîne ici
155
+ if (!connStr) {
156
+ throw new Error("La chaîne de connexion ne peut pas être vide.");
149
157
  }
150
158
  return connStr;
151
159
  }
@@ -153,14 +161,19 @@ module.exports = function (RED) {
153
161
 
154
162
  let connection;
155
163
  try {
164
+ // Le bloc try/catch gère maintenant TOUTES les erreurs.
156
165
  const testConnectionString = buildTestConnectionString();
157
- if (!testConnectionString) return res.status(400).send("La chaîne de connexion est vide.");
166
+
158
167
  connection = await odbcModule.connect(testConnectionString);
159
- res.sendStatus(200);
168
+ res.sendStatus(200); // Succès, on envoie la seule et unique réponse.
169
+
160
170
  } catch (err) {
171
+ // Qu'il s'agisse d'une erreur de validation ou de connexion, on l'attrape ici.
161
172
  res.status(500).send(err.message || "Erreur inconnue durant le test.");
162
173
  } finally {
163
- if (connection) await connection.close();
174
+ if (connection) {
175
+ await connection.close();
176
+ }
164
177
  }
165
178
  });
166
179
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bkmj/node-red-contrib-odbcmj",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "A powerful Node-RED node to connect to any ODBC data source, with connection pooling, advanced retry logic, and result streaming.",
5
5
  "keywords": [
6
6
  "node-red",