Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@4c/graphql-subscription-server

Package Overview
Dependencies
Maintainers
4
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@4c/graphql-subscription-server - npm Package Compare versions

Comparing version 0.8.2 to 0.9.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [0.9.0](https://github.com/4Catalyzer/graphql-subscription-server/compare/v0.8.2...v0.9.0) (2019-04-02)
### Features
* Allow subscription-level override of authorization check function ([#37](https://github.com/4Catalyzer/graphql-subscription-server/issues/37)) ([d5c7aaa](https://github.com/4Catalyzer/graphql-subscription-server/commit/d5c7aaa))
## [0.8.2](https://github.com/4Catalyzer/graphql-subscription-server/compare/v0.8.1...v0.8.2) (2019-03-20)

@@ -2,0 +9,0 @@

35

es/AuthorizedSocketConnection.js

@@ -20,14 +20,4 @@ import { createSourceEventStream, execute, GraphQLError, parse, specifiedRules, validate } from 'graphql';

constructor(socket, config) {
this.isAuthorized = data => {
const credentials = this.config.credentialsManager.getCredentials();
const isAuthorized = !!credentials && this.config.hasPermission(data, credentials);
if (!isAuthorized) {
this.log('info', 'unauthorized', {
payload: data,
credentials
});
}
return isAuthorized;
this.hasPermission = (data, credentials) => {
return this.config.hasPermission(data, credentials);
};

@@ -96,3 +86,8 @@

const sourcePromise = createSourceEventStream(this.config.schema, document, null, {
subscribe: async (...args) => AsyncUtils.filter((await subscriptionContext.subscribe(...args)), this.isAuthorized)
subscribe: async (topic, {
hasPermission = this.config.hasPermission,
...options
} = {}) => {
return AsyncUtils.filter((await subscriptionContext.subscribe(topic, options)), data => this.isAuthorized(data, hasPermission));
}
}, variables);

@@ -186,2 +181,16 @@ this.subscriptionContexts.set(id, subscriptionContext);

isAuthorized(data, hasPermission) {
const credentials = this.config.credentialsManager.getCredentials();
const isAuthorized = !!credentials && hasPermission(data, credentials);
if (!isAuthorized) {
this.log('info', 'unauthorized', {
payload: data,
credentials
});
}
return isAuthorized;
}
}
import { AsyncQueue } from './AsyncUtils';
/**
* A subscriber over a standard EventEmitter. Events are pushed as
* they received, passing through, the _first_ argument of the event handler.
* Events are listened to at the time of subscription, meaning only event past then will be received.
*/
export default class EventSubscriber {

@@ -32,3 +26,3 @@ constructor(emitter) {

subscribe(event) {
subscribe(event, _options) {
let eventQueues = this._queues.get(event);

@@ -35,0 +29,0 @@

@@ -36,3 +36,5 @@ import redis from 'redis';

subscribe(channel, parseMessage = this._parseMessage) {
subscribe(channel, options = {}) {
const parseMessage = options.parseMessage || this._parseMessage;
let channelQueues = this._queues.get(channel);

@@ -39,0 +41,0 @@

@@ -31,14 +31,4 @@ "use strict";

constructor(socket, config) {
this.isAuthorized = data => {
const credentials = this.config.credentialsManager.getCredentials();
const isAuthorized = !!credentials && this.config.hasPermission(data, credentials);
if (!isAuthorized) {
this.log('info', 'unauthorized', {
payload: data,
credentials
});
}
return isAuthorized;
this.hasPermission = (data, credentials) => {
return this.config.hasPermission(data, credentials);
};

@@ -107,3 +97,8 @@

const sourcePromise = (0, _graphql.createSourceEventStream)(this.config.schema, document, null, {
subscribe: async (...args) => AsyncUtils.filter((await subscriptionContext.subscribe(...args)), this.isAuthorized)
subscribe: async (topic, {
hasPermission = this.config.hasPermission,
...options
} = {}) => {
return AsyncUtils.filter((await subscriptionContext.subscribe(topic, options)), data => this.isAuthorized(data, hasPermission));
}
}, variables);

@@ -197,4 +192,18 @@ this.subscriptionContexts.set(id, subscriptionContext);

isAuthorized(data, hasPermission) {
const credentials = this.config.credentialsManager.getCredentials();
const isAuthorized = !!credentials && hasPermission(data, credentials);
if (!isAuthorized) {
this.log('info', 'unauthorized', {
payload: data,
credentials
});
}
return isAuthorized;
}
}
exports.default = AuthorizedSocketConnection;

@@ -8,7 +8,2 @@ "use strict";

/**
* A subscriber over a standard EventEmitter. Events are pushed as
* they received, passing through, the _first_ argument of the event handler.
* Events are listened to at the time of subscription, meaning only event past then will be received.
*/
class EventSubscriber {

@@ -38,3 +33,3 @@ constructor(emitter) {

subscribe(event) {
subscribe(event, _options) {
let eventQueues = this._queues.get(event);

@@ -41,0 +36,0 @@

@@ -46,3 +46,5 @@ "use strict";

subscribe(channel, parseMessage = this._parseMessage) {
subscribe(channel, options = {}) {
const parseMessage = options.parseMessage || this._parseMessage;
let channelQueues = this._queues.get(channel);

@@ -49,0 +51,0 @@

{
"name": "@4c/graphql-subscription-server",
"version": "0.8.2",
"version": "0.9.0",
"files": [

@@ -70,3 +70,3 @@ "lib",

"devDependencies": {
"@4c/babel-preset": "^5.0.4",
"@4c/babel-preset": "^5.1.0",
"@4c/semantic-release-config": "^1.0.5",

@@ -77,5 +77,5 @@ "@babel/cli": "^7.2.3",

"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"babel-jest": "^24.6.0",
"codecov": "^3.2.0",
"eslint": "^5.15.3",
"eslint": "^5.16.0",
"eslint-config-4catalyzer-flow": "^0.8.2",

@@ -91,6 +91,6 @@ "eslint-config-4catalyzer-flow-react": "^0.7.8",

"eslint-plugin-react": "^7.12.4",
"flow-bin": "^0.95.1",
"graphql": "^14.1.1",
"flow-bin": "^0.96.0",
"graphql": "^14.2.1",
"husky": "^1.3.1",
"jest": "^24.5.0",
"jest": "^24.6.0",
"lint-staged": "^8.1.5",

@@ -97,0 +97,0 @@ "prettier": "^1.16.4",

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc