payload-plugin-newsletter 0.16.8 → 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 +30 -0
- package/dist/collections.cjs +104 -40
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +104 -40
- package/dist/collections.js.map +1 -1
- package/dist/index.cjs +104 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +104 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
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
|
+
|
|
16
|
+
## [0.16.9] - 2025-01-29
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- **Deferred Provider Sync for Empty Broadcasts** - Fixed issue where broadcasts created empty were never synced to provider
|
|
20
|
+
- Update operation now handles "deferred create" scenario when providerId is missing
|
|
21
|
+
- When a broadcast has subject and content but no providerId, it creates the broadcast in the provider
|
|
22
|
+
- Normal update sync works for broadcasts that already exist in the provider
|
|
23
|
+
- Resolves workflow: create empty → add content → save → now syncs to provider
|
|
24
|
+
|
|
25
|
+
### Technical
|
|
26
|
+
- Modified update operation handler to check for missing providerId
|
|
27
|
+
- Added deferred create logic in update afterChange hook
|
|
28
|
+
- Separated normal update logic to only run when providerId exists
|
|
29
|
+
- Added comprehensive error handling for both deferred create and normal update scenarios
|
|
30
|
+
|
|
1
31
|
## [0.16.8] - 2025-01-29
|
|
2
32
|
|
|
3
33
|
### Fixed
|
package/dist/collections.cjs
CHANGED
|
@@ -1549,7 +1549,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1549
1549
|
return doc;
|
|
1550
1550
|
}
|
|
1551
1551
|
}
|
|
1552
|
-
if (operation === "update"
|
|
1552
|
+
if (operation === "update") {
|
|
1553
1553
|
req.payload.logger.info("Broadcast afterChange update hook triggered", {
|
|
1554
1554
|
operation,
|
|
1555
1555
|
hasProviderId: !!doc.providerId,
|
|
@@ -1564,58 +1564,122 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1564
1564
|
}
|
|
1565
1565
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
1566
1566
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
return doc;
|
|
1572
|
-
}
|
|
1573
|
-
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);
|
|
1574
|
-
if (contentChanged) {
|
|
1575
|
-
const updates = {};
|
|
1576
|
-
if (doc.subject !== previousDoc?.subject) {
|
|
1577
|
-
updates.name = doc.subject;
|
|
1578
|
-
updates.subject = doc.subject;
|
|
1579
|
-
}
|
|
1580
|
-
if (doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader) {
|
|
1581
|
-
updates.preheader = doc.contentSection?.preheader;
|
|
1582
|
-
}
|
|
1583
|
-
if (JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content)) {
|
|
1584
|
-
updates.content = await convertToEmailSafeHtml(doc.contentSection?.content);
|
|
1567
|
+
if (!doc.providerId) {
|
|
1568
|
+
if (!doc.subject || !doc.contentSection?.content) {
|
|
1569
|
+
req.payload.logger.info("Still missing required fields for provider sync");
|
|
1570
|
+
return doc;
|
|
1585
1571
|
}
|
|
1586
|
-
|
|
1587
|
-
|
|
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");
|
|
1576
|
+
return doc;
|
|
1588
1577
|
}
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
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
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
if (doc.providerId) {
|
|
1615
|
+
const capabilities = provider.getCapabilities();
|
|
1616
|
+
const sendStatus = doc.sendStatus || "draft" /* DRAFT */;
|
|
1617
|
+
if (!capabilities.editableStatuses.includes(sendStatus)) {
|
|
1618
|
+
req.payload.logger.info(`Skipping sync for broadcast in status: ${sendStatus}`);
|
|
1619
|
+
return doc;
|
|
1594
1620
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1621
|
+
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);
|
|
1622
|
+
if (contentChanged) {
|
|
1623
|
+
const updates = {};
|
|
1624
|
+
if (doc.subject !== previousDoc?.subject) {
|
|
1625
|
+
updates.name = doc.subject;
|
|
1626
|
+
updates.subject = doc.subject;
|
|
1627
|
+
}
|
|
1628
|
+
if (doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader) {
|
|
1629
|
+
updates.preheader = doc.contentSection?.preheader;
|
|
1630
|
+
}
|
|
1631
|
+
if (JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content)) {
|
|
1632
|
+
updates.content = await convertToEmailSafeHtml(doc.contentSection?.content);
|
|
1633
|
+
}
|
|
1634
|
+
if (doc.settings?.trackOpens !== previousDoc?.settings?.trackOpens) {
|
|
1635
|
+
updates.trackOpens = doc.settings.trackOpens;
|
|
1636
|
+
}
|
|
1637
|
+
if (doc.settings?.trackClicks !== previousDoc?.settings?.trackClicks) {
|
|
1638
|
+
updates.trackClicks = doc.settings.trackClicks;
|
|
1639
|
+
}
|
|
1640
|
+
if (doc.settings?.replyTo !== previousDoc?.settings?.replyTo) {
|
|
1641
|
+
updates.replyTo = doc.settings.replyTo || providerConfig.replyTo;
|
|
1642
|
+
}
|
|
1643
|
+
if (JSON.stringify(doc.audienceIds) !== JSON.stringify(previousDoc?.audienceIds)) {
|
|
1644
|
+
updates.audienceIds = doc.audienceIds?.map((a) => a.audienceId);
|
|
1645
|
+
}
|
|
1646
|
+
req.payload.logger.info("Syncing broadcast updates to provider", {
|
|
1647
|
+
providerId: doc.providerId,
|
|
1648
|
+
updates
|
|
1649
|
+
});
|
|
1650
|
+
await provider.update(doc.providerId, updates);
|
|
1651
|
+
req.payload.logger.info(`Broadcast ${doc.id} synced to provider successfully`);
|
|
1652
|
+
} else {
|
|
1653
|
+
req.payload.logger.info("No content changes to sync to provider");
|
|
1597
1654
|
}
|
|
1598
|
-
req.payload.logger.info("Syncing broadcast updates to provider", {
|
|
1599
|
-
providerId: doc.providerId,
|
|
1600
|
-
updates
|
|
1601
|
-
});
|
|
1602
|
-
await provider.update(doc.providerId, updates);
|
|
1603
|
-
req.payload.logger.info(`Broadcast ${doc.id} synced to provider successfully`);
|
|
1604
|
-
} else {
|
|
1605
|
-
req.payload.logger.info("No content changes to sync to provider");
|
|
1606
1655
|
}
|
|
1607
1656
|
} catch (error) {
|
|
1657
|
+
req.payload.logger.error("Raw error from broadcast update operation:");
|
|
1658
|
+
req.payload.logger.error(error);
|
|
1608
1659
|
if (error instanceof Error) {
|
|
1609
|
-
req.payload.logger.error("
|
|
1660
|
+
req.payload.logger.error("Error is instance of Error:", {
|
|
1610
1661
|
message: error.message,
|
|
1611
1662
|
stack: error.stack,
|
|
1612
1663
|
name: error.name,
|
|
1613
|
-
|
|
1614
|
-
...error.
|
|
1664
|
+
...error.details,
|
|
1665
|
+
...error.response,
|
|
1666
|
+
...error.data,
|
|
1667
|
+
...error.status,
|
|
1668
|
+
...error.statusText
|
|
1615
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));
|
|
1616
1674
|
} else {
|
|
1617
|
-
req.payload.logger.error("
|
|
1675
|
+
req.payload.logger.error("Unknown error type:", typeof error);
|
|
1618
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
|
+
});
|
|
1619
1683
|
}
|
|
1620
1684
|
}
|
|
1621
1685
|
return doc;
|