@etainabl/nodejs-sdk 1.3.184 → 1.3.186

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
@@ -1408,6 +1408,54 @@ interface Notification<ID = string, DateType = Date | string> {
1408
1408
  companyId?: ID;
1409
1409
  }
1410
1410
 
1411
+ declare const EventNamesByCategory: {
1412
+ readonly automation: readonly ["automationFailed", "automationCompleted", "automationOverdue", "automationExtractorOverdue"];
1413
+ readonly report: readonly ["reportSuccess", "reportFailed"];
1414
+ readonly team: readonly ["newUserSignIn"];
1415
+ readonly dataQuality: readonly ["invoiceOverdue", "contractOverdue", "contractDueSoon", "readingOverdue", "readingDueSoon"];
1416
+ readonly discussion: readonly ["newDiscussionReply", "userAssignedToDiscussion", "discussionMessageDue"];
1417
+ readonly scraper: readonly ["scraperLoginError", "scraperHasNotRun", "scraperRunCompleted"];
1418
+ };
1419
+ type NotificationEventName = (typeof EventNamesByCategory)[keyof typeof EventNamesByCategory][number] | 'alertTrigger';
1420
+ type NotificationTemplateSeverity = 'error' | 'warning' | 'info' | 'success';
1421
+ type NotificationTemplateDefaultChannel = 'off' | 'inApp' | 'email' | 'sms';
1422
+ type NotificationTemplateConfigType = 'text' | 'number' | 'password' | 'textarea' | 'radio' | 'select' | 'select2' | 'select-old' | 'select-multiple' | 'select-array' | 'select-array-list' | 'select-array-search' | 'multi-check-options' | 'tag-manager' | 'datePicker' | 'dateTimePicker' | 'dateRangePicker' | 'file' | 'slider';
1423
+ interface NotificationTemplateConfigOption {
1424
+ label: string;
1425
+ value: string;
1426
+ }
1427
+ interface NotificationTemplateConfig {
1428
+ type: NotificationTemplateConfigType;
1429
+ label: string;
1430
+ options?: NotificationTemplateConfigOption[];
1431
+ default?: string | null;
1432
+ required?: boolean;
1433
+ placeholder?: string;
1434
+ }
1435
+ interface NotificationTemplateRoute {
1436
+ name?: string;
1437
+ params?: Record<string, any>;
1438
+ }
1439
+ interface NotificationTemplate<ID = string, DateType = Date | string> {
1440
+ _id: ID;
1441
+ name: string;
1442
+ description?: string;
1443
+ triggerDescription?: string;
1444
+ category: NotificationCategory;
1445
+ eventName: NotificationEventName;
1446
+ severity: NotificationTemplateSeverity;
1447
+ isSystem?: boolean;
1448
+ default: NotificationTemplateDefaultChannel;
1449
+ messageTemplate?: string;
1450
+ routeTemplate?: NotificationTemplateRoute;
1451
+ icon?: string;
1452
+ config?: Map<string, NotificationTemplateConfig> | Record<string, NotificationTemplateConfig>;
1453
+ active: boolean;
1454
+ enabledByDefault?: boolean;
1455
+ createdAt?: DateType;
1456
+ updatedAt?: DateType;
1457
+ }
1458
+
1411
1459
  type NotificationContextMap = {
1412
1460
  reportSuccess: {
1413
1461
  report: {
@@ -1484,8 +1532,9 @@ type NotificationContextMap = {
1484
1532
  loginTime: string;
1485
1533
  };
1486
1534
  };
1487
- type NotificationEventType = keyof NotificationContextMap;
1488
- interface NotificationSQSMessage<E extends NotificationEventType = NotificationEventType> {
1535
+ type NotificationContext = NotificationContextMap[keyof NotificationContextMap];
1536
+ type NotificationContextEventName = keyof NotificationContextMap;
1537
+ interface NotificationSQSMessage<E extends NotificationContextEventName = NotificationContextEventName> {
1489
1538
  eventName: E;
1490
1539
  timestamp: string;
1491
1540
  companyId: string;
@@ -1494,7 +1543,7 @@ interface NotificationSQSMessage<E extends NotificationEventType = NotificationE
1494
1543
  notificationTemplateId?: string;
1495
1544
  context: NotificationContextMap[E];
1496
1545
  }
1497
- interface SendNotificationMessageInput<E extends NotificationEventType> {
1546
+ interface SendNotificationMessageInput {
1498
1547
  companyId: string;
1499
1548
  userSub: string;
1500
1549
  alertTriggerId?: string;
@@ -1502,61 +1551,6 @@ interface SendNotificationMessageInput<E extends NotificationEventType> {
1502
1551
  notificationTemplateId?: string;
1503
1552
  }
1504
1553
 
1505
- declare const NotificationTemplateCategories: readonly ["automation", "report", "team", "dataQuality", "discussion", "scraper"];
1506
- type NotificationTemplateCategory = (typeof NotificationTemplateCategories)[number];
1507
- declare const EventNamesByCategory: {
1508
- readonly automation: readonly ["automationFailed", "automationCompleted", "automationOverdue", "automationExtractorOverdue"];
1509
- readonly report: readonly ["reportSuccess", "reportFailed"];
1510
- readonly team: readonly ["newUserSignIn"];
1511
- readonly dataQuality: readonly ["invoiceOverdue", "contractOverdue", "contractDueSoon", "readingOverdue", "readingDueSoon"];
1512
- readonly discussion: readonly ["newDiscussionReply", "userAssignedToDiscussion", "discussionMessageDue"];
1513
- readonly scraper: readonly ["scraperLoginError", "scraperHasNotRun", "scraperRunCompleted"];
1514
- };
1515
- type AutomationEventName = (typeof EventNamesByCategory.automation)[number];
1516
- type ReportEventName = (typeof EventNamesByCategory.report)[number];
1517
- type TeamEventName = (typeof EventNamesByCategory.team)[number];
1518
- type DataQualityEventName = (typeof EventNamesByCategory.dataQuality)[number];
1519
- type DiscussionEventName = (typeof EventNamesByCategory.discussion)[number];
1520
- type ScraperEventName = (typeof EventNamesByCategory.scraper)[number];
1521
- type NotificationEventName = NotificationEventType;
1522
- type NotificationTemplateSeverity = 'error' | 'warning' | 'info' | 'success';
1523
- type NotificationTemplateDefaultChannel = 'off' | 'inApp' | 'email' | 'sms';
1524
- type NotificationTemplateConfigType = 'text' | 'number' | 'password' | 'textarea' | 'radio' | 'select' | 'select2' | 'select-old' | 'select-multiple' | 'select-array' | 'select-array-list' | 'select-array-search' | 'multi-check-options' | 'tag-manager' | 'datePicker' | 'dateTimePicker' | 'dateRangePicker' | 'file' | 'slider';
1525
- interface NotificationTemplateConfigOption {
1526
- label: string;
1527
- value: string;
1528
- }
1529
- interface NotificationTemplateConfig {
1530
- type: NotificationTemplateConfigType;
1531
- label: string;
1532
- options?: NotificationTemplateConfigOption[];
1533
- default?: string | null;
1534
- required?: boolean;
1535
- placeholder?: string;
1536
- }
1537
- interface NotificationTemplateRoute {
1538
- name?: string;
1539
- params?: Record<string, any>;
1540
- }
1541
- interface NotificationTemplate<ID = string, DateType = Date | string> {
1542
- _id: ID;
1543
- name: string;
1544
- description?: string;
1545
- triggerDescription?: string;
1546
- category: NotificationTemplateCategory;
1547
- eventName: NotificationEventName;
1548
- severity: NotificationTemplateSeverity;
1549
- isSystem?: boolean;
1550
- default: NotificationTemplateDefaultChannel;
1551
- messageTemplate?: string;
1552
- routeTemplate?: NotificationTemplateRoute;
1553
- icon?: string;
1554
- config?: Map<string, NotificationTemplateConfig> | Record<string, NotificationTemplateConfig>;
1555
- active: boolean;
1556
- createdAt?: DateType;
1557
- updatedAt?: DateType;
1558
- }
1559
-
1560
1554
  interface Log<IDType = ObjectId | string> {
1561
1555
  _id: IDType;
1562
1556
  message: string;
@@ -1739,14 +1733,13 @@ type NotificationChannels = {
1739
1733
  sms: boolean;
1740
1734
  };
1741
1735
  type NotificationTemplatesMap = Record<string, boolean>;
1742
- type NotificationCategoryKey = (typeof NotificationCategoryList)[number];
1743
1736
  type NotificationCategoryPreferences<IDType = ObjectId | string> = {
1744
1737
  channels: NotificationChannels;
1745
1738
  templates: NotificationTemplatesMap;
1746
1739
  };
1747
1740
  type NotificationPreferences<IDType = ObjectId | string> = {
1748
1741
  channels: NotificationChannels;
1749
- categories: Record<NotificationCategoryKey, NotificationCategoryPreferences<IDType>>;
1742
+ categories: Record<NotificationCategory, NotificationCategoryPreferences<IDType>>;
1750
1743
  };
1751
1744
  interface User<IDType = ObjectId | string> {
1752
1745
  _id: IDType;
@@ -2035,26 +2028,25 @@ interface SendNotificationMessageOptions {
2035
2028
  queueUrl?: string;
2036
2029
  sqsClient?: SQSClient;
2037
2030
  }
2038
- type NotificationType = keyof NotificationContextMap;
2039
- type SendNotificationParams<T extends NotificationType> = {
2031
+ type SendNotificationParams<T extends NotificationContextEventName> = {
2040
2032
  eventName: T;
2041
2033
  context: NotificationContextMap[T];
2042
- input: SendNotificationMessageInput<T>;
2034
+ input: SendNotificationMessageInput;
2043
2035
  options?: SendNotificationMessageOptions;
2044
2036
  };
2045
- type SendNotificationBatchParams<T extends NotificationType> = {
2037
+ type SendNotificationBatchParams<T extends NotificationContextEventName> = {
2046
2038
  messages: Array<{
2047
2039
  eventName: T;
2048
2040
  context: NotificationContextMap[T];
2049
- input: SendNotificationMessageInput<T>;
2041
+ input: SendNotificationMessageInput;
2050
2042
  }>;
2051
2043
  options?: SendNotificationMessageOptions;
2052
2044
  };
2053
- declare function createNotificationMessage<T extends NotificationType>(eventName: T, context: NotificationContextMap[T], input: SendNotificationMessageInput<T>): NotificationSQSMessage<T>;
2054
- declare function sendNotificationMessage<T extends NotificationType>({ eventName, context, input, options }: SendNotificationParams<T>): Promise<{
2045
+ declare function createNotificationMessage<T extends NotificationContextEventName>(eventName: T, context: NotificationContextMap[T], input: SendNotificationMessageInput): NotificationSQSMessage<T>;
2046
+ declare function sendNotificationMessage<T extends NotificationContextEventName>({ eventName, context, input, options }: SendNotificationParams<T>): Promise<{
2055
2047
  messageId: string;
2056
2048
  }>;
2057
- declare function sendNotificationMessageBatch<T extends NotificationType>({ messages, options }: SendNotificationBatchParams<T>): Promise<{
2049
+ declare function sendNotificationMessageBatch<T extends NotificationContextEventName>({ messages, options }: SendNotificationBatchParams<T>): Promise<{
2058
2050
  messageIds: string[];
2059
2051
  }>;
2060
2052
 
@@ -2187,11 +2179,25 @@ type SendToSqsBatchedResult = {
2187
2179
  };
2188
2180
  declare const sendToSqsBatched: <T>(messages: SqsBatchMessage<T>[], options: SendToSqsBatchedOptions) => Promise<SendToSqsBatchedResult>;
2189
2181
 
2182
+ interface ResolvedNotificationPreferences {
2183
+ channels: NotificationChannels;
2184
+ categories: Record<string, {
2185
+ channels: NotificationChannels;
2186
+ templates: Array<{
2187
+ _id: string;
2188
+ name: string;
2189
+ enabled: boolean;
2190
+ }>;
2191
+ }>;
2192
+ }
2193
+ declare function resolveNotificationPreferences(userPreferences: NotificationPreferences, systemTemplates: (NotificationTemplate<ObjectId, Date> | NotificationTemplate<string, string>)[]): ResolvedNotificationPreferences;
2194
+
2190
2195
  type index$1_FetchPage<T> = FetchPage<T>;
2191
2196
  type index$1_IngestHandler = IngestHandler;
2192
2197
  declare const index$1_IngestHandler: typeof IngestHandler;
2193
2198
  type index$1_PaginatedFetchOptions = PaginatedFetchOptions;
2194
2199
  type index$1_PaginatedResponse<T> = PaginatedResponse<T>;
2200
+ type index$1_ResolvedNotificationPreferences = ResolvedNotificationPreferences;
2195
2201
  type index$1_SendToSqsBatchedOptions = SendToSqsBatchedOptions;
2196
2202
  type index$1_SendToSqsBatchedResult = SendToSqsBatchedResult;
2197
2203
  type index$1_SqsBatchMessage<T> = SqsBatchMessage<T>;
@@ -2201,12 +2207,13 @@ declare const index$1_automationSources: typeof automationSources;
2201
2207
  declare const index$1_getMeterPointNumberBottomLine: typeof getMeterPointNumberBottomLine;
2202
2208
  declare const index$1_isTransientError: typeof isTransientError;
2203
2209
  declare const index$1_paginatedFetch: typeof paginatedFetch;
2210
+ declare const index$1_resolveNotificationPreferences: typeof resolveNotificationPreferences;
2204
2211
  declare const index$1_sendToSqsBatched: typeof sendToSqsBatched;
2205
2212
  declare const index$1_updateBatchJobStatus: typeof updateBatchJobStatus;
2206
2213
  declare const index$1_utilityTypes: typeof utilityTypes;
2207
2214
  declare const index$1_wasteCategories: typeof wasteCategories;
2208
2215
  declare namespace index$1 {
2209
- export { type index$1_FetchPage as FetchPage, index$1_IngestHandler as IngestHandler, type index$1_PaginatedFetchOptions as PaginatedFetchOptions, type index$1_PaginatedResponse as PaginatedResponse, type index$1_SendToSqsBatchedOptions as SendToSqsBatchedOptions, type index$1_SendToSqsBatchedResult as SendToSqsBatchedResult, type index$1_SqsBatchMessage as SqsBatchMessage, type index$1_SqsMessageAttribute as SqsMessageAttribute, index$1_automationServices as automationServices, index$1_automationSources as automationSources, index$1_getMeterPointNumberBottomLine as getMeterPointNumberBottomLine, index$1_isTransientError as isTransientError, index$1_paginatedFetch as paginatedFetch, index$1_sendToSqsBatched as sendToSqsBatched, units$1 as units, index$1_updateBatchJobStatus as updateBatchJobStatus, index$1_utilityTypes as utilityTypes, index$1_wasteCategories as wasteCategories };
2216
+ export { type index$1_FetchPage as FetchPage, index$1_IngestHandler as IngestHandler, type index$1_PaginatedFetchOptions as PaginatedFetchOptions, type index$1_PaginatedResponse as PaginatedResponse, type index$1_ResolvedNotificationPreferences as ResolvedNotificationPreferences, type index$1_SendToSqsBatchedOptions as SendToSqsBatchedOptions, type index$1_SendToSqsBatchedResult as SendToSqsBatchedResult, type index$1_SqsBatchMessage as SqsBatchMessage, type index$1_SqsMessageAttribute as SqsMessageAttribute, index$1_automationServices as automationServices, index$1_automationSources as automationSources, index$1_getMeterPointNumberBottomLine as getMeterPointNumberBottomLine, index$1_isTransientError as isTransientError, index$1_paginatedFetch as paginatedFetch, index$1_resolveNotificationPreferences as resolveNotificationPreferences, index$1_sendToSqsBatched as sendToSqsBatched, units$1 as units, index$1_updateBatchJobStatus as updateBatchJobStatus, index$1_utilityTypes as utilityTypes, index$1_wasteCategories as wasteCategories };
2210
2217
  }
2211
2218
 
2212
2219
  interface ETNModel {
@@ -2333,4 +2340,4 @@ declare namespace scrapers {
2333
2340
  export type { scrapers_ETNAccount as ETNAccount };
2334
2341
  }
2335
2342
 
2336
- export { type AccessLevel, type Account, type AccountResult, type Action, type ActionType, type Asset, type Automation, type AutomationEventName, type AutomationRun, type AutomationRunLog, type AutomationRunSummary, type AutomationService, type AutomationServiceCategory, type AutomationSource, type Company, type CompanyInvoiceValidationRule, type CompanyInvoiceValidationSettings, type Consumption, type CreateScraperRunParams, type CustomAlertTrigger, type CustomAlertTriggerQueueMessage, type DataIngest, type DataQualityEventName, type DefaultField, type DeliveryStatus, type DiscussionEventName, type ETNEvent, type ETNPagedResponse$1 as ETNPagedResponse, type Email, type Entity, EventNamesByCategory, type FileFormat, type ImportTemplate, type Invoice, type InvoiceCapture, type InvoiceCaptureMetadata, type InvoiceCaptureMetadataResult, type InvoiceRate, type InvoiceRateType, type InvoiceValidation, type InvoiceValidationInvoice, type InvoiceValidationResults, type InvoiceValidationRule, type InvoiceValues, type Job, type JobStatus, type Log, type Notification, type NotificationAction, type NotificationCategory, type NotificationCategoryKey, NotificationCategoryList, type NotificationCategoryPreferences, type NotificationChannels, type NotificationContextMap, NotificationDefaultChannels, type NotificationEventName, type NotificationEventType, type NotificationPreferences, type NotificationSQSMessage, type NotificationTemplate, type NotificationTemplateCategory, type NotificationTemplateConfig, type NotificationTemplateConfigOption, type NotificationTemplateConfigType, type NotificationTemplateDefaultChannel, type NotificationTemplateRoute, type NotificationTemplateSeverity, type NotificationTemplatesMap, type Portal, type PortalSupplierSchema, type Problem, type ProblemCodes, type ProblemDetails, type Reading, type Report, type ReportEventName, type ReportMetadata, type ReportSource, type ReportSourceIdItem, type ReportTemplate, type ReportType, type ScraperEventName, type ScraperRun, type SendNotificationMessageInput, type Setting, type SourceType, type Supplier, type TeamEventName, type User, type UtilityType, type WasteCategories, type WasteTypes, _default$5 as api, consumption, _default$1 as db, _default$4 as emailTemplate, integrations, _default$2 as logger, monitoring, notification, _default$3 as notificationEmailTemplate, notificationQueue, index as openai, reporting, scrapers, _default as slack, units, index$1 as utils };
2343
+ export { type AccessLevel, type Account, type AccountResult, type Action, type ActionType, type Asset, type Automation, type AutomationRun, type AutomationRunLog, type AutomationRunSummary, type AutomationService, type AutomationServiceCategory, type AutomationSource, type Company, type CompanyInvoiceValidationRule, type CompanyInvoiceValidationSettings, type Consumption, type CreateScraperRunParams, type CustomAlertTrigger, type CustomAlertTriggerQueueMessage, type DataIngest, type DefaultField, type DeliveryStatus, type ETNEvent, type ETNPagedResponse$1 as ETNPagedResponse, type Email, type Entity, EventNamesByCategory, type FileFormat, type ImportTemplate, type Invoice, type InvoiceCapture, type InvoiceCaptureMetadata, type InvoiceCaptureMetadataResult, type InvoiceRate, type InvoiceRateType, type InvoiceValidation, type InvoiceValidationInvoice, type InvoiceValidationResults, type InvoiceValidationRule, type InvoiceValues, type Job, type JobStatus, type Log, type Notification, type NotificationAction, type NotificationCategory, NotificationCategoryList, type NotificationCategoryPreferences, type NotificationChannels, type NotificationContext, type NotificationContextEventName, type NotificationContextMap, NotificationDefaultChannels, type NotificationEventName, type NotificationPreferences, type NotificationSQSMessage, type NotificationTemplate, type NotificationTemplateConfig, type NotificationTemplateConfigOption, type NotificationTemplateConfigType, type NotificationTemplateDefaultChannel, type NotificationTemplateRoute, type NotificationTemplateSeverity, type NotificationTemplatesMap, type Portal, type PortalSupplierSchema, type Problem, type ProblemCodes, type ProblemDetails, type Reading, type Report, type ReportMetadata, type ReportSource, type ReportSourceIdItem, type ReportTemplate, type ReportType, type ScraperRun, type SendNotificationMessageInput, type Setting, type SourceType, type Supplier, type User, type UtilityType, type WasteCategories, type WasteTypes, _default$5 as api, consumption, _default$1 as db, _default$4 as emailTemplate, integrations, _default$2 as logger, monitoring, notification, _default$3 as notificationEmailTemplate, notificationQueue, index as openai, reporting, scrapers, _default as slack, units, index$1 as utils };
package/dist/index.d.ts CHANGED
@@ -1408,6 +1408,54 @@ interface Notification<ID = string, DateType = Date | string> {
1408
1408
  companyId?: ID;
1409
1409
  }
1410
1410
 
1411
+ declare const EventNamesByCategory: {
1412
+ readonly automation: readonly ["automationFailed", "automationCompleted", "automationOverdue", "automationExtractorOverdue"];
1413
+ readonly report: readonly ["reportSuccess", "reportFailed"];
1414
+ readonly team: readonly ["newUserSignIn"];
1415
+ readonly dataQuality: readonly ["invoiceOverdue", "contractOverdue", "contractDueSoon", "readingOverdue", "readingDueSoon"];
1416
+ readonly discussion: readonly ["newDiscussionReply", "userAssignedToDiscussion", "discussionMessageDue"];
1417
+ readonly scraper: readonly ["scraperLoginError", "scraperHasNotRun", "scraperRunCompleted"];
1418
+ };
1419
+ type NotificationEventName = (typeof EventNamesByCategory)[keyof typeof EventNamesByCategory][number] | 'alertTrigger';
1420
+ type NotificationTemplateSeverity = 'error' | 'warning' | 'info' | 'success';
1421
+ type NotificationTemplateDefaultChannel = 'off' | 'inApp' | 'email' | 'sms';
1422
+ type NotificationTemplateConfigType = 'text' | 'number' | 'password' | 'textarea' | 'radio' | 'select' | 'select2' | 'select-old' | 'select-multiple' | 'select-array' | 'select-array-list' | 'select-array-search' | 'multi-check-options' | 'tag-manager' | 'datePicker' | 'dateTimePicker' | 'dateRangePicker' | 'file' | 'slider';
1423
+ interface NotificationTemplateConfigOption {
1424
+ label: string;
1425
+ value: string;
1426
+ }
1427
+ interface NotificationTemplateConfig {
1428
+ type: NotificationTemplateConfigType;
1429
+ label: string;
1430
+ options?: NotificationTemplateConfigOption[];
1431
+ default?: string | null;
1432
+ required?: boolean;
1433
+ placeholder?: string;
1434
+ }
1435
+ interface NotificationTemplateRoute {
1436
+ name?: string;
1437
+ params?: Record<string, any>;
1438
+ }
1439
+ interface NotificationTemplate<ID = string, DateType = Date | string> {
1440
+ _id: ID;
1441
+ name: string;
1442
+ description?: string;
1443
+ triggerDescription?: string;
1444
+ category: NotificationCategory;
1445
+ eventName: NotificationEventName;
1446
+ severity: NotificationTemplateSeverity;
1447
+ isSystem?: boolean;
1448
+ default: NotificationTemplateDefaultChannel;
1449
+ messageTemplate?: string;
1450
+ routeTemplate?: NotificationTemplateRoute;
1451
+ icon?: string;
1452
+ config?: Map<string, NotificationTemplateConfig> | Record<string, NotificationTemplateConfig>;
1453
+ active: boolean;
1454
+ enabledByDefault?: boolean;
1455
+ createdAt?: DateType;
1456
+ updatedAt?: DateType;
1457
+ }
1458
+
1411
1459
  type NotificationContextMap = {
1412
1460
  reportSuccess: {
1413
1461
  report: {
@@ -1484,8 +1532,9 @@ type NotificationContextMap = {
1484
1532
  loginTime: string;
1485
1533
  };
1486
1534
  };
1487
- type NotificationEventType = keyof NotificationContextMap;
1488
- interface NotificationSQSMessage<E extends NotificationEventType = NotificationEventType> {
1535
+ type NotificationContext = NotificationContextMap[keyof NotificationContextMap];
1536
+ type NotificationContextEventName = keyof NotificationContextMap;
1537
+ interface NotificationSQSMessage<E extends NotificationContextEventName = NotificationContextEventName> {
1489
1538
  eventName: E;
1490
1539
  timestamp: string;
1491
1540
  companyId: string;
@@ -1494,7 +1543,7 @@ interface NotificationSQSMessage<E extends NotificationEventType = NotificationE
1494
1543
  notificationTemplateId?: string;
1495
1544
  context: NotificationContextMap[E];
1496
1545
  }
1497
- interface SendNotificationMessageInput<E extends NotificationEventType> {
1546
+ interface SendNotificationMessageInput {
1498
1547
  companyId: string;
1499
1548
  userSub: string;
1500
1549
  alertTriggerId?: string;
@@ -1502,61 +1551,6 @@ interface SendNotificationMessageInput<E extends NotificationEventType> {
1502
1551
  notificationTemplateId?: string;
1503
1552
  }
1504
1553
 
1505
- declare const NotificationTemplateCategories: readonly ["automation", "report", "team", "dataQuality", "discussion", "scraper"];
1506
- type NotificationTemplateCategory = (typeof NotificationTemplateCategories)[number];
1507
- declare const EventNamesByCategory: {
1508
- readonly automation: readonly ["automationFailed", "automationCompleted", "automationOverdue", "automationExtractorOverdue"];
1509
- readonly report: readonly ["reportSuccess", "reportFailed"];
1510
- readonly team: readonly ["newUserSignIn"];
1511
- readonly dataQuality: readonly ["invoiceOverdue", "contractOverdue", "contractDueSoon", "readingOverdue", "readingDueSoon"];
1512
- readonly discussion: readonly ["newDiscussionReply", "userAssignedToDiscussion", "discussionMessageDue"];
1513
- readonly scraper: readonly ["scraperLoginError", "scraperHasNotRun", "scraperRunCompleted"];
1514
- };
1515
- type AutomationEventName = (typeof EventNamesByCategory.automation)[number];
1516
- type ReportEventName = (typeof EventNamesByCategory.report)[number];
1517
- type TeamEventName = (typeof EventNamesByCategory.team)[number];
1518
- type DataQualityEventName = (typeof EventNamesByCategory.dataQuality)[number];
1519
- type DiscussionEventName = (typeof EventNamesByCategory.discussion)[number];
1520
- type ScraperEventName = (typeof EventNamesByCategory.scraper)[number];
1521
- type NotificationEventName = NotificationEventType;
1522
- type NotificationTemplateSeverity = 'error' | 'warning' | 'info' | 'success';
1523
- type NotificationTemplateDefaultChannel = 'off' | 'inApp' | 'email' | 'sms';
1524
- type NotificationTemplateConfigType = 'text' | 'number' | 'password' | 'textarea' | 'radio' | 'select' | 'select2' | 'select-old' | 'select-multiple' | 'select-array' | 'select-array-list' | 'select-array-search' | 'multi-check-options' | 'tag-manager' | 'datePicker' | 'dateTimePicker' | 'dateRangePicker' | 'file' | 'slider';
1525
- interface NotificationTemplateConfigOption {
1526
- label: string;
1527
- value: string;
1528
- }
1529
- interface NotificationTemplateConfig {
1530
- type: NotificationTemplateConfigType;
1531
- label: string;
1532
- options?: NotificationTemplateConfigOption[];
1533
- default?: string | null;
1534
- required?: boolean;
1535
- placeholder?: string;
1536
- }
1537
- interface NotificationTemplateRoute {
1538
- name?: string;
1539
- params?: Record<string, any>;
1540
- }
1541
- interface NotificationTemplate<ID = string, DateType = Date | string> {
1542
- _id: ID;
1543
- name: string;
1544
- description?: string;
1545
- triggerDescription?: string;
1546
- category: NotificationTemplateCategory;
1547
- eventName: NotificationEventName;
1548
- severity: NotificationTemplateSeverity;
1549
- isSystem?: boolean;
1550
- default: NotificationTemplateDefaultChannel;
1551
- messageTemplate?: string;
1552
- routeTemplate?: NotificationTemplateRoute;
1553
- icon?: string;
1554
- config?: Map<string, NotificationTemplateConfig> | Record<string, NotificationTemplateConfig>;
1555
- active: boolean;
1556
- createdAt?: DateType;
1557
- updatedAt?: DateType;
1558
- }
1559
-
1560
1554
  interface Log<IDType = ObjectId | string> {
1561
1555
  _id: IDType;
1562
1556
  message: string;
@@ -1739,14 +1733,13 @@ type NotificationChannels = {
1739
1733
  sms: boolean;
1740
1734
  };
1741
1735
  type NotificationTemplatesMap = Record<string, boolean>;
1742
- type NotificationCategoryKey = (typeof NotificationCategoryList)[number];
1743
1736
  type NotificationCategoryPreferences<IDType = ObjectId | string> = {
1744
1737
  channels: NotificationChannels;
1745
1738
  templates: NotificationTemplatesMap;
1746
1739
  };
1747
1740
  type NotificationPreferences<IDType = ObjectId | string> = {
1748
1741
  channels: NotificationChannels;
1749
- categories: Record<NotificationCategoryKey, NotificationCategoryPreferences<IDType>>;
1742
+ categories: Record<NotificationCategory, NotificationCategoryPreferences<IDType>>;
1750
1743
  };
1751
1744
  interface User<IDType = ObjectId | string> {
1752
1745
  _id: IDType;
@@ -2035,26 +2028,25 @@ interface SendNotificationMessageOptions {
2035
2028
  queueUrl?: string;
2036
2029
  sqsClient?: SQSClient;
2037
2030
  }
2038
- type NotificationType = keyof NotificationContextMap;
2039
- type SendNotificationParams<T extends NotificationType> = {
2031
+ type SendNotificationParams<T extends NotificationContextEventName> = {
2040
2032
  eventName: T;
2041
2033
  context: NotificationContextMap[T];
2042
- input: SendNotificationMessageInput<T>;
2034
+ input: SendNotificationMessageInput;
2043
2035
  options?: SendNotificationMessageOptions;
2044
2036
  };
2045
- type SendNotificationBatchParams<T extends NotificationType> = {
2037
+ type SendNotificationBatchParams<T extends NotificationContextEventName> = {
2046
2038
  messages: Array<{
2047
2039
  eventName: T;
2048
2040
  context: NotificationContextMap[T];
2049
- input: SendNotificationMessageInput<T>;
2041
+ input: SendNotificationMessageInput;
2050
2042
  }>;
2051
2043
  options?: SendNotificationMessageOptions;
2052
2044
  };
2053
- declare function createNotificationMessage<T extends NotificationType>(eventName: T, context: NotificationContextMap[T], input: SendNotificationMessageInput<T>): NotificationSQSMessage<T>;
2054
- declare function sendNotificationMessage<T extends NotificationType>({ eventName, context, input, options }: SendNotificationParams<T>): Promise<{
2045
+ declare function createNotificationMessage<T extends NotificationContextEventName>(eventName: T, context: NotificationContextMap[T], input: SendNotificationMessageInput): NotificationSQSMessage<T>;
2046
+ declare function sendNotificationMessage<T extends NotificationContextEventName>({ eventName, context, input, options }: SendNotificationParams<T>): Promise<{
2055
2047
  messageId: string;
2056
2048
  }>;
2057
- declare function sendNotificationMessageBatch<T extends NotificationType>({ messages, options }: SendNotificationBatchParams<T>): Promise<{
2049
+ declare function sendNotificationMessageBatch<T extends NotificationContextEventName>({ messages, options }: SendNotificationBatchParams<T>): Promise<{
2058
2050
  messageIds: string[];
2059
2051
  }>;
2060
2052
 
@@ -2187,11 +2179,25 @@ type SendToSqsBatchedResult = {
2187
2179
  };
2188
2180
  declare const sendToSqsBatched: <T>(messages: SqsBatchMessage<T>[], options: SendToSqsBatchedOptions) => Promise<SendToSqsBatchedResult>;
2189
2181
 
2182
+ interface ResolvedNotificationPreferences {
2183
+ channels: NotificationChannels;
2184
+ categories: Record<string, {
2185
+ channels: NotificationChannels;
2186
+ templates: Array<{
2187
+ _id: string;
2188
+ name: string;
2189
+ enabled: boolean;
2190
+ }>;
2191
+ }>;
2192
+ }
2193
+ declare function resolveNotificationPreferences(userPreferences: NotificationPreferences, systemTemplates: (NotificationTemplate<ObjectId, Date> | NotificationTemplate<string, string>)[]): ResolvedNotificationPreferences;
2194
+
2190
2195
  type index$1_FetchPage<T> = FetchPage<T>;
2191
2196
  type index$1_IngestHandler = IngestHandler;
2192
2197
  declare const index$1_IngestHandler: typeof IngestHandler;
2193
2198
  type index$1_PaginatedFetchOptions = PaginatedFetchOptions;
2194
2199
  type index$1_PaginatedResponse<T> = PaginatedResponse<T>;
2200
+ type index$1_ResolvedNotificationPreferences = ResolvedNotificationPreferences;
2195
2201
  type index$1_SendToSqsBatchedOptions = SendToSqsBatchedOptions;
2196
2202
  type index$1_SendToSqsBatchedResult = SendToSqsBatchedResult;
2197
2203
  type index$1_SqsBatchMessage<T> = SqsBatchMessage<T>;
@@ -2201,12 +2207,13 @@ declare const index$1_automationSources: typeof automationSources;
2201
2207
  declare const index$1_getMeterPointNumberBottomLine: typeof getMeterPointNumberBottomLine;
2202
2208
  declare const index$1_isTransientError: typeof isTransientError;
2203
2209
  declare const index$1_paginatedFetch: typeof paginatedFetch;
2210
+ declare const index$1_resolveNotificationPreferences: typeof resolveNotificationPreferences;
2204
2211
  declare const index$1_sendToSqsBatched: typeof sendToSqsBatched;
2205
2212
  declare const index$1_updateBatchJobStatus: typeof updateBatchJobStatus;
2206
2213
  declare const index$1_utilityTypes: typeof utilityTypes;
2207
2214
  declare const index$1_wasteCategories: typeof wasteCategories;
2208
2215
  declare namespace index$1 {
2209
- export { type index$1_FetchPage as FetchPage, index$1_IngestHandler as IngestHandler, type index$1_PaginatedFetchOptions as PaginatedFetchOptions, type index$1_PaginatedResponse as PaginatedResponse, type index$1_SendToSqsBatchedOptions as SendToSqsBatchedOptions, type index$1_SendToSqsBatchedResult as SendToSqsBatchedResult, type index$1_SqsBatchMessage as SqsBatchMessage, type index$1_SqsMessageAttribute as SqsMessageAttribute, index$1_automationServices as automationServices, index$1_automationSources as automationSources, index$1_getMeterPointNumberBottomLine as getMeterPointNumberBottomLine, index$1_isTransientError as isTransientError, index$1_paginatedFetch as paginatedFetch, index$1_sendToSqsBatched as sendToSqsBatched, units$1 as units, index$1_updateBatchJobStatus as updateBatchJobStatus, index$1_utilityTypes as utilityTypes, index$1_wasteCategories as wasteCategories };
2216
+ export { type index$1_FetchPage as FetchPage, index$1_IngestHandler as IngestHandler, type index$1_PaginatedFetchOptions as PaginatedFetchOptions, type index$1_PaginatedResponse as PaginatedResponse, type index$1_ResolvedNotificationPreferences as ResolvedNotificationPreferences, type index$1_SendToSqsBatchedOptions as SendToSqsBatchedOptions, type index$1_SendToSqsBatchedResult as SendToSqsBatchedResult, type index$1_SqsBatchMessage as SqsBatchMessage, type index$1_SqsMessageAttribute as SqsMessageAttribute, index$1_automationServices as automationServices, index$1_automationSources as automationSources, index$1_getMeterPointNumberBottomLine as getMeterPointNumberBottomLine, index$1_isTransientError as isTransientError, index$1_paginatedFetch as paginatedFetch, index$1_resolveNotificationPreferences as resolveNotificationPreferences, index$1_sendToSqsBatched as sendToSqsBatched, units$1 as units, index$1_updateBatchJobStatus as updateBatchJobStatus, index$1_utilityTypes as utilityTypes, index$1_wasteCategories as wasteCategories };
2210
2217
  }
2211
2218
 
2212
2219
  interface ETNModel {
@@ -2333,4 +2340,4 @@ declare namespace scrapers {
2333
2340
  export type { scrapers_ETNAccount as ETNAccount };
2334
2341
  }
2335
2342
 
2336
- export { type AccessLevel, type Account, type AccountResult, type Action, type ActionType, type Asset, type Automation, type AutomationEventName, type AutomationRun, type AutomationRunLog, type AutomationRunSummary, type AutomationService, type AutomationServiceCategory, type AutomationSource, type Company, type CompanyInvoiceValidationRule, type CompanyInvoiceValidationSettings, type Consumption, type CreateScraperRunParams, type CustomAlertTrigger, type CustomAlertTriggerQueueMessage, type DataIngest, type DataQualityEventName, type DefaultField, type DeliveryStatus, type DiscussionEventName, type ETNEvent, type ETNPagedResponse$1 as ETNPagedResponse, type Email, type Entity, EventNamesByCategory, type FileFormat, type ImportTemplate, type Invoice, type InvoiceCapture, type InvoiceCaptureMetadata, type InvoiceCaptureMetadataResult, type InvoiceRate, type InvoiceRateType, type InvoiceValidation, type InvoiceValidationInvoice, type InvoiceValidationResults, type InvoiceValidationRule, type InvoiceValues, type Job, type JobStatus, type Log, type Notification, type NotificationAction, type NotificationCategory, type NotificationCategoryKey, NotificationCategoryList, type NotificationCategoryPreferences, type NotificationChannels, type NotificationContextMap, NotificationDefaultChannels, type NotificationEventName, type NotificationEventType, type NotificationPreferences, type NotificationSQSMessage, type NotificationTemplate, type NotificationTemplateCategory, type NotificationTemplateConfig, type NotificationTemplateConfigOption, type NotificationTemplateConfigType, type NotificationTemplateDefaultChannel, type NotificationTemplateRoute, type NotificationTemplateSeverity, type NotificationTemplatesMap, type Portal, type PortalSupplierSchema, type Problem, type ProblemCodes, type ProblemDetails, type Reading, type Report, type ReportEventName, type ReportMetadata, type ReportSource, type ReportSourceIdItem, type ReportTemplate, type ReportType, type ScraperEventName, type ScraperRun, type SendNotificationMessageInput, type Setting, type SourceType, type Supplier, type TeamEventName, type User, type UtilityType, type WasteCategories, type WasteTypes, _default$5 as api, consumption, _default$1 as db, _default$4 as emailTemplate, integrations, _default$2 as logger, monitoring, notification, _default$3 as notificationEmailTemplate, notificationQueue, index as openai, reporting, scrapers, _default as slack, units, index$1 as utils };
2343
+ export { type AccessLevel, type Account, type AccountResult, type Action, type ActionType, type Asset, type Automation, type AutomationRun, type AutomationRunLog, type AutomationRunSummary, type AutomationService, type AutomationServiceCategory, type AutomationSource, type Company, type CompanyInvoiceValidationRule, type CompanyInvoiceValidationSettings, type Consumption, type CreateScraperRunParams, type CustomAlertTrigger, type CustomAlertTriggerQueueMessage, type DataIngest, type DefaultField, type DeliveryStatus, type ETNEvent, type ETNPagedResponse$1 as ETNPagedResponse, type Email, type Entity, EventNamesByCategory, type FileFormat, type ImportTemplate, type Invoice, type InvoiceCapture, type InvoiceCaptureMetadata, type InvoiceCaptureMetadataResult, type InvoiceRate, type InvoiceRateType, type InvoiceValidation, type InvoiceValidationInvoice, type InvoiceValidationResults, type InvoiceValidationRule, type InvoiceValues, type Job, type JobStatus, type Log, type Notification, type NotificationAction, type NotificationCategory, NotificationCategoryList, type NotificationCategoryPreferences, type NotificationChannels, type NotificationContext, type NotificationContextEventName, type NotificationContextMap, NotificationDefaultChannels, type NotificationEventName, type NotificationPreferences, type NotificationSQSMessage, type NotificationTemplate, type NotificationTemplateConfig, type NotificationTemplateConfigOption, type NotificationTemplateConfigType, type NotificationTemplateDefaultChannel, type NotificationTemplateRoute, type NotificationTemplateSeverity, type NotificationTemplatesMap, type Portal, type PortalSupplierSchema, type Problem, type ProblemCodes, type ProblemDetails, type Reading, type Report, type ReportMetadata, type ReportSource, type ReportSourceIdItem, type ReportTemplate, type ReportType, type ScraperRun, type SendNotificationMessageInput, type Setting, type SourceType, type Supplier, type User, type UtilityType, type WasteCategories, type WasteTypes, _default$5 as api, consumption, _default$1 as db, _default$4 as emailTemplate, integrations, _default$2 as logger, monitoring, notification, _default$3 as notificationEmailTemplate, notificationQueue, index as openai, reporting, scrapers, _default as slack, units, index$1 as utils };
package/dist/index.js CHANGED
@@ -25103,6 +25103,7 @@ __export(utils_exports, {
25103
25103
  getMeterPointNumberBottomLine: () => getMeterPointNumberBottomLine,
25104
25104
  isTransientError: () => isTransientError2,
25105
25105
  paginatedFetch: () => paginatedFetch,
25106
+ resolveNotificationPreferences: () => resolveNotificationPreferences,
25106
25107
  sendToSqsBatched: () => sendToSqsBatched,
25107
25108
  units: () => units,
25108
25109
  updateBatchJobStatus: () => updateBatchJobStatus,
@@ -25421,6 +25422,7 @@ async function updateBatchJobStatus({
25421
25422
  errorMessage
25422
25423
  }) {
25423
25424
  if (!automationRun) return;
25425
+ if (automationRun.category !== "account") return;
25424
25426
  const jobKey = automationRun.jobId;
25425
25427
  const resolvedAccountKey = accountKey ?? automationRun.accountResults?.[0]?.id?.toString();
25426
25428
  if (!jobKey || !resolvedAccountKey) return;
@@ -30034,6 +30036,80 @@ var sendToSqsBatched = async (messages, options) => {
30034
30036
  return { successful, failed };
30035
30037
  };
30036
30038
 
30039
+ // src/types/notification.ts
30040
+ var NotificationCategoryList = [
30041
+ "automation",
30042
+ "report",
30043
+ "team",
30044
+ "dataQuality",
30045
+ "discussion",
30046
+ "scraper"
30047
+ ];
30048
+ var NotificationDefaultChannels = {
30049
+ inApp: true,
30050
+ email: false,
30051
+ sms: false
30052
+ };
30053
+
30054
+ // src/utils/notification.ts
30055
+ function extractTemplates(source) {
30056
+ if (!source) return {};
30057
+ const templates = source.templates !== void 0 ? source.templates : source;
30058
+ if (templates && typeof templates === "object" && !Array.isArray(templates)) {
30059
+ return { ...templates };
30060
+ }
30061
+ return {};
30062
+ }
30063
+ function resolveNotificationPreferences(userPreferences, systemTemplates) {
30064
+ const prefs = userPreferences || {};
30065
+ const userCategories = prefs.categories || {};
30066
+ const userChannels = prefs.channels || {};
30067
+ const globalChannels = {
30068
+ inApp: userChannels.inApp !== void 0 ? userChannels.inApp : NotificationDefaultChannels.inApp,
30069
+ sms: userChannels.sms !== void 0 ? userChannels.sms : NotificationDefaultChannels.sms,
30070
+ email: userChannels.email !== void 0 ? userChannels.email : NotificationDefaultChannels.email
30071
+ };
30072
+ const convertTemplateToStringId = (template) => ({
30073
+ ...template,
30074
+ _id: template._id.toString()
30075
+ });
30076
+ const templatesByCategory = systemTemplates.reduce(
30077
+ (acc, template) => {
30078
+ const cat = template.category || "uncategorised";
30079
+ if (!acc[cat]) acc[cat] = [];
30080
+ acc[cat].push(convertTemplateToStringId(template));
30081
+ return acc;
30082
+ },
30083
+ {}
30084
+ );
30085
+ const categories = NotificationCategoryList.reduce(
30086
+ (acc, category) => {
30087
+ const userCategory = userCategories[category] || {};
30088
+ const userCategoryChannels = userCategory.channels || {};
30089
+ const userTemplates = extractTemplates(userCategory);
30090
+ const templateList = templatesByCategory[category] || [];
30091
+ acc[category] = {
30092
+ channels: {
30093
+ inApp: userCategoryChannels.inApp !== void 0 ? userCategoryChannels.inApp : NotificationDefaultChannels.inApp,
30094
+ sms: userCategoryChannels.sms !== void 0 ? userCategoryChannels.sms : NotificationDefaultChannels.sms,
30095
+ email: userCategoryChannels.email !== void 0 ? userCategoryChannels.email : NotificationDefaultChannels.email
30096
+ },
30097
+ templates: templateList.map((template) => ({
30098
+ _id: template._id,
30099
+ name: template.name,
30100
+ description: template.description,
30101
+ category: template.category,
30102
+ severity: template.severity,
30103
+ enabled: userTemplates[template._id] !== void 0 ? userTemplates[template._id] : template.enabledByDefault ?? true
30104
+ }))
30105
+ };
30106
+ return acc;
30107
+ },
30108
+ {}
30109
+ );
30110
+ return { channels: globalChannels, categories };
30111
+ }
30112
+
30037
30113
  // src/openai/index.ts
30038
30114
  var openai_exports = {};
30039
30115
  __export(openai_exports, {
@@ -32327,15 +32403,13 @@ async function handleError({ context, etnApi, automationRun, error, lambdaSource
32327
32403
  if (automationRun.category === "account" && accountId) {
32328
32404
  await etnApi.updateAccountStatusForAutomation(automation._id, accountId, { status: "error", error: error.message });
32329
32405
  }
32330
- if (automation.category === "account") {
32331
- await updateBatchJobStatus({
32332
- etnApi,
32333
- automationRun,
32334
- accountKey: accountId,
32335
- status: "failed",
32336
- errorMessage: error.message
32337
- });
32338
- }
32406
+ await updateBatchJobStatus({
32407
+ etnApi,
32408
+ automationRun,
32409
+ accountKey: accountId,
32410
+ status: "failed",
32411
+ errorMessage: error.message
32412
+ });
32339
32413
  }
32340
32414
  async function deleteMessage(queueUrl, receiptHandle, sqsClient) {
32341
32415
  if (!queueUrl || !receiptHandle) {
@@ -32358,21 +32432,6 @@ var scrapers_exports = {};
32358
32432
  // src/types/index.ts
32359
32433
  var import_mongodb2 = require("mongodb");
32360
32434
 
32361
- // src/types/notification.ts
32362
- var NotificationCategoryList = [
32363
- "automation",
32364
- "report",
32365
- "team",
32366
- "dataQuality",
32367
- "discussion",
32368
- "scraper"
32369
- ];
32370
- var NotificationDefaultChannels = {
32371
- inApp: true,
32372
- email: false,
32373
- sms: false
32374
- };
32375
-
32376
32435
  // src/types/notificationTemplate.ts
32377
32436
  var EventNamesByCategory = {
32378
32437
  automation: ["automationFailed", "automationCompleted", "automationOverdue", "automationExtractorOverdue"],