Adds a notifications collection with titles, rich text messages, channels and personal or broadcast audiences. It also registers collections for read receipts, channel subscriptions and push subscriptions, with default access rules and REST endpoints for read state and opt-outs. Web push is optional and needs VAPID keys. Requires Payload 3.37 or newer, React, and a users collection with an admin role.
A PayloadCMS plugin that adds a configurable notifications collection for sending channel-targeted messages with titles and rich text content
Installation
npm i @xtr-dev/payload-notifications1
Stars
0
Forks
0
Open Issues
1 weeks ago
Last Updated
469
Weekly Downloads
v0.3.0
npm Version
289.8 KB
Unpacked Size
2
Dependencies
10 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 1 |
| Dec 4, 2026 | 1 |
| Dec 3, 2026 | 1 |
| Dec 2, 2026 | 1 |
| Dec 1, 2026 | 1 |
| Nov 30, 2026 | 1 |
| Nov 29, 2026 | 1 |
| Nov 28, 2026 | 1 |
| Nov 27, 2026 | 1 |
| Nov 26, 2026 | 1 |
| Nov 25, 2026 | 1 |
| Nov 24, 2026 | 1 |
| Nov 23, 2026 | 1 |
| Nov 22, 2026 | 1 |
| Nov 21, 2026 | 1 |
| Nov 20, 2026 | 1 |
| Nov 19, 2026 | 1 |
| Nov 18, 2026 | 1 |
| Nov 17, 2026 | 1 |
| Nov 16, 2026 | 1 |
| Nov 15, 2026 | 1 |
| Nov 14, 2026 | 1 |
| Nov 13, 2026 | 1 |
| Nov 12, 2026 | 1 |
| Nov 11, 2026 | 1 |
| Nov 10, 2026 | 1 |
| Nov 9, 2026 | 1 |
| Nov 8, 2026 | 1 |
| Nov 7, 2026 | 1 |
| Nov 6, 2026 | 1 |
| Nov 5, 2026 | 1 |
| Nov 4, 2026 | 1 |
| Nov 3, 2026 | 1 |
| Nov 2, 2026 | 1 |
| Nov 1, 2026 | 1 |
| Oct 31, 2026 | 1 |
| Oct 30, 2026 | 1 |
| Oct 29, 2026 | 1 |
| Oct 28, 2026 | 1 |
| Oct 27, 2026 | 1 |
| Oct 26, 2026 | 1 |
| Oct 25, 2026 | 1 |
| Oct 24, 2026 | 1 |
| Oct 23, 2026 | 1 |
| Oct 22, 2026 | 1 |
| Oct 21, 2026 | 1 |
| Oct 20, 2026 | 1 |
| Oct 19, 2026 | 1 |
| Oct 18, 2026 | 1 |
| Oct 17, 2026 | 1 |
| Oct 16, 2026 | 1 |
| Oct 15, 2026 | 1 |
| Oct 14, 2026 | 1 |
| Oct 13, 2026 | 1 |
| Oct 12, 2026 | 1 |
| Oct 11, 2026 | 1 |
| Oct 10, 2026 | 1 |
| Oct 9, 2026 | 1 |
| Oct 8, 2026 | 1 |
| Oct 7, 2026 | 1 |
| Oct 6, 2026 | 1 |
| Oct 5, 2026 | 1 |
| Oct 4, 2026 | 1 |
| Oct 3, 2026 | 1 |
| Oct 2, 2026 | 1 |
| Oct 1, 2026 | 1 |
| Sep 30, 2026 | 1 |
| Sep 29, 2026 | 1 |
| Sep 28, 2026 | 1 |
| Sep 27, 2026 | 1 |
| Sep 26, 2026 | 1 |
| Sep 25, 2026 | 1 |
| Sep 24, 2026 | 1 |
| Sep 23, 2026 | 1 |
| Sep 22, 2026 | 1 |
| Sep 21, 2026 | 1 |
| Sep 20, 2026 | 1 |
| Sep 19, 2026 | 1 |
| Sep 18, 2026 | 1 |
| Sep 17, 2026 | 1 |
| Sep 16, 2026 | 1 |
| Sep 15, 2026 | 1 |
| Sep 14, 2026 | 1 |
| Sep 13, 2026 | 1 |
| Sep 12, 2026 | 1 |
| Sep 11, 2026 | 1 |
| Sep 10, 2026 | 1 |
| Sep 9, 2026 | 1 |
| Sep 8, 2026 | 1 |
| Sep 7, 2026 | 1 |
| Sep 6, 2026 | 1 |
654+619 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 654 |
| Dec 4, 2026 | 813 |
| Dec 3, 2026 | 808 |
| Dec 2, 2026 | 782 |
| Dec 1, 2026 | 825 |
| Nov 30, 2026 | 872 |
| Nov 29, 2026 | 644 |
| Nov 28, 2026 | 498 |
| Nov 27, 2026 | 324 |
| Nov 26, 2026 | 355 |
| Nov 25, 2026 | 385 |
| Nov 24, 2026 | 331 |
| Nov 23, 2026 | 250 |
| Nov 22, 2026 | 147 |
| Nov 21, 2026 | 98 |
| Nov 20, 2026 | 101 |
| Nov 19, 2026 | 97 |
| Nov 18, 2026 | 90 |
| Nov 17, 2026 | 114 |
| Nov 16, 2026 | 162 |
| Nov 15, 2026 | 165 |
| Nov 14, 2026 | 166 |
| Nov 13, 2026 | 210 |
| Nov 12, 2026 | 242 |
| Nov 11, 2026 | 251 |
| Nov 10, 2026 | 227 |
| Nov 9, 2026 | 182 |
| Nov 8, 2026 | 175 |
| Nov 7, 2026 | 181 |
| Nov 6, 2026 | 157 |
| Nov 5, 2026 | 94 |
| Nov 4, 2026 | 58 |
| Nov 3, 2026 | 48 |
| Nov 2, 2026 | 44 |
| Nov 1, 2026 | 43 |
| Oct 31, 2026 | 29 |
| Oct 30, 2026 | 5 |
| Oct 29, 2026 | 5 |
| Oct 28, 2026 | 5 |
| Oct 27, 2026 | 6 |
| Oct 26, 2026 | 20 |
| Oct 25, 2026 | 53 |
| Oct 24, 2026 | 103 |
| Oct 23, 2026 | 103 |
| Oct 22, 2026 | 104 |
| Oct 21, 2026 | 108 |
| Oct 20, 2026 | 107 |
| Oct 19, 2026 | 93 |
| Oct 18, 2026 | 57 |
| Oct 17, 2026 | 6 |
| Oct 16, 2026 | 6 |
| Oct 15, 2026 | 64 |
| Oct 14, 2026 | 103 |
| Oct 13, 2026 | 135 |
| Oct 12, 2026 | 149 |
| Oct 11, 2026 | 162 |
| Oct 10, 2026 | 163 |
| Oct 9, 2026 | 165 |
| Oct 8, 2026 | 107 |
| Oct 7, 2026 | 64 |
| Oct 6, 2026 | 32 |
| Oct 5, 2026 | 22 |
| Oct 4, 2026 | 9 |
| Oct 3, 2026 | 14 |
| Oct 2, 2026 | 17 |
| Oct 1, 2026 | 16 |
| Sep 30, 2026 | 21 |
| Sep 29, 2026 | 30 |
| Sep 28, 2026 | 26 |
| Sep 27, 2026 | 25 |
| Sep 26, 2026 | 22 |
| Sep 25, 2026 | 18 |
| Sep 24, 2026 | 22 |
| Sep 23, 2026 | 17 |
| Sep 22, 2026 | 9 |
| Sep 21, 2026 | 23 |
| Sep 20, 2026 | 25 |
| Sep 19, 2026 | 22 |
| Sep 18, 2026 | 22 |
| Sep 17, 2026 | 21 |
| Sep 16, 2026 | 22 |
| Sep 15, 2026 | 21 |
| Sep 14, 2026 | 7 |
| Sep 13, 2026 | 5 |
| Sep 12, 2026 | 7 |
| Sep 11, 2026 | 11 |
| Sep 10, 2026 | 14 |
| Sep 9, 2026 | 16 |
| Sep 8, 2026 | 21 |
| Sep 7, 2026 | 28 |
| Sep 6, 2026 | 35 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1055701972-root)<a href="https://payloaddirectory.dev/plugins/1055701972-root"><img src="https://payloaddirectory.dev/badge/1055701972-root.svg" alt="Payload Directory"></a>README
A PayloadCMS plugin that adds a notifications collection with titles, rich text messages, channels, per-user channel subscriptions, personal and broadcast audiences, and per-user read state. Web push delivery is optional (see WEBPUSH.md).
v0.x — minor versions may contain breaking changes until 1.0.
pnpm add @xtr-dev/payload-notifications
Requires payload ^3.37.0 and react ^18.2.0 || ^19.0.0. The plugin expects a users collection; users with role === 'admin' get full access.
import { buildConfig } from 'payload'
import { notificationsPlugin } from '@xtr-dev/payload-notifications'
export default buildConfig({
plugins: [
notificationsPlugin({
channels: [
{ id: 'orders', name: 'Order Updates', description: 'Order status and shipping' },
{ id: 'marketing', name: 'Marketing' },
],
}),
],
})
Called without options, notificationsPlugin() uses a single built-in default channel. Passing an empty channels array throws.
| Option | Type | Default | Description |
|---|---|---|---|
channels | NotificationChannel[] ({ id, name, description? }) | one default channel | Choices for a notification's channel, a user's channel subscriptions and a push subscription's channels |
webPush | WebPushConfig | undefined | VAPID keys and push behaviour, see WEBPUSH.md |
collectionOverrides | { notifications?, pushSubscriptions?, notificationReads?, channelSubscriptions? } | undefined | Functions that receive and return each generated CollectionConfig |
recipientEditableFields | string[] | [] | Fields of notifications a recipient may update on their own notification, besides isRead/readAt. See Recipient-editable fields |
notificationsThe slug is fixed.
| Field | Type | Notes |
|---|---|---|
title | text, required | |
message | richText, required | Lexical (or any rich text editor); the default push body is a plain-text excerpt |
recipient | relationship to users | Optional |
audience | select: user | broadcast | Left out on create, it is broadcast without a recipient and user with one. A broadcast cannot have a recipient |
channel | select | One of the configured channel ids |
isRead / readAt | checkbox / date | For broadcasts, reads by a signed-in user return that user's own read state |
Timestamps are on.
notification-readsOne row per user and broadcast they have read, since a broadcast is a single row shared by every user. Users can read and delete their own rows and create rows only for themselves and broadcasts they can see; the read endpoints below do this for them.
channel-subscriptionsOne row per user and channel they made a choice for: user, channel, subscribed. See Channel subscriptions. Users can read, create, update and delete their own rows (a row a non-admin writes always becomes their own); admins can manage all rows.
push-subscriptionsAlways registered, even without web push, so generated types and the database schema do not depend on VAPID keys. Without webPush.enabled it stays empty and only admins can access it. See WEBPUSH.md.
| Operation | Admins (role === 'admin') | Other signed-in users |
|---|---|---|
| read | all | their own (recipient is them) and broadcasts |
| create, delete | yes | no |
| update | all fields | isRead/readAt and the recipientEditableFields of their own personal notifications |
Anonymous requests get nothing. The local API bypasses access control by default, so server code can create notifications freely. A personal notification whose recipient no longer exists stays audience: 'user' and is visible only to admins; an empty recipient is never treated as a broadcast.
Deleting a user through Payload also deletes their personal notifications, read receipts, channel subscriptions and push subscriptions. Deleting a notification deletes its read receipts.
// Personal notification
await payload.create({
collection: 'notifications',
data: {
title: 'Order shipped',
message: {
root: {
type: 'root',
children: [{ type: 'paragraph', children: [{ type: 'text', text: 'Your order is on its way.' }] }],
},
},
recipient: userId,
channel: 'orders',
},
})
// What a user can see, with broadcast read state filled in for them
const { docs } = await payload.find({
collection: 'notifications',
overrideAccess: false,
user,
sort: '-createdAt',
})
POST /api/notifications/:id/read marks a notification read for the signed-in user.DELETE /api/notifications/:id/read marks it unread.Both answer { id, isRead, readAt }. For a personal notification they set isRead/readAt on the notification (only its recipient may); for a broadcast they create or remove that user's notification-reads row, so other users are unaffected. Members cannot PATCH a broadcast.
When a signed-in user finds notifications (REST, GraphQL, or the local API with user), isRead/readAt on broadcasts are filled in from that user's receipts after the query. So where: { isRead: ... } filters broadcasts on the stored flag, not the user's state; query notification-reads for that.
Each user can opt out of (and back into) each configured channel. A user with no stored choice for a channel is subscribed to it, so existing users keep receiving everything until they opt out. A notification without a channel is never affected.
An opt-out is honoured in two places:
autoPush to the notification's recipient, and WebPushManager.sendToRecipient) sends nothing to a recipient who opted out of the notification's channel. This comes on top of the per-device channels of a push subscription, which keeps working as before; see WEBPUSH.md.subscribedChannelsWhere returns a where clause that leaves out the user's opted-out channels, for personal notifications and broadcasts alike.The notification document is always stored, so re-subscribing shows earlier notifications again. Opt-outs are a preference filter, not access control: a user can still read an opted-out notification they have access to by querying without the clause.
All three require a signed-in user and only ever act on that user.
GET /api/channel-subscriptions/me answers { channels: [{ id, name, description?, subscribed }] } with every configured channel.POST /api/channel-subscriptions/me/:channel subscribes; answers { channel, subscribed: true }.DELETE /api/channel-subscriptions/me/:channel opts out; answers { channel, subscribed: false }.An unknown channel id answers 404. Admins can manage other users' rows through the collection's standard REST/GraphQL API or the admin panel.
import {
listChannelSubscriptions,
isSubscribedToChannel,
subscribeToChannel,
unsubscribeFromChannel,
subscribedChannelsWhere,
} from '@xtr-dev/payload-notifications'
await unsubscribeFromChannel({ payload, user, channel: 'marketing' })
await subscribeToChannel({ payload, user, channel: 'marketing' })
await isSubscribedToChannel({ payload, user, channel: 'marketing' }) // true
await listChannelSubscriptions({ payload, user }) // [{ id, name, description?, subscribed }, ...]
// Inbox: what the user may see, minus the channels they opted out of
const { docs } = await payload.find({
collection: 'notifications',
overrideAccess: false,
user,
where: await subscribedChannelsWhere({ payload, user }),
sort: '-createdAt',
})
user is a user document or id. The helpers do not check access (they are for server code); pass req to run inside the request's transaction. setChannelSubscription({ ..., subscribed }) and getUnsubscribedChannels are exported too. Subscribing to an unknown channel throws UnknownChannelError.
If you deliver through other means (email, a custom webPush.findSubscriptions), call isSubscribedToChannel yourself before sending; the plugin cannot know who your custom targets are.
Spread the existing config and hooks so the plugin's own behaviour (audience derivation, read state, auto push) stays in place. Example: send an email when a notification is created.
notificationsPlugin({
channels: [{ id: 'default', name: 'Default' }],
collectionOverrides: {
notifications: (config) => ({
...config,
hooks: {
...config.hooks,
afterChange: [
...(config.hooks?.afterChange ?? []),
async ({ doc, operation, req }) => {
if (operation !== 'create' || !doc.recipient) return
const id = typeof doc.recipient === 'object' ? doc.recipient.id : doc.recipient
const user = await req.payload.findByID({ collection: 'users', id, req })
// Don't throw here, or the notification create fails with the email
await sendEmail({ to: user.email, subject: doc.title }).catch((err) => req.payload.logger.error(err))
},
],
},
}),
},
})
A recipient can update only isRead and readAt on their own notification. Every other field is admin-only for updates, including fields you add through collectionOverrides.notifications. List the fields recipients may change in recipientEditableFields:
notificationsPlugin({
channels: [{ id: 'default', name: 'Default' }],
collectionOverrides: {
notifications: (config) => ({
...config,
fields: [
...config.fields,
{ name: 'archived', type: 'checkbox' },
{ name: 'priority', type: 'text' }, // not listed below: admin-only
{
name: 'preferences',
type: 'group',
fields: [
{ name: 'pinned', type: 'checkbox' },
{ name: 'internalNote', type: 'text' }, // admin-only
],
},
],
}),
},
recipientEditableFields: ['archived', 'preferences.pinned'],
})
'preferences' opens the whole group. Listing a field inside an array or blocks field also lets recipients add and remove its rows.access.update, so it applies to REST, GraphQL and the Local API with overrideAccess: false. As with any Payload field access, a change to a field the user may not update is dropped without an error; the rest of the update goes through.access.update if it has one, and an admin must pass that too. A listed field is left exactly as you defined it.recipient and audience cannot be listed, and a path that matches no field throws when the config is built.| Path | Exports |
|---|---|
@xtr-dev/payload-notifications | notificationsPlugin (also default), the channel subscription helpers, types NotificationsPluginOptions, NotificationChannel, NotificationAudience, PushNotificationContent, WebPushConfig |
@xtr-dev/payload-notifications/client | ClientPushManager, usePushNotifications, serviceWorkerCode, type PushSubscriptionData |
@xtr-dev/payload-notifications/rsc | WebPushManager, createPushNotificationEndpoints, createPushSubscriptionsCollection, types WebPushConfig, PushSubscription, NotificationsPluginOptions |
@xtr-dev/payload-notifications/sw.js | The ready-to-serve service worker file |
Schema: there is a new channel-subscriptions collection. On Postgres/SQLite, create and run a migration, and run payload generate:types. No data needs backfilling: users without rows are subscribed to every channel, as before.
Push: a recipient who opts out of a channel no longer gets default pushes for it. Nobody is opted out until they (or you) store an opt-out.
Breaking: fields added through collectionOverrides.notifications are admin-only for updates. Before, a recipient could update any such field on their own notification unless it had its own access.update. Now recipients can update only isRead/readAt and the paths in recipientEditableFields; other changes they send are dropped. To keep a field editable by recipients, list it: recipientEditableFields: ['archived']. A field with its own access.update that non-admins should pass must be listed too (its own rule then applies unchanged). No schema change.
notifications gains an audience column and there is a new notification-reads collection. On Postgres/SQLite, create and run a migration (payload migrate:create, then payload migrate). Run payload generate:types.audience: rows with an empty audience are visible only to admins. Review rows without a recipient first (some may belong to users who were already deleted), then:
UPDATE notifications SET audience = 'user' WHERE recipient_id IS NOT NULL;
UPDATE notifications SET audience = 'broadcast' WHERE recipient_id IS NULL AND audience IS NULL;
On MongoDB use the equivalent updateMany calls.POST /api/notifications/:id/read instead of PATCH to mark notifications read. To keep the old behaviour, override access via collectionOverrides.notifications.findSubscriptions without a recipient are created as broadcasts. Pass audience: 'user' to make them admin-only.webPush.notificationUrl (default /) and set no icon, badge or actions. See WEBPUSH.md.push-subscriptions is always registered. On Postgres/SQLite, if you never enabled web push, migrate to create its tables. It is admin-only while web push is disabled.isRead/readAt of their own notifications.MIT
Tags
payload plugin notifications
In-site notices with per-kind email copies, user preferences and a retrying send queue
74127/wk0v3
payload plugin notifications
Recipient-scoped notification inbox collection with optional SSE live updates for Payload 3
6015/wk3v3
payload push
Adapter-based push notification sending from Payload, with a Firebase Cloud Messaging adapter
5136/wk2v3
payload plugin notifications
In-dashboard notifications for the Payload admin with a live bell that updates over server-sent events
469/wk7v3
payload
Push publish, update and delete events from Payload to Hibira and refresh Next.js pages automatically
6814/wk0v3
payload plugin sms
Send SMS from Payload through Twilio, Telnyx, Plivo, Vonage or AWS SNS using a single sendSMS call
5380/wk7v3