payload-plugin-newsletter 0.19.0 → 0.20.1

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
@@ -559,12 +559,15 @@ var init_broadcast2 = __esm({
559
559
  // src/index.ts
560
560
  var src_exports = {};
561
561
  __export(src_exports, {
562
+ PluginConfigProvider: () => PluginConfigProvider,
562
563
  default: () => newsletterPlugin,
563
564
  getServerSideAuth: () => getServerSideAuth,
564
565
  getTokenFromRequest: () => getTokenFromRequest,
565
566
  isAuthenticated: () => isAuthenticated,
566
567
  newsletterPlugin: () => newsletterPlugin,
567
568
  requireAuth: () => requireAuth,
569
+ usePluginConfig: () => usePluginConfig,
570
+ usePluginConfigOptional: () => usePluginConfigOptional,
568
571
  verifyToken: () => verifyToken
569
572
  });
570
573
  module.exports = __toCommonJS(src_exports);
@@ -3584,6 +3587,12 @@ async function convertToEmailSafeHtml(editorState, options) {
3584
3587
  const rawHtml = await lexicalToEmailHtml(editorState, options?.mediaUrl, options?.customBlockConverter);
3585
3588
  const sanitizedHtml = import_isomorphic_dompurify2.default.sanitize(rawHtml, EMAIL_SAFE_CONFIG);
3586
3589
  if (options?.wrapInTemplate) {
3590
+ if (options.customWrapper) {
3591
+ return await Promise.resolve(options.customWrapper(sanitizedHtml, {
3592
+ preheader: options.preheader,
3593
+ subject: options.subject
3594
+ }));
3595
+ }
3587
3596
  return wrapInEmailTemplate(sanitizedHtml, options.preheader);
3588
3597
  }
3589
3598
  return sanitizedHtml;
@@ -4417,11 +4426,14 @@ var createBroadcastPreviewEndpoint = (config, _collectionSlug) => {
4417
4426
  const mediaUrl = req.payload.config.serverURL ? `${req.payload.config.serverURL}/api/media` : "/api/media";
4418
4427
  req.payload.logger?.info("Populating media fields for email preview...");
4419
4428
  const populatedContent = await populateMediaFields(content, req.payload, config);
4429
+ const emailPreviewConfig = config.customizations?.broadcasts?.emailPreview;
4420
4430
  const htmlContent = await convertToEmailSafeHtml(populatedContent, {
4421
- wrapInTemplate: true,
4431
+ wrapInTemplate: emailPreviewConfig?.wrapInTemplate ?? true,
4422
4432
  preheader,
4433
+ subject,
4423
4434
  mediaUrl,
4424
- customBlockConverter: config.customizations?.broadcasts?.customBlockConverter
4435
+ customBlockConverter: config.customizations?.broadcasts?.customBlockConverter,
4436
+ customWrapper: emailPreviewConfig?.customWrapper
4425
4437
  });
4426
4438
  return Response.json({
4427
4439
  success: true,
@@ -5325,6 +5337,24 @@ var isAuthenticated = (req, secret) => {
5325
5337
  return !!decoded;
5326
5338
  };
5327
5339
 
5340
+ // src/contexts/PluginConfigContext.tsx
5341
+ var import_react = require("react");
5342
+ var import_jsx_runtime5 = require("react/jsx-runtime");
5343
+ var PluginConfigContext = (0, import_react.createContext)(null);
5344
+ var PluginConfigProvider = ({ config, children }) => {
5345
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PluginConfigContext.Provider, { value: config, children });
5346
+ };
5347
+ var usePluginConfig = () => {
5348
+ const config = (0, import_react.useContext)(PluginConfigContext);
5349
+ if (!config) {
5350
+ throw new Error("usePluginConfig must be used within PluginConfigProvider");
5351
+ }
5352
+ return config;
5353
+ };
5354
+ var usePluginConfigOptional = () => {
5355
+ return (0, import_react.useContext)(PluginConfigContext);
5356
+ };
5357
+
5328
5358
  // src/index.ts
5329
5359
  var newsletterPlugin = (pluginConfig) => (incomingConfig) => {
5330
5360
  const config = {
@@ -5502,11 +5532,14 @@ var newsletterPlugin = (pluginConfig) => (incomingConfig) => {
5502
5532
  };
5503
5533
  // Annotate the CommonJS export names for ESM import in node:
5504
5534
  0 && (module.exports = {
5535
+ PluginConfigProvider,
5505
5536
  getServerSideAuth,
5506
5537
  getTokenFromRequest,
5507
5538
  isAuthenticated,
5508
5539
  newsletterPlugin,
5509
5540
  requireAuth,
5541
+ usePluginConfig,
5542
+ usePluginConfigOptional,
5510
5543
  verifyToken
5511
5544
  });
5512
5545
  //# sourceMappingURL=index.cjs.map