@heathmont/lab-flask
Advanced tools
Comparing version 0.1.33 to 0.2.0
@@ -58,14 +58,16 @@ "use strict"; | ||
exports.getContextFromQueryString = (context, actKindEnum) => { | ||
const contextProto = coingaming_protobuf_1.Proto.Global.Context.decode(Buffer.from(context)); | ||
const contextProto = coingaming_protobuf_1.Proto.Global.Context.decode(Buffer.from(context, 'base64')); | ||
let targetFlaskName; | ||
switch (actKindEnum) { | ||
case coingaming_protobuf_1.Proto.Global.ActKind.ELEMENT: | ||
targetFlaskName = contextProto.flask.element.targetFlaskName.value; | ||
targetFlaskName = contextProto.flask.element.targetFlaskName ? | ||
contextProto.flask.element.targetFlaskName.value : undefined; | ||
break; | ||
case coingaming_protobuf_1.Proto.Global.ActKind.REACTION: | ||
targetFlaskName = contextProto.flask.reaction.targetFlaskName.value; | ||
targetFlaskName = contextProto.flask.reaction.targetFlaskName ? | ||
contextProto.flask.reaction.targetFlaskName.value : undefined; | ||
break; | ||
} | ||
return { | ||
siteId: parseInt(contextProto.flask.siteId.value.toString(), 10), | ||
siteId: contextProto.flask.siteId ? parseInt(contextProto.flask.siteId.value.toString(), 10) : undefined, | ||
sourceFlaskName: contextProto.flask.sourceFlaskName, | ||
@@ -72,0 +74,0 @@ targetFlaskName, |
@@ -6,3 +6,2 @@ "use strict"; | ||
const node_logger_1 = require("@heathmont/node-logger"); | ||
const _1 = require("./"); | ||
const bindImplementations = (labConfig, substance, actKindEnum, implementations) => { | ||
@@ -14,3 +13,8 @@ const { expressServer } = labConfig; | ||
const implementation = implementations[actEnumInt]; | ||
expressServer.post(`${labConfig.flaskPathname}/${_1.PROTOBUF_URL_PREFIX}/${actPath}`, async (req, res) => { | ||
node_logger_1.logger.debug(`Attaching binding ${labConfig.flaskPathnameProto}/${actPath} with async function`); | ||
expressServer.post(`${labConfig.flaskPathnameProto}/${actPath}`, async (req, res) => { | ||
node_logger_1.logger.debug('Handling POST for url', { url: `${labConfig.flaskPathnameProto}/${actPath}`, | ||
body: req.body, | ||
queryC: req.query.c, | ||
}); | ||
const isSignatureValid = labConfig.hmCrypto.isValid(req.body, req.headers['x-lab-signature']); | ||
@@ -17,0 +21,0 @@ const context = createUrls_1.getContextFromQueryString(req.query.c, actKindEnum); |
@@ -30,2 +30,3 @@ import 'source-map-support/register'; | ||
flaskPathname: string; | ||
flaskPathnameProto: string; | ||
defaultContext: Partial<LabContext>; | ||
@@ -32,0 +33,0 @@ } |
@@ -21,2 +21,3 @@ "use strict"; | ||
const bigNumberToString_1 = require("./bigNumberToString"); | ||
const path = require("path"); | ||
exports.PROTOBUF_URL_PREFIX = 'protobuf'; | ||
@@ -41,2 +42,3 @@ exports.implementFlaskMeta = (metaFunction) => { | ||
const { pathname: flaskPathname } = new url_1.URL(flaskUrl); | ||
const flaskPathnameProto = path.join(flaskPathname, exports.PROTOBUF_URL_PREFIX); | ||
const labConfig = { | ||
@@ -51,2 +53,3 @@ flaskName, | ||
flaskPathname, | ||
flaskPathnameProto, | ||
hmCrypto: HmCrypto('RSA-SHA256', flaskPrivKey, options.labPubKey), | ||
@@ -57,7 +60,8 @@ defaultContext, | ||
if (expressServer) { | ||
expressServer.post(`${flaskPathname}/${exports.PROTOBUF_URL_PREFIX}`, (req, res, next) => { | ||
node_logger_1.logger.debug('Lab request incoming', { reqHeaders: req.headers, bodyLength: req.body.length }); | ||
expressServer.post(`${flaskPathnameProto}*`, (req, res, next) => { | ||
node_logger_1.logger.debug('Lab request incoming', { reqHeaders: req.headers }); | ||
next(); | ||
}); | ||
expressServer.post(`${flaskPathname}/${exports.PROTOBUF_URL_PREFIX}`, bodyParser.raw({ | ||
node_logger_1.logger.debug('Adding body parser for path', { path: flaskPathnameProto }); | ||
expressServer.post(`${flaskPathnameProto}*`, bodyParser.raw({ | ||
type: 'application/*', | ||
@@ -64,0 +68,0 @@ limit: '10mb', |
{ | ||
"name": "@heathmont/lab-flask", | ||
"version": "0.1.33", | ||
"version": "0.2.0", | ||
"author": "Margus Lamp", | ||
@@ -46,2 +46,3 @@ "main": "./dist/index.js", | ||
"compile": "tsc -p ./", | ||
"compile:watch": "tsc -p ./ --watch", | ||
"lint": "tslint -p ./ \"src/**/*.ts\"", | ||
@@ -48,0 +49,0 @@ "test": "jest", |
@@ -74,14 +74,16 @@ import { LabConfig, LabContext } from './index'; | ||
export const getContextFromQueryString = (context: string, actKindEnum: Proto.Global.ActKind): Context => { | ||
const contextProto = Proto.Global.Context.decode(Buffer.from(context)); | ||
const contextProto = Proto.Global.Context.decode(Buffer.from(context, 'base64')); | ||
let targetFlaskName: string; | ||
switch (actKindEnum) { | ||
case Proto.Global.ActKind.ELEMENT: | ||
targetFlaskName = contextProto.flask.element.targetFlaskName.value; | ||
targetFlaskName = contextProto.flask.element.targetFlaskName ? | ||
contextProto.flask.element.targetFlaskName.value : undefined; | ||
break; | ||
case Proto.Global.ActKind.REACTION: | ||
targetFlaskName = contextProto.flask.reaction.targetFlaskName.value; | ||
targetFlaskName = contextProto.flask.reaction.targetFlaskName ? | ||
contextProto.flask.reaction.targetFlaskName.value : undefined; | ||
break; | ||
} | ||
return { | ||
siteId: parseInt(contextProto.flask.siteId.value.toString(), 10), | ||
siteId: contextProto.flask.siteId ? parseInt(contextProto.flask.siteId.value.toString(), 10) : undefined, | ||
sourceFlaskName: contextProto.flask.sourceFlaskName, | ||
@@ -88,0 +90,0 @@ targetFlaskName, |
@@ -5,3 +5,3 @@ import { Proto } from '@heathmont/coingaming-protobuf'; | ||
import { logger } from '@heathmont/node-logger'; | ||
import { LabConfig, PROTOBUF_URL_PREFIX } from './'; | ||
import { LabConfig } from './'; | ||
import express = require('express'); | ||
@@ -19,3 +19,8 @@ | ||
const implementation = implementations[actEnumInt]; | ||
expressServer.post(`${labConfig.flaskPathname}/${PROTOBUF_URL_PREFIX}/${actPath}`, async (req: express.Request, res) => { | ||
logger.debug(`Attaching binding ${labConfig.flaskPathnameProto}/${actPath} with async function`); | ||
expressServer.post(`${labConfig.flaskPathnameProto}/${actPath}`, async (req: express.Request, res) => { | ||
logger.debug('Handling POST for url', { url: `${labConfig.flaskPathnameProto}/${actPath}`, | ||
body: req.body, | ||
queryC: req.query.c, | ||
}); | ||
const isSignatureValid = labConfig.hmCrypto.isValid(req.body, req.headers['x-lab-signature']); | ||
@@ -22,0 +27,0 @@ const context: Context = getContextFromQueryString(req.query.c, actKindEnum); |
@@ -21,2 +21,3 @@ import 'source-map-support/register'; | ||
import { bigNumberToString } from './bigNumberToString'; | ||
import * as path from 'path'; | ||
@@ -52,2 +53,3 @@ export const PROTOBUF_URL_PREFIX = 'protobuf'; | ||
flaskPathname: string; | ||
flaskPathnameProto: string; | ||
defaultContext: Partial<LabContext>; | ||
@@ -111,2 +113,3 @@ } | ||
const { pathname: flaskPathname } = new URL(flaskUrl); | ||
const flaskPathnameProto = path.join(flaskPathname, PROTOBUF_URL_PREFIX); | ||
const labConfig: LabConfig = { | ||
@@ -121,2 +124,3 @@ flaskName, | ||
flaskPathname, | ||
flaskPathnameProto, | ||
hmCrypto: HmCrypto('RSA-SHA256', flaskPrivKey, options.labPubKey), | ||
@@ -127,7 +131,9 @@ defaultContext, | ||
if (expressServer) { | ||
expressServer.post(`${flaskPathname}/${PROTOBUF_URL_PREFIX}`, (req, res, next) => { | ||
logger.debug('Lab request incoming', { reqHeaders: req.headers, bodyLength: req.body.length }); | ||
expressServer.post(`${flaskPathnameProto}*`, (req, res, next) => { | ||
logger.debug('Lab request incoming', { reqHeaders: req.headers }); | ||
next(); | ||
}); | ||
expressServer.post(`${flaskPathname}/${PROTOBUF_URL_PREFIX}`, bodyParser.raw({ | ||
logger.debug('Adding body parser for path', { path: flaskPathnameProto }); | ||
expressServer.post(`${flaskPathnameProto}*`, bodyParser.raw({ | ||
type: 'application/*', | ||
@@ -134,0 +140,0 @@ limit: '10mb', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
101673
1838