@binance/common 2.0.1 → 2.1.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/dist/index.d.mts CHANGED
@@ -492,13 +492,15 @@ interface AxiosRequestArgs {
492
492
  * Represents the arguments for a request.
493
493
  * @property {string} endpoint - The endpoint for the request.
494
494
  * @property {'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH'} method - The HTTP method for the request.
495
- * @property {Record<string, unknown>} params - The parameters for the request.
495
+ * @property {Record<string, unknown>} queryParams - The query parameters for the request.
496
+ * @property {Record<string, unknown>} bodyParams - The body parameters for the request.
496
497
  * @property {TimeUnit} [timeUnit] - The optional time unit for the request.
497
498
  */
498
499
  interface RequestArgs {
499
500
  endpoint: string;
500
501
  method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
501
- params: Record<string, unknown>;
502
+ queryParams: Record<string, unknown>;
503
+ bodyParams: Record<string, unknown>;
502
504
  timeUnit?: TimeUnit;
503
505
  }
504
506
  //#endregion
@@ -559,7 +561,7 @@ declare const getSignature: (configuration: {
559
561
  apiSecret?: string;
560
562
  privateKey?: string | Buffer;
561
563
  privateKeyPassphrase?: string;
562
- }, queryParams: Record<string, unknown>) => string;
564
+ }, queryParams: Record<string, unknown>, bodyParams?: Record<string, unknown>) => string;
563
565
  /**
564
566
  * Asserts that a function parameter exists and is not null or undefined.
565
567
  *
@@ -641,7 +643,7 @@ declare const parseRateLimitHeaders: (headers: RawAxiosResponseHeaders | AxiosRe
641
643
  * @param options - Additional request options (isSigned).
642
644
  * @returns A promise resolving to the response data object.
643
645
  */
644
- declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH", params?: Record<string, unknown>, timeUnit?: TimeUnit, options?: {
646
+ declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH", queryParams?: Record<string, unknown>, bodyParams?: Record<string, unknown>, timeUnit?: TimeUnit, options?: {
645
647
  isSigned?: boolean;
646
648
  }) => Promise<RestApiResponse<T>>;
647
649
  /**
package/dist/index.d.ts CHANGED
@@ -492,13 +492,15 @@ interface AxiosRequestArgs {
492
492
  * Represents the arguments for a request.
493
493
  * @property {string} endpoint - The endpoint for the request.
494
494
  * @property {'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH'} method - The HTTP method for the request.
495
- * @property {Record<string, unknown>} params - The parameters for the request.
495
+ * @property {Record<string, unknown>} queryParams - The query parameters for the request.
496
+ * @property {Record<string, unknown>} bodyParams - The body parameters for the request.
496
497
  * @property {TimeUnit} [timeUnit] - The optional time unit for the request.
497
498
  */
498
499
  interface RequestArgs {
499
500
  endpoint: string;
500
501
  method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
501
- params: Record<string, unknown>;
502
+ queryParams: Record<string, unknown>;
503
+ bodyParams: Record<string, unknown>;
502
504
  timeUnit?: TimeUnit;
503
505
  }
504
506
  //#endregion
@@ -559,7 +561,7 @@ declare const getSignature: (configuration: {
559
561
  apiSecret?: string;
560
562
  privateKey?: string | Buffer;
561
563
  privateKeyPassphrase?: string;
562
- }, queryParams: Record<string, unknown>) => string;
564
+ }, queryParams: Record<string, unknown>, bodyParams?: Record<string, unknown>) => string;
563
565
  /**
564
566
  * Asserts that a function parameter exists and is not null or undefined.
565
567
  *
@@ -641,7 +643,7 @@ declare const parseRateLimitHeaders: (headers: RawAxiosResponseHeaders | AxiosRe
641
643
  * @param options - Additional request options (isSigned).
642
644
  * @returns A promise resolving to the response data object.
643
645
  */
644
- declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH", params?: Record<string, unknown>, timeUnit?: TimeUnit, options?: {
646
+ declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH", queryParams?: Record<string, unknown>, bodyParams?: Record<string, unknown>, timeUnit?: TimeUnit, options?: {
645
647
  isSigned?: boolean;
646
648
  }) => Promise<RestApiResponse<T>>;
647
649
  /**
package/dist/index.js CHANGED
@@ -74,8 +74,8 @@ var RequestSigner = class {
74
74
  }
75
75
  throw new Error("Either 'apiSecret' or 'privateKey' must be provided for signed requests.");
76
76
  }
77
- sign(queryParams) {
78
- const params = buildQueryString(queryParams);
77
+ sign(queryParams, bodyParams) {
78
+ const params = buildQueryString(queryParams) + (bodyParams ? buildQueryString(bodyParams) : "");
79
79
  if (this.apiSecret) return crypto.default.createHmac("sha256", this.apiSecret).update(params).digest("hex");
80
80
  if (this.keyObject && this.keyType) {
81
81
  const data = Buffer.from(params);
@@ -175,13 +175,13 @@ function getTimestamp() {
175
175
  * @param queryParams - The query parameters to be signed.
176
176
  * @returns A string representing the generated signature.
177
177
  */
178
- const getSignature = function(configuration, queryParams) {
178
+ const getSignature = function(configuration, queryParams, bodyParams) {
179
179
  let signer = signerCache.get(configuration);
180
180
  if (!signer) {
181
181
  signer = new RequestSigner(configuration);
182
182
  signerCache.set(configuration, signer);
183
183
  }
184
- return signer.sign(queryParams);
184
+ return signer.sign(queryParams, bodyParams);
185
185
  };
186
186
  /**
187
187
  * Asserts that a function parameter exists and is not null or undefined.
@@ -425,19 +425,33 @@ const parseRateLimitHeaders = function(headers) {
425
425
  * @param options - Additional request options (isSigned).
426
426
  * @returns A promise resolving to the response data object.
427
427
  */
428
- const sendRequest = function(configuration, endpoint, method, params = {}, timeUnit, options = {}) {
428
+ const sendRequest = function(configuration, endpoint, method, queryParams = {}, bodyParams = {}, timeUnit, options = {}) {
429
429
  const localVarUrlObj = new URL(endpoint, configuration?.basePath);
430
430
  const localVarRequestOptions = {
431
431
  method,
432
432
  ...configuration?.baseOptions
433
433
  };
434
- const localVarQueryParameter = { ...normalizeScientificNumbers(params) };
434
+ const localVarQueryParameter = { ...normalizeScientificNumbers(queryParams) };
435
+ const localVarBodyParameter = { ...normalizeScientificNumbers(bodyParams) };
435
436
  if (options.isSigned) {
436
437
  localVarQueryParameter["timestamp"] = getTimestamp();
437
- const signature = getSignature(configuration, localVarQueryParameter);
438
+ const signature = getSignature(configuration, localVarQueryParameter, localVarBodyParameter);
438
439
  if (signature) localVarQueryParameter["signature"] = signature;
439
440
  }
440
441
  setSearchParams(localVarUrlObj, localVarQueryParameter);
442
+ if (Object.keys(localVarBodyParameter).length > 0) {
443
+ const searchParams = new URLSearchParams();
444
+ for (const [key, value] of Object.entries(localVarBodyParameter)) {
445
+ if (value === null || value === void 0) continue;
446
+ const serializedValue = serializeValue(value);
447
+ searchParams.append(key, serializedValue);
448
+ }
449
+ localVarRequestOptions.data = searchParams.toString();
450
+ localVarRequestOptions.headers = {
451
+ ...localVarRequestOptions.headers || {},
452
+ "Content-Type": "application/x-www-form-urlencoded"
453
+ };
454
+ }
441
455
  if (timeUnit && localVarRequestOptions.headers) {
442
456
  const _timeUnit = validateTimeUnit(timeUnit);
443
457
  localVarRequestOptions.headers = {