payload-plugin-newsletter 0.20.5 → 0.20.7

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
  });
@@ -2168,7 +2171,14 @@ var createBroadcastsCollection = (pluginConfig) => {
2168
2171
  const provider = new BroadcastApiProvider2(providerConfig);
2169
2172
  req.payload.logger.info("Populating media fields and converting content to HTML...");
2170
2173
  const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
2174
+ const emailPreviewConfig = pluginConfig.customizations?.broadcasts?.emailPreview;
2171
2175
  const htmlContent = await convertToEmailSafeHtml(populatedContent, {
2176
+ wrapInTemplate: emailPreviewConfig?.wrapInTemplate ?? true,
2177
+ customWrapper: emailPreviewConfig?.customWrapper,
2178
+ preheader: doc.contentSection?.preheader,
2179
+ subject: doc.subject,
2180
+ documentData: doc,
2181
+ // Pass entire document
2172
2182
  customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
2173
2183
  });
2174
2184
  if (!htmlContent || htmlContent.trim() === "") {
@@ -2268,7 +2278,14 @@ var createBroadcastsCollection = (pluginConfig) => {
2268
2278
  }
2269
2279
  req.payload.logger.info("Creating broadcast in provider (deferred from initial create)...");
2270
2280
  const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
2281
+ const emailPreviewConfig = pluginConfig.customizations?.broadcasts?.emailPreview;
2271
2282
  const htmlContent = await convertToEmailSafeHtml(populatedContent, {
2283
+ wrapInTemplate: emailPreviewConfig?.wrapInTemplate ?? true,
2284
+ customWrapper: emailPreviewConfig?.customWrapper,
2285
+ preheader: doc.contentSection?.preheader,
2286
+ subject: doc.subject,
2287
+ documentData: doc,
2288
+ // Pass entire document
2272
2289
  customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
2273
2290
  });
2274
2291
  if (!htmlContent || htmlContent.trim() === "") {
@@ -2330,7 +2347,14 @@ var createBroadcastsCollection = (pluginConfig) => {
2330
2347
  }
2331
2348
  if (JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content)) {
2332
2349
  const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
2350
+ const emailPreviewConfig = pluginConfig.customizations?.broadcasts?.emailPreview;
2333
2351
  updates.content = await convertToEmailSafeHtml(populatedContent, {
2352
+ wrapInTemplate: emailPreviewConfig?.wrapInTemplate ?? true,
2353
+ customWrapper: emailPreviewConfig?.customWrapper,
2354
+ preheader: doc.contentSection?.preheader,
2355
+ subject: doc.subject,
2356
+ documentData: doc,
2357
+ // Pass entire document
2334
2358
  customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
2335
2359
  });
2336
2360
  }