pusher-platform-node
Advanced tools
Comparing version 0.4.3 to 0.6.0
{ | ||
"name": "pusher-platform-node", | ||
"version": "0.4.3", | ||
"version": "0.6.0", | ||
"main": "./target/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./target/index.d.ts", |
@@ -7,3 +7,3 @@ # pusher-platform-nodejs | ||
Add `pusher-platform` to your package.json file: | ||
Add `pusher-platform-node` to your package.json file: | ||
@@ -13,3 +13,3 @@ ```json | ||
"dependencies": { | ||
"pusher-platform": "^0.2.0" | ||
"pusher-platform-node": "^0.5.0" | ||
} | ||
@@ -21,17 +21,24 @@ } | ||
In order to access Pusher Platform, first instantiate an App object: | ||
In order to access Pusher Platform, first instantiate an Instance object. | ||
It takes the following arguments: | ||
```js | ||
var pusher = require("pusher-platform"); | ||
var pusher = require("pusher-platform-node"); | ||
var app = new pusher.App({ | ||
cluster: "", | ||
app_id: "", | ||
app_key: "", | ||
var pusherPlatform = new pusher.Instance({ | ||
instance: "", | ||
serviceName: "", | ||
serviceVersion: "", | ||
key: "", | ||
}); | ||
``` | ||
`instance` is the ID that is unique to app developers' instance - they get that from the dashboard. The service SDKs will need to relay that down. Same for the `key`. | ||
`serviceName` and `serviceVersion` should come from the service SDK itself. They can be hardcoded there. Think `feeds` and `v1`. | ||
It is also possible to specify `host` and `port`. This will override the cluster value that is encoded in the `instance` and allow you to connect to a development or testing server. | ||
### Authetication | ||
App objects provide an `authenticate` method, which can be used in controllers | ||
Instance objects provide an `authenticate` method, which can be used in controllers | ||
to build authentication endpoints. Authentication endpoints issue access tokens | ||
@@ -83,4 +90,3 @@ used by Pusher Platform clients to access the API. | ||
App objects provide a low-level request API, which can be used to contact | ||
Pusher Platform. | ||
Instance objects provide a low-level request API, which can be used to contact Pusher Platform. | ||
@@ -87,0 +93,0 @@ ```js |
@@ -9,5 +9,8 @@ import extend = require("extend"); | ||
export interface Options { | ||
export interface BaseClientOptions { | ||
host: string; | ||
port?: number; | ||
port: number; | ||
serviceName: string; | ||
serviceVersion: string; | ||
instanceId: string; | ||
} | ||
@@ -18,10 +21,22 @@ | ||
private port: number; | ||
private serviceName: string; | ||
private serviceVersion: string; | ||
private instanceId: string; | ||
constructor(options?: Options) { | ||
constructor(options?: BaseClientOptions) { | ||
this.host = options.host; | ||
this.port = options.port || 443; | ||
this.port = options.port | ||
this.serviceName = options.serviceName; | ||
this.serviceVersion = options.serviceVersion; | ||
this.instanceId = options.instanceId; | ||
} | ||
/** | ||
* Make a HTTPS request to a service running on Elements. | ||
* It will construct a valid elements URL from its serviceName, serviceVersion and instanceId that were passed to the Instance at construction time. | ||
*/ | ||
request(options: RequestOptions): Promise<IncomingMessage> { | ||
var headers: any = {}; | ||
let path = `services/${this.serviceName}/${this.serviceVersion}/${this.instanceId}/${options.path}`; | ||
@@ -41,3 +56,3 @@ if (options.headers) { | ||
method: options.method, | ||
path: options.path, | ||
path: path, | ||
headers: headers, | ||
@@ -44,0 +59,0 @@ }; |
@@ -30,3 +30,3 @@ import {Readable} from "stream"; | ||
export interface AuthenticateOptions { | ||
userId: string; | ||
userId?: string; | ||
serviceClaims: any; | ||
@@ -33,0 +33,0 @@ } |
@@ -7,3 +7,3 @@ export {Readable as Readable} from "stream"; | ||
export {default as App} from "./app"; | ||
export {default as Instance} from "./instance"; | ||
@@ -10,0 +10,0 @@ export {default as BaseClient} from "./base_client"; |
/// <reference types="node" /> | ||
import { IncomingMessage } from "http"; | ||
import { RequestOptions } from "./common"; | ||
export interface Options { | ||
export interface BaseClientOptions { | ||
host: string; | ||
port?: number; | ||
port: number; | ||
serviceName: string; | ||
serviceVersion: string; | ||
instanceId: string; | ||
} | ||
@@ -11,4 +14,11 @@ export default class BaseClient { | ||
private port; | ||
constructor(options?: Options); | ||
private serviceName; | ||
private serviceVersion; | ||
private instanceId; | ||
constructor(options?: BaseClientOptions); | ||
/** | ||
* Make a HTTPS request to a service running on Elements. | ||
* It will construct a valid elements URL from its serviceName, serviceVersion and instanceId that were passed to the Instance at construction time. | ||
*/ | ||
request(options: RequestOptions): Promise<IncomingMessage>; | ||
} |
@@ -9,6 +9,14 @@ "use strict"; | ||
this.host = options.host; | ||
this.port = options.port || 443; | ||
this.port = options.port; | ||
this.serviceName = options.serviceName; | ||
this.serviceVersion = options.serviceVersion; | ||
this.instanceId = options.instanceId; | ||
} | ||
/** | ||
* Make a HTTPS request to a service running on Elements. | ||
* It will construct a valid elements URL from its serviceName, serviceVersion and instanceId that were passed to the Instance at construction time. | ||
*/ | ||
BaseClient.prototype.request = function (options) { | ||
var headers = {}; | ||
var path = "services/" + this.serviceName + "/" + this.serviceVersion + "/" + this.instanceId + "/" + options.path; | ||
if (options.headers) { | ||
@@ -26,3 +34,3 @@ for (var key in options.headers) { | ||
method: options.method, | ||
path: options.path, | ||
path: path, | ||
headers: headers, | ||
@@ -29,0 +37,0 @@ }; |
@@ -24,3 +24,3 @@ /// <reference types="node" /> | ||
export interface AuthenticateOptions { | ||
userId: string; | ||
userId?: string; | ||
serviceClaims: any; | ||
@@ -27,0 +27,0 @@ } |
@@ -5,3 +5,3 @@ export { Readable as Readable } from "stream"; | ||
export { UnsupportedGrantTypeError, InvalidGrantTypeError } from './errors'; | ||
export { default as App } from "./app"; | ||
export { default as Instance } from "./instance"; | ||
export { default as BaseClient } from "./base_client"; | ||
@@ -8,0 +8,0 @@ export * from "./decoders"; |
@@ -13,4 +13,4 @@ "use strict"; | ||
exports.InvalidGrantTypeError = errors_1.InvalidGrantTypeError; | ||
var app_1 = require("./app"); | ||
exports.App = app_1.default; | ||
var instance_1 = require("./instance"); | ||
exports.Instance = instance_1.default; | ||
var base_client_1 = require("./base_client"); | ||
@@ -17,0 +17,0 @@ exports.BaseClient = base_client_1.default; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
54220
949
113