payload-plugin-newsletter 0.25.7 → 0.25.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 +24 -0
- package/dist/{broadcast-KSKQRQB6.js → broadcast-TKESOAJN.js} +1 -1
- package/dist/{chunk-KZDNTLVF.js → chunk-KETHRCG7.js} +1 -0
- package/dist/collections.cjs +40 -71
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +40 -71
- package/dist/collections.js.map +1 -1
- package/dist/server.js +45 -77
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## [0.25.9] - 2025-08-19
|
|
2
|
+
|
|
3
|
+
### Fixed
|
|
4
|
+
- Fixed providerId/externalId not being saved during broadcast creation
|
|
5
|
+
- Moved provider creation from create to update operation
|
|
6
|
+
- Provider broadcast is now created on first update when subject and content are present
|
|
7
|
+
- Ensures IDs are properly persisted to the database
|
|
8
|
+
- Prevents issues with Payload's create operation not persisting afterChange modifications
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Broadcasts are now created in Payload first, then synced to provider on first meaningful update
|
|
12
|
+
- More robust approach that works with Payload's hook lifecycle
|
|
13
|
+
|
|
14
|
+
## [0.25.8] - 2025-08-19
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- Added check to prevent double broadcast creation if externalId/providerId already exists
|
|
18
|
+
- Enhanced logging to show document status and existing IDs during creation
|
|
19
|
+
- Added logging for GET broadcast response to diagnose sync issues
|
|
20
|
+
- Helps identify root cause of duplicate broadcast creation
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- More descriptive hook logging to distinguish between sync and publish hooks
|
|
24
|
+
|
|
1
25
|
## [0.25.7] - 2025-08-19
|
|
2
26
|
|
|
3
27
|
### Fixed
|
|
@@ -177,6 +177,7 @@ var BroadcastApiProvider = class extends BaseBroadcastProvider {
|
|
|
177
177
|
throw new Error(`Broadcast API error: ${response.status} - ${error}`);
|
|
178
178
|
}
|
|
179
179
|
const broadcast = await response.json();
|
|
180
|
+
console.log("[BroadcastApiProvider] GET response:", broadcast);
|
|
180
181
|
return this.transformBroadcastFromApi(broadcast);
|
|
181
182
|
} catch (error) {
|
|
182
183
|
if (error instanceof BroadcastProviderError) throw error;
|
package/dist/collections.cjs
CHANGED
|
@@ -249,6 +249,7 @@ var init_broadcast2 = __esm({
|
|
|
249
249
|
throw new Error(`Broadcast API error: ${response.status} - ${error}`);
|
|
250
250
|
}
|
|
251
251
|
const broadcast = await response.json();
|
|
252
|
+
console.log("[BroadcastApiProvider] GET response:", broadcast);
|
|
252
253
|
return this.transformBroadcastFromApi(broadcast);
|
|
253
254
|
} catch (error) {
|
|
254
255
|
if (error instanceof BroadcastProviderError) throw error;
|
|
@@ -2305,82 +2306,18 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
2305
2306
|
async ({ doc, operation, req, previousDoc }) => {
|
|
2306
2307
|
if (!hasProviders) return doc;
|
|
2307
2308
|
if (operation === "create") {
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
docId: doc.id,
|
|
2311
|
-
docIdType: typeof doc.id,
|
|
2312
|
-
hasDoc: !!doc,
|
|
2313
|
-
operation
|
|
2314
|
-
});
|
|
2315
|
-
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
2316
|
-
if (!providerConfig || !providerConfig.token) {
|
|
2317
|
-
req.payload.logger.error("Broadcast provider not configured in Newsletter Settings or environment variables");
|
|
2318
|
-
return doc;
|
|
2319
|
-
}
|
|
2320
|
-
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
2321
|
-
const provider = new BroadcastApiProvider2(providerConfig);
|
|
2322
|
-
const subject = doc.subject || `Draft Broadcast ${(/* @__PURE__ */ new Date()).toISOString()}`;
|
|
2323
|
-
const htmlContent = doc.contentSection?.content ? await convertToEmailSafeHtml(
|
|
2324
|
-
await populateMediaFields(doc.contentSection.content, req.payload, pluginConfig),
|
|
2325
|
-
{
|
|
2326
|
-
wrapInTemplate: pluginConfig.customizations?.broadcasts?.emailPreview?.wrapInTemplate ?? true,
|
|
2327
|
-
customWrapper: pluginConfig.customizations?.broadcasts?.emailPreview?.customWrapper,
|
|
2328
|
-
preheader: doc.contentSection?.preheader,
|
|
2329
|
-
subject,
|
|
2330
|
-
documentData: doc,
|
|
2331
|
-
customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
|
|
2332
|
-
}
|
|
2333
|
-
) : "<p>Draft content - to be updated</p>";
|
|
2334
|
-
const createData = {
|
|
2335
|
-
name: subject,
|
|
2336
|
-
// Use subject as name
|
|
2337
|
-
subject,
|
|
2338
|
-
preheader: doc.contentSection?.preheader || "",
|
|
2339
|
-
content: htmlContent,
|
|
2340
|
-
trackOpens: doc.settings?.trackOpens ?? true,
|
|
2341
|
-
trackClicks: doc.settings?.trackClicks ?? true,
|
|
2342
|
-
replyTo: doc.settings?.replyTo || providerConfig.replyTo,
|
|
2343
|
-
audienceIds: doc.audienceIds?.map((a) => a.audienceId) || []
|
|
2344
|
-
};
|
|
2345
|
-
req.payload.logger.info("Creating broadcast in provider with minimal data to establish association", {
|
|
2346
|
-
subject: createData.subject,
|
|
2347
|
-
hasActualContent: !!doc.contentSection?.content
|
|
2348
|
-
});
|
|
2349
|
-
const providerBroadcast = await provider.create(createData);
|
|
2350
|
-
req.payload.logger.info("Provider broadcast created:", {
|
|
2351
|
-
providerBroadcastId: providerBroadcast.id,
|
|
2352
|
-
providerBroadcastIdType: typeof providerBroadcast.id,
|
|
2353
|
-
docId: doc.id,
|
|
2354
|
-
docIdType: typeof doc.id
|
|
2355
|
-
});
|
|
2356
|
-
req.payload.logger.info(`Broadcast ${doc.id} created in provider with ID ${providerBroadcast.id}`);
|
|
2357
|
-
return {
|
|
2358
|
-
...doc,
|
|
2359
|
-
providerId: providerBroadcast.id,
|
|
2360
|
-
externalId: providerBroadcast.id,
|
|
2361
|
-
// Include externalId in return value
|
|
2362
|
-
providerData: providerBroadcast.providerData
|
|
2363
|
-
};
|
|
2364
|
-
} catch (error) {
|
|
2365
|
-
req.payload.logger.error("Failed to create broadcast in provider during initial creation:");
|
|
2366
|
-
if (error instanceof Error) {
|
|
2367
|
-
req.payload.logger.error("Error details:", {
|
|
2368
|
-
message: error.message,
|
|
2369
|
-
stack: error.stack,
|
|
2370
|
-
name: error.name
|
|
2371
|
-
});
|
|
2372
|
-
} else {
|
|
2373
|
-
req.payload.logger.error("Raw error:", error);
|
|
2374
|
-
}
|
|
2375
|
-
return doc;
|
|
2376
|
-
}
|
|
2309
|
+
req.payload.logger.info("Broadcast created in Payload, provider sync will happen on first update with content");
|
|
2310
|
+
return doc;
|
|
2377
2311
|
}
|
|
2378
2312
|
if (operation === "update") {
|
|
2379
2313
|
req.payload.logger.info("Broadcast afterChange update hook triggered", {
|
|
2380
2314
|
operation,
|
|
2381
2315
|
hasProviderId: !!doc.providerId,
|
|
2316
|
+
hasExternalId: !!doc.externalId,
|
|
2382
2317
|
sendStatus: doc.sendStatus,
|
|
2383
|
-
publishStatus: doc._status
|
|
2318
|
+
publishStatus: doc._status,
|
|
2319
|
+
hasSubject: !!doc.subject,
|
|
2320
|
+
hasContent: !!doc.contentSection?.content
|
|
2384
2321
|
});
|
|
2385
2322
|
try {
|
|
2386
2323
|
const providerConfig = await getBroadcastConfig(req, pluginConfig);
|
|
@@ -2390,8 +2327,40 @@ var createBroadcastsCollection = (pluginConfig) => {
|
|
|
2390
2327
|
}
|
|
2391
2328
|
const { BroadcastApiProvider: BroadcastApiProvider2 } = await Promise.resolve().then(() => (init_broadcast2(), broadcast_exports));
|
|
2392
2329
|
const provider = new BroadcastApiProvider2(providerConfig);
|
|
2330
|
+
if (!doc.providerId && !doc.externalId && doc.subject && doc.contentSection?.content) {
|
|
2331
|
+
req.payload.logger.info("Creating broadcast in provider on first update with content");
|
|
2332
|
+
const htmlContent = await convertToEmailSafeHtml(
|
|
2333
|
+
await populateMediaFields(doc.contentSection.content, req.payload, pluginConfig),
|
|
2334
|
+
{
|
|
2335
|
+
wrapInTemplate: pluginConfig.customizations?.broadcasts?.emailPreview?.wrapInTemplate ?? true,
|
|
2336
|
+
customWrapper: pluginConfig.customizations?.broadcasts?.emailPreview?.customWrapper,
|
|
2337
|
+
preheader: doc.contentSection?.preheader,
|
|
2338
|
+
subject: doc.subject,
|
|
2339
|
+
documentData: doc,
|
|
2340
|
+
customBlockConverter: pluginConfig.customizations?.broadcasts?.customBlockConverter
|
|
2341
|
+
}
|
|
2342
|
+
);
|
|
2343
|
+
const createData = {
|
|
2344
|
+
name: doc.subject,
|
|
2345
|
+
subject: doc.subject,
|
|
2346
|
+
preheader: doc.contentSection?.preheader || "",
|
|
2347
|
+
content: htmlContent,
|
|
2348
|
+
trackOpens: doc.settings?.trackOpens ?? true,
|
|
2349
|
+
trackClicks: doc.settings?.trackClicks ?? true,
|
|
2350
|
+
replyTo: doc.settings?.replyTo || providerConfig.replyTo,
|
|
2351
|
+
audienceIds: doc.audienceIds?.map((a) => a.audienceId) || []
|
|
2352
|
+
};
|
|
2353
|
+
const providerBroadcast = await provider.create(createData);
|
|
2354
|
+
req.payload.logger.info(`Broadcast ${doc.id} created in provider with ID ${providerBroadcast.id}`);
|
|
2355
|
+
return {
|
|
2356
|
+
...doc,
|
|
2357
|
+
providerId: providerBroadcast.id,
|
|
2358
|
+
externalId: providerBroadcast.id,
|
|
2359
|
+
providerData: providerBroadcast.providerData
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2393
2362
|
if (!doc.providerId) {
|
|
2394
|
-
req.payload.logger.
|
|
2363
|
+
req.payload.logger.info(`Broadcast ${doc.id} has no providerId and insufficient content for creation - skipping sync`);
|
|
2395
2364
|
return doc;
|
|
2396
2365
|
}
|
|
2397
2366
|
if (doc.providerId) {
|