@etainabl/nodejs-sdk 1.2.24 → 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,82 +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 connection info using hello command (works with lower privileges)
29
- try {
30
- const helloInfo = yield client.db().command({ hello: 1 });
31
- log.debug(`Connected to: ${helloInfo.me || helloInfo.primary}`);
32
- if (helloInfo.hosts) {
33
- log.debug('Cluster hosts:');
34
- helloInfo.hosts.forEach((host) => {
35
- log.debug(`- ${host}`);
36
- });
37
- }
38
- // Connection type
39
- log.debug(`Connection type: ${helloInfo.ismaster ? 'Primary' : 'Secondary'}`);
40
- log.debug(`Connection set name: ${helloInfo.setName || 'Not part of a replica set'}`);
41
- // Direct client info
42
- const connectionInfo = client.options.hosts;
43
- if (connectionInfo && connectionInfo.length > 0) {
44
- log.debug('Client connection details:');
45
- connectionInfo.forEach((host) => {
46
- log.debug(`- ${host.host}:${host.port}`);
47
- });
48
- }
49
- }
50
- catch (err) {
51
- log.debug('Could not retrieve connection info:', err.message);
52
- }
53
- // Remaining original code...
54
- // Get database admin
55
- const admin = client.db().admin();
56
- // Get server information
57
- try {
58
- const buildInfo = yield admin.buildInfo();
59
- log.debug(`MongoDB Version: ${buildInfo.version}`);
60
- }
61
- catch (err) {
62
- log.debug('Could not retrieve build info:', err.message);
63
- }
64
- // Try to get host information
65
- try {
66
- const hostInfo = yield admin.command({ hostInfo: 1 });
67
- log.debug(`Host: ${(_a = hostInfo.system) === null || _a === void 0 ? void 0 : _a.hostname}`);
68
- 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}`);
69
- }
70
- catch (err) {
71
- log.debug('Could not retrieve host info:', err.message);
72
- }
73
- // Try to get replica set status
74
- try {
75
- const replSetStatus = yield admin.command({ replSetGetStatus: 1 });
76
- log.debug(`Replica Set: ${replSetStatus.set}`);
77
- log.debug(`Members: ${((_e = replSetStatus.members) === null || _e === void 0 ? void 0 : _e.length) || 0}`);
78
- if (replSetStatus.members && replSetStatus.members.length > 0) {
79
- replSetStatus.members.forEach((member) => {
80
- log.debug(`- ${member.name} (${member.stateStr})`);
81
- log.debug(` Health: ${member.health}, Uptime: ${member.uptime}s`);
82
- });
83
- }
84
- }
85
- catch (err) {
86
- log.debug('Not connected to a replica set or insufficient permissions');
87
- }
88
- }
89
- catch (error) {
90
- log.error('Error showing MongoDB debug info:', error);
91
- }
92
- });
93
- }
94
- function connectToDatabase(debug = false) {
19
+ function connectToDatabase(basicAuth = false) {
95
20
  return __awaiter(this, void 0, void 0, function* () {
96
21
  if (!process.env.ETAINABL_DB_URL)
97
22
  throw new Error("ETAINABL_DB_URL is not set");
@@ -103,8 +28,16 @@ function connectToDatabase(debug = false) {
103
28
  log.debug('Using cached MongoDB connection.');
104
29
  return Promise.resolve(cachedDb);
105
30
  }
106
- log.debug('Connecting to MongoDB server...');
107
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)');
108
41
  const client = new mongodb_1.MongoClient(uri, {
109
42
  auth: {
110
43
  username: process.env.AWS_ACCESS_KEY_ID,
@@ -114,9 +47,7 @@ function connectToDatabase(debug = false) {
114
47
  authMechanism: 'MONGODB-AWS'
115
48
  });
116
49
  yield client.connect();
117
- log.debug('Connected successfully to MongoDB server!');
118
- if (debug)
119
- yield showDebugInfo(client);
50
+ log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
120
51
  cachedDb = client.db('etainabl');
121
52
  return cachedDb;
122
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,79 +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 connection info using hello command (works with lower privileges)
13
- try {
14
- const helloInfo = await client.db().command({ hello: 1 });
15
- log.debug(`Connected to: ${helloInfo.me || helloInfo.primary}`);
16
- if (helloInfo.hosts) {
17
- log.debug('Cluster hosts:');
18
- helloInfo.hosts.forEach((host) => {
19
- log.debug(`- ${host}`);
20
- });
21
- }
22
- // Connection type
23
- log.debug(`Connection type: ${helloInfo.ismaster ? 'Primary' : 'Secondary'}`);
24
- log.debug(`Connection set name: ${helloInfo.setName || 'Not part of a replica set'}`);
25
- // Direct client info
26
- const connectionInfo = client.options.hosts;
27
- if (connectionInfo && connectionInfo.length > 0) {
28
- log.debug('Client connection details:');
29
- connectionInfo.forEach((host) => {
30
- log.debug(`- ${host.host}:${host.port}`);
31
- });
32
- }
33
- }
34
- catch (err) {
35
- log.debug('Could not retrieve connection info:', err.message);
36
- }
37
- // Remaining original code...
38
- // Get database admin
39
- const admin = client.db().admin();
40
- // Get server information
41
- try {
42
- const buildInfo = await admin.buildInfo();
43
- log.debug(`MongoDB Version: ${buildInfo.version}`);
44
- }
45
- catch (err) {
46
- log.debug('Could not retrieve build info:', err.message);
47
- }
48
- // Try to get host information
49
- try {
50
- const hostInfo = await admin.command({ hostInfo: 1 });
51
- log.debug(`Host: ${hostInfo.system?.hostname}`);
52
- log.debug(`OS: ${hostInfo.os?.type} ${hostInfo.os?.name} ${hostInfo.os?.version}`);
53
- }
54
- catch (err) {
55
- log.debug('Could not retrieve host info:', err.message);
56
- }
57
- // Try to get replica set status
58
- try {
59
- const replSetStatus = await admin.command({ replSetGetStatus: 1 });
60
- log.debug(`Replica Set: ${replSetStatus.set}`);
61
- log.debug(`Members: ${replSetStatus.members?.length || 0}`);
62
- if (replSetStatus.members && replSetStatus.members.length > 0) {
63
- replSetStatus.members.forEach((member) => {
64
- log.debug(`- ${member.name} (${member.stateStr})`);
65
- log.debug(` Health: ${member.health}, Uptime: ${member.uptime}s`);
66
- });
67
- }
68
- }
69
- catch (err) {
70
- log.debug('Not connected to a replica set or insufficient permissions');
71
- }
72
- }
73
- catch (error) {
74
- log.error('Error showing MongoDB debug info:', error);
75
- }
76
- }
77
- async function connectToDatabase(debug = false) {
5
+ async function connectToDatabase(basicAuth = false) {
78
6
  if (!process.env.ETAINABL_DB_URL)
79
7
  throw new Error("ETAINABL_DB_URL is not set");
80
8
  if (!process.env.AWS_ACCESS_KEY_ID)
@@ -85,8 +13,16 @@ async function connectToDatabase(debug = false) {
85
13
  log.debug('Using cached MongoDB connection.');
86
14
  return Promise.resolve(cachedDb);
87
15
  }
88
- log.debug('Connecting to MongoDB server...');
89
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)');
90
26
  const client = new MongoClient(uri, {
91
27
  auth: {
92
28
  username: process.env.AWS_ACCESS_KEY_ID,
@@ -96,9 +32,7 @@ async function connectToDatabase(debug = false) {
96
32
  authMechanism: 'MONGODB-AWS'
97
33
  });
98
34
  await client.connect();
99
- log.debug('Connected successfully to MongoDB server!');
100
- if (debug)
101
- await showDebugInfo(client);
35
+ log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
102
36
  cachedDb = client.db('etainabl');
103
37
  return cachedDb;
104
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etainabl/nodejs-sdk",
3
- "version": "1.2.24",
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,85 +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 connection info using hello command (works with lower privileges)
18
- try {
19
- const helloInfo = await client.db().command({ hello: 1 });
20
- log.debug(`Connected to: ${helloInfo.me || helloInfo.primary}`);
21
-
22
- if (helloInfo.hosts) {
23
- log.debug('Cluster hosts:');
24
- helloInfo.hosts.forEach((host: string) => {
25
- log.debug(`- ${host}`);
26
- });
27
- }
28
-
29
- // Connection type
30
- log.debug(`Connection type: ${helloInfo.ismaster ? 'Primary' : 'Secondary'}`);
31
- log.debug(`Connection set name: ${helloInfo.setName || 'Not part of a replica set'}`);
32
-
33
- // Direct client info
34
- const connectionInfo = client.options.hosts;
35
- if (connectionInfo && connectionInfo.length > 0) {
36
- log.debug('Client connection details:');
37
- connectionInfo.forEach((host: any) => {
38
- log.debug(`- ${host.host}:${host.port}`);
39
- });
40
- }
41
- } catch (err: any) {
42
- log.debug('Could not retrieve connection info:', err.message);
43
- }
44
-
45
- // Remaining original code...
46
- // Get database admin
47
- const admin = client.db().admin();
48
-
49
- // Get server information
50
- try {
51
- const buildInfo = await admin.buildInfo();
52
- log.debug(`MongoDB Version: ${buildInfo.version}`);
53
- } catch (err: any) {
54
- log.debug('Could not retrieve build info:', err.message);
55
- }
56
-
57
- // Try to get host information
58
- try {
59
- const hostInfo = await admin.command({ hostInfo: 1 });
60
- log.debug(`Host: ${hostInfo.system?.hostname}`);
61
- log.debug(`OS: ${hostInfo.os?.type} ${hostInfo.os?.name} ${hostInfo.os?.version}`);
62
- } catch (err: any) {
63
- log.debug('Could not retrieve host info:', err.message);
64
- }
65
-
66
- // Try to get replica set status
67
- try {
68
- const replSetStatus = await admin.command({ replSetGetStatus: 1 });
69
- log.debug(`Replica Set: ${replSetStatus.set}`);
70
- log.debug(`Members: ${replSetStatus.members?.length || 0}`);
71
-
72
- if (replSetStatus.members && replSetStatus.members.length > 0) {
73
- replSetStatus.members.forEach((member: any) => {
74
- log.debug(`- ${member.name} (${member.stateStr})`);
75
- log.debug(` Health: ${member.health}, Uptime: ${member.uptime}s`);
76
- });
77
- }
78
- } catch (err) {
79
- log.debug('Not connected to a replica set or insufficient permissions');
80
- }
81
- } catch (error) {
82
- log.error('Error showing MongoDB debug info:', error);
83
- }
84
- }
85
-
86
- async function connectToDatabase(debug = false) {
8
+ async function connectToDatabase(basicAuth = false) {
87
9
  if (!process.env.ETAINABL_DB_URL) throw new Error("ETAINABL_DB_URL is not set");
88
10
  if (!process.env.AWS_ACCESS_KEY_ID) throw new Error("AWS_ACCESS_KEY_ID is not set");
89
11
  if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error("AWS_SECRET_ACCESS_KEY is not set");
@@ -92,10 +14,23 @@ async function connectToDatabase(debug = false) {
92
14
  log.debug('Using cached MongoDB connection.');
93
15
  return Promise.resolve(cachedDb);
94
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)');
95
22
 
96
- log.debug('Connecting to MongoDB server...');
23
+ const client = new MongoClient(uri);
24
+ await client.connect();
97
25
 
98
- 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)');
99
34
 
100
35
  const client = new MongoClient(uri, {
101
36
  auth: {
@@ -108,9 +43,7 @@ async function connectToDatabase(debug = false) {
108
43
 
109
44
  await client.connect();
110
45
 
111
- log.debug('Connected successfully to MongoDB server!');
112
-
113
- if (debug) await showDebugInfo(client);
46
+ log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
114
47
 
115
48
  cachedDb = client.db('etainabl');
116
49