@etainabl/nodejs-sdk 1.2.23 → 1.2.25

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/dist/cjs/db.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- declare function connectToDatabase(debug?: boolean): Promise<Db>;
2
+ declare function connectToDatabase(basicAuth?: boolean): Promise<Db>;
3
3
  declare const _default: {
4
4
  connectToDatabase: typeof connectToDatabase;
5
5
  };
package/dist/cjs/db.js CHANGED
@@ -16,56 +16,7 @@ const mongodb_1 = require("mongodb");
16
16
  const logger_js_1 = __importDefault(require("./logger.js"));
17
17
  const log = (0, logger_js_1.default)('dbHelpers');
18
18
  let cachedDb;
19
- function showDebugInfo(client) {
20
- var _a, _b, _c, _d, _e;
21
- return __awaiter(this, void 0, void 0, function* () {
22
- try {
23
- log.debug('MongoDB Connection Debug Information:');
24
- // Basic connection info
25
- const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
26
- const sanitizedUri = uri.replace(/\/\/[^@]*@/, '//***:***@'); // Hide credentials
27
- log.debug(`Connection URI: ${sanitizedUri}`);
28
- // Get database admin
29
- const admin = client.db().admin();
30
- // Get server information
31
- try {
32
- const buildInfo = yield admin.buildInfo();
33
- log.debug(`MongoDB Version: ${buildInfo.version}`);
34
- }
35
- catch (err) {
36
- log.debug('Could not retrieve build info:', err.message);
37
- }
38
- // Try to get host information
39
- try {
40
- const hostInfo = yield admin.command({ hostInfo: 1 });
41
- log.debug(`Host: ${(_a = hostInfo.system) === null || _a === void 0 ? void 0 : _a.hostname}`);
42
- log.debug(`OS: ${(_b = hostInfo.os) === null || _b === void 0 ? void 0 : _b.type} ${(_c = hostInfo.os) === null || _c === void 0 ? void 0 : _c.name} ${(_d = hostInfo.os) === null || _d === void 0 ? void 0 : _d.version}`);
43
- }
44
- catch (err) {
45
- log.debug('Could not retrieve host info:', err.message);
46
- }
47
- // Try to get replica set status
48
- try {
49
- const replSetStatus = yield admin.command({ replSetGetStatus: 1 });
50
- log.debug(`Replica Set: ${replSetStatus.set}`);
51
- log.debug(`Members: ${((_e = replSetStatus.members) === null || _e === void 0 ? void 0 : _e.length) || 0}`);
52
- if (replSetStatus.members && replSetStatus.members.length > 0) {
53
- replSetStatus.members.forEach((member) => {
54
- log.debug(`- ${member.name} (${member.stateStr})`);
55
- log.debug(` Health: ${member.health}, Uptime: ${member.uptime}s`);
56
- });
57
- }
58
- }
59
- catch (err) {
60
- log.debug('Not connected to a replica set or insufficient permissions');
61
- }
62
- }
63
- catch (error) {
64
- log.error('Error showing MongoDB debug info:', error);
65
- }
66
- });
67
- }
68
- function connectToDatabase(debug = false) {
19
+ function connectToDatabase(basicAuth = false) {
69
20
  return __awaiter(this, void 0, void 0, function* () {
70
21
  if (!process.env.ETAINABL_DB_URL)
71
22
  throw new Error("ETAINABL_DB_URL is not set");
@@ -77,8 +28,16 @@ function connectToDatabase(debug = false) {
77
28
  log.debug('Using cached MongoDB connection.');
78
29
  return Promise.resolve(cachedDb);
79
30
  }
80
- log.debug('Connecting to MongoDB server...');
81
31
  const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
32
+ if (basicAuth) {
33
+ log.debug('Connecting to MongoDB server... (Auth: Basic)');
34
+ const client = new mongodb_1.MongoClient(uri);
35
+ yield client.connect();
36
+ log.debug('Connected successfully to MongoDB server! (Auth: Basic)');
37
+ cachedDb = client.db('etainabl');
38
+ return cachedDb;
39
+ }
40
+ log.debug('Connecting to MongoDB server... (Auth: AWS)');
82
41
  const client = new mongodb_1.MongoClient(uri, {
83
42
  auth: {
84
43
  username: process.env.AWS_ACCESS_KEY_ID,
@@ -88,9 +47,7 @@ function connectToDatabase(debug = false) {
88
47
  authMechanism: 'MONGODB-AWS'
89
48
  });
90
49
  yield client.connect();
91
- log.debug('Connected successfully to MongoDB server!');
92
- if (debug)
93
- yield showDebugInfo(client);
50
+ log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
94
51
  cachedDb = client.db('etainabl');
95
52
  return cachedDb;
96
53
  });
package/dist/mjs/db.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- declare function connectToDatabase(debug?: boolean): Promise<Db>;
2
+ declare function connectToDatabase(basicAuth?: boolean): Promise<Db>;
3
3
  declare const _default: {
4
4
  connectToDatabase: typeof connectToDatabase;
5
5
  };
package/dist/mjs/db.js CHANGED
@@ -2,53 +2,7 @@ import { MongoClient } from 'mongodb';
2
2
  import logger from './logger.js';
3
3
  const log = logger('dbHelpers');
4
4
  let cachedDb;
5
- async function showDebugInfo(client) {
6
- try {
7
- log.debug('MongoDB Connection Debug Information:');
8
- // Basic connection info
9
- const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
10
- const sanitizedUri = uri.replace(/\/\/[^@]*@/, '//***:***@'); // Hide credentials
11
- log.debug(`Connection URI: ${sanitizedUri}`);
12
- // Get database admin
13
- const admin = client.db().admin();
14
- // Get server information
15
- try {
16
- const buildInfo = await admin.buildInfo();
17
- log.debug(`MongoDB Version: ${buildInfo.version}`);
18
- }
19
- catch (err) {
20
- log.debug('Could not retrieve build info:', err.message);
21
- }
22
- // Try to get host information
23
- try {
24
- const hostInfo = await admin.command({ hostInfo: 1 });
25
- log.debug(`Host: ${hostInfo.system?.hostname}`);
26
- log.debug(`OS: ${hostInfo.os?.type} ${hostInfo.os?.name} ${hostInfo.os?.version}`);
27
- }
28
- catch (err) {
29
- log.debug('Could not retrieve host info:', err.message);
30
- }
31
- // Try to get replica set status
32
- try {
33
- const replSetStatus = await admin.command({ replSetGetStatus: 1 });
34
- log.debug(`Replica Set: ${replSetStatus.set}`);
35
- log.debug(`Members: ${replSetStatus.members?.length || 0}`);
36
- if (replSetStatus.members && replSetStatus.members.length > 0) {
37
- replSetStatus.members.forEach((member) => {
38
- log.debug(`- ${member.name} (${member.stateStr})`);
39
- log.debug(` Health: ${member.health}, Uptime: ${member.uptime}s`);
40
- });
41
- }
42
- }
43
- catch (err) {
44
- log.debug('Not connected to a replica set or insufficient permissions');
45
- }
46
- }
47
- catch (error) {
48
- log.error('Error showing MongoDB debug info:', error);
49
- }
50
- }
51
- async function connectToDatabase(debug = false) {
5
+ async function connectToDatabase(basicAuth = false) {
52
6
  if (!process.env.ETAINABL_DB_URL)
53
7
  throw new Error("ETAINABL_DB_URL is not set");
54
8
  if (!process.env.AWS_ACCESS_KEY_ID)
@@ -59,8 +13,16 @@ async function connectToDatabase(debug = false) {
59
13
  log.debug('Using cached MongoDB connection.');
60
14
  return Promise.resolve(cachedDb);
61
15
  }
62
- log.debug('Connecting to MongoDB server...');
63
16
  const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
17
+ if (basicAuth) {
18
+ log.debug('Connecting to MongoDB server... (Auth: Basic)');
19
+ const client = new MongoClient(uri);
20
+ await client.connect();
21
+ log.debug('Connected successfully to MongoDB server! (Auth: Basic)');
22
+ cachedDb = client.db('etainabl');
23
+ return cachedDb;
24
+ }
25
+ log.debug('Connecting to MongoDB server... (Auth: AWS)');
64
26
  const client = new MongoClient(uri, {
65
27
  auth: {
66
28
  username: process.env.AWS_ACCESS_KEY_ID,
@@ -70,9 +32,7 @@ async function connectToDatabase(debug = false) {
70
32
  authMechanism: 'MONGODB-AWS'
71
33
  });
72
34
  await client.connect();
73
- log.debug('Connected successfully to MongoDB server!');
74
- if (debug)
75
- await showDebugInfo(client);
35
+ log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
76
36
  cachedDb = client.db('etainabl');
77
37
  return cachedDb;
78
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etainabl/nodejs-sdk",
3
- "version": "1.2.23",
3
+ "version": "1.2.25",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/mjs/index.js",
6
6
  "author": "Jonathan Lambert <jonathan@etainabl.com>",
package/src/db.ts CHANGED
@@ -5,56 +5,7 @@ const log = logger('dbHelpers');
5
5
 
6
6
  let cachedDb: Db;
7
7
 
8
- async function showDebugInfo(client: MongoClient) {
9
- try {
10
- log.debug('MongoDB Connection Debug Information:');
11
-
12
- // Basic connection info
13
- const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
14
- const sanitizedUri = uri.replace(/\/\/[^@]*@/, '//***:***@'); // Hide credentials
15
- log.debug(`Connection URI: ${sanitizedUri}`);
16
-
17
- // Get database admin
18
- const admin = client.db().admin();
19
-
20
- // Get server information
21
- try {
22
- const buildInfo = await admin.buildInfo();
23
- log.debug(`MongoDB Version: ${buildInfo.version}`);
24
- } catch (err: any) {
25
- log.debug('Could not retrieve build info:', err.message);
26
- }
27
-
28
- // Try to get host information
29
- try {
30
- const hostInfo = await admin.command({ hostInfo: 1 });
31
- log.debug(`Host: ${hostInfo.system?.hostname}`);
32
- log.debug(`OS: ${hostInfo.os?.type} ${hostInfo.os?.name} ${hostInfo.os?.version}`);
33
- } catch (err: any) {
34
- log.debug('Could not retrieve host info:', err.message);
35
- }
36
-
37
- // Try to get replica set status
38
- try {
39
- const replSetStatus = await admin.command({ replSetGetStatus: 1 });
40
- log.debug(`Replica Set: ${replSetStatus.set}`);
41
- log.debug(`Members: ${replSetStatus.members?.length || 0}`);
42
-
43
- if (replSetStatus.members && replSetStatus.members.length > 0) {
44
- replSetStatus.members.forEach((member: any) => {
45
- log.debug(`- ${member.name} (${member.stateStr})`);
46
- log.debug(` Health: ${member.health}, Uptime: ${member.uptime}s`);
47
- });
48
- }
49
- } catch (err) {
50
- log.debug('Not connected to a replica set or insufficient permissions');
51
- }
52
- } catch (error) {
53
- log.error('Error showing MongoDB debug info:', error);
54
- }
55
- }
56
-
57
- async function connectToDatabase(debug = false) {
8
+ async function connectToDatabase(basicAuth = false) {
58
9
  if (!process.env.ETAINABL_DB_URL) throw new Error("ETAINABL_DB_URL is not set");
59
10
  if (!process.env.AWS_ACCESS_KEY_ID) throw new Error("AWS_ACCESS_KEY_ID is not set");
60
11
  if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error("AWS_SECRET_ACCESS_KEY is not set");
@@ -63,10 +14,23 @@ async function connectToDatabase(debug = false) {
63
14
  log.debug('Using cached MongoDB connection.');
64
15
  return Promise.resolve(cachedDb);
65
16
  }
17
+
18
+ const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
19
+
20
+ if (basicAuth) {
21
+ log.debug('Connecting to MongoDB server... (Auth: Basic)');
66
22
 
67
- log.debug('Connecting to MongoDB server...');
23
+ const client = new MongoClient(uri);
24
+ await client.connect();
68
25
 
69
- const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
26
+ log.debug('Connected successfully to MongoDB server! (Auth: Basic)');
27
+
28
+ cachedDb = client.db('etainabl');
29
+
30
+ return cachedDb;
31
+ }
32
+
33
+ log.debug('Connecting to MongoDB server... (Auth: AWS)');
70
34
 
71
35
  const client = new MongoClient(uri, {
72
36
  auth: {
@@ -79,9 +43,7 @@ async function connectToDatabase(debug = false) {
79
43
 
80
44
  await client.connect();
81
45
 
82
- log.debug('Connected successfully to MongoDB server!');
83
-
84
- if (debug) await showDebugInfo(client);
46
+ log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
85
47
 
86
48
  cachedDb = client.db('etainabl');
87
49