@etainabl/nodejs-sdk 1.2.43 → 1.2.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/cjs/package.json +3 -0
  2. package/dist/esm/package.json +3 -0
  3. package/dist/index.d.cts +782 -0
  4. package/dist/index.d.ts +782 -0
  5. package/dist/index.js +626 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +588 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +27 -26
  10. package/.prettierrc +0 -11
  11. package/__tests__/reporting.test.ts +0 -88
  12. package/dist/cjs/index.js +0 -59
  13. package/eslint.config.js +0 -60
  14. package/fixup.sh +0 -11
  15. package/package-lock.json +0 -6327
  16. package/src/api.ts +0 -382
  17. package/src/consumption.ts +0 -40
  18. package/src/db.ts +0 -69
  19. package/src/etainabl.ts +0 -10
  20. package/src/index.ts +0 -21
  21. package/src/logger.ts +0 -13
  22. package/src/monitoring.ts +0 -18
  23. package/src/reporting.ts +0 -78
  24. package/src/slack.ts +0 -16
  25. package/src/types/account.ts +0 -116
  26. package/src/types/address.ts +0 -12
  27. package/src/types/asset.ts +0 -142
  28. package/src/types/automation.ts +0 -35
  29. package/src/types/company.ts +0 -47
  30. package/src/types/dataIngest.ts +0 -8
  31. package/src/types/email.ts +0 -18
  32. package/src/types/entity.ts +0 -17
  33. package/src/types/index.ts +0 -20
  34. package/src/types/invoice.ts +0 -119
  35. package/src/types/log.ts +0 -10
  36. package/src/types/portal.ts +0 -9
  37. package/src/types/reading.ts +0 -17
  38. package/src/types/report.ts +0 -21
  39. package/src/types/scraperRun.ts +0 -15
  40. package/src/types/statusHistory.ts +0 -5
  41. package/src/types/supplier.ts +0 -31
  42. package/src/units.ts +0 -111
  43. package/tsconfig.base.json +0 -31
  44. package/tsconfig.cjs.json +0 -8
  45. package/tsconfig.json +0 -9
  46. package/tsconfig.test.json +0 -13
  47. package/vitest.config.js +0 -10
  48. package/vitest.workspace.js +0 -5
@@ -0,0 +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,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,IAAI,MAAM;AACb,UAAM,IAAI,MAAM,qBAAqB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG;AAAA,EAC/D;AAEA,MAAI,WAAW,CAAC,IAAI,KAAK,MAAM;AAC7B,UAAM,IAAI,MAAM,qBAAqB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG;AAAA,EAC/D;AAEA,SA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;AAAA,IACzB,OAAO;AACL,iBAAW,WAAW,CAAC;AAAA,IACzB;AAAA,EACF;AAEA,MAAI,SAAS,QAAQ,YAAY,QAAQ,GAAG;AAC1C,WAAO,eAAe,YAAY,UAAU,QAAQ;AAAA,EACtD;AAEA,SAAO;AACT;AAEO,IAAM,6BAA6B,CAAC,UAAe,QAAQ,GAAG,WAAWA,QAAO,MAAuB;AAC5G,MAAI,CAAC,SAAS,aAAa,CAAC,SAAS,QAAS,QAAO,CAAC;AAEtD,QAAM,oBAAoBA,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":["log","client","axios","axios","log","axios","moment"]}
package/package.json CHANGED
@@ -1,11 +1,32 @@
1
1
  {
2
2
  "name": "@etainabl/nodejs-sdk",
3
- "version": "1.2.43",
4
- "main": "dist/cjs/index.js",
5
- "module": "dist/mjs/index.js",
6
- "types": "dist/mjs/index.d.ts",
7
- "author": "Jonathan Lambert <jonathan@etainabl.com>",
3
+ "version": "1.2.45",
8
4
  "type": "module",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/esm/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/esm/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/cjs/index.js"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsup",
25
+ "dev": "tsup --watch",
26
+ "prepublishOnly": "npm run build",
27
+ "process": "vitest run && npm run build && npm version patch && npm publish",
28
+ "test": "vitest"
29
+ },
9
30
  "dependencies": {
10
31
  "axios": "^1.8.4",
11
32
  "moment": "^2.29.4",
@@ -13,29 +34,9 @@
13
34
  "winston": "^3.10.0"
14
35
  },
15
36
  "devDependencies": {
16
- "@babel/eslint-parser": "^7.27.0",
17
37
  "@types/node": "^20.4.5",
18
- "@typescript-eslint/eslint-plugin": "^8.29.0",
19
- "@typescript-eslint/parser": "^8.29.0",
20
- "eslint": "^8.57.1",
21
- "eslint-config-airbnb": "^19.0.4",
22
- "eslint-config-airbnb-base": "^15.0.0",
23
- "eslint-config-prettier": "^10.1.1",
24
- "eslint-plugin-import": "^2.31.0",
25
- "prettier-eslint": "^16.3.0",
38
+ "tsup": "^8.0.2",
26
39
  "typescript": "^5.8.2",
27
40
  "vitest": "^3.1.1"
28
- },
29
- "scripts": {
30
- "process": "vitest run && yarn build && yarn publish",
31
- "build": "rm -rf dist/* && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && ./fixup.sh",
32
- "test": "vitest",
33
- "postinstall": "npm run build"
34
- },
35
- "exports": {
36
- ".": {
37
- "import": "./dist/mjs/index.js",
38
- "require": "./dist/cjs/index.js"
39
- }
40
41
  }
41
42
  }
package/.prettierrc DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "printWidth": 150,
3
- "parser": "flow",
4
- "semi": true,
5
- "tabWidth": 4,
6
- "useTabs": false,
7
- "singleQuote": true,
8
- "trailingComma": "none",
9
- "bracketSpacing": true,
10
- "arrowParens": "avoid"
11
- }
@@ -1,88 +0,0 @@
1
- import moment from 'moment';
2
- import { reporting } from '../src/index.js';
3
-
4
- const exampleScheduledReport = {
5
- "_id" : "66964ddcdc2a32666b573d4b",
6
- "name" : "Last Months Meter Report - 008453651410226013008",
7
- "startDate" : moment('2024-07-18T08:03:00.000+0000'),
8
- "frequency" : "1|month",
9
- "frequencyDay" : "any",
10
- "frequencyPeriod" : "any",
11
- "reportPeriod" : "1|month",
12
- "subject" : "{{ siteName }} Last Month Meter Report for {{ accountMeterPointNumber }}",
13
- "message" : "Hi\n\nPlease find attached last month's meter management report for {{ accountName }} at {{ siteName }} covering the periods {{ reportStartDate }} to {{ reportEndDate }} for {{ accountMeterSerialNumber }}. \n\nIf you have any questions, please contact helpdesk@carbonxgen.com.\n\nMany thanks\nCarbonxgen",
14
- "recipients" : [
15
- "test@etainabl.com"
16
- ],
17
- "enabled" : true,
18
- "reportTemplateId" : "668f0cfd341c6b91bee5add3",
19
- "overrides" : {
20
- "accountId" : "655fcf07b7d3920014045314"
21
- },
22
- "userSub" : "auth0|6560834e165d6e67c4a4b8c9",
23
- "companyId" : "655b6d833f36810014b817a1",
24
- "deleted" : false,
25
- "createdAt" : moment('2024-07-16T10:39:24.917+0000'),
26
- "updatedAt" : moment('2024-08-14T10:37:16.263+0000'),
27
- "bulkUpdateCode" : "rerun17092024"
28
- };
29
-
30
- describe('Scheduled report run times', () => {
31
-
32
- it('should generate the correct run times for monthly report', async () => {
33
- const nextRunTimes = reporting.getScheduledReportRunTimes(exampleScheduledReport, 5, moment('2024-06-23T00:00:00.000+0000'));
34
-
35
- expect(nextRunTimes.map(t => t.toDate())).toEqual([
36
- new Date('2024-07-18T08:03:00.000+0000'),
37
- new Date('2024-08-18T08:03:00.000+0000'),
38
- new Date('2024-09-18T08:03:00.000+0000'),
39
- new Date('2024-10-18T08:03:00.000+0000'),
40
- new Date('2024-11-18T08:03:00.000+0000')
41
- ]);
42
- });
43
-
44
- it('should generate the correct run times for weekly report', async () => {
45
- const simulatedTaskTime = moment('2024-07-23T00:00:00.000+0000');
46
-
47
- const editedScheduledReport = {
48
- ...exampleScheduledReport,
49
- frequency: "1|week"
50
- };
51
-
52
- const scheduledStartDate = moment(editedScheduledReport.startDate);
53
-
54
- const nextRunTimes = reporting.getScheduledReportRunTimes(editedScheduledReport, 5, simulatedTaskTime);
55
-
56
- expect(nextRunTimes.map(t => t.toDate())).toEqual([
57
- scheduledStartDate.add(1, 'week').toDate(),
58
- scheduledStartDate.add(1, 'week').toDate(),
59
- scheduledStartDate.add(1, 'week').toDate(),
60
- scheduledStartDate.add(1, 'week').toDate(),
61
- scheduledStartDate.add(1, 'week').toDate()
62
- ]);
63
- });
64
-
65
- it('should generate a single run time for a one-time report', async () => {
66
-
67
- const expiredScheduledReport = {
68
- ...exampleScheduledReport,
69
- frequency: "1|once",
70
- startDate: moment('2024-07-25T08:03:00.000+0000')
71
- };
72
-
73
- const nextRunTimes = reporting.getScheduledReportRunTimes(expiredScheduledReport, 5, moment('2024-06-23T00:00:00.000+0000'));
74
- expect(nextRunTimes.map(t => t.toDate())).toEqual([new Date("2024-07-25T08:03:00.000Z")]);
75
- });
76
-
77
- it('should generate no run times for an expired one-time report', async () => {
78
-
79
- const expiredScheduledReport = {
80
- ...exampleScheduledReport,
81
- frequency: "1|once",
82
- startDate: moment('2024-06-18T08:03:00.000+0000')
83
- };
84
-
85
- const nextRunTimes = reporting.getScheduledReportRunTimes(expiredScheduledReport, 5, moment('2024-06-23T00:00:00.000+0000'));
86
- expect(nextRunTimes).toEqual([]);
87
- });
88
- });
package/dist/cjs/index.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.reporting = exports.units = exports.slack = exports.db = exports.monitoring = exports.consumption = exports.logger = exports.api = void 0;
43
- const api_js_1 = __importDefault(require("./api.js"));
44
- exports.api = api_js_1.default;
45
- const logger_js_1 = __importDefault(require("./logger.js"));
46
- exports.logger = logger_js_1.default;
47
- const db_js_1 = __importDefault(require("./db.js"));
48
- exports.db = db_js_1.default;
49
- const slack_js_1 = __importDefault(require("./slack.js"));
50
- exports.slack = slack_js_1.default;
51
- const units = __importStar(require("./units.js"));
52
- exports.units = units;
53
- const consumption = __importStar(require("./consumption.js"));
54
- exports.consumption = consumption;
55
- const monitoring = __importStar(require("./monitoring.js"));
56
- exports.monitoring = monitoring;
57
- const reporting = __importStar(require("./reporting.js"));
58
- exports.reporting = reporting;
59
- __exportStar(require("./types/index.js"), exports);
package/eslint.config.js DELETED
@@ -1,60 +0,0 @@
1
- import tseslint from '@typescript-eslint/eslint-plugin';
2
- import tsParser from '@typescript-eslint/parser';
3
-
4
- export default [
5
- {
6
- ignores: [
7
- 'node_modules/**',
8
- 'dist/**',
9
- 'coverage/**',
10
- 'logs/**',
11
- '*.log',
12
- '.DS_Store'
13
- ]
14
- },
15
- {
16
- files: ['**/*.js', '**/*.ts'],
17
- plugins: {
18
- '@typescript-eslint': tseslint
19
- },
20
- languageOptions: {
21
- parser: tsParser,
22
- ecmaVersion: 2020,
23
- sourceType: 'module',
24
- parserOptions: {
25
- ecmaVersion: 2020,
26
- sourceType: 'module'
27
- }
28
- },
29
- linterOptions: {
30
- reportUnusedDisableDirectives: true
31
- },
32
- rules: {
33
- 'no-console': 'off',
34
- 'comma-dangle': ['error', 'never'],
35
- 'arrow-parens': ['error', 'as-needed'],
36
- 'linebreak-style': 'off',
37
- 'padded-blocks': 'off',
38
- 'no-underscore-dangle': 'off',
39
- 'no-param-reassign': ['error', { props: false }],
40
- 'new-cap': ['error', { capIsNewExceptions: ['Router', 'ObjectId'] }],
41
- 'no-tabs': 'error',
42
- 'max-len': ['warn', 150],
43
- 'no-plusplus': 'off',
44
- 'generator-star-spacing': 'off',
45
- 'class-methods-use-this': 'off',
46
- 'import/extensions': 'off',
47
- 'import/no-unresolved': 'off',
48
- 'prefer-destructuring': 'off',
49
- 'no-use-before-define': 'off',
50
- 'import/prefer-default-export': 'off'
51
- },
52
- settings: {
53
- 'import/resolver': {
54
- node: {
55
- extensions: ['.js', '.ts']
56
- }
57
- }
58
- }
59
- }
60
- ];
package/fixup.sh DELETED
@@ -1,11 +0,0 @@
1
- cat >dist/cjs/package.json <<!EOF
2
- {
3
- "type": "commonjs"
4
- }
5
- !EOF
6
-
7
- cat >dist/mjs/package.json <<!EOF
8
- {
9
- "type": "module"
10
- }
11
- !EOF