payload-plugin-newsletter 0.16.8 → 0.16.9
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 +15 -0
- package/dist/collections.cjs +117 -39
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +117 -39
- package/dist/collections.js.map +1 -1
- package/dist/index.cjs +117 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +117 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4486,7 +4486,7 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4486
4486
|
return doc;
|
|
4487
4487
|
}
|
|
4488
4488
|
}
|
|
4489
|
-
if (operation === "update"
|
|
4489
|
+
if (operation === "update") {
|
|
4490
4490
|
req.payload.logger.info("Broadcast afterChange update hook triggered", {
|
|
4491
4491
|
operation,
|
|
4492
4492
|
hasProviderId: !!doc.providerId,
|
|
@@ -4501,57 +4501,135 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
4501
4501
|
}
|
|
4502
4502
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
4503
4503
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
return doc;
|
|
4509
|
-
}
|
|
4510
|
-
const contentChanged = doc.subject !== previousDoc?.subject || doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader || JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content) || doc.settings?.trackOpens !== previousDoc?.settings?.trackOpens || doc.settings?.trackClicks !== previousDoc?.settings?.trackClicks || doc.settings?.replyTo !== previousDoc?.settings?.replyTo || JSON.stringify(doc.audienceIds) !== JSON.stringify(previousDoc?.audienceIds);
|
|
4511
|
-
if (contentChanged) {
|
|
4512
|
-
const updates = {};
|
|
4513
|
-
if (doc.subject !== previousDoc?.subject) {
|
|
4514
|
-
updates.name = doc.subject;
|
|
4515
|
-
updates.subject = doc.subject;
|
|
4516
|
-
}
|
|
4517
|
-
if (doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader) {
|
|
4518
|
-
updates.preheader = doc.contentSection?.preheader;
|
|
4519
|
-
}
|
|
4520
|
-
if (JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content)) {
|
|
4521
|
-
updates.content = await convertToEmailSafeHtml(doc.contentSection?.content);
|
|
4504
|
+
if (!doc.providerId) {
|
|
4505
|
+
if (!doc.subject || !doc.contentSection?.content) {
|
|
4506
|
+
req.payload.logger.info("Still missing required fields for provider sync");
|
|
4507
|
+
return doc;
|
|
4522
4508
|
}
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4509
|
+
try {
|
|
4510
|
+
req.payload.logger.info("Creating broadcast in provider (deferred from initial create)...");
|
|
4511
|
+
const htmlContent = await convertToEmailSafeHtml(doc.contentSection?.content);
|
|
4512
|
+
if (!htmlContent || htmlContent.trim() === "") {
|
|
4513
|
+
req.payload.logger.info("Skipping provider sync - content is empty after conversion");
|
|
4514
|
+
return doc;
|
|
4515
|
+
}
|
|
4516
|
+
const createData = {
|
|
4517
|
+
name: doc.subject,
|
|
4518
|
+
subject: doc.subject,
|
|
4519
|
+
preheader: doc.contentSection?.preheader,
|
|
4520
|
+
content: htmlContent,
|
|
4521
|
+
trackOpens: doc.settings?.trackOpens,
|
|
4522
|
+
trackClicks: doc.settings?.trackClicks,
|
|
4523
|
+
replyTo: doc.settings?.replyTo || providerConfig.replyTo,
|
|
4524
|
+
audienceIds: doc.audienceIds?.map((a) => a.audienceId)
|
|
4525
|
+
};
|
|
4526
|
+
req.payload.logger.info("Creating broadcast with data:", {
|
|
4527
|
+
name: createData.name,
|
|
4528
|
+
subject: createData.subject,
|
|
4529
|
+
preheader: createData.preheader || "NONE",
|
|
4530
|
+
contentLength: htmlContent ? htmlContent.length : 0,
|
|
4531
|
+
contentPreview: htmlContent ? htmlContent.substring(0, 100) + "..." : "EMPTY",
|
|
4532
|
+
apiUrl: providerConfig.apiUrl,
|
|
4533
|
+
hasToken: !!providerConfig.token
|
|
4534
|
+
});
|
|
4535
|
+
const providerBroadcast = await provider.create(createData);
|
|
4536
|
+
await req.payload.update({
|
|
4537
|
+
collection: "broadcasts",
|
|
4538
|
+
id: doc.id,
|
|
4539
|
+
data: {
|
|
4540
|
+
providerId: providerBroadcast.id,
|
|
4541
|
+
providerData: providerBroadcast.providerData
|
|
4542
|
+
},
|
|
4543
|
+
req
|
|
4544
|
+
});
|
|
4545
|
+
req.payload.logger.info(`Broadcast ${doc.id} created in provider successfully (deferred)`);
|
|
4546
|
+
return {
|
|
4547
|
+
...doc,
|
|
4548
|
+
providerId: providerBroadcast.id,
|
|
4549
|
+
providerData: providerBroadcast.providerData
|
|
4550
|
+
};
|
|
4551
|
+
} catch (error) {
|
|
4552
|
+
req.payload.logger.error("Raw error from broadcast provider (deferred create):");
|
|
4553
|
+
req.payload.logger.error(error);
|
|
4554
|
+
if (error instanceof Error) {
|
|
4555
|
+
req.payload.logger.error("Error is instance of Error:", {
|
|
4556
|
+
message: error.message,
|
|
4557
|
+
stack: error.stack,
|
|
4558
|
+
name: error.name,
|
|
4559
|
+
...error.details,
|
|
4560
|
+
...error.response,
|
|
4561
|
+
...error.data,
|
|
4562
|
+
...error.status,
|
|
4563
|
+
...error.statusText
|
|
4564
|
+
});
|
|
4565
|
+
} else if (typeof error === "string") {
|
|
4566
|
+
req.payload.logger.error("Error is a string:", error);
|
|
4567
|
+
} else if (error && typeof error === "object") {
|
|
4568
|
+
req.payload.logger.error("Error is an object:", JSON.stringify(error, null, 2));
|
|
4569
|
+
} else {
|
|
4570
|
+
req.payload.logger.error("Unknown error type:", typeof error);
|
|
4571
|
+
}
|
|
4572
|
+
req.payload.logger.error("Failed broadcast document (deferred create):", {
|
|
4573
|
+
id: doc.id,
|
|
4574
|
+
subject: doc.subject,
|
|
4575
|
+
hasContent: !!doc.contentSection?.content,
|
|
4576
|
+
contentType: doc.contentSection?.content ? typeof doc.contentSection.content : "none"
|
|
4577
|
+
});
|
|
4578
|
+
return doc;
|
|
4528
4579
|
}
|
|
4529
|
-
|
|
4530
|
-
|
|
4580
|
+
}
|
|
4581
|
+
if (doc.providerId) {
|
|
4582
|
+
const capabilities = provider.getCapabilities();
|
|
4583
|
+
const sendStatus = doc.sendStatus || "draft" /* DRAFT */;
|
|
4584
|
+
if (!capabilities.editableStatuses.includes(sendStatus)) {
|
|
4585
|
+
req.payload.logger.info(`Skipping sync for broadcast in status: ${sendStatus}`);
|
|
4586
|
+
return doc;
|
|
4531
4587
|
}
|
|
4532
|
-
|
|
4533
|
-
|
|
4588
|
+
const contentChanged = doc.subject !== previousDoc?.subject || doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader || JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content) || doc.settings?.trackOpens !== previousDoc?.settings?.trackOpens || doc.settings?.trackClicks !== previousDoc?.settings?.trackClicks || doc.settings?.replyTo !== previousDoc?.settings?.replyTo || JSON.stringify(doc.audienceIds) !== JSON.stringify(previousDoc?.audienceIds);
|
|
4589
|
+
if (contentChanged) {
|
|
4590
|
+
const updates = {};
|
|
4591
|
+
if (doc.subject !== previousDoc?.subject) {
|
|
4592
|
+
updates.name = doc.subject;
|
|
4593
|
+
updates.subject = doc.subject;
|
|
4594
|
+
}
|
|
4595
|
+
if (doc.contentSection?.preheader !== previousDoc?.contentSection?.preheader) {
|
|
4596
|
+
updates.preheader = doc.contentSection?.preheader;
|
|
4597
|
+
}
|
|
4598
|
+
if (JSON.stringify(doc.contentSection?.content) !== JSON.stringify(previousDoc?.contentSection?.content)) {
|
|
4599
|
+
updates.content = await convertToEmailSafeHtml(doc.contentSection?.content);
|
|
4600
|
+
}
|
|
4601
|
+
if (doc.settings?.trackOpens !== previousDoc?.settings?.trackOpens) {
|
|
4602
|
+
updates.trackOpens = doc.settings.trackOpens;
|
|
4603
|
+
}
|
|
4604
|
+
if (doc.settings?.trackClicks !== previousDoc?.settings?.trackClicks) {
|
|
4605
|
+
updates.trackClicks = doc.settings.trackClicks;
|
|
4606
|
+
}
|
|
4607
|
+
if (doc.settings?.replyTo !== previousDoc?.settings?.replyTo) {
|
|
4608
|
+
updates.replyTo = doc.settings.replyTo || providerConfig.replyTo;
|
|
4609
|
+
}
|
|
4610
|
+
if (JSON.stringify(doc.audienceIds) !== JSON.stringify(previousDoc?.audienceIds)) {
|
|
4611
|
+
updates.audienceIds = doc.audienceIds?.map((a) => a.audienceId);
|
|
4612
|
+
}
|
|
4613
|
+
req.payload.logger.info("Syncing broadcast updates to provider", {
|
|
4614
|
+
providerId: doc.providerId,
|
|
4615
|
+
updates
|
|
4616
|
+
});
|
|
4617
|
+
await provider.update(doc.providerId, updates);
|
|
4618
|
+
req.payload.logger.info(`Broadcast ${doc.id} synced to provider successfully`);
|
|
4619
|
+
} else {
|
|
4620
|
+
req.payload.logger.info("No content changes to sync to provider");
|
|
4534
4621
|
}
|
|
4535
|
-
req.payload.logger.info("Syncing broadcast updates to provider", {
|
|
4536
|
-
providerId: doc.providerId,
|
|
4537
|
-
updates
|
|
4538
|
-
});
|
|
4539
|
-
await provider.update(doc.providerId, updates);
|
|
4540
|
-
req.payload.logger.info(`Broadcast ${doc.id} synced to provider successfully`);
|
|
4541
|
-
} else {
|
|
4542
|
-
req.payload.logger.info("No content changes to sync to provider");
|
|
4543
4622
|
}
|
|
4544
4623
|
} catch (error) {
|
|
4545
4624
|
if (error instanceof Error) {
|
|
4546
|
-
req.payload.logger.error("Failed to
|
|
4625
|
+
req.payload.logger.error("Failed to handle broadcast update operation:", {
|
|
4547
4626
|
message: error.message,
|
|
4548
4627
|
stack: error.stack,
|
|
4549
4628
|
name: error.name,
|
|
4550
|
-
// If it's a BroadcastProviderError, it might have additional details
|
|
4551
4629
|
...error.details
|
|
4552
4630
|
});
|
|
4553
4631
|
} else {
|
|
4554
|
-
req.payload.logger.error("Failed to
|
|
4632
|
+
req.payload.logger.error("Failed to handle broadcast update operation:", error);
|
|
4555
4633
|
}
|
|
4556
4634
|
}
|
|
4557
4635
|
}
|