From d959efd3fe9de8df8403c12145e71a9b159982e7 Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Mon, 11 Mar 2019 19:24:18 +0100 Subject: [PATCH] [@types/node-notifier] Update typings (#33419) * Update node-notifier typings * Add typings for NotificationCallback --- types/node-notifier/index.d.ts | 111 ++++++++++++++++----- types/node-notifier/node-notifier-tests.ts | 49 +++++---- 2 files changed, 116 insertions(+), 44 deletions(-) diff --git a/types/node-notifier/index.d.ts b/types/node-notifier/index.d.ts index dad13583b91e1b..7846a9b24683cc 100644 --- a/types/node-notifier/index.d.ts +++ b/types/node-notifier/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for node-notifier +// Type definitions for node-notifier 5.4.0 // Project: https://github.com/mikaelbr/node-notifier // Definitions by: Qubo +// Lorenzo Rapetti // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -14,12 +15,30 @@ declare module "node-notifier" { namespace nodeNotifier { interface NodeNotifier extends NodeJS.EventEmitter { + notify( + notification?: NotificationCenter.Notification, + callback?: NotificationCallback + ): NotificationCenter; + notify( + notification?: WindowsToaster.Notification, + callback?: NotificationCallback + ): WindowsToaster; + notify( + notification?: WindowsBalloon.Notification, + callback?: NotificationCallback + ): WindowsBalloon; + notify( + notification?: NotifySend.Notification, + callback?: NotificationCallback + ): NotifySend; + notify(notification?: Growl.Notification, callback?: NotificationCallback): Growl; notify(notification?: Notification, callback?: NotificationCallback): NodeNotifier; - NotificationCenter: NotificationCenter; - NotifySend: NotifySend; - WindowsToaster: WindowsToaster; - WindowsBalloon: WindowsBalloon; - Growl: Growl; + notify(notification?: string, callback?: NotificationCallback): NodeNotifier; + NotificationCenter: typeof NotificationCenter; + NotifySend: typeof NotifySend; + WindowsToaster: typeof WindowsToaster; + WindowsBalloon: typeof WindowsBalloon; + Growl: typeof Growl; } interface Notification { @@ -27,15 +46,25 @@ declare module "node-notifier" { message?: string; /** Absolute path (not balloons) */ icon?: string; - /** Only Notification Center or Windows Toasters */ - sound?: boolean; /** Wait with callback until user action is taken on notification */ wait?: boolean; } - interface NotificationCallback { - (err: any, response: any): any; - } + interface NotificationMetadata { + activationType?: string; + activationAt?: string; + deliveredAt?: string; + activationValue?: string; + activationValueIndex?: string; + } + + interface NotificationCallback { + ( + err: Error | null, + response: string, + metadata?: NotificationMetadata, + ): void; + } interface Option { withFallback?: boolean; @@ -58,11 +87,31 @@ declare module "node-notifier/notifiers/notificationcenter" { namespace NotificationCenter { interface Notification extends notifier.Notification { + /** + * Case Sensitive string for location of sound file, or use one of macOS' native sounds. + */ + sound?: boolean | string; subtitle?: string; /** Attach image? (Absolute path) */ contentImage?: string; /** URL to open on click */ open?: string; + /** + * The amount of seconds before the notification closes. + * Takes precedence over wait if both are defined. + */ + timeout?: number; + /** Label for cancel button */ + closeLabel?: string; + /** Action label or list of labels in case of dropdown. */ + actions?: string | string[]; + /** Label to be used if there are multiple actions */ + dropdownLabel?: string; + /** + * If notification should take input. + * Value passed as third argument in callback and event emitter. + */ + reply?: boolean; } } @@ -101,7 +150,27 @@ declare module "node-notifier/notifiers/toaster" { class WindowsToaster { constructor(option?: notifier.Option); - notify(notification?: notifier.Notification, callback?: notifier.NotificationCallback): WindowsToaster; + notify(notification?: WindowsToaster.Notification, callback?: notifier.NotificationCallback): WindowsToaster; + } + + namespace WindowsToaster { + interface Notification extends notifier.Notification { + /** + * Defined by http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx + */ + sound?: boolean | string; + /** ID to use for closing notification. */ + id?: number; + /** App.ID and app Name. Defaults to no value, causing SnoreToast text to be visible. */ + appID?: string; + /** Refer to previously created notification to close. */ + remove?: number; + /** + * Creates a shortcut in the start menu which point to the + * executable , appID used for the notifications. + */ + install?: string; + } } export = WindowsToaster; @@ -122,19 +191,13 @@ declare module "node-notifier/notifiers/growl" { port?: number; } - interface Notification { - title?: string; - message?: string; - /** Absolute path (not balloons) */ - icon?: string; - /** Wait with callback until user action is taken on notification */ - wait?: boolean; + interface Notification extends notifier.Notification { /** whether or not to sticky the notification (defaults to false) */ - sticky?: boolean; + sticky?: boolean; /** type of notification to use (defaults to the first registered type) */ - label: string; + label?: string; /** the priority of the notification from lowest (-2) to highest (2) */ - priority: number; + priority?: number; } } @@ -153,12 +216,12 @@ declare module "node-notifier/notifiers/balloon" { interface Notification { title?: string; message?: string; - /** Only Notification Center or Windows Toasters */ - sound?: boolean; /** How long to show balloons in ms */ time?: number; /** Wait with callback until user action is taken on notification */ wait?: boolean; + /** The notification type */ + type?: 'info' | 'warn' | 'error'; } } diff --git a/types/node-notifier/node-notifier-tests.ts b/types/node-notifier/node-notifier-tests.ts index 7e6ce74c141439..6162196c865a8b 100644 --- a/types/node-notifier/node-notifier-tests.ts +++ b/types/node-notifier/node-notifier-tests.ts @@ -4,6 +4,8 @@ import notifier = require('node-notifier'); import * as path from 'path'; +notifier.notify(); +notifier.notify('Hello there'); notifier.notify({ title: 'My awesome title', message: 'Hello from node, Mr. User!', @@ -22,8 +24,8 @@ notifier.on('timeout', function (notifierObject: any, options: any) { // Happens if `wait: true` and notification closes }); -const options = { }; +const options = { }; import NotificationCenter = require('node-notifier/notifiers/notificationcenter'); new NotificationCenter(options).notify(); @@ -41,35 +43,38 @@ import WindowsBalloon = require('node-notifier/notifiers/balloon'); new WindowsBalloon(options).notify(); -var nn = require('node-notifier'); - -new nn.NotificationCenter(options).notify(); -new nn.NotifySend(options).notify(); -new nn.WindowsToaster(options).notify(options); -new nn.WindowsBalloon(options).notify(options); -new nn.Growl(options).notify(options); +new notifier.NotificationCenter(options).notify(); +new notifier.NotifySend(options).notify(); +new notifier.WindowsToaster(options).notify(options); +new notifier.WindowsBalloon(options).notify(options); +new notifier.Growl(options).notify(options); // // All notification options with their defaults: // -var NotificationCenter2 = require('node-notifier').NotificationCenter; +const NotificationCenter2 = notifier.NotificationCenter; -var notifier2 = new NotificationCenter2({ +const notifier2 = new NotificationCenter2({ withFallback: false, // use Growl if <= 10.8? customPath: void 0 // Relative path if you want to use your fork of terminal-notifier }); notifier2.notify({ - 'title': void 0, - 'subtitle': void 0, - 'message': void 0, - 'sound': false, // Case Sensitive string of sound file (see below) - 'icon': 'Terminal Icon', // Set icon? (Absolute path to image) - 'contentImage': void 0, // Attach image? (Absolute path) - 'open': void 0, // URL to open on click - 'wait': false // if wait for notification to end + title: void 0, + subtitle: void 0, + message: void 0, + sound: false, // Case Sensitive string of sound file (see below) + icon: 'Terminal Icon', // Set icon? (Absolute path to image) + contentImage: void 0, // Attach image? (Absolute path) + open: void 0, // URL to open on click + wait: false, // if wait for notification to end + actions: ['Action 1', 'Action 2'], + closeLabel: 'Close', + dropdownLabel: 'Dropdown', + reply: true, + timeout: 10 }, function(error: any, response: any) { console.log(response); }); @@ -78,9 +83,9 @@ notifier2.notify({ // Usage WindowsToaster // -var WindowsToaster2 = require('node-notifier').WindowsToaster; +const WindowsToaster2 = notifier.WindowsToaster; -var notifier3 = new WindowsToaster2({ +const notifier3 = new WindowsToaster2({ withFallback: false, // Fallback to Growl or Balloons? customPath: void 0 // Relative path if you want to use your fork of toast.exe }); @@ -91,6 +96,10 @@ notifier3.notify({ icon: void 0, // absolute path to an icon sound: false, // true | false. wait: false, // if wait for notification to end + appID: '', + id: 1, + install: '/', + remove: 1 }, function(error: any, response: any) { console.log(response); });