New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pusher-platform-node

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pusher-platform-node - npm Package Compare versions

Comparing version

to
0.14.0

src/sdk_info.ts

9

CHANGELOG.md

@@ -7,4 +7,11 @@ # Changelog

## [Unreleased](https://github.com/pusher/pusher-platform-node/compare/0.13.2...HEAD)
## [Unreleased](https://github.com/pusher/pusher-platform-node/compare/0.14.0...HEAD)
## [0.14.0](https://github.com/pusher/pusher-platform-node/compare/0.13.2...0.14.0) - 2018-09-18
### Changes
- *Breaking*: An instance of `SDKInfo` is now required when instantiating an instance of `BaseClient`. This can either be directly provided to the `BaseClient` and then the base client provided to an instance of `Instance` in the `client` key or the `options` object that `Instance`s initializer takes, or you can provide the `SDKInfo` instance to the `Instance` initializer in the `sdkInfo` key of its `options` parameter
- Removed defaulting to generating a JWT with the `su: true` claim if no JWT is provided to a call to `request`
## [0.13.2](https://github.com/pusher/pusher-platform-node/compare/0.13.1...0.13.2) - 2018-08-17

@@ -11,0 +18,0 @@

2

package.json
{
"name": "pusher-platform-node",
"version": "0.13.2",
"version": "0.14.0",
"main": "./target/index.js",

@@ -5,0 +5,0 @@ "types": "./target/index.d.ts",

@@ -12,3 +12,3 @@ # pusher-platform-node

"dependencies": {
"pusher-platform-node": "~0.13.2"
"pusher-platform-node": "~0.14.0"
}

@@ -24,5 +24,5 @@ }

```js
var pusher = require("pusher-platform-node");
var PusherPlatform = require("pusher-platform-node");
var pusherPlatform = new pusher.Instance({
var pusherPlatform = new PusherPlatform.Instance({
locator: '',

@@ -32,7 +32,12 @@ serviceName: '',

key: '',
sdkInfo: new PusherPlatform.SDKInfo({
productName: '',
version: '',
}),
});
```
`locator` is unique to an 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`.
* `locator` is unique to an 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`.
* `sdkInfo` is used to provide product and SDK version information, via headers, to the platform

@@ -39,0 +44,0 @@ 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.

import extend = require('extend');
import { IncomingMessage } from 'http';
import * as https from 'https';
import * as HttpRequest from 'request';
import { format as formatURL } from 'url';
import {
RequestOptions, ErrorResponse, IncomingMessageWithBody
} from './common';
import * as HttpRequest from 'request';
import { format as formatURL } from 'url';
import SDKInfo from './sdk_info';

@@ -16,2 +17,3 @@ export interface BaseClientOptions {

instanceId: string;
sdkInfo: SDKInfo;
}

@@ -25,2 +27,3 @@

private instanceId: string;
private sdkInfo: SDKInfo;

@@ -33,2 +36,3 @@ constructor(options?: BaseClientOptions) {

this.instanceId = options.instanceId;
this.sdkInfo = options.sdkInfo;
}

@@ -42,3 +46,3 @@

request(options: RequestOptions): Promise<IncomingMessageWithBody> {
var headers: any = {};
var headers: any = this.sdkInfo.headers;

@@ -45,0 +49,0 @@ if (options.headers) {

@@ -17,3 +17,4 @@ export { IncomingMessage as IncomingMessage } from 'http';

export { default as BaseClient } from './base_client';
export { default as SDKInfo } from './sdk_info';
export { TokenWithExpiry } from './authenticator';

@@ -7,2 +7,3 @@ import extend = require('extend');

import BaseClient from './base_client';
import SDKInfo from './sdk_info';
import {

@@ -29,2 +30,3 @@ AuthenticateOptions,

client?: BaseClient;
sdkInfo?: SDKInfo;
}

@@ -47,8 +49,8 @@

constructor(options: InstanceOptions) {
if (!options.locator) { throw new Error('Expected `instanceLocator` property in Instance options'); }
if (options.locator.split(":").length !== 3) { throw new Error('The `locator` property is in the wrong format'); }
if (!options.serviceName) { throw new Error('Expected `serviceName` property in Instance options'); }
if (!options.serviceVersion) { throw new Error('Expected `serviceVersion` property in Instance otpions'); }
if (!options.client && !options.sdkInfo) { throw new Error('Expected one of `client` or `sdkInfo` to be provided') }
if (!options.locator) throw new Error('Expected `instanceLocator` property in Instance options!');
if (options.locator.split(":").length !== 3) throw new Error('The `locator` property is in the wrong format!');
if(!options.serviceName) throw new Error('Expected `serviceName` property in Instance options!');
if(!options.serviceVersion) throw new Error('Expected `serviceVersion` property in Instance otpions!');
let splitInstance = options.locator.split(":");

@@ -74,3 +76,4 @@ this.platformVersion = splitInstance[0];

serviceVersion: this.serviceVersion,
port: options.port || HTTPS_PORT
port: options.port || HTTPS_PORT,
sdkInfo: options.sdkInfo,
});

@@ -84,5 +87,2 @@

request(options: RequestOptions): Promise<IncomingMessageWithBody> {
if (options.jwt == null) {
options = extend(options, { jwt: `${this.authenticator.generateAccessToken({ su: true }).token}` });
}
return this.client.request(options);

@@ -89,0 +89,0 @@ }

import { RequestOptions, IncomingMessageWithBody } from './common';
import SDKInfo from './sdk_info';
export interface BaseClientOptions {

@@ -8,2 +9,3 @@ host: string;

instanceId: string;
sdkInfo: SDKInfo;
}

@@ -16,2 +18,3 @@ export default class BaseClient {

private instanceId;
private sdkInfo;
constructor(options?: BaseClientOptions);

@@ -18,0 +21,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var extend = require("extend");
var common_1 = require("./common");
var HttpRequest = require("request");
var url_1 = require("url");
var common_1 = require("./common");
var BaseClient = (function () {

@@ -14,2 +14,3 @@ function BaseClient(options) {

this.instanceId = options.instanceId;
this.sdkInfo = options.sdkInfo;
}

@@ -22,3 +23,3 @@ /**

BaseClient.prototype.request = function (options) {
var headers = {};
var headers = this.sdkInfo.headers;
if (options.headers) {

@@ -25,0 +26,0 @@ for (var key in options.headers) {

@@ -5,2 +5,3 @@ export { IncomingMessage as IncomingMessage } from 'http';

export { default as BaseClient } from './base_client';
export { default as SDKInfo } from './sdk_info';
export { TokenWithExpiry } from './authenticator';

@@ -10,2 +10,4 @@ "use strict";

exports.BaseClient = base_client_1.default;
var sdk_info_1 = require("./sdk_info");
exports.SDKInfo = sdk_info_1.default;
//# sourceMappingURL=index.js.map
import { TokenWithExpiry } from './authenticator';
import BaseClient from './base_client';
import SDKInfo from './sdk_info';
import { AuthenticateOptions, AuthenticatePayload, AuthenticationResponse, RequestOptions, IncomingMessageWithBody } from './common';

@@ -12,2 +13,3 @@ export interface InstanceOptions {

client?: BaseClient;
sdkInfo?: SDKInfo;
}

@@ -14,0 +16,0 @@ export default class Instance {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var extend = require("extend");
var authenticator_1 = require("./authenticator");

@@ -10,10 +9,17 @@ var base_client_1 = require("./base_client");

function Instance(options) {
if (!options.locator)
throw new Error('Expected `instanceLocator` property in Instance options!');
if (options.locator.split(":").length !== 3)
throw new Error('The `locator` property is in the wrong format!');
if (!options.serviceName)
throw new Error('Expected `serviceName` property in Instance options!');
if (!options.serviceVersion)
throw new Error('Expected `serviceVersion` property in Instance otpions!');
if (!options.locator) {
throw new Error('Expected `instanceLocator` property in Instance options');
}
if (options.locator.split(":").length !== 3) {
throw new Error('The `locator` property is in the wrong format');
}
if (!options.serviceName) {
throw new Error('Expected `serviceName` property in Instance options');
}
if (!options.serviceVersion) {
throw new Error('Expected `serviceVersion` property in Instance otpions');
}
if (!options.client && !options.sdkInfo) {
throw new Error('Expected one of `client` or `sdkInfo` to be provided');
}
var splitInstance = options.locator.split(":");

@@ -36,3 +42,4 @@ this.platformVersion = splitInstance[0];

serviceVersion: this.serviceVersion,
port: options.port || HTTPS_PORT
port: options.port || HTTPS_PORT,
sdkInfo: options.sdkInfo,
});

@@ -42,5 +49,2 @@ this.authenticator = new authenticator_1.default(this.id, this.keyId, this.keySecret);

Instance.prototype.request = function (options) {
if (options.jwt == null) {
options = extend(options, { jwt: "" + this.authenticator.generateAccessToken({ su: true }).token });
}
return this.client.request(options);

@@ -47,0 +51,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet