payload-plugin-newsletter 0.25.8 → 0.25.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 +13 -0
- package/dist/collections.cjs +39 -81
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +39 -81
- package/dist/collections.js.map +1 -1
- package/dist/server.js +39 -81
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -4837,92 +4837,18 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4837
4837
|
async ({ doc, operation, req, previousDoc }) => {
|
|
4838
4838
|
if (!hasProviders) return doc;
|
|
4839
4839
|
if (operation === "create") {
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
docId: doc.id,
|
|
4843
|
-
docIdType: typeof doc.id,
|
|
4844
|
-
hasDoc: !!doc,
|
|
4845
|
-
operation,
|
|
4846
|
-
status: doc._status,
|
|
4847
|
-
hasExternalId: !!doc.externalId,
|
|
4848
|
-
hasProviderId: !!doc.providerId
|
|
4849
|
-
});
|
|
4850
|
-
if (doc.externalId || doc.providerId) {
|
|
4851
|
-
req.payload.logger.info("Broadcast already has provider IDs, skipping creation", {
|
|
4852
|
-
externalId: doc.externalId,
|
|
4853
|
-
providerId: doc.providerId
|
|
4854
|
-
});
|
|
4855
|
-
return doc;
|
|
4856
|
-
}
|
|
4857
|
-
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
4858
|
-
if (!providerConfig || !providerConfig.token) {
|
|
4859
|
-
req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
|
|
4860
|
-
return doc;
|
|
4861
|
-
}
|
|
4862
|
-
const { BroadcastApiProvider: BroadcastApiProvider2 } = await import("./broadcast-TKESOAJN.js");
|
|
4863
|
-
const provider = new BroadcastApiProvider2(providerConfig);
|
|
4864
|
-
const subject = doc.subject || `Draft Broadcast ${(/* @__PURE__ */ new Date()).toISOString()}`;
|
|
4865
|
-
const htmlContent = doc.contentSection?.content ? await convertToEmailSafeHtml(
|
|
4866
|
-
await populateMediaFields(doc.contentSection.content, req.payload, pluginConfig),
|
|
4867
|
-
{
|
|
4868
|
-
wrapInTemplate: pluginConfig.customizations?.broadcasts?.emailPreview?.wrapInTemplate ?? true,
|
|
4869
|
-
customWrapper: pluginConfig.customizations?.broadcasts?.emailPreview?.customWrapper,
|
|
4870
|
-
preheader: doc.contentSection?.preheader,
|
|
4871
|
-
subject,
|
|
4872
|
-
documentData: doc,
|
|
4873
|
-
customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
|
|
4874
|
-
}
|
|
4875
|
-
) : "<p>Draft content - to be updated</p>";
|
|
4876
|
-
const createData = {
|
|
4877
|
-
name: subject,
|
|
4878
|
-
// Use subject as name
|
|
4879
|
-
subject,
|
|
4880
|
-
preheader: doc.contentSection?.preheader || "",
|
|
4881
|
-
content: htmlContent,
|
|
4882
|
-
trackOpens: doc.settings?.trackOpens ?? true,
|
|
4883
|
-
trackClicks: doc.settings?.trackClicks ?? true,
|
|
4884
|
-
replyTo: doc.settings?.replyTo || providerConfig.replyTo,
|
|
4885
|
-
audienceIds: doc.audienceIds?.map((a) => a.audienceId) || []
|
|
4886
|
-
};
|
|
4887
|
-
req.payload.logger.info("Creating broadcast in provider with minimal data to establish association", {
|
|
4888
|
-
subject: createData.subject,
|
|
4889
|
-
hasActualContent: !!doc.contentSection?.content
|
|
4890
|
-
});
|
|
4891
|
-
const providerBroadcast = await provider.create(createData);
|
|
4892
|
-
req.payload.logger.info("Provider broadcast created:", {
|
|
4893
|
-
providerBroadcastId: providerBroadcast.id,
|
|
4894
|
-
providerBroadcastIdType: typeof providerBroadcast.id,
|
|
4895
|
-
docId: doc.id,
|
|
4896
|
-
docIdType: typeof doc.id
|
|
4897
|
-
});
|
|
4898
|
-
req.payload.logger.info(`Broadcast ${doc.id} created in provider with ID ${providerBroadcast.id}`);
|
|
4899
|
-
return {
|
|
4900
|
-
...doc,
|
|
4901
|
-
providerId: providerBroadcast.id,
|
|
4902
|
-
externalId: providerBroadcast.id,
|
|
4903
|
-
// Include externalId in return value
|
|
4904
|
-
providerData: providerBroadcast.providerData
|
|
4905
|
-
};
|
|
4906
|
-
} catch (error) {
|
|
4907
|
-
req.payload.logger.error("Failed to create broadcast in provider during initial creation:");
|
|
4908
|
-
if (error instanceof Error) {
|
|
4909
|
-
req.payload.logger.error("Error details:", {
|
|
4910
|
-
message: error.message,
|
|
4911
|
-
stack: error.stack,
|
|
4912
|
-
name: error.name
|
|
4913
|
-
});
|
|
4914
|
-
} else {
|
|
4915
|
-
req.payload.logger.error("Raw error:", error);
|
|
4916
|
-
}
|
|
4917
|
-
return doc;
|
|
4918
|
-
}
|
|
4840
|
+
req.payload.logger.info("Broadcast created in Payload, provider sync will happen on first update with content");
|
|
4841
|
+
return doc;
|
|
4919
4842
|
}
|
|
4920
4843
|
if (operation === "update") {
|
|
4921
4844
|
req.payload.logger.info("Broadcast afterChange update hook triggered", {
|
|
4922
4845
|
operation,
|
|
4923
4846
|
hasProviderId: !!doc.providerId,
|
|
4847
|
+
hasExternalId: !!doc.externalId,
|
|
4924
4848
|
sendStatus: doc.sendStatus,
|
|
4925
|
-
publishStatus: doc._status
|
|
4849
|
+
publishStatus: doc._status,
|
|
4850
|
+
hasSubject: !!doc.subject,
|
|
4851
|
+
hasContent: !!doc.contentSection?.content
|
|
4926
4852
|
});
|
|
4927
4853
|
try {
|
|
4928
4854
|
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
@@ -4932,8 +4858,40 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4932
4858
|
}
|
|
4933
4859
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await import("./broadcast-TKESOAJN.js");
|
|
4934
4860
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
4861
|
+
if (!doc.providerId && !doc.externalId && doc.subject && doc.contentSection?.content) {
|
|
4862
|
+
req.payload.logger.info("Creating broadcast in provider on first update with content");
|
|
4863
|
+
const htmlContent = await convertToEmailSafeHtml(
|
|
4864
|
+
await populateMediaFields(doc.contentSection.content, req.payload, pluginConfig),
|
|
4865
|
+
{
|
|
4866
|
+
wrapInTemplate: pluginConfig.customizations?.broadcasts?.emailPreview?.wrapInTemplate ?? true,
|
|
4867
|
+
customWrapper: pluginConfig.customizations?.broadcasts?.emailPreview?.customWrapper,
|
|
4868
|
+
preheader: doc.contentSection?.preheader,
|
|
4869
|
+
subject: doc.subject,
|
|
4870
|
+
documentData: doc,
|
|
4871
|
+
customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
|
|
4872
|
+
}
|
|
4873
|
+
);
|
|
4874
|
+
const createData = {
|
|
4875
|
+
name: doc.subject,
|
|
4876
|
+
subject: doc.subject,
|
|
4877
|
+
preheader: doc.contentSection?.preheader || "",
|
|
4878
|
+
content: htmlContent,
|
|
4879
|
+
trackOpens: doc.settings?.trackOpens ?? true,
|
|
4880
|
+
trackClicks: doc.settings?.trackClicks ?? true,
|
|
4881
|
+
replyTo: doc.settings?.replyTo || providerConfig.replyTo,
|
|
4882
|
+
audienceIds: doc.audienceIds?.map((a) => a.audienceId) || []
|
|
4883
|
+
};
|
|
4884
|
+
const providerBroadcast = await provider.create(createData);
|
|
4885
|
+
req.payload.logger.info(`Broadcast ${doc.id} created in provider with ID ${providerBroadcast.id}`);
|
|
4886
|
+
return {
|
|
4887
|
+
...doc,
|
|
4888
|
+
providerId: providerBroadcast.id,
|
|
4889
|
+
externalId: providerBroadcast.id,
|
|
4890
|
+
providerData: providerBroadcast.providerData
|
|
4891
|
+
};
|
|
4892
|
+
}
|
|
4935
4893
|
if (!doc.providerId) {
|
|
4936
|
-
req.payload.logger.
|
|
4894
|
+
req.payload.logger.info(`Broadcast ${doc.id} has no providerId and insufficient content for creation - skipping sync`);
|
|
4937
4895
|
return doc;
|
|
4938
4896
|
}
|
|
4939
4897
|
if (doc.providerId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload-plugin-newsletter",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.9",
|
|
4
4
|
"description": "Complete newsletter management plugin for Payload CMS with subscriber management, magic link authentication, and email service integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|