Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
restore deprecated request for backwards compatibility, use http with…
Browse files Browse the repository at this point in the history
… special expansion
  • Loading branch information
taylordowns2000 committed Jan 26, 2021
1 parent 4aaa5bb commit 744bebe
Show file tree
Hide file tree
Showing 5 changed files with 4,063 additions and 53 deletions.
40 changes: 33 additions & 7 deletions lib/Adaptor.js
Expand Up @@ -11,6 +11,7 @@ exports.patch = patch;
exports.del = del;
exports.parseXML = parseXML;
exports.parseCSV = parseCSV;
exports.request = request;
Object.defineProperty(exports, "alterState", {
enumerable: true,
get: function () {
Expand Down Expand Up @@ -76,6 +77,8 @@ var _Utils = require("./Utils");

var _languageCommon = require("@openfn/language-common");

var _request = _interopRequireDefault(require("request"));

var _cheerio = _interopRequireDefault(require("cheerio"));

var _cheerioTableparser = _interopRequireDefault(require("cheerio-tableparser"));
Expand Down Expand Up @@ -229,13 +232,8 @@ function post(path, params, callback) {
const config = (0, _Utils.mapToAxiosConfig)({ ...params,
url,
auth
}); // NOTE: that in order to use multipart/form submissions, we call axios.post
// directly so as to avoid calling 'expandReferences' on the config (in
// language-common.http.post) once we've set up the 'form-data' module.
// Elsewhere, calling expandReferences multiple times is harmless.

return axios.post(config.url, config.data, { ...config
}).then(response => {
});
return _languageCommon.http.post(config)(state).then(response => {
const nextState = (0, _languageCommon.composeNextState)(state, response.data);
if (callback) return callback(nextState);
return nextState;
Expand Down Expand Up @@ -447,3 +445,31 @@ function parseCSV(target, config) {
});
};
}
/**
* Make a request using the 'request' node module. This module is deprecated.
* @example
* request(params);
* @function
* @param {object} params - Query, Headers and Authentication parameters
* @returns {Operation}
*/


function request(params) {
return state => {
params = (0, _languageCommon.expandReferences)(params)(state);
return new Promise((resolve, reject) => {
(0, _request.default)(params, (error, response, body) => {
error = (0, _Utils.assembleError)({
error,
response,
params
});
error && reject(error);
console.log('✓ Request succeeded. (The response body available in state.)');
const resp = (0, _Utils.tryJson)(body);
resolve(resp);
});
});
};
}

0 comments on commit 744bebe

Please sign in to comment.