payload-plugin-newsletter 0.20.6 → 0.21.0

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.
@@ -966,7 +966,8 @@ async function convertToEmailSafeHtml(editorState, options) {
966
966
  if (options.customWrapper) {
967
967
  return await Promise.resolve(options.customWrapper(sanitizedHtml, {
968
968
  preheader: options.preheader,
969
- subject: options.subject
969
+ subject: options.subject,
970
+ documentData: options.documentData
970
971
  }));
971
972
  }
972
973
  return wrapInEmailTemplate(sanitizedHtml, options.preheader);
@@ -1853,7 +1854,7 @@ var createBroadcastPreviewEndpoint = (config, _collectionSlug) => {
1853
1854
  handler: async (req) => {
1854
1855
  try {
1855
1856
  const data = await (req.json?.() || Promise.resolve({}));
1856
- const { content, preheader, subject } = data;
1857
+ const { content, preheader, subject, documentData } = data;
1857
1858
  if (!content) {
1858
1859
  return Response.json({
1859
1860
  success: false,
@@ -1869,6 +1870,8 @@ var createBroadcastPreviewEndpoint = (config, _collectionSlug) => {
1869
1870
  preheader,
1870
1871
  subject,
1871
1872
  mediaUrl,
1873
+ documentData,
1874
+ // Pass all document data
1872
1875
  customBlockConverter: config.customizations?.broadcasts?.customBlockConverter,
1873
1876
  customWrapper: emailPreviewConfig?.customWrapper
1874
1877
  });
@@ -2138,6 +2141,14 @@ var createBroadcastsCollection = (pluginConfig) => {
2138
2141
  condition: (data) => hasProviders && data?.providerId
2139
2142
  }
2140
2143
  },
2144
+ {
2145
+ name: "externalId",
2146
+ type: "text",
2147
+ admin: {
2148
+ readOnly: true,
2149
+ description: "External ID for webhook integration"
2150
+ }
2151
+ },
2141
2152
  {
2142
2153
  name: "providerData",
2143
2154
  type: "json",
@@ -2146,6 +2157,77 @@ var createBroadcastsCollection = (pluginConfig) => {
2146
2157
  condition: () => false
2147
2158
  // Hidden by default
2148
2159
  }
2160
+ },
2161
+ // Webhook tracking fields
2162
+ {
2163
+ name: "webhookData",
2164
+ type: "group",
2165
+ label: "Webhook Data",
2166
+ admin: {
2167
+ condition: () => false
2168
+ // Hidden by default, used for webhook tracking
2169
+ },
2170
+ fields: [
2171
+ {
2172
+ name: "lastWebhookEvent",
2173
+ type: "text",
2174
+ admin: {
2175
+ readOnly: true
2176
+ }
2177
+ },
2178
+ {
2179
+ name: "lastWebhookEventAt",
2180
+ type: "date",
2181
+ admin: {
2182
+ readOnly: true
2183
+ }
2184
+ },
2185
+ {
2186
+ name: "hasWarnings",
2187
+ type: "checkbox",
2188
+ defaultValue: false
2189
+ },
2190
+ {
2191
+ name: "failureReason",
2192
+ type: "text"
2193
+ },
2194
+ {
2195
+ name: "sentCount",
2196
+ type: "number"
2197
+ },
2198
+ {
2199
+ name: "totalCount",
2200
+ type: "number"
2201
+ },
2202
+ {
2203
+ name: "failedCount",
2204
+ type: "number"
2205
+ },
2206
+ {
2207
+ name: "remainingCount",
2208
+ type: "number"
2209
+ },
2210
+ {
2211
+ name: "sendingStartedAt",
2212
+ type: "date"
2213
+ },
2214
+ {
2215
+ name: "failedAt",
2216
+ type: "date"
2217
+ },
2218
+ {
2219
+ name: "abortedAt",
2220
+ type: "date"
2221
+ },
2222
+ {
2223
+ name: "abortReason",
2224
+ type: "text"
2225
+ },
2226
+ {
2227
+ name: "pausedAt",
2228
+ type: "date"
2229
+ }
2230
+ ]
2149
2231
  }
2150
2232
  ],
2151
2233
  hooks: {
@@ -2168,7 +2250,14 @@ var createBroadcastsCollection = (pluginConfig) => {
2168
2250
  const provider = new BroadcastApiProvider2(providerConfig);
2169
2251
  req.payload.logger.info("Populating media fields and converting content to HTML...");
2170
2252
  const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
2253
+ const emailPreviewConfig = pluginConfig.customizations?.broadcasts?.emailPreview;
2171
2254
  const htmlContent = await convertToEmailSafeHtml(populatedContent, {
2255
+ wrapInTemplate: emailPreviewConfig?.wrapInTemplate ?? true,
2256
+ customWrapper: emailPreviewConfig?.customWrapper,
2257
+ preheader: doc.contentSection?.preheader,
2258
+ subject: doc.subject,
2259
+ documentData: doc,
2260
+ // Pass entire document
2172
2261
  customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
2173
2262
  });
2174
2263
  if (!htmlContent || htmlContent.trim() === "") {
@@ -2268,7 +2357,14 @@ var createBroadcastsCollection = (pluginConfig) => {
2268
2357
  }
2269
2358
  req.payload.logger.info("Creating broadcast in provider (deferred from initial create)...");
2270
2359
  const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
2360
+ const emailPreviewConfig = pluginConfig.customizations?.broadcasts?.emailPreview;
2271
2361
  const htmlContent = await convertToEmailSafeHtml(populatedContent, {
2362
+ wrapInTemplate: emailPreviewConfig?.wrapInTemplate ?? true,
2363
+ customWrapper: emailPreviewConfig?.customWrapper,
2364
+ preheader: doc.contentSection?.preheader,
2365
+ subject: doc.subject,
2366
+ documentData: doc,
2367
+ // Pass entire document
2272
2368
  customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
2273
2369
  });
2274
2370
  if (!htmlContent || htmlContent.trim() === "") {
@@ -2330,7 +2426,14 @@ var createBroadcastsCollection = (pluginConfig) => {
2330
2426
  }
2331
2427
  if (JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content)) {
2332
2428
  const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
2429
+ const emailPreviewConfig = pluginConfig.customizations?.broadcasts?.emailPreview;
2333
2430
  updates.content = await convertToEmailSafeHtml(populatedContent, {
2431
+ wrapInTemplate: emailPreviewConfig?.wrapInTemplate ?? true,
2432
+ customWrapper: emailPreviewConfig?.customWrapper,
2433
+ preheader: doc.contentSection?.preheader,
2434
+ subject: doc.subject,
2435
+ documentData: doc,
2436
+ // Pass entire document
2334
2437
  customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
2335
2438
  });
2336
2439
  }
@@ -2784,6 +2887,15 @@ var createSubscribersCollection = (pluginConfig) => {
2784
2887
  type: "date",
2785
2888
  hidden: true
2786
2889
  },
2890
+ // External ID for webhook integration
2891
+ {
2892
+ name: "externalId",
2893
+ type: "text",
2894
+ admin: {
2895
+ description: "ID from email service provider",
2896
+ readOnly: true
2897
+ }
2898
+ },
2787
2899
  // Subscription status
2788
2900
  {
2789
2901
  name: "subscriptionStatus",
@@ -2799,6 +2911,14 @@ var createSubscribersCollection = (pluginConfig) => {
2799
2911
  description: "Current subscription status"
2800
2912
  }
2801
2913
  },
2914
+ {
2915
+ name: "subscribedAt",
2916
+ type: "date",
2917
+ admin: {
2918
+ description: "When the user subscribed",
2919
+ readOnly: true
2920
+ }
2921
+ },
2802
2922
  {
2803
2923
  name: "unsubscribedAt",
2804
2924
  type: "date",
@@ -2808,6 +2928,15 @@ var createSubscribersCollection = (pluginConfig) => {
2808
2928
  readOnly: true
2809
2929
  }
2810
2930
  },
2931
+ {
2932
+ name: "unsubscribeReason",
2933
+ type: "text",
2934
+ admin: {
2935
+ condition: (data) => data?.subscriptionStatus === "unsubscribed",
2936
+ description: "Reason for unsubscribing",
2937
+ readOnly: true
2938
+ }
2939
+ },
2811
2940
  // Email preferences
2812
2941
  {
2813
2942
  name: "emailPreferences",