av6-core 1.0.7 → 1.0.8

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.mts CHANGED
@@ -357,14 +357,12 @@ type EmitPayload = {
357
357
  recipient: Recipient;
358
358
  data: Record<string, any>;
359
359
  };
360
- interface ILogger {
361
- info: (...args: any[]) => void;
362
- error: (...args: any[]) => void;
363
- }
360
+ type ILogger = winston.Logger | Console;
364
361
  type NotificationEmitterDeps = {
365
362
  prisma: PrismaClient;
366
363
  logger?: ILogger;
367
364
  envMode?: "Production" | "Development";
365
+ helpers: Helpers;
368
366
  };
369
367
 
370
368
  /**
package/dist/index.d.ts CHANGED
@@ -357,14 +357,12 @@ type EmitPayload = {
357
357
  recipient: Recipient;
358
358
  data: Record<string, any>;
359
359
  };
360
- interface ILogger {
361
- info: (...args: any[]) => void;
362
- error: (...args: any[]) => void;
363
- }
360
+ type ILogger = winston.Logger | Console;
364
361
  type NotificationEmitterDeps = {
365
362
  prisma: PrismaClient;
366
363
  logger?: ILogger;
367
364
  envMode?: "Production" | "Development";
365
+ helpers: Helpers;
368
366
  };
369
367
 
370
368
  /**
package/dist/index.js CHANGED
@@ -1661,6 +1661,13 @@ var EmailProvider = class {
1661
1661
  const emailConfig = await this.prisma.emailConfig.findFirst({
1662
1662
  where: { isActive: "yes" }
1663
1663
  });
1664
+ if (!emailConfig || !emailConfig.smtpServer || !emailConfig.smtpUsername || !emailConfig.smtpPassword || !emailConfig.smtpPort) {
1665
+ return {
1666
+ ok: false,
1667
+ provider: "EMAIL" /* EMAIL */,
1668
+ error: "Missing or incomplete email configuration"
1669
+ };
1670
+ }
1664
1671
  const transporter = import_nodemailer.default.createTransport({
1665
1672
  pool: true,
1666
1673
  // Reuse the connection
@@ -1774,10 +1781,11 @@ function renderEmailTemplate(tpl, data) {
1774
1781
 
1775
1782
  // src/services/notification.service.ts
1776
1783
  var NotificationService = class {
1777
- constructor(prisma, logger = console, envMode = "Development") {
1784
+ constructor(prisma, logger = console, envMode = "Development", helpers) {
1778
1785
  this.prisma = prisma;
1779
1786
  this.logger = logger;
1780
1787
  this.envMode = envMode;
1788
+ this.helpers = helpers;
1781
1789
  }
1782
1790
  /**
1783
1791
  * Main entry: handle one business event.
@@ -1796,15 +1804,18 @@ var NotificationService = class {
1796
1804
  this.logger.info(
1797
1805
  `[NotificationService] No config for event=${evt.eventName} serviceEventId=${evt.serviceEventId}`
1798
1806
  );
1799
- return;
1807
+ throw new this.helpers.ErrorHandler(
1808
+ 400,
1809
+ this.helpers.generateErrorMessage("NOT_FOUND", evt.eventName)
1810
+ );
1800
1811
  }
1801
- const emailTpl = cfg.allowEmail ? {
1812
+ const emailTpl = cfg.allowEmail && cfg.serviceEvent.allowEmail ? {
1802
1813
  subject: "PO {{poNumber}} created",
1803
1814
  body: "<p>Hello {{vendor}}, PO {{poNumber}} created</p>"
1804
1815
  } : null;
1805
- const smsTpl = cfg.allowSms ? { body: "PO {{poNumber}} created for {{vendor}}" } : null;
1806
- const waTpl = cfg.allowWhatsapp ? { body: "*PO {{poNumber}}* created for {{vendor}}" } : null;
1807
- const appTpl = cfg.allowAppNotification ? {
1816
+ const smsTpl = cfg.allowSms && cfg.serviceEvent.allowSms ? { body: "PO {{poNumber}} created for {{vendor}}" } : null;
1817
+ const waTpl = cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp ? { body: "*PO {{poNumber}}* created for {{vendor}}" } : null;
1818
+ const appTpl = cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification ? {
1808
1819
  subject: "PO created",
1809
1820
  body: "PO {{poNumber}} created for {{vendor}}"
1810
1821
  } : null;
@@ -1876,6 +1887,7 @@ var NotificationService = class {
1876
1887
  * Helper: send through a provider and then write audit row.
1877
1888
  */
1878
1889
  async sendAndAudit(args) {
1890
+ const recipient = args.providerType === "EMAIL" /* EMAIL */ ? args.evt.recipient.email : args.providerType === "SMS" /* SMS */ ? args.evt.recipient.phone : args.providerType === "WHATSAPP" /* WHATSAPP */ ? args.evt.recipient.whatsapp : args.evt.recipient.appUserId;
1879
1891
  try {
1880
1892
  const result = await args.provider.send({
1881
1893
  subject: args.subject,
@@ -1889,7 +1901,9 @@ var NotificationService = class {
1889
1901
  eventConfigId: args.eventConfigId,
1890
1902
  notificationType: args.providerType,
1891
1903
  isSent: result.ok,
1892
- sentAt: result.ok ? /* @__PURE__ */ new Date() : null
1904
+ sentAt: result.ok ? /* @__PURE__ */ new Date() : null,
1905
+ recipient,
1906
+ messageContent: args.body
1893
1907
  }
1894
1908
  });
1895
1909
  } catch (err) {
@@ -1901,7 +1915,9 @@ var NotificationService = class {
1901
1915
  eventConfigId: args.eventConfigId,
1902
1916
  notificationType: args.providerType,
1903
1917
  isSent: false,
1904
- sentAt: null
1918
+ sentAt: null,
1919
+ recipient,
1920
+ messageContent: args.body
1905
1921
  }
1906
1922
  });
1907
1923
  }
@@ -1918,7 +1934,8 @@ var NotificationEmitter = class {
1918
1934
  this.service = new NotificationService(
1919
1935
  deps.prisma,
1920
1936
  deps.logger ?? console,
1921
- deps.envMode
1937
+ deps.envMode,
1938
+ deps.helpers
1922
1939
  );
1923
1940
  this.emitter.on("notify", async (payload) => {
1924
1941
  try {
package/dist/index.mjs CHANGED
@@ -1615,6 +1615,13 @@ var EmailProvider = class {
1615
1615
  const emailConfig = await this.prisma.emailConfig.findFirst({
1616
1616
  where: { isActive: "yes" }
1617
1617
  });
1618
+ if (!emailConfig || !emailConfig.smtpServer || !emailConfig.smtpUsername || !emailConfig.smtpPassword || !emailConfig.smtpPort) {
1619
+ return {
1620
+ ok: false,
1621
+ provider: "EMAIL" /* EMAIL */,
1622
+ error: "Missing or incomplete email configuration"
1623
+ };
1624
+ }
1618
1625
  const transporter = nodemailer.createTransport({
1619
1626
  pool: true,
1620
1627
  // Reuse the connection
@@ -1728,10 +1735,11 @@ function renderEmailTemplate(tpl, data) {
1728
1735
 
1729
1736
  // src/services/notification.service.ts
1730
1737
  var NotificationService = class {
1731
- constructor(prisma, logger = console, envMode = "Development") {
1738
+ constructor(prisma, logger = console, envMode = "Development", helpers) {
1732
1739
  this.prisma = prisma;
1733
1740
  this.logger = logger;
1734
1741
  this.envMode = envMode;
1742
+ this.helpers = helpers;
1735
1743
  }
1736
1744
  /**
1737
1745
  * Main entry: handle one business event.
@@ -1750,15 +1758,18 @@ var NotificationService = class {
1750
1758
  this.logger.info(
1751
1759
  `[NotificationService] No config for event=${evt.eventName} serviceEventId=${evt.serviceEventId}`
1752
1760
  );
1753
- return;
1761
+ throw new this.helpers.ErrorHandler(
1762
+ 400,
1763
+ this.helpers.generateErrorMessage("NOT_FOUND", evt.eventName)
1764
+ );
1754
1765
  }
1755
- const emailTpl = cfg.allowEmail ? {
1766
+ const emailTpl = cfg.allowEmail && cfg.serviceEvent.allowEmail ? {
1756
1767
  subject: "PO {{poNumber}} created",
1757
1768
  body: "<p>Hello {{vendor}}, PO {{poNumber}} created</p>"
1758
1769
  } : null;
1759
- const smsTpl = cfg.allowSms ? { body: "PO {{poNumber}} created for {{vendor}}" } : null;
1760
- const waTpl = cfg.allowWhatsapp ? { body: "*PO {{poNumber}}* created for {{vendor}}" } : null;
1761
- const appTpl = cfg.allowAppNotification ? {
1770
+ const smsTpl = cfg.allowSms && cfg.serviceEvent.allowSms ? { body: "PO {{poNumber}} created for {{vendor}}" } : null;
1771
+ const waTpl = cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp ? { body: "*PO {{poNumber}}* created for {{vendor}}" } : null;
1772
+ const appTpl = cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification ? {
1762
1773
  subject: "PO created",
1763
1774
  body: "PO {{poNumber}} created for {{vendor}}"
1764
1775
  } : null;
@@ -1830,6 +1841,7 @@ var NotificationService = class {
1830
1841
  * Helper: send through a provider and then write audit row.
1831
1842
  */
1832
1843
  async sendAndAudit(args) {
1844
+ const recipient = args.providerType === "EMAIL" /* EMAIL */ ? args.evt.recipient.email : args.providerType === "SMS" /* SMS */ ? args.evt.recipient.phone : args.providerType === "WHATSAPP" /* WHATSAPP */ ? args.evt.recipient.whatsapp : args.evt.recipient.appUserId;
1833
1845
  try {
1834
1846
  const result = await args.provider.send({
1835
1847
  subject: args.subject,
@@ -1843,7 +1855,9 @@ var NotificationService = class {
1843
1855
  eventConfigId: args.eventConfigId,
1844
1856
  notificationType: args.providerType,
1845
1857
  isSent: result.ok,
1846
- sentAt: result.ok ? /* @__PURE__ */ new Date() : null
1858
+ sentAt: result.ok ? /* @__PURE__ */ new Date() : null,
1859
+ recipient,
1860
+ messageContent: args.body
1847
1861
  }
1848
1862
  });
1849
1863
  } catch (err) {
@@ -1855,7 +1869,9 @@ var NotificationService = class {
1855
1869
  eventConfigId: args.eventConfigId,
1856
1870
  notificationType: args.providerType,
1857
1871
  isSent: false,
1858
- sentAt: null
1872
+ sentAt: null,
1873
+ recipient,
1874
+ messageContent: args.body
1859
1875
  }
1860
1876
  });
1861
1877
  }
@@ -1872,7 +1888,8 @@ var NotificationEmitter = class {
1872
1888
  this.service = new NotificationService(
1873
1889
  deps.prisma,
1874
1890
  deps.logger ?? console,
1875
- deps.envMode
1891
+ deps.envMode,
1892
+ deps.helpers
1876
1893
  );
1877
1894
  this.emitter.on("notify", async (payload) => {
1878
1895
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",