@etainabl/nodejs-sdk 1.3.184 → 1.3.187

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
@@ -5665,28 +5665,42 @@ function getBetterStackToken() {
5665
5665
  })();
5666
5666
  return tokenFetchPromise;
5667
5667
  }
5668
- var logger_default = (namespace, betterStackOptions) => {
5668
+ function createBaseLogger(namespace, options) {
5669
5669
  const transports = [new winston.transports.Console()];
5670
- const logger = winston.createLogger({
5670
+ const defaultMeta = {
5671
+ service: process.env.AWS_LAMBDA_FUNCTION_NAME,
5672
+ script: namespace
5673
+ };
5674
+ if (options?.feature) {
5675
+ defaultMeta.feature = options.feature;
5676
+ }
5677
+ const logger2 = winston.createLogger({
5671
5678
  level: "debug",
5672
5679
  format: process.env.ENV === "local" ? localFormat : winston.format.combine(winston.format.timestamp(), winston.format.json()),
5673
- defaultMeta: { service: process.env.AWS_LAMBDA_FUNCTION_NAME, script: namespace },
5680
+ defaultMeta,
5674
5681
  transports
5675
5682
  });
5676
- logger.logtail = void 0;
5677
- if (betterStackOptions?.betterstack && betterStackOptions?.betterStackHost && (process.env.ENV === "prod" || process.env.ENV === "dev")) {
5678
- getBetterStackToken().then((token) => {
5679
- if (token) {
5680
- const logtail = new Logtail(token, {
5681
- endpoint: betterStackOptions.betterStackHost
5682
- });
5683
- logger.logtail = logtail;
5684
- logger.add(new LogtailTransport(logtail));
5685
- }
5686
- });
5687
- }
5688
- return logger;
5689
- };
5683
+ logger2.logtail = void 0;
5684
+ return logger2;
5685
+ }
5686
+ function logger(namespace, options) {
5687
+ return createBaseLogger(namespace, options);
5688
+ }
5689
+ async function loggerWithBetterStack(namespace, options) {
5690
+ const baseLogger2 = createBaseLogger(namespace, options);
5691
+ const betterStackHost = process.env.BETTERSTACK_HOST;
5692
+ if (betterStackHost && (process.env.ENV === "prod" || process.env.ENV === "dev")) {
5693
+ const token = await getBetterStackToken();
5694
+ if (token) {
5695
+ const endpoint = betterStackHost.startsWith("https://") ? betterStackHost : `https://${betterStackHost}`;
5696
+ const logtail = new Logtail(token, { endpoint });
5697
+ baseLogger2.logtail = logtail;
5698
+ baseLogger2.add(new LogtailTransport(logtail));
5699
+ }
5700
+ }
5701
+ return baseLogger2;
5702
+ }
5703
+ var logger_default = logger;
5690
5704
 
5691
5705
  // src/api.ts
5692
5706
  var log = logger_default("etainablApi");
@@ -6620,9 +6634,6 @@ var slack_default = {
6620
6634
  postMessage
6621
6635
  };
6622
6636
 
6623
- // src/notification.ts
6624
- var notification_exports = {};
6625
-
6626
6637
  // src/notificationQueue.ts
6627
6638
  var notificationQueue_exports = {};
6628
6639
  __export(notificationQueue_exports, {
@@ -6763,7 +6774,7 @@ var ByteArrayCollector = class {
6763
6774
  };
6764
6775
 
6765
6776
  // node_modules/@smithy/util-stream/dist-es/createBufferedReadableStream.js
6766
- function createBufferedReadableStream(upstream, size, logger) {
6777
+ function createBufferedReadableStream(upstream, size, logger2) {
6767
6778
  const reader = upstream.getReader();
6768
6779
  let streamBufferingLoggedWarning = false;
6769
6780
  let bytesSeen = 0;
@@ -6801,7 +6812,7 @@ function createBufferedReadableStream(upstream, size, logger) {
6801
6812
  const newSize = merge(buffers, mode, chunk3);
6802
6813
  if (!streamBufferingLoggedWarning && bytesSeen > size * 2) {
6803
6814
  streamBufferingLoggedWarning = true;
6804
- logger?.warn(`@smithy/util-stream - stream chunk size ${chunkSize} is below threshold of ${size}, automatically buffering.`);
6815
+ logger2?.warn(`@smithy/util-stream - stream chunk size ${chunkSize} is below threshold of ${size}, automatically buffering.`);
6805
6816
  }
6806
6817
  if (newSize >= size) {
6807
6818
  controller.enqueue(flush(buffers, mode));
@@ -6855,9 +6866,9 @@ function modeOf(chunk3, allowBuffer = true) {
6855
6866
  }
6856
6867
 
6857
6868
  // node_modules/@smithy/util-stream/dist-es/createBufferedReadable.js
6858
- function createBufferedReadable(upstream, size, logger) {
6869
+ function createBufferedReadable(upstream, size, logger2) {
6859
6870
  if (isReadableStream(upstream)) {
6860
- return createBufferedReadableStream(upstream, size, logger);
6871
+ return createBufferedReadableStream(upstream, size, logger2);
6861
6872
  }
6862
6873
  const downstream = new Readable({ read() {
6863
6874
  } });
@@ -6890,7 +6901,7 @@ function createBufferedReadable(upstream, size, logger) {
6890
6901
  const newSize = merge(buffers, mode, chunk3);
6891
6902
  if (!streamBufferingLoggedWarning && bytesSeen > size * 2) {
6892
6903
  streamBufferingLoggedWarning = true;
6893
- logger?.warn(`@smithy/util-stream - stream chunk size ${chunkSize} is below threshold of ${size}, automatically buffering.`);
6904
+ logger2?.warn(`@smithy/util-stream - stream chunk size ${chunkSize} is below threshold of ${size}, automatically buffering.`);
6894
6905
  }
6895
6906
  if (newSize >= size) {
6896
6907
  downstream.push(flush(buffers, mode));
@@ -7050,12 +7061,12 @@ function queueUrlMiddleware({ useQueueUrlAsEndpoint, endpoint }) {
7050
7061
  const { input } = args;
7051
7062
  const resolvedEndpoint = context.endpointV2;
7052
7063
  if (!endpoint && input.QueueUrl && resolvedEndpoint && useQueueUrlAsEndpoint) {
7053
- const logger = context.logger instanceof NoOpLogger || !context.logger?.warn ? console : context.logger;
7064
+ const logger2 = context.logger instanceof NoOpLogger || !context.logger?.warn ? console : context.logger;
7054
7065
  try {
7055
7066
  const queueUrl = new URL(input.QueueUrl);
7056
7067
  const queueUrlOrigin = new URL(queueUrl.origin);
7057
7068
  if (resolvedEndpoint.url.origin !== queueUrlOrigin.origin) {
7058
- logger.warn(`QueueUrl=${input.QueueUrl} differs from SQSClient resolved endpoint=${resolvedEndpoint.url.toString()}, using QueueUrl host as endpoint.
7069
+ logger2.warn(`QueueUrl=${input.QueueUrl} differs from SQSClient resolved endpoint=${resolvedEndpoint.url.toString()}, using QueueUrl host as endpoint.
7059
7070
  Set [endpoint=string] or [useQueueUrlAsEndpoint=false] on the SQSClient.`);
7060
7071
  context.endpointV2 = {
7061
7072
  ...resolvedEndpoint,
@@ -7063,7 +7074,7 @@ Set [endpoint=string] or [useQueueUrlAsEndpoint=false] on the SQSClient.`);
7063
7074
  };
7064
7075
  }
7065
7076
  } catch (e4) {
7066
- logger.warn(e4);
7077
+ logger2.warn(e4);
7067
7078
  }
7068
7079
  }
7069
7080
  return next(args);
@@ -8901,6 +8912,7 @@ __export(utils_exports, {
8901
8912
  getMeterPointNumberBottomLine: () => getMeterPointNumberBottomLine,
8902
8913
  isTransientError: () => isTransientError,
8903
8914
  paginatedFetch: () => paginatedFetch,
8915
+ resolveNotificationPreferences: () => resolveNotificationPreferences,
8904
8916
  sendToSqsBatched: () => sendToSqsBatched,
8905
8917
  units: () => units,
8906
8918
  updateBatchJobStatus: () => updateBatchJobStatus,
@@ -9219,6 +9231,7 @@ async function updateBatchJobStatus({
9219
9231
  errorMessage
9220
9232
  }) {
9221
9233
  if (!automationRun) return;
9234
+ if (automationRun.category !== "account") return;
9222
9235
  const jobKey = automationRun.jobId;
9223
9236
  const resolvedAccountKey = accountKey ?? automationRun.accountResults?.[0]?.id?.toString();
9224
9237
  if (!jobKey || !resolvedAccountKey) return;
@@ -10442,7 +10455,7 @@ var isChecksumWithPartNumber = (checksum) => {
10442
10455
  var getChecksum = async (body, { checksumAlgorithmFn, base64Encoder }) => base64Encoder(await stringHasher(checksumAlgorithmFn, body));
10443
10456
 
10444
10457
  // node_modules/@aws-sdk/middleware-flexible-checksums/dist-es/validateChecksumFromResponse.js
10445
- var validateChecksumFromResponse = async (response, { config, responseAlgorithms, logger }) => {
10458
+ var validateChecksumFromResponse = async (response, { config, responseAlgorithms, logger: logger2 }) => {
10446
10459
  const checksumAlgorithms = getChecksumAlgorithmListForResponse(responseAlgorithms);
10447
10460
  const { body: responseBody, headers: responseHeaders } = response;
10448
10461
  for (const algorithm of checksumAlgorithms) {
@@ -10454,7 +10467,7 @@ var validateChecksumFromResponse = async (response, { config, responseAlgorithms
10454
10467
  checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config);
10455
10468
  } catch (error) {
10456
10469
  if (algorithm === ChecksumAlgorithm.CRC64NVME) {
10457
- logger?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`);
10470
+ logger2?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`);
10458
10471
  continue;
10459
10472
  }
10460
10473
  throw error;
@@ -13710,6 +13723,80 @@ var sendToSqsBatched = async (messages, options) => {
13710
13723
  return { successful, failed };
13711
13724
  };
13712
13725
 
13726
+ // src/types/notification.ts
13727
+ var NotificationCategoryList = [
13728
+ "automation",
13729
+ "report",
13730
+ "team",
13731
+ "dataQuality",
13732
+ "discussion",
13733
+ "scraper"
13734
+ ];
13735
+ var NotificationDefaultChannels = {
13736
+ inApp: true,
13737
+ email: false,
13738
+ sms: false
13739
+ };
13740
+
13741
+ // src/utils/notification.ts
13742
+ function extractTemplates(source) {
13743
+ if (!source) return {};
13744
+ const templates = source.templates !== void 0 ? source.templates : source;
13745
+ if (templates && typeof templates === "object" && !Array.isArray(templates)) {
13746
+ return { ...templates };
13747
+ }
13748
+ return {};
13749
+ }
13750
+ function resolveNotificationPreferences(userPreferences, systemTemplates) {
13751
+ const prefs = userPreferences || {};
13752
+ const userCategories = prefs.categories || {};
13753
+ const userChannels = prefs.channels || {};
13754
+ const globalChannels = {
13755
+ inApp: userChannels.inApp !== void 0 ? userChannels.inApp : NotificationDefaultChannels.inApp,
13756
+ sms: userChannels.sms !== void 0 ? userChannels.sms : NotificationDefaultChannels.sms,
13757
+ email: userChannels.email !== void 0 ? userChannels.email : NotificationDefaultChannels.email
13758
+ };
13759
+ const convertTemplateToStringId = (template) => ({
13760
+ ...template,
13761
+ _id: template._id.toString()
13762
+ });
13763
+ const templatesByCategory = systemTemplates.reduce(
13764
+ (acc, template) => {
13765
+ const cat = template.category || "uncategorised";
13766
+ if (!acc[cat]) acc[cat] = [];
13767
+ acc[cat].push(convertTemplateToStringId(template));
13768
+ return acc;
13769
+ },
13770
+ {}
13771
+ );
13772
+ const categories = NotificationCategoryList.reduce(
13773
+ (acc, category) => {
13774
+ const userCategory = userCategories[category] || {};
13775
+ const userCategoryChannels = userCategory.channels || {};
13776
+ const userTemplates = extractTemplates(userCategory);
13777
+ const templateList = templatesByCategory[category] || [];
13778
+ acc[category] = {
13779
+ channels: {
13780
+ inApp: userCategoryChannels.inApp !== void 0 ? userCategoryChannels.inApp : NotificationDefaultChannels.inApp,
13781
+ sms: userCategoryChannels.sms !== void 0 ? userCategoryChannels.sms : NotificationDefaultChannels.sms,
13782
+ email: userCategoryChannels.email !== void 0 ? userCategoryChannels.email : NotificationDefaultChannels.email
13783
+ },
13784
+ templates: templateList.map((template) => ({
13785
+ _id: template._id,
13786
+ name: template.name,
13787
+ description: template.description,
13788
+ category: template.category,
13789
+ severity: template.severity,
13790
+ enabled: userTemplates[template._id] !== void 0 ? userTemplates[template._id] : template.enabledByDefault ?? true
13791
+ }))
13792
+ };
13793
+ return acc;
13794
+ },
13795
+ {}
13796
+ );
13797
+ return { channels: globalChannels, categories };
13798
+ }
13799
+
13713
13800
  // src/openai/index.ts
13714
13801
  var openai_exports = {};
13715
13802
  __export(openai_exports, {
@@ -15950,15 +16037,13 @@ async function handleError({ context, etnApi, automationRun, error, lambdaSource
15950
16037
  if (automationRun.category === "account" && accountId) {
15951
16038
  await etnApi.updateAccountStatusForAutomation(automation._id, accountId, { status: "error", error: error.message });
15952
16039
  }
15953
- if (automation.category === "account") {
15954
- await updateBatchJobStatus({
15955
- etnApi,
15956
- automationRun,
15957
- accountKey: accountId,
15958
- status: "failed",
15959
- errorMessage: error.message
15960
- });
15961
- }
16040
+ await updateBatchJobStatus({
16041
+ etnApi,
16042
+ automationRun,
16043
+ accountKey: accountId,
16044
+ status: "failed",
16045
+ errorMessage: error.message
16046
+ });
15962
16047
  }
15963
16048
  async function deleteMessage(queueUrl, receiptHandle, sqsClient) {
15964
16049
  if (!queueUrl || !receiptHandle) {
@@ -15981,21 +16066,6 @@ var scrapers_exports = {};
15981
16066
  // src/types/index.ts
15982
16067
  import { ObjectId } from "mongodb";
15983
16068
 
15984
- // src/types/notification.ts
15985
- var NotificationCategoryList = [
15986
- "automation",
15987
- "report",
15988
- "team",
15989
- "dataQuality",
15990
- "discussion",
15991
- "scraper"
15992
- ];
15993
- var NotificationDefaultChannels = {
15994
- inApp: true,
15995
- email: false,
15996
- sms: false
15997
- };
15998
-
15999
16069
  // src/types/notificationTemplate.ts
16000
16070
  var EventNamesByCategory = {
16001
16071
  automation: ["automationFailed", "automationCompleted", "automationOverdue", "automationExtractorOverdue"],
@@ -16016,8 +16086,8 @@ export {
16016
16086
  emailTemplate_default as emailTemplate,
16017
16087
  integrations_exports as integrations,
16018
16088
  logger_default as logger,
16089
+ loggerWithBetterStack,
16019
16090
  monitoring_exports as monitoring,
16020
- notification_exports as notification,
16021
16091
  notificationEmailTemplate_default as notificationEmailTemplate,
16022
16092
  notificationQueue_exports as notificationQueue,
16023
16093
  openai_exports as openai,