@rpcbase/server 0.330.0 → 0.332.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.
|
@@ -6,7 +6,7 @@ const run_docker = require("./run_docker")
|
|
|
6
6
|
const run_native = require("./run_native")
|
|
7
7
|
|
|
8
8
|
// TODO: auto create network if necessary
|
|
9
|
-
// docker network create ${
|
|
9
|
+
// docker network create ${RB_APP_NAME}-network
|
|
10
10
|
|
|
11
11
|
const start_server = async(args) => {
|
|
12
12
|
const infrastructure_dir = path.join(process.cwd(), "../infrastructure")
|
package/get_object_id.js
CHANGED
|
@@ -22,7 +22,7 @@ assert(TENANT_PREFIX.length === 8, "TENANT_PREFIX must be exactly 4 bytes (8 hex
|
|
|
22
22
|
// generates a 12 bytes mongodb object id using the org id prefix or custom customer id
|
|
23
23
|
const get_object_id = () => {
|
|
24
24
|
const ts_bytes = Math.floor(Date.now() / 1000).toString(16)
|
|
25
|
-
|
|
25
|
+
expect(ts_bytes.length).toBe(8)
|
|
26
26
|
|
|
27
27
|
const random_bytes = crypto.randomBytes(4).toString("hex")
|
|
28
28
|
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ const dispatch_queue = require("./dispatch_queue")
|
|
|
11
11
|
|
|
12
12
|
const log = debug("rb:queue:listener")
|
|
13
13
|
|
|
14
|
-
const {RB_APP_NAME} = process.env
|
|
14
|
+
const {RB_APP_NAME, TENANT_PREFIX} = process.env
|
|
15
15
|
|
|
16
16
|
const RETRY_MAXIMUM_DELAY = 2000
|
|
17
17
|
const RETRY_MINIMUM_DELAY = 10
|
|
@@ -52,12 +52,31 @@ const mongoose_delete_plugin = (schema) => {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
|
|
55
|
+
const assert_doc_id = (change) => {
|
|
56
|
+
if (process.env.NODE_ENV !== "development") return
|
|
57
|
+
|
|
58
|
+
const doc_id = change.documentKey?._id?.toString()
|
|
59
|
+
|
|
60
|
+
if (!doc_id) return
|
|
61
|
+
|
|
62
|
+
const sub = doc_id.substring(8, 16)
|
|
63
|
+
try {
|
|
64
|
+
expect(sub).toBe(TENANT_PREFIX)
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.log("in document:", change.ns, change.documentKey)
|
|
67
|
+
console.log("_id must be constructed with get_object_id()")
|
|
68
|
+
console.log(err.message)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
55
72
|
const dispatch_change_handler = (change) => {
|
|
56
73
|
// skip if change is on another db
|
|
57
74
|
if (change?.ns?.db !== RB_APP_NAME) {
|
|
58
75
|
return
|
|
59
76
|
}
|
|
60
77
|
|
|
78
|
+
assert_doc_id(change)
|
|
79
|
+
|
|
61
80
|
const op = change.operationType
|
|
62
81
|
if (["insert", "update"].includes(op)) {
|
|
63
82
|
const coll_name = change.ns.coll
|