@etainabl/nodejs-sdk 1.2.55 → 1.2.56

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/esm/index.js CHANGED
@@ -300,9 +300,9 @@ var api_default = (auth, instanceOptions = {}) => {
300
300
  // import templates
301
301
  getImportTemplate: factory.getWithId(etainablApi, "import-templates"),
302
302
  //data imports
303
+ listDataIngest: factory.list(etainablApi, "data-ingests"),
303
304
  updateDataIngest: factory.update(etainablApi, "data-ingests"),
304
- createDataIngest: factory.create(etainablApi, "data-ingests"),
305
- listDataIngest: factory.list(etainablApi, "data-ingests")
305
+ createDataIngest: factory.create(etainablApi, "data-ingests")
306
306
  };
307
307
  } catch (e) {
308
308
  log.error(e);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api.ts","../../src/logger.ts","../../src/db.ts","../../src/slack.ts","../../src/units.ts","../../src/consumption.ts","../../src/monitoring.ts","../../src/reporting.ts"],"sourcesContent":["import axios from 'axios';\nimport type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults, AxiosResponse } from 'axios';\nimport https from 'https';\n\nimport logger from './logger.js';\n\nimport type { Account, Asset, Automation, Entity, Company, DataIngest, Invoice, Log, Reading, Report, Supplier } from './types/index.js'\n\nconst log = logger('etainablApi');\n\nexport interface ETNPagedResponse<T = any> {\n data: T[];\n total: number;\n limit: number;\n skip: number;\n}\n\nexport interface ETNReq {\n method: string;\n url: string;\n}\n\nfunction _handleResponse(req: ETNReq, res: AxiosResponse, isPaged = false) {\n if (!res) {\n throw new Error(`No response from API (${req.method} ${req.url})`);\n }\n\n if (res.status !== 200) {\n throw new Error(`${res.status} ${res.statusText} response from API (${req.method} ${req.url})`);\n }\n\n if (!res.data) {\n throw new Error(`No data from API (${req.method} ${req.url})`);\n }\n\n if (isPaged && !res.data.data) {\n throw new Error(`No data from API (${req.method} ${req.url})`);\n }\n\n return res;\n}\n\nconst factory = {\n getWithId: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'GET',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n\n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n _handleResponse(req, res)\n\n return res.data;\n },\n get: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'GET',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n\n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n _handleResponse(req, res)\n\n return res.data;\n },\n list: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<ETNPagedResponse<T>> => {\n const req = {\n method: 'GET',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n \n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n _handleResponse(req, res, true)\n\n return res.data;\n },\n update: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => {\n const req = {\n method: 'PATCH',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n \n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.patch(req.url, data, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n },\n create: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (data: any, options: AxiosRequestConfig = {}) => {\n const req = {\n method: 'POST',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.post(req.url, data, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n },\n remove: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}) => {\n const req = {\n method: 'DELETE',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n let res: AxiosResponse;\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n try {\n res = await etainablApi.delete(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res);\n\n return res.data;\n },\n customWithId: (etainablApi: AxiosInstance, method: string, endpoint: string, postEndpoint?: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => {\n const req = {\n method: method,\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`,\n data,\n ...options\n };\n \n log.info(`API Request (Custom): ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.request(req);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n }\n};\n\n// ETN Sub Endpoints\n// e.g. /assets/:id/documents/:documentId\nconst subFactory = {\n // e.g. POST /assets/:id/documents\n create: (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => { \n const subUrl = `${id}/${subEndpoint}`;\n return factory.create(etainablApi, endpoint, subUrl)(data, options);\n },\n // e.g. PATCH /assets/:id/documents/:documentId\n update: (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, subId: string, data: any, options: AxiosRequestConfig = {}) => {\n const subUrl = `${subEndpoint}/${subId}`;\n \n return factory.update(etainablApi, endpoint, subUrl)(id, data, options);\n },\n // e.g. DELETE /assets/:id/documents/:documentId\n remove: (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, subId: string, options: AxiosRequestConfig = {}) => {\n const subUrl = `${subEndpoint}/${subId}`;\n \n return factory.remove(etainablApi, endpoint, subUrl)(id, options);\n }\n}\n\ninterface AuthOptions {\n key?: string;\n token?: string;\n}\n\nexport default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) => {\n try {\n const headers: any = {};\n\n if (auth.key) {\n headers['x-key'] = auth.key;\n } else if (auth.token) {\n headers['Authorization'] = auth.token;\n } else {\n headers['x-key'] = process.env.ETAINABL_API_KEY;\n }\n \n const etainablApi = axios.create({\n baseURL: process.env.ETAINABL_API_URL,\n timeout: 300000,\n httpsAgent: new https.Agent({ keepAlive: true }),\n headers,\n ...instanceOptions\n });\n \n return {\n instance: etainablApi,\n \n // accounts\n getAccount: factory.getWithId<Account>(etainablApi, 'accounts'),\n listAccounts: factory.list<Account>(etainablApi, 'accounts'),\n updateAccount: factory.update(etainablApi, 'accounts'),\n createAccount: factory.create(etainablApi, 'accounts'),\n removeAccount: factory.remove(etainablApi, 'accounts'),\n getAccountSchema: factory.get(etainablApi, 'accounts', 'schema'),\n invalidateAccountCache: factory.customWithId(etainablApi, 'put', 'accounts', 'invalidate-cache'),\n\n // assets\n getAsset: factory.getWithId<Asset>(etainablApi, 'assets'),\n listAssets: factory.list<Asset>(etainablApi, 'assets'),\n updateAsset: factory.update(etainablApi, 'assets'),\n createAsset: factory.create(etainablApi, 'assets'),\n removeAsset: factory.remove(etainablApi, 'assets'),\n getAssetSchema: factory.get(etainablApi, 'assets', 'schema'),\n \n // assetGroups\n getAssetGroup: factory.getWithId(etainablApi, 'asset-groups'),\n listAssetGroups: factory.list(etainablApi, 'asset-groups'),\n updateAssetGroup: factory.update(etainablApi, 'asset-groups'),\n createAssetGroup: factory.create(etainablApi, 'asset-groups'),\n removeAssetGroup: factory.remove(etainablApi, 'asset-groups'),\n getAssetGroupAssets: factory.getWithId(etainablApi, 'asset-groups', 'assets'),\n getAssetGroupSchema: factory.get(etainablApi, 'asset-groups', 'schema'),\n \n // automation\n getAutomation: factory.getWithId<Automation>(etainablApi, 'automation'),\n listAutomations: factory.list<Automation>(etainablApi, 'automation'),\n updateAutomation: factory.update(etainablApi, 'automation'),\n createAutomation: factory.create(etainablApi, 'automation'),\n removeAutomation: factory.remove(etainablApi, 'automation'),\n createAutomationLog: subFactory.create(etainablApi, 'automation', 'logs'),\n updateAutomationLog: subFactory.update(etainablApi, 'automation', 'logs'),\n removeAutomationLog: subFactory.remove(etainablApi, 'automation', 'logs'),\n \n // company\n getCompany: factory.getWithId<Company>(etainablApi, 'companies'),\n \n // consumption\n getConsumption: factory.getWithId(etainablApi, 'consumptions'),\n listConsumptions: factory.list(etainablApi, 'consumptions'),\n updateConsumption: factory.update(etainablApi, 'consumptions'),\n createConsumption: factory.create(etainablApi, 'consumptions'),\n removeConsumption: factory.remove(etainablApi, 'consumptions'),\n getConsumptionSchema: factory.get(etainablApi, 'consumptions', 'schema'),\n \n // emails\n getEmail: factory.getWithId(etainablApi, 'emails'),\n listEmails: factory.list(etainablApi, 'emails'),\n updateEmail: factory.update(etainablApi, 'emails'),\n createEmail: factory.create(etainablApi, 'emails'),\n removeEmail: factory.remove(etainablApi, 'emails'),\n \n // emission factors\n getEmissionFactor: factory.getWithId(etainablApi, 'emission-factors'),\n listEmissionFactors: factory.list(etainablApi, 'emission-factors'),\n updateEmissionFactor: factory.update(etainablApi, 'emission-factors'),\n createEmissionFactor: factory.create(etainablApi, 'emission-factors'),\n removeEmissionFactor: factory.remove(etainablApi, 'emission-factors'),\n\n // entity\n getEntity: factory.getWithId<Entity>(etainablApi, 'entities'),\n listEntities: factory.list<Entity>(etainablApi, 'entities'),\n updateEntity: factory.update(etainablApi, 'entities'),\n createEntity: factory.create(etainablApi, 'entities'),\n removeEntity: factory.remove(etainablApi, 'entities'),\n getEntitiesSchema: factory.get(etainablApi, 'entities', 'schema'),\n \n \n // logs\n getLog: factory.getWithId<Log>(etainablApi, 'logs'),\n listLogs: factory.list<Log>(etainablApi, 'logs'),\n updateLog: factory.update(etainablApi, 'logs'),\n createLog: factory.create(etainablApi, 'logs'),\n removeLog: factory.remove(etainablApi, 'logs'),\n \n // readings\n getReading: factory.getWithId<Reading>(etainablApi, 'readings'),\n listReadings: factory.list<Reading>(etainablApi, 'readings'),\n updateReading: factory.update(etainablApi, 'readings'),\n createReading: factory.create(etainablApi, 'readings'),\n removeReading: factory.remove(etainablApi, 'readings'),\n getReadingSchema: factory.get(etainablApi, 'readings', 'schema'),\n \n // reports\n getReport: factory.getWithId<Report>(etainablApi, 'reports'),\n listReports: factory.list<Report>(etainablApi, 'reports'),\n updateReport: factory.update(etainablApi, 'reports'),\n createReport: factory.create(etainablApi, 'reports'),\n removeReport: factory.remove(etainablApi, 'reports'),\n sendReport: factory.customWithId(etainablApi, 'post', 'reports', 'send'),\n \n // report templates\n getReportTemplate: factory.getWithId(etainablApi, 'report-templates'),\n listReportTemplates: factory.list(etainablApi, 'report-templates'),\n updateReportTemplate: factory.update(etainablApi, 'report-templates'),\n createReportTemplate: factory.create(etainablApi, 'report-templates'),\n removeReportTemplate: factory.remove(etainablApi, 'report-templates'),\n \n // scheduled reports\n getScheduledReport: factory.getWithId(etainablApi, 'scheduled-reports'),\n listScheduledReports: factory.list(etainablApi, 'scheduled-reports'),\n updateScheduledReport: factory.update(etainablApi, 'scheduled-reports'),\n createScheduledReport: factory.create(etainablApi, 'scheduled-reports'),\n removeScheduledReport: factory.remove(etainablApi, 'scheduled-reports'),\n sendScheduledReport: factory.customWithId(etainablApi, 'post', 'scheduled-reports', 'send'),\n \n // invoices\n getInvoice: factory.getWithId<Invoice>(etainablApi, 'invoices'),\n listInvoices: factory.list<Invoice>(etainablApi, 'invoices'),\n updateInvoice: factory.update(etainablApi, 'invoices'),\n createInvoice: factory.create(etainablApi, 'invoices'),\n removeInvoice: factory.remove(etainablApi, 'invoices'),\n getInvoiceSchema: factory.get(etainablApi, 'invoices', 'schema'),\n\n //suppliers\n listSuppliers: factory.list<Supplier>(etainablApi, 'suppliers'),\n getSupplierSchema: factory.get(etainablApi, 'suppliers', 'schema'),\n\n // import templates\n getImportTemplate: factory.getWithId(etainablApi, 'import-templates'),\n\n //data imports\n updateDataIngest: factory.update(etainablApi, 'data-ingests'),\n createDataIngest: factory.create(etainablApi, 'data-ingests'),\n listDataIngest: factory.list<DataIngest>(etainablApi, 'data-ingests'),\n\n }\n } catch (e) {\n log.error(e);\n throw e;\n }\n};\n","import winston from 'winston';\n\nexport default (namespace: string) => winston.createLogger({\n level: 'debug',\n format: winston.format.combine(\n winston.format.timestamp(),\n winston.format.json()\n ),\n defaultMeta: { service: process.env.AWS_LAMBDA_FUNCTION_NAME, script: namespace },\n transports: [\n new winston.transports.Console()\n ]\n});\n","import { MongoClient, Db } from 'mongodb';\nimport logger from './logger.js';\n\nconst log = logger('dbHelpers');\n\nlet cachedDb: Db;\n\nasync function connectToDatabase(retryAttempt: number = 1): Promise<Db> {\n if (!process.env.ETAINABL_DB_URL) throw new Error(\"ETAINABL_DB_URL is not set\");\n if (!process.env.AWS_ACCESS_KEY_ID) throw new Error(\"AWS_ACCESS_KEY_ID is not set\");\n if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error(\"AWS_SECRET_ACCESS_KEY is not set\");\n\n if (cachedDb) {\n log.debug('Using cached MongoDB connection.');\n return Promise.resolve(cachedDb);\n }\n \n const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;\n \n try {\n if (process.env.DB_BASIC_AUTH === 'true') {\n log.debug('Connecting to MongoDB server... (Auth: Basic)');\n\n const client = new MongoClient(uri);\n await client.connect();\n\n log.debug('Connected successfully to MongoDB server! (Auth: Basic)');\n\n cachedDb = client.db('etainabl');\n\n return cachedDb;\n }\n\n log.debug('Connecting to MongoDB server... (Auth: AWS)');\n\n const client = new MongoClient(uri, {\n auth: {\n username: process.env.AWS_ACCESS_KEY_ID,\n password: process.env.AWS_SECRET_ACCESS_KEY\n },\n authSource: '$external',\n authMechanism: 'MONGODB-AWS'\n });\n\n await client.connect();\n\n log.debug('Connected successfully to MongoDB server! (Auth: AWS)');\n\n cachedDb = client.db('etainabl');\n\n return cachedDb;\n\n } catch (e: any) {\n // Retry\n if (retryAttempt > 5) {\n console.log(`Error connecting to MongoDB server after 5 attempts...`);\n throw e;\n }\n\n console.log(`MongoDB Connection error: ${e.message}`);\n\n console.log(`Error connecting to MongoDB server... Retrying in 3 seconds... (Attempt ${retryAttempt})`);\n return connectToDatabase(retryAttempt + 1);\n }\n}\n\nexport default {\n connectToDatabase\n};","import axios from 'axios';\n\nconst postMessage = async (message: string) => {\n const url = 'https://hooks.slack.com/services/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';\n const data = {\n text: `[${(process.env.ENV || '').toUpperCase()}][${process.env.AWS_LAMBDA_FUNCTION_NAME}] ${message}`\n };\n const headers = {\n 'Content-Type': 'application/json'\n };\n return axios.post(url, data, { headers });\n};\n\nexport default {\n postMessage\n}","interface Item {\n units?: string | null;\n unit?: string | null;\n factor?: number | null;\n value: number;\n [key: string]: any; \n}\n\nexport type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'oil' | 'other';\nexport type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';\nexport type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h' | 'l';\nexport const accountTypeMap: { [key: string]: BaseUnit } = {\n electricity: 'kwh',\n gas: 'kwh',\n water: 'm3',\n waste: 'kg',\n solar: 'kwh',\n heating: 'kwh',\n flow: 'm3/h',\n cooling: 'kwh',\n temperature: 'C',\n oil: 'l'\n};\n\nconst unitConversionFactors: { [key: string]: any } = {\n kwh: {\n kwh: 1,\n mwh: 1000,\n wh: 0.001,\n m3: (39 * 1.02264) / 3.6,\n ft3: (0.0283 * 39 * 1.02264) / 3.6,\n hcf: (2.83 * 39 * 1.02264) / 3.6\n },\n m3: {\n m3: 1,\n l: 0.001\n },\n C: {\n C: 1\n },\n kg: {\n kg: 1,\n lbs: 0.45359237,\n tonnes: 1000\n },\n 'm3/h': {\n 'm3/h': 1\n }\n};\n\nexport const accountTypeUnitMap: { [key: string]: ETNUnit[] } = {\n electricity: ['kwh', 'mwh', 'wh'],\n gas: ['kwh', 'm3', 'ft3', 'hcf'],\n water: ['m3', 'l'],\n waste: ['kg', 'lbs', 'tonnes'],\n solar: ['kwh', 'mwh', 'wh'],\n heating: ['kwh', 'mwh', 'wh'],\n flow: ['m3/h'],\n cooling: ['kwh', 'mwh', 'wh'],\n temperature: ['C'],\n oil: ['l']\n};\n\n// Convert units to base format\nexport const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined): any => {\n if (!type) throw new Error('Account type is required');\n\n const baseUnit = accountTypeMap[type];\n if (!baseUnit) throw new Error(`Account type ${type} is not supported`);\n\n const convertedItems = items.map(item => {\n const factor = item.factor || accountFactor || 1;\n const units = item.units || item.unit || defaultUnits || baseUnit;\n const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;\n return { ...item, value: convertedValue, units: baseUnit };\n });\n\n return convertedItems;\n};\n\nconst _getConversionFactor = (fromUnit: string = 'kwh', toUnit: string) => {\n const conversionFactors = unitConversionFactors[toUnit];\n\n if (!conversionFactors) {\n throw new Error(`Conversion factor base unit ${toUnit} is not defined`);\n }\n\n if (!conversionFactors[fromUnit]) {\n throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);\n }\n\n return conversionFactors[fromUnit];\n};\n\nexport const checkAccountTypeVsUnits = (type: string, unit: string, additionalLog: number | '' = '') => {\n if (!type) throw new Error('Account type is required');\n if (!unit) throw new Error('Unit is required');\n\n const parsedType = type.toLowerCase().trim();\n\n const accountTypeUnits = accountTypeUnitMap[parsedType];\n if (!accountTypeUnits) throw new Error(`Account type \"${parsedType}\" is not supported ${additionalLog}`);\n\n const parsedUnit = unit.toLowerCase().trim() as ETNUnit;\n\n if (!accountTypeUnits.includes(parsedUnit)) {\n throw new Error(`Account type \"${parsedType}\" does not support unit \"${parsedUnit}\" ${additionalLog}`);\n }\n\n return { type: parsedType as AccountType, unit: parsedUnit};\n};\n","import moment from 'moment';\n\ninterface ConsumptionData {\n date: Date;\n consumption: number;\n}\n\ninterface DayNightConsumption {\n dayConsumption: number,\n nightConsumption: number,\n consumption: number\n}\n\nexport const dayNightConsumption = (data: ConsumptionData[]) => data.reduce((acc: DayNightConsumption, item: ConsumptionData): DayNightConsumption => {\n const hour = moment.utc(item.date).hour(); // End Time of HH consumption period\n\n if (hour >= 0 && hour < 7) {\n acc.nightConsumption += item.consumption;\n } else {\n acc.dayConsumption += item.consumption;\n }\n\n acc.consumption += item.consumption;\n\n return acc;\n}, {\n dayConsumption: 0,\n nightConsumption: 0,\n consumption: 0\n});\n\nexport const calcMaxConsumptionValue = (data: ConsumptionData[]) => Math.max(...data.map((item: ConsumptionData) => item.consumption));\n\nexport const calcMaxDemand = (data: ConsumptionData[]) => calcMaxConsumptionValue(data) * 2;\n\nexport const calcPeakLoad = (consumption: number, maxDemand: number, startDate: string | moment.Moment, endDate: string | moment.Moment) => {\n const days = Math.ceil(moment(endDate).diff(moment(startDate), 'days', true));\n\n return maxDemand === 0 ? 0 : ((consumption / (maxDemand * 24 * days)) * 100);\n};","import axios from 'axios';\n\nimport logger from './logger.js';\n\nconst log = logger('monitoring');\n\nexport const sendHeartbeat = async () => {\n if (!process.env.HEARTBEAT_URL || process.env.HEARTBEAT_URL.endsWith('/')) return false;\n\n try {\n await axios.post(process.env.HEARTBEAT_URL);\n\n return true;\n } catch (e: any) {\n log.warn(`Failed to send heartbeat: ${e.message || e}`);\n return false;\n }\n}","import moment from 'moment';\n\nmoment.locale('en', {\n week: {\n dow: 1\n }\n});\n\nconst getNextRunTime = (startDate: moment.Moment, schedule: any, taskTime: moment.Moment): moment.Moment => {\n const [num, freq] = schedule.frequency.split('|');\n const targetDate = moment(startDate).add(num, freq as moment.unitOfTime.Base);\n\n if (schedule.frequencyPeriod === 'first') {\n targetDate.startOf(freq as moment.unitOfTime.StartOf);\n } else if (schedule.frequencyPeriod === 'last') {\n targetDate.endOf(freq as moment.unitOfTime.StartOf);\n }\n\n const isWeekday = targetDate.isoWeekday() > 0 && targetDate.isoWeekday() < 6;\n const isSaturday = targetDate.isoWeekday() === 6;\n\n // The weekday or weekend chosen should be within the same month as the target date\n if (schedule.frequencyDay === 'weekdays' && !isWeekday) {\n if ((targetDate.date() / 7) < 2) {\n targetDate.add(isSaturday ? 2 : 1, 'days');\n } else {\n targetDate.subtract(isSaturday ? 1 : 2, 'days');\n }\n } else if (schedule.frequencyDay === 'weekends' && isWeekday) {\n if ((targetDate.date() / 7) < 2) {\n targetDate.isoWeekday(6);\n } else {\n targetDate.isoWeekday(0);\n }\n }\n\n if (taskTime.isAfter(targetDate, 'minute')) {\n return getNextRunTime(targetDate, schedule, taskTime);\n }\n\n return targetDate;\n};\n\nexport const getScheduledReportRunTimes = (schedule: any, limit = 1, taskTime = moment()): moment.Moment[] => {\n if (!schedule.startDate || !schedule.enabled) return [];\n\n const originalStartDate = moment.utc(schedule.startDate);\n\n let startDate = originalStartDate;\n\n const includeStartDate = taskTime.isSameOrBefore(originalStartDate, 'minute');\n\n let runTimes = [] as moment.Moment[];\n\n if (includeStartDate) {\n runTimes = [originalStartDate];\n }\n\n const [, freq] = schedule.frequency.split('|');\n\n if (freq === 'once') {\n const nextRunTime = runTimes[0];\n\n // If this is now beyond the start date, return an empty array\n return taskTime.isAfter(nextRunTime, 'minute') ? [] : runTimes;\n }\n\n\n const scheduleRunTimes = Array.from(Array(includeStartDate ? limit - 1 : limit).keys()).map(() => {\n const nextRunTime = getNextRunTime(startDate, schedule, taskTime);\n\n startDate = nextRunTime.hour(originalStartDate.hour()).minute(originalStartDate.minute());\n\n return nextRunTime;\n });\n\n return [...runTimes, ...scheduleRunTimes];\n};\n"],"mappings":";;;;;;;AAAA,OAAO,WAAW;AAElB,OAAO,WAAW;;;ACFlB,OAAO,aAAa;AAEpB,IAAO,iBAAQ,CAAC,cAAsB,QAAQ,aAAa;AAAA,EACzD,OAAO;AAAA,EACP,QAAQ,QAAQ,OAAO;AAAA,IACrB,QAAQ,OAAO,UAAU;AAAA,IACzB,QAAQ,OAAO,KAAK;AAAA,EACtB;AAAA,EACA,aAAa,EAAE,SAAS,QAAQ,IAAI,0BAA0B,QAAQ,UAAU;AAAA,EAChF,YAAY;AAAA,IACV,IAAI,QAAQ,WAAW,QAAQ;AAAA,EACjC;AACF,CAAC;;;ADJD,IAAM,MAAM,eAAO,aAAa;AAchC,SAAS,gBAAgB,KAAa,KAAoB,UAAU,OAAO;AACzE,MAAI,CAAC,KAAK;AACR,UAAM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,CAAC,EAAE,IAAI,MAAM;AAChG,UAAM,cAAc,eAAe,WAAW,UAAU,QAAQ;AAEhE,gBAAY,YAAY,KAAK,kBAAkB,KAAK,CAAC,EAAE,OAAO,kBAAkB,OAAO,CAAC;AAExF,WAAO;AAAA,EACT,CAAC;AAED,SAAO,CAAC,GAAG,UAAU,GAAG,gBAAgB;AAC1C;","names":["log","client","axios","axios","log","axios","moment"]}
1
+ {"version":3,"sources":["../../src/api.ts","../../src/logger.ts","../../src/db.ts","../../src/slack.ts","../../src/units.ts","../../src/consumption.ts","../../src/monitoring.ts","../../src/reporting.ts"],"sourcesContent":["import axios from 'axios';\nimport type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults, AxiosResponse } from 'axios';\nimport https from 'https';\n\nimport logger from './logger.js';\n\nimport type { Account, Asset, Automation, Entity, Company, DataIngest, Invoice, Log, Reading, Report, Supplier } from './types/index.js'\n\nconst log = logger('etainablApi');\n\nexport interface ETNPagedResponse<T = any> {\n data: T[];\n total: number;\n limit: number;\n skip: number;\n}\n\nexport interface ETNReq {\n method: string;\n url: string;\n}\n\nfunction _handleResponse(req: ETNReq, res: AxiosResponse, isPaged = false) {\n if (!res) {\n throw new Error(`No response from API (${req.method} ${req.url})`);\n }\n\n if (res.status !== 200) {\n throw new Error(`${res.status} ${res.statusText} response from API (${req.method} ${req.url})`);\n }\n\n if (!res.data) {\n throw new Error(`No data from API (${req.method} ${req.url})`);\n }\n\n if (isPaged && !res.data.data) {\n throw new Error(`No data from API (${req.method} ${req.url})`);\n }\n\n return res;\n}\n\nconst factory = {\n getWithId: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'GET',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n\n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n _handleResponse(req, res)\n\n return res.data;\n },\n get: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'GET',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n\n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n _handleResponse(req, res)\n\n return res.data;\n },\n list: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<ETNPagedResponse<T>> => {\n const req = {\n method: 'GET',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n \n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n _handleResponse(req, res, true)\n\n return res.data;\n },\n update: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, data: any, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'PATCH',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n \n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.patch(req.url, data, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n },\n create: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (data: any, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'POST',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.post(req.url, data, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n },\n remove: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'DELETE',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n let res: AxiosResponse;\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n try {\n res = await etainablApi.delete(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res);\n\n return res.data;\n },\n customWithId: <T = any> (etainablApi: AxiosInstance, method: string, endpoint: string, postEndpoint?: string) => async (id: string, data: any, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: method,\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`,\n data,\n ...options\n };\n \n log.info(`API Request (Custom): ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.request(req);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n }\n};\n\n// ETN Sub Endpoints\n// e.g. /assets/:id/documents/:documentId\nconst subFactory = {\n // e.g. POST /assets/:id/documents\n create: <T = any> (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => { \n const subUrl = `${id}/${subEndpoint}`;\n return factory.create<T>(etainablApi, endpoint, subUrl)(data, options);\n },\n // e.g. PATCH /assets/:id/documents/:documentId\n update: <T = any> (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, subId: string, data: any, options: AxiosRequestConfig = {}) => {\n const subUrl = `${subEndpoint}/${subId}`;\n \n return factory.update<T>(etainablApi, endpoint, subUrl)(id, data, options);\n },\n // e.g. DELETE /assets/:id/documents/:documentId\n remove: <T = any> (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, subId: string, options: AxiosRequestConfig = {}) => {\n const subUrl = `${subEndpoint}/${subId}`;\n \n return factory.remove<T>(etainablApi, endpoint, subUrl)(id, options);\n }\n}\n\ninterface AuthOptions {\n key?: string;\n token?: string;\n}\n\nexport default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) => {\n try {\n const headers: any = {};\n\n if (auth.key) {\n headers['x-key'] = auth.key;\n } else if (auth.token) {\n headers['Authorization'] = auth.token;\n } else {\n headers['x-key'] = process.env.ETAINABL_API_KEY;\n }\n \n const etainablApi = axios.create({\n baseURL: process.env.ETAINABL_API_URL,\n timeout: 300000,\n httpsAgent: new https.Agent({ keepAlive: true }),\n headers,\n ...instanceOptions\n });\n \n return {\n instance: etainablApi,\n \n // accounts\n getAccount: factory.getWithId<Account<string>>(etainablApi, 'accounts'),\n listAccounts: factory.list<Account<string>>(etainablApi, 'accounts'),\n updateAccount: factory.update<Account<string>>(etainablApi, 'accounts'),\n createAccount: factory.create<Account<string>>(etainablApi, 'accounts'),\n removeAccount: factory.remove<Account<string>>(etainablApi, 'accounts'),\n getAccountSchema: factory.get(etainablApi, 'accounts', 'schema'),\n invalidateAccountCache: factory.customWithId(etainablApi, 'put', 'accounts', 'invalidate-cache'),\n\n // assets\n getAsset: factory.getWithId<Asset<string>>(etainablApi, 'assets'),\n listAssets: factory.list<Asset<string>>(etainablApi, 'assets'),\n updateAsset: factory.update<Asset<string>>(etainablApi, 'assets'),\n createAsset: factory.create<Asset<string>>(etainablApi, 'assets'),\n removeAsset: factory.remove<Asset<string>>(etainablApi, 'assets'),\n getAssetSchema: factory.get(etainablApi, 'assets', 'schema'),\n \n // assetGroups\n getAssetGroup: factory.getWithId(etainablApi, 'asset-groups'),\n listAssetGroups: factory.list(etainablApi, 'asset-groups'),\n updateAssetGroup: factory.update(etainablApi, 'asset-groups'),\n createAssetGroup: factory.create(etainablApi, 'asset-groups'),\n removeAssetGroup: factory.remove(etainablApi, 'asset-groups'),\n getAssetGroupAssets: factory.getWithId(etainablApi, 'asset-groups', 'assets'),\n getAssetGroupSchema: factory.get(etainablApi, 'asset-groups', 'schema'),\n \n // automation\n getAutomation: factory.getWithId<Automation<string>>(etainablApi, 'automation'),\n listAutomations: factory.list<Automation<string>>(etainablApi, 'automation'),\n updateAutomation: factory.update<Automation<string>>(etainablApi, 'automation'),\n createAutomation: factory.create<Automation<string>>(etainablApi, 'automation'),\n removeAutomation: factory.remove<Automation<string>>(etainablApi, 'automation'),\n createAutomationLog: subFactory.create(etainablApi, 'automation', 'logs'),\n updateAutomationLog: subFactory.update(etainablApi, 'automation', 'logs'),\n removeAutomationLog: subFactory.remove(etainablApi, 'automation', 'logs'),\n \n // company\n getCompany: factory.getWithId<Company<string>>(etainablApi, 'companies'),\n \n // consumption\n getConsumption: factory.getWithId(etainablApi, 'consumptions'),\n listConsumptions: factory.list(etainablApi, 'consumptions'),\n updateConsumption: factory.update(etainablApi, 'consumptions'),\n createConsumption: factory.create(etainablApi, 'consumptions'),\n removeConsumption: factory.remove(etainablApi, 'consumptions'),\n getConsumptionSchema: factory.get(etainablApi, 'consumptions', 'schema'),\n \n // emails\n getEmail: factory.getWithId(etainablApi, 'emails'),\n listEmails: factory.list(etainablApi, 'emails'),\n updateEmail: factory.update(etainablApi, 'emails'),\n createEmail: factory.create(etainablApi, 'emails'),\n removeEmail: factory.remove(etainablApi, 'emails'),\n \n // emission factors\n getEmissionFactor: factory.getWithId(etainablApi, 'emission-factors'),\n listEmissionFactors: factory.list(etainablApi, 'emission-factors'),\n updateEmissionFactor: factory.update(etainablApi, 'emission-factors'),\n createEmissionFactor: factory.create(etainablApi, 'emission-factors'),\n removeEmissionFactor: factory.remove(etainablApi, 'emission-factors'),\n\n // entity\n getEntity: factory.getWithId<Entity<string>>(etainablApi, 'entities'),\n listEntities: factory.list<Entity<string>>(etainablApi, 'entities'),\n updateEntity: factory.update<Entity<string>>(etainablApi, 'entities'),\n createEntity: factory.create<Entity<string>>(etainablApi, 'entities'),\n removeEntity: factory.remove<Entity<string>>(etainablApi, 'entities'),\n getEntitiesSchema: factory.get(etainablApi, 'entities', 'schema'),\n \n \n // logs\n getLog: factory.getWithId<Log<string>>(etainablApi, 'logs'),\n listLogs: factory.list<Log<string>>(etainablApi, 'logs'),\n updateLog: factory.update<Log<string>>(etainablApi, 'logs'),\n createLog: factory.create<Log<string>>(etainablApi, 'logs'),\n removeLog: factory.remove<Log<string>>(etainablApi, 'logs'),\n \n // readings\n getReading: factory.getWithId<Reading<string>>(etainablApi, 'readings'),\n listReadings: factory.list<Reading<string>>(etainablApi, 'readings'),\n updateReading: factory.update<Reading<string>>(etainablApi, 'readings'),\n createReading: factory.create<Reading<string>>(etainablApi, 'readings'),\n removeReading: factory.remove<Reading<string>>(etainablApi, 'readings'),\n getReadingSchema: factory.get(etainablApi, 'readings', 'schema'),\n \n // reports\n getReport: factory.getWithId<Report<string>>(etainablApi, 'reports'),\n listReports: factory.list<Report<string>>(etainablApi, 'reports'),\n updateReport: factory.update<Report<string>>(etainablApi, 'reports'),\n createReport: factory.create<Report<string>>(etainablApi, 'reports'),\n removeReport: factory.remove<Report<string>>(etainablApi, 'reports'),\n sendReport: factory.customWithId(etainablApi, 'post', 'reports', 'send'),\n \n // report templates\n getReportTemplate: factory.getWithId(etainablApi, 'report-templates'),\n listReportTemplates: factory.list(etainablApi, 'report-templates'),\n updateReportTemplate: factory.update(etainablApi, 'report-templates'),\n createReportTemplate: factory.create(etainablApi, 'report-templates'),\n removeReportTemplate: factory.remove(etainablApi, 'report-templates'),\n \n // scheduled reports\n getScheduledReport: factory.getWithId(etainablApi, 'scheduled-reports'),\n listScheduledReports: factory.list(etainablApi, 'scheduled-reports'),\n updateScheduledReport: factory.update(etainablApi, 'scheduled-reports'),\n createScheduledReport: factory.create(etainablApi, 'scheduled-reports'),\n removeScheduledReport: factory.remove(etainablApi, 'scheduled-reports'),\n sendScheduledReport: factory.customWithId(etainablApi, 'post', 'scheduled-reports', 'send'),\n \n // invoices\n getInvoice: factory.getWithId<Invoice<string>>(etainablApi, 'invoices'),\n listInvoices: factory.list<Invoice<string>>(etainablApi, 'invoices'),\n updateInvoice: factory.update<Invoice<string>>(etainablApi, 'invoices'),\n createInvoice: factory.create<Invoice<string>>(etainablApi, 'invoices'),\n removeInvoice: factory.remove<Invoice<string>>(etainablApi, 'invoices'),\n getInvoiceSchema: factory.get(etainablApi, 'invoices', 'schema'),\n\n //suppliers\n listSuppliers: factory.list<Supplier<string>>(etainablApi, 'suppliers'),\n getSupplierSchema: factory.get(etainablApi, 'suppliers', 'schema'),\n\n // import templates\n getImportTemplate: factory.getWithId(etainablApi, 'import-templates'),\n\n //data imports\n listDataIngest: factory.list<DataIngest<string>>(etainablApi, 'data-ingests'),\n updateDataIngest: factory.update<DataIngest<string>>(etainablApi, 'data-ingests'),\n createDataIngest: factory.create<DataIngest<string>>(etainablApi, 'data-ingests')\n\n }\n } catch (e) {\n log.error(e);\n throw e;\n }\n};\n","import winston from 'winston';\n\nexport default (namespace: string) => winston.createLogger({\n level: 'debug',\n format: winston.format.combine(\n winston.format.timestamp(),\n winston.format.json()\n ),\n defaultMeta: { service: process.env.AWS_LAMBDA_FUNCTION_NAME, script: namespace },\n transports: [\n new winston.transports.Console()\n ]\n});\n","import { MongoClient, Db } from 'mongodb';\nimport logger from './logger.js';\n\nconst log = logger('dbHelpers');\n\nlet cachedDb: Db;\n\nasync function connectToDatabase(retryAttempt: number = 1): Promise<Db> {\n if (!process.env.ETAINABL_DB_URL) throw new Error(\"ETAINABL_DB_URL is not set\");\n if (!process.env.AWS_ACCESS_KEY_ID) throw new Error(\"AWS_ACCESS_KEY_ID is not set\");\n if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error(\"AWS_SECRET_ACCESS_KEY is not set\");\n\n if (cachedDb) {\n log.debug('Using cached MongoDB connection.');\n return Promise.resolve(cachedDb);\n }\n \n const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;\n \n try {\n if (process.env.DB_BASIC_AUTH === 'true') {\n log.debug('Connecting to MongoDB server... (Auth: Basic)');\n\n const client = new MongoClient(uri);\n await client.connect();\n\n log.debug('Connected successfully to MongoDB server! (Auth: Basic)');\n\n cachedDb = client.db('etainabl');\n\n return cachedDb;\n }\n\n log.debug('Connecting to MongoDB server... (Auth: AWS)');\n\n const client = new MongoClient(uri, {\n auth: {\n username: process.env.AWS_ACCESS_KEY_ID,\n password: process.env.AWS_SECRET_ACCESS_KEY\n },\n authSource: '$external',\n authMechanism: 'MONGODB-AWS'\n });\n\n await client.connect();\n\n log.debug('Connected successfully to MongoDB server! (Auth: AWS)');\n\n cachedDb = client.db('etainabl');\n\n return cachedDb;\n\n } catch (e: any) {\n // Retry\n if (retryAttempt > 5) {\n console.log(`Error connecting to MongoDB server after 5 attempts...`);\n throw e;\n }\n\n console.log(`MongoDB Connection error: ${e.message}`);\n\n console.log(`Error connecting to MongoDB server... Retrying in 3 seconds... (Attempt ${retryAttempt})`);\n return connectToDatabase(retryAttempt + 1);\n }\n}\n\nexport default {\n connectToDatabase\n};","import axios from 'axios';\n\nconst postMessage = async (message: string) => {\n const url = 'https://hooks.slack.com/services/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';\n const data = {\n text: `[${(process.env.ENV || '').toUpperCase()}][${process.env.AWS_LAMBDA_FUNCTION_NAME}] ${message}`\n };\n const headers = {\n 'Content-Type': 'application/json'\n };\n return axios.post(url, data, { headers });\n};\n\nexport default {\n postMessage\n}","interface Item {\n units?: string | null;\n unit?: string | null;\n factor?: number | null;\n value: number;\n [key: string]: any; \n}\n\nexport type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'oil' | 'other';\nexport type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';\nexport type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h' | 'l';\nexport const accountTypeMap: { [key: string]: BaseUnit } = {\n electricity: 'kwh',\n gas: 'kwh',\n water: 'm3',\n waste: 'kg',\n solar: 'kwh',\n heating: 'kwh',\n flow: 'm3/h',\n cooling: 'kwh',\n temperature: 'C',\n oil: 'l'\n};\n\nconst unitConversionFactors: { [key: string]: any } = {\n kwh: {\n kwh: 1,\n mwh: 1000,\n wh: 0.001,\n m3: (39 * 1.02264) / 3.6,\n ft3: (0.0283 * 39 * 1.02264) / 3.6,\n hcf: (2.83 * 39 * 1.02264) / 3.6\n },\n m3: {\n m3: 1,\n l: 0.001\n },\n C: {\n C: 1\n },\n kg: {\n kg: 1,\n lbs: 0.45359237,\n tonnes: 1000\n },\n 'm3/h': {\n 'm3/h': 1\n }\n};\n\nexport const accountTypeUnitMap: { [key: string]: ETNUnit[] } = {\n electricity: ['kwh', 'mwh', 'wh'],\n gas: ['kwh', 'm3', 'ft3', 'hcf'],\n water: ['m3', 'l'],\n waste: ['kg', 'lbs', 'tonnes'],\n solar: ['kwh', 'mwh', 'wh'],\n heating: ['kwh', 'mwh', 'wh'],\n flow: ['m3/h'],\n cooling: ['kwh', 'mwh', 'wh'],\n temperature: ['C'],\n oil: ['l']\n};\n\n// Convert units to base format\nexport const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined): any => {\n if (!type) throw new Error('Account type is required');\n\n const baseUnit = accountTypeMap[type];\n if (!baseUnit) throw new Error(`Account type ${type} is not supported`);\n\n const convertedItems = items.map(item => {\n const factor = item.factor || accountFactor || 1;\n const units = item.units || item.unit || defaultUnits || baseUnit;\n const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;\n return { ...item, value: convertedValue, units: baseUnit };\n });\n\n return convertedItems;\n};\n\nconst _getConversionFactor = (fromUnit: string = 'kwh', toUnit: string) => {\n const conversionFactors = unitConversionFactors[toUnit];\n\n if (!conversionFactors) {\n throw new Error(`Conversion factor base unit ${toUnit} is not defined`);\n }\n\n if (!conversionFactors[fromUnit]) {\n throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);\n }\n\n return conversionFactors[fromUnit];\n};\n\nexport const checkAccountTypeVsUnits = (type: string, unit: string, additionalLog: number | '' = '') => {\n if (!type) throw new Error('Account type is required');\n if (!unit) throw new Error('Unit is required');\n\n const parsedType = type.toLowerCase().trim();\n\n const accountTypeUnits = accountTypeUnitMap[parsedType];\n if (!accountTypeUnits) throw new Error(`Account type \"${parsedType}\" is not supported ${additionalLog}`);\n\n const parsedUnit = unit.toLowerCase().trim() as ETNUnit;\n\n if (!accountTypeUnits.includes(parsedUnit)) {\n throw new Error(`Account type \"${parsedType}\" does not support unit \"${parsedUnit}\" ${additionalLog}`);\n }\n\n return { type: parsedType as AccountType, unit: parsedUnit};\n};\n","import moment from 'moment';\n\ninterface ConsumptionData {\n date: Date;\n consumption: number;\n}\n\ninterface DayNightConsumption {\n dayConsumption: number,\n nightConsumption: number,\n consumption: number\n}\n\nexport const dayNightConsumption = (data: ConsumptionData[]) => data.reduce((acc: DayNightConsumption, item: ConsumptionData): DayNightConsumption => {\n const hour = moment.utc(item.date).hour(); // End Time of HH consumption period\n\n if (hour >= 0 && hour < 7) {\n acc.nightConsumption += item.consumption;\n } else {\n acc.dayConsumption += item.consumption;\n }\n\n acc.consumption += item.consumption;\n\n return acc;\n}, {\n dayConsumption: 0,\n nightConsumption: 0,\n consumption: 0\n});\n\nexport const calcMaxConsumptionValue = (data: ConsumptionData[]) => Math.max(...data.map((item: ConsumptionData) => item.consumption));\n\nexport const calcMaxDemand = (data: ConsumptionData[]) => calcMaxConsumptionValue(data) * 2;\n\nexport const calcPeakLoad = (consumption: number, maxDemand: number, startDate: string | moment.Moment, endDate: string | moment.Moment) => {\n const days = Math.ceil(moment(endDate).diff(moment(startDate), 'days', true));\n\n return maxDemand === 0 ? 0 : ((consumption / (maxDemand * 24 * days)) * 100);\n};","import axios from 'axios';\n\nimport logger from './logger.js';\n\nconst log = logger('monitoring');\n\nexport const sendHeartbeat = async () => {\n if (!process.env.HEARTBEAT_URL || process.env.HEARTBEAT_URL.endsWith('/')) return false;\n\n try {\n await axios.post(process.env.HEARTBEAT_URL);\n\n return true;\n } catch (e: any) {\n log.warn(`Failed to send heartbeat: ${e.message || e}`);\n return false;\n }\n}","import moment from 'moment';\n\nmoment.locale('en', {\n week: {\n dow: 1\n }\n});\n\nconst getNextRunTime = (startDate: moment.Moment, schedule: any, taskTime: moment.Moment): moment.Moment => {\n const [num, freq] = schedule.frequency.split('|');\n const targetDate = moment(startDate).add(num, freq as moment.unitOfTime.Base);\n\n if (schedule.frequencyPeriod === 'first') {\n targetDate.startOf(freq as moment.unitOfTime.StartOf);\n } else if (schedule.frequencyPeriod === 'last') {\n targetDate.endOf(freq as moment.unitOfTime.StartOf);\n }\n\n const isWeekday = targetDate.isoWeekday() > 0 && targetDate.isoWeekday() < 6;\n const isSaturday = targetDate.isoWeekday() === 6;\n\n // The weekday or weekend chosen should be within the same month as the target date\n if (schedule.frequencyDay === 'weekdays' && !isWeekday) {\n if ((targetDate.date() / 7) < 2) {\n targetDate.add(isSaturday ? 2 : 1, 'days');\n } else {\n targetDate.subtract(isSaturday ? 1 : 2, 'days');\n }\n } else if (schedule.frequencyDay === 'weekends' && isWeekday) {\n if ((targetDate.date() / 7) < 2) {\n targetDate.isoWeekday(6);\n } else {\n targetDate.isoWeekday(0);\n }\n }\n\n if (taskTime.isAfter(targetDate, 'minute')) {\n return getNextRunTime(targetDate, schedule, taskTime);\n }\n\n return targetDate;\n};\n\nexport const getScheduledReportRunTimes = (schedule: any, limit = 1, taskTime = moment()): moment.Moment[] => {\n if (!schedule.startDate || !schedule.enabled) return [];\n\n const originalStartDate = moment.utc(schedule.startDate);\n\n let startDate = originalStartDate;\n\n const includeStartDate = taskTime.isSameOrBefore(originalStartDate, 'minute');\n\n let runTimes = [] as moment.Moment[];\n\n if (includeStartDate) {\n runTimes = [originalStartDate];\n }\n\n const [, freq] = schedule.frequency.split('|');\n\n if (freq === 'once') {\n const nextRunTime = runTimes[0];\n\n // If this is now beyond the start date, return an empty array\n return taskTime.isAfter(nextRunTime, 'minute') ? [] : runTimes;\n }\n\n\n const scheduleRunTimes = Array.from(Array(includeStartDate ? limit - 1 : limit).keys()).map(() => {\n const nextRunTime = getNextRunTime(startDate, schedule, taskTime);\n\n startDate = nextRunTime.hour(originalStartDate.hour()).minute(originalStartDate.minute());\n\n return nextRunTime;\n });\n\n return [...runTimes, ...scheduleRunTimes];\n};\n"],"mappings":";;;;;;;AAAA,OAAO,WAAW;AAElB,OAAO,WAAW;;;ACFlB,OAAO,aAAa;AAEpB,IAAO,iBAAQ,CAAC,cAAsB,QAAQ,aAAa;AAAA,EACzD,OAAO;AAAA,EACP,QAAQ,QAAQ,OAAO;AAAA,IACrB,QAAQ,OAAO,UAAU;AAAA,IACzB,QAAQ,OAAO,KAAK;AAAA,EACtB;AAAA,EACA,aAAa,EAAE,SAAS,QAAQ,IAAI,0BAA0B,QAAQ,UAAU;AAAA,EAChF,YAAY;AAA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AG;AAE7C,MAAI,SAAS,QAAQ;AACnB,UAAM,cAAc,SAAS,CAAC;AAG9B,WAAO,SAAS,QAAQ,aAAa,QAAQ,IAAI,CAAC,IAAI;AAAA,EACxD;AAGA,QAAM,mBAAmB,MAAM,KAAK,MAAM,mBAAmB,QAAQ,IAAI,KAAK,EAAE,KAAK,CAAC,EAAE,IAAI,MAAM;AAChG,UAAM,cAAc,eAAe,WAAW,UAAU,QAAQ;AAEhE,gBAAY,YAAY,KAAK,kBAAkB,KAAK,CAAC,EAAE,OAAO,kBAAkB,OAAO,CAAC;AAExF,WAAO;AAAA,EACT,CAAC;AAED,SAAO,CAAC,GAAG,UAAU,GAAG,gBAAgB;AAC1C;","names":["log","client","axios","axios","log","axios","moment"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- import * as bson from 'bson';
2
1
  import * as axios from 'axios';
3
2
  import { CreateAxiosDefaults, AxiosInstance, AxiosRequestConfig } from 'axios';
4
3
  import { ObjectId, Db } from 'mongodb';
@@ -642,18 +641,18 @@ interface AuthOptions {
642
641
  }
643
642
  declare const _default$3: (auth: AuthOptions, instanceOptions?: CreateAxiosDefaults) => {
644
643
  instance: AxiosInstance;
645
- getAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<Account<string | bson.ObjectId>>;
646
- listAccounts: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Account<string | bson.ObjectId>>>;
647
- updateAccount: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
648
- createAccount: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
649
- removeAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
644
+ getAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<Account<string>>;
645
+ listAccounts: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Account<string>>>;
646
+ updateAccount: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Account<string>>;
647
+ createAccount: (data: any, options?: AxiosRequestConfig<any>) => Promise<Account<string>>;
648
+ removeAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<Account<string>>;
650
649
  getAccountSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
651
650
  invalidateAccountCache: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
652
- getAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<Asset<string | bson.ObjectId>>;
653
- listAssets: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Asset<string | bson.ObjectId>>>;
654
- updateAsset: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
655
- createAsset: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
656
- removeAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
651
+ getAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<Asset<string>>;
652
+ listAssets: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Asset<string>>>;
653
+ updateAsset: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Asset<string>>;
654
+ createAsset: (data: any, options?: AxiosRequestConfig<any>) => Promise<Asset<string>>;
655
+ removeAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<Asset<string>>;
657
656
  getAssetSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
658
657
  getAssetGroup: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
659
658
  listAssetGroups: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
@@ -662,15 +661,15 @@ declare const _default$3: (auth: AuthOptions, instanceOptions?: CreateAxiosDefau
662
661
  removeAssetGroup: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
663
662
  getAssetGroupAssets: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
664
663
  getAssetGroupSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
665
- getAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<Automation<string | bson.ObjectId>>;
666
- listAutomations: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Automation<string | bson.ObjectId>>>;
667
- updateAutomation: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
668
- createAutomation: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
669
- removeAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
664
+ getAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<Automation<string>>;
665
+ listAutomations: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Automation<string>>>;
666
+ updateAutomation: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Automation<string>>;
667
+ createAutomation: (data: any, options?: AxiosRequestConfig<any>) => Promise<Automation<string>>;
668
+ removeAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<Automation<string>>;
670
669
  createAutomationLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
671
670
  updateAutomationLog: (id: string, subId: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
672
671
  removeAutomationLog: (id: string, subId: string, options?: AxiosRequestConfig<any>) => Promise<any>;
673
- getCompany: (id: string, options?: AxiosRequestConfig<any>) => Promise<Company<string | bson.ObjectId>>;
672
+ getCompany: (id: string, options?: AxiosRequestConfig<any>) => Promise<Company<string>>;
674
673
  getConsumption: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
675
674
  listConsumptions: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
676
675
  updateConsumption: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
@@ -687,28 +686,28 @@ declare const _default$3: (auth: AuthOptions, instanceOptions?: CreateAxiosDefau
687
686
  updateEmissionFactor: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
688
687
  createEmissionFactor: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
689
688
  removeEmissionFactor: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
690
- getEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<Entity<string | bson.ObjectId>>;
691
- listEntities: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Entity<string | bson.ObjectId>>>;
692
- updateEntity: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
693
- createEntity: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
694
- removeEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
689
+ getEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<Entity<string>>;
690
+ listEntities: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Entity<string>>>;
691
+ updateEntity: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Entity<string>>;
692
+ createEntity: (data: any, options?: AxiosRequestConfig<any>) => Promise<Entity<string>>;
693
+ removeEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<Entity<string>>;
695
694
  getEntitiesSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
696
- getLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<Log<string | bson.ObjectId>>;
697
- listLogs: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Log<string | bson.ObjectId>>>;
698
- updateLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
699
- createLog: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
700
- removeLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
701
- getReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<Reading<string | bson.ObjectId>>;
702
- listReadings: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Reading<string | bson.ObjectId>>>;
703
- updateReading: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
704
- createReading: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
705
- removeReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
695
+ getLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<Log<string>>;
696
+ listLogs: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Log<string>>>;
697
+ updateLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Log<string>>;
698
+ createLog: (data: any, options?: AxiosRequestConfig<any>) => Promise<Log<string>>;
699
+ removeLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<Log<string>>;
700
+ getReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<Reading<string>>;
701
+ listReadings: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Reading<string>>>;
702
+ updateReading: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Reading<string>>;
703
+ createReading: (data: any, options?: AxiosRequestConfig<any>) => Promise<Reading<string>>;
704
+ removeReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<Reading<string>>;
706
705
  getReadingSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
707
- getReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<Report<string | bson.ObjectId>>;
708
- listReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Report<string | bson.ObjectId>>>;
709
- updateReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
710
- createReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
711
- removeReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
706
+ getReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<Report<string>>;
707
+ listReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Report<string>>>;
708
+ updateReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Report<string>>;
709
+ createReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<Report<string>>;
710
+ removeReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<Report<string>>;
712
711
  sendReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
713
712
  getReportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
714
713
  listReportTemplates: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
@@ -721,18 +720,18 @@ declare const _default$3: (auth: AuthOptions, instanceOptions?: CreateAxiosDefau
721
720
  createScheduledReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
722
721
  removeScheduledReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
723
722
  sendScheduledReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
724
- getInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<Invoice<string | bson.ObjectId>>;
725
- listInvoices: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Invoice<string | bson.ObjectId>>>;
726
- updateInvoice: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
727
- createInvoice: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
728
- removeInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
723
+ getInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<Invoice<string>>;
724
+ listInvoices: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Invoice<string>>>;
725
+ updateInvoice: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Invoice<string>>;
726
+ createInvoice: (data: any, options?: AxiosRequestConfig<any>) => Promise<Invoice<string>>;
727
+ removeInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<Invoice<string>>;
729
728
  getInvoiceSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
730
- listSuppliers: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Supplier<string | bson.ObjectId>>>;
729
+ listSuppliers: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Supplier<string>>>;
731
730
  getSupplierSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
732
731
  getImportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
733
- updateDataIngest: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
734
- createDataIngest: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
735
- listDataIngest: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<DataIngest<string | bson.ObjectId>>>;
732
+ listDataIngest: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<DataIngest<string>>>;
733
+ updateDataIngest: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<DataIngest<string>>;
734
+ createDataIngest: (data: any, options?: AxiosRequestConfig<any>) => Promise<DataIngest<string>>;
736
735
  };
737
736
 
738
737
  declare const _default$2: (namespace: string) => winston.Logger;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as bson from 'bson';
2
1
  import * as axios from 'axios';
3
2
  import { CreateAxiosDefaults, AxiosInstance, AxiosRequestConfig } from 'axios';
4
3
  import { ObjectId, Db } from 'mongodb';
@@ -642,18 +641,18 @@ interface AuthOptions {
642
641
  }
643
642
  declare const _default$3: (auth: AuthOptions, instanceOptions?: CreateAxiosDefaults) => {
644
643
  instance: AxiosInstance;
645
- getAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<Account<string | bson.ObjectId>>;
646
- listAccounts: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Account<string | bson.ObjectId>>>;
647
- updateAccount: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
648
- createAccount: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
649
- removeAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
644
+ getAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<Account<string>>;
645
+ listAccounts: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Account<string>>>;
646
+ updateAccount: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Account<string>>;
647
+ createAccount: (data: any, options?: AxiosRequestConfig<any>) => Promise<Account<string>>;
648
+ removeAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<Account<string>>;
650
649
  getAccountSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
651
650
  invalidateAccountCache: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
652
- getAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<Asset<string | bson.ObjectId>>;
653
- listAssets: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Asset<string | bson.ObjectId>>>;
654
- updateAsset: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
655
- createAsset: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
656
- removeAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
651
+ getAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<Asset<string>>;
652
+ listAssets: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Asset<string>>>;
653
+ updateAsset: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Asset<string>>;
654
+ createAsset: (data: any, options?: AxiosRequestConfig<any>) => Promise<Asset<string>>;
655
+ removeAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<Asset<string>>;
657
656
  getAssetSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
658
657
  getAssetGroup: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
659
658
  listAssetGroups: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
@@ -662,15 +661,15 @@ declare const _default$3: (auth: AuthOptions, instanceOptions?: CreateAxiosDefau
662
661
  removeAssetGroup: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
663
662
  getAssetGroupAssets: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
664
663
  getAssetGroupSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
665
- getAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<Automation<string | bson.ObjectId>>;
666
- listAutomations: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Automation<string | bson.ObjectId>>>;
667
- updateAutomation: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
668
- createAutomation: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
669
- removeAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
664
+ getAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<Automation<string>>;
665
+ listAutomations: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Automation<string>>>;
666
+ updateAutomation: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Automation<string>>;
667
+ createAutomation: (data: any, options?: AxiosRequestConfig<any>) => Promise<Automation<string>>;
668
+ removeAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<Automation<string>>;
670
669
  createAutomationLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
671
670
  updateAutomationLog: (id: string, subId: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
672
671
  removeAutomationLog: (id: string, subId: string, options?: AxiosRequestConfig<any>) => Promise<any>;
673
- getCompany: (id: string, options?: AxiosRequestConfig<any>) => Promise<Company<string | bson.ObjectId>>;
672
+ getCompany: (id: string, options?: AxiosRequestConfig<any>) => Promise<Company<string>>;
674
673
  getConsumption: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
675
674
  listConsumptions: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
676
675
  updateConsumption: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
@@ -687,28 +686,28 @@ declare const _default$3: (auth: AuthOptions, instanceOptions?: CreateAxiosDefau
687
686
  updateEmissionFactor: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
688
687
  createEmissionFactor: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
689
688
  removeEmissionFactor: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
690
- getEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<Entity<string | bson.ObjectId>>;
691
- listEntities: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Entity<string | bson.ObjectId>>>;
692
- updateEntity: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
693
- createEntity: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
694
- removeEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
689
+ getEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<Entity<string>>;
690
+ listEntities: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Entity<string>>>;
691
+ updateEntity: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Entity<string>>;
692
+ createEntity: (data: any, options?: AxiosRequestConfig<any>) => Promise<Entity<string>>;
693
+ removeEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<Entity<string>>;
695
694
  getEntitiesSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
696
- getLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<Log<string | bson.ObjectId>>;
697
- listLogs: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Log<string | bson.ObjectId>>>;
698
- updateLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
699
- createLog: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
700
- removeLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
701
- getReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<Reading<string | bson.ObjectId>>;
702
- listReadings: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Reading<string | bson.ObjectId>>>;
703
- updateReading: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
704
- createReading: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
705
- removeReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
695
+ getLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<Log<string>>;
696
+ listLogs: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Log<string>>>;
697
+ updateLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Log<string>>;
698
+ createLog: (data: any, options?: AxiosRequestConfig<any>) => Promise<Log<string>>;
699
+ removeLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<Log<string>>;
700
+ getReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<Reading<string>>;
701
+ listReadings: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Reading<string>>>;
702
+ updateReading: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Reading<string>>;
703
+ createReading: (data: any, options?: AxiosRequestConfig<any>) => Promise<Reading<string>>;
704
+ removeReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<Reading<string>>;
706
705
  getReadingSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
707
- getReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<Report<string | bson.ObjectId>>;
708
- listReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Report<string | bson.ObjectId>>>;
709
- updateReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
710
- createReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
711
- removeReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
706
+ getReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<Report<string>>;
707
+ listReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Report<string>>>;
708
+ updateReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Report<string>>;
709
+ createReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<Report<string>>;
710
+ removeReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<Report<string>>;
712
711
  sendReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
713
712
  getReportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
714
713
  listReportTemplates: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
@@ -721,18 +720,18 @@ declare const _default$3: (auth: AuthOptions, instanceOptions?: CreateAxiosDefau
721
720
  createScheduledReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
722
721
  removeScheduledReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
723
722
  sendScheduledReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
724
- getInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<Invoice<string | bson.ObjectId>>;
725
- listInvoices: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Invoice<string | bson.ObjectId>>>;
726
- updateInvoice: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
727
- createInvoice: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
728
- removeInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
723
+ getInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<Invoice<string>>;
724
+ listInvoices: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Invoice<string>>>;
725
+ updateInvoice: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<Invoice<string>>;
726
+ createInvoice: (data: any, options?: AxiosRequestConfig<any>) => Promise<Invoice<string>>;
727
+ removeInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<Invoice<string>>;
729
728
  getInvoiceSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
730
- listSuppliers: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Supplier<string | bson.ObjectId>>>;
729
+ listSuppliers: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Supplier<string>>>;
731
730
  getSupplierSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
732
731
  getImportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
733
- updateDataIngest: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
734
- createDataIngest: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
735
- listDataIngest: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<DataIngest<string | bson.ObjectId>>>;
732
+ listDataIngest: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<DataIngest<string>>>;
733
+ updateDataIngest: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<DataIngest<string>>;
734
+ createDataIngest: (data: any, options?: AxiosRequestConfig<any>) => Promise<DataIngest<string>>;
736
735
  };
737
736
 
738
737
  declare const _default$2: (namespace: string) => winston.Logger;
package/dist/index.js CHANGED
@@ -337,9 +337,9 @@ var api_default = (auth, instanceOptions = {}) => {
337
337
  // import templates
338
338
  getImportTemplate: factory.getWithId(etainablApi, "import-templates"),
339
339
  //data imports
340
+ listDataIngest: factory.list(etainablApi, "data-ingests"),
340
341
  updateDataIngest: factory.update(etainablApi, "data-ingests"),
341
- createDataIngest: factory.create(etainablApi, "data-ingests"),
342
- listDataIngest: factory.list(etainablApi, "data-ingests")
342
+ createDataIngest: factory.create(etainablApi, "data-ingests")
343
343
  };
344
344
  } catch (e) {
345
345
  log.error(e);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/api.ts","../src/logger.ts","../src/db.ts","../src/slack.ts","../src/units.ts","../src/consumption.ts","../src/monitoring.ts","../src/reporting.ts"],"sourcesContent":["import api from './api.js';\nimport logger from './logger.js';\nimport db from './db.js';\nimport slack from './slack.js';\nimport * as units from './units.js';\nimport * as consumption from './consumption.js';\nimport * as monitoring from './monitoring.js';\nimport * as reporting from './reporting.js';\n\nexport {\n api,\n logger,\n consumption,\n monitoring,\n db,\n slack,\n units,\n reporting\n}\n\nexport * from './types/index.js';","import axios from 'axios';\nimport type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults, AxiosResponse } from 'axios';\nimport https from 'https';\n\nimport logger from './logger.js';\n\nimport type { Account, Asset, Automation, Entity, Company, DataIngest, Invoice, Log, Reading, Report, Supplier } from './types/index.js'\n\nconst log = logger('etainablApi');\n\nexport interface ETNPagedResponse<T = any> {\n data: T[];\n total: number;\n limit: number;\n skip: number;\n}\n\nexport interface ETNReq {\n method: string;\n url: string;\n}\n\nfunction _handleResponse(req: ETNReq, res: AxiosResponse, isPaged = false) {\n if (!res) {\n throw new Error(`No response from API (${req.method} ${req.url})`);\n }\n\n if (res.status !== 200) {\n throw new Error(`${res.status} ${res.statusText} response from API (${req.method} ${req.url})`);\n }\n\n if (!res.data) {\n throw new Error(`No data from API (${req.method} ${req.url})`);\n }\n\n if (isPaged && !res.data.data) {\n throw new Error(`No data from API (${req.method} ${req.url})`);\n }\n\n return res;\n}\n\nconst factory = {\n getWithId: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'GET',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n\n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n _handleResponse(req, res)\n\n return res.data;\n },\n get: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'GET',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n\n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n _handleResponse(req, res)\n\n return res.data;\n },\n list: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<ETNPagedResponse<T>> => {\n const req = {\n method: 'GET',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n \n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n _handleResponse(req, res, true)\n\n return res.data;\n },\n update: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => {\n const req = {\n method: 'PATCH',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n \n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.patch(req.url, data, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n },\n create: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (data: any, options: AxiosRequestConfig = {}) => {\n const req = {\n method: 'POST',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.post(req.url, data, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n },\n remove: (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}) => {\n const req = {\n method: 'DELETE',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n let res: AxiosResponse;\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n try {\n res = await etainablApi.delete(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res);\n\n return res.data;\n },\n customWithId: (etainablApi: AxiosInstance, method: string, endpoint: string, postEndpoint?: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => {\n const req = {\n method: method,\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`,\n data,\n ...options\n };\n \n log.info(`API Request (Custom): ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.request(req);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n }\n};\n\n// ETN Sub Endpoints\n// e.g. /assets/:id/documents/:documentId\nconst subFactory = {\n // e.g. POST /assets/:id/documents\n create: (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => { \n const subUrl = `${id}/${subEndpoint}`;\n return factory.create(etainablApi, endpoint, subUrl)(data, options);\n },\n // e.g. PATCH /assets/:id/documents/:documentId\n update: (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, subId: string, data: any, options: AxiosRequestConfig = {}) => {\n const subUrl = `${subEndpoint}/${subId}`;\n \n return factory.update(etainablApi, endpoint, subUrl)(id, data, options);\n },\n // e.g. DELETE /assets/:id/documents/:documentId\n remove: (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, subId: string, options: AxiosRequestConfig = {}) => {\n const subUrl = `${subEndpoint}/${subId}`;\n \n return factory.remove(etainablApi, endpoint, subUrl)(id, options);\n }\n}\n\ninterface AuthOptions {\n key?: string;\n token?: string;\n}\n\nexport default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) => {\n try {\n const headers: any = {};\n\n if (auth.key) {\n headers['x-key'] = auth.key;\n } else if (auth.token) {\n headers['Authorization'] = auth.token;\n } else {\n headers['x-key'] = process.env.ETAINABL_API_KEY;\n }\n \n const etainablApi = axios.create({\n baseURL: process.env.ETAINABL_API_URL,\n timeout: 300000,\n httpsAgent: new https.Agent({ keepAlive: true }),\n headers,\n ...instanceOptions\n });\n \n return {\n instance: etainablApi,\n \n // accounts\n getAccount: factory.getWithId<Account>(etainablApi, 'accounts'),\n listAccounts: factory.list<Account>(etainablApi, 'accounts'),\n updateAccount: factory.update(etainablApi, 'accounts'),\n createAccount: factory.create(etainablApi, 'accounts'),\n removeAccount: factory.remove(etainablApi, 'accounts'),\n getAccountSchema: factory.get(etainablApi, 'accounts', 'schema'),\n invalidateAccountCache: factory.customWithId(etainablApi, 'put', 'accounts', 'invalidate-cache'),\n\n // assets\n getAsset: factory.getWithId<Asset>(etainablApi, 'assets'),\n listAssets: factory.list<Asset>(etainablApi, 'assets'),\n updateAsset: factory.update(etainablApi, 'assets'),\n createAsset: factory.create(etainablApi, 'assets'),\n removeAsset: factory.remove(etainablApi, 'assets'),\n getAssetSchema: factory.get(etainablApi, 'assets', 'schema'),\n \n // assetGroups\n getAssetGroup: factory.getWithId(etainablApi, 'asset-groups'),\n listAssetGroups: factory.list(etainablApi, 'asset-groups'),\n updateAssetGroup: factory.update(etainablApi, 'asset-groups'),\n createAssetGroup: factory.create(etainablApi, 'asset-groups'),\n removeAssetGroup: factory.remove(etainablApi, 'asset-groups'),\n getAssetGroupAssets: factory.getWithId(etainablApi, 'asset-groups', 'assets'),\n getAssetGroupSchema: factory.get(etainablApi, 'asset-groups', 'schema'),\n \n // automation\n getAutomation: factory.getWithId<Automation>(etainablApi, 'automation'),\n listAutomations: factory.list<Automation>(etainablApi, 'automation'),\n updateAutomation: factory.update(etainablApi, 'automation'),\n createAutomation: factory.create(etainablApi, 'automation'),\n removeAutomation: factory.remove(etainablApi, 'automation'),\n createAutomationLog: subFactory.create(etainablApi, 'automation', 'logs'),\n updateAutomationLog: subFactory.update(etainablApi, 'automation', 'logs'),\n removeAutomationLog: subFactory.remove(etainablApi, 'automation', 'logs'),\n \n // company\n getCompany: factory.getWithId<Company>(etainablApi, 'companies'),\n \n // consumption\n getConsumption: factory.getWithId(etainablApi, 'consumptions'),\n listConsumptions: factory.list(etainablApi, 'consumptions'),\n updateConsumption: factory.update(etainablApi, 'consumptions'),\n createConsumption: factory.create(etainablApi, 'consumptions'),\n removeConsumption: factory.remove(etainablApi, 'consumptions'),\n getConsumptionSchema: factory.get(etainablApi, 'consumptions', 'schema'),\n \n // emails\n getEmail: factory.getWithId(etainablApi, 'emails'),\n listEmails: factory.list(etainablApi, 'emails'),\n updateEmail: factory.update(etainablApi, 'emails'),\n createEmail: factory.create(etainablApi, 'emails'),\n removeEmail: factory.remove(etainablApi, 'emails'),\n \n // emission factors\n getEmissionFactor: factory.getWithId(etainablApi, 'emission-factors'),\n listEmissionFactors: factory.list(etainablApi, 'emission-factors'),\n updateEmissionFactor: factory.update(etainablApi, 'emission-factors'),\n createEmissionFactor: factory.create(etainablApi, 'emission-factors'),\n removeEmissionFactor: factory.remove(etainablApi, 'emission-factors'),\n\n // entity\n getEntity: factory.getWithId<Entity>(etainablApi, 'entities'),\n listEntities: factory.list<Entity>(etainablApi, 'entities'),\n updateEntity: factory.update(etainablApi, 'entities'),\n createEntity: factory.create(etainablApi, 'entities'),\n removeEntity: factory.remove(etainablApi, 'entities'),\n getEntitiesSchema: factory.get(etainablApi, 'entities', 'schema'),\n \n \n // logs\n getLog: factory.getWithId<Log>(etainablApi, 'logs'),\n listLogs: factory.list<Log>(etainablApi, 'logs'),\n updateLog: factory.update(etainablApi, 'logs'),\n createLog: factory.create(etainablApi, 'logs'),\n removeLog: factory.remove(etainablApi, 'logs'),\n \n // readings\n getReading: factory.getWithId<Reading>(etainablApi, 'readings'),\n listReadings: factory.list<Reading>(etainablApi, 'readings'),\n updateReading: factory.update(etainablApi, 'readings'),\n createReading: factory.create(etainablApi, 'readings'),\n removeReading: factory.remove(etainablApi, 'readings'),\n getReadingSchema: factory.get(etainablApi, 'readings', 'schema'),\n \n // reports\n getReport: factory.getWithId<Report>(etainablApi, 'reports'),\n listReports: factory.list<Report>(etainablApi, 'reports'),\n updateReport: factory.update(etainablApi, 'reports'),\n createReport: factory.create(etainablApi, 'reports'),\n removeReport: factory.remove(etainablApi, 'reports'),\n sendReport: factory.customWithId(etainablApi, 'post', 'reports', 'send'),\n \n // report templates\n getReportTemplate: factory.getWithId(etainablApi, 'report-templates'),\n listReportTemplates: factory.list(etainablApi, 'report-templates'),\n updateReportTemplate: factory.update(etainablApi, 'report-templates'),\n createReportTemplate: factory.create(etainablApi, 'report-templates'),\n removeReportTemplate: factory.remove(etainablApi, 'report-templates'),\n \n // scheduled reports\n getScheduledReport: factory.getWithId(etainablApi, 'scheduled-reports'),\n listScheduledReports: factory.list(etainablApi, 'scheduled-reports'),\n updateScheduledReport: factory.update(etainablApi, 'scheduled-reports'),\n createScheduledReport: factory.create(etainablApi, 'scheduled-reports'),\n removeScheduledReport: factory.remove(etainablApi, 'scheduled-reports'),\n sendScheduledReport: factory.customWithId(etainablApi, 'post', 'scheduled-reports', 'send'),\n \n // invoices\n getInvoice: factory.getWithId<Invoice>(etainablApi, 'invoices'),\n listInvoices: factory.list<Invoice>(etainablApi, 'invoices'),\n updateInvoice: factory.update(etainablApi, 'invoices'),\n createInvoice: factory.create(etainablApi, 'invoices'),\n removeInvoice: factory.remove(etainablApi, 'invoices'),\n getInvoiceSchema: factory.get(etainablApi, 'invoices', 'schema'),\n\n //suppliers\n listSuppliers: factory.list<Supplier>(etainablApi, 'suppliers'),\n getSupplierSchema: factory.get(etainablApi, 'suppliers', 'schema'),\n\n // import templates\n getImportTemplate: factory.getWithId(etainablApi, 'import-templates'),\n\n //data imports\n updateDataIngest: factory.update(etainablApi, 'data-ingests'),\n createDataIngest: factory.create(etainablApi, 'data-ingests'),\n listDataIngest: factory.list<DataIngest>(etainablApi, 'data-ingests'),\n\n }\n } catch (e) {\n log.error(e);\n throw e;\n }\n};\n","import winston from 'winston';\n\nexport default (namespace: string) => winston.createLogger({\n level: 'debug',\n format: winston.format.combine(\n winston.format.timestamp(),\n winston.format.json()\n ),\n defaultMeta: { service: process.env.AWS_LAMBDA_FUNCTION_NAME, script: namespace },\n transports: [\n new winston.transports.Console()\n ]\n});\n","import { MongoClient, Db } from 'mongodb';\nimport logger from './logger.js';\n\nconst log = logger('dbHelpers');\n\nlet cachedDb: Db;\n\nasync function connectToDatabase(retryAttempt: number = 1): Promise<Db> {\n if (!process.env.ETAINABL_DB_URL) throw new Error(\"ETAINABL_DB_URL is not set\");\n if (!process.env.AWS_ACCESS_KEY_ID) throw new Error(\"AWS_ACCESS_KEY_ID is not set\");\n if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error(\"AWS_SECRET_ACCESS_KEY is not set\");\n\n if (cachedDb) {\n log.debug('Using cached MongoDB connection.');\n return Promise.resolve(cachedDb);\n }\n \n const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;\n \n try {\n if (process.env.DB_BASIC_AUTH === 'true') {\n log.debug('Connecting to MongoDB server... (Auth: Basic)');\n\n const client = new MongoClient(uri);\n await client.connect();\n\n log.debug('Connected successfully to MongoDB server! (Auth: Basic)');\n\n cachedDb = client.db('etainabl');\n\n return cachedDb;\n }\n\n log.debug('Connecting to MongoDB server... (Auth: AWS)');\n\n const client = new MongoClient(uri, {\n auth: {\n username: process.env.AWS_ACCESS_KEY_ID,\n password: process.env.AWS_SECRET_ACCESS_KEY\n },\n authSource: '$external',\n authMechanism: 'MONGODB-AWS'\n });\n\n await client.connect();\n\n log.debug('Connected successfully to MongoDB server! (Auth: AWS)');\n\n cachedDb = client.db('etainabl');\n\n return cachedDb;\n\n } catch (e: any) {\n // Retry\n if (retryAttempt > 5) {\n console.log(`Error connecting to MongoDB server after 5 attempts...`);\n throw e;\n }\n\n console.log(`MongoDB Connection error: ${e.message}`);\n\n console.log(`Error connecting to MongoDB server... Retrying in 3 seconds... (Attempt ${retryAttempt})`);\n return connectToDatabase(retryAttempt + 1);\n }\n}\n\nexport default {\n connectToDatabase\n};","import axios from 'axios';\n\nconst postMessage = async (message: string) => {\n const url = 'https://hooks.slack.com/services/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';\n const data = {\n text: `[${(process.env.ENV || '').toUpperCase()}][${process.env.AWS_LAMBDA_FUNCTION_NAME}] ${message}`\n };\n const headers = {\n 'Content-Type': 'application/json'\n };\n return axios.post(url, data, { headers });\n};\n\nexport default {\n postMessage\n}","interface Item {\n units?: string | null;\n unit?: string | null;\n factor?: number | null;\n value: number;\n [key: string]: any; \n}\n\nexport type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'oil' | 'other';\nexport type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';\nexport type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h' | 'l';\nexport const accountTypeMap: { [key: string]: BaseUnit } = {\n electricity: 'kwh',\n gas: 'kwh',\n water: 'm3',\n waste: 'kg',\n solar: 'kwh',\n heating: 'kwh',\n flow: 'm3/h',\n cooling: 'kwh',\n temperature: 'C',\n oil: 'l'\n};\n\nconst unitConversionFactors: { [key: string]: any } = {\n kwh: {\n kwh: 1,\n mwh: 1000,\n wh: 0.001,\n m3: (39 * 1.02264) / 3.6,\n ft3: (0.0283 * 39 * 1.02264) / 3.6,\n hcf: (2.83 * 39 * 1.02264) / 3.6\n },\n m3: {\n m3: 1,\n l: 0.001\n },\n C: {\n C: 1\n },\n kg: {\n kg: 1,\n lbs: 0.45359237,\n tonnes: 1000\n },\n 'm3/h': {\n 'm3/h': 1\n }\n};\n\nexport const accountTypeUnitMap: { [key: string]: ETNUnit[] } = {\n electricity: ['kwh', 'mwh', 'wh'],\n gas: ['kwh', 'm3', 'ft3', 'hcf'],\n water: ['m3', 'l'],\n waste: ['kg', 'lbs', 'tonnes'],\n solar: ['kwh', 'mwh', 'wh'],\n heating: ['kwh', 'mwh', 'wh'],\n flow: ['m3/h'],\n cooling: ['kwh', 'mwh', 'wh'],\n temperature: ['C'],\n oil: ['l']\n};\n\n// Convert units to base format\nexport const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined): any => {\n if (!type) throw new Error('Account type is required');\n\n const baseUnit = accountTypeMap[type];\n if (!baseUnit) throw new Error(`Account type ${type} is not supported`);\n\n const convertedItems = items.map(item => {\n const factor = item.factor || accountFactor || 1;\n const units = item.units || item.unit || defaultUnits || baseUnit;\n const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;\n return { ...item, value: convertedValue, units: baseUnit };\n });\n\n return convertedItems;\n};\n\nconst _getConversionFactor = (fromUnit: string = 'kwh', toUnit: string) => {\n const conversionFactors = unitConversionFactors[toUnit];\n\n if (!conversionFactors) {\n throw new Error(`Conversion factor base unit ${toUnit} is not defined`);\n }\n\n if (!conversionFactors[fromUnit]) {\n throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);\n }\n\n return conversionFactors[fromUnit];\n};\n\nexport const checkAccountTypeVsUnits = (type: string, unit: string, additionalLog: number | '' = '') => {\n if (!type) throw new Error('Account type is required');\n if (!unit) throw new Error('Unit is required');\n\n const parsedType = type.toLowerCase().trim();\n\n const accountTypeUnits = accountTypeUnitMap[parsedType];\n if (!accountTypeUnits) throw new Error(`Account type \"${parsedType}\" is not supported ${additionalLog}`);\n\n const parsedUnit = unit.toLowerCase().trim() as ETNUnit;\n\n if (!accountTypeUnits.includes(parsedUnit)) {\n throw new Error(`Account type \"${parsedType}\" does not support unit \"${parsedUnit}\" ${additionalLog}`);\n }\n\n return { type: parsedType as AccountType, unit: parsedUnit};\n};\n","import moment from 'moment';\n\ninterface ConsumptionData {\n date: Date;\n consumption: number;\n}\n\ninterface DayNightConsumption {\n dayConsumption: number,\n nightConsumption: number,\n consumption: number\n}\n\nexport const dayNightConsumption = (data: ConsumptionData[]) => data.reduce((acc: DayNightConsumption, item: ConsumptionData): DayNightConsumption => {\n const hour = moment.utc(item.date).hour(); // End Time of HH consumption period\n\n if (hour >= 0 && hour < 7) {\n acc.nightConsumption += item.consumption;\n } else {\n acc.dayConsumption += item.consumption;\n }\n\n acc.consumption += item.consumption;\n\n return acc;\n}, {\n dayConsumption: 0,\n nightConsumption: 0,\n consumption: 0\n});\n\nexport const calcMaxConsumptionValue = (data: ConsumptionData[]) => Math.max(...data.map((item: ConsumptionData) => item.consumption));\n\nexport const calcMaxDemand = (data: ConsumptionData[]) => calcMaxConsumptionValue(data) * 2;\n\nexport const calcPeakLoad = (consumption: number, maxDemand: number, startDate: string | moment.Moment, endDate: string | moment.Moment) => {\n const days = Math.ceil(moment(endDate).diff(moment(startDate), 'days', true));\n\n return maxDemand === 0 ? 0 : ((consumption / (maxDemand * 24 * days)) * 100);\n};","import axios from 'axios';\n\nimport logger from './logger.js';\n\nconst log = logger('monitoring');\n\nexport const sendHeartbeat = async () => {\n if (!process.env.HEARTBEAT_URL || process.env.HEARTBEAT_URL.endsWith('/')) return false;\n\n try {\n await axios.post(process.env.HEARTBEAT_URL);\n\n return true;\n } catch (e: any) {\n log.warn(`Failed to send heartbeat: ${e.message || e}`);\n return false;\n }\n}","import moment from 'moment';\n\nmoment.locale('en', {\n week: {\n dow: 1\n }\n});\n\nconst getNextRunTime = (startDate: moment.Moment, schedule: any, taskTime: moment.Moment): moment.Moment => {\n const [num, freq] = schedule.frequency.split('|');\n const targetDate = moment(startDate).add(num, freq as moment.unitOfTime.Base);\n\n if (schedule.frequencyPeriod === 'first') {\n targetDate.startOf(freq as moment.unitOfTime.StartOf);\n } else if (schedule.frequencyPeriod === 'last') {\n targetDate.endOf(freq as moment.unitOfTime.StartOf);\n }\n\n const isWeekday = targetDate.isoWeekday() > 0 && targetDate.isoWeekday() < 6;\n const isSaturday = targetDate.isoWeekday() === 6;\n\n // The weekday or weekend chosen should be within the same month as the target date\n if (schedule.frequencyDay === 'weekdays' && !isWeekday) {\n if ((targetDate.date() / 7) < 2) {\n targetDate.add(isSaturday ? 2 : 1, 'days');\n } else {\n targetDate.subtract(isSaturday ? 1 : 2, 'days');\n }\n } else if (schedule.frequencyDay === 'weekends' && isWeekday) {\n if ((targetDate.date() / 7) < 2) {\n targetDate.isoWeekday(6);\n } else {\n targetDate.isoWeekday(0);\n }\n }\n\n if (taskTime.isAfter(targetDate, 'minute')) {\n return getNextRunTime(targetDate, schedule, taskTime);\n }\n\n return targetDate;\n};\n\nexport const getScheduledReportRunTimes = (schedule: any, limit = 1, taskTime = moment()): moment.Moment[] => {\n if (!schedule.startDate || !schedule.enabled) return [];\n\n const originalStartDate = moment.utc(schedule.startDate);\n\n let startDate = originalStartDate;\n\n const includeStartDate = taskTime.isSameOrBefore(originalStartDate, 'minute');\n\n let runTimes = [] as moment.Moment[];\n\n if (includeStartDate) {\n runTimes = [originalStartDate];\n }\n\n const [, freq] = schedule.frequency.split('|');\n\n if (freq === 'once') {\n const nextRunTime = runTimes[0];\n\n // If this is now beyond the start date, return an empty array\n return taskTime.isAfter(nextRunTime, 'minute') ? [] : runTimes;\n }\n\n\n const scheduleRunTimes = Array.from(Array(includeStartDate ? limit - 1 : limit).keys()).map(() => {\n const nextRunTime = getNextRunTime(startDate, schedule, taskTime);\n\n startDate = nextRunTime.hour(originalStartDate.hour()).minute(originalStartDate.minute());\n\n return nextRunTime;\n });\n\n return [...runTimes, ...scheduleRunTimes];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAElB,mBAAkB;;;ACFlB,qBAAoB;AAEpB,IAAO,iBAAQ,CAAC,cAAsB,eAAAA,QAAQ,aAAa;AAAA,EACzD,OAAO;A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M,oBAAoB,eAAAA,QAAO,IAAI,SAAS,SAAS;AAEvD,MAAI,YAAY;AAEhB,QAAM,mBAAmB,SAAS,eAAe,mBAAmB,QAAQ;AAE5E,MAAI,WAAW,CAAC;AAEhB,MAAI,kBAAkB;AACpB,eAAW,CAAC,iBAAiB;AAAA,EAC/B;AAEA,QAAM,CAAC,EAAE,IAAI,IAAI,SAAS,UAAU,MAAM,GAAG;AAE7C,MAAI,SAAS,QAAQ;AACnB,UAAM,cAAc,SAAS,CAAC;AAG9B,WAAO,SAAS,QAAQ,aAAa,QAAQ,IAAI,CAAC,IAAI;AAAA,EACxD;AAGA,QAAM,mBAAmB,MAAM,KAAK,MAAM,mBAAmB,QAAQ,IAAI,KAAK,EAAE,KAAK,CAAC,EAAE,IAAI,MAAM;AAChG,UAAM,cAAc,eAAe,WAAW,UAAU,QAAQ;AAEhE,gBAAY,YAAY,KAAK,kBAAkB,KAAK,CAAC,EAAE,OAAO,kBAAkB,OAAO,CAAC;AAExF,WAAO;AAAA,EACT,CAAC;AAED,SAAO,CAAC,GAAG,UAAU,GAAG,gBAAgB;AAC1C;","names":["winston","axios","https","log","client","import_axios","axios","moment","import_axios","log","axios","import_moment","moment"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/api.ts","../src/logger.ts","../src/db.ts","../src/slack.ts","../src/units.ts","../src/consumption.ts","../src/monitoring.ts","../src/reporting.ts"],"sourcesContent":["import api from './api.js';\nimport logger from './logger.js';\nimport db from './db.js';\nimport slack from './slack.js';\nimport * as units from './units.js';\nimport * as consumption from './consumption.js';\nimport * as monitoring from './monitoring.js';\nimport * as reporting from './reporting.js';\n\nexport {\n api,\n logger,\n consumption,\n monitoring,\n db,\n slack,\n units,\n reporting\n}\n\nexport * from './types/index.js';","import axios from 'axios';\nimport type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults, AxiosResponse } from 'axios';\nimport https from 'https';\n\nimport logger from './logger.js';\n\nimport type { Account, Asset, Automation, Entity, Company, DataIngest, Invoice, Log, Reading, Report, Supplier } from './types/index.js'\n\nconst log = logger('etainablApi');\n\nexport interface ETNPagedResponse<T = any> {\n data: T[];\n total: number;\n limit: number;\n skip: number;\n}\n\nexport interface ETNReq {\n method: string;\n url: string;\n}\n\nfunction _handleResponse(req: ETNReq, res: AxiosResponse, isPaged = false) {\n if (!res) {\n throw new Error(`No response from API (${req.method} ${req.url})`);\n }\n\n if (res.status !== 200) {\n throw new Error(`${res.status} ${res.statusText} response from API (${req.method} ${req.url})`);\n }\n\n if (!res.data) {\n throw new Error(`No data from API (${req.method} ${req.url})`);\n }\n\n if (isPaged && !res.data.data) {\n throw new Error(`No data from API (${req.method} ${req.url})`);\n }\n\n return res;\n}\n\nconst factory = {\n getWithId: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'GET',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n\n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n _handleResponse(req, res)\n\n return res.data;\n },\n get: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'GET',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n\n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n _handleResponse(req, res)\n\n return res.data;\n },\n list: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (options: AxiosRequestConfig = {}): Promise<ETNPagedResponse<T>> => {\n const req = {\n method: 'GET',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n \n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.get(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n _handleResponse(req, res, true)\n\n return res.data;\n },\n update: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, data: any, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'PATCH',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n \n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.patch(req.url, data, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n },\n create: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (data: any, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'POST',\n url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.post(req.url, data, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n },\n remove: <T = any> (etainablApi: AxiosInstance, endpoint: string, postEndpoint?: string) => async (id: string, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: 'DELETE',\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`\n };\n\n let res: AxiosResponse;\n\n log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n try {\n res = await etainablApi.delete(req.url, options);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res);\n\n return res.data;\n },\n customWithId: <T = any> (etainablApi: AxiosInstance, method: string, endpoint: string, postEndpoint?: string) => async (id: string, data: any, options: AxiosRequestConfig = {}): Promise<T> => {\n const req = {\n method: method,\n url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`,\n data,\n ...options\n };\n \n log.info(`API Request (Custom): ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);\n\n let res: AxiosResponse;\n \n try {\n res = await etainablApi.request(req);\n } catch (e: any) {\n if (e.response?.data) throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);\n throw e;\n }\n\n _handleResponse(req, res)\n\n return res.data;\n }\n};\n\n// ETN Sub Endpoints\n// e.g. /assets/:id/documents/:documentId\nconst subFactory = {\n // e.g. POST /assets/:id/documents\n create: <T = any> (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, data: any, options: AxiosRequestConfig = {}) => { \n const subUrl = `${id}/${subEndpoint}`;\n return factory.create<T>(etainablApi, endpoint, subUrl)(data, options);\n },\n // e.g. PATCH /assets/:id/documents/:documentId\n update: <T = any> (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, subId: string, data: any, options: AxiosRequestConfig = {}) => {\n const subUrl = `${subEndpoint}/${subId}`;\n \n return factory.update<T>(etainablApi, endpoint, subUrl)(id, data, options);\n },\n // e.g. DELETE /assets/:id/documents/:documentId\n remove: <T = any> (etainablApi: AxiosInstance, endpoint: string, subEndpoint: string) => async (id: string, subId: string, options: AxiosRequestConfig = {}) => {\n const subUrl = `${subEndpoint}/${subId}`;\n \n return factory.remove<T>(etainablApi, endpoint, subUrl)(id, options);\n }\n}\n\ninterface AuthOptions {\n key?: string;\n token?: string;\n}\n\nexport default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) => {\n try {\n const headers: any = {};\n\n if (auth.key) {\n headers['x-key'] = auth.key;\n } else if (auth.token) {\n headers['Authorization'] = auth.token;\n } else {\n headers['x-key'] = process.env.ETAINABL_API_KEY;\n }\n \n const etainablApi = axios.create({\n baseURL: process.env.ETAINABL_API_URL,\n timeout: 300000,\n httpsAgent: new https.Agent({ keepAlive: true }),\n headers,\n ...instanceOptions\n });\n \n return {\n instance: etainablApi,\n \n // accounts\n getAccount: factory.getWithId<Account<string>>(etainablApi, 'accounts'),\n listAccounts: factory.list<Account<string>>(etainablApi, 'accounts'),\n updateAccount: factory.update<Account<string>>(etainablApi, 'accounts'),\n createAccount: factory.create<Account<string>>(etainablApi, 'accounts'),\n removeAccount: factory.remove<Account<string>>(etainablApi, 'accounts'),\n getAccountSchema: factory.get(etainablApi, 'accounts', 'schema'),\n invalidateAccountCache: factory.customWithId(etainablApi, 'put', 'accounts', 'invalidate-cache'),\n\n // assets\n getAsset: factory.getWithId<Asset<string>>(etainablApi, 'assets'),\n listAssets: factory.list<Asset<string>>(etainablApi, 'assets'),\n updateAsset: factory.update<Asset<string>>(etainablApi, 'assets'),\n createAsset: factory.create<Asset<string>>(etainablApi, 'assets'),\n removeAsset: factory.remove<Asset<string>>(etainablApi, 'assets'),\n getAssetSchema: factory.get(etainablApi, 'assets', 'schema'),\n \n // assetGroups\n getAssetGroup: factory.getWithId(etainablApi, 'asset-groups'),\n listAssetGroups: factory.list(etainablApi, 'asset-groups'),\n updateAssetGroup: factory.update(etainablApi, 'asset-groups'),\n createAssetGroup: factory.create(etainablApi, 'asset-groups'),\n removeAssetGroup: factory.remove(etainablApi, 'asset-groups'),\n getAssetGroupAssets: factory.getWithId(etainablApi, 'asset-groups', 'assets'),\n getAssetGroupSchema: factory.get(etainablApi, 'asset-groups', 'schema'),\n \n // automation\n getAutomation: factory.getWithId<Automation<string>>(etainablApi, 'automation'),\n listAutomations: factory.list<Automation<string>>(etainablApi, 'automation'),\n updateAutomation: factory.update<Automation<string>>(etainablApi, 'automation'),\n createAutomation: factory.create<Automation<string>>(etainablApi, 'automation'),\n removeAutomation: factory.remove<Automation<string>>(etainablApi, 'automation'),\n createAutomationLog: subFactory.create(etainablApi, 'automation', 'logs'),\n updateAutomationLog: subFactory.update(etainablApi, 'automation', 'logs'),\n removeAutomationLog: subFactory.remove(etainablApi, 'automation', 'logs'),\n \n // company\n getCompany: factory.getWithId<Company<string>>(etainablApi, 'companies'),\n \n // consumption\n getConsumption: factory.getWithId(etainablApi, 'consumptions'),\n listConsumptions: factory.list(etainablApi, 'consumptions'),\n updateConsumption: factory.update(etainablApi, 'consumptions'),\n createConsumption: factory.create(etainablApi, 'consumptions'),\n removeConsumption: factory.remove(etainablApi, 'consumptions'),\n getConsumptionSchema: factory.get(etainablApi, 'consumptions', 'schema'),\n \n // emails\n getEmail: factory.getWithId(etainablApi, 'emails'),\n listEmails: factory.list(etainablApi, 'emails'),\n updateEmail: factory.update(etainablApi, 'emails'),\n createEmail: factory.create(etainablApi, 'emails'),\n removeEmail: factory.remove(etainablApi, 'emails'),\n \n // emission factors\n getEmissionFactor: factory.getWithId(etainablApi, 'emission-factors'),\n listEmissionFactors: factory.list(etainablApi, 'emission-factors'),\n updateEmissionFactor: factory.update(etainablApi, 'emission-factors'),\n createEmissionFactor: factory.create(etainablApi, 'emission-factors'),\n removeEmissionFactor: factory.remove(etainablApi, 'emission-factors'),\n\n // entity\n getEntity: factory.getWithId<Entity<string>>(etainablApi, 'entities'),\n listEntities: factory.list<Entity<string>>(etainablApi, 'entities'),\n updateEntity: factory.update<Entity<string>>(etainablApi, 'entities'),\n createEntity: factory.create<Entity<string>>(etainablApi, 'entities'),\n removeEntity: factory.remove<Entity<string>>(etainablApi, 'entities'),\n getEntitiesSchema: factory.get(etainablApi, 'entities', 'schema'),\n \n \n // logs\n getLog: factory.getWithId<Log<string>>(etainablApi, 'logs'),\n listLogs: factory.list<Log<string>>(etainablApi, 'logs'),\n updateLog: factory.update<Log<string>>(etainablApi, 'logs'),\n createLog: factory.create<Log<string>>(etainablApi, 'logs'),\n removeLog: factory.remove<Log<string>>(etainablApi, 'logs'),\n \n // readings\n getReading: factory.getWithId<Reading<string>>(etainablApi, 'readings'),\n listReadings: factory.list<Reading<string>>(etainablApi, 'readings'),\n updateReading: factory.update<Reading<string>>(etainablApi, 'readings'),\n createReading: factory.create<Reading<string>>(etainablApi, 'readings'),\n removeReading: factory.remove<Reading<string>>(etainablApi, 'readings'),\n getReadingSchema: factory.get(etainablApi, 'readings', 'schema'),\n \n // reports\n getReport: factory.getWithId<Report<string>>(etainablApi, 'reports'),\n listReports: factory.list<Report<string>>(etainablApi, 'reports'),\n updateReport: factory.update<Report<string>>(etainablApi, 'reports'),\n createReport: factory.create<Report<string>>(etainablApi, 'reports'),\n removeReport: factory.remove<Report<string>>(etainablApi, 'reports'),\n sendReport: factory.customWithId(etainablApi, 'post', 'reports', 'send'),\n \n // report templates\n getReportTemplate: factory.getWithId(etainablApi, 'report-templates'),\n listReportTemplates: factory.list(etainablApi, 'report-templates'),\n updateReportTemplate: factory.update(etainablApi, 'report-templates'),\n createReportTemplate: factory.create(etainablApi, 'report-templates'),\n removeReportTemplate: factory.remove(etainablApi, 'report-templates'),\n \n // scheduled reports\n getScheduledReport: factory.getWithId(etainablApi, 'scheduled-reports'),\n listScheduledReports: factory.list(etainablApi, 'scheduled-reports'),\n updateScheduledReport: factory.update(etainablApi, 'scheduled-reports'),\n createScheduledReport: factory.create(etainablApi, 'scheduled-reports'),\n removeScheduledReport: factory.remove(etainablApi, 'scheduled-reports'),\n sendScheduledReport: factory.customWithId(etainablApi, 'post', 'scheduled-reports', 'send'),\n \n // invoices\n getInvoice: factory.getWithId<Invoice<string>>(etainablApi, 'invoices'),\n listInvoices: factory.list<Invoice<string>>(etainablApi, 'invoices'),\n updateInvoice: factory.update<Invoice<string>>(etainablApi, 'invoices'),\n createInvoice: factory.create<Invoice<string>>(etainablApi, 'invoices'),\n removeInvoice: factory.remove<Invoice<string>>(etainablApi, 'invoices'),\n getInvoiceSchema: factory.get(etainablApi, 'invoices', 'schema'),\n\n //suppliers\n listSuppliers: factory.list<Supplier<string>>(etainablApi, 'suppliers'),\n getSupplierSchema: factory.get(etainablApi, 'suppliers', 'schema'),\n\n // import templates\n getImportTemplate: factory.getWithId(etainablApi, 'import-templates'),\n\n //data imports\n listDataIngest: factory.list<DataIngest<string>>(etainablApi, 'data-ingests'),\n updateDataIngest: factory.update<DataIngest<string>>(etainablApi, 'data-ingests'),\n createDataIngest: factory.create<DataIngest<string>>(etainablApi, 'data-ingests')\n\n }\n } catch (e) {\n log.error(e);\n throw e;\n }\n};\n","import winston from 'winston';\n\nexport default (namespace: string) => winston.createLogger({\n level: 'debug',\n format: winston.format.combine(\n winston.format.timestamp(),\n winston.format.json()\n ),\n defaultMeta: { service: process.env.AWS_LAMBDA_FUNCTION_NAME, script: namespace },\n transports: [\n new winston.transports.Console()\n ]\n});\n","import { MongoClient, Db } from 'mongodb';\nimport logger from './logger.js';\n\nconst log = logger('dbHelpers');\n\nlet cachedDb: Db;\n\nasync function connectToDatabase(retryAttempt: number = 1): Promise<Db> {\n if (!process.env.ETAINABL_DB_URL) throw new Error(\"ETAINABL_DB_URL is not set\");\n if (!process.env.AWS_ACCESS_KEY_ID) throw new Error(\"AWS_ACCESS_KEY_ID is not set\");\n if (!process.env.AWS_SECRET_ACCESS_KEY) throw new Error(\"AWS_SECRET_ACCESS_KEY is not set\");\n\n if (cachedDb) {\n log.debug('Using cached MongoDB connection.');\n return Promise.resolve(cachedDb);\n }\n \n const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;\n \n try {\n if (process.env.DB_BASIC_AUTH === 'true') {\n log.debug('Connecting to MongoDB server... (Auth: Basic)');\n\n const client = new MongoClient(uri);\n await client.connect();\n\n log.debug('Connected successfully to MongoDB server! (Auth: Basic)');\n\n cachedDb = client.db('etainabl');\n\n return cachedDb;\n }\n\n log.debug('Connecting to MongoDB server... (Auth: AWS)');\n\n const client = new MongoClient(uri, {\n auth: {\n username: process.env.AWS_ACCESS_KEY_ID,\n password: process.env.AWS_SECRET_ACCESS_KEY\n },\n authSource: '$external',\n authMechanism: 'MONGODB-AWS'\n });\n\n await client.connect();\n\n log.debug('Connected successfully to MongoDB server! (Auth: AWS)');\n\n cachedDb = client.db('etainabl');\n\n return cachedDb;\n\n } catch (e: any) {\n // Retry\n if (retryAttempt > 5) {\n console.log(`Error connecting to MongoDB server after 5 attempts...`);\n throw e;\n }\n\n console.log(`MongoDB Connection error: ${e.message}`);\n\n console.log(`Error connecting to MongoDB server... Retrying in 3 seconds... (Attempt ${retryAttempt})`);\n return connectToDatabase(retryAttempt + 1);\n }\n}\n\nexport default {\n connectToDatabase\n};","import axios from 'axios';\n\nconst postMessage = async (message: string) => {\n const url = 'https://hooks.slack.com/services/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';\n const data = {\n text: `[${(process.env.ENV || '').toUpperCase()}][${process.env.AWS_LAMBDA_FUNCTION_NAME}] ${message}`\n };\n const headers = {\n 'Content-Type': 'application/json'\n };\n return axios.post(url, data, { headers });\n};\n\nexport default {\n postMessage\n}","interface Item {\n units?: string | null;\n unit?: string | null;\n factor?: number | null;\n value: number;\n [key: string]: any; \n}\n\nexport type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'oil' | 'other';\nexport type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';\nexport type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h' | 'l';\nexport const accountTypeMap: { [key: string]: BaseUnit } = {\n electricity: 'kwh',\n gas: 'kwh',\n water: 'm3',\n waste: 'kg',\n solar: 'kwh',\n heating: 'kwh',\n flow: 'm3/h',\n cooling: 'kwh',\n temperature: 'C',\n oil: 'l'\n};\n\nconst unitConversionFactors: { [key: string]: any } = {\n kwh: {\n kwh: 1,\n mwh: 1000,\n wh: 0.001,\n m3: (39 * 1.02264) / 3.6,\n ft3: (0.0283 * 39 * 1.02264) / 3.6,\n hcf: (2.83 * 39 * 1.02264) / 3.6\n },\n m3: {\n m3: 1,\n l: 0.001\n },\n C: {\n C: 1\n },\n kg: {\n kg: 1,\n lbs: 0.45359237,\n tonnes: 1000\n },\n 'm3/h': {\n 'm3/h': 1\n }\n};\n\nexport const accountTypeUnitMap: { [key: string]: ETNUnit[] } = {\n electricity: ['kwh', 'mwh', 'wh'],\n gas: ['kwh', 'm3', 'ft3', 'hcf'],\n water: ['m3', 'l'],\n waste: ['kg', 'lbs', 'tonnes'],\n solar: ['kwh', 'mwh', 'wh'],\n heating: ['kwh', 'mwh', 'wh'],\n flow: ['m3/h'],\n cooling: ['kwh', 'mwh', 'wh'],\n temperature: ['C'],\n oil: ['l']\n};\n\n// Convert units to base format\nexport const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined): any => {\n if (!type) throw new Error('Account type is required');\n\n const baseUnit = accountTypeMap[type];\n if (!baseUnit) throw new Error(`Account type ${type} is not supported`);\n\n const convertedItems = items.map(item => {\n const factor = item.factor || accountFactor || 1;\n const units = item.units || item.unit || defaultUnits || baseUnit;\n const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;\n return { ...item, value: convertedValue, units: baseUnit };\n });\n\n return convertedItems;\n};\n\nconst _getConversionFactor = (fromUnit: string = 'kwh', toUnit: string) => {\n const conversionFactors = unitConversionFactors[toUnit];\n\n if (!conversionFactors) {\n throw new Error(`Conversion factor base unit ${toUnit} is not defined`);\n }\n\n if (!conversionFactors[fromUnit]) {\n throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);\n }\n\n return conversionFactors[fromUnit];\n};\n\nexport const checkAccountTypeVsUnits = (type: string, unit: string, additionalLog: number | '' = '') => {\n if (!type) throw new Error('Account type is required');\n if (!unit) throw new Error('Unit is required');\n\n const parsedType = type.toLowerCase().trim();\n\n const accountTypeUnits = accountTypeUnitMap[parsedType];\n if (!accountTypeUnits) throw new Error(`Account type \"${parsedType}\" is not supported ${additionalLog}`);\n\n const parsedUnit = unit.toLowerCase().trim() as ETNUnit;\n\n if (!accountTypeUnits.includes(parsedUnit)) {\n throw new Error(`Account type \"${parsedType}\" does not support unit \"${parsedUnit}\" ${additionalLog}`);\n }\n\n return { type: parsedType as AccountType, unit: parsedUnit};\n};\n","import moment from 'moment';\n\ninterface ConsumptionData {\n date: Date;\n consumption: number;\n}\n\ninterface DayNightConsumption {\n dayConsumption: number,\n nightConsumption: number,\n consumption: number\n}\n\nexport const dayNightConsumption = (data: ConsumptionData[]) => data.reduce((acc: DayNightConsumption, item: ConsumptionData): DayNightConsumption => {\n const hour = moment.utc(item.date).hour(); // End Time of HH consumption period\n\n if (hour >= 0 && hour < 7) {\n acc.nightConsumption += item.consumption;\n } else {\n acc.dayConsumption += item.consumption;\n }\n\n acc.consumption += item.consumption;\n\n return acc;\n}, {\n dayConsumption: 0,\n nightConsumption: 0,\n consumption: 0\n});\n\nexport const calcMaxConsumptionValue = (data: ConsumptionData[]) => Math.max(...data.map((item: ConsumptionData) => item.consumption));\n\nexport const calcMaxDemand = (data: ConsumptionData[]) => calcMaxConsumptionValue(data) * 2;\n\nexport const calcPeakLoad = (consumption: number, maxDemand: number, startDate: string | moment.Moment, endDate: string | moment.Moment) => {\n const days = Math.ceil(moment(endDate).diff(moment(startDate), 'days', true));\n\n return maxDemand === 0 ? 0 : ((consumption / (maxDemand * 24 * days)) * 100);\n};","import axios from 'axios';\n\nimport logger from './logger.js';\n\nconst log = logger('monitoring');\n\nexport const sendHeartbeat = async () => {\n if (!process.env.HEARTBEAT_URL || process.env.HEARTBEAT_URL.endsWith('/')) return false;\n\n try {\n await axios.post(process.env.HEARTBEAT_URL);\n\n return true;\n } catch (e: any) {\n log.warn(`Failed to send heartbeat: ${e.message || e}`);\n return false;\n }\n}","import moment from 'moment';\n\nmoment.locale('en', {\n week: {\n dow: 1\n }\n});\n\nconst getNextRunTime = (startDate: moment.Moment, schedule: any, taskTime: moment.Moment): moment.Moment => {\n const [num, freq] = schedule.frequency.split('|');\n const targetDate = moment(startDate).add(num, freq as moment.unitOfTime.Base);\n\n if (schedule.frequencyPeriod === 'first') {\n targetDate.startOf(freq as moment.unitOfTime.StartOf);\n } else if (schedule.frequencyPeriod === 'last') {\n targetDate.endOf(freq as moment.unitOfTime.StartOf);\n }\n\n const isWeekday = targetDate.isoWeekday() > 0 && targetDate.isoWeekday() < 6;\n const isSaturday = targetDate.isoWeekday() === 6;\n\n // The weekday or weekend chosen should be within the same month as the target date\n if (schedule.frequencyDay === 'weekdays' && !isWeekday) {\n if ((targetDate.date() / 7) < 2) {\n targetDate.add(isSaturday ? 2 : 1, 'days');\n } else {\n targetDate.subtract(isSaturday ? 1 : 2, 'days');\n }\n } else if (schedule.frequencyDay === 'weekends' && isWeekday) {\n if ((targetDate.date() / 7) < 2) {\n targetDate.isoWeekday(6);\n } else {\n targetDate.isoWeekday(0);\n }\n }\n\n if (taskTime.isAfter(targetDate, 'minute')) {\n return getNextRunTime(targetDate, schedule, taskTime);\n }\n\n return targetDate;\n};\n\nexport const getScheduledReportRunTimes = (schedule: any, limit = 1, taskTime = moment()): moment.Moment[] => {\n if (!schedule.startDate || !schedule.enabled) return [];\n\n const originalStartDate = moment.utc(schedule.startDate);\n\n let startDate = originalStartDate;\n\n const includeStartDate = taskTime.isSameOrBefore(originalStartDate, 'minute');\n\n let runTimes = [] as moment.Moment[];\n\n if (includeStartDate) {\n runTimes = [originalStartDate];\n }\n\n const [, freq] = schedule.frequency.split('|');\n\n if (freq === 'once') {\n const nextRunTime = runTimes[0];\n\n // If this is now beyond the start date, return an empty array\n return taskTime.isAfter(nextRunTime, 'minute') ? [] : runTimes;\n }\n\n\n const scheduleRunTimes = Array.from(Array(includeStartDate ? limit - 1 : limit).keys()).map(() => {\n const nextRunTime = getNextRunTime(startDate, schedule, taskTime);\n\n startDate = nextRunTime.hour(originalStartDate.hour()).minute(originalStartDate.minute());\n\n return nextRunTime;\n });\n\n return [...runTimes, ...scheduleRunTimes];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAElB,mBAAkB;;;ACFlB,qBAAoB;AAEpB,IAAO,iBAAQ,CAAC,cAAsB,eAAAA,QAAQ,aAAa;AAAA,EACzD,OAAO;AAAA,EACP,QAAQ,eAAAA,QAAQ,OAAO;AAAA,IACrB,eAAAA,QAAQ,OAAO,UAAU;AAAA,IACzB,eAAAA,QAAQ,OAAO,KAAK;AAAA,EACtB;AAAA,EACA,aAAa,EAAE,SAAS,QAAQ,IAAI,0BAA0B,QAAQ,UAAU;AAAA,EAChF,YAAY;AAAA,IACV,IAAI,eAAAA,QAAQ,WAAW,QAAQ;AAAA,EACjC;AACF,CAAC;;;ADJD,IAAM,MAAM,eAAO,aAAa;AAchC,SAAS,gBAAgB,KAAa,KAAoB,UAAU,OAAO;AACzE,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,yBAAyB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG;AAAA,EACnE;AAEA,MAAI,IAAI,WAAW,KAAK;AACtB,UAAM,IAAI,MAAM,GAAG,IAAI,MAAM,IAAI,IAAI,UAAU,uBAAuB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG;AAAA,EAChG;AAEA,MAAI,CAAC,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AAO,kBAAkB,OAAO,CAAC;AAExF,WAAO;AAAA,EACT,CAAC;AAED,SAAO,CAAC,GAAG,UAAU,GAAG,gBAAgB;AAC1C;","names":["winston","axios","https","log","client","import_axios","axios","moment","import_axios","log","axios","import_moment","moment"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etainabl/nodejs-sdk",
3
- "version": "1.2.55",
3
+ "version": "1.2.56",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",