@rpcbase/client 0.32.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.
@@ -2,7 +2,7 @@
2
2
  import {useState} from "react"
3
3
  import page from "page"
4
4
 
5
- import {set_is_signed_in} from "../index"
5
+ import {set_is_signed_in, set_uid} from "../index"
6
6
  import post from "../../helpers/post"
7
7
  import Footer from "../Footer"
8
8
 
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 0"
6
6
  },
7
7
  "dependencies": {
8
- "axios": "0.27.2"
8
+ "axios": "0.27.2",
9
+ "lodash": "4.17.21"
9
10
  }
10
11
  }
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
- const res = await client.post(`${BASE_URL}${url}`, payload)
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