payload-plugin-newsletter 0.16.0 → 0.16.1
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 +8 -0
- package/dist/collections.cjs +45 -42
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +45 -42
- package/dist/collections.js.map +1 -1
- package/dist/index.cjs +45 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4376,6 +4376,51 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4376
4376
|
req.payload.logger.error("Failed to create broadcast in provider:", error);
|
|
4377
4377
|
return doc;
|
|
4378
4378
|
}
|
|
4379
|
+
},
|
|
4380
|
+
// Hook to send when published
|
|
4381
|
+
async ({ doc, operation, previousDoc, req }) => {
|
|
4382
|
+
if (operation !== "update") return doc;
|
|
4383
|
+
const wasUnpublished = !previousDoc?._status || previousDoc._status === "draft";
|
|
4384
|
+
const isNowPublished = doc._status === "published";
|
|
4385
|
+
if (wasUnpublished && isNowPublished && doc.providerId) {
|
|
4386
|
+
if (doc.status === "sent" || doc.status === "sending") {
|
|
4387
|
+
return doc;
|
|
4388
|
+
}
|
|
4389
|
+
try {
|
|
4390
|
+
const broadcastConfig = pluginConfig.providers?.broadcast;
|
|
4391
|
+
const resendConfig = pluginConfig.providers?.resend;
|
|
4392
|
+
if (!broadcastConfig && !resendConfig) {
|
|
4393
|
+
req.payload.logger.error("No provider configured for sending");
|
|
4394
|
+
return doc;
|
|
4395
|
+
}
|
|
4396
|
+
if (broadcastConfig) {
|
|
4397
|
+
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
4398
|
+
const provider = new BroadcastApiProvider2(broadcastConfig);
|
|
4399
|
+
await provider.send(doc.providerId);
|
|
4400
|
+
}
|
|
4401
|
+
await req.payload.update({
|
|
4402
|
+
collection: "broadcasts",
|
|
4403
|
+
id: doc.id,
|
|
4404
|
+
data: {
|
|
4405
|
+
status: "sending" /* SENDING */,
|
|
4406
|
+
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4407
|
+
},
|
|
4408
|
+
req
|
|
4409
|
+
});
|
|
4410
|
+
req.payload.logger.info(`Broadcast ${doc.id} sent successfully`);
|
|
4411
|
+
} catch (error) {
|
|
4412
|
+
req.payload.logger.error(`Failed to send broadcast ${doc.id}:`, error);
|
|
4413
|
+
await req.payload.update({
|
|
4414
|
+
collection: "broadcasts",
|
|
4415
|
+
id: doc.id,
|
|
4416
|
+
data: {
|
|
4417
|
+
status: "failed" /* FAILED */
|
|
4418
|
+
},
|
|
4419
|
+
req
|
|
4420
|
+
});
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4423
|
+
return doc;
|
|
4379
4424
|
}
|
|
4380
4425
|
],
|
|
4381
4426
|
// Sync updates with provider
|
|
@@ -4444,48 +4489,6 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4444
4489
|
req.payload.logger.error("Failed to delete broadcast from provider:", error);
|
|
4445
4490
|
}
|
|
4446
4491
|
return doc;
|
|
4447
|
-
},
|
|
4448
|
-
// Hook to send when published
|
|
4449
|
-
async ({ doc, req }) => {
|
|
4450
|
-
if (doc._status === "published" && doc.providerId) {
|
|
4451
|
-
if (doc.status === "sent" || doc.status === "sending") {
|
|
4452
|
-
return doc;
|
|
4453
|
-
}
|
|
4454
|
-
try {
|
|
4455
|
-
const broadcastConfig = pluginConfig.providers?.broadcast;
|
|
4456
|
-
const resendConfig = pluginConfig.providers?.resend;
|
|
4457
|
-
if (!broadcastConfig && !resendConfig) {
|
|
4458
|
-
req.payload.logger.error("No provider configured for sending");
|
|
4459
|
-
return doc;
|
|
4460
|
-
}
|
|
4461
|
-
if (broadcastConfig) {
|
|
4462
|
-
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
4463
|
-
const provider = new BroadcastApiProvider2(broadcastConfig);
|
|
4464
|
-
await provider.send(doc.providerId);
|
|
4465
|
-
}
|
|
4466
|
-
await req.payload.update({
|
|
4467
|
-
collection: "broadcasts",
|
|
4468
|
-
id: doc.id,
|
|
4469
|
-
data: {
|
|
4470
|
-
status: "sending" /* SENDING */,
|
|
4471
|
-
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4472
|
-
},
|
|
4473
|
-
req
|
|
4474
|
-
});
|
|
4475
|
-
req.payload.logger.info(`Broadcast ${doc.id} sent successfully`);
|
|
4476
|
-
} catch (error) {
|
|
4477
|
-
req.payload.logger.error(`Failed to send broadcast ${doc.id}:`, error);
|
|
4478
|
-
await req.payload.update({
|
|
4479
|
-
collection: "broadcasts",
|
|
4480
|
-
id: doc.id,
|
|
4481
|
-
data: {
|
|
4482
|
-
status: "failed" /* FAILED */
|
|
4483
|
-
},
|
|
4484
|
-
req
|
|
4485
|
-
});
|
|
4486
|
-
}
|
|
4487
|
-
}
|
|
4488
|
-
return doc;
|
|
4489
4492
|
}
|
|
4490
4493
|
]
|
|
4491
4494
|
}
|