Skip to content

Commit b81f958

Browse files
authored
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 6f114c7. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
1 parent 113f200 commit b81f958

File tree

11 files changed

+61
-2
lines changed

11 files changed

+61
-2
lines changed

.changeset/stale-suits-lose.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@medusajs/notification": patch
3+
"@medusajs/core-flows": patch
4+
"@medusajs/types": patch
5+
---
6+
7+
add provider_data to notification model

packages/core/core-flows/src/notification/steps/send-notifications.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export type SendNotificationsStepInput = {
3838
* the notification, such as the user's name or the order number.
3939
*/
4040
data?: Record<string, unknown> | null
41+
/**
42+
* Additional data specific to the provider or channel. For example, cc and bcc for emails.
43+
*/
44+
provider_data?: Record<string, unknown> | null
4145
/**
4246
* The type of trigger that caused the notification to be sent. For example, `order_created`.
4347
*/

packages/core/types/src/notification/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export interface NotificationDTO {
6363
* The data that gets passed over to the provider for rendering the notification.
6464
*/
6565
data: Record<string, unknown> | null
66+
/**
67+
* Additional data specific to the provider or channel. For example, cc and bcc for emails.
68+
*/
69+
provider_data?: Record<string, unknown> | null
6670
/**
6771
* The event name, the workflow, or anything else that can help to identify what triggered the notification.
6872
*/

packages/core/types/src/notification/mutations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export interface CreateNotificationDTO {
2727
* The data that gets passed over to the provider for rendering the notification.
2828
*/
2929
data?: Record<string, unknown> | null
30+
/**
31+
* Additional data specific to the provider or channel. For example, cc and bcc for emails.
32+
*/
33+
provider_data?: Record<string, unknown> | null
3034
/**
3135
* The content that gets passed over to the provider.
3236
*/

packages/core/types/src/notification/provider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export type ProviderSendNotificationDTO = {
3030
* The data that gets passed over to the provider for rendering the notification.
3131
*/
3232
data?: Record<string, unknown> | null
33+
/**
34+
* Additional data specific to the provider or channel. For example, cc and bcc for emails.
35+
*/
36+
provider_data?: Record<string, unknown> | null
3337
/**
3438
* The content that gets passed to the provider.
3539
*/

packages/modules/notification/integration-tests/__tests__/notification-module-service/index.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ moduleIntegrationTestRunner<INotificationModuleService>({
8080
8181
template: "some-template",
8282
channel: "email",
83-
data: {},
83+
data: { link: "http://test.com" },
84+
provider_data: { cc: "[email protected]" },
8485
} as CreateNotificationDTO
8586

8687
const result = await service.createNotifications(notification)
@@ -91,7 +92,8 @@ moduleIntegrationTestRunner<INotificationModuleService>({
9192
9293
template: "some-template",
9394
channel: "email",
94-
data: {},
95+
data: { link: "http://test.com" },
96+
provider_data: { cc: "[email protected]" },
9597
provider_id: "test-provider",
9698
external_id: "external_id",
9799
status: NotificationStatus.SUCCESS,

packages/modules/notification/integration-tests/__tests__/notification-module-service/medusa-cloud-email.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const testNotification = {
2020
data: {
2121
link: "https://test.com",
2222
},
23+
provider_data: {
24+
25+
},
2326
}
2427

2528
moduleIntegrationTestRunner<INotificationModuleService>({
@@ -58,6 +61,9 @@ moduleIntegrationTestRunner<INotificationModuleService>({
5861
data: {
5962
link: "https://test.com",
6063
},
64+
provider_data: {
65+
66+
},
6167
provider_id: "cloud",
6268
external_id: "external_id_1",
6369
status: NotificationStatus.SUCCESS,
@@ -79,6 +85,9 @@ moduleIntegrationTestRunner<INotificationModuleService>({
7985
data: {
8086
link: "https://test.com",
8187
},
88+
provider_data: {
89+
90+
},
8291
})
8392
})
8493

packages/modules/notification/src/migrations/.snapshot-medusa-notification.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@
169169
"nullable": true,
170170
"mappedType": "json"
171171
},
172+
"provider_data": {
173+
"name": "provider_data",
174+
"type": "jsonb",
175+
"unsigned": false,
176+
"autoincrement": false,
177+
"primary": false,
178+
"nullable": true,
179+
"mappedType": "json"
180+
},
172181
"trigger_type": {
173182
"name": "trigger_type",
174183
"type": "text",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Migration } from '@mikro-orm/migrations';
2+
3+
export class Migration20251121150408 extends Migration {
4+
5+
override async up(): Promise<void> {
6+
this.addSql(`alter table if exists "notification" add column if not exists "provider_data" jsonb null;`);
7+
}
8+
9+
override async down(): Promise<void> {
10+
this.addSql(`alter table if exists "notification" drop column if exists "provider_data";`);
11+
}
12+
13+
}

packages/modules/notification/src/models/notification.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const Notification = model.define("notification", {
1313
template: model.text().nullable(),
1414
// The data that gets passed over to the provider for rendering the notification.
1515
data: model.json().nullable(),
16+
// Additional data specific to the channel or provider. For example, cc and bcc for emails.
17+
provider_data: model.json().nullable(),
1618
// This can be the event name, the workflow, or anything else that can help to identify what triggered the notification.
1719
trigger_type: model.text().nullable(),
1820
// The ID of the resource this notification is for, if applicable. Useful for displaying relevant information in the UI

0 commit comments

Comments
 (0)