Skip to content

Commit eb255d2

Browse files
committed
prettier
1 parent 5b098ab commit eb255d2

38 files changed

+2197
-1866
lines changed

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
semi: false,
3+
}

README.md

Lines changed: 86 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ Then to build the file bundle for Parse Cloud:
3535
To import `Pusher`:
3636

3737
```js
38-
var Pusher = require('cloud/modules/node_modules/pusher/parse');
38+
var Pusher = require("cloud/modules/node_modules/pusher/parse")
3939
```
4040

4141
## Importing
4242

4343
It's possible to use pusher-http-node with typescript or javascript.
4444

4545
```javascript
46-
const Pusher = require('pusher');
46+
const Pusher = require("pusher")
4747
```
4848

4949
```typescript
50-
import * as Pusher from 'pusher';
50+
import * as Pusher from "pusher"
5151
```
5252

5353
All external APIs should have types in index.d.ts.
@@ -57,41 +57,41 @@ All external APIs should have types in index.d.ts.
5757
There are 3 ways to configure the client. First one is just using the Pusher constructor:
5858

5959
```javascript
60-
var Pusher = require('pusher');
60+
var Pusher = require("pusher")
6161

6262
var pusher = new Pusher({
63-
appId: 'APP_ID',
64-
key: 'APP_KEY',
65-
secret: 'SECRET_KEY',
63+
appId: "APP_ID",
64+
key: "APP_KEY",
65+
secret: "SECRET_KEY",
6666
useTLS: USE_TLS, // optional, defaults to false
67-
cluster: 'CLUSTER', // if `host` is present, it will override the `cluster` option.
68-
host: 'HOST', // optional, defaults to api.pusherapp.com
67+
cluster: "CLUSTER", // if `host` is present, it will override the `cluster` option.
68+
host: "HOST", // optional, defaults to api.pusherapp.com
6969
port: PORT, // optional, defaults to 80 for non-TLS connections and 443 for TLS connections
7070
encryptionMasterKeyBase64: ENCRYPTION_MASTER_KEY, // a base64 string which encodes 32 bytes, used to derive the per-channel encryption keys (see below!)
71-
});
71+
})
7272
```
7373

7474
For specific clusters, you can use the `forCluster` function. This is the same as using the `cluster` option in the constructor.
7575

7676
```javascript
77-
var Pusher = require('pusher');
77+
var Pusher = require("pusher")
7878

7979
var pusher = Pusher.forCluster("CLUSTER", {
80-
appId: 'APP_ID',
81-
key: 'APP_KEY',
82-
secret: 'SECRET_KEY',
80+
appId: "APP_ID",
81+
key: "APP_KEY",
82+
secret: "SECRET_KEY",
8383
useTLS: USE_TLS, // optional, defaults to false
8484
port: PORT, // optional, defaults to 80 for non-TLS connections and 443 for TLS connections
8585
encryptionMasterKeyBase64: ENCRYPTION_MASTER_KEY, // a base64 string which encodes 32 bytes, used to derive the per-channel encryption keys (see below!)
86-
});
86+
})
8787
```
8888

8989
You can also specify auth and endpoint options by passing an URL:
9090

9191
```javascript
92-
var Pusher = require('pusher');
92+
var Pusher = require("pusher")
9393

94-
var pusher = Pusher.forURL("SCHEME://APP_KEY:SECRET_KEY@HOST:PORT/apps/APP_ID");
94+
var pusher = Pusher.forURL("SCHEME://APP_KEY:SECRET_KEY@HOST:PORT/apps/APP_ID")
9595
```
9696

9797
You can pass the optional second argument with options, as in `forCluster` function.
@@ -104,14 +104,14 @@ variable to such URL, if you have the Pusher addon installed.
104104
There are a few additional options that can be used in all above methods:
105105

106106
```javascript
107-
var Pusher = require('pusher');
107+
var Pusher = require("pusher")
108108

109109
var pusher = new Pusher({
110110
// you can set other options in any of the 3 ways described above
111-
proxy: 'HTTP_PROXY_URL', // optional, URL to proxy the requests through
111+
proxy: "HTTP_PROXY_URL", // optional, URL to proxy the requests through
112112
timeout: TIMEOUT, // optional, timeout for all requests in milliseconds
113-
keepAlive: KEEP_ALIVE // optional, enables keep-alive, defaults to false
114-
});
113+
keepAlive: KEEP_ALIVE, // optional, enables keep-alive, defaults to false
114+
})
115115
```
116116

117117
## Usage
@@ -134,20 +134,22 @@ In case accessing data for invalid WebHooks, an Pusher.WebHookError exception wi
134134

135135
### Publishing events
136136

137-
To send an event to one or more channels use the trigger function. Channel names can contain only characters which are alphanumeric, '_' or '-' and have to be at most 200 characters long. Event name can be at most 200 characters long too.
137+
To send an event to one or more channels use the trigger function. Channel names can contain only characters which are alphanumeric, '\_' or '-' and have to be at most 200 characters long. Event name can be at most 200 characters long too.
138138

139139
#### Single channel
140140

141141
```javascript
142-
pusher.trigger('channel-1', 'test_event', { message: "hello world" });
142+
pusher.trigger("channel-1", "test_event", { message: "hello world" })
143143
```
144144

145145
#### Multiple channels
146146

147147
To trigger an event on multiple channels:
148148

149149
```javascript
150-
pusher.trigger([ 'channel-1', 'channel-2' ], 'test_event', { message: "hello world" });
150+
pusher.trigger(["channel-1", "channel-2"], "test_event", {
151+
message: "hello world",
152+
})
151153
```
152154

153155
You can trigger an event to at most 100 channels at once. Passing more than 100 channels will cause an exception to be thrown.
@@ -157,18 +159,20 @@ You can trigger an event to at most 100 channels at once. Passing more than 100
157159
If you wish to send multiple events in a single HTTP request, you can pass an array of events to `pusher.triggerBatch`. You can send up to a maximum of 10 events at once.
158160

159161
```javascript
160-
var events = [{
161-
channel: "channel-1",
162-
name: "test-event-1",
163-
data: {message: "hello world"}
164-
},
165-
{
166-
channel: "channel-2",
167-
name: "test-event-2",
168-
data: {message: "hello another world"}
169-
}];
170-
171-
pusher.triggerBatch(events);
162+
var events = [
163+
{
164+
channel: "channel-1",
165+
name: "test-event-1",
166+
data: { message: "hello world" },
167+
},
168+
{
169+
channel: "channel-2",
170+
name: "test-event-2",
171+
data: { message: "hello another world" },
172+
},
173+
]
174+
175+
pusher.triggerBatch(events)
172176
```
173177

174178
You can trigger a batch of up to 10 events.
@@ -178,8 +182,8 @@ You can trigger a batch of up to 10 events.
178182
In order to avoid the client that triggered the event from also receiving it, the `trigger` function takes an optional `socketId` parameter. For more informaiton see: <http://pusher.com/docs/publisher_api_guide/publisher_excluding_recipients>.
179183

180184
```javascript
181-
var socketId = '1302.1081607';
182-
pusher.trigger(channel, event, data, socketId);
185+
var socketId = "1302.1081607"
186+
pusher.trigger(channel, event, data, socketId)
183187
```
184188

185189
### End-to-end encryption [BETA]
@@ -199,24 +203,26 @@ This library supports end-to-end encryption of your private channels. This means
199203

200204
```javascript
201205
var pusher = new Pusher({
202-
appId: 'APP_ID',
203-
key: 'APP_KEY',
204-
secret: 'SECRET_KEY',
206+
appId: "APP_ID",
207+
key: "APP_KEY",
208+
secret: "SECRET_KEY",
205209
useTLS: true,
206-
encryptionMasterKeyBase64: '<KEY GENERATED BY PREVIOUS COMMAND>',
207-
});
210+
encryptionMasterKeyBase64: "<KEY GENERATED BY PREVIOUS COMMAND>",
211+
})
208212
```
209213

210214
3. Channels where you wish to use end-to-end encryption should be prefixed with `private-encrypted-`.
211215

212216
4. Subscribe to these channels in your client, and you're done! You can verify it is working by checking out the debug console on the [https://dashboard.pusher.com/](dashboard) and seeing the scrambled ciphertext.
213217

214-
**Important note: This will __not__ encrypt messages on channels that are not prefixed by `private-encrypted-`.**
218+
**Important note: This will **not** encrypt messages on channels that are not prefixed by `private-encrypted-`.**
215219

216220
**Limitation**: you cannot trigger a single event on multiple channels in a call to `trigger`, e.g.
217221

218222
```javascript
219-
pusher.trigger([ 'channel-1', 'private-encrypted-channel-2' ], 'test_event', { message: "hello world" });
223+
pusher.trigger(["channel-1", "private-encrypted-channel-2"], "test_event", {
224+
message: "hello world",
225+
})
220226
```
221227

222228
Rationale: the methods in this library map directly to individual Channels HTTP API requests. If we allowed triggering a single event on multiple channels (some encrypted, some unencrypted), then it would require two API requests: one where the event is encrypted to the encrypted channels, and one where the event is unencrypted for unencrypted channels.
@@ -226,7 +232,7 @@ Rationale: the methods in this library map directly to individual Channels HTTP
226232
To authorise your users to access private channels on Pusher Channels, you can use the `authenticate` function:
227233

228234
```javascript
229-
var auth = pusher.authenticate(socketId, channel);
235+
var auth = pusher.authenticate(socketId, channel)
230236
```
231237

232238
For more information see: <http://pusher.com/docs/authenticating_users>
@@ -255,48 +261,54 @@ For more information see: <http://pusher.com/docs/authenticating_users>
255261
It's possible to query the state of the application using the `pusher.get` function.
256262

257263
```javascript
258-
pusher.get({ path: path, params: params }, callback);
264+
pusher.get({ path: path, params: params }, callback)
259265
```
260266

261267
The `path` property identifies the resource that the request should be made to and the `params` property should be a map of additional query string key and value pairs.
262268

263269
Params can't include following keys:
270+
264271
- auth_key
265272
- auth_timestamp
266273
- auth_version
267274
- auth_signature
268275
- body_md5
269276

270277
The following example provides the signature of the callback and an example of parsing the result:
278+
271279
```javascript
272-
pusher.get({ path: '/channels', params: {} }, function(error, request, response) {
280+
pusher.get({ path: "/channels", params: {} }, function (
281+
error,
282+
request,
283+
response
284+
) {
273285
if (response.statusCode === 200) {
274-
var result = JSON.parse(response.body);
275-
var channelsInfo = result.channels;
286+
var result = JSON.parse(response.body)
287+
var channelsInfo = result.channels
276288
}
277-
});
289+
})
278290
```
279291

280292
#### Get the list of channels in an application
281293

282294
```javascript
283-
pusher.get({ path: '/channels', params: params }, callback);
295+
pusher.get({ path: "/channels", params: params }, callback)
284296
```
285297

286298
Information on the optional `params` and the structure of the returned JSON is defined in the [REST API reference](http://pusher.com/docs/rest_api#method-get-channels).
287299

288300
#### Get the state of a channel
289301

290302
```javascript
291-
pusher.get({ path: '/channels/[channel_name]', params: params }, callback);
303+
pusher.get({ path: "/channels/[channel_name]", params: params }, callback)
292304
```
293305

294306
Information on the optional `params` option property and the structure of the returned JSON is defined in the [REST API reference](http://pusher.com/docs/rest_api#method-get-channel).
295307

296308
#### Get the list of users in a presence channel
297309

298310
```javascript
299-
pusher.get({ path: '/channels/[channel_name]/users' }, callback);
311+
pusher.get({ path: "/channels/[channel_name]/users" }, callback)
300312
```
301313

302314
The `channel_name` in the path must be a [presence channel](http://pusher.com/docs/presence). The structure of the returned JSON is defined in the [REST API reference](http://pusher.com/docs/rest_api#method-get-users).
@@ -306,16 +318,18 @@ The `channel_name` in the path must be a [presence channel](http://pusher.com/do
306318
The library provides a simple helper for WebHooks, which can be accessed via Pusher instances:
307319

308320
```javascript
309-
var webhook = pusher.webhook(request);
321+
var webhook = pusher.webhook(request)
310322
```
311323

312324
Requests must expose following fields:
325+
313326
- headers - object with request headers indexed by lowercase header names
314327
- rawBody - string with the WebHook request body
315328

316329
Since neither Node.js nor express provide the body in the request, your application needs to read it and assign to the request object. See examples/webhook_endpoint.js for a simple webhook endpoint implementation using the express framework.
317330

318331
Headers object must contain following headers:
332+
319333
- x-pusher-key - application key, sent by Channels
320334
- x-pusher-signature - WebHook signature, generated by Channels
321335
- content-type - must be set to application/json, what Channels does
@@ -329,11 +343,14 @@ Validates the content type, body format and signature of the WebHook and returns
329343
Accepts an optional parameter containing additional application tokens (useful e.g. during migrations):
330344

331345
```javascript
332-
var webhook = pusher.webhook(request);
346+
var webhook = pusher.webhook(request)
333347
// will check only the key and secret assigned to the pusher object:
334-
webhook.isValid();
348+
webhook.isValid()
335349
// will also check two additional tokens:
336-
webhook.isValid([{ key: "x1", secret: "y1" }, { key: "x2", secret: "y2" }]);
350+
webhook.isValid([
351+
{ key: "x1", secret: "y1" },
352+
{ key: "x2", secret: "y2" },
353+
])
337354
```
338355

339356
#### getData
@@ -342,7 +359,7 @@ Returns the parsed WebHook body. Throws a Pusher.WebHookError if the WebHook is
342359

343360
```javascript
344361
// will return an object with the WebHook data
345-
webhook.getData();
362+
webhook.getData()
346363
```
347364

348365
Please read [the WebHooks documentation](http://pusher.com/docs/webhooks) to find out what fields are included in the body.
@@ -353,7 +370,7 @@ Returns events included in the WebHook as an array. Throws a Pusher.WebHookError
353370

354371
```javascript
355372
// will return an array with the events
356-
webhook.getEvents();
373+
webhook.getEvents()
357374
```
358375

359376
#### getTime
@@ -362,7 +379,7 @@ Returns the Date object for the time when the WebHook was sent from Channels. Th
362379

363380
```javascript
364381
// will return a Date object
365-
webhook.getTime();
382+
webhook.getTime()
366383
```
367384

368385
### Generating REST API signatures
@@ -371,11 +388,11 @@ If you wanted to send the REST API requests manually (e.g. using a different HTT
371388

372389
```javascript
373390
pusher.createSignedQueryString({
374-
method: "POST", // the HTTP request method
375-
path: "/apps/3/events", // the HTTP request path
376-
body: '{"name":"foo","channel":"donuts","data":"2-for-1"}', // optional, the HTTP request body
377-
params: {}, // optional, the query params
378-
});
391+
method: "POST", // the HTTP request method
392+
path: "/apps/3/events", // the HTTP request path
393+
body: '{"name":"foo","channel":"donuts","data":"2-for-1"}', // optional, the HTTP request body
394+
params: {}, // optional, the query params
395+
})
379396
```
380397

381398
The `params` object can't contain following keys, as they are used to sign the request:
@@ -410,8 +427,9 @@ app credentials, like following:
410427
## Credits
411428

412429
This library is based on the work of:
413-
* Christian Bäuerlein and his library pusher.
414-
* Jaewoong Kim and the node-pusher library.
430+
431+
- Christian Bäuerlein and his library pusher.
432+
- Jaewoong Kim and the node-pusher library.
415433

416434
## License
417435

0 commit comments

Comments
 (0)