@medusajs/notification 2.22.0-snapshot-20261020204851 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/AGENTS.md +73 -0
  2. package/README.md +119 -1
  3. package/package.json +8 -4
package/AGENTS.md ADDED
@@ -0,0 +1,73 @@
1
+ # @medusajs/notification
2
+
3
+ Notification Module (`Modules.NOTIFICATION`): infrastructure module that records notifications and sends them through the provider registered for each channel (e.g. `email`, `feed`, `sms`).
4
+
5
+ ## Using this package
6
+
7
+ - Registered by default as `@medusajs/medusa/notification` with `@medusajs/medusa/notification-local` (id `local`, `channels: ["feed"]`). Other providers: `@medusajs/medusa/notification-sendgrid` (`packages/modules/providers/notification-*`).
8
+ - Options (`NotificationModuleOptions` in `src/types/index.ts`): `providers[]` of `{ resolve, id, options: { channels: string[], ...providerOptions } }`, plus private `cloud` (`api_key`, `endpoint`, `environment_handle`, `sandbox_handle`) injected by `defineConfig` on Medusa Cloud.
9
+
10
+ ```ts
11
+ module.exports = defineConfig({
12
+ modules: [
13
+ {
14
+ resolve: "@medusajs/medusa/notification",
15
+ options: {
16
+ providers: [
17
+ {
18
+ resolve: "@medusajs/medusa/notification-sendgrid",
19
+ id: "sendgrid",
20
+ options: {
21
+ channels: ["email"],
22
+ api_key: process.env.SENDGRID_API_KEY,
23
+ from: process.env.SENDGRID_FROM,
24
+ },
25
+ },
26
+ ],
27
+ },
28
+ },
29
+ ],
30
+ })
31
+ ```
32
+
33
+ - Resolve: `container.resolve(Modules.NOTIFICATION)` (`INotificationModuleService`). In workflows use `sendNotificationsStep` from `@medusajs/medusa/core-flows`.
34
+
35
+ ```ts
36
+ await notificationModuleService.createNotifications({
37
+ to: "customer@example.com",
38
+ channel: "email",
39
+ template: "order-placed",
40
+ data: { order_id: order.id },
41
+ })
42
+ ```
43
+
44
+ **Data models**: `Notification` (`noti_`: `to`, `from`, `channel`, `template`, `data`, `provider_data`, `trigger_type`, `resource_id`, `resource_type`, `receiver_id`, `original_notification_id`, `idempotency_key` (unique), `external_id`, `status` pending / success / failure) and `NotificationProvider` (`id`, `handle`, `name`, `is_enabled`, `channels`). Only `Notification` gets generated `MedusaService` methods.
45
+
46
+ **Custom method**: `createNotifications(data | data[])` (overrides the generated one) creates, sends and updates status in one call. No custom events beyond the generated `notification.notification.*` ones; no module links.
47
+
48
+ Docs: https://docs.medusajs.com/resources/infrastructure-modules/notification.md, https://docs.medusajs.com/resources/infrastructure-modules/notification/send-notification.md, https://docs.medusajs.com/resources/infrastructure-modules/notification/local.md, https://docs.medusajs.com/resources/infrastructure-modules/notification/sendgrid.md
49
+
50
+ ## Architecture
51
+
52
+ - `src/loaders/providers.ts`: registers each provider as `np_<id>` and syncs the `notification_provider` table (`id`/`handle`/`name` = config `id`, `channels` from `options.channels`); DB providers not in config are set `is_enabled: false`.
53
+ - If no configured provider declares the `email` channel and `cloud` has `api_key`, `endpoint` and an `environment_handle` or `sandbox_handle`, the Medusa Cloud email provider (`src/providers/medusa-cloud-email.ts`) is added with id `cloud` and `channels: ["email"]`.
54
+ - `src/services/notification-provider.ts` resolves the provider for each channel and calls its `send`.
55
+
56
+ ## Development
57
+
58
+ ```bash
59
+ cd packages/modules/notification
60
+ yarn build
61
+ yarn test
62
+ yarn test:integration # needs Postgres
63
+ ../../../node_modules/.bin/jest integration-tests/__tests__/notification-module-service/index.spec.ts
64
+ yarn migration:create # after any change in src/models
65
+ ```
66
+
67
+ - Integration tests: `integration-tests/__tests__/notification-module-service/` (`index.spec.ts`, `medusa-cloud-email.spec.ts`).
68
+
69
+ ## Gotchas
70
+
71
+ - Boot fails with "Multiple providers are configured for the same channel: <channel>" if two providers share a channel; a provider entry without `id` also throws.
72
+ - Idempotency: a notification whose `idempotency_key` already exists is skipped unless the existing one has `status: failure`, in which case it is re-sent (and updated, not re-created). Not race-safe (see TODO in `createNotifications`).
73
+ - Records are created before sending. If no enabled provider handles the channel, or `send` fails, the notification is saved with `status: failure` and the call throws (errors aggregated across the batch).
package/README.md CHANGED
@@ -1 +1,119 @@
1
- # Notification Module
1
+ <p align="center">
2
+ <a href="https://www.medusajs.com">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
6
+ <img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
7
+ </picture>
8
+ </a>
9
+ </p>
10
+ <h1 align="center">
11
+ @medusajs/notification
12
+ </h1>
13
+
14
+ <h4 align="center">
15
+ <a href="https://docs.medusajs.com">Documentation</a> |
16
+ <a href="https://www.medusajs.com">Website</a>
17
+ </h4>
18
+
19
+ <p align="center">
20
+ Building blocks for digital commerce
21
+ </p>
22
+ <p align="center">
23
+ <a href="https://github.com/medusajs/medusa/blob/develop/LICENSE">
24
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
25
+ </a>
26
+ <a href="https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md">
27
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
28
+ </a>
29
+ <a href="https://discord.gg/xpCwq3Kfn8">
30
+ <img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
31
+ </a>
32
+ <a href="https://twitter.com/intent/follow?screen_name=medusajs">
33
+ <img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
34
+ </a>
35
+ </p>
36
+
37
+ Notification Module for Medusa: sends notifications through channels such as email, SMS, or an in-app feed, and stores a record of each notification and the providers that send them. Each channel is handled by a Notification Module Provider, and only one provider can be configured per channel. It ships with `@medusajs/medusa` and is registered by default; resolve it in your code with `container.resolve(Modules.NOTIFICATION)`.
38
+
39
+ ## At a glance
40
+
41
+ | | |
42
+ | --- | --- |
43
+ | Package | `@medusajs/notification` |
44
+ | Type | Infrastructure Module |
45
+ | Module key | `Modules.NOTIFICATION` (`"notification"`) |
46
+ | Registered by default | Yes (with the Local provider on the `feed` channel) |
47
+
48
+ ## Providers
49
+
50
+ Official providers:
51
+
52
+ | Package | Register with |
53
+ | --- | --- |
54
+ | [`@medusajs/notification-local`](../providers/notification-local) | `@medusajs/medusa/notification-local` |
55
+ | [`@medusajs/notification-sendgrid`](../providers/notification-sendgrid) | `@medusajs/medusa/notification-sendgrid` |
56
+
57
+ On Medusa Cloud, a built-in Medusa Cloud email provider is registered automatically when no provider handles the `email` channel.
58
+
59
+ ## Installation
60
+
61
+ No installation needed. The module ships with `@medusajs/medusa`.
62
+
63
+ ## Usage
64
+
65
+ Register providers in `medusa-config.ts`. Overriding `providers` replaces the default list:
66
+
67
+ ```ts
68
+ import { defineConfig } from "@medusajs/framework/utils"
69
+
70
+ module.exports = defineConfig({
71
+ // ...
72
+ modules: [
73
+ {
74
+ resolve: "@medusajs/medusa/notification",
75
+ options: {
76
+ providers: [
77
+ {
78
+ resolve: "@medusajs/medusa/notification-sendgrid",
79
+ id: "sendgrid",
80
+ options: {
81
+ channels: ["email"],
82
+ api_key: process.env.SENDGRID_API_KEY,
83
+ from: process.env.SENDGRID_FROM,
84
+ },
85
+ },
86
+ ],
87
+ },
88
+ },
89
+ ],
90
+ })
91
+ ```
92
+
93
+ Then send a notification:
94
+
95
+ ```ts
96
+ import { Modules } from "@medusajs/framework/utils"
97
+
98
+ const notificationModuleService = container.resolve(Modules.NOTIFICATION)
99
+
100
+ await notificationModuleService.createNotifications({
101
+ to: "customer@example.com",
102
+ channel: "email",
103
+ template: "order-placed",
104
+ data: { order_id: "order_123" },
105
+ })
106
+ ```
107
+
108
+ ## Configuration
109
+
110
+ | Option | Type | Description | Default |
111
+ | --- | --- | --- | --- |
112
+ | `providers` | `{ resolve: string, id: string, options: { channels: string[], ... } }[]` | Notification providers to register. `options.channels` lists the channels the provider handles; two providers can't share a channel. | Local provider (`id: "local"`, `channels: ["feed"]`) |
113
+
114
+ ## Resources
115
+
116
+ - [Notification Module](https://docs.medusajs.com/resources/infrastructure-modules/notification)
117
+ - [Send a Notification](https://docs.medusajs.com/resources/infrastructure-modules/notification/send-notification)
118
+ - [Local Notification Module Provider](https://docs.medusajs.com/resources/infrastructure-modules/notification/local)
119
+ - [SendGrid Notification Module Provider](https://docs.medusajs.com/resources/infrastructure-modules/notification/sendgrid)
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@medusajs/notification",
3
- "version": "2.22.0-snapshot-20261020204851",
3
+ "version": "2.22.0",
4
4
  "description": "Medusa Notification module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "dist",
9
+ "AGENTS.md",
9
10
  "!dist/**/__tests__",
10
11
  "!dist/**/__mocks__",
11
12
  "!dist/**/__fixtures__"
12
13
  ],
14
+ "llms": "https://docs.medusajs.com/llms.txt",
15
+ "llmsFull": "https://docs.medusajs.com/llms-full.txt",
16
+ "mcpServer": "https://docs.medusajs.com/mcp",
13
17
  "engines": {
14
18
  "node": ">=22.22.0"
15
19
  },
@@ -39,10 +43,10 @@
39
43
  "orm:cache:clear": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts MIKRO_ORM_ALLOW_GLOBAL_CLI=true medusa-mikro-orm cache:clear"
40
44
  },
41
45
  "devDependencies": {
42
- "@medusajs/framework": "2.22.0-snapshot-20261020204851",
43
- "@medusajs/test-utils": "2.22.0-snapshot-20261020204851"
46
+ "@medusajs/framework": "2.22.0",
47
+ "@medusajs/test-utils": "2.22.0"
44
48
  },
45
49
  "peerDependencies": {
46
- "@medusajs/framework": "2.22.0-snapshot-20261020204851"
50
+ "@medusajs/framework": "2.22.0"
47
51
  }
48
52
  }