payload-plugin-newsletter 0.16.1 → 0.16.2

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.cjs CHANGED
@@ -2898,6 +2898,29 @@ async function requireAdmin(req, config) {
2898
2898
  };
2899
2899
  }
2900
2900
 
2901
+ // src/utils/getBroadcastConfig.ts
2902
+ async function getBroadcastConfig(req, pluginConfig) {
2903
+ try {
2904
+ const settings = await req.payload.findGlobal({
2905
+ slug: pluginConfig.settingsSlug || "newsletter-settings",
2906
+ req
2907
+ });
2908
+ if (settings?.provider === "broadcast" && settings?.broadcastSettings) {
2909
+ return {
2910
+ apiUrl: settings.broadcastSettings.apiUrl || pluginConfig.providers?.broadcast?.apiUrl || "",
2911
+ token: settings.broadcastSettings.token || pluginConfig.providers?.broadcast?.token || "",
2912
+ fromAddress: settings.fromAddress || pluginConfig.providers?.broadcast?.fromAddress || "",
2913
+ fromName: settings.fromName || pluginConfig.providers?.broadcast?.fromName || "",
2914
+ replyTo: settings.replyTo || pluginConfig.providers?.broadcast?.replyTo
2915
+ };
2916
+ }
2917
+ return pluginConfig.providers?.broadcast || null;
2918
+ } catch (error) {
2919
+ req.payload.logger.error("Failed to get broadcast config from settings:", error);
2920
+ return pluginConfig.providers?.broadcast || null;
2921
+ }
2922
+ }
2923
+
2901
2924
  // src/endpoints/broadcasts/send.ts
2902
2925
  var createSendBroadcastEndpoint = (config, collectionSlug) => {
2903
2926
  return {
@@ -2939,11 +2962,11 @@ var createSendBroadcastEndpoint = (config, collectionSlug) => {
2939
2962
  error: "Broadcast not found or not synced with provider"
2940
2963
  }, { status: 404 });
2941
2964
  }
2942
- const providerConfig = config.providers?.broadcast;
2943
- if (!providerConfig) {
2965
+ const providerConfig = await getBroadcastConfig(req, config);
2966
+ if (!providerConfig || !providerConfig.token) {
2944
2967
  return Response.json({
2945
2968
  success: false,
2946
- error: "Broadcast provider not configured"
2969
+ error: "Broadcast provider not configured in Newsletter Settings or environment variables"
2947
2970
  }, { status: 500 });
2948
2971
  }
2949
2972
  const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
@@ -4339,9 +4362,9 @@ var createBroadcastsCollection = (pluginConfig) => {
4339
4362
  async ({ doc, operation, req }) => {
4340
4363
  if (!hasProviders || operation !== "create") return doc;
4341
4364
  try {
4342
- const providerConfig = pluginConfig.providers?.broadcast;
4343
- if (!providerConfig) {
4344
- req.payload.logger.error("Broadcast provider not configured");
4365
+ const providerConfig = await getBroadcastConfig(req, pluginConfig);
4366
+ if (!providerConfig || !providerConfig.token) {
4367
+ req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
4345
4368
  return doc;
4346
4369
  }
4347
4370
  const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
@@ -4387,13 +4410,13 @@ var createBroadcastsCollection = (pluginConfig) => {
4387
4410
  return doc;
4388
4411
  }
4389
4412
  try {
4390
- const broadcastConfig = pluginConfig.providers?.broadcast;
4413
+ const broadcastConfig = await getBroadcastConfig(req, pluginConfig);
4391
4414
  const resendConfig = pluginConfig.providers?.resend;
4392
4415
  if (!broadcastConfig && !resendConfig) {
4393
- req.payload.logger.error("No provider configured for sending");
4416
+ req.payload.logger.error("No provider configured for sending in Newsletter Settings or environment variables");
4394
4417
  return doc;
4395
4418
  }
4396
- if (broadcastConfig) {
4419
+ if (broadcastConfig && broadcastConfig.token) {
4397
4420
  const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
4398
4421
  const provider = new BroadcastApiProvider2(broadcastConfig);
4399
4422
  await provider.send(doc.providerId);
@@ -4428,9 +4451,9 @@ var createBroadcastsCollection = (pluginConfig) => {
4428
4451
  async ({ data, originalDoc, operation, req }) => {
4429
4452
  if (!hasProviders || !originalDoc?.providerId || operation !== "update") return data;
4430
4453
  try {
4431
- const providerConfig = pluginConfig.providers?.broadcast;
4432
- if (!providerConfig) {
4433
- req.payload.logger.error("Broadcast provider not configured");
4454
+ const providerConfig = await getBroadcastConfig(req, pluginConfig);
4455
+ if (!providerConfig || !providerConfig.token) {
4456
+ req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
4434
4457
  return data;
4435
4458
  }
4436
4459
  const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
@@ -4474,9 +4497,9 @@ var createBroadcastsCollection = (pluginConfig) => {
4474
4497
  async ({ doc, req }) => {
4475
4498
  if (!hasProviders || !doc?.providerId) return doc;
4476
4499
  try {
4477
- const providerConfig = pluginConfig.providers?.broadcast;
4478
- if (!providerConfig) {
4479
- req.payload.logger.error("Broadcast provider not configured");
4500
+ const providerConfig = await getBroadcastConfig(req, pluginConfig);
4501
+ if (!providerConfig || !providerConfig.token) {
4502
+ req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
4480
4503
  return doc;
4481
4504
  }
4482
4505
  const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));