[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationCategories and subjects

Categories and subjects

Every notification is filed under a subject, and every subject belongs to a category.

Every notification is filed under a subject, and every subject belongs to a category. The notification settings screen groups by these two levels, and the DMS keys user preferences on them. A preference entry exists per categoryId:subjectId pair.

You declare categories and subjects by calling NotificationCategory() and NotificationSubject(). Both calls register the declaration with the DMS and return the info object, which you keep as a module-level constant. You pass the category constant to NotificationSubject(), and the subject constant to the builder's .subject() when you send.

Declarations are function calls, not decorators. They run when the module that contains them is imported. Declare them at the top level of a module that is imported during startup, so the taxonomy is complete before the first notification is sent.

The Notification preferences walkthrough shows the System category expanded to its subjects, and describes the locked General subject in prose. The Email column holds a switch for each subject that offers e-mail once a module registers the e-mail channel, and is marked Soon otherwise (see E-mail). These switches control notifications, not the transactional authentication emails.

Declaring a category

NotificationCategory(id, category) registers a category and returns the resulting NotificationCategoryInfo.

typescript
import { NotificationCategory } from "@antelopejs/interface-dms/notifications";

export const shopCategory = NotificationCategory("shop", {
  labelKey: "shop.notifications.categories.shop",
  descriptionKey: "shop.notifications.categories.shop_desc",
  icon: "i-ph-shopping-cart",
});
ParameterDescription
idIdentifier of the category. It is the first half of every preference key under this category.
categoryEvery field of NotificationCategoryInfo except id.

NotificationCategoryInfo

OptionTypeDescription
idstringCategory identifier. Supplied through the first argument of NotificationCategory().
labelKeystringTranslation key for the category name.
descriptionKeystring (optional)Translation key for a longer description.
iconstringIcon name, in the icon syntax the dashboard uses, for example i-ph-shopping-cart.
togglePermissionTogglePermission (optional)The parent stance the DMS reads when it decides whether a subject of this category is locked. It does not lock the category's own switch by itself.
tagKeystring (optional)Translation key of a short module tag, for example SaaS. The settings screen shows it next to the category, and the inbox shows it on each notification of the category. Without it, the inbox tags a notification with its subject's label.

The DMS ignores a second category registered with an id that is already taken. The first declaration wins.

Declaring a subject

NotificationSubject(id, subject) registers a subject under an already registered category and returns the resulting NotificationSubjectInfo.

typescript
import {
  NotificationCategory,
  NotificationSubject,
} from "@antelopejs/interface-dms/notifications";

export const shopCategory = NotificationCategory("shop", {
  labelKey: "shop.notifications.categories.shop",
  icon: "i-ph-shopping-cart",
});

export const orderSubject = NotificationSubject("orders", {
  category: shopCategory,
  labelKey: "shop.notifications.subjects.orders",
  descriptionKey: "shop.notifications.subjects.orders_desc",
  togglePermission: "default",
});

export const stockSubject = NotificationSubject("stock", {
  category: shopCategory,
  labelKey: "shop.notifications.subjects.stock",
  togglePermission: "allowed",
});
ParameterDescription
idIdentifier of the subject. It is unique within its category, not across categories, because the preference key is categoryId:subjectId.
subjectEvery field of NotificationSubjectInfo except id.

NotificationSubjectInfo

OptionTypeDescription
idstringSubject identifier, unique within the category. Supplied through the first argument of NotificationSubject().
categoryNotificationCategoryInfoThe category this subject belongs to, as returned by NotificationCategory().
labelKeystringTranslation key for the subject name.
descriptionKeystring (optional)Translation key for a longer description.
togglePermissionTogglePermission (optional)Whether users may turn this subject off. The DMS reads it together with the category's value.
badgeKeystring (optional)Translation key of a badge that the settings screen shows next to the subject label, for example Developer mode.
emailboolean | { defaultOn?: boolean } (optional)Whether the subject also reaches its recipients by e-mail: true (off until the user turns it on) or { defaultOn: true } (on until the user turns it off). In-app only when unset. See E-mail.

A subject carries the whole category object, not only its id, so subject.category.id is always available from a subject you hold. A send uses it to build the preference key from the subject you passed to the builder.

The DMS ignores a second subject registered with an id already taken inside the same category, as it does for categories.

Declaration order

The DMS must have the category registered before any of its subjects. It refuses a subject whose category is not registered yet with the error Category "<id>" is not registered. Register the category before its subjects. The subject never enters the registry, so the DMS drops everything sent under it. Registrations run in call order, so declaring the category above its subjects in the same file is enough, as in the example above.

Registrations belong to the module that made them. When that module is unloaded, the DMS unregisters its categories and subjects.

Toggle permissions

TogglePermission controls whether a user may opt out of a subject.

typescript
type TogglePermission = "allowed" | "forbidden" | "default";

The field is optional on both NotificationCategoryInfo and NotificationSubjectInfo. A subject is locked only when both of these conditions hold:

  • the subject declares togglePermission: "forbidden";
  • its category declares togglePermission as "default" or "forbidden".

Every other combination leaves the subject toggleable. The value on a category acts only as the parent half of this rule. The settings screen disables a category's own switch only when every subject in it is locked, because the switch then has nothing to change.

ValueMeaning on a subjectMeaning on a category
"forbidden"The subject is locked, provided the category declares "default" or "forbidden".Allows the subject-side lock.
"default"The subject stays toggleable.Allows the subject-side lock, the same as "forbidden".
"allowed"The subject stays toggleable, the same as "default".Leaves every subject toggleable, the same as omitting the field.

A locked subject behaves the same way everywhere:

  • The settings screen shows its switch disabled, with a hint.
  • The preferences route refuses a change that turns it off, with HTTP 403, in the app or by e-mail when it offers e-mail.
  • Every dispatch method delivers it whatever preference the user has stored for it, by e-mail too when it offers e-mail.

For a notification a user must always receive, declare togglePermission: "forbidden" on the subject and togglePermission: "default" on its category. SystemCategory declares "default", which is what makes GeneralSubject mandatory.

typescript
import {
  NotificationCategory,
  NotificationSubject,
} from "@antelopejs/interface-dms/notifications";

export const alertCategory = NotificationCategory("alerts", {
  labelKey: "shop.notifications.categories.alerts",
  icon: "i-ph-warning",
  togglePermission: "default",
});

export const outageSubject = NotificationSubject("outage", {
  category: alertCategory,
  labelKey: "shop.notifications.subjects.outage",
  togglePermission: "forbidden",
});

Without togglePermission: "default" on alertCategory, outageSubject would stay toggleable. See Delivery rules for how a send reads the user's preference.

Read scope

ReadScope describes how the read state of a multi-recipient notification behaves.

typescript
type ReadScope = "individual" | "shared";
ValueMeaning
"individual"Each recipient gets their own copy with its own read state. This is the default.
"shared"The DMS groups the copies. Once one recipient reads the notification, it counts as read for the whole group.

You choose the scope per send, not per subject. You pass it through SendOptions on the multi-recipient dispatch methods. See Send options.

Built-in categories and subjects

The DMS declares one category and five subjects of its own. When your notification fits one of them, import it and pass it to .subject() instead of declaring a near-duplicate.

typescript
import {
  AccountSubject,
  AutomationSubject,
  CollaborationSubject,
  GeneralSubject,
  SecuritySubject,
  SystemCategory,
} from "@antelopejs/interface-dms/notifications";

SystemCategory is the category of all five subjects. Its id is system, its icon is i-ph-gear, and its togglePermission is "default". That parent value lets the "forbidden" on GeneralSubject take effect.

ConstantIdToggle permissionUsed for
GeneralSubjectgeneral"forbidden"Unclassified platform messages. Users cannot opt out.
SecuritySubjectsecurity"default"Sign-ins, password and email changes, two-factor changes, backup-code regeneration.
AccountSubjectaccount"default"Account lifecycle messages, such as the welcome notification.
CollaborationSubjectcollaboration"default"Messages about other people in the workspace, such as a collaborator joining.
AutomationSubjectautomation"default"Messages that automations send.

Their labels and descriptions use the dms.notifications.* translation keys that ship with the DMS.

Importing the types

The interface root exports the declaration functions, the built-in constants and every type of the domain. The types subpath exports the types alone.

SymbolImport from
NotificationCategory, NotificationSubject, SystemCategory, GeneralSubject, SecuritySubject, AccountSubject, CollaborationSubject, AutomationSubject@antelopejs/interface-dms/notifications
NotificationCategoryInfo, NotificationSubjectInfo, NotificationTone, TogglePermission, ReadScope@antelopejs/interface-dms/notifications or @antelopejs/interface-dms/notifications/types
typescript
import type { NotificationSubjectInfo } from "@antelopejs/interface-dms/notifications/types";

interface NotificationTemplate {
  icon: string;
  subject: NotificationSubjectInfo;
  linkTo: string;
}

A type such as NotificationSubjectInfo lets a template table or a helper function accept any subject, built-in or your own.

Next steps

  • Sending notifications covers building a notification under a subject and dispatching it to users, roles, or everyone.