/** * @module NotificationCenter */ /** * Need a comment block here so that the comment block above is interpreted as a file comment, and not a comment on the * import below. * * @hidden */ import { NotificationActionResult, ActionTrigger } from './actions'; import { ButtonOptions, ControlOptions } from './controls'; import { DistributiveOmit } from './internal'; import * as provider from './provider'; import { NotificationSource } from './source'; import { NotificationIndicator, NotificationIndicatorWithCustomColor, IndicatorType, IndicatorColor } from './indicator'; import { NotificationOptions } from './templates/templates'; import { UpdatableNotificationOptions } from './templates/update'; import * as actions from './actions'; import { CustomValidationError, FormStatusOptions } from './forms'; export * from './actions'; export * from './controls'; export * from './source'; export * from './forms'; export * from './sounds'; export * from './stream'; export * from './templates'; export { actions, provider, NotificationOptions }; export { NotificationIndicator, NotificationIndicatorWithCustomColor, IndicatorColor, IndicatorType as NotificationIndicatorType }; export type { PlatformRegisterPayload, PlatformDeregisterPayload } from './platform'; /** * The Notification Client library's version in semver format. * * This is the version which you are currently using. */ export declare const VERSION: string; /** * Application-defined context data that can be attached to buttons on notifications. */ export type CustomData = Record; /** * A fully-hydrated form of {@link NotificationOptions}. * * After {@link create|creating} a notification, the service will return an object of this type. This will be the given * options object, with any unspecified fields filled-in with default values. * * This object should be treated as immutable. Modifying its state will not have any effect on the notification or the * state of the service. */ export type Notification = Readonly> & { readonly buttons: ReadonlyArray>; }>; export type UpdatableNotification = Readonly & { readonly buttons?: ReadonlyArray>; }>; /** * Event fired when an action is raised for a notification due to a specified trigger. It is important to note that * applications will only receive these events if they indicate to the service that they want to receive these events. * See {@link actions} for a full example of how actions are defined, and how an application can listen to and handle * them. * * This can be fired due to interaction with notification buttons or the notification itself, the notification being * closed (either by user interaction or by API call), or by the notification expiring. Later versions of the service * will add additional control types that may raise actions from user interaction. All actions, for all control types, * will be returned to the application via the same `notification-action` event type. * * The event object will contain the application-defined {@link NotificationActionResult|metadata} that allowed this * action to be raised, and details on what triggered this action and which control the user interacted with. * * Unlike other event types, `notification-action` events will be buffered by the service until the application has * added a listener for this event type, at which point it will receive all buffered `notification-action` events. The * service will also attempt to restart the application if it is not running when the event is fired. * * This type includes a generic type argument, should applications wish to define their own interface for action * results. See {@link NotificationActionResult} for details. * * @event "notification-action" */ export interface NotificationActionEvent { type: 'notification-action'; /** * The notification that created this action */ notification: Readonly; /** * This property allows the application handling the action to identify where this notification originated. */ source: NotificationSource; /** * Indicates what triggered this action. * * Note that the `programmatic` trigger is not yet implemented. */ trigger: ActionTrigger; /** * The control whose interaction resulted in this action being raised. Will only be present when {@link trigger} is * {@link ActionTrigger.CONTROL}. * * Future versions of the service will add additional controls beyond buttons, and interactions with these new * control types will also come through this one event type. For best forward-compatibility, applications should * always check the `type` property of this control, and not assume that the type will always be `'button'`. * * This field is marked optional as future versions of the service will also include alternate methods of raising * `notification-action` events that do not originate from a button or other control. * * When present, the object here will always be strictly equal to one of the control definitions within * `notification`. This means `indexOf` checks and other equality checks can be performed on this field if * required, such as: * * ```ts * function onNotificationAction(event: NotificationActionEvent): void { * if (event.control && event.control.type === 'button') { * const butttonIndex = event.notification.buttons.indexOf(event.control); * * // Handle button click * // . . . * } * } * ``` */ control?: Readonly; /** * Application-defined metadata that this event is passing back to the application. * * A `notification-action` event is only fired for a given trigger if the * {@link NotificationOptions|notification options} included an action result for that trigger. * * See the comment on the {@link NotificationActionEvent} type for an example of buttons that do and don't raise * actions. */ result: NotificationActionResult; } /** * Event fired whenever notification toast has been dismissed. This could be either by pressing notification dismiss `-` button or * by clicking notification body if BODY_CLICK action has been set to "dismiss_event". * * @event "notification-toast-dismissed" */ export interface NotificationToastDismissedEvent { type: 'notification-toast-dismissed'; notification: Notification; } /** * Event fired whenever the notification has been closed. * * This event is fired regardless of how the notification was closed - i.e.: via a call to `clear`/`clearAll`, the * notification expiring, or by a user clicking either the notification itself, the notification's close button, or * a button on the notification. * * @event "notification-closed" */ export interface NotificationClosedEvent { type: 'notification-closed'; /** * The notification that has just been closed. * * This object will match what is returned from the `create` call when the notification was first created. */ notification: Notification; } /** * Event fired whenever a new notification has been created. * * @event "notification-created" */ export interface NotificationCreatedEvent { type: 'notification-created'; /** * The notification that has just been created. * * This object will match what is returned from the `create` call. */ notification: Notification; } /** * Event fired whenever a reminder has been created either via the Notifications API * or by the user on the Notification Center UI * * @event "notification-reminder-created" */ export interface NotificationReminderCreatedEvent { type: 'notification-reminder-created'; /** * The reminder notification that has just been created. * * This object will match what is returned from the `create` call when the notification * was first created. */ notification: Notification; /** * The reminder time-out timestamp. */ reminderDate: Date; } /** * Event fired whenever a reminder has been canceled by the user, reminder notification is deleted or the reminder timeout has reached. * * @event "notification-reminder-removed" */ export interface NotificationReminderRemovedEvent { type: 'notification-reminder-removed'; /** * The notification associated with the reminder that has just been removed. * * This object will match what is returned from the `create` call when the notification was first created. */ notification: Notification; } /** * Event fired whenever the total number of notifications from **all** sources changes. * * @event "notifications-count-changed" */ export interface NotificationsCountChanged { type: 'notifications-count-changed'; /** * Number of notifications in the Center. */ count: number; } /** * Event fired whenever any of the notification form fields changes. * * @event "notification-form-value-changed" */ export interface NotificationFormValuesChangedEvent { type: 'notification-form-values-changed'; notification: Notification; form: Record; /** * Allows to set validation errors for the form fields. * If validation errors are set, the submit button will be disabled. * @param validationErrors * Array of objects with fieldKey and error properties. * @returns * Promise that resolves when the validation errors are set. * * @example * addEventListener( * 'notification-form-values-changed', * async (formValueChanged: NotificationFormValuesChangedEvent) => { * const errors = []; * * // Simpler regular expression to test for a valid HTTP or HTTPS URL * const phonePattern = /^\(?([0-9]{3})\)?[- ]?([0-9]{3})[- ]?([0-9]{4})$/; * * // Simpler regular expression to test for a valid email address * const emailPattern = /^\S+@\S+\.\S+$/; * * // Fields to validate * const sourcePhone = formValueChanged.form.sourcePhone as string; * const email = formValueChanged.form.sourceEmail as string; * * // Validate sourceUrl if it's not null or undefined * if (sourcePhone && !phonePattern.test(sourcePhone)) { * errors.push({ * fieldKey: 'sourcePhone', * error: 'Invalid phone format' * }); * } * * // Validate email if it's not null or undefined * if (email && !emailPattern.test(email)) { * errors.push({ * fieldKey: 'sourceEmail', * error: 'Invalid email format' * }); * } * * // If there are any errors, set them all at once * if (errors.length > 0) { * await formValueChanged.setErrors(errors); * } * } * ); */ setErrors: (validationErrors: Array) => Promise; } /** * Event fired whenever submit button is clicked on a notification form. * * @event "notification-form-submitted" */ export interface NotificationFormSubmittedEvent { type: 'notification-form-submitted'; notification: Notification; button: ButtonOptions; form: Record; /** * Prevents the default behaviour of notification form submit, where notification card gets dismissed right after submit. * * @example * addEventListener('notification-form-submitted', async (event) => { * // preventing the default submit behaviour * event.preventDefault(); * * // setting the form status to processing * event.setFormStatus({ * formStatus: 'Processing' * }); * * const longOperationResult = await ...(); * * if (longOperationResult.hasError) { * // setting error if long-running operation has failed. * event.setFormStatus({ * formStatus: 'not-submitted', * error: longOperationResult.operationErrorMessage * }); * } else { * // setting form status to submitted * event.setFormStatus({ * formStatus: 'submitted' * }); * } * }); */ preventDefault: () => void; /** * * @param formStatusOptions * Allows to set the status of the form. The form status reflects the state of the submit button which includes its text. * Submit button text for different statuses is defined using `formOptions` property for a submit button when creating a notification. * * @example * addEventListener('notification-form-submitted', async (event) => { * // preventing the default submit behaviour * event.preventDefault(); * * // setting the form status to processing * event.setFormStatus({ * formStatus: 'Processing' * }); * * const longOperationResult = await ...(); * * if (longOperationResult.hasError) { * // setting error if long-running operation has failed. * event.setFormStatus({ * formStatus: 'not-submitted', * error: longOperationResult.operationErrorMessage * }); * } else { * // setting form status to submitted * event.setFormStatus({ * formStatus: 'submitted' * }); * } * }); */ setFormStatus: (formStatusOptions: Omit) => Promise; } /** * Event fired whenever the Notification Sound Enabled setting is toggled in Notification Center. * * @event "notification-sound-toggled" */ export interface ToggleNotificationSound { type: 'notification-sound-toggled'; notificationSoundEnabled: boolean; } export declare function addEventListener(eventType: 'notification-form-values-changed', listener: (event: NotificationFormValuesChangedEvent) => void): void; export declare function addEventListener(eventType: 'notification-form-submitted', listener: (event: NotificationFormSubmittedEvent) => void): Promise; export declare function addEventListener(eventType: 'notification-action', listener: (event: NotificationActionEvent) => void): Promise; export declare function addEventListener(eventType: 'notification-created', listener: (event: NotificationCreatedEvent) => void): Promise; export declare function addEventListener(eventType: 'notification-toast-dismissed', listener: (event: NotificationToastDismissedEvent) => void): Promise; export declare function addEventListener(eventType: 'notification-closed', listener: (event: NotificationClosedEvent) => void): Promise; export declare function addEventListener(eventType: 'notifications-count-changed', listener: (event: NotificationsCountChanged) => void): Promise; export declare function addEventListener(eventType: 'notification-reminder-created', listener: (event: NotificationReminderCreatedEvent) => void): Promise; export declare function addEventListener(eventType: 'notification-reminder-removed', listener: (event: NotificationReminderRemovedEvent) => void): Promise; export declare function addEventListener(eventType: 'notification-sound-toggled', listener: (event: ToggleNotificationSound) => void): Promise; export declare function removeEventListener(eventType: 'notification-form-submitted', listener: (event: NotificationFormSubmittedEvent) => void): Promise; export declare function removeEventListener(eventType: 'notification-action', listener: (event: NotificationActionEvent) => void): Promise; export declare function removeEventListener(eventType: 'notification-created', listener: (event: NotificationCreatedEvent) => void): Promise; export declare function removeEventListener(eventType: 'notification-toast-dismissed', listener: (event: NotificationToastDismissedEvent) => void): Promise; export declare function removeEventListener(eventType: 'notification-closed', listener: (event: NotificationClosedEvent) => void): Promise; export declare function removeEventListener(eventType: 'notifications-count-changed', listener: (event: NotificationsCountChanged) => void): Promise; export declare function removeEventListener(eventType: 'notification-reminder-created', listener: (event: NotificationReminderCreatedEvent) => void): Promise; export declare function removeEventListener(eventType: 'notification-reminder-removed', listener: (event: NotificationReminderRemovedEvent) => void): Promise; export declare function removeEventListener(eventType: 'notification-form-values-changed', listener: (event: NotificationFormValuesChangedEvent) => void): void; export declare function removeEventListener(eventType: 'notification-sound-toggled', listener: (event: ToggleNotificationSound) => void): Promise; /** * Extended configuration options for the notification creation. */ export interface NotificationCreationOptions { /** * The date on which the notification will be removed from reminders category and recreated * created as regular notification. * * If this date is earlier than the notification creation time, the notification will be created * immediately. * Cannot be earlier than the expiry date, if set. * */ reminderDate?: Date; } /** * Creates a new notification. * * If a reminder is not set, the notification will immediately appear in the Notification Center and as a toast if the Center is not visible. * If a reminder is set, the notification will appear in the Center when the reminder date is reached. * * If a notification is created with an `id` of an already existing notification, the existing notification will be recreated with the new content. * * ```ts * import {create} from 'openfin-notifications'; * * create({ * id: 'uniqueNotificationId', * title: 'Notification Title', * body: 'Text to display within the notification body', * icon: 'https://openfin.co/favicon.ico' * }, { * reminderDate: new Date('October 21, 2015 07:28:00'); * }); * ``` * * @param options Notification configuration options. * @param creationOptions Extended configuration options for the notification creation. */ export declare function create(options: T, creationOptions?: NotificationCreationOptions): Promise>; /** * Updates an existing notification. Requires id of original Notification and one of: * - buttons * - customData * - Template * * The updated Notification will then show in Notification Centre and in the Toast stack if not expired. * * Example: * ```ts * import {update} from 'openfin-notifications'; * * update({ * id: uniqueNotificationId, * body: 'i am an update! - ' + Date.now().toString(), * template: 'markdown', * }); * ``` * @param options * @returns */ export declare function update(options: T): Promise; /** * Clears a specific notification from the Notification Center. * * Returns true if the notification was successfully cleared. Returns false if the notification was not cleared, without errors. * * ```ts * import {clear} from 'openfin-notifications'; * * clear('uniqueNotificationId'); * ``` * * @param id ID of the notification to clear. */ export declare function clear(id: string): Promise; /** * Retrieves all Notifications which were created by the calling application, including child windows. * Child window notifications will only be included if the notification security rules allow it. * * ```ts * import {getAll} from 'openfin-notifications' * * getAll().then((notifications: Notification[]) => { * console.log(`Service has ${notifications.length} notifications for this app:`, notifications); * }); * ``` * * There is deliberately no mechanism provided for fetching notifications that were created by a different application. */ export declare function getAll(): Promise; /** * Clears all Notifications which were created by the calling application, including child windows. * Child window notifications will only be cleared if the notification security rules allow it. * * Returns the number of successfully cleared Notifications. * * ```ts * import {clearAll} from 'openfin-notifications'; * * clearAll(); * ``` */ export declare function clearAll(): Promise; /** * Toggles the visibility of the Notification Center. * * ```ts * import {toggleNotificationCenter} from 'openfin-notifications'; * * toggleNotificationCenter(); * ``` */ export declare function toggleNotificationCenter(): Promise; export declare function setDefaultPlatformShortcut(shortcut: string): Promise; /** * Options to modify the Notification Center behaviour when show() API is called. */ export interface ShowOptions { navigateToAll?: boolean; } /** * Sets the visibility of the Notification Center to true. * * ```ts * import { show } from 'openfin-notifications'; * * show({ navigateToAll: false }); * ``` * @param showOptions */ export declare function show(options?: ShowOptions): Promise; /** * Sets the visibility of the Notification Center to false. * * ```ts * import { hide } from 'openfin-notifications'; * * hide(); * ``` */ export declare function hide(): Promise; /** * Get the total count of notifications from **all** applications. * * ```ts * import {getNotificationsCount} from 'openfin-notifications'; * * getNotificationsCount(); * ``` */ export declare function getNotificationsCount(): Promise; export declare const enum UserSettings { SOUND_ENABLED = "soundEnabled" } export type UserSettingStatus = { [UserSettings.SOUND_ENABLED]: boolean; }; /** * Retrieves a user setting from Notifications Center * * ```ts * import { getUserSettingStatus } from 'openfin-notifications'; * * getUserSettingStatus('soundEnabled'); * ``` * @param UserSettings the setting of which you want to retrieve the current status. * * @returns * Promise that resolves to the status of the setting. */ export declare function getUserSettingStatus(setting: UserSettings): Promise; /** * Set the allowedOrigins for the specific client that calls the function. * * ```ts * import { setAllowedOrigins } from 'openfin-notifications'; * * setAllowedOrigins(['https://*.example.com']); * ``` * @param allowedOrigins An array of allowed origins. */ export declare const setAllowedOrigins: (allowedOrigins: string[]) => Promise;