@etainabl/nodejs-sdk 1.2.15 → 1.2.17
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/cjs/api.d.ts +99 -0
- package/dist/cjs/api.js +303 -0
- package/dist/cjs/consumption.d.ts +14 -0
- package/dist/cjs/consumption.js +32 -0
- package/dist/cjs/db.d.ts +6 -0
- package/dist/cjs/db.js +49 -0
- package/dist/cjs/etainabl.d.ts +10 -0
- package/dist/cjs/etainabl.js +2 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.js +45 -0
- package/dist/cjs/logger.d.ts +3 -0
- package/dist/cjs/logger.js +14 -0
- package/dist/cjs/monitoring.d.ts +1 -0
- package/dist/cjs/monitoring.js +31 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/reporting.d.ts +2 -0
- package/dist/cjs/reporting.js +69 -0
- package/dist/cjs/slack.d.ts +4 -0
- package/dist/cjs/slack.js +28 -0
- package/dist/cjs/units.d.ts +22 -0
- package/dist/cjs/units.js +92 -0
- package/dist/mjs/api.d.ts +24 -23
- package/dist/mjs/api.js +1 -1
- package/dist/mjs/index.d.ts +2 -0
- package/dist/mjs/package.json +3 -0
- package/package.json +1 -1
- package/src/api.ts +25 -24
- package/src/index.ts +4 -1
- package/types/account.d.ts +116 -0
- package/types/address.d.ts +12 -0
- package/types/asset.d.ts +142 -0
- package/types/automation.d.ts +36 -0
- package/types/company.d.ts +47 -0
- package/types/email.d.ts +17 -0
- package/types/index.d.ts +30 -0
- package/types/invoice.d.ts +106 -0
- package/types/log.d.ts +9 -0
- package/types/portal.d.ts +9 -0
- package/types/reading.d.ts +16 -0
- package/types/scraperRun.d.ts +15 -0
- package/types/statusHistory.d.ts +5 -0
- package/types/supplier.d.ts +31 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getScheduledReportRunTimes = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
moment_1.default.locale('en', {
|
|
9
|
+
week: {
|
|
10
|
+
dow: 1
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const getNextRunTime = (startDate, schedule, taskTime) => {
|
|
14
|
+
const [num, freq] = schedule.frequency.split('|');
|
|
15
|
+
const targetDate = (0, moment_1.default)(startDate).add(num, freq);
|
|
16
|
+
if (schedule.frequencyPeriod === 'first') {
|
|
17
|
+
targetDate.startOf(freq);
|
|
18
|
+
}
|
|
19
|
+
else if (schedule.frequencyPeriod === 'last') {
|
|
20
|
+
targetDate.endOf(freq);
|
|
21
|
+
}
|
|
22
|
+
const isWeekday = targetDate.isoWeekday() > 0 && targetDate.isoWeekday() < 6;
|
|
23
|
+
const isSaturday = targetDate.isoWeekday() === 6;
|
|
24
|
+
// The weekday or weekend chosen should be within the same month as the target date
|
|
25
|
+
if (schedule.frequencyDay === 'weekdays' && !isWeekday) {
|
|
26
|
+
if ((targetDate.date() / 7) < 2) {
|
|
27
|
+
targetDate.add(isSaturday ? 2 : 1, 'days');
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
targetDate.subtract(isSaturday ? 1 : 2, 'days');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (schedule.frequencyDay === 'weekends' && isWeekday) {
|
|
34
|
+
if ((targetDate.date() / 7) < 2) {
|
|
35
|
+
targetDate.isoWeekday(6);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
targetDate.isoWeekday(0);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (taskTime.isAfter(targetDate, 'minute')) {
|
|
42
|
+
return getNextRunTime(targetDate, schedule, taskTime);
|
|
43
|
+
}
|
|
44
|
+
return targetDate;
|
|
45
|
+
};
|
|
46
|
+
const getScheduledReportRunTimes = (schedule, limit = 1, taskTime = (0, moment_1.default)()) => {
|
|
47
|
+
if (!schedule.startDate || !schedule.enabled)
|
|
48
|
+
return [];
|
|
49
|
+
const originalStartDate = moment_1.default.utc(schedule.startDate);
|
|
50
|
+
let startDate = originalStartDate;
|
|
51
|
+
const includeStartDate = taskTime.isSameOrBefore(originalStartDate, 'minute');
|
|
52
|
+
let runTimes = [];
|
|
53
|
+
if (includeStartDate) {
|
|
54
|
+
runTimes = [originalStartDate];
|
|
55
|
+
}
|
|
56
|
+
const [, freq] = schedule.frequency.split('|');
|
|
57
|
+
if (freq === 'once') {
|
|
58
|
+
const nextRunTime = runTimes[0];
|
|
59
|
+
// If this is now beyond the start date, return an empty array
|
|
60
|
+
return taskTime.isAfter(nextRunTime, 'minute') ? [] : runTimes;
|
|
61
|
+
}
|
|
62
|
+
const scheduleRunTimes = Array.from(Array(includeStartDate ? limit - 1 : limit).keys()).map(() => {
|
|
63
|
+
const nextRunTime = getNextRunTime(startDate, schedule, taskTime);
|
|
64
|
+
startDate = nextRunTime.hour(originalStartDate.hour()).minute(originalStartDate.minute());
|
|
65
|
+
return nextRunTime;
|
|
66
|
+
});
|
|
67
|
+
return [...runTimes, ...scheduleRunTimes];
|
|
68
|
+
};
|
|
69
|
+
exports.getScheduledReportRunTimes = getScheduledReportRunTimes;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const postMessage = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const url = 'https://hooks.slack.com/services/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';
|
|
18
|
+
const data = {
|
|
19
|
+
text: `[${(process.env.ENV || '').toUpperCase()}][${process.env.AWS_LAMBDA_FUNCTION_NAME}] ${message}`
|
|
20
|
+
};
|
|
21
|
+
const headers = {
|
|
22
|
+
'Content-Type': 'application/json'
|
|
23
|
+
};
|
|
24
|
+
return axios_1.default.post(url, data, { headers });
|
|
25
|
+
});
|
|
26
|
+
exports.default = {
|
|
27
|
+
postMessage
|
|
28
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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' | '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';
|
|
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 {};
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
};
|
|
15
|
+
const unitConversionFactors = {
|
|
16
|
+
kwh: {
|
|
17
|
+
kwh: 1,
|
|
18
|
+
mwh: 1000,
|
|
19
|
+
wh: 0.001,
|
|
20
|
+
m3: (39 * 1.02264) / 3.6,
|
|
21
|
+
ft3: (0.0283 * 39 * 1.02264) / 3.6,
|
|
22
|
+
hcf: (2.83 * 39 * 1.02264) / 3.6
|
|
23
|
+
},
|
|
24
|
+
m3: {
|
|
25
|
+
m3: 1,
|
|
26
|
+
l: 0.001
|
|
27
|
+
},
|
|
28
|
+
C: {
|
|
29
|
+
C: 1
|
|
30
|
+
},
|
|
31
|
+
kg: {
|
|
32
|
+
kg: 1,
|
|
33
|
+
lbs: 0.45359237,
|
|
34
|
+
tonnes: 1000
|
|
35
|
+
},
|
|
36
|
+
'm3/h': {
|
|
37
|
+
'm3/h': 1
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.accountTypeUnitMap = {
|
|
41
|
+
electricity: ['kwh', 'mwh', 'wh'],
|
|
42
|
+
gas: ['kwh', 'm3', 'ft3', 'hcf'],
|
|
43
|
+
water: ['m3', 'l'],
|
|
44
|
+
waste: ['kg', 'lbs', 'tonnes'],
|
|
45
|
+
solar: ['kwh', 'mwh', 'wh'],
|
|
46
|
+
heating: ['kwh', 'mwh', 'wh'],
|
|
47
|
+
flow: ['m3/h'],
|
|
48
|
+
cooling: ['kwh', 'mwh', 'wh'],
|
|
49
|
+
temperature: ['C']
|
|
50
|
+
};
|
|
51
|
+
// Convert units to base format
|
|
52
|
+
const convertItems = (items, type, defaultUnits, accountFactor) => {
|
|
53
|
+
if (!type)
|
|
54
|
+
throw new Error('Account type is required');
|
|
55
|
+
const baseUnit = exports.accountTypeMap[type];
|
|
56
|
+
if (!baseUnit)
|
|
57
|
+
throw new Error(`Account type ${type} is not supported`);
|
|
58
|
+
const convertedItems = items.map(item => {
|
|
59
|
+
const factor = item.factor || accountFactor || 1;
|
|
60
|
+
const units = item.units || item.unit || defaultUnits || baseUnit;
|
|
61
|
+
const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
|
|
62
|
+
return Object.assign(Object.assign({}, item), { value: convertedValue, units: baseUnit });
|
|
63
|
+
});
|
|
64
|
+
return convertedItems;
|
|
65
|
+
};
|
|
66
|
+
exports.convertItems = convertItems;
|
|
67
|
+
const _getConversionFactor = (fromUnit = 'kwh', toUnit) => {
|
|
68
|
+
const conversionFactors = unitConversionFactors[toUnit];
|
|
69
|
+
if (!conversionFactors) {
|
|
70
|
+
throw new Error(`Conversion factor base unit ${toUnit} is not defined`);
|
|
71
|
+
}
|
|
72
|
+
if (!conversionFactors[fromUnit]) {
|
|
73
|
+
throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);
|
|
74
|
+
}
|
|
75
|
+
return conversionFactors[fromUnit];
|
|
76
|
+
};
|
|
77
|
+
const checkAccountTypeVsUnits = (type, unit, additionalLog = '') => {
|
|
78
|
+
if (!type)
|
|
79
|
+
throw new Error('Account type is required');
|
|
80
|
+
if (!unit)
|
|
81
|
+
throw new Error('Unit is required');
|
|
82
|
+
const parsedType = type.toLowerCase().trim();
|
|
83
|
+
const accountTypeUnits = exports.accountTypeUnitMap[parsedType];
|
|
84
|
+
if (!accountTypeUnits)
|
|
85
|
+
throw new Error(`Account type "${parsedType}" is not supported ${additionalLog}`);
|
|
86
|
+
const parsedUnit = unit.toLowerCase().trim();
|
|
87
|
+
if (!accountTypeUnits.includes(parsedUnit)) {
|
|
88
|
+
throw new Error(`Account type "${parsedType}" does not support unit "${parsedUnit}" ${additionalLog}`);
|
|
89
|
+
}
|
|
90
|
+
return { type: parsedType, unit: parsedUnit };
|
|
91
|
+
};
|
|
92
|
+
exports.checkAccountTypeVsUnits = checkAccountTypeVsUnits;
|
package/dist/mjs/api.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type { Account, Asset, Company, Invoice, Log, Reading, Supplier } from '../types/index.js';
|
|
3
|
+
export interface ETNPagedResponse<T = any> {
|
|
4
|
+
data: T[];
|
|
4
5
|
total: number;
|
|
5
6
|
limit: number;
|
|
6
7
|
skip: number;
|
|
@@ -15,84 +16,84 @@ interface AuthOptions {
|
|
|
15
16
|
}
|
|
16
17
|
declare const _default: (auth: AuthOptions, instanceOptions?: CreateAxiosDefaults) => {
|
|
17
18
|
instance: AxiosInstance;
|
|
18
|
-
getAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<
|
|
19
|
-
listAccounts: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
19
|
+
getAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<Account>;
|
|
20
|
+
listAccounts: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Account>>;
|
|
20
21
|
updateAccount: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
21
22
|
createAccount: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
22
23
|
removeAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
23
24
|
getAccountSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
24
|
-
getAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<
|
|
25
|
-
listAssets: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
25
|
+
getAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<Asset>;
|
|
26
|
+
listAssets: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Asset>>;
|
|
26
27
|
updateAsset: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
27
28
|
createAsset: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
28
29
|
removeAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
29
30
|
getAssetSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
30
31
|
getAssetGroup: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
31
|
-
listAssetGroups: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
32
|
+
listAssetGroups: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
32
33
|
updateAssetGroup: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
33
34
|
createAssetGroup: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
34
35
|
removeAssetGroup: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
35
36
|
getAssetGroupAssets: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
36
37
|
getAssetGroupSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
37
|
-
getAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<
|
|
38
|
-
listAutomations: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
38
|
+
getAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<Automation>;
|
|
39
|
+
listAutomations: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Automation>>;
|
|
39
40
|
updateAutomation: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
40
41
|
createAutomation: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
41
42
|
removeAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
42
43
|
createAutomationLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
43
44
|
updateAutomationLog: (id: string, subId: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
44
45
|
removeAutomationLog: (id: string, subId: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
45
|
-
getCompany: (id: string, options?: AxiosRequestConfig<any>) => Promise<
|
|
46
|
+
getCompany: (id: string, options?: AxiosRequestConfig<any>) => Promise<Company>;
|
|
46
47
|
getConsumption: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
47
|
-
listConsumptions: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
48
|
+
listConsumptions: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
48
49
|
updateConsumption: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
49
50
|
createConsumption: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
50
51
|
removeConsumption: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
51
52
|
getConsumptionSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
52
53
|
getEmail: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
53
|
-
listEmails: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
54
|
+
listEmails: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
54
55
|
updateEmail: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
55
56
|
createEmail: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
56
57
|
removeEmail: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
57
58
|
getEmissionFactor: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
58
|
-
listEmissionFactors: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
59
|
+
listEmissionFactors: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
59
60
|
updateEmissionFactor: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
60
61
|
createEmissionFactor: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
61
62
|
removeEmissionFactor: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
62
|
-
getLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<
|
|
63
|
-
listLogs: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
63
|
+
getLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<Log>;
|
|
64
|
+
listLogs: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Log>>;
|
|
64
65
|
updateLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
65
66
|
createLog: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
66
67
|
removeLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
67
|
-
getReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<
|
|
68
|
-
listReadings: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
68
|
+
getReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<Reading>;
|
|
69
|
+
listReadings: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Reading>>;
|
|
69
70
|
updateReading: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
70
71
|
createReading: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
71
72
|
removeReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
72
73
|
getReadingSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
73
74
|
getReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
74
|
-
listReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
75
|
+
listReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
75
76
|
updateReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
76
77
|
createReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
77
78
|
removeReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
78
79
|
sendReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
79
80
|
getReportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
80
|
-
listReportTemplates: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
81
|
+
listReportTemplates: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
81
82
|
updateReportTemplate: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
82
83
|
createReportTemplate: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
83
84
|
removeReportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
84
85
|
getScheduledReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
85
|
-
listScheduledReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
86
|
+
listScheduledReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
86
87
|
updateScheduledReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
87
88
|
createScheduledReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
88
89
|
removeScheduledReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
89
90
|
sendScheduledReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
90
|
-
getInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<
|
|
91
|
-
listInvoices: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse
|
|
91
|
+
getInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<Invoice>;
|
|
92
|
+
listInvoices: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Invoice>>;
|
|
92
93
|
updateInvoice: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
93
94
|
createInvoice: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
94
95
|
removeInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
95
96
|
getInvoiceSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
96
|
-
getSupplierSchema: (options?: AxiosRequestConfig<any>) => Promise<
|
|
97
|
+
getSupplierSchema: (options?: AxiosRequestConfig<any>) => Promise<Supplier>;
|
|
97
98
|
};
|
|
98
99
|
export default _default;
|
package/dist/mjs/api.js
CHANGED
|
@@ -23,7 +23,7 @@ const factory = {
|
|
|
23
23
|
method: 'GET',
|
|
24
24
|
url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
25
25
|
};
|
|
26
|
-
log.info(`API Request: ${req.method} ${process.env.
|
|
26
|
+
log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);
|
|
27
27
|
let res;
|
|
28
28
|
try {
|
|
29
29
|
res = await etainablApi.get(req.url, options);
|
package/dist/mjs/index.d.ts
CHANGED
|
@@ -6,4 +6,6 @@ import * as units from './units.js';
|
|
|
6
6
|
import * as consumption from './consumption.js';
|
|
7
7
|
import * as monitoring from './monitoring.js';
|
|
8
8
|
import * as reporting from './reporting.js';
|
|
9
|
+
import type { Account, Asset, Automation, Company, Invoice, Log, Reading, Supplier } from '../types/index.d.js';
|
|
9
10
|
export { api, logger, consumption, monitoring, db, slack, units, reporting };
|
|
11
|
+
export type { Account, Asset, Automation, Company, Invoice, Log, Reading, Supplier };
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -4,10 +4,12 @@ import https from 'https';
|
|
|
4
4
|
|
|
5
5
|
import logger from './logger.js';
|
|
6
6
|
|
|
7
|
+
import type { Account, Asset, Automation, Company, Invoice, Log, Reading, Supplier } from '../types/index.js'
|
|
8
|
+
|
|
7
9
|
const log = logger('etainablApi');
|
|
8
10
|
|
|
9
|
-
export interface ETNPagedResponse {
|
|
10
|
-
data:
|
|
11
|
+
export interface ETNPagedResponse<T = any> {
|
|
12
|
+
data: T[];
|
|
11
13
|
total: number;
|
|
12
14
|
limit: number;
|
|
13
15
|
skip: number;
|
|
@@ -39,13 +41,13 @@ function _handleResponse(req: ETNReq, res: AxiosResponse, isPaged = false) {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
const factory = {
|
|
42
|
-
getWithId: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}) => {
|
|
44
|
+
getWithId: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}): Promise<T> => {
|
|
43
45
|
const req = {
|
|
44
46
|
method: 'GET',
|
|
45
47
|
url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
log.info(`API Request: ${req.method} ${process.env.
|
|
50
|
+
log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);
|
|
49
51
|
|
|
50
52
|
let res: AxiosResponse;
|
|
51
53
|
|
|
@@ -62,7 +64,7 @@ const factory = {
|
|
|
62
64
|
|
|
63
65
|
return res.data;
|
|
64
66
|
},
|
|
65
|
-
get: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}) => {
|
|
67
|
+
get: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<T> => {
|
|
66
68
|
const req = {
|
|
67
69
|
method: 'GET',
|
|
68
70
|
url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
@@ -84,7 +86,7 @@ const factory = {
|
|
|
84
86
|
|
|
85
87
|
return res.data;
|
|
86
88
|
},
|
|
87
|
-
list: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<ETNPagedResponse
|
|
89
|
+
list: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<ETNPagedResponse<T>> => {
|
|
88
90
|
const req = {
|
|
89
91
|
method: 'GET',
|
|
90
92
|
url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
@@ -196,7 +198,6 @@ const factory = {
|
|
|
196
198
|
|
|
197
199
|
// ETN Sub Endpoints
|
|
198
200
|
// e.g. /assets/:id/documents/:documentId
|
|
199
|
-
|
|
200
201
|
const subFactory = {
|
|
201
202
|
// e.g. POST /assets/:id/documents
|
|
202
203
|
create: (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => {
|
|
@@ -246,20 +247,20 @@ export default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) =>
|
|
|
246
247
|
instance: etainablApi,
|
|
247
248
|
|
|
248
249
|
// accounts
|
|
249
|
-
getAccount: factory.getWithId(etainablApi, 'accounts'),
|
|
250
|
-
listAccounts: factory.list(etainablApi, 'accounts'),
|
|
250
|
+
getAccount: factory.getWithId<Account>(etainablApi, 'accounts'),
|
|
251
|
+
listAccounts: factory.list<Account>(etainablApi, 'accounts'),
|
|
251
252
|
updateAccount: factory.update(etainablApi, 'accounts'),
|
|
252
253
|
createAccount: factory.create(etainablApi, 'accounts'),
|
|
253
254
|
removeAccount: factory.remove(etainablApi, 'accounts'),
|
|
254
255
|
getAccountSchema: factory.get(etainablApi, 'accounts', 'schema'),
|
|
255
|
-
|
|
256
|
+
|
|
256
257
|
// assets
|
|
257
|
-
getAsset: factory.getWithId(etainablApi, 'assets'),
|
|
258
|
-
listAssets: factory.list(etainablApi, 'assets'),
|
|
258
|
+
getAsset: factory.getWithId<Asset>(etainablApi, 'assets'),
|
|
259
|
+
listAssets: factory.list<Asset>(etainablApi, 'assets'),
|
|
259
260
|
updateAsset: factory.update(etainablApi, 'assets'),
|
|
260
261
|
createAsset: factory.create(etainablApi, 'assets'),
|
|
261
262
|
removeAsset: factory.remove(etainablApi, 'assets'),
|
|
262
|
-
getAssetSchema:
|
|
263
|
+
getAssetSchema: factory.get(etainablApi, 'assets', 'schema'),
|
|
263
264
|
|
|
264
265
|
// assetGroups
|
|
265
266
|
getAssetGroup: factory.getWithId(etainablApi, 'asset-groups'),
|
|
@@ -271,8 +272,8 @@ export default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) =>
|
|
|
271
272
|
getAssetGroupSchema: factory.get(etainablApi, 'asset-groups', 'schema'),
|
|
272
273
|
|
|
273
274
|
// automation
|
|
274
|
-
getAutomation: factory.getWithId(etainablApi, 'automation'),
|
|
275
|
-
listAutomations: factory.list(etainablApi, 'automation'),
|
|
275
|
+
getAutomation: factory.getWithId<Automation>(etainablApi, 'automation'),
|
|
276
|
+
listAutomations: factory.list<Automation>(etainablApi, 'automation'),
|
|
276
277
|
updateAutomation: factory.update(etainablApi, 'automation'),
|
|
277
278
|
createAutomation: factory.create(etainablApi, 'automation'),
|
|
278
279
|
removeAutomation: factory.remove(etainablApi, 'automation'),
|
|
@@ -281,7 +282,7 @@ export default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) =>
|
|
|
281
282
|
removeAutomationLog: subFactory.remove(etainablApi, 'automation', 'logs'),
|
|
282
283
|
|
|
283
284
|
// company
|
|
284
|
-
getCompany: factory.getWithId(etainablApi, 'companies'),
|
|
285
|
+
getCompany: factory.getWithId<Company>(etainablApi, 'companies'),
|
|
285
286
|
|
|
286
287
|
// consumption
|
|
287
288
|
getConsumption: factory.getWithId(etainablApi, 'consumptions'),
|
|
@@ -306,15 +307,15 @@ export default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) =>
|
|
|
306
307
|
removeEmissionFactor: factory.remove(etainablApi, 'emission-factors'),
|
|
307
308
|
|
|
308
309
|
// logs
|
|
309
|
-
getLog: factory.getWithId(etainablApi, 'logs'),
|
|
310
|
-
listLogs: factory.list(etainablApi, 'logs'),
|
|
310
|
+
getLog: factory.getWithId<Log>(etainablApi, 'logs'),
|
|
311
|
+
listLogs: factory.list<Log>(etainablApi, 'logs'),
|
|
311
312
|
updateLog: factory.update(etainablApi, 'logs'),
|
|
312
313
|
createLog: factory.create(etainablApi, 'logs'),
|
|
313
314
|
removeLog: factory.remove(etainablApi, 'logs'),
|
|
314
315
|
|
|
315
316
|
// readings
|
|
316
|
-
getReading: factory.getWithId(etainablApi, 'readings'),
|
|
317
|
-
listReadings: factory.list(etainablApi, 'readings'),
|
|
317
|
+
getReading: factory.getWithId<Reading>(etainablApi, 'readings'),
|
|
318
|
+
listReadings: factory.list<Reading>(etainablApi, 'readings'),
|
|
318
319
|
updateReading: factory.update(etainablApi, 'readings'),
|
|
319
320
|
createReading: factory.create(etainablApi, 'readings'),
|
|
320
321
|
removeReading: factory.remove(etainablApi, 'readings'),
|
|
@@ -344,15 +345,15 @@ export default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) =>
|
|
|
344
345
|
sendScheduledReport: factory.customWithId(etainablApi, 'post', 'scheduled-reports', 'send'),
|
|
345
346
|
|
|
346
347
|
// invoices
|
|
347
|
-
getInvoice: factory.getWithId(etainablApi, 'invoices'),
|
|
348
|
-
listInvoices: factory.list(etainablApi, 'invoices'),
|
|
348
|
+
getInvoice: factory.getWithId<Invoice>(etainablApi, 'invoices'),
|
|
349
|
+
listInvoices: factory.list<Invoice>(etainablApi, 'invoices'),
|
|
349
350
|
updateInvoice: factory.update(etainablApi, 'invoices'),
|
|
350
351
|
createInvoice: factory.create(etainablApi, 'invoices'),
|
|
351
352
|
removeInvoice: factory.remove(etainablApi, 'invoices'),
|
|
352
|
-
getInvoiceSchema:
|
|
353
|
+
getInvoiceSchema: factory.get(etainablApi, 'invoices', 'schema'),
|
|
353
354
|
|
|
354
355
|
//suppliers
|
|
355
|
-
getSupplierSchema: factory.get(etainablApi, 'suppliers', 'schema')
|
|
356
|
+
getSupplierSchema: factory.get<Supplier>(etainablApi, 'suppliers', 'schema')
|
|
356
357
|
|
|
357
358
|
}
|
|
358
359
|
} catch (e) {
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import * as units from './units.js';
|
|
|
6
6
|
import * as consumption from './consumption.js';
|
|
7
7
|
import * as monitoring from './monitoring.js';
|
|
8
8
|
import * as reporting from './reporting.js';
|
|
9
|
+
import type { Account, Asset, Automation, Company, Invoice, Log, Reading, Supplier } from '../types/index.d.js';
|
|
9
10
|
|
|
10
11
|
export {
|
|
11
12
|
api,
|
|
@@ -16,4 +17,6 @@ export {
|
|
|
16
17
|
slack,
|
|
17
18
|
units,
|
|
18
19
|
reporting
|
|
19
|
-
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type { Account, Asset, Automation, Company, Invoice, Log, Reading, Supplier };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Portal } from './portal.ts';
|
|
2
|
+
import type { StatusHistory } from './statusHistory.ts'
|
|
3
|
+
|
|
4
|
+
interface PortalAccountSchema extends Portal{
|
|
5
|
+
invoiceFilenames: any[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface RateSchema {
|
|
9
|
+
type: string;
|
|
10
|
+
value: number;
|
|
11
|
+
description: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ContractSchema {
|
|
15
|
+
startDate: Date;
|
|
16
|
+
endDate: Date;
|
|
17
|
+
terminationDate?: Date;
|
|
18
|
+
paymentTerms?: string;
|
|
19
|
+
duration?: string;
|
|
20
|
+
tariffName?: string;
|
|
21
|
+
contractConsumption?: number;
|
|
22
|
+
volumeTolerance?: any[];
|
|
23
|
+
renewablePercentage?: number;
|
|
24
|
+
marketBasedEmissionFactor?: number;
|
|
25
|
+
chargeableCclPercentage?: number;
|
|
26
|
+
commissionRates?: number;
|
|
27
|
+
rates: any[];
|
|
28
|
+
s3Key?: string;
|
|
29
|
+
rateTypeMapping?: object;
|
|
30
|
+
batchId?: string;
|
|
31
|
+
supplierId?: string;
|
|
32
|
+
status: 'active' | 'inactive';
|
|
33
|
+
userSub?: string;
|
|
34
|
+
deletedOn?: Date;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface CreditNoteSchema {
|
|
38
|
+
name: string;
|
|
39
|
+
type: string;
|
|
40
|
+
amount: number;
|
|
41
|
+
netAmount: number;
|
|
42
|
+
taxAmount: number;
|
|
43
|
+
date: Date;
|
|
44
|
+
isPaid: boolean;
|
|
45
|
+
s3Key: string;
|
|
46
|
+
stampedS3Key: string;
|
|
47
|
+
fileName: string;
|
|
48
|
+
invoiceData: object;
|
|
49
|
+
userSub: string;
|
|
50
|
+
readingIds: any[];
|
|
51
|
+
supplierId: string;
|
|
52
|
+
totalUnits: number;
|
|
53
|
+
endDate: Date;
|
|
54
|
+
startDate: Date;
|
|
55
|
+
stampDate: Date;
|
|
56
|
+
totalWaterVolume: number;
|
|
57
|
+
totalWasteVolume: number;
|
|
58
|
+
totalWaterCost: number;
|
|
59
|
+
totalWasteCost: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface Account {
|
|
63
|
+
_id: string,
|
|
64
|
+
name: string;
|
|
65
|
+
modifiedBy?: string;
|
|
66
|
+
siteCode?: string;
|
|
67
|
+
type: 'gas' | 'electricity' | 'water' | 'waste' | 'solar';
|
|
68
|
+
supplierRef?: string;
|
|
69
|
+
financialCode?: string;
|
|
70
|
+
propertyCode?: string;
|
|
71
|
+
meterPointNumber?: string;
|
|
72
|
+
meterSerialNumber?: string;
|
|
73
|
+
meterPointNumber2?: string;
|
|
74
|
+
meterUnits: 'kwh' | 'm3' | 'ft3';
|
|
75
|
+
automaticMeterRead?: boolean;
|
|
76
|
+
status?: 'active' | 'inactive';
|
|
77
|
+
statusHistory?: StatusHistory[]; // Referenced from another file
|
|
78
|
+
rates?: RateSchema[];
|
|
79
|
+
capacity?: string;
|
|
80
|
+
meterOperator?: string;
|
|
81
|
+
meterLocation?: string;
|
|
82
|
+
meterOperatorType?: 'lease' | 'purchase';
|
|
83
|
+
meterOperatorExpiryDate?: Date;
|
|
84
|
+
dataCollector?: string;
|
|
85
|
+
parentAccountId?: string;
|
|
86
|
+
processingInvoices?: object[];
|
|
87
|
+
contracts?: ContractSchema[];
|
|
88
|
+
creditNotes?: CreditNoteSchema[];
|
|
89
|
+
meterUser?: string;
|
|
90
|
+
isTrc?: boolean;
|
|
91
|
+
floorArea?: string;
|
|
92
|
+
floorAreaUnit?: 'metric' | 'imperial';
|
|
93
|
+
reportingType?: string;
|
|
94
|
+
solarType?: 'generation' | 'export';
|
|
95
|
+
consumptionSource?: 'primary' | 'sub' | 'primary-sub';
|
|
96
|
+
esec?: 'a' | 'b' | 'c' | 'd' | 'e' | 'g' | 'h' | 'j' | 'k' | 'l' | 'm' | 'n' | 'p' | 'q' | 'r' | 's' | 't' | 'u';
|
|
97
|
+
portal?: PortalAccountSchema;
|
|
98
|
+
deviceId?: string;
|
|
99
|
+
gridfetchLoa?: {
|
|
100
|
+
s3Key?: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
uploadedBy?: string;
|
|
103
|
+
uploadedAt?: Date;
|
|
104
|
+
expiryDate?: Date;
|
|
105
|
+
error?: string;
|
|
106
|
+
uploaded?: boolean;
|
|
107
|
+
};
|
|
108
|
+
automationIds?: string[];
|
|
109
|
+
customIntegrations?: object;
|
|
110
|
+
supplierId?: string;
|
|
111
|
+
batchId?: string;
|
|
112
|
+
assetId: string;
|
|
113
|
+
entityId: string;
|
|
114
|
+
companyId: string;
|
|
115
|
+
userSub: string;
|
|
116
|
+
}
|