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 1.6.1 to 1.7.0

8

CHANGELOG.md

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

## [1.7.0][] - 2021-05-24
- Fix method access check
- Rename id field to support new auth
## [1.6.1][] - 2021-04-13

@@ -86,3 +91,4 @@

[unreleased]: https://github.com/metarhia/metacom/compare/v1.6.1...HEAD
[unreleased]: https://github.com/metarhia/metacom/compare/v1.7.0...HEAD
[1.7.0]: https://github.com/metarhia/metacom/compare/v1.6.1...v1.7.0
[1.6.1]: https://github.com/metarhia/metacom/compare/v1.6.0...v1.6.1

@@ -89,0 +95,0 @@ [1.6.0]: https://github.com/metarhia/metacom/compare/v1.5.3...v1.6.0

35

dist/metacom.js

@@ -113,19 +113,20 @@ import { EventEmitter } from './events.js';

scaffold(iname, ver) {
return (methodName) => async (args = {}) => {
const callId = ++this.callId;
const interfaceName = ver ? `${iname}.${ver}` : iname;
const target = interfaceName + '/' + methodName;
if (!this.connected) await this.open();
return new Promise((resolve, reject) => {
setTimeout(() => {
if (this.calls.has(callId)) {
this.calls.delete(callId);
reject(new Error('Request timeout'));
}
}, this.callTimeout);
this.calls.set(callId, [resolve, reject]);
const packet = { call: callId, [target]: args };
this.send(JSON.stringify(packet));
});
};
return (methodName) =>
async (args = {}) => {
const callId = ++this.callId;
const interfaceName = ver ? `${iname}.${ver}` : iname;
const target = interfaceName + '/' + methodName;
if (!this.connected) await this.open();
return new Promise((resolve, reject) => {
setTimeout(() => {
if (this.calls.has(callId)) {
this.calls.delete(callId);
reject(new Error('Request timeout'));
}
}, this.callTimeout);
this.calls.set(callId, [resolve, reject]);
const packet = { call: callId, [target]: args };
this.send(JSON.stringify(packet));
});
};
}

@@ -132,0 +133,0 @@ }

@@ -81,7 +81,7 @@ 'use strict';

async startSession(systemUserId) {
async startSession(accountId) {
const channel = channels.get(this);
const token = channel.application.auth.generateToken();
const data = {};
const fields = { ip: channel.ip, systemUserId };
const fields = { ip: channel.ip, accountId };
channel.application.auth.startSession(token, data, fields);

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

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

@@ -216,0 +216,0 @@ return;

@@ -88,34 +88,36 @@ 'use strict';

httpCall(iname, ver) {
return (methodName) => (args = {}) => {
const callId = ++this.callId;
const interfaceName = ver ? `${iname}.${ver}` : iname;
const target = interfaceName + '/' + methodName;
const packet = { call: callId, [target]: args };
const dest = new URL(this.url);
const protocol = dest.protocol === 'ws:' ? 'http' : 'https';
const url = `${protocol}://${dest.host}/api`;
return fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(packet),
}).then((json) => {
const packet = JSON.parse(json);
if (packet.error) throw new MetacomError(packet.error);
return packet.result;
});
};
return (methodName) =>
(args = {}) => {
const callId = ++this.callId;
const interfaceName = ver ? `${iname}.${ver}` : iname;
const target = interfaceName + '/' + methodName;
const packet = { call: callId, [target]: args };
const dest = new URL(this.url);
const protocol = dest.protocol === 'ws:' ? 'http' : 'https';
const url = `${protocol}://${dest.host}/api`;
return fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(packet),
}).then((json) => {
const packet = JSON.parse(json);
if (packet.error) throw new MetacomError(packet.error);
return packet.result;
});
};
}
socketCall(iname, ver) {
return (methodName) => async (args = {}) => {
const callId = ++this.callId;
const interfaceName = ver ? `${iname}.${ver}` : iname;
const target = interfaceName + '/' + methodName;
await this.ready();
return new Promise((resolve, reject) => {
this.calls.set(callId, [resolve, reject]);
const packet = { call: callId, [target]: args };
this.socket.send(JSON.stringify(packet));
});
};
return (methodName) =>
async (args = {}) => {
const callId = ++this.callId;
const interfaceName = ver ? `${iname}.${ver}` : iname;
const target = interfaceName + '/' + methodName;
await this.ready();
return new Promise((resolve, reject) => {
this.calls.set(callId, [resolve, reject]);
const packet = { call: callId, [target]: args };
this.socket.send(JSON.stringify(packet));
});
};
}

@@ -122,0 +124,0 @@ }

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

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

"dependencies": {
"@types/ws": "^7.4.1",
"metautil": "^3.5.1",
"ws": "^7.4.4"
"@types/ws": "^7.4.4",
"metautil": "^3.5.3",
"ws": "^7.4.5"
},
"devDependencies": {
"@types/node": "^14.14.37",
"eslint": "^7.24.0",
"@types/node": "^15.6.0",
"eslint": "^7.27.0",
"eslint-config-metarhia": "^7.0.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-prettier": "^3.4.0",
"metatests": "^0.7.2",
"prettier": "^2.2.1",
"prettier": "^2.3.0",
"typescript": "^4.2.4"
}
}
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