@rpcbase/client 0.129.0 → 0.132.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 +6 -3
- package/auth/getTenantId.js +4 -3
- package/getBaseUrl.js +14 -0
- package/helpers/post.js +2 -2
- package/index.js +1 -13
- package/package.json +1 -1
- package/rpc_post.js +3 -2
- package/rts/rts.js +3 -2
package/apiClient.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
import axios from "axios"
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import getBaseUrl from "./getBaseUrl"
|
|
5
|
+
import getTenantId from "./auth/getTenantId"
|
|
6
|
+
|
|
7
|
+
console.log("BAGGGG", getTenantId)
|
|
8
|
+
|
|
5
9
|
|
|
6
|
-
// TODO: this should be moved to rb:client
|
|
7
10
|
const apiClient = axios.create({
|
|
8
|
-
baseURL:
|
|
11
|
+
baseURL: getBaseUrl(),
|
|
9
12
|
withCredentials: true,
|
|
10
13
|
headers: {
|
|
11
14
|
"rb-tenant-id": getTenantId(),
|
package/auth/getTenantId.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
import {Platform} from "react-native"
|
|
3
3
|
|
|
4
|
-
import {getTenantId
|
|
4
|
+
import {getTenantId} from "./index"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
const getTenantIdFn = Platform.OS === "web" ? getTenantId : () => {
|
|
7
8
|
console.warn("native should not call getTenantId, use tenantId from AuthContext")
|
|
8
9
|
return null
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export default
|
|
12
|
+
export default getTenantIdFn
|
package/getBaseUrl.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
import {SERVER_PORT, APP_DOMAIN} from "env"
|
|
3
|
+
|
|
4
|
+
const protocol = (typeof window !== "undefined" && window?.location?.protocol) || "http:"
|
|
5
|
+
|
|
6
|
+
// there is no SERVER_PORT in production, as we use the default port and we are behind the gateway
|
|
7
|
+
// we assume we specify the port only when localhost or 127.0.0.1
|
|
8
|
+
const isLocal = ["localhost", "127.0.0.1"].includes(APP_DOMAIN)
|
|
9
|
+
|
|
10
|
+
const BASE_URL = isLocal ? `${protocol}//${APP_DOMAIN}:${SERVER_PORT}` : `https://${APP_DOMAIN}`
|
|
11
|
+
|
|
12
|
+
const getBaseUrl = () => BASE_URL
|
|
13
|
+
|
|
14
|
+
export default getBaseUrl
|
package/helpers/post.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
import axios from "axios"
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import getBaseUrl from "../getBaseUrl"
|
|
5
5
|
|
|
6
6
|
const client = axios.create({
|
|
7
7
|
withCredentials: true,
|
|
@@ -11,7 +11,7 @@ const client = axios.create({
|
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
const post = async(url, payload) => {
|
|
14
|
-
const res = await client.post(`${
|
|
14
|
+
const res = await client.post(`${getBaseUrl()}${url}`, payload)
|
|
15
15
|
return res.data
|
|
16
16
|
}
|
|
17
17
|
|
package/index.js
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
import {SERVER_PORT, APP_DOMAIN} from "env"
|
|
3
|
-
|
|
4
2
|
import useRPC from "./helpers/useRPC"
|
|
5
3
|
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)
|
|
16
4
|
|
|
17
|
-
export
|
|
5
|
+
export {useRPC, useStoredValue}
|
package/package.json
CHANGED
package/rpc_post.js
CHANGED
|
@@ -6,7 +6,8 @@ import _set from "lodash/set"
|
|
|
6
6
|
|
|
7
7
|
import get_txn_id from "@rpcbase/std/get_txn_id"
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import getBaseUrl from "./getBaseUrl"
|
|
10
|
+
import getTenantId from "./auth/getTenantId"
|
|
10
11
|
import {add_local_txn} from "./rts"
|
|
11
12
|
|
|
12
13
|
const TENANT_ID_HEADER = "rb-tenant-id"
|
|
@@ -29,7 +30,7 @@ const rpc_post = async(url, payload, options = {}) => {
|
|
|
29
30
|
|
|
30
31
|
options.headers[TENANT_ID_HEADER] = getTenantId()
|
|
31
32
|
|
|
32
|
-
const res = await client.post(`${
|
|
33
|
+
const res = await client.post(`${getBaseUrl()}${url}`, payload, options)
|
|
33
34
|
|
|
34
35
|
if (res.data === "") {
|
|
35
36
|
console.warn("rpc_post:error: got empty res", res)
|
package/rts/rts.js
CHANGED
|
@@ -6,7 +6,8 @@ import _get from "lodash/get"
|
|
|
6
6
|
import _set from "lodash/set"
|
|
7
7
|
import debug from "debug"
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import getBaseUrl from "../getBaseUrl"
|
|
10
|
+
import getTenantId from "../auth/getTenantId"
|
|
10
11
|
|
|
11
12
|
import store from "./store"
|
|
12
13
|
import getUseDocument from "./getUseDocument"
|
|
@@ -100,7 +101,7 @@ export const connect = () => new Promise((resolve) => {
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
|
|
103
|
-
_socket = io(
|
|
104
|
+
_socket = io(getBaseUrl(), {
|
|
104
105
|
forceNew: true,
|
|
105
106
|
transports: ["websocket", "polling"],
|
|
106
107
|
withCredentials: true,
|