soap 0.44.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +12 -0
- package/Readme.md +12 -0
- package/lib/client.d.ts +1 -0
- package/lib/client.js +168 -187
- package/lib/client.js.map +1 -1
- package/lib/http.d.ts +1 -0
- package/lib/http.js +91 -101
- package/lib/http.js.map +1 -1
- package/lib/nscontext.js +38 -40
- package/lib/nscontext.js.map +1 -1
- package/lib/security/BasicAuthSecurity.js +11 -12
- package/lib/security/BasicAuthSecurity.js.map +1 -1
- package/lib/security/BearerSecurity.js +11 -12
- package/lib/security/BearerSecurity.js.map +1 -1
- package/lib/security/ClientSSLSecurity.js +12 -13
- package/lib/security/ClientSSLSecurity.js.map +1 -1
- package/lib/security/ClientSSLSecurityPFX.js +11 -12
- package/lib/security/ClientSSLSecurityPFX.js.map +1 -1
- package/lib/security/NTLMSecurity.js +12 -13
- package/lib/security/NTLMSecurity.js.map +1 -1
- package/lib/security/WSSecurity.js +21 -22
- package/lib/security/WSSecurity.js.map +1 -1
- package/lib/security/WSSecurityCert.d.ts +1 -0
- package/lib/security/WSSecurityCert.js +74 -56
- package/lib/security/WSSecurityCert.js.map +1 -1
- package/lib/security/WSSecurityPlusCert.d.ts +9 -0
- package/lib/security/WSSecurityPlusCert.js +17 -0
- package/lib/security/WSSecurityPlusCert.js.map +1 -0
- package/lib/security/index.d.ts +1 -0
- package/lib/security/index.js +8 -3
- package/lib/security/index.js.map +1 -1
- package/lib/server.d.ts +1 -0
- package/lib/server.js +189 -209
- package/lib/server.js.map +1 -1
- package/lib/soap.d.ts +1 -1
- package/lib/soap.js +45 -40
- package/lib/soap.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.js +1 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +54 -49
- package/lib/utils.js.map +1 -1
- package/lib/wsdl/elements.js +393 -515
- package/lib/wsdl/elements.js.map +1 -1
- package/lib/wsdl/index.js +322 -322
- package/lib/wsdl/index.js.map +1 -1
- package/package.json +9 -7
- package/tsconfig.json +2 -1
package/History.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
1.0.0 / 2022-12-09
|
|
2
|
+
===================
|
|
3
|
+
* [ENHANCEMENT] allow soap.createClient to create a new SOAP client from a WSDL string (#1191)
|
|
4
|
+
* [FIX] Bump xml-crypto (#1200)
|
|
5
|
+
* [FIX] Upgrade to Formidable 3, Node 14, and audit fix (#1192)
|
|
6
|
+
* [FIX] Allow WSSecurity and WSSecurityCert to be used together (#1195)
|
|
7
|
+
|
|
8
|
+
0.45.0 / 2022-06-15
|
|
9
|
+
===================
|
|
10
|
+
* [FIX] axios peer dependency version (#1188)
|
|
11
|
+
* [MAINTENANCE] Upgrade formidable to v2 (#1183)
|
|
12
|
+
|
|
1
13
|
0.44.0 / 2022-06-06
|
|
2
14
|
===================
|
|
3
15
|
* [DOC] Readme.md: Rewrite how to get support for conciseness, update mentions of the old request module to Axios, improve documentation of several functions' arguments. (#1175)
|
package/Readme.md
CHANGED
|
@@ -929,6 +929,18 @@ The `options` object is optional and can contain the following properties:
|
|
|
929
929
|
* `existingPrefixes`: (optional) A hash of prefixes and namespaces prefix: namespace that shouldn't be in the signature because they already exist in the xml (default: `{ 'wsse': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' }`)
|
|
930
930
|
* `prefix`: (optional) Adds this value as a prefix for the generated signature tags.
|
|
931
931
|
* `attrs`: (optional) A hash of attributes and values attrName: value to add to the signature root node
|
|
932
|
+
* `idMode`: (optional) either 'wssecurity' to generate wsse-scoped reference Id on <Body> or undefined for an unscoped reference Id
|
|
933
|
+
|
|
934
|
+
### WSSecurityPlusCert
|
|
935
|
+
|
|
936
|
+
Use WSSecurity and WSSecurityCert together.
|
|
937
|
+
|
|
938
|
+
``` javascript
|
|
939
|
+
var wsSecurity = new soap.WSSecurity(/* see WSSecurity above */);
|
|
940
|
+
var wsSecurityCert = new soap.WSSecurityCert(/* see WSSecurityCert above */);
|
|
941
|
+
var wsSecurityPlusCert = new soap.WSSecurityPlusCert(wsSecurity, wsSecurityCert);
|
|
942
|
+
client.setSecurity(wsSecurityPlusCert);
|
|
943
|
+
```
|
|
932
944
|
|
|
933
945
|
#### Option examples
|
|
934
946
|
|
package/lib/client.d.ts
CHANGED
package/lib/client.js
CHANGED
|
@@ -3,123 +3,108 @@
|
|
|
3
3
|
* Copyright (c) 2011 Vinay Pulim <vinay@milewise.com>
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
var extendStatics = function (d, b) {
|
|
8
|
-
extendStatics = Object.setPrototypeOf ||
|
|
9
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
11
|
-
return extendStatics(d, b);
|
|
12
|
-
};
|
|
13
|
-
return function (d, b) {
|
|
14
|
-
extendStatics(d, b);
|
|
15
|
-
function __() { this.constructor = d; }
|
|
16
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
17
|
-
};
|
|
18
|
-
})();
|
|
19
|
-
exports.__esModule = true;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
7
|
exports.Client = void 0;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var _this_1 = _super.call(this) || this;
|
|
8
|
+
const assert = require("assert");
|
|
9
|
+
const debugBuilder = require("debug");
|
|
10
|
+
const events_1 = require("events");
|
|
11
|
+
const getStream = require("get-stream");
|
|
12
|
+
const _ = require("lodash");
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const http_1 = require("./http");
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
const debug = debugBuilder('node-soap');
|
|
17
|
+
const nonIdentifierChars = /[^a-z$_0-9]/i;
|
|
18
|
+
class Client extends events_1.EventEmitter {
|
|
19
|
+
constructor(wsdl, endpoint, options) {
|
|
20
|
+
super();
|
|
35
21
|
options = options || {};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return _this_1;
|
|
22
|
+
this.wsdl = wsdl;
|
|
23
|
+
this._initializeOptions(options);
|
|
24
|
+
this._initializeServices(endpoint);
|
|
25
|
+
this.httpClient = options.httpClient || new http_1.HttpClient(options);
|
|
41
26
|
}
|
|
42
27
|
/** add soapHeader to soap:Header node */
|
|
43
|
-
|
|
28
|
+
addSoapHeader(soapHeader, name, namespace, xmlns) {
|
|
44
29
|
if (!this.soapHeaders) {
|
|
45
30
|
this.soapHeaders = [];
|
|
46
31
|
}
|
|
47
32
|
soapHeader = this._processSoapHeader(soapHeader, name, namespace, xmlns);
|
|
48
33
|
return this.soapHeaders.push(soapHeader) - 1;
|
|
49
|
-
}
|
|
50
|
-
|
|
34
|
+
}
|
|
35
|
+
changeSoapHeader(index, soapHeader, name, namespace, xmlns) {
|
|
51
36
|
if (!this.soapHeaders) {
|
|
52
37
|
this.soapHeaders = [];
|
|
53
38
|
}
|
|
54
39
|
soapHeader = this._processSoapHeader(soapHeader, name, namespace, xmlns);
|
|
55
40
|
this.soapHeaders[index] = soapHeader;
|
|
56
|
-
}
|
|
41
|
+
}
|
|
57
42
|
/** return all defined headers */
|
|
58
|
-
|
|
43
|
+
getSoapHeaders() {
|
|
59
44
|
return this.soapHeaders;
|
|
60
|
-
}
|
|
45
|
+
}
|
|
61
46
|
/** remove all defined headers */
|
|
62
|
-
|
|
47
|
+
clearSoapHeaders() {
|
|
63
48
|
this.soapHeaders = null;
|
|
64
|
-
}
|
|
65
|
-
|
|
49
|
+
}
|
|
50
|
+
addHttpHeader(name, value) {
|
|
66
51
|
if (!this.httpHeaders) {
|
|
67
52
|
this.httpHeaders = {};
|
|
68
53
|
}
|
|
69
54
|
this.httpHeaders[name] = value;
|
|
70
|
-
}
|
|
71
|
-
|
|
55
|
+
}
|
|
56
|
+
getHttpHeaders() {
|
|
72
57
|
return this.httpHeaders;
|
|
73
|
-
}
|
|
74
|
-
|
|
58
|
+
}
|
|
59
|
+
clearHttpHeaders() {
|
|
75
60
|
this.httpHeaders = null;
|
|
76
|
-
}
|
|
77
|
-
|
|
61
|
+
}
|
|
62
|
+
addBodyAttribute(bodyAttribute, name, namespace, xmlns) {
|
|
78
63
|
if (!this.bodyAttributes) {
|
|
79
64
|
this.bodyAttributes = [];
|
|
80
65
|
}
|
|
81
66
|
if (typeof bodyAttribute === 'object') {
|
|
82
|
-
|
|
83
|
-
Object.getOwnPropertyNames(bodyAttribute).forEach(
|
|
84
|
-
|
|
67
|
+
let composition = '';
|
|
68
|
+
Object.getOwnPropertyNames(bodyAttribute).forEach((prop, idx, array) => {
|
|
69
|
+
composition += ' ' + prop + '="' + bodyAttribute[prop] + '"';
|
|
85
70
|
});
|
|
86
|
-
bodyAttribute =
|
|
71
|
+
bodyAttribute = composition;
|
|
87
72
|
}
|
|
88
73
|
if (bodyAttribute.substr(0, 1) !== ' ') {
|
|
89
74
|
bodyAttribute = ' ' + bodyAttribute;
|
|
90
75
|
}
|
|
91
76
|
this.bodyAttributes.push(bodyAttribute);
|
|
92
|
-
}
|
|
93
|
-
|
|
77
|
+
}
|
|
78
|
+
getBodyAttributes() {
|
|
94
79
|
return this.bodyAttributes;
|
|
95
|
-
}
|
|
96
|
-
|
|
80
|
+
}
|
|
81
|
+
clearBodyAttributes() {
|
|
97
82
|
this.bodyAttributes = null;
|
|
98
|
-
}
|
|
83
|
+
}
|
|
99
84
|
/** overwrite the SOAP service endpoint address */
|
|
100
|
-
|
|
85
|
+
setEndpoint(endpoint) {
|
|
101
86
|
this.endpoint = endpoint;
|
|
102
87
|
this._initializeServices(endpoint);
|
|
103
|
-
}
|
|
88
|
+
}
|
|
104
89
|
/** description of services, ports and methods as a JavaScript object */
|
|
105
|
-
|
|
90
|
+
describe() {
|
|
106
91
|
return this.wsdl.describeServices();
|
|
107
|
-
}
|
|
92
|
+
}
|
|
108
93
|
/** use the specified security protocol */
|
|
109
|
-
|
|
94
|
+
setSecurity(security) {
|
|
110
95
|
this.security = security;
|
|
111
|
-
}
|
|
112
|
-
|
|
96
|
+
}
|
|
97
|
+
setSOAPAction(SOAPAction) {
|
|
113
98
|
this.SOAPAction = SOAPAction;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
for (
|
|
119
|
-
this[
|
|
99
|
+
}
|
|
100
|
+
_initializeServices(endpoint) {
|
|
101
|
+
const definitions = this.wsdl.definitions;
|
|
102
|
+
const services = definitions.services;
|
|
103
|
+
for (const name in services) {
|
|
104
|
+
this[name] = this._defineService(services[name], endpoint);
|
|
120
105
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
106
|
+
}
|
|
107
|
+
_initializeOptions(options) {
|
|
123
108
|
this.streamAllowed = options.stream;
|
|
124
109
|
this.returnSaxStream = options.returnSaxStream;
|
|
125
110
|
this.normalizeNames = options.normalizeNames;
|
|
@@ -127,7 +112,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
127
112
|
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
|
|
128
113
|
this.wsdl.options.envelopeKey = options.envelopeKey || 'soap';
|
|
129
114
|
this.wsdl.options.preserveWhitespace = !!options.preserveWhitespace;
|
|
130
|
-
|
|
115
|
+
const igNs = options.ignoredNamespaces;
|
|
131
116
|
if (igNs !== undefined && typeof igNs === 'object') {
|
|
132
117
|
if ('override' in igNs) {
|
|
133
118
|
if (igNs.override === true) {
|
|
@@ -141,35 +126,35 @@ var Client = /** @class */ (function (_super) {
|
|
|
141
126
|
this.wsdl.options.overrideRootElement = options.overrideRootElement;
|
|
142
127
|
}
|
|
143
128
|
this.wsdl.options.forceSoap12Headers = !!options.forceSoap12Headers;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
for (
|
|
149
|
-
def[
|
|
129
|
+
}
|
|
130
|
+
_defineService(service, endpoint) {
|
|
131
|
+
const ports = service.ports;
|
|
132
|
+
const def = {};
|
|
133
|
+
for (const name in ports) {
|
|
134
|
+
def[name] = this._definePort(ports[name], endpoint ? endpoint : ports[name].location);
|
|
150
135
|
}
|
|
151
136
|
return def;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
for (
|
|
159
|
-
def[
|
|
160
|
-
|
|
161
|
-
this[methodName] = def[
|
|
137
|
+
}
|
|
138
|
+
_definePort(port, endpoint) {
|
|
139
|
+
const location = endpoint;
|
|
140
|
+
const binding = port.binding;
|
|
141
|
+
const methods = binding.methods;
|
|
142
|
+
const def = {};
|
|
143
|
+
for (const name in methods) {
|
|
144
|
+
def[name] = this._defineMethod(methods[name], location);
|
|
145
|
+
const methodName = this.normalizeNames ? name.replace(nonIdentifierChars, '_') : name;
|
|
146
|
+
this[methodName] = def[name];
|
|
162
147
|
if (!nonIdentifierChars.test(methodName)) {
|
|
163
|
-
|
|
164
|
-
this[methodName + suffix] = this._promisifyMethod(def[
|
|
148
|
+
const suffix = this.overridePromiseSuffix;
|
|
149
|
+
this[methodName + suffix] = this._promisifyMethod(def[name]);
|
|
165
150
|
}
|
|
166
151
|
}
|
|
167
152
|
return def;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return
|
|
171
|
-
return new Promise(
|
|
172
|
-
|
|
153
|
+
}
|
|
154
|
+
_promisifyMethod(method) {
|
|
155
|
+
return (args, options, extraHeaders) => {
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
const callback = (err, result, rawResponse, soapHeader, rawRequest, mtomAttachments) => {
|
|
173
158
|
if (err) {
|
|
174
159
|
reject(err);
|
|
175
160
|
}
|
|
@@ -180,11 +165,10 @@ var Client = /** @class */ (function (_super) {
|
|
|
180
165
|
method(args, callback, options, extraHeaders);
|
|
181
166
|
});
|
|
182
167
|
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return function (args, callback, options, extraHeaders) {
|
|
168
|
+
}
|
|
169
|
+
_defineMethod(method, location) {
|
|
170
|
+
let temp;
|
|
171
|
+
return (args, callback, options, extraHeaders) => {
|
|
188
172
|
if (typeof args === 'function') {
|
|
189
173
|
callback = args;
|
|
190
174
|
args = {};
|
|
@@ -200,23 +184,23 @@ var Client = /** @class */ (function (_super) {
|
|
|
200
184
|
extraHeaders = options;
|
|
201
185
|
options = temp;
|
|
202
186
|
}
|
|
203
|
-
|
|
187
|
+
this._invoke(method, args, location, (error, result, rawResponse, soapHeader, rawRequest, mtomAttachments) => {
|
|
204
188
|
callback(error, result, rawResponse, soapHeader, rawRequest, mtomAttachments);
|
|
205
189
|
}, options, extraHeaders);
|
|
206
190
|
};
|
|
207
|
-
}
|
|
208
|
-
|
|
191
|
+
}
|
|
192
|
+
_processSoapHeader(soapHeader, name, namespace, xmlns) {
|
|
209
193
|
switch (typeof soapHeader) {
|
|
210
194
|
case 'object':
|
|
211
195
|
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
|
|
212
196
|
case 'function':
|
|
213
|
-
|
|
197
|
+
const _this = this;
|
|
214
198
|
// arrow function does not support arguments variable
|
|
215
199
|
// tslint:disable-next-line
|
|
216
200
|
return function () {
|
|
217
|
-
|
|
201
|
+
const result = soapHeader.apply(null, arguments);
|
|
218
202
|
if (typeof result === 'object') {
|
|
219
|
-
return
|
|
203
|
+
return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
|
|
220
204
|
}
|
|
221
205
|
else {
|
|
222
206
|
return result;
|
|
@@ -225,27 +209,26 @@ var Client = /** @class */ (function (_super) {
|
|
|
225
209
|
default:
|
|
226
210
|
return soapHeader;
|
|
227
211
|
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
'Content-Type': 'text/xml; charset=utf-8'
|
|
212
|
+
}
|
|
213
|
+
_invoke(method, args, location, callback, options, extraHeaders) {
|
|
214
|
+
const name = method.$name;
|
|
215
|
+
const input = method.input;
|
|
216
|
+
const output = method.output;
|
|
217
|
+
const style = method.style;
|
|
218
|
+
const defs = this.wsdl.definitions;
|
|
219
|
+
const envelopeKey = this.wsdl.options.envelopeKey;
|
|
220
|
+
const ns = defs.$targetNamespace;
|
|
221
|
+
let encoding = '';
|
|
222
|
+
let message = '';
|
|
223
|
+
let xml = null;
|
|
224
|
+
let soapAction;
|
|
225
|
+
const alias = (0, utils_1.findPrefix)(defs.xmlns, ns);
|
|
226
|
+
let headers = {
|
|
227
|
+
'Content-Type': 'text/xml; charset=utf-8',
|
|
245
228
|
};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
229
|
+
let xmlnsSoap = 'xmlns:' + envelopeKey + '="http://schemas.xmlsoap.org/soap/envelope/"';
|
|
230
|
+
const finish = (obj, body, response) => {
|
|
231
|
+
let result;
|
|
249
232
|
if (!output) {
|
|
250
233
|
// one-way, no output expected
|
|
251
234
|
return callback(null, null, body, obj.Header, xml, response.mtomResponseAttachments);
|
|
@@ -253,16 +236,16 @@ var Client = /** @class */ (function (_super) {
|
|
|
253
236
|
// If it's not HTML and Soap Body is empty
|
|
254
237
|
if (!obj.html && !obj.Body) {
|
|
255
238
|
if (response.status >= 400) {
|
|
256
|
-
|
|
239
|
+
const error = new Error('Error http status codes');
|
|
257
240
|
error.response = response;
|
|
258
241
|
error.body = body;
|
|
259
|
-
|
|
242
|
+
this.emit('soapError', error, eid);
|
|
260
243
|
return callback(error, obj, body, obj.Header);
|
|
261
244
|
}
|
|
262
245
|
return callback(null, obj, body, obj.Header);
|
|
263
246
|
}
|
|
264
247
|
if (typeof obj.Body !== 'object') {
|
|
265
|
-
|
|
248
|
+
const error = new Error('Cannot parse response');
|
|
266
249
|
error.response = response;
|
|
267
250
|
error.body = body;
|
|
268
251
|
return callback(error, obj, body, undefined, xml);
|
|
@@ -275,7 +258,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
275
258
|
result = obj.Body[output.$name.replace(/(?:Out(?:put)?|Response)$/, '')];
|
|
276
259
|
}
|
|
277
260
|
if (!result) {
|
|
278
|
-
['Response', 'Out', 'Output'].forEach(
|
|
261
|
+
['Response', 'Out', 'Output'].forEach((term) => {
|
|
279
262
|
if (obj.Body.hasOwnProperty(name + term)) {
|
|
280
263
|
return result = obj.Body[name + term];
|
|
281
264
|
}
|
|
@@ -283,10 +266,10 @@ var Client = /** @class */ (function (_super) {
|
|
|
283
266
|
}
|
|
284
267
|
callback(null, result, body, obj.Header, xml, response.mtomResponseAttachments);
|
|
285
268
|
};
|
|
286
|
-
|
|
287
|
-
|
|
269
|
+
const parseSync = (body, response) => {
|
|
270
|
+
let obj;
|
|
288
271
|
try {
|
|
289
|
-
obj =
|
|
272
|
+
obj = this.wsdl.xmlToObject(body);
|
|
290
273
|
}
|
|
291
274
|
catch (error) {
|
|
292
275
|
// When the output element cannot be looked up in the wsdl and the body is JSON
|
|
@@ -294,14 +277,14 @@ var Client = /** @class */ (function (_super) {
|
|
|
294
277
|
if (!output || !output.$lookupTypes) {
|
|
295
278
|
debug('Response element is not present. Unable to convert response xml to json.');
|
|
296
279
|
// If the response is JSON then return it as-is.
|
|
297
|
-
|
|
280
|
+
const json = _.isObject(body) ? body : tryJSONparse(body);
|
|
298
281
|
if (json) {
|
|
299
282
|
return callback(null, response, json, undefined, xml);
|
|
300
283
|
}
|
|
301
284
|
}
|
|
302
285
|
error.response = response;
|
|
303
286
|
error.body = body;
|
|
304
|
-
|
|
287
|
+
this.emit('soapError', error, eid);
|
|
305
288
|
return callback(error, response, body, undefined, xml, response.mtomResponseAttachments);
|
|
306
289
|
}
|
|
307
290
|
return finish(obj, body, response);
|
|
@@ -316,7 +299,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
316
299
|
soapAction = ((ns.lastIndexOf('/') !== ns.length - 1) ? ns + '/' : ns) + name;
|
|
317
300
|
}
|
|
318
301
|
if (this.wsdl.options.forceSoap12Headers) {
|
|
319
|
-
headers['Content-Type'] =
|
|
302
|
+
headers['Content-Type'] = `application/soap+xml; charset=utf-8; action="${soapAction}"`;
|
|
320
303
|
xmlnsSoap = 'xmlns:' + envelopeKey + '="http://www.w3.org/2003/05/soap-envelope"';
|
|
321
304
|
}
|
|
322
305
|
else {
|
|
@@ -340,9 +323,9 @@ var Client = /** @class */ (function (_super) {
|
|
|
340
323
|
// pass `input.$lookupType` if `input.$type` could not be found
|
|
341
324
|
message = this.wsdl.objectToDocumentXML(input.$name, args, input.targetNSAlias, input.targetNamespace, (input.$type || input.$lookupType));
|
|
342
325
|
}
|
|
343
|
-
|
|
326
|
+
let decodedHeaders;
|
|
344
327
|
if (this.soapHeaders) {
|
|
345
|
-
decodedHeaders = this.soapHeaders.map(
|
|
328
|
+
decodedHeaders = this.soapHeaders.map((header) => {
|
|
346
329
|
if (typeof header === 'function') {
|
|
347
330
|
return header(method, location, soapAction, args);
|
|
348
331
|
}
|
|
@@ -366,7 +349,6 @@ var Client = /** @class */ (function (_super) {
|
|
|
366
349
|
'') +
|
|
367
350
|
'<' + envelopeKey + ':Body' +
|
|
368
351
|
(this.bodyAttributes ? this.bodyAttributes.join(' ') : '') +
|
|
369
|
-
(this.security && this.security.postProcess ? ' Id="_0"' : '') +
|
|
370
352
|
'>' +
|
|
371
353
|
message +
|
|
372
354
|
'</' + envelopeKey + ':Body>' +
|
|
@@ -380,7 +362,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
380
362
|
this.lastMessage = message;
|
|
381
363
|
this.lastRequest = xml;
|
|
382
364
|
this.lastEndpoint = location;
|
|
383
|
-
|
|
365
|
+
const eid = options.exchangeId || (0, uuid_1.v4)();
|
|
384
366
|
this.emit('message', message, eid);
|
|
385
367
|
this.emit('request', xml, eid);
|
|
386
368
|
// Add extra headers
|
|
@@ -388,14 +370,14 @@ var Client = /** @class */ (function (_super) {
|
|
|
388
370
|
headers = {};
|
|
389
371
|
}
|
|
390
372
|
else {
|
|
391
|
-
for (
|
|
373
|
+
for (const header in this.httpHeaders) {
|
|
392
374
|
headers[header] = this.httpHeaders[header];
|
|
393
375
|
}
|
|
394
|
-
for (
|
|
376
|
+
for (const attr in extraHeaders) {
|
|
395
377
|
headers[attr] = extraHeaders[attr];
|
|
396
378
|
}
|
|
397
379
|
}
|
|
398
|
-
|
|
380
|
+
const tryJSONparse = (body) => {
|
|
399
381
|
try {
|
|
400
382
|
return JSON.parse(body);
|
|
401
383
|
}
|
|
@@ -405,86 +387,86 @@ var Client = /** @class */ (function (_super) {
|
|
|
405
387
|
};
|
|
406
388
|
if (this.streamAllowed && typeof this.httpClient.requestStream === 'function') {
|
|
407
389
|
callback = _.once(callback);
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (
|
|
390
|
+
const startTime = Date.now();
|
|
391
|
+
const onError = (err) => {
|
|
392
|
+
this.lastResponse = null;
|
|
393
|
+
this.lastResponseHeaders = null;
|
|
394
|
+
this.lastElapsedTime = null;
|
|
395
|
+
this.lastRequestHeaders = err.config && err.config.headers;
|
|
396
|
+
this.emit('response', null, null, eid);
|
|
397
|
+
if (this.returnSaxStream || !err.response || !err.response.data) {
|
|
416
398
|
callback(err, undefined, undefined, undefined, xml);
|
|
417
399
|
}
|
|
418
400
|
else {
|
|
419
|
-
err.response.data.on('close',
|
|
401
|
+
err.response.data.on('close', (e) => {
|
|
420
402
|
callback(err, undefined, undefined, undefined, xml);
|
|
421
403
|
});
|
|
422
|
-
err.response.data.on('data',
|
|
404
|
+
err.response.data.on('data', (e) => {
|
|
423
405
|
err.response.data = e.toString();
|
|
424
406
|
});
|
|
425
407
|
}
|
|
426
408
|
};
|
|
427
|
-
this.httpClient.requestStream(location, xml, headers, options, this).then(
|
|
428
|
-
|
|
409
|
+
this.httpClient.requestStream(location, xml, headers, options, this).then((res) => {
|
|
410
|
+
this.lastRequestHeaders = res.headers;
|
|
429
411
|
if (res.data.on) {
|
|
430
|
-
res.data.on('error',
|
|
412
|
+
res.data.on('error', (err) => onError(err));
|
|
431
413
|
}
|
|
432
414
|
// When the output element cannot be looked up in the wsdl,
|
|
433
415
|
// play it safe and don't stream
|
|
434
416
|
if (res.status !== 200 || !output || !output.$lookupTypes) {
|
|
435
|
-
getStream(res.data).then(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
417
|
+
getStream(res.data).then((body) => {
|
|
418
|
+
this.lastResponse = body;
|
|
419
|
+
this.lastElapsedTime = Date.now() - startTime;
|
|
420
|
+
this.lastResponseHeaders = res && res.headers;
|
|
439
421
|
// Added mostly for testability, but possibly useful for debugging
|
|
440
|
-
|
|
441
|
-
|
|
422
|
+
this.lastRequestHeaders = res.config && res.config.headers || res.headers;
|
|
423
|
+
this.emit('response', body, res, eid);
|
|
442
424
|
return parseSync(body, res);
|
|
443
425
|
});
|
|
444
426
|
return;
|
|
445
427
|
}
|
|
446
|
-
if (
|
|
428
|
+
if (this.returnSaxStream) {
|
|
447
429
|
// directly return the saxStream allowing the end user to define
|
|
448
430
|
// the parsing logics and corresponding errors managements
|
|
449
|
-
|
|
450
|
-
return finish({ saxStream
|
|
431
|
+
const saxStream = this.wsdl.getSaxStream(res.data);
|
|
432
|
+
return finish({ saxStream }, '<stream>', res.data);
|
|
451
433
|
}
|
|
452
434
|
else {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
435
|
+
this.wsdl.xmlToObject(res.data, (error, obj) => {
|
|
436
|
+
this.lastResponse = res;
|
|
437
|
+
this.lastElapsedTime = Date.now() - startTime;
|
|
438
|
+
this.lastResponseHeaders = res && res.headers;
|
|
457
439
|
// Added mostly for testability, but possibly useful for debugging
|
|
458
|
-
|
|
459
|
-
|
|
440
|
+
this.lastRequestHeaders = res.config.headers;
|
|
441
|
+
this.emit('response', '<stream>', res.data, eid);
|
|
460
442
|
if (error) {
|
|
461
443
|
error.response = res;
|
|
462
444
|
error.body = '<stream>';
|
|
463
|
-
|
|
445
|
+
this.emit('soapError', error, eid);
|
|
464
446
|
return callback(error, res, undefined, undefined, xml);
|
|
465
447
|
}
|
|
466
448
|
return finish(obj, '<stream>', res);
|
|
467
449
|
});
|
|
468
450
|
}
|
|
469
|
-
},
|
|
451
|
+
}, onError);
|
|
470
452
|
return;
|
|
471
453
|
}
|
|
472
|
-
|
|
473
|
-
return this.httpClient.request(location, xml,
|
|
474
|
-
|
|
454
|
+
const startTime = Date.now();
|
|
455
|
+
return this.httpClient.request(location, xml, (err, response, body) => {
|
|
456
|
+
this.lastResponse = body;
|
|
475
457
|
if (response) {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
458
|
+
this.lastResponseHeaders = response.headers;
|
|
459
|
+
this.lastElapsedTime = Date.now() - startTime;
|
|
460
|
+
this.lastResponseAttachments = response.mtomResponseAttachments;
|
|
479
461
|
// Added mostly for testability, but possibly useful for debugging
|
|
480
|
-
|
|
462
|
+
this.lastRequestHeaders = response.config && response.config.headers;
|
|
481
463
|
}
|
|
482
|
-
|
|
464
|
+
this.emit('response', body, response, eid);
|
|
483
465
|
if (err) {
|
|
484
|
-
|
|
466
|
+
this.lastRequestHeaders = err.config && err.config.headers;
|
|
485
467
|
try {
|
|
486
468
|
if (err.response && err.response.data) {
|
|
487
|
-
|
|
469
|
+
this.wsdl.xmlToObject(err.response.data);
|
|
488
470
|
}
|
|
489
471
|
}
|
|
490
472
|
catch (error) {
|
|
@@ -496,8 +478,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
496
478
|
return parseSync(body, response);
|
|
497
479
|
}
|
|
498
480
|
}, headers, options, this);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
}(events_1.EventEmitter));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
502
483
|
exports.Client = Client;
|
|
503
484
|
//# sourceMappingURL=client.js.map
|