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/CHANGELOG.md +55 -0
- package/README.md +97 -0
- package/dist/collections.cjs +11 -2
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +11 -2
- package/dist/collections.js.map +1 -1
- package/dist/components.cjs +148 -125
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +2 -0
- package/dist/components.d.ts +2 -0
- package/dist/components.js +85 -62
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +35 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +32 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.cts +23 -0
- package/dist/types.d.ts +23 -0
- package/dist/utils.cjs +6 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +5 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/ESM_FIX_SUMMARY.md +0 -74
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PayloadRequest, Config } from 'payload';
|
|
2
|
-
import {
|
|
2
|
+
import { NewsletterPluginConfig, BroadcastProvider } from './types.cjs';
|
|
3
|
+
import React from 'react';
|
|
3
4
|
|
|
4
5
|
interface NextApiRequest {
|
|
5
6
|
cookies?: {
|
|
@@ -66,6 +67,17 @@ declare const requireAuth: <P extends {
|
|
|
66
67
|
*/
|
|
67
68
|
declare const isAuthenticated: (req: PayloadRequest | NextApiRequest, secret: string) => boolean;
|
|
68
69
|
|
|
70
|
+
declare const PluginConfigProvider: React.FC<{
|
|
71
|
+
config: NewsletterPluginConfig;
|
|
72
|
+
children: React.ReactNode;
|
|
73
|
+
}>;
|
|
74
|
+
declare const usePluginConfig: () => NewsletterPluginConfig;
|
|
75
|
+
/**
|
|
76
|
+
* Hook to safely access plugin config without throwing if context is not available
|
|
77
|
+
* This is useful for components that might be used outside of the plugin context
|
|
78
|
+
*/
|
|
79
|
+
declare const usePluginConfigOptional: () => NewsletterPluginConfig | null;
|
|
80
|
+
|
|
69
81
|
declare module 'payload' {
|
|
70
82
|
interface BasePayload {
|
|
71
83
|
newsletterEmailService?: any;
|
|
@@ -75,4 +87,4 @@ declare module 'payload' {
|
|
|
75
87
|
}
|
|
76
88
|
declare const newsletterPlugin: (pluginConfig: NewsletterPluginConfig) => (incomingConfig: Config) => Config;
|
|
77
89
|
|
|
78
|
-
export { newsletterPlugin as default, getServerSideAuth, getTokenFromRequest, isAuthenticated, newsletterPlugin, requireAuth, verifyToken };
|
|
90
|
+
export { PluginConfigProvider, newsletterPlugin as default, getServerSideAuth, getTokenFromRequest, isAuthenticated, newsletterPlugin, requireAuth, usePluginConfig, usePluginConfigOptional, verifyToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PayloadRequest, Config } from 'payload';
|
|
2
|
-
import {
|
|
2
|
+
import { NewsletterPluginConfig, BroadcastProvider } from './types.js';
|
|
3
|
+
import React from 'react';
|
|
3
4
|
|
|
4
5
|
interface NextApiRequest {
|
|
5
6
|
cookies?: {
|
|
@@ -66,6 +67,17 @@ declare const requireAuth: <P extends {
|
|
|
66
67
|
*/
|
|
67
68
|
declare const isAuthenticated: (req: PayloadRequest | NextApiRequest, secret: string) => boolean;
|
|
68
69
|
|
|
70
|
+
declare const PluginConfigProvider: React.FC<{
|
|
71
|
+
config: NewsletterPluginConfig;
|
|
72
|
+
children: React.ReactNode;
|
|
73
|
+
}>;
|
|
74
|
+
declare const usePluginConfig: () => NewsletterPluginConfig;
|
|
75
|
+
/**
|
|
76
|
+
* Hook to safely access plugin config without throwing if context is not available
|
|
77
|
+
* This is useful for components that might be used outside of the plugin context
|
|
78
|
+
*/
|
|
79
|
+
declare const usePluginConfigOptional: () => NewsletterPluginConfig | null;
|
|
80
|
+
|
|
69
81
|
declare module 'payload' {
|
|
70
82
|
interface BasePayload {
|
|
71
83
|
newsletterEmailService?: any;
|
|
@@ -75,4 +87,4 @@ declare module 'payload' {
|
|
|
75
87
|
}
|
|
76
88
|
declare const newsletterPlugin: (pluginConfig: NewsletterPluginConfig) => (incomingConfig: Config) => Config;
|
|
77
89
|
|
|
78
|
-
export { newsletterPlugin as default, getServerSideAuth, getTokenFromRequest, isAuthenticated, newsletterPlugin, requireAuth, verifyToken };
|
|
90
|
+
export { PluginConfigProvider, newsletterPlugin as default, getServerSideAuth, getTokenFromRequest, isAuthenticated, newsletterPlugin, requireAuth, usePluginConfig, usePluginConfigOptional, verifyToken };
|
package/dist/index.js
CHANGED
|
@@ -3584,6 +3584,12 @@ async function convertToEmailSafeHtml(editorState, options) {
|
|
|
3584
3584
|
const rawHtml = await lexicalToEmailHtml(editorState, options?.mediaUrl, options?.customBlockConverter);
|
|
3585
3585
|
const sanitizedHtml = DOMPurify2.sanitize(rawHtml, EMAIL_SAFE_CONFIG);
|
|
3586
3586
|
if (options?.wrapInTemplate) {
|
|
3587
|
+
if (options.customWrapper) {
|
|
3588
|
+
return await Promise.resolve(options.customWrapper(sanitizedHtml, {
|
|
3589
|
+
preheader: options.preheader,
|
|
3590
|
+
subject: options.subject
|
|
3591
|
+
}));
|
|
3592
|
+
}
|
|
3587
3593
|
return wrapInEmailTemplate(sanitizedHtml, options.preheader);
|
|
3588
3594
|
}
|
|
3589
3595
|
return sanitizedHtml;
|
|
@@ -4417,11 +4423,14 @@ var createBroadcastPreviewEndpoint = (config, _collectionSlug) => {
|
|
|
4417
4423
|
const mediaUrl = req.payload.config.serverURL ? `${req.payload.config.serverURL}/api/media` : "/api/media";
|
|
4418
4424
|
req.payload.logger?.info("Populating media fields for email preview...");
|
|
4419
4425
|
const populatedContent = await populateMediaFields(content, req.payload, config);
|
|
4426
|
+
const emailPreviewConfig = config.customizations?.broadcasts?.emailPreview;
|
|
4420
4427
|
const htmlContent = await convertToEmailSafeHtml(populatedContent, {
|
|
4421
|
-
wrapInTemplate: true,
|
|
4428
|
+
wrapInTemplate: emailPreviewConfig?.wrapInTemplate ?? true,
|
|
4422
4429
|
preheader,
|
|
4430
|
+
subject,
|
|
4423
4431
|
mediaUrl,
|
|
4424
|
-
customBlockConverter: config.customizations?.broadcasts?.customBlockConverter
|
|
4432
|
+
customBlockConverter: config.customizations?.broadcasts?.customBlockConverter,
|
|
4433
|
+
customWrapper: emailPreviewConfig?.customWrapper
|
|
4425
4434
|
});
|
|
4426
4435
|
return Response.json({
|
|
4427
4436
|
success: true,
|
|
@@ -5325,6 +5334,24 @@ var isAuthenticated = (req, secret) => {
|
|
|
5325
5334
|
return !!decoded;
|
|
5326
5335
|
};
|
|
5327
5336
|
|
|
5337
|
+
// src/contexts/PluginConfigContext.tsx
|
|
5338
|
+
import { createContext, useContext } from "react";
|
|
5339
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
5340
|
+
var PluginConfigContext = createContext(null);
|
|
5341
|
+
var PluginConfigProvider = ({ config, children }) => {
|
|
5342
|
+
return /* @__PURE__ */ jsx5(PluginConfigContext.Provider, { value: config, children });
|
|
5343
|
+
};
|
|
5344
|
+
var usePluginConfig = () => {
|
|
5345
|
+
const config = useContext(PluginConfigContext);
|
|
5346
|
+
if (!config) {
|
|
5347
|
+
throw new Error("usePluginConfig must be used within PluginConfigProvider");
|
|
5348
|
+
}
|
|
5349
|
+
return config;
|
|
5350
|
+
};
|
|
5351
|
+
var usePluginConfigOptional = () => {
|
|
5352
|
+
return useContext(PluginConfigContext);
|
|
5353
|
+
};
|
|
5354
|
+
|
|
5328
5355
|
// src/index.ts
|
|
5329
5356
|
var newsletterPlugin = (pluginConfig) => (incomingConfig) => {
|
|
5330
5357
|
const config = {
|
|
@@ -5501,12 +5528,15 @@ var newsletterPlugin = (pluginConfig) => (incomingConfig) => {
|
|
|
5501
5528
|
return modifiedConfig;
|
|
5502
5529
|
};
|
|
5503
5530
|
export {
|
|
5531
|
+
PluginConfigProvider,
|
|
5504
5532
|
newsletterPlugin as default,
|
|
5505
5533
|
getServerSideAuth,
|
|
5506
5534
|
getTokenFromRequest,
|
|
5507
5535
|
isAuthenticated,
|
|
5508
5536
|
newsletterPlugin,
|
|
5509
5537
|
requireAuth,
|
|
5538
|
+
usePluginConfig,
|
|
5539
|
+
usePluginConfigOptional,
|
|
5510
5540
|
verifyToken
|
|
5511
5541
|
};
|
|
5512
5542
|
//# sourceMappingURL=index.js.map
|