UNPKG

haystack-nclient

Version:

Project Haystack Network Client

100 lines (99 loc) 3.52 kB
import { HDateTime, HDict, HRef, HStr } from 'haystack-core'; import { ClientServiceConfig } from '../ClientServiceConfig'; import { NotificationsHandler } from './NotificationsHandler'; /** * Notification object that has a Notification backing record. */ export interface Notification extends HDict { /** The id of the notification record */ id?: HRef; /** The target application this notification is intended for */ targetApp: HStr; /** A unique topic the notification addresses */ topic: HStr; /** The kind of notification */ kind: 'alarm' | 'info' | 'warning' | 'success' | 'error'; /** The current notification state */ state: HStr; /** A message to accompany this notification that is direct to the end user */ message?: HStr; lastUpdateTime?: HDateTime; creation?: HDateTime; } /** * The subject changed event callback handler. */ export interface NotificationEventHandler { (notification: Notification[]): void; } /** * An implementation of the FIN Notification service. */ export declare class NotificationService<NotificationType extends Notification = Notification> { #private; /** * Constructs a new notifications service object. * * @param serviceConfig Service configuration. */ constructor(serviceConfig: ClientServiceConfig); make(callbacks: NotificationEventHandler[]): Promise<NotificationsHandler>; /** * Get all the notifications in the system for the current user * * @returns The result of the read operation. */ readAll(): Promise<NotificationType[]>; /** * Get notification topics that are visible to the current user * * @returns The result of the read operation. */ readAllTopics(): Promise<HStr[]>; /** * Get all notifications in the system for the current user filtered * according to the user notification settings. * * @param filter A haystack filter * @returns The result of the read operation. */ readAllCurrentFiltered(filter?: string): Promise<NotificationType[]>; /** * Get notifications for a topic that are visible to the * current user * * @param filter A haystack filter * @returns The filtered notifications. */ readByTopicFilter(filter?: string): Promise<NotificationType>; /** * This operations will only be valid if the current user has write access to the * notification `targetApp` and to the project the notification is stored in. * Super users are allowed to post any notification, including system ones. * * @param notification The notification object * @returns The filtered notifications. */ create(notification: NotificationType): Promise<HRef>; /** * Get all the new notifications in the system for the current user. * * @param timeOfLastMod Time of the last modification. * @returns New notifications since timeOfLastMod */ poll(timeOfLastMod: HDateTime): Promise<NotificationType[]>; /** * Marks the state of notification with the specified id as resolved. * * @param id The notification ID to resolve * @returns The notification object */ resolve(id: string | HRef): Promise<NotificationType>; /** * Marks the state of notification state as dismissed. * * @param id The notification ID to dismiss * @returns The notification object */ dismiss(id: string | HRef): Promise<NotificationType>; }