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

chayen

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chayen - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

30

dist/makeRequest.js

@@ -12,29 +12,17 @@ "use strict";

const axios_1 = require("axios");
const Boom = require("boom");
const _ = require("lodash");
function makeRequest(topic, payload, target) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield axios_1.default.post(target, {
topic,
payload
});
return response.data.payload;
}
catch (err) {
if (err.response && err.response.data) {
const errData = err.response.data;
const boomError = _.get(errData, 'output.payload');
if (boomError) {
throw boomError;
}
else {
throw new Error(errData.message);
}
return axios_1.default.post(target, { topic, payload })
.then(response => response.data.payload)
.catch(err => {
const errData = _.get(err, 'response.data');
if (errData) {
throw Boom.create(_.get(errData, 'output.statusCode'), _.get(errData, 'output.payload.message'));
}
else {
throw err;
}
}
throw err;
});
});
}
exports.default = makeRequest;

@@ -21,2 +21,3 @@ /// <reference types="node" />

private app;
private router;
private redis;

@@ -23,0 +24,0 @@ private port;

@@ -12,7 +12,8 @@ "use strict";

const Bluebird = require("bluebird");
const bodyParser = require("body-parser");
const Boom = require("boom");
const express = require("express");
const Redis = require("ioredis");
const Joi = require("joi");
const Koa = require("koa");
const bodyParser = require("koa-bodyparser");
const Router = require("koa-router");
const hash = require("object-hash");

@@ -23,15 +24,19 @@ const makeRequest_1 = require("./makeRequest");

constructor(configs = {}) {
this.app = express();
this.app.use(bodyParser.json());
this.app.post('/rpc', (req, res) => __awaiter(this, void 0, void 0, function* () {
this.app = new Koa();
this.app.use(bodyParser({
enableTypes: ['json']
}));
this.router = new Router();
this.router.post('/rpc', (ctx) => __awaiter(this, void 0, void 0, function* () {
try {
const result = yield this.executeEndpoint(req.body.topic, req.body.payload);
res.json({ payload: result });
const result = yield this.executeEndpoint(ctx.request.body.topic, ctx.request.body.payload);
ctx.body = { payload: result };
}
catch (err) {
const boomError = Boom.boomify(err, { override: false });
res.status(boomError.output.statusCode);
res.send(boomError);
ctx.status = boomError.output.statusCode;
ctx.body = boomError;
}
}));
this.app.use(this.router.routes());
if (configs.redisUrl) {

@@ -38,0 +43,0 @@ this.redis = new Redis(configs.redisUrl);

{
"name": "chayen",
"version": "0.1.3",
"version": "0.1.4",
"description": "An RPC framework with so much hype going on. such wow.",

@@ -40,5 +40,7 @@ "main": "dist/index.js",

"boom": "^6.0.0",
"express": "^4.16.1",
"ioredis": "^3.1.4",
"joi": "^11.1.1",
"koa": "^2.3.0",
"koa-bodyparser": "^4.2.0",
"koa-router": "^7.2.1",
"lodash": "^4.17.4",

@@ -50,6 +52,8 @@ "object-hash": "^1.1.8"

"@types/boom": "^4.3.7",
"@types/express": "^4.0.37",
"@types/ioredis": "^0.0.25",
"@types/jest": "^21.1.1",
"@types/joi": "^10.4.3",
"@types/koa": "^2.0.39",
"@types/koa-bodyparser": "^3.0.25",
"@types/koa-router": "^7.0.23",
"@types/lodash": "^4.14.76",

@@ -56,0 +60,0 @@ "@types/object-hash": "^0.5.29",

Sorry, the diff of this file is not supported yet

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