Add provider data to notifications (#14104)

## Summary

**What** —
Add a providerData field to notifications

**Why** —
We need the ability to pass dynamic fields to specific providers. E.g. CC and BCC for emails

**How** —
Just adding the field to the model

**Testing** —
Added the field to existing tests

## Checklist

Please ensure the following before requesting a review:

- [x] I have added a **changeset** for this PR
    - Every non-breaking change should be marked as a **patch**
    - To add a changeset, run `yarn changeset` and follow the prompts
- [x] The changes are covered by relevant **tests**
- [x] I have verified the code works as intended locally
- [ ] I have linked the related issue(s) if applicable



---

> [!NOTE]
> Adds `provider_data` to notifications (types, workflow input, DB model/migration) and forwards it in the Medusa Cloud Email provider, with tests updated accordingly.
> 
> - **Data/Schema**:
>   - Add `provider_data` (`jsonb`) to `notification` model and DB via migration `Migration20251121150408` and snapshot update.
> - **Types/DTOs**:
>   - Add optional `provider_data` to `CreateNotificationDTO`, `NotificationDTO`, and `ProviderSendNotificationDTO`.
> - **Workflows**:
>   - Extend `send-notifications` step input with `provider_data`.
> - **Providers**:
>   - Medusa Cloud Email: include `provider_data` in outgoing request payload.
> - **Tests**:
>   - Update integration tests to pass and assert `provider_data` propagation.
> - **Changeset**:
>   - Patch bumps for `@medusajs/notification`, `@medusajs/core-flows`, `@medusajs/types`.
> 
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 6f114c75c974a145ef60213637d7c41bc605a0bf. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
This commit is contained in:
Pedro Guzman
2025-11-24 10:18:47 +01:00
committed by GitHub
parent 113f200a99
commit b81f958d41
11 changed files with 61 additions and 2 deletions

View File

@@ -80,7 +80,8 @@ moduleIntegrationTestRunner<INotificationModuleService>({
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<INotificationModuleService>({
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,

View File

@@ -20,6 +20,9 @@ const testNotification = {
data: {
link: "https://test.com",
},
provider_data: {
cc: "cc@test.com",
},
}
moduleIntegrationTestRunner<INotificationModuleService>({
@@ -58,6 +61,9 @@ moduleIntegrationTestRunner<INotificationModuleService>({
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<INotificationModuleService>({
data: {
link: "https://test.com",
},
provider_data: {
cc: "cc@test.com",
},
})
})

View File

@@ -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",

View File

@@ -0,0 +1,13 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20251121150408 extends Migration {
override async up(): Promise<void> {
this.addSql(`alter table if exists "notification" add column if not exists "provider_data" jsonb null;`);
}
override async down(): Promise<void> {
this.addSql(`alter table if exists "notification" drop column if exists "provider_data";`);
}
}

View File

@@ -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

View File

@@ -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,
}),
})