payload-plugin-newsletter 0.25.11 → 0.25.12

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/server.js CHANGED
@@ -4289,25 +4289,28 @@ var createTestBroadcastEndpoint = (config, collectionSlug) => {
4289
4289
  };
4290
4290
  };
4291
4291
 
4292
- // src/endpoints/broadcasts/preview.ts
4292
+ // src/utils/mediaPopulation.ts
4293
4293
  async function populateMediaFields(content, payload, config) {
4294
4294
  if (!content || typeof content !== "object") return content;
4295
- if (content.root?.children) {
4296
- for (const child of content.root.children) {
4295
+ const typedContent = content;
4296
+ if (typedContent.root?.children) {
4297
+ for (const child of typedContent.root.children) {
4297
4298
  await populateBlockMediaFields(child, payload, config);
4298
4299
  }
4299
4300
  }
4300
4301
  return content;
4301
4302
  }
4302
4303
  async function populateBlockMediaFields(node, payload, config) {
4303
- if (node.type === "block" && node.fields) {
4304
- const blockType = node.fields.blockType || node.fields.blockName;
4304
+ if (!node || typeof node !== "object") return;
4305
+ const typedNode = node;
4306
+ if (typedNode.type === "block" && typedNode.fields) {
4307
+ const blockType = typedNode.fields.blockType || typedNode.fields.blockName;
4305
4308
  const customBlocks = config.customizations?.broadcasts?.customBlocks || [];
4306
4309
  const blockConfig = customBlocks.find((b) => b.slug === blockType);
4307
4310
  if (blockConfig && blockConfig.fields) {
4308
4311
  for (const field of blockConfig.fields) {
4309
- if (field.type === "upload" && field.relationTo && node.fields[field.name]) {
4310
- const fieldValue = node.fields[field.name];
4312
+ if (field.type === "upload" && field.relationTo && typedNode.fields[field.name]) {
4313
+ const fieldValue = typedNode.fields[field.name];
4311
4314
  const collectionName = Array.isArray(field.relationTo) ? field.relationTo[0] : field.relationTo;
4312
4315
  if (typeof fieldValue === "string" && fieldValue.match(/^[a-f0-9]{24}$/i)) {
4313
4316
  try {
@@ -4317,26 +4320,33 @@ async function populateBlockMediaFields(node, payload, config) {
4317
4320
  depth: 0
4318
4321
  });
4319
4322
  if (media) {
4320
- node.fields[field.name] = media;
4321
- payload.logger?.info({
4322
- mediaId: fieldValue,
4323
- mediaUrl: media.url,
4324
- filename: media.filename
4325
- }, `Populated ${field.name} for block ${blockType}`);
4323
+ typedNode.fields[field.name] = media;
4324
+ payload.logger?.info(
4325
+ {
4326
+ mediaId: fieldValue,
4327
+ mediaUrl: media.url,
4328
+ filename: media.filename
4329
+ },
4330
+ `Populated ${field.name} for block ${blockType}`
4331
+ );
4326
4332
  }
4327
4333
  } catch (error) {
4328
- payload.logger?.error({ error: String(error) }, `Failed to populate ${field.name} for block ${blockType}`);
4334
+ payload.logger?.error(
4335
+ { error: String(error) },
4336
+ `Failed to populate ${field.name} for block ${blockType}`
4337
+ );
4329
4338
  }
4330
4339
  }
4331
4340
  }
4332
4341
  if (field.type === "array" && field.fields) {
4333
- const arrayValue = node.fields[field.name];
4342
+ const arrayValue = typedNode.fields[field.name];
4334
4343
  if (Array.isArray(arrayValue)) {
4335
4344
  for (const arrayItem of arrayValue) {
4336
4345
  if (arrayItem && typeof arrayItem === "object") {
4346
+ const typedArrayItem = arrayItem;
4337
4347
  for (const arrayField of field.fields) {
4338
- if (arrayField.type === "upload" && arrayField.relationTo && arrayItem[arrayField.name]) {
4339
- const arrayFieldValue = arrayItem[arrayField.name];
4348
+ if (arrayField.type === "upload" && arrayField.relationTo && typedArrayItem[arrayField.name]) {
4349
+ const arrayFieldValue = typedArrayItem[arrayField.name];
4340
4350
  const arrayCollectionName = Array.isArray(arrayField.relationTo) ? arrayField.relationTo[0] : arrayField.relationTo;
4341
4351
  if (typeof arrayFieldValue === "string" && arrayFieldValue.match(/^[a-f0-9]{24}$/i)) {
4342
4352
  try {
@@ -4346,15 +4356,21 @@ async function populateBlockMediaFields(node, payload, config) {
4346
4356
  depth: 0
4347
4357
  });
4348
4358
  if (media) {
4349
- arrayItem[arrayField.name] = media;
4350
- payload.logger?.info({
4351
- mediaId: arrayFieldValue,
4352
- mediaUrl: media.url,
4353
- filename: media.filename
4354
- }, `Populated array ${arrayField.name} for block ${blockType}`);
4359
+ typedArrayItem[arrayField.name] = media;
4360
+ payload.logger?.info(
4361
+ {
4362
+ mediaId: arrayFieldValue,
4363
+ mediaUrl: media.url,
4364
+ filename: media.filename
4365
+ },
4366
+ `Populated array ${arrayField.name} for block ${blockType}`
4367
+ );
4355
4368
  }
4356
4369
  } catch (error) {
4357
- payload.logger?.error({ error: String(error) }, `Failed to populate array ${arrayField.name} for block ${blockType}`);
4370
+ payload.logger?.error(
4371
+ { error: String(error) },
4372
+ `Failed to populate array ${arrayField.name} for block ${blockType}`
4373
+ );
4358
4374
  }
4359
4375
  }
4360
4376
  }
@@ -4363,23 +4379,24 @@ async function populateBlockMediaFields(node, payload, config) {
4363
4379
  }
4364
4380
  }
4365
4381
  }
4366
- if (field.type === "richText" && node.fields[field.name]) {
4367
- await populateRichTextUploads(node.fields[field.name], payload);
4382
+ if (field.type === "richText" && typedNode.fields[field.name]) {
4383
+ await populateRichTextUploads(typedNode.fields[field.name], payload);
4368
4384
  payload.logger?.info(`Processed rich text field ${field.name} for upload nodes`);
4369
4385
  }
4370
4386
  }
4371
4387
  }
4372
4388
  }
4373
- if (node.children) {
4374
- for (const child of node.children) {
4389
+ if (typedNode.children) {
4390
+ for (const child of typedNode.children) {
4375
4391
  await populateBlockMediaFields(child, payload, config);
4376
4392
  }
4377
4393
  }
4378
4394
  }
4379
4395
  async function populateRichTextUploads(content, payload) {
4380
4396
  if (!content || typeof content !== "object") return;
4381
- if (content.root?.children) {
4382
- await processNodeArray(content.root.children);
4397
+ const typedContent = content;
4398
+ if (typedContent.root?.children) {
4399
+ await processNodeArray(typedContent.root.children);
4383
4400
  }
4384
4401
  if (Array.isArray(content)) {
4385
4402
  await processNodeArray(content);
@@ -4389,33 +4406,42 @@ async function populateRichTextUploads(content, payload) {
4389
4406
  }
4390
4407
  async function processNode(node) {
4391
4408
  if (!node || typeof node !== "object") return;
4392
- if (node.type === "upload" && node.relationTo === "media" && typeof node.value === "string" && node.value.match(/^[a-f0-9]{24}$/i)) {
4409
+ const typedNode = node;
4410
+ if (typedNode.type === "upload" && typedNode.relationTo === "media" && typeof typedNode.value === "string" && typedNode.value.match(/^[a-f0-9]{24}$/i)) {
4393
4411
  try {
4394
4412
  const media = await payload.findByID({
4395
4413
  collection: "media",
4396
- id: node.value,
4414
+ id: typedNode.value,
4397
4415
  depth: 0
4398
4416
  });
4399
4417
  if (media) {
4400
- node.value = media;
4401
- payload.logger?.info({
4402
- mediaId: node.value,
4403
- mediaUrl: media.url,
4404
- filename: media.filename
4405
- }, "Populated rich text upload node");
4418
+ typedNode.value = media;
4419
+ payload.logger?.info(
4420
+ {
4421
+ mediaId: typedNode.value,
4422
+ mediaUrl: media.url,
4423
+ filename: media.filename
4424
+ },
4425
+ "Populated rich text upload node"
4426
+ );
4406
4427
  }
4407
4428
  } catch (error) {
4408
- payload.logger?.error({ error: String(error) }, `Failed to populate rich text upload ${node.value}`);
4429
+ payload.logger?.error(
4430
+ { error: String(error) },
4431
+ `Failed to populate rich text upload ${typedNode.value}`
4432
+ );
4409
4433
  }
4410
4434
  }
4411
- if (node.children && Array.isArray(node.children)) {
4412
- await processNodeArray(node.children);
4435
+ if (typedNode.children && Array.isArray(typedNode.children)) {
4436
+ await processNodeArray(typedNode.children);
4413
4437
  }
4414
- if (node.root?.children && Array.isArray(node.root.children)) {
4415
- await processNodeArray(node.root.children);
4438
+ if (typedNode.root?.children && Array.isArray(typedNode.root.children)) {
4439
+ await processNodeArray(typedNode.root.children);
4416
4440
  }
4417
4441
  }
4418
4442
  }
4443
+
4444
+ // src/endpoints/broadcasts/preview.ts
4419
4445
  var createBroadcastPreviewEndpoint = (config, _collectionSlug) => {
4420
4446
  return {
4421
4447
  path: "/preview",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-plugin-newsletter",
3
- "version": "0.25.11",
3
+ "version": "0.25.12",
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",