@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
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- export interface StatusHistory {
2
- date: Date;
3
- value: 'active' | 'inactive';
4
- notes?: string;
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,28 +0,0 @@
1
- import { Portal } from './portal.js';
2
- interface PortalSupplierSchema extends Portal {
3
- concurrent: boolean;
4
- checkInvoiceFilenames: boolean;
5
- supplierRefRequired: boolean;
6
- }
7
- interface InvoiceOptionsSchema {
8
- stampPositionX?: number;
9
- stampPositionY?: number;
10
- }
11
- export interface Supplier {
12
- _id: string;
13
- name: string;
14
- logoUrl?: string;
15
- websiteUrl?: string;
16
- portalUrl?: string;
17
- identifier?: string;
18
- type: 'supplier' | 'distributor';
19
- region?: string;
20
- countryCode: string;
21
- defaultScraper?: string;
22
- active: boolean;
23
- transferSupplier: boolean;
24
- transferSupplierId?: string;
25
- portal: PortalSupplierSchema;
26
- invoiceOptions?: InvoiceOptionsSchema;
27
- }
28
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
@@ -1,22 +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
- export type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'oil' | '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' | 'l';
11
- export declare const accountTypeMap: {
12
- [key: string]: BaseUnit;
13
- };
14
- export declare const accountTypeUnitMap: {
15
- [key: string]: ETNUnit[];
16
- };
17
- export declare const convertItems: (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined) => any;
18
- export declare const checkAccountTypeVsUnits: (type: string, unit: string, additionalLog?: number | "") => {
19
- type: AccountType;
20
- unit: ETNUnit;
21
- };
22
- export {};
package/dist/cjs/units.js DELETED
@@ -1,94 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkAccountTypeVsUnits = exports.convertItems = exports.accountTypeUnitMap = exports.accountTypeMap = void 0;
4
- exports.accountTypeMap = {
5
- electricity: 'kwh',
6
- gas: 'kwh',
7
- water: 'm3',
8
- waste: 'kg',
9
- solar: 'kwh',
10
- heating: 'kwh',
11
- flow: 'm3/h',
12
- cooling: 'kwh',
13
- temperature: 'C',
14
- oil: 'l'
15
- };
16
- const unitConversionFactors = {
17
- kwh: {
18
- kwh: 1,
19
- mwh: 1000,
20
- wh: 0.001,
21
- m3: (39 * 1.02264) / 3.6,
22
- ft3: (0.0283 * 39 * 1.02264) / 3.6,
23
- hcf: (2.83 * 39 * 1.02264) / 3.6
24
- },
25
- m3: {
26
- m3: 1,
27
- l: 0.001
28
- },
29
- C: {
30
- C: 1
31
- },
32
- kg: {
33
- kg: 1,
34
- lbs: 0.45359237,
35
- tonnes: 1000
36
- },
37
- 'm3/h': {
38
- 'm3/h': 1
39
- }
40
- };
41
- exports.accountTypeUnitMap = {
42
- electricity: ['kwh', 'mwh', 'wh'],
43
- gas: ['kwh', 'm3', 'ft3', 'hcf'],
44
- water: ['m3', 'l'],
45
- waste: ['kg', 'lbs', 'tonnes'],
46
- solar: ['kwh', 'mwh', 'wh'],
47
- heating: ['kwh', 'mwh', 'wh'],
48
- flow: ['m3/h'],
49
- cooling: ['kwh', 'mwh', 'wh'],
50
- temperature: ['C'],
51
- oil: ['l']
52
- };
53
- // Convert units to base format
54
- const convertItems = (items, type, defaultUnits, accountFactor) => {
55
- if (!type)
56
- throw new Error('Account type is required');
57
- const baseUnit = exports.accountTypeMap[type];
58
- if (!baseUnit)
59
- throw new Error(`Account type ${type} is not supported`);
60
- const convertedItems = items.map(item => {
61
- const factor = item.factor || accountFactor || 1;
62
- const units = item.units || item.unit || defaultUnits || baseUnit;
63
- const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
64
- return Object.assign(Object.assign({}, item), { value: convertedValue, units: baseUnit });
65
- });
66
- return convertedItems;
67
- };
68
- exports.convertItems = convertItems;
69
- const _getConversionFactor = (fromUnit = 'kwh', toUnit) => {
70
- const conversionFactors = unitConversionFactors[toUnit];
71
- if (!conversionFactors) {
72
- throw new Error(`Conversion factor base unit ${toUnit} is not defined`);
73
- }
74
- if (!conversionFactors[fromUnit]) {
75
- throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);
76
- }
77
- return conversionFactors[fromUnit];
78
- };
79
- const checkAccountTypeVsUnits = (type, unit, additionalLog = '') => {
80
- if (!type)
81
- throw new Error('Account type is required');
82
- if (!unit)
83
- throw new Error('Unit is required');
84
- const parsedType = type.toLowerCase().trim();
85
- const accountTypeUnits = exports.accountTypeUnitMap[parsedType];
86
- if (!accountTypeUnits)
87
- throw new Error(`Account type "${parsedType}" is not supported ${additionalLog}`);
88
- const parsedUnit = unit.toLowerCase().trim();
89
- if (!accountTypeUnits.includes(parsedUnit)) {
90
- throw new Error(`Account type "${parsedType}" does not support unit "${parsedUnit}" ${additionalLog}`);
91
- }
92
- return { type: parsedType, unit: parsedUnit };
93
- };
94
- exports.checkAccountTypeVsUnits = checkAccountTypeVsUnits;
package/dist/mjs/api.d.ts DELETED
@@ -1,111 +0,0 @@
1
- import type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
2
- import type { Account, Asset, Automation, Entity, Company, DataIngest, Invoice, Log, Reading, Report, Supplier } from './types/index.js';
3
- export interface ETNPagedResponse<T = any> {
4
- data: T[];
5
- total: number;
6
- limit: number;
7
- skip: number;
8
- }
9
- export interface ETNReq {
10
- method: string;
11
- url: string;
12
- }
13
- interface AuthOptions {
14
- key?: string;
15
- token?: string;
16
- }
17
- declare const _default: (auth: AuthOptions, instanceOptions?: CreateAxiosDefaults) => {
18
- instance: AxiosInstance;
19
- getAccount: (id: string, options?: AxiosRequestConfig) => Promise<Account>;
20
- listAccounts: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Account>>;
21
- updateAccount: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
22
- createAccount: (data: any, options?: AxiosRequestConfig) => Promise<any>;
23
- removeAccount: (id: string, options?: AxiosRequestConfig) => Promise<any>;
24
- getAccountSchema: (options?: AxiosRequestConfig) => Promise<any>;
25
- invalidateAccountCache: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
26
- getAsset: (id: string, options?: AxiosRequestConfig) => Promise<Asset>;
27
- listAssets: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Asset>>;
28
- updateAsset: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
29
- createAsset: (data: any, options?: AxiosRequestConfig) => Promise<any>;
30
- removeAsset: (id: string, options?: AxiosRequestConfig) => Promise<any>;
31
- getAssetSchema: (options?: AxiosRequestConfig) => Promise<any>;
32
- getAssetGroup: (id: string, options?: AxiosRequestConfig) => Promise<any>;
33
- listAssetGroups: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<any>>;
34
- updateAssetGroup: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
35
- createAssetGroup: (data: any, options?: AxiosRequestConfig) => Promise<any>;
36
- removeAssetGroup: (id: string, options?: AxiosRequestConfig) => Promise<any>;
37
- getAssetGroupAssets: (id: string, options?: AxiosRequestConfig) => Promise<any>;
38
- getAssetGroupSchema: (options?: AxiosRequestConfig) => Promise<any>;
39
- getAutomation: (id: string, options?: AxiosRequestConfig) => Promise<Automation>;
40
- listAutomations: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Automation>>;
41
- updateAutomation: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
42
- createAutomation: (data: any, options?: AxiosRequestConfig) => Promise<any>;
43
- removeAutomation: (id: string, options?: AxiosRequestConfig) => Promise<any>;
44
- createAutomationLog: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
45
- updateAutomationLog: (id: string, subId: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
46
- removeAutomationLog: (id: string, subId: string, options?: AxiosRequestConfig) => Promise<any>;
47
- getCompany: (id: string, options?: AxiosRequestConfig) => Promise<Company>;
48
- getConsumption: (id: string, options?: AxiosRequestConfig) => Promise<any>;
49
- listConsumptions: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<any>>;
50
- updateConsumption: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
51
- createConsumption: (data: any, options?: AxiosRequestConfig) => Promise<any>;
52
- removeConsumption: (id: string, options?: AxiosRequestConfig) => Promise<any>;
53
- getConsumptionSchema: (options?: AxiosRequestConfig) => Promise<any>;
54
- getEmail: (id: string, options?: AxiosRequestConfig) => Promise<any>;
55
- listEmails: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<any>>;
56
- updateEmail: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
57
- createEmail: (data: any, options?: AxiosRequestConfig) => Promise<any>;
58
- removeEmail: (id: string, options?: AxiosRequestConfig) => Promise<any>;
59
- getEmissionFactor: (id: string, options?: AxiosRequestConfig) => Promise<any>;
60
- listEmissionFactors: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<any>>;
61
- updateEmissionFactor: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
62
- createEmissionFactor: (data: any, options?: AxiosRequestConfig) => Promise<any>;
63
- removeEmissionFactor: (id: string, options?: AxiosRequestConfig) => Promise<any>;
64
- getEntity: (id: string, options?: AxiosRequestConfig) => Promise<Entity>;
65
- listEntities: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Entity>>;
66
- updateEntity: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
67
- createEntity: (data: any, options?: AxiosRequestConfig) => Promise<any>;
68
- removeEntity: (id: string, options?: AxiosRequestConfig) => Promise<any>;
69
- getEntitiesSchema: (options?: AxiosRequestConfig) => Promise<any>;
70
- getLog: (id: string, options?: AxiosRequestConfig) => Promise<Log>;
71
- listLogs: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Log>>;
72
- updateLog: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
73
- createLog: (data: any, options?: AxiosRequestConfig) => Promise<any>;
74
- removeLog: (id: string, options?: AxiosRequestConfig) => Promise<any>;
75
- getReading: (id: string, options?: AxiosRequestConfig) => Promise<Reading>;
76
- listReadings: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Reading>>;
77
- updateReading: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
78
- createReading: (data: any, options?: AxiosRequestConfig) => Promise<any>;
79
- removeReading: (id: string, options?: AxiosRequestConfig) => Promise<any>;
80
- getReadingSchema: (options?: AxiosRequestConfig) => Promise<any>;
81
- getReport: (id: string, options?: AxiosRequestConfig) => Promise<Report>;
82
- listReports: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Report>>;
83
- updateReport: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
84
- createReport: (data: any, options?: AxiosRequestConfig) => Promise<any>;
85
- removeReport: (id: string, options?: AxiosRequestConfig) => Promise<any>;
86
- sendReport: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
87
- getReportTemplate: (id: string, options?: AxiosRequestConfig) => Promise<any>;
88
- listReportTemplates: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<any>>;
89
- updateReportTemplate: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
90
- createReportTemplate: (data: any, options?: AxiosRequestConfig) => Promise<any>;
91
- removeReportTemplate: (id: string, options?: AxiosRequestConfig) => Promise<any>;
92
- getScheduledReport: (id: string, options?: AxiosRequestConfig) => Promise<any>;
93
- listScheduledReports: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<any>>;
94
- updateScheduledReport: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
95
- createScheduledReport: (data: any, options?: AxiosRequestConfig) => Promise<any>;
96
- removeScheduledReport: (id: string, options?: AxiosRequestConfig) => Promise<any>;
97
- sendScheduledReport: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
98
- getInvoice: (id: string, options?: AxiosRequestConfig) => Promise<Invoice>;
99
- listInvoices: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Invoice>>;
100
- updateInvoice: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
101
- createInvoice: (data: any, options?: AxiosRequestConfig) => Promise<any>;
102
- removeInvoice: (id: string, options?: AxiosRequestConfig) => Promise<any>;
103
- getInvoiceSchema: (options?: AxiosRequestConfig) => Promise<any>;
104
- listSuppliers: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<Supplier>>;
105
- getSupplierSchema: (options?: AxiosRequestConfig) => Promise<any>;
106
- getImportTemplate: (id: string, options?: AxiosRequestConfig) => Promise<any>;
107
- updateDataIngest: (id: string, data: any, options?: AxiosRequestConfig) => Promise<any>;
108
- createDataIngest: (data: any, options?: AxiosRequestConfig) => Promise<any>;
109
- listDataIngest: (options?: AxiosRequestConfig) => Promise<ETNPagedResponse<DataIngest>>;
110
- };
111
- export default _default;
package/dist/mjs/api.js DELETED
@@ -1,308 +0,0 @@
1
- import axios from 'axios';
2
- import https from 'https';
3
- import logger from './logger.js';
4
- const log = logger('etainablApi');
5
- function _handleResponse(req, res, isPaged = false) {
6
- if (!res) {
7
- throw new Error(`No response from API (${req.method} ${req.url})`);
8
- }
9
- if (res.status !== 200) {
10
- throw new Error(`${res.status} ${res.statusText} response from API (${req.method} ${req.url})`);
11
- }
12
- if (!res.data) {
13
- throw new Error(`No data from API (${req.method} ${req.url})`);
14
- }
15
- if (isPaged && !res.data.data) {
16
- throw new Error(`No data from API (${req.method} ${req.url})`);
17
- }
18
- return res;
19
- }
20
- const factory = {
21
- getWithId: (etainablApi, endpoint, postEndpoint) => async (id, options = {}) => {
22
- const req = {
23
- method: 'GET',
24
- url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`
25
- };
26
- log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);
27
- let res;
28
- try {
29
- res = await etainablApi.get(req.url, options);
30
- }
31
- catch (e) {
32
- if (e.response?.data)
33
- throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
34
- throw e;
35
- }
36
- console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
37
- _handleResponse(req, res);
38
- return res.data;
39
- },
40
- get: (etainablApi, endpoint, postEndpoint) => async (options = {}) => {
41
- const req = {
42
- method: 'GET',
43
- url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`
44
- };
45
- log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
46
- let res;
47
- try {
48
- res = await etainablApi.get(req.url, options);
49
- }
50
- catch (e) {
51
- if (e.response?.data)
52
- throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
53
- throw e;
54
- }
55
- console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
56
- _handleResponse(req, res);
57
- return res.data;
58
- },
59
- list: (etainablApi, endpoint, postEndpoint) => async (options = {}) => {
60
- const req = {
61
- method: 'GET',
62
- url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`
63
- };
64
- log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
65
- let res;
66
- try {
67
- res = await etainablApi.get(req.url, options);
68
- }
69
- catch (e) {
70
- if (e.response?.data)
71
- throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
72
- throw e;
73
- }
74
- console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
75
- _handleResponse(req, res, true);
76
- return res.data;
77
- },
78
- update: (etainablApi, endpoint, postEndpoint) => async (id, data, options = {}) => {
79
- const req = {
80
- method: 'PATCH',
81
- url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`
82
- };
83
- log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
84
- let res;
85
- try {
86
- res = await etainablApi.patch(req.url, data, options);
87
- }
88
- catch (e) {
89
- if (e.response?.data)
90
- throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
91
- throw e;
92
- }
93
- _handleResponse(req, res);
94
- return res.data;
95
- },
96
- create: (etainablApi, endpoint, postEndpoint) => async (data, options = {}) => {
97
- const req = {
98
- method: 'POST',
99
- url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`
100
- };
101
- log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
102
- let res;
103
- try {
104
- res = await etainablApi.post(req.url, data, options);
105
- }
106
- catch (e) {
107
- if (e.response?.data)
108
- throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
109
- throw e;
110
- }
111
- _handleResponse(req, res);
112
- return res.data;
113
- },
114
- remove: (etainablApi, endpoint, postEndpoint) => async (id, options = {}) => {
115
- const req = {
116
- method: 'DELETE',
117
- url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`
118
- };
119
- let res;
120
- log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
121
- try {
122
- res = await etainablApi.delete(req.url, options);
123
- }
124
- catch (e) {
125
- if (e.response?.data)
126
- throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
127
- throw e;
128
- }
129
- _handleResponse(req, res);
130
- return res.data;
131
- },
132
- customWithId: (etainablApi, method, endpoint, postEndpoint) => async (id, data, options = {}) => {
133
- const req = {
134
- method: method,
135
- url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`,
136
- data,
137
- ...options
138
- };
139
- log.info(`API Request (Custom): ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
140
- let res;
141
- try {
142
- res = await etainablApi.request(req);
143
- }
144
- catch (e) {
145
- if (e.response?.data)
146
- throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
147
- throw e;
148
- }
149
- _handleResponse(req, res);
150
- return res.data;
151
- }
152
- };
153
- // ETN Sub Endpoints
154
- // e.g. /assets/:id/documents/:documentId
155
- const subFactory = {
156
- // e.g. POST /assets/:id/documents
157
- create: (etainablApi, endpoint, subEndpoint) => async (id, data, options = {}) => {
158
- const subUrl = `${id}/${subEndpoint}`;
159
- return factory.create(etainablApi, endpoint, subUrl)(data, options);
160
- },
161
- // e.g. PATCH /assets/:id/documents/:documentId
162
- update: (etainablApi, endpoint, subEndpoint) => async (id, subId, data, options = {}) => {
163
- const subUrl = `${subEndpoint}/${subId}`;
164
- return factory.update(etainablApi, endpoint, subUrl)(id, data, options);
165
- },
166
- // e.g. DELETE /assets/:id/documents/:documentId
167
- remove: (etainablApi, endpoint, subEndpoint) => async (id, subId, options = {}) => {
168
- const subUrl = `${subEndpoint}/${subId}`;
169
- return factory.remove(etainablApi, endpoint, subUrl)(id, options);
170
- }
171
- };
172
- export default (auth, instanceOptions = {}) => {
173
- try {
174
- const headers = {};
175
- if (auth.key) {
176
- headers['x-key'] = auth.key;
177
- }
178
- else if (auth.token) {
179
- headers['Authorization'] = auth.token;
180
- }
181
- else {
182
- headers['x-key'] = process.env.ETAINABL_API_KEY;
183
- }
184
- const etainablApi = axios.create({
185
- baseURL: process.env.ETAINABL_API_URL,
186
- timeout: 300000,
187
- httpsAgent: new https.Agent({ keepAlive: true }),
188
- headers,
189
- ...instanceOptions
190
- });
191
- return {
192
- instance: etainablApi,
193
- // accounts
194
- getAccount: factory.getWithId(etainablApi, 'accounts'),
195
- listAccounts: factory.list(etainablApi, 'accounts'),
196
- updateAccount: factory.update(etainablApi, 'accounts'),
197
- createAccount: factory.create(etainablApi, 'accounts'),
198
- removeAccount: factory.remove(etainablApi, 'accounts'),
199
- getAccountSchema: factory.get(etainablApi, 'accounts', 'schema'),
200
- invalidateAccountCache: factory.customWithId(etainablApi, 'put', 'accounts', 'invalidate-cache'),
201
- // assets
202
- getAsset: factory.getWithId(etainablApi, 'assets'),
203
- listAssets: factory.list(etainablApi, 'assets'),
204
- updateAsset: factory.update(etainablApi, 'assets'),
205
- createAsset: factory.create(etainablApi, 'assets'),
206
- removeAsset: factory.remove(etainablApi, 'assets'),
207
- getAssetSchema: factory.get(etainablApi, 'assets', 'schema'),
208
- // assetGroups
209
- getAssetGroup: factory.getWithId(etainablApi, 'asset-groups'),
210
- listAssetGroups: factory.list(etainablApi, 'asset-groups'),
211
- updateAssetGroup: factory.update(etainablApi, 'asset-groups'),
212
- createAssetGroup: factory.create(etainablApi, 'asset-groups'),
213
- removeAssetGroup: factory.remove(etainablApi, 'asset-groups'),
214
- getAssetGroupAssets: factory.getWithId(etainablApi, 'asset-groups', 'assets'),
215
- getAssetGroupSchema: factory.get(etainablApi, 'asset-groups', 'schema'),
216
- // automation
217
- getAutomation: factory.getWithId(etainablApi, 'automation'),
218
- listAutomations: factory.list(etainablApi, 'automation'),
219
- updateAutomation: factory.update(etainablApi, 'automation'),
220
- createAutomation: factory.create(etainablApi, 'automation'),
221
- removeAutomation: factory.remove(etainablApi, 'automation'),
222
- createAutomationLog: subFactory.create(etainablApi, 'automation', 'logs'),
223
- updateAutomationLog: subFactory.update(etainablApi, 'automation', 'logs'),
224
- removeAutomationLog: subFactory.remove(etainablApi, 'automation', 'logs'),
225
- // company
226
- getCompany: factory.getWithId(etainablApi, 'companies'),
227
- // consumption
228
- getConsumption: factory.getWithId(etainablApi, 'consumptions'),
229
- listConsumptions: factory.list(etainablApi, 'consumptions'),
230
- updateConsumption: factory.update(etainablApi, 'consumptions'),
231
- createConsumption: factory.create(etainablApi, 'consumptions'),
232
- removeConsumption: factory.remove(etainablApi, 'consumptions'),
233
- getConsumptionSchema: factory.get(etainablApi, 'consumptions', 'schema'),
234
- // emails
235
- getEmail: factory.getWithId(etainablApi, 'emails'),
236
- listEmails: factory.list(etainablApi, 'emails'),
237
- updateEmail: factory.update(etainablApi, 'emails'),
238
- createEmail: factory.create(etainablApi, 'emails'),
239
- removeEmail: factory.remove(etainablApi, 'emails'),
240
- // emission factors
241
- getEmissionFactor: factory.getWithId(etainablApi, 'emission-factors'),
242
- listEmissionFactors: factory.list(etainablApi, 'emission-factors'),
243
- updateEmissionFactor: factory.update(etainablApi, 'emission-factors'),
244
- createEmissionFactor: factory.create(etainablApi, 'emission-factors'),
245
- removeEmissionFactor: factory.remove(etainablApi, 'emission-factors'),
246
- // entity
247
- getEntity: factory.getWithId(etainablApi, 'entities'),
248
- listEntities: factory.list(etainablApi, 'entities'),
249
- updateEntity: factory.update(etainablApi, 'entities'),
250
- createEntity: factory.create(etainablApi, 'entities'),
251
- removeEntity: factory.remove(etainablApi, 'entities'),
252
- getEntitiesSchema: factory.get(etainablApi, 'entities', 'schema'),
253
- // logs
254
- getLog: factory.getWithId(etainablApi, 'logs'),
255
- listLogs: factory.list(etainablApi, 'logs'),
256
- updateLog: factory.update(etainablApi, 'logs'),
257
- createLog: factory.create(etainablApi, 'logs'),
258
- removeLog: factory.remove(etainablApi, 'logs'),
259
- // readings
260
- getReading: factory.getWithId(etainablApi, 'readings'),
261
- listReadings: factory.list(etainablApi, 'readings'),
262
- updateReading: factory.update(etainablApi, 'readings'),
263
- createReading: factory.create(etainablApi, 'readings'),
264
- removeReading: factory.remove(etainablApi, 'readings'),
265
- getReadingSchema: factory.get(etainablApi, 'readings', 'schema'),
266
- // reports
267
- getReport: factory.getWithId(etainablApi, 'reports'),
268
- listReports: factory.list(etainablApi, 'reports'),
269
- updateReport: factory.update(etainablApi, 'reports'),
270
- createReport: factory.create(etainablApi, 'reports'),
271
- removeReport: factory.remove(etainablApi, 'reports'),
272
- sendReport: factory.customWithId(etainablApi, 'post', 'reports', 'send'),
273
- // report templates
274
- getReportTemplate: factory.getWithId(etainablApi, 'report-templates'),
275
- listReportTemplates: factory.list(etainablApi, 'report-templates'),
276
- updateReportTemplate: factory.update(etainablApi, 'report-templates'),
277
- createReportTemplate: factory.create(etainablApi, 'report-templates'),
278
- removeReportTemplate: factory.remove(etainablApi, 'report-templates'),
279
- // scheduled reports
280
- getScheduledReport: factory.getWithId(etainablApi, 'scheduled-reports'),
281
- listScheduledReports: factory.list(etainablApi, 'scheduled-reports'),
282
- updateScheduledReport: factory.update(etainablApi, 'scheduled-reports'),
283
- createScheduledReport: factory.create(etainablApi, 'scheduled-reports'),
284
- removeScheduledReport: factory.remove(etainablApi, 'scheduled-reports'),
285
- sendScheduledReport: factory.customWithId(etainablApi, 'post', 'scheduled-reports', 'send'),
286
- // invoices
287
- getInvoice: factory.getWithId(etainablApi, 'invoices'),
288
- listInvoices: factory.list(etainablApi, 'invoices'),
289
- updateInvoice: factory.update(etainablApi, 'invoices'),
290
- createInvoice: factory.create(etainablApi, 'invoices'),
291
- removeInvoice: factory.remove(etainablApi, 'invoices'),
292
- getInvoiceSchema: factory.get(etainablApi, 'invoices', 'schema'),
293
- //suppliers
294
- listSuppliers: factory.list(etainablApi, 'suppliers'),
295
- getSupplierSchema: factory.get(etainablApi, 'suppliers', 'schema'),
296
- // import templates
297
- getImportTemplate: factory.getWithId(etainablApi, 'import-templates'),
298
- //data imports
299
- updateDataIngest: factory.update(etainablApi, 'data-ingests'),
300
- createDataIngest: factory.create(etainablApi, 'data-ingests'),
301
- listDataIngest: factory.list(etainablApi, 'data-ingests'),
302
- };
303
- }
304
- catch (e) {
305
- log.error(e);
306
- throw e;
307
- }
308
- };
@@ -1,14 +0,0 @@
1
- import moment from 'moment';
2
- interface ConsumptionData {
3
- date: Date;
4
- consumption: number;
5
- }
6
- export declare const dayNightConsumption: (data: ConsumptionData[]) => {
7
- dayConsumption: number;
8
- nightConsumption: number;
9
- consumption: number;
10
- };
11
- export declare const calcMaxConsumptionValue: (data: ConsumptionData[]) => number;
12
- export declare const calcMaxDemand: (data: ConsumptionData[]) => number;
13
- export declare const calcPeakLoad: (consumption: number, maxDemand: number, startDate: string | moment.Moment, endDate: string | moment.Moment) => number;
14
- export {};
@@ -1,22 +0,0 @@
1
- import moment from 'moment';
2
- export const dayNightConsumption = (data) => data.reduce((acc, item) => {
3
- const hour = moment.utc(item.date).hour(); // End Time of HH consumption period
4
- if (hour >= 0 && hour < 7) {
5
- acc.nightConsumption += item.consumption;
6
- }
7
- else {
8
- acc.dayConsumption += item.consumption;
9
- }
10
- acc.consumption += item.consumption;
11
- return acc;
12
- }, {
13
- dayConsumption: 0,
14
- nightConsumption: 0,
15
- consumption: 0
16
- });
17
- export const calcMaxConsumptionValue = (data) => Math.max(...data.map((item) => item.consumption));
18
- export const calcMaxDemand = (data) => calcMaxConsumptionValue(data) * 2;
19
- export const calcPeakLoad = (consumption, maxDemand, startDate, endDate) => {
20
- const days = Math.ceil(moment(endDate).diff(moment(startDate), 'days', true));
21
- return maxDemand === 0 ? 0 : ((consumption / (maxDemand * 24 * days)) * 100);
22
- };
package/dist/mjs/db.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { Db } from 'mongodb';
2
- declare function connectToDatabase(retryAttempt?: number): Promise<Db>;
3
- declare const _default: {
4
- connectToDatabase: typeof connectToDatabase;
5
- };
6
- export default _default;