Skip to content

Commit

Permalink
GG-850 Update dependencies to fix vulnerabilities (#47)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
diegodrip authored Sep 12, 2024
1 parent 8206cc5 commit 872a464
Show file tree
Hide file tree
Showing 22 changed files with 1,150 additions and 932 deletions.
47 changes: 44 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const options = {

client.listSubscribers(options)
.then((response) => {
// do something with the raw response object or with `response.body`
// do something with the raw response object or with `response.data`
})
.catch((error) => {
// do something with the error
Expand All @@ -215,7 +215,7 @@ client.listSubscribers(options)
* Using a callback
*/

client.listSubscribers(options, (error, response, body) => {
client.listSubscribers(options, (error, response, data) => {
// do someting with the response or handle errors
});
```
Expand Down Expand Up @@ -272,12 +272,53 @@ var batch = {
}]
}

client.recordBatchEvents(batch, function (error, response, body) {
client.recordBatchEvents(batch, function (error, response, data) {
// Do stuff
}
)
```

## Changelog

### [3.1.2] - 2024-09-12

**Breaking Changes:**

- **Updated HTTP Client**: We have switched to a Axios client to improve performance and reliability.
- **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.

- Old: `response.body`
- New: `response.data`

Please update your code accordingly. Example update:

```js
// Old usage
const result = response.body;

// New usage
const result = response.data;

// EXAMPLE
const client = require('drip-nodejs')({ token: YOUR_API_KEY, accountId: YOUR_ACCOUNT_ID });
const payload = {
email: "[email protected]",
time_zone: "America/Los_Angeles",
custom_fields: {
shirt_size: "Medium"
}
};

client.createUpdateSubscriber(payload)
.then((response) => {
console.log(response.data)
})
.catch((error) => {
// Handle errors
});

```

## Contributing

1. Fork it ( https://github.com/samudary/drip-nodejs/fork )
Expand Down
44 changes: 20 additions & 24 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const requestPromise = require('request-promise');
const requestPromise = require('axios');

// Resources
const Accounts = require('./accounts');
Expand Down Expand Up @@ -45,8 +45,8 @@ class Client {
request(requestOptions, callback) {
if (callback) {
return requestPromise(requestOptions).then((response) => {
const { body } = response;
callback(null, response, body);
const { data } = response;
callback(null, response, data);
}).catch((error) => {
callback(error, null, null);
});
Expand All @@ -58,48 +58,44 @@ class Client {
return { [key]: args };
}

get(url, data, callback) {
get(resourcePath, data, callback) {
return this.request({
method: 'GET',
headers: this.requestHeaders(),
uri: helper.baseUrl + url,
qs: data.qs,
json: true,
resolveWithFullResponse: true
url: helper.baseUrl + resourcePath,
params: data.qs,
responseType: 'json'
}, callback);
}

post(url, data, callback) {
post(resourcePath, data, callback) {
return this.request({
method: 'POST',
headers: this.requestHeaders(),
uri: helper.baseUrl + url,
body: data,
qs: data.qs,
json: true,
resolveWithFullResponse: true
url: helper.baseUrl + resourcePath,
data: data,
params: data.qs,
responseType: 'json'
}, callback);
}

del(url, data, callback) {
del(resourcePath, data, callback) {
return this.request({
method: 'DELETE',
headers: this.requestHeaders(),
uri: helper.baseUrl + url,
json: true,
resolveWithFullResponse: true
url: helper.baseUrl + resourcePath,
responseType: 'json'
}, callback);
}

put(url, data, callback) {
put(resourcePath, data, callback) {
return this.request({
method: 'PUT',
headers: this.requestHeaders(),
uri: helper.baseUrl + url,
body: data,
qs: data.qs,
json: true,
resolveWithFullResponse: true
url: helper.baseUrl + resourcePath,
data: data,
params: data.qs,
responseType: 'json'
}, callback);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/subscribers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const request = require('request');
const request = require('axios');
const helpers = require('./helpers');

module.exports = {
Expand Down Expand Up @@ -106,8 +106,8 @@ module.exports = {
{
url: `${helpers.baseUrl}v2/${this.accountId}/subscribers/batches`,
headers,
json: true,
body: {
responseType: 'json',
data: {
batches: [{
subscribers: batch
}]
Expand Down
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '3.1.0';
module.exports = '3.1.2';
Loading

0 comments on commit 872a464

Please sign in to comment.