dbgate-api-premium 7.0.1 → 7.0.2
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api-premium",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.2",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"compare-versions": "^3.6.0",
|
|
31
31
|
"cors": "^2.8.5",
|
|
32
32
|
"cross-env": "^6.0.3",
|
|
33
|
-
"dbgate-datalib": "^7.0.
|
|
33
|
+
"dbgate-datalib": "^7.0.2",
|
|
34
34
|
"dbgate-query-splitter": "^4.11.9",
|
|
35
|
-
"dbgate-sqltree": "^7.0.
|
|
36
|
-
"dbgate-tools": "^7.0.
|
|
35
|
+
"dbgate-sqltree": "^7.0.2",
|
|
36
|
+
"dbgate-tools": "^7.0.2",
|
|
37
37
|
"debug": "^4.3.4",
|
|
38
38
|
"diff": "^5.0.0",
|
|
39
39
|
"diff2html": "^3.4.13",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@types/fs-extra": "^9.0.11",
|
|
89
89
|
"@types/lodash": "^4.14.149",
|
|
90
|
-
"dbgate-types": "^7.0.
|
|
90
|
+
"dbgate-types": "^7.0.2",
|
|
91
91
|
"env-cmd": "^10.1.0",
|
|
92
92
|
"jsdoc-to-markdown": "^9.0.5",
|
|
93
93
|
"node-loader": "^1.0.2",
|
|
@@ -24,10 +24,12 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
|
|
|
24
24
|
const { getAuthProviderById } = require('../auth/authProvider');
|
|
25
25
|
const { startTokenChecking } = require('../utility/authProxy');
|
|
26
26
|
const { extractConnectionsFromEnv } = require('../utility/envtools');
|
|
27
|
+
const { MissingCredentialsError } = require('../utility/exceptions');
|
|
27
28
|
|
|
28
29
|
const logger = getLogger('connections');
|
|
29
30
|
|
|
30
31
|
let volatileConnections = {};
|
|
32
|
+
let pendingTestSubprocesses = {}; // Map of conid -> subprocess for MS Entra auth flows
|
|
31
33
|
|
|
32
34
|
function getNamedArgs() {
|
|
33
35
|
const res = {};
|
|
@@ -239,14 +241,60 @@ module.exports = {
|
|
|
239
241
|
);
|
|
240
242
|
pipeForkLogs(subprocess);
|
|
241
243
|
subprocess.send({ ...connection, requestDbList });
|
|
242
|
-
return new Promise(resolve => {
|
|
244
|
+
return new Promise((resolve, reject) => {
|
|
245
|
+
let isWaitingForVolatile = false;
|
|
246
|
+
|
|
247
|
+
const cleanup = () => {
|
|
248
|
+
if (connection._id && pendingTestSubprocesses[connection._id]) {
|
|
249
|
+
delete pendingTestSubprocesses[connection._id];
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
243
253
|
subprocess.on('message', resp => {
|
|
244
254
|
if (handleProcessCommunication(resp, subprocess)) return;
|
|
245
255
|
// @ts-ignore
|
|
246
|
-
const { msgtype } = resp;
|
|
256
|
+
const { msgtype, missingCredentialsDetail } = resp;
|
|
247
257
|
if (msgtype == 'connected' || msgtype == 'error') {
|
|
258
|
+
cleanup();
|
|
248
259
|
resolve(resp);
|
|
249
260
|
}
|
|
261
|
+
if (msgtype == 'missingCredentials') {
|
|
262
|
+
if (missingCredentialsDetail?.redirectToDbLogin) {
|
|
263
|
+
// Store the subprocess for later when volatile connection is ready
|
|
264
|
+
isWaitingForVolatile = true;
|
|
265
|
+
pendingTestSubprocesses[connection._id] = {
|
|
266
|
+
subprocess,
|
|
267
|
+
requestDbList,
|
|
268
|
+
};
|
|
269
|
+
// Return immediately with redirectToDbLogin status in the old format
|
|
270
|
+
resolve({
|
|
271
|
+
missingCredentials: true,
|
|
272
|
+
detail: {
|
|
273
|
+
...missingCredentialsDetail,
|
|
274
|
+
keepErrorResponseFromApi: true,
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
reject(new MissingCredentialsError(missingCredentialsDetail));
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
subprocess.on('exit', (code) => {
|
|
284
|
+
// If exit happens while waiting for volatile, that's expected
|
|
285
|
+
if (isWaitingForVolatile && code === 0) {
|
|
286
|
+
cleanup();
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
cleanup();
|
|
290
|
+
if (code !== 0) {
|
|
291
|
+
reject(new Error(`Test subprocess exited with code ${code}`));
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
subprocess.on('error', (err) => {
|
|
296
|
+
cleanup();
|
|
297
|
+
reject(err);
|
|
250
298
|
});
|
|
251
299
|
});
|
|
252
300
|
},
|
|
@@ -279,6 +327,38 @@ module.exports = {
|
|
|
279
327
|
return testRes;
|
|
280
328
|
} else {
|
|
281
329
|
volatileConnections[res._id] = res;
|
|
330
|
+
|
|
331
|
+
// Check if there's a pending test subprocess waiting for this volatile connection
|
|
332
|
+
const pendingTest = pendingTestSubprocesses[conid];
|
|
333
|
+
if (pendingTest) {
|
|
334
|
+
const { subprocess, requestDbList } = pendingTest;
|
|
335
|
+
try {
|
|
336
|
+
// Send the volatile connection to the waiting subprocess
|
|
337
|
+
subprocess.send({ ...res, requestDbList, isVolatileResolved: true });
|
|
338
|
+
|
|
339
|
+
// Wait for the test result and emit it as an event
|
|
340
|
+
subprocess.once('message', resp => {
|
|
341
|
+
if (handleProcessCommunication(resp, subprocess)) return;
|
|
342
|
+
const { msgtype } = resp;
|
|
343
|
+
if (msgtype == 'connected' || msgtype == 'error') {
|
|
344
|
+
// Emit SSE event with test result
|
|
345
|
+
socket.emit(`connection-test-result-${conid}`, {
|
|
346
|
+
...resp,
|
|
347
|
+
volatileConId: res._id,
|
|
348
|
+
});
|
|
349
|
+
delete pendingTestSubprocesses[conid];
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
} catch (err) {
|
|
353
|
+
logger.error(extractErrorLogData(err), 'DBGM-00118 Error sending volatile connection to test subprocess');
|
|
354
|
+
socket.emit(`connection-test-result-${conid}`, {
|
|
355
|
+
msgtype: 'error',
|
|
356
|
+
error: err.message,
|
|
357
|
+
});
|
|
358
|
+
delete pendingTestSubprocesses[conid];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
282
362
|
return res;
|
|
283
363
|
}
|
|
284
364
|
},
|
package/src/currentVersion.js
CHANGED
|
@@ -18,13 +18,36 @@ Platform: ${process.platform}
|
|
|
18
18
|
|
|
19
19
|
function start() {
|
|
20
20
|
childProcessChecker();
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
let isWaitingForVolatile = false;
|
|
23
|
+
|
|
24
|
+
const handleConnection = async connection => {
|
|
22
25
|
// @ts-ignore
|
|
23
26
|
const { requestDbList } = connection;
|
|
24
27
|
if (handleProcessCommunication(connection)) return;
|
|
28
|
+
|
|
25
29
|
try {
|
|
26
30
|
const driver = requireEngineDriver(connection);
|
|
27
|
-
const
|
|
31
|
+
const connectionChanged = driver?.beforeConnectionSave ? driver.beforeConnectionSave(connection) : connection;
|
|
32
|
+
|
|
33
|
+
if (!connection.isVolatileResolved) {
|
|
34
|
+
if (connectionChanged.useRedirectDbLogin) {
|
|
35
|
+
process.send({
|
|
36
|
+
msgtype: 'missingCredentials',
|
|
37
|
+
missingCredentialsDetail: {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
conid: connection._id,
|
|
40
|
+
redirectToDbLogin: true,
|
|
41
|
+
keepErrorResponseFromApi: true,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
// Don't exit - wait for volatile connection to be sent
|
|
45
|
+
isWaitingForVolatile = true;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const dbhan = await connectUtility(driver, connectionChanged, 'app');
|
|
28
51
|
let version = {
|
|
29
52
|
version: 'Unknown',
|
|
30
53
|
};
|
|
@@ -45,6 +68,16 @@ function start() {
|
|
|
45
68
|
}
|
|
46
69
|
|
|
47
70
|
process.exit(0);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
process.on('message', async connection => {
|
|
74
|
+
// If we're waiting for volatile and receive a new connection, use it
|
|
75
|
+
if (isWaitingForVolatile) {
|
|
76
|
+
isWaitingForVolatile = false;
|
|
77
|
+
await handleConnection(connection);
|
|
78
|
+
} else {
|
|
79
|
+
await handleConnection(connection);
|
|
80
|
+
}
|
|
48
81
|
});
|
|
49
82
|
}
|
|
50
83
|
|