payload-plugin-newsletter 0.16.8 → 0.16.9
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 +15 -0
- package/dist/collections.cjs +117 -39
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +117 -39
- package/dist/collections.js.map +1 -1
- package/dist/index.cjs +117 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +117 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/collections.js
CHANGED
|
@@ -1536,7 +1536,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1536
1536
|
return doc;
|
|
1537
1537
|
}
|
|
1538
1538
|
}
|
|
1539
|
-
if (operation === "update"
|
|
1539
|
+
if (operation === "update") {
|
|
1540
1540
|
req.payload.logger.info("Broadcast afterChange update hook triggered", {
|
|
1541
1541
|
operation,
|
|
1542
1542
|
hasProviderId: !!doc.providerId,
|
|
@@ -1551,57 +1551,135 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1551
1551
|
}
|
|
1552
1552
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
1553
1553
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
return doc;
|
|
1559
|
-
}
|
|
1560
|
-
const contentChanged = doc.subject !== previousDoc?.subject || doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader || JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content) || doc.settings?.trackOpens !== previousDoc?.settings?.trackOpens || doc.settings?.trackClicks !== previousDoc?.settings?.trackClicks || doc.settings?.replyTo !== previousDoc?.settings?.replyTo || JSON.stringify(doc.audienceIds) !== JSON.stringify(previousDoc?.audienceIds);
|
|
1561
|
-
if (contentChanged) {
|
|
1562
|
-
const updates = {};
|
|
1563
|
-
if (doc.subject !== previousDoc?.subject) {
|
|
1564
|
-
updates.name = doc.subject;
|
|
1565
|
-
updates.subject = doc.subject;
|
|
1566
|
-
}
|
|
1567
|
-
if (doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader) {
|
|
1568
|
-
updates.preheader = doc.contentSection?.preheader;
|
|
1554
|
+
if (!doc.providerId) {
|
|
1555
|
+
if (!doc.subject || !doc.contentSection?.content) {
|
|
1556
|
+
req.payload.logger.info("Still missing required fields for provider sync");
|
|
1557
|
+
return doc;
|
|
1569
1558
|
}
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1559
|
+
try {
|
|
1560
|
+
req.payload.logger.info("Creating broadcast in provider (deferred from initial create)...");
|
|
1561
|
+
const htmlContent = await convertToEmailSafeHtml(doc.contentSection?.content);
|
|
1562
|
+
if (!htmlContent || htmlContent.trim() === "") {
|
|
1563
|
+
req.payload.logger.info("Skipping provider sync - content is empty after conversion");
|
|
1564
|
+
return doc;
|
|
1565
|
+
}
|
|
1566
|
+
const createData = {
|
|
1567
|
+
name: doc.subject,
|
|
1568
|
+
subject: doc.subject,
|
|
1569
|
+
preheader: doc.contentSection?.preheader,
|
|
1570
|
+
content: htmlContent,
|
|
1571
|
+
trackOpens: doc.settings?.trackOpens,
|
|
1572
|
+
trackClicks: doc.settings?.trackClicks,
|
|
1573
|
+
replyTo: doc.settings?.replyTo || providerConfig.replyTo,
|
|
1574
|
+
audienceIds: doc.audienceIds?.map((a) => a.audienceId)
|
|
1575
|
+
};
|
|
1576
|
+
req.payload.logger.info("Creating broadcast with data:", {
|
|
1577
|
+
name: createData.name,
|
|
1578
|
+
subject: createData.subject,
|
|
1579
|
+
preheader: createData.preheader || "NONE",
|
|
1580
|
+
contentLength: htmlContent ? htmlContent.length : 0,
|
|
1581
|
+
contentPreview: htmlContent ? htmlContent.substring(0, 100) + "..." : "EMPTY",
|
|
1582
|
+
apiUrl: providerConfig.apiUrl,
|
|
1583
|
+
hasToken: !!providerConfig.token
|
|
1584
|
+
});
|
|
1585
|
+
const providerBroadcast = await provider.create(createData);
|
|
1586
|
+
await req.payload.update({
|
|
1587
|
+
collection: "broadcasts",
|
|
1588
|
+
id: doc.id,
|
|
1589
|
+
data: {
|
|
1590
|
+
providerId: providerBroadcast.id,
|
|
1591
|
+
providerData: providerBroadcast.providerData
|
|
1592
|
+
},
|
|
1593
|
+
req
|
|
1594
|
+
});
|
|
1595
|
+
req.payload.logger.info(`Broadcast ${doc.id} created in provider successfully (deferred)`);
|
|
1596
|
+
return {
|
|
1597
|
+
...doc,
|
|
1598
|
+
providerId: providerBroadcast.id,
|
|
1599
|
+
providerData: providerBroadcast.providerData
|
|
1600
|
+
};
|
|
1601
|
+
} catch (error) {
|
|
1602
|
+
req.payload.logger.error("Raw error from broadcast provider (deferred create):");
|
|
1603
|
+
req.payload.logger.error(error);
|
|
1604
|
+
if (error instanceof Error) {
|
|
1605
|
+
req.payload.logger.error("Error is instance of Error:", {
|
|
1606
|
+
message: error.message,
|
|
1607
|
+
stack: error.stack,
|
|
1608
|
+
name: error.name,
|
|
1609
|
+
...error.details,
|
|
1610
|
+
...error.response,
|
|
1611
|
+
...error.data,
|
|
1612
|
+
...error.status,
|
|
1613
|
+
...error.statusText
|
|
1614
|
+
});
|
|
1615
|
+
} else if (typeof error === "string") {
|
|
1616
|
+
req.payload.logger.error("Error is a string:", error);
|
|
1617
|
+
} else if (error && typeof error === "object") {
|
|
1618
|
+
req.payload.logger.error("Error is an object:", JSON.stringify(error, null, 2));
|
|
1619
|
+
} else {
|
|
1620
|
+
req.payload.logger.error("Unknown error type:", typeof error);
|
|
1621
|
+
}
|
|
1622
|
+
req.payload.logger.error("Failed broadcast document (deferred create):", {
|
|
1623
|
+
id: doc.id,
|
|
1624
|
+
subject: doc.subject,
|
|
1625
|
+
hasContent: !!doc.contentSection?.content,
|
|
1626
|
+
contentType: doc.contentSection?.content ? typeof doc.contentSection.content : "none"
|
|
1627
|
+
});
|
|
1628
|
+
return doc;
|
|
1578
1629
|
}
|
|
1579
|
-
|
|
1580
|
-
|
|
1630
|
+
}
|
|
1631
|
+
if (doc.providerId) {
|
|
1632
|
+
const capabilities = provider.getCapabilities();
|
|
1633
|
+
const sendStatus = doc.sendStatus || "draft" /* DRAFT */;
|
|
1634
|
+
if (!capabilities.editableStatuses.includes(sendStatus)) {
|
|
1635
|
+
req.payload.logger.info(`Skipping sync for broadcast in status: ${sendStatus}`);
|
|
1636
|
+
return doc;
|
|
1581
1637
|
}
|
|
1582
|
-
|
|
1583
|
-
|
|
1638
|
+
const contentChanged = doc.subject !== previousDoc?.subject || doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader || JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content) || doc.settings?.trackOpens !== previousDoc?.settings?.trackOpens || doc.settings?.trackClicks !== previousDoc?.settings?.trackClicks || doc.settings?.replyTo !== previousDoc?.settings?.replyTo || JSON.stringify(doc.audienceIds) !== JSON.stringify(previousDoc?.audienceIds);
|
|
1639
|
+
if (contentChanged) {
|
|
1640
|
+
const updates = {};
|
|
1641
|
+
if (doc.subject !== previousDoc?.subject) {
|
|
1642
|
+
updates.name = doc.subject;
|
|
1643
|
+
updates.subject = doc.subject;
|
|
1644
|
+
}
|
|
1645
|
+
if (doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader) {
|
|
1646
|
+
updates.preheader = doc.contentSection?.preheader;
|
|
1647
|
+
}
|
|
1648
|
+
if (JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content)) {
|
|
1649
|
+
updates.content = await convertToEmailSafeHtml(doc.contentSection?.content);
|
|
1650
|
+
}
|
|
1651
|
+
if (doc.settings?.trackOpens !== previousDoc?.settings?.trackOpens) {
|
|
1652
|
+
updates.trackOpens = doc.settings.trackOpens;
|
|
1653
|
+
}
|
|
1654
|
+
if (doc.settings?.trackClicks !== previousDoc?.settings?.trackClicks) {
|
|
1655
|
+
updates.trackClicks = doc.settings.trackClicks;
|
|
1656
|
+
}
|
|
1657
|
+
if (doc.settings?.replyTo !== previousDoc?.settings?.replyTo) {
|
|
1658
|
+
updates.replyTo = doc.settings.replyTo || providerConfig.replyTo;
|
|
1659
|
+
}
|
|
1660
|
+
if (JSON.stringify(doc.audienceIds) !== JSON.stringify(previousDoc?.audienceIds)) {
|
|
1661
|
+
updates.audienceIds = doc.audienceIds?.map((a) => a.audienceId);
|
|
1662
|
+
}
|
|
1663
|
+
req.payload.logger.info("Syncing broadcast updates to provider", {
|
|
1664
|
+
providerId: doc.providerId,
|
|
1665
|
+
updates
|
|
1666
|
+
});
|
|
1667
|
+
await provider.update(doc.providerId, updates);
|
|
1668
|
+
req.payload.logger.info(`Broadcast ${doc.id} synced to provider successfully`);
|
|
1669
|
+
} else {
|
|
1670
|
+
req.payload.logger.info("No content changes to sync to provider");
|
|
1584
1671
|
}
|
|
1585
|
-
req.payload.logger.info("Syncing broadcast updates to provider", {
|
|
1586
|
-
providerId: doc.providerId,
|
|
1587
|
-
updates
|
|
1588
|
-
});
|
|
1589
|
-
await provider.update(doc.providerId, updates);
|
|
1590
|
-
req.payload.logger.info(`Broadcast ${doc.id} synced to provider successfully`);
|
|
1591
|
-
} else {
|
|
1592
|
-
req.payload.logger.info("No content changes to sync to provider");
|
|
1593
1672
|
}
|
|
1594
1673
|
} catch (error) {
|
|
1595
1674
|
if (error instanceof Error) {
|
|
1596
|
-
req.payload.logger.error("Failed to
|
|
1675
|
+
req.payload.logger.error("Failed to handle broadcast update operation:", {
|
|
1597
1676
|
message: error.message,
|
|
1598
1677
|
stack: error.stack,
|
|
1599
1678
|
name: error.name,
|
|
1600
|
-
// If it's a BroadcastProviderError, it might have additional details
|
|
1601
1679
|
...error.details
|
|
1602
1680
|
});
|
|
1603
1681
|
} else {
|
|
1604
|
-
req.payload.logger.error("Failed to
|
|
1682
|
+
req.payload.logger.error("Failed to handle broadcast update operation:", error);
|
|
1605
1683
|
}
|
|
1606
1684
|
}
|
|
1607
1685
|
}
|