Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/external-templates-normalization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@codee-sh/medusa-plugin-notification-emails": patch
---

Normalize external template registration to use a single shape
(`templateBlocks` + `translations`) and ensure `getConfig` is
always available for external templates.
39 changes: 36 additions & 3 deletions src/modules/mpn-builder/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,21 @@ class MpnBuilderService extends MedusaService({
const templateModule = await import(
templateValue
)
const template = templateModule.default
// renderer = template?.default || template
renderer = template?.default || templateModule
renderer =
templateModule?.default || templateModule

if (!renderer) {
this.logger_.warn(
`Template module from "${templateValue}" does not export a default function or expected named export`
)
return
}

renderer =
this.normalizeExternalRenderer(
renderer,
templateService
)
} catch (error: any) {
this.logger_.warn(
`Failed to load template from "${templateValue}": ${error?.message || "Unknown error"}`
Expand All @@ -155,6 +160,34 @@ class MpnBuilderService extends MedusaService({
)
}

/**
* Normalize external template modules to match system template shape.
* Ensures getConfig() exists and base template renderers are included.
*/
private normalizeExternalRenderer(
renderer: any,
templateService: BaseTemplateService
) {
if (!renderer) {
return renderer
}

const templateBlocks = renderer.templateBlocks
const translations = renderer.translations

const baseTemplateConfig = (templateService as any)
?.baseTemplateConfig

return {
...(baseTemplateConfig || {}),
...renderer,
getConfig: () => ({
blocks: templateBlocks || [],
translations: translations || {},
}),
}
}

/**
* Get template types
*
Expand Down
6 changes: 6 additions & 0 deletions src/workflows/mpn-builder-services/steps/slack-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export const slackServiceStep = createStep(

let blocks: any[] = []

console.log('templateId', templateId);
console.log('isSystemTemplateId', isSystemTemplateId);
console.log('isExternalTemplateId', isExternalTemplateId);
console.log('isRegistryTemplate', isRegistryTemplate);


// If it's not a registry template, get the blocks from the database
if (!isRegistryTemplate) {
const { result: templateData } = await getTemplateWorkflow(container).run({
Expand Down