npm.io
2.22.7 • Published 4d ago

@medusajs/notification

Licence
MIT
Version
2.22.7
Deps
0
Size
80 kB
Vulns
0
Weekly
0
Stars
36.7K

Medusa logo

@medusajs/notification

Documentation | Website

Building blocks for digital commerce

Medusa is released under the MIT license. PRs welcome! Discord Chat Follow @medusajs

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).

At a glance

Package @medusajs/notification
Type Infrastructure Module
Module key Modules.NOTIFICATION ("notification")
Registered by default Yes (with the Local provider on the feed channel)

Providers

Official providers:

Package Register with
@medusajs/notification-local @medusajs/medusa/notification-local
@medusajs/notification-sendgrid @medusajs/medusa/notification-sendgrid

On Medusa Cloud, a built-in Medusa Cloud email provider is registered automatically when no provider handles the email channel.

Installation

No installation needed. The module ships with @medusajs/medusa.

Usage

Register providers in medusa-config.ts. Overriding providers replaces the default list:

import { defineConfig } from "@medusajs/framework/utils"

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/medusa/notification",
      options: {
        providers: [
          {
            resolve: "@medusajs/medusa/notification-sendgrid",
            id: "sendgrid",
            options: {
              channels: ["email"],
              api_key: process.env.SENDGRID_API_KEY,
              from: process.env.SENDGRID_FROM,
            },
          },
        ],
      },
    },
  ],
})

Then send a notification:

import { Modules } from "@medusajs/framework/utils"

const notificationModuleService = container.resolve(Modules.NOTIFICATION)

await notificationModuleService.createNotifications({
  to: "customer@example.com",
  channel: "email",
  template: "order-placed",
  data: { order_id: "order_123" },
})

Configuration

Option Type Description Default
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"])

Resources