@rpcbase/server 0.55.0 → 0.58.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}
@@ -257,7 +257,7 @@ loglevel notice
257
257
  # Specify the log file name. Also the empty string can be used to force
258
258
  # Redis to log on the standard output. Note that if you use standard
259
259
  # output for logging but daemonize, logs will be sent to /dev/null
260
- logfile "logfile "/var/log/redis/logs.txt""
260
+ logfile "/var/log/redis/logs.txt"
261
261
 
262
262
  # To enable logging to the system logger, just set 'syslog-enabled' to yes,
263
263
  # and optionally update the other syslog parameters to suit your needs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.55.0",
3
+ "version": "0.58.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 0"
11
11
  },
12
12
  "dependencies": {
13
- "@rpcbase/agent": "0.2.0",
13
+ "@rpcbase/agent": "0.4.0",
14
14
  "body-parser": "1.20.0",
15
15
  "connect-redis": "6.1.3",
16
16
  "cors": "2.8.5",
@@ -20,7 +20,7 @@
20
20
  "express-session": "1.17.3",
21
21
  "glob": "8.0.3",
22
22
  "mongoose": "6.3.4",
23
- "postmark": "3.0.1",
23
+ "postmark": "3.0.11",
24
24
  "redis": "4.1.0",
25
25
  "validator": "13.7.0",
26
26
  "yargs": "17.5.1"
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
  })