@blackcode_sa/metaestetics-api 1.5.47 → 1.5.48

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.
@@ -1518,6 +1518,11 @@ declare class BaseMailingService {
1518
1518
  * @param mailgunClient Mailgun client instance provided by the caller
1519
1519
  */
1520
1520
  constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: mailgun.Mailgun);
1521
+ /**
1522
+ * Validates that the Mailgun client is configured correctly
1523
+ * Particularly checks for EU region configuration
1524
+ */
1525
+ private validateMailgunClient;
1521
1526
  /**
1522
1527
  * Sends an email using Mailgun
1523
1528
  * @param data Email data to send, including the 'from' address
@@ -1518,6 +1518,11 @@ declare class BaseMailingService {
1518
1518
  * @param mailgunClient Mailgun client instance provided by the caller
1519
1519
  */
1520
1520
  constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: mailgun.Mailgun);
1521
+ /**
1522
+ * Validates that the Mailgun client is configured correctly
1523
+ * Particularly checks for EU region configuration
1524
+ */
1525
+ private validateMailgunClient;
1521
1526
  /**
1522
1527
  * Sends an email using Mailgun
1523
1528
  * @param data Email data to send, including the 'from' address
@@ -1650,8 +1650,34 @@ var BaseMailingService = class {
1650
1650
  Logger.error("[BaseMailingService] No Mailgun client provided");
1651
1651
  throw new Error("Mailgun client is required");
1652
1652
  }
1653
+ this.validateMailgunClient();
1653
1654
  Logger.info("[BaseMailingService] Service initialized successfully");
1654
1655
  }
1656
+ /**
1657
+ * Validates that the Mailgun client is configured correctly
1658
+ * Particularly checks for EU region configuration
1659
+ */
1660
+ validateMailgunClient() {
1661
+ try {
1662
+ const clientOptions = this.mailgunClient.options || {};
1663
+ const host = clientOptions.host || "";
1664
+ const isEuRegion = host.includes("eu.mailgun.net");
1665
+ Logger.info("[BaseMailingService] Mailgun client configuration:", {
1666
+ host: host || "default",
1667
+ isEuRegion,
1668
+ domain: clientOptions.domain || "unknown"
1669
+ });
1670
+ if (clientOptions.domain && clientOptions.domain.endsWith(".eu") && !isEuRegion) {
1671
+ Logger.warn(
1672
+ "[BaseMailingService] Domain appears to be in EU region but not using EU endpoint. If you're getting 401 Forbidden errors, ensure the host is set to 'api.eu.mailgun.net'"
1673
+ );
1674
+ }
1675
+ } catch (error) {
1676
+ Logger.warn("[BaseMailingService] Could not validate Mailgun client:", {
1677
+ error: error instanceof Error ? error.message : String(error)
1678
+ });
1679
+ }
1680
+ }
1655
1681
  /**
1656
1682
  * Sends an email using Mailgun
1657
1683
  * @param data Email data to send, including the 'from' address
@@ -1692,10 +1718,25 @@ var BaseMailingService = class {
1692
1718
  }
1693
1719
  messagesApi.send(data, (error, body) => {
1694
1720
  if (error) {
1695
- Logger.error("[BaseMailingService] Mailgun API error:", {
1696
- error: error instanceof Error ? error.message : error,
1697
- stack: error instanceof Error ? error.stack : void 0
1698
- });
1721
+ if (error.statusCode === 401 || error.statusCode === 403) {
1722
+ const clientOptions = this.mailgunClient.options || {};
1723
+ Logger.error(
1724
+ "[BaseMailingService] Mailgun authentication error - possible region mismatch:",
1725
+ {
1726
+ error: error instanceof Error ? error.message : error,
1727
+ statusCode: error.statusCode,
1728
+ domain: clientOptions.domain || "unknown",
1729
+ host: clientOptions.host || "default api.mailgun.net",
1730
+ suggestion: "If using EU region domains, ensure host is set to 'api.eu.mailgun.net'"
1731
+ }
1732
+ );
1733
+ } else {
1734
+ Logger.error("[BaseMailingService] Mailgun API error:", {
1735
+ error: error instanceof Error ? error.message : error,
1736
+ statusCode: error.statusCode,
1737
+ stack: error instanceof Error ? error.stack : void 0
1738
+ });
1739
+ }
1699
1740
  reject(error);
1700
1741
  } else {
1701
1742
  Logger.info(
@@ -1609,8 +1609,34 @@ var BaseMailingService = class {
1609
1609
  Logger.error("[BaseMailingService] No Mailgun client provided");
1610
1610
  throw new Error("Mailgun client is required");
1611
1611
  }
1612
+ this.validateMailgunClient();
1612
1613
  Logger.info("[BaseMailingService] Service initialized successfully");
1613
1614
  }
1615
+ /**
1616
+ * Validates that the Mailgun client is configured correctly
1617
+ * Particularly checks for EU region configuration
1618
+ */
1619
+ validateMailgunClient() {
1620
+ try {
1621
+ const clientOptions = this.mailgunClient.options || {};
1622
+ const host = clientOptions.host || "";
1623
+ const isEuRegion = host.includes("eu.mailgun.net");
1624
+ Logger.info("[BaseMailingService] Mailgun client configuration:", {
1625
+ host: host || "default",
1626
+ isEuRegion,
1627
+ domain: clientOptions.domain || "unknown"
1628
+ });
1629
+ if (clientOptions.domain && clientOptions.domain.endsWith(".eu") && !isEuRegion) {
1630
+ Logger.warn(
1631
+ "[BaseMailingService] Domain appears to be in EU region but not using EU endpoint. If you're getting 401 Forbidden errors, ensure the host is set to 'api.eu.mailgun.net'"
1632
+ );
1633
+ }
1634
+ } catch (error) {
1635
+ Logger.warn("[BaseMailingService] Could not validate Mailgun client:", {
1636
+ error: error instanceof Error ? error.message : String(error)
1637
+ });
1638
+ }
1639
+ }
1614
1640
  /**
1615
1641
  * Sends an email using Mailgun
1616
1642
  * @param data Email data to send, including the 'from' address
@@ -1651,10 +1677,25 @@ var BaseMailingService = class {
1651
1677
  }
1652
1678
  messagesApi.send(data, (error, body) => {
1653
1679
  if (error) {
1654
- Logger.error("[BaseMailingService] Mailgun API error:", {
1655
- error: error instanceof Error ? error.message : error,
1656
- stack: error instanceof Error ? error.stack : void 0
1657
- });
1680
+ if (error.statusCode === 401 || error.statusCode === 403) {
1681
+ const clientOptions = this.mailgunClient.options || {};
1682
+ Logger.error(
1683
+ "[BaseMailingService] Mailgun authentication error - possible region mismatch:",
1684
+ {
1685
+ error: error instanceof Error ? error.message : error,
1686
+ statusCode: error.statusCode,
1687
+ domain: clientOptions.domain || "unknown",
1688
+ host: clientOptions.host || "default api.mailgun.net",
1689
+ suggestion: "If using EU region domains, ensure host is set to 'api.eu.mailgun.net'"
1690
+ }
1691
+ );
1692
+ } else {
1693
+ Logger.error("[BaseMailingService] Mailgun API error:", {
1694
+ error: error instanceof Error ? error.message : error,
1695
+ statusCode: error.statusCode,
1696
+ stack: error instanceof Error ? error.stack : void 0
1697
+ });
1698
+ }
1658
1699
  reject(error);
1659
1700
  } else {
1660
1701
  Logger.info(
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.47",
4
+ "version": "1.5.48",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -40,10 +40,49 @@ export class BaseMailingService {
40
40
  throw new Error("Mailgun client is required");
41
41
  }
42
42
 
43
+ // Validate the Mailgun client configuration
44
+ this.validateMailgunClient();
45
+
43
46
  // Log successful initialization
44
47
  Logger.info("[BaseMailingService] Service initialized successfully");
45
48
  }
46
49
 
50
+ /**
51
+ * Validates that the Mailgun client is configured correctly
52
+ * Particularly checks for EU region configuration
53
+ */
54
+ private validateMailgunClient(): void {
55
+ try {
56
+ // Access the host property to check if it's configured for EU region
57
+ const clientOptions = (this.mailgunClient as any).options || {};
58
+ const host = clientOptions.host || "";
59
+ const isEuRegion = host.includes("eu.mailgun.net");
60
+
61
+ Logger.info("[BaseMailingService] Mailgun client configuration:", {
62
+ host: host || "default",
63
+ isEuRegion,
64
+ domain: clientOptions.domain || "unknown",
65
+ });
66
+
67
+ // Check if this appears to be an EU domain but not using EU endpoint
68
+ if (
69
+ clientOptions.domain &&
70
+ clientOptions.domain.endsWith(".eu") &&
71
+ !isEuRegion
72
+ ) {
73
+ Logger.warn(
74
+ "[BaseMailingService] Domain appears to be in EU region but not using EU endpoint. " +
75
+ "If you're getting 401 Forbidden errors, ensure the host is set to 'api.eu.mailgun.net'"
76
+ );
77
+ }
78
+ } catch (error) {
79
+ // Just log the error, don't throw
80
+ Logger.warn("[BaseMailingService] Could not validate Mailgun client:", {
81
+ error: error instanceof Error ? error.message : String(error),
82
+ });
83
+ }
84
+ }
85
+
47
86
  /**
48
87
  * Sends an email using Mailgun
49
88
  * @param data Email data to send, including the 'from' address
@@ -97,10 +136,28 @@ export class BaseMailingService {
97
136
 
98
137
  messagesApi.send(data, (error, body) => {
99
138
  if (error) {
100
- Logger.error("[BaseMailingService] Mailgun API error:", {
101
- error: error instanceof Error ? error.message : error,
102
- stack: error instanceof Error ? error.stack : undefined,
103
- });
139
+ // Enhanced error logging for auth/region issues
140
+ if (error.statusCode === 401 || error.statusCode === 403) {
141
+ const clientOptions =
142
+ (this.mailgunClient as any).options || {};
143
+ Logger.error(
144
+ "[BaseMailingService] Mailgun authentication error - possible region mismatch:",
145
+ {
146
+ error: error instanceof Error ? error.message : error,
147
+ statusCode: error.statusCode,
148
+ domain: clientOptions.domain || "unknown",
149
+ host: clientOptions.host || "default api.mailgun.net",
150
+ suggestion:
151
+ "If using EU region domains, ensure host is set to 'api.eu.mailgun.net'",
152
+ }
153
+ );
154
+ } else {
155
+ Logger.error("[BaseMailingService] Mailgun API error:", {
156
+ error: error instanceof Error ? error.message : error,
157
+ statusCode: error.statusCode,
158
+ stack: error instanceof Error ? error.stack : undefined,
159
+ });
160
+ }
104
161
  reject(error);
105
162
  } else {
106
163
  Logger.info(