payload-plugin-newsletter 0.16.9 → 0.16.10

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.10] - 2025-01-29
2
+
3
+ ### Fixed
4
+ - **Corrected Syntax Errors** - Fixed TypeScript compilation errors in broadcast afterChange hook
5
+ - Simplified deferred create logic to avoid nested try-catch blocks
6
+ - Removed duplicate error handling and extra braces
7
+ - Fixed all TypeScript compilation errors
8
+ - Maintained functionality for deferred provider sync
9
+
10
+ ### Technical
11
+ - Cleaned up afterChange hook structure
12
+ - Simplified error handling flow
13
+ - Removed redundant code blocks
14
+ - All TypeScript errors resolved
15
+
1
16
  ## [0.16.9] - 2025-01-29
2
17
 
3
18
  ### Fixed
@@ -1569,77 +1569,47 @@ var createBroadcastsCollection = (pluginConfig) => {
1569
1569
  req.payload.logger.info("Still missing required fields for provider sync");
1570
1570
  return doc;
1571
1571
  }
1572
- try {
1573
- req.payload.logger.info("Creating broadcast in provider (deferred from initial create)...");
1574
- const htmlContent = await convertToEmailSafeHtml(doc.contentSection?.content);
1575
- if (!htmlContent || htmlContent.trim() === "") {
1576
- req.payload.logger.info("Skipping provider sync - content is empty after conversion");
1577
- return doc;
1578
- }
1579
- const createData = {
1580
- name: doc.subject,
1581
- subject: doc.subject,
1582
- preheader: doc.contentSection?.preheader,
1583
- content: htmlContent,
1584
- trackOpens: doc.settings?.trackOpens,
1585
- trackClicks: doc.settings?.trackClicks,
1586
- replyTo: doc.settings?.replyTo || providerConfig.replyTo,
1587
- audienceIds: doc.audienceIds?.map((a) => a.audienceId)
1588
- };
1589
- req.payload.logger.info("Creating broadcast with data:", {
1590
- name: createData.name,
1591
- subject: createData.subject,
1592
- preheader: createData.preheader || "NONE",
1593
- contentLength: htmlContent ? htmlContent.length : 0,
1594
- contentPreview: htmlContent ? htmlContent.substring(0, 100) + "..." : "EMPTY",
1595
- apiUrl: providerConfig.apiUrl,
1596
- hasToken: !!providerConfig.token
1597
- });
1598
- const providerBroadcast = await provider.create(createData);
1599
- await req.payload.update({
1600
- collection: "broadcasts",
1601
- id: doc.id,
1602
- data: {
1603
- providerId: providerBroadcast.id,
1604
- providerData: providerBroadcast.providerData
1605
- },
1606
- req
1607
- });
1608
- req.payload.logger.info(`Broadcast ${doc.id} created in provider successfully (deferred)`);
1609
- return {
1610
- ...doc,
1611
- providerId: providerBroadcast.id,
1612
- providerData: providerBroadcast.providerData
1613
- };
1614
- } catch (error) {
1615
- req.payload.logger.error("Raw error from broadcast provider (deferred create):");
1616
- req.payload.logger.error(error);
1617
- if (error instanceof Error) {
1618
- req.payload.logger.error("Error is instance of Error:", {
1619
- message: error.message,
1620
- stack: error.stack,
1621
- name: error.name,
1622
- ...error.details,
1623
- ...error.response,
1624
- ...error.data,
1625
- ...error.status,
1626
- ...error.statusText
1627
- });
1628
- } else if (typeof error === "string") {
1629
- req.payload.logger.error("Error is a string:", error);
1630
- } else if (error && typeof error === "object") {
1631
- req.payload.logger.error("Error is an object:", JSON.stringify(error, null, 2));
1632
- } else {
1633
- req.payload.logger.error("Unknown error type:", typeof error);
1634
- }
1635
- req.payload.logger.error("Failed broadcast document (deferred create):", {
1636
- id: doc.id,
1637
- subject: doc.subject,
1638
- hasContent: !!doc.contentSection?.content,
1639
- contentType: doc.contentSection?.content ? typeof doc.contentSection.content : "none"
1640
- });
1572
+ req.payload.logger.info("Creating broadcast in provider (deferred from initial create)...");
1573
+ const htmlContent = await convertToEmailSafeHtml(doc.contentSection?.content);
1574
+ if (!htmlContent || htmlContent.trim() === "") {
1575
+ req.payload.logger.info("Skipping provider sync - content is empty after conversion");
1641
1576
  return doc;
1642
1577
  }
1578
+ const createData = {
1579
+ name: doc.subject,
1580
+ subject: doc.subject,
1581
+ preheader: doc.contentSection?.preheader,
1582
+ content: htmlContent,
1583
+ trackOpens: doc.settings?.trackOpens,
1584
+ trackClicks: doc.settings?.trackClicks,
1585
+ replyTo: doc.settings?.replyTo || providerConfig.replyTo,
1586
+ audienceIds: doc.audienceIds?.map((a) => a.audienceId)
1587
+ };
1588
+ req.payload.logger.info("Creating broadcast with data:", {
1589
+ name: createData.name,
1590
+ subject: createData.subject,
1591
+ preheader: createData.preheader || "NONE",
1592
+ contentLength: htmlContent ? htmlContent.length : 0,
1593
+ contentPreview: htmlContent ? htmlContent.substring(0, 100) + "..." : "EMPTY",
1594
+ apiUrl: providerConfig.apiUrl,
1595
+ hasToken: !!providerConfig.token
1596
+ });
1597
+ const providerBroadcast = await provider.create(createData);
1598
+ await req.payload.update({
1599
+ collection: "broadcasts",
1600
+ id: doc.id,
1601
+ data: {
1602
+ providerId: providerBroadcast.id,
1603
+ providerData: providerBroadcast.providerData
1604
+ },
1605
+ req
1606
+ });
1607
+ req.payload.logger.info(`Broadcast ${doc.id} created in provider successfully (deferred)`);
1608
+ return {
1609
+ ...doc,
1610
+ providerId: providerBroadcast.id,
1611
+ providerData: providerBroadcast.providerData
1612
+ };
1643
1613
  }
1644
1614
  if (doc.providerId) {
1645
1615
  const capabilities = provider.getCapabilities();
@@ -1684,16 +1654,32 @@ var createBroadcastsCollection = (pluginConfig) => {
1684
1654
  }
1685
1655
  }
1686
1656
  } catch (error) {
1657
+ req.payload.logger.error("Raw error from broadcast update operation:");
1658
+ req.payload.logger.error(error);
1687
1659
  if (error instanceof Error) {
1688
- req.payload.logger.error("Failed to handle broadcast update operation:", {
1660
+ req.payload.logger.error("Error is instance of Error:", {
1689
1661
  message: error.message,
1690
1662
  stack: error.stack,
1691
1663
  name: error.name,
1692
- ...error.details
1664
+ ...error.details,
1665
+ ...error.response,
1666
+ ...error.data,
1667
+ ...error.status,
1668
+ ...error.statusText
1693
1669
  });
1670
+ } else if (typeof error === "string") {
1671
+ req.payload.logger.error("Error is a string:", error);
1672
+ } else if (error && typeof error === "object") {
1673
+ req.payload.logger.error("Error is an object:", JSON.stringify(error, null, 2));
1694
1674
  } else {
1695
- req.payload.logger.error("Failed to handle broadcast update operation:", error);
1675
+ req.payload.logger.error("Unknown error type:", typeof error);
1696
1676
  }
1677
+ req.payload.logger.error("Failed broadcast document (update operation):", {
1678
+ id: doc.id,
1679
+ subject: doc.subject,
1680
+ hasContent: !!doc.contentSection?.content,
1681
+ contentType: doc.contentSection?.content ? typeof doc.contentSection.content : "none"
1682
+ });
1697
1683
  }
1698
1684
  }
1699
1685
  return doc;