Skip to content

Commit 872a464

Browse files
authored
GG-850 Update dependencies to fix vulnerabilities (#47)
* update dependencies to fix vulnerabilities * bump version * update dependencies * key fix in request param * update axios request/response property from body to data * update readme * fix vulnerabilities and update properties
1 parent 8206cc5 commit 872a464

22 files changed

Lines changed: 1150 additions & 932 deletions

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const options = {
205205

206206
client.listSubscribers(options)
207207
.then((response) => {
208-
// do something with the raw response object or with `response.body`
208+
// do something with the raw response object or with `response.data`
209209
})
210210
.catch((error) => {
211211
// do something with the error
@@ -215,7 +215,7 @@ client.listSubscribers(options)
215215
* Using a callback
216216
*/
217217

218-
client.listSubscribers(options, (error, response, body) => {
218+
client.listSubscribers(options, (error, response, data) => {
219219
// do someting with the response or handle errors
220220
});
221221
```
@@ -272,12 +272,53 @@ var batch = {
272272
}]
273273
}
274274

275-
client.recordBatchEvents(batch, function (error, response, body) {
275+
client.recordBatchEvents(batch, function (error, response, data) {
276276
// Do stuff
277277
}
278278
)
279279
```
280280

281+
## Changelog
282+
283+
### [3.1.2] - 2024-09-12
284+
285+
**Breaking Changes:**
286+
287+
- **Updated HTTP Client**: We have switched to a Axios client to improve performance and reliability.
288+
- **Property Name Change**: The `body` property in responses has been renamed to `data` to ensure compatibility with the new client and align with modern conventions.
289+
290+
- Old: `response.body`
291+
- New: `response.data`
292+
293+
Please update your code accordingly. Example update:
294+
295+
```js
296+
// Old usage
297+
const result = response.body;
298+
299+
// New usage
300+
const result = response.data;
301+
302+
// EXAMPLE
303+
const client = require('drip-nodejs')({ token: YOUR_API_KEY, accountId: YOUR_ACCOUNT_ID });
304+
const payload = {
305+
email: "john@acme.com",
306+
time_zone: "America/Los_Angeles",
307+
custom_fields: {
308+
shirt_size: "Medium"
309+
}
310+
};
311+
312+
client.createUpdateSubscriber(payload)
313+
.then((response) => {
314+
console.log(response.data)
315+
})
316+
.catch((error) => {
317+
// Handle errors
318+
});
319+
320+
```
321+
281322
## Contributing
282323

283324
1. Fork it ( https://github.com/samudary/drip-nodejs/fork )

lib/index.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const requestPromise = require('request-promise');
1+
const requestPromise = require('axios');
22

33
// Resources
44
const Accounts = require('./accounts');
@@ -45,8 +45,8 @@ class Client {
4545
request(requestOptions, callback) {
4646
if (callback) {
4747
return requestPromise(requestOptions).then((response) => {
48-
const { body } = response;
49-
callback(null, response, body);
48+
const { data } = response;
49+
callback(null, response, data);
5050
}).catch((error) => {
5151
callback(error, null, null);
5252
});
@@ -58,48 +58,44 @@ class Client {
5858
return { [key]: args };
5959
}
6060

61-
get(url, data, callback) {
61+
get(resourcePath, data, callback) {
6262
return this.request({
6363
method: 'GET',
6464
headers: this.requestHeaders(),
65-
uri: helper.baseUrl + url,
66-
qs: data.qs,
67-
json: true,
68-
resolveWithFullResponse: true
65+
url: helper.baseUrl + resourcePath,
66+
params: data.qs,
67+
responseType: 'json'
6968
}, callback);
7069
}
7170

72-
post(url, data, callback) {
71+
post(resourcePath, data, callback) {
7372
return this.request({
7473
method: 'POST',
7574
headers: this.requestHeaders(),
76-
uri: helper.baseUrl + url,
77-
body: data,
78-
qs: data.qs,
79-
json: true,
80-
resolveWithFullResponse: true
75+
url: helper.baseUrl + resourcePath,
76+
data: data,
77+
params: data.qs,
78+
responseType: 'json'
8179
}, callback);
8280
}
8381

84-
del(url, data, callback) {
82+
del(resourcePath, data, callback) {
8583
return this.request({
8684
method: 'DELETE',
8785
headers: this.requestHeaders(),
88-
uri: helper.baseUrl + url,
89-
json: true,
90-
resolveWithFullResponse: true
86+
url: helper.baseUrl + resourcePath,
87+
responseType: 'json'
9188
}, callback);
9289
}
9390

94-
put(url, data, callback) {
91+
put(resourcePath, data, callback) {
9592
return this.request({
9693
method: 'PUT',
9794
headers: this.requestHeaders(),
98-
uri: helper.baseUrl + url,
99-
body: data,
100-
qs: data.qs,
101-
json: true,
102-
resolveWithFullResponse: true
95+
url: helper.baseUrl + resourcePath,
96+
data: data,
97+
params: data.qs,
98+
responseType: 'json'
10399
}, callback);
104100
}
105101
}

lib/subscribers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const request = require('request');
1+
const request = require('axios');
22
const helpers = require('./helpers');
33

44
module.exports = {
@@ -106,8 +106,8 @@ module.exports = {
106106
{
107107
url: `${helpers.baseUrl}v2/${this.accountId}/subscribers/batches`,
108108
headers,
109-
json: true,
110-
body: {
109+
responseType: 'json',
110+
data: {
111111
batches: [{
112112
subscribers: batch
113113
}]

lib/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = '3.1.0';
1+
module.exports = '3.1.2';

0 commit comments

Comments
 (0)