@etainabl/nodejs-sdk 1.2.44 → 1.2.45

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 (155) hide show
  1. package/dist/cjs/package.json +2 -2
  2. package/dist/esm/package.json +3 -0
  3. package/dist/index.d.cts +782 -0
  4. package/dist/index.d.ts +782 -0
  5. package/dist/index.js +626 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +588 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +28 -31
  10. package/.prettierrc +0 -11
  11. package/__tests__/reporting.test.ts +0 -88
  12. package/dist/cjs/api.d.ts +0 -111
  13. package/dist/cjs/api.js +0 -318
  14. package/dist/cjs/consumption.d.ts +0 -14
  15. package/dist/cjs/consumption.js +0 -32
  16. package/dist/cjs/db.d.ts +0 -6
  17. package/dist/cjs/db.js +0 -69
  18. package/dist/cjs/etainabl.d.ts +0 -10
  19. package/dist/cjs/etainabl.js +0 -2
  20. package/dist/cjs/index.d.ts +0 -10
  21. package/dist/cjs/index.js +0 -59
  22. package/dist/cjs/logger.d.ts +0 -3
  23. package/dist/cjs/logger.js +0 -14
  24. package/dist/cjs/monitoring.d.ts +0 -1
  25. package/dist/cjs/monitoring.js +0 -31
  26. package/dist/cjs/reporting.d.ts +0 -2
  27. package/dist/cjs/reporting.js +0 -69
  28. package/dist/cjs/slack.d.ts +0 -4
  29. package/dist/cjs/slack.js +0 -28
  30. package/dist/cjs/types/account.d.ts +0 -112
  31. package/dist/cjs/types/account.js +0 -2
  32. package/dist/cjs/types/address.d.ts +0 -11
  33. package/dist/cjs/types/address.js +0 -2
  34. package/dist/cjs/types/asset.d.ts +0 -122
  35. package/dist/cjs/types/asset.js +0 -3
  36. package/dist/cjs/types/automation.d.ts +0 -33
  37. package/dist/cjs/types/automation.js +0 -2
  38. package/dist/cjs/types/company.d.ts +0 -42
  39. package/dist/cjs/types/company.js +0 -2
  40. package/dist/cjs/types/dataIngest.d.ts +0 -8
  41. package/dist/cjs/types/dataIngest.js +0 -2
  42. package/dist/cjs/types/email.d.ts +0 -18
  43. package/dist/cjs/types/email.js +0 -2
  44. package/dist/cjs/types/entity.d.ts +0 -16
  45. package/dist/cjs/types/entity.js +0 -2
  46. package/dist/cjs/types/index.d.ts +0 -19
  47. package/dist/cjs/types/index.js +0 -2
  48. package/dist/cjs/types/invoice.d.ts +0 -118
  49. package/dist/cjs/types/invoice.js +0 -2
  50. package/dist/cjs/types/log.d.ts +0 -10
  51. package/dist/cjs/types/log.js +0 -2
  52. package/dist/cjs/types/portal.d.ts +0 -8
  53. package/dist/cjs/types/portal.js +0 -2
  54. package/dist/cjs/types/reading.d.ts +0 -17
  55. package/dist/cjs/types/reading.js +0 -2
  56. package/dist/cjs/types/report.d.ts +0 -21
  57. package/dist/cjs/types/report.js +0 -2
  58. package/dist/cjs/types/scraperRun.d.ts +0 -15
  59. package/dist/cjs/types/scraperRun.js +0 -2
  60. package/dist/cjs/types/statusHistory.d.ts +0 -5
  61. package/dist/cjs/types/statusHistory.js +0 -2
  62. package/dist/cjs/types/supplier.d.ts +0 -28
  63. package/dist/cjs/types/supplier.js +0 -3
  64. package/dist/cjs/units.d.ts +0 -22
  65. package/dist/cjs/units.js +0 -94
  66. package/dist/mjs/api.d.ts +0 -111
  67. package/dist/mjs/api.js +0 -308
  68. package/dist/mjs/consumption.d.ts +0 -14
  69. package/dist/mjs/consumption.js +0 -22
  70. package/dist/mjs/db.d.ts +0 -6
  71. package/dist/mjs/db.js +0 -53
  72. package/dist/mjs/etainabl.d.ts +0 -10
  73. package/dist/mjs/etainabl.js +0 -1
  74. package/dist/mjs/index.d.ts +0 -10
  75. package/dist/mjs/index.js +0 -10
  76. package/dist/mjs/logger.d.ts +0 -3
  77. package/dist/mjs/logger.js +0 -9
  78. package/dist/mjs/monitoring.d.ts +0 -1
  79. package/dist/mjs/monitoring.js +0 -15
  80. package/dist/mjs/package.json +0 -3
  81. package/dist/mjs/reporting.d.ts +0 -2
  82. package/dist/mjs/reporting.js +0 -62
  83. package/dist/mjs/slack.d.ts +0 -4
  84. package/dist/mjs/slack.js +0 -14
  85. package/dist/mjs/types/account.d.ts +0 -112
  86. package/dist/mjs/types/account.js +0 -1
  87. package/dist/mjs/types/address.d.ts +0 -11
  88. package/dist/mjs/types/address.js +0 -1
  89. package/dist/mjs/types/asset.d.ts +0 -122
  90. package/dist/mjs/types/asset.js +0 -2
  91. package/dist/mjs/types/automation.d.ts +0 -33
  92. package/dist/mjs/types/automation.js +0 -1
  93. package/dist/mjs/types/company.d.ts +0 -42
  94. package/dist/mjs/types/company.js +0 -1
  95. package/dist/mjs/types/dataIngest.d.ts +0 -8
  96. package/dist/mjs/types/dataIngest.js +0 -1
  97. package/dist/mjs/types/email.d.ts +0 -18
  98. package/dist/mjs/types/email.js +0 -1
  99. package/dist/mjs/types/entity.d.ts +0 -16
  100. package/dist/mjs/types/entity.js +0 -1
  101. package/dist/mjs/types/index.d.ts +0 -19
  102. package/dist/mjs/types/index.js +0 -1
  103. package/dist/mjs/types/invoice.d.ts +0 -118
  104. package/dist/mjs/types/invoice.js +0 -1
  105. package/dist/mjs/types/log.d.ts +0 -10
  106. package/dist/mjs/types/log.js +0 -1
  107. package/dist/mjs/types/portal.d.ts +0 -8
  108. package/dist/mjs/types/portal.js +0 -1
  109. package/dist/mjs/types/reading.d.ts +0 -17
  110. package/dist/mjs/types/reading.js +0 -1
  111. package/dist/mjs/types/report.d.ts +0 -21
  112. package/dist/mjs/types/report.js +0 -1
  113. package/dist/mjs/types/scraperRun.d.ts +0 -15
  114. package/dist/mjs/types/scraperRun.js +0 -1
  115. package/dist/mjs/types/statusHistory.d.ts +0 -5
  116. package/dist/mjs/types/statusHistory.js +0 -1
  117. package/dist/mjs/types/supplier.d.ts +0 -28
  118. package/dist/mjs/types/supplier.js +0 -2
  119. package/dist/mjs/units.d.ts +0 -22
  120. package/dist/mjs/units.js +0 -89
  121. package/eslint.config.js +0 -60
  122. package/fixup.sh +0 -11
  123. package/src/api.ts +0 -382
  124. package/src/consumption.ts +0 -40
  125. package/src/db.ts +0 -69
  126. package/src/etainabl.ts +0 -10
  127. package/src/index.ts +0 -21
  128. package/src/logger.ts +0 -13
  129. package/src/monitoring.ts +0 -18
  130. package/src/reporting.ts +0 -78
  131. package/src/slack.ts +0 -16
  132. package/src/types/account.ts +0 -116
  133. package/src/types/address.ts +0 -12
  134. package/src/types/asset.ts +0 -142
  135. package/src/types/automation.ts +0 -35
  136. package/src/types/company.ts +0 -47
  137. package/src/types/dataIngest.ts +0 -8
  138. package/src/types/email.ts +0 -18
  139. package/src/types/entity.ts +0 -17
  140. package/src/types/index.ts +0 -20
  141. package/src/types/invoice.ts +0 -119
  142. package/src/types/log.ts +0 -10
  143. package/src/types/portal.ts +0 -9
  144. package/src/types/reading.ts +0 -17
  145. package/src/types/report.ts +0 -21
  146. package/src/types/scraperRun.ts +0 -15
  147. package/src/types/statusHistory.ts +0 -5
  148. package/src/types/supplier.ts +0 -31
  149. package/src/units.ts +0 -111
  150. package/tsconfig.base.json +0 -31
  151. package/tsconfig.cjs.json +0 -8
  152. package/tsconfig.json +0 -9
  153. package/tsconfig.test.json +0 -13
  154. package/vitest.config.js +0 -10
  155. 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
- };
@@ -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
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "CommonJS",
5
- "outDir": "./dist/cjs",
6
- "target": "es2015"
7
- }
8
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "target": "es2022",
7
- "outDir": "./dist/mjs"
8
- }
9
- }
@@ -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
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- coverage: {
6
- provider: 'v8'
7
- },
8
- globals: true
9
- }
10
- });
@@ -1,5 +0,0 @@
1
- import { defineWorkspace } from 'vitest/config'
2
-
3
- export default defineWorkspace([
4
- "./vitest.config.js"
5
- ])