@rpcbase/server 0.98.0 → 0.100.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.
package/cli/run_native.js CHANGED
@@ -11,6 +11,8 @@ const mkdirp = require("mkdirp")
11
11
  // TODO: verify mongod and redis-sever and elasticsearch executables are present
12
12
  // and have the right version
13
13
 
14
+ const is_production = process.env.NODE_ENV === "production"
15
+
14
16
  const NO_PRINT_LIST = [
15
17
  // "database",
16
18
  ]
@@ -119,6 +121,10 @@ const init_processes = (args) => {
119
121
  "-s",
120
122
  "-E", `path.logs=${logs_dir}`,
121
123
  "-E", `http.port=${env.SEARCH_INDEX_PORT}`,
124
+ ...(is_production ? [] : [
125
+ "-E", `http.cors.enabled=true`,
126
+ "-E", `http.cors.allow-origin=http://localhost:8080`,
127
+ ]),
122
128
  "-E", `path.data=${data_dir}`,
123
129
  "-E", "discovery.type=single-node",
124
130
  "-E", "ingest.geoip.downloader.enabled=false",
@@ -155,7 +161,7 @@ const run_native = (infrastructure_dir, proj_prefix, args) => {
155
161
  let prefix = ""
156
162
  // avoid printing [server] server:
157
163
  if (!args.verbose && item.name !== "server") {
158
- prefix = `${colors.green(item.name)}: `
164
+ prefix = `${colors.green(item.name)}:`
159
165
  }
160
166
 
161
167
  ps.stdout.on("data", (data) => {
@@ -5,14 +5,16 @@ const validator = require("validator")
5
5
  const {createClient} = require("redis")
6
6
  const redis_store = require("connect-redis")(session)
7
7
 
8
+
9
+ const {SESSION_STORE_PORT, CONTAINER_MODE} = process.env
10
+
8
11
  const log = debug("rb:session")
12
+ // log.useColors = true
9
13
 
10
14
  // WARNING:
11
15
  // https://stackoverflow.com/questions/70867229/error-connection-timeout-when-connecting-to-redis-docker-instance
12
16
  // https://github.com/redis/node-redis/issues/1656/
13
17
 
14
- const {SESSION_STORE_PORT, CONTAINER_MODE} = process.env
15
-
16
18
  if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PORT)) {
17
19
  throw new Error("expected SESSION_STORE_PORT to be a valid port number")
18
20
  }
package/mongoose/index.js CHANGED
@@ -1,8 +1,5 @@
1
1
  /* @flow */
2
2
  const mongoose = require("mongoose")
3
3
 
4
- // override register model method to keep track of all registered models
5
- // console.log("MONGOOSE", mongoose)
6
-
7
4
 
8
5
  module.exports = mongoose
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.98.0",
3
+ "version": "0.100.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/queue/index.js CHANGED
@@ -69,6 +69,10 @@ const get_instance = () => {
69
69
  return worker_queue
70
70
  }
71
71
 
72
+ // TMP used to create additional queues, should be implemented with a better API in the future
73
+ const get_url = () => {
74
+ return worker_queue_url
75
+ }
72
76
 
73
77
  module.exports = {
74
78
  start: start_worker,
@@ -76,4 +80,5 @@ module.exports = {
76
80
  get_tasks,
77
81
  add: worker_add,
78
82
  instance: get_instance,
83
+ get_url,
79
84
  }
@@ -1,8 +1,10 @@
1
1
  /* @flow */
2
2
  const debug = require("debug")
3
3
 
4
+ const User = require("../models/User")
4
5
 
5
6
  const log = debug("rb:auth:check_session")
7
+ log.useColors = true
6
8
 
7
9
 
8
10
  const check_session = async(payload, ctx) => {
@@ -10,14 +12,23 @@ const check_session = async(payload, ctx) => {
10
12
 
11
13
  log("session:", req.session)
12
14
 
13
- const is_signed_in = !!req.session.user_id
15
+ let is_signed_in = !!req.session.user_id
14
16
 
15
17
  log("is_signed_in:", is_signed_in)
16
18
 
19
+ // check if user exists
20
+ const user = await User.findOne({_id: req.session.user_id}, {_id: 1})
21
+ if (!user) {
22
+ is_signed_in = false
23
+ req.session.destroy(/* TODO: this should take callback */)
24
+ }
25
+
26
+ // TODO: check if user is disabled or blocked
27
+
17
28
  return {
18
29
  status: "ok",
19
30
  is_signed_in,
20
- user_id: req.session.user_id,
31
+ user_id: req.session?.user_id,
21
32
  }
22
33
  }
23
34
 
@@ -6,6 +6,9 @@ const User = mongoose.model("User", {
6
6
  type: String,
7
7
  default: "",
8
8
  },
9
+ avatar_url: {
10
+ type: String,
11
+ },
9
12
  email: String,
10
13
  is_email_verified: {
11
14
  type: Boolean,