payload-plugin-newsletter 0.16.6 → 0.16.7
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 +24 -0
- package/dist/collections.cjs +68 -19
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +68 -19
- package/dist/collections.js.map +1 -1
- package/dist/index.cjs +68 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -262,29 +262,46 @@ var init_broadcast2 = __esm({
|
|
|
262
262
|
async create(data) {
|
|
263
263
|
try {
|
|
264
264
|
this.validateRequiredFields(data, ["name", "subject", "content"]);
|
|
265
|
+
const requestBody = {
|
|
266
|
+
broadcast: {
|
|
267
|
+
name: data.name,
|
|
268
|
+
subject: data.subject,
|
|
269
|
+
preheader: data.preheader,
|
|
270
|
+
body: data.content,
|
|
271
|
+
html_body: true,
|
|
272
|
+
track_opens: data.trackOpens ?? true,
|
|
273
|
+
track_clicks: data.trackClicks ?? true,
|
|
274
|
+
reply_to: data.replyTo,
|
|
275
|
+
segment_ids: data.audienceIds
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
console.log("[BroadcastApiProvider] Creating broadcast:", {
|
|
279
|
+
url: `${this.apiUrl}/api/v1/broadcasts`,
|
|
280
|
+
method: "POST",
|
|
281
|
+
hasToken: !!this.token,
|
|
282
|
+
tokenLength: this.token?.length,
|
|
283
|
+
body: JSON.stringify(requestBody, null, 2)
|
|
284
|
+
});
|
|
265
285
|
const response = await fetch(`${this.apiUrl}/api/v1/broadcasts`, {
|
|
266
286
|
method: "POST",
|
|
267
287
|
headers: {
|
|
268
288
|
"Authorization": `Bearer ${this.token}`,
|
|
269
289
|
"Content-Type": "application/json"
|
|
270
290
|
},
|
|
271
|
-
body: JSON.stringify(
|
|
272
|
-
broadcast: {
|
|
273
|
-
name: data.name,
|
|
274
|
-
subject: data.subject,
|
|
275
|
-
preheader: data.preheader,
|
|
276
|
-
body: data.content,
|
|
277
|
-
html_body: true,
|
|
278
|
-
track_opens: data.trackOpens ?? true,
|
|
279
|
-
track_clicks: data.trackClicks ?? true,
|
|
280
|
-
reply_to: data.replyTo,
|
|
281
|
-
segment_ids: data.audienceIds
|
|
282
|
-
}
|
|
283
|
-
})
|
|
291
|
+
body: JSON.stringify(requestBody)
|
|
284
292
|
});
|
|
293
|
+
console.log("[BroadcastApiProvider] Response status:", response.status);
|
|
294
|
+
console.log("[BroadcastApiProvider] Response headers:", Object.fromEntries(response.headers.entries()));
|
|
285
295
|
if (!response.ok) {
|
|
286
|
-
const
|
|
287
|
-
|
|
296
|
+
const errorText = await response.text();
|
|
297
|
+
console.error("[BroadcastApiProvider] Error response body:", errorText);
|
|
298
|
+
let errorDetails;
|
|
299
|
+
try {
|
|
300
|
+
errorDetails = JSON.parse(errorText);
|
|
301
|
+
console.error("[BroadcastApiProvider] Parsed error:", errorDetails);
|
|
302
|
+
} catch {
|
|
303
|
+
}
|
|
304
|
+
throw new Error(`Broadcast API error: ${response.status} - ${errorText}`);
|
|
288
305
|
}
|
|
289
306
|
const result = await response.json();
|
|
290
307
|
return this.get(result.id.toString());
|
|
@@ -4385,8 +4402,9 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4385
4402
|
}
|
|
4386
4403
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
4387
4404
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
4405
|
+
req.payload.logger.info("Converting content to HTML...");
|
|
4388
4406
|
const htmlContent = await convertToEmailSafeHtml(doc.contentSection?.content);
|
|
4389
|
-
const
|
|
4407
|
+
const createData = {
|
|
4390
4408
|
name: doc.subject,
|
|
4391
4409
|
// Use subject as name since we removed the name field
|
|
4392
4410
|
subject: doc.subject,
|
|
@@ -4396,7 +4414,21 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4396
4414
|
trackClicks: doc.settings?.trackClicks,
|
|
4397
4415
|
replyTo: doc.settings?.replyTo || providerConfig.replyTo,
|
|
4398
4416
|
audienceIds: doc.audienceIds?.map((a) => a.audienceId)
|
|
4417
|
+
};
|
|
4418
|
+
req.payload.logger.info("Creating broadcast with data:", {
|
|
4419
|
+
name: createData.name,
|
|
4420
|
+
subject: createData.subject,
|
|
4421
|
+
preheader: createData.preheader || "NONE",
|
|
4422
|
+
contentLength: htmlContent ? htmlContent.length : 0,
|
|
4423
|
+
contentPreview: htmlContent ? htmlContent.substring(0, 100) + "..." : "EMPTY",
|
|
4424
|
+
trackOpens: createData.trackOpens,
|
|
4425
|
+
trackClicks: createData.trackClicks,
|
|
4426
|
+
replyTo: createData.replyTo,
|
|
4427
|
+
audienceIds: createData.audienceIds || [],
|
|
4428
|
+
apiUrl: providerConfig.apiUrl,
|
|
4429
|
+
hasToken: !!providerConfig.token
|
|
4399
4430
|
});
|
|
4431
|
+
const providerBroadcast = await provider.create(createData);
|
|
4400
4432
|
await req.payload.update({
|
|
4401
4433
|
collection: "broadcasts",
|
|
4402
4434
|
id: doc.id,
|
|
@@ -4412,17 +4444,34 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4412
4444
|
providerData: providerBroadcast.providerData
|
|
4413
4445
|
};
|
|
4414
4446
|
} catch (error) {
|
|
4447
|
+
req.payload.logger.error("Raw error from broadcast provider:");
|
|
4448
|
+
req.payload.logger.error(error);
|
|
4415
4449
|
if (error instanceof Error) {
|
|
4416
|
-
req.payload.logger.error("
|
|
4450
|
+
req.payload.logger.error("Error is instance of Error:", {
|
|
4417
4451
|
message: error.message,
|
|
4418
4452
|
stack: error.stack,
|
|
4419
4453
|
name: error.name,
|
|
4420
4454
|
// If it's a BroadcastProviderError, it might have additional details
|
|
4421
|
-
...error.details
|
|
4455
|
+
...error.details,
|
|
4456
|
+
// Check if it's a fetch response error
|
|
4457
|
+
...error.response,
|
|
4458
|
+
...error.data,
|
|
4459
|
+
...error.status,
|
|
4460
|
+
...error.statusText
|
|
4422
4461
|
});
|
|
4462
|
+
} else if (typeof error === "string") {
|
|
4463
|
+
req.payload.logger.error("Error is a string:", error);
|
|
4464
|
+
} else if (error && typeof error === "object") {
|
|
4465
|
+
req.payload.logger.error("Error is an object:", JSON.stringify(error, null, 2));
|
|
4423
4466
|
} else {
|
|
4424
|
-
req.payload.logger.error("
|
|
4467
|
+
req.payload.logger.error("Unknown error type:", typeof error);
|
|
4425
4468
|
}
|
|
4469
|
+
req.payload.logger.error("Failed broadcast document:", {
|
|
4470
|
+
id: doc.id,
|
|
4471
|
+
subject: doc.subject,
|
|
4472
|
+
hasContent: !!doc.contentSection?.content,
|
|
4473
|
+
contentType: doc.contentSection?.content ? typeof doc.contentSection.content : "none"
|
|
4474
|
+
});
|
|
4426
4475
|
return doc;
|
|
4427
4476
|
}
|
|
4428
4477
|
}
|