payload-plugin-newsletter 0.15.1 → 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/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: {
@@ -4382,6 +4376,51 @@ var createBroadcastsCollection = (pluginConfig) => {
4382
4376
  req.payload.logger.error("Failed to create broadcast in provider:", error);
4383
4377
  return doc;
4384
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;
4385
4424
  }
4386
4425
  ],
4387
4426
  // Sync updates with provider