payload-plugin-newsletter 0.13.0 → 0.13.2

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/dist/index.cjs CHANGED
@@ -1046,11 +1046,19 @@ var createSubscribersCollection = (pluginConfig) => {
1046
1046
  async ({ doc, req, operation, previousDoc }) => {
1047
1047
  if (operation === "create") {
1048
1048
  const emailService = req.payload.newsletterEmailService;
1049
+ console.log("[Newsletter Plugin] Creating subscriber:", {
1050
+ email: doc.email,
1051
+ hasEmailService: !!emailService
1052
+ });
1049
1053
  if (emailService) {
1050
1054
  try {
1051
1055
  await emailService.addContact(doc);
1052
- } catch {
1056
+ console.log("[Newsletter Plugin] Successfully added contact to email service");
1057
+ } catch (error) {
1058
+ console.error("[Newsletter Plugin] Failed to add contact to email service:", error);
1053
1059
  }
1060
+ } else {
1061
+ console.warn("[Newsletter Plugin] No email service configured for subscriber creation");
1054
1062
  }
1055
1063
  if (doc.subscriptionStatus === "active" && emailService) {
1056
1064
  try {
@@ -1080,10 +1088,22 @@ var createSubscribersCollection = (pluginConfig) => {
1080
1088
  }
1081
1089
  if (operation === "update" && previousDoc) {
1082
1090
  const emailService = req.payload.newsletterEmailService;
1083
- if (doc.subscriptionStatus !== previousDoc.subscriptionStatus && emailService) {
1084
- try {
1085
- await emailService.updateContact(doc);
1086
- } catch {
1091
+ if (doc.subscriptionStatus !== previousDoc.subscriptionStatus) {
1092
+ console.log("[Newsletter Plugin] Subscription status changed:", {
1093
+ email: doc.email,
1094
+ from: previousDoc.subscriptionStatus,
1095
+ to: doc.subscriptionStatus,
1096
+ hasEmailService: !!emailService
1097
+ });
1098
+ if (emailService) {
1099
+ try {
1100
+ await emailService.updateContact(doc);
1101
+ console.log("[Newsletter Plugin] Successfully updated contact in email service");
1102
+ } catch (error) {
1103
+ console.error("[Newsletter Plugin] Failed to update contact in email service:", error);
1104
+ }
1105
+ } else {
1106
+ console.warn("[Newsletter Plugin] No email service configured");
1087
1107
  }
1088
1108
  }
1089
1109
  if (doc.subscriptionStatus === "unsubscribed" && previousDoc.subscriptionStatus !== "unsubscribed") {
@@ -1654,6 +1674,7 @@ var BroadcastProvider = class {
1654
1674
  },
1655
1675
  body: JSON.stringify({
1656
1676
  email: contact.email,
1677
+ // Email at root level to identify the subscriber
1657
1678
  subscriber: {
1658
1679
  first_name: firstName || void 0,
1659
1680
  last_name: lastName || void 0,
@@ -3772,11 +3793,19 @@ var createBroadcastsCollection = (pluginConfig) => {
3772
3793
  plural: "Broadcasts"
3773
3794
  },
3774
3795
  admin: {
3775
- useAsTitle: "contentSection.subject",
3796
+ useAsTitle: "subject",
3776
3797
  description: "Individual email campaigns sent to subscribers",
3777
- defaultColumns: ["contentSection.subject", "status", "sentAt", "recipientCount", "actions"]
3798
+ defaultColumns: ["subject", "status", "sentAt", "recipientCount", "actions"]
3778
3799
  },
3779
3800
  fields: [
3801
+ {
3802
+ name: "subject",
3803
+ type: "text",
3804
+ required: true,
3805
+ admin: {
3806
+ description: "Email subject line"
3807
+ }
3808
+ },
3780
3809
  {
3781
3810
  type: "row",
3782
3811
  fields: [
@@ -3791,14 +3820,6 @@ var createBroadcastsCollection = (pluginConfig) => {
3791
3820
  }
3792
3821
  },
3793
3822
  fields: [
3794
- {
3795
- name: "subject",
3796
- type: "text",
3797
- required: true,
3798
- admin: {
3799
- description: "Email subject line"
3800
- }
3801
- },
3802
3823
  {
3803
3824
  name: "preheader",
3804
3825
  type: "text",
@@ -4009,9 +4030,9 @@ var createBroadcastsCollection = (pluginConfig) => {
4009
4030
  const provider = new BroadcastApiProvider2(providerConfig);
4010
4031
  const htmlContent = await convertToEmailSafeHtml(doc.contentSection?.content);
4011
4032
  const providerBroadcast = await provider.create({
4012
- name: doc.contentSection?.subject,
4033
+ name: doc.subject,
4013
4034
  // Use subject as name since we removed the name field
4014
- subject: doc.contentSection?.subject,
4035
+ subject: doc.subject,
4015
4036
  preheader: doc.contentSection?.preheader,
4016
4037
  content: htmlContent,
4017
4038
  trackOpens: doc.settings?.trackOpens,
@@ -4056,9 +4077,9 @@ var createBroadcastsCollection = (pluginConfig) => {
4056
4077
  return data;
4057
4078
  }
4058
4079
  const updates = {};
4059
- if (data.contentSection?.subject !== originalDoc.contentSection?.subject) {
4060
- updates.name = data.contentSection?.subject;
4061
- updates.subject = data.contentSection?.subject;
4080
+ if (data.subject !== originalDoc.subject) {
4081
+ updates.name = data.subject;
4082
+ updates.subject = data.subject;
4062
4083
  }
4063
4084
  if (data.contentSection?.preheader !== originalDoc.contentSection?.preheader) updates.preheader = data.contentSection?.preheader;
4064
4085
  if (data.contentSection?.content !== originalDoc.contentSection?.content) {
@@ -4489,6 +4510,12 @@ var newsletterPlugin = (pluginConfig) => (incomingConfig) => {
4489
4510
  const settings = await payload.findGlobal({
4490
4511
  slug: config.settingsSlug || "newsletter-settings"
4491
4512
  });
4513
+ console.log("[Newsletter Plugin] Initializing with settings:", {
4514
+ hasSettings: !!settings,
4515
+ settingsProvider: settings?.provider,
4516
+ configProvider: config.providers?.default,
4517
+ hasBroadcastConfig: !!config.providers?.broadcast
4518
+ });
4492
4519
  let emailServiceConfig;
4493
4520
  if (settings) {
4494
4521
  emailServiceConfig = {
@@ -4523,8 +4550,24 @@ var newsletterPlugin = (pluginConfig) => (incomingConfig) => {
4523
4550
  broadcast: config.providers.broadcast
4524
4551
  };
4525
4552
  }
4526
- payload.newsletterEmailService = createEmailService(emailServiceConfig);
4527
- console.warn("Newsletter plugin initialized with", payload.newsletterEmailService.getProvider(), "provider");
4553
+ console.log("[Newsletter Plugin] Email service config:", {
4554
+ provider: emailServiceConfig.provider,
4555
+ hasBroadcastConfig: !!emailServiceConfig.broadcast,
4556
+ broadcastUrl: emailServiceConfig.broadcast?.apiUrl,
4557
+ hasToken: !!emailServiceConfig.broadcast?.token
4558
+ });
4559
+ try {
4560
+ const emailService = createEmailService(emailServiceConfig);
4561
+ payload.newsletterEmailService = emailService;
4562
+ console.log("[Newsletter Plugin] Email service initialized:", {
4563
+ provider: emailService.getProvider(),
4564
+ hasProvider: !!emailService,
4565
+ payloadHasService: !!payload.newsletterEmailService
4566
+ });
4567
+ } catch (emailServiceError) {
4568
+ console.error("[Newsletter Plugin] Failed to create email service:", emailServiceError);
4569
+ console.error("[Newsletter Plugin] Email service config was:", emailServiceConfig);
4570
+ }
4528
4571
  if (config.features?.newsletterManagement?.enabled) {
4529
4572
  try {
4530
4573
  let broadcastProvider;