@rpcbase/server 0.56.0 → 0.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ admin middleware that exposes models, schemas etc
package/admin/index.js ADDED
@@ -0,0 +1,43 @@
1
+ // /* @flow */
2
+ // const fs = require("fs")
3
+ // const path = require("path")
4
+ // const glob = require("glob")
5
+ // const debug = require("debug")
6
+ //
7
+ // const src_path = path.join(process.cwd(), "./src/")
8
+ // const build_dir = path.join(process.cwd(), "build/")
9
+ //
10
+ //
11
+ // const async_wrapper = fn => (req, res, next) => {
12
+ // Promise.resolve(fn(req, res, next))
13
+ // .catch(next)
14
+ // }
15
+ //
16
+ //
17
+ // const rpc_router = (app) => {
18
+ // const rpc_routes = glob.sync(path.join(build_dir, "./rpc/*"))
19
+ //
20
+ // rpc_routes.forEach((file_path) => {
21
+ // const basename = path.basename(file_path)
22
+ // const route_path = basename.replace(/__slash__/g, "/")
23
+ // const module_path = path.join(src_path, `${route_path}.js`)
24
+ //
25
+ // // if module not found, remove created route file
26
+ // if (!fs.existsSync(module_path)) {
27
+ // fs.unlinkSync(file_path)
28
+ // console.log("removed inexistant rpc route", basename, "with module path", module_path)
29
+ // }
30
+ //
31
+ // const rpc_fn = require(module_path)
32
+ // app.post(`/rpc/${route_path}`, async_wrapper(async(req, res) => {
33
+ //
34
+ // console.log(`POST /rpc/${route_path}`)
35
+ // // TODO: add jaegerclient / opentelemetry
36
+ // const result = await rpc_fn(req.body, {req})
37
+ // res.json(result)
38
+ // }))
39
+ // })
40
+ //
41
+ // }
42
+ //
43
+ // module.exports = rpc_router
@@ -0,0 +1,45 @@
1
+ /* @flow */
2
+ const crypto = require("crypto")
3
+
4
+ const ALGORITHM = "aes-256-cbc"
5
+ const {CRYPTO_SECRET} = process.env
6
+
7
+ if (!CRYPTO_SECRET || CRYPTO_SECRET === "") {
8
+ throw new Error("CRYPTO_SECRET not found in env")
9
+ }
10
+
11
+ const key = crypto.createHash("sha256")
12
+ .update(String(CRYPTO_SECRET))
13
+ .digest()
14
+
15
+
16
+ const encrypt = (text) => {
17
+ const iv = crypto.randomBytes(16)
18
+ const cipher = crypto.createCipheriv(ALGORITHM, key, iv)
19
+
20
+ const encrypted = Buffer.concat([
21
+ cipher.update(text),
22
+ cipher.final()
23
+ ])
24
+
25
+ return {
26
+ iv: iv.toString("hex"),
27
+ content: encrypted.toString("hex")
28
+ }
29
+ }
30
+
31
+ const decrypt = (hash) => {
32
+ const decipher = crypto.createDecipheriv(
33
+ ALGORITHM, key, Buffer.from(hash.iv, "hex")
34
+ )
35
+
36
+ const decrpyted = Buffer.concat([
37
+ decipher.update(Buffer.from(hash.content, "hex")),
38
+ decipher.final(),
39
+ ])
40
+
41
+ return decrpyted.toString()
42
+ }
43
+
44
+
45
+ module.exports = {encrypt, decrypt}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.56.0",
3
+ "version": "0.57.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/rpc/rpc_router.js CHANGED
@@ -30,11 +30,10 @@ const rpc_router = (app) => {
30
30
 
31
31
  const rpc_fn = require(module_path)
32
32
  app.post(`/rpc/${route_path}`, async_wrapper(async(req, res) => {
33
- // console.log("GOT REQ", req.body)
33
+
34
34
  console.log(`POST /rpc/${route_path}`)
35
35
  // TODO: add jaegerclient / opentelemetry
36
36
  const result = await rpc_fn(req.body, {req})
37
-
38
37
  res.json(result)
39
38
  }))
40
39
  })