Research
Security News
Malicious PyPI Package ‘pycord-self’ Targets Discord Developers with Token Theft and Backdoor Exploit
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
jsonrpc-ts-client
Advanced tools
Warning: this project is in alpha, and the API is subject to change.
Check out the Open RPC Ecosystem for more tools.
Feature | Supported |
---|---|
Isomorphism | ✅ |
Batch Support | ✅ |
Contract Support | ✅ |
npm install jsonrpc-ts-client --save
or
yarn add jsonrpc-ts-client
import JSONRPC from 'jsonrpc-ts-client'
interface UserDto { // ideally, these are generated from your JSON Schema.
name: string,
occupation: string,
}
const client = new JSONRPC({
url: 'https://foo.com/jsonrpc'
})
const response = await client.exec<UserDto>('my_method', { userId: 123 }); // sends payload {jsonrpc: '2.0', params: ...}
if (response.isSuccess()) { // returns an JsonRpcYeah<Result>
console.log(response.result.name)
console.log(response.result.occupation)
} else if (response.isError()) {
// more information on errors: https://www.jsonrpc.org/specification#error_object
console.log(result.error.message) // e.g. "Invalid Params"
console.log(result.error.code) // e.g -32603
}
You can make batch requests per the JSON-RPC specification.
import JSONRPC from 'jsonrpc-ts-client'
type MyApiContract = {
getUser: (params: UserParamsDto) => UserDto;
getConfig: () => ConfigDto,
getProduct: (productId: string) => ProductDto,
};
// pass in your api contract to get type-safety and autocomplete
const client = new JsonRpcClient<MyApiContract>({
idGeneratorFn: uuid.v4,
url: JSONRPC_URL,
});
const result = await client.exec("getUser", { userId: 123 }); // autocomplete!
if (result.isSuccess()) {
console.log(result.user.name)
console.log(result.user.id)
}
import JSONRPC from 'jsonrpc-ts-client'
type MyApiContract = {
getUser: (params: UserParamsDto) => UserDto;
getConfig: () => ConfigDto,
getProduct: (productId: string) => ProductDto,
};
const [user, config] = await client.execBatch([
{ method: "getUser", params: { userId: 123 } },
{ method: "getConfig" },
] as const
);
if (user.isSuccess()) {
console.log(user.name)
console.log(user.id)
}
if (config.isSuccesss()) {
console.log(config.foo)
}
Generate IDs automatically, and/or override or set them on a per-request basis.
import JSONRPC from 'jsonrpc-ts-client'
import uuid from 'uuid'
// automatically generate IDs on each request
const client = new JSONRPC({
...
idGeneratorFn: uuid.v4,
})
// override your generated IDs at any time...
const response = await client.exec( 'my_method', { userId: 123 }, 'MY_OVERRIDING_ID');
// => {jsonrpc: '2.0', id: 'MY_OVERRIDING_ID', params: { userId: 123 } }
FAQs
A modern isomorphic typescript client for JSON-RPC 2.0
The npm package jsonrpc-ts-client receives a total of 28 weekly downloads. As such, jsonrpc-ts-client popularity was classified as not popular.
We found that jsonrpc-ts-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.