API reference for the @novu/js package
Complete API reference for the Novu JavaScript package
Novu
The Novu client provides methods to interact with notifications, preferences, and real-time events.
Constructor Options
Prop | Type | Default |
---|---|---|
applicationIdentifier? | string | - |
subscriberId? | string | - |
subscriberHash? | string | - |
backendUrl? | string | - |
apiUrl? | string | - |
socketUrl? | string | - |
useCache? | boolean | - |
Usage
Notifications
Methods
list
Fetches a list of notifications based on provided filters.
Prop | Type | Default |
---|---|---|
tags? | string[] | - |
read? | boolean | - |
archived? | boolean | - |
The response will be of type:
Prop | Type | Default |
---|---|---|
notifications? | Notification[] | - |
hasMore? | boolean | - |
filter? | NotificationFilter | - |
count
Fetches the count of notifications based on filters.
Prop | Type | Default |
---|---|---|
tags? | string[] | - |
read? | boolean | - |
archived? | boolean | - |
read
Marks a notification as read.
unread
Marks a notification as unread.
archive
Archives a notification.
unarchive
Unarchives a notification.
readAll
Marks all notifications as read. Can be filtered by tags.
archiveAll
Archives all notifications. Can be filtered by tags.
archiveAllRead
Archives all read notifications. Can be filtered by tags.
completePrimary
Marks primary action of a notification as completed.
completeSecondary
Marks secondary action of a notification as completed.
revertPrimary
Reverts primary action of a notification to pending.
revertSecondary
Reverts secondary action of a notification to pending.
Preferences
Methods
list
Fetches the subscriber's notification preferences.
The response will be of type:
Prop | Type | Default |
---|---|---|
level? | PreferenceLevel | - |
enabled? | boolean | - |
channels? | ChannelPreference | - |
overrides? | IPreferenceOverride[] | - |
workflow? | Workflow | - |
update
Updates channel preferences for a specific workflow or globally.
Prop | Type | Default |
---|---|---|
email? | boolean | - |
sms? | boolean | - |
in_app? | boolean | - |
chat? | boolean | - |
push? | boolean | - |
Events
The Novu client provides real-time event handling through WebSocket connections.
Available Events
notifications.notification_received
: Triggered when a new notification is receivednotifications.unread_count_changed
: Triggered when the unread count changes
Usage
Types
Notification
Prop | Type | Default |
---|---|---|
id? | string | - |
subject? | string | - |
body? | string | - |
to? | Subscriber | - |
isRead? | boolean | - |
isArchived? | boolean | - |
createdAt? | string | - |
readAt? | string | - |
archivedAt? | string | - |
avatar? | string | - |
primaryAction? | Action | - |
secondaryAction? | Action | - |
channelType? | ChannelType | - |
tags? | string[] | - |
redirect? | Redirect | - |
data? | Record<string, unknown> | - |
read? | () => Result<Notification, NovuError> | - |
unread? | () => Result<Notification, NovuError> | - |
archive? | () => Result<Notification, NovuError> | - |
unarchive? | () => Result<Notification, NovuError> | - |
completePrimary? | () => Result<Notification, NovuError> | - |
completeSecondary? | () => Result<Notification, NovuError> | - |
revertPrimary? | () => Result<Notification, NovuError> | - |
revertSecondary? | () => Result<Notification, NovuError> | - |
on? | <Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => () => void | - |
off? | <Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => void | - |
Action
Prop | Type | Default |
---|---|---|
label? | string | - |
isCompleted? | boolean | - |
redirect? | Redirect | - |
NotificationButton
Prop | Type | Default |
---|---|---|
PRIMARY? | NotificationButton.PRIMARY | - |
SECONDARY? | NotificationButton.SECONDARY | - |
Subscriber
Prop | Type | Default |
---|---|---|
id? | string | - |
firstName? | string | - |
lastName? | string | - |
avatar? | string | - |
subscriberId? | string | - |