dbgate-api-premium 6.6.4 → 6.6.6

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": "6.6.4",
4
+ "version": "6.6.6",
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": "^6.6.4",
33
+ "dbgate-datalib": "^6.6.6",
34
34
  "dbgate-query-splitter": "^4.11.7",
35
- "dbgate-sqltree": "^6.6.4",
36
- "dbgate-tools": "^6.6.4",
35
+ "dbgate-sqltree": "^6.6.6",
36
+ "dbgate-tools": "^6.6.6",
37
37
  "debug": "^4.3.4",
38
38
  "diff": "^5.0.0",
39
39
  "diff2html": "^3.4.13",
@@ -86,7 +86,7 @@
86
86
  "devDependencies": {
87
87
  "@types/fs-extra": "^9.0.11",
88
88
  "@types/lodash": "^4.14.149",
89
- "dbgate-types": "^6.6.4",
89
+ "dbgate-types": "^6.6.6",
90
90
  "env-cmd": "^10.1.0",
91
91
  "jsdoc-to-markdown": "^9.0.5",
92
92
  "node-loader": "^1.0.2",
@@ -8,6 +8,9 @@ const {
8
8
  getCloudContent,
9
9
  putCloudContent,
10
10
  removeCloudCachedConnection,
11
+ getPromoWidgetData,
12
+ getPromoWidgetList,
13
+ getPromoWidgetPreview,
11
14
  } = require('../utility/cloudIntf');
12
15
  const connections = require('./connections');
13
16
  const socket = require('../utility/socket');
@@ -283,6 +286,28 @@ module.exports = {
283
286
  return getAiGatewayServer();
284
287
  },
285
288
 
289
+ premiumPromoWidget_meta: true,
290
+ async premiumPromoWidget() {
291
+ const data = await getPromoWidgetData();
292
+ if (data?.state != 'data') {
293
+ return null;
294
+ }
295
+ if (data.validTo && new Date().getTime() > new Date(data.validTo).getTime()) {
296
+ return null;
297
+ }
298
+ return data;
299
+ },
300
+
301
+ promoWidgetList_meta: true,
302
+ async promoWidgetList() {
303
+ return getPromoWidgetList();
304
+ },
305
+
306
+ promoWidgetPreview_meta: true,
307
+ async promoWidgetPreview({ campaign, variant }) {
308
+ return getPromoWidgetPreview(campaign, variant);
309
+ },
310
+
286
311
  // chatStream_meta: {
287
312
  // raw: true,
288
313
  // method: 'post',
@@ -274,8 +274,6 @@ module.exports = {
274
274
 
275
275
  start_meta: true,
276
276
  async start({ script }, req) {
277
- await testStandardPermission('run-shell-script', req);
278
-
279
277
  const runid = crypto.randomUUID();
280
278
 
281
279
  if (script.type == 'json') {
@@ -291,6 +289,8 @@ module.exports = {
291
289
  return this.startCore(runid, scriptTemplate(js, false));
292
290
  }
293
291
 
292
+ await testStandardPermission('run-shell-script', req);
293
+
294
294
  if (!platformInfo.allowShellScripting) {
295
295
  sendToAuditLog(req, {
296
296
  category: 'shell',
@@ -209,11 +209,11 @@ module.exports = {
209
209
  return Promise.resolve();
210
210
  }
211
211
  this.lastPinged[conid] = new Date().getTime();
212
- const opened = await this.ensureOpened(conid);
213
- if (!opened) {
214
- return Promise.resolve();
215
- }
216
212
  try {
213
+ const opened = await this.ensureOpened(conid);
214
+ if (!opened) {
215
+ return Promise.resolve();
216
+ }
217
217
  opened.subprocess.send({ msgtype: 'ping' });
218
218
  } catch (err) {
219
219
  logger.error(extractErrorLogData(err), 'DBGM-00121 Error pinging server connection');
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '6.6.4',
4
- buildTime: '2025-10-02T14:26:45.204Z'
3
+ version: '6.6.6',
4
+ buildTime: '2025-10-27T16:20:54.818Z'
5
5
  };
@@ -13,11 +13,12 @@ const socket = require('./socket');
13
13
  const config = require('../controllers/config');
14
14
  const simpleEncryptor = require('simple-encryptor');
15
15
  const currentVersion = require('../currentVersion');
16
- const { getPublicIpInfo } = require('./hardwareFingerprint');
17
16
 
18
17
  const logger = getLogger('cloudIntf');
19
18
 
20
19
  let cloudFiles = null;
20
+ let promoWidgetData = null;
21
+ let promoWidgetDataLoaded = false;
21
22
 
22
23
  const DBGATE_IDENTITY_URL = process.env.LOCAL_DBGATE_IDENTITY
23
24
  ? 'http://localhost:3103'
@@ -200,8 +201,6 @@ async function updateCloudFiles(isRefresh) {
200
201
  lastCloudFilesTags = '';
201
202
  }
202
203
 
203
- const ipInfo = await getPublicIpInfo();
204
-
205
204
  const tags = (await collectCloudFilesSearchTags()).join(',');
206
205
  let lastCheckedTm = 0;
207
206
  if (tags == lastCloudFilesTags && cloudFiles.length > 0) {
@@ -213,7 +212,7 @@ async function updateCloudFiles(isRefresh) {
213
212
  const resp = await axios.default.get(
214
213
  `${DBGATE_CLOUD_URL}/public-cloud-updates?lastCheckedTm=${lastCheckedTm}&tags=${tags}&isRefresh=${
215
214
  isRefresh ? 1 : 0
216
- }&country=${ipInfo?.country || ''}`,
215
+ }`,
217
216
  {
218
217
  headers: {
219
218
  ...getLicenseHttpHeaders(),
@@ -262,6 +261,44 @@ async function getPublicFileData(path) {
262
261
  return resp.data;
263
262
  }
264
263
 
264
+ async function ensurePromoWidgetDataLoaded() {
265
+ if (promoWidgetDataLoaded) {
266
+ return;
267
+ }
268
+ try {
269
+ const fileContent = await fs.readFile(path.join(datadir(), 'promo-widget.json'), 'utf-8');
270
+ promoWidgetData = JSON.parse(fileContent);
271
+ } catch (err) {
272
+ promoWidgetData = null;
273
+ }
274
+ promoWidgetDataLoaded = true;
275
+ }
276
+
277
+ async function updatePremiumPromoWidget() {
278
+ await ensurePromoWidgetDataLoaded();
279
+
280
+ const tags = (await collectCloudFilesSearchTags()).join(',');
281
+
282
+ const resp = await axios.default.get(
283
+ `${DBGATE_CLOUD_URL}/premium-promo-widget?identifier=${promoWidgetData?.identifier ?? 'empty'}&tags=${tags}`,
284
+ {
285
+ headers: {
286
+ ...(await getCloudInstanceHeaders()),
287
+ 'x-app-version': currentVersion.version,
288
+ },
289
+ }
290
+ );
291
+
292
+ if (!resp.data || resp.data?.state == 'unchanged') {
293
+ return;
294
+ }
295
+
296
+ promoWidgetData = resp.data;
297
+ await fs.writeFile(path.join(datadir(), 'promo-widget.json'), JSON.stringify(promoWidgetData, null, 2));
298
+
299
+ socket.emitChanged(`promo-widget-changed`);
300
+ }
301
+
265
302
  async function refreshPublicFiles(isRefresh) {
266
303
  if (!cloudFiles) {
267
304
  await loadCloudFiles();
@@ -271,6 +308,9 @@ async function refreshPublicFiles(isRefresh) {
271
308
  } catch (err) {
272
309
  logger.error(extractErrorLogData(err), 'DBGM-00166 Error updating cloud files');
273
310
  }
311
+ if (!isProApp()) {
312
+ await updatePremiumPromoWidget();
313
+ }
274
314
  }
275
315
 
276
316
  async function callCloudApiGet(endpoint, signinHolder = null, additionalHeaders = {}) {
@@ -423,6 +463,33 @@ function removeCloudCachedConnection(folid, cntid) {
423
463
  delete cloudConnectionCache[cacheKey];
424
464
  }
425
465
 
466
+ async function getPublicIpInfo() {
467
+ try {
468
+ const resp = await axios.default.get(`${DBGATE_CLOUD_URL}/ipinfo`);
469
+ if (!resp.data?.ip) {
470
+ return { ip: 'unknown-ip' };
471
+ }
472
+ return resp.data;
473
+ } catch (err) {
474
+ return { ip: 'unknown-ip' };
475
+ }
476
+ }
477
+
478
+ async function getPromoWidgetData() {
479
+ await ensurePromoWidgetDataLoaded();
480
+ return promoWidgetData;
481
+ }
482
+
483
+ async function getPromoWidgetPreview(campaign, variant) {
484
+ const resp = await axios.default.get(`${DBGATE_CLOUD_URL}/premium-promo-widget-preview/${campaign}/${variant}`);
485
+ return resp.data;
486
+ }
487
+
488
+ async function getPromoWidgetList() {
489
+ const resp = await axios.default.get(`${DBGATE_CLOUD_URL}/promo-widget-list`);
490
+ return resp.data;
491
+ }
492
+
426
493
  module.exports = {
427
494
  createDbGateIdentitySession,
428
495
  startCloudTokenChecking,
@@ -439,4 +506,8 @@ module.exports = {
439
506
  removeCloudCachedConnection,
440
507
  readCloudTokenHolder,
441
508
  readCloudTestTokenHolder,
509
+ getPublicIpInfo,
510
+ getPromoWidgetData,
511
+ getPromoWidgetPreview,
512
+ getPromoWidgetList,
442
513
  };
@@ -53,7 +53,7 @@ const getChartExport = (title, config, imageFile, plugins) => {
53
53
  </div>
54
54
 
55
55
  <div class="footer">
56
- Exported from <a href='https://dbgate.io/' target='_blank'>DbGate</a>, powered by <a href='https://www.chartjs.org/' target='_blank'>Chart.js</a>
56
+ Exported from <a href='https://www.dbgate.io/' target='_blank'>DbGate</a>, powered by <a href='https://www.chartjs.org/' target='_blank'>Chart.js</a>
57
57
  </div>
58
58
  </body>
59
59
 
@@ -18,7 +18,7 @@ const getMapExport = (geoJson) => {
18
18
  leaflet
19
19
  .tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
20
20
  maxZoom: 19,
21
- attribution: '<a href="https://dbgate.io" title="Exported from DbGate">DbGate</a> | © OpenStreetMap',
21
+ attribution: '<a href="https://www.dbgate.io" title="Exported from DbGate">DbGate</a> | © OpenStreetMap',
22
22
  })
23
23
  .addTo(map);
24
24
 
@@ -3,18 +3,6 @@ const os = require('os');
3
3
  const crypto = require('crypto');
4
4
  const platformInfo = require('./platformInfo');
5
5
 
6
- async function getPublicIpInfo() {
7
- try {
8
- const resp = await axios.default.get('https://ipinfo.io/json');
9
- if (!resp.data?.ip) {
10
- return { ip: 'unknown-ip' };
11
- }
12
- return resp.data;
13
- } catch (err) {
14
- return { ip: 'unknown-ip' };
15
- }
16
- }
17
-
18
6
  function getMacAddress() {
19
7
  try {
20
8
  const interfaces = os.networkInterfaces();
@@ -32,6 +20,7 @@ function getMacAddress() {
32
20
  }
33
21
 
34
22
  async function getHardwareFingerprint() {
23
+ const { getPublicIpInfo } = require('./cloudIntf');
35
24
  const publicIpInfo = await getPublicIpInfo();
36
25
  const macAddress = getMacAddress();
37
26
  const platform = os.platform();
@@ -42,8 +31,6 @@ async function getHardwareFingerprint() {
42
31
  return {
43
32
  publicIp: publicIpInfo.ip,
44
33
  country: publicIpInfo.country,
45
- region: publicIpInfo.region,
46
- city: publicIpInfo.city,
47
34
  macAddress,
48
35
  platform,
49
36
  release,
@@ -68,9 +55,7 @@ async function getPublicHardwareFingerprint() {
68
55
  hash,
69
56
  payload: {
70
57
  platform: fingerprint.platform,
71
- city: fingerprint.city,
72
58
  country: fingerprint.country,
73
- region: fingerprint.region,
74
59
  isDocker: platformInfo.isDocker,
75
60
  isAwsUbuntuLayout: platformInfo.isAwsUbuntuLayout,
76
61
  isAzureUbuntuLayout: platformInfo.isAzureUbuntuLayout,
@@ -87,5 +72,4 @@ module.exports = {
87
72
  getHardwareFingerprint,
88
73
  getHardwareFingerprintHash,
89
74
  getPublicHardwareFingerprint,
90
- getPublicIpInfo,
91
75
  };