@heathmont/lab-flask
Advanced tools
Comparing version 2.9.12 to 2.9.13
@@ -26,3 +26,11 @@ const createLabError = (type = 'BUSINESS_LOGIC', errors = []) => { | ||
}; | ||
const handleInternalError = (e) => { | ||
const error = createLabError('INTERNAL'); | ||
if (e.message) | ||
addParameterError(error, 'message', e.message); | ||
if (e.stack) | ||
addParameterError(error, 'stack', e.stack); | ||
return error; | ||
}; | ||
export { addParameterError, createLabError, createParameterError, handleLabError }; | ||
export { addParameterError, createLabError, createParameterError, handleInternalError, handleLabError }; |
@@ -39,3 +39,3 @@ import { createSubstanceActUrl, getContextFromQueryString } from './createUrls.js'; | ||
}; | ||
const privateImplemenSubstance = (labConfig, substance, implementations) => { | ||
function privateImplemenSubstance(labConfig, substance, implementations) { | ||
if (implementations.element) { | ||
@@ -47,4 +47,30 @@ bindImplementations(labConfig, substance, 'ELEMENT', implementations.element); | ||
} | ||
} | ||
; | ||
function implement(requestClass, processor) { | ||
return async (reqData, context, rawReq) => { | ||
let req; | ||
try { | ||
req = decodeRequestBody(requestClass, reqData); | ||
} | ||
catch (e) { | ||
logger.error('Error decoding body', { reqBodyLength: rawReq.body.toString().length }); | ||
throw e; | ||
} | ||
return await processor(req, context, rawReq); | ||
}; | ||
} | ||
; | ||
const decodeRequestBody = (requestClass, reqData) => { | ||
let req; | ||
try { | ||
req = requestClass.fromBinary(reqData); | ||
} | ||
catch (e) { | ||
logger.error('Failed to decode request', { reqData }); | ||
throw e; | ||
} | ||
return req; | ||
}; | ||
export { privateImplemenSubstance }; | ||
export { implement, privateImplemenSubstance }; |
import typescriptPlugin from '@rollup/plugin-typescript'; | ||
import dtsPlugin from 'rollup-plugin-dts'; | ||
import modify from 'rollup-plugin-modify'; | ||
// import modify from 'rollup-plugin-modify' | ||
// import { globSync } from 'glob' | ||
@@ -42,6 +42,6 @@ // import path from 'path' | ||
// } | ||
const replaceProtobufImports = modify({ | ||
find: /'@heathmont\/coingaming-protobuf\/((lab_protobuf|coingaming_protobuf)\/.*)'/, | ||
replace: (match, path) => `'@heathmont/coingaming-protobuf/dist/cjs/${path}.js'` | ||
}); | ||
// const replaceProtobufImports = modify({ | ||
// find: /'@heathmont\/coingaming-protobuf\/((lab_protobuf|coingaming_protobuf)\/.*)'/, | ||
// replace: (match, path) => `'@heathmont/coingaming-protobuf/dist/cjs/${path}.js'` | ||
// }) | ||
const config = [ | ||
@@ -51,2 +51,3 @@ { | ||
plugins: [typescriptPlugin()], | ||
treeshake: false, | ||
output: [ | ||
@@ -64,2 +65,3 @@ { | ||
plugins: [typescriptPlugin()], | ||
treeshake: false, | ||
output: [ | ||
@@ -77,2 +79,3 @@ { | ||
plugins: [typescriptPlugin(), dtsPlugin()], | ||
treeshake: false, | ||
output: [ | ||
@@ -79,0 +82,0 @@ { |
@@ -8,4 +8,6 @@ /// <reference types="node" /> | ||
import express from 'express'; | ||
export declare const privateImplemenSubstance: (labConfig: LabConfig, substance: string, implementations: Implementations) => void; | ||
export declare const implement: <REQ extends Message<REQ>, RES extends Message<RES>>(requestClass: new () => REQ, processor: (req: REQ, context: Context, rawReq: express.Request) => RES | Promise<RES>) => (reqData: Buffer, context: Context, rawReq: express.Request) => Promise<RES>; | ||
export declare function privateImplemenSubstance(labConfig: LabConfig, substance: string, implementations: Implementations): void; | ||
export declare function implement<REQ extends Message<REQ>, RES extends Message<RES>>(requestClass: { | ||
new (): REQ; | ||
}, processor: (req: REQ, context: Context, rawReq: express.Request) => RES | Promise<RES>): (reqData: Buffer, context: Context, rawReq: express.Request) => Promise<RES>; | ||
export interface ReactionImplementations { | ||
@@ -12,0 +14,0 @@ [reactionEnum: string]: (reqDataR: Buffer, context: Context, rawReq: express.Request) => any; |
@@ -38,3 +38,3 @@ import { createSubstanceActUrl, getContextFromQueryString } from './createUrls'; | ||
}; | ||
export const privateImplemenSubstance = (labConfig, substance, implementations) => { | ||
export function privateImplemenSubstance(labConfig, substance, implementations) { | ||
if (implementations.element) { | ||
@@ -46,4 +46,5 @@ bindImplementations(labConfig, substance, 'ELEMENT', implementations.element); | ||
} | ||
}; | ||
export const implement = (requestClass, processor) => { | ||
} | ||
; | ||
export function implement(requestClass, processor) { | ||
return async (reqData, context, rawReq) => { | ||
@@ -60,3 +61,4 @@ let req; | ||
}; | ||
}; | ||
} | ||
; | ||
const decodeRequestBody = (requestClass, reqData) => { | ||
@@ -63,0 +65,0 @@ let req; |
{ | ||
"name": "@heathmont/lab-flask", | ||
"version": "2.9.12", | ||
"version": "2.9.13", | ||
"author": "Margus Lamp", | ||
@@ -12,7 +12,9 @@ "type": "module", | ||
"import": "./dist/esm/index.js", | ||
"require": "./dist/cjs/index.cjs" | ||
"require": "./dist/cjs/index.cjs", | ||
"types": "./dist/src/index.d.ts" | ||
}, | ||
"./*": { | ||
"import": "./dist/esm/*.js", | ||
"require": "./dist/cjs/*.cjs" | ||
"require": "./dist/cjs/*.cjs", | ||
"types": "./dist/src/*.d.ts" | ||
} | ||
@@ -42,2 +44,5 @@ }, | ||
"@babel/preset-typescript": "^7.23.3", | ||
"@rollup/plugin-commonjs": "^28.0.2", | ||
"@rollup/plugin-json": "^6.1.0", | ||
"@rollup/plugin-node-resolve": "^16.0.0", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
@@ -57,2 +62,3 @@ "@rollup/plugin-typescript": "^11.1.6", | ||
"eslint-plugin-react": "^7.34.1", | ||
"glob": "^11.0.1", | ||
"globals": "^15.0.0", | ||
@@ -65,2 +71,3 @@ "husky": "^4.2.5", | ||
"rollup-plugin-dts": "^6.1.0", | ||
"rollup-plugin-modify": "^3.0.0", | ||
"semantic-release": "^23.0.2", | ||
@@ -70,5 +77,3 @@ "ts-jest": "~29.1", | ||
"typescript": "~5.2", | ||
"typescript-eslint": "^7.7.0", | ||
"rollup-plugin-modify": "^3.0.0", | ||
"glob": "^11.0.1" | ||
"typescript-eslint": "^7.7.0" | ||
}, | ||
@@ -75,0 +80,0 @@ "optionalDependencies": { |
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
Sorry, the diff of this file is not supported yet
101602
1823
33