chore(types,notification): Make template nullable on emails (#13889)

* chore: Make template nullable on emails

* Create curvy-lamps-float.md
This commit is contained in:
Oli Juhl
2025-10-29 18:36:06 +01:00
committed by GitHub
parent ef7b9b9375
commit 01ee437926
6 changed files with 61 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/notification": patch
"@medusajs/types": patch
---
chore: Make template nullable on emails

View File

@@ -18,7 +18,7 @@ export interface CreateNotificationDTO {
/**
* The template name in the provider's system.
*/
template: string
template?: string | null
/**
* The data that gets passed over to the provider for rendering the notification.
*/

View File

@@ -108,6 +108,30 @@ moduleIntegrationTestRunner<INotificationModuleService>({
provider_id: "test-provider",
external_id: "external_id",
status: NotificationStatus.SUCCESS,
template: "signup-template",
})
)
expect(dbEntry).not.toHaveProperty("content")
})
it("should send a notification without a template", async () => {
const notification = {
to: "admin@medusa.com",
channel: "email",
content: {
html: "<p>Welcome to medusa</p>",
},
}
const result = await service.createNotifications(notification)
const dbEntry = await service.retrieveNotification(result.id)
expect(dbEntry).toEqual(
expect.objectContaining({
provider_id: "test-provider",
external_id: "external_id",
status: NotificationStatus.SUCCESS,
template: null,
})
)
expect(dbEntry).not.toHaveProperty("content")

View File

@@ -93,6 +93,7 @@
"keyName": "IDX_notification_provider_deleted_at",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_notification_provider_deleted_at\" ON \"notification_provider\" (deleted_at) WHERE deleted_at IS NULL"
@@ -103,12 +104,14 @@
"id"
],
"composite": false,
"constraint": true,
"primary": true,
"unique": true
}
],
"checks": [],
"foreignKeys": {}
"foreignKeys": {},
"nativeEnums": {}
},
{
"columns": {
@@ -145,7 +148,7 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"nullable": true,
"mappedType": "text"
},
"data": {
@@ -284,6 +287,7 @@
"keyName": "IDX_notification_receiver_id",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_notification_receiver_id\" ON \"notification\" (receiver_id) WHERE deleted_at IS NULL"
@@ -292,6 +296,7 @@
"keyName": "IDX_notification_idempotency_key_unique",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_notification_idempotency_key_unique\" ON \"notification\" (idempotency_key) WHERE deleted_at IS NULL"
@@ -300,6 +305,7 @@
"keyName": "IDX_notification_provider_id",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_notification_provider_id\" ON \"notification\" (provider_id) WHERE deleted_at IS NULL"
@@ -308,6 +314,7 @@
"keyName": "IDX_notification_deleted_at",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_notification_deleted_at\" ON \"notification\" (deleted_at) WHERE deleted_at IS NULL"
@@ -318,6 +325,7 @@
"id"
],
"composite": false,
"constraint": true,
"primary": true,
"unique": true
}
@@ -337,7 +345,9 @@
"deleteRule": "set null",
"updateRule": "cascade"
}
}
},
"nativeEnums": {}
}
]
],
"nativeEnums": {}
}

View File

@@ -0,0 +1,15 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20251028172715 extends Migration {
override async up(): Promise<void> {
this.addSql(`alter table if exists "notification" alter column "template" type text using ("template"::text);`);
this.addSql(`alter table if exists "notification" alter column "template" drop not null;`);
}
override async down(): Promise<void> {
this.addSql(`alter table if exists "notification" alter column "template" type text using ("template"::text);`);
this.addSql(`alter table if exists "notification" alter column "template" set not null;`);
}
}

View File

@@ -8,7 +8,7 @@ export const Notification = model.define("notification", {
to: model.text().searchable(),
channel: model.text(),
// The template name in the provider's system.
template: model.text(),
template: model.text().nullable(),
// The data that gets passed over to the provider for rendering the notification.
data: model.json().nullable(),
// This can be the event name, the workflow, or anything else that can help to identify what triggered the notification.