Skip to content

Commit

Permalink
Remove dependency request from package.json
Browse files Browse the repository at this point in the history
Summary:
[BizSDK][NodeJS] Remove dependency request from package.json

`request` package has long been deprecated and shall be replaced.

Remove `request` and `request-promise` dependencies. Use `axios` as a replacement.

Update `api.js` and `http.js` during migration.

Set `response` to `response.data` due to the return format of Axios response format change. Known issue axios/axios#5332.

Reviewed By: mengxuanzhangz

Differential Revision: D48271770

fbshipit-source-id: f22e5e336cbf9f69cdd597fea62ca08822ce72fd
  • Loading branch information
stcheng authored and facebook-github-bot committed Aug 14, 2023
1 parent d539b83 commit a2d64d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
7 changes: 3 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "facebook-nodejs-business-sdk",
"version": "17.0.2",
"version": "17.0.3",
"description": "SDK for the Facebook Ads API in Javascript and Node.js",
"author": "Facebook",
"maintainers": [
Expand Down Expand Up @@ -30,12 +30,11 @@
"url": "git://github.com/facebook/facebook-nodejs-business-sdk.git"
},
"dependencies": {
"axios": "^1.4.0",
"currency-codes": "^1.5.1",
"iso-3166-1": "^2.1.1",
"js-sha256": "^0.9.0",
"mixwith": "~0.1.1",
"request": "^2.88.0",
"request-promise": "~4.1.1"
"mixwith": "~0.1.1"
},
"devDependencies": {
"babel-cli": "^6.24.1",
Expand Down
7 changes: 4 additions & 3 deletions src/api.js
Expand Up @@ -24,7 +24,7 @@ export default class FacebookAdsApi {
return 'v17.0';
}
static get SDK_VERSION(): string {
return '17.0.1';
return '17.0.3';
}
static get GRAPH(): string {
return 'https://graph.facebook.com';
Expand Down Expand Up @@ -126,10 +126,11 @@ export default class FacebookAdsApi {
return Http.request(method, strUrl, data, files, useMultipartFormData, this._showHeader)
.then(response => {
if (this._showHeader) {
response.body['headers'] = response.headers;
response = response.body;
response.data['headers'] = response.headers;
}

response = response.data;

if (this._debug) {
console.log(`200 ${method} ${url} ${Object.keys(data).length > 0 ? JSON.stringify(data) : ""}`);
console.log(
Expand Down
15 changes: 8 additions & 7 deletions src/http.js
Expand Up @@ -9,7 +9,7 @@
*/
import Api from './api';
import HTTP_STATUS from './http-status';
const requestPromise = require('request-promise');
const axios = require("axios");

/**
* Isomorphic Http Promise Requests Class
Expand Down Expand Up @@ -100,10 +100,11 @@ export default class Http {
): Promise<*> {
const options = {
method: method,
uri: url,
url: url,
baseURL: Api.GRAPH,
json: !useMultipartFormData,
headers: {'User-Agent': `fbbizsdk-nodejs-v${Api.SDK_VERSION}`},
body: Object,
data: Object,
resolveWithFullResponse: showHeader,
};
// Prevent null or undefined input
Expand All @@ -112,16 +113,16 @@ export default class Http {
data = {};
}

options.body = data;
options.data = data;

// Handle file attachments if provided
if (useMultipartFormData || (files && Object.keys(files).length > 0)) {
// Use formData instead of body (required by the request-promise library)
options.formData = Object.assign(data, files);
delete options.body;
options.data = Object.assign(data, files);
delete options.data;
}

return requestPromise(options).catch((response: Object) => {
return axios(options).catch((response: Object) => {
throw response;
});
}
Expand Down

0 comments on commit a2d64d9

Please sign in to comment.