From ff0b55bbd79b0c0fcdcc7e89571556193c68564a Mon Sep 17 00:00:00 2001 From: Adam Kaczmarzyk Date: Fri, 1 Mar 2019 02:20:07 +0100 Subject: [PATCH] * fixed problem with XML generation #5. Transport getParams is now passed to _xml object to avoid injection of unwanted tags and 500 status code --- lib/service.js | 26 ++++++++++++++------------ lib/transport.js | 4 ++-- package.json | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/service.js b/lib/service.js index fad0103..290fd04 100644 --- a/lib/service.js +++ b/lib/service.js @@ -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."; @@ -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) @@ -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]]; @@ -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]]; @@ -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() { @@ -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; @@ -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\""); @@ -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) { @@ -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; } @@ -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) { diff --git a/lib/transport.js b/lib/transport.js index 8318395..ce31f68 100644 --- a/lib/transport.js +++ b/lib/transport.js @@ -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); @@ -109,7 +110,6 @@ var Transport = function(wsdl, options, callback) { _(params).forEach(function(value, key) { response += self.getParamValue(key, value); }); - console.log(); return response; } diff --git a/package.json b/package.json index 6d22a37..534c062 100644 --- a/package.json +++ b/package.json @@ -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": {