From 0581890243914b0023516d390e01f9fc8b7bc584 Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Tue, 14 Apr 2020 21:27:10 -0600 Subject: [PATCH] keep headers when keepCookies is set to true, allows token auth --- README.md | 2 +- lib/Adaptor.js | 141 ++++++++++++++++++++++++++-------------------- lib/Client.js | 54 +++++++++++------- lib/Utils.js | 10 +++- lib/index.js | 18 +++--- package-lock.json | 57 +++++++++++-------- package.json | 8 +-- src/Adaptor.js | 42 ++++++++------ src/Client.js | 1 + 9 files changed, 192 insertions(+), 141 deletions(-) diff --git a/README.md b/README.md index 28dbd32..923c04e 100644 --- a/README.md +++ b/README.md @@ -92,4 +92,4 @@ Clone the repo, run `npm install`. Run tests using `npm run test` or `npm run test:watch` -Build the project using `make`. +Build the project using `make`. \ No newline at end of file diff --git a/lib/Adaptor.js b/lib/Adaptor.js index cc2d86b..bec8acd 100644 --- a/lib/Adaptor.js +++ b/lib/Adaptor.js @@ -1,13 +1,8 @@ -'use strict'; +"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.sourceValue = exports.merge = exports.lastReferenceValue = exports.fields = exports.field = exports.each = exports.dataValue = exports.dataPath = exports.alterState = undefined; - -var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** @module Adaptor */ - - exports.execute = execute; exports.get = get; exports.post = post; @@ -17,87 +12,86 @@ exports.del = del; exports.parseXML = parseXML; exports.parseCSV = parseCSV; exports.request = request; - -var _languageCommon = require('language-common'); - -Object.defineProperty(exports, 'alterState', { +Object.defineProperty(exports, "alterState", { enumerable: true, get: function get() { return _languageCommon.alterState; } }); -Object.defineProperty(exports, 'dataPath', { +Object.defineProperty(exports, "dataPath", { enumerable: true, get: function get() { return _languageCommon.dataPath; } }); -Object.defineProperty(exports, 'dataValue', { +Object.defineProperty(exports, "dataValue", { enumerable: true, get: function get() { return _languageCommon.dataValue; } }); -Object.defineProperty(exports, 'each', { +Object.defineProperty(exports, "each", { enumerable: true, get: function get() { return _languageCommon.each; } }); -Object.defineProperty(exports, 'field', { +Object.defineProperty(exports, "field", { enumerable: true, get: function get() { return _languageCommon.field; } }); -Object.defineProperty(exports, 'fields', { +Object.defineProperty(exports, "fields", { enumerable: true, get: function get() { return _languageCommon.fields; } }); -Object.defineProperty(exports, 'lastReferenceValue', { +Object.defineProperty(exports, "lastReferenceValue", { enumerable: true, get: function get() { return _languageCommon.lastReferenceValue; } }); -Object.defineProperty(exports, 'merge', { +Object.defineProperty(exports, "merge", { enumerable: true, get: function get() { return _languageCommon.merge; } }); -Object.defineProperty(exports, 'sourceValue', { +Object.defineProperty(exports, "sourceValue", { enumerable: true, get: function get() { return _languageCommon.sourceValue; } }); -var _Client = require('./Client'); +var _Client = require("./Client"); + +var _Utils = require("./Utils"); -var _Utils = require('./Utils'); +var _languageCommon = require("language-common"); -var _cheerio = require('cheerio'); +var _cheerio = _interopRequireDefault(require("cheerio")); -var _cheerio2 = _interopRequireDefault(_cheerio); +var _cheerioTableparser = _interopRequireDefault(require("cheerio-tableparser")); -var _cheerioTableparser = require('cheerio-tableparser'); +var _fs = _interopRequireDefault(require("fs")); -var _cheerioTableparser2 = _interopRequireDefault(_cheerioTableparser); +var _csvParse = _interopRequireDefault(require("csv-parse")); -var _fs = require('fs'); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } -var _fs2 = _interopRequireDefault(_fs); +function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } -var _csvParse = require('csv-parse'); +function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } -var _csvParse2 = _interopRequireDefault(_csvParse); +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } -function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /** * Execute a sequence of operations. @@ -112,7 +106,7 @@ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in ob * @returns {Operation} */ function execute() { - for (var _len = arguments.length, operations = Array(_len), _key = 0; _key < _len; _key++) { + for (var _len = arguments.length, operations = new Array(_len), _key = 0; _key < _len; _key++) { operations[_key] = arguments[_key]; } @@ -120,12 +114,10 @@ function execute() { references: [], data: null }; - return function (state) { - return _languageCommon.execute.apply(undefined, operations)(_extends({}, initialState, state)); + return _languageCommon.execute.apply(void 0, operations)(_objectSpread({}, initialState, {}, state)); }; } - /** * Make a GET request * @public @@ -145,6 +137,8 @@ function execute() { * @param {function} callback - (Optional) Callback function * @returns {Operation} */ + + function get(path, params, callback) { return function (state) { var url = (0, _Utils.setUrl)(state.configuration, path); @@ -153,18 +147,25 @@ function get(path, params, callback) { query = _expandReferences.query, headers = _expandReferences.headers, authentication = _expandReferences.authentication, - rest = _objectWithoutProperties(_expandReferences, ['query', 'headers', 'authentication']); + body = _expandReferences.body, + formData = _expandReferences.formData, + options = _expandReferences.options, + rest = _objectWithoutProperties(_expandReferences, ["query", "headers", "authentication", "body", "formData", "options"]); var auth = (0, _Utils.setAuth)(state.configuration, authentication); - - return (0, _Client.req)('GET', { url: url, query: query, auth: auth, headers: headers, rest: rest }).then(function (response) { + return (0, _Client.req)('GET', { + url: url, + query: query, + auth: auth, + headers: headers, + rest: rest + }).then(function (response) { var nextState = (0, _languageCommon.composeNextState)(state, response); if (callback) return callback(nextState); return nextState; }); }; } - /** * Make a POST request * @public @@ -184,6 +185,8 @@ function get(path, params, callback) { * @param {function} callback - (Optional) Callback function * @returns {Operation} */ + + function post(path, params, callback) { return function (state) { var url = (0, _Utils.setUrl)(state.configuration, path); @@ -195,10 +198,9 @@ function post(path, params, callback) { body = _expandReferences2.body, formData = _expandReferences2.formData, options = _expandReferences2.options, - rest = _objectWithoutProperties(_expandReferences2, ['query', 'headers', 'authentication', 'body', 'formData', 'options']); + rest = _objectWithoutProperties(_expandReferences2, ["query", "headers", "authentication", "body", "formData", "options"]); var auth = (0, _Utils.setAuth)(state.configuration, authentication); - return (0, _Client.req)('POST', { url: url, query: query, @@ -215,7 +217,6 @@ function post(path, params, callback) { }); }; } - /** * Make a PUT request * @public @@ -235,6 +236,8 @@ function post(path, params, callback) { * @param {function} callback - (Optional) Callback function * @returns {Operation} */ + + function put(path, params, callback) { return function (state) { var url = (0, _Utils.setUrl)(state.configuration, path); @@ -246,10 +249,9 @@ function put(path, params, callback) { body = _expandReferences3.body, formData = _expandReferences3.formData, options = _expandReferences3.options, - rest = _objectWithoutProperties(_expandReferences3, ['query', 'headers', 'authentication', 'body', 'formData', 'options']); + rest = _objectWithoutProperties(_expandReferences3, ["query", "headers", "authentication", "body", "formData", "options"]); var auth = (0, _Utils.setAuth)(state.configuration, authentication); - return (0, _Client.req)('PUT', { url: url, query: query, @@ -266,7 +268,6 @@ function put(path, params, callback) { }); }; } - /** * Make a PATCH request * @public @@ -286,6 +287,8 @@ function put(path, params, callback) { * @param {function} callback - (Optional) Callback function * @returns {Operation} */ + + function patch(path, params, callback) { return function (state) { var url = (0, _Utils.setUrl)(state.configuration, path); @@ -297,10 +300,9 @@ function patch(path, params, callback) { body = _expandReferences4.body, formData = _expandReferences4.formData, options = _expandReferences4.options, - rest = _objectWithoutProperties(_expandReferences4, ['query', 'headers', 'authentication', 'body', 'formData', 'options']); + rest = _objectWithoutProperties(_expandReferences4, ["query", "headers", "authentication", "body", "formData", "options"]); var auth = (0, _Utils.setAuth)(state.configuration, authentication); - return (0, _Client.req)('PATCH', { url: url, query: query, @@ -317,7 +319,6 @@ function patch(path, params, callback) { }); }; } - /** * Make a DELETE request * @public @@ -337,6 +338,8 @@ function patch(path, params, callback) { * @param {function} callback - (Optional) Callback function * @returns {Operation} */ + + function del(path, params, callback) { return function (state) { var url = (0, _Utils.setUrl)(state.configuration, path); @@ -348,10 +351,9 @@ function del(path, params, callback) { body = _expandReferences5.body, formData = _expandReferences5.formData, options = _expandReferences5.options, - rest = _objectWithoutProperties(_expandReferences5, ['query', 'headers', 'authentication', 'body', 'formData', 'options']); + rest = _objectWithoutProperties(_expandReferences5, ["query", "headers", "authentication", "body", "formData", "options"]); var auth = (0, _Utils.setAuth)(state.configuration, authentication); - return (0, _Client.req)('DELETE', { url: url, query: query, @@ -368,7 +370,6 @@ function del(path, params, callback) { }); }; } - /** * Cheerio parser for XML and HTML * @public @@ -381,25 +382,32 @@ function del(path, params, callback) { * @param {function} script - script for extracting data * @returns {Operation} */ + + function parseXML(body, script) { return function (state) { - var $ = _cheerio2.default.load(body); - (0, _cheerioTableparser2.default)($); + var $ = _cheerio["default"].load(body); + + (0, _cheerioTableparser["default"])($); if (script) { var result = script($); + try { var r = JSON.parse(result); return (0, _languageCommon.composeNextState)(state, r); } catch (e) { - return (0, _languageCommon.composeNextState)(state, { body: result }); + return (0, _languageCommon.composeNextState)(state, { + body: result + }); } } else { - return (0, _languageCommon.composeNextState)(state, { body: body }); + return (0, _languageCommon.composeNextState)(state, { + body: body + }); } }; } - /** * CSV-Parse for CSV conversion to JSON * @public @@ -413,35 +421,43 @@ function parseXML(body, script) { * @param {Object} config - PapaParse config object * @returns {Operation} */ + + function parseCSV(target, config) { return function (state) { return new Promise(function (resolve, reject) { var csvData = []; try { - _fs2.default.readFileSync(target); - _fs2.default.createReadStream(target).pipe((0, _csvParse2.default)(config)).on('data', function (csvrow) { + _fs["default"].readFileSync(target); + + _fs["default"].createReadStream(target).pipe((0, _csvParse["default"])(config)).on('data', function (csvrow) { csvData.push(csvrow); }).on('end', function () { console.log(csvData); - resolve((0, _languageCommon.composeNextState)(state, { records: csvData })); + resolve((0, _languageCommon.composeNextState)(state, { + records: csvData + })); }); } catch (err) { var csvString; + if (typeof target === 'string') { csvString = target; } else { csvString = (0, _languageCommon.expandReferences)(target)(state); } - csvData = (0, _csvParse2.default)(csvString, config, function (err, output) { + + csvData = (0, _csvParse["default"])(csvString, config, function (err, output) { console.log(output); - resolve((0, _languageCommon.composeNextState)(state, { records: output })); + resolve((0, _languageCommon.composeNextState)(state, { + records: output + })); }); } }); }; } - /** * Make a request using the 'request' node module. * @public @@ -451,10 +467,11 @@ function parseCSV(target, config) { * @param {object} params - Query, Headers and Authentication parameters * @returns {Operation} */ + + function request(params) { return function (state) { var expanded = typeof params === 'string' ? params : (0, _languageCommon.expandReferences)(params)(state); - return (0, _Client.rawRequest)(expanded); }; } diff --git a/lib/Client.js b/lib/Client.js index 9396492..0183a07 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1,30 +1,34 @@ -'use strict'; +"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - -var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; - exports.rawRequest = rawRequest; exports.req = req; -var _request = require('request'); +var _request = _interopRequireDefault(require("request")); + +var _Utils = require("./Utils"); -var _request2 = _interopRequireDefault(_request); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } -var _Utils = require('./Utils'); +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function rawRequest(params) { return new Promise(function (resolve, reject) { - (0, _request2.default)(params, function (error, response, body) { - error = (0, _Utils.assembleError)({ error: error, response: response, params: params }); + (0, _request["default"])(params, function (error, response, body) { + error = (0, _Utils.assembleError)({ + error: error, + response: response, + params: params + }); error && reject(error); - - console.log('\u2713 Request succeeded.'); - console.log('Server responded with: \n' + JSON.stringify(response, null, 2)); + console.log("\u2713 Request succeeded."); + console.log("Server responded with: \n".concat(JSON.stringify(response, null, 2))); var resp = (0, _Utils.tryJson)(body); resolve(resp); }); @@ -40,10 +44,10 @@ function req(method, params) { query = params.query, options = params.options, rest = params.rest; - return new Promise(function (resolve, reject) { - var j = _request2.default.jar(); - (0, _request2.default)(_extends({ + var j = _request["default"].jar(); + + (0, _request["default"])(_objectSpread({ url: url, headers: headers, auth: auth, @@ -55,17 +59,25 @@ function req(method, params) { options: options }, rest), function (error, response, body) { console.log(params); - error = (0, _Utils.assembleError)({ error: error, response: response, params: params }); + error = (0, _Utils.assembleError)({ + error: error, + response: response, + params: params + }); + if (error) { reject(error); } else { - console.log('\u2713 ' + method + ' succeeded.'); - console.log('Server responded with: \n' + JSON.stringify(response, null, 2)); + console.log("\u2713 ".concat(method, " succeeded.")); + console.log("Server responded with: \n".concat(JSON.stringify(response, null, 2))); var resp = (0, _Utils.tryJson)(body); + if (rest.keepCookie) { var __cookie = j.getCookieString(url); - resolve(_extends({ - __cookie: __cookie + + resolve(_objectSpread({ + __cookie: __cookie, + __headers: response.headers }, resp)); } else { resolve(resp); diff --git a/lib/Utils.js b/lib/Utils.js index 37fe922..4ad7b70 100644 --- a/lib/Utils.js +++ b/lib/Utils.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; Object.defineProperty(exports, "__esModule", { value: true @@ -7,6 +7,7 @@ exports.setUrl = setUrl; exports.setAuth = setAuth; exports.assembleError = assembleError; exports.tryJson = tryJson; + function setUrl(configuration, path) { if (configuration && configuration.baseUrl) return configuration.baseUrl + path;else return path; } @@ -28,14 +29,17 @@ function assembleError(_ref) { var customCodes = params.options && params.options.successCodes; if ((customCodes || [200, 201, 202]).indexOf(response.statusCode) > -1) return false; } + if (error) return error; - return new Error('Server responded with: \n' + JSON.stringify(response, null, 2)); + return new Error("Server responded with: \n".concat(JSON.stringify(response, null, 2))); } function tryJson(data) { try { return JSON.parse(data); } catch (e) { - return { body: data }; + return { + body: data + }; } } diff --git a/lib/index.js b/lib/index.js index 3c3046a..e5762ef 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,15 +1,19 @@ -'use strict'; +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); -exports.Adaptor = undefined; +exports.Adaptor = exports["default"] = void 0; + +var Adaptor = _interopRequireWildcard(require("./Adaptor")); -var _Adaptor = require('./Adaptor'); +exports.Adaptor = Adaptor; -var Adaptor = _interopRequireWildcard(_Adaptor); +function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } -exports.Adaptor = Adaptor; -exports.default = Adaptor; +var _default = Adaptor; +exports["default"] = _default; diff --git a/package-lock.json b/package-lock.json index b716ffa..14dfbae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1563,9 +1563,9 @@ } }, "@types/node": { - "version": "12.6.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.6.8.tgz", - "integrity": "sha1-5Gm0v50cmDKu5JB7qKBRSUNXwSw=" + "version": "13.11.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.11.1.tgz", + "integrity": "sha512-eWQGP3qtxwL8FGneRrC5DwrJLGN4/dH1clNTuLfN81HCrxVtxRjygDTUoZJ5ASlDEeo0ppYFQjQIlXhtXpOn6g==" }, "JSONPath": { "version": "0.10.0", @@ -1869,12 +1869,12 @@ } }, "cheerio": { - "version": "1.0.0-rc.2", - "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.2.tgz", - "integrity": "sha1-S59TqBsn5NXawxwP/Qz6A8xoMNs=", + "version": "1.0.0-rc.3", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.3.tgz", + "integrity": "sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA==", "requires": { "css-select": "~1.2.0", - "dom-serializer": "~0.1.0", + "dom-serializer": "~0.1.1", "entities": "~1.1.1", "htmlparser2": "^3.9.1", "lodash": "^4.15.0", @@ -2063,12 +2063,12 @@ "css-what": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.3.tgz", - "integrity": "sha1-ptdgRXM2X+dGhsPzEcVlE9iChfI=" + "integrity": "sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg==" }, "csv-parse": { - "version": "4.8.3", - "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-4.8.3.tgz", - "integrity": "sha512-0GPxubzYzSn08lhNTWDCkcDKn8krmw0WuscqB2RrW6sugGGskbwaaEz7PCFFwbQ0phNGTTieiyfzzu3S/jZZ7Q==" + "version": "4.8.8", + "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-4.8.8.tgz", + "integrity": "sha512-Kv3Ilz2GV58dOoHBXRCTF8ijxlLjl80bG3d67XPI6DNqffb3AnbPbKr/WvCUMJq5V0AZYi6sukOaOQAVpfuVbg==" }, "dashdash": { "version": "1.14.1", @@ -2200,7 +2200,7 @@ "dom-serializer": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", - "integrity": "sha1-HsQFnihLq+027sKUHUqXChic58A=", + "integrity": "sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==", "requires": { "domelementtype": "^1.3.0", "entities": "^1.1.1" @@ -2209,12 +2209,12 @@ "domelementtype": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", - "integrity": "sha1-0EjESzew0Qp/Kj1f7j9DM9eQSB8=" + "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==" }, "domhandler": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz", - "integrity": "sha1-iAUJfpM9ZehVRvcm1g9euItE+AM=", + "integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==", "requires": { "domelementtype": "1" } @@ -2252,7 +2252,7 @@ "entities": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", - "integrity": "sha1-vfpzUplmTfr9NFKe1PhSKidf6lY=" + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" }, "es-abstract": { "version": "1.13.0", @@ -3149,7 +3149,7 @@ "htmlparser2": { "version": "3.10.1", "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz", - "integrity": "sha1-vWedw/WYl7ajS7EHSchVu1OpOS8=", + "integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==", "requires": { "domelementtype": "^1.3.1", "domhandler": "^2.3.0", @@ -3888,7 +3888,7 @@ "nth-check": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz", - "integrity": "sha1-sr0pXDfj3VijvwcAN2Zjuk2c8Fw=", + "integrity": "sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg==", "requires": { "boolbase": "~1.0.0" } @@ -4095,7 +4095,7 @@ "parse5": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz", - "integrity": "sha1-BC95L/3TaFFVHPTp4Gazh0q0W1w=", + "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==", "requires": { "@types/node": "*" } @@ -4263,9 +4263,9 @@ "integrity": "sha1-yzroBuh0BERYTvFUzo7pjUA/PjY=" }, "readable-stream": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz", - "integrity": "sha1-pRwmdUZY4KPCHb9ZFjvUW6b0R/w=", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", "requires": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -5279,11 +5279,18 @@ } }, "string_decoder": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.2.0.tgz", - "integrity": "sha1-/obnOLGVRK/nBGkkOyoe6SQOro0=", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", "requires": { - "safe-buffer": "~5.1.0" + "safe-buffer": "~5.2.0" + }, + "dependencies": { + "safe-buffer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" + } } }, "strip-json-comments": { diff --git a/package.json b/package.json index 7f10cad..c327c78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "language-http", - "version": "2.4.1", + "version": "2.4.2", "description": "An HTTP request language package for use with Open Function", "main": "lib/index.js", "scripts": { @@ -14,9 +14,9 @@ "lib/" ], "dependencies": { - "cheerio": "1.0.0-rc.2", - "cheerio-tableparser": "1.0.1", - "csv-parse": "^4.8.3", + "cheerio": "^1.0.0-rc.3", + "cheerio-tableparser": "^1.0.1", + "csv-parse": "^4.8.8", "language-common": "github:openfn/language-common#v0.3.0", "request": "^2.72.0" }, diff --git a/src/Adaptor.js b/src/Adaptor.js index 5f69956..1b1b3fd 100644 --- a/src/Adaptor.js +++ b/src/Adaptor.js @@ -29,7 +29,7 @@ export function execute(...operations) { data: null, }; - return state => { + return (state) => { return commonExecute(...operations)({ ...initialState, ...state }); }; } @@ -54,16 +54,22 @@ export function execute(...operations) { * @returns {Operation} */ export function get(path, params, callback) { - return state => { + return (state) => { const url = setUrl(state.configuration, path); - const { query, headers, authentication, ...rest } = expandReferences( - params - )(state); + const { + query, + headers, + authentication, + body, + formData, + options, + ...rest + } = expandReferences(params)(state); const auth = setAuth(state.configuration, authentication); - return req('GET', { url, query, auth, headers, rest }).then(response => { + return req('GET', { url, query, auth, headers, rest }).then((response) => { const nextState = composeNextState(state, response); if (callback) return callback(nextState); return nextState; @@ -91,7 +97,7 @@ export function get(path, params, callback) { * @returns {Operation} */ export function post(path, params, callback) { - return state => { + return (state) => { const url = setUrl(state.configuration, path); const { @@ -115,7 +121,7 @@ export function post(path, params, callback) { formData, options, rest, - }).then(response => { + }).then((response) => { const nextState = composeNextState(state, response); if (callback) return callback(nextState); return nextState; @@ -143,7 +149,7 @@ export function post(path, params, callback) { * @returns {Operation} */ export function put(path, params, callback) { - return state => { + return (state) => { const url = setUrl(state.configuration, path); const { @@ -167,7 +173,7 @@ export function put(path, params, callback) { headers, options, rest, - }).then(response => { + }).then((response) => { const nextState = composeNextState(state, response); if (callback) return callback(nextState); return nextState; @@ -195,7 +201,7 @@ export function put(path, params, callback) { * @returns {Operation} */ export function patch(path, params, callback) { - return state => { + return (state) => { const url = setUrl(state.configuration, path); const { @@ -219,7 +225,7 @@ export function patch(path, params, callback) { auth, headers, rest, - }).then(response => { + }).then((response) => { const nextState = composeNextState(state, response); if (callback) return callback(nextState); return nextState; @@ -247,7 +253,7 @@ export function patch(path, params, callback) { * @returns {Operation} */ export function del(path, params, callback) { - return state => { + return (state) => { const url = setUrl(state.configuration, path); const { @@ -271,7 +277,7 @@ export function del(path, params, callback) { auth, headers, rest, - }).then(response => { + }).then((response) => { const nextState = composeNextState(state, response); if (callback) return callback(nextState); return nextState; @@ -292,7 +298,7 @@ export function del(path, params, callback) { * @returns {Operation} */ export function parseXML(body, script) { - return state => { + return (state) => { const $ = cheerio.load(body); cheerioTableparser($); @@ -324,7 +330,7 @@ export function parseXML(body, script) { * @returns {Operation} */ export function parseCSV(target, config) { - return state => { + return (state) => { return new Promise((resolve, reject) => { var csvData = []; @@ -332,7 +338,7 @@ export function parseCSV(target, config) { fs.readFileSync(target); fs.createReadStream(target) .pipe(parse(config)) - .on('data', csvrow => { + .on('data', (csvrow) => { csvData.push(csvrow); }) .on('end', () => { @@ -365,7 +371,7 @@ export function parseCSV(target, config) { * @returns {Operation} */ export function request(params) { - return state => { + return (state) => { const expanded = typeof params === 'string' ? params : expandReferences(params)(state); diff --git a/src/Client.js b/src/Client.js index 2a8f87c..9285b69 100644 --- a/src/Client.js +++ b/src/Client.js @@ -49,6 +49,7 @@ export function req(method, params) { const __cookie = j.getCookieString(url); resolve({ __cookie, + __headers: response.headers, ...resp, }); } else {