pusher 5.1.2 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/lib/pusher.js +0 -12
- package/lib/token.js +25 -25
- package/lib/webhook.js +5 -1
- package/package.json +1 -1
- package/lib/notification_client.js +0 -25
- package/lib/notification_config.js +0 -18
- package/tests/integration/pusher/notification_client.js +0 -49
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.2.0
|
|
4
|
+
|
|
5
|
+
- [CHANGED] Remove old notification references. It's no longer being used
|
|
6
|
+
|
|
7
|
+
## 5.1.3
|
|
8
|
+
|
|
9
|
+
[FIXED] Parsing of the extraTokens in webhook's isValid method
|
|
10
|
+
|
|
3
11
|
## 5.1.2
|
|
4
12
|
|
|
5
|
-
- [CHANGED] Add types/node-fetch to dependencies.
|
|
13
|
+
- [CHANGED] Add types/node-fetch to dependencies.
|
|
14
|
+
|
|
6
15
|
## 5.1.1-beta (2022-06-01)
|
|
7
16
|
|
|
8
17
|
[FIXED] Updated typescript types with new user features.
|
|
@@ -90,7 +99,7 @@ const pusher = new Pusher.forURL(process.env.PUSHER_URL, {
|
|
|
90
99
|
|
|
91
100
|
## 2.2.1 (2019-07-03)
|
|
92
101
|
|
|
93
|
-
no-op release to fix the description on https://www.npmjs.com/package/pusher
|
|
102
|
+
no-op release to fix the description on <https://www.npmjs.com/package/pusher>
|
|
94
103
|
|
|
95
104
|
## 2.2.0 (2018-11-26)
|
|
96
105
|
|
package/lib/pusher.js
CHANGED
|
@@ -9,7 +9,6 @@ const requests = require("./requests")
|
|
|
9
9
|
const PusherConfig = require("./pusher_config")
|
|
10
10
|
const Token = require("./token")
|
|
11
11
|
const WebHook = require("./webhook")
|
|
12
|
-
const NotificationClient = require("./notification_client")
|
|
13
12
|
|
|
14
13
|
const validateChannel = function (channel) {
|
|
15
14
|
if (
|
|
@@ -52,10 +51,8 @@ const validateUserData = function (userData) {
|
|
|
52
51
|
* @constructor
|
|
53
52
|
* @param {Object} options
|
|
54
53
|
* @param {String} [options.host="api.pusherapp.com"] API hostname
|
|
55
|
-
* @param {String} [options.notification_host="api.pusherapp.com"] Notification API hostname
|
|
56
54
|
* @param {Boolean} [options.useTLS=false] whether to use TLS
|
|
57
55
|
* @param {Boolean} [options.encrypted=false] deprecated; renamed to `useTLS`
|
|
58
|
-
* @param {Boolean} [options.notification_encrypted=false] whether to use TLS for notifications
|
|
59
56
|
* @param {Integer} [options.port] port, default depends on the scheme
|
|
60
57
|
* @param {Integer} options.appId application ID
|
|
61
58
|
* @param {String} options.key application key
|
|
@@ -65,11 +62,6 @@ const validateUserData = function (userData) {
|
|
|
65
62
|
*/
|
|
66
63
|
function Pusher(options) {
|
|
67
64
|
this.config = new PusherConfig(options)
|
|
68
|
-
const notificationOptions = Object.assign({}, options, {
|
|
69
|
-
host: options.notificationHost,
|
|
70
|
-
encrypted: options.notificationEncrypted,
|
|
71
|
-
})
|
|
72
|
-
this.notificationClient = new NotificationClient(notificationOptions)
|
|
73
65
|
}
|
|
74
66
|
|
|
75
67
|
/** Create a Pusher instance using a URL.
|
|
@@ -237,10 +229,6 @@ Pusher.prototype.triggerBatch = function (batch) {
|
|
|
237
229
|
return events.triggerBatch(this, batch)
|
|
238
230
|
}
|
|
239
231
|
|
|
240
|
-
Pusher.prototype.notify = function () {
|
|
241
|
-
this.notificationClient.notify.apply(this.notificationClient, arguments)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
232
|
/** Makes a POST request to Pusher, handles the authentication.
|
|
245
233
|
*
|
|
246
234
|
* Returns a promise resolving to a response, or rejecting to a RequestError.
|
package/lib/token.js
CHANGED
|
@@ -7,31 +7,31 @@ const util = require("./util")
|
|
|
7
7
|
* @param {String} key app key
|
|
8
8
|
* @param {String} secret app secret
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/** Signs the string using the secret.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
10
|
+
class Token {
|
|
11
|
+
constructor(key, secret) {
|
|
12
|
+
this.key = key
|
|
13
|
+
this.secret = secret
|
|
14
|
+
}
|
|
15
|
+
/** Signs the string using the secret.
|
|
16
|
+
*
|
|
17
|
+
* @param {String} string
|
|
18
|
+
* @returns {String}
|
|
19
|
+
*/
|
|
20
|
+
sign(string) {
|
|
21
|
+
return crypto
|
|
22
|
+
.createHmac("sha256", this.secret)
|
|
23
|
+
.update(Buffer.from(string))
|
|
24
|
+
.digest("hex")
|
|
25
|
+
}
|
|
26
|
+
/** Checks if the string has correct signature.
|
|
27
|
+
*
|
|
28
|
+
* @param {String} string
|
|
29
|
+
* @param {String} signature
|
|
30
|
+
* @returns {Boolean}
|
|
31
|
+
*/
|
|
32
|
+
verify(string, signature) {
|
|
33
|
+
return util.secureCompare(this.sign(string), signature)
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
module.exports = Token
|
package/lib/webhook.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const errors = require("./errors")
|
|
2
|
+
const Token = require("./token")
|
|
2
3
|
|
|
3
4
|
/** Provides validation and access methods for a WebHook.
|
|
4
5
|
*
|
|
@@ -46,7 +47,10 @@ WebHook.prototype.isValid = function (extraTokens) {
|
|
|
46
47
|
|
|
47
48
|
const tokens = [this.token].concat(extraTokens)
|
|
48
49
|
for (const i in tokens) {
|
|
49
|
-
|
|
50
|
+
let token = tokens[i]
|
|
51
|
+
if (token instanceof Token === false) {
|
|
52
|
+
token = new Token(token.key, token.secret)
|
|
53
|
+
}
|
|
50
54
|
if (this.key == token.key && token.verify(this.body, this.signature)) {
|
|
51
55
|
return true
|
|
52
56
|
}
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const requests = require("./requests")
|
|
2
|
-
const NotificationConfig = require("./notification_config")
|
|
3
|
-
|
|
4
|
-
function NotificationClient(options) {
|
|
5
|
-
this.config = new NotificationConfig(options)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
NotificationClient.prototype.notify = function (interests, notification) {
|
|
9
|
-
if (!Array.isArray(interests)) {
|
|
10
|
-
throw new Error("Interests must be an array")
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (interests.length == 0) {
|
|
14
|
-
throw new Error("Interests array must not be empty")
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const body = Object.assign({ interests: interests }, notification)
|
|
18
|
-
return requests.send(this.config, {
|
|
19
|
-
method: "POST",
|
|
20
|
-
body: body,
|
|
21
|
-
path: "/notifications",
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = NotificationClient
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const Config = require("./config")
|
|
2
|
-
|
|
3
|
-
const DEFAULT_HOST = "nativepush-cluster1.pusher.com"
|
|
4
|
-
const API_PREFIX = "server_api"
|
|
5
|
-
const API_VERSION = "v1"
|
|
6
|
-
|
|
7
|
-
function NotificationConfig(options) {
|
|
8
|
-
Config.call(this, options)
|
|
9
|
-
this.host = options.host || DEFAULT_HOST
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
Object.assign(NotificationConfig.prototype, Config.prototype)
|
|
13
|
-
|
|
14
|
-
NotificationConfig.prototype.prefixPath = function (subPath) {
|
|
15
|
-
return "/" + API_PREFIX + "/" + API_VERSION + "/apps/" + this.appId + subPath
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = NotificationConfig
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const expect = require("expect.js")
|
|
2
|
-
const NotificationClient = require("../../../lib/notification_client")
|
|
3
|
-
const nock = require("nock")
|
|
4
|
-
|
|
5
|
-
describe("NativeNotificationClient", function () {
|
|
6
|
-
let client
|
|
7
|
-
|
|
8
|
-
beforeEach(function () {
|
|
9
|
-
client = new NotificationClient({
|
|
10
|
-
appId: 1234,
|
|
11
|
-
key: "f00d",
|
|
12
|
-
secret: "tofu",
|
|
13
|
-
})
|
|
14
|
-
nock.cleanAll()
|
|
15
|
-
nock.disableNetConnect()
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
afterEach(function () {
|
|
19
|
-
nock.cleanAll()
|
|
20
|
-
nock.enableNetConnect()
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
xit("should send in the success case", function (done) {
|
|
24
|
-
const mock = nock("nativepush-cluster1.pusher.com:80")
|
|
25
|
-
client.notify(
|
|
26
|
-
["yolo"],
|
|
27
|
-
{
|
|
28
|
-
apns: {
|
|
29
|
-
aps: {
|
|
30
|
-
alert: {
|
|
31
|
-
title: "yolo",
|
|
32
|
-
body: "woot",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
gcm: {
|
|
37
|
-
notification: {
|
|
38
|
-
title: "huzzah",
|
|
39
|
-
icon: "woot",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
function () {
|
|
44
|
-
expect(mock.isDone()).to.be(true)
|
|
45
|
-
done()
|
|
46
|
-
}
|
|
47
|
-
)
|
|
48
|
-
})
|
|
49
|
-
})
|