Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mpns

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mpns - npm Package Compare versions

Comparing version 1.1.2 to 1.2.3

115

lib/mpns.js

@@ -38,2 +38,10 @@ // Copyright Jeff Wilcox

var FlipTile = function(options) {
if(!options){
options = {};
}
options.tileTemplate = 'FlipTile';
return new PushMessage('tile', '1', 'token', options);
}
var RawNotification = function(payload, options) {

@@ -54,3 +62,4 @@ if (options == undefined) {

if (options) {
copyOfInterest(options, this, propertiesOfInterest);
copyOfInterest(options, this, propertiesOfInterest,
this.pushType === 'tile');
}

@@ -61,20 +70,16 @@ }

var payload = this.getXmlPayload();
var uriInfo = url.parse(pushUri);
var me = this;
var headers = {
var options = url.parse(pushUri);
options.method = 'POST';
options.headers = {
'Content-Type': 'text/xml',
'Content-Length': Buffer.byteLength(payload),
'Content-Length': Buffer.byteLength(payload).toString(),
'Accept': 'application/*',
'X-NotificationClass': this.notificationClass,
'X-WindowsPhone-Target': this.targetName
'X-NotificationClass': this.notificationClass
};
var options = {
headers: headers,
host: uriInfo.host,
port: uriInfo.protocol == "http:" ? 80 : 443,
path: uriInfo.pathname,
method: 'POST'
};
if(this.targetName){
options.headers['X-WindowsPhone-Target'] = this.targetName;
}

@@ -99,3 +104,4 @@ var result = { };

// Store the fields that were sent to make it easy to log.
copyOfInterest(me, result, propertiesOfInterest);
copyOfInterest(me, result, propertiesOfInterest,
this.pushType === 'tile');

@@ -124,3 +130,3 @@ switch (res.statusCode) {

err = result;
err.error = 'Per-day throttling limit reached.';
err.innerError = 'Per-day throttling limit reached.';
break;

@@ -131,3 +137,3 @@

result.minutesToDelay = ERROR_MINIMUM_DELAY_MINUTES;
err.error = 'The Push Notification Service is unable to process the request.';
err.innerError = 'The Push Notification Service is unable to process the request.';
break;

@@ -142,3 +148,3 @@ }

err = result;
err.error = e;
err.innerError = e;

@@ -155,7 +161,7 @@ if (callback)

function copyOfInterest(source, destination, fieldsOfInterest) {
function copyOfInterest(source, destination, fieldsOfInterest, allowNull) {
if (source && destination && fieldsOfInterest && fieldsOfInterest.length) {
for (var i = 0; i < fieldsOfInterest.length; i++) {
var key = fieldsOfInterest[i];
if (source[key]) {
if (source[key] || (source[key] === null && allowNull)) {
destination[key] = source[key];

@@ -205,5 +211,5 @@ }

function getPushHeader(type) {
function getPushHeader(type, attributes) {
return '<?xml version="1.0" encoding="utf-8"?><wp:Notification xmlns:wp="WPNotification">' +
startTag(type);
startTag(type, attributes);
}

@@ -215,12 +221,24 @@

function startTag(tag, endInstead) {
return '<' + (endInstead ? '/' : '') + 'wp:' + tag + '>';
function startTag(tag, attributes, endInstead) {
var tag = '<' + (endInstead ? '/' : '') + 'wp:' + tag;
if(!endInstead && attributes && attributes.length){
attributes.forEach(function(pair){
tag += ' ' + pair[0] + '="' + escapeXml(pair[1]) + '"';
});
}
tag += '>';
return tag;
}
function endTag(tag) {
return startTag(tag, true);
return startTag(tag, null, true);
}
function wrapValue(object, key, name) {
return object[key] ? startTag(name) + escapeXml(object[key]) + endTag(name) : null;
// We want to clear the value
if(object[key] === null){
return startTag(name, [['Action', 'Clear']]) + endTag(name);
} else {
return object[key] ? startTag(name) + escapeXml(object[key]) + endTag(name) : '';
}
}

@@ -239,3 +257,3 @@

var type = 'Tile';
return getPushHeader(type) +
return getPushHeader(type, tileGetAttributes(options)) +
wrapValue(options, 'backgroundImage', 'BackgroundImage') +

@@ -247,5 +265,20 @@ wrapValue(options, 'count', 'Count') +

wrapValue(options, 'backContent', 'BackContent') +
wrapValue(options, 'smallbackgroundImage', 'SmallbackgroundImage') +
wrapValue(options, 'wideBackgroundImage', 'WideBackgroundImage') +
wrapValue(options, 'wideBackContent', 'WideBackContent') +
wrapValue(options, 'wideBackBackgroundImage', 'WideBackBackgroundImage') +
getPushFooter(type);
}
function tileGetAttributes(options){
var attributes = [];
if(options.tileTemplate){
attributes.push(['Template', options.tileTemplate]);
}
if (options.id){
attributes.push(['Id', options.id]);
};;
return attributes;
}
exports.sendTile = function () {

@@ -255,2 +288,6 @@ send('tile', tileProperties, LiveTile, arguments);

exports.sendFlipTile = function() {
send('tile', flipTileProperties, FlipTile, arguments);
}
exports.sendToast = function () {

@@ -260,4 +297,4 @@ send('toast', toastProperties, Toast, arguments);

exports.sendRawNotification = function () {
send('raw', 'payload', RawNotification, arguments);
exports.sendRaw = function () {
send('raw', ['payload'], RawNotification, arguments);
}

@@ -271,6 +308,6 @@

var params = [];
var params = {};
if (typeof args[0] === 'object') {
var payload = Array.prototype.shift.apply(args);
copyOfInterest(payload, params, typeProperties);
copyOfInterest(payload, params, typeProperties, type === 'tile');
}

@@ -290,3 +327,3 @@ else {

if (type == 'tile' && params.length == 0)
if (type == 'tile' && Object.keys(params).length == 0)
throw new Error('At least 1 tile parameter must be set.');

@@ -315,12 +352,20 @@

'backTitle',
'backContent'
'backContent',
'id'
];
var propertiesOfInterest = toastProperties.concat(tileProperties);
propertiesOfInterest.push('payload', 'pushType');
var flipTileProperties = tileProperties.concat([
'smallbackgroundImage',
'wideBackgroundImage',
'wideBackContent',
'wideBackBackgroundImage'
]);
var propertiesOfInterest = toastProperties.concat(flipTileProperties);
propertiesOfInterest.push('payload', 'pushType', 'tileTemplate');
// These object constructors are effectively deprecated. Consider using
// sendToast, sendTile or sendRawNotification methods going forward.
// sendToast, sendTile or sendRaw methods going forward.
exports.liveTile = LiveTile;
exports.toast = Toast;
exports.rawNotification = RawNotification;
{
"name": "mpns",
"description": "A Node.js interface to the Microsoft Push Notification Service (MPNS) for Windows Phone.",
"version": "1.1.2",
"version": "1.2.3",
"author": "Jeff Wilcox <jeffwilcox+github@gmail.com>",
"contributors": [
{ "name": "Jeff Wilcox", "email": "jeffwilcox+github@gmail.com" }
{ "name": "Jeff Wilcox", "email": "jeffwilcox+github@gmail.com" },
{ "name": "Yavor Georgiev" }
],

@@ -9,0 +10,0 @@ "keywords": ["mpns", "notifications", "wp", "windows phone", "microsoft", "push", "push notifications"],

@@ -52,3 +52,3 @@ #mpns

It is recommended that you use the options syntax for this call as it is possible for the live tile update to include just one component in the update, say the tile count, and not update other properties.
It is recommended that you use the options syntax for this call as it is possible for the live tile update to include just one component in the update, say the tile count, and not update other properties. To clear the value of a property, simply pass `null` as the value.

@@ -63,3 +63,11 @@ The option names or ordering for parameters is:

* `backContent` optional content for the back tile (appears in a larger font size)
* `id` optional ID for a secodary tile
Some devices support an enhanced tile format called a "flip tile", which supports some additional parameters. This kind of tile can be sent using the `sendFlipTile` method, which supports *all of the above* parameters as well as:
* `smallbackgroundImage` URI to the background image for the tile when it is shrunk to small size
* `wideBackgroundImage` URI to the background image for the tile when it is expanded to wide size
* `wideBackContent` content for the back tile (appears in a larger font size) when the tile is expanded to wide size
* `wideBackBackgroundImage` URI to the image to be on the flip side of the tile when the tile is expanded to wide size
### Create a new notification object

@@ -100,9 +108,17 @@ You can create a new notification object (either of type live tile or toast). This is the original style for this module but it is now recommended that you use the shorter `send*` syntax on the mpns object itself. This aligns with the WNS module for Windows in its simplicity.

- `shouldDeleteChannel`: If this is set to `true`, the channel is gone according to MPNS. Delete it from your channel/subscription database and never look back.
- `error`: If an error is captured while trying to make the HTTP request, this will be set to that error callback instance.
- `innerError`: If an error is captured while trying to make the HTTP request, this will be set to that error callback instance.
### A note about Windows Phone 7.5
This module permits sending toasts and tiles specific to Mango. If you include the `param` field when sending a push to a 7.0 (first Windows Phone release) phone, unfortunately it may not be received, or will error out the subscription.
### A note about different Windows Phone versions
This module permits sending toasts and tiles supported only on specific versions of Windows Phone. If you use those features on a version where they are unsupported, unfortunately notifications may not be received, or will error out the subscription.
Take care when registering your subscription channels with your cloud service to include the application platform version of the app (7.1 for Mango apps). To rock, maybe also grab the OS version and deployed app version. That information can be helpful when supporting customers.
Here is a list of features that are only supported in given versions of Windows Phone:
* Only supported in Windows Phone 7.5+ (Mango)
* Including the `param` field when sending a push
* Including the `id` parameter when sending a tile
* Only supported in Windows Phone 7.8+
* Sending "flip" tiles
## Credits

@@ -115,2 +131,3 @@

- Jeremie Pelletier : https://github.com/ddude
- Yavor Georgiev: https://github.com/yavorg

@@ -138,2 +155,17 @@ ## License

1.2.2:
* Allows clearing a property value for tiles
1.2.1:
* Renames `sendRawNotification` to `sendRaw`
* Renames `error` parameter to `innerError`
* Fixes issue #8 that `sendRaw` wasn't working
1.2.0:
* Adds support for `sendFlipTile` method to support the new kinds of tiles added in 7.8+ devices
* Adds support for secondary tiles via the `id` parameter
1.1.1:

@@ -140,0 +172,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc