payload-plugin-newsletter 0.16.7 → 0.16.8

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.8] - 2025-01-29
2
+
3
+ ### Fixed
4
+ - **Handle Empty Content When Creating Broadcasts** - Fixed error when creating broadcasts without content
5
+ - Added null/undefined check in convertToEmailSafeHtml function
6
+ - Skip provider sync when subject or content is missing on create
7
+ - Skip provider sync when content is empty after conversion
8
+ - Prevents "Cannot destructure property 'root' of 'editorState'" error
9
+ - Broadcasts can now be created empty and synced later when content is added
10
+
11
+ ### Technical
12
+ - Updated convertToEmailSafeHtml to accept undefined/null editorState
13
+ - Added pre-sync validation in afterChange hook for create operations
14
+ - Empty broadcasts are saved in Payload but not synced to provider until content is added
15
+
1
16
  ## [0.16.7] - 2025-07-29
2
17
 
3
18
  ### Added
@@ -960,6 +960,9 @@ var EMAIL_SAFE_CONFIG = {
960
960
  FORBID_ATTR: ["class", "id", "onclick", "onload", "onerror"]
961
961
  };
962
962
  async function convertToEmailSafeHtml(editorState, options) {
963
+ if (!editorState) {
964
+ return "";
965
+ }
963
966
  const rawHtml = await lexicalToEmailHtml(editorState, options?.mediaUrl);
964
967
  const sanitizedHtml = import_isomorphic_dompurify.default.sanitize(rawHtml, EMAIL_SAFE_CONFIG);
965
968
  if (options?.wrapInTemplate) {
@@ -1457,6 +1460,10 @@ var createBroadcastsCollection = (pluginConfig) => {
1457
1460
  async ({ doc, operation, req, previousDoc }) => {
1458
1461
  if (!hasProviders) return doc;
1459
1462
  if (operation === "create") {
1463
+ if (!doc.subject || !doc.contentSection?.content) {
1464
+ req.payload.logger.info("Skipping provider sync - broadcast has no subject or content yet");
1465
+ return doc;
1466
+ }
1460
1467
  try {
1461
1468
  const providerConfig = await getBroadcastConfig(req, pluginConfig);
1462
1469
  if (!providerConfig || !providerConfig.token) {
@@ -1467,6 +1474,10 @@ var createBroadcastsCollection = (pluginConfig) => {
1467
1474
  const provider = new BroadcastApiProvider2(providerConfig);
1468
1475
  req.payload.logger.info("Converting content to HTML...");
1469
1476
  const htmlContent = await convertToEmailSafeHtml(doc.contentSection?.content);
1477
+ if (!htmlContent || htmlContent.trim() === "") {
1478
+ req.payload.logger.info("Skipping provider sync - content is empty after conversion");
1479
+ return doc;
1480
+ }
1470
1481
  const createData = {
1471
1482
  name: doc.subject,
1472
1483
  // Use subject as name since we removed the name field