import OpenFin from '@openfin/core'; import { ThemeSet, ColorSchemeType } from '@openfin/ui-library'; import { DefaultTheme } from 'styled-components'; type NotificationProviderInfo = { /** * Unique identifier for the provider. This id must not change between sessions. * * @remarks A non-zero length string. */ id: string; /** * A UI friendly title for the provider. * * @remarks A non-zero length string. */ title: string; /** * Icon url for the provider. */ icon?: string; /** * Unique identifier for the Notification Center instance. * Must be a non-empty string that matches the `serviceId` used in the Web Notification Center instance. */ serviceId: string; }; /** * @module Notifications */ /** * @deprecated * Lists possible semantic use-cases for notifications, which can alter how the notification is presented to the user. */ declare enum IndicatorType { FAILURE = "failure", WARNING = "warning", SUCCESS = "success" } /** * Lists possible colors available for use as NotificationIndicator background color. */ declare enum IndicatorColor { RED = "red", GREEN = "green", YELLOW = "yellow", BLUE = "blue", PURPLE = "purple", GRAY = "gray", ORANGE = "orange", MAGENTA = "magenta", TEAL = "teal" } interface NotificationIndicator { /** * @deprecated * * Deprecated - use the priority field instead. * * Indicates the semantic intent behind the indicator - this determines the visual styling of the indicator when * seen by the user. * * For example - an indicator could be used to: * - `IndicatorType.FAILURE`: Indicate a failure has occurred from an action the user has taken. * - `IndicatorType.WARNING`: Warn a user that they have a limited amount of time to buy. * - `IndicatorType.SUCCESS`: Inform the user that an item has been successfully ordered. */ type?: IndicatorType; /** * The indicator banner color. Defaults to red. */ color?: IndicatorColor; /** * Customized text to be displayed in the indicator. When set, this will override the default indicator text. * Text is limited to 32 characters including spaces. */ text?: string; } interface NotificationIndicatorWithCustomColor extends Omit { /** * Custom color string for indicator banner. This string must be defined in `theme` during Workspace Platform initialization. */ color: string; /** * Fallback color if custom color could not be found in theme. */ fallback: IndicatorColor; } /** * These are available widgets for use in forms. * * @module FormWidgets */ /** * The StringWidgetType is how you display a text string. */ declare const StringWidgetType: { readonly Text: "Text"; readonly Dropdown: "Dropdown"; }; declare const NumberWidgetType: { readonly Number: "Number"; }; declare const BooleanWidgetType: { readonly Toggle: "Toggle"; readonly Checkbox: "Checkbox"; }; declare const CheckboxGroupWidgetType: { readonly CheckboxGroup: "CheckboxGroup"; }; declare const RadioGroupWidgetType: { readonly RadioGroup: "RadioGroup"; }; declare const DateWidgetType: { readonly Date: "Date"; }; declare const TimeWidgetType: { readonly Time: "Time"; }; declare const WidgetType: { readonly Time: "Time"; readonly Date: "Date"; readonly RadioGroup: "RadioGroup"; readonly CheckboxGroup: "CheckboxGroup"; readonly Toggle: "Toggle"; readonly Checkbox: "Checkbox"; readonly Number: "Number"; readonly Text: "Text"; readonly Dropdown: "Dropdown"; }; /** * All available widgets. */ type Widget = StringWidget | NumberWidget | BooleanWidget | CheckboxGroupWidget | RadioGroupWidget | DateWidget; interface BaseWidgetSpec { /** * The type of widget to be used. Widgets can only be used with matching specific data types. * For example the `Text` widget can be used with the `string` field type. */ type: T; } /** * A simple text field input widget. */ interface TextWidgetSpec extends BaseWidgetSpec { placeholder?: string; multiline?: boolean; rows?: number; } /** * String field input widget. */ type StringWidget = TextWidgetSpec | DropdownWidgetSpec; interface NumberWidgetSpec extends BaseWidgetSpec { placeholder?: string; min?: number; max?: number; currencyChar?: string; decimalPlaces?: number; step?: number; } interface CheckboxGroupWidgetSpec extends BaseWidgetSpec { group: Array<{ value: string; label: string; }>; } type CheckboxGroupWidget = CheckboxGroupWidgetSpec; interface RadioGroupWidgetSpec extends BaseWidgetSpec { group: Array<{ value: string; label: string; }>; } type RadioGroupWidget = RadioGroupWidgetSpec; interface DateWidgetSpec extends BaseWidgetSpec { minDate?: Date | null; maxDate?: Date | null; } type TimeWidgetSpec = BaseWidgetSpec; type DateWidget = DateWidgetSpec; type TimeWidget = TimeWidgetSpec; interface DropdownWidgetSpec extends BaseWidgetSpec { placeholder?: string; options: Array<{ value: string; label: string; }>; } type DropdownWidget = DropdownWidgetSpec; /** * Number field input widget. */ type NumberWidget = NumberWidgetSpec; type ToggleWidgetSpec = BaseWidgetSpec; type CheckboxWidgetSpec = BaseWidgetSpec; type BooleanWidget = ToggleWidgetSpec | CheckboxWidgetSpec; /** * When you make a form, you provide a list of [[FormFields]]. Each FormField contains the ingredients to make a single widget in the form. * The actual definitions of the widgets are derived from [[BaseWidgetSpec]]. * * A FormField contains the type of data, the key to store the user input into [[CustomDataWithForms]], and some additional configuration. * @module FormFields */ /** * imports. */ /** * Data type of a fields. e.g. string, number */ declare const FieldType: { readonly string: "string"; readonly number: "number"; readonly boolean: "boolean"; readonly date: "date"; readonly checkboxGroup: "checkboxGroup"; readonly radioGroup: "radioGroup"; readonly time: "time"; }; /** * An abstract validation entry. */ interface ValidationEntry { /** * Message displayed to the user when input is invalid. */ invalidMessage?: string; /** * Validation argument to test against. */ arg?: T; } /** * The base type for form fields. */ interface BaseField { /** * Field data type. */ type: T; /** * The property key that this field value will appear in the returned {@link NotificationFormSubmittedEvent.form|form} object. */ key: string; /** * Default value for field, and where it will be written to */ value?: D; /** * Validation rules used to validate user input. */ validation?: Record; /** * Input label. */ label?: string; /** * Helper text. */ helperText?: string; } /** * String field within a form. */ interface StringField extends BaseField<'string', string> { validation?: Partial<{ /** * Minimum number of characters. */ min: ValidationEntry; /** * Maximum number of characters. */ max: ValidationEntry; /** * Length of the input string. */ length: ValidationEntry; /** * The field is required to be filled in by the user. */ required: ValidationEntry; /** * Provide a regex string that will be tested against the input value. */ match: ValidationEntry; }>; /** * What input widget is used. * @default StringWidgets {@link StringWidgets} */ widget: W; } /** * Number field within a form. */ interface NumberField extends BaseField<'number', number> { validation?: Partial<{ /** * Minimum number of characters. */ min: ValidationEntry; /** * Maximum number of characters. */ max: ValidationEntry; /** * Number must be less than this. */ lessThan: ValidationEntry; /** * Number must be more than this. */ moreThan: ValidationEntry; /** * Number must be positive. */ positive: ValidationEntry; /** * Number must be negative. */ negative: ValidationEntry; /** * The field is required to be filled in by the user. */ required: ValidationEntry; }>; widget: W; } interface BooleanField extends BaseField<'boolean', boolean> { widget: W; } type DateFieldValue = { date?: number; month?: number; year?: number; }; interface DateField extends BaseField<'date', DateFieldValue> { widget: W; } type TimeFieldValue = { hour?: number; minute?: number; }; interface TimeField extends BaseField<'time', TimeFieldValue> { widget: W; } interface RadioGroupField extends BaseField<'radioGroup', string> { widget: W; } interface CheckboxGroupField extends BaseField<'checkboxGroup', Array> { widget: W; } /** * A field in a form. */ type FormField = StringField | NumberField | BooleanField | DateField | RadioGroupField | CheckboxGroupField | TimeField; /** * A field in a form. * * The difference with [[FormField]] is that the label property is required. */ type FormFieldWithRequiredLabel = MakePropertyRequired; /** * A field in a form. Either [[FormField]] or [[FormFieldWithRequiredLabel]] */ type AnyFormField = FormField | FormFieldWithRequiredLabel; /** * An ordered array of fields representing a form. * When the form is displayed to the user the fields will appear in the same order they are in the array. */ type NotificationFormData = ReadonlyArray; /** * An ordered array of fields representing a form. * When the form is displayed to the user the fields will appear in the same order they are in the array. * * The difference with [[NotificationFormData]] is that the label property is required for each field. */ type NotificationFormDataWithRequiredLabel = ReadonlyArray; type FormStatus = 'not-submitted' | 'submitting' | 'submitted'; interface FormStatusOptions { /** * Controls form status, */ formStatus: FormStatus; /** * Sets error message at the top of the form. */ error?: string; _notificationId: string; } type CustomValidationError = { fieldKey: string; error: string; }; /** * OpenFin Notification Templates API Version 1 * * @module Templates */ /** * imports */ type SectionAlignment = 'left' | 'center' | 'right'; type ListPairs = [string, string][]; type CustomTemplateData = Record; /** * The options you pass to the [[create]] function to generate a notification. */ type NotificationOptions = TemplateMarkdown | TemplateList | TemplateCustom; /** * The options to build your custom template composition layout. */ type TemplateFragment = ContainerTemplateFragment | TextTemplateFragment | ListTemplateFragment | ImageTemplateFragment | ActionableTextTemplateFragment; declare const TemplateNames: { readonly markdown: "markdown"; readonly list: "list"; readonly custom: "custom"; }; declare const ContainerTemplateFragmentNames: { readonly container: "container"; }; declare const PresentationTemplateFragmentNames: { readonly text: "text"; readonly image: "image"; readonly list: "list"; readonly actionableText: "actionableText"; }; declare const TemplateFragmentNames: { readonly text: "text"; readonly image: "image"; readonly list: "list"; readonly actionableText: "actionableText"; readonly container: "container"; }; interface TemplateComposition { /** * Minimum Template API version required for the service to render this composition. * * For example, a composition that consists only of container, text, image, or list * fragments must declare a minimum template API version of "1". * * See {@link BodyTemplateOptions} for more details. */ minTemplateAPIVersion: string; /** * Root of the template composition tree. See {@link ContainerTemplateFragment} for nesting. */ layout: TemplateFragment; } interface IndicatorTemplateOptions { /** * Alignment of the notification's indicator section. * * Can be `left`, `center` or `right`. * * The default value is `center`. */ align?: SectionAlignment; /** * Color of the indicator bar. * * Note: {@link BaseNotificationOptions|Notification's indicator color} definition has precedence over Template definition. * Template's indicator color value will be taken into account only if the notification itself doesn't have the indicator color * specified. */ color?: IndicatorColor; } interface ButtonTemplateOptions { /** * Alignment of the notification's button section. * * Can be `left`, `center` or `right`. * * The default value is `right`. */ align?: SectionAlignment; } interface BodyTemplateOptions { /** * A list of template compositions. * * You can include multiple compositions with different minimum Template API version to create fallback compositions and support the * earlier versions of Notification Center (Starting from the Template API version 1). * * The service will search for the composition with the version number matching the Template API version it is supporting. * If this doesn't exist, the service will then select the composition with the nearest version number smaller than the Template API version * it is supporting and render the notification card with that composition. */ compositions: TemplateComposition[]; /** * Composition fallback text. * * The service will render this text instead of the notification body section if there are no compatible compositions found in the template. * * (E.g. All of the compositions in the template declare a greater minimum Template API version than the version supported by the running * service instance.) * */ fallbackText?: string; } interface BaseTemplateFragment { /** * Type of the template fragment. */ type: T; /** * CSS style properties of the fragment. * * All the available custom template fragments support all of the React's inline style properties (with camelCase keys) * * Note: "position: fixed" is disallowed in the fragments. */ style?: Record; } interface ContainerTemplateFragment extends BaseTemplateFragment<'container'>, ActionableFragment { /** * Sub-fragments of the container. * * You can use container template fragment to create nested composition structures. */ children?: TemplateFragment[]; } interface PresentationTemplateFragment extends BaseTemplateFragment { /** * Optional flag. * * If a presentation template fragment is flagged as optional, The service will not require * the fragment's `dataKey` to exist in `templateData`. If a fragment is optional and its data * is missing, the fragment will be omitted quietly by the server. */ optional?: boolean; /** * Data key of the template fragment. * * The data associated with this fragment will be looked up in `templateData` map with this key. * * Example: * ```ts * const myTemplate = { * body: { * compositions: [{ * minTemplateAPIVersion: '1', * layout: { * type: CustomTemplateFragmentNames.text, * dataKey: 'message', * }, * }], * }, * } * * const notificationOption: TemplateCustom = { * //... * templateOptions: myTemplate, * templateData: { * message: 'My Custom Notification Message', * } * }; * ``` * */ dataKey: string; } interface ActionableFragment { /** * onClick object that is user defined. * * If provided, notification-action event will be raised when clicking on the fragment. * * * Example: * ```ts * { * "type": "actionableText", * "dataKey": "titlexyz", * "tooltipKey": "some_key", * "onClick": { // contents are user-defined * "task": "schedule-reminder", * "eventId": 142341, * "intervalMs": 5000 * } * } * * import { addEventListener, clear } from 'openfin-notifications'; * * addEventListener('notification-action', (event: NotificationActionEvent)) => { * if (event.result.task === 'schedule-reminder') { * scheduleReminder(event.result.eventId, Date.now() + event.result.intervalMs); * } * clear(event.notification.id); * }); * ``` * */ onClick?: ActionDeclaration | null; /** * Tooltip key of the template fragment. * * The string tooltip associated with this fragment will be looked up in templateData map with this key. * * * Example: * ```ts * const myTemplate = { * body: { * compositions: [{ * minTemplateAPIVersion: '1', * layout: { * type: "actionableText", * dataKey: 'message', * tooltipKey: 'tooltipxyz', * }, * }], * }, * } * * const notificationOption: TemplateCustom = { * //... * templateOptions: myTemplate, * templateData: { * message: 'view stock tracker', * tooltipxyz: 'My Custom Tooltip', * } * }; * ``` * */ tooltipKey?: string; } type TextTemplateFragment = PresentationTemplateFragment<'text'>; type ImageTemplateFragment = PresentationTemplateFragment<'image'> & ActionableFragment; type ListTemplateFragment = PresentationTemplateFragment<'list'>; type ActionableTextTemplateFragment = PresentationTemplateFragment<'actionableText'> & ActionableFragment; /** * Configuration options for the custom notification template. */ interface CustomTemplateOptions { /** * Configuration options for the custom notification template body. */ body: BodyTemplateOptions; /** * Configuration options for the custom notification template's modifications on the notification's indicator section. */ indicator?: IndicatorTemplateOptions; /** * Configuration options for the custom notification template's modifications on the notification's button section. */ buttons?: ButtonTemplateOptions; } /** * Default markdown template. Contains a markdown body and forms data. */ interface TemplateMarkdown extends Omit, 'template'> { template?: 'markdown'; /** * Notification body text. * * This is the main notification content, displayed below the notification title. The notification will expand to fit the length of this text. * Markdown may be used in the body text to control how it is styled when rendered. * With the exception of links and code blocks, all basic syntax as documented [here](https://www.markdownguide.org/basic-syntax) is supported. */ body: string; /** * A collection of form fields or a form definition (Form) * @example * ```ts * [ * { * key: 'phone', * type: 'string', * label: 'Phone', * helperText: * 'Must be in the following formats 123-456-7890, 123 456 7890, (123) 456 7890 or 1234567890', * widget: { * type: 'Text' * }, * validation: { * required: { * arg: true * } * } * }, * { * key: 'email', * type: 'string', * label: 'Email', * helperText: 'We will use this email to send you the report after we crawl your website', * widget: { * type: 'Text' * }, * validation: { * required: { * arg: true * } * } * } * ] * ``` */ form?: NotificationFormData | Form | null; } /** * Simple template that can render a list of name-value pairs. */ interface TemplateList extends BaseNotificationOptions<'list'> { /** * Notification list template data. */ list: Record; } /** * Notification that renders custom templates. */ interface TemplateCustom extends BaseNotificationOptions<'custom'> { templateOptions: CustomTemplateOptions; /** * Data associated with the custom notification template's presentation fragments. */ templateData: CustomTemplateData; /** * A collection of form fields or a form definition (Form) * @example * ```ts * [ * { * key: 'phone', * type: 'string', * label: 'Phone', * helperText: * 'Must be in the following formats 123-456-7890, 123 456 7890, (123) 456 7890 or 1234567890', * widget: { * type: 'Text' * }, * validation: { * required: { * arg: true * } * } * }, * { * key: 'email', * type: 'string', * label: 'Email', * helperText: 'We will use this email to send you the report after we crawl your website', * widget: { * type: 'Text' * }, * validation: { * required: { * arg: true * } * } * } * ] * ``` */ form?: NotificationFormDataWithRequiredLabel | Form | null; } interface FormSettings { /** * Controls that display of (Required) or (Optional) labels next to form fields. */ displayFieldRequirementStatus?: boolean; } interface Form extends FormSettings { /** * A collection of form fields. * @example * ```ts * [ * { * key: 'phone', * type: 'string', * label: 'Phone', * helperText: * 'Must be in the following formats 123-456-7890, 123 456 7890, (123) 456 7890 or 1234567890', * widget: { * type: 'Text' * }, * validation: { * required: { * arg: true * } * } * }, * { * key: 'email', * type: 'string', * label: 'Email', * helperText: 'We will use this email to send you the report after we crawl your website', * widget: { * type: 'Text' * }, * validation: { * required: { * arg: true * } * } * } * ] * ``` */ fields: ReadonlyArray; } /** * Core notification features. * * @module BaseNotificationOptions */ /** * imports */ /** * Configuration options for constructing a Notifications object, shared between all templates. */ interface BaseNotificationOptions { /** * A unique identifier for the notification. * * If not provided at time of creation, one will be generated for you and returned as part of the {@link create} method. */ id?: string; /** * Template of the notification payload. */ template: T; /** * Title of the notification. * * Displayed as the first line of the notification, in a heading style. */ title: string; /** * If set to false, the user won't be able to set a reminder for this notification in the Notification Center. * * Default value is `true`. */ allowReminder?: boolean; /** * Describes the context of this notification. Allows users to control different notification types that are raised * by an application. * * This string is not displayed on the notification itself, but should be user-readable. It will be displayed in * the Notification Center preferences section, and any string passed as a `category` should make sense when * displayed in that context. * * Event categories should list all the different types of notifications raised by your app. As a general guide, if * a user may want to have different preferences for some subset of notifications created by your app, then * applications should ensure that those notifications have a distinct category. * * @deprecated This property is deprecated and will be removed in a future release. */ category?: string; /** * Add a semantic visual indicator to a notification, to signal to the user the nature of the event that they are * being notified about. * * This should not be treated as a priority. */ indicator?: NotificationIndicator | NotificationIndicatorWithCustomColor | null; /** * URL of the icon to be displayed in the notification. */ icon?: string; /** * Application-defined context data that can be attached to buttons on notifications. * * When using forms, form data submitted will be written to `customData` and returned to your app by * listening to the submit {@link NotificationActionEvent|`notification-action`} with the trigger {@link ActionTrigger.SUBMIT|submit}. */ customData?: CustomData; /** * The timestamp shown on the notification. If omitted, the current date/time will be used. * * This is presentational only - a date in the future does not incur a scheduling action. */ date?: Date; /** * The expiry date and time of the notification. If specified, the notification will be removed at this time, or as * soon as possible after. If not specified, the notification will never expire, and will persist until it * is closed. */ expires?: Date | null; /** * When set to `sticky` this settings enables the notification toast to stay visible on the desktop * until the user interacts with it. When set to `transient` the toasts will follow the default behavior * of fading away after a short duration. When set to `none` the toasts will not appear and the notification * will only appear in the Notification Center. * * This property has a precedence over `sticky` propery. * */ toast?: 'sticky' | 'transient' | 'none'; /** * @deprecated * * This property is deprecated. Use `toast` instead. */ sticky?: 'sticky' | 'transient'; /** * A list of buttons to display below the notification text. * * Notifications support up to four buttons. Attempting to add more than four will result in the notification * being rejected by the service. */ buttons?: ButtonOptions[]; /** * Notification Stream * * If the notification belongs to a stream, the user will be able to group notifications by stream. */ stream?: NotificationStream | null; /** * Id of the platform this notification belongs to. * * If the application belongs to a platform, the user interaction with the notification will be dispatched * back to the platform provider. */ platform?: string | null; /** * An {@link NotificationActionResult|action result} to be passed back to the application inside the * {@link NotificationActionEvent|`notification-action`} event fired when the notification is clicked. * * This action will only be raised on clicks to the notification body. Interactions with buttons (both * application-defined buttons, and the default 'X' close button) or with actionable fragments will not trigger a * {@link ActionTrigger.SELECT|select} action. * * See {@link Actions} for more details on notification actions, and receiving action events from notifications. */ onSelect?: (ActionDeclaration & ActionNoop & ActionBodyClick) | null; /** * An {@link NotificationActionResult|action result} to be passed back to the application inside the * {@link NotificationActionEvent|`notification-action`} event fired when the notification the expires. * * If `expires` is specified for the notification, this action will be raised when the notification expires. If * `expires` is not specified for the notification, this action will never be raised. Note that if an `onClose` * action result is also specified, both actions will be raised if and when the notification expires. * * See {@link Actions} for more details on notification actions, and receiving action events from notifications. */ onExpire?: ActionDeclaration | null; /** * An {@link NotificationActionResult|action result} to be passed back to the application inside the * {@link NotificationActionEvent|`notification-action`} event fired when the notification is closed. * * This action is raised regardless of how the notification is closed, whether from user interaction, expiration, * or programmatic removal -- such as a call to `clear`. * * See {@link Actions} for more details on notification actions, and receiving action events from notifications. */ onClose?: ActionDeclaration | null; /** * A priority for this notification. It's from 1 - 4. */ priority?: number; /** * Sound options for a notification. */ soundOptions?: NotificationSoundOptions; } /** * Configuration options for constructing an updatable Notifications object, shared between all templates. */ interface BaseUpdatableNotificationOptions { /** * A unique identifier for the notification. * * Mandatory field for Notification updates. */ id: string; /** * description of update type 'markdown', 'list' or 'custom' */ template?: T; /** * Application-defined context data that can be attached to buttons on notifications. * * When using forms, form data submitted will be written to `customData` and returned to your app by * listening to the submit {@link NotificationActionEvent|`notification-action`} with the trigger {@link ActionTrigger.SUBMIT|submit}. */ customData?: CustomData; /** * A list of buttons to display below the notification text. * * Notifications support up to four buttons. Attempting to add more than four will result in the notification * being rejected by the service. */ buttons?: ButtonOptions[]; } /** * Default markdown template update. */ interface UpdatableNotificationTemplateMarkdown extends Omit, 'template'> { template?: 'markdown'; body?: string; form?: NotificationFormData | null; } /** * Simple template that can render a list of name-value pairs. */ interface UpdatableNotificationTemplateList extends BaseUpdatableNotificationOptions<'list'> { /** * Notification list template data. */ list?: Record; } /** * Update Payload for Custom Template Notification. * This will let you update the template data associated with the existing template * composition of the notification template. */ interface UpdatableNotificationTemplateCustom extends BaseUpdatableNotificationOptions<'custom'> { /** * Data associated with the custom notification template's presentation fragments. */ templateData?: CustomTemplateData; form?: NotificationFormData | null; } type UpdatableNotificationOptions = UpdatableNotificationTemplateMarkdown | UpdatableNotificationTemplateList | UpdatableNotificationTemplateCustom; /** * Notifications allow additional UI components to be specified by applications. The service controls the * positioning and styling of these components. * * @module Controls */ /** * 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 */ /** * Helper to make the `type` field required on any type that defines it as being optional. */ type WithExplicitType = T & { type: string; }; /** * *Not yet implemented* * * Union of the options objects of all "primary control" components supported by the service. */ type PrimaryControlOptions = never; /** * Union of options objects of all components that can be added to a notification, includes both buttons and primary * controls. */ type ControlOptions = Required> | WithExplicitType | WithExplicitType | WithExplicitType; /** * Configuration options for constructing a button within a notification. */ interface ButtonOptions { /** * The type of the control. Optional, added automatically if `NotificationOptions.buttons` includes the `onClick` * property and therefore generates a `notification-action` event. */ type?: 'button'; /** * User-facing button text. * * The button caption should be kept short, particularly if there are multiple buttons. Notifications are * fixed-width, and all buttons will be displayed on the same row. */ title: string; /** * Indicates that this button will be visually displayed as a 'Call to Action' button. In this case a Call To Action * means the button is made more prominent. We recommend you use this for true calls to action. For example, if you * have a notification which contains a report, it might have an 'OK' button which takes you to the report, and a * 'Dismiss' button which simply closes the notification. We suggest you make only the 'OK' button a CTA here.' * * If set as `false` or `undefined`, the default simple text button will be used instead. */ cta?: boolean; /** * Indicates that this button should submit a form. * If a form is invalid, based on your validation rules provided, the button will be disabled until the users input within the form is valid. */ submit?: boolean; /** * @deprecated * Optional icon URL, if an icon should be placed on the button. * * Icons are placed to the left of the button text. */ iconUrl?: string; /** * Defines the data to be passed back to the application when the button is clicked. * * The {@link NotificationActionResult} specified here will be returned to the application via a * `notification-action` event when the button is clicked. * * If omitted or `null`, applications will not receive a {@link NotificationActionEvent|`notification-action`} * event when the button is clicked. This may be appropriate if the button represents a "dismiss" or some other * side-effect-free interaction. Even if `onClick` is omitted or `null`, a `notification-closed` event will still be * raised after the button click. * */ onClick?: ActionDeclaration | null; /** * Button index used for events. This gets set when hydrating. * * @hidden */ index?: number; formOptions?: { /** * Title to display on a button when form is submitting. */ submittingTitle?: string | null; /** * Title to display on a button when form is in the error state. */ errorTitle?: string | null; /** * Title to display on a button when form is in the success state. */ successTitle?: string | null; } | null; } /** * @module Provider */ /** * Status object returned by the Provider. */ interface ProviderStatus { /** * The current connection status from the Client to the Provider. */ connected: boolean; /** * The version number of the Provider. If the Provider is not connected, this will be `null`. */ version: string | null; /** * The version number of the Templates API. If the Provider is not connected, this will be `null`. */ templateAPIVersion?: string | null; } /** * Retrieves the connection status and version semver of the Service Provider in the shape of a {@link ProviderStatus} object. * * If the Provider is connected, its' version number will be supplied in the returned object. If not, `version` will be `null`. * * ```ts * import {provider} from 'openfin-notifications'; * * const status: ProviderStatus = provider.getStatus(); * console.log(status.connected ? `Conencted to provider (version ${status.version})` : 'Not connected to provider'); * ``` * * Note: Connection status is only available when the connected provider is verison 0.11.2 or later. For earlier * versions, this API will indicate that the provider is disconnected. * * @since 0.11.2 * * Note: Template API version is only available when the connected provider is verison 1.10.2 or later. * */ declare function getStatus(): Promise; /** * Evaluates the provided version against the Providers version. * * This will return `true` if the Provider version is greater than or equal to the provided version. If not, `false` will be returned. * * If the Provider is not connected, `false` will be returned. * * ```ts * import {provider, VERSION} from 'openfin-notifications'; * * const hasMatchingProvider: boolean = provider.isConnectedToAtLeast(VERSION); * if (!hasMatchingProvider) { * console.warn('Connected to an older provider version. Some functionality may not be available.'); * } * ``` * * Note: Version information is only available when the connected provider is verison 0.11.2 or later. For earlier * versions, this API will indicate that the provider is disconnected. * * @param version Version to compare against the Provider version. This should be in semvar format. * @since 0.11.2 */ declare function isConnectedToAtLeast(version: string): Promise; type provider_d_ProviderStatus = ProviderStatus; declare const provider_d_getStatus: typeof getStatus; declare const provider_d_isConnectedToAtLeast: typeof isConnectedToAtLeast; declare namespace provider_d { export { provider_d_getStatus as getStatus, provider_d_isConnectedToAtLeast as isConnectedToAtLeast }; export type { provider_d_ProviderStatus as ProviderStatus }; } /** * @hidden */ /** * 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 */ /** * For notifications that have originated from an application running on the same machine as the provider. */ interface NotificationSourceDesktop { type: 'desktop'; /** * The identity of the window that raised this notification. * * This will always be a window of the current application - but * could have been raised by an instance of this application * running on a different machine. */ identity: OpenFin.Identity; /** * The origin of the notification, which is the url of the window that raised the notification. * This property is optional to support backward compatibility with sources that do not have the origin starting with version 2.7.1. */ origin?: string; } /** * Union of all possible notification sources. */ type NotificationSource = NotificationSourceDesktop; /** * @module Notifications */ /** * Sound options for a notification */ interface NotificationSoundOptions { /** * Determines the sound that will be played when a notification is received. * * @default 'default' plays the default notification sound. */ mode: 'default' | 'silent'; } /** * @module Notifications */ /** * Details of the application that will handle any actions coming from a particular stream. */ interface NotificationStream { /** * Unique id of the stream. */ id: string; /** * Stream title. * * Providing a different displayName for an existing stream id will update the * displayName of the stream stored in Notification Center. * */ displayName: string; /** * ID of the application source of this stream. */ appId: string; } interface NotificationsThemeSet extends ThemeSet { light: ThemeExtension; dark: ThemeExtension; } interface ThemeExtension extends DefaultTheme { notificationIndicatorColors?: Record; } interface NotificationIndicatorColorsSet { background: string; foreground: string; } declare module 'styled-components' { interface DefaultTheme { notificationIndicatorColors?: Record; } } interface NotificationsPlatform { /** * Unique identifier of the platform. */ id: string; /** * Stream title. * * Providing a different displayName for an existing stream id will update the * displayName of the stream stored in Notification Center. * */ title: string; /** * URL of the icon to be displayed for this platform. */ icon: string; /** * This is the theme associated with this platform. The center will be themed accordingly * when the platform is selected. */ theme?: NotificationsThemeSet; /** * This is the scheme associated with this platform. */ scheme?: ColorSchemeOption; /** * Workspace platform that registers this platform */ workspacePlatform?: { /** * @deprecated */ identity: OpenFin.ApplicationIdentity; analytics: { isSupported: boolean; }; }; platformIdentity: OpenFin.ApplicationIdentity; } type PlatformRegisterPayload = Omit; interface PlatformDeregisterPayload { id: string; } /** * @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 */ /** * The Notification Client library's version in semver format. * * This is the version which you are currently using. */ declare const VERSION: string; /** * Application-defined context data that can be attached to buttons on notifications. */ 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. */ type Notification = Readonly> & { readonly buttons: ReadonlyArray>; }>; 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" */ 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" */ 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" */ 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" */ 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" */ 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" */ 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" */ 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" */ 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" */ 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" */ interface ToggleNotificationSound { type: 'notification-sound-toggled'; notificationSoundEnabled: boolean; } declare function addEventListener(eventType: 'notification-form-values-changed', listener: (event: NotificationFormValuesChangedEvent) => void): void; declare function addEventListener(eventType: 'notification-form-submitted', listener: (event: NotificationFormSubmittedEvent) => void): Promise; declare function addEventListener(eventType: 'notification-action', listener: (event: NotificationActionEvent) => void): Promise; declare function addEventListener(eventType: 'notification-created', listener: (event: NotificationCreatedEvent) => void): Promise; declare function addEventListener(eventType: 'notification-toast-dismissed', listener: (event: NotificationToastDismissedEvent) => void): Promise; declare function addEventListener(eventType: 'notification-closed', listener: (event: NotificationClosedEvent) => void): Promise; declare function addEventListener(eventType: 'notifications-count-changed', listener: (event: NotificationsCountChanged) => void): Promise; declare function addEventListener(eventType: 'notification-reminder-created', listener: (event: NotificationReminderCreatedEvent) => void): Promise; declare function addEventListener(eventType: 'notification-reminder-removed', listener: (event: NotificationReminderRemovedEvent) => void): Promise; declare function addEventListener(eventType: 'notification-sound-toggled', listener: (event: ToggleNotificationSound) => void): Promise; declare function removeEventListener(eventType: 'notification-form-submitted', listener: (event: NotificationFormSubmittedEvent) => void): Promise; declare function removeEventListener(eventType: 'notification-action', listener: (event: NotificationActionEvent) => void): Promise; declare function removeEventListener(eventType: 'notification-created', listener: (event: NotificationCreatedEvent) => void): Promise; declare function removeEventListener(eventType: 'notification-toast-dismissed', listener: (event: NotificationToastDismissedEvent) => void): Promise; declare function removeEventListener(eventType: 'notification-closed', listener: (event: NotificationClosedEvent) => void): Promise; declare function removeEventListener(eventType: 'notifications-count-changed', listener: (event: NotificationsCountChanged) => void): Promise; declare function removeEventListener(eventType: 'notification-reminder-created', listener: (event: NotificationReminderCreatedEvent) => void): Promise; declare function removeEventListener(eventType: 'notification-reminder-removed', listener: (event: NotificationReminderRemovedEvent) => void): Promise; declare function removeEventListener(eventType: 'notification-form-values-changed', listener: (event: NotificationFormValuesChangedEvent) => void): void; declare function removeEventListener(eventType: 'notification-sound-toggled', listener: (event: ToggleNotificationSound) => void): Promise; /** * Extended configuration options for the notification creation. */ 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. */ 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 */ 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. */ 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. */ 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(); * ``` */ declare function clearAll(): Promise; /** * Toggles the visibility of the Notification Center. * * ```ts * import {toggleNotificationCenter} from 'openfin-notifications'; * * toggleNotificationCenter(); * ``` */ declare function toggleNotificationCenter(): Promise; declare function setDefaultPlatformShortcut(shortcut: string): Promise; /** * Options to modify the Notification Center behaviour when show() API is called. */ interface ShowOptions { navigateToAll?: boolean; } /** * Sets the visibility of the Notification Center to true. * * ```ts * import { show } from 'openfin-notifications'; * * show({ navigateToAll: false }); * ``` * @param showOptions */ declare function show(options?: ShowOptions): Promise; /** * Sets the visibility of the Notification Center to false. * * ```ts * import { hide } from 'openfin-notifications'; * * hide(); * ``` */ declare function hide(): Promise; /** * Get the total count of notifications from **all** applications. * * ```ts * import {getNotificationsCount} from 'openfin-notifications'; * * getNotificationsCount(); * ``` */ declare function getNotificationsCount(): Promise; declare const enum UserSettings { SOUND_ENABLED = "soundEnabled" } 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. */ 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. */ declare const setAllowedOrigins: (allowedOrigins: string[]) => Promise; /** * Actions are the mechanism through which notifications send messages back to the application that created them. The * service defines a number of ways in which actions can be raised (a notification being interacted with by the user, * being closed, expiring, etc.), and it is up to each application to decide if it wishes to be informed when each of * these triggers occur. * * For an action to be raised when one of these triggers occurs, the application must specify an * {@link NotificationActionResult|action result} for each trigger it is interested in. The application should then * listen for when these actions are raised by listening for the {@link NotificationActionEvent|`notification-action`} * event. * * This event is fired once each time an action is raised, and will contain the * {@link NotificationActionResult|action result} the application specified for that trigger. The application may then * use the {@link NotificationActionResult|action result} to determine which trigger occurred and respond appropriately. * * If an {@link NotificationActionResult|action result} is not specified for a particular trigger, or it is set to * `null`, the application will not receive a corresponding {@link NotificationActionEvent|`notification-action`} when * that trigger occurs. * * Unlike other event types, {@link NotificationActionEvent|`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 * {@link NotificationActionEvent|`notification-action`} events. The service will also attempt to restart the * application if it is not running when the event is fired. * * For an overview of actions, consider the sample notification below: * ```ts * import {addEventListener, create} from 'openfin-notifications'; * * // Create a notification with two buttons * create({ * // Basic info * title: 'Reminder', * body: 'Event "Weekly Meeting" is starting soon...', * * // We'll use the 'customData' field to store metadata about the event * customData: {eventId: '12345'}, * * // We want the user clicking the notification to open the associated event, so register an 'onSelect' action * onSelect: {task: 'view-calendar-event', target: 'popup'}, * * buttons: [ * // A button that will schedule another reminder for 5 minutes from now. Since the application will be * // responsible for snoozing the event, it will need to know about the user clicking this button. By setting * // a NotificationActionResult for 'onClick', the service will raise a "notification-action" event when this * // button is clicked, and will pass the value of 'onClick' as the 'result' field within the event * { * title: 'Snooze for 5 minutes', * iconUrl: 'https://www.example.com/timer.png', * onClick: { * task: 'schedule-reminder', * intervalMs: 5 * 60 * 1000 * } * }, * * // A button that closes the notification and doesn't prompt the user about this event again. Since the * // application doesn't need to do anything when the user clicks this button, we leave 'onClick' undefined * // rather than specifying a NotificationActionResult. This means that no action will be raised when the * // button is clicked, and hence no "notification-action" event will be fired * { * title: 'Dismiss', * iconUrl: 'https://www.example.com/cancel.png' * } * ] * }); * * // Create a listener that will be called for each action * // Note: This handler will be used for ALL actions, from ALL notifications that are created by this application. * addEventListener('notification-action', (event: NotificationActionEvent) => { * const {result, notification} = event; * * if (result['task'] === 'view-calendar-event') { * // Open a window with full details of the associated event * openEventDetails(notification.customData.eventId, result['target']); * } else if (result['task'] === 'schedule-reminder') { * // Schedule a new notification * scheduleReminder(notification.customData.eventId, Date.now() + result['intervalMs']); * } // Etc... * }); * ``` * * The example above uses `customData` to store details about the notification subject (in this case, a calendar * event), and `onClick` actions to inform the application about how it should respond when the user interacts with the * notification. This is our intended usage and recommended best-practice, but the service doesn't require applications * to follow this convention - application developers are free to decide how to manage notification state. * * Within the `notification-action` handler, the application must be able to understand which notification is being * handled, and how to decide what it should do next. The example above uses an application-defined `action` field to * determine the correct action, but the notification's `id`, `customData` and other fields are also useful * selectors. * * @module Actions */ /** * 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 */ /** * Denotes a field as being an action. Defining this field (with a non-`undefined` value) will result in actions being * raised and sent back to the source application when the corresponding event happens. * * For example, providing a value for the `onClick` field of {@link ButtonOptions} will result in a * {@link NotificationActionEvent|`notification-action`} event being fired when that button is clicked. * * The `NotificationActionResult returned back to an application is static * and must be defined at the point where the notification is created. */ type ActionDeclaration = NotificationActionResult; /** * Data type used to represent the action result returned back to applications when an action is raised. Applications * capture these responses by adding a `notification-action` listener. The contents of this type are entirely * application-defined, the only requirement is that the item is serializable by `JSON.stringify`. * * Since this type is entirely application-specific, the type is used in these definitions. However, there is an * optional generic argument here, which can be used if an application were to define its own conventions for the shape * of this field (which is recommended). To make use of this, define a `notification-action` handler that includes the * application-defined type as a template argument. This type is then propagated up to {@link NotificationActionEvent}. * The example below demonstrates this, using the same use-case as at the top of this page. * * ```ts * interface MyAction = SnoozeAction | DetailsAction; * * interface SnoozeAction { * task: 'schedule-reminder'; * intervalMs: number; * } * * interface DetailsAction { * task: 'view-calendar-event'; * target: 'self'|'popup'; * } * * addEventListener('notification-action', (event: NotificationActionEvent)) => { * if (event.result.task === 'schedule-reminder') { * // 'event.result' will now be strongly-typed as an instance of SnoozeAction * scheduleReminder(notification.customData.eventId, Date.now() + result.intervalMs); * } * // Etc... * }; * ``` */ type NotificationActionResult = T; /** * Lists the different triggers that can raise an {@link Actions|action}. Each action that is raised will result in a * {@link NotificationActionEvent|`notification-action`} event, which can be captured by the application that created * the notification. */ declare enum ActionTrigger { /** * The user interacted with one of the controls in the notification: a button or an actionable fragment. */ CONTROL = "control", /** * The user clicked the body of the notification itself. Any clicks of the notification that don't hit a control * or the close button will fire an event with the `'select'` action trigger. */ SELECT = "select", /** * The notification was closed, either by user interaction, programmatically by an application, or by the notification expiring. */ CLOSE = "close", /** * The notification expired. */ EXPIRE = "expire", /** * The action was triggered programmatically by an application. * * *Not currently supported* */ PROGRAMMATIC = "programmatic" } /** * Noop action types see {@link ActionNoop|ActionNoop}. */ declare enum ActionNoopType { /** * No event will be raised and no dismissal of the notification on action. */ EVENT_DISMISS = "event_dismiss" } /** * BODY_CLICK action types see {@link ActionBodyClick|ActionBodyClick}. */ declare enum ActionBodyClickType { /** * Dissmisal/Clearing event will be raised */ DISMISS_EVENT = "dismiss_event" } /** * @depracated {__NOOP__} has been deprecated. Notifications now default to not triggering the dismiss action when the body is clicked * * Setting the `__NOOP__` field on an action with a {@link ActionNoopType|type} allows you to override default user interaction with a notification. * * @example * ``` * const notification = { * //... * onSelect: {__NOOP__: ActionNoopType.EVENT_DISMISS} * }; * ``` * * When a user clicks the notification body, the notification will not be dismissed and no event will be raised to the client application. * *
  • Currently ActionBodyClickType.DISMISS_EVENT is only supported by ActionTrigger.SELECT/onSelect
  • */ interface ActionNoop { __NOOP__?: ActionNoopType; } /** * Set the `BODY_CLICK` field on an action with a {@link ActionBodyClickType|type} to allow the end-user to click the body of the notification to dismiss it. This was the default behavior in earlier releases. An event is also sent to the client application. * * Note the following restrictions: * *
      *
    • This override is ignored if buttons are passed to notification options.
    • *
    • The ActionBodyClickType.DISMISS_EVENT is supported only by ActionTrigger.SELECT/onSelect
    • * * @example * ``` * const notification = { * //... * onSelect: {BODY_CLICK: ActionBodyClickType.DISMISS_EVENT} * }; * ``` * */ interface ActionBodyClick { BODY_CLICK?: ActionBodyClickType; } type actions_d_ActionBodyClick = ActionBodyClick; type actions_d_ActionBodyClickType = ActionBodyClickType; declare const actions_d_ActionBodyClickType: typeof ActionBodyClickType; type actions_d_ActionDeclaration = ActionDeclaration; type actions_d_ActionNoop = ActionNoop; type actions_d_ActionNoopType = ActionNoopType; declare const actions_d_ActionNoopType: typeof ActionNoopType; type actions_d_ActionTrigger = ActionTrigger; declare const actions_d_ActionTrigger: typeof ActionTrigger; type actions_d_NotificationActionResult = NotificationActionResult; declare namespace actions_d { export { actions_d_ActionBodyClickType as ActionBodyClickType, actions_d_ActionNoopType as ActionNoopType, actions_d_ActionTrigger as ActionTrigger }; export type { actions_d_ActionBodyClick as ActionBodyClick, actions_d_ActionDeclaration as ActionDeclaration, actions_d_ActionNoop as ActionNoop, actions_d_NotificationActionResult as NotificationActionResult }; } /** * @hidden */ /** * File contains types used to communicate between client and provider. * * These types are a part of the client, but are not required by applications wishing to interact with the service. * This file is excluded from the public-facing TypeScript documentation. */ type ColorSchemeOption = ColorSchemeType; /** * Distribute Omit across all union types instead of Omitting the union. * https://davidgomes.com/pick-omit-over-union-types-in-typescript/ */ type DistributiveOmit = T extends unknown ? Omit : never; type MakePropertyRequired = Omit & Required>; /** * Data returned by the service when registering a platform. */ interface NotificationsRegistration { /** * Version of the client API. */ clientAPIVersion: string; /** * Version of the notification service that is running. * A response of 'unknown' indicates that an older version of the service is running that does not support returning the service version. */ notificationsVersion: string; } /** * Options for using privately hosted notification service. */ type CustomManifestOptions = { /** * A custom manifest location to start the notification service from. * The UUID cannot be OpenFin hosted Notification Service UUID, 'notifications-service'. */ manifestUrl: string; /** * The UUID of the provided custom notifications service manifest. * This value **MUST** match the UUID of the manifest provided in `manifestUrl`. */ manifestUuid: string; }; /** * Options for registering the notification service. * @property customManifest - Options for using privately hosted notification service. * @property toggleNotificationCenterHotkey - The hotkey combination to toggle the notification center. */ type RegistrationOptions = { customManifest?: CustomManifestOptions; }; type WebNotificationProviderConfig = NotificationProviderInfo & { environment?: 'web'; /** * `fin` entry point for the Here Core Web. * For setup instructions, see: https://www.npmjs.com/package/@openfin/core-web */ finContext: OpenFin.Fin<'external connection'>; }; type DesktopNotificationProviderConfig = RegistrationOptions & { environment: 'desktop'; /** * `fin` entry point for the Here Core. */ finContext: OpenFin.Fin<'window' | 'view'>; }; type NotificationProviderConfig = DesktopNotificationProviderConfig | WebNotificationProviderConfig; declare function connectToNotifications(config: NotificationProviderConfig): Promise; export { ActionBodyClickType, ActionNoopType, ActionTrigger, BooleanWidgetType, CheckboxGroupWidgetType, ContainerTemplateFragmentNames, DateWidgetType, FieldType, IndicatorColor, IndicatorType as NotificationIndicatorType, NumberWidgetType, PresentationTemplateFragmentNames, RadioGroupWidgetType, StringWidgetType, TemplateFragmentNames, TemplateNames, TimeWidgetType, UserSettings, VERSION, WidgetType, actions_d as actions, addEventListener, clear, clearAll, connectToNotifications, create, getAll, getNotificationsCount, getUserSettingStatus, hide, provider_d as provider, removeEventListener, setAllowedOrigins, setDefaultPlatformShortcut, show, toggleNotificationCenter, update }; export type { ActionBodyClick, ActionDeclaration, ActionNoop, ActionableFragment, ActionableTextTemplateFragment, AnyFormField, BaseField, BaseNotificationOptions, BaseTemplateFragment, BaseUpdatableNotificationOptions, BaseWidgetSpec, BodyTemplateOptions, BooleanField, BooleanWidget, ButtonOptions, ButtonTemplateOptions, CheckboxGroupField, CheckboxGroupWidget, CheckboxGroupWidgetSpec, CheckboxWidgetSpec, ContainerTemplateFragment, ControlOptions, CustomData, CustomTemplateData, CustomTemplateOptions, CustomValidationError, DateField, DateFieldValue, DateWidget, DateWidgetSpec, DesktopNotificationProviderConfig, DropdownWidget, DropdownWidgetSpec, Form, FormField, FormFieldWithRequiredLabel, FormSettings, FormStatus, FormStatusOptions, ImageTemplateFragment, IndicatorTemplateOptions, ListPairs, ListTemplateFragment, Notification, NotificationActionEvent, NotificationActionResult, NotificationClosedEvent, NotificationCreatedEvent, NotificationCreationOptions, NotificationFormData, NotificationFormDataWithRequiredLabel, NotificationFormSubmittedEvent, NotificationFormValuesChangedEvent, NotificationIndicator, NotificationIndicatorWithCustomColor, NotificationOptions, NotificationProviderConfig, NotificationReminderCreatedEvent, NotificationReminderRemovedEvent, NotificationSoundOptions, NotificationSource, NotificationSourceDesktop, NotificationStream, NotificationToastDismissedEvent, NotificationsCountChanged, NumberField, NumberWidget, NumberWidgetSpec, PlatformDeregisterPayload, PlatformRegisterPayload, PresentationTemplateFragment, PrimaryControlOptions, RadioGroupField, RadioGroupWidget, RadioGroupWidgetSpec, SectionAlignment, ShowOptions, StringField, StringWidget, TemplateComposition, TemplateCustom, TemplateFragment, TemplateList, TemplateMarkdown, TextTemplateFragment, TextWidgetSpec, TimeField, TimeFieldValue, TimeWidget, TimeWidgetSpec, ToggleNotificationSound, ToggleWidgetSpec, UpdatableNotification, UpdatableNotificationOptions, UpdatableNotificationTemplateCustom, UpdatableNotificationTemplateList, UpdatableNotificationTemplateMarkdown, UserSettingStatus, ValidationEntry, WebNotificationProviderConfig, Widget };