Packbase

Notification

Understand the notification objects returned by the inbox API.

Notification

Notification describes one item in the signed-in user's inbox. Fields with a ? are optional. A notification can omit a field when it does not require the field. The endpoint can also omit fields.

interface Notification {
  id: string
  created_at: string
  user_id: string
  type: string
  title: string
  content?: string
  read: boolean
  read_at?: string | null
  metadata?: JsonValue
  related_id?: string | null
}

Field reference

FieldTypeDescription
idstringUUID of the notification.
created_atstringISO 8601 creation timestamp.
user_idstringUUID of the recipient user.
typestringNotification type identifier (e.g. 'follow', 'comment', 'reaction').
titlestringHuman-readable title.
contentstring?Full notification message, when supplied.
readbooleanWhether the notification has been read.
read_atstring | nullISO 8601 timestamp when it was read, or null if unread. May be omitted.
metadataJsonValueOptional context data. Its shape varies by notification type, so check it before use.
related_idstring | nullOptional UUID of the related entity.

Usage example

const { data } = await pb.inbox.fetch({ unreadOnly: true })

for (const notification of data) {
  console.log(`[${notification.type}] ${notification.title}`)
  if (!notification.read) {
    console.log(' → UNREAD')
  }
}

// Mark the notifications in this page as read.
await pb.inbox.markRead(data.map(n => n.id))

Use a separate metadata format for each known notification type. For unknown types, show JSON primitives, arrays, and object keys recursively. Alternatively, show formatted JSON.stringify output. This prevents a new server metadata type from producing a blank notification.

Import

import type { Notification } from '@packbase/sdk-ts'

On this page