@rpcbase/server 0.380.0 → 0.382.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/package.json +16 -72
- package/src/getDerivedKey.ts +20 -0
- package/src/hashPassword.ts +24 -0
- package/src/index.ts +3 -0
- package/src/initServer.ts +68 -0
- package/src/types/index.ts +7 -0
- package/src/types/session.d.ts +10 -0
- package/boot/server.js +0 -36
- package/boot/shared.js +0 -17
- package/boot/worker.js +0 -37
- package/constants/keys.ts +0 -1
- package/database.js +0 -96
- package/express/custom_cors.js +0 -80
- package/express/dev_save_coverage.js +0 -18
- package/express/index.js +0 -93
- package/express/setup_handlers.js +0 -49
- package/files.ts +0 -1
- package/firebase.js +0 -33
- package/get_object_id.ts +0 -39
- package/index.js +0 -17
- package/mailer/index.js +0 -31
- package/mongoose/index.ts +0 -16
- package/mongoose/plugins/disable_default_timestamps_plugin.ts +0 -5
- package/mongoose/plugins/disable_default_version_key_plugin.ts +0 -5
- package/mongoose/plugins/object_id_plugin.ts +0 -31
- package/openai.js +0 -10
- package/publish-output.txt +0 -0
- package/queue/dispatch_indexer_queue.js +0 -22
- package/queue/dispatch_worker_queue.js +0 -38
- package/queue/index.js +0 -110
- package/queue/register_queue_listener.js +0 -180
- package/redis.js +0 -2
- package/rts/index.js +0 -444
- package/search/constants.ts +0 -1
- package/search/ensure_index.ts +0 -53
- package/search/get_client.ts +0 -15
- package/search/index.ts +0 -3
- package/src/access-control/apply_policies.js +0 -104
- package/src/access-control/get_added_fields.js +0 -23
- package/src/access-control/get_policies.js +0 -29
- package/src/access-control/hooks/doc_pre_create.js +0 -26
- package/src/access-control/hooks/query_pre_delete.js +0 -30
- package/src/access-control/index.js +0 -6
- package/src/access-control/mongoose_plugin.js +0 -136
- package/src/api/index.js +0 -6
- package/src/api/stored-values/get_stored_values.js +0 -41
- package/src/api/stored-values/index.js +0 -8
- package/src/api/stored-values/set_stored_values.js +0 -31
- package/src/auth/check_session.js +0 -43
- package/src/auth/forgot_password_email.html +0 -515
- package/src/auth/get_account.js +0 -35
- package/src/auth/get_accounts.js +0 -42
- package/src/auth/index.js +0 -24
- package/src/auth/reset_password.js +0 -70
- package/src/auth/set_new_password.js +0 -63
- package/src/auth/set_new_password_email.html +0 -3
- package/src/auth/sign_in.js +0 -61
- package/src/auth/sign_out.js +0 -11
- package/src/auth/sign_up.js +0 -56
- package/src/client/client_router.js +0 -105
- package/src/files/constants.ts +0 -9
- package/src/files/finalize_file_upload.ts +0 -25
- package/src/files/helpers/get_grid_fs_bucket.ts +0 -20
- package/src/files/index.js +0 -5
- package/src/files/tasks/finalize_file_upload/apply_img_preview.ts +0 -49
- package/src/files/tasks/finalize_file_upload/constants.ts +0 -23
- package/src/files/tasks/finalize_file_upload/download_file.ts +0 -98
- package/src/files/tasks/finalize_file_upload/get_text_vectors.ts +0 -13
- package/src/files/tasks/finalize_file_upload/helpers/convert_pdf_to_png.ts +0 -34
- package/src/files/tasks/finalize_file_upload/helpers/exec.ts +0 -5
- package/src/files/tasks/finalize_file_upload/helpers/get_metadata.ts +0 -18
- package/src/files/tasks/finalize_file_upload/index.ts +0 -53
- package/src/files/tasks/finalize_file_upload/run_ocr.ts +0 -42
- package/src/files/tasks/index.ts +0 -6
- package/src/files/upload_chunk.ts +0 -83
- package/src/helpers/sim_test_inject.ts +0 -21
- package/src/models/Invite.js +0 -23
- package/src/models/Notification.js +0 -44
- package/src/models/Policy.ts +0 -13
- package/src/models/ResetPasswordToken.js +0 -14
- package/src/models/SearchHistory.ts +0 -22
- package/src/models/User.js +0 -42
- package/src/models/UserStoredValues.js +0 -18
- package/src/models/index.js +0 -7
- package/src/notitications/ack_notification.js +0 -26
- package/src/notitications/get_notifications.js +0 -39
- package/src/notitications/llt/README.md +0 -8
- package/src/notitications/llt/get_llts.js +0 -42
- package/src/notitications/set_seen.js +0 -26
- package/src/sessions/index.js +0 -27
- package/src/sessions/session_proxy_middleware.js +0 -18
- package/src/sessions/session_store_middleware.js +0 -106
- package/src/sessions/warning_proxy_middleware.js +0 -17
- package/src/tasks/index.js +0 -8
- package/src/tasks/index_item.js +0 -8
- package/store/index.js +0 -31
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
const apply_policies = require("../apply_policies")
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = (schema) => async function(next) {
|
|
6
|
-
const model_name = this.model.modelName
|
|
7
|
-
const collection_name = this.model.collection.name
|
|
8
|
-
|
|
9
|
-
console.log("DELETE PLUGIN GET OPTIONS", this.getOptions())
|
|
10
|
-
|
|
11
|
-
const operation = "delete"
|
|
12
|
-
|
|
13
|
-
if (this.op !== "findOneAndDelete") {
|
|
14
|
-
throw new Error(`in pre_delete unknown operation: ${this.op}`)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const user_id = this.options.ctx.req.session.user_id
|
|
18
|
-
|
|
19
|
-
const filter = this.getFilter()
|
|
20
|
-
const doc = await this.model.findOne(filter)
|
|
21
|
-
|
|
22
|
-
// check if user has permission to delete
|
|
23
|
-
const err = await apply_policies({collection_name, model_name, operation, user_id, doc})
|
|
24
|
-
if (err) {
|
|
25
|
-
console.error(err)
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
next()
|
|
30
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
const assert = require("assert")
|
|
2
|
-
const debug = require("debug")
|
|
3
|
-
|
|
4
|
-
const get_added_fields = require("./get_added_fields")
|
|
5
|
-
const apply_policies = require("./apply_policies")
|
|
6
|
-
|
|
7
|
-
// hooks
|
|
8
|
-
const query_pre_delete = require("./hooks/query_pre_delete")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const log = debug("rb:acl")
|
|
12
|
-
|
|
13
|
-
const QUERY = {document: false, query: true}
|
|
14
|
-
const DOC_OPTIONS = {document: true, query: false}
|
|
15
|
-
|
|
16
|
-
const get_query_middleware = (op) => (schema) => async function(next, save_options) {
|
|
17
|
-
|
|
18
|
-
// TODO: this is wrong (AND BREAKS ACL)
|
|
19
|
-
// when no save options, it's a sub schema, we don't want acl on those
|
|
20
|
-
// if (!save_options) {
|
|
21
|
-
// next()
|
|
22
|
-
// console.log("has returned")
|
|
23
|
-
// return
|
|
24
|
-
// }
|
|
25
|
-
|
|
26
|
-
const collection_name = this.model.collection.name
|
|
27
|
-
const model_name = this.model.modelName
|
|
28
|
-
|
|
29
|
-
assert(model_name, "cannot find model_name for query")
|
|
30
|
-
assert(collection_name, "cannot find collection_name for query")
|
|
31
|
-
|
|
32
|
-
const options = this.getOptions()
|
|
33
|
-
const user_id = options.ctx?.req?.session?.user_id
|
|
34
|
-
|
|
35
|
-
// console
|
|
36
|
-
|
|
37
|
-
// client requests should always be authenticated?
|
|
38
|
-
if (options.is_client && !user_id) {
|
|
39
|
-
throw new Error("expected user_id in client request")
|
|
40
|
-
}
|
|
41
|
-
// skip if no ctx::user_id (=> is from admin)
|
|
42
|
-
else if (!user_id) {
|
|
43
|
-
log("mongoose_plugin: NO USER ID, skipping")
|
|
44
|
-
return next()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const errors = await apply_policies({collection_name, model_name, operation: "read", user_id, doc: this})
|
|
48
|
-
|
|
49
|
-
if (errors?.length > 0) {
|
|
50
|
-
throw new AggregateError(errors, "access-control policies error")
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
log("access-control will continue")
|
|
54
|
-
next()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// https://mongoosejs.com/docs/middleware.html#types-of-middleware
|
|
59
|
-
const mongoose_plugin = async function(schema, options) {
|
|
60
|
-
// TODO: should strict be true here??
|
|
61
|
-
schema.options.strict = false
|
|
62
|
-
// TODO:
|
|
63
|
-
// DANGER: strictQuery to true silently DROPS filter params
|
|
64
|
-
// which can be a critical security risk
|
|
65
|
-
schema.options.strictQuery = false
|
|
66
|
-
|
|
67
|
-
// TODO: acl should be explicitly on by default and only if set to false in schema definition we remove it
|
|
68
|
-
if (!schema.options.isSubSchema && schema.options.acl !== false) {
|
|
69
|
-
// Add Access Control fields to top level schemas
|
|
70
|
-
schema.add(get_added_fields())
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Queries
|
|
74
|
-
schema.pre("find", QUERY, get_query_middleware("find")(schema))
|
|
75
|
-
schema.pre("findOne", QUERY, get_query_middleware("findOne")(schema))
|
|
76
|
-
// TODO: add countDocuments, estimatedDocumentCount
|
|
77
|
-
// aggregate
|
|
78
|
-
schema.pre("findOneAndDelete", QUERY, query_pre_delete(schema))
|
|
79
|
-
|
|
80
|
-
// Documents create and save
|
|
81
|
-
schema.pre("save", DOC_OPTIONS, async function(next, save_options) {
|
|
82
|
-
if (this.$isSubdocument) {
|
|
83
|
-
return next()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const model_name = this.constructor.modelName
|
|
87
|
-
assert(model_name, "doc pre save model_name is undefined")
|
|
88
|
-
|
|
89
|
-
const collection_name = this.constructor.collection.name
|
|
90
|
-
assert(collection_name, "doc pre save collection_name is undefined")
|
|
91
|
-
|
|
92
|
-
const {ctx} = save_options
|
|
93
|
-
|
|
94
|
-
// when no context, assume admin mode and authorize op
|
|
95
|
-
if (!ctx) {
|
|
96
|
-
this._created_at = new Date
|
|
97
|
-
next()
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const user_id = ctx.req.session?.user_id
|
|
101
|
-
|
|
102
|
-
const fields = this.modifiedPaths({includeChildren: true})
|
|
103
|
-
|
|
104
|
-
const doc = this
|
|
105
|
-
// Create
|
|
106
|
-
if (this.isNew) {
|
|
107
|
-
const err = await apply_policies({collection_name, model_name, operation: "create", fields, user_id, doc})
|
|
108
|
-
if (err) {
|
|
109
|
-
console.warn(err)
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
if (!this._owners.includes(user_id)) {
|
|
113
|
-
this._owners.push(user_id)
|
|
114
|
-
}
|
|
115
|
-
this._created_by = user_id
|
|
116
|
-
this._created_at = new Date
|
|
117
|
-
next()
|
|
118
|
-
}
|
|
119
|
-
// Update
|
|
120
|
-
else {
|
|
121
|
-
const err = await apply_policies({collection_name, model_name, operation: "update", fields, user_id, doc})
|
|
122
|
-
if (err) {
|
|
123
|
-
console.warn(err)
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
next()
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
schema.pre("remove", DOC_OPTIONS, function(next) {
|
|
131
|
-
console.log("schema pre REMOVE", this)
|
|
132
|
-
next()
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
module.exports = mongoose_plugin
|
package/src/api/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
const assert = require("assert")
|
|
3
|
-
|
|
4
|
-
const UserStoredValues = require("../../models/UserStoredValues")
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const get_projection = (payload) => {
|
|
8
|
-
const projection = {}
|
|
9
|
-
|
|
10
|
-
payload.forEach((key) => {
|
|
11
|
-
projection[key] = 1
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
return projection
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const get_stored_values = async(payload, ctx) => {
|
|
18
|
-
const {user_id} = ctx.req.session
|
|
19
|
-
expect(user_id).toBeMongoId()
|
|
20
|
-
|
|
21
|
-
const projection = get_projection(payload)
|
|
22
|
-
|
|
23
|
-
const storage_doc = await UserStoredValues.findOne(
|
|
24
|
-
{_owners: {$in: [user_id]}},
|
|
25
|
-
projection,
|
|
26
|
-
{ctx},
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
assert(storage_doc, `unable to retrieve storage_doc for user: ${user_id}`)
|
|
30
|
-
|
|
31
|
-
const result = {
|
|
32
|
-
values: payload.map((k) => storage_doc.get(k)),
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
status: "ok",
|
|
37
|
-
...result,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = get_stored_values
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
const get_stored_values = require("./get_stored_values")
|
|
3
|
-
const set_stored_values = require("./set_stored_values")
|
|
4
|
-
|
|
5
|
-
module.exports = (app) => {
|
|
6
|
-
app.handler("/rb-api/v1/stored-values/get", get_stored_values)
|
|
7
|
-
app.handler("/rb-api/v1/stored-values/set", set_stored_values)
|
|
8
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
const assert = require("assert")
|
|
3
|
-
|
|
4
|
-
const UserStoredValues = require("../../models/UserStoredValues")
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const set_stored_values = async(payload, ctx) => {
|
|
8
|
-
const {values} = payload
|
|
9
|
-
|
|
10
|
-
const {user_id} = ctx.req.session
|
|
11
|
-
expect(user_id).toBeMongoId()
|
|
12
|
-
|
|
13
|
-
const updates = Object.create(null)
|
|
14
|
-
|
|
15
|
-
values.forEach(({key, value}) => {
|
|
16
|
-
updates[key] = value
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const res = await UserStoredValues.updateOne(
|
|
20
|
-
{_owners: {$in: [user_id]}},
|
|
21
|
-
{$set: updates},
|
|
22
|
-
{ctx}
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
// TODO: this breaks on signup???
|
|
26
|
-
// assert(res.modifiedCount === 1, `unable to update user stored values`)
|
|
27
|
-
|
|
28
|
-
return {status: "ok"}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = set_stored_values
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
const debug = require("debug")
|
|
3
|
-
|
|
4
|
-
const User = require("../models/User")
|
|
5
|
-
|
|
6
|
-
const log = debug("rb:auth")
|
|
7
|
-
log.useColors = true
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const has_session_store = process.env.RB_SESSION_STORE === "yes"
|
|
11
|
-
|
|
12
|
-
// TODO: we must separate the check session from the check user exists
|
|
13
|
-
const check_session = async(payload, ctx) => {
|
|
14
|
-
const {req} = ctx
|
|
15
|
-
|
|
16
|
-
log("session:", req.session)
|
|
17
|
-
|
|
18
|
-
let is_signed_in = !!req.session.user_id
|
|
19
|
-
|
|
20
|
-
log("is_signed_in:", is_signed_in)
|
|
21
|
-
|
|
22
|
-
// check if user exists
|
|
23
|
-
let user
|
|
24
|
-
try {
|
|
25
|
-
user = await User.findOne({_id: req.session.user_id}, {_id: 1})
|
|
26
|
-
} catch (err) {
|
|
27
|
-
log("find_user_err:", err)
|
|
28
|
-
}
|
|
29
|
-
if (!user) {
|
|
30
|
-
is_signed_in = false
|
|
31
|
-
req.session.destroy?.(/* TODO: this should take callback */)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// TODO: check if user is disabled or blocked
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
status: "ok",
|
|
38
|
-
is_signed_in,
|
|
39
|
-
user_id: req.session?.user_id,
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = check_session
|