payload-plugin-newsletter 0.16.0 → 0.16.1
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 +8 -0
- package/dist/collections.cjs +45 -42
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +45 -42
- package/dist/collections.js.map +1 -1
- package/dist/index.cjs +45 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [0.16.1] - 2025-07-27
|
|
2
|
+
|
|
3
|
+
### Fixed
|
|
4
|
+
- **Critical Bug Fix** - Fixed afterChange hook placement for sending broadcasts
|
|
5
|
+
- The send hook was incorrectly placed in the `afterDelete` array instead of `afterChange`
|
|
6
|
+
- This prevented broadcasts from being sent when published
|
|
7
|
+
- Publishing broadcasts now correctly triggers the send functionality
|
|
8
|
+
|
|
1
9
|
## [0.16.0] - 2025-07-27
|
|
2
10
|
|
|
3
11
|
### Changed
|
package/dist/collections.cjs
CHANGED
|
@@ -1439,6 +1439,51 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1439
1439
|
req.payload.logger.error("Failed to create broadcast in provider:", error);
|
|
1440
1440
|
return doc;
|
|
1441
1441
|
}
|
|
1442
|
+
},
|
|
1443
|
+
// Hook to send when published
|
|
1444
|
+
async ({ doc, operation, previousDoc, req }) => {
|
|
1445
|
+
if (operation !== "update") return doc;
|
|
1446
|
+
const wasUnpublished = !previousDoc?._status || previousDoc._status === "draft";
|
|
1447
|
+
const isNowPublished = doc._status === "published";
|
|
1448
|
+
if (wasUnpublished && isNowPublished && doc.providerId) {
|
|
1449
|
+
if (doc.status === "sent" || doc.status === "sending") {
|
|
1450
|
+
return doc;
|
|
1451
|
+
}
|
|
1452
|
+
try {
|
|
1453
|
+
const broadcastConfig = pluginConfig.providers?.broadcast;
|
|
1454
|
+
const resendConfig = pluginConfig.providers?.resend;
|
|
1455
|
+
if (!broadcastConfig && !resendConfig) {
|
|
1456
|
+
req.payload.logger.error("No provider configured for sending");
|
|
1457
|
+
return doc;
|
|
1458
|
+
}
|
|
1459
|
+
if (broadcastConfig) {
|
|
1460
|
+
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
1461
|
+
const provider = new BroadcastApiProvider2(broadcastConfig);
|
|
1462
|
+
await provider.send(doc.providerId);
|
|
1463
|
+
}
|
|
1464
|
+
await req.payload.update({
|
|
1465
|
+
collection: "broadcasts",
|
|
1466
|
+
id: doc.id,
|
|
1467
|
+
data: {
|
|
1468
|
+
status: "sending" /* SENDING */,
|
|
1469
|
+
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1470
|
+
},
|
|
1471
|
+
req
|
|
1472
|
+
});
|
|
1473
|
+
req.payload.logger.info(`Broadcast ${doc.id} sent successfully`);
|
|
1474
|
+
} catch (error) {
|
|
1475
|
+
req.payload.logger.error(`Failed to send broadcast ${doc.id}:`, error);
|
|
1476
|
+
await req.payload.update({
|
|
1477
|
+
collection: "broadcasts",
|
|
1478
|
+
id: doc.id,
|
|
1479
|
+
data: {
|
|
1480
|
+
status: "failed" /* FAILED */
|
|
1481
|
+
},
|
|
1482
|
+
req
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return doc;
|
|
1442
1487
|
}
|
|
1443
1488
|
],
|
|
1444
1489
|
// Sync updates with provider
|
|
@@ -1507,48 +1552,6 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1507
1552
|
req.payload.logger.error("Failed to delete broadcast from provider:", error);
|
|
1508
1553
|
}
|
|
1509
1554
|
return doc;
|
|
1510
|
-
},
|
|
1511
|
-
// Hook to send when published
|
|
1512
|
-
async ({ doc, req }) => {
|
|
1513
|
-
if (doc._status === "published" && doc.providerId) {
|
|
1514
|
-
if (doc.status === "sent" || doc.status === "sending") {
|
|
1515
|
-
return doc;
|
|
1516
|
-
}
|
|
1517
|
-
try {
|
|
1518
|
-
const broadcastConfig = pluginConfig.providers?.broadcast;
|
|
1519
|
-
const resendConfig = pluginConfig.providers?.resend;
|
|
1520
|
-
if (!broadcastConfig && !resendConfig) {
|
|
1521
|
-
req.payload.logger.error("No provider configured for sending");
|
|
1522
|
-
return doc;
|
|
1523
|
-
}
|
|
1524
|
-
if (broadcastConfig) {
|
|
1525
|
-
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
1526
|
-
const provider = new BroadcastApiProvider2(broadcastConfig);
|
|
1527
|
-
await provider.send(doc.providerId);
|
|
1528
|
-
}
|
|
1529
|
-
await req.payload.update({
|
|
1530
|
-
collection: "broadcasts",
|
|
1531
|
-
id: doc.id,
|
|
1532
|
-
data: {
|
|
1533
|
-
status: "sending" /* SENDING */,
|
|
1534
|
-
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1535
|
-
},
|
|
1536
|
-
req
|
|
1537
|
-
});
|
|
1538
|
-
req.payload.logger.info(`Broadcast ${doc.id} sent successfully`);
|
|
1539
|
-
} catch (error) {
|
|
1540
|
-
req.payload.logger.error(`Failed to send broadcast ${doc.id}:`, error);
|
|
1541
|
-
await req.payload.update({
|
|
1542
|
-
collection: "broadcasts",
|
|
1543
|
-
id: doc.id,
|
|
1544
|
-
data: {
|
|
1545
|
-
status: "failed" /* FAILED */
|
|
1546
|
-
},
|
|
1547
|
-
req
|
|
1548
|
-
});
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
return doc;
|
|
1552
1555
|
}
|
|
1553
1556
|
]
|
|
1554
1557
|
}
|