@etainabl/nodejs-sdk 1.2.33 → 1.2.35

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.
Files changed (49) hide show
  1. package/dist/cjs/index.js +11 -17
  2. package/package.json +3 -2
  3. package/src/api.ts +1 -0
  4. package/src/index.ts +1 -2
  5. package/dist/cjs/api.d.ts +0 -110
  6. package/dist/cjs/api.js +0 -317
  7. package/dist/cjs/consumption.d.ts +0 -14
  8. package/dist/cjs/consumption.js +0 -32
  9. package/dist/cjs/db.d.ts +0 -6
  10. package/dist/cjs/db.js +0 -69
  11. package/dist/cjs/etainabl.d.ts +0 -10
  12. package/dist/cjs/etainabl.js +0 -2
  13. package/dist/cjs/index.d.ts +0 -11
  14. package/dist/cjs/logger.d.ts +0 -3
  15. package/dist/cjs/logger.js +0 -14
  16. package/dist/cjs/monitoring.d.ts +0 -1
  17. package/dist/cjs/monitoring.js +0 -31
  18. package/dist/cjs/package.json +0 -3
  19. package/dist/cjs/reporting.d.ts +0 -2
  20. package/dist/cjs/reporting.js +0 -69
  21. package/dist/cjs/slack.d.ts +0 -4
  22. package/dist/cjs/slack.js +0 -28
  23. package/dist/cjs/types/index.d.ts +0 -20
  24. package/dist/cjs/types/index.js +0 -2
  25. package/dist/cjs/units.d.ts +0 -22
  26. package/dist/cjs/units.js +0 -94
  27. package/dist/mjs/api.d.ts +0 -110
  28. package/dist/mjs/api.js +0 -307
  29. package/dist/mjs/consumption.d.ts +0 -14
  30. package/dist/mjs/consumption.js +0 -22
  31. package/dist/mjs/db.d.ts +0 -6
  32. package/dist/mjs/db.js +0 -53
  33. package/dist/mjs/etainabl.d.ts +0 -10
  34. package/dist/mjs/etainabl.js +0 -1
  35. package/dist/mjs/index.d.ts +0 -11
  36. package/dist/mjs/index.js +0 -9
  37. package/dist/mjs/logger.d.ts +0 -3
  38. package/dist/mjs/logger.js +0 -9
  39. package/dist/mjs/monitoring.d.ts +0 -1
  40. package/dist/mjs/monitoring.js +0 -15
  41. package/dist/mjs/package.json +0 -3
  42. package/dist/mjs/reporting.d.ts +0 -2
  43. package/dist/mjs/reporting.js +0 -62
  44. package/dist/mjs/slack.d.ts +0 -4
  45. package/dist/mjs/slack.js +0 -14
  46. package/dist/mjs/types/index.d.ts +0 -20
  47. package/dist/mjs/types/index.js +0 -1
  48. package/dist/mjs/units.d.ts +0 -22
  49. package/dist/mjs/units.js +0 -89
package/dist/mjs/units.js DELETED
@@ -1,89 +0,0 @@
1
- export const accountTypeMap = {
2
- electricity: 'kwh',
3
- gas: 'kwh',
4
- water: 'm3',
5
- waste: 'kg',
6
- solar: 'kwh',
7
- heating: 'kwh',
8
- flow: 'm3/h',
9
- cooling: 'kwh',
10
- temperature: 'C',
11
- oil: 'l'
12
- };
13
- const unitConversionFactors = {
14
- kwh: {
15
- kwh: 1,
16
- mwh: 1000,
17
- wh: 0.001,
18
- m3: (39 * 1.02264) / 3.6,
19
- ft3: (0.0283 * 39 * 1.02264) / 3.6,
20
- hcf: (2.83 * 39 * 1.02264) / 3.6
21
- },
22
- m3: {
23
- m3: 1,
24
- l: 0.001
25
- },
26
- C: {
27
- C: 1
28
- },
29
- kg: {
30
- kg: 1,
31
- lbs: 0.45359237,
32
- tonnes: 1000
33
- },
34
- 'm3/h': {
35
- 'm3/h': 1
36
- }
37
- };
38
- export const accountTypeUnitMap = {
39
- electricity: ['kwh', 'mwh', 'wh'],
40
- gas: ['kwh', 'm3', 'ft3', 'hcf'],
41
- water: ['m3', 'l'],
42
- waste: ['kg', 'lbs', 'tonnes'],
43
- solar: ['kwh', 'mwh', 'wh'],
44
- heating: ['kwh', 'mwh', 'wh'],
45
- flow: ['m3/h'],
46
- cooling: ['kwh', 'mwh', 'wh'],
47
- temperature: ['C'],
48
- oil: ['l']
49
- };
50
- // Convert units to base format
51
- export const convertItems = (items, type, defaultUnits, accountFactor) => {
52
- if (!type)
53
- throw new Error('Account type is required');
54
- const baseUnit = accountTypeMap[type];
55
- if (!baseUnit)
56
- throw new Error(`Account type ${type} is not supported`);
57
- const convertedItems = items.map(item => {
58
- const factor = item.factor || accountFactor || 1;
59
- const units = item.units || item.unit || defaultUnits || baseUnit;
60
- const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
61
- return { ...item, value: convertedValue, units: baseUnit };
62
- });
63
- return convertedItems;
64
- };
65
- const _getConversionFactor = (fromUnit = 'kwh', toUnit) => {
66
- const conversionFactors = unitConversionFactors[toUnit];
67
- if (!conversionFactors) {
68
- throw new Error(`Conversion factor base unit ${toUnit} is not defined`);
69
- }
70
- if (!conversionFactors[fromUnit]) {
71
- throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);
72
- }
73
- return conversionFactors[fromUnit];
74
- };
75
- export const checkAccountTypeVsUnits = (type, unit, additionalLog = '') => {
76
- if (!type)
77
- throw new Error('Account type is required');
78
- if (!unit)
79
- throw new Error('Unit is required');
80
- const parsedType = type.toLowerCase().trim();
81
- const accountTypeUnits = accountTypeUnitMap[parsedType];
82
- if (!accountTypeUnits)
83
- throw new Error(`Account type "${parsedType}" is not supported ${additionalLog}`);
84
- const parsedUnit = unit.toLowerCase().trim();
85
- if (!accountTypeUnits.includes(parsedUnit)) {
86
- throw new Error(`Account type "${parsedType}" does not support unit "${parsedUnit}" ${additionalLog}`);
87
- }
88
- return { type: parsedType, unit: parsedUnit };
89
- };