@blackcode_sa/metaestetics-api 1.5.47 → 1.5.49
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/admin/index.d.mts
CHANGED
|
@@ -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
|
package/dist/admin/index.d.ts
CHANGED
|
@@ -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
|
package/dist/admin/index.js
CHANGED
|
@@ -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
|
|
@@ -1691,11 +1717,42 @@ var BaseMailingService = class {
|
|
|
1691
1717
|
throw new Error("Could not get Mailgun messages API");
|
|
1692
1718
|
}
|
|
1693
1719
|
messagesApi.send(data, (error, body) => {
|
|
1720
|
+
var _a, _b, _c;
|
|
1694
1721
|
if (error) {
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1722
|
+
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
1723
|
+
const clientOptions = this.mailgunClient.options || {};
|
|
1724
|
+
Logger.error(
|
|
1725
|
+
"[BaseMailingService] Mailgun authentication error - possible region mismatch:",
|
|
1726
|
+
{
|
|
1727
|
+
error: error instanceof Error ? error.message : error,
|
|
1728
|
+
statusCode: error.statusCode,
|
|
1729
|
+
domain: clientOptions.domain || "unknown",
|
|
1730
|
+
host: clientOptions.host || "default api.mailgun.net",
|
|
1731
|
+
suggestion: "If using EU region domains, ensure host is set to 'api.eu.mailgun.net'",
|
|
1732
|
+
response: error.response ? JSON.stringify(error.response) : "No response details",
|
|
1733
|
+
request: error.request ? {
|
|
1734
|
+
method: (_a = error.request) == null ? void 0 : _a.method,
|
|
1735
|
+
path: (_b = error.request) == null ? void 0 : _b.path,
|
|
1736
|
+
host: (_c = error.request) == null ? void 0 : _c.host
|
|
1737
|
+
} : "No request details"
|
|
1738
|
+
}
|
|
1739
|
+
);
|
|
1740
|
+
const enhancedError = new Error(
|
|
1741
|
+
`Mailgun Authentication Error (${error.statusCode}): Possible EU region misconfiguration. Set host to 'api.eu.mailgun.net' for EU domains.`
|
|
1742
|
+
);
|
|
1743
|
+
enhancedError.originalError = error;
|
|
1744
|
+
enhancedError.mailgunConfig = {
|
|
1745
|
+
domain: clientOptions.domain,
|
|
1746
|
+
host: clientOptions.host
|
|
1747
|
+
};
|
|
1748
|
+
reject(enhancedError);
|
|
1749
|
+
} else {
|
|
1750
|
+
Logger.error("[BaseMailingService] Mailgun API error:", {
|
|
1751
|
+
error: error instanceof Error ? error.message : error,
|
|
1752
|
+
statusCode: error.statusCode,
|
|
1753
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1699
1756
|
reject(error);
|
|
1700
1757
|
} else {
|
|
1701
1758
|
Logger.info(
|
package/dist/admin/index.mjs
CHANGED
|
@@ -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
|
|
@@ -1650,11 +1676,42 @@ var BaseMailingService = class {
|
|
|
1650
1676
|
throw new Error("Could not get Mailgun messages API");
|
|
1651
1677
|
}
|
|
1652
1678
|
messagesApi.send(data, (error, body) => {
|
|
1679
|
+
var _a, _b, _c;
|
|
1653
1680
|
if (error) {
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1681
|
+
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
1682
|
+
const clientOptions = this.mailgunClient.options || {};
|
|
1683
|
+
Logger.error(
|
|
1684
|
+
"[BaseMailingService] Mailgun authentication error - possible region mismatch:",
|
|
1685
|
+
{
|
|
1686
|
+
error: error instanceof Error ? error.message : error,
|
|
1687
|
+
statusCode: error.statusCode,
|
|
1688
|
+
domain: clientOptions.domain || "unknown",
|
|
1689
|
+
host: clientOptions.host || "default api.mailgun.net",
|
|
1690
|
+
suggestion: "If using EU region domains, ensure host is set to 'api.eu.mailgun.net'",
|
|
1691
|
+
response: error.response ? JSON.stringify(error.response) : "No response details",
|
|
1692
|
+
request: error.request ? {
|
|
1693
|
+
method: (_a = error.request) == null ? void 0 : _a.method,
|
|
1694
|
+
path: (_b = error.request) == null ? void 0 : _b.path,
|
|
1695
|
+
host: (_c = error.request) == null ? void 0 : _c.host
|
|
1696
|
+
} : "No request details"
|
|
1697
|
+
}
|
|
1698
|
+
);
|
|
1699
|
+
const enhancedError = new Error(
|
|
1700
|
+
`Mailgun Authentication Error (${error.statusCode}): Possible EU region misconfiguration. Set host to 'api.eu.mailgun.net' for EU domains.`
|
|
1701
|
+
);
|
|
1702
|
+
enhancedError.originalError = error;
|
|
1703
|
+
enhancedError.mailgunConfig = {
|
|
1704
|
+
domain: clientOptions.domain,
|
|
1705
|
+
host: clientOptions.host
|
|
1706
|
+
};
|
|
1707
|
+
reject(enhancedError);
|
|
1708
|
+
} else {
|
|
1709
|
+
Logger.error("[BaseMailingService] Mailgun API error:", {
|
|
1710
|
+
error: error instanceof Error ? error.message : error,
|
|
1711
|
+
statusCode: error.statusCode,
|
|
1712
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1658
1715
|
reject(error);
|
|
1659
1716
|
} else {
|
|
1660
1717
|
Logger.info(
|
package/package.json
CHANGED
|
@@ -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,49 @@ export class BaseMailingService {
|
|
|
97
136
|
|
|
98
137
|
messagesApi.send(data, (error, body) => {
|
|
99
138
|
if (error) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
+
response: (error as any).response
|
|
153
|
+
? JSON.stringify((error as any).response)
|
|
154
|
+
: "No response details",
|
|
155
|
+
request: (error as any).request
|
|
156
|
+
? {
|
|
157
|
+
method: (error as any).request?.method,
|
|
158
|
+
path: (error as any).request?.path,
|
|
159
|
+
host: (error as any).request?.host,
|
|
160
|
+
}
|
|
161
|
+
: "No request details",
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
// Provide a more specific error object
|
|
166
|
+
const enhancedError = new Error(
|
|
167
|
+
`Mailgun Authentication Error (${error.statusCode}): Possible EU region misconfiguration. Set host to 'api.eu.mailgun.net' for EU domains.`
|
|
168
|
+
);
|
|
169
|
+
(enhancedError as any).originalError = error;
|
|
170
|
+
(enhancedError as any).mailgunConfig = {
|
|
171
|
+
domain: clientOptions.domain,
|
|
172
|
+
host: clientOptions.host,
|
|
173
|
+
};
|
|
174
|
+
reject(enhancedError);
|
|
175
|
+
} else {
|
|
176
|
+
Logger.error("[BaseMailingService] Mailgun API error:", {
|
|
177
|
+
error: error instanceof Error ? error.message : error,
|
|
178
|
+
statusCode: error.statusCode,
|
|
179
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
104
182
|
reject(error);
|
|
105
183
|
} else {
|
|
106
184
|
Logger.info(
|