@rpcbase/server 0.284.0 → 0.285.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 +0 -2
- package/package.json +1 -1
- package/queue/index.js +6 -6
- package/src/auth/get_account.js +36 -0
- package/src/auth/get_accounts.js +42 -0
- package/src/auth/index.js +11 -29
- package/src/helpers/handler_wrapper.js +11 -0
package/cli/run_native.js
CHANGED
|
@@ -42,8 +42,6 @@ const get_processes = (args) => {
|
|
|
42
42
|
const worker_queue_dir = path.join(process.cwd(), "../infrastructure/data/worker-queue/data")
|
|
43
43
|
const worker_queue_logs_path = path.join(process.cwd(), "../infrastructure/data/worker-queue/log/logs.txt")
|
|
44
44
|
|
|
45
|
-
// console.log("WORKER QUEUE ON PORT", env.WORKER_QUEUE_PORT)
|
|
46
|
-
|
|
47
45
|
// TODO: add a redis cache
|
|
48
46
|
const processes = [
|
|
49
47
|
// web server
|
package/package.json
CHANGED
package/queue/index.js
CHANGED
|
@@ -9,26 +9,26 @@ const hostname = is_docker() ? "worker-queue" : "127.0.0.1"
|
|
|
9
9
|
|
|
10
10
|
const worker_queue_url = `redis://${hostname}:${WORKER_QUEUE_PORT}`
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// TODO: implement latency queues
|
|
13
|
+
const QUEUE_DEFAULT_NAME = "rb-queue-default"
|
|
14
|
+
// const QUEUE_10S_NAME
|
|
13
15
|
|
|
14
16
|
const tasks_list = Object.create(null)
|
|
15
17
|
|
|
16
18
|
let worker_queue
|
|
17
19
|
|
|
18
20
|
const get_instance = () => {
|
|
19
|
-
if (!worker_queue) worker_queue = new Queue(
|
|
21
|
+
if (!worker_queue) worker_queue = new Queue(QUEUE_DEFAULT_NAME, worker_queue_url)
|
|
20
22
|
return worker_queue
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
const worker_add = async(task_name, payload, options) => {
|
|
25
27
|
if (!worker_queue) {
|
|
26
|
-
worker_queue = new Queue(
|
|
28
|
+
worker_queue = new Queue(QUEUE_DEFAULT_NAME, worker_queue_url)
|
|
27
29
|
}
|
|
28
30
|
const res = await worker_queue.add({task_name, payload}, options)
|
|
29
31
|
console.log("worker_add:created task:", task_name, res.id)
|
|
30
|
-
// console.log(payload)
|
|
31
|
-
// console.log("\n")
|
|
32
32
|
return res
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -52,7 +52,7 @@ const get_tasks = () => tasks_list
|
|
|
52
52
|
const start_worker = async() => {
|
|
53
53
|
console.log("start worker queue", worker_queue_url)
|
|
54
54
|
|
|
55
|
-
worker_queue = new Queue(
|
|
55
|
+
worker_queue = new Queue(QUEUE_DEFAULT_NAME, worker_queue_url)
|
|
56
56
|
|
|
57
57
|
// error handler
|
|
58
58
|
worker_queue.on("error", (err) => {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const assert = require("assert")
|
|
3
|
+
|
|
4
|
+
const mongoose = require("../../mongoose")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const get_account = async(payload, ctx) => {
|
|
8
|
+
const {user_id} = payload
|
|
9
|
+
assert(user_id, "missing user_id")
|
|
10
|
+
|
|
11
|
+
const User = mongoose.model("User")
|
|
12
|
+
|
|
13
|
+
// verify we are only requesting our own account's info
|
|
14
|
+
const session_user_id = ctx.req.session.user_id
|
|
15
|
+
assert(user_id === session_user_id, "user ids don't match")
|
|
16
|
+
|
|
17
|
+
const user = await User.findOne(
|
|
18
|
+
{_id: user_id},
|
|
19
|
+
{
|
|
20
|
+
email: 1,
|
|
21
|
+
first_name: 1,
|
|
22
|
+
last_name: 1,
|
|
23
|
+
initials: 1,
|
|
24
|
+
avatar_color: 1,
|
|
25
|
+
},
|
|
26
|
+
{ctx},
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
status: "ok",
|
|
31
|
+
// when user has been deleted return null, this case shouldn't really happen though
|
|
32
|
+
user: user?.toObject() || null,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = get_account
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const Promise = require("bluebird")
|
|
3
|
+
|
|
4
|
+
const get_account = require("./get_account")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const is_dev = process.env.NODE_ENV === "development"
|
|
8
|
+
|
|
9
|
+
// TODO: RM this method when live reload works in dev mode behind the reverse proxy
|
|
10
|
+
const MAX_CONCURRENCY = 256
|
|
11
|
+
|
|
12
|
+
const get_accounts = async(payload, ctx) => {
|
|
13
|
+
if (!is_dev)
|
|
14
|
+
throw new Error(
|
|
15
|
+
"cannot call the get_accounts api when NODE_ENV isn't development, this api must be called through the reverse proxy",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const user_ids = [ctx.req.session.user_id, ctx.req.session.user_id, ctx.req.session.user_id]
|
|
19
|
+
|
|
20
|
+
const accounts = await Promise.map(
|
|
21
|
+
user_ids,
|
|
22
|
+
async(user_id) => {
|
|
23
|
+
if (!user_id) return null
|
|
24
|
+
const res = await get_account({user_id}, ctx)
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
user: res.user,
|
|
28
|
+
tenant: {
|
|
29
|
+
name: "MOCK",
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{concurrency: MAX_CONCURRENCY},
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
status: "ok",
|
|
38
|
+
accounts: accounts.filter((account) => !!account),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = get_accounts
|
package/src/auth/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const async_wrapper = require("../helpers/async_wrapper")
|
|
3
|
+
const handler_wrapper = require("../helpers/handler_wrapper")
|
|
3
4
|
|
|
4
5
|
const sign_up = require("./sign_up")
|
|
5
6
|
const sign_in = require("./sign_in")
|
|
@@ -8,38 +9,19 @@ const reset_password = require("./reset_password")
|
|
|
8
9
|
const set_new_password = require("./set_new_password")
|
|
9
10
|
const check_session = require("./check_session")
|
|
10
11
|
|
|
12
|
+
const get_accounts = require("./get_accounts")
|
|
13
|
+
const get_account = require("./get_account")
|
|
11
14
|
|
|
12
|
-
const sign_in_handler = async(req, res) => {
|
|
13
|
-
const result = await sign_in(req.body, {req, res})
|
|
14
|
-
res.json(result)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const sign_out_handler = async(req, res) => {
|
|
18
|
-
const result = await sign_out(req.body, {req, res})
|
|
19
|
-
res.json(result)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const reset_password_handler = async(req, res) => {
|
|
23
|
-
const result = await reset_password(req.body, {req, res})
|
|
24
|
-
res.json(result)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const set_new_password_handler = async(req, res) => {
|
|
28
|
-
const result = await set_new_password(req.body, {req, res})
|
|
29
|
-
res.json(result)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const check_session_handler = async(req, res) => {
|
|
33
|
-
const result = await check_session(req.body, {req, res})
|
|
34
|
-
res.json(result)
|
|
35
|
-
}
|
|
36
15
|
|
|
37
16
|
module.exports = (app) => {
|
|
38
|
-
app.post("/api/v1/auth/sign_in",
|
|
39
|
-
app.post("/api/v1/auth/sign_out",
|
|
17
|
+
app.post("/api/v1/auth/sign_in", handler_wrapper(sign_in))
|
|
18
|
+
app.post("/api/v1/auth/sign_out", handler_wrapper(sign_out))
|
|
19
|
+
|
|
20
|
+
app.post("/api/v1/auth/reset_password", handler_wrapper(reset_password))
|
|
21
|
+
app.post("/api/v1/auth/set_new_password", handler_wrapper(set_new_password))
|
|
40
22
|
|
|
41
|
-
app.post("/api/v1/auth/
|
|
42
|
-
app.post("/api/v1/auth/set_new_password", async_wrapper(set_new_password_handler))
|
|
23
|
+
app.post("/api/v1/auth/check_session", handler_wrapper(check_session))
|
|
43
24
|
|
|
44
|
-
app.post("/api/v1/auth/
|
|
25
|
+
app.post("/api/v1/auth/get_account", handler_wrapper(get_account))
|
|
26
|
+
app.post("/api/v1/auth/get_accounts", handler_wrapper(get_accounts))
|
|
45
27
|
}
|