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

apn

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apn - npm Package Compare versions

Comparing version 1.3.4 to 1.3.5

examples/feedback.js

10

ChangeLog.md
## Changelog
1.3.5:
* Feedback now emits a `feedbackError` instead of `error` for socket errors.
* Fixed: Incorrect handling of errors when connection fails during TLS handshake.
* Added `Connection#setCacheLength()` for configuration of cache length during run-time.
* Notification confguration methods are now chainable.
* Updated documentation to point to new Apple Documentation URL.
* Added some more overview documentation.
* New example code.
1.3.4:

@@ -4,0 +14,0 @@

11

lib/connection.js

@@ -370,3 +370,3 @@ var Errors = require('./errors');

if (socket === this.socket && !this.deferredConnection.promise.isPending()) {
if (socket === this.socket && this.deferredConnection.promise.isPending()) {
debug("Connection error occurred before TLS Handshake");

@@ -388,2 +388,9 @@ this.deferredConnection.reject(new Error("Unable to connect"));

/**
* Use this method to modify the cache length after initialisation.
*/
Connection.prototype.setCacheLength = function(newLength) {
this.options.cacheLength = newLength;
};
/**
* @private

@@ -402,3 +409,3 @@ */

debug("Clearing notification %d from the cache", socket.cachedNotifications[0]['_uid']);
socket.cachedNotifications.shift();
socket.cachedNotifications.splice(0, socket.cachedNotifications.length - this.options.cacheLength);
}

@@ -405,0 +412,0 @@ };

2

lib/device.js

@@ -21,3 +21,3 @@ /**

}
};
}

@@ -24,0 +24,0 @@ /**

@@ -80,3 +80,3 @@ var Device = require('./device');

}
process.nextTick(function() {

@@ -203,2 +203,3 @@ if(this.listeners('feedback').length === 0) {

debug("Module initialisation error:", error);
this.emit('error', error);
this.deferredConnection.reject(error);

@@ -251,3 +252,3 @@ this.deferredConnection = null;

if(err) {
this.emit('error', err);
this.emit('feedbackError', err);
}

@@ -299,3 +300,3 @@ if (this.socket) {

this.connect().fail(function (error) {
this.emit('error', error);
this.emit('feedbackError');
}.bind(this));

@@ -302,0 +303,0 @@ };

@@ -21,2 +21,4 @@ /**

this.contentAvailable = undefined;
this.mdm = undefined;

@@ -47,2 +49,3 @@

notification.newsstandAvailable = this.newsstandAvailable;
notification.contentAvailable = this.contentAvailable;
notification.mdm = this.mdm;

@@ -54,5 +57,35 @@

/**
* Set the expiry value on the payload
* @param {Number} [expiry] Timestamp when the notification should expire.
* @since v1.3.5
*/
Notification.prototype.setExpiry = function (expiry) {
this.expiry = expiry;
return this;
};
/**
* Set the "badge" value on the alert object
* @param {Number} [badge] Badge Value
* @since v1.3.5
*/
Notification.prototype.setBadge = function (badge) {
this.badge = badge;
return this;
};
/**
* Set the "sound" value on the alert object
* @param {String} [sound] Sound file name
* @since v1.3.5
*/
Notification.prototype.setSound = function (sound) {
this.sound = sound;
return this;
};
/**
* Set the alert text for the notification
* @param {String} alertText The text of the alert message.
* @see The <a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @see The <a href="https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @since v1.2.0

@@ -73,3 +106,3 @@ */

* @param {String} [key] If a string is specified, displays an alert with two buttons, whose behavior is described in Table 3-1. However, iOS uses the string as a key to get a localized string in the current localization to use for the right button’s title instead of “View”. If the value is null, the system displays an alert with a single OK button that simply dismisses the alert when tapped.
* @see The <a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @see The <a href="https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @since v1.2.0

@@ -80,2 +113,3 @@ */

this.alert['action-loc-key'] = key;
return this;
};

@@ -86,3 +120,3 @@

* @param {String} [key] A key to an alert-message string in a Localizable.strings file for the current localization (which is set by the user’s language preference).
* @see The <a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @see The <a href="https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @since v1.2.0

@@ -97,2 +131,3 @@ */

this.alert['loc-key'] = key;
return this;
};

@@ -103,3 +138,3 @@

* @param {String[]} [args] Variable string values to appear in place of the format specifiers in loc-key.
* @see The <a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @see The <a href="https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @since v1.2.0

@@ -114,2 +149,3 @@ */

this.alert['loc-args'] = args;
return this;
};

@@ -120,3 +156,3 @@

* @param {String} [image] The filename of an image file in the application bundle; it may include the extension or omit it.
* @see The <a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @see The <a href="https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1">Payload Documentation</a>
* @since v1.2.0

@@ -131,6 +167,36 @@ */

this.alert["launch-image"] = image;
return this;
};
/**
* Set the 'content-available' flag on the payload
* @param {Boolean} [contentAvailable] Whether the content-available flag should be set or not.
* @since v1.3.5
*/
Notification.prototype.setContentAvailable = function (contentAvailable) {
this.contentAvailable = contentAvailable;
return this;
};
/**
* Set the 'content-available' flag on the payload
* @param {Boolean} [newsstandAvailable] Whether the content-available flag should be set or not.
* @since v1.3.5
*/
Notification.prototype.setNewsstandAvailable = function (newsstandAvailable) {
this.newsstandAvailable = newsstandAvailable;
return this;
};
/**
* Set the 'mdm' flag on the payload
* @param {Object} [mdm] The mdm property for the payload.
* @since v1.3.5
*/
Notification.prototype.setMDM = function (mdm) {
this.mdm = mdm;
return this;
};
/**
* If an alert object doesn't already exist create it and transfer any existing message into the .body property

@@ -262,3 +328,3 @@ * @private

}
if (this.newsstandAvailable) {
if (this.newsstandAvailable || this.contentAvailable) {
this.payload.aps['content-available'] = 1;

@@ -265,0 +331,0 @@ }

{
"name": "apn",
"description": "An interface to the Apple Push Notification service for Node.js",
"version": "1.3.4",
"version": "1.3.5",
"author": "Andrew Naylor <argon@mkbot.net>",

@@ -6,0 +6,0 @@ "contributors": [

@@ -33,9 +33,2 @@ #node-apn

### Exported Objects
- Connection
- Notification
- Device
- Feedback
- Errors
### Connecting

@@ -49,5 +42,5 @@ Create a new connection to the APN gateway server using a dictionary of options. If you name your certificate and key files appropriately (`cert.pem` and `key.pem`) then the defaults should be suitable to get you up and running, the only thing you'll need to change is the `gateway` if you're in the sandbox environment.

```
**Important:** In a development environment you must set `gateway` to `gateway.sandbox.push.apple.com`.
Help with preparing the key and certificate files for connection can be found in the [wiki][certificateWiki]
### Sending a notification

@@ -58,3 +51,3 @@ To send a notification first create a `Device` object. Pass it the device token as either a hexadecimal string, or alternatively as a `Buffer` object containing the token in binary form.

Next, create a notification object and set parameters. See the [payload documentation][pl] for more details.
Next, create a notification object, set the relevant parameters (See the [payload documentation][pl] for more details.) and use the `pushNotification` method on the connection to send it.

@@ -70,5 +63,3 @@ var note = new apn.Notification();

apnConnection.pushNotification(note, myDevice);
The above options will compile the following dictionary to send to the device:

@@ -78,8 +69,2 @@

#### A note on Unicode.
If you wish to send notifications containing emoji or other multi-byte characters you will need to ensure they are encoded correctly within the string. Notifications can be transmitted to Apple in either UTF-8 or UTF-16 and strings passed in for the Alert will be converted accordingly. UTF-8 is recommended for most cases as it can represent exactly the same characters as UTF-16 but is usually more space-efficient. When manually encoding strings as above with `\uD83D\uDCE7` the character (in this case a surrogate pair) is escaped in UTF-16 form because Javascript uses UTF-16 internally for Strings but does not handle surrogate pairs automatically.
If in doubt, leave the encoding as default. If you experience any problems raise an issue on GitHub.
### Setting up the feedback service

@@ -107,19 +92,4 @@

**Important:** In a development environment you must set `address` to `feedback.sandbox.push.apple.com`.
More information about the feedback service can be found in the [feedback service documentation][fs].
## Converting your APNs Certificate
After requesting the certificate from Apple, export your private key as a .p12 file and download the .cer file from the iOS Provisioning Portal.
Now, in the directory containing cert.cer and key.p12 execute the following commands to generate your .pem files:
$ openssl x509 -in cert.cer -inform DER -outform PEM -out cert.pem
$ openssl pkcs12 -in key.p12 -out key.pem -nodes
If you are using a development certificate you may wish to name them differently to enable fast switching between development and production. The filenames are configurable within the module options, so feel free to name them something more appropriate.
It is also possible to supply a PFX (PFX/PKCS12) package containing your certificate, key and any relevant CA certificates. The method to accomplish this is left as an exercise to the reader. It should be possible to select the relevant items in "Keychain Access" and use the export option with ".p12" format.
## Debugging

@@ -133,4 +103,8 @@

If you experience any difficulties please create an Issue on GitHub and if possible include a log of the debug output around the time the problem manifests itself. If the problem is reproducible sample code is also extremely helpful.
## Support
If you have any questions or difficulties working with the module, the [node-apn Google group][googlegroup] should be your first port of call.
Please include as much detail as possible - especially debug logs, if the problem is reproducible sample code is also extremely helpful. GitHub Issues should only be created for verified problems and enhancements, this will allow them to be tracked more easily.
## Resources

@@ -166,6 +140,8 @@

[errors]:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4 "The Binary Interface and Notification Formats"
[pl]: https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1 "Local and Push Notification Programming Guide: Apple Push Notification Service"
[fs]: https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3 "Communicating With APS"
[certificateWiki]:https://github.com/argon/node-apn/wiki/Preparing-Certificates "Preparing Certificates"
[errors]:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4 "The Binary Interface and Notification Formats"
[pl]: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1 "Local and Push Notification Programming Guide: Apple Push Notification Service"
[fs]: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3 "The Feedback Service"
[tn2265]: http://developer.apple.com/library/ios/#technotes/tn2265/_index.html "Troubleshooting Push Notifications"
[googlegroup]:https://groups.google.com/group/node-apn "node-apn Google Group"
[pacapn]:https://github.com/argon/node-apn/wiki/Projects,-Applications,-and-Companies-Using-Node-apn "List of Projects, Applications and Companies Using Node-apn"

@@ -172,0 +148,0 @@ [andrewnaylor]: http://andrewnaylor.co.uk

Sorry, the diff of this file is not supported yet

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