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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @codee-sh/medusa-plugin-notification-emails

## 1.0.2

### Patch Changes

- bff5e4e: Normalize external template registration to use a single shape
(`templateBlocks` + `translations`) and ensure `getConfig` is
always available for external templates.

## 1.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codee-sh/medusa-plugin-notification-emails",
"version": "1.0.1",
"version": "1.0.2",
"description": "Medusa plugin for notifications emails.",
"author": "Codee Team (https://codee.dev)",
"license": "MIT",
Expand Down
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