@rpcbase/client 0.184.0-treefloatview.0 → 0.185.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/env.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare module "env" {
2
+ export const RB_TENANT_ID: string;
3
+ }
package/getObjectId.ts ADDED
@@ -0,0 +1,31 @@
1
+ import assert from "assert"
2
+ import mongoose from "mongoose"
3
+ import isHexadecimal from "validator/lib/isHexadecimal"
4
+
5
+ import { RB_TENANT_ID } from "env"
6
+
7
+ const getRandomBytes = (n: number): Uint8Array => {
8
+ let array = new Uint8Array(n)
9
+ window.crypto.getRandomValues(array)
10
+ return array
11
+ }
12
+
13
+ // validate env var is defined
14
+ assert(RB_TENANT_ID, "expected RB_TENANT_ID to be defined")
15
+ // is hexadecimal
16
+ assert(isHexadecimal(RB_TENANT_ID), "expected RB_TENANT_ID to be a hexadecimal")
17
+ // is 4 bytes
18
+ assert(RB_TENANT_ID.length === 8, "RB_TENANT_ID must be exactly 4 bytes long ie: 8 hex chars")
19
+
20
+ // generates a 12 bytes mongodb object id using the org id prefix or custom customer id
21
+ export const getObjectId = (): mongoose.Types.ObjectId => {
22
+ const tsBytes = Math.floor(Date.now() / 1000).toString(16)
23
+ assert(tsBytes.length === 8, "expected tsBytes.length to be 4")
24
+
25
+ const randomBytes = getRandomBytes(4)
26
+ const randomHex = Buffer.from(randomBytes).toString("hex")
27
+
28
+ const objId = `${tsBytes}${RB_TENANT_ID}${randomHex}`
29
+
30
+ return new mongoose.Types.ObjectId(objId)
31
+ }
@@ -1,6 +1,6 @@
1
1
  /* @flow */
2
- import ActivityIndicator from "@rpcbase/ui/ActivityIndicator"
3
- import Modal, {withHashStateModal} from "@rpcbase/ui/Modal"
2
+ import ActivityIndicator from "../../ui/ActivityIndicator"
3
+ import Modal, {withHashStateModal} from "../../ui/Modal"
4
4
 
5
5
  // import TemplatesView from "./TemplatesView"
6
6
  // import {TemplateContextProvider} from "./TemplateContext"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.184.0-treefloatview.0",
3
+ "version": "0.185.0",
4
4
  "scripts": {
5
5
  "test": "../../node_modules/.bin/wireit"
6
6
  },
package/get_object_id.js DELETED
@@ -1,34 +0,0 @@
1
- /* @flow */
2
- import assert from "assert"
3
-
4
- import isHexadecimal from "validator/lib/isHexadecimal"
5
-
6
- import {RB_TENANT_ID} from "env"
7
-
8
-
9
- const get_random_bytes = (n) => {
10
- let array = new Uint8Array(n)
11
- window.crypto.getRandomValues(array)
12
- return array
13
- }
14
-
15
- // Validation: is defined
16
- assert(RB_TENANT_ID, "expected RB_TENANT_ID to be defined")
17
- // is hexadecimal
18
- assert(isHexadecimal(RB_TENANT_ID), "expected RB_TENANT_ID to be a hexadecimal")
19
- // is 4 bytes
20
- assert(RB_TENANT_ID.length === 8, "RB_TENANT_ID must be exactly bytes long ie: 8 hex chars")
21
-
22
- // generates a 12 bytes mongodb object id using the org id prefix or custom customer id
23
- const get_object_id = () => {
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)
28
- const random_hex = Buffer.from(random_bytes).toString("hex")
29
-
30
- const obj_id = `${ts_bytes}${RB_TENANT_ID}${random_hex}`
31
- return obj_id
32
- }
33
-
34
- export default get_object_id