@binance/common 1.2.4 → 1.2.6
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/dist/index.d.mts +16 -27
- package/dist/index.d.ts +16 -27
- package/dist/index.js +24 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -50,13 +50,22 @@ var RequestSigner = class {
|
|
|
50
50
|
var clearSignerCache = function() {
|
|
51
51
|
signerCache = /* @__PURE__ */ new WeakMap();
|
|
52
52
|
};
|
|
53
|
+
function serializeValue(value) {
|
|
54
|
+
if (value === null || value === void 0) return "";
|
|
55
|
+
if (Array.isArray(value) || typeof value === "object" && value !== null)
|
|
56
|
+
return JSON.stringify(value);
|
|
57
|
+
return String(value);
|
|
58
|
+
}
|
|
53
59
|
function buildQueryString(params) {
|
|
54
60
|
if (!params) return "";
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
const pairs = [];
|
|
62
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
63
|
+
if (value !== null && value !== void 0) {
|
|
64
|
+
const serializedValue = serializeValue(value);
|
|
65
|
+
pairs.push(`${key}=${encodeURIComponent(serializedValue)}`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return pairs.join("&");
|
|
60
69
|
}
|
|
61
70
|
function randomString() {
|
|
62
71
|
return crypto.randomBytes(16).toString("hex");
|
|
@@ -91,34 +100,16 @@ var assertParamExists = function(functionName, paramName, paramValue) {
|
|
|
91
100
|
);
|
|
92
101
|
}
|
|
93
102
|
};
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
for (const item of parameter) {
|
|
101
|
-
setFlattenedQueryParams(urlSearchParams, item, "");
|
|
102
|
-
}
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (typeof parameter === "object") {
|
|
106
|
-
for (const subKey of Object.keys(parameter)) {
|
|
107
|
-
const subVal = parameter[subKey];
|
|
108
|
-
const newKey = key ? `${key}.${subKey}` : subKey;
|
|
109
|
-
setFlattenedQueryParams(urlSearchParams, subVal, newKey);
|
|
103
|
+
function setSearchParams(url, params) {
|
|
104
|
+
const searchParams = new URLSearchParams();
|
|
105
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
106
|
+
if (value !== null && value !== void 0) {
|
|
107
|
+
const serializedValue = serializeValue(value);
|
|
108
|
+
searchParams.set(key, serializedValue);
|
|
110
109
|
}
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
const str = String(parameter);
|
|
114
|
-
if (urlSearchParams.has(key)) urlSearchParams.append(key, str);
|
|
115
|
-
else urlSearchParams.set(key, str);
|
|
116
|
-
}
|
|
117
|
-
var setSearchParams = function(url, ...objects) {
|
|
118
|
-
const searchParams = new URLSearchParams(url.search);
|
|
119
|
-
setFlattenedQueryParams(searchParams, objects);
|
|
110
|
+
});
|
|
120
111
|
url.search = searchParams.toString();
|
|
121
|
-
}
|
|
112
|
+
}
|
|
122
113
|
var toPathString = function(url) {
|
|
123
114
|
return url.pathname + url.search + url.hash;
|
|
124
115
|
};
|
|
@@ -489,7 +480,6 @@ var TimeUnit = {
|
|
|
489
480
|
microsecond: "microsecond"
|
|
490
481
|
};
|
|
491
482
|
var ALGO_REST_API_PROD_URL = "https://api.binance.com";
|
|
492
|
-
var AUTO_INVEST_REST_API_PROD_URL = "https://api.binance.com";
|
|
493
483
|
var C2C_REST_API_PROD_URL = "https://api.binance.com";
|
|
494
484
|
var CONVERT_REST_API_PROD_URL = "https://api.binance.com";
|
|
495
485
|
var COPY_TRADING_REST_API_PROD_URL = "https://api.binance.com";
|
|
@@ -961,6 +951,7 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
961
951
|
} else if (targetConnection.closeInitiated) {
|
|
962
952
|
this.closeConnectionGracefully(targetConnection.ws, targetConnection);
|
|
963
953
|
} else {
|
|
954
|
+
targetConnection.reconnectionPending = false;
|
|
964
955
|
this.emit("open", this);
|
|
965
956
|
}
|
|
966
957
|
this.sessionReLogon(targetConnection);
|
|
@@ -1074,6 +1065,7 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1074
1065
|
ws.on("close", (closeEventCode, reason) => {
|
|
1075
1066
|
this.emit("close", closeEventCode, reason);
|
|
1076
1067
|
if (!targetConnection.closeInitiated && !isRenewal) {
|
|
1068
|
+
this.cleanup(ws);
|
|
1077
1069
|
this.logger.warn(
|
|
1078
1070
|
`Connection with id ${targetConnection.id} closed due to ${closeEventCode}: ${reason}`
|
|
1079
1071
|
);
|
|
@@ -1551,7 +1543,6 @@ function createStreamHandler(websocketBase, streamOrId, id) {
|
|
|
1551
1543
|
}
|
|
1552
1544
|
export {
|
|
1553
1545
|
ALGO_REST_API_PROD_URL,
|
|
1554
|
-
AUTO_INVEST_REST_API_PROD_URL,
|
|
1555
1546
|
BadRequestError,
|
|
1556
1547
|
C2C_REST_API_PROD_URL,
|
|
1557
1548
|
CONVERT_REST_API_PROD_URL,
|
|
@@ -1637,7 +1628,6 @@ export {
|
|
|
1637
1628
|
replaceWebsocketStreamsPlaceholders,
|
|
1638
1629
|
sanitizeHeaderValue,
|
|
1639
1630
|
sendRequest,
|
|
1640
|
-
setFlattenedQueryParams,
|
|
1641
1631
|
setSearchParams,
|
|
1642
1632
|
shouldRetryRequest,
|
|
1643
1633
|
sortObject,
|