payload-plugin-newsletter 0.15.1 → 0.16.0

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/index.js CHANGED
@@ -4105,6 +4105,12 @@ var createBroadcastsCollection = (pluginConfig) => {
4105
4105
  const customizations = pluginConfig.customizations?.broadcasts;
4106
4106
  return {
4107
4107
  slug: "broadcasts",
4108
+ versions: {
4109
+ drafts: {
4110
+ autosave: true,
4111
+ schedulePublish: true
4112
+ }
4113
+ },
4108
4114
  labels: {
4109
4115
  singular: "Broadcast",
4110
4116
  plural: "Broadcasts"
@@ -4112,7 +4118,7 @@ var createBroadcastsCollection = (pluginConfig) => {
4112
4118
  admin: {
4113
4119
  useAsTitle: "subject",
4114
4120
  description: "Individual email campaigns sent to subscribers",
4115
- defaultColumns: ["subject", "status", "sentAt", "recipientCount", "actions"]
4121
+ defaultColumns: ["subject", "_status", "status", "sentAt", "recipientCount"]
4116
4122
  },
4117
4123
  fields: [
4118
4124
  {
@@ -4325,18 +4331,6 @@ var createBroadcastsCollection = (pluginConfig) => {
4325
4331
  condition: () => false
4326
4332
  // Hidden by default
4327
4333
  }
4328
- },
4329
- // UI Field for custom actions in list view
4330
- {
4331
- name: "actions",
4332
- type: "ui",
4333
- admin: {
4334
- components: {
4335
- Cell: "payload-plugin-newsletter/components#ActionsCell",
4336
- Field: "payload-plugin-newsletter/components#EmptyField"
4337
- },
4338
- disableListColumn: false
4339
- }
4340
4334
  }
4341
4335
  ],
4342
4336
  hooks: {
@@ -4450,6 +4444,48 @@ var createBroadcastsCollection = (pluginConfig) => {
4450
4444
  req.payload.logger.error("Failed to delete broadcast from provider:", error);
4451
4445
  }
4452
4446
  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;
4453
4489
  }
4454
4490
  ]
4455
4491
  }