@rpcbase/client 0.33.0 → 0.34.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/package.json +3 -2
- package/rpc_post.js +17 -2
package/package.json
CHANGED
package/rpc_post.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
+
import assert from "assert"
|
|
2
3
|
import axios from "axios"
|
|
4
|
+
import _get from "lodash/get"
|
|
5
|
+
import _set from "lodash/set"
|
|
6
|
+
|
|
7
|
+
import get_txn_id from "@rpcbase/std/get_txn_id"
|
|
8
|
+
import {add_local_txn} from "@rpcbase/realtime-state-client"
|
|
3
9
|
|
|
4
10
|
import env from "env"
|
|
5
11
|
|
|
12
|
+
|
|
6
13
|
const {BASE_URL} = env
|
|
7
14
|
|
|
8
15
|
const client = axios.create({
|
|
@@ -12,8 +19,16 @@ const client = axios.create({
|
|
|
12
19
|
},
|
|
13
20
|
})
|
|
14
21
|
|
|
15
|
-
const rpc_post = async(url, payload) => {
|
|
16
|
-
|
|
22
|
+
const rpc_post = async(url, payload, options = {}) => {
|
|
23
|
+
if (!options?.headers?.["rts-txn-id"]) {
|
|
24
|
+
_set(options, ["headers", "rts-txn-id"], get_txn_id())
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const txn_id = _get(options, ["headers", "rts-txn-id"])
|
|
28
|
+
assert(txn_id, `unable to find txn_id for request ${url}`)
|
|
29
|
+
add_local_txn(txn_id)
|
|
30
|
+
|
|
31
|
+
const res = await client.post(`${BASE_URL}${url}`, payload, options)
|
|
17
32
|
return res.data
|
|
18
33
|
}
|
|
19
34
|
|