@etainabl/nodejs-sdk 1.2.22 → 1.2.23

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,56 @@ 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 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) {
20
69
  return __awaiter(this, void 0, void 0, function* () {
21
70
  if (!process.env.ETAINABL_DB_URL)
22
71
  throw new Error("ETAINABL_DB_URL is not set");
@@ -40,6 +89,8 @@ function connectToDatabase() {
40
89
  });
41
90
  yield client.connect();
42
91
  log.debug('Connected successfully to MongoDB server!');
92
+ if (debug)
93
+ yield showDebugInfo(client);
43
94
  cachedDb = client.db('etainabl');
44
95
  return cachedDb;
45
96
  });
@@ -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,53 @@ 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 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) {
6
52
  if (!process.env.ETAINABL_DB_URL)
7
53
  throw new Error("ETAINABL_DB_URL is not set");
8
54
  if (!process.env.AWS_ACCESS_KEY_ID)
@@ -25,6 +71,8 @@ async function connectToDatabase() {
25
71
  });
26
72
  await client.connect();
27
73
  log.debug('Connected successfully to MongoDB server!');
74
+ if (debug)
75
+ await showDebugInfo(client);
28
76
  cachedDb = client.db('etainabl');
29
77
  return cachedDb;
30
78
  }
@@ -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.23",
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,56 @@ 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 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) {
9
58
  if (!process.env.ETAINABL_DB_URL) throw new Error("ETAINABL_DB_URL is not set");
10
59
  if (!process.env.AWS_ACCESS_KEY_ID) throw new Error("AWS_ACCESS_KEY_ID is not set");
11
60
  if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error("AWS_SECRET_ACCESS_KEY is not set");
@@ -32,6 +81,8 @@ async function connectToDatabase() {
32
81
 
33
82
  log.debug('Connected successfully to MongoDB server!');
34
83
 
84
+ if (debug) await showDebugInfo(client);
85
+
35
86
  cachedDb = client.db('etainabl');
36
87
 
37
88
  return cachedDb;