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/lib/server.js CHANGED
@@ -3,25 +3,12 @@
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.Server = void 0;
21
- var events_1 = require("events");
22
- var url = require("url");
23
- var utils_1 = require("./utils");
24
- var zlib;
8
+ const events_1 = require("events");
9
+ const url = require("url");
10
+ const utils_1 = require("./utils");
11
+ let zlib;
25
12
  try {
26
13
  zlib = require('zlib');
27
14
  }
@@ -44,104 +31,102 @@ function getDateString(d) {
44
31
  + pad(d.getUTCMinutes()) + ':'
45
32
  + pad(d.getUTCSeconds()) + 'Z';
46
33
  }
47
- var Server = /** @class */ (function (_super) {
48
- __extends(Server, _super);
49
- function Server(server, path, services, wsdl, options) {
50
- var _this_1 = _super.call(this) || this;
34
+ class Server extends events_1.EventEmitter {
35
+ constructor(server, path, services, wsdl, options) {
36
+ super();
51
37
  options = options || {
52
38
  path: path,
53
- services: services
39
+ services: services,
54
40
  };
55
- _this_1.path = path;
56
- _this_1.services = services;
57
- _this_1.wsdl = wsdl;
58
- _this_1.suppressStack = options && options.suppressStack;
59
- _this_1.returnFault = options && options.returnFault;
60
- _this_1.onewayOptions = options && options.oneWay || {};
61
- _this_1.enableChunkedEncoding =
41
+ this.path = path;
42
+ this.services = services;
43
+ this.wsdl = wsdl;
44
+ this.suppressStack = options && options.suppressStack;
45
+ this.returnFault = options && options.returnFault;
46
+ this.onewayOptions = options && options.oneWay || {};
47
+ this.enableChunkedEncoding =
62
48
  options.enableChunkedEncoding === undefined ? true : !!options.enableChunkedEncoding;
63
- _this_1.callback = options.callback ? options.callback : function () { };
49
+ this.callback = options.callback ? options.callback : () => { };
64
50
  if (typeof path === 'string' && path[path.length - 1] !== '/') {
65
51
  path += '/';
66
52
  }
67
53
  else if (path instanceof RegExp && path.source[path.source.length - 1] !== '/') {
68
54
  path = new RegExp(path.source + '(?:\\/|)');
69
55
  }
70
- wsdl.onReady(function (err) {
56
+ wsdl.onReady((err) => {
71
57
  if (isExpress(server)) {
72
58
  // handle only the required URL path for express server
73
- server.route(path).all(function (req, res) {
74
- if (typeof _this_1.authorizeConnection === 'function') {
75
- if (!_this_1.authorizeConnection(req, res)) {
59
+ server.route(path).all((req, res) => {
60
+ if (typeof this.authorizeConnection === 'function') {
61
+ if (!this.authorizeConnection(req, res)) {
76
62
  res.end();
77
63
  return;
78
64
  }
79
65
  }
80
- _this_1._requestListener(req, res);
66
+ this._requestListener(req, res);
81
67
  });
82
- _this_1.callback(err, _this_1);
68
+ this.callback(err, this);
83
69
  }
84
70
  else {
85
- var listeners_1 = server.listeners('request').slice();
71
+ const listeners = server.listeners('request').slice();
86
72
  server.removeAllListeners('request');
87
- server.addListener('request', function (req, res) {
88
- if (typeof _this_1.authorizeConnection === 'function') {
89
- if (!_this_1.authorizeConnection(req, res)) {
73
+ server.addListener('request', (req, res) => {
74
+ if (typeof this.authorizeConnection === 'function') {
75
+ if (!this.authorizeConnection(req, res)) {
90
76
  res.end();
91
77
  return;
92
78
  }
93
79
  }
94
- var reqPath = url.parse(req.url).pathname;
80
+ let reqPath = url.parse(req.url).pathname;
95
81
  if (reqPath[reqPath.length - 1] !== '/') {
96
82
  reqPath += '/';
97
83
  }
98
84
  if (path === reqPath || (path instanceof RegExp && reqPath.match(path))) {
99
- _this_1._requestListener(req, res);
85
+ this._requestListener(req, res);
100
86
  }
101
87
  else {
102
- for (var i = 0, len = listeners_1.length; i < len; i++) {
103
- listeners_1[i].call(_this_1, req, res);
88
+ for (let i = 0, len = listeners.length; i < len; i++) {
89
+ listeners[i].call(this, req, res);
104
90
  }
105
91
  }
106
92
  });
107
- _this_1.callback(err, _this_1);
93
+ this.callback(err, this);
108
94
  }
109
95
  });
110
- _this_1._initializeOptions(options);
111
- return _this_1;
96
+ this._initializeOptions(options);
112
97
  }
113
- Server.prototype.addSoapHeader = function (soapHeader, name, namespace, xmlns) {
98
+ addSoapHeader(soapHeader, name, namespace, xmlns) {
114
99
  if (!this.soapHeaders) {
115
100
  this.soapHeaders = [];
116
101
  }
117
102
  soapHeader = this._processSoapHeader(soapHeader, name, namespace, xmlns);
118
103
  return this.soapHeaders.push(soapHeader) - 1;
119
- };
120
- Server.prototype.changeSoapHeader = function (index, soapHeader, name, namespace, xmlns) {
104
+ }
105
+ changeSoapHeader(index, soapHeader, name, namespace, xmlns) {
121
106
  if (!this.soapHeaders) {
122
107
  this.soapHeaders = [];
123
108
  }
124
109
  soapHeader = this._processSoapHeader(soapHeader, name, namespace, xmlns);
125
110
  this.soapHeaders[index] = soapHeader;
126
- };
127
- Server.prototype.getSoapHeaders = function () {
111
+ }
112
+ getSoapHeaders() {
128
113
  return this.soapHeaders;
129
- };
130
- Server.prototype.clearSoapHeaders = function () {
114
+ }
115
+ clearSoapHeaders() {
131
116
  this.soapHeaders = null;
132
- };
133
- Server.prototype._processSoapHeader = function (soapHeader, name, namespace, xmlns) {
117
+ }
118
+ _processSoapHeader(soapHeader, name, namespace, xmlns) {
134
119
  switch (typeof soapHeader) {
135
120
  case 'object':
136
121
  return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
137
122
  case 'function':
138
- var _this_2 = this;
123
+ const _this = this;
139
124
  // arrow function does not support arguments variable
140
125
  // tslint:disable-next-line
141
126
  return function () {
142
- var result = soapHeader.apply(null, arguments);
127
+ const result = soapHeader.apply(null, arguments);
143
128
  if (typeof result === 'object') {
144
- return _this_2.wsdl.objectToXML(result, name, namespace, xmlns, true);
129
+ return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
145
130
  }
146
131
  else {
147
132
  return result;
@@ -150,32 +135,31 @@ var Server = /** @class */ (function (_super) {
150
135
  default:
151
136
  return soapHeader;
152
137
  }
153
- };
154
- Server.prototype._initializeOptions = function (options) {
138
+ }
139
+ _initializeOptions(options) {
155
140
  this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
156
141
  this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200;
157
142
  this.onewayOptions.emptyBody = !!this.onewayOptions.emptyBody;
158
- };
159
- Server.prototype._processRequestXml = function (req, res, xml) {
160
- var _this_1 = this;
161
- var error;
143
+ }
144
+ _processRequestXml(req, res, xml) {
145
+ let error;
162
146
  try {
163
147
  if (typeof this.log === 'function') {
164
148
  this.log('received', xml);
165
149
  }
166
- this._process(xml, req, res, function (result, statusCode) {
167
- _this_1._sendHttpResponse(res, statusCode, result);
168
- if (typeof _this_1.log === 'function') {
169
- _this_1.log('replied', result);
150
+ this._process(xml, req, res, (result, statusCode) => {
151
+ this._sendHttpResponse(res, statusCode, result);
152
+ if (typeof this.log === 'function') {
153
+ this.log('replied', result);
170
154
  }
171
155
  });
172
156
  }
173
157
  catch (err) {
174
158
  if (err.Fault !== undefined) {
175
- return this._sendError(err.Fault, function (result, statusCode) {
176
- _this_1._sendHttpResponse(res, statusCode || 500, result);
177
- if (typeof _this_1.log === 'function') {
178
- _this_1.log('error', err);
159
+ return this._sendError(err.Fault, (result, statusCode) => {
160
+ this._sendHttpResponse(res, statusCode || 500, result);
161
+ if (typeof this.log === 'function') {
162
+ this.log('error', err);
179
163
  }
180
164
  }, new Date().toISOString());
181
165
  }
@@ -187,12 +171,11 @@ var Server = /** @class */ (function (_super) {
187
171
  }
188
172
  }
189
173
  }
190
- };
191
- Server.prototype._requestListener = function (req, res) {
192
- var _this_1 = this;
193
- var reqParse = url.parse(req.url);
194
- var reqPath = reqParse.pathname;
195
- var reqQuery = reqParse.search;
174
+ }
175
+ _requestListener(req, res) {
176
+ const reqParse = url.parse(req.url);
177
+ const reqPath = reqParse.pathname;
178
+ const reqQuery = reqParse.search;
196
179
  if (typeof this.log === 'function') {
197
180
  this.log('info', 'Handling ' + req.method + ' on ' + req.url);
198
181
  }
@@ -218,55 +201,54 @@ var Server = /** @class */ (function (_super) {
218
201
  if (req.body && req.body.length > 0) {
219
202
  return this._processRequestXml(req, res, req.body.toString());
220
203
  }
221
- var chunks_1 = [];
222
- var gunzip = void 0;
223
- var source = req;
204
+ const chunks = [];
205
+ let gunzip;
206
+ let source = req;
224
207
  if (req.headers['content-encoding'] === 'gzip') {
225
208
  gunzip = zlib.createGunzip();
226
209
  req.pipe(gunzip);
227
210
  source = gunzip;
228
211
  }
229
- source.on('data', function (chunk) {
230
- chunks_1.push(chunk);
212
+ source.on('data', (chunk) => {
213
+ chunks.push(chunk);
231
214
  });
232
- source.on('end', function () {
233
- var xml = Buffer.concat(chunks_1).toString();
234
- _this_1._processRequestXml(req, res, xml);
215
+ source.on('end', () => {
216
+ const xml = Buffer.concat(chunks).toString();
217
+ this._processRequestXml(req, res, xml);
235
218
  });
236
219
  }
237
220
  else {
238
221
  res.end();
239
222
  }
240
- };
241
- Server.prototype._getSoapAction = function (req) {
223
+ }
224
+ _getSoapAction(req) {
242
225
  if (typeof req.headers.soapaction === 'undefined') {
243
226
  return;
244
227
  }
245
- var soapAction = req.headers.soapaction;
228
+ const soapAction = req.headers.soapaction;
246
229
  return (soapAction.indexOf('"') === 0)
247
230
  ? soapAction.slice(1, -1)
248
231
  : soapAction;
249
- };
250
- Server.prototype._process = function (input, req, res, cb) {
251
- var _this_1 = this;
252
- var pathname = url.parse(req.url).pathname.replace(/\/$/, '');
253
- var obj = this.wsdl.xmlToObject(input);
254
- var body = obj.Body;
255
- var headers = obj.Header;
256
- var binding;
257
- var methodName;
258
- var serviceName;
259
- var portName;
260
- var includeTimestamp = obj.Header && obj.Header.Security && obj.Header.Security.Timestamp;
261
- var authenticate = this.authenticate || function defaultAuthenticate() { return true; };
262
- var callback = function (result, statusCode) {
263
- var response = { result: result };
264
- _this_1.emit('response', response, methodName);
232
+ }
233
+ _process(input, req, res, cb) {
234
+ const pathname = url.parse(req.url).pathname.replace(/\/$/, '');
235
+ const obj = this.wsdl.xmlToObject(input);
236
+ const body = obj.Body;
237
+ const headers = obj.Header;
238
+ let binding;
239
+ let methodName;
240
+ let serviceName;
241
+ let portName;
242
+ const includeTimestamp = obj.Header && obj.Header.Security && obj.Header.Security.Timestamp;
243
+ const authenticate = this.authenticate || function defaultAuthenticate() { return true; };
244
+ const callback = (result, statusCode) => {
245
+ const response = { result: result };
246
+ this.emit('response', response, methodName);
265
247
  cb(response.result, statusCode);
266
248
  };
267
- var process = function () {
268
- if (typeof _this_1.log === 'function') {
269
- _this_1.log('info', 'Attempting to bind to ' + pathname);
249
+ const process = () => {
250
+ if (typeof this.log === 'function') {
251
+ this.log('info', 'Attempting to bind to ' + pathname);
270
252
  }
271
253
  // Avoid Cannot convert undefined or null to object due to Object.keys(body)
272
254
  // and throw more meaningful error
@@ -274,20 +256,20 @@ var Server = /** @class */ (function (_super) {
274
256
  throw new Error('Failed to parse the SOAP Message body');
275
257
  }
276
258
  // use port.location and current url to find the right binding
277
- binding = (function () {
278
- var services = _this_1.wsdl.definitions.services;
279
- var firstPort;
280
- var name;
259
+ binding = (() => {
260
+ const services = this.wsdl.definitions.services;
261
+ let firstPort;
262
+ let name;
281
263
  for (name in services) {
282
264
  serviceName = name;
283
- var service = services[serviceName];
284
- var ports = service.ports;
265
+ const service = services[serviceName];
266
+ const ports = service.ports;
285
267
  for (name in ports) {
286
268
  portName = name;
287
- var port = ports[portName];
288
- var portPathname = url.parse(port.location).pathname.replace(/\/$/, '');
289
- if (typeof _this_1.log === 'function') {
290
- _this_1.log('info', 'Trying ' + portName + ' from path ' + portPathname);
269
+ const port = ports[portName];
270
+ const portPathname = url.parse(port.location).pathname.replace(/\/$/, '');
271
+ if (typeof this.log === 'function') {
272
+ this.log('info', 'Trying ' + portName + ' from path ' + portPathname);
291
273
  }
292
274
  if (portPathname === pathname) {
293
275
  return port.binding;
@@ -304,68 +286,68 @@ var Server = /** @class */ (function (_super) {
304
286
  throw new Error('Failed to bind to WSDL');
305
287
  }
306
288
  try {
307
- var soapAction = _this_1._getSoapAction(req);
308
- var messageElemName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
309
- var pair = binding.topElements[messageElemName];
289
+ const soapAction = this._getSoapAction(req);
290
+ const messageElemName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
291
+ const pair = binding.topElements[messageElemName];
310
292
  if (soapAction) {
311
- methodName = _this_1._getMethodNameBySoapAction(binding, soapAction);
293
+ methodName = this._getMethodNameBySoapAction(binding, soapAction);
312
294
  }
313
295
  else {
314
296
  methodName = pair ? pair.methodName : messageElemName;
315
297
  }
316
298
  /** Style can be defined in method. If method has no style then look in binding */
317
- var style = binding.methods[methodName].style || binding.style;
318
- _this_1.emit('request', obj, methodName);
299
+ const style = binding.methods[methodName].style || binding.style;
300
+ this.emit('request', obj, methodName);
319
301
  if (headers) {
320
- _this_1.emit('headers', headers, methodName);
302
+ this.emit('headers', headers, methodName);
321
303
  }
322
304
  if (style === 'rpc') {
323
- _this_1._executeMethod({
305
+ this._executeMethod({
324
306
  serviceName: serviceName,
325
307
  portName: portName,
326
308
  methodName: methodName,
327
309
  outputName: messageElemName + 'Response',
328
310
  args: body[messageElemName],
329
311
  headers: headers,
330
- style: 'rpc'
312
+ style: 'rpc',
331
313
  }, req, res, callback);
332
314
  }
333
315
  else {
334
- _this_1._executeMethod({
316
+ this._executeMethod({
335
317
  serviceName: serviceName,
336
318
  portName: portName,
337
319
  methodName: methodName,
338
320
  outputName: pair.outputName,
339
321
  args: body[messageElemName],
340
322
  headers: headers,
341
- style: 'document'
323
+ style: 'document',
342
324
  }, req, res, callback, includeTimestamp);
343
325
  }
344
326
  }
345
327
  catch (error) {
346
328
  if (error.Fault !== undefined) {
347
- return _this_1._sendError(error.Fault, callback, includeTimestamp);
329
+ return this._sendError(error.Fault, callback, includeTimestamp);
348
330
  }
349
331
  throw error;
350
332
  }
351
333
  };
352
334
  // Authentication
353
335
  if (typeof authenticate === 'function') {
354
- var authResultProcessed_1 = false;
355
- var processAuthResult_1 = function (authResult) {
356
- if (authResultProcessed_1) {
336
+ let authResultProcessed = false;
337
+ const processAuthResult = (authResult) => {
338
+ if (authResultProcessed) {
357
339
  return;
358
340
  }
359
- authResultProcessed_1 = true;
341
+ authResultProcessed = true;
360
342
  // Handle errors
361
343
  if (authResult instanceof Error) {
362
- return _this_1._sendError({
344
+ return this._sendError({
363
345
  Code: {
364
346
  Value: 'SOAP-ENV:Server',
365
- Subcode: { Value: 'InternalServerError' }
347
+ Subcode: { Value: 'InternalServerError' },
366
348
  },
367
349
  Reason: { Text: authResult.toString() },
368
- statusCode: 500
350
+ statusCode: 500,
369
351
  }, callback, includeTimestamp);
370
352
  }
371
353
  // Handle actual results
@@ -376,70 +358,69 @@ var Server = /** @class */ (function (_super) {
376
358
  }
377
359
  catch (error) {
378
360
  if (error.Fault !== undefined) {
379
- return _this_1._sendError(error.Fault, callback, includeTimestamp);
361
+ return this._sendError(error.Fault, callback, includeTimestamp);
380
362
  }
381
- return _this_1._sendError({
363
+ return this._sendError({
382
364
  Code: {
383
365
  Value: 'SOAP-ENV:Server',
384
- Subcode: { Value: 'InternalServerError' }
366
+ Subcode: { Value: 'InternalServerError' },
385
367
  },
386
368
  Reason: { Text: error.toString() },
387
- statusCode: 500
369
+ statusCode: 500,
388
370
  }, callback, includeTimestamp);
389
371
  }
390
372
  }
391
373
  else {
392
- return _this_1._sendError({
374
+ return this._sendError({
393
375
  Code: {
394
376
  Value: 'SOAP-ENV:Client',
395
- Subcode: { Value: 'AuthenticationFailure' }
377
+ Subcode: { Value: 'AuthenticationFailure' },
396
378
  },
397
379
  Reason: { Text: 'Invalid username or password' },
398
- statusCode: 401
380
+ statusCode: 401,
399
381
  }, callback, includeTimestamp);
400
382
  }
401
383
  }
402
384
  };
403
- var functionResult = authenticate(obj.Header && obj.Header.Security, processAuthResult_1, req, obj);
385
+ const functionResult = authenticate(obj.Header && obj.Header.Security, processAuthResult, req, obj);
404
386
  if (isPromiseLike(functionResult)) {
405
- functionResult.then(function (result) {
406
- processAuthResult_1(result);
407
- }, function (err) {
408
- processAuthResult_1(err);
387
+ functionResult.then((result) => {
388
+ processAuthResult(result);
389
+ }, (err) => {
390
+ processAuthResult(err);
409
391
  });
410
392
  }
411
393
  if (typeof functionResult === 'boolean') {
412
- processAuthResult_1(functionResult);
394
+ processAuthResult(functionResult);
413
395
  }
414
396
  }
415
397
  else {
416
398
  throw new Error('Invalid authenticate function (not a function)');
417
399
  }
418
- };
419
- Server.prototype._getMethodNameBySoapAction = function (binding, soapAction) {
420
- for (var methodName in binding.methods) {
400
+ }
401
+ _getMethodNameBySoapAction(binding, soapAction) {
402
+ for (const methodName in binding.methods) {
421
403
  if (binding.methods[methodName].soapAction === soapAction) {
422
404
  return methodName;
423
405
  }
424
406
  }
425
- };
426
- Server.prototype._executeMethod = function (options, req, res, callback, includeTimestamp) {
427
- var _this_1 = this;
407
+ }
408
+ _executeMethod(options, req, res, callback, includeTimestamp) {
428
409
  options = options || {};
429
- var method;
430
- var body;
431
- var headers;
432
- var serviceName = options.serviceName;
433
- var portName = options.portName;
434
- var binding = this.wsdl.definitions.services[serviceName].ports[portName].binding;
435
- var methodName = options.methodName;
436
- var outputName = options.outputName;
437
- var args = options.args;
438
- var style = options.style;
410
+ let method;
411
+ let body;
412
+ let headers;
413
+ const serviceName = options.serviceName;
414
+ const portName = options.portName;
415
+ const binding = this.wsdl.definitions.services[serviceName].ports[portName].binding;
416
+ const methodName = options.methodName;
417
+ const outputName = options.outputName;
418
+ const args = options.args;
419
+ const style = options.style;
439
420
  if (this.soapHeaders) {
440
- headers = this.soapHeaders.map(function (header) {
421
+ headers = this.soapHeaders.map((header) => {
441
422
  if (typeof header === 'function') {
442
- return header(methodName, args, options.headers, req, res, _this_1);
423
+ return header(methodName, args, options.headers, req, res, this);
443
424
  }
444
425
  else {
445
426
  return header;
@@ -452,46 +433,46 @@ var Server = /** @class */ (function (_super) {
452
433
  catch (error) {
453
434
  return callback(this._envelope('', headers, includeTimestamp));
454
435
  }
455
- var handled = false;
456
- var handleResult = function (error, result) {
436
+ let handled = false;
437
+ const handleResult = (error, result) => {
457
438
  if (handled) {
458
439
  return;
459
440
  }
460
441
  handled = true;
461
442
  if (error) {
462
443
  if (error.Fault !== undefined) {
463
- return _this_1._sendError(error.Fault, callback, includeTimestamp);
444
+ return this._sendError(error.Fault, callback, includeTimestamp);
464
445
  }
465
446
  else {
466
- return _this_1._sendError({
447
+ return this._sendError({
467
448
  Code: {
468
449
  Value: 'SOAP-ENV:Server',
469
- Subcode: { Value: 'InternalServerError' }
450
+ Subcode: { Value: 'InternalServerError' },
470
451
  },
471
452
  Reason: { Text: error.toString() },
472
- statusCode: 500
453
+ statusCode: 500,
473
454
  }, callback, includeTimestamp);
474
455
  }
475
456
  }
476
457
  if (style === 'rpc') {
477
- body = _this_1.wsdl.objectToRpcXML(outputName, result, '', _this_1.wsdl.definitions.$targetNamespace);
458
+ body = this.wsdl.objectToRpcXML(outputName, result, '', this.wsdl.definitions.$targetNamespace);
478
459
  }
479
460
  else if (style === 'document') {
480
- var element = binding.methods[methodName].output;
481
- body = _this_1.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace);
461
+ const element = binding.methods[methodName].output;
462
+ body = this.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace);
482
463
  }
483
464
  else {
484
- var element = binding.methods[methodName].output;
465
+ const element = binding.methods[methodName].output;
485
466
  // Check for targetNamespace on the element
486
- var elementTargetNamespace = element.$targetNamespace;
487
- var outputNameWithNamespace = outputName;
467
+ const elementTargetNamespace = element.$targetNamespace;
468
+ let outputNameWithNamespace = outputName;
488
469
  if (elementTargetNamespace) {
489
470
  // if targetNamespace is set on the element concatinate it with the outputName
490
- outputNameWithNamespace = elementTargetNamespace + ":" + outputNameWithNamespace;
471
+ outputNameWithNamespace = `${elementTargetNamespace}:${outputNameWithNamespace}`;
491
472
  }
492
- body = _this_1.wsdl.objectToDocumentXML(outputNameWithNamespace, result, element.targetNSAlias, element.targetNamespace);
473
+ body = this.wsdl.objectToDocumentXML(outputNameWithNamespace, result, element.targetNSAlias, element.targetNamespace);
493
474
  }
494
- callback(_this_1._envelope(body, headers, includeTimestamp));
475
+ callback(this._envelope(body, headers, includeTimestamp));
495
476
  };
496
477
  if (!binding.methods[methodName].output) {
497
478
  // no output defined = one-way operation so return empty response
@@ -502,7 +483,7 @@ var Server = /** @class */ (function (_super) {
502
483
  }
503
484
  callback(body, this.onewayOptions.responseCode);
504
485
  }
505
- var methodCallback = function (error, result) {
486
+ const methodCallback = (error, result) => {
506
487
  if (error && error.Fault !== undefined) {
507
488
  // do nothing
508
489
  }
@@ -513,12 +494,12 @@ var Server = /** @class */ (function (_super) {
513
494
  }
514
495
  handleResult(error, result);
515
496
  };
516
- var result = method(args, methodCallback, options.headers, req, res, this);
497
+ const result = method(args, methodCallback, options.headers, req, res, this);
517
498
  if (typeof result !== 'undefined') {
518
499
  if (isPromiseLike(result)) {
519
- result.then(function (value) {
500
+ result.then((value) => {
520
501
  handleResult(null, value);
521
- }, function (err) {
502
+ }, (err) => {
522
503
  handleResult(err);
523
504
  });
524
505
  }
@@ -526,24 +507,24 @@ var Server = /** @class */ (function (_super) {
526
507
  handleResult(null, result);
527
508
  }
528
509
  }
529
- };
530
- Server.prototype._envelope = function (body, headers, includeTimestamp) {
531
- var defs = this.wsdl.definitions;
532
- var ns = defs.$targetNamespace;
533
- var encoding = '';
534
- var alias = utils_1.findPrefix(defs.xmlns, ns);
535
- var envelopeDefinition = this.wsdl.options.forceSoap12Headers
510
+ }
511
+ _envelope(body, headers, includeTimestamp) {
512
+ const defs = this.wsdl.definitions;
513
+ const ns = defs.$targetNamespace;
514
+ const encoding = '';
515
+ const alias = (0, utils_1.findPrefix)(defs.xmlns, ns);
516
+ const envelopeDefinition = this.wsdl.options.forceSoap12Headers
536
517
  ? 'http://www.w3.org/2003/05/soap-envelope'
537
518
  : 'http://schemas.xmlsoap.org/soap/envelope/';
538
- var xml = '<?xml version="1.0" encoding="utf-8"?>' +
519
+ let xml = '<?xml version="1.0" encoding="utf-8"?>' +
539
520
  '<soap:Envelope xmlns:soap="' + envelopeDefinition + '" ' +
540
521
  encoding +
541
522
  this.wsdl.xmlnsInEnvelope + '>';
542
523
  headers = headers || '';
543
524
  if (includeTimestamp) {
544
- var now = new Date();
545
- var created = getDateString(now);
546
- var expires = getDateString(new Date(now.getTime() + (1000 * 600)));
525
+ const now = new Date();
526
+ const created = getDateString(now);
527
+ const expires = getDateString(new Date(now.getTime() + (1000 * 600)));
547
528
  headers += '<o:Security soap:mustUnderstand="1" ' +
548
529
  'xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" ' +
549
530
  'xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">' +
@@ -559,10 +540,10 @@ var Server = /** @class */ (function (_super) {
559
540
  xml += body ? '<soap:Body>' + body + '</soap:Body>' : '<soap:Body/>';
560
541
  xml += '</soap:Envelope>';
561
542
  return xml;
562
- };
563
- Server.prototype._sendError = function (soapFault, callback, includeTimestamp) {
564
- var fault;
565
- var statusCode;
543
+ }
544
+ _sendError(soapFault, callback, includeTimestamp) {
545
+ let fault;
546
+ let statusCode;
566
547
  if (soapFault.statusCode) {
567
548
  statusCode = soapFault.statusCode;
568
549
  soapFault.statusCode = undefined;
@@ -580,8 +561,8 @@ var Server = /** @class */ (function (_super) {
580
561
  fault = this.wsdl.objectToDocumentXML('Fault', soapFault, 'soap');
581
562
  }
582
563
  return callback(this._envelope(fault, '', includeTimestamp), statusCode);
583
- };
584
- Server.prototype._sendHttpResponse = function (res, statusCode, result) {
564
+ }
565
+ _sendHttpResponse(res, statusCode, result) {
585
566
  if (statusCode) {
586
567
  res.statusCode = statusCode;
587
568
  }
@@ -598,8 +579,7 @@ var Server = /** @class */ (function (_super) {
598
579
  else {
599
580
  res.end(result);
600
581
  }
601
- };
602
- return Server;
603
- }(events_1.EventEmitter));
582
+ }
583
+ }
604
584
  exports.Server = Server;
605
585
  //# sourceMappingURL=server.js.map