@etainabl/nodejs-sdk 1.2.26 → 1.2.28
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 +1 -0
- package/dist/cjs/db.d.ts +1 -1
- package/dist/cjs/db.js +30 -18
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/units.d.ts +3 -3
- package/dist/mjs/api.d.ts +1 -0
- package/dist/mjs/db.d.ts +1 -1
- package/dist/mjs/db.js +30 -18
- package/dist/mjs/index.d.ts +1 -1
- package/dist/mjs/units.d.ts +3 -3
- package/package.json +1 -1
- package/src/api.ts +1 -1
- package/src/db.ts +36 -22
- package/src/index.ts +1 -1
- /package/{types → src/types}/account.d.ts +0 -0
- /package/{types → src/types}/address.d.ts +0 -0
- /package/{types → src/types}/asset.d.ts +0 -0
- /package/{types → src/types}/automation.d.ts +0 -0
- /package/{types → src/types}/company.d.ts +0 -0
- /package/{types → src/types}/dataIngest.d.ts +0 -0
- /package/{types → src/types}/email.d.ts +0 -0
- /package/{types → src/types}/index.d.ts +0 -0
- /package/{types → src/types}/invoice.d.ts +0 -0
- /package/{types → src/types}/log.d.ts +0 -0
- /package/{types → src/types}/portal.d.ts +0 -0
- /package/{types → src/types}/reading.d.ts +0 -0
- /package/{types → src/types}/report.d.ts +0 -0
- /package/{types → src/types}/scraperRun.d.ts +0 -0
- /package/{types → src/types}/statusHistory.d.ts +0 -0
- /package/{types → src/types}/supplier.d.ts +0 -0
package/dist/cjs/api.d.ts
CHANGED
package/dist/cjs/db.d.ts
CHANGED
package/dist/cjs/db.js
CHANGED
|
@@ -16,7 +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 connectToDatabase() {
|
|
19
|
+
function connectToDatabase(retryAttempt = 1) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
if (!process.env.ETAINABL_DB_URL)
|
|
22
22
|
throw new Error("ETAINABL_DB_URL is not set");
|
|
@@ -29,27 +29,39 @@ function connectToDatabase() {
|
|
|
29
29
|
return Promise.resolve(cachedDb);
|
|
30
30
|
}
|
|
31
31
|
const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
try {
|
|
33
|
+
if (process.env.DB_BASIC_AUTH === 'true') {
|
|
34
|
+
log.debug('Connecting to MongoDB server... (Auth: Basic)');
|
|
35
|
+
const client = new mongodb_1.MongoClient(uri);
|
|
36
|
+
yield client.connect();
|
|
37
|
+
log.debug('Connected successfully to MongoDB server! (Auth: Basic)');
|
|
38
|
+
cachedDb = client.db('etainabl');
|
|
39
|
+
return cachedDb;
|
|
40
|
+
}
|
|
41
|
+
log.debug('Connecting to MongoDB server... (Auth: AWS)');
|
|
42
|
+
const client = new mongodb_1.MongoClient(uri, {
|
|
43
|
+
auth: {
|
|
44
|
+
username: process.env.AWS_ACCESS_KEY_ID,
|
|
45
|
+
password: process.env.AWS_SECRET_ACCESS_KEY
|
|
46
|
+
},
|
|
47
|
+
authSource: '$external',
|
|
48
|
+
authMechanism: 'MONGODB-AWS'
|
|
49
|
+
});
|
|
35
50
|
yield client.connect();
|
|
36
|
-
log.debug('Connected successfully to MongoDB server! (Auth:
|
|
51
|
+
log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
|
|
37
52
|
cachedDb = client.db('etainabl');
|
|
38
53
|
return cachedDb;
|
|
39
54
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
|
|
51
|
-
cachedDb = client.db('etainabl');
|
|
52
|
-
return cachedDb;
|
|
55
|
+
catch (e) {
|
|
56
|
+
// Retry
|
|
57
|
+
if (retryAttempt > 5) {
|
|
58
|
+
console.log(`Error connecting to MongoDB server after 5 attempts...`);
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
console.log(`MongoDB Connection error: ${e.message}`);
|
|
62
|
+
console.log(`Error connecting to MongoDB server... Retrying in 3 seconds... (Attempt ${retryAttempt})`);
|
|
63
|
+
return connectToDatabase(retryAttempt + 1);
|
|
64
|
+
}
|
|
53
65
|
});
|
|
54
66
|
}
|
|
55
67
|
exports.default = {
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ import * as units from './units.js';
|
|
|
6
6
|
import * as consumption from './consumption.js';
|
|
7
7
|
import * as monitoring from './monitoring.js';
|
|
8
8
|
import * as reporting from './reporting.js';
|
|
9
|
-
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier } from '
|
|
9
|
+
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier } from './types/index.d.js';
|
|
10
10
|
export { api, logger, consumption, monitoring, db, slack, units, reporting };
|
|
11
11
|
export type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier };
|
package/dist/cjs/units.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ interface Item {
|
|
|
5
5
|
value: number;
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
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';
|
|
11
11
|
export declare const accountTypeMap: {
|
|
12
12
|
[key: string]: BaseUnit;
|
|
13
13
|
};
|
package/dist/mjs/api.d.ts
CHANGED
package/dist/mjs/db.d.ts
CHANGED
package/dist/mjs/db.js
CHANGED
|
@@ -2,7 +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 connectToDatabase() {
|
|
5
|
+
async function connectToDatabase(retryAttempt = 1) {
|
|
6
6
|
if (!process.env.ETAINABL_DB_URL)
|
|
7
7
|
throw new Error("ETAINABL_DB_URL is not set");
|
|
8
8
|
if (!process.env.AWS_ACCESS_KEY_ID)
|
|
@@ -14,27 +14,39 @@ async function connectToDatabase() {
|
|
|
14
14
|
return Promise.resolve(cachedDb);
|
|
15
15
|
}
|
|
16
16
|
const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
try {
|
|
18
|
+
if (process.env.DB_BASIC_AUTH === 'true') {
|
|
19
|
+
log.debug('Connecting to MongoDB server... (Auth: Basic)');
|
|
20
|
+
const client = new MongoClient(uri);
|
|
21
|
+
await client.connect();
|
|
22
|
+
log.debug('Connected successfully to MongoDB server! (Auth: Basic)');
|
|
23
|
+
cachedDb = client.db('etainabl');
|
|
24
|
+
return cachedDb;
|
|
25
|
+
}
|
|
26
|
+
log.debug('Connecting to MongoDB server... (Auth: AWS)');
|
|
27
|
+
const client = new MongoClient(uri, {
|
|
28
|
+
auth: {
|
|
29
|
+
username: process.env.AWS_ACCESS_KEY_ID,
|
|
30
|
+
password: process.env.AWS_SECRET_ACCESS_KEY
|
|
31
|
+
},
|
|
32
|
+
authSource: '$external',
|
|
33
|
+
authMechanism: 'MONGODB-AWS'
|
|
34
|
+
});
|
|
20
35
|
await client.connect();
|
|
21
|
-
log.debug('Connected successfully to MongoDB server! (Auth:
|
|
36
|
+
log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
|
|
22
37
|
cachedDb = client.db('etainabl');
|
|
23
38
|
return cachedDb;
|
|
24
39
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
|
|
36
|
-
cachedDb = client.db('etainabl');
|
|
37
|
-
return cachedDb;
|
|
40
|
+
catch (e) {
|
|
41
|
+
// Retry
|
|
42
|
+
if (retryAttempt > 5) {
|
|
43
|
+
console.log(`Error connecting to MongoDB server after 5 attempts...`);
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
console.log(`MongoDB Connection error: ${e.message}`);
|
|
47
|
+
console.log(`Error connecting to MongoDB server... Retrying in 3 seconds... (Attempt ${retryAttempt})`);
|
|
48
|
+
return connectToDatabase(retryAttempt + 1);
|
|
49
|
+
}
|
|
38
50
|
}
|
|
39
51
|
export default {
|
|
40
52
|
connectToDatabase
|
package/dist/mjs/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ import * as units from './units.js';
|
|
|
6
6
|
import * as consumption from './consumption.js';
|
|
7
7
|
import * as monitoring from './monitoring.js';
|
|
8
8
|
import * as reporting from './reporting.js';
|
|
9
|
-
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier } from '
|
|
9
|
+
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier } from './types/index.d.js';
|
|
10
10
|
export { api, logger, consumption, monitoring, db, slack, units, reporting };
|
|
11
11
|
export type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier };
|
package/dist/mjs/units.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ interface Item {
|
|
|
5
5
|
value: number;
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
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';
|
|
11
11
|
export declare const accountTypeMap: {
|
|
12
12
|
[key: string]: BaseUnit;
|
|
13
13
|
};
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -4,7 +4,7 @@ import https from 'https';
|
|
|
4
4
|
|
|
5
5
|
import logger from './logger.js';
|
|
6
6
|
|
|
7
|
-
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Report, Supplier } from '
|
|
7
|
+
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Report, Supplier } from './types/index.js'
|
|
8
8
|
|
|
9
9
|
const log = logger('etainablApi');
|
|
10
10
|
|
package/src/db.ts
CHANGED
|
@@ -5,7 +5,7 @@ const log = logger('dbHelpers');
|
|
|
5
5
|
|
|
6
6
|
let cachedDb: Db;
|
|
7
7
|
|
|
8
|
-
async function connectToDatabase() {
|
|
8
|
+
async function connectToDatabase(retryAttempt: number = 1): Promise<Db> {
|
|
9
9
|
if (!process.env.ETAINABL_DB_URL) throw new Error("ETAINABL_DB_URL is not set");
|
|
10
10
|
if (!process.env.AWS_ACCESS_KEY_ID) throw new Error("AWS_ACCESS_KEY_ID is not set");
|
|
11
11
|
if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error("AWS_SECRET_ACCESS_KEY is not set");
|
|
@@ -17,37 +17,51 @@ async function connectToDatabase() {
|
|
|
17
17
|
|
|
18
18
|
const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
try {
|
|
21
|
+
if (process.env.DB_BASIC_AUTH === 'true') {
|
|
22
|
+
log.debug('Connecting to MongoDB server... (Auth: Basic)');
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const client = new MongoClient(uri);
|
|
25
|
+
await client.connect();
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
log.debug('Connected successfully to MongoDB server! (Auth: Basic)');
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
cachedDb = client.db('etainabl');
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
return cachedDb;
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
log.debug('Connecting to MongoDB server... (Auth: AWS)');
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
const client = new MongoClient(uri, {
|
|
37
|
+
auth: {
|
|
38
|
+
username: process.env.AWS_ACCESS_KEY_ID,
|
|
39
|
+
password: process.env.AWS_SECRET_ACCESS_KEY
|
|
40
|
+
},
|
|
41
|
+
authSource: '$external',
|
|
42
|
+
authMechanism: 'MONGODB-AWS'
|
|
43
|
+
});
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
await client.connect();
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
cachedDb = client.db('etainabl');
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
return cachedDb;
|
|
52
|
+
|
|
53
|
+
} catch (e: any) {
|
|
54
|
+
// Retry
|
|
55
|
+
if (retryAttempt > 5) {
|
|
56
|
+
console.log(`Error connecting to MongoDB server after 5 attempts...`);
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(`MongoDB Connection error: ${e.message}`);
|
|
61
|
+
|
|
62
|
+
console.log(`Error connecting to MongoDB server... Retrying in 3 seconds... (Attempt ${retryAttempt})`);
|
|
63
|
+
return connectToDatabase(retryAttempt + 1);
|
|
64
|
+
}
|
|
51
65
|
}
|
|
52
66
|
|
|
53
67
|
export default {
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as units from './units.js';
|
|
|
6
6
|
import * as consumption from './consumption.js';
|
|
7
7
|
import * as monitoring from './monitoring.js';
|
|
8
8
|
import * as reporting from './reporting.js';
|
|
9
|
-
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier } from '
|
|
9
|
+
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier } from './types/index.d.js';
|
|
10
10
|
|
|
11
11
|
export {
|
|
12
12
|
api,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|