Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bifot/json-rpc

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bifot/json-rpc - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

src/helpers/buildOptions.js

5

package.json
{
"name": "@bifot/json-rpc",
"version": "1.2.0",
"version": "1.3.0",
"description": "Solution for communication between services using HTTP protocol via JSON RPC. 🔬",

@@ -20,3 +20,4 @@ "main": "src/index.js",

"dependencies": {
"axios": "^0.19.0",
"axios": "^0.18.0",
"axios-retry": "^3.1.2",
"co-body": "^6.0.0",

@@ -23,0 +24,0 @@ "http-assert": "^1.4.1"

3

README.md

@@ -54,2 +54,5 @@ # @bifot/json-rpc

id: 10,
}, {
retries: 5,
retryDelay: 500,
});

@@ -56,0 +59,0 @@

const axios = require('axios');
const enableRetries = require('axios-retry');
const { buildOptions } = require('./helpers');
enableRetries(axios, {
retries: 0,
});
class Client {

@@ -17,6 +23,17 @@ constructor(options) {

async ask(name, params, options) {
mock(responses) {
this.responses = responses;
return this;
}
async ask(name, params = {}, options = {}) {
const [service, method] = name.split('.');
const url = this.services.get(service);
const mock = this.responses && this.responses[service] && this.responses[service][method];
if (mock) {
return typeof mock === 'function' ? mock(params) : mock;
}
if (!url) {

@@ -32,3 +49,3 @@ throw new Error('Service is not found');

id: params.params && params.id,
}, options);
}, buildOptions(options));

@@ -35,0 +52,0 @@ return {

const formatResponse = require('./formatResponse');
const buildOptions = require('./buildOptions');
module.exports = {
formatResponse,
buildOptions,
};
const { expect } = require('chai');
const { Client } = require('../src');
const server = require('../examples/server');
require('../examples/server');
describe('api', () => {

@@ -45,4 +44,49 @@ let client;

result: undefined,
})
});
});
it('should get response after retries', async () => {
server.close();
setTimeout(() => {
server.listen(process.env.APP_PORT);
}, 1000);
const user = await client.ask('users.get', {
age: 10,
}, {
retries: 5,
retryDelay: 500,
});
expect(user).to.be.deep.equal({
error: {
code: 400,
message: 'Invalid age',
},
result: undefined,
});
});
it('should get mock response', async () => {
const response = {
error: {
code: 500,
message: 'Server error',
},
result: undefined,
};
server.close();
client.mock({
users: {
get: response,
},
});
const user = await client.ask('users.get');
expect(user).to.be.deep.equal(response);
});
});
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