payload-plugin-newsletter 0.16.1 → 0.16.2

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 CHANGED
@@ -1,3 +1,18 @@
1
+ ## [0.16.2] - 2025-07-27
2
+
3
+ ### Fixed
4
+ - **Configuration Consistency** - Fixed broadcast operations to read from Newsletter Settings collection
5
+ - Broadcast create/update/delete operations now check Newsletter Settings first before falling back to env vars
6
+ - This matches the behavior of email operations (magic links, welcome emails)
7
+ - Resolves issue where broadcasts failed when env vars were missing despite settings being configured
8
+ - Added `getBroadcastConfig` utility for consistent configuration retrieval
9
+
10
+ ### Added
11
+ - **Configuration Utilities** - New utilities for consistent provider configuration
12
+ - `getBroadcastConfig` - Gets Broadcast provider config from settings or env vars
13
+ - `getResendConfig` - Gets Resend provider config from settings or env vars
14
+ - Both utilities handle errors gracefully with fallback to env vars
15
+
1
16
  ## [0.16.1] - 2025-07-27
2
17
 
3
18
  ### Fixed
@@ -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.providers?.broadcast;
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));
@@ -1450,13 +1473,13 @@ var createBroadcastsCollection = (pluginConfig) => {
1450
1473
  return doc;
1451
1474
  }
1452
1475
  try {
1453
- const broadcastConfig = pluginConfig.providers?.broadcast;
1476
+ const broadcastConfig = await getBroadcastConfig(req, pluginConfig);
1454
1477
  const resendConfig = pluginConfig.providers?.resend;
1455
1478
  if (!broadcastConfig && !resendConfig) {
1456
- req.payload.logger.error("No provider configured for sending");
1479
+ req.payload.logger.error("No provider configured for sending in Newsletter Settings or environment variables");
1457
1480
  return doc;
1458
1481
  }
1459
- if (broadcastConfig) {
1482
+ if (broadcastConfig && broadcastConfig.token) {
1460
1483
  const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
1461
1484
  const provider = new BroadcastApiProvider2(broadcastConfig);
1462
1485
  await provider.send(doc.providerId);
@@ -1491,9 +1514,9 @@ var createBroadcastsCollection = (pluginConfig) => {
1491
1514
  async ({ data, originalDoc, operation, req }) => {
1492
1515
  if (!hasProviders || !originalDoc?.providerId || operation !== "update") return data;
1493
1516
  try {
1494
- const providerConfig = pluginConfig.providers?.broadcast;
1495
- if (!providerConfig) {
1496
- req.payload.logger.error("Broadcast provider not configured");
1517
+ const providerConfig = await getBroadcastConfig(req, pluginConfig);
1518
+ if (!providerConfig || !providerConfig.token) {
1519
+ req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
1497
1520
  return data;
1498
1521
  }
1499
1522
  const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
@@ -1537,9 +1560,9 @@ var createBroadcastsCollection = (pluginConfig) => {
1537
1560
  async ({ doc, req }) => {
1538
1561
  if (!hasProviders || !doc?.providerId) return doc;
1539
1562
  try {
1540
- const providerConfig = pluginConfig.providers?.broadcast;
1541
- if (!providerConfig) {
1542
- req.payload.logger.error("Broadcast provider not configured");
1563
+ const providerConfig = await getBroadcastConfig(req, pluginConfig);
1564
+ if (!providerConfig || !providerConfig.token) {
1565
+ req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
1543
1566
  return doc;
1544
1567
  }
1545
1568
  const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));