pusher 4.0.0 → 5.0.1
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/.github/stale.yml +2 -2
- package/.github/workflows/test.yml +36 -0
- package/CHANGELOG.md +20 -0
- package/README.md +78 -8
- package/examples/typescript/main.ts +1 -2
- package/index.d.ts +12 -4
- package/lib/config.js +2 -5
- package/lib/events.js +3 -7
- package/lib/pusher.js +13 -7
- package/lib/requests.js +4 -2
- package/lib/version.js +1 -1
- package/package.json +3 -1
- package/tests/integration/pusher/authenticate.js +3 -3
- package/tests/integration/pusher/constructor.js +5 -5
- package/tests/integration/pusher/trigger.js +36 -11
- package/.travis.yml +0 -20
package/.github/stale.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Configuration for probot-stale - https://github.com/probot/stale
|
|
2
2
|
|
|
3
3
|
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
|
4
|
-
daysUntilStale:
|
|
4
|
+
daysUntilStale: 90
|
|
5
5
|
|
|
6
6
|
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
|
|
7
7
|
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
|
@@ -23,4 +23,4 @@ markComment: >
|
|
|
23
23
|
This issue has been automatically marked as stale because it has not had
|
|
24
24
|
recent activity. It will be closed if no further activity occurs. If you'd
|
|
25
25
|
like this issue to stay open please leave a comment indicating how this issue
|
|
26
|
-
is affecting you.
|
|
26
|
+
is affecting you. Thank you.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches: [master, main]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-20.04
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
node: [10.x, 10.x, 12.x, 14.x]
|
|
15
|
+
|
|
16
|
+
name: Node.js ${{ matrix.node }} Test
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout
|
|
20
|
+
uses: actions/checkout@v2
|
|
21
|
+
|
|
22
|
+
- name: Setup Node.js
|
|
23
|
+
uses: actions/setup-node@v2
|
|
24
|
+
with:
|
|
25
|
+
node-version: ${{ matrix.node }}
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: npm ci
|
|
29
|
+
|
|
30
|
+
- name: Run linter
|
|
31
|
+
run: npm run lint
|
|
32
|
+
|
|
33
|
+
- name: Run test suite
|
|
34
|
+
run: npm test
|
|
35
|
+
env:
|
|
36
|
+
PUSHER_URL: ${{ secrets.INTEGRATION_TESTS_PUSHER_URL }}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## 5.0.1 (2022-01-24)
|
|
2
|
+
|
|
3
|
+
[FIXED] Incorrect `require` on `version.js` was causing a compilation error in Webpack
|
|
4
|
+
[FIXED] Inconsistent encoding for shared secret between other SDKs
|
|
5
|
+
|
|
6
|
+
## 5.0.0 (2021-02-18)
|
|
7
|
+
|
|
8
|
+
[BREAKING CHANGE] `trigger` now accepts a `params` _object_ instead of a `socket_id` as the third parameter.
|
|
9
|
+
|
|
10
|
+
[ADDED] Support for requesting channel attributes as part of a `trigger` and `triggerBatch` request via an `info` parameter.
|
|
11
|
+
|
|
12
|
+
## 4.0.2 (2020-11-30)
|
|
13
|
+
|
|
14
|
+
[FIXED] Workaround for a [Webpack bug](https://github.com/webpack/webpack/issues/4742) (thanks @JJ-Kidd)
|
|
15
|
+
|
|
16
|
+
## 4.0.1 (2020-11-09)
|
|
17
|
+
|
|
18
|
+
[FIXED] The type definitions had drifted out of sync with the implementation.
|
|
19
|
+
|
|
1
20
|
## 4.0.0 (2020-10-20)
|
|
2
21
|
|
|
3
22
|
[BREAKING CHANGE] Methods that previously took callbacks now return promises.
|
|
@@ -38,6 +57,7 @@ const pusher = new Pusher.forURL(process.env.PUSHER_URL, {
|
|
|
38
57
|
[UPGRADED] development dependencies
|
|
39
58
|
|
|
40
59
|
[ADDED] encryptionMasterKeyBase64 constructor parameter to make it easier to use the full range of 32 byte binary values in encryption key
|
|
60
|
+
|
|
41
61
|
[DEPRECATED] encryptionMasterKey constructor parameter - use encryptionMasterKeyBase64
|
|
42
62
|
|
|
43
63
|
## 3.0.0 (2019-09-26)
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://github.com/pusher/pusher-http-node/actions?query=workflow%3ATests+branch%3Amaster)
|
|
2
2
|
[](https://badge.fury.io/js/pusher)
|
|
3
3
|
|
|
4
4
|
# Pusher Channels Node.js REST library
|
|
@@ -7,15 +7,15 @@ In order to use this library, you need to have an account on <https://pusher.com
|
|
|
7
7
|
|
|
8
8
|
## Supported platforms
|
|
9
9
|
|
|
10
|
-
This SDK supports **Node.js** version
|
|
10
|
+
This SDK supports **Node.js** version 10+.
|
|
11
11
|
|
|
12
|
-
We test the library against a selection of Node.js versions which we update over time. Please refer to [
|
|
12
|
+
We test the library against a selection of Node.js versions which we update over time. Please refer to [test.yml](https://github.com/pusher/pusher-http-node/blob/master/.github/workflows/test.yml) for the set of versions that are currently tested with CI.
|
|
13
13
|
|
|
14
14
|
If you find any compatibility issues, please [raise an issue](https://github.com/pusher/pusher-http-node/issues/new) in the repository or contact support at [support@pusher.com](support@pusher.com). We will happily investigate reported problems ❤️.
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
18
|
-
You need to be running at least Node.js
|
|
18
|
+
You need to be running at least Node.js 10 to use this library.
|
|
19
19
|
|
|
20
20
|
```
|
|
21
21
|
$ npm install pusher
|
|
@@ -160,14 +160,84 @@ You can trigger a batch of up to 10 events.
|
|
|
160
160
|
|
|
161
161
|
### Excluding event recipients
|
|
162
162
|
|
|
163
|
-
In order to avoid the client that triggered the event from also receiving it,
|
|
163
|
+
In order to avoid the client that triggered the event from also receiving it, a `socket_id` parameter can be added to the `params` object. For more information see: <http://pusher.com/docs/publisher_api_guide/publisher_excluding_recipients>.
|
|
164
164
|
|
|
165
165
|
```javascript
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
pusher.trigger(channel, event, data, { socket_id: "1302.1081607" })
|
|
167
|
+
|
|
168
|
+
pusher.triggerBatch([
|
|
169
|
+
{ channel: channel, name: name, data: data, socket_id: "1302.1081607" },
|
|
170
|
+
])
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Fetch subscriber and user counts at the time of publish [[EXPERIMENTAL](https://pusher.com/docs/lab#experimental-program)]
|
|
174
|
+
|
|
175
|
+
For the channels that were published to, you can request for the number of subscribers or user to be returned in the response body.
|
|
176
|
+
|
|
177
|
+
#### Regular triggering
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
pusher
|
|
181
|
+
.trigger("presence-my-channel", "event", "test", { info: "user_count,subscription_count" })
|
|
182
|
+
.then(response => {
|
|
183
|
+
if (response.status !== 200) {
|
|
184
|
+
throw Error("unexpected status")
|
|
185
|
+
}
|
|
186
|
+
// Parse the response body as JSON
|
|
187
|
+
return response.json()
|
|
188
|
+
)
|
|
189
|
+
.then(body => {
|
|
190
|
+
const channelsInfo = body.channels
|
|
191
|
+
// Do something with channelsInfo
|
|
192
|
+
})
|
|
193
|
+
.catch(error => {
|
|
194
|
+
// Handle error
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### Batch triggering
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
const batch = [
|
|
202
|
+
{
|
|
203
|
+
channel: "my-channel",
|
|
204
|
+
name: "event",
|
|
205
|
+
data: "test1",
|
|
206
|
+
info: "subscription_count",
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
channel: "presence-my-channel",
|
|
210
|
+
name: "event",
|
|
211
|
+
data: "test2",
|
|
212
|
+
info: "user_count,subscription_count",
|
|
213
|
+
},
|
|
214
|
+
]
|
|
215
|
+
pusher
|
|
216
|
+
.triggerBatch(batch)
|
|
217
|
+
.then((response) => {
|
|
218
|
+
if (response.status !== 200) {
|
|
219
|
+
throw Error("unexpected status")
|
|
220
|
+
}
|
|
221
|
+
// Parse the response body as JSON
|
|
222
|
+
return response.json()
|
|
223
|
+
})
|
|
224
|
+
.then((body) => {
|
|
225
|
+
body.batch.forEach((attributes, i) => {
|
|
226
|
+
process.stdout.write(
|
|
227
|
+
`channel: ${batch[i].channel}, name: ${batch[i].name}, subscription_count: ${attributes.subscription_count}`
|
|
228
|
+
)
|
|
229
|
+
if ("user_count" in attributes) {
|
|
230
|
+
process.stdout.write(`, user_count: ${attributes.user_count}`)
|
|
231
|
+
}
|
|
232
|
+
process.stdout.write("\n")
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
.catch((error) => {
|
|
236
|
+
console.error(error)
|
|
237
|
+
})
|
|
168
238
|
```
|
|
169
239
|
|
|
170
|
-
### End-to-end encryption
|
|
240
|
+
### End-to-end encryption
|
|
171
241
|
|
|
172
242
|
This library supports end-to-end encryption of your private channels. This means that only you and your connected clients will be able to read your messages. Pusher cannot decrypt them. You can enable this feature by following these steps:
|
|
173
243
|
|
|
@@ -4,8 +4,7 @@ import * as Pusher from "pusher"
|
|
|
4
4
|
|
|
5
5
|
const pusher = Pusher.forURL(process.env.PUSHER_URL, {
|
|
6
6
|
encryptionMasterKeyBase64: Buffer.from(
|
|
7
|
-
"01234567890123456789012345678901"
|
|
8
|
-
"binary"
|
|
7
|
+
"01234567890123456789012345678901"
|
|
9
8
|
).toString("base64"),
|
|
10
9
|
agent: new Agent({ keepAlive: true }),
|
|
11
10
|
})
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Agent } from "http"
|
|
1
2
|
import { Response } from "node-fetch"
|
|
2
3
|
|
|
3
4
|
export = Pusher
|
|
@@ -9,7 +10,7 @@ declare class Pusher {
|
|
|
9
10
|
channel: string | Array<string>,
|
|
10
11
|
event: string,
|
|
11
12
|
data: any,
|
|
12
|
-
|
|
13
|
+
params?: Pusher.TriggerParams
|
|
13
14
|
): Promise<Response>
|
|
14
15
|
|
|
15
16
|
trigger(
|
|
@@ -47,7 +48,7 @@ declare namespace Pusher {
|
|
|
47
48
|
useTLS?: boolean
|
|
48
49
|
encrypted?: boolean
|
|
49
50
|
timeout?: number
|
|
50
|
-
agent?:
|
|
51
|
+
agent?: Agent
|
|
51
52
|
encryptionMasterKeyBase64?: string
|
|
52
53
|
}
|
|
53
54
|
interface ClusterOptions extends BaseOptions {
|
|
@@ -60,10 +61,17 @@ declare namespace Pusher {
|
|
|
60
61
|
|
|
61
62
|
export type Options = ClusterOptions | HostOptions
|
|
62
63
|
|
|
64
|
+
export interface TriggerParams {
|
|
65
|
+
socket_id?: string
|
|
66
|
+
info?: string
|
|
67
|
+
}
|
|
68
|
+
|
|
63
69
|
export interface BatchEvent {
|
|
64
70
|
channel: string
|
|
65
71
|
name: string
|
|
66
72
|
data: any
|
|
73
|
+
socket_id?: string
|
|
74
|
+
info?: string
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
type ReservedParams =
|
|
@@ -135,7 +143,7 @@ declare namespace Pusher {
|
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
export class WebHook {
|
|
138
|
-
constructor(token: Token, request:
|
|
146
|
+
constructor(token: Token, request: WebHookRequest)
|
|
139
147
|
|
|
140
148
|
isValid(extraTokens?: Token | Array<Token>): boolean
|
|
141
149
|
isContentTypeValid(): boolean
|
|
@@ -145,5 +153,5 @@ declare namespace Pusher {
|
|
|
145
153
|
getTime(): Date
|
|
146
154
|
}
|
|
147
155
|
|
|
148
|
-
export
|
|
156
|
+
export { Response }
|
|
149
157
|
}
|
package/lib/config.js
CHANGED
|
@@ -49,7 +49,7 @@ function Config(options) {
|
|
|
49
49
|
)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
this.encryptionMasterKey = options.encryptionMasterKey
|
|
52
|
+
this.encryptionMasterKey = Buffer.from(options.encryptionMasterKey)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// Handle base64 encoded 32 byte key to encourage use of the full range of byte values
|
|
@@ -61,10 +61,7 @@ function Config(options) {
|
|
|
61
61
|
throw new Error("encryptionMasterKeyBase64 must be valid base64")
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const decodedKey = Buffer.from(
|
|
65
|
-
options.encryptionMasterKeyBase64,
|
|
66
|
-
"base64"
|
|
67
|
-
).toString("binary")
|
|
64
|
+
const decodedKey = Buffer.from(options.encryptionMasterKeyBase64, "base64")
|
|
68
65
|
if (decodedKey.length !== 32) {
|
|
69
66
|
throw new Error(
|
|
70
67
|
"encryptionMasterKeyBase64 must decode to 32 bytes, but the string " +
|
package/lib/events.js
CHANGED
|
@@ -23,16 +23,14 @@ function encrypt(pusher, channel, data) {
|
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
exports.trigger = function (pusher, channels, eventName, data,
|
|
26
|
+
exports.trigger = function (pusher, channels, eventName, data, params) {
|
|
27
27
|
if (channels.length === 1 && util.isEncryptedChannel(channels[0])) {
|
|
28
28
|
const channel = channels[0]
|
|
29
29
|
const event = {
|
|
30
30
|
name: eventName,
|
|
31
31
|
data: encrypt(pusher, channel, data),
|
|
32
32
|
channels: [channel],
|
|
33
|
-
|
|
34
|
-
if (socketId) {
|
|
35
|
-
event.socket_id = socketId
|
|
33
|
+
...params,
|
|
36
34
|
}
|
|
37
35
|
return pusher.post({ path: "/events", body: event })
|
|
38
36
|
} else {
|
|
@@ -49,9 +47,7 @@ exports.trigger = function (pusher, channels, eventName, data, socketId) {
|
|
|
49
47
|
name: eventName,
|
|
50
48
|
data: ensureJSON(data),
|
|
51
49
|
channels: channels,
|
|
52
|
-
|
|
53
|
-
if (socketId) {
|
|
54
|
-
event.socket_id = socketId
|
|
50
|
+
...params,
|
|
55
51
|
}
|
|
56
52
|
return pusher.post({ path: "/events", body: event })
|
|
57
53
|
}
|
package/lib/pusher.js
CHANGED
|
@@ -130,12 +130,14 @@ Pusher.prototype.authenticate = function (socketId, channel, data) {
|
|
|
130
130
|
* @param {String|String[]} channel list of at most 100 channels
|
|
131
131
|
* @param {String} event event name
|
|
132
132
|
* @param data event data, objects are JSON-encoded
|
|
133
|
-
* @param {
|
|
133
|
+
* @param {Object} [params] additional optional request body parameters
|
|
134
|
+
* @param {String} [params.socket_id] id of a socket that should not receive the event
|
|
135
|
+
* @param {String} [params.info] a comma separate list of attributes to be returned in the response. Experimental, see https://pusher.com/docs/lab#experimental-program
|
|
134
136
|
* @see RequestError
|
|
135
137
|
*/
|
|
136
|
-
Pusher.prototype.trigger = function (channels, event, data,
|
|
137
|
-
if (
|
|
138
|
-
validateSocketId(
|
|
138
|
+
Pusher.prototype.trigger = function (channels, event, data, params) {
|
|
139
|
+
if (params && params.socket_id) {
|
|
140
|
+
validateSocketId(params.socket_id)
|
|
139
141
|
}
|
|
140
142
|
if (!(channels instanceof Array)) {
|
|
141
143
|
// add single channel to array for multi trigger compatibility
|
|
@@ -150,7 +152,7 @@ Pusher.prototype.trigger = function (channels, event, data, socketId) {
|
|
|
150
152
|
for (let i = 0; i < channels.length; i++) {
|
|
151
153
|
validateChannel(channels[i])
|
|
152
154
|
}
|
|
153
|
-
return events.trigger(this, channels, event, data,
|
|
155
|
+
return events.trigger(this, channels, event, data, params)
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
/* Triggers a batch of events
|
|
@@ -159,7 +161,9 @@ Pusher.prototype.trigger = function (channels, event, data, socketId) {
|
|
|
159
161
|
* {
|
|
160
162
|
* name: string,
|
|
161
163
|
* channel: string,
|
|
162
|
-
* data: any JSON-encodable data
|
|
164
|
+
* data: any JSON-encodable data,
|
|
165
|
+
* socket_id: [optional] string,
|
|
166
|
+
* info: [optional] string experimental, see https://pusher.com/docs/lab#experimental-program
|
|
163
167
|
* }
|
|
164
168
|
*/
|
|
165
169
|
Pusher.prototype.triggerBatch = function (batch) {
|
|
@@ -230,7 +234,9 @@ Pusher.prototype.createSignedQueryString = function (options) {
|
|
|
230
234
|
Pusher.prototype.channelSharedSecret = function (channel) {
|
|
231
235
|
return crypto
|
|
232
236
|
.createHash("sha256")
|
|
233
|
-
.update(
|
|
237
|
+
.update(
|
|
238
|
+
Buffer.concat([Buffer.from(channel), this.config.encryptionMasterKey])
|
|
239
|
+
)
|
|
234
240
|
.digest()
|
|
235
241
|
}
|
|
236
242
|
|
package/lib/requests.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Redundant default as a workaround for this WebPack bug:
|
|
2
|
+
// https://github.com/webpack/webpack/issues/4742
|
|
3
|
+
const fetch = require("node-fetch").default
|
|
4
|
+
const AbortController = require("abort-controller").default
|
|
3
5
|
|
|
4
6
|
const errors = require("./errors")
|
|
5
7
|
const util = require("./util")
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require("../package").version
|
|
1
|
+
module.exports = require("../package.json").version
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pusher",
|
|
3
3
|
"description": "Node.js client to interact with the Pusher Channels REST API",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.1",
|
|
5
5
|
"author": "Pusher <support@pusher.com>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
{
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"tweetnacl-util": "^0.15.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@types/node": "^14.14.6",
|
|
33
|
+
"@types/node-fetch": "^2.5.7",
|
|
32
34
|
"eslint": "^7.11.0",
|
|
33
35
|
"expect.js": "=0.3.1",
|
|
34
36
|
"express": "^4.17.1",
|
|
@@ -149,14 +149,14 @@ describe("Pusher", function () {
|
|
|
149
149
|
describe("Pusher with encryptionMasterKey", function () {
|
|
150
150
|
let pusher
|
|
151
151
|
|
|
152
|
-
const
|
|
152
|
+
const testMasterKeyBase64 = "zyrm8pvV2C9fJcBfhyXzvxbJVN/H7QLmbe0xJi1GhPU="
|
|
153
153
|
|
|
154
154
|
beforeEach(function () {
|
|
155
155
|
pusher = new Pusher({
|
|
156
156
|
appId: 1234,
|
|
157
157
|
key: "f00d",
|
|
158
158
|
secret: "tofu",
|
|
159
|
-
|
|
159
|
+
encryptionMasterKeyBase64: testMasterKeyBase64,
|
|
160
160
|
})
|
|
161
161
|
})
|
|
162
162
|
|
|
@@ -168,7 +168,7 @@ describe("Pusher with encryptionMasterKey", function () {
|
|
|
168
168
|
auth:
|
|
169
169
|
"f00d:962c48b78bf93d98ff4c92ee7dff04865821455b7b401e9d60a9e0a90af2c105",
|
|
170
170
|
channel_data: '"foo"',
|
|
171
|
-
shared_secret: "
|
|
171
|
+
shared_secret: "nlr49ISQHz91yS3cy/yWmW8wFMNeTnNL5tNHnbPJcLQ=",
|
|
172
172
|
})
|
|
173
173
|
})
|
|
174
174
|
it("should not return a shared_secret for non-encrypted channels", function () {
|
|
@@ -102,7 +102,7 @@ describe("Pusher", function () {
|
|
|
102
102
|
it("should support `encryptionMasterKey` of 32 bytes", function () {
|
|
103
103
|
const key = "01234567890123456789012345678901"
|
|
104
104
|
const pusher = new Pusher({ encryptionMasterKey: key })
|
|
105
|
-
expect(pusher.config.encryptionMasterKey).to.equal(key)
|
|
105
|
+
expect(pusher.config.encryptionMasterKey.toString()).to.equal(key)
|
|
106
106
|
})
|
|
107
107
|
|
|
108
108
|
it("should reject `encryptionMasterKey` of 31 bytes", function () {
|
|
@@ -121,14 +121,14 @@ describe("Pusher", function () {
|
|
|
121
121
|
|
|
122
122
|
it("should support `encryptionMasterKeyBase64` which decodes to 32 bytes", function () {
|
|
123
123
|
const key = "01234567890123456789012345678901"
|
|
124
|
-
const keyBase64 = Buffer.from(key
|
|
124
|
+
const keyBase64 = Buffer.from(key).toString("base64")
|
|
125
125
|
const pusher = new Pusher({ encryptionMasterKeyBase64: keyBase64 })
|
|
126
|
-
expect(pusher.config.encryptionMasterKey).to.equal(key)
|
|
126
|
+
expect(pusher.config.encryptionMasterKey.toString()).to.equal(key)
|
|
127
127
|
})
|
|
128
128
|
|
|
129
129
|
it("should reject `encryptionMasterKeyBase64` which decodes to 31 bytes", function () {
|
|
130
130
|
const key = "0123456789012345678901234567890"
|
|
131
|
-
const keyBase64 = Buffer.from(key
|
|
131
|
+
const keyBase64 = Buffer.from(key).toString("base64")
|
|
132
132
|
expect(function () {
|
|
133
133
|
new Pusher({ encryptionMasterKeyBase64: keyBase64 })
|
|
134
134
|
}).to.throwException(/31 bytes/)
|
|
@@ -136,7 +136,7 @@ describe("Pusher", function () {
|
|
|
136
136
|
|
|
137
137
|
it("should reject `encryptionMasterKeyBase64` which decodes to 33 bytes", function () {
|
|
138
138
|
const key = "012345678901234567890123456789012"
|
|
139
|
-
const keyBase64 = Buffer.from(key
|
|
139
|
+
const keyBase64 = Buffer.from(key).toString("base64")
|
|
140
140
|
expect(function () {
|
|
141
141
|
new Pusher({ encryptionMasterKeyBase64: keyBase64 })
|
|
142
142
|
}).to.throwException(/33 bytes/)
|
|
@@ -99,7 +99,7 @@ describe("Pusher", function () {
|
|
|
99
99
|
.catch(done)
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
it("should add
|
|
102
|
+
it("should add params to the request body", function (done) {
|
|
103
103
|
nock("http://api.pusherapp.com")
|
|
104
104
|
.filteringPath(function (path) {
|
|
105
105
|
return path
|
|
@@ -107,18 +107,23 @@ describe("Pusher", function () {
|
|
|
107
107
|
.replace(/auth_signature=[0-9a-f]{64}/, "auth_signature=Y")
|
|
108
108
|
})
|
|
109
109
|
.post(
|
|
110
|
-
"/apps/1234/events?auth_key=f00d&auth_timestamp=X&auth_version=1.0&body_md5=
|
|
110
|
+
"/apps/1234/events?auth_key=f00d&auth_timestamp=X&auth_version=1.0&body_md5=2e4f053f1c325dedbe21abd8f1852b53&auth_signature=Y",
|
|
111
111
|
{
|
|
112
112
|
name: "my_event",
|
|
113
113
|
data: '{"some":"data "}',
|
|
114
114
|
channels: ["test_channel"],
|
|
115
115
|
socket_id: "123.567",
|
|
116
|
+
info: "user_count,subscription_count",
|
|
116
117
|
}
|
|
117
118
|
)
|
|
118
119
|
.reply(200, "{}")
|
|
119
120
|
|
|
121
|
+
const params = {
|
|
122
|
+
socket_id: "123.567",
|
|
123
|
+
info: "user_count,subscription_count",
|
|
124
|
+
}
|
|
120
125
|
pusher
|
|
121
|
-
.trigger("test_channel", "my_event", { some: "data " },
|
|
126
|
+
.trigger("test_channel", "my_event", { some: "data " }, params)
|
|
122
127
|
.then(() => done())
|
|
123
128
|
.catch(done)
|
|
124
129
|
})
|
|
@@ -131,20 +136,31 @@ describe("Pusher", function () {
|
|
|
131
136
|
.replace(/auth_signature=[0-9a-f]{64}/, "auth_signature=Y")
|
|
132
137
|
})
|
|
133
138
|
.post(
|
|
134
|
-
"/apps/1234/events?auth_key=f00d&auth_timestamp=X&auth_version=1.0&body_md5=
|
|
139
|
+
"/apps/1234/events?auth_key=f00d&auth_timestamp=X&auth_version=1.0&body_md5=d3a47b3241328a6432adf60c8e91b6fb&auth_signature=Y",
|
|
135
140
|
{
|
|
136
141
|
name: "my_event",
|
|
137
142
|
data: '{"some":"data "}',
|
|
138
143
|
channels: ["test_channel"],
|
|
144
|
+
info: "subscription_count",
|
|
139
145
|
}
|
|
140
146
|
)
|
|
141
|
-
.reply(200, "
|
|
147
|
+
.reply(200, '{"channels":{"test_channel":{"subscription_count":123}}}')
|
|
142
148
|
|
|
143
149
|
pusher
|
|
144
|
-
.trigger(
|
|
150
|
+
.trigger(
|
|
151
|
+
"test_channel",
|
|
152
|
+
"my_event",
|
|
153
|
+
{ some: "data " },
|
|
154
|
+
{ info: "subscription_count" }
|
|
155
|
+
)
|
|
145
156
|
.then((response) => {
|
|
146
157
|
expect(response.status).to.equal(200)
|
|
147
|
-
|
|
158
|
+
return response.text().then((body) => {
|
|
159
|
+
expect(body).to.equal(
|
|
160
|
+
'{"channels":{"test_channel":{"subscription_count":123}}}'
|
|
161
|
+
)
|
|
162
|
+
done()
|
|
163
|
+
})
|
|
148
164
|
})
|
|
149
165
|
.catch(done)
|
|
150
166
|
})
|
|
@@ -286,7 +302,12 @@ describe("Pusher", function () {
|
|
|
286
302
|
.reply(200, "{}")
|
|
287
303
|
|
|
288
304
|
pusher
|
|
289
|
-
.trigger(
|
|
305
|
+
.trigger(
|
|
306
|
+
"test_channel",
|
|
307
|
+
"my_event",
|
|
308
|
+
{ some: "data " },
|
|
309
|
+
{ socket_id: "123.567" }
|
|
310
|
+
)
|
|
290
311
|
.then(() => done())
|
|
291
312
|
.catch(done)
|
|
292
313
|
})
|
|
@@ -317,7 +338,12 @@ describe("Pusher", function () {
|
|
|
317
338
|
.reply(200)
|
|
318
339
|
|
|
319
340
|
pusher
|
|
320
|
-
.trigger(
|
|
341
|
+
.trigger(
|
|
342
|
+
"test_channel",
|
|
343
|
+
"my_event",
|
|
344
|
+
{ some: "data " },
|
|
345
|
+
{ socket_id: "123.567" }
|
|
346
|
+
)
|
|
321
347
|
.catch((error) => {
|
|
322
348
|
expect(error).to.be.a(Pusher.RequestError)
|
|
323
349
|
expect(error.message).to.equal("Request failed with an error")
|
|
@@ -421,8 +447,7 @@ describe("Pusher with encryptionMasterKey", function () {
|
|
|
421
447
|
let pusher
|
|
422
448
|
|
|
423
449
|
const testMasterKey = Buffer.from(
|
|
424
|
-
"01234567890123456789012345678901"
|
|
425
|
-
"binary"
|
|
450
|
+
"01234567890123456789012345678901"
|
|
426
451
|
).toString("base64")
|
|
427
452
|
|
|
428
453
|
beforeEach(function () {
|
package/.travis.yml
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
language: node_js
|
|
2
|
-
jobs:
|
|
3
|
-
include:
|
|
4
|
-
- node_js: 14
|
|
5
|
-
script:
|
|
6
|
-
- npm run lint
|
|
7
|
-
- npm test
|
|
8
|
-
- node_js: 12
|
|
9
|
-
script:
|
|
10
|
-
- npm run lint
|
|
11
|
-
- npm test
|
|
12
|
-
- node_js: 10
|
|
13
|
-
script:
|
|
14
|
-
- npm run lint
|
|
15
|
-
- npm test
|
|
16
|
-
- node_js: 8
|
|
17
|
-
script:
|
|
18
|
-
# eslint doesn't support node 8, but it's sufficient to check that the
|
|
19
|
-
# tests pass.
|
|
20
|
-
- npm test
|