soap 0.45.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.
Files changed (48) hide show
  1. package/History.md +7 -0
  2. package/Readme.md +12 -0
  3. package/lib/client.d.ts +1 -0
  4. package/lib/client.js +168 -187
  5. package/lib/client.js.map +1 -1
  6. package/lib/http.d.ts +1 -0
  7. package/lib/http.js +91 -101
  8. package/lib/http.js.map +1 -1
  9. package/lib/nscontext.js +38 -40
  10. package/lib/nscontext.js.map +1 -1
  11. package/lib/security/BasicAuthSecurity.js +11 -12
  12. package/lib/security/BasicAuthSecurity.js.map +1 -1
  13. package/lib/security/BearerSecurity.js +11 -12
  14. package/lib/security/BearerSecurity.js.map +1 -1
  15. package/lib/security/ClientSSLSecurity.js +12 -13
  16. package/lib/security/ClientSSLSecurity.js.map +1 -1
  17. package/lib/security/ClientSSLSecurityPFX.js +11 -12
  18. package/lib/security/ClientSSLSecurityPFX.js.map +1 -1
  19. package/lib/security/NTLMSecurity.js +12 -13
  20. package/lib/security/NTLMSecurity.js.map +1 -1
  21. package/lib/security/WSSecurity.js +21 -22
  22. package/lib/security/WSSecurity.js.map +1 -1
  23. package/lib/security/WSSecurityCert.d.ts +1 -0
  24. package/lib/security/WSSecurityCert.js +74 -56
  25. package/lib/security/WSSecurityCert.js.map +1 -1
  26. package/lib/security/WSSecurityPlusCert.d.ts +9 -0
  27. package/lib/security/WSSecurityPlusCert.js +17 -0
  28. package/lib/security/WSSecurityPlusCert.js.map +1 -0
  29. package/lib/security/index.d.ts +1 -0
  30. package/lib/security/index.js +8 -3
  31. package/lib/security/index.js.map +1 -1
  32. package/lib/server.d.ts +1 -0
  33. package/lib/server.js +189 -209
  34. package/lib/server.js.map +1 -1
  35. package/lib/soap.d.ts +1 -1
  36. package/lib/soap.js +45 -40
  37. package/lib/soap.js.map +1 -1
  38. package/lib/types.d.ts +1 -0
  39. package/lib/types.js +1 -1
  40. package/lib/utils.d.ts +1 -1
  41. package/lib/utils.js +55 -53
  42. package/lib/utils.js.map +1 -1
  43. package/lib/wsdl/elements.js +393 -515
  44. package/lib/wsdl/elements.js.map +1 -1
  45. package/lib/wsdl/index.js +322 -322
  46. package/lib/wsdl/index.js.map +1 -1
  47. package/package.json +8 -7
  48. package/tsconfig.json +2 -1
package/History.md CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  0.45.0 / 2022-06-15
2
9
  ===================
3
10
  * [FIX] axios peer dependency version (#1188)
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
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { EventEmitter } from 'events';
3
4
  import { IncomingHttpHeaders } from 'http';
4
5
  import { IHeaders, IMTOMAttachments, IOptions, ISecurity } from './types';
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
- var __extends = (this && this.__extends) || (function () {
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
- var assert = require("assert");
22
- var debugBuilder = require("debug");
23
- var events_1 = require("events");
24
- var getStream = require("get-stream");
25
- var _ = require("lodash");
26
- var uuid_1 = require("uuid");
27
- var http_1 = require("./http");
28
- var utils_1 = require("./utils");
29
- var debug = debugBuilder('node-soap');
30
- var nonIdentifierChars = /[^a-z$_0-9]/i;
31
- var Client = /** @class */ (function (_super) {
32
- __extends(Client, _super);
33
- function Client(wsdl, endpoint, options) {
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
- _this_1.wsdl = wsdl;
37
- _this_1._initializeOptions(options);
38
- _this_1._initializeServices(endpoint);
39
- _this_1.httpClient = options.httpClient || new http_1.HttpClient(options);
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
- Client.prototype.addSoapHeader = function (soapHeader, name, namespace, xmlns) {
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
- Client.prototype.changeSoapHeader = function (index, soapHeader, name, namespace, xmlns) {
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
- Client.prototype.getSoapHeaders = function () {
43
+ getSoapHeaders() {
59
44
  return this.soapHeaders;
60
- };
45
+ }
61
46
  /** remove all defined headers */
62
- Client.prototype.clearSoapHeaders = function () {
47
+ clearSoapHeaders() {
63
48
  this.soapHeaders = null;
64
- };
65
- Client.prototype.addHttpHeader = function (name, value) {
49
+ }
50
+ addHttpHeader(name, value) {
66
51
  if (!this.httpHeaders) {
67
52
  this.httpHeaders = {};
68
53
  }
69
54
  this.httpHeaders[name] = value;
70
- };
71
- Client.prototype.getHttpHeaders = function () {
55
+ }
56
+ getHttpHeaders() {
72
57
  return this.httpHeaders;
73
- };
74
- Client.prototype.clearHttpHeaders = function () {
58
+ }
59
+ clearHttpHeaders() {
75
60
  this.httpHeaders = null;
76
- };
77
- Client.prototype.addBodyAttribute = function (bodyAttribute, name, namespace, xmlns) {
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
- var composition_1 = '';
83
- Object.getOwnPropertyNames(bodyAttribute).forEach(function (prop, idx, array) {
84
- composition_1 += ' ' + prop + '="' + bodyAttribute[prop] + '"';
67
+ let composition = '';
68
+ Object.getOwnPropertyNames(bodyAttribute).forEach((prop, idx, array) => {
69
+ composition += ' ' + prop + '="' + bodyAttribute[prop] + '"';
85
70
  });
86
- bodyAttribute = composition_1;
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
- Client.prototype.getBodyAttributes = function () {
77
+ }
78
+ getBodyAttributes() {
94
79
  return this.bodyAttributes;
95
- };
96
- Client.prototype.clearBodyAttributes = function () {
80
+ }
81
+ clearBodyAttributes() {
97
82
  this.bodyAttributes = null;
98
- };
83
+ }
99
84
  /** overwrite the SOAP service endpoint address */
100
- Client.prototype.setEndpoint = function (endpoint) {
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
- Client.prototype.describe = function () {
90
+ describe() {
106
91
  return this.wsdl.describeServices();
107
- };
92
+ }
108
93
  /** use the specified security protocol */
109
- Client.prototype.setSecurity = function (security) {
94
+ setSecurity(security) {
110
95
  this.security = security;
111
- };
112
- Client.prototype.setSOAPAction = function (SOAPAction) {
96
+ }
97
+ setSOAPAction(SOAPAction) {
113
98
  this.SOAPAction = SOAPAction;
114
- };
115
- Client.prototype._initializeServices = function (endpoint) {
116
- var definitions = this.wsdl.definitions;
117
- var services = definitions.services;
118
- for (var name_1 in services) {
119
- this[name_1] = this._defineService(services[name_1], endpoint);
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
- Client.prototype._initializeOptions = function (options) {
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
- var igNs = options.ignoredNamespaces;
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
- Client.prototype._defineService = function (service, endpoint) {
146
- var ports = service.ports;
147
- var def = {};
148
- for (var name_2 in ports) {
149
- def[name_2] = this._definePort(ports[name_2], endpoint ? endpoint : ports[name_2].location);
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
- Client.prototype._definePort = function (port, endpoint) {
154
- var location = endpoint;
155
- var binding = port.binding;
156
- var methods = binding.methods;
157
- var def = {};
158
- for (var name_3 in methods) {
159
- def[name_3] = this._defineMethod(methods[name_3], location);
160
- var methodName = this.normalizeNames ? name_3.replace(nonIdentifierChars, '_') : name_3;
161
- this[methodName] = def[name_3];
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
- var suffix = this.overridePromiseSuffix;
164
- this[methodName + suffix] = this._promisifyMethod(def[name_3]);
148
+ const suffix = this.overridePromiseSuffix;
149
+ this[methodName + suffix] = this._promisifyMethod(def[name]);
165
150
  }
166
151
  }
167
152
  return def;
168
- };
169
- Client.prototype._promisifyMethod = function (method) {
170
- return function (args, options, extraHeaders) {
171
- return new Promise(function (resolve, reject) {
172
- var callback = function (err, result, rawResponse, soapHeader, rawRequest, mtomAttachments) {
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
- Client.prototype._defineMethod = function (method, location) {
185
- var _this_1 = this;
186
- var temp;
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
- _this_1._invoke(method, args, location, function (error, result, rawResponse, soapHeader, rawRequest, mtomAttachments) {
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
- Client.prototype._processSoapHeader = function (soapHeader, name, namespace, xmlns) {
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
- var _this_2 = this;
197
+ const _this = this;
214
198
  // arrow function does not support arguments variable
215
199
  // tslint:disable-next-line
216
200
  return function () {
217
- var result = soapHeader.apply(null, arguments);
201
+ const result = soapHeader.apply(null, arguments);
218
202
  if (typeof result === 'object') {
219
- return _this_2.wsdl.objectToXML(result, name, namespace, xmlns, true);
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
- Client.prototype._invoke = function (method, args, location, callback, options, extraHeaders) {
230
- var _this_1 = this;
231
- var name = method.$name;
232
- var input = method.input;
233
- var output = method.output;
234
- var style = method.style;
235
- var defs = this.wsdl.definitions;
236
- var envelopeKey = this.wsdl.options.envelopeKey;
237
- var ns = defs.$targetNamespace;
238
- var encoding = '';
239
- var message = '';
240
- var xml = null;
241
- var soapAction;
242
- var alias = utils_1.findPrefix(defs.xmlns, ns);
243
- var headers = {
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
- var xmlnsSoap = 'xmlns:' + envelopeKey + '="http://schemas.xmlsoap.org/soap/envelope/"';
247
- var finish = function (obj, body, response) {
248
- var result;
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
- var error = new Error('Error http status codes');
239
+ const error = new Error('Error http status codes');
257
240
  error.response = response;
258
241
  error.body = body;
259
- _this_1.emit('soapError', error, eid);
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
- var error = new Error('Cannot parse response');
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(function (term) {
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
- var parseSync = function (body, response) {
287
- var obj;
269
+ const parseSync = (body, response) => {
270
+ let obj;
288
271
  try {
289
- obj = _this_1.wsdl.xmlToObject(body);
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
- var json = _.isObject(body) ? body : tryJSONparse(body);
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
- _this_1.emit('soapError', error, eid);
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'] = "application/soap+xml; charset=utf-8; action=\"" + soapAction + "\"";
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
- var decodedHeaders;
326
+ let decodedHeaders;
344
327
  if (this.soapHeaders) {
345
- decodedHeaders = this.soapHeaders.map(function (header) {
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
- var eid = options.exchangeId || uuid_1.v4();
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 (var header in this.httpHeaders) {
373
+ for (const header in this.httpHeaders) {
392
374
  headers[header] = this.httpHeaders[header];
393
375
  }
394
- for (var attr in extraHeaders) {
376
+ for (const attr in extraHeaders) {
395
377
  headers[attr] = extraHeaders[attr];
396
378
  }
397
379
  }
398
- var tryJSONparse = function (body) {
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
- var startTime_1 = Date.now();
409
- var onError_1 = function (err) {
410
- _this_1.lastResponse = null;
411
- _this_1.lastResponseHeaders = null;
412
- _this_1.lastElapsedTime = null;
413
- _this_1.lastRequestHeaders = err.config && err.config.headers;
414
- _this_1.emit('response', null, null, eid);
415
- if (_this_1.returnSaxStream || !err.response || !err.response.data) {
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', function (e) {
401
+ err.response.data.on('close', (e) => {
420
402
  callback(err, undefined, undefined, undefined, xml);
421
403
  });
422
- err.response.data.on('data', function (e) {
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(function (res) {
428
- _this_1.lastRequestHeaders = res.headers;
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', function (err) { return onError_1(err); });
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(function (body) {
436
- _this_1.lastResponse = body;
437
- _this_1.lastElapsedTime = Date.now() - startTime_1;
438
- _this_1.lastResponseHeaders = res && res.headers;
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
- _this_1.lastRequestHeaders = res.config && res.config.headers || res.headers;
441
- _this_1.emit('response', body, res, eid);
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 (_this_1.returnSaxStream) {
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
- var saxStream = _this_1.wsdl.getSaxStream(res.data);
450
- return finish({ saxStream: saxStream }, '<stream>', res.data);
431
+ const saxStream = this.wsdl.getSaxStream(res.data);
432
+ return finish({ saxStream }, '<stream>', res.data);
451
433
  }
452
434
  else {
453
- _this_1.wsdl.xmlToObject(res.data, function (error, obj) {
454
- _this_1.lastResponse = res;
455
- _this_1.lastElapsedTime = Date.now() - startTime_1;
456
- _this_1.lastResponseHeaders = res && res.headers;
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
- _this_1.lastRequestHeaders = res.config.headers;
459
- _this_1.emit('response', '<stream>', res.data, eid);
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
- _this_1.emit('soapError', error, eid);
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
- }, onError_1);
451
+ }, onError);
470
452
  return;
471
453
  }
472
- var startTime = Date.now();
473
- return this.httpClient.request(location, xml, function (err, response, body) {
474
- _this_1.lastResponse = body;
454
+ const startTime = Date.now();
455
+ return this.httpClient.request(location, xml, (err, response, body) => {
456
+ this.lastResponse = body;
475
457
  if (response) {
476
- _this_1.lastResponseHeaders = response.headers;
477
- _this_1.lastElapsedTime = Date.now() - startTime;
478
- _this_1.lastResponseAttachments = response.mtomResponseAttachments;
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
- _this_1.lastRequestHeaders = response.config && response.config.headers;
462
+ this.lastRequestHeaders = response.config && response.config.headers;
481
463
  }
482
- _this_1.emit('response', body, response, eid);
464
+ this.emit('response', body, response, eid);
483
465
  if (err) {
484
- _this_1.lastRequestHeaders = err.config && err.config.headers;
466
+ this.lastRequestHeaders = err.config && err.config.headers;
485
467
  try {
486
468
  if (err.response && err.response.data) {
487
- _this_1.wsdl.xmlToObject(err.response.data);
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
- return Client;
501
- }(events_1.EventEmitter));
481
+ }
482
+ }
502
483
  exports.Client = Client;
503
484
  //# sourceMappingURL=client.js.map