Skip to content

Commit 1a55458

Browse files
committed
sorts query parameters for rest calls
1 parent acae0ed commit 1a55458

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/client.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class Client {
3939

4040
async makeRequest(method, endpoint, params, publc=false) {
4141
let url = new URL(apiUrl + apiVersion + endpoint)
42-
let query = new URLSearchParams(params).toString()
42+
let rawQuery = new URLSearchParams(params)
43+
rawQuery.sort()
44+
let query = rawQuery.toString()
4345

4446
// build fetch options
4547
let opts = {
@@ -53,7 +55,7 @@ class Client {
5355
if (!publc) opts.headers['Authorization'] = this.buildCredential(method, endpoint, query)
5456

5557
// include query params to call
56-
if (method === methodGet) url.search = query
58+
if (method === methodGet || method === methodPut) url.search = query
5759
else opts.body = query
5860

5961
// make request
@@ -79,7 +81,7 @@ class Client {
7981
let timestamp = Math.floor(Date.now() / 1000).toString()
8082
let msg = httpMethod + timestamp + apiVersion + method
8183
if (query) {
82-
if (httpMethod === methodGet) msg += "?"
84+
if (httpMethod === methodGet || httpMethod === methodPut) msg += "?"
8385
msg += query
8486
}
8587
let signature = CryptoJS.HmacSHA256(msg, this.apiSecret).toString()

0 commit comments

Comments
 (0)