payload-plugin-newsletter 0.17.4 → 0.18.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.
- package/CHANGELOG.md +40 -0
- package/dist/collections.cjs +90 -5
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +90 -5
- package/dist/collections.js.map +1 -1
- package/dist/components.cjs.map +1 -1
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +90 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +90 -5
- package/dist/index.js.map +1 -1
- package/dist/types.d.cts +18 -0
- package/dist/types.d.ts +18 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4172,6 +4172,86 @@ var createTestBroadcastEndpoint = (config, collectionSlug) => {
|
|
|
4172
4172
|
};
|
|
4173
4173
|
|
|
4174
4174
|
// src/endpoints/broadcasts/preview.ts
|
|
4175
|
+
async function populateMediaFields(content, payload, config) {
|
|
4176
|
+
if (!content || typeof content !== "object") return content;
|
|
4177
|
+
if (content.root?.children) {
|
|
4178
|
+
for (const child of content.root.children) {
|
|
4179
|
+
await populateBlockMediaFields(child, payload, config);
|
|
4180
|
+
}
|
|
4181
|
+
}
|
|
4182
|
+
return content;
|
|
4183
|
+
}
|
|
4184
|
+
async function populateBlockMediaFields(node, payload, config) {
|
|
4185
|
+
if (node.type === "block" && node.fields) {
|
|
4186
|
+
const blockType = node.fields.blockType || node.fields.blockName;
|
|
4187
|
+
const customBlocks = config.customizations?.broadcasts?.customBlocks || [];
|
|
4188
|
+
const blockConfig = customBlocks.find((b) => b.slug === blockType);
|
|
4189
|
+
if (blockConfig && blockConfig.fields) {
|
|
4190
|
+
for (const field of blockConfig.fields) {
|
|
4191
|
+
if (field.type === "upload" && field.relationTo && node.fields[field.name]) {
|
|
4192
|
+
const fieldValue = node.fields[field.name];
|
|
4193
|
+
if (typeof fieldValue === "string" && fieldValue.match(/^[a-f0-9]{24}$/i)) {
|
|
4194
|
+
try {
|
|
4195
|
+
const media = await payload.findByID({
|
|
4196
|
+
collection: field.relationTo,
|
|
4197
|
+
id: fieldValue,
|
|
4198
|
+
depth: 0
|
|
4199
|
+
});
|
|
4200
|
+
if (media) {
|
|
4201
|
+
node.fields[field.name] = media;
|
|
4202
|
+
payload.logger?.info(`Populated ${field.name} for block ${blockType}:`, {
|
|
4203
|
+
mediaId: fieldValue,
|
|
4204
|
+
mediaUrl: media.url,
|
|
4205
|
+
filename: media.filename
|
|
4206
|
+
});
|
|
4207
|
+
}
|
|
4208
|
+
} catch (error) {
|
|
4209
|
+
payload.logger?.error(`Failed to populate ${field.name} for block ${blockType}:`, error);
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
}
|
|
4213
|
+
if (field.type === "array" && field.fields) {
|
|
4214
|
+
const arrayValue = node.fields[field.name];
|
|
4215
|
+
if (Array.isArray(arrayValue)) {
|
|
4216
|
+
for (const arrayItem of arrayValue) {
|
|
4217
|
+
if (arrayItem && typeof arrayItem === "object") {
|
|
4218
|
+
for (const arrayField of field.fields) {
|
|
4219
|
+
if (arrayField.type === "upload" && arrayField.relationTo && arrayItem[arrayField.name]) {
|
|
4220
|
+
const arrayFieldValue = arrayItem[arrayField.name];
|
|
4221
|
+
if (typeof arrayFieldValue === "string" && arrayFieldValue.match(/^[a-f0-9]{24}$/i)) {
|
|
4222
|
+
try {
|
|
4223
|
+
const media = await payload.findByID({
|
|
4224
|
+
collection: arrayField.relationTo,
|
|
4225
|
+
id: arrayFieldValue,
|
|
4226
|
+
depth: 0
|
|
4227
|
+
});
|
|
4228
|
+
if (media) {
|
|
4229
|
+
arrayItem[arrayField.name] = media;
|
|
4230
|
+
payload.logger?.info(`Populated array ${arrayField.name} for block ${blockType}:`, {
|
|
4231
|
+
mediaId: arrayFieldValue,
|
|
4232
|
+
mediaUrl: media.url,
|
|
4233
|
+
filename: media.filename
|
|
4234
|
+
});
|
|
4235
|
+
}
|
|
4236
|
+
} catch (error) {
|
|
4237
|
+
payload.logger?.error(`Failed to populate array ${arrayField.name} for block ${blockType}:`, error);
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4247
|
+
}
|
|
4248
|
+
}
|
|
4249
|
+
if (node.children) {
|
|
4250
|
+
for (const child of node.children) {
|
|
4251
|
+
await populateBlockMediaFields(child, payload, config);
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
}
|
|
4175
4255
|
var createBroadcastPreviewEndpoint = (config, _collectionSlug) => {
|
|
4176
4256
|
return {
|
|
4177
4257
|
path: "/preview",
|
|
@@ -4187,7 +4267,9 @@ var createBroadcastPreviewEndpoint = (config, _collectionSlug) => {
|
|
|
4187
4267
|
}, { status: 400 });
|
|
4188
4268
|
}
|
|
4189
4269
|
const mediaUrl = req.payload.config.serverURL ? `${req.payload.config.serverURL}/api/media` : "/api/media";
|
|
4190
|
-
|
|
4270
|
+
req.payload.logger?.info("Populating media fields for email preview...");
|
|
4271
|
+
const populatedContent = await populateMediaFields(content, req.payload, config);
|
|
4272
|
+
const htmlContent = await convertToEmailSafeHtml(populatedContent, {
|
|
4191
4273
|
wrapInTemplate: true,
|
|
4192
4274
|
preheader,
|
|
4193
4275
|
mediaUrl,
|
|
@@ -4486,8 +4568,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4486
4568
|
}
|
|
4487
4569
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
4488
4570
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
4489
|
-
req.payload.logger.info("
|
|
4490
|
-
const
|
|
4571
|
+
req.payload.logger.info("Populating media fields and converting content to HTML...");
|
|
4572
|
+
const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
|
|
4573
|
+
const htmlContent = await convertToEmailSafeHtml(populatedContent, {
|
|
4491
4574
|
customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
|
|
4492
4575
|
});
|
|
4493
4576
|
if (!htmlContent || htmlContent.trim() === "") {
|
|
@@ -4586,7 +4669,8 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4586
4669
|
return doc;
|
|
4587
4670
|
}
|
|
4588
4671
|
req.payload.logger.info("Creating broadcast in provider (deferred from initial create)...");
|
|
4589
|
-
const
|
|
4672
|
+
const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
|
|
4673
|
+
const htmlContent = await convertToEmailSafeHtml(populatedContent, {
|
|
4590
4674
|
customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
|
|
4591
4675
|
});
|
|
4592
4676
|
if (!htmlContent || htmlContent.trim() === "") {
|
|
@@ -4647,7 +4731,8 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4647
4731
|
updates.preheader = doc.contentSection?.preheader;
|
|
4648
4732
|
}
|
|
4649
4733
|
if (JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content)) {
|
|
4650
|
-
|
|
4734
|
+
const populatedContent = await populateMediaFields(doc.contentSection?.content, req.payload, pluginConfig);
|
|
4735
|
+
updates.content = await convertToEmailSafeHtml(populatedContent, {
|
|
4651
4736
|
customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
|
|
4652
4737
|
});
|
|
4653
4738
|
}
|