@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/esm/index.js CHANGED
@@ -1471,8 +1471,9 @@ var integrations_exports = {};
1471
1471
  __export(integrations_exports, {
1472
1472
  collectionTypes: () => collectionTypes,
1473
1473
  createCsv: () => createCsv,
1474
+ deleteMessage: () => deleteMessage,
1474
1475
  errorCodes: () => errorCodes,
1475
- sendToDLQ: () => sendToDLQ,
1476
+ handleError: () => handleError,
1476
1477
  uploadCsv: () => uploadCsv
1477
1478
  });
1478
1479
  import { stringify } from "csv-stringify/sync";
@@ -5461,7 +5462,7 @@ var PutObjectCommand = class extends Command.classBuilder().ep({
5461
5462
  };
5462
5463
 
5463
5464
  // src/integrations.ts
5464
- import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
5465
+ import { SQSClient, DeleteMessageCommand } from "@aws-sdk/client-sqs";
5465
5466
  var collectionTypes = ["readings", "consumptions", "invoices"];
5466
5467
  var errorCodes = [
5467
5468
  "ACCOUNT_NOT_FOUND",
@@ -5474,66 +5475,6 @@ var errorCodes = [
5474
5475
  "VALIDATION_ERROR",
5475
5476
  "METER_READS_ZERO"
5476
5477
  ];
5477
- async function sendToDLQ({ payload, sqsClient }) {
5478
- if (!process.env.DEAD_LETTER_QUEUE_URL) {
5479
- throw new Error("QueueUrl is required to send to DLQ");
5480
- }
5481
- if (!payload || !payload.account) {
5482
- throw new Error("Payload and account information are required");
5483
- }
5484
- const { automation, account, context, error } = payload;
5485
- if (!context || !context.processingStage) {
5486
- throw new Error("Context with processingStage is required");
5487
- }
5488
- if (!account || !account._id) {
5489
- throw new Error("Account information with _id is required");
5490
- }
5491
- if (!error || !error.message || !error.timestamp) {
5492
- throw new Error("Error information with message and timestamp is required");
5493
- }
5494
- if (!automation || !automation._id) {
5495
- throw new Error("Automation information with _id is required");
5496
- }
5497
- if (!sqsClient) {
5498
- sqsClient = new SQSClient({ region: "eu-west-1" });
5499
- }
5500
- await sqsClient.send(
5501
- new SendMessageCommand({
5502
- QueueUrl: process.env.DEAD_LETTER_QUEUE_URL,
5503
- MessageBody: JSON.stringify(payload),
5504
- MessageAttributes: {
5505
- service: {
5506
- DataType: "String",
5507
- StringValue: automation.service
5508
- },
5509
- accountId: {
5510
- DataType: "String",
5511
- StringValue: account._id || "unknown"
5512
- },
5513
- category: {
5514
- DataType: "String",
5515
- StringValue: automation.category || "unknown"
5516
- },
5517
- automationId: {
5518
- DataType: "String",
5519
- StringValue: automation._id || "unknown"
5520
- },
5521
- processingStage: {
5522
- DataType: "String",
5523
- StringValue: context.processingStage
5524
- },
5525
- timestamp: {
5526
- DataType: "String",
5527
- StringValue: error.timestamp
5528
- },
5529
- lambdaFunctionName: {
5530
- DataType: "String",
5531
- StringValue: process.env.AWS_LAMBDA_FUNCTION_NAME || "unknown"
5532
- }
5533
- }
5534
- })
5535
- );
5536
- }
5537
5478
  function createCsv(data) {
5538
5479
  function flattenObject(obj, prefix = "") {
5539
5480
  const flattened = {};
@@ -5614,6 +5555,44 @@ async function uploadCsv({ csvContent, automationRun, s3Client, orgFilename, col
5614
5555
  throw new Error(error);
5615
5556
  }
5616
5557
  }
5558
+ async function handleError({ etnApi, automationRun, error, lambdaSource, accountId }) {
5559
+ await etnApi.createAutomationRunLog(automationRun._id, {
5560
+ message: error.message,
5561
+ status: "error",
5562
+ lambdaSource
5563
+ });
5564
+ const message = automationRun.source?.fileName ? `Automation "${automationRun.description}" FAILED while processing file: ${automationRun.source.fileName}` : `Automation "${automationRun.description}" FAILED.`;
5565
+ await etnApi.createLog({
5566
+ message,
5567
+ context: {
5568
+ status: "error",
5569
+ error: error.message,
5570
+ automationId: automationRun.automationId,
5571
+ automationDescription: automationRun.description,
5572
+ automationRunId: automationRun._id
5573
+ },
5574
+ type: "automation-ingest",
5575
+ userSub: lambdaSource,
5576
+ companyId: automationRun.companyId
5577
+ });
5578
+ if (accountId) {
5579
+ await etnApi.updateAccountStatusForAutomation(automationRun.automationId, accountId, { status: "error" });
5580
+ }
5581
+ }
5582
+ async function deleteMessage(queueUrl, receiptHandle, sqsClient) {
5583
+ if (!queueUrl || !receiptHandle) {
5584
+ throw new Error("QueueUrl and ReceiptHandle are required to delete a message");
5585
+ }
5586
+ if (!sqsClient) {
5587
+ sqsClient = new SQSClient({ region: "eu-west-1" });
5588
+ }
5589
+ const deleteMessageCommand = new DeleteMessageCommand({
5590
+ QueueUrl: queueUrl,
5591
+ ReceiptHandle: receiptHandle
5592
+ });
5593
+ await sqsClient.send(deleteMessageCommand);
5594
+ console.log("Deleted SQS message", { ReceiptHandle: receiptHandle });
5595
+ }
5617
5596
 
5618
5597
  // src/types/index.ts
5619
5598
  import { ObjectId } from "mongodb";