Comparing version 1.1.7 to 1.2.0
15
index.js
@@ -1,1 +0,14 @@ | ||
module.exports = require('./lib/apn'); | ||
exports.Connection = require('./lib/connection'); | ||
exports.connection = exports.Connection; | ||
exports.Device = require("./lib/device"); | ||
exports.device = exports.Device; | ||
exports.Errors = require('./lib/errors'); | ||
exports.error = exports.Errors; | ||
exports.Feedback = require("./lib/feedback"); | ||
exports.feedback = exports.Feedback; | ||
exports.Notification = require("./lib/notification"); | ||
exports.notification = exports.Notification; |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.1.7", | ||
"version": "1.2.0", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -11,7 +11,15 @@ "contributors": [ | ||
"main": "index.js", | ||
"bugs": { | ||
"email": "argon@mkbot.net", | ||
"url": "https://github.com/argon/node-apn/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/argon/node-apn.git" | ||
"url": "https://github.com/argon/node-apn.git" | ||
}, | ||
"engines": { "node": ">= 0.4.0" } | ||
"dependencies": { | ||
"q": ">=0.8.5" | ||
}, | ||
"engines": { "node": ">= 0.6.6" }, | ||
"license": "MIT" | ||
} |
@@ -18,3 +18,3 @@ #node-apn | ||
As a submodule of your project | ||
As a submodule of your project (you will also need to install [q][q]) | ||
@@ -34,3 +34,3 @@ $ git submodule add http://github.com/argon/node-apn.git apn | ||
- Feedback | ||
- errors | ||
- Errors | ||
@@ -41,25 +41,29 @@ ### Connecting | ||
var options = { | ||
cert: 'cert.pem', /* Certificate file */ | ||
certData: null, /* Optional: if supplied uses this instead of Certificate File */ | ||
key: 'key.pem', /* Key file */ | ||
keyData: null, /* Optional: if supplied uses this instead of Key file */ | ||
passphrase: null, /* Optional: A passphrase for the Key file */ | ||
cert: 'cert.pem', /* Certificate file path */ | ||
certData: null, /* String or Buffer containing certificate data, if supplied uses this instead of cert file path */ | ||
key: 'key.pem', /* Key file path */ | ||
keyData: null, /* String or Buffer containing key data, as certData */ | ||
passphrase: null, /* A passphrase for the Key file */ | ||
ca: null /* String or Buffer of CA data to use for the TLS connection */ | ||
gateway: 'gateway.push.apple.com',/* gateway address */ | ||
port: 2195, /* gateway port */ | ||
enhanced: true, /* enable enhanced format */ | ||
errorCallback: undefined, /* Callback when error occurs */ | ||
cacheLength: 5 /* Number of notifications to cache for error purposes */ | ||
errorCallback: undefined, /* Callback when error occurs function(err,notification) */ | ||
cacheLength: 100 /* Number of notifications to cache for error purposes */ | ||
}; | ||
var apnsConnection = new apns.Connection(options); | ||
**Important:** In a development environment you must set `gateway` to `gateway.sandbox.push.apple.com`. | ||
### Sending a notification | ||
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 binary token, setting the second argument to `false`. | ||
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. | ||
var myDevice = new apns.Device(token /*, ascii=true*/); | ||
var myDevice = new apns.Device(token); | ||
Next create a notification object and set parameters. See the [payload documentation][pl] for more details | ||
Next, create a notification object and set parameters. See the [payload documentation][pl] for more details. | ||
var note = new apns.Notification(); | ||
note.expiry = 60; | ||
note.badge = 3; | ||
@@ -73,2 +77,4 @@ note.sound = "ping.aiff"; | ||
As of version 1.2.0 it is also possible to use a set of methods provided by Notification object (`setAlertText`, `setActionLocKey`, `setLocKey`, `setLocArgs`, `setLaunchImage`) to aid the creation of the alert parameters. For applications which provide Newsstand capability there is a new boolean parameter `note.newsstandAvailable` to specify `content-available` in the payload. | ||
The above options will compile the following dictionary to send to the device: | ||
@@ -78,12 +84,18 @@ | ||
\* N.B.: If you wish to send notifications containing emoji or other multi-byte characters you will need to set `note.encoding = 'ucs2'`. This tells node to send the message with 16bit characters, however it also means your message payload will be limited to 127 characters. | ||
**\*N.B.:** If you wish to send notifications containing emoji or other multi-byte characters you will need to set `note.encoding = 'ucs2'`. This tells node to send the message with 16bit characters, however it also means your message payload will be limited to 127 characters. | ||
### Handling Errors | ||
If the enhanced binary interface is enabled and an error occurs when sending a message then subsequent messages will be automatically resent* and the connection will be re-established. If an `errorCallback` is also specified in the connection options then it will be invoked with 2 arguments. | ||
If the enhanced binary interface is enabled and an error occurs - as defined in Apple's documentation - when sending a message, then subsequent messages will be automatically resent* and the connection will be re-established. If an `errorCallback` is also specified in the connection options then it will be invoked with 2 arguments `(err, notification)` | ||
1. The error number as returned from Apple. This can be compared to the predefined values in the `Errors` object. | ||
1. The notification object as it existed when the notification was converted and sent to the server. | ||
If a notification fails to be sent because a connection error occurs then the `errorCallback` will be called for each notification waiting for the connection which failed. In this case the first parameter will be an Error object instead of an error number. | ||
\* N.B.: The `cacheLength` option specifies the number of sent notifications which will be cached for error handling purposes. At present if more than the specified number of notifications have been sent between the incorrect notification being sent and the error being received then no resending will occur. This is only envisaged within very high volume environments and a higher cache number might be desired. | ||
`errorCallback` will be called in 3 situations with the parameters shown. | ||
1. The notification has been rejected by Apple (or determined to have an invalid device token or payload before sending) for one of the reasons shown in Table 5-1 [here][errors] `errorCallback(errorCode, notification)` | ||
1. A notification has been rejected by Apple but it has been removed from the cache so it is not possible to identify which. In this case subsequent notifications may be lost. **If this happens you should consider increasing your `cacheLength` value to prevent data loss** `errorCallback(255, null)` | ||
1. A connection error has occurred before the notification can be sent. `errorCallback(Error object, notification)` | ||
**\*N.B.:** The `cacheLength` option for the connection specifies the number of sent notifications which will be cached, on a FIFO basis for error handling purposes. If `cacheLength` is not set to a large enough value, then in high volume environments, a notification - possibly including some subsequent notifications - may be removed from the cache before Apple returns an error associated with it. In this case the `errorCallback` will still be called, but with a `null` notification and error code 255. If this happens you should consider increasing `cacheLength` to prevent losing notifications. All the notifications still residing in the cache will be resent automatically. | ||
### Setting up the feedback service | ||
@@ -93,10 +105,11 @@ | ||
Using the `Feedback` object it is possible to periodically query the server for the list. You should provide a function which will accept two arguments, the `time` returned by the server (epoch time) and a `Device` object containing the device token. You can also set the query interval in seconds. Again the default options are shown below. | ||
Using the `Feedback` object it is possible to periodically query the server for the list. You should provide a function `feedback` which will accept two arguments, the `time` returned by the server (epoch time) and a `Buffer` object containing the device token. You can also set the query interval in seconds. The default options are shown below. | ||
var options = { | ||
cert: 'cert.pem', /* Certificate file */ | ||
certData: null, /* Certificate file contents */ | ||
certData: null, /* Certificate file contents (String|Buffer) */ | ||
key: 'key.pem', /* Key file */ | ||
keyData: null, /* Key file contents */ | ||
passphrase: null, /* Optional: A passphrase for the Key file */ | ||
keyData: null, /* Key file contents (String|Buffer) */ | ||
passphrase: null, /* A passphrase for the Key file */ | ||
ca: null, /* Certificate authority data to pass to the TLS connection */ | ||
address: 'feedback.push.apple.com', /* feedback address */ | ||
@@ -110,7 +123,13 @@ port: 2196, /* feedback port */ | ||
This will automatically start a timer to check with Apple every `interval` seconds. You can cancel the interval by calling `feedback.cancel()`. If you do not wish to have the service automatically queried then set `interval` to 0 and use `feedback.start()`. | ||
**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. | ||
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: | ||
Now, in the directory containing cert.cer and key.p12 execute the following commands to generate your .pem files: | ||
@@ -124,8 +143,6 @@ $ openssl x509 -in cert.cer -inform DER -outform PEM -out cert.pem | ||
Written and maintained by [Andrew Naylor][mphys]. | ||
Written and maintained by [Andrew Naylor][andrewnaylor]. | ||
Contributors: [Ian Babrou][bobrik], [dgthistle][dgthistle], [Keith Larsen][keithnlarsen], [Mike P][mypark] | ||
Special thanks to [Ben Noordhuis][bnoordhuis] for `invoke_after` code. | ||
## License | ||
@@ -149,4 +166,6 @@ | ||
[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" | ||
[mphys]: http://mphys.com | ||
[fs]:https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3 "Communicating With APS" | ||
[andrewnaylor]: http://andrewnaylor.co.uk | ||
[bnoordhuis]: http://bnoordhuis.nl | ||
@@ -158,6 +177,21 @@ [npm]: https://github.com/isaacs/npm | ||
[mypark]: https://github.com/mypark | ||
[q]: https://github.com/kriskowal/q | ||
## Changelog | ||
1.2.0: | ||
* Complete rewrite of the connection handling. | ||
* [q][q] is now required. | ||
* Change in the error handling logic. When a notification errors and it cannot be found in the cache, then all notifications in the cache will be resent instead of being discarded. | ||
* `errorCallback` will also be invoked for connection errors. | ||
* New methods on `Notification` to aid settings the alert properties. | ||
* `content-available` can now be set for Newsstand applications by setting the `newsstandAvailable` property on the Notification object. | ||
* `Notification` objects now have a `.clone(device)` method to assist you in sending the same notification to multiple devices. | ||
* Included some js-doc tags in the source. | ||
* Device object now provides a `.toString()` method to return the hex representation of the device token. | ||
* Fixes #23, #28, #32, #34, #35, #40, #42 | ||
1.1.7: | ||
* Fixes a problem with sockets being closed on transmission error causing EPIPE errors in node. | ||
@@ -167,2 +201,3 @@ * Issues #29, #30 | ||
1.1.6: | ||
* Fixes a regression from v1.1.5 causing connections to stall and messages to not be sent. | ||
@@ -169,0 +204,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
38729
11
730
1
246
1
2
3
+ Addedq@>=0.8.5
+ Addedasap@2.0.6(transitive)
+ Addedpop-iterate@1.0.1(transitive)
+ Addedq@2.0.3(transitive)
+ Addedweak-map@1.0.8(transitive)