Comparing version 0.0.2 to 0.0.3
@@ -76,2 +76,9 @@ /* | ||
}; | ||
options = {}; | ||
// Allow the security object a change to add headers | ||
if (self.security && self.security.addHeaders) | ||
self.security.addHeaders(headers); | ||
if (self.security && self.security.addOptions) | ||
self.security.addOptions(options); | ||
@@ -104,5 +111,5 @@ args[input.element.$name] = arguments; | ||
} | ||
}, headers); | ||
}, headers, options); | ||
} | ||
exports.Client = Client; |
@@ -15,7 +15,7 @@ /* | ||
exports.request = function(rurl, data, callback, exheaders) { | ||
exports.request = function(rurl, data, callback, exheaders, exoptions) { | ||
var curl = url.parse(rurl); | ||
var secure = curl.protocol == 'https:'; | ||
var host = curl.hostname; | ||
var port = parseInt(curl.port || secure ? 443 : 80); | ||
var port = parseInt(curl.port || (secure ? 443 : 80)); | ||
var path = [curl.pathname || '/', curl.search || '', curl.hash || ''].join(''); | ||
@@ -48,2 +48,5 @@ var method = data ? "POST" : "GET"; | ||
}; | ||
exoptions = exoptions || {}; | ||
for (attr in exoptions) { options[attr] = exoptions[attr]; } | ||
@@ -50,0 +53,0 @@ var request = (secure ? https : http).request(options); |
@@ -9,3 +9,4 @@ /* | ||
WSDL = require('./wsdl').WSDL, | ||
http = require('./http'); | ||
http = require('./http'), | ||
fs = require('fs'); | ||
@@ -19,2 +20,14 @@ var _wsdlCache = {}; | ||
} | ||
else if (!/^http/.test(url)) { | ||
fs.readFile(url, 'utf8', function (err, data) { | ||
if (err) { | ||
callback(err) | ||
} | ||
else { | ||
wsdl = new WSDL(data); | ||
_wsdlCache[url] = wsdl; | ||
callback(null, wsdl); | ||
} | ||
}) | ||
} | ||
else { | ||
@@ -49,4 +62,4 @@ http.request(url, null, function(err, response) { | ||
function WSSecurity(username, password) { | ||
this._username = username; | ||
this._password = password; | ||
this._username = username; | ||
this._password = password; | ||
} | ||
@@ -56,7 +69,7 @@ | ||
return "<wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" + | ||
"<wsse:UsernameToken>" + | ||
"<wsse:Username>"+this._username+"</wsse:Username>" + | ||
"<wsse:Password>"+this._password+"</wsse:Password>" + | ||
"</wsse:UsernameToken>" + | ||
"</wsse:Security>" | ||
"<wsse:UsernameToken>" + | ||
"<wsse:Username>"+this._username+"</wsse:Username>" + | ||
"<wsse:Password>"+this._password+"</wsse:Password>" + | ||
"</wsse:UsernameToken>" + | ||
"</wsse:Security>" | ||
} | ||
@@ -63,0 +76,0 @@ |
@@ -18,8 +18,19 @@ /* | ||
function splitNSName(nsName) { | ||
var parts = nsName.split(':'), | ||
namespace = parts.length > 1 ? parts.shift() : null; | ||
return { namespace: namespace, name: parts[0] }; | ||
var i = nsName.indexOf(':'); | ||
return i < 0 ? {namespace:null,name:nsName} : {namespace:nsName.substring(0, i), name:nsName.substring(i+1)}; | ||
} | ||
function xmlEscape(obj) { | ||
if (typeof(obj) === 'string') { | ||
return obj | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
} | ||
return obj; | ||
} | ||
var Element = function(nsName, attrs, parent) { | ||
@@ -370,3 +381,4 @@ var parts = splitNSName(nsName); | ||
else if (child instanceof BindingElement) { | ||
if (child.transport === 'http://schemas.xmlsoap.org/soap/http') | ||
if (child.transport === 'http://schemas.xmlsoap.org/soap/http' || | ||
child.transport === 'http://www.w3.org/2003/05/soap/bindings/HTTP/') | ||
self.bindings[child.$name] = child; | ||
@@ -415,3 +427,3 @@ } | ||
Body: { | ||
Fault: { faultcode: 'string', faultstring: 'string' }}}}, | ||
Fault: { faultcode: 'string', faultstring: 'string', detail: 'string' }}}}, | ||
stack = [{name: null, object: root, schema: schema}]; | ||
@@ -447,2 +459,9 @@ | ||
} | ||
else if (name in topObject) { | ||
if (!Array.isArray(topObject[name])) { | ||
topObject[name] = [topObject[name]]; | ||
} | ||
topObject[name].push(obj); | ||
} | ||
else { | ||
@@ -480,3 +499,3 @@ topObject[name] = obj; | ||
if (body.Fault) { | ||
throw new Error(body.Fault.faultcode+': '+body.Fault.faultstring); | ||
throw new Error(body.Fault.faultcode+': '+body.Fault.faultstring+(body.Fault.detail ? ': ' + body.Fault.detail : '')); | ||
} | ||
@@ -486,6 +505,8 @@ return body; | ||
WSDL.prototype.objectToXML = function(obj, namespace, name) { | ||
WSDL.prototype.objectToXML = function(obj, namespace, name, xmlns) { | ||
var self = this, | ||
parts = [], | ||
namespace = namespace || 'ns0'; | ||
namespace = namespace || 'ns0', | ||
xmlns = xmlns || '', | ||
nsAttrName = '_xmlns'; | ||
@@ -496,3 +517,3 @@ if (Array.isArray(obj)) { | ||
parts.push(['</',namespace,':',name,'>'].join('')); | ||
parts.push(['<',namespace,':',name,'>'].join('')); | ||
parts.push(['<',namespace,':',name,xmlns,'>'].join('')); | ||
} | ||
@@ -504,9 +525,20 @@ parts.push(self.objectToXML(item, namespace, name)); | ||
for (var name in obj) { | ||
parts.push(['<',namespace,':',name,'>'].join('')); | ||
parts.push(self.objectToXML(obj[name], namespace, name)); | ||
parts.push(['</',namespace,':',name,'>'].join('')); | ||
if (name != nsAttrName) { | ||
var child = obj[name], | ||
childNamespace = namespace, | ||
xmlns = '', | ||
nsAttr = child && child[nsAttrName]; | ||
if (nsAttr) { | ||
childNamespace = nsAttr.ns; | ||
if (nsAttr.uri) | ||
xmlns = [' xmlns:',childNamespace,'="',nsAttr.uri,'"'].join(''); | ||
} | ||
parts.push(['<',childNamespace,':',name,xmlns,'>'].join('')); | ||
parts.push(self.objectToXML(child, childNamespace, name, xmlns)); | ||
parts.push(['</',childNamespace,':',name,'>'].join('')); | ||
} | ||
} | ||
} | ||
else if (obj) { | ||
parts.push(obj); | ||
parts.push(xmlEscape(obj)); | ||
} | ||
@@ -513,0 +545,0 @@ return parts.join(''); |
{ | ||
"name": "soap", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A minimal node SOAP client", | ||
@@ -5,0 +5,0 @@ "engines": { "node": ">=0.4.0" }, |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
32003
877
1