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/index.cjs
CHANGED
|
@@ -301,9 +301,9 @@ var init_broadcast2 = __esm({
|
|
|
301
301
|
async update(id, data) {
|
|
302
302
|
try {
|
|
303
303
|
const existing = await this.get(id);
|
|
304
|
-
if (!this.canEditInStatus(existing.
|
|
304
|
+
if (!this.canEditInStatus(existing.sendStatus)) {
|
|
305
305
|
throw new BroadcastProviderError(
|
|
306
|
-
`Cannot update broadcast in status: ${existing.
|
|
306
|
+
`Cannot update broadcast in status: ${existing.sendStatus}`,
|
|
307
307
|
"INVALID_STATUS" /* INVALID_STATUS */,
|
|
308
308
|
this.name
|
|
309
309
|
);
|
|
@@ -346,9 +346,9 @@ var init_broadcast2 = __esm({
|
|
|
346
346
|
async delete(id) {
|
|
347
347
|
try {
|
|
348
348
|
const existing = await this.get(id);
|
|
349
|
-
if (!this.canEditInStatus(existing.
|
|
349
|
+
if (!this.canEditInStatus(existing.sendStatus)) {
|
|
350
350
|
throw new BroadcastProviderError(
|
|
351
|
-
`Cannot delete broadcast in status: ${existing.
|
|
351
|
+
`Cannot delete broadcast in status: ${existing.sendStatus}`,
|
|
352
352
|
"INVALID_STATUS" /* INVALID_STATUS */,
|
|
353
353
|
this.name
|
|
354
354
|
);
|
|
@@ -507,7 +507,7 @@ var init_broadcast2 = __esm({
|
|
|
507
507
|
subject: broadcast.subject,
|
|
508
508
|
preheader: broadcast.preheader,
|
|
509
509
|
content: broadcast.body,
|
|
510
|
-
|
|
510
|
+
sendStatus: this.mapBroadcastStatus(broadcast.status),
|
|
511
511
|
trackOpens: broadcast.track_opens,
|
|
512
512
|
trackClicks: broadcast.track_clicks,
|
|
513
513
|
replyTo: broadcast.reply_to,
|
|
@@ -2976,7 +2976,7 @@ var createSendBroadcastEndpoint = (config, collectionSlug) => {
|
|
|
2976
2976
|
collection: collectionSlug,
|
|
2977
2977
|
id,
|
|
2978
2978
|
data: {
|
|
2979
|
-
|
|
2979
|
+
sendStatus: "sending" /* SENDING */,
|
|
2980
2980
|
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2981
2981
|
},
|
|
2982
2982
|
user: auth.user
|
|
@@ -3080,7 +3080,7 @@ var createScheduleBroadcastEndpoint = (config, collectionSlug) => {
|
|
|
3080
3080
|
collection: collectionSlug,
|
|
3081
3081
|
id,
|
|
3082
3082
|
data: {
|
|
3083
|
-
|
|
3083
|
+
sendStatus: "scheduled" /* SCHEDULED */,
|
|
3084
3084
|
scheduledAt: scheduledDate.toISOString()
|
|
3085
3085
|
},
|
|
3086
3086
|
user: auth.user
|
|
@@ -4128,6 +4128,19 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4128
4128
|
const customizations = pluginConfig.customizations?.broadcasts;
|
|
4129
4129
|
return {
|
|
4130
4130
|
slug: "broadcasts",
|
|
4131
|
+
access: {
|
|
4132
|
+
read: () => true,
|
|
4133
|
+
// Public read access
|
|
4134
|
+
create: ({ req: { user } }) => {
|
|
4135
|
+
return Boolean(user);
|
|
4136
|
+
},
|
|
4137
|
+
update: ({ req: { user } }) => {
|
|
4138
|
+
return Boolean(user);
|
|
4139
|
+
},
|
|
4140
|
+
delete: ({ req: { user } }) => {
|
|
4141
|
+
return Boolean(user);
|
|
4142
|
+
}
|
|
4143
|
+
},
|
|
4131
4144
|
versions: {
|
|
4132
4145
|
drafts: {
|
|
4133
4146
|
autosave: true,
|
|
@@ -4141,7 +4154,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4141
4154
|
admin: {
|
|
4142
4155
|
useAsTitle: "subject",
|
|
4143
4156
|
description: "Individual email campaigns sent to subscribers",
|
|
4144
|
-
defaultColumns: ["subject", "_status", "
|
|
4157
|
+
defaultColumns: ["subject", "_status", "sendStatus", "sentAt", "recipientCount"]
|
|
4145
4158
|
},
|
|
4146
4159
|
fields: [
|
|
4147
4160
|
{
|
|
@@ -4201,8 +4214,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4201
4214
|
]
|
|
4202
4215
|
},
|
|
4203
4216
|
{
|
|
4204
|
-
name: "
|
|
4217
|
+
name: "sendStatus",
|
|
4205
4218
|
type: "select",
|
|
4219
|
+
label: "Send Status",
|
|
4206
4220
|
required: true,
|
|
4207
4221
|
defaultValue: "draft" /* DRAFT */,
|
|
4208
4222
|
options: [
|
|
@@ -4216,6 +4230,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4216
4230
|
],
|
|
4217
4231
|
admin: {
|
|
4218
4232
|
readOnly: true,
|
|
4233
|
+
description: "The status of the email send operation",
|
|
4219
4234
|
components: {
|
|
4220
4235
|
Cell: "payload-plugin-newsletter/components#StatusBadge"
|
|
4221
4236
|
}
|
|
@@ -4272,7 +4287,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4272
4287
|
type: "group",
|
|
4273
4288
|
admin: {
|
|
4274
4289
|
readOnly: true,
|
|
4275
|
-
condition: (data) => data?.
|
|
4290
|
+
condition: (data) => data?.sendStatus === "sent" /* SENT */
|
|
4276
4291
|
},
|
|
4277
4292
|
fields: [
|
|
4278
4293
|
{
|
|
@@ -4331,7 +4346,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4331
4346
|
name: "scheduledAt",
|
|
4332
4347
|
type: "date",
|
|
4333
4348
|
admin: {
|
|
4334
|
-
condition: (data) => data?.
|
|
4349
|
+
condition: (data) => data?.sendStatus === "scheduled" /* SCHEDULED */,
|
|
4335
4350
|
date: {
|
|
4336
4351
|
displayFormat: "MMM d, yyyy h:mm a"
|
|
4337
4352
|
}
|
|
@@ -4416,7 +4431,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4416
4431
|
const wasUnpublished = !previousDoc?._status || previousDoc._status === "draft";
|
|
4417
4432
|
const isNowPublished = doc._status === "published";
|
|
4418
4433
|
if (wasUnpublished && isNowPublished && doc.providerId) {
|
|
4419
|
-
if (doc.
|
|
4434
|
+
if (doc.sendStatus === "sent" /* SENT */ || doc.sendStatus === "sending" /* SENDING */) {
|
|
4420
4435
|
return doc;
|
|
4421
4436
|
}
|
|
4422
4437
|
try {
|
|
@@ -4435,7 +4450,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4435
4450
|
collection: "broadcasts",
|
|
4436
4451
|
id: doc.id,
|
|
4437
4452
|
data: {
|
|
4438
|
-
|
|
4453
|
+
sendStatus: "sending" /* SENDING */,
|
|
4439
4454
|
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4440
4455
|
},
|
|
4441
4456
|
req
|
|
@@ -4457,7 +4472,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4457
4472
|
collection: "broadcasts",
|
|
4458
4473
|
id: doc.id,
|
|
4459
4474
|
data: {
|
|
4460
|
-
|
|
4475
|
+
sendStatus: "failed" /* FAILED */
|
|
4461
4476
|
},
|
|
4462
4477
|
req
|
|
4463
4478
|
});
|
|
@@ -4470,6 +4485,14 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4470
4485
|
beforeChange: [
|
|
4471
4486
|
async ({ data, originalDoc, operation, req }) => {
|
|
4472
4487
|
if (!hasProviders || !originalDoc?.providerId || operation !== "update") return data;
|
|
4488
|
+
req.payload.logger.info("Broadcast beforeChange update hook triggered", {
|
|
4489
|
+
operation,
|
|
4490
|
+
hasProviderId: !!originalDoc?.providerId,
|
|
4491
|
+
originalSendStatus: originalDoc?.sendStatus,
|
|
4492
|
+
originalPublishStatus: originalDoc?._status,
|
|
4493
|
+
newSendStatus: data?.sendStatus,
|
|
4494
|
+
newPublishStatus: data?._status
|
|
4495
|
+
});
|
|
4473
4496
|
try {
|
|
4474
4497
|
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
4475
4498
|
if (!providerConfig || !providerConfig.token) {
|
|
@@ -4479,7 +4502,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4479
4502
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
4480
4503
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
4481
4504
|
const capabilities = provider.getCapabilities();
|
|
4482
|
-
|
|
4505
|
+
const sendStatus = originalDoc.sendStatus || "draft" /* DRAFT */;
|
|
4506
|
+
if (!capabilities.editableStatuses.includes(sendStatus)) {
|
|
4507
|
+
req.payload.logger.info(`Skipping sync for broadcast in status: ${sendStatus}`);
|
|
4483
4508
|
return data;
|
|
4484
4509
|
}
|
|
4485
4510
|
const updates = {};
|
|
@@ -4504,7 +4529,14 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4504
4529
|
updates.audienceIds = data.audienceIds?.map((a) => a.audienceId);
|
|
4505
4530
|
}
|
|
4506
4531
|
if (Object.keys(updates).length > 0) {
|
|
4532
|
+
req.payload.logger.info("Syncing broadcast updates to provider", {
|
|
4533
|
+
providerId: originalDoc.providerId,
|
|
4534
|
+
updates
|
|
4535
|
+
});
|
|
4507
4536
|
await provider.update(originalDoc.providerId, updates);
|
|
4537
|
+
req.payload.logger.info("Successfully synced broadcast updates to provider");
|
|
4538
|
+
} else {
|
|
4539
|
+
req.payload.logger.info("No broadcast updates to sync to provider");
|
|
4508
4540
|
}
|
|
4509
4541
|
} catch (error) {
|
|
4510
4542
|
if (error instanceof Error) {
|
|
@@ -4535,7 +4567,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4535
4567
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
4536
4568
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
4537
4569
|
const capabilities = provider.getCapabilities();
|
|
4538
|
-
if (capabilities.editableStatuses.includes(doc.
|
|
4570
|
+
if (capabilities.editableStatuses.includes(doc.sendStatus)) {
|
|
4539
4571
|
await provider.delete(doc.providerId);
|
|
4540
4572
|
}
|
|
4541
4573
|
} catch (error) {
|
|
@@ -4659,7 +4691,7 @@ var ResendBroadcastProvider = class extends BaseBroadcastProvider {
|
|
|
4659
4691
|
name: "Unknown",
|
|
4660
4692
|
subject: "Unknown",
|
|
4661
4693
|
content: "",
|
|
4662
|
-
|
|
4694
|
+
sendStatus: "sending" /* SENDING */,
|
|
4663
4695
|
trackOpens: true,
|
|
4664
4696
|
trackClicks: true,
|
|
4665
4697
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -4746,7 +4778,7 @@ var ResendBroadcastProvider = class extends BaseBroadcastProvider {
|
|
|
4746
4778
|
subject: broadcast.subject,
|
|
4747
4779
|
preheader: broadcast.preheader,
|
|
4748
4780
|
content: broadcast.content?.html || broadcast.html || "",
|
|
4749
|
-
|
|
4781
|
+
sendStatus: this.mapResendStatus(broadcast.status),
|
|
4750
4782
|
trackOpens: true,
|
|
4751
4783
|
// Resend tracks by default
|
|
4752
4784
|
trackClicks: true,
|