payload-plugin-newsletter 0.16.1 → 0.16.3
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/CHANGELOG.md +24 -0
- package/dist/collections.cjs +79 -16
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +79 -16
- package/dist/collections.js.map +1 -1
- package/dist/index.cjs +82 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -19
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +49 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -1
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +47 -0
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## [0.16.3] - 2025-07-27
|
|
2
|
+
|
|
3
|
+
### Improved
|
|
4
|
+
- **Enhanced Error Logging** - Improved error logging for broadcast operations
|
|
5
|
+
- Now logs full error details including message, stack trace, and any additional error properties
|
|
6
|
+
- Helps diagnose API connection issues, authentication failures, and validation errors
|
|
7
|
+
- Structured error logging makes it easier to identify root causes
|
|
8
|
+
- Applied to all broadcast hooks: create, update, delete, and send
|
|
9
|
+
|
|
10
|
+
## [0.16.2] - 2025-07-27
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- **Configuration Consistency** - Fixed broadcast operations to read from Newsletter Settings collection
|
|
14
|
+
- Broadcast create/update/delete operations now check Newsletter Settings first before falling back to env vars
|
|
15
|
+
- This matches the behavior of email operations (magic links, welcome emails)
|
|
16
|
+
- Resolves issue where broadcasts failed when env vars were missing despite settings being configured
|
|
17
|
+
- Added `getBroadcastConfig` utility for consistent configuration retrieval
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- **Configuration Utilities** - New utilities for consistent provider configuration
|
|
21
|
+
- `getBroadcastConfig` - Gets Broadcast provider config from settings or env vars
|
|
22
|
+
- `getResendConfig` - Gets Resend provider config from settings or env vars
|
|
23
|
+
- Both utilities handle errors gracefully with fallback to env vars
|
|
24
|
+
|
|
1
25
|
## [0.16.1] - 2025-07-27
|
|
2
26
|
|
|
3
27
|
### Fixed
|
package/dist/collections.cjs
CHANGED
|
@@ -1162,6 +1162,29 @@ function wrapInEmailTemplate(content, preheader) {
|
|
|
1162
1162
|
</html>`;
|
|
1163
1163
|
}
|
|
1164
1164
|
|
|
1165
|
+
// src/utils/getBroadcastConfig.ts
|
|
1166
|
+
async function getBroadcastConfig(req, pluginConfig) {
|
|
1167
|
+
try {
|
|
1168
|
+
const settings = await req.payload.findGlobal({
|
|
1169
|
+
slug: pluginConfig.settingsSlug || "newsletter-settings",
|
|
1170
|
+
req
|
|
1171
|
+
});
|
|
1172
|
+
if (settings?.provider === "broadcast" && settings?.broadcastSettings) {
|
|
1173
|
+
return {
|
|
1174
|
+
apiUrl: settings.broadcastSettings.apiUrl || pluginConfig.providers?.broadcast?.apiUrl || "",
|
|
1175
|
+
token: settings.broadcastSettings.token || pluginConfig.providers?.broadcast?.token || "",
|
|
1176
|
+
fromAddress: settings.fromAddress || pluginConfig.providers?.broadcast?.fromAddress || "",
|
|
1177
|
+
fromName: settings.fromName || pluginConfig.providers?.broadcast?.fromName || "",
|
|
1178
|
+
replyTo: settings.replyTo || pluginConfig.providers?.broadcast?.replyTo
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
return pluginConfig.providers?.broadcast || null;
|
|
1182
|
+
} catch (error) {
|
|
1183
|
+
req.payload.logger.error("Failed to get broadcast config from settings:", error);
|
|
1184
|
+
return pluginConfig.providers?.broadcast || null;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1165
1188
|
// src/collections/Broadcasts.ts
|
|
1166
1189
|
var createBroadcastsCollection = (pluginConfig) => {
|
|
1167
1190
|
const hasProviders = !!(pluginConfig.providers?.broadcast || pluginConfig.providers?.resend);
|
|
@@ -1402,9 +1425,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1402
1425
|
async ({ doc, operation, req }) => {
|
|
1403
1426
|
if (!hasProviders || operation !== "create") return doc;
|
|
1404
1427
|
try {
|
|
1405
|
-
const providerConfig = pluginConfig
|
|
1406
|
-
if (!providerConfig) {
|
|
1407
|
-
req.payload.logger.error("Broadcast provider not configured");
|
|
1428
|
+
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
1429
|
+
if (!providerConfig || !providerConfig.token) {
|
|
1430
|
+
req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
|
|
1408
1431
|
return doc;
|
|
1409
1432
|
}
|
|
1410
1433
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
@@ -1436,7 +1459,17 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1436
1459
|
providerData: providerBroadcast.providerData
|
|
1437
1460
|
};
|
|
1438
1461
|
} catch (error) {
|
|
1439
|
-
|
|
1462
|
+
if (error instanceof Error) {
|
|
1463
|
+
req.payload.logger.error("Failed to create broadcast in provider:", {
|
|
1464
|
+
message: error.message,
|
|
1465
|
+
stack: error.stack,
|
|
1466
|
+
name: error.name,
|
|
1467
|
+
// If it's a BroadcastProviderError, it might have additional details
|
|
1468
|
+
...error.details
|
|
1469
|
+
});
|
|
1470
|
+
} else {
|
|
1471
|
+
req.payload.logger.error("Failed to create broadcast in provider:", error);
|
|
1472
|
+
}
|
|
1440
1473
|
return doc;
|
|
1441
1474
|
}
|
|
1442
1475
|
},
|
|
@@ -1450,13 +1483,13 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1450
1483
|
return doc;
|
|
1451
1484
|
}
|
|
1452
1485
|
try {
|
|
1453
|
-
const broadcastConfig = pluginConfig
|
|
1486
|
+
const broadcastConfig = await getBroadcastConfig(req, pluginConfig);
|
|
1454
1487
|
const resendConfig = pluginConfig.providers?.resend;
|
|
1455
1488
|
if (!broadcastConfig && !resendConfig) {
|
|
1456
|
-
req.payload.logger.error("No provider configured for sending");
|
|
1489
|
+
req.payload.logger.error("No provider configured for sending in Newsletter Settings or environment variables");
|
|
1457
1490
|
return doc;
|
|
1458
1491
|
}
|
|
1459
|
-
if (broadcastConfig) {
|
|
1492
|
+
if (broadcastConfig && broadcastConfig.token) {
|
|
1460
1493
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
1461
1494
|
const provider = new BroadcastApiProvider2(broadcastConfig);
|
|
1462
1495
|
await provider.send(doc.providerId);
|
|
@@ -1472,7 +1505,17 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1472
1505
|
});
|
|
1473
1506
|
req.payload.logger.info(`Broadcast ${doc.id} sent successfully`);
|
|
1474
1507
|
} catch (error) {
|
|
1475
|
-
|
|
1508
|
+
if (error instanceof Error) {
|
|
1509
|
+
req.payload.logger.error(`Failed to send broadcast ${doc.id}:`, {
|
|
1510
|
+
message: error.message,
|
|
1511
|
+
stack: error.stack,
|
|
1512
|
+
name: error.name,
|
|
1513
|
+
// If it's a BroadcastProviderError, it might have additional details
|
|
1514
|
+
...error.details
|
|
1515
|
+
});
|
|
1516
|
+
} else {
|
|
1517
|
+
req.payload.logger.error(`Failed to send broadcast ${doc.id}:`, error);
|
|
1518
|
+
}
|
|
1476
1519
|
await req.payload.update({
|
|
1477
1520
|
collection: "broadcasts",
|
|
1478
1521
|
id: doc.id,
|
|
@@ -1491,9 +1534,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1491
1534
|
async ({ data, originalDoc, operation, req }) => {
|
|
1492
1535
|
if (!hasProviders || !originalDoc?.providerId || operation !== "update") return data;
|
|
1493
1536
|
try {
|
|
1494
|
-
const providerConfig = pluginConfig
|
|
1495
|
-
if (!providerConfig) {
|
|
1496
|
-
req.payload.logger.error("Broadcast provider not configured");
|
|
1537
|
+
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
1538
|
+
if (!providerConfig || !providerConfig.token) {
|
|
1539
|
+
req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
|
|
1497
1540
|
return data;
|
|
1498
1541
|
}
|
|
1499
1542
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
@@ -1527,7 +1570,17 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1527
1570
|
await provider.update(originalDoc.providerId, updates);
|
|
1528
1571
|
}
|
|
1529
1572
|
} catch (error) {
|
|
1530
|
-
|
|
1573
|
+
if (error instanceof Error) {
|
|
1574
|
+
req.payload.logger.error("Failed to update broadcast in provider:", {
|
|
1575
|
+
message: error.message,
|
|
1576
|
+
stack: error.stack,
|
|
1577
|
+
name: error.name,
|
|
1578
|
+
// If it's a BroadcastProviderError, it might have additional details
|
|
1579
|
+
...error.details
|
|
1580
|
+
});
|
|
1581
|
+
} else {
|
|
1582
|
+
req.payload.logger.error("Failed to update broadcast in provider:", error);
|
|
1583
|
+
}
|
|
1531
1584
|
}
|
|
1532
1585
|
return data;
|
|
1533
1586
|
}
|
|
@@ -1537,9 +1590,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1537
1590
|
async ({ doc, req }) => {
|
|
1538
1591
|
if (!hasProviders || !doc?.providerId) return doc;
|
|
1539
1592
|
try {
|
|
1540
|
-
const providerConfig = pluginConfig
|
|
1541
|
-
if (!providerConfig) {
|
|
1542
|
-
req.payload.logger.error("Broadcast provider not configured");
|
|
1593
|
+
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
1594
|
+
if (!providerConfig || !providerConfig.token) {
|
|
1595
|
+
req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
|
|
1543
1596
|
return doc;
|
|
1544
1597
|
}
|
|
1545
1598
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
@@ -1549,7 +1602,17 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1549
1602
|
await provider.delete(doc.providerId);
|
|
1550
1603
|
}
|
|
1551
1604
|
} catch (error) {
|
|
1552
|
-
|
|
1605
|
+
if (error instanceof Error) {
|
|
1606
|
+
req.payload.logger.error("Failed to delete broadcast from provider:", {
|
|
1607
|
+
message: error.message,
|
|
1608
|
+
stack: error.stack,
|
|
1609
|
+
name: error.name,
|
|
1610
|
+
// If it's a BroadcastProviderError, it might have additional details
|
|
1611
|
+
...error.details
|
|
1612
|
+
});
|
|
1613
|
+
} else {
|
|
1614
|
+
req.payload.logger.error("Failed to delete broadcast from provider:", error);
|
|
1615
|
+
}
|
|
1553
1616
|
}
|
|
1554
1617
|
return doc;
|
|
1555
1618
|
}
|