Skip to content

Commit

Permalink
* fixed problem with XML generation #5. Transport getParams is now pa…
Browse files Browse the repository at this point in the history
…ssed to _xml object to avoid injection of unwanted tags and 500 status code
  • Loading branch information
adamkac committed Mar 1, 2019
1 parent 6c6fae3 commit ff0b55b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
26 changes: 14 additions & 12 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ this.login = function() {
return this.getSessionId();

var function_name = "Zaloguj";
var params = this.transport_class.getParams(function_name, _this.key);
var params = {_xml:this.transport_class.getParams(function_name, _this.key)};
var result = _this.call(function_name, params);

if (!result.error)
this.sid = result.response.ZalogujResult;

if(!result.response.ZalogujResult)
throw "Problem with login. Please check if you entered correct api key, and if sandbox is defined correctly.";

Expand All @@ -86,7 +86,7 @@ this.logout = function(value) {
if (!value)
value = this.getSessionId();

var params = this.transport_class.getParams(function_name, value);
var params = {_xml:this.transport_class.getParams(function_name, value)};
var result = _this.call(function_name, params);

if (!result.error)
Expand All @@ -98,7 +98,7 @@ this.Wyloguj = this.logout;

this.getInfo = function() {
var function_name = "DaneKomunikat";
var params = this.transport_class.getParams(function_name);
var params = {_xml:this.transport_class.getParams(function_name)};
var result = _this.call(function_name, params);

return result.response[Object.keys(result.response)[0]];
Expand All @@ -107,7 +107,7 @@ this.DaneKomunikat = this.getInfo;

this.getValue = function(value) {
var function_name = "GetValue";
var params = this.transport_class.getParams(function_name, value);
var params = {_xml:this.transport_class.getParams(function_name, value)};
var result = _this.call(function_name, params);

return result.response[Object.keys(result.response)[0]];
Expand All @@ -128,7 +128,7 @@ var function_name = '';
throw "You need to make login request! SessionId is not defined.";

function_name = "DanePobierzPelnyRaport";
var params = this.transport_class.getParams(function_name, value, type, silosId);
var params = {_xml:this.transport_class.getParams(function_name, value, type, silosId)};
var result = _this.call(function_name, params);
return this.checkIfNeedCaptcha(result, function_name, params, function() {

Expand All @@ -143,7 +143,7 @@ this.DanePobierzPelnyRaportP = this.getFullReport;

this.getCaptcha = function() {
var function_name = "PobierzCaptcha";
var params = this.transport_class.getParams(function_name);
var params = {_xml:this.transport_class.getParams(function_name)};
var result = _this.call(function_name, params);

return result.response;
Expand Down Expand Up @@ -180,7 +180,7 @@ this.search = function(params) {
throw "You need to make login request! SessionId is not defined.";


var paramsForXml = this.transport_class.getParams(function_name, paramsRenderered);
var paramsForXml = {_xml:this.transport_class.getParams(function_name, paramsRenderered)};

var result = _this.call(function_name, paramsForXml, "xmlns:dat=\"http://CIS/BIR/PUBL/2014/07/DataContract\"");

Expand Down Expand Up @@ -231,6 +231,7 @@ this.checkIfNeedCaptcha = function(result, function_name, params, callbackCaptch
var iterator = iterator || 0;
var error = result.error;
var response = result.response;

var firstObject = response[Object.keys(response)[0]];

if (iterator > 5) {
Expand All @@ -250,14 +251,16 @@ this.checkIfNeedCaptcha = function(result, function_name, params, callbackCaptch
parseString(firstObject, function (err, result) {
json = result;
});
json = JSON.parse(json);

// json = JSON.parse(json);
if (json.root)
if (json.root.dane)
json = json.root.dane;

delete result.response[Object.keys(response)[0]];
result.response = json;
if(typeof json[0] != undefined)
result.response = json[0];
else
result.response = json;
return result;
}

Expand Down Expand Up @@ -432,7 +435,6 @@ this.call = function(function_name, arguments, additionalEnvelope) {
this.transport.addHttpHeader("sid", this.sid);



debug('service.call', 'Start Calling: ', function_name, arguments, additionalEnvelope);

this.transport[function_name](arguments, function(error, result, raw, soapHeader) {
Expand Down
4 changes: 2 additions & 2 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ var soap = require('soap-extended'),

var Transport = function(wsdl, options, callback) {
var wsdlOptions = {
"forceSoap12Headers": true
"forceSoap12Headers": true,
"escapeXML": false
}
this.client = soap.createClient(wsdl, wsdlOptions, callback);

Expand Down Expand Up @@ -109,7 +110,6 @@ var Transport = function(wsdl, options, callback) {
_(params).forEach(function(value, key) {
response += self.getParamValue(key, value);
});
console.log();
return response;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-regon",
"version": "0.1.49",
"version": "0.1.50",
"description": "An API for accessing a Polish REGON database",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ff0b55b

Please sign in to comment.