diff --git a/.changeset/stale-suits-lose.md b/.changeset/stale-suits-lose.md new file mode 100644 index 0000000000..97c0360d4e --- /dev/null +++ b/.changeset/stale-suits-lose.md @@ -0,0 +1,7 @@ +--- +"@medusajs/notification": patch +"@medusajs/core-flows": patch +"@medusajs/types": patch +--- + +add provider_data to notification model diff --git a/packages/core/core-flows/src/notification/steps/send-notifications.ts b/packages/core/core-flows/src/notification/steps/send-notifications.ts index d111bc029f..c83dab9d48 100644 --- a/packages/core/core-flows/src/notification/steps/send-notifications.ts +++ b/packages/core/core-flows/src/notification/steps/send-notifications.ts @@ -38,6 +38,10 @@ export type SendNotificationsStepInput = { * the notification, such as the user's name or the order number. */ data?: Record | null + /** + * Additional data specific to the provider or channel. For example, cc and bcc for emails. + */ + provider_data?: Record | null /** * The type of trigger that caused the notification to be sent. For example, `order_created`. */ diff --git a/packages/core/types/src/notification/common.ts b/packages/core/types/src/notification/common.ts index 447b2d0ac5..b236bad2aa 100644 --- a/packages/core/types/src/notification/common.ts +++ b/packages/core/types/src/notification/common.ts @@ -63,6 +63,10 @@ export interface NotificationDTO { * The data that gets passed over to the provider for rendering the notification. */ data: Record | null + /** + * Additional data specific to the provider or channel. For example, cc and bcc for emails. + */ + provider_data?: Record | null /** * The event name, the workflow, or anything else that can help to identify what triggered the notification. */ diff --git a/packages/core/types/src/notification/mutations.ts b/packages/core/types/src/notification/mutations.ts index 0ef088d022..87260460e6 100644 --- a/packages/core/types/src/notification/mutations.ts +++ b/packages/core/types/src/notification/mutations.ts @@ -27,6 +27,10 @@ export interface CreateNotificationDTO { * The data that gets passed over to the provider for rendering the notification. */ data?: Record | null + /** + * Additional data specific to the provider or channel. For example, cc and bcc for emails. + */ + provider_data?: Record | null /** * The content that gets passed over to the provider. */ diff --git a/packages/core/types/src/notification/provider.ts b/packages/core/types/src/notification/provider.ts index ff98475376..d44835d7e9 100644 --- a/packages/core/types/src/notification/provider.ts +++ b/packages/core/types/src/notification/provider.ts @@ -30,6 +30,10 @@ export type ProviderSendNotificationDTO = { * The data that gets passed over to the provider for rendering the notification. */ data?: Record | null + /** + * Additional data specific to the provider or channel. For example, cc and bcc for emails. + */ + provider_data?: Record | null /** * The content that gets passed to the provider. */ 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 5f6df79a36..9b386d367a 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 @@ -80,7 +80,8 @@ moduleIntegrationTestRunner({ from: "sender@verified.com", template: "some-template", channel: "email", - data: {}, + data: { link: "http://test.com" }, + provider_data: { cc: "cc@test.com" }, } as CreateNotificationDTO const result = await service.createNotifications(notification) @@ -91,7 +92,8 @@ moduleIntegrationTestRunner({ from: "sender@verified.com", template: "some-template", channel: "email", - data: {}, + data: { link: "http://test.com" }, + provider_data: { cc: "cc@test.com" }, provider_id: "test-provider", external_id: "external_id", status: NotificationStatus.SUCCESS, diff --git a/packages/modules/notification/integration-tests/__tests__/notification-module-service/medusa-cloud-email.spec.ts b/packages/modules/notification/integration-tests/__tests__/notification-module-service/medusa-cloud-email.spec.ts index e71388660b..5ec17efdca 100644 --- a/packages/modules/notification/integration-tests/__tests__/notification-module-service/medusa-cloud-email.spec.ts +++ b/packages/modules/notification/integration-tests/__tests__/notification-module-service/medusa-cloud-email.spec.ts @@ -20,6 +20,9 @@ const testNotification = { data: { link: "https://test.com", }, + provider_data: { + cc: "cc@test.com", + }, } moduleIntegrationTestRunner({ @@ -58,6 +61,9 @@ moduleIntegrationTestRunner({ data: { link: "https://test.com", }, + provider_data: { + cc: "cc@test.com", + }, provider_id: "cloud", external_id: "external_id_1", status: NotificationStatus.SUCCESS, @@ -79,6 +85,9 @@ moduleIntegrationTestRunner({ data: { link: "https://test.com", }, + provider_data: { + cc: "cc@test.com", + }, }) }) diff --git a/packages/modules/notification/src/migrations/.snapshot-medusa-notification.json b/packages/modules/notification/src/migrations/.snapshot-medusa-notification.json index b6a598f273..008d4133e9 100644 --- a/packages/modules/notification/src/migrations/.snapshot-medusa-notification.json +++ b/packages/modules/notification/src/migrations/.snapshot-medusa-notification.json @@ -169,6 +169,15 @@ "nullable": true, "mappedType": "json" }, + "provider_data": { + "name": "provider_data", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, "trigger_type": { "name": "trigger_type", "type": "text", diff --git a/packages/modules/notification/src/migrations/Migration20251121150408.ts b/packages/modules/notification/src/migrations/Migration20251121150408.ts new file mode 100644 index 0000000000..bf1855dc2e --- /dev/null +++ b/packages/modules/notification/src/migrations/Migration20251121150408.ts @@ -0,0 +1,13 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20251121150408 extends Migration { + + override async up(): Promise { + this.addSql(`alter table if exists "notification" add column if not exists "provider_data" jsonb null;`); + } + + override async down(): Promise { + this.addSql(`alter table if exists "notification" drop column if exists "provider_data";`); + } + +} diff --git a/packages/modules/notification/src/models/notification.ts b/packages/modules/notification/src/models/notification.ts index 26b432c9f2..220d53352c 100644 --- a/packages/modules/notification/src/models/notification.ts +++ b/packages/modules/notification/src/models/notification.ts @@ -13,6 +13,8 @@ export const Notification = model.define("notification", { template: model.text().nullable(), // The data that gets passed over to the provider for rendering the notification. data: model.json().nullable(), + // Additional data specific to the channel or provider. For example, cc and bcc for emails. + provider_data: model.json().nullable(), // This can be the event name, the workflow, or anything else that can help to identify what triggered the notification. trigger_type: model.text().nullable(), // The ID of the resource this notification is for, if applicable. Useful for displaying relevant information in the UI diff --git a/packages/modules/notification/src/providers/medusa-cloud-email.ts b/packages/modules/notification/src/providers/medusa-cloud-email.ts index 75df0ba67f..8fe6fe351b 100644 --- a/packages/modules/notification/src/providers/medusa-cloud-email.ts +++ b/packages/modules/notification/src/providers/medusa-cloud-email.ts @@ -39,6 +39,7 @@ export class MedusaCloudEmailNotificationProvider extends AbstractNotificationPr attachments: notification.attachments, template: notification.template, data: notification.data, + provider_data: notification.provider_data, content: notification.content, }), })