payload-plugin-newsletter 0.25.12 → 0.25.13
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 +6 -0
- package/dist/server.d.ts +93 -2
- package/dist/server.js +26 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Field, Block, RichTextField, Config, Endpoint, CollectionConfig, GlobalConfig } from 'payload';
|
|
1
|
+
import { Field, Block, RichTextField, Payload, Config, Endpoint, CollectionConfig, GlobalConfig } from 'payload';
|
|
2
|
+
import { SerializedEditorState } from 'lexical';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Core types for broadcast management functionality
|
|
@@ -632,6 +633,96 @@ interface SurveyQuestion {
|
|
|
632
633
|
required?: boolean;
|
|
633
634
|
}
|
|
634
635
|
|
|
636
|
+
/**
|
|
637
|
+
* Recursively populates media fields in Lexical content.
|
|
638
|
+
* Resolves Media IDs to full media objects with URLs.
|
|
639
|
+
*
|
|
640
|
+
* @param content - Lexical editor state content
|
|
641
|
+
* @param payload - Payload instance for database queries
|
|
642
|
+
* @param config - Newsletter plugin configuration
|
|
643
|
+
* @returns Populated content with resolved media objects
|
|
644
|
+
*/
|
|
645
|
+
declare function populateMediaFields(content: unknown, payload: Payload, config: NewsletterPluginConfig): Promise<unknown>;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Options for generating broadcast preview HTML
|
|
649
|
+
*/
|
|
650
|
+
interface PreviewOptions {
|
|
651
|
+
/** Email subject line */
|
|
652
|
+
subject: string;
|
|
653
|
+
/** Email preheader text (preview text in inbox) */
|
|
654
|
+
preheader?: string;
|
|
655
|
+
/** Whether to wrap content in email template (default: true) */
|
|
656
|
+
wrapInTemplate?: boolean;
|
|
657
|
+
/** Base URL for media files (optional, derived from payload.config.serverURL if not provided) */
|
|
658
|
+
mediaUrl?: string;
|
|
659
|
+
/** Additional document data to pass to custom wrapper */
|
|
660
|
+
documentData?: Record<string, unknown>;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Result from preview generation
|
|
664
|
+
*/
|
|
665
|
+
interface PreviewResult {
|
|
666
|
+
/** Generated HTML content */
|
|
667
|
+
html: string;
|
|
668
|
+
/** Subject line used */
|
|
669
|
+
subject: string;
|
|
670
|
+
/** Preheader text used (null if not provided) */
|
|
671
|
+
preheader: string | null;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Generates preview HTML from broadcast content.
|
|
675
|
+
*
|
|
676
|
+
* This utility handles the full preview generation pipeline:
|
|
677
|
+
* 1. Populates media fields (resolves Media IDs to full objects with URLs)
|
|
678
|
+
* 2. Converts Lexical content to email-safe HTML
|
|
679
|
+
* 3. Optionally wraps in email template
|
|
680
|
+
*
|
|
681
|
+
* @param content - Lexical editor state content from broadcast
|
|
682
|
+
* @param payload - Payload instance for database queries
|
|
683
|
+
* @param config - Newsletter plugin configuration
|
|
684
|
+
* @param options - Preview generation options
|
|
685
|
+
* @returns Preview result with HTML, subject, and preheader
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```typescript
|
|
689
|
+
* import { generateBroadcastPreviewHtml } from 'payload-plugin-newsletter'
|
|
690
|
+
*
|
|
691
|
+
* const preview = await generateBroadcastPreviewHtml(
|
|
692
|
+
* broadcast.content,
|
|
693
|
+
* payload,
|
|
694
|
+
* pluginConfig,
|
|
695
|
+
* {
|
|
696
|
+
* subject: broadcast.subject,
|
|
697
|
+
* preheader: broadcast.preheader,
|
|
698
|
+
* wrapInTemplate: true,
|
|
699
|
+
* }
|
|
700
|
+
* )
|
|
701
|
+
*
|
|
702
|
+
* // preview.html contains the rendered email HTML
|
|
703
|
+
* ```
|
|
704
|
+
*/
|
|
705
|
+
declare function generateBroadcastPreviewHtml(content: SerializedEditorState | null | undefined, payload: Payload, config: NewsletterPluginConfig, options: PreviewOptions): Promise<PreviewResult>;
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Converts Lexical editor state to email-safe HTML
|
|
709
|
+
*/
|
|
710
|
+
declare function convertToEmailSafeHtml(editorState: SerializedEditorState | undefined | null, options?: {
|
|
711
|
+
wrapInTemplate?: boolean;
|
|
712
|
+
preheader?: string;
|
|
713
|
+
mediaUrl?: string;
|
|
714
|
+
customBlockConverter?: (node: any, mediaUrl?: string) => Promise<string>;
|
|
715
|
+
payload?: any;
|
|
716
|
+
populateFields?: string[] | ((blockType: string) => string[]);
|
|
717
|
+
customWrapper?: (content: string, options?: {
|
|
718
|
+
preheader?: string;
|
|
719
|
+
subject?: string;
|
|
720
|
+
documentData?: Record<string, any>;
|
|
721
|
+
}) => string | Promise<string>;
|
|
722
|
+
subject?: string;
|
|
723
|
+
documentData?: Record<string, any>;
|
|
724
|
+
}): Promise<string>;
|
|
725
|
+
|
|
635
726
|
declare module 'payload' {
|
|
636
727
|
interface BasePayload {
|
|
637
728
|
newsletterEmailService?: any;
|
|
@@ -710,4 +801,4 @@ declare class BroadcastProvider implements EmailProvider {
|
|
|
710
801
|
removeContact(email: string): Promise<void>;
|
|
711
802
|
}
|
|
712
803
|
|
|
713
|
-
export { BroadcastProvider, type NewsletterPluginConfig, ResendProvider, type Subscriber, createBroadcastsCollection, createNewsletterSettingsGlobal, createPreferencesEndpoint, createSubscribeEndpoint, createSubscribersCollection, createUnsubscribeEndpoint, createVerifyMagicLinkEndpoint, newsletterPlugin };
|
|
804
|
+
export { BroadcastProvider, type NewsletterPluginConfig, type PreviewOptions, type PreviewResult, ResendProvider, type Subscriber, convertToEmailSafeHtml, createBroadcastsCollection, createNewsletterSettingsGlobal, createPreferencesEndpoint, createSubscribeEndpoint, createSubscribersCollection, createUnsubscribeEndpoint, createVerifyMagicLinkEndpoint, generateBroadcastPreviewHtml, newsletterPlugin, populateMediaFields };
|
package/dist/server.js
CHANGED
|
@@ -5289,6 +5289,28 @@ var setPluginConfig = (config) => {
|
|
|
5289
5289
|
// src/utilities/session.ts
|
|
5290
5290
|
import jwt2 from "jsonwebtoken";
|
|
5291
5291
|
|
|
5292
|
+
// src/utils/preview.ts
|
|
5293
|
+
async function generateBroadcastPreviewHtml(content, payload, config, options) {
|
|
5294
|
+
const mediaUrl = options.mediaUrl ?? (payload.config.serverURL ? `${payload.config.serverURL}/api/media` : "/api/media");
|
|
5295
|
+
const emailPreviewConfig = config.customizations?.broadcasts?.emailPreview;
|
|
5296
|
+
payload.logger?.info("Populating media fields for preview generation...");
|
|
5297
|
+
const populatedContent = await populateMediaFields(content, payload, config);
|
|
5298
|
+
const html = await convertToEmailSafeHtml(populatedContent, {
|
|
5299
|
+
wrapInTemplate: options.wrapInTemplate ?? emailPreviewConfig?.wrapInTemplate ?? true,
|
|
5300
|
+
preheader: options.preheader,
|
|
5301
|
+
subject: options.subject,
|
|
5302
|
+
mediaUrl,
|
|
5303
|
+
documentData: options.documentData,
|
|
5304
|
+
customBlockConverter: config.customizations?.broadcasts?.customBlockConverter,
|
|
5305
|
+
customWrapper: emailPreviewConfig?.customWrapper
|
|
5306
|
+
});
|
|
5307
|
+
return {
|
|
5308
|
+
html,
|
|
5309
|
+
subject: options.subject,
|
|
5310
|
+
preheader: options.preheader ?? null
|
|
5311
|
+
};
|
|
5312
|
+
}
|
|
5313
|
+
|
|
5292
5314
|
// src/index.ts
|
|
5293
5315
|
var newsletterPlugin = (pluginConfig) => (incomingConfig) => {
|
|
5294
5316
|
const config = {
|
|
@@ -5443,6 +5465,7 @@ var newsletterPlugin = (pluginConfig) => (incomingConfig) => {
|
|
|
5443
5465
|
export {
|
|
5444
5466
|
BroadcastProvider,
|
|
5445
5467
|
ResendProvider,
|
|
5468
|
+
convertToEmailSafeHtml,
|
|
5446
5469
|
createBroadcastsCollection,
|
|
5447
5470
|
createNewsletterSettingsGlobal,
|
|
5448
5471
|
createPreferencesEndpoint,
|
|
@@ -5450,5 +5473,7 @@ export {
|
|
|
5450
5473
|
createSubscribersCollection,
|
|
5451
5474
|
createUnsubscribeEndpoint,
|
|
5452
5475
|
createVerifyMagicLinkEndpoint,
|
|
5453
|
-
|
|
5476
|
+
generateBroadcastPreviewHtml,
|
|
5477
|
+
newsletterPlugin,
|
|
5478
|
+
populateMediaFields
|
|
5454
5479
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload-plugin-newsletter",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.13",
|
|
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",
|