@etainabl/nodejs-sdk 1.2.44 → 1.2.46
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/index.d.cts +782 -0
- package/dist/index.d.ts +782 -0
- package/dist/index.js +626 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +588 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +28 -31
- package/.prettierrc +0 -11
- package/__tests__/reporting.test.ts +0 -88
- package/dist/cjs/api.d.ts +0 -111
- package/dist/cjs/api.js +0 -318
- package/dist/cjs/consumption.d.ts +0 -14
- package/dist/cjs/consumption.js +0 -32
- package/dist/cjs/db.d.ts +0 -6
- package/dist/cjs/db.js +0 -69
- package/dist/cjs/etainabl.d.ts +0 -10
- package/dist/cjs/etainabl.js +0 -2
- package/dist/cjs/index.d.ts +0 -10
- package/dist/cjs/index.js +0 -59
- package/dist/cjs/logger.d.ts +0 -3
- package/dist/cjs/logger.js +0 -14
- package/dist/cjs/monitoring.d.ts +0 -1
- package/dist/cjs/monitoring.js +0 -31
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/reporting.d.ts +0 -2
- package/dist/cjs/reporting.js +0 -69
- package/dist/cjs/slack.d.ts +0 -4
- package/dist/cjs/slack.js +0 -28
- package/dist/cjs/types/account.d.ts +0 -112
- package/dist/cjs/types/account.js +0 -2
- package/dist/cjs/types/address.d.ts +0 -11
- package/dist/cjs/types/address.js +0 -2
- package/dist/cjs/types/asset.d.ts +0 -122
- package/dist/cjs/types/asset.js +0 -3
- package/dist/cjs/types/automation.d.ts +0 -33
- package/dist/cjs/types/automation.js +0 -2
- package/dist/cjs/types/company.d.ts +0 -42
- package/dist/cjs/types/company.js +0 -2
- package/dist/cjs/types/dataIngest.d.ts +0 -8
- package/dist/cjs/types/dataIngest.js +0 -2
- package/dist/cjs/types/email.d.ts +0 -18
- package/dist/cjs/types/email.js +0 -2
- package/dist/cjs/types/entity.d.ts +0 -16
- package/dist/cjs/types/entity.js +0 -2
- package/dist/cjs/types/index.d.ts +0 -19
- package/dist/cjs/types/index.js +0 -2
- package/dist/cjs/types/invoice.d.ts +0 -118
- package/dist/cjs/types/invoice.js +0 -2
- package/dist/cjs/types/log.d.ts +0 -10
- package/dist/cjs/types/log.js +0 -2
- package/dist/cjs/types/portal.d.ts +0 -8
- package/dist/cjs/types/portal.js +0 -2
- package/dist/cjs/types/reading.d.ts +0 -17
- package/dist/cjs/types/reading.js +0 -2
- package/dist/cjs/types/report.d.ts +0 -21
- package/dist/cjs/types/report.js +0 -2
- package/dist/cjs/types/scraperRun.d.ts +0 -15
- package/dist/cjs/types/scraperRun.js +0 -2
- package/dist/cjs/types/statusHistory.d.ts +0 -5
- package/dist/cjs/types/statusHistory.js +0 -2
- package/dist/cjs/types/supplier.d.ts +0 -28
- package/dist/cjs/types/supplier.js +0 -3
- package/dist/cjs/units.d.ts +0 -22
- package/dist/cjs/units.js +0 -94
- package/dist/mjs/api.d.ts +0 -111
- package/dist/mjs/api.js +0 -308
- package/dist/mjs/consumption.d.ts +0 -14
- package/dist/mjs/consumption.js +0 -22
- package/dist/mjs/db.d.ts +0 -6
- package/dist/mjs/db.js +0 -53
- package/dist/mjs/etainabl.d.ts +0 -10
- package/dist/mjs/etainabl.js +0 -1
- package/dist/mjs/index.d.ts +0 -10
- package/dist/mjs/index.js +0 -10
- package/dist/mjs/logger.d.ts +0 -3
- package/dist/mjs/logger.js +0 -9
- package/dist/mjs/monitoring.d.ts +0 -1
- package/dist/mjs/monitoring.js +0 -15
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/reporting.d.ts +0 -2
- package/dist/mjs/reporting.js +0 -62
- package/dist/mjs/slack.d.ts +0 -4
- package/dist/mjs/slack.js +0 -14
- package/dist/mjs/types/account.d.ts +0 -112
- package/dist/mjs/types/account.js +0 -1
- package/dist/mjs/types/address.d.ts +0 -11
- package/dist/mjs/types/address.js +0 -1
- package/dist/mjs/types/asset.d.ts +0 -122
- package/dist/mjs/types/asset.js +0 -2
- package/dist/mjs/types/automation.d.ts +0 -33
- package/dist/mjs/types/automation.js +0 -1
- package/dist/mjs/types/company.d.ts +0 -42
- package/dist/mjs/types/company.js +0 -1
- package/dist/mjs/types/dataIngest.d.ts +0 -8
- package/dist/mjs/types/dataIngest.js +0 -1
- package/dist/mjs/types/email.d.ts +0 -18
- package/dist/mjs/types/email.js +0 -1
- package/dist/mjs/types/entity.d.ts +0 -16
- package/dist/mjs/types/entity.js +0 -1
- package/dist/mjs/types/index.d.ts +0 -19
- package/dist/mjs/types/index.js +0 -1
- package/dist/mjs/types/invoice.d.ts +0 -118
- package/dist/mjs/types/invoice.js +0 -1
- package/dist/mjs/types/log.d.ts +0 -10
- package/dist/mjs/types/log.js +0 -1
- package/dist/mjs/types/portal.d.ts +0 -8
- package/dist/mjs/types/portal.js +0 -1
- package/dist/mjs/types/reading.d.ts +0 -17
- package/dist/mjs/types/reading.js +0 -1
- package/dist/mjs/types/report.d.ts +0 -21
- package/dist/mjs/types/report.js +0 -1
- package/dist/mjs/types/scraperRun.d.ts +0 -15
- package/dist/mjs/types/scraperRun.js +0 -1
- package/dist/mjs/types/statusHistory.d.ts +0 -5
- package/dist/mjs/types/statusHistory.js +0 -1
- package/dist/mjs/types/supplier.d.ts +0 -28
- package/dist/mjs/types/supplier.js +0 -2
- package/dist/mjs/units.d.ts +0 -22
- package/dist/mjs/units.js +0 -89
- package/eslint.config.js +0 -60
- package/fixup.sh +0 -11
- package/src/api.ts +0 -382
- package/src/consumption.ts +0 -40
- package/src/db.ts +0 -69
- package/src/etainabl.ts +0 -10
- package/src/index.ts +0 -21
- package/src/logger.ts +0 -13
- package/src/monitoring.ts +0 -18
- package/src/reporting.ts +0 -78
- package/src/slack.ts +0 -16
- package/src/types/account.ts +0 -116
- package/src/types/address.ts +0 -12
- package/src/types/asset.ts +0 -142
- package/src/types/automation.ts +0 -35
- package/src/types/company.ts +0 -47
- package/src/types/dataIngest.ts +0 -8
- package/src/types/email.ts +0 -18
- package/src/types/entity.ts +0 -17
- package/src/types/index.ts +0 -20
- package/src/types/invoice.ts +0 -119
- package/src/types/log.ts +0 -10
- package/src/types/portal.ts +0 -9
- package/src/types/reading.ts +0 -17
- package/src/types/report.ts +0 -21
- package/src/types/scraperRun.ts +0 -15
- package/src/types/statusHistory.ts +0 -5
- package/src/types/supplier.ts +0 -31
- package/src/units.ts +0 -111
- package/tsconfig.base.json +0 -31
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.json +0 -9
- package/tsconfig.test.json +0 -13
- package/vitest.config.js +0 -10
- package/vitest.workspace.js +0 -5
package/src/units.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
interface Item {
|
|
2
|
-
units?: string | null;
|
|
3
|
-
unit?: string | null;
|
|
4
|
-
factor?: number | null;
|
|
5
|
-
value: number;
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'oil' | 'other';
|
|
10
|
-
export type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';
|
|
11
|
-
export type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h' | 'l';
|
|
12
|
-
export const accountTypeMap: { [key: string]: BaseUnit } = {
|
|
13
|
-
electricity: 'kwh',
|
|
14
|
-
gas: 'kwh',
|
|
15
|
-
water: 'm3',
|
|
16
|
-
waste: 'kg',
|
|
17
|
-
solar: 'kwh',
|
|
18
|
-
heating: 'kwh',
|
|
19
|
-
flow: 'm3/h',
|
|
20
|
-
cooling: 'kwh',
|
|
21
|
-
temperature: 'C',
|
|
22
|
-
oil: 'l'
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const unitConversionFactors: { [key: string]: any } = {
|
|
26
|
-
kwh: {
|
|
27
|
-
kwh: 1,
|
|
28
|
-
mwh: 1000,
|
|
29
|
-
wh: 0.001,
|
|
30
|
-
m3: (39 * 1.02264) / 3.6,
|
|
31
|
-
ft3: (0.0283 * 39 * 1.02264) / 3.6,
|
|
32
|
-
hcf: (2.83 * 39 * 1.02264) / 3.6
|
|
33
|
-
},
|
|
34
|
-
m3: {
|
|
35
|
-
m3: 1,
|
|
36
|
-
l: 0.001
|
|
37
|
-
},
|
|
38
|
-
C: {
|
|
39
|
-
C: 1
|
|
40
|
-
},
|
|
41
|
-
kg: {
|
|
42
|
-
kg: 1,
|
|
43
|
-
lbs: 0.45359237,
|
|
44
|
-
tonnes: 1000
|
|
45
|
-
},
|
|
46
|
-
'm3/h': {
|
|
47
|
-
'm3/h': 1
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const accountTypeUnitMap: { [key: string]: ETNUnit[] } = {
|
|
52
|
-
electricity: ['kwh', 'mwh', 'wh'],
|
|
53
|
-
gas: ['kwh', 'm3', 'ft3', 'hcf'],
|
|
54
|
-
water: ['m3', 'l'],
|
|
55
|
-
waste: ['kg', 'lbs', 'tonnes'],
|
|
56
|
-
solar: ['kwh', 'mwh', 'wh'],
|
|
57
|
-
heating: ['kwh', 'mwh', 'wh'],
|
|
58
|
-
flow: ['m3/h'],
|
|
59
|
-
cooling: ['kwh', 'mwh', 'wh'],
|
|
60
|
-
temperature: ['C'],
|
|
61
|
-
oil: ['l']
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Convert units to base format
|
|
65
|
-
export const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined): any => {
|
|
66
|
-
if (!type) throw new Error('Account type is required');
|
|
67
|
-
|
|
68
|
-
const baseUnit = accountTypeMap[type];
|
|
69
|
-
if (!baseUnit) throw new Error(`Account type ${type} is not supported`);
|
|
70
|
-
|
|
71
|
-
const convertedItems = items.map(item => {
|
|
72
|
-
const factor = item.factor || accountFactor || 1;
|
|
73
|
-
const units = item.units || item.unit || defaultUnits || baseUnit;
|
|
74
|
-
const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
|
|
75
|
-
return { ...item, value: convertedValue, units: baseUnit };
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return convertedItems;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const _getConversionFactor = (fromUnit: string = 'kwh', toUnit: string) => {
|
|
82
|
-
const conversionFactors = unitConversionFactors[toUnit];
|
|
83
|
-
|
|
84
|
-
if (!conversionFactors) {
|
|
85
|
-
throw new Error(`Conversion factor base unit ${toUnit} is not defined`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!conversionFactors[fromUnit]) {
|
|
89
|
-
throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return conversionFactors[fromUnit];
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const checkAccountTypeVsUnits = (type: string, unit: string, additionalLog: number | '' = '') => {
|
|
96
|
-
if (!type) throw new Error('Account type is required');
|
|
97
|
-
if (!unit) throw new Error('Unit is required');
|
|
98
|
-
|
|
99
|
-
const parsedType = type.toLowerCase().trim();
|
|
100
|
-
|
|
101
|
-
const accountTypeUnits = accountTypeUnitMap[parsedType];
|
|
102
|
-
if (!accountTypeUnits) throw new Error(`Account type "${parsedType}" is not supported ${additionalLog}`);
|
|
103
|
-
|
|
104
|
-
const parsedUnit = unit.toLowerCase().trim() as ETNUnit;
|
|
105
|
-
|
|
106
|
-
if (!accountTypeUnits.includes(parsedUnit)) {
|
|
107
|
-
throw new Error(`Account type "${parsedType}" does not support unit "${parsedUnit}" ${additionalLog}`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return { type: parsedType as AccountType, unit: parsedUnit};
|
|
111
|
-
};
|
package/tsconfig.base.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"allowJs": true,
|
|
4
|
-
"allowSyntheticDefaultImports": true,
|
|
5
|
-
"baseUrl": "src",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"inlineSourceMap": false,
|
|
9
|
-
"lib": ["esnext"],
|
|
10
|
-
"listEmittedFiles": false,
|
|
11
|
-
"listFiles": false,
|
|
12
|
-
"moduleResolution": "node",
|
|
13
|
-
"noFallthroughCasesInSwitch": true,
|
|
14
|
-
"pretty": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"rootDir": "src",
|
|
17
|
-
"skipLibCheck": true,
|
|
18
|
-
"strict": true,
|
|
19
|
-
"traceResolution": false,
|
|
20
|
-
"types": ["node"]
|
|
21
|
-
},
|
|
22
|
-
"watchOptions": {
|
|
23
|
-
"watchFile": "useFsEvents",
|
|
24
|
-
"watchDirectory": "useFsEvents",
|
|
25
|
-
"fallbackPolling": "dynamicPriority",
|
|
26
|
-
"synchronousWatchDirectory": true
|
|
27
|
-
},
|
|
28
|
-
"exclude": ["node_modules", "dist"],
|
|
29
|
-
"include": ["src"],
|
|
30
|
-
"compileOnSave": true
|
|
31
|
-
}
|
package/tsconfig.cjs.json
DELETED
package/tsconfig.json
DELETED
package/tsconfig.test.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": ".", // Set rootDir to the root folder for tests and mocks
|
|
6
|
-
"types": ["vitest/globals"],
|
|
7
|
-
"noEmit": true // Prevents emitting files since these are test files
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"__tests__/**/*",
|
|
11
|
-
"__mocks__/**/*"
|
|
12
|
-
]
|
|
13
|
-
}
|
package/vitest.config.js
DELETED