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
Name | Type | Description |
---|---|---|
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? | string | Logo to display in content section of a notification.HTML source data URI or URL. Defaults set by type in configuration. |
cssClassName? | string | Allows a css class to be applied to a notification to change it's appearance. |
details? | string | Details about the notification mainly for display purposes. |
devModeOnly? | boolean | A flag to determine whether the notification is to be displayed only if Finsemble is running in dev mode. |
headerLogo? | string | Logo displayed in header section of a notification. HTML source data URI or URL. Defaults set by type in configuration. |
headerText? | string | An 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? | string | Either set when notification is created to refer to id an external system or if null set to UUID. |
isDeleted | boolean | Private: Indicating a notification has been deleted |
isMuted | boolean | Private: If a Notification has been muted after being received |
isRead | boolean | Private: If an notification has been marked as read. |
isSnoozed | boolean | Private: Indicating a notification is currently snoozed |
issuedAt | string | ISO8601 date formatted string. When the notification was generated. |
meta? | Meta | Additional 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? | string | Private: ISO8601 date formatted string. When the notification was received by Finsemble |
source? | string | The source that the notification originated from |
stateHistory | INotification [] | - |
timeout? | number | The number of milliseconds the notification should appear in the UIs. |
title | string | Main display title |
type? | string | The type of notification. |
INotificationHistoryOptions
Ƭ INotificationHistoryOptions: Object
Type declaration
Name | Type | Description |
---|---|---|
pageNumber? | number | The page number |
pageSize? | number | The number of notifications to fetch |
sentAfter? | string | ISO8601 date formatted string. Fetch (from) notifications sent after this date |
sentBefore? | string | ISO8601 date formatted string. Fetch (from) notifications sent before this date |
NotificationServiceConfig
Ƭ NotificationServiceConfig: Object
Type declaration
Name | Type |
---|---|
defaultSnoozePeriodSeconds | number |
disableDotOnToolbarIcon | boolean |
informationalNotificationToastPeriodSeconds | number |
newNotificationHaloPeriodSeconds | number |
showDotOnToolbarIconForMutedNotifications | boolean |
toastTimeoutOnActionableNotifications | boolean |
Functions
deleteNotifications
▸ deleteNotifications(notifications
): Promise
<void
>
Deletes a notification
All clients subscribed to receive the updated notifications will be sent the new state.
Parameters
Name | Type | Description |
---|---|---|
notifications | INotification [] | 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
Name | Type | Description |
---|---|---|
options? | string | INotificationHistoryOptions | An options object or an ISO8601 formatted date string. |
filter? | IFilter | to match to notifications. |
Returns
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
Name | Type | Description |
---|---|---|
source? | string | to 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
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
Name | Type |
---|---|
notifications | INotification [] |
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
Name | Type |
---|---|
notifications | INotification [] |
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
Name | Type | Description |
---|---|---|
filter | IMuteFilter | 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
Name | Type | Description |
---|---|---|
notifications | Partial <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
Name | Type | Description |
---|---|---|
notifications | Partial <INotification >[] | Notifications to apply action to. |
action | IAction | which 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
Name | Type | Description |
---|---|---|
subscription | Partial <ISubscription > | with name value pair used to match on. |
onNotification | OnNotificationCallback | callback 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
Name | Type | Description |
---|---|---|
filter | IMuteFilter | 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
Name | Type | Description |
---|---|---|
subscriptionId | string | which 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