From 01ee437926f0a4ec587510c65f8282620bf72d3f Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Wed, 29 Oct 2025 18:36:06 +0100 Subject: [PATCH] chore(types,notification): Make template nullable on emails (#13889) * chore: Make template nullable on emails * Create curvy-lamps-float.md --- .changeset/curvy-lamps-float.md | 6 +++++ .../core/types/src/notification/mutations.ts | 2 +- .../notification-module-service/index.spec.ts | 24 +++++++++++++++++++ .../.snapshot-medusa-notification.json | 18 ++++++++++---- .../src/migrations/Migration20251028172715.ts | 15 ++++++++++++ .../notification/src/models/notification.ts | 2 +- 6 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 .changeset/curvy-lamps-float.md create mode 100644 packages/modules/notification/src/migrations/Migration20251028172715.ts diff --git a/.changeset/curvy-lamps-float.md b/.changeset/curvy-lamps-float.md new file mode 100644 index 0000000000..b24e329b21 --- /dev/null +++ b/.changeset/curvy-lamps-float.md @@ -0,0 +1,6 @@ +--- +"@medusajs/notification": patch +"@medusajs/types": patch +--- + +chore: Make template nullable on emails diff --git a/packages/core/types/src/notification/mutations.ts b/packages/core/types/src/notification/mutations.ts index 3c9a3c33b8..c27249a124 100644 --- a/packages/core/types/src/notification/mutations.ts +++ b/packages/core/types/src/notification/mutations.ts @@ -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. */ diff --git a/packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts b/packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts index 089c5db5c0..bd96ceb425 100644 --- a/packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts +++ b/packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts @@ -108,6 +108,30 @@ moduleIntegrationTestRunner({ 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: "

Welcome to medusa

", + }, + } + + 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") diff --git a/packages/modules/notification/src/migrations/.snapshot-medusa-notification.json b/packages/modules/notification/src/migrations/.snapshot-medusa-notification.json index 3a6ea7b7f7..11a701ae74 100644 --- a/packages/modules/notification/src/migrations/.snapshot-medusa-notification.json +++ b/packages/modules/notification/src/migrations/.snapshot-medusa-notification.json @@ -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": {} } diff --git a/packages/modules/notification/src/migrations/Migration20251028172715.ts b/packages/modules/notification/src/migrations/Migration20251028172715.ts new file mode 100644 index 0000000000..62ae337758 --- /dev/null +++ b/packages/modules/notification/src/migrations/Migration20251028172715.ts @@ -0,0 +1,15 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20251028172715 extends Migration { + + override async up(): Promise { + 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 { + 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;`); + } + +} diff --git a/packages/modules/notification/src/models/notification.ts b/packages/modules/notification/src/models/notification.ts index 4b178beeb8..dd22c75706 100644 --- a/packages/modules/notification/src/models/notification.ts +++ b/packages/modules/notification/src/models/notification.ts @@ -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.