Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

easysoap

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easysoap - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

4

CHANGELOG.md
# easysoap changelog
## 2.1.0
* bugfix: headers not interpreted
* bugfix: attributes will not be set
## 2.0.2

@@ -4,0 +8,0 @@ * bugfix: readd missing "SOAP-HEADER" tag

4

package.json

@@ -8,3 +8,3 @@ {

},
"version": "2.0.2",
"version": "2.1.0",
"main": "./src/index.js",

@@ -14,3 +14,3 @@ "dependencies": {

"underscore": "^1.8.3",
"wsdlrdr": "^0.4.0",
"wsdlrdr": "^0.5.0",
"xmldoc": "^1.1.0"

@@ -17,0 +17,0 @@ },

@@ -5,2 +5,4 @@ (() => {

const _ = require('underscore');
const assert = require('assert');
const request = require('request');

@@ -48,92 +50,88 @@ const wsdlrdr = require('wsdlrdr');

function getRequestParamsAsString (callParams, baseParams, opts) {
var getTagAttributes = function (attributes) {
return ' ' + _.map(attributes,
(attributeValue, attributeKey) => {
return attributeKey + '="' + attributeValue + '"';
}
).join(' ');
};
function getTagAttributes (attributes = {}) {
const attributeKeys = Object.keys(attributes);
if (attributeKeys.length === 0) {
return '';
}
var getParamAsString = function (value, name, paramData, attributes) {
paramData = paramData || {};
return ' ' + attributeKeys
.map((key) => `${key}="${attributes[key]}"`)
.join(' ');
};
var namespace = '';
if (paramData) {
if (paramData.namespace) {
namespace = paramData.namespace + ':';
}
}
function getParamAsString (key, value, paramData = {}, attributes = {}) {
// array value given, then create item for every value
if (Array.isArray(value)) {
return value
.map((valueItem) => getParamAsString(key, valueItem, paramData, attributes))
.join('');
}
// get underline parameter values
var attributesString = '';
if (_.isObject(value)) {
if (value._attributes) {
attributesString = getTagAttributes(value._attributes);
}
if (value._value) {
value = value._value;
}
// handle objects
if (Object(value) === value) {
if (value._value ||
value._attributes) {
attributes = Object.assign({}, attributes, value._attributes || {});
value = value._value || '';
} else {
value = Object.keys(value)
.map((valueKey) => getParamAsString(valueKey, value[valueKey], paramData, attributes))
.join('');
}
}
// array value given, then create item for every value
if (_.isArray(value)) {
return _.map(value,
(valueItem) => getParamAsString(valueItem, name, paramData, attributes)
).join('');
// add namespace to tag
let namespace = '';
if (paramData) {
if (paramData.namespace) {
namespace = paramData.namespace + ':';
}
}
// object value given, create a string for object
if (_.isObject(value)) {
var valueAsString = _.map(value,
(valueItem, valueKey) => {
if (_.isObject(valueItem)) {
valueItem = _.map(valueItem, (valueItemItem, valueKeyKey) => {
return getParamAsString(valueItemItem, valueKeyKey, paramData[name], attributes);
}).join('');
}
// add attributes to tag
let attributesString = '';
if (attributes) {
attributesString = getTagAttributes(attributes);
}
return getParamAsString(valueItem, valueKey, paramData[name], attributes);
}
).join('');
return `<${namespace}${key}${attributesString}>${value}</${namespace}${key}>`;
}
return getParamAsString(valueAsString, name, paramData, attributes);
function getMethodParamRequestString (requestParams, paramKey, callParams) {
// got request param attributes
let methodRequestParams = {};
for (const requestParamsAttributes of requestParams) {
if (requestParamsAttributes.params) {
methodRequestParams = requestParamsAttributes.params
.find((requestParamItem) =>
requestParamItem.name === paramKey ||
requestParamItem.element === paramKey);
}
}
// add global attributes
if (attributes) {
attributesString += getTagAttributes(attributes);
}
const paramValue = callParams.params[paramKey];
const mergedAttributes = Object.assign({}, callParams.attributes, paramValue._attributes || {});
return `<${namespace}${name}${attributesString}>${value}</${namespace}${name}>`;
};
return getParamAsString(
paramKey,
paramValue,
methodRequestParams,
mergedAttributes
);
}
return wsdlrdr.getMethodParamsByName(callParams.method, baseParamsToRequestParams(baseParams), opts)
.then((methodParams) => {
var requestParams = methodParams.request;
async function getRequestParamsAsString (callParams = {}, baseParams = {}, opts = {}) {
assert.ok(callParams.method, 'no method given');
if (!callParams.params.hasOwnProperty(callParams.method)) {
var topObject = {};
topObject[callParams.method] = callParams.params;
const methodParams = await wsdlrdr.getMethodParamsByName(callParams.method, baseParamsToRequestParams(baseParams), opts);
const requestParams = methodParams.request;
callParams.params = topObject;
}
const responseArray = [];
for (const paramKey of Object.keys(callParams.params)) {
responseArray.push(
getMethodParamRequestString(requestParams, paramKey, callParams)
);
}
var result = _.map(callParams.params,
(paramValue, paramName) => {
var methodRequestParams = _.findWhere(requestParams, { 'element': paramName });
if (!methodRequestParams) {
methodRequestParams = _.findWhere(requestParams, { 'name': paramName });
}
return getParamAsString(paramValue, paramName,
methodRequestParams,
callParams.attributes
);
}
);
return result.join('');
});
return getParamAsString(callParams.method, responseArray.join(''), null, callParams.attributes);
}

@@ -177,10 +175,10 @@

if (!_.isArray(params.headers) &&
_.isObject(params.headers)) {
var keyName = _.keys(params.headers)[0];
params.headers = [{
name : keyName,
value: params.headers[keyName]
}];
if (!Array.isArray(params.headers) &&
params.headers === Object(params.headers)) {
params.headers = Object.keys(params.headers).map((key) => {
return {
name : key,
value: params.headers[key]
};
});
}

@@ -214,3 +212,3 @@

const $head = (head !== null) ? `<SOAP-ENV:Header>${head.map((headItem) => headItem)}</SOAP-ENV:Header>` : '';
const $head = (head !== null) ? `<SOAP-ENV:Header>${head.join('')}</SOAP-ENV:Header>` : '';
const $body = `<SOAP-ENV:Body>${body}</SOAP-ENV:Body>`;

@@ -217,0 +215,0 @@

@@ -131,2 +131,149 @@ (() => {

});
test('getRequestXml.simple', async (t) => {
const soapClient = soapClients.find((item) => item.url === 'www.dataaccess.com/webservicesserver/numberconversion.wso');
if (!soapClient) {
t.end('no soap client available');
}
const xml = await soapClient.instance.getRequestXml({
method : 'NumberToDollars',
headers: {
header1: 'header-data1',
header2: 'header-data2',
header3: 'header-data3'
},
params: {
testParam1: 1,
testParam2: [2, 3]
}
});
const json = soapClient.instance.getXmlDataAsJson(xml);
t.ok(json.NumberToDollars, 'no "NumberToDollars" key');
t.ok(json.NumberToDollars.filter((i) => i['testParam1']).length === 1, 'found testParam1 only once');
t.ok(json.NumberToDollars.some((i) => i['testParam1'] && i['testParam1'] === '1'), 'testParam1 has value 1');
t.ok(json.NumberToDollars.filter((i) => i['testParam2']).length === 1, 'found testParam2 only once');
t.ok(json.NumberToDollars.some((i) => i['testParam2'] && i['testParam2'].length === 2), 'testParam2 has only 2 items');
t.ok(json.NumberToDollars.some((i) => i['testParam2'] && i['testParam2'].includes('2')), 'testParam2 has value 2');
t.ok(json.NumberToDollars.some((i) => i['testParam2'] && i['testParam2'].includes('3')), 'testParam2 has value 3');
t.end();
});
test('getRequestXml.base', async (t) => {
const soapClient = soapClients.find((item) => item.url === 'www.dataaccess.com/webservicesserver/numberconversion.wso');
if (!soapClient) {
t.end('no soap client available');
}
const xml = await soapClient.instance.getRequestXml({
method : 'NumberToDollars',
attributes: {
globalAttr1: '1111',
globalAttr2: '2222'
},
headers: {
header1: 'header-data1',
header2: 'header-data2',
header3: 'header-data3'
},
params: {
testParam1: 1,
testParam2: [2, 3],
testParam3: {
'_value' : 4,
'_attributes': {
'attr1': '123',
'attr2': '456',
'attr3': '789'
}
},
testParam4: {
'_attributes': {
'attr1': '123',
'attr2': '456',
'attr3': '789'
}
}
}
});
const json = soapClient.instance.getXmlDataAsJson(xml);
t.ok(json.NumberToDollars, 'no "NumberToDollars" key');
t.ok(json.NumberToDollars.filter((i) => i['testParam1']).length === 1, 'found testParam1 only once');
t.ok(json.NumberToDollars.filter((i) => i['testParam2']).length === 1, 'found testParam2 only once');
t.ok(json.NumberToDollars.filter((i) => i['testParam3']).length === 1, 'found testParam3 only once');
t.ok(json.NumberToDollars.filter((i) => i['testParam4']).length === 1, 'found testParam4 only once');
t.end();
});
test('getRequestXml.base-deep', async (t) => {
const soapClient = soapClients.find((item) => item.url === 'www.dataaccess.com/webservicesserver/numberconversion.wso');
if (!soapClient) {
t.end('no soap client available');
}
const xml = await soapClient.instance.getRequestXml({
method : 'NumberToDollars',
attributes: {
globalAttr1: '1111',
globalAttr2: '2222'
},
params: {
testParam1: {
testParam1Deep: {
'_value' : 4,
'_attributes': {
'attr1': '123',
'attr2': '456',
'attr3': '789'
}
}
}
}
});
const json = soapClient.instance.getXmlDataAsJson(xml);
t.ok(json.NumberToDollars, '"NumberToDollars" key');
t.ok(json.NumberToDollars.testParam1, '"testParam1" key');
t.ok(json.NumberToDollars.testParam1.testParam1Deep, '"testParam1Deep" key');
t.end();
});
test('getRequestXml.special', async (t) => {
const soapClient = soapClients.find((item) => item.url === 'www.dataaccess.com/webservicesserver/numberconversion.wso');
if (!soapClient) {
t.end('no soap client available');
}
const xml = await soapClient.instance.getRequestXml({
method: 'NumberToDollars',
params: {
request: {
locale: {
_attributes: {
country : 'DE',
datCountryIndicator: 'DE',
language : 'de'
}
},
sessionID : null,
restriction: 'ALL'
}
}
});
const json = soapClient.instance.getXmlDataAsJson(xml);
t.ok(json.NumberToDollars, '"NumberToDollars" key');
t.ok(json.NumberToDollars.request, '"request" key');
t.end();
});
})();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc