Socket
Socket
Sign inDemoInstall

node-notifier

Package Overview
Dependencies
5
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.6.1 to 5.0.0

vendor/snoreToast/SnoreToast.exe

44

CHANGELOG.md
Changelog
===
### `v5.0.0`
#### Breaking Changes
1. CLI is now removed. Can be found in separate project: https://github.com/mikaelbr/node-notifier-cli. This means you no longer get the `notify` bin when installing `node-notifier`. To get this do `npm i [-g] node-notifier-cli`
2. Changed toaster implementation from `toast.exe` to [Snoretoast](https://github.com/KDE/snoretoast). This means if you are using your custom fork, you need to change. SnoreToast has some better default implemented functionality.
3. [terminal-notifier](https://github.com/julienXX/terminal-notifier) dependency has been bumped to `v1.7.1`. With that there can be changes in the API, and supports now reply and buttons. Output has changed to JSON by default, this means the output of some functions of the terminal-notifier has broken. See https://github.com/julienXX/terminal-notifier for more details. See [README](https://github.com/mikaelbr/node-notifier#usage-notificationcenter) for documentation on how to use the new features, or [an example file](https://github.com/mikaelbr/node-notifier/blob/master/example/macInput.js).
4. `notify` method will now throw error if second argument is something else than function (still optional): [#138](https://github.com/mikaelbr/node-notifier/pull/138).
#### Additions
1. Now supports *BSD systems: [#142](https://github.com/mikaelbr/node-notifier/pull/142).
2. With the new toaster implementation you can do more! For instance customize sound and close notification. See all options:
```javascript
{
title: void 0, // String. Required
message: void 0, // String. Required if remove is not defined
icon: void 0, // String. Absolute path to Icon
sound: false, // Bool | String (as defined by http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx)
wait: false, // Bool. Wait for User Action against Notification or times out
id: void 0, // Number. ID to use for closing notification.
appID: void 0, // String. App.ID. Don't create a shortcut but use the provided app id.
remove: void 0, // Number. Refer to previously created notification to close.
install: void 0 // String (path, application, app id). Creates a shortcut <path> in the start menu which point to the executable <application>, appID used for the notifications.
}
```
#### Fixes
1. Fixes new lines on messages on Windows: [#123](https://github.com/mikaelbr/node-notifier/issues/123)
#### Technical Changes
_Internal changes for those who might be interested_.
1. Dependencies bumped
2. Unnecessary dependencies removed (`lodash.deepClone`). Now uses JSON serialize/deserialize instead.
3. Project is auto-formatted by [`prettier`](https://github.com/jlongster/prettier).
4. [Linting is added](https://github.com/mikaelbr/node-notifier/blob/master/.eslintrc)
5. Added way to better debug what is happening by setting `DEBUG` env-var to `true`. See [CONTRIBUTE.md](https://github.com/mikaelbr/node-notifier/blob/master/CONTRIBUTE.md) for more details.
### `v4.6.1`
1. Adds npm ignore file, ignoring tests and examples from package.
2. Fixes CI builds
2. Fixes CI builds.

@@ -10,0 +52,0 @@ ### `v4.6.0`

17

index.js
var os = require('os');
var utils = require('./lib/utils');
var utils = require('./lib/utils');

@@ -8,8 +8,8 @@ // All notifiers

var WindowsToaster = require('./notifiers/toaster');
var Growl = require('./notifiers/growl');
var WindowsBalloon = require('./notifiers/balloon');
var Growl = require('./notifiers/growl');
var WindowsBalloon = require('./notifiers/balloon');
var options = { withFallback: true };
switch(os.type()) {
switch (os.type()) {
case 'Linux':

@@ -33,4 +33,9 @@ module.exports = new NotifySend(options);

default:
module.exports = new Growl(options);
module.exports.Notification = Growl;
if (os.type().match(/BSD$/)) {
module.exports = new NotifySend(options);
module.exports.Notification = NotifySend;
} else {
module.exports = new Growl(options);
module.exports.Notification = Growl;
}
}

@@ -37,0 +42,0 @@

var net = require('net');
var hasGrowl = false;
module.exports = function (growlConfig, cb) {
if (typeof cb == 'undefined') {
module.exports = function(growlConfig, cb) {
if (typeof cb === 'undefined') {
cb = growlConfig;

@@ -8,0 +7,0 @@ growlConfig = {};

@@ -1,12 +0,16 @@

var cp = require('child_process'),
os = require('os'),
fs = require('fs'),
url = require('url'),
path = require('path'),
shellwords = require('shellwords'),
semver = require('semver'),
clone = require('lodash.clonedeep');
var shellwords = require('shellwords');
var cp = require('child_process');
var semver = require('semver');
var path = require('path');
var url = require('url');
var os = require('os');
var fs = require('fs');
function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
var escapeQuotes = function (str) {
module.exports.clone = clone;
var escapeQuotes = function(str) {
if (typeof str === 'string') {

@@ -19,4 +23,4 @@ return str.replace(/(["$`\\])/g, '\\$1');

var inArray = function (arr, val) {
for(var i = 0; i < arr.length; i++) {
var inArray = function(arr, val) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === val) {

@@ -30,20 +34,30 @@ return true;

var notifySendFlags = {
"u": "urgency",
"urgency": "urgency",
"t": "expire-time",
"e": "expire-time",
"expire": "expire-time",
"expire-time": "expire-time",
"i": "icon",
"icon": "icon",
"c": "category",
"category": "category",
"subtitle": "category",
"h": "hint",
"hint": "hint"
u: 'urgency',
urgency: 'urgency',
t: 'expire-time',
e: 'expire-time',
expire: 'expire-time',
'expire-time': 'expire-time',
i: 'icon',
icon: 'icon',
c: 'category',
category: 'category',
subtitle: 'category',
h: 'hint',
hint: 'hint'
};
module.exports.command = function (notifier, options, cb) {
module.exports.command = function(notifier, options, cb) {
notifier = shellwords.escape(notifier);
return cp.exec(notifier + ' ' + options.join(' '), function (error, stdout, stderr) {
if (process.env.DEBUG) {
console.info('node-notifier debug info (command):');
console.info('[notifier path]', notifier);
console.info('[notifier options]', options.join(' '));
}
return cp.exec(notifier + ' ' + options.join(' '), function(
error,
stdout,
stderr
) {
if (error) return cb(error);

@@ -54,4 +68,10 @@ cb(stderr, stdout);

module.exports.fileCommand = function (notifier, options, cb) {
return cp.execFile(notifier, options, function (error, stdout, stderr) {
module.exports.fileCommand = function(notifier, options, cb) {
if (process.env.DEBUG) {
console.info('node-notifier debug info (fileCommand):');
console.info('[notifier path]', notifier);
console.info('[notifier options]', options.join(' '));
}
return cp.execFile(notifier, options, function(error, stdout, stderr) {
if (error) return cb(error, stdout);

@@ -62,5 +82,30 @@ cb(stderr, stdout);

module.exports.immediateFileCommand = function (notifier, options, cb) {
notifierExists(notifier, function (exists) {
if (!exists) return cb(new Error('Notifier (' + notifier + ') not found on system.'));
module.exports.fileCommandJson = function(notifier, options, cb) {
if (process.env.DEBUG) {
console.info('node-notifier debug info (fileCommandJson):');
console.info('[notifier path]', notifier);
console.info('[notifier options]', options.join(' '));
}
return cp.execFile(notifier, options, function(error, stdout, stderr) {
if (error) return cb(error, stdout);
try {
var data = JSON.parse(stdout);
cb(stderr, data);
} catch (e) {
cb(e, stdout);
}
});
};
module.exports.immediateFileCommand = function(notifier, options, cb) {
if (process.env.DEBUG) {
console.info('node-notifier debug info (notifier):');
console.info('[notifier path]', notifier);
}
notifierExists(notifier, function(exists) {
if (!exists) {
return cb(new Error('Notifier (' + notifier + ') not found on system.'));
}
cp.execFile(notifier, options);

@@ -71,8 +116,8 @@ cb();

function notifierExists (notifier, cb) {
return fs.stat(notifier, function (err, stat) {
function notifierExists(notifier, cb) {
return fs.stat(notifier, function(err, stat) {
if (!err) return cb(stat.isFile());
// Check if Windows alias
if (!!path.extname(notifier)) {
if (path.extname(notifier)) {
// Has extentioon, no need to check more

@@ -83,3 +128,4 @@ return cb(false);

// Check if there is an exe file in the directory
return fs.stat(notifier + '.exe', function (err, stat) {
return fs.stat(notifier + '.exe', function(err, stat) {
if (err) return cb(false);
cb(stat.isFile());

@@ -90,3 +136,3 @@ });

var mapAppIcon = function (options) {
var mapAppIcon = function(options) {
if (options.appIcon) {

@@ -100,3 +146,3 @@ options.icon = options.appIcon;

var mapText = function (options) {
var mapText = function(options) {
if (options.text) {

@@ -110,3 +156,3 @@ options.message = options.text;

var mapIconShorthand = function (options) {
var mapIconShorthand = function(options) {
if (options.i) {

@@ -120,3 +166,3 @@ options.icon = options.i;

module.exports.mapToNotifySend = function (options) {
module.exports.mapToNotifySend = function(options) {
options = mapAppIcon(options);

@@ -126,4 +172,4 @@ options = mapText(options);

for (var key in options) {
if (key === "message" || key === "title") continue;
if (options.hasOwnProperty(key) && (notifySendFlags[key] != key)) {
if (key === 'message' || key === 'title') continue;
if (options.hasOwnProperty(key) && notifySendFlags[key] !== key) {
options[notifySendFlags[key]] = options[key];

@@ -137,3 +183,3 @@ delete options[key];

module.exports.mapToGrowl = function (options) {
module.exports.mapToGrowl = function(options) {
options = mapAppIcon(options);

@@ -146,4 +192,3 @@ options = mapIconShorthand(options);

options.icon = fs.readFileSync(options.icon);
}catch(ex){
} catch (ex) {
}

@@ -155,3 +200,3 @@ }

module.exports.mapToMac = function (options) {
module.exports.mapToMac = function(options) {
options = mapIconShorthand(options);

@@ -173,28 +218,61 @@ options = mapText(options);

if (options.sound && options.sound.indexOf('Notification.') === 0) {
options.sound = 'Bottle';
}
if (options.wait === true) {
if (!options.timeout) {
options.timeout = 5;
}
delete options.wait;
}
options.json = true;
return options;
};
module.exports.actionJackerDecorator = function (emitter, options, fn, mapper) {
function isArray(arr) {
return Object.prototype.toString.call(arr) === '[object Array]';
}
function noop() {
}
module.exports.actionJackerDecorator = function(emitter, options, fn, mapper) {
options = clone(options);
fn = fn || function (err, data) {};
return function (err, data) {
fn = fn || noop;
if (typeof fn !== 'function') {
throw new TypeError(
'The second argument must be a function callback. You have passed ' +
typeof fn
);
}
return function(err, data) {
var resultantData = data;
var metadata = {};
// Allow for extra data if resultantData is an object
if (resultantData && typeof resultantData === 'object') {
metadata = resultantData;
resultantData = resultantData.activationType;
}
// Sanitize the data
if(resultantData) {
if (resultantData) {
resultantData = resultantData.toLowerCase().trim();
if(resultantData.match(/^activate/)) {
if (resultantData.match(/^activate|clicked$/)) {
resultantData = 'activate';
}
}
fn.apply(emitter, [err, resultantData]);
if (err || !mapper || !resultantData) return;
fn.apply(emitter, [ err, resultantData, metadata ]);
if (!mapper || !resultantData) return;
var key = mapper(resultantData);
if (!key) return;
emitter.emit(key, emitter, options);
emitter.emit(key, emitter, options, metadata);
};
};
module.exports.constructArgumentList = function (options, extra) {
module.exports.constructArgumentList = function(options, extra) {
var args = [];

@@ -205,3 +283,3 @@ extra = extra || {};

var initial = extra.initial || [];
var keyExtra = extra.keyExtra || "";
var keyExtra = extra.keyExtra || '';
var allowedArguments = extra.allowedArguments || [];

@@ -211,22 +289,35 @@ var noEscape = extra.noEscape !== void 0;

var explicitTrue = !!extra.explicitTrue;
var keepNewlines = !!extra.keepNewlines;
var wrapper = extra.wrapper === void 0 ? '"' : extra.wrapper;
var escapeFn = function(arg) {
if (isArray(arg)) {
return removeNewLines(
arg.map(function(current) {
return '"' + escapeQuotes(current) + '"';
}).join(',')
);
}
if (!noEscape) {
arg = escapeQuotes(arg);
}
if(typeof arg === 'string'){
arg = arg.replace(/\r?\n/g, '\\n');
if (typeof arg === 'string' && !keepNewlines) {
arg = removeNewLines(arg);
}
return arg;
}
return wrapper + arg + wrapper;
};
initial.forEach(function (val) {
args.push(wrapper + escapeFn(val) + wrapper);
initial.forEach(function(val) {
args.push(escapeFn(val));
});
for(var key in options) {
if (options.hasOwnProperty(key) && (!checkForAllowed || inArray(allowedArguments, key))) {
if (explicitTrue && options[key] === true) args.push('-' + keyExtra + key);
else if (explicitTrue && options[key] === false) continue;
else args.push('-' + keyExtra + key, wrapper + escapeFn(options[key]) + wrapper);
for (var key in options) {
if (
options.hasOwnProperty(key) &&
(!checkForAllowed || inArray(allowedArguments, key))
) {
if (explicitTrue && options[key] === true) {
args.push('-' + keyExtra + key);
} else if (explicitTrue && options[key] === false) continue;
else args.push('-' + keyExtra + key, escapeFn(options[key]));
}

@@ -237,11 +328,43 @@ }

module.exports.mapToWin8 = function (options){
function removeNewLines(str) {
var excapedNewline = process.platform === 'win32' ? '\\r\\n' : '\\n';
return str.replace(/\r?\n/g, excapedNewline);
}
/*
---- Options ----
[-t] <title string> | Displayed on the first line of the toast.
[-m] <message string> | Displayed on the remaining lines, wrapped.
[-p] <image URI> | Display toast with an image, local files only.
[-w] | Wait for toast to expire or activate.
[-id] <id> | sets the id for a notification to be able to close it later.
[-s] <sound URI> | Sets the sound of the notifications, for possible values see http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx.
[-silent] | Don't play a sound file when showing the notifications.
[-appID] <App.ID> | Don't create a shortcut but use the provided app id.
-close <id> | Closes a currently displayed notification, in order to be able to close a notification the parameter -w must be used to create the notification.
*/
var allowedToasterFlags = [
't',
'm',
'p',
'w',
'id',
's',
'silent',
'appID',
'close',
'install'
];
var toasterSoundPrefix = 'Notification.';
var toasterDefaultSound = 'Notification.Default';
module.exports.mapToWin8 = function(options) {
options = mapAppIcon(options);
options = mapText(options);
if(options.icon){
if (options.icon) {
if (/^file:\/+/.test(options.icon)) {
// should parse file protocol URL to path
options.p = url.parse(options.icon).pathname.replace(/^\/(\w\:\/)/, "$1").replace(/\//g, "\\");
options.p = url.parse(options.icon).pathname
.replace(/^\/(\w:\/)/, '$1')
.replace(/\//g, '\\');
} else {

@@ -253,3 +376,3 @@ options.p = options.icon;

if(options.message){
if (options.message) {
// Remove escape char to debug "HRESULT : 0xC00CE508" exception

@@ -265,19 +388,35 @@ options.m = options.message.replace(/\x1b/g, '');

if (typeof options.remove !== 'undefined') {
options.close = options.remove;
delete options.remove;
}
if (options.quiet || options.silent) {
options.q = options.quiet || options.silent;
options.silent = options.quiet || options.silent;
delete options.quiet;
delete options.silent;
}
if (options.q !== false) {
options.q = true;
} else {
delete options.q;
if (typeof options.sound !== 'undefined') {
options.s = options.sound;
delete options.sound;
}
if (options.sound) {
delete options.q;
delete options.sound;
if (options.s === false) {
options.silent = true;
delete options.s;
}
// Silent takes precedence. Remove sound.
if (options.s && options.silent) {
delete options.s;
}
if (options.s === true) {
options.s = toasterDefaultSound;
}
if (options.s && options.s.indexOf(toasterSoundPrefix) !== 0) {
options.s = toasterDefaultSound;
}
if (options.wait) {

@@ -288,10 +427,19 @@ options.w = options.wait;

for (var key in options) {
// Check if is allowed. If not, delete!
if (
options.hasOwnProperty(key) && allowedToasterFlags.indexOf(key) === -1
) {
delete options[key];
}
}
return options;
};
module.exports.mapToNotifu = function (options) {
module.exports.mapToNotifu = function(options) {
options = mapAppIcon(options);
options = mapText(options);
if(options.icon){
if (options.icon) {
options.i = options.icon;

@@ -301,3 +449,3 @@ delete options.icon;

if(options.message){
if (options.message) {
options.m = options.message;

@@ -351,14 +499,17 @@ delete options.message;

module.exports.isMountainLion = function() {
return os.type() === 'Darwin' && semver.satisfies(garanteeSemverFormat(os.release()), '>=12.0.0');
return os.type() === 'Darwin' &&
semver.satisfies(garanteeSemverFormat(os.release()), '>=12.0.0');
};
module.exports.isWin8 = function() {
return os.type() === 'Windows_NT' && semver.satisfies(garanteeSemverFormat(os.release()), '>=6.2.9200');
return os.type() === 'Windows_NT' &&
semver.satisfies(garanteeSemverFormat(os.release()), '>=6.2.9200');
};
module.exports.isLessThanWin8 = function() {
return os.type() === 'Windows_NT' && semver.satisfies(garanteeSemverFormat(os.release()), '<6.2.9200');
return os.type() === 'Windows_NT' &&
semver.satisfies(garanteeSemverFormat(os.release()), '<6.2.9200');
};
function garanteeSemverFormat (version) {
function garanteeSemverFormat(version) {
if (version.split('.').length === 2) {

@@ -372,11 +523,8 @@ version += '.0';

if (typeof type === 'string' || type instanceof String) {
if (type.toLowerCase() == 'info')
return 'info';
if (type.toLowerCase() == 'warn')
return 'warn';
if (type.toLowerCase() == 'error')
return 'error';
if (type.toLowerCase() === 'info') return 'info';
if (type.toLowerCase() === 'warn') return 'warn';
if (type.toLowerCase() === 'error') return 'error';
}
return 'info';
}
}

@@ -18,3 +18,2 @@ /**

// Kill codes:

@@ -26,10 +25,9 @@ 2 = Timeout

*/
var path = require('path'),
notifier = path.resolve(__dirname, '../vendor/notifu/notifu'),
utils = require('../lib/utils'),
checkGrowl = require('../lib/checkGrowl'),
Toaster = require('./toaster'),
Growl = require('./growl'),
os = require('os'),
cloneDeep = require('lodash.clonedeep');
var path = require('path');
var notifier = path.resolve(__dirname, '../vendor/notifu/notifu');
var checkGrowl = require('../lib/checkGrowl');
var utils = require('../lib/utils');
var Toaster = require('./toaster');
var Growl = require('./growl');
var os = require('os');

@@ -43,4 +41,4 @@ var EventEmitter = require('events').EventEmitter;

function WindowsBalloon (options) {
options = cloneDeep(options || {});
function WindowsBalloon(options) {
options = utils.clone(options || {});
if (!(this instanceof WindowsBalloon)) {

@@ -56,21 +54,28 @@ return new WindowsBalloon(options);

WindowsBalloon.prototype.notify = function (options, callback) {
var fallback, notifierOptions = this.options;
options = cloneDeep(options || {});
callback = callback || function () {};
function noop() {
}
WindowsBalloon.prototype.notify = function(options, callback) {
var fallback;
var notifierOptions = this.options;
options = utils.clone(options || {});
callback = callback || noop;
if (typeof options === 'string') options = {
title: 'node-notifier',
message: options
};
if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
}
var actionJackedCallback = utils.actionJackerDecorator(this, options, callback, function (data) {
if (data === 'activate') {
return 'click';
var actionJackedCallback = utils.actionJackerDecorator(
this,
options,
callback,
function(data) {
if (data === 'activate') {
return 'click';
}
if (data === 'timeout') {
return 'timeout';
}
return false;
}
if (data === 'timeout') {
return 'timeout';
}
return false;
});
);

@@ -82,3 +87,6 @@ if (!!this.options.withFallback && utils.isWin8()) {

if (!!this.options.withFallback && (!utils.isLessThanWin8() || hasGrowl === true)) {
if (
!!this.options.withFallback &&
(!utils.isLessThanWin8() || hasGrowl === true)
) {
fallback = fallback || new Growl(notifierOptions);

@@ -93,3 +101,3 @@ return fallback.notify(options, callback);

checkGrowl(notifierOptions, function (hasGrowlResult) {
checkGrowl(notifierOptions, function(hasGrowlResult) {
hasGrowl = hasGrowlResult;

@@ -108,5 +116,5 @@

var allowedArguments = ["t", "d", "p", "m", "i", "e", "q", "w", "xp"];
var allowedArguments = [ 't', 'd', 'p', 'm', 'i', 'e', 'q', 'w', 'xp' ];
function doNotification (options, notifierOptions, callback) {
function doNotification(options, notifierOptions, callback) {
var is64Bit = os.arch() === 'x64';

@@ -132,4 +140,4 @@ options = options || {};

if (!!options.wait) {
return utils.fileCommand(localNotifier, argsList, function (error, data) {
if (options.wait) {
return utils.fileCommand(localNotifier, argsList, function(error, data) {
var action = fromErrorCodeToAction(error.code);

@@ -144,3 +152,3 @@ if (action === 'error') return callback(error, data);

function fromErrorCodeToAction (errorCode) {
function fromErrorCodeToAction(errorCode) {
switch (errorCode) {

@@ -147,0 +155,0 @@ case 2:

/**
* Wrapper for the growly module
*/
var utils = require('../lib/utils'),
checkGrowl = require('../lib/checkGrowl'),
growly = require('growly'),
cloneDeep = require('lodash.clonedeep');
var checkGrowl = require('../lib/checkGrowl');
var utils = require('../lib/utils');
var growly = require('growly');

@@ -12,3 +11,3 @@ var EventEmitter = require('events').EventEmitter;

var errorMessageNotFound = 'Couldn\'t connect to growl (might be used as a fallback). Make sure it is running';
var errorMessageNotFound = "Couldn't connect to growl (might be used as a fallback). Make sure it is running";

@@ -19,4 +18,4 @@ module.exports = Growl;

function Growl (options) {
options = cloneDeep(options || {});
function Growl(options) {
options = utils.clone(options || {});
if (!(this instanceof Growl)) {

@@ -33,13 +32,13 @@ return new Growl(options);

Growl.prototype.notify = function (options, callback) {
Growl.prototype.notify = function(options, callback) {
growly.setHost(this.options.host, this.options.port);
options = cloneDeep(options || {});
options = utils.clone(options || {});
if (typeof options === 'string') options = {
title: 'node-notifier',
message: options
};
if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
}
callback = utils.actionJackerDecorator(this, options, callback, function (data) {
callback = utils.actionJackerDecorator(this, options, callback, function(
data
) {
if (data === 'click') {

@@ -64,3 +63,3 @@ return 'click';

if (hasGrowl || !!options.wait) {
var localCallback = !!options.wait ? callback : function () {};
var localCallback = options.wait ? callback : noop;
growly.notify(options.message, options, localCallback);

@@ -71,3 +70,3 @@ if (!options.wait) callback();

checkGrowl(growly, function (didHaveGrowl) {
checkGrowl(growly, function(didHaveGrowl) {
hasGrowl = didHaveGrowl;

@@ -80,1 +79,4 @@ if (!didHaveGrowl) return callback(new Error(errorMessageNotFound));

};
function noop() {
}
/**
* A Node.js wrapper for terminal-notify (with fallback).
*/
var path = require('path'),
notifier = path.join(__dirname, '../vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier'),
utils = require('../lib/utils'),
Growl = require('./growl'),
cloneDeep = require('lodash.clonedeep');
var utils = require('../lib/utils');
var Growl = require('./growl');
var path = require('path');
var notifier = path.join(
__dirname,
'../vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier'
);

@@ -14,8 +16,8 @@ var EventEmitter = require('events').EventEmitter;

var errorMessageOsX = 'You need Mac OS X 10.8 or above to use NotificationCenter,' +
' or use Growl fallback with constructor option {withFallback: true}.';
' or use Growl fallback with constructor option {withFallback: true}.';
module.exports = NotificationCenter;
function NotificationCenter (options) {
options = cloneDeep(options || {});
function NotificationCenter(options) {
options = utils.clone(options || {});
if (!(this instanceof NotificationCenter)) {

@@ -31,29 +33,36 @@ return new NotificationCenter(options);

NotificationCenter.prototype.notify = function (options, callback) {
var fallbackNotifier = null, id = identificator();
options = cloneDeep(options || {});
function noop() {
}
NotificationCenter.prototype.notify = function(options, callback) {
var fallbackNotifier;
var id = identificator();
options = utils.clone(options || {});
activeId = id;
if (typeof options === 'string') options = {
title: 'node-notifier',
message: options
};
if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
}
callback = callback || function () {};
var actionJackedCallback = utils.actionJackerDecorator(this, options, callback, function (data) {
if (activeId !== id) return false;
callback = callback || noop;
var actionJackedCallback = utils.actionJackerDecorator(
this,
options,
callback,
function(data) {
if (activeId !== id) return false;
if (data === 'activate') {
return 'click';
if (data === 'activate') {
return 'click';
}
if (data === 'timeout') {
return 'timeout';
}
if (data === 'replied') {
return 'replied';
}
return false;
}
if (data === 'timeout') {
return 'timeout';
}
return false;
});
);
options = utils.mapToMac(options);
if (!!options.wait) {
options.wait = 'YES';
}

@@ -67,4 +76,8 @@ if (!options.message && !options.group && !options.list && !options.remove) {

if(utils.isMountainLion()) {
utils.fileCommand(this.options.customPath || notifier, argsList, actionJackedCallback);
if (utils.isMountainLion()) {
utils.fileCommandJson(
this.options.customPath || notifier,
argsList,
actionJackedCallback
);
return this;

@@ -82,4 +95,4 @@ }

function identificator () {
function identificator() {
return { _ref: 'val' };
}
/**
* Node.js wrapper for "notify-send".
*/
var os = require('os'),
which = require('which'),
utils = require('../lib/utils'),
cloneDeep = require('lodash.clonedeep');
var os = require('os');
var which = require('which');
var utils = require('../lib/utils');

@@ -12,8 +11,9 @@ var EventEmitter = require('events').EventEmitter;

var notifier = 'notify-send', hasNotifier = void 0;
var notifier = 'notify-send';
var hasNotifier = void 0;
module.exports = NotifySend;
function NotifySend (options) {
options = cloneDeep(options || {});
function NotifySend(options) {
options = utils.clone(options || {});
if (!(this instanceof NotifySend)) {

@@ -29,11 +29,19 @@ return new NotifySend(options);

NotifySend.prototype.notify = function (options, callback) {
options = cloneDeep(options || {});
callback = callback || function () {};
function noop() {
}
NotifySend.prototype.notify = function(options, callback) {
options = utils.clone(options || {});
callback = callback || noop;
if (typeof options === 'string') options = {
title: 'node-notifier',
message: options
};
if (typeof callback !== 'function') {
throw new TypeError(
'The second argument must be a function callback. You have passed ' +
typeof callback
);
}
if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
}
if (!options.message) {

@@ -44,4 +52,4 @@ callback(new Error('Message is required.'));

if (os.type() !== 'Linux') {
callback(new Error('Only supported on Linux systems'));
if (os.type() !== 'Linux' && !os.type().match(/BSD$/)) {
callback(new Error('Only supported on Linux and *BSD systems'));
return this;

@@ -66,3 +74,3 @@ }

return callback(err);
};
}

@@ -72,11 +80,5 @@ return this;

var allowedArguments = [
"urgency",
"expire-time",
"icon",
"category",
"hint"
];
var allowedArguments = [ 'urgency', 'expire-time', 'icon', 'category', 'hint' ];
function doNotification (options, callback) {
function doNotification(options, callback) {
var initial, argsList;

@@ -87,3 +89,3 @@

initial = [options.title, options.message];
initial = [ options.title, options.message ];
delete options.title;

@@ -90,0 +92,0 @@ delete options.message;

/**
* Wrapper for the toaster (https://github.com/nels-o/toaster)
*/
var path = require('path'),
notifier = path.resolve(__dirname, '../vendor/toaster/toast.exe'),
utils = require('../lib/utils'),
Balloon = require('./balloon'),
cloneDeep = require('lodash.clonedeep');
var path = require('path');
var notifier = path.resolve(__dirname, '../vendor/snoreToast/SnoreToast.exe');
var utils = require('../lib/utils');
var Balloon = require('./balloon');

@@ -17,4 +16,4 @@ var EventEmitter = require('events').EventEmitter;

function WindowsToaster (options) {
options = cloneDeep(options || {});
function WindowsToaster(options) {
options = utils.clone(options || {});
if (!(this instanceof WindowsToaster)) {

@@ -30,25 +29,54 @@ return new WindowsToaster(options);

WindowsToaster.prototype.notify = function (options, callback) {
options = cloneDeep(options || {});
callback = callback || function () {};
function noop() {
}
if (typeof options === 'string') options = {
title: 'node-notifier',
message: options
};
var timeoutMessage = 'the toast has timed out';
var successMessage = 'user clicked on the toast';
var actionJackedCallback = utils.actionJackerDecorator(this, options, callback, function (data) {
if (data === 'activate') {
return 'click';
function hasText(str, txt) {
return str && str.indexOf(txt) !== -1;
}
WindowsToaster.prototype.notify = function(options, callback) {
options = utils.clone(options || {});
callback = callback || noop;
if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
}
if (typeof callback !== 'function') {
throw new TypeError(
'The second argument must be a function callback. You have passed ' +
typeof fn
);
}
var actionJackedCallback = utils.actionJackerDecorator(
this,
options,
function cb(err, data) {
// Needs to filter out timeout. Not an actual error.
if (err && hasText(data, timeoutMessage)) {
return callback(null, data);
}
callback(err, data);
},
function mapper(data) {
if (hasText(data, successMessage)) {
return 'click';
}
if (hasText(data, timeoutMessage)) {
return 'timeout';
}
return false;
}
if (data === 'timeout') {
return 'timeout';
}
return false;
});
);
options.title = options.title || 'Node Notification:';
if (!options.message) {
callback(new Error('Message is required.'));
if (
typeof options.message === 'undefined' &&
typeof options.close === 'undefined'
) {
callback(new Error('Message or ID to close is required.'));
return this;

@@ -64,7 +92,13 @@ }

var argsList = utils.constructArgumentList(options, {
explicitTrue: true,
wrapper: '',
keepNewlines: true,
noEscape: true
});
utils.fileCommand(this.options.customPath || notifier, argsList, actionJackedCallback);
utils.fileCommand(
this.options.customPath || notifier,
argsList,
actionJackedCallback
);
return this;
};
{
"name": "node-notifier",
"version": "4.6.1",
"version": "5.0.0",
"description": "A Node.js module for sending notifications on native Mac, Windows (post and pre 8) and Linux (or Growl as fallback)",
"main": "index.js",
"directories": {
"example": "example"
},
"scripts": {
"test": "./node_modules/.bin/mocha -R spec"
"pretest": "npm run lint",
"test": "jest",
"example": "node ./example/message.js",
"example:mac": "node ./example/advanced.js",
"example:mac:input": "node ./example/macInput.js",
"example:windows": "node ./example/toaster.js",
"lint": "eslint example/*.js lib/*.js notifiers/*.js test/**/*.js index.js"
},
"repository": "git@github.com:mikaelbr/node-notifier.git",
"jest": {
"testRegex": "/test/[^_]*.js",
"testEnvironment": "node",
"setupTestFrameworkScriptFile": "./test/_test-matchers.js"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/mikaelbr/node-notifier.git"
},
"keywords": [

@@ -27,17 +38,23 @@ "notification center",

"devDependencies": {
"mocha": "^3.0.0",
"should": "^4.0.4"
"eslint": "^3.13.1",
"eslint-config-semistandard": "^7.0.0",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"jest": "^18.1.0"
},
"dependencies": {
"cli-usage": "^0.1.1",
"growly": "^1.2.0",
"lodash.clonedeep": "^3.0.0",
"minimist": "^1.1.1",
"semver": "^5.1.0",
"growly": "^1.3.0",
"semver": "^5.3.0",
"shellwords": "^0.1.0",
"which": "^1.0.5"
"which": "^1.2.12"
},
"bin": {
"notify": "./bin.js"
"bugs": {
"url": "https://github.com/mikaelbr/node-notifier/issues"
},
"homepage": "https://github.com/mikaelbr/node-notifier#readme",
"directories": {
"example": "example",
"test": "test"
}
}
# node-notifier [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
A Node.js module for sending cross platform system notifications. Using
Notification Center for Mac, notify-osd/libnotify-bin for Linux, Toasters for
Notification Center for macOS, notify-osd/libnotify-bin for Linux, Toasters for
Windows 8/10, or taskbar Balloons for earlier Windows versions. If none of
these requirements are met, Growl is used.
![Mac Screenshot](https://raw.githubusercontent.com/mikaelbr/node-notifier/master/example/mac.png)
![macOS Screenshot](https://raw.githubusercontent.com/mikaelbr/node-notifier/master/example/mac.png)
![Native Windows Screenshot](https://raw.githubusercontent.com/mikaelbr/node-notifier/master/example/windows.png)
![Growl Screenshot](https://raw.githubusercontent.com/mikaelbr/node-notifier/master/example/growl.png)
## Input Example macOS Notification Center
![Input Example](https://raw.githubusercontent.com/mikaelbr/node-notifier/master/example/input-example.gif)
## Quick Usage
Show a native notification on Mac, Windows, Linux:
Show a native notification on macOS, Windows, Linux:

@@ -29,3 +32,3 @@ ```javascript

## Requirements
- **Mac OS X**: >= 10.8 or Growl if earlier.
- **macOS**: >= 10.8 or Growl if earlier.
- **Linux**: `notify-osd` or `libnotify-bin` installed (Ubuntu should have this by default)

@@ -122,4 +125,4 @@ - **Windows**: >= 8, task bar balloon if earlier or Growl if that is installed.

Native Notification Center requires Mac OS X version 10.8 or higher. If you have
an earlier version, Growl will be the fallback. If Growl isn't installed, an
Native Notification Center requires macOS version 10.8 or higher. If you have
an earlier version, Growl will be the fallback. If Growl isn't installed, an
error will be returned in the callback.

@@ -144,3 +147,3 @@

withFallback: false, // Use Growl Fallback if <= 10.8
customPath: void 0 // Relative path if you want to use your fork of terminal-notifier
customPath: void 0 // Relative/Absolute path to binary if you want to use your own fork of terminal-notifier
});

@@ -152,16 +155,28 @@

'message': void 0,
'sound': false, // Case Sensitive string for location of sound file, or use one of OS X's native sounds (see below)
'sound': false, // Case Sensitive string for location of sound file, or use one of macOS' native sounds (see below)
'icon': 'Terminal Icon', // Absolute Path to Triggering Icon
'contentImage': void 0, // Absolute Path to Attached Image (Content Image)
'open': void 0, // URL to open on Click
'wait': false // Wait for User Action against Notification
}, function(error, response) {
console.log(response);
'wait': false, // Wait for User Action against Notification or times out. Same as timeout = 5 seconds
// New in latest version. See `example/macInput.js` for usage
timeout: 5, // Takes precedence over wait if both are defined.
closeLabel: void 0, // String. Label for cancel button
actions: void 0, // String | Array<String>. Action label or list of labels in case of dropdown
dropdownLabel: void 0, // String. Label to be used if multiple actions
reply: false // Boolean. If notification should take input. Value passed as third argument in callback and event emitter.
}, function(error, response, metadata) {
console.log(response, metadata);
});
```
**For Mac OS notifications, icon and contentImage requires OS X 10.9.**
**Note:** `wait` option is shorthand for `timeout: 5` and doesn't make the notification sticky, but sets
timeout for 5 seconds. Without `wait` or `timeout` notifications are just fired and forgotten Without
given any response. To be able to listen for response (like activation/clicked), you have to define a timeout.
This is not true if you have defined `reply`. If using `reply` it's recommended to set a high timeout or no timeout at all.
**For macOS notifications, icon and contentImage, and all forms of reply/actions requires macOS 10.9.**
Sound can be one of these: `Basso`, `Blow`, `Bottle`, `Frog`, `Funk`, `Glass`,
`Hero`, `Morse`, `Ping`, `Pop`, `Purr`, `Sosumi`, `Submarine`, `Tink`.
`Hero`, `Morse`, `Ping`, `Pop`, `Purr`, `Sosumi`, `Submarine`, `Tink`.
If sound is simply `true`, `Bottle` is used.

@@ -171,2 +186,8 @@

**Custom Path clarification**
`customPath` takes a value of a relative or absolute path to the binary of your fork/custom version of terminal-notifier.
Example: `./vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier`
### Usage WindowsToaster

@@ -185,3 +206,3 @@

[toaster](https://github.com/nels-o/toaster) is used to get native Windows Toasts!
[Snoretoast](https://github.com/KDE/snoretoast) is used to get native Windows Toasts!

@@ -193,11 +214,15 @@ ```javascript

withFallback: false, // Fallback to Growl or Balloons?
customPath: void 0 // Relative path if you want to use your fork of toast.exe
customPath: void 0 // Relative/Absolute path if you want to use your fork of SnoreToast.exe
});
notifier.notify({
title: void 0,
message: void 0,
icon: void 0, // Absolute path to Icon
sound: false, // true | false.
wait: false, // Wait for User Action against Notification
title: void 0, // String. Required
message: void 0, // String. Required if remove is not defined
icon: void 0, // String. Absolute path to Icon
sound: false, // Bool | String (as defined by http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx)
wait: false, // Bool. Wait for User Action against Notification or times out
id: void 0, // Number. ID to use for closing notification.
appID: void 0, // String. App.ID. Don't create a shortcut but use the provided app id.
remove: void 0, // Number. Refer to previously created notification to close.
install: void 0 // String (path, application, app id). Creates a shortcut <path> in the start menu which point to the executable <application>, appID used for the notifications.
}, function(error, response) {

@@ -222,3 +247,3 @@ console.log(response);

message: 'Hello World',
icon: fs.readFileSync(__dirname + "/coulson.jpg"),
icon: fs.readFileSync(__dirname + '/coulson.jpg'),
wait: false, // Wait for User Action against Notification

@@ -247,3 +272,3 @@

withFallback: false, // Try Windows Toast and Growl first?
customPath: void 0 // Relative path if you want to use your fork of notifu
customPath: void 0 // Relative/Absolute path if you want to use your fork of notifu
});

@@ -278,3 +303,3 @@

message: 'Hello World',
icon: __dirname + "/coulson.jpg",
icon: __dirname + '/coulson.jpg',

@@ -293,35 +318,4 @@ // .. and other notify-send flags:

You can also use node-notifier as a CLI (as of `v4.2.0`).
CLI is moved to separate project: https://github.com/mikaelbr/node-notifier-cli
```shell
$ notify -h
# notify
## Options
* --help (alias -h)
* --title (alias -t)
* --subtitle (alias -st)
* --message (alias -m)
* --icon (alias -i)
* --sound (alias -s)
* --open (alias -o)
## Example
$ notify -t "Hello" -m "My Message" -s --open http://github.com
$ notify -t "Agent Coulson" --icon https://raw.githubusercontent.com/mikaelbr/node-notifier/master/example/coulson.jpg -m "Well, that's new. "
$ notify -m "My Message" -s Glass
$ echo "My Message" | notify -t "Hello"
```
You can also pass message in as `stdin`:
```js
➜ echo "Message" | notify
# Works with existing arguments
➜ echo "Message" | notify -t "My Title"
➜ echo "Some message" | notify -t "My Title" -s
```
## Thanks to OSS

@@ -331,3 +325,3 @@

* [terminal-notifier](https://github.com/alloy/terminal-notifier)
* [toaster](https://github.com/nels-o/toaster)
* [Snoretoast](https://github.com/KDE/snoretoast)
* [notifu](http://www.paralint.com/projects/notifu/)

@@ -334,0 +328,0 @@ * [growly](https://github.com/theabraham/growly/)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc