@etainabl/nodejs-sdk 1.1.15 → 1.1.16

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/units.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  interface Item {
2
- units: string | null;
3
- unit: string | null;
4
- factor: number | null;
2
+ units?: string | null;
3
+ unit?: string | null;
4
+ factor?: number | null;
5
5
  value: number;
6
6
  [key: string]: any;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etainabl/nodejs-sdk",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "main": "dist/index.js",
5
5
  "author": "Jonathan Lambert <jonathan@etainabl.com>",
6
6
  "type": "module",
package/src/units.ts CHANGED
@@ -6,8 +6,8 @@ interface Item {
6
6
  [key: string]: any;
7
7
  }
8
8
 
9
- export type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature';
10
- export type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'wh' | 'qty' | 'l' | 'C';
9
+ export type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'other';
10
+ export type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C';
11
11
  export type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h';
12
12
  export const accountTypeMap: { [key: string]: BaseUnit } = {
13
13
  electricity: 'kwh',
@@ -60,14 +60,14 @@ const accountTypeUnitMap: { [key: string]: ETNUnit[] } = {
60
60
  };
61
61
 
62
62
  // Convert units to base format
63
- export const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined): any => {
63
+ export const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number = 1): any => {
64
64
  if (!type) throw new Error('Account type is required');
65
65
 
66
66
  const baseUnit = accountTypeMap[type];
67
67
  if (!baseUnit) throw new Error(`Account type ${type} is not supported`);
68
68
 
69
69
  const convertedItems = items.map(item => {
70
- const factor = item.factor || 1;
70
+ const factor = item.factor || accountFactor || 1;
71
71
  const units = item.units || item.unit || defaultUnits || baseUnit;
72
72
  const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
73
73
  return { ...item, value: convertedValue, units: baseUnit };