Installations
npm install jsonrpc-lite
Releases
Unable to fetch releases
Developer
teambition
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
12.15.0
NPM Version
6.13.4
Statistics
96 Stars
46 Commits
13 Forks
4 Watching
3 Branches
11 Contributors
Updated on 28 Nov 2024
Bundle Size
4.39 kB
Minified
1.46 kB
Minified + Gzipped
Languages
JavaScript (56.73%)
TypeScript (43.27%)
Total Downloads
Cumulative downloads
Total Downloads
5,353,587
Last day
-26.9%
1,877
Compared to previous day
Last week
-9.4%
12,977
Compared to previous week
Last month
-9.7%
71,067
Compared to previous month
Last year
-22.2%
740,109
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
6
JSON-RPC lite
Parse and Serialize JSON-RPC2 messages in node.js or browser.
Inspired by https://github.com/soggie/jsonrpc-serializer
A implementation of JSON-RPC 2.0 specifications
Install
1npm install jsonrpc-lite
API
1const jsonrpc = require('jsonrpc-lite')
jsonrpc.request(id, method[, params])
Creates a JSON-RPC 2.0 request object, return JsonRpc object.
id
: {String|Integer}method
: {String}params
: {Object|Array}, optional
1const requestObj = jsonrpc.request('123', 'update', {list: [1, 2, 3]}) 2// { 3// jsonrpc: '2.0', 4// id: '123', 5// method: 'update', 6// params: {list: [1, 2, 3]} 7// }
jsonrpc.notification(method[, params])
Creates a JSON-RPC 2.0 notification object, return JsonRpc object.
method
: {String}params
: {Object|Array}, optional
1const notificationObj = jsonrpc.notification('update', {list: [1, 2, 3]}) 2// { 3// jsonrpc: '2.0', 4// method: 'update', 5// params: {list: [1, 2, 3]} 6// }
jsonrpc.success(id, result)
Creates a JSON-RPC 2.0 success response object, return JsonRpc object.
id
: {String|Integer}result
: {Mixed}
1const successObj = jsonrpc.success('123', 'OK') 2// { 3// jsonrpc: '2.0', 4// id: '123', 5// result: 'OK', 6// }
jsonrpc.error(id, error)
Creates a JSON-RPC 2.0 error response object, return JsonRpc object.
id
: {String|Integer}error
: {JsonRpcError}
1const errorObj = jsonrpc.error('123', new jsonrpc.JsonRpcError('some error', 99)) 2// { 3// jsonrpc: '2.0', 4// id: '123', 5// error: {code: 99, 'message': 'some error'}, 6// }
jsonrpc.parse(message)
Takes a JSON-RPC 2.0 payload (string) and tries to parse it into a JSON. If successful, determine what object is it (response, notification, success, error, or invalid), and return it's type and properly formatted object.
message
: {String}
return an array, or an object of this format:
single parsed request:
1{ 2 type: 'request', 3 payload: { 4 jsonrpc: '2.0', 5 id: 123, 6 method: 'update', 7 params: {} 8 } 9}
batch parsed result:
1[{ 2 type: 'request', 3 payload: { 4 jsonrpc: '2.0', 5 id: '123', 6 method: 'update', 7 params: [1, 2, 3] 8 } 9}, { 10 type: 'notification', 11 payload: { 12 jsonrpc: '2.0', 13 method: 'update', 14 params: {_id: 'xxx'} 15 } 16}, { 17 type: 'success', 18 payload: { 19 jsonrpc: '2.0', 20 id: '123', 21 result: 'OK' 22 } 23}, { 24 type: 'error', 25 payload: { 26 jsonrpc: '2.0', 27 id: '123', 28 error: [jsonrpc.JsonRpcError object] 29 } 30}, { 31 type: 'invalid', 32 payload: [jsonrpc.JsonRpcError object] 33}]
jsonrpc.parseObject(message)
Takes a JSON-RPC 2.0 payload (Object) and tries to parse it into a JSON. If successful, determine what object is it (response, notification, success, error, or invalid), and return it's type and properly formatted object.
message
: {Object}
return an JsonRpcParsed
object with type
and payload
.
Class: jsonrpc.JsonRpc()
Class: jsonrpc.JsonRpcError(message, code[, data])
Create a JsonRpcError instance.
message
: {String}code
: {Integer}data
: {Mixed} optional
1const error = new jsonrpc.JsonRpcError('some error', 999)
Class Method: jsonrpc.JsonRpcError.invalidRequest([data])
Class Method: jsonrpc.JsonRpcError.methodNotFound([data])
Class Method: jsonrpc.JsonRpcError.invalidParams([data])
Class Method: jsonrpc.JsonRpcError.internalError([data])
Class Method: jsonrpc.JsonRpcError.parseError([data])
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
4 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Reason
Found 4/17 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 18 are checked with a SAST tool
Score
2.8
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More