payload-plugin-newsletter 0.25.11 → 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 +21 -0
- package/dist/collections.cjs +69 -43
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +69 -43
- package/dist/collections.js.map +1 -1
- package/dist/server.d.ts +93 -2
- package/dist/server.js +95 -44
- package/package.json +1 -1
package/dist/collections.js
CHANGED
|
@@ -1745,25 +1745,28 @@ var createTestBroadcastEndpoint = (config, collectionSlug) => {
|
|
|
1745
1745
|
};
|
|
1746
1746
|
};
|
|
1747
1747
|
|
|
1748
|
-
// src/
|
|
1748
|
+
// src/utils/mediaPopulation.ts
|
|
1749
1749
|
async function populateMediaFields(content, payload, config) {
|
|
1750
1750
|
if (!content || typeof content !== "object") return content;
|
|
1751
|
-
|
|
1752
|
-
|
|
1751
|
+
const typedContent = content;
|
|
1752
|
+
if (typedContent.root?.children) {
|
|
1753
|
+
for (const child of typedContent.root.children) {
|
|
1753
1754
|
await populateBlockMediaFields(child, payload, config);
|
|
1754
1755
|
}
|
|
1755
1756
|
}
|
|
1756
1757
|
return content;
|
|
1757
1758
|
}
|
|
1758
1759
|
async function populateBlockMediaFields(node, payload, config) {
|
|
1759
|
-
if (node
|
|
1760
|
-
|
|
1760
|
+
if (!node || typeof node !== "object") return;
|
|
1761
|
+
const typedNode = node;
|
|
1762
|
+
if (typedNode.type === "block" && typedNode.fields) {
|
|
1763
|
+
const blockType = typedNode.fields.blockType || typedNode.fields.blockName;
|
|
1761
1764
|
const customBlocks = config.customizations?.broadcasts?.customBlocks || [];
|
|
1762
1765
|
const blockConfig = customBlocks.find((b) => b.slug === blockType);
|
|
1763
1766
|
if (blockConfig && blockConfig.fields) {
|
|
1764
1767
|
for (const field of blockConfig.fields) {
|
|
1765
|
-
if (field.type === "upload" && field.relationTo &&
|
|
1766
|
-
const fieldValue =
|
|
1768
|
+
if (field.type === "upload" && field.relationTo && typedNode.fields[field.name]) {
|
|
1769
|
+
const fieldValue = typedNode.fields[field.name];
|
|
1767
1770
|
const collectionName = Array.isArray(field.relationTo) ? field.relationTo[0] : field.relationTo;
|
|
1768
1771
|
if (typeof fieldValue === "string" && fieldValue.match(/^[a-f0-9]{24}$/i)) {
|
|
1769
1772
|
try {
|
|
@@ -1773,26 +1776,33 @@ async function populateBlockMediaFields(node, payload, config) {
|
|
|
1773
1776
|
depth: 0
|
|
1774
1777
|
});
|
|
1775
1778
|
if (media) {
|
|
1776
|
-
|
|
1777
|
-
payload.logger?.info(
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1779
|
+
typedNode.fields[field.name] = media;
|
|
1780
|
+
payload.logger?.info(
|
|
1781
|
+
{
|
|
1782
|
+
mediaId: fieldValue,
|
|
1783
|
+
mediaUrl: media.url,
|
|
1784
|
+
filename: media.filename
|
|
1785
|
+
},
|
|
1786
|
+
`Populated ${field.name} for block ${blockType}`
|
|
1787
|
+
);
|
|
1782
1788
|
}
|
|
1783
1789
|
} catch (error) {
|
|
1784
|
-
payload.logger?.error(
|
|
1790
|
+
payload.logger?.error(
|
|
1791
|
+
{ error: String(error) },
|
|
1792
|
+
`Failed to populate ${field.name} for block ${blockType}`
|
|
1793
|
+
);
|
|
1785
1794
|
}
|
|
1786
1795
|
}
|
|
1787
1796
|
}
|
|
1788
1797
|
if (field.type === "array" && field.fields) {
|
|
1789
|
-
const arrayValue =
|
|
1798
|
+
const arrayValue = typedNode.fields[field.name];
|
|
1790
1799
|
if (Array.isArray(arrayValue)) {
|
|
1791
1800
|
for (const arrayItem of arrayValue) {
|
|
1792
1801
|
if (arrayItem && typeof arrayItem === "object") {
|
|
1802
|
+
const typedArrayItem = arrayItem;
|
|
1793
1803
|
for (const arrayField of field.fields) {
|
|
1794
|
-
if (arrayField.type === "upload" && arrayField.relationTo &&
|
|
1795
|
-
const arrayFieldValue =
|
|
1804
|
+
if (arrayField.type === "upload" && arrayField.relationTo && typedArrayItem[arrayField.name]) {
|
|
1805
|
+
const arrayFieldValue = typedArrayItem[arrayField.name];
|
|
1796
1806
|
const arrayCollectionName = Array.isArray(arrayField.relationTo) ? arrayField.relationTo[0] : arrayField.relationTo;
|
|
1797
1807
|
if (typeof arrayFieldValue === "string" && arrayFieldValue.match(/^[a-f0-9]{24}$/i)) {
|
|
1798
1808
|
try {
|
|
@@ -1802,15 +1812,21 @@ async function populateBlockMediaFields(node, payload, config) {
|
|
|
1802
1812
|
depth: 0
|
|
1803
1813
|
});
|
|
1804
1814
|
if (media) {
|
|
1805
|
-
|
|
1806
|
-
payload.logger?.info(
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1815
|
+
typedArrayItem[arrayField.name] = media;
|
|
1816
|
+
payload.logger?.info(
|
|
1817
|
+
{
|
|
1818
|
+
mediaId: arrayFieldValue,
|
|
1819
|
+
mediaUrl: media.url,
|
|
1820
|
+
filename: media.filename
|
|
1821
|
+
},
|
|
1822
|
+
`Populated array ${arrayField.name} for block ${blockType}`
|
|
1823
|
+
);
|
|
1811
1824
|
}
|
|
1812
1825
|
} catch (error) {
|
|
1813
|
-
payload.logger?.error(
|
|
1826
|
+
payload.logger?.error(
|
|
1827
|
+
{ error: String(error) },
|
|
1828
|
+
`Failed to populate array ${arrayField.name} for block ${blockType}`
|
|
1829
|
+
);
|
|
1814
1830
|
}
|
|
1815
1831
|
}
|
|
1816
1832
|
}
|
|
@@ -1819,23 +1835,24 @@ async function populateBlockMediaFields(node, payload, config) {
|
|
|
1819
1835
|
}
|
|
1820
1836
|
}
|
|
1821
1837
|
}
|
|
1822
|
-
if (field.type === "richText" &&
|
|
1823
|
-
await populateRichTextUploads(
|
|
1838
|
+
if (field.type === "richText" && typedNode.fields[field.name]) {
|
|
1839
|
+
await populateRichTextUploads(typedNode.fields[field.name], payload);
|
|
1824
1840
|
payload.logger?.info(`Processed rich text field ${field.name} for upload nodes`);
|
|
1825
1841
|
}
|
|
1826
1842
|
}
|
|
1827
1843
|
}
|
|
1828
1844
|
}
|
|
1829
|
-
if (
|
|
1830
|
-
for (const child of
|
|
1845
|
+
if (typedNode.children) {
|
|
1846
|
+
for (const child of typedNode.children) {
|
|
1831
1847
|
await populateBlockMediaFields(child, payload, config);
|
|
1832
1848
|
}
|
|
1833
1849
|
}
|
|
1834
1850
|
}
|
|
1835
1851
|
async function populateRichTextUploads(content, payload) {
|
|
1836
1852
|
if (!content || typeof content !== "object") return;
|
|
1837
|
-
|
|
1838
|
-
|
|
1853
|
+
const typedContent = content;
|
|
1854
|
+
if (typedContent.root?.children) {
|
|
1855
|
+
await processNodeArray(typedContent.root.children);
|
|
1839
1856
|
}
|
|
1840
1857
|
if (Array.isArray(content)) {
|
|
1841
1858
|
await processNodeArray(content);
|
|
@@ -1845,33 +1862,42 @@ async function populateRichTextUploads(content, payload) {
|
|
|
1845
1862
|
}
|
|
1846
1863
|
async function processNode(node) {
|
|
1847
1864
|
if (!node || typeof node !== "object") return;
|
|
1848
|
-
|
|
1865
|
+
const typedNode = node;
|
|
1866
|
+
if (typedNode.type === "upload" && typedNode.relationTo === "media" && typeof typedNode.value === "string" && typedNode.value.match(/^[a-f0-9]{24}$/i)) {
|
|
1849
1867
|
try {
|
|
1850
1868
|
const media = await payload.findByID({
|
|
1851
1869
|
collection: "media",
|
|
1852
|
-
id:
|
|
1870
|
+
id: typedNode.value,
|
|
1853
1871
|
depth: 0
|
|
1854
1872
|
});
|
|
1855
1873
|
if (media) {
|
|
1856
|
-
|
|
1857
|
-
payload.logger?.info(
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1874
|
+
typedNode.value = media;
|
|
1875
|
+
payload.logger?.info(
|
|
1876
|
+
{
|
|
1877
|
+
mediaId: typedNode.value,
|
|
1878
|
+
mediaUrl: media.url,
|
|
1879
|
+
filename: media.filename
|
|
1880
|
+
},
|
|
1881
|
+
"Populated rich text upload node"
|
|
1882
|
+
);
|
|
1862
1883
|
}
|
|
1863
1884
|
} catch (error) {
|
|
1864
|
-
payload.logger?.error(
|
|
1885
|
+
payload.logger?.error(
|
|
1886
|
+
{ error: String(error) },
|
|
1887
|
+
`Failed to populate rich text upload ${typedNode.value}`
|
|
1888
|
+
);
|
|
1865
1889
|
}
|
|
1866
1890
|
}
|
|
1867
|
-
if (
|
|
1868
|
-
await processNodeArray(
|
|
1891
|
+
if (typedNode.children && Array.isArray(typedNode.children)) {
|
|
1892
|
+
await processNodeArray(typedNode.children);
|
|
1869
1893
|
}
|
|
1870
|
-
if (
|
|
1871
|
-
await processNodeArray(
|
|
1894
|
+
if (typedNode.root?.children && Array.isArray(typedNode.root.children)) {
|
|
1895
|
+
await processNodeArray(typedNode.root.children);
|
|
1872
1896
|
}
|
|
1873
1897
|
}
|
|
1874
1898
|
}
|
|
1899
|
+
|
|
1900
|
+
// src/endpoints/broadcasts/preview.ts
|
|
1875
1901
|
var createBroadcastPreviewEndpoint = (config, _collectionSlug) => {
|
|
1876
1902
|
return {
|
|
1877
1903
|
path: "/preview",
|