@rpcbase/client 0.127.0 → 0.128.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/apiClient.js +15 -0
- package/auth/getTenantId.js +11 -0
- package/auth/index.js +3 -2
- package/helpers/post.js +1 -1
- package/index.js +13 -1
- package/jest.config.js +2 -1
- package/package.json +4 -1
- package/rpc_post.js +3 -4
- package/rts/rts.js +2 -3
- package/auth/get_tenant_id.js +0 -11
- package/base_url.js +0 -15
package/apiClient.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
import axios from "axios"
|
|
3
|
+
|
|
4
|
+
import {BASE_URL, getTenantId} from "./index"
|
|
5
|
+
|
|
6
|
+
// TODO: this should be moved to rb:client
|
|
7
|
+
const apiClient = axios.create({
|
|
8
|
+
baseURL: BASE_URL,
|
|
9
|
+
withCredentials: true,
|
|
10
|
+
headers: {
|
|
11
|
+
"rb-tenant-id": getTenantId(),
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export default apiClient
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
import {Platform} from "react-native"
|
|
3
|
+
|
|
4
|
+
import {getTenantId as _getTenantId} from "./index"
|
|
5
|
+
|
|
6
|
+
const getTenantId = Platform.OS === "web" ? _getTenantId : () => {
|
|
7
|
+
console.warn("native should not call getTenantId, use tenantId from AuthContext")
|
|
8
|
+
return null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default getTenantId
|
package/auth/index.js
CHANGED
|
@@ -78,7 +78,8 @@ const run_session_check = async() => {
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
// Force trigger run first session check (when we are not in a webworker (or mobile))
|
|
81
|
-
|
|
81
|
+
const isJest = !!process?.env?.JEST_WORKER_ID
|
|
82
|
+
if (typeof window !== "undefined" && !isJest) run_session_check()
|
|
82
83
|
|
|
83
84
|
|
|
84
85
|
export const session_restrict = (ctx, next) => {
|
|
@@ -120,7 +121,7 @@ export const setUid = (val) => {
|
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
export const
|
|
124
|
+
export const getTenantId = () => __tenant_id
|
|
124
125
|
export const set_tenant_id = (val) => {
|
|
125
126
|
__tenant_id = val
|
|
126
127
|
storage.setItem(LAST_TENANT_KEY, val)
|
package/helpers/post.js
CHANGED
package/index.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
+
import {SERVER_PORT, APP_DOMAIN} from "env"
|
|
3
|
+
|
|
2
4
|
import useRPC from "./helpers/useRPC"
|
|
3
5
|
import useStoredValue from "./helpers/useStoredValue"
|
|
6
|
+
import getTenantId from "./auth/getTenantId"
|
|
7
|
+
|
|
8
|
+
export {useRPC, useStoredValue, getTenantId}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const protocol = (typeof window !== "undefined" && window?.location?.protocol) || "http:"
|
|
12
|
+
|
|
13
|
+
// there is no SERVER_PORT in production, as we use the default port and we are behind the gateway
|
|
14
|
+
// we assume we specify the port only when localhost or 127.0.0.1
|
|
15
|
+
const isLocal = ["localhost", "127.0.0.1"].includes(APP_DOMAIN)
|
|
4
16
|
|
|
5
|
-
export {
|
|
17
|
+
export const BASE_URL = isLocal ? `${protocol}//${APP_DOMAIN}:${SERVER_PORT}` : `https://${APP_DOMAIN}`
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.128.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build-firebase": "webpack -c firebase/webpack.config.js",
|
|
6
6
|
"build": "yarn build-firebase",
|
|
@@ -28,14 +28,17 @@
|
|
|
28
28
|
"@babel/preset-react": "7.23.3",
|
|
29
29
|
"@testing-library/react": "14.1.2",
|
|
30
30
|
"@testing-library/react-hooks": "8.0.1",
|
|
31
|
+
"axios": "1.6.2",
|
|
31
32
|
"babel-jest": "29.7.0",
|
|
32
33
|
"bluebird": "3.7.2",
|
|
33
34
|
"jest": "29.7.0",
|
|
34
35
|
"jest-environment-jsdom": "29.7.0",
|
|
36
|
+
"page": "1.11.6",
|
|
35
37
|
"react": "18.2.0",
|
|
36
38
|
"react-dom": "18.2.0",
|
|
37
39
|
"react-native-web": "0.19.9",
|
|
38
40
|
"react-test-renderer": "18.2.0",
|
|
41
|
+
"validator": "13.11.0",
|
|
39
42
|
"webpack": "5.89.0",
|
|
40
43
|
"webpack-cli": "5.1.4"
|
|
41
44
|
}
|
package/rpc_post.js
CHANGED
|
@@ -5,10 +5,9 @@ import _get from "lodash/get"
|
|
|
5
5
|
import _set from "lodash/set"
|
|
6
6
|
|
|
7
7
|
import get_txn_id from "@rpcbase/std/get_txn_id"
|
|
8
|
-
import {add_local_txn} from "@rpcbase/client/rts"
|
|
9
8
|
|
|
10
|
-
import
|
|
11
|
-
import
|
|
9
|
+
import {BASE_URL, getTenantId} from "./index"
|
|
10
|
+
import {add_local_txn} from "./rts"
|
|
12
11
|
|
|
13
12
|
const TENANT_ID_HEADER = "rb-tenant-id"
|
|
14
13
|
|
|
@@ -28,7 +27,7 @@ const rpc_post = async(url, payload, options = {}) => {
|
|
|
28
27
|
assert(txn_id, `unable to find txn_id for request ${url}`)
|
|
29
28
|
add_local_txn(txn_id)
|
|
30
29
|
|
|
31
|
-
options.headers[TENANT_ID_HEADER] =
|
|
30
|
+
options.headers[TENANT_ID_HEADER] = getTenantId()
|
|
32
31
|
|
|
33
32
|
const res = await client.post(`${BASE_URL}${url}`, payload, options)
|
|
34
33
|
|
package/rts/rts.js
CHANGED
|
@@ -6,8 +6,7 @@ import _get from "lodash/get"
|
|
|
6
6
|
import _set from "lodash/set"
|
|
7
7
|
import debug from "debug"
|
|
8
8
|
|
|
9
|
-
import BASE_URL from "../
|
|
10
|
-
import {get_tenant_id} from "../auth"
|
|
9
|
+
import {BASE_URL, getTenantId} from "../index"
|
|
11
10
|
|
|
12
11
|
import store from "./store"
|
|
13
12
|
import getUseDocument from "./getUseDocument"
|
|
@@ -91,7 +90,7 @@ const dispatch_query_payload = (payload) => {
|
|
|
91
90
|
|
|
92
91
|
|
|
93
92
|
export const connect = () => new Promise((resolve) => {
|
|
94
|
-
const tenant_id =
|
|
93
|
+
const tenant_id = getTenantId()
|
|
95
94
|
|
|
96
95
|
if (tenant_id) {
|
|
97
96
|
log("rts client will connect")
|
package/auth/get_tenant_id.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import {Platform} from "react-native"
|
|
3
|
-
|
|
4
|
-
import {get_tenant_id as _get_tenant_id} from "./index"
|
|
5
|
-
|
|
6
|
-
const get_tenant_id = Platform.OS === "web" ? _get_tenant_id : () => {
|
|
7
|
-
console.warn("native should not call get_tenant_id, use tenantId from AuthContext")
|
|
8
|
-
return null
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default get_tenant_id
|
package/base_url.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import axios from "axios"
|
|
3
|
-
|
|
4
|
-
import {SERVER_PORT, APP_DOMAIN} from "env"
|
|
5
|
-
|
|
6
|
-
const protocol = (typeof window !== "undefined" && window?.location?.protocol) || "http:"
|
|
7
|
-
|
|
8
|
-
// there is no SERVER_PORT in production, as we use the default port and we are behind the gateway
|
|
9
|
-
// we assume we specify the port only when localhost or 127.0.0.1
|
|
10
|
-
const is_local = ["localhost", "127.0.0.1"].includes(APP_DOMAIN)
|
|
11
|
-
|
|
12
|
-
const BASE_URL = is_local ? `${protocol}//${APP_DOMAIN}:${SERVER_PORT}` : `https://${APP_DOMAIN}`
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export default BASE_URL
|