Socket
Socket
Sign inDemoInstall

soap

Package Overview
Dependencies
Maintainers
3
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soap - npm Package Compare versions

Comparing version 0.39.0 to 0.40.0

6

History.md

@@ -0,1 +1,7 @@

0.40.0 / 2021-07-06
===================
* [DOC] Update Readme.md (#1150)
* [ENHANCEMENT] Allow server path to be a regex (#1149)
* [ENHANCEMENT] replace request & httpntlm with axios & axios-ntlm (#1146)
0.39.0 / 2021-06-01

@@ -2,0 +8,0 @@ ===================

3

lib/client.d.ts
/// <reference types="node" />
import { EventEmitter } from 'events';
import { IncomingHttpHeaders } from 'http';
import * as request from 'request';
import { IHeaders, IOptions, ISecurity } from './types';

@@ -31,3 +30,3 @@ import { WSDL } from './wsdl';

lastEndpoint?: string;
lastRequestHeaders?: request.Headers;
lastRequestHeaders?: any;
lastResponse?: any;

@@ -34,0 +33,0 @@ lastResponseHeaders?: IncomingHttpHeaders;

@@ -241,3 +241,2 @@ "use strict";

var xml = null;
var req;
var soapAction;

@@ -257,3 +256,3 @@ var alias = utils_1.findPrefix(defs.xmlns, ns);

if (!obj.html && !obj.Body) {
if (response.statusCode >= 400) {
if (response.status >= 400) {
var error = new Error('Error http status codes');

@@ -412,4 +411,2 @@ error.response = response;

var startTime_1 = Date.now();
req = this.httpClient.requestStream(location, xml, headers, options, this);
this.lastRequestHeaders = req.headers;
var onError_1 = function (err) {

@@ -419,17 +416,32 @@ _this_1.lastResponse = null;

_this_1.lastElapsedTime = null;
_this_1.lastRequestHeaders = err.config && err.config.headers;
_this_1.emit('response', null, null, eid);
callback(err, undefined, undefined, undefined, xml);
if (_this_1.returnSaxStream || !err.response || !err.response.data) {
callback(err, undefined, undefined, undefined, xml);
}
else {
err.response.data.on('close', function (e) {
callback(err, undefined, undefined, undefined, xml);
});
err.response.data.on('data', function (e) {
err.response.data = e.toString();
});
}
};
req.on('error', onError_1);
req.on('response', function (response) {
response.on('error', onError_1);
// When the output element cannot be looked up in the wsdl, play it safe and
// don't stream
if (response.statusCode !== 200 || !output || !output.$lookupTypes) {
getStream(response).then(function (body) {
this.httpClient.requestStream(location, xml, headers, options, this).then(function (res) {
_this_1.lastRequestHeaders = res.headers;
if (res.data.on) {
res.data.on('error', function (err) { return onError_1(err); });
}
// When the output element cannot be looked up in the wsdl,
// play it safe and don't stream
if (res.status !== 200 || !output || !output.$lookupTypes) {
getStream(res.data).then(function (body) {
_this_1.lastResponse = body;
_this_1.lastResponseHeaders = response && response.headers;
_this_1.lastElapsedTime = Date.now() - startTime_1;
_this_1.emit('response', body, response, eid);
return parseSync(body, response);
_this_1.lastResponseHeaders = res && res.headers;
// Added mostly for testability, but possibly useful for debugging
_this_1.lastRequestHeaders = res.config && res.config.headers || res.headers;
_this_1.emit('response', body, res, eid);
return parseSync(body, res);
});

@@ -441,29 +453,44 @@ return;

// the parsing logics and corresponding errors managements
var saxStream = _this_1.wsdl.getSaxStream(response);
return finish({ saxStream: saxStream }, '<stream>', response);
var saxStream = _this_1.wsdl.getSaxStream(res.data);
return finish({ saxStream: saxStream }, '<stream>', res.data);
}
else {
_this_1.wsdl.xmlToObject(response, function (error, obj) {
_this_1.lastResponse = response;
_this_1.lastResponseHeaders = response && response.headers;
_this_1.wsdl.xmlToObject(res.data, function (error, obj) {
_this_1.lastResponse = res;
_this_1.lastElapsedTime = Date.now() - startTime_1;
_this_1.emit('response', '<stream>', response, eid);
_this_1.lastResponseHeaders = res && res.headers;
// Added mostly for testability, but possibly useful for debugging
_this_1.lastRequestHeaders = res.config.headers;
_this_1.emit('response', '<stream>', res.data, eid);
if (error) {
error.response = response;
error.response = res;
error.body = '<stream>';
_this_1.emit('soapError', error, eid);
return callback(error, response, undefined, undefined, xml);
return callback(error, res, undefined, undefined, xml);
}
return finish(obj, '<stream>', response);
return finish(obj, '<stream>', res);
});
}
});
}, onError_1);
return;
}
req = this.httpClient.request(location, xml, function (err, response, body) {
return this.httpClient.request(location, xml, function (err, response, body) {
_this_1.lastResponse = body;
_this_1.lastResponseHeaders = response && response.headers;
_this_1.lastElapsedTime = response && response.elapsedTime;
if (response) {
_this_1.lastResponseHeaders = response.headers;
_this_1.lastElapsedTime = response.headers.date;
// Added mostly for testability, but possibly useful for debugging
_this_1.lastRequestHeaders = response.config && response.config.headers;
}
_this_1.emit('response', body, response, eid);
if (err) {
_this_1.lastRequestHeaders = err.config && err.config.headers;
try {
if (err.response && err.response.data) {
_this_1.wsdl.xmlToObject(err.response.data);
}
}
catch (error) {
err.root = error.root || error;
}
callback(err, undefined, undefined, undefined, xml);

@@ -475,6 +502,2 @@ }

}, headers, options, this);
// Added mostly for testability, but possibly useful for debugging
if (req && req.headers && !options.ntlm) { // fixes an issue when req or req.headers is undefined, doesn't apply to ntlm requests
this.lastRequestHeaders = req.headers;
}
};

@@ -481,0 +504,0 @@ return Client;

/// <reference types="node" />
import * as req from 'request';
import * as req from 'axios';
import { ReadStream } from 'fs';
import { IExOptions, IHeaders, IHttpClient, IOptions } from './types';

@@ -10,3 +11,2 @@ export interface IAttachment {

}
export declare type Request = req.Request;
/**

@@ -38,5 +38,5 @@ * A class representing the http client

*/
handleResponse(req: req.Request, res: req.Response, body: any): any;
request(rurl: string, data: any, callback: (error: any, res?: any, body?: any) => any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): req.Request;
requestStream(rurl: string, data: any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): req.Request;
handleResponse(req: req.AxiosPromise, res: req.AxiosResponse, body: any): any;
request(rurl: string, data: any, callback: (error: any, res?: any, body?: any) => any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): req.AxiosPromise<any>;
requestStream(rurl: string, data: any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): req.AxiosPromise<ReadStream>;
}

@@ -19,5 +19,5 @@ "use strict";

exports.HttpClient = void 0;
var req = require("axios");
var axios_ntlm_1 = require("axios-ntlm");
var debugBuilder = require("debug");
var httpNtlm = require("httpntlm");
var req = require("request");
var url = require("url");

@@ -37,3 +37,3 @@ var uuid_1 = require("uuid");

options = options || {};
this._request = options.request || req;
this._request = options.request || req["default"].create();
}

@@ -51,7 +51,7 @@ /**

var curl = url.parse(rurl);
var method = data ? 'POST' : 'GET';
var secure = curl.protocol === 'https:';
var path = [curl.pathname || '/', curl.search || '', curl.hash || ''].join('');
var host = curl.hostname;
var port = parseInt(curl.port, 10);
var path = [curl.pathname || '/', curl.search || '', curl.hash || ''].join('');
var method = data ? 'POST' : 'GET';
var headers = {

@@ -77,6 +77,5 @@ 'User-Agent': 'node-soap/' + VERSION,

var options = {
uri: curl,
url: curl.href,
method: method,
headers: headers,
followAllRedirects: true
headers: headers
};

@@ -94,4 +93,3 @@ if (exoptions.forceMTOM || attachments.length > 0) {

}
headers['Content-Type'] =
'multipart/related; type="application/xop+xml"; start="<' + start + '>"; start-info="text/xml"; boundary=' + uuid_1.v4();
headers['Content-Type'] = 'multipart/related; type="application/xop+xml"; start="<' + start + '>"; start-info="text/xml"; boundary=' + uuid_1.v4();
if (action) {

@@ -114,6 +112,6 @@ headers['Content-Type'] = headers['Content-Type'] + '; ' + action;

});
options.multipart = multipart_1;
// options.multipart = multipart;
}
else {
options.body = data;
options.data = data;
}

@@ -143,5 +141,5 @@ for (var attr in newExoptions) {

if (typeof body === 'string') {
// Remove any extra characters that appear before or after the SOAP
// envelope.
var match = body.replace(/<!--[\s\S]*?-->/, '').match(/(?:<\?[^?]*\?>[\s]*)?<([^:]*):Envelope([\S\s]*)<\/\1:Envelope>/i);
// Remove any extra characters that appear before or after the SOAP envelope.
var regex = /(?:<\?[^?]*\?>[\s]*)?<([^:]*):Envelope([\S\s]*)<\/\1:Envelope>/i;
var match = body.replace(/<!--[\s\S]*?-->/, '').match(regex);
if (match) {

@@ -157,34 +155,31 @@ body = match[0];

var req;
if (exoptions !== undefined && exoptions.hasOwnProperty('ntlm')) {
// sadly when using ntlm nothing to return
// Not sure if this can be handled in a cleaner way rather than an if/else,
// will to tidy up if I get chance later, patches welcome - insanityinside
// TODO - should the following be uri?
options.url = rurl;
httpNtlm[options.method.toLowerCase()](options, function (err, res) {
if (err) {
return callback(err);
}
// if result is stream
if (typeof res.body !== 'string') {
res.body = res.body.toString();
}
res.body = _this.handleResponse(req, res, res.body);
callback(null, res, res.body);
if (exoptions !== undefined && exoptions.ntlm) {
var ntlmReq = axios_ntlm_1.NtlmClient({
username: exoptions.username,
password: exoptions.password,
domain: exoptions.domain
});
req = ntlmReq(options);
}
else {
req = this._request(options, function (err, res, body) {
if (err) {
return callback(err);
}
body = _this.handleResponse(req, res, body);
callback(null, res, body);
});
req = this._request(options);
}
req.then(function (res) {
res.data = _this.handleResponse(req, res, res.data);
callback(null, res, res.data);
return res;
}, function (err) {
return callback(err);
});
return req;
};
HttpClient.prototype.requestStream = function (rurl, data, exheaders, exoptions, caller) {
var _this = this;
var options = this.buildRequest(rurl, data, exheaders, exoptions);
return this._request(options);
options.responseType = 'stream';
var req = this._request(options).then(function (res) {
res.data = _this.handleResponse(req, res, res.data);
return res;
});
return req;
};

@@ -191,0 +186,0 @@ return HttpClient;

@@ -27,3 +27,3 @@ /// <reference types="node" />

export declare class Server extends EventEmitter {
path: string;
path: string | RegExp;
services: IServices;

@@ -40,3 +40,3 @@ log: (type: string, data: any) => any;

private callback?;
constructor(server: ServerType, path: string, services: IServices, wsdl: WSDL, options?: IServerOptions);
constructor(server: ServerType, path: string | RegExp, services: IServices, wsdl: WSDL, options?: IServerOptions);
addSoapHeader(soapHeader: any, name?: string, namespace?: any, xmlns?: string): number;

@@ -43,0 +43,0 @@ changeSoapHeader(index: any, soapHeader: any, name?: any, namespace?: any, xmlns?: any): void;

@@ -64,5 +64,8 @@ "use strict";

_this_1.callback = options.callback ? options.callback : function () { };
if (path[path.length - 1] !== '/') {
if (typeof path === 'string' && path[path.length - 1] !== '/') {
path += '/';
}
else if (path instanceof RegExp && path.source[path.source.length - 1] !== '/') {
path = new RegExp(path.source + '(?:\\/|)');
}
wsdl.onReady(function (err) {

@@ -96,3 +99,3 @@ if (isExpress(server)) {

}
if (path === reqPath) {
if (path === reqPath || (path instanceof RegExp && reqPath.match(path))) {
_this_1._requestListener(req, res);

@@ -99,0 +102,0 @@ }

@@ -17,3 +17,3 @@ import { Client } from './client';

export declare function createClientAsync(url: string, options?: IOptions, endpoint?: string): Promise<Client>;
export declare function listen(server: ServerType, path: string, services: IServices, wsdl: string, callback?: (err: any, res: any) => void): Server;
export declare function listen(server: ServerType, path: string | RegExp, services: IServices, wsdl: string, callback?: (err: any, res: any) => void): Server;
export declare function listen(server: ServerType, options: IServerOptions): Server;

@@ -117,3 +117,3 @@ "use strict";

var uri = '';
if (typeof p2 === 'object') {
if (typeof p2 === 'object' && !(p2 instanceof RegExp)) {
// p2 is options

@@ -120,0 +120,0 @@ // server, options

@@ -1,2 +0,4 @@

import * as req from 'request';
/// <reference types="node" />
import * as req from 'axios';
import { ReadStream } from 'fs';
export interface IHeaders {

@@ -9,4 +11,4 @@ [k: string]: any;

export interface IHttpClient {
request(rurl: string, data: any, callback: (error: any, res?: any, body?: any) => any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): any;
requestStream?(rurl: string, data: any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): req.Request;
request(rurl: string, data: any, callback: (error: any, res?: any, body?: any) => any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): req.AxiosPromise;
requestStream?(rurl: string, data: any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): req.AxiosPromise<ReadStream>;
}

@@ -110,3 +112,3 @@ /** @deprecated use SoapMethod */

/** override the request module. */
request?: req.RequestAPI<req.Request, req.CoreOptions, req.RequiredUriUrl>;
request?: req.AxiosInstance;
stream?: boolean;

@@ -123,3 +125,3 @@ returnSaxStream?: boolean;

export interface IServerOptions extends IWsdlBaseOptions {
path: string;
path: string | RegExp;
services: IServices;

@@ -126,0 +128,0 @@ xml?: string;

@@ -404,3 +404,4 @@ "use strict";

var typeElement = schema && (schema.complexTypes[typeName] ||
schema.types[typeName] || schema.elements[typeName]);
schema.types[typeName] ||
schema.elements[typeName]);
if (typeElement) {

@@ -407,0 +408,0 @@ var base = typeElement.description(definitions, schema.xmlns);

@@ -1271,3 +1271,3 @@ "use strict";

}
else if (response && response.statusCode === 200) {
else if (response && response.status === 200) {
wsdl = new WSDL(definition, uri, options);

@@ -1279,3 +1279,3 @@ WSDL_CACHE[uri] = wsdl;

else {
callback(new Error('Invalid WSDL URL: ' + uri + '\n\n\r Code: ' + response.statusCode + '\n\n\r Response Body: ' + response.body));
callback(new Error('Invalid WSDL URL: ' + uri + '\n\n\r Code: ' + response.status + '\n\n\r Response Body: ' + response.data));
}

@@ -1282,0 +1282,0 @@ }, request_headers, request_options);

{
"name": "soap",
"version": "0.39.0",
"version": "0.40.0",
"description": "A minimal node SOAP client",

@@ -10,10 +10,10 @@ "engines": {

"dependencies": {
"debug": "^4.1.1",
"get-stream": "^6.0.0",
"httpntlm": "^1.5.2",
"lodash": "^4.17.19",
"request": ">=2.9.0",
"axios": "^0.21.1",
"axios-ntlm": "^1.1.6",
"debug": "^4.3.1",
"get-stream": "^6.0.1",
"lodash": "^4.17.21",
"sax": ">=0.6",
"strip-bom": "^3.0.0",
"uuid": "^8.3.0",
"uuid": "^8.3.2",
"xml-crypto": "^2.1.0"

@@ -50,4 +50,4 @@ },

"@types/express": "^4.16.1",
"@types/lodash": "^4.14.122",
"@types/node": "^11.11.0",
"@types/lodash": "^4.14.169",
"@types/node": "^11.15.54",
"@types/request": "^2.48.1",

@@ -64,3 +64,3 @@ "@types/sax": "^1.0.1",

"finalhandler": "^1.1.1",
"glob": "^7.1.3",
"glob": "^7.1.7",
"jshint": "^2.10.1",

@@ -67,0 +67,0 @@ "mocha": "^6.1.4",

@@ -116,3 +116,3 @@ # Soap [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]

```
This client has a built in WSDL cache. You can use the `disableCache` option to disable it.
This client (WSDL files and specified options) has a built in WSDL cache. You can use the `disableCache` option to disable it.

@@ -132,3 +132,3 @@ ### soap.createClientAsync(url[, options]) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.

This client has a built in WSDL cache. You can use the `disableCache` option to disable it.
This client (WSDL files and specified options) has a built in WSDL cache. You can use the `disableCache` option to disable it.

@@ -150,3 +150,3 @@ #### Options

- wsdl_options: custom options for the request module on WSDL requests.
- disableCache: don't cache WSDL files, request them every time.
- disableCache: don't cache WSDL files and client options, request them every time.
- overridePromiseSuffix: if your wsdl operations contains names with Async suffix, you will need to override the default promise suffix to a custom one, default: `Async`.

@@ -153,0 +153,0 @@ - normalizeNames: if your wsdl operations contains names with non identifier characters (`[^a-z$_0-9]`), replace them with `_`. Note: if using this option, clients using wsdls with two operations like `soap:method` and `soap-method` will be overwritten. Then, use bracket notation instead (`client['soap:method']()`).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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