payload-plugin-newsletter 0.16.3 → 0.16.5
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 +41 -0
- package/dist/collections.cjs +46 -14
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +46 -14
- package/dist/collections.js.map +1 -1
- package/dist/index.cjs +50 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -18
- package/dist/index.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/plugin-api-key-recommendations.md +117 -0
package/dist/collections.js
CHANGED
|
@@ -269,9 +269,9 @@ var init_broadcast2 = __esm({
|
|
|
269
269
|
async update(id, data) {
|
|
270
270
|
try {
|
|
271
271
|
const existing = await this.get(id);
|
|
272
|
-
if (!this.canEditInStatus(existing.
|
|
272
|
+
if (!this.canEditInStatus(existing.sendStatus)) {
|
|
273
273
|
throw new BroadcastProviderError(
|
|
274
|
-
`Cannot update broadcast in status: ${existing.
|
|
274
|
+
`Cannot update broadcast in status: ${existing.sendStatus}`,
|
|
275
275
|
"INVALID_STATUS" /* INVALID_STATUS */,
|
|
276
276
|
this.name
|
|
277
277
|
);
|
|
@@ -314,9 +314,9 @@ var init_broadcast2 = __esm({
|
|
|
314
314
|
async delete(id) {
|
|
315
315
|
try {
|
|
316
316
|
const existing = await this.get(id);
|
|
317
|
-
if (!this.canEditInStatus(existing.
|
|
317
|
+
if (!this.canEditInStatus(existing.sendStatus)) {
|
|
318
318
|
throw new BroadcastProviderError(
|
|
319
|
-
`Cannot delete broadcast in status: ${existing.
|
|
319
|
+
`Cannot delete broadcast in status: ${existing.sendStatus}`,
|
|
320
320
|
"INVALID_STATUS" /* INVALID_STATUS */,
|
|
321
321
|
this.name
|
|
322
322
|
);
|
|
@@ -475,7 +475,7 @@ var init_broadcast2 = __esm({
|
|
|
475
475
|
subject: broadcast.subject,
|
|
476
476
|
preheader: broadcast.preheader,
|
|
477
477
|
content: broadcast.body,
|
|
478
|
-
|
|
478
|
+
sendStatus: this.mapBroadcastStatus(broadcast.status),
|
|
479
479
|
trackOpens: broadcast.track_opens,
|
|
480
480
|
trackClicks: broadcast.track_clicks,
|
|
481
481
|
replyTo: broadcast.reply_to,
|
|
@@ -1178,6 +1178,19 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1178
1178
|
const customizations = pluginConfig.customizations?.broadcasts;
|
|
1179
1179
|
return {
|
|
1180
1180
|
slug: "broadcasts",
|
|
1181
|
+
access: {
|
|
1182
|
+
read: () => true,
|
|
1183
|
+
// Public read access
|
|
1184
|
+
create: ({ req: { user } }) => {
|
|
1185
|
+
return Boolean(user);
|
|
1186
|
+
},
|
|
1187
|
+
update: ({ req: { user } }) => {
|
|
1188
|
+
return Boolean(user);
|
|
1189
|
+
},
|
|
1190
|
+
delete: ({ req: { user } }) => {
|
|
1191
|
+
return Boolean(user);
|
|
1192
|
+
}
|
|
1193
|
+
},
|
|
1181
1194
|
versions: {
|
|
1182
1195
|
drafts: {
|
|
1183
1196
|
autosave: true,
|
|
@@ -1191,7 +1204,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1191
1204
|
admin: {
|
|
1192
1205
|
useAsTitle: "subject",
|
|
1193
1206
|
description: "Individual email campaigns sent to subscribers",
|
|
1194
|
-
defaultColumns: ["subject", "_status", "
|
|
1207
|
+
defaultColumns: ["subject", "_status", "sendStatus", "sentAt", "recipientCount"]
|
|
1195
1208
|
},
|
|
1196
1209
|
fields: [
|
|
1197
1210
|
{
|
|
@@ -1251,8 +1264,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1251
1264
|
]
|
|
1252
1265
|
},
|
|
1253
1266
|
{
|
|
1254
|
-
name: "
|
|
1267
|
+
name: "sendStatus",
|
|
1255
1268
|
type: "select",
|
|
1269
|
+
label: "Send Status",
|
|
1256
1270
|
required: true,
|
|
1257
1271
|
defaultValue: "draft" /* DRAFT */,
|
|
1258
1272
|
options: [
|
|
@@ -1266,6 +1280,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1266
1280
|
],
|
|
1267
1281
|
admin: {
|
|
1268
1282
|
readOnly: true,
|
|
1283
|
+
description: "The status of the email send operation",
|
|
1269
1284
|
components: {
|
|
1270
1285
|
Cell: "payload-plugin-newsletter/components#StatusBadge"
|
|
1271
1286
|
}
|
|
@@ -1322,7 +1337,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1322
1337
|
type: "group",
|
|
1323
1338
|
admin: {
|
|
1324
1339
|
readOnly: true,
|
|
1325
|
-
condition: (data) => data?.
|
|
1340
|
+
condition: (data) => data?.sendStatus === "sent" /* SENT */
|
|
1326
1341
|
},
|
|
1327
1342
|
fields: [
|
|
1328
1343
|
{
|
|
@@ -1381,7 +1396,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1381
1396
|
name: "scheduledAt",
|
|
1382
1397
|
type: "date",
|
|
1383
1398
|
admin: {
|
|
1384
|
-
condition: (data) => data?.
|
|
1399
|
+
condition: (data) => data?.sendStatus === "scheduled" /* SCHEDULED */,
|
|
1385
1400
|
date: {
|
|
1386
1401
|
displayFormat: "MMM d, yyyy h:mm a"
|
|
1387
1402
|
}
|
|
@@ -1466,7 +1481,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1466
1481
|
const wasUnpublished = !previousDoc?._status || previousDoc._status === "draft";
|
|
1467
1482
|
const isNowPublished = doc._status === "published";
|
|
1468
1483
|
if (wasUnpublished && isNowPublished && doc.providerId) {
|
|
1469
|
-
if (doc.
|
|
1484
|
+
if (doc.sendStatus === "sent" /* SENT */ || doc.sendStatus === "sending" /* SENDING */) {
|
|
1470
1485
|
return doc;
|
|
1471
1486
|
}
|
|
1472
1487
|
try {
|
|
@@ -1485,7 +1500,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1485
1500
|
collection: "broadcasts",
|
|
1486
1501
|
id: doc.id,
|
|
1487
1502
|
data: {
|
|
1488
|
-
|
|
1503
|
+
sendStatus: "sending" /* SENDING */,
|
|
1489
1504
|
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1490
1505
|
},
|
|
1491
1506
|
req
|
|
@@ -1507,7 +1522,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1507
1522
|
collection: "broadcasts",
|
|
1508
1523
|
id: doc.id,
|
|
1509
1524
|
data: {
|
|
1510
|
-
|
|
1525
|
+
sendStatus: "failed" /* FAILED */
|
|
1511
1526
|
},
|
|
1512
1527
|
req
|
|
1513
1528
|
});
|
|
@@ -1520,6 +1535,14 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1520
1535
|
beforeChange: [
|
|
1521
1536
|
async ({ data, originalDoc, operation, req }) => {
|
|
1522
1537
|
if (!hasProviders || !originalDoc?.providerId || operation !== "update") return data;
|
|
1538
|
+
req.payload.logger.info("Broadcast beforeChange update hook triggered", {
|
|
1539
|
+
operation,
|
|
1540
|
+
hasProviderId: !!originalDoc?.providerId,
|
|
1541
|
+
originalSendStatus: originalDoc?.sendStatus,
|
|
1542
|
+
originalPublishStatus: originalDoc?._status,
|
|
1543
|
+
newSendStatus: data?.sendStatus,
|
|
1544
|
+
newPublishStatus: data?._status
|
|
1545
|
+
});
|
|
1523
1546
|
try {
|
|
1524
1547
|
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
1525
1548
|
if (!providerConfig || !providerConfig.token) {
|
|
@@ -1529,7 +1552,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1529
1552
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
1530
1553
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
1531
1554
|
const capabilities = provider.getCapabilities();
|
|
1532
|
-
|
|
1555
|
+
const sendStatus = originalDoc.sendStatus || "draft" /* DRAFT */;
|
|
1556
|
+
if (!capabilities.editableStatuses.includes(sendStatus)) {
|
|
1557
|
+
req.payload.logger.info(`Skipping sync for broadcast in status: ${sendStatus}`);
|
|
1533
1558
|
return data;
|
|
1534
1559
|
}
|
|
1535
1560
|
const updates = {};
|
|
@@ -1554,7 +1579,14 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1554
1579
|
updates.audienceIds = data.audienceIds?.map((a) => a.audienceId);
|
|
1555
1580
|
}
|
|
1556
1581
|
if (Object.keys(updates).length > 0) {
|
|
1582
|
+
req.payload.logger.info("Syncing broadcast updates to provider", {
|
|
1583
|
+
providerId: originalDoc.providerId,
|
|
1584
|
+
updates
|
|
1585
|
+
});
|
|
1557
1586
|
await provider.update(originalDoc.providerId, updates);
|
|
1587
|
+
req.payload.logger.info("Successfully synced broadcast updates to provider");
|
|
1588
|
+
} else {
|
|
1589
|
+
req.payload.logger.info("No broadcast updates to sync to provider");
|
|
1558
1590
|
}
|
|
1559
1591
|
} catch (error) {
|
|
1560
1592
|
if (error instanceof Error) {
|
|
@@ -1585,7 +1617,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
1585
1617
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
1586
1618
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
1587
1619
|
const capabilities = provider.getCapabilities();
|
|
1588
|
-
if (capabilities.editableStatuses.includes(doc.
|
|
1620
|
+
if (capabilities.editableStatuses.includes(doc.sendStatus)) {
|
|
1589
1621
|
await provider.delete(doc.providerId);
|
|
1590
1622
|
}
|
|
1591
1623
|
} catch (error) {
|