@etainabl/nodejs-sdk 1.3.117 → 1.3.119

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
@@ -615,23 +615,15 @@ interface Automation<IDType = ObjectId | string> {
615
615
  type FormattedConsumption = Omit<Consumption<string, string>, '_id'>;
616
616
  type FormattedReading = Omit<Reading<string, string>, '_id'>;
617
617
  type FormattedInvoice = Omit<Invoice<string, string>, '_id' | 's3Key'>;
618
- declare const collectionTypes: readonly ["readings", "consumptions", "invoices"];
619
- 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"];
620
- interface DLQPayload {
621
- originalMessage: string;
622
- account?: Account<string>;
623
- automation: Automation<string>;
618
+ interface HandleErrorParams {
619
+ etnApi: ReturnType<typeof _default$4>;
624
620
  automationRun: AutomationRun<string>;
625
- error: {
626
- message: string;
627
- stack?: string;
628
- timestamp: string;
629
- };
630
- context: {
631
- messageId: string;
632
- processingStage?: string;
633
- };
621
+ lambdaSource: string;
622
+ error: Error;
623
+ accountId?: string;
634
624
  }
625
+ declare const collectionTypes: readonly ["readings", "consumptions", "invoices"];
626
+ 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"];
635
627
  type CollectionType = 'readings' | 'consumptions' | 'invoices';
636
628
  interface UploadCsv {
637
629
  csvContent: string;
@@ -640,25 +632,23 @@ interface UploadCsv {
640
632
  collectionType: CollectionType;
641
633
  orgFilename?: string;
642
634
  }
643
- declare function sendToDLQ({ payload, sqsClient }: {
644
- payload: Partial<DLQPayload>;
645
- sqsClient?: SQSClient;
646
- }): Promise<void>;
647
635
  declare function createCsv(data: (FormattedConsumption | FormattedReading | FormattedInvoice)[]): string;
648
636
  declare function uploadCsv({ csvContent, automationRun, s3Client, orgFilename, collectionType }: UploadCsv): Promise<string>;
637
+ declare function handleError({ etnApi, automationRun, error, lambdaSource, accountId }: HandleErrorParams): Promise<void>;
638
+ declare function deleteMessage(queueUrl: string, receiptHandle: string, sqsClient?: SQSClient): Promise<void>;
649
639
 
650
640
  type integrations_CollectionType = CollectionType;
651
- type integrations_DLQPayload = DLQPayload;
652
641
  type integrations_FormattedConsumption = FormattedConsumption;
653
642
  type integrations_FormattedInvoice = FormattedInvoice;
654
643
  type integrations_FormattedReading = FormattedReading;
655
644
  declare const integrations_collectionTypes: typeof collectionTypes;
656
645
  declare const integrations_createCsv: typeof createCsv;
646
+ declare const integrations_deleteMessage: typeof deleteMessage;
657
647
  declare const integrations_errorCodes: typeof errorCodes;
658
- declare const integrations_sendToDLQ: typeof sendToDLQ;
648
+ declare const integrations_handleError: typeof handleError;
659
649
  declare const integrations_uploadCsv: typeof uploadCsv;
660
650
  declare namespace integrations {
661
- export { type integrations_CollectionType as CollectionType, type integrations_DLQPayload as DLQPayload, type integrations_FormattedConsumption as FormattedConsumption, type integrations_FormattedInvoice as FormattedInvoice, type integrations_FormattedReading as FormattedReading, integrations_collectionTypes as collectionTypes, integrations_createCsv as createCsv, integrations_errorCodes as errorCodes, integrations_sendToDLQ as sendToDLQ, integrations_uploadCsv as uploadCsv };
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 };
662
652
  }
663
653
 
664
654
  interface AutomationRunLog<DateType = Date | string> {
@@ -676,8 +666,7 @@ interface AccountResult<IDType = ObjectId | string, DateType = Date | string> {
676
666
  mpan: string;
677
667
  deviceId?: string;
678
668
  status: 'success' | 'warning' | 'error' | 'running';
679
- processedRows?: number;
680
- failedRows?: number;
669
+ rowsProcessed?: number;
681
670
  dateRange?: {
682
671
  from?: DateType;
683
672
  to?: DateType;
@@ -736,6 +725,7 @@ interface AutomationRun<IDType = ObjectId | string, DateType = Date | string> {
736
725
  _id: IDType;
737
726
  automationId: IDType;
738
727
  companyId: IDType;
728
+ description: string;
739
729
  active: boolean;
740
730
  category: 'dataFetcher' | 'dataExtractor';
741
731
  status: 'running' | 'success' | 'failed' | 'completedWithWarnings';
package/dist/index.d.ts CHANGED
@@ -615,23 +615,15 @@ interface Automation<IDType = ObjectId | string> {
615
615
  type FormattedConsumption = Omit<Consumption<string, string>, '_id'>;
616
616
  type FormattedReading = Omit<Reading<string, string>, '_id'>;
617
617
  type FormattedInvoice = Omit<Invoice<string, string>, '_id' | 's3Key'>;
618
- declare const collectionTypes: readonly ["readings", "consumptions", "invoices"];
619
- 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"];
620
- interface DLQPayload {
621
- originalMessage: string;
622
- account?: Account<string>;
623
- automation: Automation<string>;
618
+ interface HandleErrorParams {
619
+ etnApi: ReturnType<typeof _default$4>;
624
620
  automationRun: AutomationRun<string>;
625
- error: {
626
- message: string;
627
- stack?: string;
628
- timestamp: string;
629
- };
630
- context: {
631
- messageId: string;
632
- processingStage?: string;
633
- };
621
+ lambdaSource: string;
622
+ error: Error;
623
+ accountId?: string;
634
624
  }
625
+ declare const collectionTypes: readonly ["readings", "consumptions", "invoices"];
626
+ 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"];
635
627
  type CollectionType = 'readings' | 'consumptions' | 'invoices';
636
628
  interface UploadCsv {
637
629
  csvContent: string;
@@ -640,25 +632,23 @@ interface UploadCsv {
640
632
  collectionType: CollectionType;
641
633
  orgFilename?: string;
642
634
  }
643
- declare function sendToDLQ({ payload, sqsClient }: {
644
- payload: Partial<DLQPayload>;
645
- sqsClient?: SQSClient;
646
- }): Promise<void>;
647
635
  declare function createCsv(data: (FormattedConsumption | FormattedReading | FormattedInvoice)[]): string;
648
636
  declare function uploadCsv({ csvContent, automationRun, s3Client, orgFilename, collectionType }: UploadCsv): Promise<string>;
637
+ declare function handleError({ etnApi, automationRun, error, lambdaSource, accountId }: HandleErrorParams): Promise<void>;
638
+ declare function deleteMessage(queueUrl: string, receiptHandle: string, sqsClient?: SQSClient): Promise<void>;
649
639
 
650
640
  type integrations_CollectionType = CollectionType;
651
- type integrations_DLQPayload = DLQPayload;
652
641
  type integrations_FormattedConsumption = FormattedConsumption;
653
642
  type integrations_FormattedInvoice = FormattedInvoice;
654
643
  type integrations_FormattedReading = FormattedReading;
655
644
  declare const integrations_collectionTypes: typeof collectionTypes;
656
645
  declare const integrations_createCsv: typeof createCsv;
646
+ declare const integrations_deleteMessage: typeof deleteMessage;
657
647
  declare const integrations_errorCodes: typeof errorCodes;
658
- declare const integrations_sendToDLQ: typeof sendToDLQ;
648
+ declare const integrations_handleError: typeof handleError;
659
649
  declare const integrations_uploadCsv: typeof uploadCsv;
660
650
  declare namespace integrations {
661
- export { type integrations_CollectionType as CollectionType, type integrations_DLQPayload as DLQPayload, type integrations_FormattedConsumption as FormattedConsumption, type integrations_FormattedInvoice as FormattedInvoice, type integrations_FormattedReading as FormattedReading, integrations_collectionTypes as collectionTypes, integrations_createCsv as createCsv, integrations_errorCodes as errorCodes, integrations_sendToDLQ as sendToDLQ, integrations_uploadCsv as uploadCsv };
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 };
662
652
  }
663
653
 
664
654
  interface AutomationRunLog<DateType = Date | string> {
@@ -676,8 +666,7 @@ interface AccountResult<IDType = ObjectId | string, DateType = Date | string> {
676
666
  mpan: string;
677
667
  deviceId?: string;
678
668
  status: 'success' | 'warning' | 'error' | 'running';
679
- processedRows?: number;
680
- failedRows?: number;
669
+ rowsProcessed?: number;
681
670
  dateRange?: {
682
671
  from?: DateType;
683
672
  to?: DateType;
@@ -736,6 +725,7 @@ interface AutomationRun<IDType = ObjectId | string, DateType = Date | string> {
736
725
  _id: IDType;
737
726
  automationId: IDType;
738
727
  companyId: IDType;
728
+ description: string;
739
729
  active: boolean;
740
730
  category: 'dataFetcher' | 'dataExtractor';
741
731
  status: 'running' | 'success' | 'failed' | 'completedWithWarnings';
package/dist/index.js CHANGED
@@ -17485,8 +17485,9 @@ var integrations_exports = {};
17485
17485
  __export(integrations_exports, {
17486
17486
  collectionTypes: () => collectionTypes,
17487
17487
  createCsv: () => createCsv,
17488
+ deleteMessage: () => deleteMessage,
17488
17489
  errorCodes: () => errorCodes,
17489
- sendToDLQ: () => sendToDLQ,
17490
+ handleError: () => handleError,
17490
17491
  uploadCsv: () => uploadCsv
17491
17492
  });
17492
17493
  var import_sync = require("csv-stringify/sync");
@@ -21623,66 +21624,6 @@ var errorCodes = [
21623
21624
  "VALIDATION_ERROR",
21624
21625
  "METER_READS_ZERO"
21625
21626
  ];
21626
- async function sendToDLQ({ payload, sqsClient }) {
21627
- if (!process.env.DEAD_LETTER_QUEUE_URL) {
21628
- throw new Error("QueueUrl is required to send to DLQ");
21629
- }
21630
- if (!payload || !payload.account) {
21631
- throw new Error("Payload and account information are required");
21632
- }
21633
- const { automation, account, context, error } = payload;
21634
- if (!context || !context.processingStage) {
21635
- throw new Error("Context with processingStage is required");
21636
- }
21637
- if (!account || !account._id) {
21638
- throw new Error("Account information with _id is required");
21639
- }
21640
- if (!error || !error.message || !error.timestamp) {
21641
- throw new Error("Error information with message and timestamp is required");
21642
- }
21643
- if (!automation || !automation._id) {
21644
- throw new Error("Automation information with _id is required");
21645
- }
21646
- if (!sqsClient) {
21647
- sqsClient = new import_client_sqs.SQSClient({ region: "eu-west-1" });
21648
- }
21649
- await sqsClient.send(
21650
- new import_client_sqs.SendMessageCommand({
21651
- QueueUrl: process.env.DEAD_LETTER_QUEUE_URL,
21652
- MessageBody: JSON.stringify(payload),
21653
- MessageAttributes: {
21654
- service: {
21655
- DataType: "String",
21656
- StringValue: automation.service
21657
- },
21658
- accountId: {
21659
- DataType: "String",
21660
- StringValue: account._id || "unknown"
21661
- },
21662
- category: {
21663
- DataType: "String",
21664
- StringValue: automation.category || "unknown"
21665
- },
21666
- automationId: {
21667
- DataType: "String",
21668
- StringValue: automation._id || "unknown"
21669
- },
21670
- processingStage: {
21671
- DataType: "String",
21672
- StringValue: context.processingStage
21673
- },
21674
- timestamp: {
21675
- DataType: "String",
21676
- StringValue: error.timestamp
21677
- },
21678
- lambdaFunctionName: {
21679
- DataType: "String",
21680
- StringValue: process.env.AWS_LAMBDA_FUNCTION_NAME || "unknown"
21681
- }
21682
- }
21683
- })
21684
- );
21685
- }
21686
21627
  function createCsv(data) {
21687
21628
  function flattenObject(obj, prefix = "") {
21688
21629
  const flattened = {};
@@ -21763,6 +21704,44 @@ async function uploadCsv({ csvContent, automationRun, s3Client, orgFilename, col
21763
21704
  throw new Error(error);
21764
21705
  }
21765
21706
  }
21707
+ async function handleError({ etnApi, automationRun, error, lambdaSource, accountId }) {
21708
+ await etnApi.createAutomationRunLog(automationRun._id, {
21709
+ message: error.message,
21710
+ status: "error",
21711
+ lambdaSource
21712
+ });
21713
+ const message = automationRun.source?.fileName ? `Automation "${automationRun.description}" FAILED while processing file: ${automationRun.source.fileName}` : `Automation "${automationRun.description}" FAILED.`;
21714
+ await etnApi.createLog({
21715
+ message,
21716
+ context: {
21717
+ status: "error",
21718
+ error: error.message,
21719
+ automationId: automationRun.automationId,
21720
+ automationDescription: automationRun.description,
21721
+ automationRunId: automationRun._id
21722
+ },
21723
+ type: "automation-ingest",
21724
+ userSub: lambdaSource,
21725
+ companyId: automationRun.companyId
21726
+ });
21727
+ if (accountId) {
21728
+ await etnApi.updateAccountStatusForAutomation(automationRun.automationId, accountId, { status: "error" });
21729
+ }
21730
+ }
21731
+ async function deleteMessage(queueUrl, receiptHandle, sqsClient) {
21732
+ if (!queueUrl || !receiptHandle) {
21733
+ throw new Error("QueueUrl and ReceiptHandle are required to delete a message");
21734
+ }
21735
+ if (!sqsClient) {
21736
+ sqsClient = new import_client_sqs.SQSClient({ region: "eu-west-1" });
21737
+ }
21738
+ const deleteMessageCommand = new import_client_sqs.DeleteMessageCommand({
21739
+ QueueUrl: queueUrl,
21740
+ ReceiptHandle: receiptHandle
21741
+ });
21742
+ await sqsClient.send(deleteMessageCommand);
21743
+ console.log("Deleted SQS message", { ReceiptHandle: receiptHandle });
21744
+ }
21766
21745
 
21767
21746
  // src/types/index.ts
21768
21747
  var import_mongodb2 = require("mongodb");