@etainabl/nodejs-sdk 1.2.34 → 1.2.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +4 -0
- package/package.json +3 -2
- package/src/index.ts +1 -2
- package/dist/cjs/api.d.ts +0 -111
- package/dist/cjs/api.js +0 -318
- package/dist/cjs/consumption.d.ts +0 -14
- package/dist/cjs/consumption.js +0 -32
- package/dist/cjs/db.d.ts +0 -6
- package/dist/cjs/db.js +0 -69
- package/dist/cjs/etainabl.d.ts +0 -10
- package/dist/cjs/etainabl.js +0 -2
- package/dist/cjs/index.d.ts +0 -11
- package/dist/cjs/logger.d.ts +0 -3
- package/dist/cjs/logger.js +0 -14
- package/dist/cjs/monitoring.d.ts +0 -1
- package/dist/cjs/monitoring.js +0 -31
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/reporting.d.ts +0 -2
- package/dist/cjs/reporting.js +0 -69
- package/dist/cjs/slack.d.ts +0 -4
- package/dist/cjs/slack.js +0 -28
- package/dist/cjs/types/index.d.ts +0 -20
- package/dist/cjs/types/index.js +0 -2
- package/dist/cjs/units.d.ts +0 -22
- package/dist/cjs/units.js +0 -94
- package/dist/mjs/api.d.ts +0 -111
- package/dist/mjs/api.js +0 -308
- package/dist/mjs/consumption.d.ts +0 -14
- package/dist/mjs/consumption.js +0 -22
- package/dist/mjs/db.d.ts +0 -6
- package/dist/mjs/db.js +0 -53
- package/dist/mjs/etainabl.d.ts +0 -10
- package/dist/mjs/etainabl.js +0 -1
- package/dist/mjs/index.d.ts +0 -11
- package/dist/mjs/index.js +0 -9
- package/dist/mjs/logger.d.ts +0 -3
- package/dist/mjs/logger.js +0 -9
- package/dist/mjs/monitoring.d.ts +0 -1
- package/dist/mjs/monitoring.js +0 -15
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/reporting.d.ts +0 -2
- package/dist/mjs/reporting.js +0 -62
- package/dist/mjs/slack.d.ts +0 -4
- package/dist/mjs/slack.js +0 -14
- package/dist/mjs/types/index.d.ts +0 -20
- package/dist/mjs/types/index.js +0 -1
- package/dist/mjs/units.d.ts +0 -22
- package/dist/mjs/units.js +0 -89
package/dist/cjs/index.js
CHANGED
|
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
25
28
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
30
|
};
|
|
@@ -43,3 +46,4 @@ const monitoring = __importStar(require("./monitoring.js"));
|
|
|
43
46
|
exports.monitoring = monitoring;
|
|
44
47
|
const reporting = __importStar(require("./reporting.js"));
|
|
45
48
|
exports.reporting = reporting;
|
|
49
|
+
__exportStar(require("./types/index.js"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etainabl/nodejs-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.35",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/mjs/index.js",
|
|
6
6
|
"types": "dist/mjs/index.d.ts",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"process": "vitest run && yarn build && yarn publish",
|
|
21
21
|
"build": "rm -rf dist/* && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && ./fixup.sh",
|
|
22
|
-
"test": "vitest"
|
|
22
|
+
"test": "vitest",
|
|
23
|
+
"prepare": "yarn build"
|
|
23
24
|
},
|
|
24
25
|
"exports": {
|
|
25
26
|
".": {
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,6 @@ import * as units from './units.js';
|
|
|
6
6
|
import * as consumption from './consumption.js';
|
|
7
7
|
import * as monitoring from './monitoring.js';
|
|
8
8
|
import * as reporting from './reporting.js';
|
|
9
|
-
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier } from './types/index.js';
|
|
10
9
|
|
|
11
10
|
export {
|
|
12
11
|
api,
|
|
@@ -19,4 +18,4 @@ export {
|
|
|
19
18
|
reporting
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
export
|
|
21
|
+
export * from './types/index.js';
|
package/dist/cjs/api.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type { AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
|
|
2
|
-
import type { Account, Asset, Automation, Entity, Company, DataIngest, Invoice, Log, Reading, Report, Supplier } from './types/index.js';
|
|
3
|
-
export interface ETNPagedResponse<T = any> {
|
|
4
|
-
data: T[];
|
|
5
|
-
total: number;
|
|
6
|
-
limit: number;
|
|
7
|
-
skip: number;
|
|
8
|
-
}
|
|
9
|
-
export interface ETNReq {
|
|
10
|
-
method: string;
|
|
11
|
-
url: string;
|
|
12
|
-
}
|
|
13
|
-
interface AuthOptions {
|
|
14
|
-
key?: string;
|
|
15
|
-
token?: string;
|
|
16
|
-
}
|
|
17
|
-
declare const _default: (auth: AuthOptions, instanceOptions?: CreateAxiosDefaults) => {
|
|
18
|
-
instance: AxiosInstance;
|
|
19
|
-
getAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<Account>;
|
|
20
|
-
listAccounts: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Account>>;
|
|
21
|
-
updateAccount: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
22
|
-
createAccount: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
23
|
-
removeAccount: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
24
|
-
getAccountSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
25
|
-
invalidateAccountCache: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
26
|
-
getAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<Asset>;
|
|
27
|
-
listAssets: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Asset>>;
|
|
28
|
-
updateAsset: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
29
|
-
createAsset: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
30
|
-
removeAsset: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
31
|
-
getAssetSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
32
|
-
getAssetGroup: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
33
|
-
listAssetGroups: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
34
|
-
updateAssetGroup: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
35
|
-
createAssetGroup: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
36
|
-
removeAssetGroup: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
37
|
-
getAssetGroupAssets: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
38
|
-
getAssetGroupSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
39
|
-
getAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<Automation>;
|
|
40
|
-
listAutomations: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Automation>>;
|
|
41
|
-
updateAutomation: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
42
|
-
createAutomation: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
43
|
-
removeAutomation: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
44
|
-
createAutomationLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
45
|
-
updateAutomationLog: (id: string, subId: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
46
|
-
removeAutomationLog: (id: string, subId: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
47
|
-
getCompany: (id: string, options?: AxiosRequestConfig<any>) => Promise<Company>;
|
|
48
|
-
getConsumption: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
49
|
-
listConsumptions: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
50
|
-
updateConsumption: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
51
|
-
createConsumption: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
52
|
-
removeConsumption: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
53
|
-
getConsumptionSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
54
|
-
getEmail: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
55
|
-
listEmails: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
56
|
-
updateEmail: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
57
|
-
createEmail: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
58
|
-
removeEmail: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
59
|
-
getEmissionFactor: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
60
|
-
listEmissionFactors: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
61
|
-
updateEmissionFactor: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
62
|
-
createEmissionFactor: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
63
|
-
removeEmissionFactor: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
64
|
-
getEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<Entity>;
|
|
65
|
-
listEntities: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Entity>>;
|
|
66
|
-
updateEntity: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
67
|
-
createEntity: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
68
|
-
removeEntity: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
69
|
-
getEntitiesSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
70
|
-
getLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<Log>;
|
|
71
|
-
listLogs: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Log>>;
|
|
72
|
-
updateLog: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
73
|
-
createLog: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
74
|
-
removeLog: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
75
|
-
getReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<Reading>;
|
|
76
|
-
listReadings: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Reading>>;
|
|
77
|
-
updateReading: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
78
|
-
createReading: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
79
|
-
removeReading: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
80
|
-
getReadingSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
81
|
-
getReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<Report>;
|
|
82
|
-
listReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Report>>;
|
|
83
|
-
updateReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
84
|
-
createReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
85
|
-
removeReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
86
|
-
sendReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
87
|
-
getReportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
88
|
-
listReportTemplates: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
89
|
-
updateReportTemplate: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
90
|
-
createReportTemplate: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
91
|
-
removeReportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
92
|
-
getScheduledReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
93
|
-
listScheduledReports: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<any>>;
|
|
94
|
-
updateScheduledReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
95
|
-
createScheduledReport: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
96
|
-
removeScheduledReport: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
97
|
-
sendScheduledReport: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
98
|
-
getInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<Invoice>;
|
|
99
|
-
listInvoices: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Invoice>>;
|
|
100
|
-
updateInvoice: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
101
|
-
createInvoice: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
102
|
-
removeInvoice: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
103
|
-
getInvoiceSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
104
|
-
listSuppliers: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<Supplier>>;
|
|
105
|
-
getSupplierSchema: (options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
106
|
-
getImportTemplate: (id: string, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
107
|
-
updateDataIngest: (id: string, data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
108
|
-
createDataIngest: (data: any, options?: AxiosRequestConfig<any>) => Promise<any>;
|
|
109
|
-
listDataIngest: (options?: AxiosRequestConfig<any>) => Promise<ETNPagedResponse<DataIngest>>;
|
|
110
|
-
};
|
|
111
|
-
export default _default;
|
package/dist/cjs/api.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const axios_1 = __importDefault(require("axios"));
|
|
16
|
-
const https_1 = __importDefault(require("https"));
|
|
17
|
-
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
18
|
-
const log = (0, logger_js_1.default)('etainablApi');
|
|
19
|
-
function _handleResponse(req, res, isPaged = false) {
|
|
20
|
-
if (!res) {
|
|
21
|
-
throw new Error(`No response from API (${req.method} ${req.url})`);
|
|
22
|
-
}
|
|
23
|
-
if (res.status !== 200) {
|
|
24
|
-
throw new Error(`${res.status} ${res.statusText} response from API (${req.method} ${req.url})`);
|
|
25
|
-
}
|
|
26
|
-
if (!res.data) {
|
|
27
|
-
throw new Error(`No data from API (${req.method} ${req.url})`);
|
|
28
|
-
}
|
|
29
|
-
if (isPaged && !res.data.data) {
|
|
30
|
-
throw new Error(`No data from API (${req.method} ${req.url})`);
|
|
31
|
-
}
|
|
32
|
-
return res;
|
|
33
|
-
}
|
|
34
|
-
const factory = {
|
|
35
|
-
getWithId: (etainablApi, endpoint, postEndpoint) => (id, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
var _a;
|
|
37
|
-
const req = {
|
|
38
|
-
method: 'GET',
|
|
39
|
-
url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
40
|
-
};
|
|
41
|
-
log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);
|
|
42
|
-
let res;
|
|
43
|
-
try {
|
|
44
|
-
res = yield etainablApi.get(req.url, options);
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
if ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data)
|
|
48
|
-
throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
52
|
-
_handleResponse(req, res);
|
|
53
|
-
return res.data;
|
|
54
|
-
}),
|
|
55
|
-
get: (etainablApi, endpoint, postEndpoint) => (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
var _b;
|
|
57
|
-
const req = {
|
|
58
|
-
method: 'GET',
|
|
59
|
-
url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
60
|
-
};
|
|
61
|
-
log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
62
|
-
let res;
|
|
63
|
-
try {
|
|
64
|
-
res = yield etainablApi.get(req.url, options);
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
if ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data)
|
|
68
|
-
throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
|
|
69
|
-
throw e;
|
|
70
|
-
}
|
|
71
|
-
console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
72
|
-
_handleResponse(req, res);
|
|
73
|
-
return res.data;
|
|
74
|
-
}),
|
|
75
|
-
list: (etainablApi, endpoint, postEndpoint) => (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
-
var _c;
|
|
77
|
-
const req = {
|
|
78
|
-
method: 'GET',
|
|
79
|
-
url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
80
|
-
};
|
|
81
|
-
log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
82
|
-
let res;
|
|
83
|
-
try {
|
|
84
|
-
res = yield etainablApi.get(req.url, options);
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
if ((_c = e.response) === null || _c === void 0 ? void 0 : _c.data)
|
|
88
|
-
throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
|
|
89
|
-
throw e;
|
|
90
|
-
}
|
|
91
|
-
console.log(`API Response: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
92
|
-
_handleResponse(req, res, true);
|
|
93
|
-
return res.data;
|
|
94
|
-
}),
|
|
95
|
-
update: (etainablApi, endpoint, postEndpoint) => (id, data, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
-
var _d;
|
|
97
|
-
const req = {
|
|
98
|
-
method: 'PATCH',
|
|
99
|
-
url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
100
|
-
};
|
|
101
|
-
log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
102
|
-
let res;
|
|
103
|
-
try {
|
|
104
|
-
res = yield etainablApi.patch(req.url, data, options);
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
if ((_d = e.response) === null || _d === void 0 ? void 0 : _d.data)
|
|
108
|
-
throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
|
|
109
|
-
throw e;
|
|
110
|
-
}
|
|
111
|
-
_handleResponse(req, res);
|
|
112
|
-
return res.data;
|
|
113
|
-
}),
|
|
114
|
-
create: (etainablApi, endpoint, postEndpoint) => (data, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
-
var _e;
|
|
116
|
-
const req = {
|
|
117
|
-
method: 'POST',
|
|
118
|
-
url: `${endpoint}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
119
|
-
};
|
|
120
|
-
log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
121
|
-
let res;
|
|
122
|
-
try {
|
|
123
|
-
res = yield etainablApi.post(req.url, data, options);
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
if ((_e = e.response) === null || _e === void 0 ? void 0 : _e.data)
|
|
127
|
-
throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
|
|
128
|
-
throw e;
|
|
129
|
-
}
|
|
130
|
-
_handleResponse(req, res);
|
|
131
|
-
return res.data;
|
|
132
|
-
}),
|
|
133
|
-
remove: (etainablApi, endpoint, postEndpoint) => (id, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
-
var _f;
|
|
135
|
-
const req = {
|
|
136
|
-
method: 'DELETE',
|
|
137
|
-
url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`
|
|
138
|
-
};
|
|
139
|
-
let res;
|
|
140
|
-
log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
141
|
-
try {
|
|
142
|
-
res = yield etainablApi.delete(req.url, options);
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
if ((_f = e.response) === null || _f === void 0 ? void 0 : _f.data)
|
|
146
|
-
throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
|
|
147
|
-
throw e;
|
|
148
|
-
}
|
|
149
|
-
_handleResponse(req, res);
|
|
150
|
-
return res.data;
|
|
151
|
-
}),
|
|
152
|
-
customWithId: (etainablApi, method, endpoint, postEndpoint) => (id, data, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
|
-
var _g;
|
|
154
|
-
const req = Object.assign({ method: method, url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ''}`, data }, options);
|
|
155
|
-
log.info(`API Request (Custom): ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
|
|
156
|
-
let res;
|
|
157
|
-
try {
|
|
158
|
-
res = yield etainablApi.request(req);
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
if ((_g = e.response) === null || _g === void 0 ? void 0 : _g.data)
|
|
162
|
-
throw new Error(`API error response: ${JSON.stringify(e.response.data)}`);
|
|
163
|
-
throw e;
|
|
164
|
-
}
|
|
165
|
-
_handleResponse(req, res);
|
|
166
|
-
return res.data;
|
|
167
|
-
})
|
|
168
|
-
};
|
|
169
|
-
// ETN Sub Endpoints
|
|
170
|
-
// e.g. /assets/:id/documents/:documentId
|
|
171
|
-
const subFactory = {
|
|
172
|
-
// e.g. POST /assets/:id/documents
|
|
173
|
-
create: (etainablApi, endpoint, subEndpoint) => (id, data, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
-
const subUrl = `${id}/${subEndpoint}`;
|
|
175
|
-
return factory.create(etainablApi, endpoint, subUrl)(data, options);
|
|
176
|
-
}),
|
|
177
|
-
// e.g. PATCH /assets/:id/documents/:documentId
|
|
178
|
-
update: (etainablApi, endpoint, subEndpoint) => (id, subId, data, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
179
|
-
const subUrl = `${subEndpoint}/${subId}`;
|
|
180
|
-
return factory.update(etainablApi, endpoint, subUrl)(id, data, options);
|
|
181
|
-
}),
|
|
182
|
-
// e.g. DELETE /assets/:id/documents/:documentId
|
|
183
|
-
remove: (etainablApi, endpoint, subEndpoint) => (id, subId, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
-
const subUrl = `${subEndpoint}/${subId}`;
|
|
185
|
-
return factory.remove(etainablApi, endpoint, subUrl)(id, options);
|
|
186
|
-
})
|
|
187
|
-
};
|
|
188
|
-
exports.default = (auth, instanceOptions = {}) => {
|
|
189
|
-
try {
|
|
190
|
-
const headers = {};
|
|
191
|
-
if (auth.key) {
|
|
192
|
-
headers['x-key'] = auth.key;
|
|
193
|
-
}
|
|
194
|
-
else if (auth.token) {
|
|
195
|
-
headers['Authorization'] = auth.token;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
headers['x-key'] = process.env.ETAINABL_API_KEY;
|
|
199
|
-
}
|
|
200
|
-
const etainablApi = axios_1.default.create(Object.assign({ baseURL: process.env.ETAINABL_API_URL, timeout: 300000, httpsAgent: new https_1.default.Agent({ keepAlive: true }), headers }, instanceOptions));
|
|
201
|
-
return {
|
|
202
|
-
instance: etainablApi,
|
|
203
|
-
// accounts
|
|
204
|
-
getAccount: factory.getWithId(etainablApi, 'accounts'),
|
|
205
|
-
listAccounts: factory.list(etainablApi, 'accounts'),
|
|
206
|
-
updateAccount: factory.update(etainablApi, 'accounts'),
|
|
207
|
-
createAccount: factory.create(etainablApi, 'accounts'),
|
|
208
|
-
removeAccount: factory.remove(etainablApi, 'accounts'),
|
|
209
|
-
getAccountSchema: factory.get(etainablApi, 'accounts', 'schema'),
|
|
210
|
-
invalidateAccountCache: factory.customWithId(etainablApi, 'put', 'accounts', 'invalidate-cache'),
|
|
211
|
-
// assets
|
|
212
|
-
getAsset: factory.getWithId(etainablApi, 'assets'),
|
|
213
|
-
listAssets: factory.list(etainablApi, 'assets'),
|
|
214
|
-
updateAsset: factory.update(etainablApi, 'assets'),
|
|
215
|
-
createAsset: factory.create(etainablApi, 'assets'),
|
|
216
|
-
removeAsset: factory.remove(etainablApi, 'assets'),
|
|
217
|
-
getAssetSchema: factory.get(etainablApi, 'assets', 'schema'),
|
|
218
|
-
// assetGroups
|
|
219
|
-
getAssetGroup: factory.getWithId(etainablApi, 'asset-groups'),
|
|
220
|
-
listAssetGroups: factory.list(etainablApi, 'asset-groups'),
|
|
221
|
-
updateAssetGroup: factory.update(etainablApi, 'asset-groups'),
|
|
222
|
-
createAssetGroup: factory.create(etainablApi, 'asset-groups'),
|
|
223
|
-
removeAssetGroup: factory.remove(etainablApi, 'asset-groups'),
|
|
224
|
-
getAssetGroupAssets: factory.getWithId(etainablApi, 'asset-groups', 'assets'),
|
|
225
|
-
getAssetGroupSchema: factory.get(etainablApi, 'asset-groups', 'schema'),
|
|
226
|
-
// automation
|
|
227
|
-
getAutomation: factory.getWithId(etainablApi, 'automation'),
|
|
228
|
-
listAutomations: factory.list(etainablApi, 'automation'),
|
|
229
|
-
updateAutomation: factory.update(etainablApi, 'automation'),
|
|
230
|
-
createAutomation: factory.create(etainablApi, 'automation'),
|
|
231
|
-
removeAutomation: factory.remove(etainablApi, 'automation'),
|
|
232
|
-
createAutomationLog: subFactory.create(etainablApi, 'automation', 'logs'),
|
|
233
|
-
updateAutomationLog: subFactory.update(etainablApi, 'automation', 'logs'),
|
|
234
|
-
removeAutomationLog: subFactory.remove(etainablApi, 'automation', 'logs'),
|
|
235
|
-
// company
|
|
236
|
-
getCompany: factory.getWithId(etainablApi, 'companies'),
|
|
237
|
-
// consumption
|
|
238
|
-
getConsumption: factory.getWithId(etainablApi, 'consumptions'),
|
|
239
|
-
listConsumptions: factory.list(etainablApi, 'consumptions'),
|
|
240
|
-
updateConsumption: factory.update(etainablApi, 'consumptions'),
|
|
241
|
-
createConsumption: factory.create(etainablApi, 'consumptions'),
|
|
242
|
-
removeConsumption: factory.remove(etainablApi, 'consumptions'),
|
|
243
|
-
getConsumptionSchema: factory.get(etainablApi, 'consumptions', 'schema'),
|
|
244
|
-
// emails
|
|
245
|
-
getEmail: factory.getWithId(etainablApi, 'emails'),
|
|
246
|
-
listEmails: factory.list(etainablApi, 'emails'),
|
|
247
|
-
updateEmail: factory.update(etainablApi, 'emails'),
|
|
248
|
-
createEmail: factory.create(etainablApi, 'emails'),
|
|
249
|
-
removeEmail: factory.remove(etainablApi, 'emails'),
|
|
250
|
-
// emission factors
|
|
251
|
-
getEmissionFactor: factory.getWithId(etainablApi, 'emission-factors'),
|
|
252
|
-
listEmissionFactors: factory.list(etainablApi, 'emission-factors'),
|
|
253
|
-
updateEmissionFactor: factory.update(etainablApi, 'emission-factors'),
|
|
254
|
-
createEmissionFactor: factory.create(etainablApi, 'emission-factors'),
|
|
255
|
-
removeEmissionFactor: factory.remove(etainablApi, 'emission-factors'),
|
|
256
|
-
// entity
|
|
257
|
-
getEntity: factory.getWithId(etainablApi, 'entities'),
|
|
258
|
-
listEntities: factory.list(etainablApi, 'entities'),
|
|
259
|
-
updateEntity: factory.update(etainablApi, 'entities'),
|
|
260
|
-
createEntity: factory.create(etainablApi, 'entities'),
|
|
261
|
-
removeEntity: factory.remove(etainablApi, 'entities'),
|
|
262
|
-
getEntitiesSchema: factory.get(etainablApi, 'entities', 'schema'),
|
|
263
|
-
// logs
|
|
264
|
-
getLog: factory.getWithId(etainablApi, 'logs'),
|
|
265
|
-
listLogs: factory.list(etainablApi, 'logs'),
|
|
266
|
-
updateLog: factory.update(etainablApi, 'logs'),
|
|
267
|
-
createLog: factory.create(etainablApi, 'logs'),
|
|
268
|
-
removeLog: factory.remove(etainablApi, 'logs'),
|
|
269
|
-
// readings
|
|
270
|
-
getReading: factory.getWithId(etainablApi, 'readings'),
|
|
271
|
-
listReadings: factory.list(etainablApi, 'readings'),
|
|
272
|
-
updateReading: factory.update(etainablApi, 'readings'),
|
|
273
|
-
createReading: factory.create(etainablApi, 'readings'),
|
|
274
|
-
removeReading: factory.remove(etainablApi, 'readings'),
|
|
275
|
-
getReadingSchema: factory.get(etainablApi, 'readings', 'schema'),
|
|
276
|
-
// reports
|
|
277
|
-
getReport: factory.getWithId(etainablApi, 'reports'),
|
|
278
|
-
listReports: factory.list(etainablApi, 'reports'),
|
|
279
|
-
updateReport: factory.update(etainablApi, 'reports'),
|
|
280
|
-
createReport: factory.create(etainablApi, 'reports'),
|
|
281
|
-
removeReport: factory.remove(etainablApi, 'reports'),
|
|
282
|
-
sendReport: factory.customWithId(etainablApi, 'post', 'reports', 'send'),
|
|
283
|
-
// report templates
|
|
284
|
-
getReportTemplate: factory.getWithId(etainablApi, 'report-templates'),
|
|
285
|
-
listReportTemplates: factory.list(etainablApi, 'report-templates'),
|
|
286
|
-
updateReportTemplate: factory.update(etainablApi, 'report-templates'),
|
|
287
|
-
createReportTemplate: factory.create(etainablApi, 'report-templates'),
|
|
288
|
-
removeReportTemplate: factory.remove(etainablApi, 'report-templates'),
|
|
289
|
-
// scheduled reports
|
|
290
|
-
getScheduledReport: factory.getWithId(etainablApi, 'scheduled-reports'),
|
|
291
|
-
listScheduledReports: factory.list(etainablApi, 'scheduled-reports'),
|
|
292
|
-
updateScheduledReport: factory.update(etainablApi, 'scheduled-reports'),
|
|
293
|
-
createScheduledReport: factory.create(etainablApi, 'scheduled-reports'),
|
|
294
|
-
removeScheduledReport: factory.remove(etainablApi, 'scheduled-reports'),
|
|
295
|
-
sendScheduledReport: factory.customWithId(etainablApi, 'post', 'scheduled-reports', 'send'),
|
|
296
|
-
// invoices
|
|
297
|
-
getInvoice: factory.getWithId(etainablApi, 'invoices'),
|
|
298
|
-
listInvoices: factory.list(etainablApi, 'invoices'),
|
|
299
|
-
updateInvoice: factory.update(etainablApi, 'invoices'),
|
|
300
|
-
createInvoice: factory.create(etainablApi, 'invoices'),
|
|
301
|
-
removeInvoice: factory.remove(etainablApi, 'invoices'),
|
|
302
|
-
getInvoiceSchema: factory.get(etainablApi, 'invoices', 'schema'),
|
|
303
|
-
//suppliers
|
|
304
|
-
listSuppliers: factory.list(etainablApi, 'suppliers'),
|
|
305
|
-
getSupplierSchema: factory.get(etainablApi, 'suppliers', 'schema'),
|
|
306
|
-
// import templates
|
|
307
|
-
getImportTemplate: factory.getWithId(etainablApi, 'import-templates'),
|
|
308
|
-
//data imports
|
|
309
|
-
updateDataIngest: factory.update(etainablApi, 'data-ingests'),
|
|
310
|
-
createDataIngest: factory.create(etainablApi, 'data-ingests'),
|
|
311
|
-
listDataIngest: factory.list(etainablApi, 'data-ingests'),
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
catch (e) {
|
|
315
|
-
log.error(e);
|
|
316
|
-
throw e;
|
|
317
|
-
}
|
|
318
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import moment from 'moment';
|
|
2
|
-
interface ConsumptionData {
|
|
3
|
-
date: Date;
|
|
4
|
-
consumption: number;
|
|
5
|
-
}
|
|
6
|
-
export declare const dayNightConsumption: (data: ConsumptionData[]) => {
|
|
7
|
-
dayConsumption: number;
|
|
8
|
-
nightConsumption: number;
|
|
9
|
-
consumption: number;
|
|
10
|
-
};
|
|
11
|
-
export declare const calcMaxConsumptionValue: (data: ConsumptionData[]) => number;
|
|
12
|
-
export declare const calcMaxDemand: (data: ConsumptionData[]) => number;
|
|
13
|
-
export declare const calcPeakLoad: (consumption: number, maxDemand: number, startDate: string | moment.Moment, endDate: string | moment.Moment) => number;
|
|
14
|
-
export {};
|
package/dist/cjs/consumption.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calcPeakLoad = exports.calcMaxDemand = exports.calcMaxConsumptionValue = exports.dayNightConsumption = void 0;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const dayNightConsumption = (data) => data.reduce((acc, item) => {
|
|
9
|
-
const hour = moment_1.default.utc(item.date).hour(); // End Time of HH consumption period
|
|
10
|
-
if (hour >= 0 && hour < 7) {
|
|
11
|
-
acc.nightConsumption += item.consumption;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
acc.dayConsumption += item.consumption;
|
|
15
|
-
}
|
|
16
|
-
acc.consumption += item.consumption;
|
|
17
|
-
return acc;
|
|
18
|
-
}, {
|
|
19
|
-
dayConsumption: 0,
|
|
20
|
-
nightConsumption: 0,
|
|
21
|
-
consumption: 0
|
|
22
|
-
});
|
|
23
|
-
exports.dayNightConsumption = dayNightConsumption;
|
|
24
|
-
const calcMaxConsumptionValue = (data) => Math.max(...data.map((item) => item.consumption));
|
|
25
|
-
exports.calcMaxConsumptionValue = calcMaxConsumptionValue;
|
|
26
|
-
const calcMaxDemand = (data) => (0, exports.calcMaxConsumptionValue)(data) * 2;
|
|
27
|
-
exports.calcMaxDemand = calcMaxDemand;
|
|
28
|
-
const calcPeakLoad = (consumption, maxDemand, startDate, endDate) => {
|
|
29
|
-
const days = Math.ceil((0, moment_1.default)(endDate).diff((0, moment_1.default)(startDate), 'days', true));
|
|
30
|
-
return maxDemand === 0 ? 0 : ((consumption / (maxDemand * 24 * days)) * 100);
|
|
31
|
-
};
|
|
32
|
-
exports.calcPeakLoad = calcPeakLoad;
|
package/dist/cjs/db.d.ts
DELETED
package/dist/cjs/db.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const mongodb_1 = require("mongodb");
|
|
16
|
-
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
17
|
-
const log = (0, logger_js_1.default)('dbHelpers');
|
|
18
|
-
let cachedDb;
|
|
19
|
-
function connectToDatabase(retryAttempt = 1) {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
if (!process.env.ETAINABL_DB_URL)
|
|
22
|
-
throw new Error("ETAINABL_DB_URL is not set");
|
|
23
|
-
if (!process.env.AWS_ACCESS_KEY_ID)
|
|
24
|
-
throw new Error("AWS_ACCESS_KEY_ID is not set");
|
|
25
|
-
if (!process.env.AWS_SECRET_ACCESS_KEY)
|
|
26
|
-
throw new Error("AWS_SECRET_ACCESS_KEY is not set");
|
|
27
|
-
if (cachedDb) {
|
|
28
|
-
log.debug('Using cached MongoDB connection.');
|
|
29
|
-
return Promise.resolve(cachedDb);
|
|
30
|
-
}
|
|
31
|
-
const uri = `mongodb+srv://${process.env.ETAINABL_DB_URL}`;
|
|
32
|
-
try {
|
|
33
|
-
if (process.env.DB_BASIC_AUTH === 'true') {
|
|
34
|
-
log.debug('Connecting to MongoDB server... (Auth: Basic)');
|
|
35
|
-
const client = new mongodb_1.MongoClient(uri);
|
|
36
|
-
yield client.connect();
|
|
37
|
-
log.debug('Connected successfully to MongoDB server! (Auth: Basic)');
|
|
38
|
-
cachedDb = client.db('etainabl');
|
|
39
|
-
return cachedDb;
|
|
40
|
-
}
|
|
41
|
-
log.debug('Connecting to MongoDB server... (Auth: AWS)');
|
|
42
|
-
const client = new mongodb_1.MongoClient(uri, {
|
|
43
|
-
auth: {
|
|
44
|
-
username: process.env.AWS_ACCESS_KEY_ID,
|
|
45
|
-
password: process.env.AWS_SECRET_ACCESS_KEY
|
|
46
|
-
},
|
|
47
|
-
authSource: '$external',
|
|
48
|
-
authMechanism: 'MONGODB-AWS'
|
|
49
|
-
});
|
|
50
|
-
yield client.connect();
|
|
51
|
-
log.debug('Connected successfully to MongoDB server! (Auth: AWS)');
|
|
52
|
-
cachedDb = client.db('etainabl');
|
|
53
|
-
return cachedDb;
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
// Retry
|
|
57
|
-
if (retryAttempt > 5) {
|
|
58
|
-
console.log(`Error connecting to MongoDB server after 5 attempts...`);
|
|
59
|
-
throw e;
|
|
60
|
-
}
|
|
61
|
-
console.log(`MongoDB Connection error: ${e.message}`);
|
|
62
|
-
console.log(`Error connecting to MongoDB server... Retrying in 3 seconds... (Attempt ${retryAttempt})`);
|
|
63
|
-
return connectToDatabase(retryAttempt + 1);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
exports.default = {
|
|
68
|
-
connectToDatabase
|
|
69
|
-
};
|
package/dist/cjs/etainabl.d.ts
DELETED
package/dist/cjs/etainabl.js
DELETED
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import api from './api.js';
|
|
2
|
-
import logger from './logger.js';
|
|
3
|
-
import db from './db.js';
|
|
4
|
-
import slack from './slack.js';
|
|
5
|
-
import * as units from './units.js';
|
|
6
|
-
import * as consumption from './consumption.js';
|
|
7
|
-
import * as monitoring from './monitoring.js';
|
|
8
|
-
import * as reporting from './reporting.js';
|
|
9
|
-
import type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier } from './types/index.js';
|
|
10
|
-
export { api, logger, consumption, monitoring, db, slack, units, reporting };
|
|
11
|
-
export type { Account, Asset, Automation, Company, DataIngest, Invoice, Log, Reading, Supplier };
|
package/dist/cjs/logger.d.ts
DELETED
package/dist/cjs/logger.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const winston_1 = __importDefault(require("winston"));
|
|
7
|
-
exports.default = (namespace) => winston_1.default.createLogger({
|
|
8
|
-
level: 'debug',
|
|
9
|
-
format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.json()),
|
|
10
|
-
defaultMeta: { service: process.env.AWS_LAMBDA_FUNCTION_NAME, script: namespace },
|
|
11
|
-
transports: [
|
|
12
|
-
new winston_1.default.transports.Console()
|
|
13
|
-
]
|
|
14
|
-
});
|