flowcl-node-api-client
Advanced tools
Comparing version 1.0.5 to 1.0.6
133
lib/index.js
"use strict"; | ||
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; }; | ||
var _keys = require("babel-runtime/core-js/object/keys"); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _regenerator = require("babel-runtime/regenerator"); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _extends2 = require("babel-runtime/helpers/extends"); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator"); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _promise = require("babel-runtime/core-js/promise"); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require("babel-runtime/helpers/createClass"); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var axios = require("axios"); | ||
@@ -20,5 +44,4 @@ var axiosRetry = require("axios-retry"); | ||
apiURL = _ref.apiURL; | ||
(0, _classCallCheck3.default)(this, FlowApi); | ||
_classCallCheck(this, FlowApi); | ||
this.apiKey = apiKey; | ||
@@ -29,3 +52,3 @@ this.secretKey = secretKey; | ||
_createClass(FlowApi, [{ | ||
(0, _createClass3.default)(FlowApi, [{ | ||
key: "send", | ||
@@ -37,31 +60,68 @@ value: function send(service, params) { | ||
return new Promise(async function (resolve, reject) { | ||
method = method.toUpperCase(); | ||
var url = _this.apiURL + "/" + service; | ||
params = _extends({ | ||
apiKey: _this.apiKey | ||
}, params); | ||
var data = _this.getPack(params, method); | ||
var sign = _this.sign(params); | ||
var response = void 0; | ||
if (method == "GET") { | ||
response = await _this.httpGet(url, data, sign); | ||
} else { | ||
response = await _this.httpPost(url, data, sign); | ||
} | ||
return new _promise2.default(function () { | ||
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(resolve, reject) { | ||
var url, data, sign, response, code, body; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
method = method.toUpperCase(); | ||
url = _this.apiURL + "/" + service; | ||
if (!!response["info"]) { | ||
var code = response.info.http_code; | ||
var body = response.output; | ||
if (code === 200) { | ||
resolve(body); | ||
} else if ([400, 401].includes(code)) { | ||
reject(Error(body.message)); | ||
} else { | ||
reject(Error("Unexpected error occurred. HTTP_CODE: " + code)); | ||
} | ||
} else { | ||
reject(Error("Unexpected error occurred.")); | ||
} | ||
}); | ||
params = (0, _extends3.default)({ | ||
apiKey: _this.apiKey | ||
}, params); | ||
data = _this.getPack(params, method); | ||
sign = _this.sign(params); | ||
response = void 0; | ||
if (!(method == "GET")) { | ||
_context.next = 12; | ||
break; | ||
} | ||
_context.next = 9; | ||
return _this.httpGet(url, data, sign); | ||
case 9: | ||
response = _context.sent; | ||
_context.next = 15; | ||
break; | ||
case 12: | ||
_context.next = 14; | ||
return _this.httpPost(url, data, sign); | ||
case 14: | ||
response = _context.sent; | ||
case 15: | ||
if (!!response["info"]) { | ||
code = response.info.http_code; | ||
body = response.output; | ||
if (code === 200) { | ||
resolve(body); | ||
} else if ([400, 401].includes(code)) { | ||
reject(Error(body.message)); | ||
} else { | ||
reject(Error("Unexpected error occurred. HTTP_CODE: " + code)); | ||
} | ||
} else { | ||
reject(Error("Unexpected error occurred.")); | ||
} | ||
case 16: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
})); | ||
return function (_x2, _x3) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}()); | ||
} | ||
@@ -71,3 +131,3 @@ }, { | ||
value: function getPack(params, method) { | ||
var keys = Object.keys(params).map(function (key) { | ||
var keys = (0, _keys2.default)(params).map(function (key) { | ||
return key; | ||
@@ -91,3 +151,3 @@ }).sort(function (a, b) { | ||
value: function sign(params) { | ||
var keys = Object.keys(params).map(function (key) { | ||
var keys = (0, _keys2.default)(params).map(function (key) { | ||
return key; | ||
@@ -147,3 +207,2 @@ }).sort(function (a, b) { | ||
}]); | ||
return FlowApi; | ||
@@ -150,0 +209,0 @@ }(); |
{ | ||
"name": "flowcl-node-api-client", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "", | ||
@@ -28,3 +28,6 @@ "main": "index.js", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-stage-0": "^6.24.1", | ||
"babel-preset-stage-3": "^6.24.1", | ||
"babel-register": "^6.26.0", | ||
@@ -31,0 +34,0 @@ "body-parser": "^1.18.3", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22930
387
10