Skip to content

Commit d6087e2

Browse files
Merge pull request #352 from mercadopago/feature/add-headers
Feature: add new headers to request options
2 parents ebee5b0 + 218fce6 commit d6087e2

File tree

6 files changed

+51
-25
lines changed

6 files changed

+51
-25
lines changed

CHANGELOG.MD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Releases
22

3+
## VERSION 2.1.0
4+
5+
- Add `X-Expand-Response-Nodes` header to request options
6+
- Add `X-Card-Validation` header to request options
7+
- Add `X-Meli-Session-Id` header to request options
8+
39
## VERSION 2.0.15
410

511
- Include `reference_id` in Data in Payment Method in Payment

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mercadopago",
3-
"version": "2.0.15",
3+
"version": "2.1.0",
44
"description": "Mercadopago SDK for Node.js",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/types.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
export declare type Config = {
2-
accessToken: string;
3-
options?: Options;
2+
accessToken: string;
3+
options?: Options;
44
};
55

66
export declare type Options = {
7-
timeout?: number;
8-
idempotencyKey?: string;
9-
plataformId?: string;
10-
integratorId?: string;
11-
corporationId?: string;
7+
timeout?: number;
8+
idempotencyKey?: string;
9+
plataformId?: string;
10+
integratorId?: string;
11+
corporationId?: string;
12+
meliSessionId?: string;
13+
expandResponseNodes?: string;
14+
cardValidation?: string;
1215
};
1316

1417
export declare interface SearchOptions {
15-
limit?: number;
16-
offset?: number;
17-
[key: string]: string | number;
18+
limit?: number;
19+
offset?: number;
20+
[key: string]: string | number;
1821
}
1922

2023
export declare interface ApiResponse {
21-
api_response: ResponseFields;
24+
api_response: ResponseFields;
2225
}
2326

2427
export declare type ResponseFields = {
25-
status: number;
26-
headers: [string, string[]];
28+
status: number;
29+
headers: [string, string[]];
2730
};

src/utils/config/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class AppConfig {
55
static readonly BASE_URL = 'https://api.mercadopago.com';
66
static readonly PRODUCT_ID = 'bc32b6ntrpp001u8nhkg';
77

8-
static SDK_VERSION = '2.0.15';
8+
static SDK_VERSION = '2.1.0';
99

1010
static readonly Headers = {
1111
AUTHORIZATION: 'Authorization',
@@ -16,7 +16,10 @@ export class AppConfig {
1616
TRACKING_ID: 'X-Tracking-Id',
1717
CORPORATION_ID: 'X-Corporation-Id',
1818
INTEGRATOR_ID: 'X-Integrator-Id',
19-
PLATFORM_ID: 'X-Platform-Id'
19+
PLATFORM_ID: 'X-Platform-Id',
20+
MELI_SESSION_ID: 'X-Meli-Session-Id',
21+
EXPAND_RESPONSE_NODES: 'X-Expand-Response-Nodes',
22+
CARD_VALIDATION: 'X-Card-Validation',
2023
};
2124

2225
static getNodeVersion(): string {
@@ -32,7 +35,7 @@ export class AppConfig {
3235
}
3336

3437
static getTrackingId(): string {
35-
return 'platform:' + this.getNodeVersion().substring(0, this.getNodeVersion().indexOf('.')) + '|' + this.getNodeVersion() + ',type:SDK'+ this.SDK_VERSION + ',so;';
38+
return 'platform:' + this.getNodeVersion().substring(0, this.getNodeVersion().indexOf('.')) + '|' + this.getNodeVersion() + ',type:SDK' + this.SDK_VERSION + ',so;';
3639
}
3740

3841
static getUserAgent(): string {

src/utils/restClient/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { v4 as uuidv4 } from 'uuid';
55
import type { Options } from '@src/types';
66

77
interface RestClientConfig extends Options {
8-
queryParams?: Record<string, string | number>;
9-
retries?: number;
8+
queryParams?: Record<string, string | number>;
9+
retries?: number;
1010
}
1111

1212
class RestClient {
@@ -66,6 +66,9 @@ class RestClient {
6666
corporationId,
6767
integratorId,
6868
plataformId,
69+
meliSessionId,
70+
expandResponseNodes,
71+
cardValidation,
6972
...customConfig
7073
} = config || {};
7174

@@ -79,6 +82,9 @@ class RestClient {
7982
...(corporationId ? { [AppConfig.Headers.CORPORATION_ID]: corporationId } : {}),
8083
...(integratorId ? { [AppConfig.Headers.INTEGRATOR_ID]: integratorId } : {}),
8184
...(plataformId ? { [AppConfig.Headers.PLATFORM_ID]: plataformId } : {}),
85+
...(meliSessionId ? { [AppConfig.Headers.MELI_SESSION_ID]: meliSessionId } : {}),
86+
...(expandResponseNodes ? { [AppConfig.Headers.EXPAND_RESPONSE_NODES]: expandResponseNodes } : {}),
87+
...(cardValidation ? { [AppConfig.Headers.CARD_VALIDATION]: cardValidation } : {}),
8288
};
8389

8490
if (method && method !== 'GET') {

src/utils/restClient/restClient.spec.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ describe('RestClient', () => {
8383
expect(fetch).toHaveBeenCalledTimes(retries);
8484
expect(response).toEqual({
8585
success: true,
86-
api_response: {
87-
headers: {
86+
api_response: {
87+
headers: {
8888
'Content-Type': [
8989
'text/plain;charset=UTF-8',
9090
],
@@ -98,12 +98,17 @@ describe('RestClient', () => {
9898
(fetch as jest.MockedFunction<typeof fetch>).mockResolvedValue(
9999
new Response(JSON.stringify({ success: true }), { url: 'url', status: 200, statusText: 'OK' })
100100
);
101-
102101
const customHeaders = {
103102
Authorization: 'Bearer Token123',
104103
};
105104
const endpoint = '/test-custom-headers';
106-
await RestClient.fetch(endpoint, { headers: customHeaders });
105+
106+
await RestClient.fetch(endpoint, {
107+
headers: customHeaders,
108+
expandResponseNodes: 'gateway.reference',
109+
cardValidation: 'card_validation',
110+
meliSessionId: 'device_id',
111+
});
107112

108113
expect(fetch).toHaveBeenCalledWith(expect.any(String), {
109114
method: 'GET',
@@ -114,6 +119,9 @@ describe('RestClient', () => {
114119
'User-Agent': expect.any(String),
115120
'X-Product-Id': expect.any(String),
116121
'X-Tracking-Id': expect.any(String),
122+
'X-Meli-Session-Id': 'device_id',
123+
'X-Expand-Response-Nodes': 'gateway.reference',
124+
'X-Card-Validation': 'card_validation',
117125
},
118126
});
119127
});
@@ -181,8 +189,8 @@ describe('RestClient', () => {
181189
expect(fetch).toHaveBeenCalledTimes(4);
182190
expect(response).toEqual({
183191
success: true,
184-
api_response: {
185-
headers: {
192+
api_response: {
193+
headers: {
186194
'Content-Type': [
187195
'text/plain;charset=UTF-8',
188196
],

0 commit comments

Comments
 (0)