@binance/common 1.2.1 → 1.2.2
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 +29 -2
- package/dist/index.d.ts +29 -2
- package/dist/index.js +46 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -122,6 +122,39 @@ var setSearchParams = function(url, ...objects) {
|
|
|
122
122
|
var toPathString = function(url) {
|
|
123
123
|
return url.pathname + url.search + url.hash;
|
|
124
124
|
};
|
|
125
|
+
function normalizeScientificNumbers(obj) {
|
|
126
|
+
if (Array.isArray(obj)) {
|
|
127
|
+
return obj.map((item) => normalizeScientificNumbers(item));
|
|
128
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
129
|
+
const result = {};
|
|
130
|
+
for (const key of Object.keys(obj)) {
|
|
131
|
+
result[key] = normalizeScientificNumbers(obj[key]);
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
} else if (typeof obj === "number") {
|
|
135
|
+
if (!Number.isFinite(obj)) return obj;
|
|
136
|
+
const abs = Math.abs(obj);
|
|
137
|
+
if (abs === 0 || abs >= 1e-6 && abs < 1e21) return String(obj);
|
|
138
|
+
const isNegative = obj < 0;
|
|
139
|
+
const [rawMantissa, rawExponent] = abs.toExponential().split("e");
|
|
140
|
+
const exponent = +rawExponent;
|
|
141
|
+
const digits = rawMantissa.replace(".", "");
|
|
142
|
+
if (exponent < 0) {
|
|
143
|
+
const zeros = "0".repeat(Math.abs(exponent) - 1);
|
|
144
|
+
return (isNegative ? "-" : "") + "0." + zeros + digits;
|
|
145
|
+
} else {
|
|
146
|
+
const pad = exponent - (digits.length - 1);
|
|
147
|
+
if (pad >= 0) {
|
|
148
|
+
return (isNegative ? "-" : "") + digits + "0".repeat(pad);
|
|
149
|
+
} else {
|
|
150
|
+
const point = digits.length + pad;
|
|
151
|
+
return (isNegative ? "-" : "") + digits.slice(0, point) + "." + digits.slice(point);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
return obj;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
125
158
|
var shouldRetryRequest = function(error, method, retriesLeft) {
|
|
126
159
|
const isRetriableMethod = ["GET", "DELETE"].includes(method ?? "");
|
|
127
160
|
const isRetriableStatus = [500, 502, 503, 504].includes(
|
|
@@ -283,7 +316,7 @@ var sendRequest = function(configuration, endpoint, method, params = {}, timeUni
|
|
|
283
316
|
method,
|
|
284
317
|
...configuration?.baseOptions
|
|
285
318
|
};
|
|
286
|
-
const localVarQueryParameter = { ...params };
|
|
319
|
+
const localVarQueryParameter = { ...normalizeScientificNumbers(params) };
|
|
287
320
|
if (options.isSigned) {
|
|
288
321
|
const timestamp = getTimestamp();
|
|
289
322
|
localVarQueryParameter["timestamp"] = timestamp;
|
|
@@ -354,7 +387,7 @@ function buildUserAgent(packageName, packageVersion) {
|
|
|
354
387
|
function buildWebsocketAPIMessage(configuration, method, payload, options, skipAuth = false) {
|
|
355
388
|
const id = payload.id && /^[0-9a-f]{32}$/.test(payload.id) ? payload.id : randomString();
|
|
356
389
|
delete payload.id;
|
|
357
|
-
let params = removeEmptyValue(payload);
|
|
390
|
+
let params = normalizeScientificNumbers(removeEmptyValue(payload));
|
|
358
391
|
if ((options.withApiKey || options.isSigned) && !skipAuth) params.apiKey = configuration.apiKey;
|
|
359
392
|
if (options.isSigned) {
|
|
360
393
|
params.timestamp = getTimestamp();
|
|
@@ -377,7 +410,7 @@ function parseCustomHeaders(headers) {
|
|
|
377
410
|
for (const [rawName, rawValue] of Object.entries(headers || {})) {
|
|
378
411
|
const name = rawName.trim();
|
|
379
412
|
if (forbidden.has(name.toLowerCase())) {
|
|
380
|
-
|
|
413
|
+
Logger.getInstance().warn(`Dropping forbidden header: ${name}`);
|
|
381
414
|
continue;
|
|
382
415
|
}
|
|
383
416
|
try {
|
|
@@ -597,33 +630,27 @@ var Logger = class _Logger {
|
|
|
597
630
|
"warn" /* WARN */,
|
|
598
631
|
"error" /* ERROR */
|
|
599
632
|
];
|
|
633
|
+
const envLevel = process.env.LOG_LEVEL?.toLowerCase();
|
|
634
|
+
this.minLogLevel = envLevel && this.isValidLogLevel(envLevel) ? envLevel : "info" /* INFO */;
|
|
600
635
|
}
|
|
601
636
|
static getInstance() {
|
|
602
|
-
if (!_Logger.instance)
|
|
603
|
-
_Logger.instance = new _Logger();
|
|
604
|
-
}
|
|
637
|
+
if (!_Logger.instance) _Logger.instance = new _Logger();
|
|
605
638
|
return _Logger.instance;
|
|
606
639
|
}
|
|
607
640
|
setMinLogLevel(level) {
|
|
608
|
-
if (!this.isValidLogLevel(level)) {
|
|
609
|
-
throw new Error(`Invalid log level: ${level}`);
|
|
610
|
-
}
|
|
641
|
+
if (!this.isValidLogLevel(level)) throw new Error(`Invalid log level: ${level}`);
|
|
611
642
|
this.minLogLevel = level;
|
|
612
643
|
}
|
|
613
644
|
isValidLogLevel(level) {
|
|
614
645
|
return this.levelsOrder.includes(level);
|
|
615
646
|
}
|
|
616
647
|
log(level, ...message) {
|
|
617
|
-
if (level === "" /* NONE */ || !this.allowLevelLog(level))
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
648
|
+
if (level === "" /* NONE */ || !this.allowLevelLog(level)) return;
|
|
620
649
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
621
650
|
console[level](`[${timestamp}] [${level.toLowerCase()}]`, ...message);
|
|
622
651
|
}
|
|
623
652
|
allowLevelLog(level) {
|
|
624
|
-
if (!this.isValidLogLevel(level)) {
|
|
625
|
-
throw new Error(`Invalid log level: ${level}`);
|
|
626
|
-
}
|
|
653
|
+
if (!this.isValidLogLevel(level)) throw new Error(`Invalid log level: ${level}`);
|
|
627
654
|
const currentLevelIndex = this.levelsOrder.indexOf(level);
|
|
628
655
|
const minLevelIndex = this.levelsOrder.indexOf(this.minLogLevel);
|
|
629
656
|
return currentLevelIndex >= minLevelIndex;
|
|
@@ -1348,7 +1375,7 @@ var WebsocketStreamsBase = class extends WebsocketCommon {
|
|
|
1348
1375
|
params: streams,
|
|
1349
1376
|
id: id && /^[0-9a-f]{32}$/.test(id) ? id : randomString()
|
|
1350
1377
|
};
|
|
1351
|
-
this.logger.
|
|
1378
|
+
this.logger.debug("SUBSCRIBE", payload);
|
|
1352
1379
|
this.send(JSON.stringify(payload), void 0, false, 0, connection);
|
|
1353
1380
|
}
|
|
1354
1381
|
/**
|
|
@@ -1468,7 +1495,7 @@ var WebsocketStreamsBase = class extends WebsocketCommon {
|
|
|
1468
1495
|
params: [stream2],
|
|
1469
1496
|
id: id && /^[0-9a-f]{32}$/.test(id) ? id : randomString()
|
|
1470
1497
|
};
|
|
1471
|
-
this.logger.
|
|
1498
|
+
this.logger.debug("UNSUBSCRIBE", payload);
|
|
1472
1499
|
this.send(JSON.stringify(payload), void 0, false, 0, connection);
|
|
1473
1500
|
this.streamConnectionMap.delete(stream2);
|
|
1474
1501
|
this.streamCallbackMap.delete(stream2);
|
|
@@ -1588,6 +1615,7 @@ export {
|
|
|
1588
1615
|
getSignature,
|
|
1589
1616
|
getTimestamp,
|
|
1590
1617
|
httpRequestFunction,
|
|
1618
|
+
normalizeScientificNumbers,
|
|
1591
1619
|
parseCustomHeaders,
|
|
1592
1620
|
parseRateLimitHeaders,
|
|
1593
1621
|
randomString,
|