Skip to content

Commit

Permalink
[@types/node-notifier] Update typings (#33419)
Browse files Browse the repository at this point in the history
* Update node-notifier typings

* Add typings for NotificationCallback
  • Loading branch information
lorenzorapetti authored and weswigham committed Mar 11, 2019
1 parent 3db0bee commit d959efd
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 44 deletions.
111 changes: 87 additions & 24 deletions 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 <https://github.com/tkQubo>
// Lorenzo Rapetti <https://github.com/loryman>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node" />
Expand All @@ -14,28 +15,56 @@ 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 {
title?: string;
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;
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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 <path> in the start menu which point to the
* executable <application>, appID used for the notifications.
*/
install?: string;
}
}

export = WindowsToaster;
Expand All @@ -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;
}
}

Expand All @@ -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';
}
}

Expand Down
49 changes: 29 additions & 20 deletions types/node-notifier/node-notifier-tests.ts
Expand Up @@ -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!',
Expand All @@ -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();
Expand All @@ -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);
});
Expand All @@ -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
});
Expand All @@ -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);
});
Expand Down

0 comments on commit d959efd

Please sign in to comment.