diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 00499d20..24a93b8a 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,5 +1,11 @@ # Releases +## VERSION 2.1.0 + +- Add `X-Expand-Response-Nodes` header to request options +- Add `X-Card-Validation` header to request options +- Add `X-Meli-Session-Id` header to request options + ## VERSION 2.0.15 - Include `reference_id` in Data in Payment Method in Payment diff --git a/package.json b/package.json index beb3ec9a..08f9d491 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mercadopago", - "version": "2.0.15", + "version": "2.1.0", "description": "Mercadopago SDK for Node.js", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/types.ts b/src/types.ts index f7b664c8..240273aa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,27 +1,30 @@ export declare type Config = { - accessToken: string; - options?: Options; + accessToken: string; + options?: Options; }; export declare type Options = { - timeout?: number; - idempotencyKey?: string; - plataformId?: string; - integratorId?: string; - corporationId?: string; + timeout?: number; + idempotencyKey?: string; + plataformId?: string; + integratorId?: string; + corporationId?: string; + meliSessionId?: string; + expandResponseNodes?: string; + cardValidation?: string; }; export declare interface SearchOptions { - limit?: number; - offset?: number; - [key: string]: string | number; + limit?: number; + offset?: number; + [key: string]: string | number; } export declare interface ApiResponse { - api_response: ResponseFields; + api_response: ResponseFields; } export declare type ResponseFields = { - status: number; - headers: [string, string[]]; + status: number; + headers: [string, string[]]; }; diff --git a/src/utils/config/index.ts b/src/utils/config/index.ts index 499f05c7..8456da54 100644 --- a/src/utils/config/index.ts +++ b/src/utils/config/index.ts @@ -5,7 +5,7 @@ export class AppConfig { static readonly BASE_URL = 'https://api.mercadopago.com'; static readonly PRODUCT_ID = 'bc32b6ntrpp001u8nhkg'; - static SDK_VERSION = '2.0.15'; + static SDK_VERSION = '2.1.0'; static readonly Headers = { AUTHORIZATION: 'Authorization', @@ -16,7 +16,10 @@ export class AppConfig { TRACKING_ID: 'X-Tracking-Id', CORPORATION_ID: 'X-Corporation-Id', INTEGRATOR_ID: 'X-Integrator-Id', - PLATFORM_ID: 'X-Platform-Id' + PLATFORM_ID: 'X-Platform-Id', + MELI_SESSION_ID: 'X-Meli-Session-Id', + EXPAND_RESPONSE_NODES: 'X-Expand-Response-Nodes', + CARD_VALIDATION: 'X-Card-Validation', }; static getNodeVersion(): string { @@ -32,7 +35,7 @@ export class AppConfig { } static getTrackingId(): string { - return 'platform:' + this.getNodeVersion().substring(0, this.getNodeVersion().indexOf('.')) + '|' + this.getNodeVersion() + ',type:SDK'+ this.SDK_VERSION + ',so;'; + return 'platform:' + this.getNodeVersion().substring(0, this.getNodeVersion().indexOf('.')) + '|' + this.getNodeVersion() + ',type:SDK' + this.SDK_VERSION + ',so;'; } static getUserAgent(): string { diff --git a/src/utils/restClient/index.ts b/src/utils/restClient/index.ts index 596c2012..bcb37a7c 100644 --- a/src/utils/restClient/index.ts +++ b/src/utils/restClient/index.ts @@ -5,8 +5,8 @@ import { v4 as uuidv4 } from 'uuid'; import type { Options } from '@src/types'; interface RestClientConfig extends Options { - queryParams?: Record; - retries?: number; + queryParams?: Record; + retries?: number; } class RestClient { @@ -66,6 +66,9 @@ class RestClient { corporationId, integratorId, plataformId, + meliSessionId, + expandResponseNodes, + cardValidation, ...customConfig } = config || {}; @@ -79,6 +82,9 @@ class RestClient { ...(corporationId ? { [AppConfig.Headers.CORPORATION_ID]: corporationId } : {}), ...(integratorId ? { [AppConfig.Headers.INTEGRATOR_ID]: integratorId } : {}), ...(plataformId ? { [AppConfig.Headers.PLATFORM_ID]: plataformId } : {}), + ...(meliSessionId ? { [AppConfig.Headers.MELI_SESSION_ID]: meliSessionId } : {}), + ...(expandResponseNodes ? { [AppConfig.Headers.EXPAND_RESPONSE_NODES]: expandResponseNodes } : {}), + ...(cardValidation ? { [AppConfig.Headers.CARD_VALIDATION]: cardValidation } : {}), }; if (method && method !== 'GET') { diff --git a/src/utils/restClient/restClient.spec.ts b/src/utils/restClient/restClient.spec.ts index 08c639ea..97c01268 100644 --- a/src/utils/restClient/restClient.spec.ts +++ b/src/utils/restClient/restClient.spec.ts @@ -83,8 +83,8 @@ describe('RestClient', () => { expect(fetch).toHaveBeenCalledTimes(retries); expect(response).toEqual({ success: true, - api_response: { - headers: { + api_response: { + headers: { 'Content-Type': [ 'text/plain;charset=UTF-8', ], @@ -98,12 +98,17 @@ describe('RestClient', () => { (fetch as jest.MockedFunction).mockResolvedValue( new Response(JSON.stringify({ success: true }), { url: 'url', status: 200, statusText: 'OK' }) ); - const customHeaders = { Authorization: 'Bearer Token123', }; const endpoint = '/test-custom-headers'; - await RestClient.fetch(endpoint, { headers: customHeaders }); + + await RestClient.fetch(endpoint, { + headers: customHeaders, + expandResponseNodes: 'gateway.reference', + cardValidation: 'card_validation', + meliSessionId: 'device_id', + }); expect(fetch).toHaveBeenCalledWith(expect.any(String), { method: 'GET', @@ -114,6 +119,9 @@ describe('RestClient', () => { 'User-Agent': expect.any(String), 'X-Product-Id': expect.any(String), 'X-Tracking-Id': expect.any(String), + 'X-Meli-Session-Id': 'device_id', + 'X-Expand-Response-Nodes': 'gateway.reference', + 'X-Card-Validation': 'card_validation', }, }); }); @@ -181,8 +189,8 @@ describe('RestClient', () => { expect(fetch).toHaveBeenCalledTimes(4); expect(response).toEqual({ success: true, - api_response: { - headers: { + api_response: { + headers: { 'Content-Type': [ 'text/plain;charset=UTF-8', ],