@blackcode_sa/metaestetics-api 1.5.45 → 1.5.46

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.
@@ -1559,9 +1559,73 @@ var PatientAggregationService = class {
1559
1559
 
1560
1560
  // src/admin/mailing/base.mailing.service.ts
1561
1561
  var admin6 = __toESM(require("firebase-admin"));
1562
+
1563
+ // src/admin/logger/index.ts
1564
+ var firebaseFunctionsLogger;
1565
+ try {
1566
+ firebaseFunctionsLogger = require("firebase-functions/logger");
1567
+ require("firebase-functions/logger/compat");
1568
+ } catch (e) {
1569
+ }
1570
+ var Logger = class {
1571
+ /**
1572
+ * Log an error message
1573
+ * @param message Message to log
1574
+ * @param data Optional data to include
1575
+ */
1576
+ static error(message, data) {
1577
+ if (firebaseFunctionsLogger) {
1578
+ firebaseFunctionsLogger.error(message, data);
1579
+ } else {
1580
+ console.error(message, data !== void 0 ? data : "");
1581
+ }
1582
+ }
1583
+ /**
1584
+ * Log a warning message
1585
+ * @param message Message to log
1586
+ * @param data Optional data to include
1587
+ */
1588
+ static warn(message, data) {
1589
+ if (firebaseFunctionsLogger) {
1590
+ firebaseFunctionsLogger.warn(message, data);
1591
+ } else {
1592
+ console.warn(message, data !== void 0 ? data : "");
1593
+ }
1594
+ }
1595
+ /**
1596
+ * Log an info message
1597
+ * @param message Message to log
1598
+ * @param data Optional data to include
1599
+ */
1600
+ static info(message, data) {
1601
+ if (firebaseFunctionsLogger) {
1602
+ firebaseFunctionsLogger.info(message, data);
1603
+ } else {
1604
+ console.info(message, data !== void 0 ? data : "");
1605
+ }
1606
+ }
1607
+ /**
1608
+ * Log a debug message
1609
+ * @param message Message to log
1610
+ * @param data Optional data to include
1611
+ */
1612
+ static debug(message, data) {
1613
+ if (firebaseFunctionsLogger) {
1614
+ firebaseFunctionsLogger.debug(message, data);
1615
+ } else {
1616
+ console.debug(message, data !== void 0 ? data : "");
1617
+ }
1618
+ }
1619
+ };
1620
+
1621
+ // src/admin/mailing/base.mailing.service.ts
1562
1622
  var BaseMailingService = class {
1563
1623
  // Removed config property as it's no longer managed here
1564
- // protected config: MailgunConfig;
1624
+ // import {
1625
+ // getMailgunConfig,
1626
+ // createMailgunClient,
1627
+ // MailgunConfig,
1628
+ // } from "./mailgun.config";
1565
1629
  /**
1566
1630
  * Constructor for BaseMailingService
1567
1631
  * @param firestore Firestore instance provided by the caller
@@ -1571,14 +1635,14 @@ var BaseMailingService = class {
1571
1635
  this.db = firestore8;
1572
1636
  this.mailgunClient = mailgunClient;
1573
1637
  if (!this.db) {
1574
- console.error("[BaseMailingService] No Firestore instance provided");
1638
+ Logger.error("[BaseMailingService] No Firestore instance provided");
1575
1639
  throw new Error("Firestore instance is required");
1576
1640
  }
1577
1641
  if (!this.mailgunClient) {
1578
- console.error("[BaseMailingService] No Mailgun client provided");
1642
+ Logger.error("[BaseMailingService] No Mailgun client provided");
1579
1643
  throw new Error("Mailgun client is required");
1580
1644
  }
1581
- console.log("[BaseMailingService] Service initialized successfully");
1645
+ Logger.info("[BaseMailingService] Service initialized successfully");
1582
1646
  }
1583
1647
  /**
1584
1648
  * Sends an email using Mailgun
@@ -1604,7 +1668,7 @@ var BaseMailingService = class {
1604
1668
  if (!data.html && !data.text) {
1605
1669
  throw new Error("Email must have either 'html' or 'text' content");
1606
1670
  }
1607
- console.log("[BaseMailingService] Sending email via Mailgun", {
1671
+ Logger.info("[BaseMailingService] Sending email via Mailgun", {
1608
1672
  to: data.to,
1609
1673
  from: data.from,
1610
1674
  subject: data.subject,
@@ -1620,14 +1684,13 @@ var BaseMailingService = class {
1620
1684
  }
1621
1685
  messagesApi.send(data, (error, body) => {
1622
1686
  if (error) {
1623
- console.error(
1624
- "[BaseMailingService] Mailgun API error:",
1625
- error instanceof Error ? error.message : error,
1626
- error instanceof Error ? error.stack : ""
1627
- );
1687
+ Logger.error("[BaseMailingService] Mailgun API error:", {
1688
+ error: error instanceof Error ? error.message : error,
1689
+ stack: error instanceof Error ? error.stack : void 0
1690
+ });
1628
1691
  reject(error);
1629
1692
  } else {
1630
- console.log(
1693
+ Logger.info(
1631
1694
  "[BaseMailingService] Email sent successfully:",
1632
1695
  body
1633
1696
  );
@@ -1635,21 +1698,22 @@ var BaseMailingService = class {
1635
1698
  }
1636
1699
  });
1637
1700
  } catch (sendError) {
1638
- console.error(
1701
+ Logger.error(
1639
1702
  "[BaseMailingService] Error in mailgun.messages().send():",
1640
- sendError instanceof Error ? sendError.message : sendError,
1641
- sendError instanceof Error ? sendError.stack : ""
1703
+ {
1704
+ error: sendError instanceof Error ? sendError.message : sendError,
1705
+ stack: sendError instanceof Error ? sendError.stack : void 0
1706
+ }
1642
1707
  );
1643
1708
  reject(sendError);
1644
1709
  }
1645
1710
  }
1646
1711
  );
1647
1712
  } catch (error) {
1648
- console.error(
1649
- "[BaseMailingService] Error in sendEmail:",
1650
- error instanceof Error ? error.message : error,
1651
- error instanceof Error ? error.stack : ""
1652
- );
1713
+ Logger.error("[BaseMailingService] Error in sendEmail:", {
1714
+ error: error instanceof Error ? error.message : error,
1715
+ stack: error instanceof Error ? error.stack : void 0
1716
+ });
1653
1717
  throw error;
1654
1718
  }
1655
1719
  }
@@ -1670,15 +1734,14 @@ var BaseMailingService = class {
1670
1734
  error: error ? error instanceof Error ? { message: error.message, stack: error.stack } : JSON.stringify(error) : null,
1671
1735
  sentAt: admin6.firestore.FieldValue.serverTimestamp()
1672
1736
  });
1673
- console.log(
1737
+ Logger.info(
1674
1738
  `[BaseMailingService] Email log recorded. Success: ${success}`
1675
1739
  );
1676
1740
  } catch (logError) {
1677
- console.error(
1678
- "[BaseMailingService] Error logging email attempt:",
1679
- logError instanceof Error ? logError.message : logError,
1680
- logError instanceof Error ? logError.stack : ""
1681
- );
1741
+ Logger.error("[BaseMailingService] Error logging email attempt:", {
1742
+ error: logError instanceof Error ? logError.message : logError,
1743
+ stack: logError instanceof Error ? logError.stack : void 0
1744
+ });
1682
1745
  }
1683
1746
  }
1684
1747
  /**
@@ -1699,10 +1762,9 @@ var BaseMailingService = class {
1699
1762
  });
1700
1763
  return rendered;
1701
1764
  } catch (renderError) {
1702
- console.error(
1703
- "[BaseMailingService] Error rendering template:",
1704
- renderError instanceof Error ? renderError.message : renderError
1705
- );
1765
+ Logger.error("[BaseMailingService] Error rendering template:", {
1766
+ error: renderError instanceof Error ? renderError.message : renderError
1767
+ });
1706
1768
  throw new Error(
1707
1769
  `Template rendering failed: ${renderError instanceof Error ? renderError.message : "Unknown error"}`
1708
1770
  );
@@ -1819,9 +1881,9 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1819
1881
  */
1820
1882
  constructor(firestore8, mailgunClient) {
1821
1883
  super(firestore8, mailgunClient);
1822
- this.DEFAULT_REGISTRATION_URL = "https://app.medclinic.com/register";
1884
+ this.DEFAULT_REGISTRATION_URL = "https://metaestetics.net/register";
1823
1885
  this.DEFAULT_SUBJECT = "You've Been Invited to Join as a Practitioner";
1824
- this.DEFAULT_FROM_ADDRESS = "MedClinic <no-reply@your-domain.com>";
1886
+ this.DEFAULT_FROM_ADDRESS = "MedClinic <no-reply@mg.metaestetics.net>";
1825
1887
  }
1826
1888
  /**
1827
1889
  * Sends a practitioner invitation email
@@ -1831,7 +1893,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1831
1893
  async sendInvitationEmail(data) {
1832
1894
  var _a, _b, _c, _d;
1833
1895
  try {
1834
- console.log(
1896
+ Logger.info(
1835
1897
  "[PractitionerInviteMailingService] Sending invitation email to",
1836
1898
  data.token.email
1837
1899
  );
@@ -1858,7 +1920,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1858
1920
  contactEmail,
1859
1921
  currentYear
1860
1922
  };
1861
- console.log("[PractitionerInviteMailingService] Template variables:", {
1923
+ Logger.info("[PractitionerInviteMailingService] Template variables:", {
1862
1924
  clinicName: templateVariables.clinicName,
1863
1925
  practitionerName: templateVariables.practitionerName,
1864
1926
  expirationDate: templateVariables.expirationDate,
@@ -1878,7 +1940,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1878
1940
  subject,
1879
1941
  html
1880
1942
  };
1881
- console.log(
1943
+ Logger.info(
1882
1944
  "[PractitionerInviteMailingService] Sending email with data:",
1883
1945
  {
1884
1946
  to: emailData.to,
@@ -1898,10 +1960,12 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1898
1960
  );
1899
1961
  return result;
1900
1962
  } catch (error) {
1901
- console.error(
1963
+ Logger.error(
1902
1964
  "[PractitionerInviteMailingService] Error sending invitation email:",
1903
- error instanceof Error ? error.message : error,
1904
- error instanceof Error ? error.stack : ""
1965
+ {
1966
+ error: error instanceof Error ? error.message : error,
1967
+ stack: error instanceof Error ? error.stack : void 0
1968
+ }
1905
1969
  );
1906
1970
  await this.logEmailAttempt(
1907
1971
  {
@@ -1925,7 +1989,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1925
1989
  */
1926
1990
  async handleTokenCreationEvent(tokenData, fromAddress) {
1927
1991
  try {
1928
- console.log(
1992
+ Logger.info(
1929
1993
  "[PractitionerInviteMailingService] Handling token creation event for token:",
1930
1994
  tokenData.id
1931
1995
  );
@@ -1945,7 +2009,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1945
2009
  if (!tokenData.expiresAt) {
1946
2010
  throw new Error(`Token ${tokenData.id} is missing expiration date`);
1947
2011
  }
1948
- console.log(
2012
+ Logger.info(
1949
2013
  `[PractitionerInviteMailingService] Fetching practitioner data: ${tokenData.practitionerId}`
1950
2014
  );
1951
2015
  const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(tokenData.practitionerId);
@@ -1959,10 +2023,10 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1959
2023
  `Practitioner ${tokenData.practitionerId} has invalid data structure`
1960
2024
  );
1961
2025
  }
1962
- console.log(
2026
+ Logger.info(
1963
2027
  `[PractitionerInviteMailingService] Practitioner found: ${practitionerData.basicInfo.firstName} ${practitionerData.basicInfo.lastName}`
1964
2028
  );
1965
- console.log(
2029
+ Logger.info(
1966
2030
  `[PractitionerInviteMailingService] Fetching clinic data: ${tokenData.clinicId}`
1967
2031
  );
1968
2032
  const clinicRef = this.db.collection(CLINICS_COLLECTION).doc(tokenData.clinicId);
@@ -1976,11 +2040,11 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1976
2040
  `Clinic ${tokenData.clinicId} has invalid data structure`
1977
2041
  );
1978
2042
  }
1979
- console.log(
2043
+ Logger.info(
1980
2044
  `[PractitionerInviteMailingService] Clinic found: ${clinicData.name}`
1981
2045
  );
1982
2046
  if (!fromAddress) {
1983
- console.warn(
2047
+ Logger.warn(
1984
2048
  "[PractitionerInviteMailingService] No fromAddress provided, using default"
1985
2049
  );
1986
2050
  fromAddress = this.DEFAULT_FROM_ADDRESS;
@@ -2008,18 +2072,20 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
2008
2072
  fromAddress
2009
2073
  }
2010
2074
  };
2011
- console.log(
2075
+ Logger.info(
2012
2076
  "[PractitionerInviteMailingService] Email data prepared, sending invitation"
2013
2077
  );
2014
2078
  await this.sendInvitationEmail(emailData);
2015
- console.log(
2079
+ Logger.info(
2016
2080
  "[PractitionerInviteMailingService] Invitation email sent successfully"
2017
2081
  );
2018
2082
  } catch (error) {
2019
- console.error(
2083
+ Logger.error(
2020
2084
  "[PractitionerInviteMailingService] Error handling token creation event:",
2021
- error instanceof Error ? error.message : error,
2022
- error instanceof Error ? error.stack : ""
2085
+ {
2086
+ error: error instanceof Error ? error.message : error,
2087
+ stack: error instanceof Error ? error.stack : void 0
2088
+ }
2023
2089
  );
2024
2090
  throw error;
2025
2091
  }
@@ -1,3 +1,10 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
1
8
  // src/types/notifications/index.ts
2
9
  var NotificationType = /* @__PURE__ */ ((NotificationType2) => {
3
10
  NotificationType2["PRE_REQUIREMENT"] = "preRequirement";
@@ -1512,9 +1519,73 @@ var PatientAggregationService = class {
1512
1519
 
1513
1520
  // src/admin/mailing/base.mailing.service.ts
1514
1521
  import * as admin6 from "firebase-admin";
1522
+
1523
+ // src/admin/logger/index.ts
1524
+ var firebaseFunctionsLogger;
1525
+ try {
1526
+ firebaseFunctionsLogger = __require("firebase-functions/logger");
1527
+ __require("firebase-functions/logger/compat");
1528
+ } catch (e) {
1529
+ }
1530
+ var Logger = class {
1531
+ /**
1532
+ * Log an error message
1533
+ * @param message Message to log
1534
+ * @param data Optional data to include
1535
+ */
1536
+ static error(message, data) {
1537
+ if (firebaseFunctionsLogger) {
1538
+ firebaseFunctionsLogger.error(message, data);
1539
+ } else {
1540
+ console.error(message, data !== void 0 ? data : "");
1541
+ }
1542
+ }
1543
+ /**
1544
+ * Log a warning message
1545
+ * @param message Message to log
1546
+ * @param data Optional data to include
1547
+ */
1548
+ static warn(message, data) {
1549
+ if (firebaseFunctionsLogger) {
1550
+ firebaseFunctionsLogger.warn(message, data);
1551
+ } else {
1552
+ console.warn(message, data !== void 0 ? data : "");
1553
+ }
1554
+ }
1555
+ /**
1556
+ * Log an info message
1557
+ * @param message Message to log
1558
+ * @param data Optional data to include
1559
+ */
1560
+ static info(message, data) {
1561
+ if (firebaseFunctionsLogger) {
1562
+ firebaseFunctionsLogger.info(message, data);
1563
+ } else {
1564
+ console.info(message, data !== void 0 ? data : "");
1565
+ }
1566
+ }
1567
+ /**
1568
+ * Log a debug message
1569
+ * @param message Message to log
1570
+ * @param data Optional data to include
1571
+ */
1572
+ static debug(message, data) {
1573
+ if (firebaseFunctionsLogger) {
1574
+ firebaseFunctionsLogger.debug(message, data);
1575
+ } else {
1576
+ console.debug(message, data !== void 0 ? data : "");
1577
+ }
1578
+ }
1579
+ };
1580
+
1581
+ // src/admin/mailing/base.mailing.service.ts
1515
1582
  var BaseMailingService = class {
1516
1583
  // Removed config property as it's no longer managed here
1517
- // protected config: MailgunConfig;
1584
+ // import {
1585
+ // getMailgunConfig,
1586
+ // createMailgunClient,
1587
+ // MailgunConfig,
1588
+ // } from "./mailgun.config";
1518
1589
  /**
1519
1590
  * Constructor for BaseMailingService
1520
1591
  * @param firestore Firestore instance provided by the caller
@@ -1524,14 +1595,14 @@ var BaseMailingService = class {
1524
1595
  this.db = firestore8;
1525
1596
  this.mailgunClient = mailgunClient;
1526
1597
  if (!this.db) {
1527
- console.error("[BaseMailingService] No Firestore instance provided");
1598
+ Logger.error("[BaseMailingService] No Firestore instance provided");
1528
1599
  throw new Error("Firestore instance is required");
1529
1600
  }
1530
1601
  if (!this.mailgunClient) {
1531
- console.error("[BaseMailingService] No Mailgun client provided");
1602
+ Logger.error("[BaseMailingService] No Mailgun client provided");
1532
1603
  throw new Error("Mailgun client is required");
1533
1604
  }
1534
- console.log("[BaseMailingService] Service initialized successfully");
1605
+ Logger.info("[BaseMailingService] Service initialized successfully");
1535
1606
  }
1536
1607
  /**
1537
1608
  * Sends an email using Mailgun
@@ -1557,7 +1628,7 @@ var BaseMailingService = class {
1557
1628
  if (!data.html && !data.text) {
1558
1629
  throw new Error("Email must have either 'html' or 'text' content");
1559
1630
  }
1560
- console.log("[BaseMailingService] Sending email via Mailgun", {
1631
+ Logger.info("[BaseMailingService] Sending email via Mailgun", {
1561
1632
  to: data.to,
1562
1633
  from: data.from,
1563
1634
  subject: data.subject,
@@ -1573,14 +1644,13 @@ var BaseMailingService = class {
1573
1644
  }
1574
1645
  messagesApi.send(data, (error, body) => {
1575
1646
  if (error) {
1576
- console.error(
1577
- "[BaseMailingService] Mailgun API error:",
1578
- error instanceof Error ? error.message : error,
1579
- error instanceof Error ? error.stack : ""
1580
- );
1647
+ Logger.error("[BaseMailingService] Mailgun API error:", {
1648
+ error: error instanceof Error ? error.message : error,
1649
+ stack: error instanceof Error ? error.stack : void 0
1650
+ });
1581
1651
  reject(error);
1582
1652
  } else {
1583
- console.log(
1653
+ Logger.info(
1584
1654
  "[BaseMailingService] Email sent successfully:",
1585
1655
  body
1586
1656
  );
@@ -1588,21 +1658,22 @@ var BaseMailingService = class {
1588
1658
  }
1589
1659
  });
1590
1660
  } catch (sendError) {
1591
- console.error(
1661
+ Logger.error(
1592
1662
  "[BaseMailingService] Error in mailgun.messages().send():",
1593
- sendError instanceof Error ? sendError.message : sendError,
1594
- sendError instanceof Error ? sendError.stack : ""
1663
+ {
1664
+ error: sendError instanceof Error ? sendError.message : sendError,
1665
+ stack: sendError instanceof Error ? sendError.stack : void 0
1666
+ }
1595
1667
  );
1596
1668
  reject(sendError);
1597
1669
  }
1598
1670
  }
1599
1671
  );
1600
1672
  } catch (error) {
1601
- console.error(
1602
- "[BaseMailingService] Error in sendEmail:",
1603
- error instanceof Error ? error.message : error,
1604
- error instanceof Error ? error.stack : ""
1605
- );
1673
+ Logger.error("[BaseMailingService] Error in sendEmail:", {
1674
+ error: error instanceof Error ? error.message : error,
1675
+ stack: error instanceof Error ? error.stack : void 0
1676
+ });
1606
1677
  throw error;
1607
1678
  }
1608
1679
  }
@@ -1623,15 +1694,14 @@ var BaseMailingService = class {
1623
1694
  error: error ? error instanceof Error ? { message: error.message, stack: error.stack } : JSON.stringify(error) : null,
1624
1695
  sentAt: admin6.firestore.FieldValue.serverTimestamp()
1625
1696
  });
1626
- console.log(
1697
+ Logger.info(
1627
1698
  `[BaseMailingService] Email log recorded. Success: ${success}`
1628
1699
  );
1629
1700
  } catch (logError) {
1630
- console.error(
1631
- "[BaseMailingService] Error logging email attempt:",
1632
- logError instanceof Error ? logError.message : logError,
1633
- logError instanceof Error ? logError.stack : ""
1634
- );
1701
+ Logger.error("[BaseMailingService] Error logging email attempt:", {
1702
+ error: logError instanceof Error ? logError.message : logError,
1703
+ stack: logError instanceof Error ? logError.stack : void 0
1704
+ });
1635
1705
  }
1636
1706
  }
1637
1707
  /**
@@ -1652,10 +1722,9 @@ var BaseMailingService = class {
1652
1722
  });
1653
1723
  return rendered;
1654
1724
  } catch (renderError) {
1655
- console.error(
1656
- "[BaseMailingService] Error rendering template:",
1657
- renderError instanceof Error ? renderError.message : renderError
1658
- );
1725
+ Logger.error("[BaseMailingService] Error rendering template:", {
1726
+ error: renderError instanceof Error ? renderError.message : renderError
1727
+ });
1659
1728
  throw new Error(
1660
1729
  `Template rendering failed: ${renderError instanceof Error ? renderError.message : "Unknown error"}`
1661
1730
  );
@@ -1772,9 +1841,9 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1772
1841
  */
1773
1842
  constructor(firestore8, mailgunClient) {
1774
1843
  super(firestore8, mailgunClient);
1775
- this.DEFAULT_REGISTRATION_URL = "https://app.medclinic.com/register";
1844
+ this.DEFAULT_REGISTRATION_URL = "https://metaestetics.net/register";
1776
1845
  this.DEFAULT_SUBJECT = "You've Been Invited to Join as a Practitioner";
1777
- this.DEFAULT_FROM_ADDRESS = "MedClinic <no-reply@your-domain.com>";
1846
+ this.DEFAULT_FROM_ADDRESS = "MedClinic <no-reply@mg.metaestetics.net>";
1778
1847
  }
1779
1848
  /**
1780
1849
  * Sends a practitioner invitation email
@@ -1784,7 +1853,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1784
1853
  async sendInvitationEmail(data) {
1785
1854
  var _a, _b, _c, _d;
1786
1855
  try {
1787
- console.log(
1856
+ Logger.info(
1788
1857
  "[PractitionerInviteMailingService] Sending invitation email to",
1789
1858
  data.token.email
1790
1859
  );
@@ -1811,7 +1880,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1811
1880
  contactEmail,
1812
1881
  currentYear
1813
1882
  };
1814
- console.log("[PractitionerInviteMailingService] Template variables:", {
1883
+ Logger.info("[PractitionerInviteMailingService] Template variables:", {
1815
1884
  clinicName: templateVariables.clinicName,
1816
1885
  practitionerName: templateVariables.practitionerName,
1817
1886
  expirationDate: templateVariables.expirationDate,
@@ -1831,7 +1900,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1831
1900
  subject,
1832
1901
  html
1833
1902
  };
1834
- console.log(
1903
+ Logger.info(
1835
1904
  "[PractitionerInviteMailingService] Sending email with data:",
1836
1905
  {
1837
1906
  to: emailData.to,
@@ -1851,10 +1920,12 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1851
1920
  );
1852
1921
  return result;
1853
1922
  } catch (error) {
1854
- console.error(
1923
+ Logger.error(
1855
1924
  "[PractitionerInviteMailingService] Error sending invitation email:",
1856
- error instanceof Error ? error.message : error,
1857
- error instanceof Error ? error.stack : ""
1925
+ {
1926
+ error: error instanceof Error ? error.message : error,
1927
+ stack: error instanceof Error ? error.stack : void 0
1928
+ }
1858
1929
  );
1859
1930
  await this.logEmailAttempt(
1860
1931
  {
@@ -1878,7 +1949,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1878
1949
  */
1879
1950
  async handleTokenCreationEvent(tokenData, fromAddress) {
1880
1951
  try {
1881
- console.log(
1952
+ Logger.info(
1882
1953
  "[PractitionerInviteMailingService] Handling token creation event for token:",
1883
1954
  tokenData.id
1884
1955
  );
@@ -1898,7 +1969,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1898
1969
  if (!tokenData.expiresAt) {
1899
1970
  throw new Error(`Token ${tokenData.id} is missing expiration date`);
1900
1971
  }
1901
- console.log(
1972
+ Logger.info(
1902
1973
  `[PractitionerInviteMailingService] Fetching practitioner data: ${tokenData.practitionerId}`
1903
1974
  );
1904
1975
  const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(tokenData.practitionerId);
@@ -1912,10 +1983,10 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1912
1983
  `Practitioner ${tokenData.practitionerId} has invalid data structure`
1913
1984
  );
1914
1985
  }
1915
- console.log(
1986
+ Logger.info(
1916
1987
  `[PractitionerInviteMailingService] Practitioner found: ${practitionerData.basicInfo.firstName} ${practitionerData.basicInfo.lastName}`
1917
1988
  );
1918
- console.log(
1989
+ Logger.info(
1919
1990
  `[PractitionerInviteMailingService] Fetching clinic data: ${tokenData.clinicId}`
1920
1991
  );
1921
1992
  const clinicRef = this.db.collection(CLINICS_COLLECTION).doc(tokenData.clinicId);
@@ -1929,11 +2000,11 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1929
2000
  `Clinic ${tokenData.clinicId} has invalid data structure`
1930
2001
  );
1931
2002
  }
1932
- console.log(
2003
+ Logger.info(
1933
2004
  `[PractitionerInviteMailingService] Clinic found: ${clinicData.name}`
1934
2005
  );
1935
2006
  if (!fromAddress) {
1936
- console.warn(
2007
+ Logger.warn(
1937
2008
  "[PractitionerInviteMailingService] No fromAddress provided, using default"
1938
2009
  );
1939
2010
  fromAddress = this.DEFAULT_FROM_ADDRESS;
@@ -1961,18 +2032,20 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
1961
2032
  fromAddress
1962
2033
  }
1963
2034
  };
1964
- console.log(
2035
+ Logger.info(
1965
2036
  "[PractitionerInviteMailingService] Email data prepared, sending invitation"
1966
2037
  );
1967
2038
  await this.sendInvitationEmail(emailData);
1968
- console.log(
2039
+ Logger.info(
1969
2040
  "[PractitionerInviteMailingService] Invitation email sent successfully"
1970
2041
  );
1971
2042
  } catch (error) {
1972
- console.error(
2043
+ Logger.error(
1973
2044
  "[PractitionerInviteMailingService] Error handling token creation event:",
1974
- error instanceof Error ? error.message : error,
1975
- error instanceof Error ? error.stack : ""
2045
+ {
2046
+ error: error instanceof Error ? error.message : error,
2047
+ stack: error instanceof Error ? error.stack : void 0
2048
+ }
1976
2049
  );
1977
2050
  throw error;
1978
2051
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.5.45",
4
+ "version": "1.5.46",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -100,6 +100,9 @@
100
100
  "geofire-common": "^6.0.0",
101
101
  "zod": "^3.24.1"
102
102
  },
103
+ "optionalDependencies": {
104
+ "firebase-functions": "^6.2.0"
105
+ },
103
106
  "jest": {
104
107
  "preset": "ts-jest",
105
108
  "testEnvironment": "node",
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Cloud Functions-compatible logger with fallback for other environments
3
+ *
4
+ * This logger automatically detects if it's running in a Cloud Functions environment
5
+ * and uses the appropriate logging method. It falls back to console methods in other environments.
6
+ */
7
+
8
+ // Try to import Firebase Functions logger, but don't cause errors if it's not available
9
+ let firebaseFunctionsLogger: any;
10
+ try {
11
+ // Use dynamic import to avoid requiring firebase-functions in non-Functions environments
12
+ firebaseFunctionsLogger = require("firebase-functions/logger");
13
+ // Import the compatibility module for console.log support if available
14
+ require("firebase-functions/logger/compat");
15
+ } catch (e) {
16
+ // Firebase Functions logger not available, will use fallback
17
+ }
18
+
19
+ /**
20
+ * Logger class that uses Firebase Functions logger when available
21
+ * with fallback to console methods when not in a Cloud Functions environment
22
+ */
23
+ export class Logger {
24
+ /**
25
+ * Log an error message
26
+ * @param message Message to log
27
+ * @param data Optional data to include
28
+ */
29
+ static error(message: string, data?: any): void {
30
+ if (firebaseFunctionsLogger) {
31
+ firebaseFunctionsLogger.error(message, data);
32
+ } else {
33
+ console.error(message, data !== undefined ? data : "");
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Log a warning message
39
+ * @param message Message to log
40
+ * @param data Optional data to include
41
+ */
42
+ static warn(message: string, data?: any): void {
43
+ if (firebaseFunctionsLogger) {
44
+ firebaseFunctionsLogger.warn(message, data);
45
+ } else {
46
+ console.warn(message, data !== undefined ? data : "");
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Log an info message
52
+ * @param message Message to log
53
+ * @param data Optional data to include
54
+ */
55
+ static info(message: string, data?: any): void {
56
+ if (firebaseFunctionsLogger) {
57
+ firebaseFunctionsLogger.info(message, data);
58
+ } else {
59
+ console.info(message, data !== undefined ? data : "");
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Log a debug message
65
+ * @param message Message to log
66
+ * @param data Optional data to include
67
+ */
68
+ static debug(message: string, data?: any): void {
69
+ if (firebaseFunctionsLogger) {
70
+ firebaseFunctionsLogger.debug(message, data);
71
+ } else {
72
+ console.debug(message, data !== undefined ? data : "");
73
+ }
74
+ }
75
+ }
76
+
77
+ // Default export for easier importing
78
+ export default Logger;
@@ -1,11 +1,6 @@
1
1
  import * as mailgun from "mailgun-js";
2
2
  import * as admin from "firebase-admin";
3
- // Configuration is no longer read here
4
- // import {
5
- // getMailgunConfig,
6
- // createMailgunClient,
7
- // MailgunConfig,
8
- // } from "./mailgun.config";
3
+ import { Logger } from "../logger";
9
4
 
10
5
  /**
11
6
  * Base mailing service class that provides common functionality for all mailing services
@@ -14,7 +9,11 @@ export class BaseMailingService {
14
9
  protected db: FirebaseFirestore.Firestore;
15
10
  protected mailgunClient: mailgun.Mailgun;
16
11
  // Removed config property as it's no longer managed here
17
- // protected config: MailgunConfig;
12
+ // import {
13
+ // getMailgunConfig,
14
+ // createMailgunClient,
15
+ // MailgunConfig,
16
+ // } from "./mailgun.config";
18
17
 
19
18
  /**
20
19
  * Constructor for BaseMailingService
@@ -32,17 +31,17 @@ export class BaseMailingService {
32
31
 
33
32
  // Validate instances
34
33
  if (!this.db) {
35
- console.error("[BaseMailingService] No Firestore instance provided");
34
+ Logger.error("[BaseMailingService] No Firestore instance provided");
36
35
  throw new Error("Firestore instance is required");
37
36
  }
38
37
 
39
38
  if (!this.mailgunClient) {
40
- console.error("[BaseMailingService] No Mailgun client provided");
39
+ Logger.error("[BaseMailingService] No Mailgun client provided");
41
40
  throw new Error("Mailgun client is required");
42
41
  }
43
42
 
44
43
  // Log successful initialization
45
- console.log("[BaseMailingService] Service initialized successfully");
44
+ Logger.info("[BaseMailingService] Service initialized successfully");
46
45
  }
47
46
 
48
47
  /**
@@ -79,7 +78,7 @@ export class BaseMailingService {
79
78
  throw new Error("Email must have either 'html' or 'text' content");
80
79
  }
81
80
 
82
- console.log("[BaseMailingService] Sending email via Mailgun", {
81
+ Logger.info("[BaseMailingService] Sending email via Mailgun", {
83
82
  to: data.to,
84
83
  from: data.from,
85
84
  subject: data.subject,
@@ -98,14 +97,13 @@ export class BaseMailingService {
98
97
 
99
98
  messagesApi.send(data, (error, body) => {
100
99
  if (error) {
101
- console.error(
102
- "[BaseMailingService] Mailgun API error:",
103
- error instanceof Error ? error.message : error,
104
- error instanceof Error ? error.stack : ""
105
- );
100
+ Logger.error("[BaseMailingService] Mailgun API error:", {
101
+ error: error instanceof Error ? error.message : error,
102
+ stack: error instanceof Error ? error.stack : undefined,
103
+ });
106
104
  reject(error);
107
105
  } else {
108
- console.log(
106
+ Logger.info(
109
107
  "[BaseMailingService] Email sent successfully:",
110
108
  body
111
109
  );
@@ -113,21 +111,23 @@ export class BaseMailingService {
113
111
  }
114
112
  });
115
113
  } catch (sendError) {
116
- console.error(
114
+ Logger.error(
117
115
  "[BaseMailingService] Error in mailgun.messages().send():",
118
- sendError instanceof Error ? sendError.message : sendError,
119
- sendError instanceof Error ? sendError.stack : ""
116
+ {
117
+ error:
118
+ sendError instanceof Error ? sendError.message : sendError,
119
+ stack: sendError instanceof Error ? sendError.stack : undefined,
120
+ }
120
121
  );
121
122
  reject(sendError);
122
123
  }
123
124
  }
124
125
  );
125
126
  } catch (error) {
126
- console.error(
127
- "[BaseMailingService] Error in sendEmail:",
128
- error instanceof Error ? error.message : error,
129
- error instanceof Error ? error.stack : ""
130
- );
127
+ Logger.error("[BaseMailingService] Error in sendEmail:", {
128
+ error: error instanceof Error ? error.message : error,
129
+ stack: error instanceof Error ? error.stack : undefined,
130
+ });
131
131
  throw error;
132
132
  }
133
133
  }
@@ -158,15 +158,14 @@ export class BaseMailingService {
158
158
  sentAt: admin.firestore.FieldValue.serverTimestamp(),
159
159
  });
160
160
 
161
- console.log(
161
+ Logger.info(
162
162
  `[BaseMailingService] Email log recorded. Success: ${success}`
163
163
  );
164
164
  } catch (logError) {
165
- console.error(
166
- "[BaseMailingService] Error logging email attempt:",
167
- logError instanceof Error ? logError.message : logError,
168
- logError instanceof Error ? logError.stack : ""
169
- );
165
+ Logger.error("[BaseMailingService] Error logging email attempt:", {
166
+ error: logError instanceof Error ? logError.message : logError,
167
+ stack: logError instanceof Error ? logError.stack : undefined,
168
+ });
170
169
  // Don't throw here to prevent disrupting the main flow
171
170
  }
172
171
  }
@@ -196,10 +195,9 @@ export class BaseMailingService {
196
195
 
197
196
  return rendered;
198
197
  } catch (renderError) {
199
- console.error(
200
- "[BaseMailingService] Error rendering template:",
201
- renderError instanceof Error ? renderError.message : renderError
202
- );
198
+ Logger.error("[BaseMailingService] Error rendering template:", {
199
+ error: renderError instanceof Error ? renderError.message : renderError,
200
+ });
203
201
  throw new Error(
204
202
  `Template rendering failed: ${
205
203
  renderError instanceof Error ? renderError.message : "Unknown error"
@@ -2,7 +2,7 @@ import * as admin from "firebase-admin";
2
2
  import * as mailgun from "mailgun-js";
3
3
  import { BaseMailingService } from "../base.mailing.service";
4
4
  import { practitionerInvitationTemplate } from "./templates/invitation.template";
5
-
5
+ import { Logger } from "../../logger";
6
6
  // Import specific types and collection constants
7
7
  import {
8
8
  Practitioner,
@@ -51,11 +51,11 @@ export interface PractitionerInviteEmailData {
51
51
  */
52
52
  export class PractitionerInviteMailingService extends BaseMailingService {
53
53
  private readonly DEFAULT_REGISTRATION_URL =
54
- "https://app.medclinic.com/register";
54
+ "https://metaestetics.net/register";
55
55
  private readonly DEFAULT_SUBJECT =
56
56
  "You've Been Invited to Join as a Practitioner";
57
57
  private readonly DEFAULT_FROM_ADDRESS =
58
- "MedClinic <no-reply@your-domain.com>";
58
+ "MedClinic <no-reply@mg.metaestetics.net>";
59
59
 
60
60
  /**
61
61
  * Constructor for PractitionerInviteMailingService
@@ -78,7 +78,7 @@ export class PractitionerInviteMailingService extends BaseMailingService {
78
78
  data: PractitionerInviteEmailData
79
79
  ): Promise<mailgun.messages.SendResponse> {
80
80
  try {
81
- console.log(
81
+ Logger.info(
82
82
  "[PractitionerInviteMailingService] Sending invitation email to",
83
83
  data.token.email
84
84
  );
@@ -127,7 +127,7 @@ export class PractitionerInviteMailingService extends BaseMailingService {
127
127
  };
128
128
 
129
129
  // Debug log for template variables (excluding token for security)
130
- console.log("[PractitionerInviteMailingService] Template variables:", {
130
+ Logger.info("[PractitionerInviteMailingService] Template variables:", {
131
131
  clinicName: templateVariables.clinicName,
132
132
  practitionerName: templateVariables.practitionerName,
133
133
  expirationDate: templateVariables.expirationDate,
@@ -152,7 +152,7 @@ export class PractitionerInviteMailingService extends BaseMailingService {
152
152
  html,
153
153
  };
154
154
 
155
- console.log(
155
+ Logger.info(
156
156
  "[PractitionerInviteMailingService] Sending email with data:",
157
157
  {
158
158
  to: emailData.to,
@@ -176,10 +176,12 @@ export class PractitionerInviteMailingService extends BaseMailingService {
176
176
 
177
177
  return result;
178
178
  } catch (error) {
179
- console.error(
179
+ Logger.error(
180
180
  "[PractitionerInviteMailingService] Error sending invitation email:",
181
- error instanceof Error ? error.message : error,
182
- error instanceof Error ? error.stack : ""
181
+ {
182
+ error: error instanceof Error ? error.message : error,
183
+ stack: error instanceof Error ? error.stack : undefined,
184
+ }
183
185
  );
184
186
 
185
187
  // Log failure
@@ -210,7 +212,7 @@ export class PractitionerInviteMailingService extends BaseMailingService {
210
212
  fromAddress: string
211
213
  ): Promise<void> {
212
214
  try {
213
- console.log(
215
+ Logger.info(
214
216
  "[PractitionerInviteMailingService] Handling token creation event for token:",
215
217
  tokenData.id
216
218
  );
@@ -237,7 +239,7 @@ export class PractitionerInviteMailingService extends BaseMailingService {
237
239
  }
238
240
 
239
241
  // Get practitioner data using constant and type
240
- console.log(
242
+ Logger.info(
241
243
  `[PractitionerInviteMailingService] Fetching practitioner data: ${tokenData.practitionerId}`
242
244
  );
243
245
  const practitionerRef = this.db
@@ -256,12 +258,12 @@ export class PractitionerInviteMailingService extends BaseMailingService {
256
258
  );
257
259
  }
258
260
 
259
- console.log(
261
+ Logger.info(
260
262
  `[PractitionerInviteMailingService] Practitioner found: ${practitionerData.basicInfo.firstName} ${practitionerData.basicInfo.lastName}`
261
263
  );
262
264
 
263
265
  // Get clinic data using constant and type
264
- console.log(
266
+ Logger.info(
265
267
  `[PractitionerInviteMailingService] Fetching clinic data: ${tokenData.clinicId}`
266
268
  );
267
269
  const clinicRef = this.db
@@ -280,7 +282,7 @@ export class PractitionerInviteMailingService extends BaseMailingService {
280
282
  );
281
283
  }
282
284
 
283
- console.log(
285
+ Logger.info(
284
286
  `[PractitionerInviteMailingService] Clinic found: ${clinicData.name}`
285
287
  );
286
288
 
@@ -289,7 +291,7 @@ export class PractitionerInviteMailingService extends BaseMailingService {
289
291
 
290
292
  // Validate fromAddress
291
293
  if (!fromAddress) {
292
- console.warn(
294
+ Logger.warn(
293
295
  "[PractitionerInviteMailingService] No fromAddress provided, using default"
294
296
  );
295
297
  fromAddress = this.DEFAULT_FROM_ADDRESS;
@@ -320,21 +322,23 @@ export class PractitionerInviteMailingService extends BaseMailingService {
320
322
  },
321
323
  };
322
324
 
323
- console.log(
325
+ Logger.info(
324
326
  "[PractitionerInviteMailingService] Email data prepared, sending invitation"
325
327
  );
326
328
 
327
329
  // Send the invitation email
328
330
  await this.sendInvitationEmail(emailData);
329
331
 
330
- console.log(
332
+ Logger.info(
331
333
  "[PractitionerInviteMailingService] Invitation email sent successfully"
332
334
  );
333
335
  } catch (error) {
334
- console.error(
336
+ Logger.error(
335
337
  "[PractitionerInviteMailingService] Error handling token creation event:",
336
- error instanceof Error ? error.message : error,
337
- error instanceof Error ? error.stack : ""
338
+ {
339
+ error: error instanceof Error ? error.message : error,
340
+ stack: error instanceof Error ? error.stack : undefined,
341
+ }
338
342
  );
339
343
  throw error;
340
344
  }