Socket
Socket
Sign inDemoInstall

metacom

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metacom - npm Package Compare versions

Comparing version 2.0.5 to 2.0.6

10

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [2.0.6][] - 2022-04-26
- Fix missing channel handling in Client
- Fix default `httpCode` in `Channel#error()` calls
- Add custom http headers for rpc hooks
- Prevent return after semaphore enter
## [2.0.5][] - 2022-03-18

@@ -175,3 +182,4 @@

[unreleased]: https://github.com/metarhia/metacom/compare/v2.0.5...HEAD
[unreleased]: https://github.com/metarhia/metacom/compare/v2.0.6...HEAD
[2.0.6]: https://github.com/metarhia/metacom/compare/v2.0.5...v2.0.6
[2.0.5]: https://github.com/metarhia/metacom/compare/v2.0.4...v2.0.5

@@ -178,0 +186,0 @@ [2.0.4]: https://github.com/metarhia/metacom/compare/v2.0.3...v2.0.4

29

lib/channel.js

@@ -38,7 +38,9 @@ 'use strict';

redirect(location) {
return channels.get(this).redirect(location);
const channel = channels.get(this);
if (channel) channel.redirect(location);
}
get ip() {
return channels.get(this).ip;
const channel = channels.get(this);
return channel ? channel.ip : undefined;
}

@@ -54,3 +56,3 @@

const channel = channels.get(this);
if (!channel.connection) {
if (!channel || !channel.connection) {
throw new Error(`Can't send metacom events to http transport`);

@@ -63,2 +65,3 @@ }

const channel = channels.get(this);
if (!channel) return false;
if (channel.session) sessions.delete(channel.session.token);

@@ -74,2 +77,3 @@ const session = new Session(token, channel, data);

const channel = channels.get(this);
if (!channel) return false;
channel.session = session;

@@ -120,3 +124,3 @@ return true;

async rpc(callId, interfaceName, methodName, args) {
async rpc(callId, interfaceName, methodName, args, headers = null) {
const { application, session, client } = this;

@@ -129,2 +133,8 @@ const [iname, ver = '*'] = interfaceName.split('.');

}
const context = session ? session.context : { client };
context.headers = headers;
if (!this.session && proc.access !== 'public') {
this.error(403, { callId });
return;
}
try {

@@ -136,7 +146,2 @@ await proc.enter();

}
const context = session ? session.context : { client };
if (!this.session && proc.access !== 'public') {
this.error(403, { callId });
return;
}
let result = null;

@@ -149,4 +154,3 @@ try {

}
const httpCode = error.httpCode || error.code;
this.error(error.code, { callId, error, httpCode });
this.error(error.code, { callId, error });
return;

@@ -166,5 +170,6 @@ } finally {

error(code = 500, { callId, error = null, httpCode = 500 } = {}) {
error(code = 500, { callId, error = null, httpCode = null } = {}) {
const { req, ip, application } = this;
const { url, method } = req;
if (!httpCode) httpCode = (error && error.httpCode) || code;
const status = http.STATUS_CODES[httpCode];

@@ -171,0 +176,0 @@ const pass = httpCode < 500 || httpCode > 599;

@@ -107,5 +107,6 @@ 'use strict';

const [interfaceName, methodName] = metautil.split(path, '/');
const { headers } = req;
const hook = this.application.getHook(interfaceName);
if (hook) channel.hook(hook, interfaceName, methodName, args);
else channel.rpc(-1, interfaceName, methodName, args);
if (hook) channel.hook(hook, interfaceName, methodName, args, headers);
else channel.rpc(-1, interfaceName, methodName, args, headers);
});

@@ -112,0 +113,0 @@ }

@@ -49,2 +49,11 @@ import { EventEmitter } from 'events';

export class Client extends EventEmitter {
events: { close: Array<Function> };
callId: number;
ip: string | undefined;
redirect(location: string): void;
startSession(token: string, data: object): boolean;
restoreSession(token: string): boolean;
}
export class Channel {

@@ -55,3 +64,3 @@ application: object;

ip: string;
client: Metacom;
client: Client;
session?: Session;

@@ -58,0 +67,0 @@ constructor(application: object, req: ClientRequest, res: ServerResponse);

{
"name": "metacom",
"version": "2.0.5",
"version": "2.0.6",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",

@@ -60,13 +60,13 @@ "description": "Communication protocol for Metarhia stack with rpc, events, binary streams, memory and db access",

"devDependencies": {
"@types/node": "^17.0.21",
"@types/node": "^17.0.28",
"@types/ws": "^8.5.3",
"eslint": "^8.11.0",
"eslint": "^8.14.0",
"eslint-config-metarhia": "^7.0.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"metatests": "^0.8.2",
"prettier": "^2.6.0",
"typescript": "^4.6.2"
"prettier": "^2.6.2",
"typescript": "^4.6.3"
}
}
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