API: NotificationClient
Used to send, receive and manipulate notifications
Enumerations
Classes
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
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
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
Promise
<IMuteFilter
[]>
an array with all the mute filters.
getPreferences
▸ getPreferences(): Promise
<Object
>
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
<Object
>
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
>
onClose
▸ onClose(cb?
): void
Parameters
Name | Type |
---|---|
cb? | () => void |
Returns
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 true
// 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