@etainabl/nodejs-sdk 1.3.147 → 1.3.148

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
@@ -136,6 +136,8 @@ import https from "https";
136
136
 
137
137
  // src/logger.ts
138
138
  import winston from "winston";
139
+ import { Logtail } from "@logtail/node";
140
+ import { LogtailTransport } from "@logtail/winston";
139
141
  var localFormat = winston.format.combine(
140
142
  winston.format.timestamp({ format: "HH:mm:ss" }),
141
143
  winston.format.colorize(),
@@ -146,12 +148,24 @@ var localFormat = winston.format.combine(
146
148
  return `${timestamp} ${level} ${namespace} ${message}${metaStr}`;
147
149
  })
148
150
  );
149
- var logger_default = (namespace) => winston.createLogger({
150
- level: "debug",
151
- format: process.env.ENV === "local" ? localFormat : winston.format.combine(winston.format.timestamp(), winston.format.json()),
152
- defaultMeta: { service: process.env.AWS_LAMBDA_FUNCTION_NAME, script: namespace },
153
- transports: [new winston.transports.Console()]
154
- });
151
+ var logger_default = (namespace, betterStackOptions) => {
152
+ const transports = [new winston.transports.Console()];
153
+ let logtail;
154
+ if (betterStackOptions?.betterstack && betterStackOptions?.betterStackToken && betterStackOptions?.betterStackHost) {
155
+ logtail = new Logtail(betterStackOptions.betterStackToken, {
156
+ endpoint: betterStackOptions.betterStackHost
157
+ });
158
+ transports.push(new LogtailTransport(logtail));
159
+ }
160
+ const logger = winston.createLogger({
161
+ level: "debug",
162
+ format: process.env.ENV === "local" ? localFormat : winston.format.combine(winston.format.timestamp(), winston.format.json()),
163
+ defaultMeta: { service: process.env.AWS_LAMBDA_FUNCTION_NAME, script: namespace },
164
+ transports
165
+ });
166
+ logger.logtail = logtail;
167
+ return logger;
168
+ };
155
169
 
156
170
  // src/api.ts
157
171
  var log = logger_default("etainablApi");
@@ -768,8 +782,38 @@ __export(units_exports, {
768
782
  accountTypeUnitMap: () => accountTypeUnitMap,
769
783
  checkAccountTypeVsUnits: () => checkAccountTypeVsUnits,
770
784
  convertItems: () => convertItems,
771
- simpleConvert: () => simpleConvert
785
+ simpleConvert: () => simpleConvert,
786
+ unitTypes: () => unitTypes
772
787
  });
788
+ var unitTypes = [
789
+ "kwh",
790
+ "kg",
791
+ "m3",
792
+ "lbs",
793
+ "tonnes",
794
+ "wh",
795
+ "mwh",
796
+ "ft3",
797
+ "hcf",
798
+ "m3/h",
799
+ "qty",
800
+ "l",
801
+ "C",
802
+ "mcuf",
803
+ "hcuf",
804
+ "tcuf",
805
+ "ocuf",
806
+ "hm3",
807
+ "tm3",
808
+ "nm3",
809
+ "%",
810
+ "lux",
811
+ "ppm",
812
+ "db",
813
+ "hpa",
814
+ "ppb",
815
+ "count"
816
+ ];
773
817
  var accountTypeMap = {
774
818
  electricity: "kwh",
775
819
  gas: "kwh",
@@ -7177,6 +7221,7 @@ __export(integrations_exports, {
7177
7221
  createCsv: () => createCsv,
7178
7222
  dataFetchersIds: () => dataFetchersIds,
7179
7223
  deleteMessage: () => deleteMessage,
7224
+ errorCodeMap: () => errorCodeMap,
7180
7225
  errorCodes: () => errorCodes,
7181
7226
  handleError: () => handleError,
7182
7227
  sendEmail: () => sendEmail,
@@ -9040,6 +9085,51 @@ var errorCodes = [
9040
9085
  "VALIDATION_ERROR",
9041
9086
  "METER_READS_ZERO"
9042
9087
  ];
9088
+ var errorCodeMap = {
9089
+ ACCOUNT_NOT_FOUND: {
9090
+ status: "error",
9091
+ message: "Account not found for the provided device ID or MPAN.",
9092
+ isUnique: ({ details }, problems) => {
9093
+ return !problems.some((p4) => p4.code === "ACCOUNT_NOT_FOUND" && p4.details?.value === details?.value) || true;
9094
+ }
9095
+ },
9096
+ INVALID_DATE_FORMAT: {
9097
+ status: "error",
9098
+ message: "The date format in the file is invalid"
9099
+ },
9100
+ INVALID_TIME_FORMAT: {
9101
+ status: "error",
9102
+ message: "The time format in the file is invalid"
9103
+ },
9104
+ COLUMN_LIMIT_EXCEEDED: {
9105
+ status: "error",
9106
+ message: "The number of columns in the file exceeds the allowed limit.",
9107
+ unique: true
9108
+ },
9109
+ INVALID_TIMESTAMP: {
9110
+ status: "error",
9111
+ message: "The timestamp in the file is invalid."
9112
+ },
9113
+ MISSING_DEVICE_ID: {
9114
+ status: "error",
9115
+ message: "The device ID is missing in the file.",
9116
+ unique: true
9117
+ },
9118
+ UNSUPPORTED_UTILITY_TYPE: {
9119
+ status: "error",
9120
+ message: "The utility type in the file is not supported.",
9121
+ unique: true
9122
+ },
9123
+ VALIDATION_ERROR: {
9124
+ status: "error",
9125
+ message: "There was a validation error with the data in the file."
9126
+ },
9127
+ METER_READS_ZERO: {
9128
+ status: "warning",
9129
+ message: "Some meter reads are zero, which may indicate an issue with the data.",
9130
+ unique: true
9131
+ }
9132
+ };
9043
9133
  var dataFetchersIds = ["bacnet", "solis", "solarman", "gridfetch", "smartflow", "smartvatten", "beringar", "4dmonitoring"];
9044
9134
  function sendEmail(lambdaSource, context, error, destinations) {
9045
9135
  const sesClient = new SESClient({ region: "eu-west-1" });