jsonrpcserver
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "jsonrpcserver", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "JSON-RPC Server (http://www.jsonrpc.org/specification) with endpoints implementation", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "env NODE_PATH=\"/usr/lib/node_modules\" node ./test/index.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -8,3 +8,3 @@ /** | ||
"E_PARSE_ERROR_32700": {httpCode: 500, response: {code: -32700, message: "Parse error"}, name: "E_PARSE_ERROR_32700"}, | ||
"E_INVALID_REQUEST_32600": {httpCode: 400, response: {code: -32600, message: "Invalid Request"}, name: "E_INVALID_REQUEST_32600"}, | ||
"E_INVALID_REQUEST_32600": {httpCode: 400, response: {code: -32600, message: "Invalid request"}, name: "E_INVALID_REQUEST_32600"}, | ||
"E_METHOD_NOT_FOUND_32601": {httpCode: 404, response: {code: -32601, message: "Method not found"}, name: "E_METHOD_NOT_FOUND_32601"}, | ||
@@ -11,0 +11,0 @@ "E_INVALID_PARAMS_32602": {httpCode: 500, response: {code: -32602, message: "Invalid params"}, name: "E_INVALID_PARAMS_32602"}, |
@@ -6,3 +6,4 @@ 'use strict'; | ||
fs = require('fs'), | ||
RpcEntity = require('./entity'), | ||
HttpEntity = require('./entities/http_entity'), | ||
ProxyEntity = require('./entities/proxy_entity'), | ||
RpcErrors = require('./errors'); | ||
@@ -157,3 +158,3 @@ | ||
var uuid = this.generateUuid(); | ||
this.entities[uuid] = new RpcEntity(this.logger, request, response, this.options.timeout || this.defaults.timeout, this.cleanup.bind(this, uuid)); | ||
this.entities[uuid] = new HttpEntity(this.logger, request, response, this.options.timeout || this.defaults.timeout, this.cleanup.bind(this, uuid)); | ||
this.entities[uuid].on('ready', this.checkRequest.bind(this, uuid)); | ||
@@ -163,2 +164,28 @@ }; | ||
/** | ||
* Proxy (emulate) request (may uses without server instantiate) | ||
* @param endpoint | ||
* @param request | ||
* @param cb | ||
*/ | ||
RpcServer.prototype.proxy = function(endpoint, request, cb) | ||
{ | ||
var payload = (typeof request == 'object' && request) || {}; | ||
payload.jsonrpc || (payload.jsonrpc = '2.0'); | ||
var uuid = this.generateUuid(), | ||
requestObject = { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json-rpc' | ||
}, | ||
payload: payload, | ||
url: { | ||
path: endpoint | ||
} | ||
}; | ||
this.entities[uuid] = new ProxyEntity(this.logger, requestObject, cb, this.options.timeout || this.defaults.timeout, this.cleanup.bind(this, uuid)); | ||
this.checkRequest(uuid); | ||
}; | ||
/** | ||
* Step-by-step check request | ||
@@ -194,7 +221,5 @@ * @param uuid | ||
//if notification | ||
if(request.content && !request.content.hasOwnProperty('id')) isNotification = true; | ||
//call method or process response with error | ||
if(!error) this.callMethod(uuid, request.url.path, request.content.method, request.content.params); | ||
if(error || isNotification) this.processResponse(uuid, error); | ||
else this.processResponse(uuid, error); | ||
}; | ||
@@ -333,3 +358,3 @@ | ||
if(!this.entities[uuid]) this.logger.warn('JSON-RPC server: unknown consumer'); | ||
if(!this.entities[uuid]) this.logger.warn('JSON-RPC server: attempt to call method for unknown consumer'); | ||
else { | ||
@@ -365,5 +390,5 @@ if(context && (typeof context == 'object')) { | ||
if(this.entities[uuid]) this.entities[uuid].processResponse(error, data); | ||
else this.logger.warn('JSON-RPC server: unknown consumer'); | ||
else this.logger.warn('JSON-RPC server: attempt to process response for unknown consumer'); | ||
}; | ||
module.exports = RpcServer; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
43604
2
13
1158
0
212
5