@rpcbase/client 0.146.0 → 0.148.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.
@@ -56,7 +56,7 @@ const SignIn = ({
56
56
  assert(res.user_id, "missing user_id")
57
57
 
58
58
  setUid(user_id)
59
- set_tenant_id(user_id.slice(0, 8))
59
+ set_tenant_id(user_id.slice(8, 16))
60
60
  set_is_signed_in(true)
61
61
 
62
62
  // we must now reconnect on the websocket as we now have a new cookie
@@ -32,7 +32,7 @@ const SignUp = ({
32
32
  if (res.status === "ok") {
33
33
  const {user_id} = res
34
34
  setUid(user_id)
35
- set_tenant_id(user_id.slice(0, 8))
35
+ set_tenant_id(user_id.slice(8, 16))
36
36
  set_is_signed_in(true)
37
37
 
38
38
  // we must now reconnect on the websocket as we have a new cookie
package/auth/index.js CHANGED
@@ -63,7 +63,7 @@ const run_session_check = async() => {
63
63
  }
64
64
 
65
65
  __user_id = res.user_id
66
- __tenant_id = __user_id.slice(0, 8)
66
+ __tenant_id = __user_id.slice(8, 16)
67
67
 
68
68
  // save tenant id
69
69
  if (__tenant_id) {
@@ -116,7 +116,7 @@ export const setUid = (val) => {
116
116
  __user_id = val
117
117
 
118
118
  if (typeof val === "string") {
119
- const tenant_id_prefix = val.slice(0, 8)
119
+ const tenant_id_prefix = val.slice(8, 16)
120
120
  storage.setItem(uid_storage_key(tenant_id_prefix), val)
121
121
  }
122
122
  }
package/get_object_id.js CHANGED
@@ -12,23 +12,22 @@ const get_random_bytes = (n) => {
12
12
  return array
13
13
  }
14
14
 
15
- // Validation
16
- // is defined
15
+ // Validation: is defined
17
16
  assert(TENANT_PREFIX, "expected TENANT_PREFIX to be defined")
18
17
  // is hexadecimal
19
18
  assert(isHexadecimal(TENANT_PREFIX), "expected TENANT_PREFIX to be a hexadecimal")
20
19
  // is 4 bytes
21
20
  assert(TENANT_PREFIX.length === 8, "TENANT_PREFIX must be exactly bytes long ie: 8 hex chars")
22
- // is lower than
23
- const max_val = parseInt("6387427d", 16)
24
- const tenant_prefix_int = parseInt(TENANT_PREFIX, 16)
25
- assert(max_val - tenant_prefix_int > 0, "TENANT_PREFIX must be lower than 6387427d")
26
21
 
27
22
  // generates a 12 bytes mongodb object id using the org id prefix or custom customer id
28
23
  const get_object_id = () => {
29
- const random_bytes = get_random_bytes(8)
24
+ const ts_bytes = Math.floor(Date.now() / 1000).toString(16)
25
+ assert(ts_bytes.length === 8, "expected ts_bytes.length to be 4")
26
+
27
+ const random_bytes = get_random_bytes(4)
30
28
  const random_hex = Buffer.from(random_bytes).toString("hex")
31
- const obj_id = `${TENANT_PREFIX}${random_hex}`
29
+
30
+ const obj_id = `${ts_bytes}${TENANT_PREFIX}${random_hex}`
32
31
  return obj_id
33
32
  }
34
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.146.0",
3
+ "version": "0.148.0",
4
4
  "scripts": {
5
5
  "test": "../../node_modules/.bin/wireit"
6
6
  },