Skip to main content

Module: NotificationClient

Used to send, receive and manipulate notifications

Enumerations

Classes

Interfaces

Type Aliases

INotification

Ƭ INotification: Object

description Interface to define what structure the Finsemble notification service is able to process

Type declaration

NameTypeDescription
actions?(IAction | IAction[])[]A list of Actions and/or Action Groups. An action can be a single action (IAction), or an action group (IAction[]). An action group is a collection of related actions grouped together as a single element.
actionsHistory?IPerformedAction[]list of actions which have been performed on a notification.
contentLogo?stringLogo to display in content section of a notification.HTML source data URI or URL. Defaults set by type in configuration.
cssClassName?stringAllows a css class to be applied to a notification to change it's appearance.
details?stringDetails about the notification mainly for display purposes.
devModeOnly?booleanA flag to determine whether the notification is to be displayed only if Finsemble is running in dev mode.
headerLogo?stringLogo displayed in header section of a notification. HTML source data URI or URL. Defaults set by type in configuration.
headerText?stringAn informational header additional to the title usually referencing the source. Deprecated: Not used since 5.3 and expected to be removed in version 6.0 deprecated - Not used in 5.3 and expected to be removed in version 6.0
id?stringEither set when notification is created to refer to id an external system or if null set to UUID.
isDeletedbooleanPrivate: Indicating a notification has been deleted
isMutedbooleanPrivate: If a Notification has been muted after being received
isReadbooleanPrivate: If an notification has been marked as read.
isSnoozedbooleanPrivate: Indicating a notification is currently snoozed
issuedAtstringISO8601 date formatted string. When the notification was generated.
meta?MetaAdditional metadata to be passed along with a notification. Supports arbitrary metadata fields. For example, a team may decide to include a Source or Channel field in all notifications to support filtering operations, or a Quote or Customer ID field to support grouping of notifications generated by different systems but relating to the same entity (for example for filtering/drill down in the Notification Center).
notificationAlertSound?string-
receivedAt?stringPrivate: ISO8601 date formatted string. When the notification was received by Finsemble
source?stringThe source that the notification originated from
stateHistoryINotification[]-
timeout?numberThe number of milliseconds the notification should appear in the UIs.
titlestringMain display title
type?stringThe type of notification.

INotificationHistoryOptions

Ƭ INotificationHistoryOptions: Object

Type declaration

NameTypeDescription
pageNumber?numberThe page number
pageSize?numberThe number of notifications to fetch
sentAfter?stringISO8601 date formatted string. Fetch (from) notifications sent after this date
sentBefore?stringISO8601 date formatted string. Fetch (from) notifications sent before this date

NotificationServiceConfig

Ƭ NotificationServiceConfig: Object

Type declaration

NameType
defaultSnoozePeriodSecondsnumber
disableDotOnToolbarIconboolean
informationalNotificationToastPeriodSecondsnumber
newNotificationHaloPeriodSecondsnumber
showDotOnToolbarIconForMutedNotificationsboolean
toastTimeoutOnActionableNotificationsboolean

Functions

deleteNotifications

deleteNotifications(notifications): Promise<void>

Deletes a notification

All clients subscribed to receive the updated notifications will be sent the new state.

Parameters

NameTypeDescription
notificationsINotification[]The notifications to delete

Returns

Promise<void>


fetchHistory

fetchHistory(options?, filter?): Promise<INotification[]>

Fetches all the notifications sent to Finsemble after a specific date.

let lastMonth = new Date();
lastMonth.setMonth(lastMonth.getMonth() - 1);

const notifications = await FSBL.Clients.NotificationClient.fetchHistory({
sentAfter: lastMonth.toISOString(),
});

Get notifications sent between now and one month ago that matches a filter.

const lastMonth = new Date();
lastMonth.setMonth(lastMonth.getMonth() - 1);

const filter = new FSBL.Clients.NotificationClient.Filter();

// include all notifications from the OMS
filter.include.push({ source: "order-management-system" });

// But exclude informational notifications from the OMS
filter.exclude.push({
source: "order-management-system",
type: "informational",
});
const notifications = await FSBL.Clients.NotificationClient.fetchHistory(
{
sentAfter: lastMonth.toISOString(),
},
filter,
);

throws Error throws an error on par with the Promise standard, containing detail why the request did not complete

Get notifications sent between now and one month ago

Parameters

NameTypeDescription
options?string | INotificationHistoryOptionsAn options object or an ISO8601 formatted date string.
filter?IFilterto match to notifications.

Returns

Promise<INotification[]>

array of notifications.


getLastIssuedAt

getLastIssuedAt(source?): Promise<string>

Return an ISO8601 date a notification matching the specified source was issued. If no source is provided it will get the latest issue date for all notifications (i.e the last time any notification was issue to the service)

If you're sending notifications to Finsemble from an external source, you might want to know when the last Notification of that type was received by Finsemble, so you're able to send any pending ones to the user's desktop

// Get the last date Finsemble received a notification sent with the source field set to "product-update-service"
const lastIssuedDate = await FSBL.Clients.NotificationClient.getLastIssuedAt(
"product-update-service",
);

throws Error throws an error on par with the Promise standard, containing detail why the request did not complete

Parameters

NameTypeDescription
source?stringto identify which notification to save lastUpdated time for.

Returns

Promise<string>

last issued at date string in the ISO8601 date format.


getMuteFilters

getMuteFilters(): Promise<IMuteFilter[]>

Gets the current mute filters for Notification sources in Finsemble.

Returns

Promise<IMuteFilter[]>

an array with all the mute filters.


getPreferences

getPreferences(): Promise<NotificationServiceConfig>

Gets the current notifications preferences object. It tries to load the configs saved in the user preferences and will fallback to config/schema defaults if none are present.

Returns

Promise<NotificationServiceConfig>

The notification preferences object.


markRead

markRead(notifications): Promise<void>

Sets the states of the isRead field to true.

All clients subscribed to received the updated notifications will be sent the new state.

await FSBL.Clients.NotificationClient.markRead([
previouslyReceivedNotification,
]);

Parameters

NameType
notificationsINotification[]

Returns

Promise<void>


markUnread

markUnread(notifications): Promise<void>

Sets the states of the isRead field to false.

All clients subscribed to received the updated notifications will be sent the new state.

await FSBL.Clients.NotificationClient.markUnread([
previouslyReceivedNotification,
]);

Parameters

NameType
notificationsINotification[]

Returns

Promise<void>


mute

mute(filter): Promise<void>

Sets a user preference on which notifications to mute. All future notifications that match the filter will have the mute flag set to true

// Mute all notifications coming from the 'order-management-system' source with type 'informational'
await FSBL.Clients.NotificationClient.mute({
source: "order-management-system",
type: "informational",
});

throws If no error is thrown the service has performed the mute successfully.

Parameters

NameTypeDescription
filterIMuteFilter | IMuteFilter[]Notifications to apply action to.

Returns

Promise<void>


notify

notify(notifications): Promise<void>

Send a new notification to Finsemble or update existing notifications already in Finsemble.

Send a new notification

const notification = new FSBL.Clients.NotificationClient.Notification();
// Set your notification fields accordingly
notification.title = "Regarding Order...";
notification.details = "Creates a new notification in UI";
notification.type = "email";

await FSBL.Clients.NotificationClient.notify([notification]);

throws Error If no error is thrown the service has received the notifications successfully

Parameters

NameTypeDescription
notificationsPartial<INotification> | Partial<INotification>[]Array of INotification

Returns

Promise<void>


performAction

performAction(notifications, action): Promise<void>

Tells the service to perform the supplied action on the notification(s)

await FSBL.Clients.NotificationClient.performAction(
[notification],
action,
).catch((e) => {
console.log("Request to perform action failed");
});
// Request to perform action succeeded. The updated notification state will be broadcast to the subscribed clients

throws If no error is thrown, the service has received the request to perform the action successfully. Note a successful resolution of the promise does not mean successful completion of the action.

Parameters

NameTypeDescription
notificationsPartial<INotification>[]Notifications to apply action to.
actionIActionwhich has been triggered by user.

Returns

Promise<void>


subscribe

subscribe(subscription, onNotification): Promise<{ channel: string ; id: string }>

Subscribe to a notification stream given filters. Returns subscriptionId

const { NotificationClient } = FSBL.Clients;
const subscription = new NotificationClient.Subscription();

// Set the filter to match INotification fields
subscription.filter = new NotificationClient.Filter();
// subscription.filter.include.push({"type": "chat"});

const onNotification = (notification: INotification) => {
// This function will be called when a notification arrives
addToList(notification);
};

// Use the subscription Id to unsubscribe from a specific subscription
const subscriptionId = await NotificationClient.subscribe(
subscription,
onNotification,
);

throws Throws an error on par with the Promise standard, containing detail why the request did not complete

Parameters

NameTypeDescription
subscriptionPartial<ISubscription>with name value pair used to match on.
onNotificationOnNotificationCallbackcallback for when a subscribing UI component receives a notification.

Returns

Promise<{ channel: string ; id: string }>

A subscription Id that can be used to unsubscribe from the notification stream.


unmute

unmute(filter): Promise<void>

Sets the filter preference on which notifications to mute. All future notifications that match the filter will have the mute flag set to false

// Unmute all notifications coming from the 'order-management-system' source with type 'informational'
await FSBL.Clients.NotificationClient.unmute({
source: "order-management-system",
type: "informational",
});

throws If no error is thrown the service has performed the unmute successfully.

Parameters

NameTypeDescription
filterIMuteFilter | IMuteFilter[]Notifications to apply action to.

Returns

Promise<void>


unsubscribe

unsubscribe(subscriptionId): Promise<void>

Used to unsubscribe from a notification stream.

// the subscriptionId is returned from the subscribe function
await FSBL.Clients.NotificationClient.unsubscribe(subscriptionId);

throws Throws an error on par with the Promise standard, containing detail why the request did not complete

Parameters

NameTypeDescription
subscriptionIdstringwhich was returned when subscription was created.

Returns

Promise<void>


unsubscribeAll

unsubscribeAll(): void

Unsubscribe from all notification streams registered with the window's client instance.

FSBL.Clients.NotificationClient.unsubscribeAll();

Returns

void