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
5 changes: 5 additions & 0 deletions .changeset/dark-hoops-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codee-sh/medusa-plugin-notification-emails": patch
---

Fix external template rendering for Slack and Email workflows by treating `external_*` IDs as registry templates instead of DB templates. Update docs to clarify template ID resolution.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ module.exports = defineConfig({

Then continue with configuration and usage guides in `docs/`.

Template IDs are resolved by prefix:

- IDs starting with `system` or `external` are rendered from the in-memory registry (no DB lookup).
- Other IDs are treated as DB templates and must exist in `mpn_builder_template`.

## Documentation

- [Configuration](./docs/configuration.md)
Expand Down
5 changes: 5 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ Notes:
- if service id is unknown, template registration is skipped
- registered templates are available as type `external`

Template ID resolution:

- IDs starting with `system` or `external` are rendered from the registry and are not looked up in the database.
- Any other ID is treated as a DB template and must exist in `mpn_builder_template`.

## Minimal complete example

```typescript
Expand Down
8 changes: 5 additions & 3 deletions src/workflows/mpn-builder-services/steps/email-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ export const emailServiceStep = createStep(

const templateId = input.template_id
const isSystemTemplateId = templateId?.startsWith(TEMPLATE_TYPES.SYSTEM_TEMPLATE)
const isExternalTemplateId = templateId?.startsWith(TEMPLATE_TYPES.EXTERNAL_TEMPLATE)
const isRegistryTemplate = isSystemTemplateId || isExternalTemplateId

let blocks: any[] = []
let template: any = {}

// If it's not a system template, get the blocks from the database
if (!isSystemTemplateId) {
// If it's not a registry template, get the blocks from the database
if (!isRegistryTemplate) {
const { result: templateData } = await getTemplateWorkflow(container).run({
input: {
template_id: templateId,
Expand All @@ -68,7 +70,7 @@ export const emailServiceStep = createStep(

const { html, text, subject } =
await templateEmailService.render({
templateName: isSystemTemplateId
templateName: isRegistryTemplate
? templateId
: "base-template",
data: input.data,
Expand Down
8 changes: 5 additions & 3 deletions src/workflows/mpn-builder-services/steps/slack-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ export const slackServiceStep = createStep(

const templateId = input.template_id
const isSystemTemplateId = templateId?.startsWith(TEMPLATE_TYPES.SYSTEM_TEMPLATE)
const isExternalTemplateId = templateId?.startsWith(TEMPLATE_TYPES.EXTERNAL_TEMPLATE)
const isRegistryTemplate = isSystemTemplateId || isExternalTemplateId

let blocks: any[] = []

// If it's not a system template, get the blocks from the database
if (!isSystemTemplateId) {
// If it's not a registry template, get the blocks from the database
if (!isRegistryTemplate) {
const { result: templateData } = await getTemplateWorkflow(container).run({
input: {
template_id: templateId,
Expand All @@ -68,7 +70,7 @@ export const slackServiceStep = createStep(
// TODO CHECK WHY .config is undefined in the prepareData method when using external templates
const { blocks: renderedBlocks } =
await templateSlackService.render({
templateName: isSystemTemplateId
templateName: isRegistryTemplate
? templateId
: "base-template",
data: input.data,
Expand Down