@etainabl/nodejs-sdk 1.3.119 → 1.3.120

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/index.d.cts CHANGED
@@ -2,7 +2,9 @@ import * as axios from 'axios';
2
2
  import { CreateAxiosDefaults, AxiosInstance, AxiosRequestConfig } from 'axios';
3
3
  import { ObjectId, Db } from 'mongodb';
4
4
  export { ObjectId } from 'mongodb';
5
+ import * as _aws_sdk_client_ses from '@aws-sdk/client-ses';
5
6
  import { S3Client } from '@aws-sdk/client-s3';
7
+ import { Context } from 'aws-lambda';
6
8
  import { SQSClient } from '@aws-sdk/client-sqs';
7
9
  import winston from 'winston';
8
10
  import moment from 'moment';
@@ -624,6 +626,7 @@ interface HandleErrorParams {
624
626
  }
625
627
  declare const collectionTypes: readonly ["readings", "consumptions", "invoices"];
626
628
  declare const errorCodes: readonly ["ACCOUNT_NOT_FOUND", "INVALID_DATE_FORMAT", "INVALID_TIME_FORMAT", "COLUMN_LIMIT_EXCEEDED", "INVALID_TIMESTAMP", "MISSING_DEVICE_ID", "UNSUPPORTED_UTILITY_TYPE", "VALIDATION_ERROR", "METER_READS_ZERO"];
629
+ declare const dataFetchersIds: AutomationService[];
627
630
  type CollectionType = 'readings' | 'consumptions' | 'invoices';
628
631
  interface UploadCsv {
629
632
  csvContent: string;
@@ -632,6 +635,7 @@ interface UploadCsv {
632
635
  collectionType: CollectionType;
633
636
  orgFilename?: string;
634
637
  }
638
+ declare function sendEmail(lambdaSource: string, context: Context, error: Error, destinations: string[]): Promise<_aws_sdk_client_ses.SendEmailCommandOutput>;
635
639
  declare function createCsv(data: (FormattedConsumption | FormattedReading | FormattedInvoice)[]): string;
636
640
  declare function uploadCsv({ csvContent, automationRun, s3Client, orgFilename, collectionType }: UploadCsv): Promise<string>;
637
641
  declare function handleError({ etnApi, automationRun, error, lambdaSource, accountId }: HandleErrorParams): Promise<void>;
@@ -643,12 +647,14 @@ type integrations_FormattedInvoice = FormattedInvoice;
643
647
  type integrations_FormattedReading = FormattedReading;
644
648
  declare const integrations_collectionTypes: typeof collectionTypes;
645
649
  declare const integrations_createCsv: typeof createCsv;
650
+ declare const integrations_dataFetchersIds: typeof dataFetchersIds;
646
651
  declare const integrations_deleteMessage: typeof deleteMessage;
647
652
  declare const integrations_errorCodes: typeof errorCodes;
648
653
  declare const integrations_handleError: typeof handleError;
654
+ declare const integrations_sendEmail: typeof sendEmail;
649
655
  declare const integrations_uploadCsv: typeof uploadCsv;
650
656
  declare namespace integrations {
651
- export { type integrations_CollectionType as CollectionType, type integrations_FormattedConsumption as FormattedConsumption, type integrations_FormattedInvoice as FormattedInvoice, type integrations_FormattedReading as FormattedReading, integrations_collectionTypes as collectionTypes, integrations_createCsv as createCsv, integrations_deleteMessage as deleteMessage, integrations_errorCodes as errorCodes, integrations_handleError as handleError, integrations_uploadCsv as uploadCsv };
657
+ export { type integrations_CollectionType as CollectionType, type integrations_FormattedConsumption as FormattedConsumption, type integrations_FormattedInvoice as FormattedInvoice, type integrations_FormattedReading as FormattedReading, integrations_collectionTypes as collectionTypes, integrations_createCsv as createCsv, integrations_dataFetchersIds as dataFetchersIds, integrations_deleteMessage as deleteMessage, integrations_errorCodes as errorCodes, integrations_handleError as handleError, integrations_sendEmail as sendEmail, integrations_uploadCsv as uploadCsv };
652
658
  }
653
659
 
654
660
  interface AutomationRunLog<DateType = Date | string> {
@@ -740,6 +746,12 @@ interface AutomationRun<IDType = ObjectId | string, DateType = Date | string> {
740
746
  s3Key: string;
741
747
  fileName: string;
742
748
  };
749
+ importProcessing?: {
750
+ totalChunks: number;
751
+ chunksCompleted: number;
752
+ totalRecordsToProcess: number;
753
+ totalRecordsProcessed: number;
754
+ };
743
755
  }
744
756
 
745
757
  interface Consumption<IDType = ObjectId | string, DateType = Date> {
@@ -763,6 +775,7 @@ interface Consumption<IDType = ObjectId | string, DateType = Date> {
763
775
  userSub: string;
764
776
  invoiceId?: IDType;
765
777
  automationId?: IDType;
778
+ automationRunId?: IDType;
766
779
  accountId: IDType;
767
780
  entityId: IDType;
768
781
  companyId: IDType;
@@ -1191,6 +1204,7 @@ interface Reading<IDType = ObjectId | string, DateType = Date> {
1191
1204
  batchCorrectionId?: string;
1192
1205
  metadata?: Record<string, any>;
1193
1206
  automationId?: IDType;
1207
+ automationRunId?: IDType;
1194
1208
  createdAt?: DateType;
1195
1209
  updatedAt?: DateType;
1196
1210
  }
@@ -1478,6 +1492,7 @@ declare const _default$4: (auth: AuthOptions, instanceOptions?: CreateAxiosDefau
1478
1492
  updateAutomationRun: (id: string, data: any, options?: AxiosRequestConfig) => Promise<AutomationRun<string, string>>;
1479
1493
  createAutomationRunLog: (id: string, data: Omit<AutomationRunLog<string>, "date">, options?: AxiosRequestConfig) => Promise<AutomationRun<string, string | Date>>;
1480
1494
  searchAutomationRun: (options?: AxiosRequestConfig) => Promise<any>;
1495
+ updateAccountResults: (id: string, data: any, options?: AxiosRequestConfig) => Promise<AutomationRun<string, string | Date>>;
1481
1496
  globalSearch: (options?: AxiosRequestConfig) => Promise<any>;
1482
1497
  };
1483
1498
 
package/dist/index.d.ts CHANGED
@@ -2,7 +2,9 @@ import * as axios from 'axios';
2
2
  import { CreateAxiosDefaults, AxiosInstance, AxiosRequestConfig } from 'axios';
3
3
  import { ObjectId, Db } from 'mongodb';
4
4
  export { ObjectId } from 'mongodb';
5
+ import * as _aws_sdk_client_ses from '@aws-sdk/client-ses';
5
6
  import { S3Client } from '@aws-sdk/client-s3';
7
+ import { Context } from 'aws-lambda';
6
8
  import { SQSClient } from '@aws-sdk/client-sqs';
7
9
  import winston from 'winston';
8
10
  import moment from 'moment';
@@ -624,6 +626,7 @@ interface HandleErrorParams {
624
626
  }
625
627
  declare const collectionTypes: readonly ["readings", "consumptions", "invoices"];
626
628
  declare const errorCodes: readonly ["ACCOUNT_NOT_FOUND", "INVALID_DATE_FORMAT", "INVALID_TIME_FORMAT", "COLUMN_LIMIT_EXCEEDED", "INVALID_TIMESTAMP", "MISSING_DEVICE_ID", "UNSUPPORTED_UTILITY_TYPE", "VALIDATION_ERROR", "METER_READS_ZERO"];
629
+ declare const dataFetchersIds: AutomationService[];
627
630
  type CollectionType = 'readings' | 'consumptions' | 'invoices';
628
631
  interface UploadCsv {
629
632
  csvContent: string;
@@ -632,6 +635,7 @@ interface UploadCsv {
632
635
  collectionType: CollectionType;
633
636
  orgFilename?: string;
634
637
  }
638
+ declare function sendEmail(lambdaSource: string, context: Context, error: Error, destinations: string[]): Promise<_aws_sdk_client_ses.SendEmailCommandOutput>;
635
639
  declare function createCsv(data: (FormattedConsumption | FormattedReading | FormattedInvoice)[]): string;
636
640
  declare function uploadCsv({ csvContent, automationRun, s3Client, orgFilename, collectionType }: UploadCsv): Promise<string>;
637
641
  declare function handleError({ etnApi, automationRun, error, lambdaSource, accountId }: HandleErrorParams): Promise<void>;
@@ -643,12 +647,14 @@ type integrations_FormattedInvoice = FormattedInvoice;
643
647
  type integrations_FormattedReading = FormattedReading;
644
648
  declare const integrations_collectionTypes: typeof collectionTypes;
645
649
  declare const integrations_createCsv: typeof createCsv;
650
+ declare const integrations_dataFetchersIds: typeof dataFetchersIds;
646
651
  declare const integrations_deleteMessage: typeof deleteMessage;
647
652
  declare const integrations_errorCodes: typeof errorCodes;
648
653
  declare const integrations_handleError: typeof handleError;
654
+ declare const integrations_sendEmail: typeof sendEmail;
649
655
  declare const integrations_uploadCsv: typeof uploadCsv;
650
656
  declare namespace integrations {
651
- export { type integrations_CollectionType as CollectionType, type integrations_FormattedConsumption as FormattedConsumption, type integrations_FormattedInvoice as FormattedInvoice, type integrations_FormattedReading as FormattedReading, integrations_collectionTypes as collectionTypes, integrations_createCsv as createCsv, integrations_deleteMessage as deleteMessage, integrations_errorCodes as errorCodes, integrations_handleError as handleError, integrations_uploadCsv as uploadCsv };
657
+ export { type integrations_CollectionType as CollectionType, type integrations_FormattedConsumption as FormattedConsumption, type integrations_FormattedInvoice as FormattedInvoice, type integrations_FormattedReading as FormattedReading, integrations_collectionTypes as collectionTypes, integrations_createCsv as createCsv, integrations_dataFetchersIds as dataFetchersIds, integrations_deleteMessage as deleteMessage, integrations_errorCodes as errorCodes, integrations_handleError as handleError, integrations_sendEmail as sendEmail, integrations_uploadCsv as uploadCsv };
652
658
  }
653
659
 
654
660
  interface AutomationRunLog<DateType = Date | string> {
@@ -740,6 +746,12 @@ interface AutomationRun<IDType = ObjectId | string, DateType = Date | string> {
740
746
  s3Key: string;
741
747
  fileName: string;
742
748
  };
749
+ importProcessing?: {
750
+ totalChunks: number;
751
+ chunksCompleted: number;
752
+ totalRecordsToProcess: number;
753
+ totalRecordsProcessed: number;
754
+ };
743
755
  }
744
756
 
745
757
  interface Consumption<IDType = ObjectId | string, DateType = Date> {
@@ -763,6 +775,7 @@ interface Consumption<IDType = ObjectId | string, DateType = Date> {
763
775
  userSub: string;
764
776
  invoiceId?: IDType;
765
777
  automationId?: IDType;
778
+ automationRunId?: IDType;
766
779
  accountId: IDType;
767
780
  entityId: IDType;
768
781
  companyId: IDType;
@@ -1191,6 +1204,7 @@ interface Reading<IDType = ObjectId | string, DateType = Date> {
1191
1204
  batchCorrectionId?: string;
1192
1205
  metadata?: Record<string, any>;
1193
1206
  automationId?: IDType;
1207
+ automationRunId?: IDType;
1194
1208
  createdAt?: DateType;
1195
1209
  updatedAt?: DateType;
1196
1210
  }
@@ -1478,6 +1492,7 @@ declare const _default$4: (auth: AuthOptions, instanceOptions?: CreateAxiosDefau
1478
1492
  updateAutomationRun: (id: string, data: any, options?: AxiosRequestConfig) => Promise<AutomationRun<string, string>>;
1479
1493
  createAutomationRunLog: (id: string, data: Omit<AutomationRunLog<string>, "date">, options?: AxiosRequestConfig) => Promise<AutomationRun<string, string | Date>>;
1480
1494
  searchAutomationRun: (options?: AxiosRequestConfig) => Promise<any>;
1495
+ updateAccountResults: (id: string, data: any, options?: AxiosRequestConfig) => Promise<AutomationRun<string, string | Date>>;
1481
1496
  globalSearch: (options?: AxiosRequestConfig) => Promise<any>;
1482
1497
  };
1483
1498
 
package/dist/index.js CHANGED
@@ -16183,7 +16183,7 @@ var factory = {
16183
16183
  method: "GET",
16184
16184
  url: `${endpoint}/${id}${postEndpoint ? `/${postEndpoint}` : ""}`
16185
16185
  };
16186
- log.info(`API Request: ${req.method} ${process.env.ETAsINABL_API_URL}/${req.url}`);
16186
+ log.info(`API Request: ${req.method} ${process.env.ETAINABL_API_URL}/${req.url}`);
16187
16187
  let res;
16188
16188
  try {
16189
16189
  res = await etainablApi.get(req.url, options);
@@ -16366,7 +16366,7 @@ var api_default = (auth, instanceOptions = {}) => {
16366
16366
  createAutomationLog: subFactory.create(etainablApi, "automation", "logs"),
16367
16367
  updateAutomationLog: subFactory.update(etainablApi, "automation", "logs"),
16368
16368
  removeAutomationLog: subFactory.remove(etainablApi, "automation", "logs"),
16369
- updateAccountStatusForAutomation: subFactory.update(etainablApi, "automation", "status"),
16369
+ updateAccountStatusForAutomation: subFactory.update(etainablApi, "automation", "account-status"),
16370
16370
  // company
16371
16371
  getCompany: factory.getWithId(etainablApi, "companies"),
16372
16372
  getCompanyInvoiceValidationRules: factory.getWithId(
@@ -16492,6 +16492,7 @@ var api_default = (auth, instanceOptions = {}) => {
16492
16492
  "logs"
16493
16493
  ),
16494
16494
  searchAutomationRun: factory.get(etainablApi, "automation-runs", "search"),
16495
+ updateAccountResults: factory.update(etainablApi, "automation-runs", "import"),
16495
16496
  // global search
16496
16497
  globalSearch: factory.get(etainablApi, "global-search", "search")
16497
16498
  };
@@ -17485,9 +17486,11 @@ var integrations_exports = {};
17485
17486
  __export(integrations_exports, {
17486
17487
  collectionTypes: () => collectionTypes,
17487
17488
  createCsv: () => createCsv,
17489
+ dataFetchersIds: () => dataFetchersIds,
17488
17490
  deleteMessage: () => deleteMessage,
17489
17491
  errorCodes: () => errorCodes,
17490
17492
  handleError: () => handleError,
17493
+ sendEmail: () => sendEmail,
17491
17494
  uploadCsv: () => uploadCsv
17492
17495
  });
17493
17496
  var import_sync = require("csv-stringify/sync");
@@ -21611,6 +21614,7 @@ var PutObjectCommand = class extends Command.classBuilder().ep({
21611
21614
  };
21612
21615
 
21613
21616
  // src/integrations.ts
21617
+ var import_client_ses = require("@aws-sdk/client-ses");
21614
21618
  var import_client_sqs = require("@aws-sdk/client-sqs");
21615
21619
  var collectionTypes = ["readings", "consumptions", "invoices"];
21616
21620
  var errorCodes = [
@@ -21624,6 +21628,28 @@ var errorCodes = [
21624
21628
  "VALIDATION_ERROR",
21625
21629
  "METER_READS_ZERO"
21626
21630
  ];
21631
+ var dataFetchersIds = ["bacnet", "solis", "solarman", "gridfetch", "smartflow", "smartvatten", "beringar", "4dmonitoring"];
21632
+ function sendEmail(lambdaSource, context, error, destinations) {
21633
+ const sesClient = new import_client_ses.SESClient({ region: "eu-west-1" });
21634
+ const template = emailTemplate_default({
21635
+ title: `WARNING: ${lambdaSource} Lambda Failed`,
21636
+ alertLevel: "warning",
21637
+ message: `Error: ${error.message}. AWS Log Stream: ${context.logStreamName}, AWS Request ID: ${context.awsRequestId}`
21638
+ });
21639
+ const emailCommand = new import_client_ses.SendEmailCommand({
21640
+ Source: `alerts@${process.env.EMAIL_DOMAIN}`,
21641
+ Destination: {
21642
+ ToAddresses: destinations
21643
+ },
21644
+ Message: {
21645
+ Subject: { Data: `WARNING: New Alert for the ${lambdaSource}` },
21646
+ Body: {
21647
+ Html: { Data: template }
21648
+ }
21649
+ }
21650
+ });
21651
+ return sesClient.send(emailCommand);
21652
+ }
21627
21653
  function createCsv(data) {
21628
21654
  function flattenObject(obj, prefix = "") {
21629
21655
  const flattened = {};