@etainabl/nodejs-sdk 1.2.22 → 1.2.24

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/api.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
2
- import type { Account, Asset, Company, Invoice, Log, Reading, Report } from '../types/index.js';
3
2
  export interface ETNPagedResponse<T = any> {
4
3
  data: T[];
5
4
  total: number;
package/dist/cjs/db.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- declare function connectToDatabase(): Promise<Db>;
2
+ declare function connectToDatabase(debug?: boolean): Promise<Db>;
3
3
  declare const _default: {
4
4
  connectToDatabase: typeof connectToDatabase;
5
5
  };
package/dist/cjs/db.js CHANGED
@@ -16,7 +16,82 @@ 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 connectToDatabase() {
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) {
20
95
  return __awaiter(this, void 0, void 0, function* () {
21
96
  if (!process.env.ETAINABL_DB_URL)
22
97
  throw new Error("ETAINABL_DB_URL is not set");
@@ -40,6 +115,8 @@ function connectToDatabase() {
40
115
  });
41
116
  yield client.connect();
42
117
  log.debug('Connected successfully to MongoDB server!');
118
+ if (debug)
119
+ yield showDebugInfo(client);
43
120
  cachedDb = client.db('etainabl');
44
121
  return cachedDb;
45
122
  });
@@ -5,9 +5,9 @@ interface Item {
5
5
  value: number;
6
6
  [key: string]: any;
7
7
  }
8
- export type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'other';
9
- export type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';
10
- export type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h';
8
+ export declare type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'other';
9
+ export declare type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';
10
+ export declare type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h';
11
11
  export declare const accountTypeMap: {
12
12
  [key: string]: BaseUnit;
13
13
  };
package/dist/mjs/api.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
2
- import type { Account, Asset, Company, Invoice, Log, Reading, Report } from '../types/index.js';
3
2
  export interface ETNPagedResponse<T = any> {
4
3
  data: T[];
5
4
  total: number;
package/dist/mjs/db.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- declare function connectToDatabase(): Promise<Db>;
2
+ declare function connectToDatabase(debug?: boolean): Promise<Db>;
3
3
  declare const _default: {
4
4
  connectToDatabase: typeof connectToDatabase;
5
5
  };
package/dist/mjs/db.js CHANGED
@@ -2,7 +2,79 @@ import { MongoClient } from 'mongodb';
2
2
  import logger from './logger.js';
3
3
  const log = logger('dbHelpers');
4
4
  let cachedDb;
5
- async function connectToDatabase() {
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) {
6
78
  if (!process.env.ETAINABL_DB_URL)
7
79
  throw new Error("ETAINABL_DB_URL is not set");
8
80
  if (!process.env.AWS_ACCESS_KEY_ID)
@@ -25,6 +97,8 @@ async function connectToDatabase() {
25
97
  });
26
98
  await client.connect();
27
99
  log.debug('Connected successfully to MongoDB server!');
100
+ if (debug)
101
+ await showDebugInfo(client);
28
102
  cachedDb = client.db('etainabl');
29
103
  return cachedDb;
30
104
  }
@@ -5,9 +5,9 @@ interface Item {
5
5
  value: number;
6
6
  [key: string]: any;
7
7
  }
8
- export type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'other';
9
- export type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';
10
- export type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h';
8
+ export declare type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'other';
9
+ export declare type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';
10
+ export declare type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h';
11
11
  export declare const accountTypeMap: {
12
12
  [key: string]: BaseUnit;
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etainabl/nodejs-sdk",
3
- "version": "1.2.22",
3
+ "version": "1.2.24",
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,7 +5,85 @@ const log = logger('dbHelpers');
5
5
 
6
6
  let cachedDb: Db;
7
7
 
8
- async function connectToDatabase() {
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) {
9
87
  if (!process.env.ETAINABL_DB_URL) throw new Error("ETAINABL_DB_URL is not set");
10
88
  if (!process.env.AWS_ACCESS_KEY_ID) throw new Error("AWS_ACCESS_KEY_ID is not set");
11
89
  if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error("AWS_SECRET_ACCESS_KEY is not set");
@@ -32,6 +110,8 @@ async function connectToDatabase() {
32
110
 
33
111
  log.debug('Connected successfully to MongoDB server!');
34
112
 
113
+ if (debug) await showDebugInfo(client);
114
+
35
115
  cachedDb = client.db('etainabl');
36
116
 
37
117
  return cachedDb;